* [U-Boot] [PATH V3] usb: dwc2: invalidate the dcache before starting the DMA
@ 2017-04-06 3:37 Eddie Cai
2017-04-06 15:34 ` Marek Vasut
0 siblings, 1 reply; 2+ messages in thread
From: Eddie Cai @ 2017-04-06 3:37 UTC (permalink / raw)
To: u-boot
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 <eddie.cai.linux@gmail.com>
Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
---
drivers/usb/host/dwc2.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index 5ac602e..f295843 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -811,12 +811,19 @@ 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(
+ (uintptr_t)aligned_buffer,
+ (uintptr_t)aligned_buffer +
+ roundup(xfer_len, ARCH_DMA_MINALIGN));
+ } else {
+ memcpy(aligned_buffer, buffer, xfer_len);
+ flush_dcache_range(
+ (uintptr_t)aligned_buffer,
+ (uintptr_t)aligned_buffer +
+ roundup(xfer_len, ARCH_DMA_MINALIGN));
+ }
}
writel(phys_to_bus((unsigned long)aligned_buffer), &hc_regs->hcdma);
--
2.10.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATH V3] usb: dwc2: invalidate the dcache before starting the DMA
2017-04-06 3:37 [U-Boot] [PATH V3] usb: dwc2: invalidate the dcache before starting the DMA Eddie Cai
@ 2017-04-06 15:34 ` Marek Vasut
0 siblings, 0 replies; 2+ messages in thread
From: Marek Vasut @ 2017-04-06 15:34 UTC (permalink / raw)
To: u-boot
On 04/06/2017 05:37 AM, 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 <eddie.cai.linux@gmail.com>
> Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
Applied, thanks.
--
Best regards,
Marek Vasut
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-04-06 15:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-06 3:37 [U-Boot] [PATH V3] usb: dwc2: invalidate the dcache before starting the DMA Eddie Cai
2017-04-06 15:34 ` Marek Vasut
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox