cgroups: make cftype.unregister_event() void-returning
[safe/jmp/linux-2.6] / mm / dmapool.c
index 72e7ece..3df0637 100644 (file)
 #include <linux/types.h>
 #include <linux/wait.h>
 
+#if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB_DEBUG_ON)
+#define DMAPOOL_DEBUG 1
+#endif
+
 struct dma_pool {              /* the pool */
        struct list_head page_list;
        spinlock_t lock;
        size_t size;
        struct device *dev;
        size_t allocation;
+       size_t boundary;
        char name[32];
        wait_queue_head_t waitq;
        struct list_head pools;
@@ -81,10 +86,12 @@ show_pools(struct device *dev, struct device_attribute *attr, char *buf)
                unsigned pages = 0;
                unsigned blocks = 0;
 
+               spin_lock_irq(&pool->lock);
                list_for_each_entry(page, &pool->page_list, page_list) {
                        pages++;
                        blocks += page->in_use;
                }
+               spin_unlock_irq(&pool->lock);
 
                /* per-pool info, no real statistics yet */
                temp = scnprintf(next, size, "%-16s %4u %4Zu %4Zu %2u\n",
@@ -107,7 +114,7 @@ static DEVICE_ATTR(pools, S_IRUGO, show_pools, NULL);
  * @dev: device that will be doing the DMA
  * @size: size of the blocks in this pool.
  * @align: alignment requirement for blocks; must be a power of two
- * @allocation: returned blocks won't cross this boundary (or zero)
+ * @boundary: returned blocks won't cross this power of two boundary
  * Context: !in_interrupt()
  *
  * Returns a dma allocation pool with the requested characteristics, or
@@ -117,15 +124,16 @@ static DEVICE_ATTR(pools, S_IRUGO, show_pools, NULL);
  * cache flushing primitives.  The actual size of blocks allocated may be
  * larger than requested because of alignment.
  *
- * If allocation is nonzero, objects returned from dma_pool_alloc() won't
+ * If @boundary is nonzero, objects returned from dma_pool_alloc() won't
  * cross that size boundary.  This is useful for devices which have
  * addressing restrictions on individual DMA transfers, such as not crossing
  * boundaries of 4KBytes.
  */
 struct dma_pool *dma_pool_create(const char *name, struct device *dev,
-                                size_t size, size_t align, size_t allocation)
+                                size_t size, size_t align, size_t boundary)
 {
        struct dma_pool *retval;
+       size_t allocation;
 
        if (align == 0) {
                align = 1;
@@ -142,27 +150,26 @@ struct dma_pool *dma_pool_create(const char *name, struct device *dev,
        if ((size % align) != 0)
                size = ALIGN(size, align);
 
-       if (allocation == 0) {
-               if (PAGE_SIZE < size)
-                       allocation = size;
-               else
-                       allocation = PAGE_SIZE;
-               /* FIXME: round up for less fragmentation */
-       } else if (allocation < size)
+       allocation = max_t(size_t, size, PAGE_SIZE);
+
+       if (!boundary) {
+               boundary = allocation;
+       } else if ((boundary < size) || (boundary & (boundary - 1))) {
                return NULL;
+       }
 
-       if (!
-           (retval =
-            kmalloc_node(sizeof *retval, GFP_KERNEL, dev_to_node(dev))))
+       retval = kmalloc_node(sizeof(*retval), GFP_KERNEL, dev_to_node(dev));
+       if (!retval)
                return retval;
 
-       strlcpy(retval->name, name, sizeof retval->name);
+       strlcpy(retval->name, name, sizeof(retval->name));
 
        retval->dev = dev;
 
        INIT_LIST_HEAD(&retval->page_list);
        spin_lock_init(&retval->lock);
        retval->size = size;
+       retval->boundary = boundary;
        retval->allocation = allocation;
        init_waitqueue_head(&retval->waitq);
 
@@ -192,11 +199,14 @@ EXPORT_SYMBOL(dma_pool_create);
 static void pool_initialise_page(struct dma_pool *pool, struct dma_page *page)
 {
        unsigned int offset = 0;
+       unsigned int next_boundary = pool->boundary;
 
        do {
                unsigned int next = offset + pool->size;
-               if (unlikely((next + pool->size) >= pool->allocation))
-                       next = pool->allocation;
+               if (unlikely((next + pool->size) >= next_boundary)) {
+                       next = next_boundary;
+                       next_boundary += pool->boundary;
+               }
                *(int *)(page->vaddr + offset) = next;
                offset = next;
        } while (offset < pool->allocation);
@@ -212,7 +222,7 @@ static struct dma_page *pool_alloc_page(struct dma_pool *pool, gfp_t mem_flags)
        page->vaddr = dma_alloc_coherent(pool->dev, pool->allocation,
                                         &page->dma, mem_flags);
        if (page->vaddr) {
-#ifdef CONFIG_DEBUG_SLAB
+#ifdef DMAPOOL_DEBUG
                memset(page->vaddr, POOL_POISON_FREED, pool->allocation);
 #endif
                pool_initialise_page(pool, page);
@@ -235,7 +245,7 @@ static void pool_free_page(struct dma_pool *pool, struct dma_page *page)
 {
        dma_addr_t dma = page->dma;
 
-#ifdef CONFIG_DEBUG_SLAB
+#ifdef DMAPOOL_DEBUG
        memset(page->vaddr, POOL_POISON_FREED, pool->allocation);
 #endif
        dma_free_coherent(pool->dev, pool->allocation, page->vaddr, dma);
@@ -332,7 +342,7 @@ void *dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,
        page->offset = *(int *)(page->vaddr + offset);
        retval = offset + page->vaddr;
        *handle = offset + page->dma;
-#ifdef CONFIG_DEBUG_SLAB
+#ifdef DMAPOOL_DEBUG
        memset(retval, POOL_POISON_ALLOCATED, pool->size);
 #endif
  done:
@@ -387,7 +397,7 @@ void dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma)
        }
 
        offset = vaddr - page->vaddr;
-#ifdef CONFIG_DEBUG_SLAB
+#ifdef DMAPOOL_DEBUG
        if ((dma - page->dma) != offset) {
                if (pool->dev)
                        dev_err(pool->dev,