Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 1 | From 1e43bd55c951da0610230c4f28a8ebdd13b30733 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jens Wiklander <jens.wiklander@linaro.org> |
| 3 | Date: Wed, 20 Jan 2021 11:14:12 +0100 |
| 4 | Subject: [PATCH 16/22] optee: sync OP-TEE headers |
| 5 | |
| 6 | Pulls in updates in the internal headers from OP-TEE OS [1]. A few |
| 7 | defines has been shortened, hence the changes in rpc.c. Defines not used |
| 8 | by the driver in tee_rpc_cmd.h has been filtered out. |
| 9 | |
| 10 | Note that this does not change the ABI. |
| 11 | |
| 12 | Link: [1] https://github.com/OP-TEE/optee_os |
| 13 | Reviewed-by: Sumit Garg <sumit.garg@linaro.org> |
| 14 | Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> |
| 15 | Change-Id: I5d20a22a3f38bfc9d232279d5f00505c4d3ba965 |
| 16 | |
| 17 | Upstream-Status: Backport [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.13-rc7&id=617d8e8b347edcee6da38df0aeb671fc9c9ba19c] |
| 18 | --- |
| 19 | drivers/tee/optee/optee_msg.h | 156 ++---------------------------- |
| 20 | drivers/tee/optee/optee_rpc_cmd.h | 103 ++++++++++++++++++++ |
| 21 | drivers/tee/optee/optee_smc.h | 70 +++++++++----- |
| 22 | drivers/tee/optee/rpc.c | 39 ++++---- |
| 23 | 4 files changed, 179 insertions(+), 189 deletions(-) |
| 24 | create mode 100644 drivers/tee/optee/optee_rpc_cmd.h |
| 25 | |
| 26 | diff --git a/drivers/tee/optee/optee_msg.h b/drivers/tee/optee/optee_msg.h |
| 27 | index c7ac7d02d6cc..5bef6a0165db 100644 |
| 28 | --- a/drivers/tee/optee/optee_msg.h |
| 29 | +++ b/drivers/tee/optee/optee_msg.h |
| 30 | @@ -1,6 +1,6 @@ |
| 31 | /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ |
| 32 | /* |
| 33 | - * Copyright (c) 2015-2019, Linaro Limited |
| 34 | + * Copyright (c) 2015-2021, Linaro Limited |
| 35 | */ |
| 36 | #ifndef _OPTEE_MSG_H |
| 37 | #define _OPTEE_MSG_H |
| 38 | @@ -12,11 +12,9 @@ |
| 39 | * This file defines the OP-TEE message protocol (ABI) used to communicate |
| 40 | * with an instance of OP-TEE running in secure world. |
| 41 | * |
| 42 | - * This file is divided into three sections. |
| 43 | + * This file is divided into two sections. |
| 44 | * 1. Formatting of messages. |
| 45 | * 2. Requests from normal world |
| 46 | - * 3. Requests from secure world, Remote Procedure Call (RPC), handled by |
| 47 | - * tee-supplicant. |
| 48 | */ |
| 49 | |
| 50 | /***************************************************************************** |
| 51 | @@ -54,8 +52,8 @@ |
| 52 | * Every entry in buffer should point to a 4k page beginning (12 least |
| 53 | * significant bits must be equal to zero). |
| 54 | * |
| 55 | - * 12 least significant bints of optee_msg_param.u.tmem.buf_ptr should hold page |
| 56 | - * offset of the user buffer. |
| 57 | + * 12 least significant bits of optee_msg_param.u.tmem.buf_ptr should hold |
| 58 | + * page offset of user buffer. |
| 59 | * |
| 60 | * So, entries should be placed like members of this structure: |
| 61 | * |
| 62 | @@ -178,17 +176,9 @@ struct optee_msg_param { |
| 63 | * @params: the parameters supplied to the OS Command |
| 64 | * |
| 65 | * All normal calls to Trusted OS uses this struct. If cmd requires further |
| 66 | - * information than what these field holds it can be passed as a parameter |
| 67 | + * information than what these fields hold it can be passed as a parameter |
| 68 | * tagged as meta (setting the OPTEE_MSG_ATTR_META bit in corresponding |
| 69 | - * attrs field). All parameters tagged as meta has to come first. |
| 70 | - * |
| 71 | - * Temp memref parameters can be fragmented if supported by the Trusted OS |
| 72 | - * (when optee_smc.h is bearer of this protocol this is indicated with |
| 73 | - * OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM). If a logical memref parameter is |
| 74 | - * fragmented then has all but the last fragment the |
| 75 | - * OPTEE_MSG_ATTR_FRAGMENT bit set in attrs. Even if a memref is fragmented |
| 76 | - * it will still be presented as a single logical memref to the Trusted |
| 77 | - * Application. |
| 78 | + * attrs field). All parameters tagged as meta have to come first. |
| 79 | */ |
| 80 | struct optee_msg_arg { |
| 81 | u32 cmd; |
| 82 | @@ -292,15 +282,12 @@ struct optee_msg_arg { |
| 83 | * OPTEE_MSG_CMD_REGISTER_SHM registers a shared memory reference. The |
| 84 | * information is passed as: |
| 85 | * [in] param[0].attr OPTEE_MSG_ATTR_TYPE_TMEM_INPUT |
| 86 | - * [| OPTEE_MSG_ATTR_FRAGMENT] |
| 87 | + * [| OPTEE_MSG_ATTR_NONCONTIG] |
| 88 | * [in] param[0].u.tmem.buf_ptr physical address (of first fragment) |
| 89 | * [in] param[0].u.tmem.size size (of first fragment) |
| 90 | * [in] param[0].u.tmem.shm_ref holds shared memory reference |
| 91 | - * ... |
| 92 | - * The shared memory can optionally be fragmented, temp memrefs can follow |
| 93 | - * each other with all but the last with the OPTEE_MSG_ATTR_FRAGMENT bit set. |
| 94 | * |
| 95 | - * OPTEE_MSG_CMD_UNREGISTER_SHM unregisteres a previously registered shared |
| 96 | + * OPTEE_MSG_CMD_UNREGISTER_SHM unregisters a previously registered shared |
| 97 | * memory reference. The information is passed as: |
| 98 | * [in] param[0].attr OPTEE_MSG_ATTR_TYPE_RMEM_INPUT |
| 99 | * [in] param[0].u.rmem.shm_ref holds shared memory reference |
| 100 | @@ -315,131 +302,4 @@ struct optee_msg_arg { |
| 101 | #define OPTEE_MSG_CMD_UNREGISTER_SHM 5 |
| 102 | #define OPTEE_MSG_FUNCID_CALL_WITH_ARG 0x0004 |
| 103 | |
| 104 | -/***************************************************************************** |
| 105 | - * Part 3 - Requests from secure world, RPC |
| 106 | - *****************************************************************************/ |
| 107 | - |
| 108 | -/* |
| 109 | - * All RPC is done with a struct optee_msg_arg as bearer of information, |
| 110 | - * struct optee_msg_arg::arg holds values defined by OPTEE_MSG_RPC_CMD_* below |
| 111 | - * |
| 112 | - * RPC communication with tee-supplicant is reversed compared to normal |
| 113 | - * client communication desribed above. The supplicant receives requests |
| 114 | - * and sends responses. |
| 115 | - */ |
| 116 | - |
| 117 | -/* |
| 118 | - * Load a TA into memory, defined in tee-supplicant |
| 119 | - */ |
| 120 | -#define OPTEE_MSG_RPC_CMD_LOAD_TA 0 |
| 121 | - |
| 122 | -/* |
| 123 | - * Reserved |
| 124 | - */ |
| 125 | -#define OPTEE_MSG_RPC_CMD_RPMB 1 |
| 126 | - |
| 127 | -/* |
| 128 | - * File system access, defined in tee-supplicant |
| 129 | - */ |
| 130 | -#define OPTEE_MSG_RPC_CMD_FS 2 |
| 131 | - |
| 132 | -/* |
| 133 | - * Get time |
| 134 | - * |
| 135 | - * Returns number of seconds and nano seconds since the Epoch, |
| 136 | - * 1970-01-01 00:00:00 +0000 (UTC). |
| 137 | - * |
| 138 | - * [out] param[0].u.value.a Number of seconds |
| 139 | - * [out] param[0].u.value.b Number of nano seconds. |
| 140 | - */ |
| 141 | -#define OPTEE_MSG_RPC_CMD_GET_TIME 3 |
| 142 | - |
| 143 | -/* |
| 144 | - * Wait queue primitive, helper for secure world to implement a wait queue. |
| 145 | - * |
| 146 | - * If secure world need to wait for a secure world mutex it issues a sleep |
| 147 | - * request instead of spinning in secure world. Conversely is a wakeup |
| 148 | - * request issued when a secure world mutex with a thread waiting thread is |
| 149 | - * unlocked. |
| 150 | - * |
| 151 | - * Waiting on a key |
| 152 | - * [in] param[0].u.value.a OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP |
| 153 | - * [in] param[0].u.value.b wait key |
| 154 | - * |
| 155 | - * Waking up a key |
| 156 | - * [in] param[0].u.value.a OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP |
| 157 | - * [in] param[0].u.value.b wakeup key |
| 158 | - */ |
| 159 | -#define OPTEE_MSG_RPC_CMD_WAIT_QUEUE 4 |
| 160 | -#define OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP 0 |
| 161 | -#define OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP 1 |
| 162 | - |
| 163 | -/* |
| 164 | - * Suspend execution |
| 165 | - * |
| 166 | - * [in] param[0].value .a number of milliseconds to suspend |
| 167 | - */ |
| 168 | -#define OPTEE_MSG_RPC_CMD_SUSPEND 5 |
| 169 | - |
| 170 | -/* |
| 171 | - * Allocate a piece of shared memory |
| 172 | - * |
| 173 | - * Shared memory can optionally be fragmented, to support that additional |
| 174 | - * spare param entries are allocated to make room for eventual fragments. |
| 175 | - * The spare param entries has .attr = OPTEE_MSG_ATTR_TYPE_NONE when |
| 176 | - * unused. All returned temp memrefs except the last should have the |
| 177 | - * OPTEE_MSG_ATTR_FRAGMENT bit set in the attr field. |
| 178 | - * |
| 179 | - * [in] param[0].u.value.a type of memory one of |
| 180 | - * OPTEE_MSG_RPC_SHM_TYPE_* below |
| 181 | - * [in] param[0].u.value.b requested size |
| 182 | - * [in] param[0].u.value.c required alignment |
| 183 | - * |
| 184 | - * [out] param[0].u.tmem.buf_ptr physical address (of first fragment) |
| 185 | - * [out] param[0].u.tmem.size size (of first fragment) |
| 186 | - * [out] param[0].u.tmem.shm_ref shared memory reference |
| 187 | - * ... |
| 188 | - * [out] param[n].u.tmem.buf_ptr physical address |
| 189 | - * [out] param[n].u.tmem.size size |
| 190 | - * [out] param[n].u.tmem.shm_ref shared memory reference (same value |
| 191 | - * as in param[n-1].u.tmem.shm_ref) |
| 192 | - */ |
| 193 | -#define OPTEE_MSG_RPC_CMD_SHM_ALLOC 6 |
| 194 | -/* Memory that can be shared with a non-secure user space application */ |
| 195 | -#define OPTEE_MSG_RPC_SHM_TYPE_APPL 0 |
| 196 | -/* Memory only shared with non-secure kernel */ |
| 197 | -#define OPTEE_MSG_RPC_SHM_TYPE_KERNEL 1 |
| 198 | - |
| 199 | -/* |
| 200 | - * Free shared memory previously allocated with OPTEE_MSG_RPC_CMD_SHM_ALLOC |
| 201 | - * |
| 202 | - * [in] param[0].u.value.a type of memory one of |
| 203 | - * OPTEE_MSG_RPC_SHM_TYPE_* above |
| 204 | - * [in] param[0].u.value.b value of shared memory reference |
| 205 | - * returned in param[0].u.tmem.shm_ref |
| 206 | - * above |
| 207 | - */ |
| 208 | -#define OPTEE_MSG_RPC_CMD_SHM_FREE 7 |
| 209 | - |
| 210 | -/* |
| 211 | - * Access a device on an i2c bus |
| 212 | - * |
| 213 | - * [in] param[0].u.value.a mode: RD(0), WR(1) |
| 214 | - * [in] param[0].u.value.b i2c adapter |
| 215 | - * [in] param[0].u.value.c i2c chip |
| 216 | - * |
| 217 | - * [in] param[1].u.value.a i2c control flags |
| 218 | - * |
| 219 | - * [in/out] memref[2] buffer to exchange the transfer data |
| 220 | - * with the secure world |
| 221 | - * |
| 222 | - * [out] param[3].u.value.a bytes transferred by the driver |
| 223 | - */ |
| 224 | -#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER 21 |
| 225 | -/* I2C master transfer modes */ |
| 226 | -#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD 0 |
| 227 | -#define OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR 1 |
| 228 | -/* I2C master control flags */ |
| 229 | -#define OPTEE_MSG_RPC_CMD_I2C_FLAGS_TEN_BIT BIT(0) |
| 230 | - |
| 231 | #endif /* _OPTEE_MSG_H */ |
| 232 | diff --git a/drivers/tee/optee/optee_rpc_cmd.h b/drivers/tee/optee/optee_rpc_cmd.h |
| 233 | new file mode 100644 |
| 234 | index 000000000000..b8275140cef8 |
| 235 | --- /dev/null |
| 236 | +++ b/drivers/tee/optee/optee_rpc_cmd.h |
| 237 | @@ -0,0 +1,103 @@ |
| 238 | +/* SPDX-License-Identifier: BSD-2-Clause */ |
| 239 | +/* |
| 240 | + * Copyright (c) 2016-2021, Linaro Limited |
| 241 | + */ |
| 242 | + |
| 243 | +#ifndef __OPTEE_RPC_CMD_H |
| 244 | +#define __OPTEE_RPC_CMD_H |
| 245 | + |
| 246 | +/* |
| 247 | + * All RPC is done with a struct optee_msg_arg as bearer of information, |
| 248 | + * struct optee_msg_arg::arg holds values defined by OPTEE_RPC_CMD_* below. |
| 249 | + * Only the commands handled by the kernel driver are defined here. |
| 250 | + * |
| 251 | + * RPC communication with tee-supplicant is reversed compared to normal |
| 252 | + * client communication described above. The supplicant receives requests |
| 253 | + * and sends responses. |
| 254 | + */ |
| 255 | + |
| 256 | +/* |
| 257 | + * Get time |
| 258 | + * |
| 259 | + * Returns number of seconds and nano seconds since the Epoch, |
| 260 | + * 1970-01-01 00:00:00 +0000 (UTC). |
| 261 | + * |
| 262 | + * [out] value[0].a Number of seconds |
| 263 | + * [out] value[0].b Number of nano seconds. |
| 264 | + */ |
| 265 | +#define OPTEE_RPC_CMD_GET_TIME 3 |
| 266 | + |
| 267 | +/* |
| 268 | + * Wait queue primitive, helper for secure world to implement a wait queue. |
| 269 | + * |
| 270 | + * If secure world needs to wait for a secure world mutex it issues a sleep |
| 271 | + * request instead of spinning in secure world. Conversely is a wakeup |
| 272 | + * request issued when a secure world mutex with a thread waiting thread is |
| 273 | + * unlocked. |
| 274 | + * |
| 275 | + * Waiting on a key |
| 276 | + * [in] value[0].a OPTEE_RPC_WAIT_QUEUE_SLEEP |
| 277 | + * [in] value[0].b Wait key |
| 278 | + * |
| 279 | + * Waking up a key |
| 280 | + * [in] value[0].a OPTEE_RPC_WAIT_QUEUE_WAKEUP |
| 281 | + * [in] value[0].b Wakeup key |
| 282 | + */ |
| 283 | +#define OPTEE_RPC_CMD_WAIT_QUEUE 4 |
| 284 | +#define OPTEE_RPC_WAIT_QUEUE_SLEEP 0 |
| 285 | +#define OPTEE_RPC_WAIT_QUEUE_WAKEUP 1 |
| 286 | + |
| 287 | +/* |
| 288 | + * Suspend execution |
| 289 | + * |
| 290 | + * [in] value[0].a Number of milliseconds to suspend |
| 291 | + */ |
| 292 | +#define OPTEE_RPC_CMD_SUSPEND 5 |
| 293 | + |
| 294 | +/* |
| 295 | + * Allocate a piece of shared memory |
| 296 | + * |
| 297 | + * [in] value[0].a Type of memory one of |
| 298 | + * OPTEE_RPC_SHM_TYPE_* below |
| 299 | + * [in] value[0].b Requested size |
| 300 | + * [in] value[0].c Required alignment |
| 301 | + * [out] memref[0] Buffer |
| 302 | + */ |
| 303 | +#define OPTEE_RPC_CMD_SHM_ALLOC 6 |
| 304 | +/* Memory that can be shared with a non-secure user space application */ |
| 305 | +#define OPTEE_RPC_SHM_TYPE_APPL 0 |
| 306 | +/* Memory only shared with non-secure kernel */ |
| 307 | +#define OPTEE_RPC_SHM_TYPE_KERNEL 1 |
| 308 | + |
| 309 | +/* |
| 310 | + * Free shared memory previously allocated with OPTEE_RPC_CMD_SHM_ALLOC |
| 311 | + * |
| 312 | + * [in] value[0].a Type of memory one of |
| 313 | + * OPTEE_RPC_SHM_TYPE_* above |
| 314 | + * [in] value[0].b Value of shared memory reference or cookie |
| 315 | + */ |
| 316 | +#define OPTEE_RPC_CMD_SHM_FREE 7 |
| 317 | + |
| 318 | +/* |
| 319 | + * Issue master requests (read and write operations) to an I2C chip. |
| 320 | + * |
| 321 | + * [in] value[0].a Transfer mode (OPTEE_RPC_I2C_TRANSFER_*) |
| 322 | + * [in] value[0].b The I2C bus (a.k.a adapter). |
| 323 | + * 16 bit field. |
| 324 | + * [in] value[0].c The I2C chip (a.k.a address). |
| 325 | + * 16 bit field (either 7 or 10 bit effective). |
| 326 | + * [in] value[1].a The I2C master control flags (ie, 10 bit address). |
| 327 | + * 16 bit field. |
| 328 | + * [in/out] memref[2] Buffer used for data transfers. |
| 329 | + * [out] value[3].a Number of bytes transferred by the REE. |
| 330 | + */ |
| 331 | +#define OPTEE_RPC_CMD_I2C_TRANSFER 21 |
| 332 | + |
| 333 | +/* I2C master transfer modes */ |
| 334 | +#define OPTEE_RPC_I2C_TRANSFER_RD 0 |
| 335 | +#define OPTEE_RPC_I2C_TRANSFER_WR 1 |
| 336 | + |
| 337 | +/* I2C master control flags */ |
| 338 | +#define OPTEE_RPC_I2C_FLAGS_TEN_BIT BIT(0) |
| 339 | + |
| 340 | +#endif /*__OPTEE_RPC_CMD_H*/ |
| 341 | diff --git a/drivers/tee/optee/optee_smc.h b/drivers/tee/optee/optee_smc.h |
| 342 | index 777ad54d4c2c..821e1c30c150 100644 |
| 343 | --- a/drivers/tee/optee/optee_smc.h |
| 344 | +++ b/drivers/tee/optee/optee_smc.h |
| 345 | @@ -1,6 +1,6 @@ |
| 346 | /* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */ |
| 347 | /* |
| 348 | - * Copyright (c) 2015-2019, Linaro Limited |
| 349 | + * Copyright (c) 2015-2021, Linaro Limited |
| 350 | */ |
| 351 | #ifndef OPTEE_SMC_H |
| 352 | #define OPTEE_SMC_H |
| 353 | @@ -39,10 +39,10 @@ |
| 354 | /* |
| 355 | * Function specified by SMC Calling convention |
| 356 | * |
| 357 | - * Return one of the following UIDs if using API specified in this file |
| 358 | - * without further extentions: |
| 359 | - * 65cb6b93-af0c-4617-8ed6-644a8d1140f8 |
| 360 | - * see also OPTEE_SMC_UID_* in optee_msg.h |
| 361 | + * Return the following UID if using API specified in this file |
| 362 | + * without further extensions: |
| 363 | + * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b. |
| 364 | + * see also OPTEE_MSG_UID_* in optee_msg.h |
| 365 | */ |
| 366 | #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID |
| 367 | #define OPTEE_SMC_CALLS_UID \ |
| 368 | @@ -53,7 +53,7 @@ |
| 369 | /* |
| 370 | * Function specified by SMC Calling convention |
| 371 | * |
| 372 | - * Returns 2.0 if using API specified in this file without further extentions. |
| 373 | + * Returns 2.0 if using API specified in this file without further extensions. |
| 374 | * see also OPTEE_MSG_REVISION_* in optee_msg.h |
| 375 | */ |
| 376 | #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION |
| 377 | @@ -109,8 +109,8 @@ struct optee_smc_call_get_os_revision_result { |
| 378 | * |
| 379 | * Call register usage: |
| 380 | * a0 SMC Function ID, OPTEE_SMC*CALL_WITH_ARG |
| 381 | - * a1 Upper 32bit of a 64bit physical pointer to a struct optee_msg_arg |
| 382 | - * a2 Lower 32bit of a 64bit physical pointer to a struct optee_msg_arg |
| 383 | + * a1 Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg |
| 384 | + * a2 Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg |
| 385 | * a3 Cache settings, not used if physical pointer is in a predefined shared |
| 386 | * memory area else per OPTEE_SMC_SHM_* |
| 387 | * a4-6 Not used |
| 388 | @@ -214,8 +214,9 @@ struct optee_smc_get_shm_config_result { |
| 389 | * secure world accepts command buffers located in any parts of non-secure RAM |
| 390 | */ |
| 391 | #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2) |
| 392 | - |
| 393 | -/* Secure world supports Shared Memory with a NULL buffer reference */ |
| 394 | +/* Secure world is built with virtualization support */ |
| 395 | +#define OPTEE_SMC_SEC_CAP_VIRTUALIZATION BIT(3) |
| 396 | +/* Secure world supports Shared Memory with a NULL reference */ |
| 397 | #define OPTEE_SMC_SEC_CAP_MEMREF_NULL BIT(4) |
| 398 | |
| 399 | #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9 |
| 400 | @@ -245,8 +246,8 @@ struct optee_smc_exchange_capabilities_result { |
| 401 | * |
| 402 | * Normal return register usage: |
| 403 | * a0 OPTEE_SMC_RETURN_OK |
| 404 | - * a1 Upper 32bit of a 64bit Shared memory cookie |
| 405 | - * a2 Lower 32bit of a 64bit Shared memory cookie |
| 406 | + * a1 Upper 32 bits of a 64-bit Shared memory cookie |
| 407 | + * a2 Lower 32 bits of a 64-bit Shared memory cookie |
| 408 | * a3-7 Preserved |
| 409 | * |
| 410 | * Cache empty return register usage: |
| 411 | @@ -293,6 +294,31 @@ struct optee_smc_disable_shm_cache_result { |
| 412 | #define OPTEE_SMC_ENABLE_SHM_CACHE \ |
| 413 | OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE) |
| 414 | |
| 415 | +/* |
| 416 | + * Query OP-TEE about number of supported threads |
| 417 | + * |
| 418 | + * Normal World OS or Hypervisor issues this call to find out how many |
| 419 | + * threads OP-TEE supports. That is how many standard calls can be issued |
| 420 | + * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT. |
| 421 | + * |
| 422 | + * Call requests usage: |
| 423 | + * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT |
| 424 | + * a1-6 Not used |
| 425 | + * a7 Hypervisor Client ID register |
| 426 | + * |
| 427 | + * Normal return register usage: |
| 428 | + * a0 OPTEE_SMC_RETURN_OK |
| 429 | + * a1 Number of threads |
| 430 | + * a2-7 Preserved |
| 431 | + * |
| 432 | + * Error return: |
| 433 | + * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented |
| 434 | + * a1-7 Preserved |
| 435 | + */ |
| 436 | +#define OPTEE_SMC_FUNCID_GET_THREAD_COUNT 15 |
| 437 | +#define OPTEE_SMC_GET_THREAD_COUNT \ |
| 438 | + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT) |
| 439 | + |
| 440 | /* |
| 441 | * Resume from RPC (for example after processing a foreign interrupt) |
| 442 | * |
| 443 | @@ -341,16 +367,16 @@ struct optee_smc_disable_shm_cache_result { |
| 444 | * |
| 445 | * "Return" register usage: |
| 446 | * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. |
| 447 | - * a1 Upper 32bits of 64bit physical pointer to allocated |
| 448 | + * a1 Upper 32 bits of 64-bit physical pointer to allocated |
| 449 | * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't |
| 450 | * be allocated. |
| 451 | - * a2 Lower 32bits of 64bit physical pointer to allocated |
| 452 | + * a2 Lower 32 bits of 64-bit physical pointer to allocated |
| 453 | * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't |
| 454 | * be allocated |
| 455 | * a3 Preserved |
| 456 | - * a4 Upper 32bits of 64bit Shared memory cookie used when freeing |
| 457 | + * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing |
| 458 | * the memory or doing an RPC |
| 459 | - * a5 Lower 32bits of 64bit Shared memory cookie used when freeing |
| 460 | + * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing |
| 461 | * the memory or doing an RPC |
| 462 | * a6-7 Preserved |
| 463 | */ |
| 464 | @@ -363,9 +389,9 @@ struct optee_smc_disable_shm_cache_result { |
| 465 | * |
| 466 | * "Call" register usage: |
| 467 | * a0 This value, OPTEE_SMC_RETURN_RPC_FREE |
| 468 | - * a1 Upper 32bits of 64bit shared memory cookie belonging to this |
| 469 | + * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this |
| 470 | * argument memory |
| 471 | - * a2 Lower 32bits of 64bit shared memory cookie belonging to this |
| 472 | + * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this |
| 473 | * argument memory |
| 474 | * a3-7 Resume information, must be preserved |
| 475 | * |
| 476 | @@ -379,7 +405,7 @@ struct optee_smc_disable_shm_cache_result { |
| 477 | OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE) |
| 478 | |
| 479 | /* |
| 480 | - * Deliver foreign interrupt to normal world. |
| 481 | + * Deliver a foreign interrupt in normal world. |
| 482 | * |
| 483 | * "Call" register usage: |
| 484 | * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR |
| 485 | @@ -389,7 +415,7 @@ struct optee_smc_disable_shm_cache_result { |
| 486 | * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. |
| 487 | * a1-7 Preserved |
| 488 | */ |
| 489 | -#define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4 |
| 490 | +#define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4 |
| 491 | #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \ |
| 492 | OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR) |
| 493 | |
| 494 | @@ -405,10 +431,10 @@ struct optee_smc_disable_shm_cache_result { |
| 495 | * |
| 496 | * "Call" register usage: |
| 497 | * a0 OPTEE_SMC_RETURN_RPC_CMD |
| 498 | - * a1 Upper 32bit of a 64bit Shared memory cookie holding a |
| 499 | + * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a |
| 500 | * struct optee_msg_arg, must be preserved, only the data should |
| 501 | * be updated |
| 502 | - * a2 Lower 32bit of a 64bit Shared memory cookie holding a |
| 503 | + * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a |
| 504 | * struct optee_msg_arg, must be preserved, only the data should |
| 505 | * be updated |
| 506 | * a3-7 Resume information, must be preserved |
| 507 | diff --git a/drivers/tee/optee/rpc.c b/drivers/tee/optee/rpc.c |
| 508 | index 6cbb3643c6c4..1849180b0278 100644 |
| 509 | --- a/drivers/tee/optee/rpc.c |
| 510 | +++ b/drivers/tee/optee/rpc.c |
| 511 | @@ -12,6 +12,7 @@ |
| 512 | #include <linux/tee_drv.h> |
| 513 | #include "optee_private.h" |
| 514 | #include "optee_smc.h" |
| 515 | +#include "optee_rpc_cmd.h" |
| 516 | |
| 517 | struct wq_entry { |
| 518 | struct list_head link; |
| 519 | @@ -90,7 +91,7 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, |
| 520 | if (!adapter) |
| 521 | goto bad; |
| 522 | |
| 523 | - if (params[1].u.value.a & OPTEE_MSG_RPC_CMD_I2C_FLAGS_TEN_BIT) { |
| 524 | + if (params[1].u.value.a & OPTEE_RPC_I2C_FLAGS_TEN_BIT) { |
| 525 | if (!i2c_check_functionality(adapter, |
| 526 | I2C_FUNC_10BIT_ADDR)) { |
| 527 | i2c_put_adapter(adapter); |
| 528 | @@ -105,10 +106,10 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx, |
| 529 | msg.len = params[2].u.memref.size; |
| 530 | |
| 531 | switch (params[0].u.value.a) { |
| 532 | - case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_RD: |
| 533 | + case OPTEE_RPC_I2C_TRANSFER_RD: |
| 534 | msg.flags |= I2C_M_RD; |
| 535 | break; |
| 536 | - case OPTEE_MSG_RPC_CMD_I2C_TRANSFER_WR: |
| 537 | + case OPTEE_RPC_I2C_TRANSFER_WR: |
| 538 | break; |
| 539 | default: |
| 540 | i2c_put_adapter(adapter); |
| 541 | @@ -195,10 +196,10 @@ static void handle_rpc_func_cmd_wq(struct optee *optee, |
| 542 | goto bad; |
| 543 | |
| 544 | switch (arg->params[0].u.value.a) { |
| 545 | - case OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP: |
| 546 | + case OPTEE_RPC_WAIT_QUEUE_SLEEP: |
| 547 | wq_sleep(&optee->wait_queue, arg->params[0].u.value.b); |
| 548 | break; |
| 549 | - case OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP: |
| 550 | + case OPTEE_RPC_WAIT_QUEUE_WAKEUP: |
| 551 | wq_wakeup(&optee->wait_queue, arg->params[0].u.value.b); |
| 552 | break; |
| 553 | default: |
| 554 | @@ -268,11 +269,11 @@ static struct tee_shm *cmd_alloc_suppl(struct tee_context *ctx, size_t sz) |
| 555 | struct tee_shm *shm; |
| 556 | |
| 557 | param.attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT; |
| 558 | - param.u.value.a = OPTEE_MSG_RPC_SHM_TYPE_APPL; |
| 559 | + param.u.value.a = OPTEE_RPC_SHM_TYPE_APPL; |
| 560 | param.u.value.b = sz; |
| 561 | param.u.value.c = 0; |
| 562 | |
| 563 | - ret = optee_supp_thrd_req(ctx, OPTEE_MSG_RPC_CMD_SHM_ALLOC, 1, ¶m); |
| 564 | + ret = optee_supp_thrd_req(ctx, OPTEE_RPC_CMD_SHM_ALLOC, 1, ¶m); |
| 565 | if (ret) |
| 566 | return ERR_PTR(-ENOMEM); |
| 567 | |
| 568 | @@ -309,10 +310,10 @@ static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, |
| 569 | |
| 570 | sz = arg->params[0].u.value.b; |
| 571 | switch (arg->params[0].u.value.a) { |
| 572 | - case OPTEE_MSG_RPC_SHM_TYPE_APPL: |
| 573 | + case OPTEE_RPC_SHM_TYPE_APPL: |
| 574 | shm = cmd_alloc_suppl(ctx, sz); |
| 575 | break; |
| 576 | - case OPTEE_MSG_RPC_SHM_TYPE_KERNEL: |
| 577 | + case OPTEE_RPC_SHM_TYPE_KERNEL: |
| 578 | shm = tee_shm_alloc(ctx, sz, TEE_SHM_MAPPED); |
| 579 | break; |
| 580 | default: |
| 581 | @@ -384,7 +385,7 @@ static void cmd_free_suppl(struct tee_context *ctx, struct tee_shm *shm) |
| 582 | struct tee_param param; |
| 583 | |
| 584 | param.attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT; |
| 585 | - param.u.value.a = OPTEE_MSG_RPC_SHM_TYPE_APPL; |
| 586 | + param.u.value.a = OPTEE_RPC_SHM_TYPE_APPL; |
| 587 | param.u.value.b = tee_shm_get_id(shm); |
| 588 | param.u.value.c = 0; |
| 589 | |
| 590 | @@ -401,7 +402,7 @@ static void cmd_free_suppl(struct tee_context *ctx, struct tee_shm *shm) |
| 591 | */ |
| 592 | tee_shm_put(shm); |
| 593 | |
| 594 | - optee_supp_thrd_req(ctx, OPTEE_MSG_RPC_CMD_SHM_FREE, 1, ¶m); |
| 595 | + optee_supp_thrd_req(ctx, OPTEE_RPC_CMD_SHM_FREE, 1, ¶m); |
| 596 | } |
| 597 | |
| 598 | static void handle_rpc_func_cmd_shm_free(struct tee_context *ctx, |
| 599 | @@ -419,10 +420,10 @@ static void handle_rpc_func_cmd_shm_free(struct tee_context *ctx, |
| 600 | |
| 601 | shm = (struct tee_shm *)(unsigned long)arg->params[0].u.value.b; |
| 602 | switch (arg->params[0].u.value.a) { |
| 603 | - case OPTEE_MSG_RPC_SHM_TYPE_APPL: |
| 604 | + case OPTEE_RPC_SHM_TYPE_APPL: |
| 605 | cmd_free_suppl(ctx, shm); |
| 606 | break; |
| 607 | - case OPTEE_MSG_RPC_SHM_TYPE_KERNEL: |
| 608 | + case OPTEE_RPC_SHM_TYPE_KERNEL: |
| 609 | tee_shm_free(shm); |
| 610 | break; |
| 611 | default: |
| 612 | @@ -459,23 +460,23 @@ static void handle_rpc_func_cmd(struct tee_context *ctx, struct optee *optee, |
| 613 | } |
| 614 | |
| 615 | switch (arg->cmd) { |
| 616 | - case OPTEE_MSG_RPC_CMD_GET_TIME: |
| 617 | + case OPTEE_RPC_CMD_GET_TIME: |
| 618 | handle_rpc_func_cmd_get_time(arg); |
| 619 | break; |
| 620 | - case OPTEE_MSG_RPC_CMD_WAIT_QUEUE: |
| 621 | + case OPTEE_RPC_CMD_WAIT_QUEUE: |
| 622 | handle_rpc_func_cmd_wq(optee, arg); |
| 623 | break; |
| 624 | - case OPTEE_MSG_RPC_CMD_SUSPEND: |
| 625 | + case OPTEE_RPC_CMD_SUSPEND: |
| 626 | handle_rpc_func_cmd_wait(arg); |
| 627 | break; |
| 628 | - case OPTEE_MSG_RPC_CMD_SHM_ALLOC: |
| 629 | + case OPTEE_RPC_CMD_SHM_ALLOC: |
| 630 | free_pages_list(call_ctx); |
| 631 | handle_rpc_func_cmd_shm_alloc(ctx, arg, call_ctx); |
| 632 | break; |
| 633 | - case OPTEE_MSG_RPC_CMD_SHM_FREE: |
| 634 | + case OPTEE_RPC_CMD_SHM_FREE: |
| 635 | handle_rpc_func_cmd_shm_free(ctx, arg); |
| 636 | break; |
| 637 | - case OPTEE_MSG_RPC_CMD_I2C_TRANSFER: |
| 638 | + case OPTEE_RPC_CMD_I2C_TRANSFER: |
| 639 | handle_rpc_func_cmd_i2c_transfer(ctx, arg); |
| 640 | break; |
| 641 | default: |
| 642 | -- |
| 643 | 2.17.1 |
| 644 | |