1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2016-2017, 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 * Definition of protocol for command OPTEE_RPC_CMD_FS 153 */ 154 155 /* 156 * Open a file 157 * 158 * [in] value[0].a OPTEE_RPC_FS_OPEN 159 * [in] memref[1] A string holding the file name 160 * [out] value[2].a File descriptor of open file 161 */ 162 #define OPTEE_RPC_FS_OPEN 0 163 164 /* 165 * Create a file 166 * 167 * [in] value[0].a OPTEE_RPC_FS_CREATE 168 * [in] memref[1] A string holding the file name 169 * [out] value[2].a File descriptor of open file 170 */ 171 #define OPTEE_RPC_FS_CREATE 1 172 173 /* 174 * Close a file 175 * 176 * [in] value[0].a OPTEE_RPC_FS_CLOSE 177 * [in] value[0].b File descriptor of open file. 178 */ 179 #define OPTEE_RPC_FS_CLOSE 2 180 181 /* 182 * Read from a file 183 * 184 * [in] value[0].a OPTEE_RPC_FS_READ 185 * [in] value[0].b File descriptor of open file 186 * [in] value[0].c Offset into file 187 * [out] memref[1] Buffer to hold returned data 188 */ 189 #define OPTEE_RPC_FS_READ 3 190 191 /* 192 * Write to a file 193 * 194 * [in] value[0].a OPTEE_RPC_FS_WRITE 195 * [in] value[0].b File descriptor of open file 196 * [in] value[0].c Offset into file 197 * [in] memref[1] Buffer holding data to be written 198 */ 199 #define OPTEE_RPC_FS_WRITE 4 200 201 /* 202 * Truncate a file 203 * 204 * [in] value[0].a OPTEE_RPC_FS_TRUNCATE 205 * [in] value[0].b File descriptor of open file 206 * [in] value[0].c Length of file. 207 */ 208 #define OPTEE_RPC_FS_TRUNCATE 5 209 210 /* 211 * Remove a file 212 * 213 * [in] value[0].a OPTEE_RPC_FS_REMOVE 214 * [in] memref[1] A string holding the file name 215 */ 216 #define OPTEE_RPC_FS_REMOVE 6 217 218 /* 219 * Rename a file 220 * 221 * [in] value[0].a OPTEE_RPC_FS_RENAME 222 * [in] value[0].b True if existing target should be removed 223 * [in] memref[1] A string holding the old file name 224 * [in] memref[2] A string holding the new file name 225 */ 226 #define OPTEE_RPC_FS_RENAME 7 227 228 /* 229 * Opens a directory for file listing 230 * 231 * [in] value[0].a OPTEE_RPC_FS_OPENDIR 232 * [in] memref[1] A string holding the name of the directory 233 * [out] value[2].a Handle to open directory 234 */ 235 #define OPTEE_RPC_FS_OPENDIR 8 236 237 /* 238 * Closes a directory handle 239 * 240 * [in] value[0].a OPTEE_RPC_FS_CLOSEDIR 241 * [in] value[0].b Handle to open directory 242 */ 243 #define OPTEE_RPC_FS_CLOSEDIR 9 244 245 /* 246 * Read next file name of directory 247 * 248 * 249 * [in] value[0].a OPTEE_RPC_FS_READDIR 250 * [in] value[0].b Handle to open directory 251 * [out] memref[1] A string holding the file name 252 */ 253 #define OPTEE_RPC_FS_READDIR 10 254 255 /* End of definition of protocol for command OPTEE_RPC_CMD_FS */ 256 257 /* 258 * Definition of protocol for command OPTEE_RPC_CMD_SOCKET 259 */ 260 261 #define OPTEE_RPC_SOCKET_TIMEOUT_NONBLOCKING 0 262 #define OPTEE_RPC_SOCKET_TIMEOUT_BLOCKING 0xffffffff 263 264 /* 265 * Open socket 266 * 267 * [in] value[0].a OPTEE_RPC_SOCKET_OPEN 268 * [in] value[0].b TA instance id 269 * [in] value[1].a Server port number 270 * [in] value[1].b Protocol, TEE_ISOCKET_PROTOCOLID_* 271 * [in] value[1].c Ip version TEE_IP_VERSION_* from tee_ipsocket.h 272 * [in] memref[2] Server address 273 * [out] value[3].a Socket handle (32-bit) 274 */ 275 #define OPTEE_RPC_SOCKET_OPEN 0 276 277 /* 278 * Close socket 279 * 280 * [in] value[0].a OPTEE_RPC_SOCKET_CLOSE 281 * [in] value[0].b TA instance id 282 * [in] value[0].c Socket handle 283 */ 284 #define OPTEE_RPC_SOCKET_CLOSE 1 285 286 /* 287 * Close all sockets 288 * 289 * [in] value[0].a OPTEE_RPC_SOCKET_CLOSE_ALL 290 * [in] value[0].b TA instance id 291 */ 292 #define OPTEE_RPC_SOCKET_CLOSE_ALL 2 293 294 /* 295 * Send data on socket 296 * 297 * [in] value[0].a OPTEE_RPC_SOCKET_SEND 298 * [in] value[0].b TA instance id 299 * [in] value[0].c Socket handle 300 * [in] memref[1] Buffer to transmit 301 * [in] value[2].a Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_* 302 * [out] value[2].b Number of transmitted bytes 303 */ 304 #define OPTEE_RPC_SOCKET_SEND 3 305 306 /* 307 * Receive data on socket 308 * 309 * [in] value[0].a OPTEE_RPC_SOCKET_RECV 310 * [in] value[0].b TA instance id 311 * [in] value[0].c Socket handle 312 * [out] memref[1] Buffer to receive 313 * [in] value[2].a Timeout ms or OPTEE_RPC_SOCKET_TIMEOUT_* 314 */ 315 #define OPTEE_RPC_SOCKET_RECV 4 316 317 /* 318 * Perform IOCTL on socket 319 * 320 * [in] value[0].a OPTEE_RPC_SOCKET_IOCTL 321 * [in] value[0].b TA instance id 322 * [in] value[0].c Socket handle 323 * [in/out] memref[1] Buffer 324 * [in] value[2].a Ioctl command 325 */ 326 #define OPTEE_RPC_SOCKET_IOCTL 5 327 328 /* End of definition of protocol for command OPTEE_RPC_CMD_SOCKET */ 329 330 #endif /*__OPTEE_RPC_CMD_H*/ 331