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 AAE65208AE35F for ; Fri, 22 Feb 2019 00:06:40 -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:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,398,1544515200"; d="scan'208";a="146374628" Received: from pg-iccf0308.altera.com ([10.104.2.61]) by fmsmga004.fm.intel.com with ESMTP; 22 Feb 2019 00:06:38 -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:09 +0800 Message-Id: <1550822770-6159-4-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 3/4] EmbeddedPkg/DwEmmc: Fix DMA transfer length 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:40 -0000 From: "Loh, Tien Hock" DMA should not transfer more than requested length otherwise FIFO might run into buffer underrun and causes errors in future transfers. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Loh Tien Hock --- EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c index 600ab01..c232309 100644 --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c @@ -496,7 +496,13 @@ PrepareDmaData ( Cnt = (Length + DWEMMC_DMA_BUF_SIZE - 1) / DWEMMC_DMA_BUF_SIZE; Blks = (Length + DWEMMC_BLOCK_SIZE - 1) / DWEMMC_BLOCK_SIZE; - Length = DWEMMC_BLOCK_SIZE * Blks; + + if(Length < DWEMMC_BLOCK_SIZE) { + Length = Length; + } + else { + Length = DWEMMC_BLOCK_SIZE * Blks; + } for (Idx = 0; Idx < Cnt; Idx++) { (IdmacDesc + Idx)->Des0 = DWEMMC_IDMAC_DES0_OWN | DWEMMC_IDMAC_DES0_CH | @@ -534,11 +540,18 @@ StartDma ( Data |= DWEMMC_CTRL_INT_EN | DWEMMC_CTRL_DMA_EN | DWEMMC_CTRL_IDMAC_EN; MmioWrite32 (DWEMMC_CTRL, Data); Data = MmioRead32 (DWEMMC_BMOD); + Data |= DWEMMC_IDMAC_ENABLE | DWEMMC_IDMAC_FB; MmioWrite32 (DWEMMC_BMOD, Data); - MmioWrite32 (DWEMMC_BLKSIZ, DWEMMC_BLOCK_SIZE); - MmioWrite32 (DWEMMC_BYTCNT, Length); + if(Length < DWEMMC_BLOCK_SIZE) { + MmioWrite32 (DWEMMC_BLKSIZ, Length); + MmioWrite32 (DWEMMC_BYTCNT, Length); + } + else { + MmioWrite32 (DWEMMC_BLKSIZ, DWEMMC_BLOCK_SIZE); + MmioWrite32 (DWEMMC_BYTCNT, Length); + } } EFI_STATUS -- 2.2.2