xref: /optee_os/core/include/optee_rpc_cmd.h (revision 19a31ec40245ae01a9adcd206eec2a4bb4479fc9)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2016-2021, Linaro Limited
4  */
5 
6 #ifndef __OPTEE_RPC_CMD_H
7 #define __OPTEE_RPC_CMD_H
8 
9 /*
10  * All RPC is done with a struct optee_msg_arg as bearer of information,
11  * struct optee_msg_arg::arg holds values defined by OPTEE_RPC_CMD_* below.
12  * Only the commands handled by the kernel driver are defined here.
13  *
14  * RPC communication with tee-supplicant is reversed compared to normal
15  * client communication described above. The supplicant receives requests
16  * and sends responses.
17  */
18 
19 /*
20  * Load a TA into memory
21  *
22  * Since the size of the TA isn't known in advance the size of the TA is
23  * can be queried with a NULL buffer.
24  *
25  * [in]     value[0].a-b    UUID
26  * [out]    memref[1]	    Buffer with TA
27  */
28 #define OPTEE_RPC_CMD_LOAD_TA		U(0)
29 
30 /*
31  * Replay Protected Memory Block access
32  *
33  * [in]     memref[0]	    Frames to device
34  * [out]    memref[1]	    Frames from device
35  */
36 #define OPTEE_RPC_CMD_RPMB		U(1)
37 
38 /*
39  * File system access, see definition of protocol below
40  */
41 #define OPTEE_RPC_CMD_FS		U(2)
42 
43 /*
44  * Get time
45  *
46  * Returns number of seconds and nano seconds since the Epoch,
47  * 1970-01-01 00:00:00 +0000 (UTC).
48  *
49  * [out]    value[0].a	    Number of seconds
50  * [out]    value[0].b	    Number of nano seconds.
51  */
52 #define OPTEE_RPC_CMD_GET_TIME		U(3)
53 
54 /*
55  * Notification from/to secure world.
56  *
57  * If secure world needs to wait for something, for instance a mutex, it
58  * does a notification wait request instead of spinning in secure world.
59  * Conversely a synchronous notification can be sent when a secure
60  * world mutex with a thread waiting thread is unlocked.
61  *
62  * This interface can also be used to wait for a asynchronous notification
63  * which instead is sent via a non-secure interrupt.
64  *
65  * Waiting on notification
66  * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_WAIT
67  * [in]    value[0].b	    notification value
68  * [in]    value[0].c	    timeout in millisecond or 0 if no timeout
69  *
70  * Sending a synchronous notification
71  * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_SEND
72  * [in]    value[0].b	    notification value
73  * [in]    value[0].c	    shall be 0, reserved for future evolution
74  */
75 #define OPTEE_RPC_CMD_NOTIFICATION	U(4)
76 #define OPTEE_RPC_NOTIFICATION_WAIT	U(0)
77 #define OPTEE_RPC_NOTIFICATION_SEND	U(1)
78 
79 /*
80  * Suspend execution
81  *
82  * [in]    value[0].a	Number of milliseconds to suspend
83  */
84 #define OPTEE_RPC_CMD_SUSPEND		U(5)
85 
86 /*
87  * Allocate a piece of shared memory
88  *
89  * [in]    value[0].a	    Type of memory one of
90  *			    OPTEE_RPC_SHM_TYPE_* below
91  * [in]    value[0].b	    Requested size
92  * [in]    value[0].c	    Required alignment
93  * [out]   memref[0]	    Buffer
94  */
95 #define OPTEE_RPC_CMD_SHM_ALLOC		U(6)
96 /* Memory that can be shared with a non-secure user space application */
97 #define OPTEE_RPC_SHM_TYPE_APPL		U(0)
98 /* Memory only shared with non-secure kernel */
99 #define OPTEE_RPC_SHM_TYPE_KERNEL	U(1)
100 /*
101  * Memory shared with non-secure kernel and exported to a non-secure user
102  * space application
103  */
104 #define OPTEE_RPC_SHM_TYPE_GLOBAL	U(2)
105 
106 /*
107  * Free shared memory previously allocated with OPTEE_RPC_CMD_SHM_ALLOC
108  *
109  * [in]     value[0].a	    Type of memory one of
110  *			    OPTEE_RPC_SHM_TYPE_* above
111  * [in]     value[0].b	    Value of shared memory reference or cookie
112  */
113 #define OPTEE_RPC_CMD_SHM_FREE		U(7)
114 
115 /* Was OPTEE_RPC_CMD_SQL_FS, which isn't supported any longer */
116 #define OPTEE_RPC_CMD_SQL_FS_RESERVED	U(8)
117 
118 /*
119  * Send TA profiling information to normal world
120  *
121  * [in/out] value[0].a	    File identifier. Must be set to 0 on
122  *			    first call. A value >= 1 will be
123  *			    returned on success. Re-use this value
124  *			    to append data to the same file.
125  * [in]     memref[1]	    TA UUID
126  * [in]     memref[2]	    Profile data
127  */
128 #define OPTEE_RPC_CMD_GPROF		U(9)
129 
130 /*
131  * Socket command, see definition of protocol below
132  */
133 #define OPTEE_RPC_CMD_SOCKET		U(10)
134 
135 /*
136  * Send TA function graph data to normal world
137  *
138  * [in/out] value[0].a	    File identifier. Must be set to 0 on
139  *			    first call. A value >= 1 will be
140  *			    returned on success. Re-use this value
141  *			    to append data to the same file.
142  * [in]     memref[1]	    TA UUID
143  * [in]     memref[2]	    function graph data
144  */
145 #define OPTEE_RPC_CMD_FTRACE		U(11)
146 
147 /*
148  * tee-supplicant plugin command, see definition of protocol below
149  */
150 #define OPTEE_RPC_CMD_SUPP_PLUGIN	U(12)
151 
152 /*
153  * Register timestamp buffer in the linux kernel optee driver
154  *
155  * [in]     value[0].a	    Subcommand (register buffer, unregister buffer)
156  * [in]     value[0].b	    Physical address of timestamp buffer
157  * [in]     value[0].c	    Size of buffer
158  */
159 #define OPTEE_RPC_CMD_BENCH_REG		U(20)
160 
161 /*
162  * Issue master requests (read and write operations) to an I2C chip.
163  *
164  * [in]     value[0].a	    Transfer mode (OPTEE_RPC_I2C_TRANSFER_*)
165  * [in]     value[0].b	    The I2C bus (a.k.a adapter).
166  *				16 bit field.
167  * [in]     value[0].c	    The I2C chip (a.k.a address).
168  *				16 bit field (either 7 or 10 bit effective).
169  * [in]     value[1].a	    The I2C master control flags (ie, 10 bit address).
170  *				16 bit field.
171  * [in/out] memref[2]	    Buffer used for data transfers.
172  * [out]    value[3].a	    Number of bytes transferred by the REE.
173  */
174 #define OPTEE_RPC_CMD_I2C_TRANSFER	U(21)
175 
176 /* I2C master transfer modes */
177 #define OPTEE_RPC_I2C_TRANSFER_RD	U(0)
178 #define OPTEE_RPC_I2C_TRANSFER_WR	U(1)
179 
180 /* I2C master control flags */
181 #define OPTEE_RPC_I2C_FLAGS_TEN_BIT	BIT(0)
182 
183 /*
184  * Definition of protocol for command OPTEE_RPC_CMD_FS
185  */
186 
187 /*
188  * Open a file
189  *
190  * [in]     value[0].a	    OPTEE_RPC_FS_OPEN
191  * [in]     memref[1]	    A string holding the file name
192  * [out]    value[2].a	    File descriptor of open file
193  */
194 #define OPTEE_RPC_FS_OPEN		U(0)
195 
196 /*
197  * Create a file
198  *
199  * [in]     value[0].a	    OPTEE_RPC_FS_CREATE
200  * [in]     memref[1]	    A string holding the file name
201  * [out]    value[2].a	    File descriptor of open file
202  */
203 #define OPTEE_RPC_FS_CREATE		U(1)
204 
205 /*
206  * Close a file
207  *
208  * [in]     value[0].a	    OPTEE_RPC_FS_CLOSE
209  * [in]     value[0].b	    File descriptor of open file.
210  */
211 #define OPTEE_RPC_FS_CLOSE		U(2)
212 
213 /*
214  * Read from a file
215  *
216  * [in]     value[0].a	    OPTEE_RPC_FS_READ
217  * [in]     value[0].b	    File descriptor of open file
218  * [in]     value[0].c	    Offset into file
219  * [out]    memref[1]	    Buffer to hold returned data
220  */
221 #define OPTEE_RPC_FS_READ		U(3)
222 
223 /*
224  * Write to a file
225  *
226  * [in]     value[0].a	    OPTEE_RPC_FS_WRITE
227  * [in]     value[0].b	    File descriptor of open file
228  * [in]     value[0].c	    Offset into file
229  * [in]     memref[1]	    Buffer holding data to be written
230  */
231 #define OPTEE_RPC_FS_WRITE		U(4)
232 
233 /*
234  * Truncate a file
235  *
236  * [in]     value[0].a	    OPTEE_RPC_FS_TRUNCATE
237  * [in]     value[0].b	    File descriptor of open file
238  * [in]     value[0].c	    Length of file.
239  */
240 #define OPTEE_RPC_FS_TRUNCATE		U(5)
241 
242 /*
243  * Remove a file
244  *
245  * [in]     value[0].a	    OPTEE_RPC_FS_REMOVE
246  * [in]     memref[1]	    A string holding the file name
247  */
248 #define OPTEE_RPC_FS_REMOVE		U(6)
249 
250 /*
251  * Rename a file
252  *
253  * [in]     value[0].a	    OPTEE_RPC_FS_RENAME
254  * [in]     value[0].b	    True if existing target should be removed
255  * [in]     memref[1]	    A string holding the old file name
256  * [in]     memref[2]	    A string holding the new file name
257  */
258 #define OPTEE_RPC_FS_RENAME		U(7)
259 
260 /*
261  * Opens a directory for file listing
262  *
263  * [in]     value[0].a	    OPTEE_RPC_FS_OPENDIR
264  * [in]     memref[1]	    A string holding the name of the directory
265  * [out]    value[2].a	    Handle to open directory
266  */
267 #define OPTEE_RPC_FS_OPENDIR		U(8)
268 
269 /*
270  * Closes a directory handle
271  *
272  * [in]     value[0].a	    OPTEE_RPC_FS_CLOSEDIR
273  * [in]     value[0].b	    Handle to open directory
274  */
275 #define OPTEE_RPC_FS_CLOSEDIR		U(9)
276 
277 /*
278  * Read next file name of directory
279  *
280  *
281  * [in]     value[0].a	    OPTEE_RPC_FS_READDIR
282  * [in]     value[0].b	    Handle to open directory
283  * [out]    memref[1]	    A string holding the file name
284  */
285 #define OPTEE_RPC_FS_READDIR		U(10)
286 
287 /* End of definition of protocol for command OPTEE_RPC_CMD_FS */
288 
289 /*
290  * Definition of protocol for command OPTEE_RPC_CMD_SOCKET
291  */
292 
293 #define OPTEE_RPC_SOCKET_TIMEOUT_NONBLOCKING	U(0)
294 #define OPTEE_RPC_SOCKET_TIMEOUT_BLOCKING	U(0xffffffff)
295 
296 /*
297  * Open socket
298  *
299  * [in]     value[0].a	    OPTEE_RPC_SOCKET_OPEN
300  * [in]     value[0].b	    TA instance id
301  * [in]     value[1].a	    Server port number
302  * [in]     value[1].b	    Protocol, TEE_ISOCKET_PROTOCOLID_*
303  * [in]     value[1].c	    Ip version TEE_IP_VERSION_* from tee_ipsocket.h
304  * [in]     memref[2]	    Server address
305  * [out]    value[3].a	    Socket handle (32-bit)
306  */
307 #define OPTEE_RPC_SOCKET_OPEN	U(0)
308 
309 /*
310  * Close socket
311  *
312  * [in]     value[0].a	    OPTEE_RPC_SOCKET_CLOSE
313  * [in]     value[0].b	    TA instance id
314  * [in]     value[0].c	    Socket handle
315  */
316 #define OPTEE_RPC_SOCKET_CLOSE	U(1)
317 
318 /*
319  * Close all sockets
320  *
321  * [in]     value[0].a	    OPTEE_RPC_SOCKET_CLOSE_ALL
322  * [in]     value[0].b	    TA instance id
323  */
324 #define OPTEE_RPC_SOCKET_CLOSE_ALL U(2)
325 
326 /*
327  * Send data on socket
328  *
329  * [in]     value[0].a	    OPTEE_RPC_SOCKET_SEND
330  * [in]     value[0].b	    TA instance id
331  * [in]     value[0].c	    Socket handle
332  * [in]     memref[1]	    Buffer to transmit
333  * [in]     value[2].a	    Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_*
334  * [out]    value[2].b	    Number of transmitted bytes
335  */
336 #define OPTEE_RPC_SOCKET_SEND	U(3)
337 
338 /*
339  * Receive data on socket
340  *
341  * [in]     value[0].a	    OPTEE_RPC_SOCKET_RECV
342  * [in]     value[0].b	    TA instance id
343  * [in]     value[0].c	    Socket handle
344  * [out]    memref[1]	    Buffer to receive
345  * [in]     value[2].a	    Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_*
346  */
347 #define OPTEE_RPC_SOCKET_RECV	U(4)
348 
349 /*
350  * Perform IOCTL on socket
351  *
352  * [in]     value[0].a	    OPTEE_RPC_SOCKET_IOCTL
353  * [in]     value[0].b	    TA instance id
354  * [in]     value[0].c	    Socket handle
355  * [in/out] memref[1]	    Buffer
356  * [in]     value[2].a	    Ioctl command
357  */
358 #define OPTEE_RPC_SOCKET_IOCTL	U(5)
359 
360 /* End of definition of protocol for command OPTEE_RPC_CMD_SOCKET */
361 
362 /*
363  * Definition of protocol for command OPTEE_RPC_CMD_SUPP_PLUGIN
364  */
365 
366 /*
367  * Invoke tee-supplicant's plugin.
368  *
369  * [in]     value[0].a	OPTEE_RPC_SUPP_PLUGIN_INVOKE
370  * [in]     value[0].b	uuid.d1
371  * [in]     value[0].c	uuid.d2
372  * [in]     value[1].a	uuid.d3
373  * [in]     value[1].b	uuid.d4
374  * [in]     value[1].c	cmd for plugin
375  * [in]     value[2].a	sub_cmd for plugin
376  * [out]    value[2].b  length of the outbuf (memref[3]), if out is needed.
377  * [in/out] memref[3]	buffer holding data for plugin
378  *
379  * UUID serialized into octets:
380  * b0  b1  b2  b3   b4  b5  b6  b7   b8  b9  b10  b11   b12  b13  b14  b15
381  *       d1       |       d2       |        d3        |         d4
382  *
383  * The endianness of words d1, d2, d3 and d4 must be little-endian.
384  * d1 word contains [b3 b2 b1 b0]
385  * d2 word contains [b7 b6 b5 b4]
386  * d3 word contains [b11 b10 b9 b8]
387  * d4 word contains [b15 b14 b13 b12]
388  */
389 #define OPTEE_RPC_SUPP_PLUGIN_INVOKE	U(0)
390 
391 /* End of definition of protocol for command OPTEE_RPC_CMD_SUPP_PLUGIN */
392 
393 #endif /*__OPTEE_RPC_CMD_H*/
394