Hi Eddie,

    We should only need to do only one time cache operation for a buffer

ready to do DMA transfer, so you need to remove another cache invalidate

operation for the same buffer in the same function.


Thanks,
- Kever
On 04/01/2017 02:51 PM, Eddie Cai wrote:
We should invalidate the dcache before starting the DMA. In case there are
any dirty lines from the DMA buffer in the cache, subsequent cache-line
replacements may corrupt the buffer in memory while the DMA is still going on.
Cache-line replacement can happen if the CPU tries to bring some other memory
locations into the cache while the DMA is going on.

Signed-off-by: Eddie Cai <[email protected]>
---
  drivers/usb/host/dwc2.c | 17 +++++++++++------
  1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 5ac602e..a151ba6 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -811,12 +811,17 @@ static int transfer_chunk(struct dwc2_hc_regs *hc_regs, 
void *aligned_buffer,
               (*pid << DWC2_HCTSIZ_PID_OFFSET),
               &hc_regs->hctsiz);
- if (!in && xfer_len) {
-               memcpy(aligned_buffer, buffer, xfer_len);
-
-               flush_dcache_range((unsigned long)aligned_buffer,
-                                  (unsigned long)aligned_buffer +
-                                  roundup(xfer_len, ARCH_DMA_MINALIGN));
+       if (xfer_len) {
+               if(in){
+                       invalidate_dcache_range((unsigned long)aligned_buffer,
+                                          (unsigned long)aligned_buffer +
+                                          roundup(xfer_len, 
ARCH_DMA_MINALIGN));
+               }else{
+                       memcpy(aligned_buffer, buffer, xfer_len);
+                       flush_dcache_range((unsigned long)aligned_buffer,
+                                          (unsigned long)aligned_buffer +
+                                          roundup(xfer_len, 
ARCH_DMA_MINALIGN));
+               }
        }
writel(phys_to_bus((unsigned long)aligned_buffer), &hc_regs->hcdma);


_______________________________________________
U-Boot mailing list
[email protected]
https://lists.denx.de/listinfo/u-boot

Reply via email to