mirror of https://github.com/acidanthera/audk.git
EmbeddedPkg/MmcDxe: Update Mmc code to conform to coding standard
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14524 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
e7e50d6b19
commit
842b02d87f
|
@ -19,9 +19,6 @@
|
||||||
|
|
||||||
#include "Mmc.h"
|
#include "Mmc.h"
|
||||||
|
|
||||||
// Untested ...
|
|
||||||
//#define USE_STREAM
|
|
||||||
|
|
||||||
#define MAX_RETRY_COUNT 1000
|
#define MAX_RETRY_COUNT 1000
|
||||||
#define CMD_RETRY_COUNT 20
|
#define CMD_RETRY_COUNT 20
|
||||||
|
|
||||||
|
@ -112,7 +109,7 @@ PrintCSD (
|
||||||
DEBUG ((EFI_D_ERROR, "\t- Maximum Read Data Block: %d\n",2 << (MMC_CSD_GET_READBLLEN(Csd)-1)));
|
DEBUG ((EFI_D_ERROR, "\t- Maximum Read Data Block: %d\n",2 << (MMC_CSD_GET_READBLLEN(Csd)-1)));
|
||||||
DEBUG ((EFI_D_ERROR, "\t- Maximum Write Data Block: %d\n",2 << (MMC_CSD_GET_WRITEBLLEN(Csd)-1)));
|
DEBUG ((EFI_D_ERROR, "\t- Maximum Write Data Block: %d\n",2 << (MMC_CSD_GET_WRITEBLLEN(Csd)-1)));
|
||||||
|
|
||||||
if (!MMC_CSD_GET_FILEFORMATGRP(Csd)) {
|
if (!MMC_CSD_GET_FILEFORMATGRP (Csd)) {
|
||||||
Value = MMC_CSD_GET_FILEFORMAT (Csd);
|
Value = MMC_CSD_GET_FILEFORMAT (Csd);
|
||||||
if (Value == 0) DEBUG ((EFI_D_ERROR, "\t- Format (0): Hard disk-like file system with partition table\n"));
|
if (Value == 0) DEBUG ((EFI_D_ERROR, "\t- Format (0): Hard disk-like file system with partition table\n"));
|
||||||
else if (Value == 1) DEBUG ((EFI_D_ERROR, "\t- Format (1): DOS FAT (floppy-like) with boot sector only (no partition table)\n"));
|
else if (Value == 1) DEBUG ((EFI_D_ERROR, "\t- Format (1): DOS FAT (floppy-like) with boot sector only (no partition table)\n"));
|
||||||
|
@ -157,7 +154,7 @@ PrintResponseR1 (
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
MmcGetCardStatus(
|
MmcGetCardStatus (
|
||||||
IN MMC_HOST_INSTANCE *MmcHostInstance
|
IN MMC_HOST_INSTANCE *MmcHostInstance
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +170,7 @@ MmcGetCardStatus(
|
||||||
if (MmcHost == NULL) {
|
if (MmcHost == NULL) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
if(MmcHostInstance->State != MmcHwInitializationState){
|
if (MmcHostInstance->State != MmcHwInitializationState) {
|
||||||
//Get the Status of the card.
|
//Get the Status of the card.
|
||||||
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
||||||
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
||||||
|
@ -249,7 +246,7 @@ MmcIdentificationMode (
|
||||||
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R7, Response);
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R7, Response);
|
||||||
PrintResponseR1 (Response[0]);
|
PrintResponseR1 (Response[0]);
|
||||||
//check if it is valid response
|
//check if it is valid response
|
||||||
if(Response[0] != CmdArg){
|
if (Response[0] != CmdArg) {
|
||||||
DEBUG ((EFI_D_ERROR, "The Card is not usable\n"));
|
DEBUG ((EFI_D_ERROR, "The Card is not usable\n"));
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
@ -327,7 +324,7 @@ MmcIdentificationMode (
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID, Response);
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID, Response);
|
||||||
PrintCID(Response);
|
PrintCID (Response);
|
||||||
|
|
||||||
Status = MmcNotifyState (MmcHostInstance, MmcIdentificationState);
|
Status = MmcNotifyState (MmcHostInstance, MmcIdentificationState);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
|
@ -374,8 +371,9 @@ EFI_STATUS InitializeMmcDevice (
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN CardSize, NumBlocks, BlockSize, CmdArg;
|
UINTN CardSize, NumBlocks, BlockSize, CmdArg;
|
||||||
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
||||||
UINTN BlockCount = 1;
|
UINTN BlockCount;
|
||||||
|
|
||||||
|
BlockCount = 1;
|
||||||
MmcHost = MmcHostInstance->MmcHost;
|
MmcHost = MmcHostInstance->MmcHost;
|
||||||
|
|
||||||
MmcIdentificationMode (MmcHostInstance);
|
MmcIdentificationMode (MmcHostInstance);
|
||||||
|
@ -384,21 +382,21 @@ EFI_STATUS InitializeMmcDevice (
|
||||||
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
||||||
Status = MmcHost->SendCommand (MmcHost, MMC_CMD9, CmdArg);
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD9, CmdArg);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD9): Error, Status=%r\n", Status));
|
DEBUG((EFI_D_ERROR, "InitializeMmcDevice(MMC_CMD9): Error, Status=%r\n", Status));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
//Read Response
|
//Read Response
|
||||||
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CSD, Response);
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CSD, Response);
|
||||||
PrintCSD(Response);
|
PrintCSD (Response);
|
||||||
|
|
||||||
if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) {
|
if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) {
|
||||||
CardSize = HC_MMC_CSD_GET_DEVICESIZE (Response);
|
CardSize = HC_MMC_CSD_GET_DEVICESIZE (Response);
|
||||||
NumBlocks = ((CardSize + 1) * 1024);
|
NumBlocks = ((CardSize + 1) * 1024);
|
||||||
BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);
|
BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response);
|
||||||
} else {
|
} else {
|
||||||
CardSize = MMC_CSD_GET_DEVICESIZE (Response);
|
CardSize = MMC_CSD_GET_DEVICESIZE (Response);
|
||||||
NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2));
|
NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2));
|
||||||
BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);
|
BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response);
|
||||||
}
|
}
|
||||||
|
|
||||||
//For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.
|
//For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.
|
||||||
|
@ -416,20 +414,21 @@ EFI_STATUS InitializeMmcDevice (
|
||||||
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
||||||
Status = MmcHost->SendCommand (MmcHost, MMC_CMD7, CmdArg);
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD7, CmdArg);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD7): Error and Status = %r\n", Status));
|
DEBUG((EFI_D_ERROR, "InitializeMmcDevice(MMC_CMD7): Error and Status = %r\n", Status));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
|
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcTransferState\n"));
|
DEBUG((EFI_D_ERROR, "InitializeMmcDevice(): Error MmcTransferState\n"));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Block Length
|
// Set Block Length
|
||||||
Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize);
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n", MmcHostInstance->BlockIo.Media->BlockSize, Status));
|
DEBUG((EFI_D_ERROR, "InitializeMmcDevice(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n",
|
||||||
|
MmcHostInstance->BlockIo.Media->BlockSize, Status));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,10 +507,11 @@ MmcIoBlocks (
|
||||||
MMC_HOST_INSTANCE *MmcHostInstance;
|
MMC_HOST_INSTANCE *MmcHostInstance;
|
||||||
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
||||||
UINTN BytesRemainingToBeTransfered;
|
UINTN BytesRemainingToBeTransfered;
|
||||||
UINTN BlockCount = 1;
|
UINTN BlockCount;
|
||||||
|
|
||||||
|
BlockCount = 1;
|
||||||
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
||||||
ASSERT (MmcHostInstance != 0);
|
ASSERT (MmcHostInstance != NULL);
|
||||||
MmcHost = MmcHostInstance->MmcHost;
|
MmcHost = MmcHostInstance->MmcHost;
|
||||||
ASSERT (MmcHost);
|
ASSERT (MmcHost);
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ MmcIoBlocks (
|
||||||
return EFI_MEDIA_CHANGED;
|
return EFI_MEDIA_CHANGED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((MmcHost == 0)|| (Buffer == NULL)) {
|
if ((MmcHost == NULL) || (Buffer == NULL)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,11 +529,11 @@ MmcIoBlocks (
|
||||||
}
|
}
|
||||||
|
|
||||||
// All blocks must be within the device
|
// All blocks must be within the device
|
||||||
if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)){
|
if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) {
|
if ((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) {
|
||||||
return EFI_WRITE_PROTECTED;
|
return EFI_WRITE_PROTECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,19 +581,11 @@ MmcIoBlocks (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Transfer == MMC_IOBLOCKS_READ) {
|
if (Transfer == MMC_IOBLOCKS_READ) {
|
||||||
#ifndef USE_STREAM
|
|
||||||
// Read a single block
|
// Read a single block
|
||||||
Cmd = MMC_CMD17;
|
Cmd = MMC_CMD17;
|
||||||
#else
|
|
||||||
//TODO: Should we support read stream (MMC_CMD11)
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
#ifndef USE_STREAM
|
|
||||||
// Write a single block
|
// Write a single block
|
||||||
Cmd = MMC_CMD24;
|
Cmd = MMC_CMD24;
|
||||||
#else
|
|
||||||
//TODO: Should we support write stream (MMC_CMD20)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
|
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
|
@ -602,34 +594,24 @@ MmcIoBlocks (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Transfer == MMC_IOBLOCKS_READ) {
|
if (Transfer == MMC_IOBLOCKS_READ) {
|
||||||
#ifndef USE_STREAM
|
|
||||||
// Read one block of Data
|
// Read one block of Data
|
||||||
Status = MmcHost->ReadBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
Status = MmcHost->ReadBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Read Block Data and Status = %r\n", Status));
|
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Read Block Data and Status = %r\n", Status));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
//TODO: Read a stream
|
|
||||||
ASSERT (0);
|
|
||||||
#endif
|
|
||||||
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
|
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcProgrammingState\n"));
|
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcProgrammingState\n"));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifndef USE_STREAM
|
|
||||||
// Write one block of Data
|
// Write one block of Data
|
||||||
Status = MmcHost->WriteBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
Status = MmcHost->WriteBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Write Block Data and Status = %r\n", Status));
|
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Write Block Data and Status = %r\n", Status));
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
//TODO: Write a stream
|
|
||||||
ASSERT (0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command 12 - Stop transmission (ends read)
|
// Command 12 - Stop transmission (ends read)
|
||||||
|
|
Loading…
Reference in New Issue