1 /*
2 * Copyright (C) 2000 Ani Joshi <ajoshi@unixbox.com>
3 *
4 *
5 * Dynamic DMA mapping support.
6 *
7 * swiped from i386
8 *
9 */
10
11 #include <linux/types.h>
12 #include <linux/mm.h>
13 #include <linux/string.h>
14 #include <linux/pci.h>
15 #include <asm/io.h>
16
pci_alloc_consistent(struct pci_dev * hwdev,size_t size,dma_addr_t * dma_handle)17 void *pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
18 dma_addr_t *dma_handle)
19 {
20 void *ret;
21 int gfp = GFP_ATOMIC;
22
23 if (hwdev == NULL || hwdev->dma_mask < 0xffffffff)
24 gfp |= GFP_DMA;
25
26 #ifdef CONFIG_NOT_COHERENT_CACHE
27 ret = consistent_alloc(gfp, size, dma_handle);
28 #else
29 ret = (void *)__get_free_pages(gfp, get_order(size));
30 #endif
31
32 if (ret != NULL) {
33 memset(ret, 0, size);
34 #ifndef CONFIG_NOT_COHERENT_CACHE
35 *dma_handle = virt_to_bus(ret);
36 #endif
37 }
38 return ret;
39 }
40
pci_free_consistent(struct pci_dev * hwdev,size_t size,void * vaddr,dma_addr_t dma_handle)41 void pci_free_consistent(struct pci_dev *hwdev, size_t size,
42 void *vaddr, dma_addr_t dma_handle)
43 {
44 #ifdef CONFIG_NOT_COHERENT_CACHE
45 consistent_free(vaddr);
46 #else
47 free_pages((unsigned long)vaddr, get_order(size));
48 #endif
49 }
50