]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/usb/core/buffer.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / drivers / usb / core / buffer.c
index c3915dc28608da7aa3ef3ae88fc005cbdf37eba7..cadb2dc1d28ae4ccee6cec683979938d874f6008 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/device.h>
 #include <linux/mm.h>
 #include <asm/io.h>
-#include <asm/scatterlist.h>
 #include <linux/dma-mapping.h>
 #include <linux/dmapool.h>
 #include <linux/usb.h>
@@ -49,22 +48,24 @@ static const size_t pool_max [HCD_BUFFER_POOLS] = {
  *
  * Call hcd_buffer_destroy() to clean up after using those pools.
  */
-int hcd_buffer_create (struct usb_hcd *hcd)
+int hcd_buffer_create(struct usb_hcd *hcd)
 {
-       char            name [16];
+       char            name[16];
        int             i, size;
 
-       if (!hcd->self.controller->dma_mask)
+       if (!hcd->self.controller->dma_mask &&
+           !(hcd->driver->flags & HCD_LOCAL_MEM))
                return 0;
 
-       for (i = 0; i < HCD_BUFFER_POOLS; i++) { 
-               if (!(size = pool_max [i]))
+       for (i = 0; i < HCD_BUFFER_POOLS; i++) {
+               size = pool_max[i];
+               if (!size)
                        continue;
-               snprintf (name, sizeof name, "buffer-%d", size);
-               hcd->pool [i] = dma_pool_create (name, hcd->self.controller,
+               snprintf(name, sizeof name, "buffer-%d", size);
+               hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
                                size, size, 0);
                if (!hcd->pool [i]) {
-                       hcd_buffer_destroy (hcd);
+                       hcd_buffer_destroy(hcd);
                        return -ENOMEM;
                }
        }
@@ -79,14 +80,14 @@ int hcd_buffer_create (struct usb_hcd *hcd)
  *
  * This frees the buffer pools created by hcd_buffer_create().
  */
-void hcd_buffer_destroy (struct usb_hcd *hcd)
+void hcd_buffer_destroy(struct usb_hcd *hcd)
 {
-       int             i;
+       int i;
 
-       for (i = 0; i < HCD_BUFFER_POOLS; i++) { 
-               struct dma_pool         *pool = hcd->pool [i];
+       for (i = 0; i < HCD_BUFFER_POOLS; i++) {
+               struct dma_pool *pool = hcd->pool[i];
                if (pool) {
-                       dma_pool_destroy (pool);
+                       dma_pool_destroy(pool);
                        hcd->pool[i] = NULL;
                }
        }
@@ -97,8 +98,8 @@ void hcd_buffer_destroy (struct usb_hcd *hcd)
  * better sharing and to leverage mm/slab.c intelligence.
  */
 
-void *hcd_buffer_alloc (
-       struct usb_bus          *bus,
+void *hcd_buffer_alloc(
+       struct usb_bus  *bus,
        size_t                  size,
        gfp_t                   mem_flags,
        dma_addr_t              *dma
@@ -108,20 +109,21 @@ void *hcd_buffer_alloc (
        int                     i;
 
        /* some USB hosts just use PIO */
-       if (!bus->controller->dma_mask) {
+       if (!bus->controller->dma_mask &&
+           !(hcd->driver->flags & HCD_LOCAL_MEM)) {
                *dma = ~(dma_addr_t) 0;
-               return kmalloc (size, mem_flags);
+               return kmalloc(size, mem_flags);
        }
 
        for (i = 0; i < HCD_BUFFER_POOLS; i++) {
                if (size <= pool_max [i])
-                       return dma_pool_alloc (hcd->pool [i], mem_flags, dma);
+                       return dma_pool_alloc(hcd->pool [i], mem_flags, dma);
        }
-       return dma_alloc_coherent (hcd->self.controller, size, dma, 0);
+       return dma_alloc_coherent(hcd->self.controller, size, dma, 0);
 }
 
-void hcd_buffer_free (
-       struct usb_bus          *bus,
+void hcd_buffer_free(
+       struct usb_bus  *bus,
        size_t                  size,
        void                    *addr,
        dma_addr_t              dma
@@ -133,16 +135,17 @@ void hcd_buffer_free (
        if (!addr)
                return;
 
-       if (!bus->controller->dma_mask) {
-               kfree (addr);
+       if (!bus->controller->dma_mask &&
+           !(hcd->driver->flags & HCD_LOCAL_MEM)) {
+               kfree(addr);
                return;
        }
 
        for (i = 0; i < HCD_BUFFER_POOLS; i++) {
                if (size <= pool_max [i]) {
-                       dma_pool_free (hcd->pool [i], addr, dma);
+                       dma_pool_free(hcd->pool [i], addr, dma);
                        return;
                }
        }
-       dma_free_coherent (hcd->self.controller, size, addr, dma);
+       dma_free_coherent(hcd->self.controller, size, addr, dma);
 }