From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-x22b.google.com (mail-io0-x22b.google.com [IPv6:2607:f8b0:4001:c06::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F269E81D6A for ; Wed, 23 Nov 2016 01:01:27 -0800 (PST) Received: by mail-io0-x22b.google.com with SMTP id j65so13012666iof.0 for ; Wed, 23 Nov 2016 01:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=eTbW91AEbKr77XVgSCi0/AmERkSMP/NfClOAB5AXNko=; b=dPyH6yIkROUFvHdMDfQ7j2Umd6yHHjcOwAAlZJv0QhpsvsDhoS4DsHXQxSXB5Bf59H gUDflRH9MEAztttssoPv37hKljcxBIOnoAbbuje1aFIOl8E3g1UAwTxC/bOJPEG8N0Td lnUiG9yzMJ8VkSSv+JkCKlfpnlH9Ajt1/IAq0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=eTbW91AEbKr77XVgSCi0/AmERkSMP/NfClOAB5AXNko=; b=XBv5npr20pgAvCc+qvIkB5I9AsuvXlaH6/52XjDrE6cqGDU8zm++BtwaQKdlFyEYW1 Jgc1b8bsLrMSeLUsqh6t2NVOIKyAEb+rjQ6M8OMQAYP1UwQDsMYweaNDec481jd6g2pN sqp2ygMUZ4Csc2XF9/+zq4Wn1nMHbmSbeDqaP+z0cG/Cco5SsEXgZY2678cavT7A9019 fWxlsQWumGa/3aKU5dbv/bK+Hsd6CULqT00fpGW/H5/xZsfKIVoI/xUrsNpFLs2moAjv gNFdGHtoVsDHWj2La1PX0kXOSOmmg7ClQr8ulZFuQU6rZW8VR7Gul3fYq/chzk7z4RAF 8xXQ== X-Gm-Message-State: AKaTC01gek4CEMvyA7Bg+SpwKOyDmtUuXX3TZXIF+CsgGI+rcYDYEz3rKW4Jt4gb7SkVBpxymOV7ATP4UipkXpeT X-Received: by 10.107.2.8 with SMTP id 8mr1974897ioc.83.1479891687207; Wed, 23 Nov 2016 01:01:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.59.147 with HTTP; Wed, 23 Nov 2016 01:01:26 -0800 (PST) In-Reply-To: <1479884921-25398-5-git-send-email-haojian.zhuang@linaro.org> References: <1479884921-25398-1-git-send-email-haojian.zhuang@linaro.org> <1479884921-25398-5-git-send-email-haojian.zhuang@linaro.org> From: Ard Biesheuvel Date: Wed, 23 Nov 2016 09:01:26 +0000 Message-ID: To: Haojian Zhuang Cc: Ryan Harkin , edk2-devel-01 , Leif Lindholm Subject: Re: [PATCH v7 4/4] MmcDxe: expand to support multiple blocks X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Nov 2016 09:01:28 -0000 Content-Type: text/plain; charset=UTF-8 On 23 November 2016 at 07:08, Haojian Zhuang wrote: > 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 > Tested-by: Ryan Harkin > --- > EmbeddedPkg/Include/Protocol/MmcHost.h | 10 +- > EmbeddedPkg/Universal/MmcDxe/Mmc.h | 4 + > EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 176 ++++++++++++++++++++---------- > 3 files changed, 130 insertions(+), 60 deletions(-) > > diff --git a/EmbeddedPkg/Include/Protocol/MmcHost.h b/EmbeddedPkg/Include/Protocol/MmcHost.h > index 445e53f..8c8c8a7 100644 > --- a/EmbeddedPkg/Include/Protocol/MmcHost.h > +++ b/EmbeddedPkg/Include/Protocol/MmcHost.h > @@ -62,6 +62,7 @@ typedef UINT32 MMC_CMD; > #define MMC_CMD20 (MMC_INDX(20) | MMC_CMD_WAIT_RESPONSE) > #define MMC_CMD23 (MMC_INDX(23) | MMC_CMD_WAIT_RESPONSE) > #define MMC_CMD24 (MMC_INDX(24) | MMC_CMD_WAIT_RESPONSE) > +#define MMC_CMD25 (MMC_INDX(25) | MMC_CMD_WAIT_RESPONSE) > #define MMC_CMD55 (MMC_INDX(55) | MMC_CMD_WAIT_RESPONSE) > #define MMC_ACMD41 (MMC_INDX(41) | MMC_CMD_WAIT_RESPONSE | MMC_CMD_NO_CRC_RESPONSE) > #define MMC_ACMD51 (MMC_INDX(51) | MMC_CMD_WAIT_RESPONSE) > @@ -152,6 +153,10 @@ typedef EFI_STATUS (EFIAPI *MMC_SETIOS) ( > IN UINT32 TimingMode > ); > > +typedef BOOLEAN (EFIAPI *MMC_ISMULTIBLOCK) ( > + IN EFI_MMC_HOST_PROTOCOL *This > + ); > + > > struct _EFI_MMC_HOST_PROTOCOL { > > @@ -169,13 +174,16 @@ struct _EFI_MMC_HOST_PROTOCOL { > MMC_WRITEBLOCKDATA WriteBlockData; > > MMC_SETIOS SetIos; > + MMC_ISMULTIBLOCK IsMultiBlock; > > }; > > -#define MMC_HOST_PROTOCOL_REVISION 0x00010002 // 1.2 > +#define MMC_HOST_PROTOCOL_REVISION 0x00010003 // 1.3 > > #define MMC_HOST_HAS_SETIOS(Host) (Host->Revision >= MMC_HOST_PROTOCOL_REVISION && \ > Host->SetIos != NULL) > +#define MMC_HOST_HAS_ISMULTIBLOCK(Host) (Host->Revision >= MMC_HOST_PROTOCOL_REVISION && \ > + Host->IsMultiBlock != NULL) > > extern EFI_GUID gEfiMmcHostProtocolGuid; > Please move this part into the new, separate patch I suggested in 1/4. That way, we can keep the version at 1.2. Could you please also add a comment next to the new methods to show that they were added in revision 1.2? > diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.h b/EmbeddedPkg/Universal/MmcDxe/Mmc.h > index 6bc85e0..8e7a80a 100644 > --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.h > +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.h > @@ -34,6 +34,10 @@ > > #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_TRANSPEED(Response) (Response[3] & 0xFF) > #define MMC_CSD_GET_READBLLEN(Response) ((Response[2] >> 16) & 0xF) > diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c > index 0e1ef57..35570fd 100644 > --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c > +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c > @@ -126,6 +126,96 @@ MmcStopTransmission ( > #define MMCI0_BLOCKLEN 512 > #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 > MmcIoBlocks ( > IN EFI_BLOCK_IO_PROTOCOL *This, > @@ -145,6 +235,7 @@ MmcIoBlocks ( > EFI_MMC_HOST_PROTOCOL *MmcHost; > UINTN BytesRemainingToBeTransfered; > UINTN BlockCount; > + UINTN ConsumeSize; > > BlockCount = 1; > MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This); > @@ -165,6 +256,10 @@ MmcIoBlocks ( > return EFI_NO_MEDIA; > } > > + if (MmcHost->IsMultiBlock && MmcHost->IsMultiBlock(MmcHost)) { Shouldn't you use the macro here? > + BlockCount = (BufferSize + This->Media->BlockSize - 1) / This->Media->BlockSize; > + } > + > // All blocks must be within the device > if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)) { > return EFI_INVALID_PARAMETER; > @@ -210,75 +305,38 @@ MmcIoBlocks ( > 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) { > - // Read a single block > - Cmd = MMC_CMD17; > - } else { > - // Write a single block > - Cmd = MMC_CMD24; > - } > - 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; > + if (BlockCount == 1) { > + // Read a single block > + Cmd = MMC_CMD17; > + } else { > + // Read multiple blocks > + Cmd = MMC_CMD18; > } > } else { > - // Write one block of Data > - Status = MmcHost->WriteBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer); > - if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Write Block Data and Status = %r\n", Status)); > - MmcStopTransmission (MmcHost); > - return Status; > + if (BlockCount == 1) { > + // Write a single block > + Cmd = MMC_CMD24; > + } else { > + // Write multiple blocks > + Cmd = MMC_CMD25; > } > } > > - // 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 > - } > - } > - gBS->Stall (1); > + ConsumeSize = BlockCount * This->Media->BlockSize; > + if (BytesRemainingToBeTransfered < ConsumeSize) { > + ConsumeSize = BytesRemainingToBeTransfered; > } > - > - Status = MmcNotifyState (MmcHostInstance, MmcTransferState); > + Status = MmcTransferBlock (This, Cmd, Transfer, MediaId, Lba, ConsumeSize, Buffer); > if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcTransferState\n")); > - return Status; > + DEBUG ((EFI_D_ERROR, "%a(): Failed to transfer block and Status:%r\n", __func__, Status)); > } > > - BytesRemainingToBeTransfered -= This->Media->BlockSize; > - Lba += BlockCount; > - Buffer = (UINT8 *)Buffer + This->Media->BlockSize; > + BytesRemainingToBeTransfered -= ConsumeSize; > + if (BytesRemainingToBeTransfered > 0) { > + Lba += BlockCount; > + Buffer = (UINT8 *)Buffer + ConsumeSize; > + } > } > > return EFI_SUCCESS; > -- > 2.7.4 >