提交 57ca63b8 编写于 作者: E Eddie Cai 提交者: Marek Vasut

usb: dwc2: invalidate the dcache before starting the DMA

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: NEddie Cai <eddie.cai.linux@gmail.com>
Reviewed-by: NStefan Brüns <stefan.bruens@rwth-aachen.de>
上级 889239d6
......@@ -817,12 +817,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册