tegra: usb: host: dma buffer sync while mapping
Vinayak Pane [Fri, 23 Mar 2012 23:52:56 +0000 (16:52 -0700)]
Implementing dma_sync_* functions for usb transfer buffers
when DMA is being used by ehci-hcd.

Bug 953885

Change-Id: Ia772138752e3fe03bb45ee983dffa1b5d8d620f5
Signed-off-by: Vinayak Pane <vpane@nvidia.com>
Reviewed-on: http://git-master/r/102687
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Venkat Moganty <vmoganty@nvidia.com>

drivers/usb/host/ehci-tegra.c

index 5e646b6..4e7277b 100644 (file)
@@ -938,6 +938,22 @@ static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
                return ret;
 
        ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
+
+       /* control packets over dma */
+       if (urb->setup_dma)
+               dma_sync_single_for_device(hcd->self.controller,
+                               urb->setup_dma, sizeof(struct usb_ctrlrequest),
+                               DMA_TO_DEVICE);
+
+       /* urb buffers over dma */
+       if (urb->transfer_dma) {
+               enum dma_data_direction dir;
+               dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+
+               dma_sync_single_for_device(hcd->self.controller,
+                       urb->transfer_dma, urb->transfer_buffer_length, dir);
+       }
+
        if (ret)
                free_dma_aligned_buffer(urb);
 
@@ -956,6 +972,15 @@ static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
        else if (tegra->phy->instance == 2)
                readb(IO_ADDRESS(IO_PPCS_PHYS + USB3_PREFETCH_ID));
 
+       if (urb->transfer_dma) {
+               enum dma_data_direction dir;
+               dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
+               if (dir == DMA_FROM_DEVICE)
+                       dma_sync_single_for_cpu(hcd->self.controller,
+                               urb->transfer_dma, urb->transfer_buffer_length,
+                               DMA_FROM_DEVICE);
+       }
+
        usb_hcd_unmap_urb_for_dma(hcd, urb);
        free_dma_aligned_buffer(urb);
 }