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 * Register timestamp buffer in the linux kernel optee driver 144 * 145 * [in] value[0].a Subcommand (register buffer, unregister buffer) 146 * [in] value[0].b Physical address of timestamp buffer 147 * [in] value[0].c Size of buffer 148 */ 149 #define OPTEE_RPC_CMD_BENCH_REG 20 150 151 /* 152 * Issue master requests (read and write operations) to an I2C chip. 153 * 154 * [in] value[0].a Transfer mode (OPTEE_RPC_I2C_TRANSFER_*) 155 * [in] value[0].b The I2C bus (a.k.a adapter). 156 * 16 bit field. 157 * [in] value[0].c The I2C chip (a.k.a address). 158 * 16 bit field (either 7 or 10 bit effective). 159 * [in] value[1].a The I2C master control flags (ie, 10 bit address). 160 * 16 bit field. 161 * [in/out] memref[2] Buffer used for data transfers. 162 * [out] value[3].a Number of bytes transferred by the REE. 163 */ 164 #define OPTEE_RPC_CMD_I2C_TRANSFER 21 165 166 /* I2C master transfer modes */ 167 #define OPTEE_RPC_I2C_TRANSFER_RD 0 168 #define OPTEE_RPC_I2C_TRANSFER_WR 1 169 170 /* I2C master control flags */ 171 #define OPTEE_RPC_I2C_FLAGS_TEN_BIT BIT(0) 172 173 /* 174 * Definition of protocol for command OPTEE_RPC_CMD_FS 175 */ 176 177 /* 178 * Open a file 179 * 180 * [in] value[0].a OPTEE_RPC_FS_OPEN 181 * [in] memref[1] A string holding the file name 182 * [out] value[2].a File descriptor of open file 183 */ 184 #define OPTEE_RPC_FS_OPEN 0 185 186 /* 187 * Create a file 188 * 189 * [in] value[0].a OPTEE_RPC_FS_CREATE 190 * [in] memref[1] A string holding the file name 191 * [out] value[2].a File descriptor of open file 192 */ 193 #define OPTEE_RPC_FS_CREATE 1 194 195 /* 196 * Close a file 197 * 198 * [in] value[0].a OPTEE_RPC_FS_CLOSE 199 * [in] value[0].b File descriptor of open file. 200 */ 201 #define OPTEE_RPC_FS_CLOSE 2 202 203 /* 204 * Read from a file 205 * 206 * [in] value[0].a OPTEE_RPC_FS_READ 207 * [in] value[0].b File descriptor of open file 208 * [in] value[0].c Offset into file 209 * [out] memref[1] Buffer to hold returned data 210 */ 211 #define OPTEE_RPC_FS_READ 3 212 213 /* 214 * Write to a file 215 * 216 * [in] value[0].a OPTEE_RPC_FS_WRITE 217 * [in] value[0].b File descriptor of open file 218 * [in] value[0].c Offset into file 219 * [in] memref[1] Buffer holding data to be written 220 */ 221 #define OPTEE_RPC_FS_WRITE 4 222 223 /* 224 * Truncate a file 225 * 226 * [in] value[0].a OPTEE_RPC_FS_TRUNCATE 227 * [in] value[0].b File descriptor of open file 228 * [in] value[0].c Length of file. 229 */ 230 #define OPTEE_RPC_FS_TRUNCATE 5 231 232 /* 233 * Remove a file 234 * 235 * [in] value[0].a OPTEE_RPC_FS_REMOVE 236 * [in] memref[1] A string holding the file name 237 */ 238 #define OPTEE_RPC_FS_REMOVE 6 239 240 /* 241 * Rename a file 242 * 243 * [in] value[0].a OPTEE_RPC_FS_RENAME 244 * [in] value[0].b True if existing target should be removed 245 * [in] memref[1] A string holding the old file name 246 * [in] memref[2] A string holding the new file name 247 */ 248 #define OPTEE_RPC_FS_RENAME 7 249 250 /* 251 * Opens a directory for file listing 252 * 253 * [in] value[0].a OPTEE_RPC_FS_OPENDIR 254 * [in] memref[1] A string holding the name of the directory 255 * [out] value[2].a Handle to open directory 256 */ 257 #define OPTEE_RPC_FS_OPENDIR 8 258 259 /* 260 * Closes a directory handle 261 * 262 * [in] value[0].a OPTEE_RPC_FS_CLOSEDIR 263 * [in] value[0].b Handle to open directory 264 */ 265 #define OPTEE_RPC_FS_CLOSEDIR 9 266 267 /* 268 * Read next file name of directory 269 * 270 * 271 * [in] value[0].a OPTEE_RPC_FS_READDIR 272 * [in] value[0].b Handle to open directory 273 * [out] memref[1] A string holding the file name 274 */ 275 #define OPTEE_RPC_FS_READDIR 10 276 277 /* End of definition of protocol for command OPTEE_RPC_CMD_FS */ 278 279 /* 280 * Definition of protocol for command OPTEE_RPC_CMD_SOCKET 281 */ 282 283 #define OPTEE_RPC_SOCKET_TIMEOUT_NONBLOCKING 0 284 #define OPTEE_RPC_SOCKET_TIMEOUT_BLOCKING 0xffffffff 285 286 /* 287 * Open socket 288 * 289 * [in] value[0].a OPTEE_RPC_SOCKET_OPEN 290 * [in] value[0].b TA instance id 291 * [in] value[1].a Server port number 292 * [in] value[1].b Protocol, TEE_ISOCKET_PROTOCOLID_* 293 * [in] value[1].c Ip version TEE_IP_VERSION_* from tee_ipsocket.h 294 * [in] memref[2] Server address 295 * [out] value[3].a Socket handle (32-bit) 296 */ 297 #define OPTEE_RPC_SOCKET_OPEN 0 298 299 /* 300 * Close socket 301 * 302 * [in] value[0].a OPTEE_RPC_SOCKET_CLOSE 303 * [in] value[0].b TA instance id 304 * [in] value[0].c Socket handle 305 */ 306 #define OPTEE_RPC_SOCKET_CLOSE 1 307 308 /* 309 * Close all sockets 310 * 311 * [in] value[0].a OPTEE_RPC_SOCKET_CLOSE_ALL 312 * [in] value[0].b TA instance id 313 */ 314 #define OPTEE_RPC_SOCKET_CLOSE_ALL 2 315 316 /* 317 * Send data on socket 318 * 319 * [in] value[0].a OPTEE_RPC_SOCKET_SEND 320 * [in] value[0].b TA instance id 321 * [in] value[0].c Socket handle 322 * [in] memref[1] Buffer to transmit 323 * [in] value[2].a Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_* 324 * [out] value[2].b Number of transmitted bytes 325 */ 326 #define OPTEE_RPC_SOCKET_SEND 3 327 328 /* 329 * Receive data on socket 330 * 331 * [in] value[0].a OPTEE_RPC_SOCKET_RECV 332 * [in] value[0].b TA instance id 333 * [in] value[0].c Socket handle 334 * [out] memref[1] Buffer to receive 335 * [in] value[2].a Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_* 336 */ 337 #define OPTEE_RPC_SOCKET_RECV 4 338 339 /* 340 * Perform IOCTL on socket 341 * 342 * [in] value[0].a OPTEE_RPC_SOCKET_IOCTL 343 * [in] value[0].b TA instance id 344 * [in] value[0].c Socket handle 345 * [in/out] memref[1] Buffer 346 * [in] value[2].a Ioctl command 347 */ 348 #define OPTEE_RPC_SOCKET_IOCTL 5 349 350 /* End of definition of protocol for command OPTEE_RPC_CMD_SOCKET */ 351 352 #endif /*__OPTEE_RPC_CMD_H*/ 353