Merge tag 'arm-dt-6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-microblaze.git] / drivers / tee / optee / optee_smc.h
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
65 struct 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
100 struct 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  * Call with struct optee_msg_arg as argument
109  *
110  * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or
111  * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg
112  * following after the first struct optee_msg_arg. The RPC struct
113  * optee_msg_arg has reserved space for the number of RPC parameters as
114  * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES.
115  *
116  * When calling these functions, normal world has a few responsibilities:
117  * 1. It must be able to handle eventual RPCs
118  * 2. Non-secure interrupts should not be masked
119  * 3. If asynchronous notifications has been negotiated successfully, then
120  *    the interrupt for asynchronous notifications should be unmasked
121  *    during this call.
122  *
123  * Call register usage, OPTEE_SMC_CALL_WITH_ARG and
124  * OPTEE_SMC_CALL_WITH_RPC_ARG:
125  * a0   SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG
126  * a1   Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
127  * a2   Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
128  * a3   Cache settings, not used if physical pointer is in a predefined shared
129  *      memory area else per OPTEE_SMC_SHM_*
130  * a4-6 Not used
131  * a7   Hypervisor Client ID register
132  *
133  * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG:
134  * a0   SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG
135  * a1   Upper 32 bits of a 64-bit shared memory cookie
136  * a2   Lower 32 bits of a 64-bit shared memory cookie
137  * a3   Offset of the struct optee_msg_arg in the shared memory with the
138  *      supplied cookie
139  * a4-6 Not used
140  * a7   Hypervisor Client ID register
141  *
142  * Normal return register usage:
143  * a0   Return value, OPTEE_SMC_RETURN_*
144  * a1-3 Not used
145  * a4-7 Preserved
146  *
147  * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
148  * a0   Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
149  * a1-3 Preserved
150  * a4-7 Preserved
151  *
152  * RPC return register usage:
153  * a0   Return value, OPTEE_SMC_RETURN_IS_RPC(val)
154  * a1-2 RPC parameters
155  * a3-7 Resume information, must be preserved
156  *
157  * Possible return values:
158  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION    Trusted OS does not recognize this
159  *                                      function.
160  * OPTEE_SMC_RETURN_OK                  Call completed, result updated in
161  *                                      the previously supplied struct
162  *                                      optee_msg_arg.
163  * OPTEE_SMC_RETURN_ETHREAD_LIMIT       Number of Trusted OS threads exceeded,
164  *                                      try again later.
165  * OPTEE_SMC_RETURN_EBADADDR            Bad physical pointer to struct
166  *                                      optee_msg_arg.
167  * OPTEE_SMC_RETURN_EBADCMD             Bad/unknown cmd in struct optee_msg_arg
168  * OPTEE_SMC_RETURN_IS_RPC()            Call suspended by RPC call to normal
169  *                                      world.
170  */
171 #define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
172 #define OPTEE_SMC_CALL_WITH_ARG \
173         OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG)
174 #define OPTEE_SMC_CALL_WITH_RPC_ARG \
175         OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG)
176 #define OPTEE_SMC_CALL_WITH_REGD_ARG \
177         OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG)
178
179 /*
180  * Get Shared Memory Config
181  *
182  * Returns the Secure/Non-secure shared memory config.
183  *
184  * Call register usage:
185  * a0   SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
186  * a1-6 Not used
187  * a7   Hypervisor Client ID register
188  *
189  * Have config return register usage:
190  * a0   OPTEE_SMC_RETURN_OK
191  * a1   Physical address of start of SHM
192  * a2   Size of SHM
193  * a3   Cache settings of memory, as defined by the
194  *      OPTEE_SMC_SHM_* values above
195  * a4-7 Preserved
196  *
197  * Not available register usage:
198  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
199  * a1-3 Not used
200  * a4-7 Preserved
201  */
202 #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7
203 #define OPTEE_SMC_GET_SHM_CONFIG \
204         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
205
206 struct optee_smc_get_shm_config_result {
207         unsigned long status;
208         unsigned long start;
209         unsigned long size;
210         unsigned long settings;
211 };
212
213 /*
214  * Exchanges capabilities between normal world and secure world
215  *
216  * Call register usage:
217  * a0   SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
218  * a1   bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
219  * a2-6 Not used
220  * a7   Hypervisor Client ID register
221  *
222  * Normal return register usage:
223  * a0   OPTEE_SMC_RETURN_OK
224  * a1   bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
225  * a2   The maximum secure world notification number
226  * a3   Bit[7:0]: Number of parameters needed for RPC to be supplied
227  *                as the second MSG arg struct for
228  *                OPTEE_SMC_CALL_WITH_ARG
229  *      Bit[31:8]: Reserved (MBZ)
230  * a4-7 Preserved
231  *
232  * Error return register usage:
233  * a0   OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
234  * a1   bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
235  * a2-7 Preserved
236  */
237 /* Normal world works as a uniprocessor system */
238 #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR         BIT(0)
239 /* Secure world has reserved shared memory for normal world to use */
240 #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM     BIT(0)
241 /* Secure world can communicate via previously unregistered shared memory */
242 #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM      BIT(1)
243
244 /*
245  * Secure world supports commands "register/unregister shared memory",
246  * secure world accepts command buffers located in any parts of non-secure RAM
247  */
248 #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM           BIT(2)
249 /* Secure world is built with virtualization support */
250 #define OPTEE_SMC_SEC_CAP_VIRTUALIZATION        BIT(3)
251 /* Secure world supports Shared Memory with a NULL reference */
252 #define OPTEE_SMC_SEC_CAP_MEMREF_NULL           BIT(4)
253 /* Secure world supports asynchronous notification of normal world */
254 #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF           BIT(5)
255 /* Secure world supports pre-allocating RPC arg struct */
256 #define OPTEE_SMC_SEC_CAP_RPC_ARG               BIT(6)
257
258 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES  9
259 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \
260         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
261
262 struct optee_smc_exchange_capabilities_result {
263         unsigned long status;
264         unsigned long capabilities;
265         unsigned long max_notif_value;
266         unsigned long data;
267 };
268
269 /*
270  * Disable and empties cache of shared memory objects
271  *
272  * Secure world can cache frequently used shared memory objects, for
273  * example objects used as RPC arguments. When secure world is idle this
274  * function returns one shared memory reference to free. To disable the
275  * cache and free all cached objects this function has to be called until
276  * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
277  *
278  * Call register usage:
279  * a0   SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
280  * a1-6 Not used
281  * a7   Hypervisor Client ID register
282  *
283  * Normal return register usage:
284  * a0   OPTEE_SMC_RETURN_OK
285  * a1   Upper 32 bits of a 64-bit Shared memory cookie
286  * a2   Lower 32 bits of a 64-bit Shared memory cookie
287  * a3-7 Preserved
288  *
289  * Cache empty return register usage:
290  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
291  * a1-7 Preserved
292  *
293  * Not idle return register usage:
294  * a0   OPTEE_SMC_RETURN_EBUSY
295  * a1-7 Preserved
296  */
297 #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE      10
298 #define OPTEE_SMC_DISABLE_SHM_CACHE \
299         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
300
301 struct optee_smc_disable_shm_cache_result {
302         unsigned long status;
303         unsigned long shm_upper32;
304         unsigned long shm_lower32;
305         unsigned long reserved0;
306 };
307
308 /*
309  * Enable cache of shared memory objects
310  *
311  * Secure world can cache frequently used shared memory objects, for
312  * example objects used as RPC arguments. When secure world is idle this
313  * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
314  * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
315  *
316  * Call register usage:
317  * a0   SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
318  * a1-6 Not used
319  * a7   Hypervisor Client ID register
320  *
321  * Normal return register usage:
322  * a0   OPTEE_SMC_RETURN_OK
323  * a1-7 Preserved
324  *
325  * Not idle return register usage:
326  * a0   OPTEE_SMC_RETURN_EBUSY
327  * a1-7 Preserved
328  */
329 #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE       11
330 #define OPTEE_SMC_ENABLE_SHM_CACHE \
331         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
332
333 /*
334  * Query OP-TEE about number of supported threads
335  *
336  * Normal World OS or Hypervisor issues this call to find out how many
337  * threads OP-TEE supports. That is how many standard calls can be issued
338  * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
339  *
340  * Call requests usage:
341  * a0   SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
342  * a1-6 Not used
343  * a7   Hypervisor Client ID register
344  *
345  * Normal return register usage:
346  * a0   OPTEE_SMC_RETURN_OK
347  * a1   Number of threads
348  * a2-7 Preserved
349  *
350  * Error return:
351  * a0   OPTEE_SMC_RETURN_UNKNOWN_FUNCTION   Requested call is not implemented
352  * a1-7 Preserved
353  */
354 #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT       15
355 #define OPTEE_SMC_GET_THREAD_COUNT \
356         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
357
358 /*
359  * Inform OP-TEE that normal world is able to receive asynchronous
360  * notifications.
361  *
362  * Call requests usage:
363  * a0   SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
364  * a1-6 Not used
365  * a7   Hypervisor Client ID register
366  *
367  * Normal return register usage:
368  * a0   OPTEE_SMC_RETURN_OK
369  * a1-7 Preserved
370  *
371  * Not supported return register usage:
372  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
373  * a1-7 Preserved
374  */
375 #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF     16
376 #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
377         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
378
379 /*
380  * Retrieve a value of notifications pending since the last call of this
381  * function.
382  *
383  * OP-TEE keeps a record of all posted values. When an interrupt is
384  * received which indicates that there are posted values this function
385  * should be called until all pended values have been retrieved. When a
386  * value is retrieved, it's cleared from the record in secure world.
387  *
388  * It is expected that this function is called from an interrupt handler
389  * in normal world.
390  *
391  * Call requests usage:
392  * a0   SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
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   value
399  * a2   Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
400  *              valid, else 0 if no values where pending
401  * a2   Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
402  *              pending, else 0.
403  *      Bit[31:2]: MBZ
404  * a3-7 Preserved
405  *
406  * Not supported return register usage:
407  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
408  * a1-7 Preserved
409  */
410 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID       BIT(0)
411 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING     BIT(1)
412
413 /*
414  * Notification that OP-TEE expects a yielding call to do some bottom half
415  * work in a driver.
416  */
417 #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF      0
418
419 #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE  17
420 #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
421         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
422
423 /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */
424 #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG      18
425
426 /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */
427 #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG     19
428
429 /*
430  * Resume from RPC (for example after processing a foreign interrupt)
431  *
432  * Call register usage:
433  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
434  * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
435  *      OPTEE_SMC_RETURN_RPC in a0
436  *
437  * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
438  *
439  * Possible return values
440  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION    Trusted OS does not recognize this
441  *                                      function.
442  * OPTEE_SMC_RETURN_OK                  Original call completed, result
443  *                                      updated in the previously supplied.
444  *                                      struct optee_msg_arg
445  * OPTEE_SMC_RETURN_RPC                 Call suspended by RPC call to normal
446  *                                      world.
447  * OPTEE_SMC_RETURN_ERESUME             Resume failed, the opaque resume
448  *                                      information was corrupt.
449  */
450 #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC        3
451 #define OPTEE_SMC_CALL_RETURN_FROM_RPC \
452         OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
453
454 #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK        0xFFFF0000
455 #define OPTEE_SMC_RETURN_RPC_PREFIX             0xFFFF0000
456 #define OPTEE_SMC_RETURN_RPC_FUNC_MASK          0x0000FFFF
457
458 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
459         ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
460
461 #define OPTEE_SMC_RPC_VAL(func)         ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
462
463 /*
464  * Allocate memory for RPC parameter passing. The memory is used to hold a
465  * struct optee_msg_arg.
466  *
467  * "Call" register usage:
468  * a0   This value, OPTEE_SMC_RETURN_RPC_ALLOC
469  * a1   Size in bytes of required argument memory
470  * a2   Not used
471  * a3   Resume information, must be preserved
472  * a4-5 Not used
473  * a6-7 Resume information, must be preserved
474  *
475  * "Return" register usage:
476  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
477  * a1   Upper 32 bits of 64-bit physical pointer to allocated
478  *      memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
479  *      be allocated.
480  * a2   Lower 32 bits of 64-bit physical pointer to allocated
481  *      memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
482  *      be allocated
483  * a3   Preserved
484  * a4   Upper 32 bits of 64-bit Shared memory cookie used when freeing
485  *      the memory or doing an RPC
486  * a5   Lower 32 bits of 64-bit Shared memory cookie used when freeing
487  *      the memory or doing an RPC
488  * a6-7 Preserved
489  */
490 #define OPTEE_SMC_RPC_FUNC_ALLOC        0
491 #define OPTEE_SMC_RETURN_RPC_ALLOC \
492         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
493
494 /*
495  * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
496  *
497  * "Call" register usage:
498  * a0   This value, OPTEE_SMC_RETURN_RPC_FREE
499  * a1   Upper 32 bits of 64-bit shared memory cookie belonging to this
500  *      argument memory
501  * a2   Lower 32 bits of 64-bit shared memory cookie belonging to this
502  *      argument memory
503  * a3-7 Resume information, must be preserved
504  *
505  * "Return" register usage:
506  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
507  * a1-2 Not used
508  * a3-7 Preserved
509  */
510 #define OPTEE_SMC_RPC_FUNC_FREE         2
511 #define OPTEE_SMC_RETURN_RPC_FREE \
512         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
513
514 /*
515  * Deliver a foreign interrupt in normal world.
516  *
517  * "Call" register usage:
518  * a0   OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
519  * a1-7 Resume information, must be preserved
520  *
521  * "Return" register usage:
522  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
523  * a1-7 Preserved
524  */
525 #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4
526 #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
527         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
528
529 /*
530  * Do an RPC request. The supplied struct optee_msg_arg tells which
531  * request to do and the parameters for the request. The following fields
532  * are used (the rest are unused):
533  * - cmd                the Request ID
534  * - ret                return value of the request, filled in by normal world
535  * - num_params         number of parameters for the request
536  * - params             the parameters
537  * - param_attrs        attributes of the parameters
538  *
539  * "Call" register usage:
540  * a0   OPTEE_SMC_RETURN_RPC_CMD
541  * a1   Upper 32 bits of a 64-bit Shared memory cookie holding a
542  *      struct optee_msg_arg, must be preserved, only the data should
543  *      be updated
544  * a2   Lower 32 bits of a 64-bit Shared memory cookie holding a
545  *      struct optee_msg_arg, must be preserved, only the data should
546  *      be updated
547  * a3-7 Resume information, must be preserved
548  *
549  * "Return" register usage:
550  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
551  * a1-2 Not used
552  * a3-7 Preserved
553  */
554 #define OPTEE_SMC_RPC_FUNC_CMD          5
555 #define OPTEE_SMC_RETURN_RPC_CMD \
556         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
557
558 /* Returned in a0 */
559 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
560
561 /* Returned in a0 only from Trusted OS functions */
562 #define OPTEE_SMC_RETURN_OK             0x0
563 #define OPTEE_SMC_RETURN_ETHREAD_LIMIT  0x1
564 #define OPTEE_SMC_RETURN_EBUSY          0x2
565 #define OPTEE_SMC_RETURN_ERESUME        0x3
566 #define OPTEE_SMC_RETURN_EBADADDR       0x4
567 #define OPTEE_SMC_RETURN_EBADCMD        0x5
568 #define OPTEE_SMC_RETURN_ENOMEM         0x6
569 #define OPTEE_SMC_RETURN_ENOTAVAIL      0x7
570 #define OPTEE_SMC_RETURN_IS_RPC(ret)    __optee_smc_return_is_rpc((ret))
571
572 static inline bool __optee_smc_return_is_rpc(u32 ret)
573 {
574         return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
575                (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
576                         OPTEE_SMC_RETURN_RPC_PREFIX;
577 }
578
579 #endif /* OPTEE_SMC_H */