1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * drivers/staging/android/uapi/ion.h (This is the ION Uapi prior kernel 4.12)
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_OLD_H
19 #define _UAPI_LINUX_ION_OLD_H
20 
21 /* All ION resources are prefixed ION0_ to ditinguish from companion new API */
22 
23 #include <linux/ioctl.h>
24 #include <linux/types.h>
25 
26 typedef int ion0_user_handle_t;
27 
28 /**
29  * struct ion0_allocation_data - metadata passed from userspace for allocations
30  * @len:		size of the allocation
31  * @align:		required alignment of the allocation
32  * @heap_id_mask:	mask of heap ids to allocate from
33  * @flags:		flags passed to heap
34  * @handle:		pointer that will be populated with a cookie to use to
35  *			refer to this allocation
36  *
37  * Provided by userspace as an argument to the ioctl
38  */
39 struct ion0_allocation_data {
40 	size_t len;
41 	size_t align;
42 	unsigned int heap_id_mask;
43 	unsigned int flags;
44 	ion0_user_handle_t handle;
45 };
46 
47 /**
48  * struct ion0_fd_data - metadata passed to/from userspace for a handle/fd pair
49  * @handle:	a handle
50  * @fd:		a file descriptor representing that handle
51  *
52  * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
53  * the handle returned from ion alloc, and the kernel returns the file
54  * descriptor to share or map in the fd field.  For ION_IOC_IMPORT, userspace
55  * provides the file descriptor and the kernel returns the handle.
56  */
57 struct ion0_fd_data {
58 	ion0_user_handle_t handle;
59 	int fd;
60 };
61 
62 /**
63  * struct ion0_handle_data - a handle passed to/from the kernel
64  * @handle:	a handle
65  */
66 struct ion0_handle_data {
67 	ion0_user_handle_t handle;
68 };
69 
70 /**
71  * struct ion0_custom_data - metadata passed to/from userspace for a custom ioctl
72  * @cmd:	the custom ioctl function to call
73  * @arg:	additional data to pass to the custom ioctl, typically a user
74  *		pointer to a predefined structure
75  *
76  * This works just like the regular cmd and arg fields of an ioctl.
77  */
78 struct ion0_custom_data {
79 	unsigned int cmd;
80 	unsigned long arg;
81 };
82 
83 /**
84  * DOC: ION_IOC_ALLOC - allocate memory
85  *
86  * Takes an ion_allocation_data struct and returns it with the handle field
87  * populated with the opaque handle for the allocation.
88  */
89 #define ION0_IOC_ALLOC		_IOWR(ION_IOC_MAGIC, 0, \
90 				      struct ion0_allocation_data)
91 /**
92  * DOC: ION_IOC_FREE - free memory
93  *
94  * Takes an ion_handle_data struct and frees the handle.
95  */
96 #define ION0_IOC_FREE		_IOWR(ION_IOC_MAGIC, 1, struct ion0_handle_data)
97 
98 /**
99  * DOC: ION_IOC_MAP - get a file descriptor to mmap
100  *
101  * Takes an ion0_fd_data struct with the handle field populated with a valid
102  * opaque handle.  Returns the struct with the fd field set to a file
103  * descriptor open in the current address space.  This file descriptor
104  * can then be used as an argument to mmap.
105  */
106 #define ION0_IOC_MAP		_IOWR(ION_IOC_MAGIC, 2, struct ion0_fd_data)
107 
108 /**
109  * DOC: ION_IOC_SHARE - creates a file descriptor to use to share an allocation
110  *
111  * Takes an ion_fd_data struct with the handle field populated with a valid
112  * opaque handle.  Returns the struct with the fd field set to a file
113  * descriptor open in the current address space.  This file descriptor
114  * can then be passed to another process.  The corresponding opaque handle can
115  * be retrieved via ION_IOC_IMPORT.
116  */
117 #define ION0_IOC_SHARE		_IOWR(ION_IOC_MAGIC, 4, struct ion0_fd_data)
118 
119 /**
120  * DOC: ION_IOC_IMPORT - imports a shared file descriptor
121  *
122  * Takes an ion0_fd_data struct with the fd field populated with a valid file
123  * descriptor obtained from ION_IOC_SHARE and returns the struct with the handle
124  * filed set to the corresponding opaque handle.
125  */
126 #define ION0_IOC_IMPORT		_IOWR(ION_IOC_MAGIC, 5, struct ion0_fd_data)
127 
128 /**
129  * DOC: ION_IOC_SYNC - syncs a shared file descriptors to memory
130  *
131  * Deprecated in favor of using the dma_buf api's correctly (syncing
132  * will happen automatically when the buffer is mapped to a device).
133  * If necessary should be used after touching a cached buffer from the cpu,
134  * this will make the buffer in memory coherent.
135  */
136 #define ION0_IOC_SYNC		_IOWR(ION_IOC_MAGIC, 7, struct ion0_fd_data)
137 
138 /**
139  * DOC: ION_IOC_CUSTOM - call architecture specific ion ioctl
140  *
141  * Takes the argument of the architecture specific ioctl to call and
142  * passes appropriate userdata for that ioctl
143  */
144 #define ION0_IOC_CUSTOM		_IOWR(ION_IOC_MAGIC, 6, struct ion0_custom_data)
145 
146 #endif /* _UAPI_LINUX_ION_OLD_H */
147