]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blob - arch/cris/arch-v32/drivers/pci/dma.c
Merge branch 'linus' into core/generic-dma-coherent
[mirror_ubuntu-focal-kernel.git] / arch / cris / arch-v32 / drivers / pci / dma.c
1 /*
2 * Dynamic DMA mapping support.
3 *
4 * On cris 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 * Borrowed from i386.
10 */
11
12 #include <linux/types.h>
13 #include <linux/mm.h>
14 #include <linux/string.h>
15 #include <linux/pci.h>
16 #include <asm/io.h>
17
18 void *dma_alloc_coherent(struct device *dev, size_t size,
19 dma_addr_t *dma_handle, gfp_t gfp)
20 {
21 void *ret;
22 int order = get_order(size);
23 /* ignore region specifiers */
24 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
25
26 if (dma_alloc_from_coherent(dev, size, dma_handle, &ret))
27 return ret;
28
29 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
30 gfp |= GFP_DMA;
31
32 ret = (void *)__get_free_pages(gfp, order);
33
34 if (ret != NULL) {
35 memset(ret, 0, size);
36 *dma_handle = virt_to_phys(ret);
37 }
38 return ret;
39 }
40
41 void dma_free_coherent(struct device *dev, size_t size,
42 void *vaddr, dma_addr_t dma_handle)
43 {
44 int order = get_order(size);
45
46 if (!dma_release_from_coherent(dev, order, vaddr))
47 free_pages((unsigned long)vaddr, order);
48 }
49