19
19
#define _LINUX_ION_H
20
20
21
21
#include <linux/err.h>
22
+ #include <linux/memblock.h>
23
+ #include <linux/msm_dma_iommu_mapping.h>
22
24
#include "../uapi/ion.h"
23
25
24
26
struct ion_handle ;
@@ -28,6 +30,21 @@ struct ion_mapper;
28
30
struct ion_client ;
29
31
struct ion_buffer ;
30
32
33
+ struct ion_buffer {
34
+ struct ion_heap * heap ;
35
+ struct sg_table * sg_table ;
36
+ struct mutex kmap_lock ;
37
+ struct work_struct free ;
38
+ atomic_t refcount ;
39
+ void * priv_virt ;
40
+ void * vaddr ;
41
+ unsigned int flags ;
42
+ unsigned int private_flags ;
43
+ size_t size ;
44
+ int kmap_refcount ;
45
+ struct msm_iommu_data iommu_data ;
46
+ };
47
+
31
48
/* This should be removed some day when phys_addr_t's are fully
32
49
plumbed in the kernel, and all instances of ion_phys_addr_t should
33
50
be converted to phys_addr_t. For the time being many kernel interfaces
@@ -88,15 +105,31 @@ struct ion_platform_data {
88
105
* located at specific memory addresses or of specific sizes not
89
106
* managed by the kernel
90
107
*/
91
- void ion_reserve (struct ion_platform_data * data );
108
+ static inline void ion_reserve (struct ion_platform_data * data )
109
+ {
110
+ int i ;
111
+
112
+ for (i = 0 ; i < data -> nr ; i ++ ) {
113
+ struct ion_platform_heap * pheap = & data -> heaps [i ];
114
+
115
+ if (pheap -> size ) {
116
+ if (pheap -> base )
117
+ memblock_reserve (pheap -> base , pheap -> size );
118
+ else
119
+ pheap -> base = memblock_alloc_base (pheap -> size ,
120
+ pheap -> align , MEMBLOCK_ALLOC_ANYWHERE );
121
+ }
122
+ }
123
+ }
92
124
93
125
/**
94
126
* ion_client_create() - allocate a client and returns it
95
127
* @dev: the global ion device
96
- * @name: used for debugging
97
128
*/
98
- struct ion_client * ion_client_create (struct ion_device * dev ,
99
- const char * name );
129
+ static inline struct ion_client * ion_client_create (void * idev )
130
+ {
131
+ return idev ;
132
+ }
100
133
101
134
/**
102
135
* ion_client_destroy() - free's a client and all it's handles
@@ -105,7 +138,9 @@ struct ion_client *ion_client_create(struct ion_device *dev,
105
138
* Free the provided client and all it's resources including
106
139
* any handles it is holding.
107
140
*/
108
- void ion_client_destroy (struct ion_client * client );
141
+ static inline void ion_client_destroy (struct ion_client * client )
142
+ {
143
+ }
109
144
110
145
/**
111
146
* ion_alloc - allocate ion memory
@@ -123,9 +158,14 @@ void ion_client_destroy(struct ion_client *client);
123
158
* Allocate memory in one of the heaps provided in heap mask and return
124
159
* an opaque handle to it.
125
160
*/
126
- struct ion_handle * ion_alloc (struct ion_client * client , size_t len ,
127
- size_t align , unsigned int heap_id_mask ,
128
- unsigned int flags );
161
+ struct ion_buffer * __ion_alloc (struct ion_device * idev , size_t len ,
162
+ size_t align , unsigned int heap_id_mask ,
163
+ unsigned int flags );
164
+ static inline void * ion_alloc (void * client , size_t len , size_t align ,
165
+ unsigned int heap_id_mask , unsigned int flags )
166
+ {
167
+ return __ion_alloc (client , len , align , heap_id_mask , flags );
168
+ }
129
169
130
170
/**
131
171
* ion_free - free a handle
@@ -134,7 +174,11 @@ struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
134
174
*
135
175
* Free the provided handle.
136
176
*/
137
- void ion_free (struct ion_client * client , struct ion_handle * handle );
177
+ void ion_buffer_put (struct ion_buffer * buffer );
178
+ static inline void ion_free (struct ion_client * client , void * handle )
179
+ {
180
+ ion_buffer_put (handle );
181
+ }
138
182
139
183
/**
140
184
* ion_phys - returns the physical address and len of a handle
@@ -152,19 +196,12 @@ void ion_free(struct ion_client *client, struct ion_handle *handle);
152
196
* the returned value may not be valid if the caller is not
153
197
* holding a reference.
154
198
*/
155
- int ion_phys (struct ion_client * client , struct ion_handle * handle ,
156
- ion_phys_addr_t * addr , size_t * len );
157
-
158
- /**
159
- * ion_map_dma - return an sg_table describing a handle
160
- * @client: the client
161
- * @handle: the handle
162
- *
163
- * This function returns the sg_table describing
164
- * a particular ion handle.
165
- */
166
- struct sg_table * ion_sg_table (struct ion_client * client ,
167
- struct ion_handle * handle );
199
+ int __ion_phys (struct ion_buffer * buffer , ion_phys_addr_t * addr , size_t * len );
200
+ static inline int ion_phys (struct ion_client * client , void * handle ,
201
+ ion_phys_addr_t * addr , size_t * len )
202
+ {
203
+ return __ion_phys (handle , addr , len );
204
+ }
168
205
169
206
/**
170
207
* ion_map_kernel - create mapping for the given handle
@@ -174,29 +211,45 @@ struct sg_table *ion_sg_table(struct ion_client *client,
174
211
* Map the given handle into the kernel and return a kernel address that
175
212
* can be used to access this address.
176
213
*/
177
- void * ion_map_kernel (struct ion_client * client , struct ion_handle * handle );
214
+ void * __ion_map_kernel (struct ion_buffer * buffer );
215
+ static inline void * ion_map_kernel (struct ion_client * client , void * handle )
216
+ {
217
+ return __ion_map_kernel (handle );
218
+ }
178
219
179
220
/**
180
221
* ion_unmap_kernel() - destroy a kernel mapping for a handle
181
222
* @client: the client
182
223
* @handle: handle to unmap
183
224
*/
184
- void ion_unmap_kernel (struct ion_client * client , struct ion_handle * handle );
225
+ void __ion_unmap_kernel (struct ion_buffer * buffer );
226
+ static inline void ion_unmap_kernel (struct ion_client * client , void * handle )
227
+ {
228
+ __ion_unmap_kernel (handle );
229
+ }
185
230
186
231
/**
187
232
* ion_share_dma_buf() - share buffer as dma-buf
188
233
* @client: the client
189
234
* @handle: the handle
190
235
*/
191
- struct dma_buf * ion_share_dma_buf (struct ion_client * client ,
192
- struct ion_handle * handle );
236
+ struct dma_buf * __ion_share_dma_buf (struct ion_buffer * buffer );
237
+ static inline struct dma_buf * ion_share_dma_buf (struct ion_client * client ,
238
+ void * handle )
239
+ {
240
+ return __ion_share_dma_buf (handle );
241
+ }
193
242
194
243
/**
195
244
* ion_share_dma_buf_fd() - given an ion client, create a dma-buf fd
196
245
* @client: the client
197
246
* @handle: the handle
198
247
*/
199
- int ion_share_dma_buf_fd (struct ion_client * client , struct ion_handle * handle );
248
+ int __ion_share_dma_buf_fd (struct ion_buffer * buffer );
249
+ static inline int ion_share_dma_buf_fd (struct ion_client * client , void * handle )
250
+ {
251
+ return __ion_share_dma_buf_fd (handle );
252
+ }
200
253
201
254
/**
202
255
* ion_import_dma_buf() - given an dma-buf fd from the ion exporter get handle
@@ -207,7 +260,11 @@ int ion_share_dma_buf_fd(struct ion_client *client, struct ion_handle *handle);
207
260
* import that fd and return a handle representing it. If a dma-buf from
208
261
* another exporter is passed in this function will return ERR_PTR(-EINVAL)
209
262
*/
210
- struct ion_handle * ion_import_dma_buf (struct ion_client * client , int fd );
263
+ struct ion_buffer * __ion_import_dma_buf (int fd );
264
+ static inline void * ion_import_dma_buf (struct ion_client * client , int fd )
265
+ {
266
+ return __ion_import_dma_buf (fd );
267
+ }
211
268
212
269
#else
213
270
static inline void ion_reserve (struct ion_platform_data * data )
0 commit comments