File Index
Files and directories
Sign in
FILE

optee_smc.h

File preview with syntax highlighting.

linux-6.19.14/drivers/tee/optee/optee_smc.h C
  1/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
  2/*
  3 * Copyright (c) 2015-2021, Linaro Limited
  4 */
  5#ifndef OPTEE_SMC_H
  6#define OPTEE_SMC_H
  7
  8#include <linux/arm-smccc.h>
  9#include <linux/bitops.h>
 10
 11#define OPTEE_SMC_STD_CALL_VAL(func_num) \
 12	ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
 13			   ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
 14#define OPTEE_SMC_FAST_CALL_VAL(func_num) \
 15	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
 16			   ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
 17
 18/*
 19 * Function specified by SMC Calling convention.
 20 */
 21#define OPTEE_SMC_FUNCID_CALLS_COUNT	0xFF00
 22#define OPTEE_SMC_CALLS_COUNT \
 23	ARM_SMCCC_CALL_VAL(OPTEE_SMC_FAST_CALL, SMCCC_SMC_32, \
 24			   SMCCC_OWNER_TRUSTED_OS_END, \
 25			   OPTEE_SMC_FUNCID_CALLS_COUNT)
 26
 27/*
 28 * Normal cached memory (write-back), shareable for SMP systems and not
 29 * shareable for UP systems.
 30 */
 31#define OPTEE_SMC_SHM_CACHED		1
 32
 33/*
 34 * a0..a7 is used as register names in the descriptions below, on arm32
 35 * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's
 36 * 32-bit registers.
 37 */
 38
 39/*
 40 * Function specified by SMC Calling convention
 41 *
 42 * Return the following UID if using API specified in this file
 43 * without further extensions:
 44 * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
 45 * see also OPTEE_MSG_UID_* in optee_msg.h
 46 */
 47#define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID
 48#define OPTEE_SMC_CALLS_UID \
 49	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
 50			   ARM_SMCCC_OWNER_TRUSTED_OS_END, \
 51			   OPTEE_SMC_FUNCID_CALLS_UID)
 52
 53/*
 54 * Function specified by SMC Calling convention
 55 *
 56 * Returns 2.0 if using API specified in this file without further extensions.
 57 * see also OPTEE_MSG_REVISION_* in optee_msg.h
 58 */
 59#define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION
 60#define OPTEE_SMC_CALLS_REVISION \
 61	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
 62			   ARM_SMCCC_OWNER_TRUSTED_OS_END, \
 63			   OPTEE_SMC_FUNCID_CALLS_REVISION)
 64
 65struct optee_smc_calls_revision_result {
 66	unsigned long major;
 67	unsigned long minor;
 68	unsigned long reserved0;
 69	unsigned long reserved1;
 70};
 71
 72/*
 73 * Get UUID of Trusted OS.
 74 *
 75 * Used by non-secure world to figure out which Trusted OS is installed.
 76 * Note that returned UUID is the UUID of the Trusted OS, not of the API.
 77 *
 78 * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID
 79 * described above.
 80 */
 81#define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID
 82#define OPTEE_SMC_CALL_GET_OS_UUID \
 83	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID)
 84
 85/*
 86 * Get revision of Trusted OS.
 87 *
 88 * Used by non-secure world to figure out which version of the Trusted OS
 89 * is installed. Note that the returned revision is the revision of the
 90 * Trusted OS, not of the API.
 91 *
 92 * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
 93 * described above. May optionally return a 32-bit build identifier in a2,
 94 * with zero meaning unspecified.
 95 */
 96#define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
 97#define OPTEE_SMC_CALL_GET_OS_REVISION \
 98	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION)
 99
100struct optee_smc_call_get_os_revision_result {
101	unsigned long major;
102	unsigned long minor;
103	unsigned long build_id;
104	unsigned long reserved1;
105};
106
107/*
108 * Load Trusted OS from optee/tee.bin in the Linux firmware.
109 *
110 * WARNING: Use this cautiously as it could lead to insecure loading of the
111 * Trusted OS.
112 * This SMC instructs EL3 to load a binary and execute it as the Trusted OS.
113 *
114 * Call register usage:
115 * a0 SMC Function ID, OPTEE_SMC_CALL_LOAD_IMAGE
116 * a1 Upper 32bit of a 64bit size for the payload
117 * a2 Lower 32bit of a 64bit size for the payload
118 * a3 Upper 32bit of the physical address for the payload
119 * a4 Lower 32bit of the physical address for the payload
120 *
121 * The payload is in the OP-TEE image format.
122 *
123 * Returns result in a0, 0 on success and an error code otherwise.
124 */
125#define OPTEE_SMC_FUNCID_LOAD_IMAGE 2
126#define OPTEE_SMC_CALL_LOAD_IMAGE \
127	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
128			   ARM_SMCCC_OWNER_TRUSTED_OS_END, \
129			   OPTEE_SMC_FUNCID_LOAD_IMAGE)
130
131/*
132 * Call with struct optee_msg_arg as argument
133 *
134 * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or
135 * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg
136 * following after the first struct optee_msg_arg. The RPC struct
137 * optee_msg_arg has reserved space for the number of RPC parameters as
138 * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES.
139 *
140 * When calling these functions, normal world has a few responsibilities:
141 * 1. It must be able to handle eventual RPCs
142 * 2. Non-secure interrupts should not be masked
143 * 3. If asynchronous notifications has been negotiated successfully, then
144 *    the interrupt for asynchronous notifications should be unmasked
145 *    during this call.
146 *
147 * Call register usage, OPTEE_SMC_CALL_WITH_ARG and
148 * OPTEE_SMC_CALL_WITH_RPC_ARG:
149 * a0	SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG
150 * a1	Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
151 * a2	Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
152 * a3	Cache settings, not used if physical pointer is in a predefined shared
153 *	memory area else per OPTEE_SMC_SHM_*
154 * a4-6	Not used
155 * a7	Hypervisor Client ID register
156 *
157 * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG:
158 * a0	SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG
159 * a1	Upper 32 bits of a 64-bit shared memory cookie
160 * a2	Lower 32 bits of a 64-bit shared memory cookie
161 * a3	Offset of the struct optee_msg_arg in the shared memory with the
162 *	supplied cookie
163 * a4-6	Not used
164 * a7	Hypervisor Client ID register
165 *
166 * Normal return register usage:
167 * a0	Return value, OPTEE_SMC_RETURN_*
168 * a1-3	Not used
169 * a4-7	Preserved
170 *
171 * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
172 * a0	Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
173 * a1-3	Preserved
174 * a4-7	Preserved
175 *
176 * RPC return register usage:
177 * a0	Return value, OPTEE_SMC_RETURN_IS_RPC(val)
178 * a1-2	RPC parameters
179 * a3-7	Resume information, must be preserved
180 *
181 * Possible return values:
182 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
183 *					function.
184 * OPTEE_SMC_RETURN_OK			Call completed, result updated in
185 *					the previously supplied struct
186 *					optee_msg_arg.
187 * OPTEE_SMC_RETURN_ETHREAD_LIMIT	Number of Trusted OS threads exceeded,
188 *					try again later.
189 * OPTEE_SMC_RETURN_EBADADDR		Bad physical pointer to struct
190 *					optee_msg_arg.
191 * OPTEE_SMC_RETURN_EBADCMD		Bad/unknown cmd in struct optee_msg_arg
192 * OPTEE_SMC_RETURN_IS_RPC()		Call suspended by RPC call to normal
193 *					world.
194 */
195#define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
196#define OPTEE_SMC_CALL_WITH_ARG \
197	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG)
198#define OPTEE_SMC_CALL_WITH_RPC_ARG \
199	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG)
200#define OPTEE_SMC_CALL_WITH_REGD_ARG \
201	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG)
202
203/*
204 * Get Shared Memory Config
205 *
206 * Returns the Secure/Non-secure shared memory config.
207 *
208 * Call register usage:
209 * a0	SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
210 * a1-6	Not used
211 * a7	Hypervisor Client ID register
212 *
213 * Have config return register usage:
214 * a0	OPTEE_SMC_RETURN_OK
215 * a1	Physical address of start of SHM
216 * a2	Size of SHM
217 * a3	Cache settings of memory, as defined by the
218 *	OPTEE_SMC_SHM_* values above
219 * a4-7	Preserved
220 *
221 * Not available register usage:
222 * a0	OPTEE_SMC_RETURN_ENOTAVAIL
223 * a1-3 Not used
224 * a4-7	Preserved
225 */
226#define OPTEE_SMC_FUNCID_GET_SHM_CONFIG	7
227#define OPTEE_SMC_GET_SHM_CONFIG \
228	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
229
230struct optee_smc_get_shm_config_result {
231	unsigned long status;
232	unsigned long start;
233	unsigned long size;
234	unsigned long settings;
235};
236
237/*
238 * Exchanges capabilities between normal world and secure world
239 *
240 * Call register usage:
241 * a0	SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
242 * a1	bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
243 * a2-6	Not used
244 * a7	Hypervisor Client ID register
245 *
246 * Normal return register usage:
247 * a0	OPTEE_SMC_RETURN_OK
248 * a1	bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
249 * a2	The maximum secure world notification number
250 * a3	Bit[7:0]: Number of parameters needed for RPC to be supplied
251 *		  as the second MSG arg struct for
252 *		  OPTEE_SMC_CALL_WITH_ARG
253 *	Bit[31:8]: Reserved (MBZ)
254 * a4-7	Preserved
255 *
256 * Error return register usage:
257 * a0	OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
258 * a1	bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
259 * a2-7 Preserved
260 */
261/* Normal world works as a uniprocessor system */
262#define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR		BIT(0)
263/* Secure world has reserved shared memory for normal world to use */
264#define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM	BIT(0)
265/* Secure world can communicate via previously unregistered shared memory */
266#define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM	BIT(1)
267/*
268 * Secure world supports commands "register/unregister shared memory",
269 * secure world accepts command buffers located in any parts of non-secure RAM
270 */
271#define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM		BIT(2)
272/* Secure world is built with virtualization support */
273#define OPTEE_SMC_SEC_CAP_VIRTUALIZATION	BIT(3)
274/* Secure world supports Shared Memory with a NULL reference */
275#define OPTEE_SMC_SEC_CAP_MEMREF_NULL		BIT(4)
276/* Secure world supports asynchronous notification of normal world */
277#define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF		BIT(5)
278/* Secure world supports pre-allocating RPC arg struct */
279#define OPTEE_SMC_SEC_CAP_RPC_ARG		BIT(6)
280/* Secure world supports probing for RPMB device if needed */
281#define OPTEE_SMC_SEC_CAP_RPMB_PROBE		BIT(7)
282/* Secure world supports protected memory */
283#define OPTEE_SMC_SEC_CAP_PROTMEM		BIT(8)
284/* Secure world supports dynamic protected memory */
285#define OPTEE_SMC_SEC_CAP_DYNAMIC_PROTMEM	BIT(9)
286
287#define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES	9
288#define OPTEE_SMC_EXCHANGE_CAPABILITIES \
289	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
290
291struct optee_smc_exchange_capabilities_result {
292	unsigned long status;
293	unsigned long capabilities;
294	unsigned long max_notif_value;
295	unsigned long data;
296};
297
298/*
299 * Disable and empties cache of shared memory objects
300 *
301 * Secure world can cache frequently used shared memory objects, for
302 * example objects used as RPC arguments. When secure world is idle this
303 * function returns one shared memory reference to free. To disable the
304 * cache and free all cached objects this function has to be called until
305 * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
306 *
307 * Call register usage:
308 * a0	SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
309 * a1-6	Not used
310 * a7	Hypervisor Client ID register
311 *
312 * Normal return register usage:
313 * a0	OPTEE_SMC_RETURN_OK
314 * a1	Upper 32 bits of a 64-bit Shared memory cookie
315 * a2	Lower 32 bits of a 64-bit Shared memory cookie
316 * a3-7	Preserved
317 *
318 * Cache empty return register usage:
319 * a0	OPTEE_SMC_RETURN_ENOTAVAIL
320 * a1-7	Preserved
321 *
322 * Not idle return register usage:
323 * a0	OPTEE_SMC_RETURN_EBUSY
324 * a1-7	Preserved
325 */
326#define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE	10
327#define OPTEE_SMC_DISABLE_SHM_CACHE \
328	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
329
330struct optee_smc_disable_shm_cache_result {
331	unsigned long status;
332	unsigned long shm_upper32;
333	unsigned long shm_lower32;
334	unsigned long reserved0;
335};
336
337/*
338 * Enable cache of shared memory objects
339 *
340 * Secure world can cache frequently used shared memory objects, for
341 * example objects used as RPC arguments. When secure world is idle this
342 * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
343 * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
344 *
345 * Call register usage:
346 * a0	SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
347 * a1-6	Not used
348 * a7	Hypervisor Client ID register
349 *
350 * Normal return register usage:
351 * a0	OPTEE_SMC_RETURN_OK
352 * a1-7	Preserved
353 *
354 * Not idle return register usage:
355 * a0	OPTEE_SMC_RETURN_EBUSY
356 * a1-7	Preserved
357 */
358#define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE	11
359#define OPTEE_SMC_ENABLE_SHM_CACHE \
360	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
361
362/*
363 * Query OP-TEE about number of supported threads
364 *
365 * Normal World OS or Hypervisor issues this call to find out how many
366 * threads OP-TEE supports. That is how many standard calls can be issued
367 * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
368 *
369 * Call requests usage:
370 * a0	SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
371 * a1-6 Not used
372 * a7	Hypervisor Client ID register
373 *
374 * Normal return register usage:
375 * a0	OPTEE_SMC_RETURN_OK
376 * a1	Number of threads
377 * a2-7 Preserved
378 *
379 * Error return:
380 * a0	OPTEE_SMC_RETURN_UNKNOWN_FUNCTION   Requested call is not implemented
381 * a1-7	Preserved
382 */
383#define OPTEE_SMC_FUNCID_GET_THREAD_COUNT	15
384#define OPTEE_SMC_GET_THREAD_COUNT \
385	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
386
387/*
388 * Inform OP-TEE that normal world is able to receive asynchronous
389 * notifications.
390 *
391 * Call requests usage:
392 * a0	SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
393 * a1-6	Not used
394 * a7	Hypervisor Client ID register
395 *
396 * Normal return register usage:
397 * a0	OPTEE_SMC_RETURN_OK
398 * a1-7	Preserved
399 *
400 * Not supported return register usage:
401 * a0	OPTEE_SMC_RETURN_ENOTAVAIL
402 * a1-7	Preserved
403 */
404#define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF	16
405#define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
406	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
407
408/*
409 * Retrieve a value of notifications pending since the last call of this
410 * function.
411 *
412 * OP-TEE keeps a record of all posted values. When an interrupt is
413 * received which indicates that there are posted values this function
414 * should be called until all pended values have been retrieved. When a
415 * value is retrieved, it's cleared from the record in secure world.
416 *
417 * It is expected that this function is called from an interrupt handler
418 * in normal world.
419 *
420 * Call requests usage:
421 * a0	SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
422 * a1-6	Not used
423 * a7	Hypervisor Client ID register
424 *
425 * Normal return register usage:
426 * a0	OPTEE_SMC_RETURN_OK
427 * a1	value
428 * a2	Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
429 *		valid, else 0 if no values where pending
430 * a2	Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
431 *		pending, else 0.
432 *	Bit[31:2]: MBZ
433 * a3-7	Preserved
434 *
435 * Not supported return register usage:
436 * a0	OPTEE_SMC_RETURN_ENOTAVAIL
437 * a1-7	Preserved
438 */
439#define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID	BIT(0)
440#define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING	BIT(1)
441
442/*
443 * Notification that OP-TEE expects a yielding call to do some bottom half
444 * work in a driver.
445 */
446#define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF	0
447
448#define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE	17
449#define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
450	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
451
452/* See OPTEE_SMC_CALL_WITH_RPC_ARG above */
453#define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG	18
454
455/* See OPTEE_SMC_CALL_WITH_REGD_ARG above */
456#define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG	19
457/*
458 * Get protected memory config
459 *
460 * Returns the protected memory config.
461 *
462 * Call register usage:
463 * a0   SMC Function ID, OPTEE_SMC_GET_PROTMEM_CONFIG
464 * a2-6	Not used, must be zero
465 * a7	Hypervisor Client ID register
466 *
467 * Have config return register usage:
468 * a0	OPTEE_SMC_RETURN_OK
469 * a1	Physical address of start of protected memory
470 * a2	Size of protected memory
471 * a3	PA width, max 64
472 * a4-7	Preserved
473 *
474 * Not available register usage:
475 * a0	OPTEE_SMC_RETURN_ENOTAVAIL
476 * a1-3 Not used
477 * a4-7	Preserved
478 */
479#define OPTEE_SMC_FUNCID_GET_PROTMEM_CONFIG		20
480#define OPTEE_SMC_GET_PROTMEM_CONFIG \
481	OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_PROTMEM_CONFIG)
482
483struct optee_smc_get_protmem_config_result {
484	unsigned long status;
485	unsigned long start;
486	unsigned long size;
487	unsigned long pa_width;
488};
489
490/*
491 * Resume from RPC (for example after processing a foreign interrupt)
492 *
493 * Call register usage:
494 * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
495 * a1-3	Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
496 *	OPTEE_SMC_RETURN_RPC in a0
497 *
498 * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
499 *
500 * Possible return values
501 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
502 *					function.
503 * OPTEE_SMC_RETURN_OK			Original call completed, result
504 *					updated in the previously supplied.
505 *					struct optee_msg_arg
506 * OPTEE_SMC_RETURN_RPC			Call suspended by RPC call to normal
507 *					world.
508 * OPTEE_SMC_RETURN_ERESUME		Resume failed, the opaque resume
509 *					information was corrupt.
510 */
511#define OPTEE_SMC_FUNCID_RETURN_FROM_RPC	3
512#define OPTEE_SMC_CALL_RETURN_FROM_RPC \
513	OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
514
515#define OPTEE_SMC_RETURN_RPC_PREFIX_MASK	0xFFFF0000
516#define OPTEE_SMC_RETURN_RPC_PREFIX		0xFFFF0000
517#define OPTEE_SMC_RETURN_RPC_FUNC_MASK		0x0000FFFF
518
519#define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
520	((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
521
522#define OPTEE_SMC_RPC_VAL(func)		((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
523
524/*
525 * Allocate memory for RPC parameter passing. The memory is used to hold a
526 * struct optee_msg_arg.
527 *
528 * "Call" register usage:
529 * a0	This value, OPTEE_SMC_RETURN_RPC_ALLOC
530 * a1	Size in bytes of required argument memory
531 * a2	Not used
532 * a3	Resume information, must be preserved
533 * a4-5	Not used
534 * a6-7	Resume information, must be preserved
535 *
536 * "Return" register usage:
537 * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
538 * a1	Upper 32 bits of 64-bit physical pointer to allocated
539 *	memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
540 *	be allocated.
541 * a2	Lower 32 bits of 64-bit physical pointer to allocated
542 *	memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
543 *	be allocated
544 * a3	Preserved
545 * a4	Upper 32 bits of 64-bit Shared memory cookie used when freeing
546 *	the memory or doing an RPC
547 * a5	Lower 32 bits of 64-bit Shared memory cookie used when freeing
548 *	the memory or doing an RPC
549 * a6-7	Preserved
550 */
551#define OPTEE_SMC_RPC_FUNC_ALLOC	0
552#define OPTEE_SMC_RETURN_RPC_ALLOC \
553	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
554
555/*
556 * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
557 *
558 * "Call" register usage:
559 * a0	This value, OPTEE_SMC_RETURN_RPC_FREE
560 * a1	Upper 32 bits of 64-bit shared memory cookie belonging to this
561 *	argument memory
562 * a2	Lower 32 bits of 64-bit shared memory cookie belonging to this
563 *	argument memory
564 * a3-7	Resume information, must be preserved
565 *
566 * "Return" register usage:
567 * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
568 * a1-2	Not used
569 * a3-7	Preserved
570 */
571#define OPTEE_SMC_RPC_FUNC_FREE		2
572#define OPTEE_SMC_RETURN_RPC_FREE \
573	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
574
575/*
576 * Deliver a foreign interrupt in normal world.
577 *
578 * "Call" register usage:
579 * a0	OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
580 * a1-7	Resume information, must be preserved
581 *
582 * "Return" register usage:
583 * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
584 * a1-7	Preserved
585 */
586#define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR	4
587#define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
588	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
589
590/*
591 * Do an RPC request. The supplied struct optee_msg_arg tells which
592 * request to do and the parameters for the request. The following fields
593 * are used (the rest are unused):
594 * - cmd		the Request ID
595 * - ret		return value of the request, filled in by normal world
596 * - num_params		number of parameters for the request
597 * - params		the parameters
598 * - param_attrs	attributes of the parameters
599 *
600 * "Call" register usage:
601 * a0	OPTEE_SMC_RETURN_RPC_CMD
602 * a1	Upper 32 bits of a 64-bit Shared memory cookie holding a
603 *	struct optee_msg_arg, must be preserved, only the data should
604 *	be updated
605 * a2	Lower 32 bits of a 64-bit Shared memory cookie holding a
606 *	struct optee_msg_arg, must be preserved, only the data should
607 *	be updated
608 * a3-7	Resume information, must be preserved
609 *
610 * "Return" register usage:
611 * a0	SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
612 * a1-2	Not used
613 * a3-7	Preserved
614 */
615#define OPTEE_SMC_RPC_FUNC_CMD		5
616#define OPTEE_SMC_RETURN_RPC_CMD \
617	OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
618
619/* Returned in a0 */
620#define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
621
622/* Returned in a0 only from Trusted OS functions */
623#define OPTEE_SMC_RETURN_OK		0x0
624#define OPTEE_SMC_RETURN_ETHREAD_LIMIT	0x1
625#define OPTEE_SMC_RETURN_EBUSY		0x2
626#define OPTEE_SMC_RETURN_ERESUME	0x3
627#define OPTEE_SMC_RETURN_EBADADDR	0x4
628#define OPTEE_SMC_RETURN_EBADCMD	0x5
629#define OPTEE_SMC_RETURN_ENOMEM		0x6
630#define OPTEE_SMC_RETURN_ENOTAVAIL	0x7
631#define OPTEE_SMC_RETURN_IS_RPC(ret)	__optee_smc_return_is_rpc((ret))
632
633static inline bool __optee_smc_return_is_rpc(u32 ret)
634{
635	return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
636	       (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
637			OPTEE_SMC_RETURN_RPC_PREFIX;
638}
639
640#endif /* OPTEE_SMC_H */
~/ Read-only file preview.