diff mbox series

[edk2,v3,2/2] EmbeddedPkg/DwEmmc: Adjust FIFO threshold

Message ID 1499419297-18886-1-git-send-email-jun.nie@linaro.org
State Accepted
Commit a58bfb37f63a9c16e37c39a48b273ce69194f281
Headers show
Series None | expand

Commit Message

Jun Nie July 7, 2017, 9:21 a.m. UTC
Adjust FIFO threshold according to FIFO depth. Skip
the adjustment if we do not have FIFO depth info.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jun Nie <jun.nie@linaro.org>

---
 EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h      |  6 +++++
 EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c   | 42 +++++++++++++++++++++++++++++
 EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf |  1 +
 EmbeddedPkg/EmbeddedPkg.dec                 |  1 +
 4 files changed, 50 insertions(+)

-- 
1.9.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Haojian Zhuang July 17, 2017, 1:41 a.m. UTC | #1
On 7 July 2017 at 17:21, Jun Nie <jun.nie@linaro.org> wrote:
> Adjust FIFO threshold according to FIFO depth. Skip

> the adjustment if we do not have FIFO depth info.

>

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Jun Nie <jun.nie@linaro.org>

> ---

>  EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h      |  6 +++++

>  EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c   | 42 +++++++++++++++++++++++++++++

>  EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf |  1 +

>  EmbeddedPkg/EmbeddedPkg.dec                 |  1 +

>  4 files changed, 50 insertions(+)

>

> diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h

> index 055f1e0..90c7676 100644

> --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h

> +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h

> @@ -38,7 +38,10 @@

>  #define DWEMMC_RINTSTS          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x044)

>  #define DWEMMC_STATUS           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x048)

>  #define DWEMMC_FIFOTH           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x04c)

> +#define DWEMMC_TCBCNT           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x05c)

> +#define DWEMMC_TBBCNT           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x060)

>  #define DWEMMC_DEBNCE           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x064)

> +#define DWEMMC_HCON             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x070)

>  #define DWEMMC_UHSREG           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x074)

>  #define DWEMMC_BMOD             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x080)

>  #define DWEMMC_DBADDR           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x088)

> @@ -47,6 +50,7 @@

>  #define DWEMMC_DSCADDR          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x094)

>  #define DWEMMC_BUFADDR          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x098)

>  #define DWEMMC_CARDTHRCTL       ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X100)

> +#define DWEMMC_DATA             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X200)

>

>  #define CMD_UPDATE_CLK                          0x80202000

>  #define CMD_START_BIT                           (1 << 31)

> @@ -124,4 +128,6 @@

>  #define DWEMMC_CARD_RD_THR(x)                   ((x & 0xfff) << 16)

>  #define DWEMMC_CARD_RD_THR_EN                   (1 << 0)

>

> +#define DWEMMC_GET_HDATA_WIDTH(x)               (((x) >> 7) & 0x7)

> +

>  #endif  // __DWEMMC_H__

> diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c

> index bb26b69..bd20f4b 100644

> --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c

> +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c

> @@ -415,6 +415,47 @@ DwEmmcReceiveResponse (

>    return EFI_SUCCESS;

>  }

>

> +VOID

> +DwEmmcAdjustFifothresholdreshold (

> +  VOID

> +  )

> +{

> +  /* DMA multiple transaction size map to reg value as array index */

> +  CONST UINT32 BurstSize[] = {1, 4, 8, 16, 32, 64, 128, 256};

> +  UINT32 BlkDepthInFifo, Fifothreshold, FifoWidth, FifoDepth;

> +  UINT32 BlkSize = DWEMMC_BLOCK_SIZE, Idx = 0, RxWatermark = 1, TxWatermark, TxWatermarkInvers;

> +

> +  /* Skip FIFO adjustment if we do not have platform FIFO depth info */

> +  FifoDepth = PcdGet32 (PcdDwEmmcDxeFifoDepth);

> +  if (!FifoDepth) {

> +    return;

> +  }

> +

> +  TxWatermark = FifoDepth / 2;

> +  TxWatermarkInvers = FifoDepth - TxWatermark;

> +

> +  FifoWidth = DWEMMC_GET_HDATA_WIDTH (MmioRead32 (DWEMMC_HCON));

> +  if (!FifoWidth) {

> +    FifoWidth = 2;

> +  } else if (FifoWidth == 2) {

> +    FifoWidth = 8;

> +  } else {

> +    FifoWidth = 4;

> +  }

> +

> +  BlkDepthInFifo = BlkSize / FifoWidth;

> +

> +  Idx = ARRAY_SIZE (BurstSize) - 1;

> +  while (Idx && ((BlkDepthInFifo % BurstSize[Idx]) || (TxWatermarkInvers % BurstSize[Idx]))) {

> +    Idx--;

> +  }

> +

> +  RxWatermark = BurstSize[Idx] - 1;

> +  Fifothreshold = DWEMMC_DMA_BURST_SIZE (Idx) | DWEMMC_FIFO_TWMARK (TxWatermark)

> +           | DWEMMC_FIFO_RWMARK (RxWatermark);

> +  MmioWrite32 (DWEMMC_FIFOTH, Fifothreshold);

> +}

> +

>  EFI_STATUS

>  PrepareDmaData (

>    IN DWEMMC_IDMAC_DESCRIPTOR*    IdmacDesc,

> @@ -633,6 +674,7 @@ DwEmmcDxeInitialize (

>

>    Handle = NULL;

>

> +  DwEmmcAdjustFifothresholdreshold ();

>    gpIdmacDesc = (DWEMMC_IDMAC_DESCRIPTOR *)AllocatePages (DWEMMC_MAX_DESC_PAGES);

>    if (gpIdmacDesc == NULL) {

>      return EFI_BUFFER_TOO_SMALL;

> diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf

> index 99b4f99..bc4413e 100644

> --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf

> +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf

> @@ -49,6 +49,7 @@

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz

> +  gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth

>

>  [Depex]

>    TRUE

> diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec

> index 3cb30a4..4cd528a 100644

> --- a/EmbeddedPkg/EmbeddedPkg.dec

> +++ b/EmbeddedPkg/EmbeddedPkg.dec

> @@ -168,6 +168,7 @@

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress|0x0|UINT32|0x00000035

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz|0x0|UINT32|0x00000036

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz|0x0|UINT32|0x00000037

> +  gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth|0x0|UINT32|0x00000038

>

>    #

>    # Android FastBoot

> --

> 1.9.1

>


Acked-by: Haojian Zhuang <haojian.zhuang@linaro.org>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Leif Lindholm July 17, 2017, 4:55 p.m. UTC | #2
On Fri, Jul 07, 2017 at 05:21:37PM +0800, Jun Nie wrote:
> Adjust FIFO threshold according to FIFO depth. Skip

> the adjustment if we do not have FIFO depth info.

> 

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Jun Nie <jun.nie@linaro.org>

> ---

>  EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h      |  6 +++++

>  EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c   | 42 +++++++++++++++++++++++++++++

>  EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf |  1 +

>  EmbeddedPkg/EmbeddedPkg.dec                 |  1 +

>  4 files changed, 50 insertions(+)

> 

> diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h

> index 055f1e0..90c7676 100644

> --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h

> +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h

> @@ -38,7 +38,10 @@

>  #define DWEMMC_RINTSTS          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x044)

>  #define DWEMMC_STATUS           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x048)

>  #define DWEMMC_FIFOTH           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x04c)

> +#define DWEMMC_TCBCNT           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x05c)

> +#define DWEMMC_TBBCNT           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x060)

>  #define DWEMMC_DEBNCE           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x064)

> +#define DWEMMC_HCON             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x070)

>  #define DWEMMC_UHSREG           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x074)

>  #define DWEMMC_BMOD             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x080)

>  #define DWEMMC_DBADDR           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x088)

> @@ -47,6 +50,7 @@

>  #define DWEMMC_DSCADDR          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x094)

>  #define DWEMMC_BUFADDR          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x098)

>  #define DWEMMC_CARDTHRCTL       ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X100)

> +#define DWEMMC_DATA             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X200)

>  

>  #define CMD_UPDATE_CLK                          0x80202000

>  #define CMD_START_BIT                           (1 << 31)

> @@ -124,4 +128,6 @@

>  #define DWEMMC_CARD_RD_THR(x)                   ((x & 0xfff) << 16)

>  #define DWEMMC_CARD_RD_THR_EN                   (1 << 0)

>  

> +#define DWEMMC_GET_HDATA_WIDTH(x)               (((x) >> 7) & 0x7)

> +

>  #endif  // __DWEMMC_H__

> diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c

> index bb26b69..bd20f4b 100644

> --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c

> +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c

> @@ -415,6 +415,47 @@ DwEmmcReceiveResponse (

>    return EFI_SUCCESS;

>  }

>  

> +VOID

> +DwEmmcAdjustFifothresholdreshold (


Should be ...FifoThreshold (camel case).
Also, looks like some search-and-replace went wrong here.

> +  VOID

> +  )

> +{

> +  /* DMA multiple transaction size map to reg value as array index */

> +  CONST UINT32 BurstSize[] = {1, 4, 8, 16, 32, 64, 128, 256};

> +  UINT32 BlkDepthInFifo, Fifothreshold, FifoWidth, FifoDepth;


Should be FifoThreshold (camel case).

Anyway, I fixed these up before committing.

Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>


Pushed as d4f6c35c84..a58bfb37f6.

/
    Leif

> +  UINT32 BlkSize = DWEMMC_BLOCK_SIZE, Idx = 0, RxWatermark = 1, TxWatermark, TxWatermarkInvers;

> +

> +  /* Skip FIFO adjustment if we do not have platform FIFO depth info */

> +  FifoDepth = PcdGet32 (PcdDwEmmcDxeFifoDepth);

> +  if (!FifoDepth) {

> +    return;

> +  }

> +

> +  TxWatermark = FifoDepth / 2;

> +  TxWatermarkInvers = FifoDepth - TxWatermark;

> +

> +  FifoWidth = DWEMMC_GET_HDATA_WIDTH (MmioRead32 (DWEMMC_HCON));

> +  if (!FifoWidth) {

> +    FifoWidth = 2;

> +  } else if (FifoWidth == 2) {

> +    FifoWidth = 8;

> +  } else {

> +    FifoWidth = 4;

> +  }

> +

> +  BlkDepthInFifo = BlkSize / FifoWidth;

> +

> +  Idx = ARRAY_SIZE (BurstSize) - 1;

> +  while (Idx && ((BlkDepthInFifo % BurstSize[Idx]) || (TxWatermarkInvers % BurstSize[Idx]))) {

> +    Idx--;

> +  }

> +

> +  RxWatermark = BurstSize[Idx] - 1;

> +  Fifothreshold = DWEMMC_DMA_BURST_SIZE (Idx) | DWEMMC_FIFO_TWMARK (TxWatermark)

> +           | DWEMMC_FIFO_RWMARK (RxWatermark);

> +  MmioWrite32 (DWEMMC_FIFOTH, Fifothreshold);

> +}

> +

>  EFI_STATUS

>  PrepareDmaData (

>    IN DWEMMC_IDMAC_DESCRIPTOR*    IdmacDesc,

> @@ -633,6 +674,7 @@ DwEmmcDxeInitialize (

>  

>    Handle = NULL;

>  

> +  DwEmmcAdjustFifothresholdreshold ();

>    gpIdmacDesc = (DWEMMC_IDMAC_DESCRIPTOR *)AllocatePages (DWEMMC_MAX_DESC_PAGES);

>    if (gpIdmacDesc == NULL) {

>      return EFI_BUFFER_TOO_SMALL;

> diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf

> index 99b4f99..bc4413e 100644

> --- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf

> +++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf

> @@ -49,6 +49,7 @@

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz

> +  gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth

>  

>  [Depex]

>    TRUE

> diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec

> index 3cb30a4..4cd528a 100644

> --- a/EmbeddedPkg/EmbeddedPkg.dec

> +++ b/EmbeddedPkg/EmbeddedPkg.dec

> @@ -168,6 +168,7 @@

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress|0x0|UINT32|0x00000035

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz|0x0|UINT32|0x00000036

>    gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz|0x0|UINT32|0x00000037

> +  gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth|0x0|UINT32|0x00000038

>  

>    #

>    # Android FastBoot

> -- 

> 1.9.1

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h
index 055f1e0..90c7676 100644
--- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h
+++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmc.h
@@ -38,7 +38,10 @@ 
 #define DWEMMC_RINTSTS          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x044)
 #define DWEMMC_STATUS           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x048)
 #define DWEMMC_FIFOTH           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x04c)
+#define DWEMMC_TCBCNT           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x05c)
+#define DWEMMC_TBBCNT           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x060)
 #define DWEMMC_DEBNCE           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x064)
+#define DWEMMC_HCON             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x070)
 #define DWEMMC_UHSREG           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x074)
 #define DWEMMC_BMOD             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x080)
 #define DWEMMC_DBADDR           ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x088)
@@ -47,6 +50,7 @@ 
 #define DWEMMC_DSCADDR          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x094)
 #define DWEMMC_BUFADDR          ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0x098)
 #define DWEMMC_CARDTHRCTL       ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X100)
+#define DWEMMC_DATA             ((UINT32)PcdGet32 (PcdDwEmmcDxeBaseAddress) + 0X200)
 
 #define CMD_UPDATE_CLK                          0x80202000
 #define CMD_START_BIT                           (1 << 31)
@@ -124,4 +128,6 @@ 
 #define DWEMMC_CARD_RD_THR(x)                   ((x & 0xfff) << 16)
 #define DWEMMC_CARD_RD_THR_EN                   (1 << 0)
 
+#define DWEMMC_GET_HDATA_WIDTH(x)               (((x) >> 7) & 0x7)
+
 #endif  // __DWEMMC_H__
diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c
index bb26b69..bd20f4b 100644
--- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c
+++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.c
@@ -415,6 +415,47 @@  DwEmmcReceiveResponse (
   return EFI_SUCCESS;
 }
 
+VOID
+DwEmmcAdjustFifothresholdreshold (
+  VOID
+  )
+{
+  /* DMA multiple transaction size map to reg value as array index */
+  CONST UINT32 BurstSize[] = {1, 4, 8, 16, 32, 64, 128, 256};
+  UINT32 BlkDepthInFifo, Fifothreshold, FifoWidth, FifoDepth;
+  UINT32 BlkSize = DWEMMC_BLOCK_SIZE, Idx = 0, RxWatermark = 1, TxWatermark, TxWatermarkInvers;
+
+  /* Skip FIFO adjustment if we do not have platform FIFO depth info */
+  FifoDepth = PcdGet32 (PcdDwEmmcDxeFifoDepth);
+  if (!FifoDepth) {
+    return;
+  }
+
+  TxWatermark = FifoDepth / 2;
+  TxWatermarkInvers = FifoDepth - TxWatermark;
+
+  FifoWidth = DWEMMC_GET_HDATA_WIDTH (MmioRead32 (DWEMMC_HCON));
+  if (!FifoWidth) {
+    FifoWidth = 2;
+  } else if (FifoWidth == 2) {
+    FifoWidth = 8;
+  } else {
+    FifoWidth = 4;
+  }
+
+  BlkDepthInFifo = BlkSize / FifoWidth;
+
+  Idx = ARRAY_SIZE (BurstSize) - 1;
+  while (Idx && ((BlkDepthInFifo % BurstSize[Idx]) || (TxWatermarkInvers % BurstSize[Idx]))) {
+    Idx--;
+  }
+
+  RxWatermark = BurstSize[Idx] - 1;
+  Fifothreshold = DWEMMC_DMA_BURST_SIZE (Idx) | DWEMMC_FIFO_TWMARK (TxWatermark)
+           | DWEMMC_FIFO_RWMARK (RxWatermark);
+  MmioWrite32 (DWEMMC_FIFOTH, Fifothreshold);
+}
+
 EFI_STATUS
 PrepareDmaData (
   IN DWEMMC_IDMAC_DESCRIPTOR*    IdmacDesc,
@@ -633,6 +674,7 @@  DwEmmcDxeInitialize (
 
   Handle = NULL;
 
+  DwEmmcAdjustFifothresholdreshold ();
   gpIdmacDesc = (DWEMMC_IDMAC_DESCRIPTOR *)AllocatePages (DWEMMC_MAX_DESC_PAGES);
   if (gpIdmacDesc == NULL) {
     return EFI_BUFFER_TOO_SMALL;
diff --git a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf
index 99b4f99..bc4413e 100644
--- a/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf
+++ b/EmbeddedPkg/Drivers/DwEmmcDxe/DwEmmcDxe.inf
@@ -49,6 +49,7 @@ 
   gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress
   gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz
   gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz
+  gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth
 
 [Depex]
   TRUE
diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec
index 3cb30a4..4cd528a 100644
--- a/EmbeddedPkg/EmbeddedPkg.dec
+++ b/EmbeddedPkg/EmbeddedPkg.dec
@@ -168,6 +168,7 @@ 
   gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeBaseAddress|0x0|UINT32|0x00000035
   gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeClockFrequencyInHz|0x0|UINT32|0x00000036
   gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeMaxClockFreqInHz|0x0|UINT32|0x00000037
+  gEmbeddedTokenSpaceGuid.PcdDwEmmcDxeFifoDepth|0x0|UINT32|0x00000038
 
   #
   # Android FastBoot