xref: /optee_os/core/arch/riscv/include/tee/optee_abi.h (revision fbe66cf83199aa6a2aca9f93384cf1ad9185a5f6)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2023 NXP
4  * Copyright (c) 2015-2021, Linaro Limited
5  */
6 #ifndef __TEE_OPTEE_ABI_H
7 #define __TEE_OPTEE_ABI_H
8 
9 #include <stdint.h>
10 
11 /*
12  * This file should be kept in sync between secure domain and non-secure
13  * domain kernel driver.
14  * This file depends on optee_msg.h being included to expand the ABI id
15  * macros below.
16  */
17 
18 #define OPTEE_ABI_32			U(0)
19 #define OPTEE_ABI_64			U(0x40000000)
20 #define OPTEE_ABI_FAST_CALL		U(0x80000000)
21 #define OPTEE_ABI_STD_CALL		U(0)
22 
23 #define OPTEE_ABI_OWNER_MASK		U(0x3F)
24 #define OPTEE_ABI_OWNER_SHIFT		U(24)
25 
26 #define OPTEE_ABI_FUNC_MASK		U(0xFFFF)
27 
28 #define OPTEE_ABI_IS_FAST_CALL(abi_val)	((abi_val) & OPTEE_ABI_FAST_CALL)
29 #define OPTEE_ABI_IS_64(abi_val)	((abi_val) & OPTEE_ABI_64)
30 #define OPTEE_ABI_FUNC_NUM(abi_val)	((abi_val) & OPTEE_ABI_FUNC_MASK)
31 #define OPTEE_ABI_OWNER_NUM(abi_val) \
32 	(((abi_val) >> OPTEE_ABI_OWNER_SHIFT) & OPTEE_ABI_OWNER_MASK)
33 
34 #define OPTEE_ABI_CALL_VAL(type, calling_convention, owner, func_num) \
35 			((type) | (calling_convention) | \
36 			(((owner) & OPTEE_ABI_OWNER_MASK) << \
37 				OPTEE_ABI_OWNER_SHIFT) |\
38 			((func_num) & OPTEE_ABI_FUNC_MASK))
39 
40 #define OPTEE_ABI_STD_CALL_VAL(func_num) \
41 	OPTEE_ABI_CALL_VAL(OPTEE_ABI_32, OPTEE_ABI_STD_CALL, \
42 			   OPTEE_ABI_OWNER_TRUSTED_OS, (func_num))
43 #define OPTEE_ABI_FAST_CALL_VAL(func_num) \
44 	OPTEE_ABI_CALL_VAL(OPTEE_ABI_32, OPTEE_ABI_FAST_CALL, \
45 			   OPTEE_ABI_OWNER_TRUSTED_OS, (func_num))
46 
47 #define OPTEE_ABI_OWNER_ARCH		U(0)
48 #define OPTEE_ABI_OWNER_CPU		U(1)
49 #define OPTEE_ABI_OWNER_SIP		U(2)
50 #define OPTEE_ABI_OWNER_OEM		U(3)
51 #define OPTEE_ABI_OWNER_STANDARD	U(4)
52 #define OPTEE_ABI_OWNER_TRUSTED_APP	U(48)
53 #define OPTEE_ABI_OWNER_TRUSTED_OS	U(50)
54 
55 #define OPTEE_ABI_OWNER_TRUSTED_OS_OPTEED U(62)
56 #define OPTEE_ABI_OWNER_TRUSTED_OS_API	U(63)
57 
58 /*
59  * Function specified by ABI Calling convention.
60  */
61 #define OPTEE_ABI_FUNCID_CALLS_COUNT	U(0xFF00)
62 #define OPTEE_ABI_CALLS_COUNT \
63 	OPTEE_ABI_CALL_VAL(OPTEE_ABI_32, OPTEE_ABI_FAST_CALL, \
64 			   OPTEE_ABI_OWNER_TRUSTED_OS_API, \
65 			   OPTEE_ABI_FUNCID_CALLS_COUNT)
66 
67 /*
68  * Normal cached memory (write-back), shareable for SMP systems and not
69  * shareable for UP systems.
70  */
71 #define OPTEE_ABI_SHM_CACHED		U(1)
72 
73 /*
74  * a0..a7 is used as register names in the descriptions below.
75  */
76 
77 /*
78  * Function specified by ABI Calling convention
79  *
80  * Return the following UID if using API specified in this file
81  * without further extensions:
82  * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
83  * see also OPTEE_MSG_UID_* in optee_msg.h
84  */
85 #define OPTEE_ABI_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID
86 #define OPTEE_ABI_CALLS_UID \
87 	OPTEE_ABI_CALL_VAL(OPTEE_ABI_32, OPTEE_ABI_FAST_CALL, \
88 			   OPTEE_ABI_OWNER_TRUSTED_OS_API, \
89 			   OPTEE_ABI_FUNCID_CALLS_UID)
90 
91 /*
92  * Function specified by ABI Calling convention
93  *
94  * Returns 2.0 if using API specified in this file without further extensions.
95  * see also OPTEE_MSG_REVISION_* in optee_msg.h
96  */
97 #define OPTEE_ABI_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION
98 #define OPTEE_ABI_CALLS_REVISION \
99 	OPTEE_ABI_CALL_VAL(OPTEE_ABI_32, OPTEE_ABI_FAST_CALL, \
100 			   OPTEE_ABI_OWNER_TRUSTED_OS_API, \
101 			   OPTEE_ABI_FUNCID_CALLS_REVISION)
102 
103 /*
104  * Get UUID of Trusted OS.
105  *
106  * Used by non-secure world to figure out which Trusted OS is installed.
107  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
108  *
109  * Returns UUID in a0-4 in the same way as OPTEE_ABI_CALLS_UID
110  * described above.
111  */
112 #define OPTEE_ABI_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID
113 #define OPTEE_ABI_CALL_GET_OS_UUID \
114 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_GET_OS_UUID)
115 
116 /*
117  * Get revision of Trusted OS.
118  *
119  * Used by non-secure world to figure out which version of the Trusted OS
120  * is installed. Note that the returned revision is the revision of the
121  * Trusted OS, not of the API.
122  *
123  * Returns revision in a0-1 in the same way as OPTEE_ABI_CALLS_REVISION
124  * described above. May optionally return a 32-bit build identifier in a2,
125  * with zero meaning unspecified.
126  */
127 #define OPTEE_ABI_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
128 #define OPTEE_ABI_CALL_GET_OS_REVISION \
129 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_GET_OS_REVISION)
130 
131 /*
132  * Call with struct optee_msg_arg as argument
133  *
134  * When called with OPTEE_ABI_CALL_WITH_RPC_ARG or
135  * OPTEE_ABI_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_ABI_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_ABI_CALL_WITH_ARG and
148  * OPTEE_ABI_CALL_WITH_RPC_ARG:
149  * a0	ABI Function ID, OPTEE_ABI_CALL_WITH_ARG or OPTEE_ABI_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_ABI_SHM_*
154  * a4-6	Not used
155  * a7	Hypervisor Client ID register
156  *
157  * Call register usage, OPTEE_ABI_CALL_WITH_REGD_ARG:
158  * a0	ABI Function ID, OPTEE_ABI_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_ABI_RETURN_*
168  * a1-3	Not used
169  * a4-7	Preserved
170  *
171  * OPTEE_ABI_RETURN_ETHREAD_LIMIT return register usage:
172  * a0	Return value, OPTEE_ABI_RETURN_ETHREAD_LIMIT
173  * a1-3	Preserved
174  * a4-7	Preserved
175  *
176  * RPC return register usage:
177  * a0	Return value, OPTEE_ABI_RETURN_IS_RPC(val)
178  * a1-2	RPC parameters
179  * a3-7	Resume information, must be preserved
180  *
181  * Possible return values:
182  * OPTEE_ABI_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
183  *					function.
184  * OPTEE_ABI_RETURN_OK			Call completed, result updated in
185  *					the previously supplied struct
186  *					optee_msg_arg.
187  * OPTEE_ABI_RETURN_ETHREAD_LIMIT	Number of Trusted OS threads exceeded,
188  *					try again later.
189  * OPTEE_ABI_RETURN_EBADADDR		Bad physical pointer to struct
190  *					optee_msg_arg.
191  * OPTEE_ABI_RETURN_EBADCMD		Bad/unknown cmd in struct optee_msg_arg
192  * OPTEE_ABI_RETURN_IS_RPC()		Call suspended by RPC call to normal
193  *					world.
194  */
195 #define OPTEE_ABI_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
196 #define OPTEE_ABI_CALL_WITH_ARG \
197 	OPTEE_ABI_STD_CALL_VAL(OPTEE_ABI_FUNCID_CALL_WITH_ARG)
198 #define OPTEE_ABI_CALL_WITH_RPC_ARG \
199 	OPTEE_ABI_STD_CALL_VAL(OPTEE_ABI_FUNCID_CALL_WITH_RPC_ARG)
200 #define OPTEE_ABI_CALL_WITH_REGD_ARG \
201 	OPTEE_ABI_STD_CALL_VAL(OPTEE_ABI_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	ABI Function ID, OPTEE_ABI_GET_SHM_CONFIG
210  * a1-6	Not used
211  * a7	Hypervisor Client ID register
212  *
213  * Have config return register usage:
214  * a0	OPTEE_ABI_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_ABI_SHM_* values above
219  * a4-7	Preserved
220  *
221  * Not available register usage:
222  * a0	OPTEE_ABI_RETURN_ENOTAVAIL
223  * a1-3 Not used
224  * a4-7	Preserved
225  */
226 #define OPTEE_ABI_FUNCID_GET_SHM_CONFIG	7
227 #define OPTEE_ABI_GET_SHM_CONFIG \
228 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_GET_SHM_CONFIG)
229 
230 /*
231  * Configures L2CC mutex
232  *
233  * Disables, enables usage of L2CC mutex. Returns or sets physical address
234  * of L2CC mutex.
235  *
236  * Call register usage:
237  * a0	ABI Function ID, OPTEE_ABI_L2CC_MUTEX
238  * a1	OPTEE_ABI_L2CC_MUTEX_GET_ADDR	Get physical address of mutex
239  *	OPTEE_ABI_L2CC_MUTEX_SET_ADDR	Set physical address of mutex
240  *	OPTEE_ABI_L2CC_MUTEX_ENABLE	Enable usage of mutex
241  *	OPTEE_ABI_L2CC_MUTEX_DISABLE	Disable usage of mutex
242  * a2	if a1 == OPTEE_ABI_L2CC_MUTEX_SET_ADDR, upper 32bit of a 64bit
243  *      physical address of mutex
244  * a3	if a1 == OPTEE_ABI_L2CC_MUTEX_SET_ADDR, lower 32bit of a 64bit
245  *      physical address of mutex
246  * a3-6	Not used
247  * a7	Hypervisor Client ID register
248  *
249  * Have config return register usage:
250  * a0	OPTEE_ABI_RETURN_OK
251  * a1	Preserved
252  * a2	if a1 == OPTEE_ABI_L2CC_MUTEX_GET_ADDR, upper 32bit of a 64bit
253  *      physical address of mutex
254  * a3	if a1 == OPTEE_ABI_L2CC_MUTEX_GET_ADDR, lower 32bit of a 64bit
255  *      physical address of mutex
256  * a3-7	Preserved
257  *
258  * Error return register usage:
259  * a0	OPTEE_ABI_RETURN_ENOTAVAIL	Physical address not available
260  *	OPTEE_ABI_RETURN_EBADADDR	Bad supplied physical address
261  *	OPTEE_ABI_RETURN_EBADCMD	Unsupported value in a1
262  * a1-7	Preserved
263  */
264 #define OPTEE_ABI_L2CC_MUTEX_GET_ADDR	U(0)
265 #define OPTEE_ABI_L2CC_MUTEX_SET_ADDR	U(1)
266 #define OPTEE_ABI_L2CC_MUTEX_ENABLE	U(2)
267 #define OPTEE_ABI_L2CC_MUTEX_DISABLE	U(3)
268 #define OPTEE_ABI_FUNCID_L2CC_MUTEX	U(8)
269 #define OPTEE_ABI_L2CC_MUTEX \
270 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_L2CC_MUTEX)
271 
272 /*
273  * Exchanges capabilities between normal world and secure world
274  *
275  * Call register usage:
276  * a0	ABI Function ID, OPTEE_ABI_EXCHANGE_CAPABILITIES
277  * a1	bitfield of normal world capabilities OPTEE_ABI_NSEC_CAP_*
278  * a2-6	Not used
279  * a7	Hypervisor Client ID register
280  *
281  * Normal return register usage:
282  * a0	OPTEE_ABI_RETURN_OK
283  * a1	bitfield of secure world capabilities OPTEE_ABI_SEC_CAP_*
284  * a2	The maximum secure world notification number
285  * a3	Bit[7:0]: Number of parameters needed for RPC to be supplied
286  *		  as the second MSG arg struct for
287  *		  OPTEE_ABI_CALL_WITH_ARG
288  *	Bit[31:8]: Reserved (MBZ)
289  * a3-7	Preserved
290  *
291  * Error return register usage:
292  * a0	OPTEE_ABI_RETURN_ENOTAVAIL, can't use the capabilities from normal world
293  * a1	bitfield of secure world capabilities OPTEE_ABI_SEC_CAP_*
294  * a2-7 Preserved
295  */
296 /* Normal world works as a uniprocessor system */
297 #define OPTEE_ABI_NSEC_CAP_UNIPROCESSOR		BIT(0)
298 /* Secure world has reserved shared memory for normal world to use */
299 #define OPTEE_ABI_SEC_CAP_HAVE_RESERVED_SHM	BIT(0)
300 /* Secure world can communicate via previously unregistered shared memory */
301 #define OPTEE_ABI_SEC_CAP_UNREGISTERED_SHM	BIT(1)
302 /*
303  * Secure world supports commands "register/unregister shared memory",
304  * secure world accepts command buffers located in any parts of non-secure RAM
305  */
306 #define OPTEE_ABI_SEC_CAP_DYNAMIC_SHM		BIT(2)
307 /* Secure world is built with virtualization support */
308 #define OPTEE_ABI_SEC_CAP_VIRTUALIZATION	BIT(3)
309 /* Secure world supports Shared Memory with a NULL reference */
310 #define OPTEE_ABI_SEC_CAP_MEMREF_NULL		BIT(4)
311 /* Secure world supports asynchronous notification of normal world */
312 #define OPTEE_ABI_SEC_CAP_ASYNC_NOTIF		BIT(5)
313 /* Secure world supports pre-allocating RPC arg struct */
314 #define OPTEE_ABI_SEC_CAP_RPC_ARG		BIT(6)
315 
316 #define OPTEE_ABI_FUNCID_EXCHANGE_CAPABILITIES	U(9)
317 #define OPTEE_ABI_EXCHANGE_CAPABILITIES \
318 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_EXCHANGE_CAPABILITIES)
319 
320 /*
321  * Disable and empties cache of shared memory objects
322  *
323  * Secure world can cache frequently used shared memory objects, for
324  * example objects used as RPC arguments. When secure world is idle this
325  * function returns one shared memory reference to free. To disable the
326  * cache and free all cached objects this function has to be called until
327  * it returns OPTEE_ABI_RETURN_ENOTAVAIL.
328  *
329  * Call register usage:
330  * a0	ABI Function ID, OPTEE_ABI_DISABLE_SHM_CACHE
331  * a1-6	Not used
332  * a7	Hypervisor Client ID register
333  *
334  * Normal return register usage:
335  * a0	OPTEE_ABI_RETURN_OK
336  * a1	Upper 32 bits of a 64-bit Shared memory cookie
337  * a2	Lower 32 bits of a 64-bit Shared memory cookie
338  * a3-7	Preserved
339  *
340  * Cache empty return register usage:
341  * a0	OPTEE_ABI_RETURN_ENOTAVAIL
342  * a1-7	Preserved
343  *
344  * Not idle return register usage:
345  * a0	OPTEE_ABI_RETURN_EBUSY
346  * a1-7	Preserved
347  */
348 #define OPTEE_ABI_FUNCID_DISABLE_SHM_CACHE	U(10)
349 #define OPTEE_ABI_DISABLE_SHM_CACHE \
350 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_DISABLE_SHM_CACHE)
351 
352 /*
353  * Enable cache of shared memory objects
354  *
355  * Secure world can cache frequently used shared memory objects, for
356  * example objects used as RPC arguments. When secure world is idle this
357  * function returns OPTEE_ABI_RETURN_OK and the cache is enabled. If
358  * secure world isn't idle OPTEE_ABI_RETURN_EBUSY is returned.
359  *
360  * Call register usage:
361  * a0	ABI Function ID, OPTEE_ABI_ENABLE_SHM_CACHE
362  * a1-6	Not used
363  * a7	Hypervisor Client ID register
364  *
365  * Normal return register usage:
366  * a0	OPTEE_ABI_RETURN_OK
367  * a1-7	Preserved
368  *
369  * Not idle return register usage:
370  * a0	OPTEE_ABI_RETURN_EBUSY
371  * a1-7	Preserved
372  */
373 #define OPTEE_ABI_FUNCID_ENABLE_SHM_CACHE	U(11)
374 #define OPTEE_ABI_ENABLE_SHM_CACHE \
375 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_ENABLE_SHM_CACHE)
376 
377 /*
378  * Release of secondary cores
379  *
380  * OP-TEE in secure world is in charge of the release process of secondary
381  * cores. The Rich OS issue the this request to ask OP-TEE to boot up the
382  * secondary cores, go through the OP-TEE per-core initialization, and then
383  * switch to the Non-seCure world with the Rich OS provided entry address.
384  * The secondary cores enter Non-Secure world in SVC mode, with Thumb, FIQ,
385  * IRQ and Abort bits disabled.
386  *
387  * Call register usage:
388  * a0	ABI Function ID, OPTEE_ABI_BOOT_SECONDARY
389  * a1	Index of secondary core to boot
390  * a2	Upper 32 bits of a 64-bit Non-Secure world entry physical address
391  * a3	Lower 32 bits of a 64-bit Non-Secure world entry physical address
392  * a4-7	Not used
393  *
394  * Normal return register usage:
395  * a0	OPTEE_ABI_RETURN_OK
396  * a1-7	Preserved
397  *
398  * Error return:
399  * a0	OPTEE_ABI_RETURN_EBADCMD		Core index out of range
400  * a1-7	Preserved
401  *
402  * Not idle return register usage:
403  * a0	OPTEE_ABI_RETURN_EBUSY
404  * a1-7	Preserved
405  */
406 #define OPTEE_ABI_FUNCID_BOOT_SECONDARY  U(12)
407 #define OPTEE_ABI_BOOT_SECONDARY \
408 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_BOOT_SECONDARY)
409 
410 /*
411  * Inform OP-TEE about a new virtual machine
412  *
413  * Hypervisor issues this call during virtual machine (guest) creation.
414  * OP-TEE records client id of new virtual machine and prepares
415  * to receive requests from it. This call is available only if OP-TEE
416  * was built with virtualization support.
417  *
418  * Call requests usage:
419  * a0	ABI Function ID, OPTEE_ABI_VM_CREATED
420  * a1	Hypervisor Client ID of newly created virtual machine
421  * a2-6 Not used
422  * a7	Hypervisor Client ID register. Must be 0, because only hypervisor
423  *      can issue this call
424  *
425  * Normal return register usage:
426  * a0	OPTEE_ABI_RETURN_OK
427  * a1-7	Preserved
428  *
429  * Error return:
430  * a0	OPTEE_ABI_RETURN_ENOTAVAIL	OP-TEE have no resources for
431  *					another VM
432  * a1-7	Preserved
433  *
434  */
435 #define OPTEE_ABI_FUNCID_VM_CREATED	U(13)
436 #define OPTEE_ABI_VM_CREATED \
437 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_VM_CREATED)
438 
439 /*
440  * Inform OP-TEE about shutdown of a virtual machine
441  *
442  * Hypervisor issues this call during virtual machine (guest) destruction.
443  * OP-TEE will clean up all resources associated with this VM. This call is
444  * available only if OP-TEE was built with virtualization support.
445  *
446  * Call requests usage:
447  * a0	ABI Function ID, OPTEE_ABI_VM_DESTROYED
448  * a1	Hypervisor Client ID of virtual machine being shut down
449  * a2-6 Not used
450  * a7	Hypervisor Client ID register. Must be 0, because only hypervisor
451  *      can issue this call
452  *
453  * Normal return register usage:
454  * a0	OPTEE_ABI_RETURN_OK
455  * a1-7	Preserved
456  *
457  */
458 #define OPTEE_ABI_FUNCID_VM_DESTROYED	U(14)
459 #define OPTEE_ABI_VM_DESTROYED \
460 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_VM_DESTROYED)
461 
462 /*
463  * Query OP-TEE about number of supported threads
464  *
465  * Normal World OS or Hypervisor issues this call to find out how many
466  * threads OP-TEE supports. That is how many standard calls can be issued
467  * in parallel before OP-TEE will return OPTEE_ABI_RETURN_ETHREAD_LIMIT.
468  *
469  * Call requests usage:
470  * a0	ABI Function ID, OPTEE_ABI_GET_THREAD_COUNT
471  * a1-6 Not used
472  * a7	Hypervisor Client ID register
473  *
474  * Normal return register usage:
475  * a0	OPTEE_ABI_RETURN_OK
476  * a1	Number of threads
477  * a2-7 Preserved
478  *
479  * Error return:
480  * a0	OPTEE_ABI_RETURN_UNKNOWN_FUNCTION   Requested call is not implemented
481  * a1-7	Preserved
482  */
483 #define OPTEE_ABI_FUNCID_GET_THREAD_COUNT	U(15)
484 #define OPTEE_ABI_GET_THREAD_COUNT \
485 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_GET_THREAD_COUNT)
486 
487 /*
488  * Inform OP-TEE that normal world is able to receive asynchronous
489  * notifications.
490  *
491  * Call requests usage:
492  * a0	ABI Function ID, OPTEE_ABI_ENABLE_ASYNC_NOTIF
493  * a1-6	Not used
494  * a7	Hypervisor Client ID register
495  *
496  * Normal return register usage:
497  * a0	OPTEE_ABI_RETURN_OK
498  * a1-7	Preserved
499  *
500  * Not supported return register usage:
501  * a0	OPTEE_ABI_RETURN_ENOTAVAIL
502  * a1-7	Preserved
503  */
504 #define OPTEE_ABI_FUNCID_ENABLE_ASYNC_NOTIF	16
505 #define OPTEE_ABI_ENABLE_ASYNC_NOTIF \
506 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_ENABLE_ASYNC_NOTIF)
507 
508 /*
509  * Retrieve a value of notifications pending since the last call of this
510  * function.
511  *
512  * OP-TEE keeps a record of all posted values. When an interrupt is
513  * received which indicates that there are posted values this function
514  * should be called until all pended values have been retrieved. When a
515  * value is retrieved, it's cleared from the record in secure world.
516  *
517  * It is expected that this function is called from an interrupt handler
518  * in normal world.
519  *
520  * Call requests usage:
521  * a0	ABI Function ID, OPTEE_ABI_GET_ASYNC_NOTIF_VALUE
522  * a1-6	Not used
523  * a7	Hypervisor Client ID register
524  *
525  * Normal return register usage:
526  * a0	OPTEE_ABI_RETURN_OK
527  * a1	value
528  * a2	Bit[0]: OPTEE_ABI_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
529  *		valid, else 0 if no values were pending
530  * a2	Bit[1]: OPTEE_ABI_ASYNC_NOTIF_VALUE_PENDING if another value is
531  *		pending, else 0.
532  *	Bit[31:2]: MBZ
533  * a3-7	Preserved
534  *
535  * Not supported return register usage:
536  * a0	OPTEE_ABI_RETURN_ENOTAVAIL
537  * a1-7	Preserved
538  */
539 #define OPTEE_ABI_ASYNC_NOTIF_VALID	BIT(0)
540 #define OPTEE_ABI_ASYNC_NOTIF_PENDING	BIT(1)
541 
542 /*
543  * Notification that OP-TEE expects a yielding call to do some bottom half
544  * work in a driver.
545  */
546 #define OPTEE_ABI_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF	0
547 
548 #define OPTEE_ABI_FUNCID_GET_ASYNC_NOTIF_VALUE	17
549 #define OPTEE_ABI_GET_ASYNC_NOTIF_VALUE \
550 	OPTEE_ABI_FAST_CALL_VAL(OPTEE_ABI_FUNCID_GET_ASYNC_NOTIF_VALUE)
551 
552 /* See OPTEE_ABI_CALL_WITH_RPC_ARG above */
553 #define OPTEE_ABI_FUNCID_CALL_WITH_RPC_ARG	U(18)
554 
555 /* See OPTEE_ABI_CALL_WITH_REGD_ARG above */
556 #define OPTEE_ABI_FUNCID_CALL_WITH_REGD_ARG	U(19)
557 
558 /*
559  * Resume from RPC (for example after processing a foreign interrupt)
560  *
561  * Call register usage:
562  * a0	ABI Function ID, OPTEE_ABI_CALL_RETURN_FROM_RPC
563  * a1-3	Value of a1-3 when OPTEE_ABI_CALL_WITH_ARG returned
564  *	OPTEE_ABI_RETURN_RPC in a0
565  *
566  * Return register usage is the same as for OPTEE_ABI_*CALL_WITH_ARG above.
567  *
568  * Possible return values
569  * OPTEE_ABI_RETURN_UNKNOWN_FUNCTION	Trusted OS does not recognize this
570  *					function.
571  * OPTEE_ABI_RETURN_OK			Original call completed, result
572  *					updated in the previously supplied.
573  *					struct optee_msg_arg
574  * OPTEE_ABI_RETURN_RPC			Call suspended by RPC call to normal
575  *					world.
576  * OPTEE_ABI_RETURN_ERESUME		Resume failed, the opaque resume
577  *					information was corrupt.
578  */
579 #define OPTEE_ABI_FUNCID_RETURN_FROM_RPC	U(3)
580 #define OPTEE_ABI_CALL_RETURN_FROM_RPC \
581 	OPTEE_ABI_STD_CALL_VAL(OPTEE_ABI_FUNCID_RETURN_FROM_RPC)
582 
583 #define OPTEE_ABI_RETURN_RPC_PREFIX_MASK	U(0xFFFF0000)
584 #define OPTEE_ABI_RETURN_RPC_PREFIX		U(0xFFFF0000)
585 #define OPTEE_ABI_RETURN_RPC_FUNC_MASK		U(0x0000FFFF)
586 
587 #define OPTEE_ABI_RETURN_GET_RPC_FUNC(ret) \
588 	((ret) & OPTEE_ABI_RETURN_RPC_FUNC_MASK)
589 
590 #define OPTEE_ABI_RPC_VAL(func)		((func) | OPTEE_ABI_RETURN_RPC_PREFIX)
591 
592 /*
593  * Allocate memory for RPC parameter passing. The memory is used to hold a
594  * struct optee_msg_arg.
595  *
596  * "Call" register usage:
597  * a0	This value, OPTEE_ABI_RETURN_RPC_ALLOC
598  * a1	Size in bytes of required argument memory
599  * a2	Not used
600  * a3	Resume information, must be preserved
601  * a4-5	Not used
602  * a6-7	Resume information, must be preserved
603  *
604  * "Return" register usage:
605  * a0	ABI Function ID, OPTEE_ABI_CALL_RETURN_FROM_RPC.
606  * a1	Upper 32 bits of 64-bit physical pointer to allocated
607  *	memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
608  *	be allocated.
609  * a2	Lower 32 bits of 64-bit physical pointer to allocated
610  *	memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
611  *	be allocated
612  * a3	Preserved
613  * a4	Upper 32 bits of 64-bit Shared memory cookie used when freeing
614  *	the memory or doing an RPC
615  * a5	Lower 32 bits of 64-bit Shared memory cookie used when freeing
616  *	the memory or doing an RPC
617  * a6-7	Preserved
618  */
619 #define OPTEE_ABI_RPC_FUNC_ALLOC	U(0)
620 #define OPTEE_ABI_RETURN_RPC_ALLOC \
621 	OPTEE_ABI_RPC_VAL(OPTEE_ABI_RPC_FUNC_ALLOC)
622 
623 /*
624  * Free memory previously allocated by OPTEE_ABI_RETURN_RPC_ALLOC
625  *
626  * "Call" register usage:
627  * a0	This value, OPTEE_ABI_RETURN_RPC_FREE
628  * a1	Upper 32 bits of 64-bit shared memory cookie belonging to this
629  *	argument memory
630  * a2	Lower 32 bits of 64-bit shared memory cookie belonging to this
631  *	argument memory
632  * a3-7	Resume information, must be preserved
633  *
634  * "Return" register usage:
635  * a0	ABI Function ID, OPTEE_ABI_CALL_RETURN_FROM_RPC.
636  * a1-2	Not used
637  * a3-7	Preserved
638  */
639 #define OPTEE_ABI_RPC_FUNC_FREE		U(2)
640 #define OPTEE_ABI_RETURN_RPC_FREE \
641 	OPTEE_ABI_RPC_VAL(OPTEE_ABI_RPC_FUNC_FREE)
642 
643 /*
644  * Deliver a foreign interrupt in normal world.
645  *
646  * "Call" register usage:
647  * a0	OPTEE_ABI_RETURN_RPC_FOREIGN_INTR
648  * a1-7	Resume information, must be preserved
649  *
650  * "Return" register usage:
651  * a0	ABI Function ID, OPTEE_ABI_CALL_RETURN_FROM_RPC.
652  * a1-7	Preserved
653  */
654 #define OPTEE_ABI_RPC_FUNC_FOREIGN_INTR	U(4)
655 #define OPTEE_ABI_RETURN_RPC_FOREIGN_INTR \
656 	OPTEE_ABI_RPC_VAL(OPTEE_ABI_RPC_FUNC_FOREIGN_INTR)
657 
658 /*
659  * Do an RPC request. The supplied struct optee_msg_arg tells which
660  * request to do and the parameters for the request. The following fields
661  * are used (the rest are unused):
662  * - cmd		the Request ID
663  * - ret		return value of the request, filled in by normal world
664  * - num_params		number of parameters for the request
665  * - params		the parameters
666  * - param_attrs	attributes of the parameters
667  *
668  * "Call" register usage:
669  * a0	OPTEE_ABI_RETURN_RPC_CMD
670  * a1	Upper 32 bits of a 64-bit Shared memory cookie holding a
671  *	struct optee_msg_arg, must be preserved, only the data should
672  *	be updated
673  * a2	Lower 32 bits of a 64-bit Shared memory cookie holding a
674  *	struct optee_msg_arg, must be preserved, only the data should
675  *	be updated
676  * a3-7	Resume information, must be preserved
677  *
678  * "Return" register usage:
679  * a0	ABI Function ID, OPTEE_ABI_CALL_RETURN_FROM_RPC.
680  * a1-2	Not used
681  * a3-7	Preserved
682  */
683 #define OPTEE_ABI_RPC_FUNC_CMD		U(5)
684 #define OPTEE_ABI_RETURN_RPC_CMD \
685 	OPTEE_ABI_RPC_VAL(OPTEE_ABI_RPC_FUNC_CMD)
686 
687 /* Returned in a0 */
688 #define OPTEE_ABI_RETURN_UNKNOWN_FUNCTION U(0xFFFFFFFF)
689 
690 /* Returned in a0 only from Trusted OS functions */
691 #define OPTEE_ABI_RETURN_OK		U(0x0)
692 #define OPTEE_ABI_RETURN_ETHREAD_LIMIT	U(0x1)
693 #define OPTEE_ABI_RETURN_EBUSY		U(0x2)
694 #define OPTEE_ABI_RETURN_ERESUME	U(0x3)
695 #define OPTEE_ABI_RETURN_EBADADDR	U(0x4)
696 #define OPTEE_ABI_RETURN_EBADCMD	U(0x5)
697 #define OPTEE_ABI_RETURN_ENOMEM		U(0x6)
698 #define OPTEE_ABI_RETURN_ENOTAVAIL	U(0x7)
699 #define OPTEE_ABI_RETURN_IS_RPC(_ret) ({\
700 	typeof(_ret) (ret) = (_ret); \
701 	(((ret) != OPTEE_ABI_RETURN_UNKNOWN_FUNCTION) && \
702 	((((ret) & OPTEE_ABI_RETURN_RPC_PREFIX_MASK) == \
703 		OPTEE_ABI_RETURN_RPC_PREFIX))); })
704 
705 #endif /* __TEE_OPTEE_ABI_H */
706