b6fcd6526e50395b6454c25c7914acc76b6c624d
[platform/core/security/tef-optee_os.git] / core / arch / arm / include / sm / optee_smc.h
1 /*
2  * Copyright (c) 2015, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef OPTEE_SMC_H
28 #define OPTEE_SMC_H
29
30 /*
31  * This file is exported by OP-TEE and is in kept in sync between secure
32  * world and normal world kernel driver. We're following ARM SMC Calling
33  * Convention as specified in
34  * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
35  *
36  * This file depends on optee_msg.h being included to expand the SMC id
37  * macros below.
38  */
39
40 #define OPTEE_SMC_32                    0
41 #define OPTEE_SMC_64                    0x40000000
42 #define OPTEE_SMC_FAST_CALL             0x80000000
43 #define OPTEE_SMC_STD_CALL              0
44
45 #define OPTEE_SMC_OWNER_MASK            0x3F
46 #define OPTEE_SMC_OWNER_SHIFT           24
47
48 #define OPTEE_SMC_FUNC_MASK             0xFFFF
49
50 #define OPTEE_SMC_IS_FAST_CALL(smc_val) ((smc_val) & OPTEE_SMC_FAST_CALL)
51 #define OPTEE_SMC_IS_64(smc_val)        ((smc_val) & OPTEE_SMC_64)
52 #define OPTEE_SMC_FUNC_NUM(smc_val)     ((smc_val) & OPTEE_SMC_FUNC_MASK)
53 #define OPTEE_SMC_OWNER_NUM(smc_val) \
54         (((smc_val) >> OPTEE_SMC_OWNER_SHIFT) & OPTEE_SMC_OWNER_MASK)
55
56 #define OPTEE_SMC_CALL_VAL(type, calling_convention, owner, func_num) \
57                         ((type) | (calling_convention) | \
58                         (((owner) & OPTEE_SMC_OWNER_MASK) << \
59                                 OPTEE_SMC_OWNER_SHIFT) |\
60                         ((func_num) & OPTEE_SMC_FUNC_MASK))
61
62 #define OPTEE_SMC_STD_CALL_VAL(func_num) \
63         OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_STD_CALL, \
64                            OPTEE_SMC_OWNER_TRUSTED_OS, (func_num))
65 #define OPTEE_SMC_FAST_CALL_VAL(func_num) \
66         OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \
67                            OPTEE_SMC_OWNER_TRUSTED_OS, (func_num))
68
69 #define OPTEE_SMC_OWNER_ARCH            0
70 #define OPTEE_SMC_OWNER_CPU             1
71 #define OPTEE_SMC_OWNER_SIP             2
72 #define OPTEE_SMC_OWNER_OEM             3
73 #define OPTEE_SMC_OWNER_STANDARD        4
74 #define OPTEE_SMC_OWNER_TRUSTED_APP     48
75 #define OPTEE_SMC_OWNER_TRUSTED_OS      50
76
77 #define OPTEE_SMC_OWNER_TRUSTED_OS_OPTEED 62
78 #define OPTEE_SMC_OWNER_TRUSTED_OS_API  63
79
80 /*
81  * Function specified by SMC Calling convention.
82  */
83 #define OPTEE_SMC_FUNCID_CALLS_COUNT    0xFF00
84 #define OPTEE_SMC_CALLS_COUNT \
85         OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \
86                            OPTEE_SMC_OWNER_TRUSTED_OS_API, \
87                            OPTEE_SMC_FUNCID_CALLS_COUNT)
88
89 /*
90  * Normal cached memory (write-back), shareable for SMP systems and not
91  * shareable for UP systems.
92  */
93 #define OPTEE_SMC_SHM_CACHED            1
94
95 /*
96  * a0..a7 is used as register names in the descriptions below, on arm32
97  * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's
98  * 32-bit registers.
99  */
100
101 /*
102  * Function specified by SMC Calling convention
103  *
104  * Return the following UID if using API specified in this file
105  * without further extensions:
106  * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
107  * see also OPTEE_MSG_UID_* in optee_msg.h
108  */
109 #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID
110 #define OPTEE_SMC_CALLS_UID \
111         OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \
112                            OPTEE_SMC_OWNER_TRUSTED_OS_API, \
113                            OPTEE_SMC_FUNCID_CALLS_UID)
114
115 /*
116  * Function specified by SMC Calling convention
117  *
118  * Returns 2.0 if using API specified in this file without further extensions.
119  * see also OPTEE_MSG_REVISION_* in optee_msg.h
120  */
121 #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION
122 #define OPTEE_SMC_CALLS_REVISION \
123         OPTEE_SMC_CALL_VAL(OPTEE_SMC_32, OPTEE_SMC_FAST_CALL, \
124                            OPTEE_SMC_OWNER_TRUSTED_OS_API, \
125                            OPTEE_SMC_FUNCID_CALLS_REVISION)
126
127 /*
128  * Get UUID of Trusted OS.
129  *
130  * Used by non-secure world to figure out which Trusted OS is installed.
131  * Note that returned UUID is the UUID of the Trusted OS, not of the API.
132  *
133  * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID
134  * described above.
135  */
136 #define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID
137 #define OPTEE_SMC_CALL_GET_OS_UUID \
138         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID)
139
140 /*
141  * Get revision of Trusted OS.
142  *
143  * Used by non-secure world to figure out which version of the Trusted OS
144  * is installed. Note that the returned revision is the revision of the
145  * Trusted OS, not of the API.
146  *
147  * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
148  * described above.
149  */
150 #define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
151 #define OPTEE_SMC_CALL_GET_OS_REVISION \
152         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION)
153
154 /*
155  * Call with struct optee_msg_arg as argument
156  *
157  * Call register usage:
158  * a0   SMC Function ID, OPTEE_SMC*CALL_WITH_ARG
159  * a1   Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
160  * a2   Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
161  * a3   Cache settings, not used if physical pointer is in a predefined shared
162  *      memory area else per OPTEE_SMC_SHM_*
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
199 /*
200  * Get Shared Memory Config
201  *
202  * Returns the Secure/Non-secure shared memory config.
203  *
204  * Call register usage:
205  * a0   SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
206  * a1-6 Not used
207  * a7   Hypervisor Client ID register
208  *
209  * Have config return register usage:
210  * a0   OPTEE_SMC_RETURN_OK
211  * a1   Physical address of start of SHM
212  * a2   Size of of SHM
213  * a3   Cache settings of memory, as defined by the
214  *      OPTEE_SMC_SHM_* values above
215  * a4-7 Preserved
216  *
217  * Not available register usage:
218  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
219  * a1-3 Not used
220  * a4-7 Preserved
221  */
222 #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7
223 #define OPTEE_SMC_GET_SHM_CONFIG \
224         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
225
226 /*
227  * Configures L2CC mutex
228  *
229  * Disables, enables usage of L2CC mutex. Returns or sets physical address
230  * of L2CC mutex.
231  *
232  * Call register usage:
233  * a0   SMC Function ID, OPTEE_SMC_L2CC_MUTEX
234  * a1   OPTEE_SMC_L2CC_MUTEX_GET_ADDR   Get physical address of mutex
235  *      OPTEE_SMC_L2CC_MUTEX_SET_ADDR   Set physical address of mutex
236  *      OPTEE_SMC_L2CC_MUTEX_ENABLE     Enable usage of mutex
237  *      OPTEE_SMC_L2CC_MUTEX_DISABLE    Disable usage of mutex
238  * a2   if a1 == OPTEE_SMC_L2CC_MUTEX_SET_ADDR, upper 32bit of a 64bit
239  *      physical address of mutex
240  * a3   if a1 == OPTEE_SMC_L2CC_MUTEX_SET_ADDR, lower 32bit of a 64bit
241  *      physical address of mutex
242  * a3-6 Not used
243  * a7   Hypervisor Client ID register
244  *
245  * Have config return register usage:
246  * a0   OPTEE_SMC_RETURN_OK
247  * a1   Preserved
248  * a2   if a1 == OPTEE_SMC_L2CC_MUTEX_GET_ADDR, upper 32bit of a 64bit
249  *      physical address of mutex
250  * a3   if a1 == OPTEE_SMC_L2CC_MUTEX_GET_ADDR, lower 32bit of a 64bit
251  *      physical address of mutex
252  * a3-7 Preserved
253  *
254  * Error return register usage:
255  * a0   OPTEE_SMC_RETURN_ENOTAVAIL      Physical address not available
256  *      OPTEE_SMC_RETURN_EBADADDR       Bad supplied physical address
257  *      OPTEE_SMC_RETURN_EBADCMD        Unsupported value in a1
258  * a1-7 Preserved
259  */
260 #define OPTEE_SMC_L2CC_MUTEX_GET_ADDR   0
261 #define OPTEE_SMC_L2CC_MUTEX_SET_ADDR   1
262 #define OPTEE_SMC_L2CC_MUTEX_ENABLE     2
263 #define OPTEE_SMC_L2CC_MUTEX_DISABLE    3
264 #define OPTEE_SMC_FUNCID_L2CC_MUTEX     8
265 #define OPTEE_SMC_L2CC_MUTEX \
266         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_L2CC_MUTEX)
267
268 /*
269  * Exchanges capabilities between normal world and secure world
270  *
271  * Call register usage:
272  * a0   SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
273  * a1   bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
274  * a2-6 Not used
275  * a7   Hypervisor Client ID register
276  *
277  * Normal return register usage:
278  * a0   OPTEE_SMC_RETURN_OK
279  * a1   bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
280  * a2-7 Preserved
281  *
282  * Error return register usage:
283  * a0   OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
284  * a1   bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
285  * a2-7 Preserved
286  */
287 /* Normal world works as a uniprocessor system */
288 #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR         (1 << 0)
289 /* Secure world has reserved shared memory for normal world to use */
290 #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM     (1 << 0)
291 /* Secure world can communicate via previously unregistered shared memory */
292 #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM      (1 << 1)
293 #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES  9
294 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \
295         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
296
297 /*
298  * Disable and empties cache of shared memory objects
299  *
300  * Secure world can cache frequently used shared memory objects, for
301  * example objects used as RPC arguments. When secure world is idle this
302  * function returns one shared memory reference to free. To disable the
303  * cache and free all cached objects this function has to be called until
304  * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
305  *
306  * Call register usage:
307  * a0   SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
308  * a1-6 Not used
309  * a7   Hypervisor Client ID register
310  *
311  * Normal return register usage:
312  * a0   OPTEE_SMC_RETURN_OK
313  * a1   Upper 32 bits of a 64-bit Shared memory cookie
314  * a2   Lower 32 bits of a 64-bit Shared memory cookie
315  * a3-7 Preserved
316  *
317  * Cache empty return register usage:
318  * a0   OPTEE_SMC_RETURN_ENOTAVAIL
319  * a1-7 Preserved
320  *
321  * Not idle return register usage:
322  * a0   OPTEE_SMC_RETURN_EBUSY
323  * a1-7 Preserved
324  */
325 #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE      10
326 #define OPTEE_SMC_DISABLE_SHM_CACHE \
327         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
328
329 /*
330  * Enable cache of shared memory objects
331  *
332  * Secure world can cache frequently used shared memory objects, for
333  * example objects used as RPC arguments. When secure world is idle this
334  * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
335  * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
336  *
337  * Call register usage:
338  * a0   SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
339  * a1-6 Not used
340  * a7   Hypervisor Client ID register
341  *
342  * Normal return register usage:
343  * a0   OPTEE_SMC_RETURN_OK
344  * a1-7 Preserved
345  *
346  * Not idle return register usage:
347  * a0   OPTEE_SMC_RETURN_EBUSY
348  * a1-7 Preserved
349  */
350 #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE       11
351 #define OPTEE_SMC_ENABLE_SHM_CACHE \
352         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
353
354 /*
355  * Release of secondary cores
356  *
357  * OP-TEE in secure world is in charge of the release process of secondary
358  * cores. The Rich OS issue the this request to ask OP-TEE to boot up the
359  * secondary cores, go through the OP-TEE per-core initialization, and then
360  * switch to the Non-seCure world with the Rich OS provided entry address.
361  * The secondary cores enter Non-Secure world in SVC mode, with Thumb, FIQ,
362  * IRQ and Abort bits disabled.
363  *
364  * Call register usage:
365  * a0   SMC Function ID, OPTEE_SMC_BOOT_SECONDARY
366  * a1   Index of secondary core to boot
367  * a2   Upper 32 bits of a 64-bit Non-Secure world entry physical address
368  * a3   Lower 32 bits of a 64-bit Non-Secure world entry physical address
369  * a4-7 Not used
370  *
371  * Normal return register usage:
372  * a0   OPTEE_SMC_RETURN_OK
373  * a1-7 Preserved
374  *
375  * Error return:
376  * a0   OPTEE_SMC_RETURN_EBADCMD                Core index out of range
377  * a1-7 Preserved
378  *
379  * Not idle return register usage:
380  * a0   OPTEE_SMC_RETURN_EBUSY
381  * a1-7 Preserved
382  */
383 #define OPTEE_SMC_FUNCID_BOOT_SECONDARY  12
384 #define OPTEE_SMC_BOOT_SECONDARY \
385         OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_BOOT_SECONDARY)
386
387 /*
388  * Resume from RPC (for example after processing an IRQ)
389  *
390  * Call register usage:
391  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
392  * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
393  *      OPTEE_SMC_RETURN_RPC in a0
394  *
395  * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
396  *
397  * Possible return values
398  * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION    Trusted OS does not recognize this
399  *                                      function.
400  * OPTEE_SMC_RETURN_OK                  Original call completed, result
401  *                                      updated in the previously supplied.
402  *                                      struct optee_msg_arg
403  * OPTEE_SMC_RETURN_RPC                 Call suspended by RPC call to normal
404  *                                      world.
405  * OPTEE_SMC_RETURN_ERESUME             Resume failed, the opaque resume
406  *                                      information was corrupt.
407  */
408 #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC        3
409 #define OPTEE_SMC_CALL_RETURN_FROM_RPC \
410         OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
411
412 #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK        0xFFFF0000
413 #define OPTEE_SMC_RETURN_RPC_PREFIX             0xFFFF0000
414 #define OPTEE_SMC_RETURN_RPC_FUNC_MASK          0x0000FFFF
415
416 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
417         ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
418
419 #define OPTEE_SMC_RPC_VAL(func)         ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
420
421 /*
422  * Allocate memory for RPC parameter passing. The memory is used to hold a
423  * struct optee_msg_arg.
424  *
425  * "Call" register usage:
426  * a0   This value, OPTEE_SMC_RETURN_RPC_ALLOC
427  * a1   Size in bytes of required argument memory
428  * a2   Not used
429  * a3   Resume information, must be preserved
430  * a4-5 Not used
431  * a6-7 Resume information, must be preserved
432  *
433  * "Return" register usage:
434  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
435  * a1   Upper 32 bits of 64-bit physical pointer to allocated
436  *      memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
437  *      be allocated.
438  * a2   Lower 32 bits of 64-bit physical pointer to allocated
439  *      memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
440  *      be allocated
441  * a3   Preserved
442  * a4   Upper 32 bits of 64-bit Shared memory cookie used when freeing
443  *      the memory or doing an RPC
444  * a5   Lower 32 bits of 64-bit Shared memory cookie used when freeing
445  *      the memory or doing an RPC
446  * a6-7 Preserved
447  */
448 #define OPTEE_SMC_RPC_FUNC_ALLOC        0
449 #define OPTEE_SMC_RETURN_RPC_ALLOC \
450         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
451
452 /*
453  * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
454  *
455  * "Call" register usage:
456  * a0   This value, OPTEE_SMC_RETURN_RPC_FREE
457  * a1   Upper 32 bits of 64-bit shared memory cookie belonging to this
458  *      argument memory
459  * a2   Lower 32 bits of 64-bit shared memory cookie belonging to this
460  *      argument memory
461  * a3-7 Resume information, must be preserved
462  *
463  * "Return" register usage:
464  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
465  * a1-2 Not used
466  * a3-7 Preserved
467  */
468 #define OPTEE_SMC_RPC_FUNC_FREE         2
469 #define OPTEE_SMC_RETURN_RPC_FREE \
470         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
471
472 /*
473  * Deliver an IRQ in normal world.
474  *
475  * "Call" register usage:
476  * a0   OPTEE_SMC_RETURN_RPC_IRQ
477  * a1-7 Resume information, must be preserved
478  *
479  * "Return" register usage:
480  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
481  * a1-7 Preserved
482  */
483 #define OPTEE_SMC_RPC_FUNC_IRQ          4
484 #define OPTEE_SMC_RETURN_RPC_IRQ \
485         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_IRQ)
486
487 /*
488  * Do an RPC request. The supplied struct optee_msg_arg tells which
489  * request to do and the parameters for the request. The following fields
490  * are used (the rest are unused):
491  * - cmd                the Request ID
492  * - ret                return value of the request, filled in by normal world
493  * - num_params         number of parameters for the request
494  * - params             the parameters
495  * - param_attrs        attributes of the parameters
496  *
497  * "Call" register usage:
498  * a0   OPTEE_SMC_RETURN_RPC_CMD
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 32 bits of a 64-bit Shared memory cookie holding a
503  *      struct optee_msg_arg, must be preserved, only the data should
504  *      be updated
505  * a3-7 Resume information, must be preserved
506  *
507  * "Return" register usage:
508  * a0   SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
509  * a1-2 Not used
510  * a3-7 Preserved
511  */
512 #define OPTEE_SMC_RPC_FUNC_CMD          5
513 #define OPTEE_SMC_RETURN_RPC_CMD \
514         OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
515
516 /* Returned in a0 */
517 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
518
519 /* Returned in a0 only from Trusted OS functions */
520 #define OPTEE_SMC_RETURN_OK             0x0
521 #define OPTEE_SMC_RETURN_ETHREAD_LIMIT  0x1
522 #define OPTEE_SMC_RETURN_EBUSY          0x2
523 #define OPTEE_SMC_RETURN_ERESUME        0x3
524 #define OPTEE_SMC_RETURN_EBADADDR       0x4
525 #define OPTEE_SMC_RETURN_EBADCMD        0x5
526 #define OPTEE_SMC_RETURN_ENOMEM         0x6
527 #define OPTEE_SMC_RETURN_ENOTAVAIL      0x7
528 #define OPTEE_SMC_RETURN_IS_RPC(ret) \
529         (((ret) != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION) && \
530         ((((ret) & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) == \
531                 OPTEE_SMC_RETURN_RPC_PREFIX)))
532
533 #endif /* OPTEE_SMC_H */