USB: use genalloc for USB HCs with local memory
For HCs that have local memory, replace the current DMA API usage with a genalloc generic allocator to manage the mappings for these devices. To help users, introduce a new HCD API, usb_hcd_setup_local_mem() that will setup up the genalloc backing up the device local memory. It will be used in subsequent patches. This is in preparation for dropping the existing "coherent" dma mem declaration APIs. The current implementation was relying on a short circuit in the DMA API that in the end, was acting as an allocator for these type of devices. 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>
This commit is contained in:
committed by
Christoph Hellwig
parent
da83a72295
commit
b0310c2f09
@@ -16,6 +16,7 @@
|
||||
#include <linux/io.h>
|
||||
#include <linux/dma-mapping.h>
|
||||
#include <linux/dmapool.h>
|
||||
#include <linux/genalloc.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/usb/hcd.h>
|
||||
|
||||
@@ -124,6 +125,9 @@ void *hcd_buffer_alloc(
|
||||
if (size == 0)
|
||||
return NULL;
|
||||
|
||||
if (hcd->localmem_pool)
|
||||
return gen_pool_dma_alloc(hcd->localmem_pool, size, dma);
|
||||
|
||||
/* some USB hosts just use PIO */
|
||||
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
|
||||
(!is_device_dma_capable(bus->sysdev) &&
|
||||
@@ -152,6 +156,11 @@ void hcd_buffer_free(
|
||||
if (!addr)
|
||||
return;
|
||||
|
||||
if (hcd->localmem_pool) {
|
||||
gen_pool_free(hcd->localmem_pool, (unsigned long)addr, size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
|
||||
(!is_device_dma_capable(bus->sysdev) &&
|
||||
!(hcd->driver->flags & HCD_LOCAL_MEM))) {
|
||||
|
||||
Reference in New Issue
Block a user