ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / i386 / kernel / pci-dma.c
1 /*
2  * Dynamic DMA mapping support.
3  *
4  * On i386 there is no hardware dynamic DMA address translation,
5  * so consistent alloc/free are merely page allocation/freeing.
6  * The rest of the dynamic DMA mapping interface is implemented
7  * in asm/pci.h.
8  */
9
10 #include <linux/types.h>
11 #include <linux/mm.h>
12 #include <linux/string.h>
13 #include <linux/pci.h>
14 #include <asm/io.h>
15
16 void *dma_alloc_coherent(struct device *dev, size_t size,
17                            dma_addr_t *dma_handle, int gfp)
18 {
19         void *ret;
20         /* ignore region specifiers */
21         gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
22
23         if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
24                 gfp |= GFP_DMA;
25
26         ret = (void *)__get_free_pages(gfp, get_order(size));
27
28         if (ret != NULL) {
29                 memset(ret, 0, size);
30                 *dma_handle = virt_to_phys(ret);
31         }
32         return ret;
33 }
34
35 void dma_free_coherent(struct device *dev, size_t size,
36                          void *vaddr, dma_addr_t dma_handle)
37 {
38         free_pages((unsigned long)vaddr, get_order(size));
39 }