2 * Copyright (c) 2015, Linaro Limited
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
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
36 * This file depends on optee_msg.h being included to expand the SMC id
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
45 #define OPTEE_SMC_OWNER_MASK 0x3F
46 #define OPTEE_SMC_OWNER_SHIFT 24
48 #define OPTEE_SMC_FUNC_MASK 0xFFFF
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)
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))
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))
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
77 #define OPTEE_SMC_OWNER_TRUSTED_OS_OPTEED 62
78 #define OPTEE_SMC_OWNER_TRUSTED_OS_API 63
81 * Function specified by SMC Calling convention.
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)
90 * Normal cached memory (write-back), shareable for SMP systems and not
91 * shareable for UP systems.
93 #define OPTEE_SMC_SHM_CACHED 1
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
102 * Function specified by SMC Calling convention
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
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)
116 * Function specified by SMC Calling convention
118 * Returns 2.0 if using API specified in this file without further extensions.
119 * see also OPTEE_MSG_REVISION_* in optee_msg.h
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)
128 * Get UUID of Trusted OS.
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.
133 * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID
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)
141 * Get revision of Trusted OS.
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.
147 * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
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)
155 * Call with struct optee_msg_arg as argument
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_*
164 * a7 Hypervisor Client ID register
166 * Normal return register usage:
167 * a0 Return value, OPTEE_SMC_RETURN_*
171 * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
172 * a0 Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
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
181 * Possible return values:
182 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
184 * OPTEE_SMC_RETURN_OK Call completed, result updated in
185 * the previously supplied struct
187 * OPTEE_SMC_RETURN_ETHREAD_LIMIT Number of Trusted OS threads exceeded,
189 * OPTEE_SMC_RETURN_EBADADDR Bad physical pointer to struct
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
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)
200 * Get Shared Memory Config
202 * Returns the Secure/Non-secure shared memory config.
204 * Call register usage:
205 * a0 SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
207 * a7 Hypervisor Client ID register
209 * Have config return register usage:
210 * a0 OPTEE_SMC_RETURN_OK
211 * a1 Physical address of start of SHM
213 * a3 Cache settings of memory, as defined by the
214 * OPTEE_SMC_SHM_* values above
217 * Not available register usage:
218 * a0 OPTEE_SMC_RETURN_ENOTAVAIL
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)
227 * Configures L2CC mutex
229 * Disables, enables usage of L2CC mutex. Returns or sets physical address
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
243 * a7 Hypervisor Client ID register
245 * Have config return register usage:
246 * a0 OPTEE_SMC_RETURN_OK
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
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
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)
269 * Exchanges capabilities between normal world and secure world
271 * Call register usage:
272 * a0 SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
273 * a1 bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
275 * a7 Hypervisor Client ID register
277 * Normal return register usage:
278 * a0 OPTEE_SMC_RETURN_OK
279 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
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_*
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)
298 * Disable and empties cache of shared memory objects
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.
306 * Call register usage:
307 * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
309 * a7 Hypervisor Client ID register
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
317 * Cache empty return register usage:
318 * a0 OPTEE_SMC_RETURN_ENOTAVAIL
321 * Not idle return register usage:
322 * a0 OPTEE_SMC_RETURN_EBUSY
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)
330 * Enable cache of shared memory objects
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.
337 * Call register usage:
338 * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
340 * a7 Hypervisor Client ID register
342 * Normal return register usage:
343 * a0 OPTEE_SMC_RETURN_OK
346 * Not idle return register usage:
347 * a0 OPTEE_SMC_RETURN_EBUSY
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)
355 * Release of secondary cores
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.
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
371 * Normal return register usage:
372 * a0 OPTEE_SMC_RETURN_OK
376 * a0 OPTEE_SMC_RETURN_EBADCMD Core index out of range
379 * Not idle return register usage:
380 * a0 OPTEE_SMC_RETURN_EBUSY
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)
388 * Resume from RPC (for example after processing an IRQ)
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
395 * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
397 * Possible return values
398 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
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
405 * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume
406 * information was corrupt.
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)
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
416 #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
417 ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
419 #define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
422 * Allocate memory for RPC parameter passing. The memory is used to hold a
423 * struct optee_msg_arg.
425 * "Call" register usage:
426 * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC
427 * a1 Size in bytes of required argument memory
429 * a3 Resume information, must be preserved
431 * a6-7 Resume information, must be preserved
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
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
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
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)
453 * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
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
459 * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this
461 * a3-7 Resume information, must be preserved
463 * "Return" register usage:
464 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
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)
473 * Deliver an IRQ in normal world.
475 * "Call" register usage:
476 * a0 OPTEE_SMC_RETURN_RPC_IRQ
477 * a1-7 Resume information, must be preserved
479 * "Return" register usage:
480 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
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)
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
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
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
505 * a3-7 Resume information, must be preserved
507 * "Return" register usage:
508 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
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)
517 #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
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)))
533 #endif /* OPTEE_SMC_H */