+/** @file\r
+*\r
+* Copyright (c) 2011, ARM Limited. All rights reserved.\r
+* \r
+* This program and the accompanying materials \r
+* are licensed and made available under the terms and conditions of the BSD License \r
+* which accompanies this distribution. The full text of the license may be found at \r
+* http://opensource.org/licenses/bsd-license.php \r
+*\r
+* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+*\r
+**/\r
+\r
+#include <Protocol/MmcHost.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/TimerLib.h>\r
+\r
+#include "Mmc.h"\r
+\r
+// Untested ...\r
+//#define USE_STREAM\r
+\r
+#define MAX_RETRY_COUNT 200\r
+\r
+EFI_STATUS\r
+MmcNotifyState (\r
+ MMC_HOST_INSTANCE *MmcHostInstance,\r
+ MMC_STATE State\r
+ ) {\r
+ MmcHostInstance->State = State;\r
+ return MmcHostInstance->MmcHost->NotifyState(State);\r
+}\r
+\r
+VOID PrintOCR(UINT32 ocr) {\r
+ float minv, maxv, volts;\r
+ int loop;\r
+\r
+ minv = 3.6;\r
+ maxv = 2.0;\r
+ volts = 2.0;\r
+\r
+ // The MMC register bits [23:8] indicate the working range of the card\r
+ for (loop = 8; loop < 24; loop++) {\r
+ if (ocr & (1 << loop)) {\r
+ if (minv > volts) minv = volts;\r
+ if (maxv < volts) maxv = volts + 0.1;\r
+ }\r
+ volts = volts + 0.1;\r
+ }\r
+\r
+ DEBUG((EFI_D_ERROR, "- PrintOCR ocr (0x%X)\n",ocr));\r
+ //DEBUG((EFI_D_ERROR, "\t- Card operating voltage: %fV to %fV\n", minv, maxv));\r
+ if (((ocr >> 29) & 3) == 0)\r
+ DEBUG((EFI_D_ERROR, "\t- AccessMode: Byte Mode\n"));\r
+ else\r
+ DEBUG((EFI_D_ERROR, "\t- AccessMode: Block Mode (0x%X)\n",((ocr >> 29) & 3)));\r
+\r
+ if (ocr & MMC_OCR_POWERUP)\r
+ DEBUG((EFI_D_ERROR, "\t- PowerUp\n"));\r
+ else\r
+ DEBUG((EFI_D_ERROR, "\t- Voltage Not Supported\n"));\r
+}\r
+\r
+VOID PrintCID(UINT32* cid) {\r
+ DEBUG((EFI_D_ERROR, "- PrintCID\n"));\r
+ DEBUG((EFI_D_ERROR, "\t- Manufacturing date: %d/%d\n",(cid[0] >> 8) & 0xF,(cid[0] >> 12) & 0xFF));\r
+ DEBUG((EFI_D_ERROR, "\t- Product serial number: 0x%X%X\n",cid[1] & 0xFFFFFF,(cid[0] >> 24) & 0xFF));\r
+ DEBUG((EFI_D_ERROR, "\t- Product revision: %d\n",cid[1] >> 24));\r
+ //DEBUG((EFI_D_ERROR, "\t- Product name: %s\n",(char*)(cid + 2)));\r
+ DEBUG((EFI_D_ERROR, "\t- OEM ID: %c%c\n",(cid[3] >> 8) & 0xFF,(cid[3] >> 16) & 0xFF));\r
+}\r
+\r
+VOID PrintCSD(UINT32* csd) {\r
+ UINTN val32;\r
+ CONST CHAR8* str_unit[] = { "100kbit/s","1Mbit/s","10Mbit/s","100MBit/s","Unkbown","Unkbown","Unkbown","Unkbown" };\r
+ CONST CHAR8* str_value[] = { "1.0","1.2","1.3","1.5","2.0","2.5","3.0","3.5","4.0","4.5","5.0","Unknown","Unknown","Unknown","Unknown" };\r
+\r
+ if (((csd[2] >> 30) & 0x3) == 0)\r
+ DEBUG((EFI_D_ERROR, "- PrintCSD Version 1.01-1.10/Version 2.00/Standard Capacity\n"));\r
+ else if (((csd[2] >> 30) & 0x3) == 1)\r
+ DEBUG((EFI_D_ERROR, "- PrintCSD Version 2.00/High Capacity\n"));\r
+ else\r
+ DEBUG((EFI_D_ERROR, "- PrintCSD Version Higher than v3.3\n"));\r
+\r
+ DEBUG((EFI_D_ERROR, "\t- Supported card command class: 0x%X\n",MMC_CSD_GET_CCC(csd)));\r
+ DEBUG((EFI_D_ERROR, "\t- Speed: %a %a\n",str_value[(MMC_CSD_GET_TRANSPEED(csd) >> 3) & 0xF],str_unit[MMC_CSD_GET_TRANSPEED(csd) & 7]));\r
+ DEBUG((EFI_D_ERROR, "\t- Maximum Read Data Block: %d\n",2 << (MMC_CSD_GET_READBLLEN(csd)-1)));\r
+ DEBUG((EFI_D_ERROR, "\t- Maximum Write Data Block: %d\n",2 << (MMC_CSD_GET_WRITEBLLEN(csd)-1)));\r
+ \r
+ if (!MMC_CSD_GET_FILEFORMATGRP(csd)) {\r
+ val32 = MMC_CSD_GET_FILEFORMAT(csd);\r
+ if (val32 == 0) DEBUG((EFI_D_ERROR, "\t- Format(0): Hard disk-like file system with partition table\n"));\r
+ else if (val32 == 1) DEBUG((EFI_D_ERROR, "\t- Format(1): DOS FAT (floppy-like) with boot sector only (no partition table)\n"));\r
+ else if (val32 == 2) DEBUG((EFI_D_ERROR, "\t- Format(2): Universal File Format\n"));\r
+ else DEBUG((EFI_D_ERROR, "\t- Format(3): Others/Unknown\n"));\r
+ } else {\r
+ DEBUG((EFI_D_ERROR, "\t- Format: Reserved\n"));\r
+ }\r
+}\r
+\r
+VOID PrintRCA(UINT32 rca) {\r
+ DEBUG((EFI_D_ERROR, "- PrintRCA: 0x%X\n",rca));\r
+ DEBUG((EFI_D_ERROR, "\t- Status: 0x%X\n",rca & 0xFFFF));\r
+ DEBUG((EFI_D_ERROR, "\t- RCA: 0x%X\n",(rca >> 16) & 0xFFFF));\r
+}\r
+\r
+VOID PrintResponseR1(UINT32 response) {\r
+ DEBUG((EFI_D_ERROR, "Response: 0x%X\n",response));\r
+ if (response & (1 << 8)) DEBUG((EFI_D_ERROR, "\t- READY_FOR_DATA\n"));\r
+\r
+ if (((response >> 9) & 0xF) == 0) DEBUG((EFI_D_ERROR, "\t- State: Idle\n"));\r
+ else if (((response >> 9) & 0xF) == 1) DEBUG((EFI_D_ERROR, "\t- State: Ready\n"));\r
+ else if (((response >> 9) & 0xF) == 2) DEBUG((EFI_D_ERROR, "\t- State: Ident\n"));\r
+ else if (((response >> 9) & 0xF) == 3) DEBUG((EFI_D_ERROR, "\t- State: StandBy\n"));\r
+ else if (((response >> 9) & 0xF) == 4) DEBUG((EFI_D_ERROR, "\t- State: Tran\n"));\r
+ else if (((response >> 9) & 0xF) == 5) DEBUG((EFI_D_ERROR, "\t- State: Data\n"));\r
+ else if (((response >> 9) & 0xF) == 6) DEBUG((EFI_D_ERROR, "\t- State: Rcv\n"));\r
+ else if (((response >> 9) & 0xF) == 7) DEBUG((EFI_D_ERROR, "\t- State: Prg\n"));\r
+ else if (((response >> 9) & 0xF) == 8) DEBUG((EFI_D_ERROR, "\t- State: Dis\n"));\r
+ else DEBUG((EFI_D_ERROR, "\t- State: Reserved\n"));\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MmcIdentificationMode (\r
+ MMC_HOST_INSTANCE *MmcHostInstance\r
+ ) {\r
+ EFI_STATUS Status;\r
+ UINT32 Response[4];\r
+ UINTN timer;\r
+ UINTN CmdArg;\r
+ BOOLEAN bHCS;\r
+ EFI_MMC_HOST_PROTOCOL *MmcHost;\r
+ \r
+ MmcHost = MmcHostInstance->MmcHost;\r
+ CmdArg = 0;\r
+ bHCS = FALSE;\r
+\r
+ if (MmcHost == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ // We can get into this function if we restart the identification mode\r
+ if (MmcHostInstance->State == MmcHwInitializationState) {\r
+ // Initialize the MMC Host HW\r
+ Status = MmcNotifyState (MmcHostInstance, MmcHwInitializationState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcHwInitializationState\n"));\r
+ return Status;\r
+ }\r
+ } else {\r
+ //Note: Could even be used in all cases. But it looks this command could put the state machine into inactive for some cards\r
+ Status = MmcHost->SendCommand(MMC_CMD0, 0);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD0): Error\n"));\r
+ return Status;\r
+ }\r
+ }\r
+\r
+ Status = MmcNotifyState (MmcHostInstance, MmcIdleState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcIdleState\n"));\r
+ return Status;\r
+ }\r
+\r
+ // Are we using SDIO ?\r
+ Status = MmcHost->SendCommand(MMC_CMD5, 0);\r
+ if (Status == EFI_SUCCESS) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD5): Error - SDIO not supported.\n"));\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ // Check which kind of card we are using. Ver2.00 or later SD Memory Card (PL180 is SD v1.1)\r
+ CmdArg = (0x0UL << 12 | BIT8 | 0xCEUL << 0);\r
+ Status = MmcHost->SendCommand(MMC_CMD8, CmdArg);\r
+ if (Status == EFI_SUCCESS) {\r
+ DEBUG ((EFI_D_ERROR, "Card is SD2.0 => Supports high capacity\n"));\r
+ bHCS = TRUE;\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R7,Response);\r
+ PrintResponseR1(Response[0]);\r
+ } else {\r
+ DEBUG ((EFI_D_ERROR, "Not a SD2.0 Card\n"));\r
+ }\r
+\r
+ // We need to wait for the MMC or SD card is ready => (gCardInfo.OCRData.Busy == 1)\r
+ timer = MAX_RETRY_COUNT;\r
+ while (timer > 0) {\r
+ // SD Card or MMC Card ? CMD55 indicates to the card that the next command is an application specific command\r
+ Status = MmcHost->SendCommand(MMC_CMD55, 0);\r
+ if (Status == EFI_SUCCESS) {\r
+ DEBUG ((EFI_D_INFO, "Card should be SD\n"));\r
+ if (bHCS) {\r
+ MmcHostInstance->CardInfo.CardType = SD_CARD_2;\r
+ } else {\r
+ MmcHostInstance->CardInfo.CardType = SD_CARD;\r
+ }\r
+\r
+ // Note: The first time CmdArg will be zero\r
+ CmdArg = ((UINTN *) &(MmcHostInstance->CardInfo.OCRData))[0];\r
+ if (bHCS) {\r
+ CmdArg |= BIT30;\r
+ }\r
+ Status = MmcHost->SendCommand(MMC_ACMD41, CmdArg);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(ACMD41): Error\n"));\r
+ return Status;\r
+ }\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_OCR,Response);\r
+ ((UINT32 *) &(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];\r
+ } else {\r
+ DEBUG ((EFI_D_INFO, "Card should be MMC\n"));\r
+ MmcHostInstance->CardInfo.CardType = MMC_CARD;\r
+\r
+ Status = MmcHost->SendCommand(MMC_CMD1, 0x800000);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(ACMD41): Error\n"));\r
+ return Status;\r
+ }\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_OCR,Response);\r
+ ((UINT32 *) &(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];\r
+ }\r
+\r
+ if (MmcHostInstance->CardInfo.OCRData.Busy == 0) {\r
+ MicroSecondDelay(10*1000);\r
+ timer--;\r
+ } else {\r
+ if ((MmcHostInstance->CardInfo.CardType == SD_CARD_2) && (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1)) {\r
+ MmcHostInstance->CardInfo.CardType = SD_CARD_2_HIGH;\r
+ DEBUG ((EFI_D_ERROR, "High capacity card.\n"));\r
+ }\r
+ break; // The MMC/SD card is ready. Continue the Identification Mode\r
+ }\r
+ }\r
+\r
+ if (timer == 0) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(): No Card\n"));\r
+ ASSERT(0);\r
+ return EFI_NO_MEDIA;\r
+ } else {\r
+ PrintOCR(Response[0]);\r
+ }\r
+\r
+ Status = MmcNotifyState (MmcHostInstance, MmcReadyState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcReadyState\n"));\r
+ return Status;\r
+ }\r
+\r
+ Status = MmcHost->SendCommand(MMC_CMD2, 0);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD2): Error\n"));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_CID,Response);\r
+ PrintCID(Response);\r
+\r
+ Status = MmcNotifyState (MmcHostInstance, MmcIdentificationState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcIdentificationState\n"));\r
+ return Status;\r
+ }\r
+\r
+ CmdArg = 0;\r
+ Status = MmcHost->SendCommand(MMC_CMD3, CmdArg);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD3): Error\n"));\r
+ return Status;\r
+ }\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_RCA,Response);\r
+ PrintRCA(Response[0]);\r
+\r
+ // For MMC card, RCA is assigned by CMD3 while CMD3 dumps the RCA for SD card\r
+ if (MmcHostInstance->CardInfo.CardType != MMC_CARD) {\r
+ MmcHostInstance->CardInfo.RCA = Response[0] >> 16;\r
+ } else {\r
+ MmcHostInstance->CardInfo.RCA = CmdArg;\r
+ }\r
+\r
+ Status = MmcNotifyState (MmcHostInstance, MmcStandByState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcStandByState\n"));\r
+ return Status;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MmcReset (\r
+ IN EFI_BLOCK_IO_PROTOCOL *This,\r
+ IN BOOLEAN ExtendedVerification\r
+ ) {\r
+ // Implement me. Either send a CMD0 (could not work for some MMC host) or just turn off/turn\r
+ // on power and restart Identification mode\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+MmcDetectCard (\r
+ EFI_MMC_HOST_PROTOCOL *MmcHost\r
+ )\r
+{\r
+ if (!MmcHost->IsCardPresent()) {\r
+ return EFI_NO_MEDIA;\r
+ } else {\r
+ return EFI_SUCCESS;\r
+ }\r
+}\r
+\r
+#define MMCI0_BLOCKLEN 512\r
+#define MMCI0_TIMEOUT 10000\r
+\r
+EFI_STATUS MmcIoBlocks (\r
+ IN EFI_BLOCK_IO_PROTOCOL *This,\r
+ IN UINTN Transfer,\r
+ IN UINT32 MediaId,\r
+ IN EFI_LBA Lba,\r
+ IN UINTN BufferSize,\r
+ OUT VOID *Buffer\r
+ ) {\r
+ UINT32 Response[4];\r
+ EFI_STATUS Status;\r
+ UINTN CardSize, NumBlocks, BlockSize, CmdArg;\r
+ UINTN timer;\r
+ UINTN Cmd;\r
+ MMC_HOST_INSTANCE *MmcHostInstance;\r
+ EFI_MMC_HOST_PROTOCOL *MmcHost;\r
+ UINTN BytesRemainingToBeTransfered;\r
+ UINTN BlockCount = 1;\r
+\r
+ MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS(This);\r
+ ASSERT(MmcHostInstance != 0);\r
+ MmcHost = MmcHostInstance->MmcHost;\r
+ ASSERT(MmcHost);\r
+\r
+ if (MmcHost == 0) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ // Check if a Card is Present\r
+ if (!MmcHost->IsCardPresent()) {\r
+ MmcHostInstance->BlockIo.Media->MediaPresent = FALSE;\r
+ MmcHostInstance->BlockIo.Media->LastBlock = 0;\r
+ MmcHostInstance->BlockIo.Media->BlockSize = 512; // Should be zero but there is a bug in DiskIo\r
+ MmcHostInstance->BlockIo.Media->ReadOnly = FALSE; \r
+ return EFI_NO_MEDIA;\r
+ }\r
+\r
+ // If the driver has not been initialized yet then go into Iddentification Mode\r
+ if (MmcHostInstance->State == MmcHwInitializationState) {\r
+ MmcIdentificationMode (MmcHostInstance);\r
+\r
+ CmdArg = MmcHostInstance->CardInfo.RCA << 16;\r
+ Status = MmcHost->SendCommand(MMC_CMD9, CmdArg);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD9): Error\n"));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_CSD,Response);\r
+ PrintCSD(Response);\r
+\r
+\r
+ if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) {\r
+ ASSERT(0); //TODO: Implementation needed\r
+ CardSize = MMC_CSD_GET_DEVICESIZE(Response);\r
+ NumBlocks = ((CardSize + 1) * 1024);;\r
+ BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);\r
+ } else {\r
+ CardSize = MMC_CSD_GET_DEVICESIZE(Response);\r
+ NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT(Response) + 2));\r
+ BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);\r
+ }\r
+\r
+ //For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.\r
+ if (BlockSize > 512) {\r
+ NumBlocks = MultU64x32(NumBlocks, BlockSize/512);\r
+ BlockSize = 512; \r
+ }\r
+\r
+ MmcHostInstance->BlockIo.Media->LastBlock = (NumBlocks - 1);\r
+ MmcHostInstance->BlockIo.Media->BlockSize = BlockSize;\r
+ MmcHostInstance->BlockIo.Media->ReadOnly = MmcHost->IsReadOnly();\r
+ MmcHostInstance->BlockIo.Media->MediaPresent = TRUE; \r
+ MmcHostInstance->BlockIo.Media->MediaId++; \r
+\r
+ CmdArg = MmcHostInstance->CardInfo.RCA << 16;\r
+ Status = MmcHost->SendCommand(MMC_CMD7, CmdArg);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD7): Error\n"));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+ \r
+ Status = MmcNotifyState (MmcHostInstance, MmcTransferState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcTransferState\n"));\r
+ return Status;\r
+ }\r
+ } else {\r
+ // Maybe test if the card has changed to update gMmcMedia information\r
+ if (MmcHostInstance->State == MmcTransferState) {\r
+ //DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : MmcTransferState\n"));\r
+ } else if (MmcHostInstance->State == MmcStandByState) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : MmcStandByState\n"));\r
+ } else {\r
+ ASSERT(0);\r
+ }\r
+ }\r
+\r
+ if (Lba > This->Media->LastBlock) {\r
+ ASSERT(0);\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ \r
+ if ((BufferSize % This->Media->BlockSize) != 0) {\r
+ ASSERT(0);\r
+ return EFI_BAD_BUFFER_SIZE;\r
+ }\r
+\r
+ BytesRemainingToBeTransfered = BufferSize;\r
+ while (BytesRemainingToBeTransfered > 0) {\r
+ // Set Block Length\r
+ Status = MmcHost->SendCommand(MMC_CMD16, This->Media->BlockSize);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD16): Error This->Media->BlockSize:%d\n",This->Media->BlockSize));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+\r
+ // Block Count (not used). Could return an error for SD card\r
+ MmcHost->SendCommand(MMC_CMD23, BlockCount);\r
+\r
+ //Set command argument based on the card access mode (Byte mode or Block mode)\r
+ if (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1) {\r
+ CmdArg = Lba;\r
+ } else {\r
+ CmdArg = Lba * This->Media->BlockSize;\r
+ }\r
+\r
+ if (Transfer == MMC_IOBLOCKS_READ) {\r
+#ifndef USE_STREAM\r
+ // Read a single block\r
+ Cmd = MMC_CMD17;\r
+#else\r
+ //TODO: Should we support read stream (MMC_CMD11)\r
+#endif\r
+ } else {\r
+#ifndef USE_STREAM\r
+ // Write a single block\r
+ Cmd = MMC_CMD24;\r
+#else\r
+ //TODO: Should we support write stream (MMC_CMD20)\r
+#endif\r
+ }\r
+ Status = MmcHost->SendCommand(Cmd, CmdArg);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD%d): Error\n",Cmd));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+\r
+ if (Transfer == MMC_IOBLOCKS_READ) {\r
+#ifndef USE_STREAM\r
+ // Read one block of Data\r
+ Status = MmcHost->ReadBlockData(Lba,This->Media->BlockSize,Buffer);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_BLKIO, "MmcIdentificationMode(): Error Read Block Data"));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+#else\r
+ //TODO: Read a steam\r
+ ASSERT(0);\r
+#endif\r
+ Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcProgrammingState\n"));\r
+ return Status;\r
+ }\r
+ } else {\r
+#ifndef USE_STREAM\r
+ // Write one block of Data\r
+ Status = MmcHost->WriteBlockData(Lba,This->Media->BlockSize,Buffer);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_BLKIO, "MmcIdentificationMode(): Error Write Block Data"));\r
+ ASSERT(0);\r
+ return Status;\r
+ }\r
+#else\r
+ //TODO: Write a steam\r
+ ASSERT(0);\r
+#endif\r
+ }\r
+\r
+ // Command 12 - Stop transmission (ends read)\r
+ Status = MmcHost->SendCommand(MMC_CMD12, 0);\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1b,Response);\r
+\r
+ // Command 13 - Read status and wait for programming to complete (return to tran)\r
+ timer = MMCI0_TIMEOUT;\r
+ while ((MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && timer) {\r
+ MmcHost->SendCommand(MMC_CMD13, 0);\r
+ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response);\r
+ NanoSecondDelay(100);\r
+ timer--;\r
+ }\r
+\r
+ Status = MmcNotifyState (MmcHostInstance, MmcTransferState);\r
+ if (EFI_ERROR(Status)) {\r
+ DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcTransferState\n"));\r
+ return Status;\r
+ }\r
+\r
+ BytesRemainingToBeTransfered -= This->Media->BlockSize;\r
+ Lba += BlockCount;\r
+ Buffer = (UINT8 *)Buffer + This->Media->BlockSize;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MmcReadBlocks (\r
+ IN EFI_BLOCK_IO_PROTOCOL *This,\r
+ IN UINT32 MediaId,\r
+ IN EFI_LBA Lba,\r
+ IN UINTN BufferSize,\r
+ OUT VOID *Buffer\r
+ ) {\r
+ return MmcIoBlocks (This, MMC_IOBLOCKS_READ, MediaId, Lba, BufferSize, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MmcWriteBlocks (\r
+ IN EFI_BLOCK_IO_PROTOCOL *This,\r
+ IN UINT32 MediaId,\r
+ IN EFI_LBA Lba,\r
+ IN UINTN BufferSize,\r
+ IN VOID *Buffer\r
+ ) {\r
+ return MmcIoBlocks (This, MMC_IOBLOCKS_WRITE, MediaId, Lba, BufferSize, Buffer);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MmcFlushBlocks (\r
+ IN EFI_BLOCK_IO_PROTOCOL *This\r
+ ) {\r
+ return EFI_SUCCESS;\r
+}\r
+\r