History

usb: add a hcd_uses_dma helper

The USB buffer allocation code is the only place in the usb core (and in fact the whole kernel) that uses is_device_dma_capable, while the URB mapping code uses the uses_dma flag in struct usb_bus. Switch the buffer allocation to use the uses_dma flag used by the rest of the USB code, and create a helper in hcd.h that checks this flag as well as the CONFIG_HAS_DMA to simplify the caller a bit.

Christoph Hellwig committed 7 years ago

Commit edfbcb31 parent dd3ecf15 files · +10 −11Browse files

Unified · Split

5 files
  1. drivers/usb/core/buffer.c +3 −7
  2. drivers/usb/core/hcd.c +2 −2
  3. drivers/usb/dwc2/hcd.c +1 −1
  4. include/linux/usb.h +1 −1
  5. include/linux/usb/hcd.h +3 −0
drivers/usb/core/buffer.c+3−7
@@ -66,9 +66,7 @@ int hcd_buffer_create(struct usb_hcd *hcd) · 65 unmodified lines
6666 char name[16];
6767 int i, size;
6868
69− if (hcd->localmem_pool ||
70− !IS_ENABLED(CONFIG_HAS_DMA) ||
71− !is_device_dma_capable(hcd->self.sysdev))
69+ if (hcd->localmem_pool || !hcd_uses_dma(hcd))
7270 return 0;
7371
7472 for (i = 0; i < HCD_BUFFER_POOLS; i++) {
@@ -129,8 +127,7 @@ void *hcd_buffer_alloc( · 54 unmodified lines
129127 return gen_pool_dma_alloc(hcd->localmem_pool, size, dma);
130128
131129 /* some USB hosts just use PIO */
132− if (!IS_ENABLED(CONFIG_HAS_DMA) ||
133− !is_device_dma_capable(bus->sysdev)) {
130+ if (!hcd_uses_dma(hcd)) {
134131 *dma = ~(dma_addr_t) 0;
135132 return kmalloc(size, mem_flags);
136133 }
@@ -160,8 +157,7 @@ void hcd_buffer_free( · 23 unmodified lines
160157 return;
161158 }
162159
163− if (!IS_ENABLED(CONFIG_HAS_DMA) ||
164− !is_device_dma_capable(bus->sysdev)) {
160+ if (!hcd_uses_dma(hcd)) {
165161 kfree(addr);
166162 return;
167163 }
drivers/usb/core/hcd.c+2−2
@@ -1412,7 +1412,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · 1411 unmodified lines
14121412 if (usb_endpoint_xfer_control(&urb->ep->desc)) {
14131413 if (hcd->self.uses_pio_for_control)
14141414 return ret;
1415− if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1415+ if (hcd_uses_dma(hcd)) {
14161416 if (is_vmalloc_addr(urb->setup_packet)) {
14171417 WARN_ONCE(1, "setup packet is not dma capable\n");
14181418 return -EAGAIN;
@@ -1446,7 +1446,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb, · 27 unmodified lines
14461446 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
14471447 if (urb->transfer_buffer_length != 0
14481448 && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
1449− if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
1449+ if (hcd_uses_dma(hcd)) {
14501450 if (urb->num_sgs) {
14511451 int n;
14521452
drivers/usb/dwc2/hcd.c+1−1
@@ -4608,7 +4608,7 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, · 4607 unmodified lines
46084608
46094609 buf = urb->transfer_buffer;
46104610
4611− if (hcd->self.uses_dma) {
4611+ if (hcd_uses_dma(hcd)) {
46124612 if (!buf && (urb->transfer_dma & 3)) {
46134613 dev_err(hsotg->dev,
46144614 "%s: unaligned transfer with no transfer_buffer",
include/linux/usb.h+1−1
@@ -1457,7 +1457,7 @@ typedef void (*usb_complete_t)(struct urb *); · 1456 unmodified lines
14571457 * field rather than determining a dma address themselves.
14581458 *
14591459 * Note that transfer_buffer must still be set if the controller
1460− * does not support DMA (as indicated by bus.uses_dma) and when talking
1460+ * does not support DMA (as indicated by hcd_uses_dma()) and when talking
14611461 * to root hub. If you have to trasfer between highmem zone and the device
14621462 * on such controller, create a bounce buffer or bail out with an error.
14631463 * If transfer_buffer cannot be set (is in highmem) and the controller is DMA
include/linux/usb/hcd.h+3−0
@@ -422,6 +422,9 @@ static inline bool hcd_periodic_completion_in_progress(struct usb_hcd *hcd, · 421 unmodified lines
422422 return hcd->high_prio_bh.completing_ep == ep;
423423 }
424424
425+#define hcd_uses_dma(hcd) \
426+ (IS_ENABLED(CONFIG_HAS_DMA) && (hcd)->self.uses_dma)
427+
425428 extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
426429 extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
427430 int status);