1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#if !defined(__VMCS_SM_IOCTL_H__INCLUDED__)
29#define __VMCS_SM_IOCTL_H__INCLUDED__
30
31/* ---- Include Files ---------------------------------------------------- */
32
33#if defined(__KERNEL__)
34#include <linux/types.h> /* Needed for standard types */
35#else
36#include <stdint.h>
37#endif
38
39#include <linux/ioctl.h>
40
41/* ---- Constants and Types ---------------------------------------------- */
42
43#define VMCS_SM_RESOURCE_NAME 32
44#define VMCS_SM_RESOURCE_NAME_DEFAULT "sm-host-resource"
45
46/* Type define used to create unique IOCTL number */
47#define VMCS_SM_MAGIC_TYPE 'I'
48
49/* IOCTL commands */
50enum vmcs_sm_cmd_e {
51 VMCS_SM_CMD_ALLOC = 0x5A, /* Start at 0x5A arbitrarily */
52 VMCS_SM_CMD_ALLOC_SHARE,
53 VMCS_SM_CMD_LOCK,
54 VMCS_SM_CMD_LOCK_CACHE,
55 VMCS_SM_CMD_UNLOCK,
56 VMCS_SM_CMD_RESIZE,
57 VMCS_SM_CMD_UNMAP,
58 VMCS_SM_CMD_FREE,
59 VMCS_SM_CMD_FLUSH,
60 VMCS_SM_CMD_INVALID,
61
62 VMCS_SM_CMD_SIZE_USR_HANDLE,
63 VMCS_SM_CMD_CHK_USR_HANDLE,
64
65 VMCS_SM_CMD_MAPPED_USR_HANDLE,
66 VMCS_SM_CMD_MAPPED_USR_ADDRESS,
67 VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,
68 VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,
69 VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,
70
71 VMCS_SM_CMD_VC_WALK_ALLOC,
72 VMCS_SM_CMD_HOST_WALK_MAP,
73 VMCS_SM_CMD_HOST_WALK_PID_ALLOC,
74 VMCS_SM_CMD_HOST_WALK_PID_MAP,
75
76 VMCS_SM_CMD_CLEAN_INVALID,
77 VMCS_SM_CMD_CLEAN_INVALID2,
78
79 VMCS_SM_CMD_IMPORT_DMABUF,
80
81 VMCS_SM_CMD_LAST /* Do no delete */
82};
83
84/* Cache type supported, conveniently matches the user space definition in
85** user-vcsm.h.
86*/
87enum vmcs_sm_cache_e {
88 VMCS_SM_CACHE_NONE,
89 VMCS_SM_CACHE_HOST,
90 VMCS_SM_CACHE_VC,
91 VMCS_SM_CACHE_BOTH,
92};
93
94/* IOCTL Data structures */
95struct vmcs_sm_ioctl_alloc {
96 /* user -> kernel */
97 unsigned int size;
98 unsigned int num;
99 enum vmcs_sm_cache_e cached;
100 char name[VMCS_SM_RESOURCE_NAME];
101
102 /* kernel -> user */
103 unsigned int handle;
104 /* unsigned int base_addr; */
105};
106
107struct vmcs_sm_ioctl_alloc_share {
108 /* user -> kernel */
109 unsigned int handle;
110 unsigned int size;
111};
112
113struct vmcs_sm_ioctl_free {
114 /* user -> kernel */
115 unsigned int handle;
116 /* unsigned int base_addr; */
117};
118
119struct vmcs_sm_ioctl_lock_unlock {
120 /* user -> kernel */
121 unsigned int handle;
122
123 /* kernel -> user */
124 unsigned int addr;
125};
126
127struct vmcs_sm_ioctl_lock_cache {
128 /* user -> kernel */
129 unsigned int handle;
130 enum vmcs_sm_cache_e cached;
131};
132
133struct vmcs_sm_ioctl_resize {
134 /* user -> kernel */
135 unsigned int handle;
136 unsigned int new_size;
137
138 /* kernel -> user */
139 unsigned int old_size;
140};
141
142struct vmcs_sm_ioctl_map {
143 /* user -> kernel */
144 /* and kernel -> user */
145 unsigned int pid;
146 unsigned int handle;
147 unsigned int addr;
148
149 /* kernel -> user */
150 unsigned int size;
151};
152
153struct vmcs_sm_ioctl_walk {
154 /* user -> kernel */
155 unsigned int pid;
156};
157
158struct vmcs_sm_ioctl_chk {
159 /* user -> kernel */
160 unsigned int handle;
161
162 /* kernel -> user */
163 unsigned int addr;
164 unsigned int size;
165 enum vmcs_sm_cache_e cache;
166};
167
168struct vmcs_sm_ioctl_size {
169 /* user -> kernel */
170 unsigned int handle;
171
172 /* kernel -> user */
173 unsigned int size;
174};
175
176struct vmcs_sm_ioctl_cache {
177 /* user -> kernel */
178 unsigned int handle;
179 unsigned int addr;
180 unsigned int size;
181};
182
183struct vmcs_sm_ioctl_clean_invalid {
184 /* user -> kernel */
185 struct {
186 unsigned int cmd;
187 unsigned int handle;
188 unsigned int addr;
189 unsigned int size;
190 } s[8];
191};
192
193struct vmcs_sm_ioctl_clean_invalid2 {
194 uint8_t op_count;
195 uint8_t zero[3];
196 struct vmcs_sm_ioctl_clean_invalid_block {
197 uint16_t invalidate_mode;
198 uint16_t block_count;
199 void * start_address;
200 uint32_t block_size;
201 uint32_t inter_block_stride;
202 } s[0];
203};
204
205struct vmcs_sm_ioctl_import_dmabuf {
206 /* user -> kernel */
207 int dmabuf_fd;
208 enum vmcs_sm_cache_e cached;
209 char name[VMCS_SM_RESOURCE_NAME];
210
211 /* kernel -> user */
212 unsigned int handle;
213};
214
215/* IOCTL numbers */
216#define VMCS_SM_IOCTL_MEM_ALLOC\
217 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC,\
218 struct vmcs_sm_ioctl_alloc)
219#define VMCS_SM_IOCTL_MEM_ALLOC_SHARE\
220 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_ALLOC_SHARE,\
221 struct vmcs_sm_ioctl_alloc_share)
222#define VMCS_SM_IOCTL_MEM_LOCK\
223 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK,\
224 struct vmcs_sm_ioctl_lock_unlock)
225#define VMCS_SM_IOCTL_MEM_LOCK_CACHE\
226 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_LOCK_CACHE,\
227 struct vmcs_sm_ioctl_lock_cache)
228#define VMCS_SM_IOCTL_MEM_UNLOCK\
229 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_UNLOCK,\
230 struct vmcs_sm_ioctl_lock_unlock)
231#define VMCS_SM_IOCTL_MEM_RESIZE\
232 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_RESIZE,\
233 struct vmcs_sm_ioctl_resize)
234#define VMCS_SM_IOCTL_MEM_FREE\
235 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FREE,\
236 struct vmcs_sm_ioctl_free)
237#define VMCS_SM_IOCTL_MEM_FLUSH\
238 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_FLUSH,\
239 struct vmcs_sm_ioctl_cache)
240#define VMCS_SM_IOCTL_MEM_INVALID\
241 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_INVALID,\
242 struct vmcs_sm_ioctl_cache)
243#define VMCS_SM_IOCTL_MEM_CLEAN_INVALID\
244 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_CLEAN_INVALID,\
245 struct vmcs_sm_ioctl_clean_invalid)
246#define VMCS_SM_IOCTL_MEM_CLEAN_INVALID2\
247 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_CLEAN_INVALID2,\
248 struct vmcs_sm_ioctl_clean_invalid2)
249
250#define VMCS_SM_IOCTL_SIZE_USR_HDL\
251 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_SIZE_USR_HANDLE,\
252 struct vmcs_sm_ioctl_size)
253#define VMCS_SM_IOCTL_CHK_USR_HDL\
254 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_CHK_USR_HANDLE,\
255 struct vmcs_sm_ioctl_chk)
256
257#define VMCS_SM_IOCTL_MAP_USR_HDL\
258 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_HANDLE,\
259 struct vmcs_sm_ioctl_map)
260#define VMCS_SM_IOCTL_MAP_USR_ADDRESS\
261 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_USR_ADDRESS,\
262 struct vmcs_sm_ioctl_map)
263#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_ADDR\
264 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_ADDR,\
265 struct vmcs_sm_ioctl_map)
266#define VMCS_SM_IOCTL_MAP_VC_HDL_FR_HDL\
267 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_HDL_FROM_HDL,\
268 struct vmcs_sm_ioctl_map)
269#define VMCS_SM_IOCTL_MAP_VC_ADDR_FR_HDL\
270 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_MAPPED_VC_ADDR_FROM_HDL,\
271 struct vmcs_sm_ioctl_map)
272
273#define VMCS_SM_IOCTL_VC_WALK_ALLOC\
274 _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_VC_WALK_ALLOC)
275#define VMCS_SM_IOCTL_HOST_WALK_MAP\
276 _IO(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_MAP)
277#define VMCS_SM_IOCTL_HOST_WALK_PID_ALLOC\
278 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_ALLOC,\
279 struct vmcs_sm_ioctl_walk)
280#define VMCS_SM_IOCTL_HOST_WALK_PID_MAP\
281 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_HOST_WALK_PID_MAP,\
282 struct vmcs_sm_ioctl_walk)
283
284#define VMCS_SM_IOCTL_MEM_IMPORT_DMABUF\
285 _IOR(VMCS_SM_MAGIC_TYPE, VMCS_SM_CMD_IMPORT_DMABUF,\
286 struct vmcs_sm_ioctl_import_dmabuf)
287
288/* ---- Variable Externs ------------------------------------------------- */
289
290/* ---- Function Prototypes ---------------------------------------------- */
291
292#endif /* __VMCS_SM_IOCTL_H__INCLUDED__ */
293