xref: /rockchip-linux_mpp/osal/allocator/ion.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1*437bfbebSnyanmisaka /*
2*437bfbebSnyanmisaka  * include/linux/ion.h
3*437bfbebSnyanmisaka  *
4*437bfbebSnyanmisaka  * Copyright (C) 2011 Google, Inc.
5*437bfbebSnyanmisaka  *
6*437bfbebSnyanmisaka  * This software is licensed under the terms of the GNU General Public
7*437bfbebSnyanmisaka  * License version 2, as published by the Free Software Foundation, and
8*437bfbebSnyanmisaka  * may be copied, distributed, and modified under those terms.
9*437bfbebSnyanmisaka  *
10*437bfbebSnyanmisaka  * This program is distributed in the hope that it will be useful,
11*437bfbebSnyanmisaka  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*437bfbebSnyanmisaka  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*437bfbebSnyanmisaka  * GNU General Public License for more details.
14*437bfbebSnyanmisaka  *
15*437bfbebSnyanmisaka  */
16*437bfbebSnyanmisaka 
17*437bfbebSnyanmisaka #ifndef _LINUX_ION_H
18*437bfbebSnyanmisaka #define _LINUX_ION_H
19*437bfbebSnyanmisaka 
20*437bfbebSnyanmisaka #include <linux/types.h>
21*437bfbebSnyanmisaka #define ION_VERSION     "1.0"
22*437bfbebSnyanmisaka 
23*437bfbebSnyanmisaka typedef int ion_user_handle_t;
24*437bfbebSnyanmisaka 
25*437bfbebSnyanmisaka /**
26*437bfbebSnyanmisaka  * enum ion_heap_types - list of all possible types of heaps
27*437bfbebSnyanmisaka  * @ION_HEAP_TYPE_SYSTEM:    memory allocated via vmalloc
28*437bfbebSnyanmisaka  * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
29*437bfbebSnyanmisaka  * @ION_HEAP_TYPE_CARVEOUT:  memory allocated from a prereserved
30*437bfbebSnyanmisaka  *               carveout heap, allocations are physically
31*437bfbebSnyanmisaka  *               contiguous
32*437bfbebSnyanmisaka  * @ION_HEAP_TYPE_DMA:       memory allocated via DMA API
33*437bfbebSnyanmisaka  * @ION_NUM_HEAPS:       helper for iterating over heaps, a bit mask
34*437bfbebSnyanmisaka  *               is used to identify the heaps, so only 32
35*437bfbebSnyanmisaka  *               total heap types are supported
36*437bfbebSnyanmisaka  */
37*437bfbebSnyanmisaka enum ion_heap_type {
38*437bfbebSnyanmisaka     ION_HEAP_TYPE_SYSTEM,
39*437bfbebSnyanmisaka     ION_HEAP_TYPE_SYSTEM_CONTIG,
40*437bfbebSnyanmisaka     ION_HEAP_TYPE_CARVEOUT,
41*437bfbebSnyanmisaka     ION_HEAP_TYPE_CHUNK,
42*437bfbebSnyanmisaka     ION_HEAP_TYPE_DMA,
43*437bfbebSnyanmisaka     ION_HEAP_TYPE_CUSTOM, /* must be last so device specific heaps always
44*437bfbebSnyanmisaka                  are at the end of this enum */
45*437bfbebSnyanmisaka     ION_NUM_HEAPS = 16,
46*437bfbebSnyanmisaka };
47*437bfbebSnyanmisaka enum ion_heap_ids {
48*437bfbebSnyanmisaka     ION_NOR_HEAP_ID = 0,
49*437bfbebSnyanmisaka     ION_CMA_HEAP_ID = 1,
50*437bfbebSnyanmisaka 
51*437bfbebSnyanmisaka     ION_VPU_ID = 16,
52*437bfbebSnyanmisaka     ION_CAM_ID = 17,
53*437bfbebSnyanmisaka     ION_UI_ID = 18,
54*437bfbebSnyanmisaka };
55*437bfbebSnyanmisaka 
56*437bfbebSnyanmisaka #define ION_HEAP_SYSTEM_MASK        (1 << ION_HEAP_TYPE_SYSTEM)
57*437bfbebSnyanmisaka #define ION_HEAP_SYSTEM_CONTIG_MASK (1 << ION_HEAP_TYPE_SYSTEM_CONTIG)
58*437bfbebSnyanmisaka #define ION_HEAP_CARVEOUT_MASK      (1 << ION_HEAP_TYPE_CARVEOUT)
59*437bfbebSnyanmisaka #define ION_HEAP_TYPE_DMA_MASK      (1 << ION_HEAP_TYPE_DMA)
60*437bfbebSnyanmisaka 
61*437bfbebSnyanmisaka #ifdef __KERNEL__
62*437bfbebSnyanmisaka struct ion_device;
63*437bfbebSnyanmisaka struct ion_heap;
64*437bfbebSnyanmisaka struct ion_mapper;
65*437bfbebSnyanmisaka struct ion_client;
66*437bfbebSnyanmisaka struct ion_buffer;
67*437bfbebSnyanmisaka 
68*437bfbebSnyanmisaka /* This should be removed some day when phys_addr_t's are fully
69*437bfbebSnyanmisaka    plumbed in the kernel, and all instances of ion_phys_addr_t should
70*437bfbebSnyanmisaka    be converted to phys_addr_t.  For the time being many kernel interfaces
71*437bfbebSnyanmisaka    do not accept phys_addr_t's that would have to */
72*437bfbebSnyanmisaka #define ion_phys_addr_t unsigned long
73*437bfbebSnyanmisaka 
74*437bfbebSnyanmisaka /**
75*437bfbebSnyanmisaka  * struct ion_platform_heap - defines a heap in the given platform
76*437bfbebSnyanmisaka  * @type:   type of the heap from ion_heap_type enum
77*437bfbebSnyanmisaka  * @id:     unique identifier for heap.  When allocating (lower numbers
78*437bfbebSnyanmisaka  *      will be allocated from first)
79*437bfbebSnyanmisaka  * @name:   used for debug purposes
80*437bfbebSnyanmisaka  * @base:   base address of heap in physical memory if applicable
81*437bfbebSnyanmisaka  * @size:   size of the heap in bytes if applicable
82*437bfbebSnyanmisaka  *
83*437bfbebSnyanmisaka  * Provided by the board file.
84*437bfbebSnyanmisaka  */
85*437bfbebSnyanmisaka struct ion_platform_heap {
86*437bfbebSnyanmisaka     enum ion_heap_type type;
87*437bfbebSnyanmisaka     unsigned int id;
88*437bfbebSnyanmisaka     const char *name;
89*437bfbebSnyanmisaka     ion_phys_addr_t base;
90*437bfbebSnyanmisaka     size_t size;
91*437bfbebSnyanmisaka };
92*437bfbebSnyanmisaka 
93*437bfbebSnyanmisaka /**
94*437bfbebSnyanmisaka  * struct ion_platform_data - array of platform heaps passed from board file
95*437bfbebSnyanmisaka  * @nr:     number of structures in the array
96*437bfbebSnyanmisaka  * @heaps:  array of platform_heap structions
97*437bfbebSnyanmisaka  *
98*437bfbebSnyanmisaka  * Provided by the board file in the form of platform data to a platform device.
99*437bfbebSnyanmisaka  */
100*437bfbebSnyanmisaka struct ion_platform_data {
101*437bfbebSnyanmisaka     int nr;
102*437bfbebSnyanmisaka     struct ion_platform_heap heaps[];
103*437bfbebSnyanmisaka };
104*437bfbebSnyanmisaka 
105*437bfbebSnyanmisaka /**
106*437bfbebSnyanmisaka  * ion_client_create() -  allocate a client and returns it
107*437bfbebSnyanmisaka  * @dev:    the global ion device
108*437bfbebSnyanmisaka  * @heap_mask:  mask of heaps this client can allocate from
109*437bfbebSnyanmisaka  * @name:   used for debugging
110*437bfbebSnyanmisaka  */
111*437bfbebSnyanmisaka struct ion_client *ion_client_create(struct ion_device *dev,
112*437bfbebSnyanmisaka                                      unsigned int heap_mask, const char *name);
113*437bfbebSnyanmisaka 
114*437bfbebSnyanmisaka /**
115*437bfbebSnyanmisaka  * ion_client_destroy() -  free's a client and all it's handles
116*437bfbebSnyanmisaka  * @client: the client
117*437bfbebSnyanmisaka  *
118*437bfbebSnyanmisaka  * Free the provided client and all it's resources including
119*437bfbebSnyanmisaka  * any handles it is holding.
120*437bfbebSnyanmisaka  */
121*437bfbebSnyanmisaka void ion_client_destroy(struct ion_client *client);
122*437bfbebSnyanmisaka 
123*437bfbebSnyanmisaka /**
124*437bfbebSnyanmisaka  * ion_alloc - allocate ion memory
125*437bfbebSnyanmisaka  * @client: the client
126*437bfbebSnyanmisaka  * @len:    size of the allocation
127*437bfbebSnyanmisaka  * @align:  requested allocation alignment, lots of hardware blocks have
128*437bfbebSnyanmisaka  *      alignment requirements of some kind
129*437bfbebSnyanmisaka  * @flags:  mask of heaps to allocate from, if multiple bits are set
130*437bfbebSnyanmisaka  *      heaps will be tried in order from lowest to highest order bit
131*437bfbebSnyanmisaka  *
132*437bfbebSnyanmisaka  * Allocate memory in one of the heaps provided in heap mask and return
133*437bfbebSnyanmisaka  * an opaque handle to it.
134*437bfbebSnyanmisaka  */
135*437bfbebSnyanmisaka struct ion_handle *ion_alloc(struct ion_client *client, size_t len,
136*437bfbebSnyanmisaka                              size_t align, unsigned int flags);
137*437bfbebSnyanmisaka 
138*437bfbebSnyanmisaka /**
139*437bfbebSnyanmisaka  * ion_free - free a handle
140*437bfbebSnyanmisaka  * @client: the client
141*437bfbebSnyanmisaka  * @handle: the handle to free
142*437bfbebSnyanmisaka  *
143*437bfbebSnyanmisaka  * Free the provided handle.
144*437bfbebSnyanmisaka  */
145*437bfbebSnyanmisaka void ion_free(struct ion_client *client, struct ion_handle *handle);
146*437bfbebSnyanmisaka 
147*437bfbebSnyanmisaka /**
148*437bfbebSnyanmisaka  * ion_phys - returns the physical address and len of a handle
149*437bfbebSnyanmisaka  * @client: the client
150*437bfbebSnyanmisaka  * @handle: the handle
151*437bfbebSnyanmisaka  * @addr:   a pointer to put the address in
152*437bfbebSnyanmisaka  * @len:    a pointer to put the length in
153*437bfbebSnyanmisaka  *
154*437bfbebSnyanmisaka  * This function queries the heap for a particular handle to get the
155*437bfbebSnyanmisaka  * handle's physical address.  It't output is only correct if
156*437bfbebSnyanmisaka  * a heap returns physically contiguous memory -- in other cases
157*437bfbebSnyanmisaka  * this api should not be implemented -- ion_map_dma should be used
158*437bfbebSnyanmisaka  * instead.  Returns -EINVAL if the handle is invalid.  This has
159*437bfbebSnyanmisaka  * no implications on the reference counting of the handle --
160*437bfbebSnyanmisaka  * the returned value may not be valid if the caller is not
161*437bfbebSnyanmisaka  * holding a reference.
162*437bfbebSnyanmisaka  */
163*437bfbebSnyanmisaka int ion_phys(struct ion_client *client, struct ion_handle *handle,
164*437bfbebSnyanmisaka              ion_phys_addr_t *addr, size_t *len);
165*437bfbebSnyanmisaka 
166*437bfbebSnyanmisaka /**
167*437bfbebSnyanmisaka  * ion_map_kernel - create mapping for the given handle
168*437bfbebSnyanmisaka  * @client: the client
169*437bfbebSnyanmisaka  * @handle: handle to map
170*437bfbebSnyanmisaka  *
171*437bfbebSnyanmisaka  * Map the given handle into the kernel and return a kernel address that
172*437bfbebSnyanmisaka  * can be used to access this address.
173*437bfbebSnyanmisaka  */
174*437bfbebSnyanmisaka void *ion_map_kernel(struct ion_client *client, struct ion_handle *handle);
175*437bfbebSnyanmisaka 
176*437bfbebSnyanmisaka /**
177*437bfbebSnyanmisaka  * ion_unmap_kernel() - destroy a kernel mapping for a handle
178*437bfbebSnyanmisaka  * @client: the client
179*437bfbebSnyanmisaka  * @handle: handle to unmap
180*437bfbebSnyanmisaka  */
181*437bfbebSnyanmisaka void ion_unmap_kernel(struct ion_client *client, struct ion_handle *handle);
182*437bfbebSnyanmisaka 
183*437bfbebSnyanmisaka /**
184*437bfbebSnyanmisaka  * ion_map_dma - create a dma mapping for a given handle
185*437bfbebSnyanmisaka  * @client: the client
186*437bfbebSnyanmisaka  * @handle: handle to map
187*437bfbebSnyanmisaka  *
188*437bfbebSnyanmisaka  * Return an sglist describing the given handle
189*437bfbebSnyanmisaka  */
190*437bfbebSnyanmisaka struct scatterlist *ion_map_dma(struct ion_client *client,
191*437bfbebSnyanmisaka                                 struct ion_handle *handle);
192*437bfbebSnyanmisaka 
193*437bfbebSnyanmisaka /**
194*437bfbebSnyanmisaka  * ion_unmap_dma() - destroy a dma mapping for a handle
195*437bfbebSnyanmisaka  * @client: the client
196*437bfbebSnyanmisaka  * @handle: handle to unmap
197*437bfbebSnyanmisaka  */
198*437bfbebSnyanmisaka void ion_unmap_dma(struct ion_client *client, struct ion_handle *handle);
199*437bfbebSnyanmisaka 
200*437bfbebSnyanmisaka /**
201*437bfbebSnyanmisaka  * ion_share() - given a handle, obtain a buffer to pass to other clients
202*437bfbebSnyanmisaka  * @client: the client
203*437bfbebSnyanmisaka  * @handle: the handle to share
204*437bfbebSnyanmisaka  *
205*437bfbebSnyanmisaka  * Given a handle, return a buffer, which exists in a global name
206*437bfbebSnyanmisaka  * space, and can be passed to other clients.  Should be passed into ion_import
207*437bfbebSnyanmisaka  * to obtain a new handle for this buffer.
208*437bfbebSnyanmisaka  *
209*437bfbebSnyanmisaka  * NOTE: This function does do not an extra reference.  The burden is on the
210*437bfbebSnyanmisaka  * caller to make sure the buffer doesn't go away while it's being passed to
211*437bfbebSnyanmisaka  * another client.  That is, ion_free should not be called on this handle until
212*437bfbebSnyanmisaka  * the buffer has been imported into the other client.
213*437bfbebSnyanmisaka  */
214*437bfbebSnyanmisaka struct ion_buffer *ion_share(struct ion_client *client,
215*437bfbebSnyanmisaka                              struct ion_handle *handle);
216*437bfbebSnyanmisaka 
217*437bfbebSnyanmisaka /**
218*437bfbebSnyanmisaka  * ion_import() - given an buffer in another client, import it
219*437bfbebSnyanmisaka  * @client: this blocks client
220*437bfbebSnyanmisaka  * @buffer: the buffer to import (as obtained from ion_share)
221*437bfbebSnyanmisaka  *
222*437bfbebSnyanmisaka  * Given a buffer, add it to the client and return the handle to use to refer
223*437bfbebSnyanmisaka  * to it further.  This is called to share a handle from one kernel client to
224*437bfbebSnyanmisaka  * another.
225*437bfbebSnyanmisaka  */
226*437bfbebSnyanmisaka struct ion_handle *ion_import(struct ion_client *client,
227*437bfbebSnyanmisaka                               struct ion_buffer *buffer);
228*437bfbebSnyanmisaka 
229*437bfbebSnyanmisaka /**
230*437bfbebSnyanmisaka  * ion_import_fd() - given an fd obtained via ION_IOC_SHARE ioctl, import it
231*437bfbebSnyanmisaka  * @client: this blocks client
232*437bfbebSnyanmisaka  * @fd:     the fd
233*437bfbebSnyanmisaka  *
234*437bfbebSnyanmisaka  * A helper function for drivers that will be recieving ion buffers shared
235*437bfbebSnyanmisaka  * with them from userspace.  These buffers are represented by a file
236*437bfbebSnyanmisaka  * descriptor obtained as the return from the ION_IOC_SHARE ioctl.
237*437bfbebSnyanmisaka  * This function coverts that fd into the underlying buffer, and returns
238*437bfbebSnyanmisaka  * the handle to use to refer to it further.
239*437bfbebSnyanmisaka  */
240*437bfbebSnyanmisaka struct ion_handle *ion_import_fd(struct ion_client *client, int fd);
241*437bfbebSnyanmisaka #endif /* __KERNEL__ */
242*437bfbebSnyanmisaka 
243*437bfbebSnyanmisaka /**
244*437bfbebSnyanmisaka  * DOC: Ion Userspace API
245*437bfbebSnyanmisaka  *
246*437bfbebSnyanmisaka  * create a client by opening /dev/ion
247*437bfbebSnyanmisaka  * most operations handled via following ioctls
248*437bfbebSnyanmisaka  *
249*437bfbebSnyanmisaka  */
250*437bfbebSnyanmisaka 
251*437bfbebSnyanmisaka /**
252*437bfbebSnyanmisaka  * struct ion_allocation_data - metadata passed from userspace for allocations
253*437bfbebSnyanmisaka  * @len:    size of the allocation
254*437bfbebSnyanmisaka  * @align:  required alignment of the allocation
255*437bfbebSnyanmisaka  * @flags:  flags passed to heap
256*437bfbebSnyanmisaka  * @handle: pointer that will be populated with a cookie to use to refer
257*437bfbebSnyanmisaka  *      to this allocation
258*437bfbebSnyanmisaka  *
259*437bfbebSnyanmisaka  * Provided by userspace as an argument to the ioctl
260*437bfbebSnyanmisaka  */
261*437bfbebSnyanmisaka struct ion_allocation_data {
262*437bfbebSnyanmisaka     size_t len;
263*437bfbebSnyanmisaka     size_t align;
264*437bfbebSnyanmisaka     unsigned int heap_id_mask;
265*437bfbebSnyanmisaka     unsigned int flags;
266*437bfbebSnyanmisaka     ion_user_handle_t handle;
267*437bfbebSnyanmisaka };
268*437bfbebSnyanmisaka 
269*437bfbebSnyanmisaka /**
270*437bfbebSnyanmisaka  * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
271*437bfbebSnyanmisaka  * @handle: a handle
272*437bfbebSnyanmisaka  * @fd:     a file descriptor representing that handle
273*437bfbebSnyanmisaka  *
274*437bfbebSnyanmisaka  * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
275*437bfbebSnyanmisaka  * the handle returned from ion alloc, and the kernel returns the file
276*437bfbebSnyanmisaka  * descriptor to share or map in the fd field.  For ION_IOC_IMPORT, userspace
277*437bfbebSnyanmisaka  * provides the file descriptor and the kernel returns the handle.
278*437bfbebSnyanmisaka  */
279*437bfbebSnyanmisaka struct ion_fd_data {
280*437bfbebSnyanmisaka     ion_user_handle_t handle;
281*437bfbebSnyanmisaka     int fd;
282*437bfbebSnyanmisaka };
283*437bfbebSnyanmisaka 
284*437bfbebSnyanmisaka /**
285*437bfbebSnyanmisaka  * struct ion_handle_data - a handle passed to/from the kernel
286*437bfbebSnyanmisaka  * @handle: a handle
287*437bfbebSnyanmisaka  */
288*437bfbebSnyanmisaka struct ion_handle_data {
289*437bfbebSnyanmisaka     ion_user_handle_t handle;
290*437bfbebSnyanmisaka };
291*437bfbebSnyanmisaka 
292*437bfbebSnyanmisaka /**
293*437bfbebSnyanmisaka  * struct ion_custom_data - metadata passed to/from userspace for a custom ioctl
294*437bfbebSnyanmisaka  * @cmd:    the custom ioctl function to call
295*437bfbebSnyanmisaka  * @arg:    additional data to pass to the custom ioctl, typically a user
296*437bfbebSnyanmisaka  *      pointer to a predefined structure
297*437bfbebSnyanmisaka  *
298*437bfbebSnyanmisaka  * This works just like the regular cmd and arg fields of an ioctl.
299*437bfbebSnyanmisaka  */
300*437bfbebSnyanmisaka struct ion_custom_data {
301*437bfbebSnyanmisaka     unsigned int cmd;
302*437bfbebSnyanmisaka     unsigned long arg;
303*437bfbebSnyanmisaka };
304*437bfbebSnyanmisaka 
305*437bfbebSnyanmisaka /* struct ion_flush_data - data passed to ion for flushing caches
306*437bfbebSnyanmisaka  *
307*437bfbebSnyanmisaka  * @handle: handle with data to flush
308*437bfbebSnyanmisaka  * @fd:     fd to flush
309*437bfbebSnyanmisaka  * @vaddr:  userspace virtual address mapped with mmap
310*437bfbebSnyanmisaka  * @offset: offset into the handle to flush
311*437bfbebSnyanmisaka  * @length: length of handle to flush
312*437bfbebSnyanmisaka  *
313*437bfbebSnyanmisaka  * Performs cache operations on the handle. If p is the start address
314*437bfbebSnyanmisaka  * of the handle, p + offset through p + offset + length will have
315*437bfbebSnyanmisaka  * the cache operations performed
316*437bfbebSnyanmisaka  */
317*437bfbebSnyanmisaka struct ion_flush_data {
318*437bfbebSnyanmisaka     //struct ion_handle *handle;
319*437bfbebSnyanmisaka     ion_user_handle_t handle;
320*437bfbebSnyanmisaka     int fd;
321*437bfbebSnyanmisaka     void *vaddr;
322*437bfbebSnyanmisaka     unsigned int offset;
323*437bfbebSnyanmisaka     unsigned int length;
324*437bfbebSnyanmisaka };
325*437bfbebSnyanmisaka 
326*437bfbebSnyanmisaka /// no available in new ion-kernel
327*437bfbebSnyanmisaka struct ion_phys_data {
328*437bfbebSnyanmisaka     //struct ion_handle *handle;
329*437bfbebSnyanmisaka     ion_user_handle_t handle;
330*437bfbebSnyanmisaka     unsigned long phys;
331*437bfbebSnyanmisaka     unsigned long size;
332*437bfbebSnyanmisaka };
333*437bfbebSnyanmisaka 
334*437bfbebSnyanmisaka struct ion_cacheop_data {
335*437bfbebSnyanmisaka #define ION_CACHE_FLUSH     0
336*437bfbebSnyanmisaka #define ION_CACHE_CLEAN     1
337*437bfbebSnyanmisaka #define ION_CACHE_INV       2
338*437bfbebSnyanmisaka     unsigned int type;
339*437bfbebSnyanmisaka     struct ion_handle *handle;
340*437bfbebSnyanmisaka     void *virt;
341*437bfbebSnyanmisaka };
342*437bfbebSnyanmisaka struct ion_buffer_info {
343*437bfbebSnyanmisaka     unsigned long phys;
344*437bfbebSnyanmisaka     unsigned long size;
345*437bfbebSnyanmisaka };
346*437bfbebSnyanmisaka struct ion_client_info {
347*437bfbebSnyanmisaka #define MAX_BUFFER_COUNT    127
348*437bfbebSnyanmisaka     unsigned int count;
349*437bfbebSnyanmisaka     unsigned long total_size;
350*437bfbebSnyanmisaka     struct ion_buffer_info buf[MAX_BUFFER_COUNT];
351*437bfbebSnyanmisaka };
352*437bfbebSnyanmisaka struct ion_heap_info {
353*437bfbebSnyanmisaka     unsigned int id;
354*437bfbebSnyanmisaka     unsigned long allocated_size;
355*437bfbebSnyanmisaka     unsigned long max_allocated;
356*437bfbebSnyanmisaka     unsigned long total_size;
357*437bfbebSnyanmisaka };
358*437bfbebSnyanmisaka 
359*437bfbebSnyanmisaka struct ion_share_obj_data {
360*437bfbebSnyanmisaka     int fd;
361*437bfbebSnyanmisaka     void *obj;
362*437bfbebSnyanmisaka };
363*437bfbebSnyanmisaka ///////////////////////////////////////////////////
364*437bfbebSnyanmisaka 
365*437bfbebSnyanmisaka #define ION_IOC_MAGIC       'I'
366*437bfbebSnyanmisaka 
367*437bfbebSnyanmisaka /**
368*437bfbebSnyanmisaka  * DOC: ION_IOC_ALLOC - allocate memory
369*437bfbebSnyanmisaka  *
370*437bfbebSnyanmisaka  * Takes an ion_allocation_data struct and returns it with the handle field
371*437bfbebSnyanmisaka  * populated with the opaque handle for the allocation.
372*437bfbebSnyanmisaka  */
373*437bfbebSnyanmisaka #define ION_IOC_ALLOC       _IOWR(ION_IOC_MAGIC, 0, \
374*437bfbebSnyanmisaka                       struct ion_allocation_data)
375*437bfbebSnyanmisaka 
376*437bfbebSnyanmisaka /**
377*437bfbebSnyanmisaka  * DOC: ION_IOC_FREE - free memory
378*437bfbebSnyanmisaka  *
379*437bfbebSnyanmisaka  * Takes an ion_handle_data struct and frees the handle.
380*437bfbebSnyanmisaka  */
381*437bfbebSnyanmisaka #define ION_IOC_FREE        _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
382*437bfbebSnyanmisaka 
383*437bfbebSnyanmisaka /**
384*437bfbebSnyanmisaka  * DOC: ION_IOC_MAP - get a file descriptor to mmap
385*437bfbebSnyanmisaka  *
386*437bfbebSnyanmisaka  * Takes an ion_fd_data struct with the handle field populated with a valid
387*437bfbebSnyanmisaka  * opaque handle.  Returns the struct with the fd field set to a file
388*437bfbebSnyanmisaka  * descriptor open in the current address space.  This file descriptor
389*437bfbebSnyanmisaka  * can then be used as an argument to mmap.
390*437bfbebSnyanmisaka  */
391*437bfbebSnyanmisaka #define ION_IOC_MAP     _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
392*437bfbebSnyanmisaka 
393*437bfbebSnyanmisaka /**
394*437bfbebSnyanmisaka  * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
395*437bfbebSnyanmisaka  *
396*437bfbebSnyanmisaka  * Takes an ion_fd_data struct with the handle field populated with a valid
397*437bfbebSnyanmisaka  * opaque handle.  Returns the struct with the fd field set to a file
398*437bfbebSnyanmisaka  * descriptor open in the current address space.  This file descriptor
399*437bfbebSnyanmisaka  * can then be passed to another process.  The corresponding opaque handle can
400*437bfbebSnyanmisaka  * be retrieved via ION_IOC_IMPORT.
401*437bfbebSnyanmisaka  */
402*437bfbebSnyanmisaka #define ION_IOC_SHARE       _IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
403*437bfbebSnyanmisaka 
404*437bfbebSnyanmisaka /**
405*437bfbebSnyanmisaka  * DOC: ION_IOC_IMPORT - imports a shared file descriptor
406*437bfbebSnyanmisaka  *
407*437bfbebSnyanmisaka  * Takes an ion_fd_data struct with the fd field populated with a valid file
408*437bfbebSnyanmisaka  * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
409*437bfbebSnyanmisaka  * filed set to the corresponding opaque handle.
410*437bfbebSnyanmisaka  */
411*437bfbebSnyanmisaka #define ION_IOC_IMPORT      _IOWR(ION_IOC_MAGIC, 5, struct ion_fd_data)
412*437bfbebSnyanmisaka 
413*437bfbebSnyanmisaka /**
414*437bfbebSnyanmisaka  * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
415*437bfbebSnyanmisaka  *
416*437bfbebSnyanmisaka  * Deprecated in favor of using the dma_buf api's correctly (syncing
417*437bfbebSnyanmisaka  * will happend automatically when the buffer is mapped to a device).
418*437bfbebSnyanmisaka  * If necessary should be used after touching a cached buffer from the cpu,
419*437bfbebSnyanmisaka  * this will make the buffer in memory coherent.
420*437bfbebSnyanmisaka  */
421*437bfbebSnyanmisaka #define ION_IOC_SYNC        _IOWR(ION_IOC_MAGIC, 7, struct ion_fd_data)
422*437bfbebSnyanmisaka 
423*437bfbebSnyanmisaka /**
424*437bfbebSnyanmisaka  * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
425*437bfbebSnyanmisaka  *
426*437bfbebSnyanmisaka  * Takes the argument of the architecture specific ioctl to call and
427*437bfbebSnyanmisaka  * passes appropriate userdata for that ioctl
428*437bfbebSnyanmisaka  */
429*437bfbebSnyanmisaka #define ION_IOC_CUSTOM          _IOWR(ION_IOC_MAGIC, 6, struct ion_custom_data)
430*437bfbebSnyanmisaka 
431*437bfbebSnyanmisaka 
432*437bfbebSnyanmisaka #if 1
433*437bfbebSnyanmisaka #define ION_IOC_ROCKCHIP_MAGIC 'R'
434*437bfbebSnyanmisaka 
435*437bfbebSnyanmisaka /**
436*437bfbebSnyanmisaka  * Clean the caches of the handle specified.
437*437bfbebSnyanmisaka  */
438*437bfbebSnyanmisaka #define ION_IOC_CLEAN_CACHES    _IOWR(ION_IOC_ROCKCHIP_MAGIC, 0, \
439*437bfbebSnyanmisaka                         struct ion_flush_data)
440*437bfbebSnyanmisaka /**
441*437bfbebSnyanmisaka  * Invalidate the caches of the handle specified.
442*437bfbebSnyanmisaka  */
443*437bfbebSnyanmisaka #define ION_IOC_INV_CACHES  _IOWR(ION_IOC_ROCKCHIP_MAGIC, 1, \
444*437bfbebSnyanmisaka                         struct ion_flush_data)
445*437bfbebSnyanmisaka /**
446*437bfbebSnyanmisaka  * Clean and invalidate the caches of the handle specified.
447*437bfbebSnyanmisaka  */
448*437bfbebSnyanmisaka #define ION_IOC_CLEAN_INV_CACHES    _IOWR(ION_IOC_ROCKCHIP_MAGIC, 2, \
449*437bfbebSnyanmisaka                         struct ion_flush_data)
450*437bfbebSnyanmisaka 
451*437bfbebSnyanmisaka /**
452*437bfbebSnyanmisaka  * Get phys addr of the handle specified.
453*437bfbebSnyanmisaka  */
454*437bfbebSnyanmisaka #define ION_IOC_GET_PHYS    _IOWR(ION_IOC_ROCKCHIP_MAGIC, 3, \
455*437bfbebSnyanmisaka                         struct ion_phys_data)
456*437bfbebSnyanmisaka 
457*437bfbebSnyanmisaka #define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_ROCKCHIP_MAGIC, 0,   struct ion_flush_data)
458*437bfbebSnyanmisaka #define ION_IOC_INV_CACHES _IOWR(ION_IOC_ROCKCHIP_MAGIC, 1,   struct ion_flush_data)
459*437bfbebSnyanmisaka /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
460*437bfbebSnyanmisaka #define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_ROCKCHIP_MAGIC, 2,   struct ion_flush_data)
461*437bfbebSnyanmisaka 
462*437bfbebSnyanmisaka #define ION_IOC_GET_SHARE _IOWR(ION_IOC_ROCKCHIP_MAGIC, 4, struct ion_share_obj_data)
463*437bfbebSnyanmisaka #define ION_IOC_SET_SHARE _IOWR(ION_IOC_ROCKCHIP_MAGIC, 5, struct ion_share_obj_data)
464*437bfbebSnyanmisaka 
465*437bfbebSnyanmisaka #else
466*437bfbebSnyanmisaka /// no available in new ion-kernel.
467*437bfbebSnyanmisaka #define ION_CUSTOM_GET_PHYS     _IOWR(ION_IOC_MAGIC, 15, \
468*437bfbebSnyanmisaka                             struct ion_phys_data)
469*437bfbebSnyanmisaka 
470*437bfbebSnyanmisaka #define ION_CUSTOM_CACHE_OP     _IOWR(ION_IOC_MAGIC, 8, \
471*437bfbebSnyanmisaka                             struct ion_cacheop_data)
472*437bfbebSnyanmisaka 
473*437bfbebSnyanmisaka #define ION_CUSTOM_GET_CLIENT_INFO  _IOWR(ION_IOC_MAGIC, 9, \
474*437bfbebSnyanmisaka                             struct ion_client_info)
475*437bfbebSnyanmisaka 
476*437bfbebSnyanmisaka #define ION_CUSTOM_GET_HEAP_INFO    _IOWR(ION_IOC_MAGIC, 10, \
477*437bfbebSnyanmisaka                             struct ion_heap_info)
478*437bfbebSnyanmisaka /* Compatible with pmem */
479*437bfbebSnyanmisaka struct ion_pmem_region {
480*437bfbebSnyanmisaka     unsigned long offset;
481*437bfbebSnyanmisaka     unsigned long len;
482*437bfbebSnyanmisaka };
483*437bfbebSnyanmisaka #define ION_PMEM_GET_PHYS       _IOW('p', 1, unsigned int)
484*437bfbebSnyanmisaka #define ION_PMEM_CACHE_FLUSH        _IOW('p', 8, unsigned int)
485*437bfbebSnyanmisaka #endif
486*437bfbebSnyanmisaka ///////////////////////////////////////////
487*437bfbebSnyanmisaka 
488*437bfbebSnyanmisaka #endif /* _LINUX_ION_H */
489