From patchwork Fri Feb 26 09:27:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 62980 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp608680lbc; Fri, 26 Feb 2016 01:28:55 -0800 (PST) X-Received: by 10.66.191.104 with SMTP id gx8mr633638pac.21.1456478935402; Fri, 26 Feb 2016 01:28:55 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id l84si18770786pfb.158.2016.02.26.01.28.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Feb 2016 01:28:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 56DD51A1E23; Fri, 26 Feb 2016 01:28:59 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-ob0-x22a.google.com (mail-ob0-x22a.google.com [IPv6:2607:f8b0:4003:c01::22a]) (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 77FD21A1E0D for ; Fri, 26 Feb 2016 01:28:58 -0800 (PST) Received: by mail-ob0-x22a.google.com with SMTP id s6so23139410obg.3 for ; Fri, 26 Feb 2016 01:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:from:to:cc:subject:date:in-reply-to:references :mime-version; bh=LiO91fZNmeZGU7//CX55rPpmoSxRZwFzZWo4mee3/ik=; b=aVTX551IbypBloEOkAr0+VSvNuVezRmGyJNKOEpIXW7pUnzXLFJ1nbpvImBWMhUeAb UmacwdyW/o1FEFjys9bWHzh9D8uCxVLIfBFLuhu8i2aoW4XqoKhrCvFAtv12dfyutgLq Eu7MX308iYN+FAbBlHU+LlNLwvdEFZTuprd9o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date:in-reply-to :references:mime-version; bh=LiO91fZNmeZGU7//CX55rPpmoSxRZwFzZWo4mee3/ik=; b=adhNAOUo5r9YcY9cfB8o+5rFL9IRShbbqnNnEFPW3rciqyzFw3dNA5yAQ2l3t5nxfA 9QZwKs0Mdi6taA4UxfqATyWfUE3oNwImzCdPUWIWdPz8unQVqjwPrS38ytb/2HzPbB62 jHfYWf9rrgvJ0BcPIV08IGDIFy4mxehuR7FuATy+I4UHicw3t60zX1GQQ/XhrV/EEjf3 m59IeNaXYFH+85MutCq0I8rRm/vtQMmTYs+C1er9fb9SI1UOb9EFJqVjt7ukuRWQcVHd JzHPe7XqaY8VJI/O8c+T9ii7XsUhtbFoIp/5MqOON58o3a2Jq56wdP6I9maYJI/jn+AT yx7Q== X-Gm-Message-State: AD7BkJJWxWSVLhOa1C1R69NUWAJK5gbzJ+xWaA5OJalmlPNSeloIU8Lb8y174cenNiNPCCYU X-Received: by 10.60.82.229 with SMTP id l5mr387897oey.6.1456478932972; Fri, 26 Feb 2016 01:28:52 -0800 (PST) Received: from mail.hotmail.com (blu004-wss1s6.hotmail.com. [134.170.2.221]) by smtp.gmail.com with ESMTPSA id x144sm8191561oif.23.2016.02.26.01.28.51 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Feb 2016 01:28:51 -0800 (PST) Received: from BLU437-SMTP102 ([134.170.2.215]) by BLU004-WSS1S6.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Fri, 26 Feb 2016 01:28:51 -0800 X-TMN: [6zP3GiLO1/jcPRy3Mr+hEDc9jBemsYMN] Message-ID: From: Haojian Zhuang To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org Date: Fri, 26 Feb 2016 17:27:56 +0800 X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456478876-23434-1-git-send-email-haojian.zhuang@linaro.org> References: <1456478876-23434-1-git-send-email-haojian.zhuang@linaro.org> X-OriginalArrivalTime: 26 Feb 2016 09:28:48.0924 (UTC) FILETIME=[190EC5C0:01D17078] MIME-Version: 1.0 Cc: Haojian Zhuang Subject: [edk2] [PATCH 9/9] MmcDxe: expand to support multiple blocks X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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 --- EmbeddedPkg/Include/Protocol/MmcHost.h | 6 + EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 175 ++++++++++++++++++++---------- 2 files changed, 122 insertions(+), 59 deletions(-) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/EmbeddedPkg/Include/Protocol/MmcHost.h b/EmbeddedPkg/Include/Protocol/MmcHost.h index ce0a024..f11fca7 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_CMD51 (MMC_INDX(51) | 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) @@ -150,6 +151,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 { @@ -167,6 +172,7 @@ struct _EFI_MMC_HOST_PROTOCOL { MMC_WRITEBLOCKDATA WriteBlockData; MMC_SETIOS SetIos; + MMC_ISMULTIBLOCK IsMultiBlock; }; diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c index 0e1ef57..3bfae08 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c @@ -126,6 +126,95 @@ 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 & BIT1) { + 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 + } + } + gBS->Stall (1); + } + + 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 +234,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 +255,10 @@ MmcIoBlocks ( return EFI_NO_MEDIA; } + if (MmcHost->IsMultiBlock && MmcHost->IsMultiBlock(MmcHost)) { + 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 +304,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;