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  *
69  * Sending a synchronous notification
70  * [in]    value[0].a	    OPTEE_RPC_NOTIFICATION_SEND
71  * [in]    value[0].b	    notification value
72  */
73 #define OPTEE_RPC_CMD_NOTIFICATION	U(4)
74 #define OPTEE_RPC_NOTIFICATION_WAIT	U(0)
75 #define OPTEE_RPC_NOTIFICATION_SEND	U(1)
76 
77 /*
78  * Suspend execution
79  *
80  * [in]    value[0].a	Number of milliseconds to suspend
81  */
82 #define OPTEE_RPC_CMD_SUSPEND		U(5)
83 
84 /*
85  * Allocate a piece of shared memory
86  *
87  * [in]    value[0].a	    Type of memory one of
88  *			    OPTEE_RPC_SHM_TYPE_* below
89  * [in]    value[0].b	    Requested size
90  * [in]    value[0].c	    Required alignment
91  * [out]   memref[0]	    Buffer
92  */
93 #define OPTEE_RPC_CMD_SHM_ALLOC		U(6)
94 /* Memory that can be shared with a non-secure user space application */
95 #define OPTEE_RPC_SHM_TYPE_APPL		U(0)
96 /* Memory only shared with non-secure kernel */
97 #define OPTEE_RPC_SHM_TYPE_KERNEL	U(1)
98 /*
99  * Memory shared with non-secure kernel and exported to a non-secure user
100  * space application
101  */
102 #define OPTEE_RPC_SHM_TYPE_GLOBAL	U(2)
103 
104 /*
105  * Free shared memory previously allocated with OPTEE_RPC_CMD_SHM_ALLOC
106  *
107  * [in]     value[0].a	    Type of memory one of
108  *			    OPTEE_RPC_SHM_TYPE_* above
109  * [in]     value[0].b	    Value of shared memory reference or cookie
110  */
111 #define OPTEE_RPC_CMD_SHM_FREE		U(7)
112 
113 /* Was OPTEE_RPC_CMD_SQL_FS, which isn't supported any longer */
114 #define OPTEE_RPC_CMD_SQL_FS_RESERVED	U(8)
115 
116 /*
117  * Send TA profiling information to normal world
118  *
119  * [in/out] value[0].a	    File identifier. Must be set to 0 on
120  *			    first call. A value >= 1 will be
121  *			    returned on success. Re-use this value
122  *			    to append data to the same file.
123  * [in]     memref[1]	    TA UUID
124  * [in]     memref[2]	    Profile data
125  */
126 #define OPTEE_RPC_CMD_GPROF		U(9)
127 
128 /*
129  * Socket command, see definition of protocol below
130  */
131 #define OPTEE_RPC_CMD_SOCKET		U(10)
132 
133 /*
134  * Send TA function graph data to normal world
135  *
136  * [in/out] value[0].a	    File identifier. Must be set to 0 on
137  *			    first call. A value >= 1 will be
138  *			    returned on success. Re-use this value
139  *			    to append data to the same file.
140  * [in]     memref[1]	    TA UUID
141  * [in]     memref[2]	    function graph data
142  */
143 #define OPTEE_RPC_CMD_FTRACE		U(11)
144 
145 /*
146  * tee-supplicant plugin command, see definition of protocol below
147  */
148 #define OPTEE_RPC_CMD_SUPP_PLUGIN	U(12)
149 
150 /*
151  * Register timestamp buffer in the linux kernel optee driver
152  *
153  * [in]     value[0].a	    Subcommand (register buffer, unregister buffer)
154  * [in]     value[0].b	    Physical address of timestamp buffer
155  * [in]     value[0].c	    Size of buffer
156  */
157 #define OPTEE_RPC_CMD_BENCH_REG		U(20)
158 
159 /*
160  * Issue master requests (read and write operations) to an I2C chip.
161  *
162  * [in]     value[0].a	    Transfer mode (OPTEE_RPC_I2C_TRANSFER_*)
163  * [in]     value[0].b	    The I2C bus (a.k.a adapter).
164  *				16 bit field.
165  * [in]     value[0].c	    The I2C chip (a.k.a address).
166  *				16 bit field (either 7 or 10 bit effective).
167  * [in]     value[1].a	    The I2C master control flags (ie, 10 bit address).
168  *				16 bit field.
169  * [in/out] memref[2]	    Buffer used for data transfers.
170  * [out]    value[3].a	    Number of bytes transferred by the REE.
171  */
172 #define OPTEE_RPC_CMD_I2C_TRANSFER	U(21)
173 
174 /* I2C master transfer modes */
175 #define OPTEE_RPC_I2C_TRANSFER_RD	U(0)
176 #define OPTEE_RPC_I2C_TRANSFER_WR	U(1)
177 
178 /* I2C master control flags */
179 #define OPTEE_RPC_I2C_FLAGS_TEN_BIT	BIT(0)
180 
181 /*
182  * Definition of protocol for command OPTEE_RPC_CMD_FS
183  */
184 
185 /*
186  * Open a file
187  *
188  * [in]     value[0].a	    OPTEE_RPC_FS_OPEN
189  * [in]     memref[1]	    A string holding the file name
190  * [out]    value[2].a	    File descriptor of open file
191  */
192 #define OPTEE_RPC_FS_OPEN		U(0)
193 
194 /*
195  * Create a file
196  *
197  * [in]     value[0].a	    OPTEE_RPC_FS_CREATE
198  * [in]     memref[1]	    A string holding the file name
199  * [out]    value[2].a	    File descriptor of open file
200  */
201 #define OPTEE_RPC_FS_CREATE		U(1)
202 
203 /*
204  * Close a file
205  *
206  * [in]     value[0].a	    OPTEE_RPC_FS_CLOSE
207  * [in]     value[0].b	    File descriptor of open file.
208  */
209 #define OPTEE_RPC_FS_CLOSE		U(2)
210 
211 /*
212  * Read from a file
213  *
214  * [in]     value[0].a	    OPTEE_RPC_FS_READ
215  * [in]     value[0].b	    File descriptor of open file
216  * [in]     value[0].c	    Offset into file
217  * [out]    memref[1]	    Buffer to hold returned data
218  */
219 #define OPTEE_RPC_FS_READ		U(3)
220 
221 /*
222  * Write to a file
223  *
224  * [in]     value[0].a	    OPTEE_RPC_FS_WRITE
225  * [in]     value[0].b	    File descriptor of open file
226  * [in]     value[0].c	    Offset into file
227  * [in]     memref[1]	    Buffer holding data to be written
228  */
229 #define OPTEE_RPC_FS_WRITE		U(4)
230 
231 /*
232  * Truncate a file
233  *
234  * [in]     value[0].a	    OPTEE_RPC_FS_TRUNCATE
235  * [in]     value[0].b	    File descriptor of open file
236  * [in]     value[0].c	    Length of file.
237  */
238 #define OPTEE_RPC_FS_TRUNCATE		U(5)
239 
240 /*
241  * Remove a file
242  *
243  * [in]     value[0].a	    OPTEE_RPC_FS_REMOVE
244  * [in]     memref[1]	    A string holding the file name
245  */
246 #define OPTEE_RPC_FS_REMOVE		U(6)
247 
248 /*
249  * Rename a file
250  *
251  * [in]     value[0].a	    OPTEE_RPC_FS_RENAME
252  * [in]     value[0].b	    True if existing target should be removed
253  * [in]     memref[1]	    A string holding the old file name
254  * [in]     memref[2]	    A string holding the new file name
255  */
256 #define OPTEE_RPC_FS_RENAME		U(7)
257 
258 /*
259  * Opens a directory for file listing
260  *
261  * [in]     value[0].a	    OPTEE_RPC_FS_OPENDIR
262  * [in]     memref[1]	    A string holding the name of the directory
263  * [out]    value[2].a	    Handle to open directory
264  */
265 #define OPTEE_RPC_FS_OPENDIR		U(8)
266 
267 /*
268  * Closes a directory handle
269  *
270  * [in]     value[0].a	    OPTEE_RPC_FS_CLOSEDIR
271  * [in]     value[0].b	    Handle to open directory
272  */
273 #define OPTEE_RPC_FS_CLOSEDIR		U(9)
274 
275 /*
276  * Read next file name of directory
277  *
278  *
279  * [in]     value[0].a	    OPTEE_RPC_FS_READDIR
280  * [in]     value[0].b	    Handle to open directory
281  * [out]    memref[1]	    A string holding the file name
282  */
283 #define OPTEE_RPC_FS_READDIR		U(10)
284 
285 /* End of definition of protocol for command OPTEE_RPC_CMD_FS */
286 
287 /*
288  * Definition of protocol for command OPTEE_RPC_CMD_SOCKET
289  */
290 
291 #define OPTEE_RPC_SOCKET_TIMEOUT_NONBLOCKING	U(0)
292 #define OPTEE_RPC_SOCKET_TIMEOUT_BLOCKING	U(0xffffffff)
293 
294 /*
295  * Open socket
296  *
297  * [in]     value[0].a	    OPTEE_RPC_SOCKET_OPEN
298  * [in]     value[0].b	    TA instance id
299  * [in]     value[1].a	    Server port number
300  * [in]     value[1].b	    Protocol, TEE_ISOCKET_PROTOCOLID_*
301  * [in]     value[1].c	    Ip version TEE_IP_VERSION_* from tee_ipsocket.h
302  * [in]     memref[2]	    Server address
303  * [out]    value[3].a	    Socket handle (32-bit)
304  */
305 #define OPTEE_RPC_SOCKET_OPEN	U(0)
306 
307 /*
308  * Close socket
309  *
310  * [in]     value[0].a	    OPTEE_RPC_SOCKET_CLOSE
311  * [in]     value[0].b	    TA instance id
312  * [in]     value[0].c	    Socket handle
313  */
314 #define OPTEE_RPC_SOCKET_CLOSE	U(1)
315 
316 /*
317  * Close all sockets
318  *
319  * [in]     value[0].a	    OPTEE_RPC_SOCKET_CLOSE_ALL
320  * [in]     value[0].b	    TA instance id
321  */
322 #define OPTEE_RPC_SOCKET_CLOSE_ALL U(2)
323 
324 /*
325  * Send data on socket
326  *
327  * [in]     value[0].a	    OPTEE_RPC_SOCKET_SEND
328  * [in]     value[0].b	    TA instance id
329  * [in]     value[0].c	    Socket handle
330  * [in]     memref[1]	    Buffer to transmit
331  * [in]     value[2].a	    Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_*
332  * [out]    value[2].b	    Number of transmitted bytes
333  */
334 #define OPTEE_RPC_SOCKET_SEND	U(3)
335 
336 /*
337  * Receive data on socket
338  *
339  * [in]     value[0].a	    OPTEE_RPC_SOCKET_RECV
340  * [in]     value[0].b	    TA instance id
341  * [in]     value[0].c	    Socket handle
342  * [out]    memref[1]	    Buffer to receive
343  * [in]     value[2].a	    Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_*
344  */
345 #define OPTEE_RPC_SOCKET_RECV	U(4)
346 
347 /*
348  * Perform IOCTL on socket
349  *
350  * [in]     value[0].a	    OPTEE_RPC_SOCKET_IOCTL
351  * [in]     value[0].b	    TA instance id
352  * [in]     value[0].c	    Socket handle
353  * [in/out] memref[1]	    Buffer
354  * [in]     value[2].a	    Ioctl command
355  */
356 #define OPTEE_RPC_SOCKET_IOCTL	U(5)
357 
358 /* End of definition of protocol for command OPTEE_RPC_CMD_SOCKET */
359 
360 /*
361  * Definition of protocol for command OPTEE_RPC_CMD_SUPP_PLUGIN
362  */
363 
364 /*
365  * Invoke tee-supplicant's plugin.
366  *
367  * [in]     value[0].a	OPTEE_RPC_SUPP_PLUGIN_INVOKE
368  * [in]     value[0].b	uuid.d1
369  * [in]     value[0].c	uuid.d2
370  * [in]     value[1].a	uuid.d3
371  * [in]     value[1].b	uuid.d4
372  * [in]     value[1].c	cmd for plugin
373  * [in]     value[2].a	sub_cmd for plugin
374  * [out]    value[2].b  length of the outbuf (memref[3]), if out is needed.
375  * [in/out] memref[3]	buffer holding data for plugin
376  *
377  * UUID serialized into octets:
378  * b0  b1  b2  b3   b4  b5  b6  b7   b8  b9  b10  b11   b12  b13  b14  b15
379  *       d1       |       d2       |        d3        |         d4
380  *
381  * The endianness of words d1, d2, d3 and d4 must be little-endian.
382  * d1 word contains [b3 b2 b1 b0]
383  * d2 word contains [b7 b6 b5 b4]
384  * d3 word contains [b11 b10 b9 b8]
385  * d4 word contains [b15 b14 b13 b12]
386  */
387 #define OPTEE_RPC_SUPP_PLUGIN_INVOKE	U(0)
388 
389 /* End of definition of protocol for command OPTEE_RPC_CMD_SUPP_PLUGIN */
390 
391 #endif /*__OPTEE_RPC_CMD_H*/
392