[PATCH V3] usb: musb: host: Unmap the buffer for PIO data transfers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The USB stack maps the buffer for DMA if the controller supports DMA.
MUSB controller can perform DMA as well as PIO transfers.
The buffer needs to be unmapped before CPU can perform
PIO data transfers.

Export unmap_urb_for_dma() so that drivers can perform 
the DMA unmapping in a sane way.

Signed-off-by: Maulik Mankad <x0082077@xxxxxx>
Cc: Felipe Balbi <felipe.balbi@xxxxxxxxx>
Cc: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
---
Based on 2.6.36-rc1
V3: Fix Alan's comments.
 drivers/usb/core/hcd.c       |    3 ++-
 drivers/usb/musb/musb_host.c |    5 +++++
 include/linux/usb/hcd.h      |    1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

Index: mainline/drivers/usb/core/hcd.c
===================================================================
--- mainline.orig/drivers/usb/core/hcd.c
+++ mainline/drivers/usb/core/hcd.c
@@ -1263,7 +1263,7 @@ static void hcd_free_coherent(struct usb
 	*dma_handle = 0;
 }
 
-static void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
+void unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
 {
 	enum dma_data_direction dir;
 
@@ -1307,6 +1307,7 @@ static void unmap_urb_for_dma(struct usb
 			URB_DMA_MAP_SG | URB_DMA_MAP_PAGE |
 			URB_DMA_MAP_SINGLE | URB_MAP_LOCAL);
 }
+EXPORT_SYMBOL_GPL(unmap_urb_for_dma);
 
 static int map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
 			   gfp_t mem_flags)
Index: mainline/drivers/usb/musb/musb_host.c
===================================================================
--- mainline.orig/drivers/usb/musb/musb_host.c
+++ mainline/drivers/usb/musb/musb_host.c
@@ -41,6 +41,7 @@
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/list.h>
+#include <linux/dma-mapping.h>
 
 #include "musb_core.h"
 #include "musb_host.h"
@@ -1326,6 +1327,8 @@ void musb_host_tx(struct musb *musb, u8 
 	 */
 	if (length > qh->maxpacket)
 		length = qh->maxpacket;
+	/* Unmap the buffer so that CPU can use it */
+	unmap_urb_for_dma(musb_to_hcd(musb), urb);
 	musb_write_fifo(hw_ep, length, urb->transfer_buffer + offset);
 	qh->segsize = length;
 
@@ -1746,6 +1749,8 @@ void musb_host_rx(struct musb *musb, u8 
 #endif	/* Mentor DMA */
 
 		if (!dma) {
+			/* Unmap the buffer so that CPU can use it */
+			unmap_urb_for_dma(musb_to_hcd(musb), urb);
 			done = musb_host_packet_rx(musb, urb,
 					epnum, iso_err);
 			DBG(6, "read %spacket\n", done ? "last " : "");
Index: mainline/include/linux/usb/hcd.h
===================================================================
--- mainline.orig/include/linux/usb/hcd.h
+++ mainline/include/linux/usb/hcd.h
@@ -349,6 +349,7 @@ extern void usb_put_hcd(struct usb_hcd *
 extern int usb_add_hcd(struct usb_hcd *hcd,
 		unsigned int irqnum, unsigned long irqflags);
 extern void usb_remove_hcd(struct usb_hcd *hcd);
+extern void unmap_urb_for_dma(struct usb_hcd *, struct urb *);
 
 struct platform_device;
 extern void usb_hcd_platform_shutdown(struct platform_device *dev);
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux