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