19 MmcHostInstance->State = State;
20 return MmcHostInstance->MmcHost->NotifyState (MmcHostInstance->MmcHost, State);
35 MmcHost = MmcHostInstance->MmcHost;
38 if (MmcHost ==
NULL) {
39 return EFI_INVALID_PARAMETER;
42 if (MmcHostInstance->State != MmcHwInitializationState) {
44 CmdArg = MmcHostInstance->CardInfo.RCA << 16;
45 Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
46 if (EFI_ERROR (Status)) {
47 DEBUG ((DEBUG_ERROR,
"MmcGetCardStatus(MMC_CMD13): Error and Status = %r\n", Status));
52 MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
53 PrintResponseR1 (Response[0]);
63 IN BOOLEAN ExtendedVerification
68 MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
70 if (MmcHostInstance->MmcHost ==
NULL) {
76 if (!MmcHostInstance->MmcHost->IsCardPresent (MmcHostInstance->MmcHost)) {
83 MmcHostInstance->State = MmcHwInitializationState;
98 if (!MmcHost->IsCardPresent (MmcHost)) {
115 Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0);
116 if (!EFI_ERROR (Status)) {
117 MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response);
123#define MMCI0_BLOCKLEN 512
124#define MMCI0_TIMEOUT 10000
145 MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
146 MmcHost = MmcHostInstance->MmcHost;
148 if (MmcHostInstance->CardInfo.CardType != EMMC_CARD) {
152 if (MmcHostInstance->CardInfo.OCRData.AccessMode & SD_CARD_CAPACITY) {
155 CmdArg =
MultU64x32 (Lba, This->Media->BlockSize);
159 if ((MmcHostInstance->CardInfo.OCRData.AccessMode & MMC_OCR_ACCESS_MASK) ==
160 MMC_OCR_ACCESS_SECTOR)
164 CmdArg =
MultU64x32 (Lba, This->Media->BlockSize);
168 Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
169 if (EFI_ERROR (Status)) {
170 DEBUG ((DEBUG_ERROR,
"%a(MMC_CMD%d): Error %r\n", __func__, Cmd, Status));
174 if (Transfer == MMC_IOBLOCKS_READ) {
176 Status = MmcHost->ReadBlockData (MmcHost, Lba, BufferSize, Buffer);
177 if (EFI_ERROR (Status)) {
178 DEBUG ((DEBUG_BLKIO,
"%a(): Error Read Block Data and Status = %r\n", __func__, Status));
179 MmcStopTransmission (MmcHost);
183 Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
184 if (EFI_ERROR (Status)) {
185 DEBUG ((DEBUG_ERROR,
"%a() : Error MmcProgrammingState\n", __func__));
190 Status = MmcHost->WriteBlockData (MmcHost, Lba, BufferSize, Buffer);
191 if (EFI_ERROR (Status)) {
192 DEBUG ((DEBUG_BLKIO,
"%a(): Error Write Block Data and Status = %r\n", __func__, Status));
193 MmcStopTransmission (MmcHost);
199 Timeout = MMCI0_TIMEOUT;
200 CmdArg = MmcHostInstance->CardInfo.RCA << 16;
202 while ( !(Response[0] & MMC_R0_READY_FOR_DATA)
203 && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
206 Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
207 if (!EFI_ERROR (Status)) {
208 MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
209 if (Response[0] & MMC_R0_READY_FOR_DATA) {
215 if (BufferSize > This->Media->BlockSize) {
216 Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0);
217 if (EFI_ERROR (Status)) {
218 DEBUG ((DEBUG_BLKIO,
"%a(): Error and Status:%r\n", __func__, Status));
221 MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response);
224 Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
225 if (EFI_ERROR (Status)) {
226 DEBUG ((DEBUG_ERROR,
"MmcIoBlocks() : Error MmcTransferState\n"));
250 UINTN BytesRemainingToBeTransfered;
254 UINTN RemainingBlock;
257 MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
258 ASSERT (MmcHostInstance !=
NULL);
259 MmcHost = MmcHostInstance->MmcHost;
262 if (This->Media->MediaId != MediaId) {
263 return EFI_MEDIA_CHANGED;
266 if ((MmcHost ==
NULL) || (Buffer ==
NULL)) {
267 return EFI_INVALID_PARAMETER;
276 if (BufferSize == 0) {
281 if ((BufferSize % This->Media->BlockSize) != 0) {
282 return EFI_BAD_BUFFER_SIZE;
285 if (MMC_HOST_HAS_ISMULTIBLOCK (MmcHost) && MmcHost->IsMultiBlock (MmcHost)) {
286 BlockCount = BufferSize / This->Media->BlockSize;
290 if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)) {
291 return EFI_INVALID_PARAMETER;
294 if ((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly ==
TRUE)) {
295 return EFI_WRITE_PROTECTED;
299 if ((This->Media->IoAlign > 2) && (((
UINTN)Buffer & (This->Media->IoAlign - 1)) != 0)) {
300 return EFI_INVALID_PARAMETER;
305 RemainingBlock = BlockCount;
306 BytesRemainingToBeTransfered = BufferSize;
307 while (BytesRemainingToBeTransfered > 0) {
308 if (RemainingBlock <= MaxBlock) {
309 BlockCount = RemainingBlock;
311 BlockCount = MaxBlock;
315 CmdArg = MmcHostInstance->CardInfo.RCA << 16;
318 while ( (!(Response[0] & MMC_R0_READY_FOR_DATA))
319 && (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
322 Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
323 if (!EFI_ERROR (Status)) {
324 MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
329 DEBUG ((DEBUG_ERROR,
"The Card is busy\n"));
330 return EFI_NOT_READY;
333 if (Transfer == MMC_IOBLOCKS_READ) {
334 if (BlockCount == 1) {
342 if (BlockCount == 1) {
351 ConsumeSize = BlockCount * This->Media->BlockSize;
352 if (BytesRemainingToBeTransfered < ConsumeSize) {
353 ConsumeSize = BytesRemainingToBeTransfered;
356 Status = MmcTransferBlock (This, Cmd, Transfer, MediaId, Lba, ConsumeSize, Buffer);
357 if (EFI_ERROR (Status)) {
358 DEBUG ((DEBUG_ERROR,
"%a(): Failed to transfer block and Status:%r\n", __func__, Status));
361 RemainingBlock -= BlockCount;
362 BytesRemainingToBeTransfered -= ConsumeSize;
363 if (BytesRemainingToBeTransfered > 0) {
365 Buffer = (UINT8 *)Buffer + ConsumeSize;
382 return MmcIoBlocks (This, MMC_IOBLOCKS_READ, MediaId, Lba, BufferSize, Buffer);
395 return MmcIoBlocks (This, MMC_IOBLOCKS_WRITE, MediaId, Lba, BufferSize, Buffer);
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
#define DEBUG(Expression)
EFI_STATUS EFIAPI MmcFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
EFI_STATUS EFIAPI MmcReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
EFI_STATUS EFIAPI MmcWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI MmcReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_BLOCK_IO_MEDIA * Media