1
2#ifndef __LINUX_CMA_H
3#define __LINUX_CMA_H
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#ifdef __KERNEL__
51
52#include <linux/device.h>
53#include <linux/mm.h>
54
55struct cma;
56struct page;
57
58#ifdef CONFIG_DMA_CMA
59
60extern struct cma *dma_contiguous_default_area;
61
62static inline struct cma *dev_get_cma_area(struct device *dev)
63{
64 if (dev && dev->cma_area)
65 return dev->cma_area;
66 return dma_contiguous_default_area;
67}
68
69static inline void dev_set_cma_area(struct device *dev, struct cma *cma)
70{
71 if (dev)
72 dev->cma_area = cma;
73}
74
75static inline void dma_contiguous_set_default(struct cma *cma)
76{
77 dma_contiguous_default_area = cma;
78}
79
80void dma_contiguous_reserve(phys_addr_t addr_limit);
81
82int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
83 phys_addr_t limit, struct cma **res_cma,
84 bool fixed);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99static inline int dma_declare_contiguous(struct device *dev, phys_addr_t size,
100 phys_addr_t base, phys_addr_t limit)
101{
102 struct cma *cma;
103 int ret;
104 ret = dma_contiguous_reserve_area(size, base, limit, &cma, true);
105 if (ret == 0)
106 dev_set_cma_area(dev, cma);
107
108 return ret;
109}
110
111struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
112 unsigned int order, bool no_warn);
113bool dma_release_from_contiguous(struct device *dev, struct page *pages,
114 int count);
115struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp);
116void dma_free_contiguous(struct device *dev, struct page *page, size_t size);
117
118#else
119
120static inline struct cma *dev_get_cma_area(struct device *dev)
121{
122 return NULL;
123}
124
125static inline void dev_set_cma_area(struct device *dev, struct cma *cma) { }
126
127static inline void dma_contiguous_set_default(struct cma *cma) { }
128
129static inline void dma_contiguous_reserve(phys_addr_t limit) { }
130
131static inline int dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
132 phys_addr_t limit, struct cma **res_cma,
133 bool fixed)
134{
135 return -ENOSYS;
136}
137
138static inline
139int dma_declare_contiguous(struct device *dev, phys_addr_t size,
140 phys_addr_t base, phys_addr_t limit)
141{
142 return -ENOSYS;
143}
144
145static inline
146struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
147 unsigned int order, bool no_warn)
148{
149 return NULL;
150}
151
152static inline
153bool dma_release_from_contiguous(struct device *dev, struct page *pages,
154 int count)
155{
156 return false;
157}
158
159
160static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
161 gfp_t gfp)
162{
163 return NULL;
164}
165
166static inline void dma_free_contiguous(struct device *dev, struct page *page,
167 size_t size)
168{
169 __free_pages(page, get_order(size));
170}
171
172#endif
173
174#endif
175
176#endif
177