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