From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.65; helo=mga03.intel.com; envelope-from=tien.hock.loh@intel.com; receiver=edk2-devel@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 396CC208AE35F for ; Fri, 22 Feb 2019 00:06:43 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Feb 2019 00:06:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,398,1544515200"; d="scan'208";a="146374640" Received: from pg-iccf0308.altera.com ([10.104.2.61]) by fmsmga004.fm.intel.com with ESMTP; 22 Feb 2019 00:06:40 -0800 From: tien.hock.loh@intel.com To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, thloh85@gmail.com Date: Fri, 22 Feb 2019 16:06:10 +0800 Message-Id: <1550822770-6159-5-git-send-email-tien.hock.loh@intel.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1550822770-6159-1-git-send-email-tien.hock.loh@intel.com> References: <1550822770-6159-1-git-send-email-tien.hock.loh@intel.com> Subject: [PATCH 4/4] EmbeddedPkg/DwEmmc: Check DMA completion in SendCommand X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Feb 2019 08:06:43 -0000 From: "Tien Hock, Loh" DwEmmcReadBlockData and DwEmmcWriteBlockData needs to check for the transfer completion before returning. This also adds error checking to the DMA transfer. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Tien Hock, Loh --- EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c | 36 +++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c index c232309..c13cd97 100644 --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c @@ -212,6 +212,7 @@ DwEmmcNotifyState ( MmioWrite32 (DWEMMC_TMOUT, ~0); MmioWrite32 (DWEMMC_IDINTEN, 0); MmioWrite32 (DWEMMC_BMOD, DWEMMC_IDMAC_SWRESET); + MmioWrite32 (DWEMMC_CTYPE, 0); MmioWrite32 (DWEMMC_BLKSIZ, DWEMMC_BLOCK_SIZE); do { @@ -497,10 +498,7 @@ PrepareDmaData ( Cnt = (Length + DWEMMC_DMA_BUF_SIZE - 1) / DWEMMC_DMA_BUF_SIZE; Blks = (Length + DWEMMC_BLOCK_SIZE - 1) / DWEMMC_BLOCK_SIZE; - if(Length < DWEMMC_BLOCK_SIZE) { - Length = Length; - } - else { + if(Length >= DWEMMC_BLOCK_SIZE) { Length = DWEMMC_BLOCK_SIZE * Blks; } @@ -563,8 +561,9 @@ DwEmmcReadBlockData ( ) { EFI_STATUS Status; - UINT32 DescPages, CountPerPage, Count; + UINT32 DescPages, CountPerPage, Count, ErrMask; EFI_TPL Tpl; + UINTN Rintsts = 0; Tpl = gBS->RaiseTPL (TPL_NOTIFY); @@ -587,6 +586,18 @@ DwEmmcReadBlockData ( DEBUG ((DEBUG_ERROR, "Failed to read data, mDwEmmcCommand:%x, mDwEmmcArgument:%x, Status:%r\n", mDwEmmcCommand, mDwEmmcArgument, Status)); goto out; } + + while(!((MmioRead32(DWEMMC_RINTSTS) & (DWEMMC_INT_DTO)))) { + Rintsts = MmioRead32 (DWEMMC_RINTSTS); + } + ErrMask = DWEMMC_INT_EBE | DWEMMC_INT_HLE | DWEMMC_INT_RTO | + DWEMMC_INT_RCRC | DWEMMC_INT_RE | DWEMMC_INT_DCRC | + DWEMMC_INT_DRT | DWEMMC_INT_SBE; + + if (Rintsts & ErrMask) { + Status = EFI_DEVICE_ERROR; + goto out; + } out: // Restore Tpl gBS->RestoreTPL (Tpl); @@ -602,8 +613,9 @@ DwEmmcWriteBlockData ( ) { EFI_STATUS Status; - UINT32 DescPages, CountPerPage, Count; + UINT32 DescPages, CountPerPage, Count, ErrMask; EFI_TPL Tpl; + UINTN Rintsts = 0; Tpl = gBS->RaiseTPL (TPL_NOTIFY); @@ -626,6 +638,18 @@ DwEmmcWriteBlockData ( DEBUG ((DEBUG_ERROR, "Failed to write data, mDwEmmcCommand:%x, mDwEmmcArgument:%x, Status:%r\n", mDwEmmcCommand, mDwEmmcArgument, Status)); goto out; } + + while(!((MmioRead32(DWEMMC_RINTSTS) & (DWEMMC_INT_DTO)))) { + Rintsts = MmioRead32 (DWEMMC_RINTSTS); + } + ErrMask = DWEMMC_INT_EBE | DWEMMC_INT_HLE | DWEMMC_INT_RTO | + DWEMMC_INT_RCRC | DWEMMC_INT_RE | DWEMMC_INT_DCRC | + DWEMMC_INT_DRT | DWEMMC_INT_SBE; + + if (Rintsts & ErrMask) { + Status = EFI_DEVICE_ERROR; + goto out; + } out: // Restore Tpl gBS->RestoreTPL (Tpl); -- 2.2.2