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