1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * drivers/staging/android/uapi/ion.h
4  *
5  * Copyright (C) 2011 Google, Inc.
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17 
18 #ifndef _UAPI_LINUX_ION_H
19 #define _UAPI_LINUX_ION_H
20 
21 #include <linux/ioctl.h>
22 #include <linux/types.h>
23 
24 /**
25  * enum ion_heap_types - list of all possible types of heaps
26  * @ION_HEAP_TYPE_SYSTEM:	 memory allocated via vmalloc
27  * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
28  * @ION_HEAP_TYPE_CARVEOUT:	 memory allocated from a prereserved
29  *				 carveout heap, allocations are physically
30  *				 contiguous
31  * @ION_HEAP_TYPE_DMA:		 memory allocated via DMA API
32  * @ION_HEAP_TYPE_UNMAPPED:	 memory not intended to be mapped into the
33  *				 linux address space unless for debug cases
34  * @ION_NUM_HEAPS:		 helper for iterating over heaps, a bit mask
35  *				 is used to identify the heaps, so only 32
36  *				 total heap types are supported
37  */
38 enum ion_heap_type {
39 	ION_HEAP_TYPE_SYSTEM,
40 	ION_HEAP_TYPE_SYSTEM_CONTIG,
41 	ION_HEAP_TYPE_CARVEOUT,
42 	ION_HEAP_TYPE_CHUNK,
43 	ION_HEAP_TYPE_DMA,
44 	ION_HEAP_TYPE_UNMAPPED,
45 	ION_HEAP_TYPE_CUSTOM, /*
46 			       * must be last so device specific heaps always
47 			       * are at the end of this enum
48 			       */
49 };
50 
51 #define ION_NUM_HEAP_IDS		(sizeof(unsigned int) * 8)
52 
53 /**
54  * allocation flags - the lower 16 bits are used by core ion, the upper 16
55  * bits are reserved for use by the heaps themselves.
56  */
57 
58 /*
59  * mappings of this buffer should be cached, ion will do cache maintenance
60  * when the buffer is mapped for dma
61  */
62 #define ION_FLAG_CACHED 1
63 
64 /*
65  * mappings of this buffer will created at mmap time, if this is set
66  * caches must be managed manually
67  */
68 #define ION_FLAG_CACHED_NEEDS_SYNC 2
69 
70 /**
71  * DOC: Ion Userspace API
72  *
73  * create a client by opening /dev/ion
74  * most operations handled via following ioctls
75  *
76  */
77 
78 /**
79  * struct ion_allocation_data - metadata passed from userspace for allocations
80  * @len:		size of the allocation
81  * @heap_id_mask:	mask of heap ids to allocate from
82  * @flags:		flags passed to heap
83  * @handle:		pointer that will be populated with a cookie to use to
84  *			refer to this allocation
85  *
86  * Provided by userspace as an argument to the ioctl
87  */
88 struct ion_allocation_data {
89 	__u64 len;
90 	__u32 heap_id_mask;
91 	__u32 flags;
92 	__u32 fd;
93 	__u32 unused;
94 };
95 
96 #define MAX_HEAP_NAME			32
97 
98 /**
99  * struct ion_heap_data - data about a heap
100  * @name - first 32 characters of the heap name
101  * @type - heap type
102  * @heap_id - heap id for the heap
103  */
104 struct ion_heap_data {
105 	char name[MAX_HEAP_NAME];
106 	__u32 type;
107 	__u32 heap_id;
108 	__u32 reserved0;
109 	__u32 reserved1;
110 	__u32 reserved2;
111 };
112 
113 /**
114  * struct ion_heap_query - collection of data about all heaps
115  * @cnt - total number of heaps to be copied
116  * @heaps - buffer to copy heap data
117  */
118 struct ion_heap_query {
119 	__u32 cnt; /* Total number of heaps to be copied */
120 	__u32 reserved0; /* align to 64bits */
121 	__u64 heaps; /* buffer to be populated */
122 	__u32 reserved1;
123 	__u32 reserved2;
124 };
125 
126 #define ION_IOC_MAGIC		'I'
127 
128 /**
129  * DOC: ION_IOC_ALLOC - allocate memory
130  *
131  * Takes an ion_allocation_data struct and returns it with the handle field
132  * populated with the opaque handle for the allocation.
133  */
134 #define ION_IOC_ALLOC		_IOWR(ION_IOC_MAGIC, 0, \
135 				      struct ion_allocation_data)
136 
137 /**
138  * DOC: ION_IOC_FREE - free memory
139  *
140  * Takes an ion_handle_data struct and frees the handle.
141  */
142 #define ION_IOC_FREE		_IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
143 
144 /**
145  * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
146  *
147  * Takes an ion_fd_data struct with the handle field populated with a valid
148  * opaque handle.  Returns the struct with the fd field set to a file
149  * descriptor open in the current address space.  This file descriptor
150  * can then be passed to another process.  The corresponding opaque handle can
151  * be retrieved via ION_IOC_IMPORT.
152  */
153 #define ION_IOC_SHARE		_IOWR(ION_IOC_MAGIC, 4, struct ion_fd_data)
154 
155 /**
156  * DOC: ION_IOC_HEAP_QUERY - information about available heaps
157  *
158  * Takes an ion_heap_query structure and populates information about
159  * available Ion heaps.
160  */
161 #define ION_IOC_HEAP_QUERY     _IOWR(ION_IOC_MAGIC, 8, \
162 					struct ion_heap_query)
163 
164 #endif /* _UAPI_LINUX_ION_H */
165