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