mirror of https://github.com/acidanthera/audk.git
EmbeddedPkg/MmcDxe: expand to support multiple blocks
Make use of DMA to transfer multiple blocks at one time. It could improve the performance on MMC/SD driver. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org> Tested-by: Ryan Harkin <ryan.harkin@linaro.org> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
This commit is contained in:
parent
e06253ba80
commit
339c6e905a
|
@ -34,6 +34,10 @@
|
||||||
|
|
||||||
#define MMC_OCR_POWERUP 0x80000000
|
#define MMC_OCR_POWERUP 0x80000000
|
||||||
|
|
||||||
|
#define MMC_OCR_ACCESS_MASK 0x3 /* bit[30-29] */
|
||||||
|
#define MMC_OCR_ACCESS_BYTE 0x1 /* bit[29] */
|
||||||
|
#define MMC_OCR_ACCESS_SECTOR 0x2 /* bit[30] */
|
||||||
|
|
||||||
#define MMC_CSD_GET_CCC(Response) (Response[2] >> 20)
|
#define MMC_CSD_GET_CCC(Response) (Response[2] >> 20)
|
||||||
#define MMC_CSD_GET_TRANSPEED(Response) (Response[3] & 0xFF)
|
#define MMC_CSD_GET_TRANSPEED(Response) (Response[3] & 0xFF)
|
||||||
#define MMC_CSD_GET_READBLLEN(Response) ((Response[2] >> 16) & 0xF)
|
#define MMC_CSD_GET_READBLLEN(Response) ((Response[2] >> 16) & 0xF)
|
||||||
|
|
|
@ -126,6 +126,96 @@ MmcStopTransmission (
|
||||||
#define MMCI0_BLOCKLEN 512
|
#define MMCI0_BLOCKLEN 512
|
||||||
#define MMCI0_TIMEOUT 10000
|
#define MMCI0_TIMEOUT 10000
|
||||||
|
|
||||||
|
STATIC
|
||||||
|
EFI_STATUS
|
||||||
|
MmcTransferBlock (
|
||||||
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||||
|
IN UINTN Cmd,
|
||||||
|
IN UINTN Transfer,
|
||||||
|
IN UINT32 MediaId,
|
||||||
|
IN EFI_LBA Lba,
|
||||||
|
IN UINTN BufferSize,
|
||||||
|
OUT VOID *Buffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
UINTN CmdArg;
|
||||||
|
INTN Timeout;
|
||||||
|
UINT32 Response[4];
|
||||||
|
MMC_HOST_INSTANCE *MmcHostInstance;
|
||||||
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
||||||
|
|
||||||
|
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
||||||
|
MmcHost = MmcHostInstance->MmcHost;
|
||||||
|
|
||||||
|
//Set command argument based on the card access mode (Byte mode or Block mode)
|
||||||
|
if ((MmcHostInstance->CardInfo.OCRData.AccessMode & MMC_OCR_ACCESS_MASK) ==
|
||||||
|
MMC_OCR_ACCESS_SECTOR) {
|
||||||
|
CmdArg = Lba;
|
||||||
|
} else {
|
||||||
|
CmdArg = Lba * This->Media->BlockSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_ERROR, "%a(MMC_CMD%d): Error %r\n", __func__, Cmd, Status));
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Transfer == MMC_IOBLOCKS_READ) {
|
||||||
|
// Read Data
|
||||||
|
Status = MmcHost->ReadBlockData (MmcHost, Lba, BufferSize, Buffer);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_BLKIO, "%a(): Error Read Block Data and Status = %r\n", __func__, Status));
|
||||||
|
MmcStopTransmission (MmcHost);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_ERROR, "%a() : Error MmcProgrammingState\n", __func__));
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Write Data
|
||||||
|
Status = MmcHost->WriteBlockData (MmcHost, Lba, BufferSize, Buffer);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_BLKIO, "%a(): Error Write Block Data and Status = %r\n", __func__, Status));
|
||||||
|
MmcStopTransmission (MmcHost);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command 13 - Read status and wait for programming to complete (return to tran)
|
||||||
|
Timeout = MMCI0_TIMEOUT;
|
||||||
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
||||||
|
Response[0] = 0;
|
||||||
|
while(!(Response[0] & MMC_R0_READY_FOR_DATA)
|
||||||
|
&& (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
|
||||||
|
&& Timeout--) {
|
||||||
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
|
||||||
|
if (Response[0] & MMC_R0_READY_FOR_DATA) {
|
||||||
|
break; // Prevents delay once finished
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BufferSize > This->Media->BlockSize) {
|
||||||
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_BLKIO, "%a(): Error and Status:%r\n", __func__, Status));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcTransferState\n"));
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
MmcIoBlocks (
|
MmcIoBlocks (
|
||||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||||
|
@ -145,6 +235,7 @@ MmcIoBlocks (
|
||||||
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
||||||
UINTN BytesRemainingToBeTransfered;
|
UINTN BytesRemainingToBeTransfered;
|
||||||
UINTN BlockCount;
|
UINTN BlockCount;
|
||||||
|
UINTN ConsumeSize;
|
||||||
|
|
||||||
BlockCount = 1;
|
BlockCount = 1;
|
||||||
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
||||||
|
@ -165,6 +256,10 @@ MmcIoBlocks (
|
||||||
return EFI_NO_MEDIA;
|
return EFI_NO_MEDIA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MMC_HOST_HAS_ISMULTIBLOCK(MmcHost) && MmcHost->IsMultiBlock(MmcHost)) {
|
||||||
|
BlockCount = (BufferSize + This->Media->BlockSize - 1) / This->Media->BlockSize;
|
||||||
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
|
@ -210,75 +305,38 @@ MmcIoBlocks (
|
||||||
return EFI_NOT_READY;
|
return EFI_NOT_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set command argument based on the card access mode (Byte mode or Block mode)
|
|
||||||
if (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1) {
|
|
||||||
CmdArg = Lba;
|
|
||||||
} else {
|
|
||||||
CmdArg = Lba * This->Media->BlockSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Transfer == MMC_IOBLOCKS_READ) {
|
if (Transfer == MMC_IOBLOCKS_READ) {
|
||||||
// Read a single block
|
if (BlockCount == 1) {
|
||||||
Cmd = MMC_CMD17;
|
// Read a single block
|
||||||
} else {
|
Cmd = MMC_CMD17;
|
||||||
// Write a single block
|
} else {
|
||||||
Cmd = MMC_CMD24;
|
// Read multiple blocks
|
||||||
}
|
Cmd = MMC_CMD18;
|
||||||
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIoBlocks(MMC_CMD%d): Error %r\n", Cmd, Status));
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Transfer == MMC_IOBLOCKS_READ) {
|
|
||||||
// Read one block of Data
|
|
||||||
Status = MmcHost->ReadBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Read Block Data and Status = %r\n", Status));
|
|
||||||
MmcStopTransmission (MmcHost);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcProgrammingState\n"));
|
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Write one block of Data
|
if (BlockCount == 1) {
|
||||||
Status = MmcHost->WriteBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
// Write a single block
|
||||||
if (EFI_ERROR (Status)) {
|
Cmd = MMC_CMD24;
|
||||||
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Write Block Data and Status = %r\n", Status));
|
} else {
|
||||||
MmcStopTransmission (MmcHost);
|
// Write multiple blocks
|
||||||
return Status;
|
Cmd = MMC_CMD25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command 13 - Read status and wait for programming to complete (return to tran)
|
ConsumeSize = BlockCount * This->Media->BlockSize;
|
||||||
Timeout = MMCI0_TIMEOUT;
|
if (BytesRemainingToBeTransfered < ConsumeSize) {
|
||||||
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
ConsumeSize = BytesRemainingToBeTransfered;
|
||||||
Response[0] = 0;
|
|
||||||
while( (!(Response[0] & MMC_R0_READY_FOR_DATA))
|
|
||||||
&& (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
|
|
||||||
&& Timeout--) {
|
|
||||||
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
|
||||||
if (!EFI_ERROR (Status)) {
|
|
||||||
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
|
|
||||||
if ((Response[0] & MMC_R0_READY_FOR_DATA)) {
|
|
||||||
break; // Prevents delay once finished
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gBS->Stall (1);
|
|
||||||
}
|
}
|
||||||
|
Status = MmcTransferBlock (This, Cmd, Transfer, MediaId, Lba, ConsumeSize, Buffer);
|
||||||
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcTransferState\n"));
|
DEBUG ((EFI_D_ERROR, "%a(): Failed to transfer block and Status:%r\n", __func__, Status));
|
||||||
return Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BytesRemainingToBeTransfered -= This->Media->BlockSize;
|
BytesRemainingToBeTransfered -= ConsumeSize;
|
||||||
Lba += BlockCount;
|
if (BytesRemainingToBeTransfered > 0) {
|
||||||
Buffer = (UINT8 *)Buffer + This->Media->BlockSize;
|
Lba += BlockCount;
|
||||||
|
Buffer = (UINT8 *)Buffer + ConsumeSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue