[U-Boot] [PATCH v4 6/7] dwc2: Add dcache support

Alexander Stein alexanders83 at web.de
Fri Jul 24 09:22:14 CEST 2015


This adds dcache support for dwc2. The DMA buffers must be DMA aligned and
is flushed for outgoing transactions before starting transfer. For
ingoing transactions it is invalidated after the transfer has finished.

Signed-off-by: Alexander Stein <alexanders83 at web.de>
Acked-by: Stephen Warren <swarren at wwwdotorg.org>
---
Changes in v4:
* Updated USB buffer comment about required alignment

 drivers/usb/host/dwc2.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index eee60a2..b7fb4f8 100644
--- a/drivers/usb/host/dwc2.c
+++ b/drivers/usb/host/dwc2.c
@@ -21,9 +21,9 @@
 #define DWC2_STATUS_BUF_SIZE		64
 #define DWC2_DATA_BUF_SIZE		(64 * 1024)
 
-/* We need doubleword-aligned buffers for DMA transfers */
-DEFINE_ALIGN_BUFFER(uint8_t, aligned_buffer, DWC2_DATA_BUF_SIZE, 8);
-DEFINE_ALIGN_BUFFER(uint8_t, status_buffer, DWC2_STATUS_BUF_SIZE, 8);
+/* We need cacheline-aligned buffers for DMA transfers and dcache support */
+DEFINE_ALIGN_BUFFER(uint8_t, aligned_buffer, DWC2_DATA_BUF_SIZE, ARCH_DMA_MINALIGN);
+DEFINE_ALIGN_BUFFER(uint8_t, status_buffer, DWC2_STATUS_BUF_SIZE, ARCH_DMA_MINALIGN);
 
 #define MAX_DEVICE			16
 #define MAX_ENDPOINT			16
@@ -802,9 +802,14 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
 		       (*pid << DWC2_HCTSIZ_PID_OFFSET),
 		       &hc_regs->hctsiz);
 
-		if (!in)
+		if (!in) {
 			memcpy(aligned_buffer, (char *)buffer + done, len);
 
+			flush_dcache_range((unsigned long)aligned_buffer,
+				(unsigned long)((void *)aligned_buffer +
+				roundup(len, ARCH_DMA_MINALIGN)));
+		}
+
 		writel(phys_to_bus((unsigned long)aligned_buffer),
 		       &hc_regs->hcdma);
 
@@ -820,6 +825,11 @@ int chunk_msg(struct usb_device *dev, unsigned long pipe, int *pid, int in,
 
 		if (in) {
 			xfer_len -= sub;
+
+			invalidate_dcache_range((unsigned long)aligned_buffer,
+				(unsigned long)((void *)aligned_buffer +
+				roundup(xfer_len, ARCH_DMA_MINALIGN)));
+
 			memcpy(buffer + done, aligned_buffer, xfer_len);
 			if (sub)
 				stop_transfer = 1;
-- 
2.4.6



More information about the U-Boot mailing list