1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/dma-mapping.h>
22#include <linux/dma-debug.h>
23#include <linux/export.h>
24#include <asm/cacheflush.h>
25
26
27
28
29void *dma_alloc_noncoherent(struct device *dev, size_t size,
30 dma_addr_t *dma_handle, gfp_t gfp)
31{
32 void *paddr;
33
34
35 paddr = alloc_pages_exact(size, gfp);
36 if (!paddr)
37 return NULL;
38
39
40 *dma_handle = plat_kernel_addr_to_dma(dev, paddr);
41
42 return paddr;
43}
44EXPORT_SYMBOL(dma_alloc_noncoherent);
45
46void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
47 dma_addr_t dma_handle)
48{
49 free_pages_exact((void *)plat_dma_addr_to_kernel(dev, dma_handle),
50 size);
51}
52EXPORT_SYMBOL(dma_free_noncoherent);
53
54void *dma_alloc_coherent(struct device *dev, size_t size,
55 dma_addr_t *dma_handle, gfp_t gfp)
56{
57 void *paddr, *kvaddr;
58
59
60 paddr = alloc_pages_exact(size, gfp);
61 if (!paddr)
62 return NULL;
63
64
65 kvaddr = ioremap_nocache((unsigned long)paddr, size);
66 if (kvaddr != NULL)
67 memset(kvaddr, 0, size);
68
69
70 *dma_handle = plat_kernel_addr_to_dma(dev, paddr);
71
72 return kvaddr;
73}
74EXPORT_SYMBOL(dma_alloc_coherent);
75
76void dma_free_coherent(struct device *dev, size_t size, void *kvaddr,
77 dma_addr_t dma_handle)
78{
79 iounmap((void __force __iomem *)kvaddr);
80
81 free_pages_exact((void *)plat_dma_addr_to_kernel(dev, dma_handle),
82 size);
83}
84EXPORT_SYMBOL(dma_free_coherent);
85
86
87
88
89void __arc_dma_cache_sync(unsigned long paddr, size_t size,
90 enum dma_data_direction dir)
91{
92 __inline_dma_cache_sync(paddr, size, dir);
93}
94EXPORT_SYMBOL(__arc_dma_cache_sync);
95