9 #include <linux/types.h>
11 #include <linux/string.h>
15 #include <linux/export.h>
19 static unsigned int dma_pages;
20 static unsigned long dma_base;
21 static unsigned long dma_size;
22 static unsigned int dma_initialized;
24 static void dma_alloc_init(
unsigned long start,
unsigned long end)
37 printk(
KERN_INFO "%s: dma_page @ 0x%p - %d pages at 0x%08lx\n", __func__,
41 static inline unsigned int get_pages(
size_t size)
43 return ((size - 1) >> PAGE_SHIFT) + 1;
46 static unsigned long __alloc_dma_pages(
unsigned int pages)
51 if (dma_initialized == 0)
56 for (i = 0; i < dma_pages;) {
58 if (++count == pages) {
68 spin_unlock_irqrestore(&dma_page_lock,
flags);
72 static void __free_dma_pages(
unsigned long addr,
unsigned int pages)
74 unsigned long page = (addr - dma_base) >> PAGE_SHIFT;
78 if ((page + pages) > dma_pages) {
84 for (i = page; i < page +
pages; i++)
87 spin_unlock_irqrestore(&dma_page_lock, flags);
95 ret = (
void *)__alloc_dma_pages(get_pages(size));
110 __free_dma_pages((
unsigned long)vaddr, get_pages(size));
120 __dma_sync_inline(addr, size, dir);