From: tien.hock.loh@intel.com
To: edk2-devel@lists.01.org, leif.lindholm@linaro.org,
ard.biesheuvel@linaro.org, thloh85@gmail.com
Subject: [PATCH 3/4] EmbeddedPkg/DwEmmc: Fix DMA transfer length
Date: Fri, 22 Feb 2019 16:06:09 +0800 [thread overview]
Message-ID: <1550822770-6159-4-git-send-email-tien.hock.loh@intel.com> (raw)
In-Reply-To: <1550822770-6159-1-git-send-email-tien.hock.loh@intel.com>
From: "Loh, Tien Hock" <tien.hock.loh@intel.com>
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 <tien.hock.loh@intel.com>
---
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
next prev parent reply other threads:[~2019-02-22 8:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-22 8:06 [PATCH 0/4] EmbeddedPkg/DwEmmc: Fix bugs causing DwEmmc to fail to initialize tien.hock.loh
2019-02-22 8:06 ` [PATCH 1/4] EmbeddedPkg/DwEmmc: Remove unnecessary MicroSecondDelay tien.hock.loh
2019-02-22 8:06 ` [PATCH 2/4] EmbeddedPkg/DwEmmc: Fix SendCommand parameters tien.hock.loh
2019-02-22 8:06 ` tien.hock.loh [this message]
2019-02-22 8:06 ` [PATCH 4/4] EmbeddedPkg/DwEmmc: Check DMA completion in SendCommand tien.hock.loh
-- strict thread matches above, loose matches on Subject: below --
2019-02-22 7:52 [PATCH 0/4] EmbeddedPkg/DwEmmc: Fix bugs causing DwEmmc to fail to initialize tien.hock.loh
2019-02-22 7:52 ` [PATCH 3/4] EmbeddedPkg/DwEmmc: Fix DMA transfer length tien.hock.loh
2018-10-25 5:52 [PATCH 0/4] EmbeddedPkg/DwEmmc: Fix bugs causing DwEmmc to fail to initialize tien.hock.loh
2018-10-25 5:52 ` [PATCH 3/4] EmbeddedPkg/DwEmmc: Fix DMA transfer length tien.hock.loh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1550822770-6159-4-git-send-email-tien.hock.loh@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox