The bitmap library provides more efficient functions than accessing
individual bits with bitops.
This uses bitmap_find_next_zero_area() to find a continuing zero area,
and uses bitmap_set()/bitmap_clear() to set/clear specified bit area.
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: uclinux-dist-devel@blackfin.uclinux.org
Signed-off-by: Bob Liu <lliubbo@gmail.com>
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/export.h>
#include <linux/dma-mapping.h>
#include <linux/scatterlist.h>
#include <linux/export.h>
+#include <linux/bitmap.h>
static spinlock_t dma_page_lock;
static unsigned long *dma_page;
static spinlock_t dma_page_lock;
static unsigned long *dma_page;
static unsigned long __alloc_dma_pages(unsigned int pages)
{
unsigned long ret = 0, flags;
static unsigned long __alloc_dma_pages(unsigned int pages)
{
unsigned long ret = 0, flags;
if (dma_initialized == 0)
dma_alloc_init(_ramend - DMA_UNCACHED_REGION, _ramend);
spin_lock_irqsave(&dma_page_lock, flags);
if (dma_initialized == 0)
dma_alloc_init(_ramend - DMA_UNCACHED_REGION, _ramend);
spin_lock_irqsave(&dma_page_lock, flags);
- for (i = 0; i < dma_pages;) {
- if (test_bit(i++, dma_page) == 0) {
- if (++count == pages) {
- while (count--)
- __set_bit(--i, dma_page);
-
- ret = dma_base + (i << PAGE_SHIFT);
- break;
- }
- } else
- count = 0;
+ start = bitmap_find_next_zero_area(dma_page, dma_pages, 0, pages, 0);
+ if (start < dma_pages) {
+ ret = dma_base + (start << PAGE_SHIFT);
+ bitmap_set(dma_page, start, pages);
}
spin_unlock_irqrestore(&dma_page_lock, flags);
return ret;
}
spin_unlock_irqrestore(&dma_page_lock, flags);
return ret;
{
unsigned long page = (addr - dma_base) >> PAGE_SHIFT;
unsigned long flags;
{
unsigned long page = (addr - dma_base) >> PAGE_SHIFT;
unsigned long flags;
if ((page + pages) > dma_pages) {
printk(KERN_ERR "%s: freeing outside range.\n", __func__);
if ((page + pages) > dma_pages) {
printk(KERN_ERR "%s: freeing outside range.\n", __func__);
}
spin_lock_irqsave(&dma_page_lock, flags);
}
spin_lock_irqsave(&dma_page_lock, flags);
- for (i = page; i < page + pages; i++)
- __clear_bit(i, dma_page);
-
+ bitmap_clear(dma_page, page, pages);
spin_unlock_irqrestore(&dma_page_lock, flags);
}
spin_unlock_irqrestore(&dma_page_lock, flags);
}