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 * Reset RPMB probing 185 * 186 * Releases a possibly already used RPMB device and starts over searching 187 * for RPMB devices. Returns the kind of shared memory to use in subsequent 188 * OPTEE_RPC_CMD_RPMB_PROBE_NEXT and OPTEE_RPC_CMD_RPMB_FRAMES calls. 189 * 190 * [out] value[0].a OPTEE_RPC_SHM_TYPE_*, the parameter for 191 * OPTEE_RPC_CMD_SHM_ALLOC 192 */ 193 #define OPTEE_RPC_CMD_RPMB_PROBE_RESET U(22) 194 195 /* 196 * Probe next RPMB device 197 * 198 * value[0].a indicates kind of RPMB device found, currently is only 199 * OPTEE_RPC_RPMB_EMMC supported. If another kind of RPMB device is found 200 * it will have a new unique value in value[0].a and the other 201 * out-parameters will be defined specifically for that device. 202 * 203 * If an eMMC/RPMB partition is found: 204 * [out] value[0].a OPTEE_RPC_RPMB_EMMC 205 * [out] value[0].b EXT CSD-slice 168 "RPMB Size" 206 * [out] value[0].c EXT CSD-slice 222 "Reliable Write Sector Count" 207 * [out] memref[1] Buffer with the raw CID 208 */ 209 #define OPTEE_RPC_CMD_RPMB_PROBE_NEXT U(23) 210 211 #define OPTEE_RPC_RPMB_EMMC U(0) 212 213 /* 214 * Replay Protected Memory Block access 215 * 216 * [in] memref[0] Frames to device 217 * [out] memref[1] Frames from device 218 */ 219 #define OPTEE_RPC_CMD_RPMB_FRAMES U(24) 220 221 /* 222 * Definition of protocol for command OPTEE_RPC_CMD_FS 223 */ 224 225 /* 226 * Open a file 227 * 228 * [in] value[0].a OPTEE_RPC_FS_OPEN 229 * [in] memref[1] A string holding the file name 230 * [out] value[2].a File descriptor of open file 231 */ 232 #define OPTEE_RPC_FS_OPEN U(0) 233 234 /* 235 * Create a file 236 * 237 * [in] value[0].a OPTEE_RPC_FS_CREATE 238 * [in] memref[1] A string holding the file name 239 * [out] value[2].a File descriptor of open file 240 */ 241 #define OPTEE_RPC_FS_CREATE U(1) 242 243 /* 244 * Close a file 245 * 246 * [in] value[0].a OPTEE_RPC_FS_CLOSE 247 * [in] value[0].b File descriptor of open file. 248 */ 249 #define OPTEE_RPC_FS_CLOSE U(2) 250 251 /* 252 * Read from a file 253 * 254 * [in] value[0].a OPTEE_RPC_FS_READ 255 * [in] value[0].b File descriptor of open file 256 * [in] value[0].c Offset into file 257 * [out] memref[1] Buffer to hold returned data 258 */ 259 #define OPTEE_RPC_FS_READ U(3) 260 261 /* 262 * Write to a file 263 * 264 * [in] value[0].a OPTEE_RPC_FS_WRITE 265 * [in] value[0].b File descriptor of open file 266 * [in] value[0].c Offset into file 267 * [in] memref[1] Buffer holding data to be written 268 */ 269 #define OPTEE_RPC_FS_WRITE U(4) 270 271 /* 272 * Truncate a file 273 * 274 * [in] value[0].a OPTEE_RPC_FS_TRUNCATE 275 * [in] value[0].b File descriptor of open file 276 * [in] value[0].c Length of file. 277 */ 278 #define OPTEE_RPC_FS_TRUNCATE U(5) 279 280 /* 281 * Remove a file 282 * 283 * [in] value[0].a OPTEE_RPC_FS_REMOVE 284 * [in] memref[1] A string holding the file name 285 */ 286 #define OPTEE_RPC_FS_REMOVE U(6) 287 288 /* 289 * Rename a file 290 * 291 * [in] value[0].a OPTEE_RPC_FS_RENAME 292 * [in] value[0].b True if existing target should be removed 293 * [in] memref[1] A string holding the old file name 294 * [in] memref[2] A string holding the new file name 295 */ 296 #define OPTEE_RPC_FS_RENAME U(7) 297 298 /* 299 * Opens a directory for file listing 300 * 301 * [in] value[0].a OPTEE_RPC_FS_OPENDIR 302 * [in] memref[1] A string holding the name of the directory 303 * [out] value[2].a Handle to open directory 304 */ 305 #define OPTEE_RPC_FS_OPENDIR U(8) 306 307 /* 308 * Closes a directory handle 309 * 310 * [in] value[0].a OPTEE_RPC_FS_CLOSEDIR 311 * [in] value[0].b Handle to open directory 312 */ 313 #define OPTEE_RPC_FS_CLOSEDIR U(9) 314 315 /* 316 * Read next file name of directory 317 * 318 * 319 * [in] value[0].a OPTEE_RPC_FS_READDIR 320 * [in] value[0].b Handle to open directory 321 * [out] memref[1] A string holding the file name 322 */ 323 #define OPTEE_RPC_FS_READDIR U(10) 324 325 /* End of definition of protocol for command OPTEE_RPC_CMD_FS */ 326 327 /* 328 * Definition of protocol for command OPTEE_RPC_CMD_SOCKET 329 */ 330 331 #define OPTEE_RPC_SOCKET_TIMEOUT_NONBLOCKING U(0) 332 #define OPTEE_RPC_SOCKET_TIMEOUT_BLOCKING U(0xffffffff) 333 334 /* 335 * Open socket 336 * 337 * [in] value[0].a OPTEE_RPC_SOCKET_OPEN 338 * [in] value[0].b TA instance id 339 * [in] value[1].a Server port number 340 * [in] value[1].b Protocol, TEE_ISOCKET_PROTOCOLID_* 341 * [in] value[1].c Ip version TEE_IP_VERSION_* from tee_ipsocket.h 342 * [in] memref[2] Server address 343 * [out] value[3].a Socket handle (32-bit) 344 */ 345 #define OPTEE_RPC_SOCKET_OPEN U(0) 346 347 /* 348 * Close socket 349 * 350 * [in] value[0].a OPTEE_RPC_SOCKET_CLOSE 351 * [in] value[0].b TA instance id 352 * [in] value[0].c Socket handle 353 */ 354 #define OPTEE_RPC_SOCKET_CLOSE U(1) 355 356 /* 357 * Close all sockets 358 * 359 * [in] value[0].a OPTEE_RPC_SOCKET_CLOSE_ALL 360 * [in] value[0].b TA instance id 361 */ 362 #define OPTEE_RPC_SOCKET_CLOSE_ALL U(2) 363 364 /* 365 * Send data on socket 366 * 367 * [in] value[0].a OPTEE_RPC_SOCKET_SEND 368 * [in] value[0].b TA instance id 369 * [in] value[0].c Socket handle 370 * [in] memref[1] Buffer to transmit 371 * [in] value[2].a Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_* 372 * [out] value[2].b Number of transmitted bytes 373 */ 374 #define OPTEE_RPC_SOCKET_SEND U(3) 375 376 /* 377 * Receive data on socket 378 * 379 * [in] value[0].a OPTEE_RPC_SOCKET_RECV 380 * [in] value[0].b TA instance id 381 * [in] value[0].c Socket handle 382 * [out] memref[1] Buffer to receive 383 * [in] value[2].a Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_* 384 */ 385 #define OPTEE_RPC_SOCKET_RECV U(4) 386 387 /* 388 * Perform IOCTL on socket 389 * 390 * [in] value[0].a OPTEE_RPC_SOCKET_IOCTL 391 * [in] value[0].b TA instance id 392 * [in] value[0].c Socket handle 393 * [in/out] memref[1] Buffer 394 * [in] value[2].a Ioctl command 395 */ 396 #define OPTEE_RPC_SOCKET_IOCTL U(5) 397 398 /* End of definition of protocol for command OPTEE_RPC_CMD_SOCKET */ 399 400 /* 401 * Definition of protocol for command OPTEE_RPC_CMD_SUPP_PLUGIN 402 */ 403 404 /* 405 * Invoke tee-supplicant's plugin. 406 * 407 * [in] value[0].a OPTEE_RPC_SUPP_PLUGIN_INVOKE 408 * [in] value[0].b uuid.d1 409 * [in] value[0].c uuid.d2 410 * [in] value[1].a uuid.d3 411 * [in] value[1].b uuid.d4 412 * [in] value[1].c cmd for plugin 413 * [in] value[2].a sub_cmd for plugin 414 * [out] value[2].b length of the outbuf (memref[3]), if out is needed. 415 * [in/out] memref[3] buffer holding data for plugin 416 * 417 * UUID serialized into octets: 418 * b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 419 * d1 | d2 | d3 | d4 420 * 421 * The endianness of words d1, d2, d3 and d4 must be little-endian. 422 * d1 word contains [b3 b2 b1 b0] 423 * d2 word contains [b7 b6 b5 b4] 424 * d3 word contains [b11 b10 b9 b8] 425 * d4 word contains [b15 b14 b13 b12] 426 */ 427 #define OPTEE_RPC_SUPP_PLUGIN_INVOKE U(0) 428 429 /* End of definition of protocol for command OPTEE_RPC_CMD_SUPP_PLUGIN */ 430 431 #endif /*__OPTEE_RPC_CMD_H*/ 432