USB: use genalloc for USB HCs with local memory
[platform/kernel/linux-starfive.git] / drivers / usb / core / buffer.c
index f641342..d2064ad 100644 (file)
@@ -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))) {