1#ifndef __LINUX_CMA_H
2#define __LINUX_CMA_H
3
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
51
52
53
54#ifdef __KERNEL__
55
56#include <linux/device.h>
57#include <linux/mm.h>
58
59struct cma;
60struct page;
61
62#ifdef CONFIG_DMA_CMA
63
64extern struct cma *dma_contiguous_default_area;
65
66static inline struct cma *dev_get_cma_area(struct device *dev)
67{
68 if (dev && dev->cma_area)
69 return dev->cma_area;
70 return dma_contiguous_default_area;
71}
72
73static inline void dev_set_cma_area(struct device *dev, struct cma *cma)
74{
75 if (dev)
76 dev->cma_area = cma;
77}
78
79static inline void dma_contiguous_set_default(struct cma *cma)
80{
81 dma_contiguous_default_area = cma;
82}
83
84void dma_contiguous_reserve(phys_addr_t addr_limit);
85
86int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
87 phys_addr_t limit, struct cma **res_cma,
88 bool fixed);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103static inline int dma_declare_contiguous(struct device *dev, phys_addr_t size,
104 phys_addr_t base, phys_addr_t limit)
105{
106 struct cma *cma;
107 int ret;
108 ret = dma_contiguous_reserve_area(size, base, limit, &cma, true);
109 if (ret == 0)
110 dev_set_cma_area(dev, cma);
111
112 return ret;
113}
114
115struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
116 unsigned int order, bool no_warn);
117bool dma_release_from_contiguous(struct device *dev, struct page *pages,
118 int count);
119struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp);
120void dma_free_contiguous(struct device *dev, struct page *page, size_t size);
121
122#else
123
124static inline struct cma *dev_get_cma_area(struct device *dev)
125{
126 return NULL;
127}
128
129static inline void dev_set_cma_area(struct device *dev, struct cma *cma) { }
130
131static inline void dma_contiguous_set_default(struct cma *cma) { }
132
133static inline void dma_contiguous_reserve(phys_addr_t limit) { }
134
135static inline int dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
136 phys_addr_t limit, struct cma **res_cma,
137 bool fixed)
138{
139 return -ENOSYS;
140}
141
142static inline
143int dma_declare_contiguous(struct device *dev, phys_addr_t size,
144 phys_addr_t base, phys_addr_t limit)
145{
146 return -ENOSYS;
147}
148
149static inline
150struct page *dma_alloc_from_contiguous(struct device *dev, size_t count,
151 unsigned int order, bool no_warn)
152{
153 return NULL;
154}
155
156static inline
157bool dma_release_from_contiguous(struct device *dev, struct page *pages,
158 int count)
159{
160 return false;
161}
162
163
164static inline struct page *dma_alloc_contiguous(struct device *dev, size_t size,
165 gfp_t gfp)
166{
167 return NULL;
168}
169
170static inline void dma_free_contiguous(struct device *dev, struct page *page,
171 size_t size)
172{
173 __free_pages(page, get_order(size));
174}
175
176#endif
177
178#endif
179
180#endif
181