Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: drop HCD_LOCAL_MEM flag

With the addition of the local memory allocator, the HCD_LOCAL_MEM
flag can be dropped and the checks against it replaced with a check
for the localmem_pool ptr being initialized.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Tested-by: Fredrik Noring <noring@nocrew.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Laurentiu Tudor and committed by
Christoph Hellwig
2d7a3dc3 7d995329

+17 -22
+3 -5
drivers/usb/core/buffer.c
··· 68 68 69 69 if (!IS_ENABLED(CONFIG_HAS_DMA) || 70 70 (!is_device_dma_capable(hcd->self.sysdev) && 71 - !(hcd->driver->flags & HCD_LOCAL_MEM))) 71 + !hcd->localmem_pool)) 72 72 return 0; 73 73 74 74 for (i = 0; i < HCD_BUFFER_POOLS; i++) { ··· 130 130 131 131 /* some USB hosts just use PIO */ 132 132 if (!IS_ENABLED(CONFIG_HAS_DMA) || 133 - (!is_device_dma_capable(bus->sysdev) && 134 - !(hcd->driver->flags & HCD_LOCAL_MEM))) { 133 + !is_device_dma_capable(bus->sysdev)) { 135 134 *dma = ~(dma_addr_t) 0; 136 135 return kmalloc(size, mem_flags); 137 136 } ··· 161 162 } 162 163 163 164 if (!IS_ENABLED(CONFIG_HAS_DMA) || 164 - (!is_device_dma_capable(bus->sysdev) && 165 - !(hcd->driver->flags & HCD_LOCAL_MEM))) { 165 + !is_device_dma_capable(bus->sysdev)) { 166 166 kfree(addr); 167 167 return; 168 168 }
+6 -9
drivers/usb/core/hcd.c
··· 1347 1347 * using regular system memory - like pci devices doing bus mastering. 1348 1348 * 1349 1349 * To support host controllers with limited dma capabilities we provide dma 1350 - * bounce buffers. This feature can be enabled using the HCD_LOCAL_MEM flag. 1350 + * bounce buffers. This feature can be enabled by initializing 1351 + * hcd->localmem_pool using usb_hcd_setup_local_mem(). 1351 1352 * For this to work properly the host controller code must first use the 1352 1353 * function dma_declare_coherent_memory() to point out which memory area 1353 1354 * that should be used for dma allocations. 1354 1355 * 1355 - * The HCD_LOCAL_MEM flag then tells the usb code to allocate all data for 1356 - * dma using dma_alloc_coherent() which in turn allocates from the memory 1357 - * area pointed out with dma_declare_coherent_memory(). 1356 + * The initialized hcd->localmem_pool then tells the usb code to allocate all 1357 + * data for dma using the genalloc API. 1358 1358 * 1359 1359 * So, to summarize... 1360 1360 * ··· 1363 1363 * only memory that the controller can read ... 1364 1364 * (a) "normal" kernel memory is no good, and 1365 1365 * (b) there's not enough to share 1366 - * 1367 - * - The only *portable* hook for such stuff in the 1368 - * DMA framework is dma_declare_coherent_memory() 1369 1366 * 1370 1367 * - So we use that, even though the primary requirement 1371 1368 * is that the memory be "local" (hence addressable ··· 1530 1533 urb->setup_dma)) 1531 1534 return -EAGAIN; 1532 1535 urb->transfer_flags |= URB_SETUP_MAP_SINGLE; 1533 - } else if (hcd->driver->flags & HCD_LOCAL_MEM) { 1536 + } else if (hcd->localmem_pool) { 1534 1537 ret = hcd_alloc_coherent( 1535 1538 urb->dev->bus, mem_flags, 1536 1539 &urb->setup_dma, ··· 1600 1603 else 1601 1604 urb->transfer_flags |= URB_DMA_MAP_SINGLE; 1602 1605 } 1603 - } else if (hcd->driver->flags & HCD_LOCAL_MEM) { 1606 + } else if (hcd->localmem_pool) { 1604 1607 ret = hcd_alloc_coherent( 1605 1608 urb->dev->bus, mem_flags, 1606 1609 &urb->transfer_dma,
+1 -1
drivers/usb/host/ehci-hcd.c
··· 559 559 ehci->command = temp; 560 560 561 561 /* Accept arbitrarily long scatter-gather lists */ 562 - if (!(hcd->driver->flags & HCD_LOCAL_MEM)) 562 + if (!hcd->localmem_pool) 563 563 hcd->self.sg_tablesize = ~0; 564 564 565 565 /* Prepare for unlinking active QHs */
+1 -1
drivers/usb/host/fotg210-hcd.c
··· 4995 4995 fotg210->command = temp; 4996 4996 4997 4997 /* Accept arbitrarily long scatter-gather lists */ 4998 - if (!(hcd->driver->flags & HCD_LOCAL_MEM)) 4998 + if (!hcd->localmem_pool) 4999 4999 hcd->self.sg_tablesize = ~0; 5000 5000 return 0; 5001 5001 }
+1 -1
drivers/usb/host/ohci-hcd.c
··· 448 448 struct usb_hcd *hcd = ohci_to_hcd(ohci); 449 449 450 450 /* Accept arbitrarily long scatter-gather lists */ 451 - if (!(hcd->driver->flags & HCD_LOCAL_MEM)) 451 + if (!hcd->localmem_pool) 452 452 hcd->self.sg_tablesize = ~0; 453 453 454 454 if (distrust_firmware)
+3 -2
drivers/usb/host/ohci-sm501.c
··· 49 49 * generic hardware linkage 50 50 */ 51 51 .irq = ohci_irq, 52 - .flags = HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM, 52 + .flags = HCD_USB11 | HCD_MEMORY, 53 53 54 54 /* 55 55 * basic lifecycle operations ··· 153 153 * fine. This is however not always the case - buffers may be allocated 154 154 * using kmalloc() - so the usb core needs to be told that it must copy 155 155 * data into our local memory if the buffers happen to be placed in 156 - * regular memory. The HCD_LOCAL_MEM flag does just that. 156 + * regular memory. A non-null hcd->localmem_pool initialized by the 157 + * the call to usb_hcd_setup_local_mem() below does just that. 157 158 */ 158 159 159 160 if (usb_hcd_setup_local_mem(hcd, mem->start,
+1 -1
drivers/usb/host/ohci-tmio.c
··· 153 153 154 154 /* generic hardware linkage */ 155 155 .irq = ohci_irq, 156 - .flags = HCD_USB11 | HCD_MEMORY | HCD_LOCAL_MEM, 156 + .flags = HCD_USB11 | HCD_MEMORY, 157 157 158 158 /* basic lifecycle operations */ 159 159 .start = ohci_tmio_start,
+1 -1
drivers/usb/host/uhci-hcd.c
··· 581 581 582 582 hcd->uses_new_polling = 1; 583 583 /* Accept arbitrarily long scatter-gather lists */ 584 - if (!(hcd->driver->flags & HCD_LOCAL_MEM)) 584 + if (!hcd->localmem_pool) 585 585 hcd->self.sg_tablesize = ~0; 586 586 587 587 spin_lock_init(&uhci->lock);
-1
include/linux/usb/hcd.h
··· 256 256 257 257 int flags; 258 258 #define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ 259 - #define HCD_LOCAL_MEM 0x0002 /* HC needs local memory */ 260 259 #define HCD_SHARED 0x0004 /* Two (or more) usb_hcds share HW */ 261 260 #define HCD_USB11 0x0010 /* USB 1.1 */ 262 261 #define HCD_USB2 0x0020 /* USB 2.0 */