blob: d44a6ae994f8527381c76e17d0c3d7f0a7585443 [file] [log] [blame]
Jerome Forissier32356d32019-02-08 16:42:06 +01001/* SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) */
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +02002/*
Jens Wiklander617d8e82021-01-20 11:14:12 +01003 * Copyright (c) 2015-2021, Linaro Limited
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +02004 */
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 *
Jens Wiklander617d8e82021-01-20 11:14:12 +010042 * 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
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +020046 */
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 *
Jens Wiklander617d8e82021-01-20 11:14:12 +010056 * Returns 2.0 if using API specified in this file without further extensions.
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +020057 * 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
Jérôme Forissier6e112de2017-11-24 15:47:17 +010093 * described above. May optionally return a 32-bit build identifier in a2,
94 * with zero meaning unspecified.
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +020095 */
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
Jérôme Forissier6e112de2017-11-24 15:47:17 +0100100struct 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
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200107/*
108 * Call with struct optee_msg_arg as argument
109 *
Jens Wiklander6749e692021-06-15 22:23:54 +0200110 * When calling this function normal world has a few responsibilities:
111 * 1. It must be able to handle eventual RPCs
112 * 2. Non-secure interrupts should not be masked
113 * 3. If asynchronous notifications has been negotiated successfully, then
114 * asynchronous notifications should be unmasked during this call.
115 *
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200116 * Call register usage:
117 * a0 SMC Function ID, OPTEE_SMC*CALL_WITH_ARG
Jens Wiklander617d8e82021-01-20 11:14:12 +0100118 * a1 Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
119 * a2 Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200120 * a3 Cache settings, not used if physical pointer is in a predefined shared
121 * memory area else per OPTEE_SMC_SHM_*
122 * a4-6 Not used
123 * a7 Hypervisor Client ID register
124 *
125 * Normal return register usage:
126 * a0 Return value, OPTEE_SMC_RETURN_*
127 * a1-3 Not used
128 * a4-7 Preserved
129 *
130 * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
131 * a0 Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
132 * a1-3 Preserved
133 * a4-7 Preserved
134 *
135 * RPC return register usage:
136 * a0 Return value, OPTEE_SMC_RETURN_IS_RPC(val)
137 * a1-2 RPC parameters
138 * a3-7 Resume information, must be preserved
139 *
140 * Possible return values:
141 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
142 * function.
143 * OPTEE_SMC_RETURN_OK Call completed, result updated in
144 * the previously supplied struct
145 * optee_msg_arg.
146 * OPTEE_SMC_RETURN_ETHREAD_LIMIT Number of Trusted OS threads exceeded,
147 * try again later.
Bjorn Helgaasbed13b52021-01-26 15:15:07 -0600148 * OPTEE_SMC_RETURN_EBADADDR Bad physical pointer to struct
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200149 * optee_msg_arg.
150 * OPTEE_SMC_RETURN_EBADCMD Bad/unknown cmd in struct optee_msg_arg
151 * OPTEE_SMC_RETURN_IS_RPC() Call suspended by RPC call to normal
152 * world.
153 */
154#define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
155#define OPTEE_SMC_CALL_WITH_ARG \
156 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG)
157
158/*
159 * Get Shared Memory Config
160 *
161 * Returns the Secure/Non-secure shared memory config.
162 *
163 * Call register usage:
164 * a0 SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
165 * a1-6 Not used
166 * a7 Hypervisor Client ID register
167 *
168 * Have config return register usage:
169 * a0 OPTEE_SMC_RETURN_OK
170 * a1 Physical address of start of SHM
171 * a2 Size of of SHM
172 * a3 Cache settings of memory, as defined by the
173 * OPTEE_SMC_SHM_* values above
174 * a4-7 Preserved
175 *
176 * Not available register usage:
177 * a0 OPTEE_SMC_RETURN_ENOTAVAIL
178 * a1-3 Not used
179 * a4-7 Preserved
180 */
181#define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7
182#define OPTEE_SMC_GET_SHM_CONFIG \
183 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
184
185struct optee_smc_get_shm_config_result {
186 unsigned long status;
187 unsigned long start;
188 unsigned long size;
189 unsigned long settings;
190};
191
192/*
193 * Exchanges capabilities between normal world and secure world
194 *
195 * Call register usage:
196 * a0 SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
197 * a1 bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
198 * a2-6 Not used
199 * a7 Hypervisor Client ID register
200 *
201 * Normal return register usage:
202 * a0 OPTEE_SMC_RETURN_OK
203 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
Jens Wiklander6749e692021-06-15 22:23:54 +0200204 * a2 The maximum secure world notification number
205 * a3-7 Preserved
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200206 *
207 * Error return register usage:
208 * a0 OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
209 * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
210 * a2-7 Preserved
211 */
212/* Normal world works as a uniprocessor system */
213#define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR BIT(0)
214/* Secure world has reserved shared memory for normal world to use */
215#define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0)
216/* Secure world can communicate via previously unregistered shared memory */
217#define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM BIT(1)
Volodymyr Babchukde5c6df2017-11-29 14:48:29 +0200218
219/*
220 * Secure world supports commands "register/unregister shared memory",
221 * secure world accepts command buffers located in any parts of non-secure RAM
222 */
223#define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2)
Jens Wiklander617d8e82021-01-20 11:14:12 +0100224/* Secure world is built with virtualization support */
225#define OPTEE_SMC_SEC_CAP_VIRTUALIZATION BIT(3)
226/* Secure world supports Shared Memory with a NULL reference */
Cedric Neveuxba171d32019-03-04 08:54:23 +0100227#define OPTEE_SMC_SEC_CAP_MEMREF_NULL BIT(4)
Jens Wiklander6749e692021-06-15 22:23:54 +0200228/* Secure world supports asynchronous notification of normal world */
229#define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF BIT(5)
Cedric Neveuxba171d32019-03-04 08:54:23 +0100230
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200231#define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9
232#define OPTEE_SMC_EXCHANGE_CAPABILITIES \
233 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
234
235struct optee_smc_exchange_capabilities_result {
236 unsigned long status;
237 unsigned long capabilities;
Jens Wiklander6749e692021-06-15 22:23:54 +0200238 unsigned long max_notif_value;
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200239 unsigned long reserved0;
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200240};
241
242/*
243 * Disable and empties cache of shared memory objects
244 *
245 * Secure world can cache frequently used shared memory objects, for
246 * example objects used as RPC arguments. When secure world is idle this
247 * function returns one shared memory reference to free. To disable the
248 * cache and free all cached objects this function has to be called until
249 * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
250 *
251 * Call register usage:
252 * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
253 * a1-6 Not used
254 * a7 Hypervisor Client ID register
255 *
256 * Normal return register usage:
257 * a0 OPTEE_SMC_RETURN_OK
Jens Wiklander617d8e82021-01-20 11:14:12 +0100258 * a1 Upper 32 bits of a 64-bit Shared memory cookie
259 * a2 Lower 32 bits of a 64-bit Shared memory cookie
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200260 * a3-7 Preserved
261 *
262 * Cache empty return register usage:
263 * a0 OPTEE_SMC_RETURN_ENOTAVAIL
264 * a1-7 Preserved
265 *
266 * Not idle return register usage:
267 * a0 OPTEE_SMC_RETURN_EBUSY
268 * a1-7 Preserved
269 */
270#define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE 10
271#define OPTEE_SMC_DISABLE_SHM_CACHE \
272 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
273
274struct optee_smc_disable_shm_cache_result {
275 unsigned long status;
276 unsigned long shm_upper32;
277 unsigned long shm_lower32;
278 unsigned long reserved0;
279};
280
281/*
282 * Enable cache of shared memory objects
283 *
284 * Secure world can cache frequently used shared memory objects, for
285 * example objects used as RPC arguments. When secure world is idle this
286 * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
287 * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
288 *
289 * Call register usage:
290 * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
291 * a1-6 Not used
292 * a7 Hypervisor Client ID register
293 *
294 * Normal return register usage:
295 * a0 OPTEE_SMC_RETURN_OK
296 * a1-7 Preserved
297 *
298 * Not idle return register usage:
299 * a0 OPTEE_SMC_RETURN_EBUSY
300 * a1-7 Preserved
301 */
302#define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE 11
303#define OPTEE_SMC_ENABLE_SHM_CACHE \
304 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
305
306/*
Jens Wiklander617d8e82021-01-20 11:14:12 +0100307 * Query OP-TEE about number of supported threads
308 *
309 * Normal World OS or Hypervisor issues this call to find out how many
310 * threads OP-TEE supports. That is how many standard calls can be issued
311 * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
312 *
313 * Call requests usage:
314 * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
315 * a1-6 Not used
316 * a7 Hypervisor Client ID register
317 *
318 * Normal return register usage:
319 * a0 OPTEE_SMC_RETURN_OK
320 * a1 Number of threads
321 * a2-7 Preserved
322 *
323 * Error return:
324 * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented
325 * a1-7 Preserved
326 */
327#define OPTEE_SMC_FUNCID_GET_THREAD_COUNT 15
328#define OPTEE_SMC_GET_THREAD_COUNT \
329 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
330
331/*
Jens Wiklander6749e692021-06-15 22:23:54 +0200332 * Inform OP-TEE that normal world is able to receive asynchronous
333 * notifications.
334 *
335 * Call requests usage:
336 * a0 SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
337 * a1-6 Not used
338 * a7 Hypervisor Client ID register
339 *
340 * Normal return register usage:
341 * a0 OPTEE_SMC_RETURN_OK
342 * a1-7 Preserved
343 *
344 * Not supported return register usage:
345 * a0 OPTEE_SMC_RETURN_ENOTAVAIL
346 * a1-7 Preserved
347 */
348#define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16
349#define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
350 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
351
352/*
353 * Retrieve a value of notifications pending since the last call of this
354 * function.
355 *
356 * OP-TEE keeps a record of all posted values. When an interrupt is
357 * received which indicates that there are posted values this function
358 * should be called until all pended values have been retrieved. When a
359 * value is retrieved, it's cleared from the record in secure world.
360 *
361 * Call requests usage:
362 * a0 SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
363 * a1-6 Not used
364 * a7 Hypervisor Client ID register
365 *
366 * Normal return register usage:
367 * a0 OPTEE_SMC_RETURN_OK
368 * a1 value
369 * a2 Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
370 * valid, else 0 if no values where pending
371 * a2 Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
372 * pending, else 0.
373 * Bit[31:2]: MBZ
374 * a3-7 Preserved
375 *
376 * Not supported return register usage:
377 * a0 OPTEE_SMC_RETURN_ENOTAVAIL
378 * a1-7 Preserved
379 */
380#define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID BIT(0)
381#define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING BIT(1)
382
383/*
384 * Notification that OP-TEE expects a yielding call to do some bottom half
385 * work in a driver.
386 */
387#define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF 0
388
389#define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE 17
390#define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
391 OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
392
393/*
David Wang39e65192017-02-16 16:43:44 +0800394 * Resume from RPC (for example after processing a foreign interrupt)
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200395 *
396 * Call register usage:
397 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
398 * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
399 * OPTEE_SMC_RETURN_RPC in a0
400 *
401 * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
402 *
403 * Possible return values
404 * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
405 * function.
406 * OPTEE_SMC_RETURN_OK Original call completed, result
407 * updated in the previously supplied.
408 * struct optee_msg_arg
409 * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal
410 * world.
411 * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume
412 * information was corrupt.
413 */
414#define OPTEE_SMC_FUNCID_RETURN_FROM_RPC 3
415#define OPTEE_SMC_CALL_RETURN_FROM_RPC \
416 OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
417
418#define OPTEE_SMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000
419#define OPTEE_SMC_RETURN_RPC_PREFIX 0xFFFF0000
420#define OPTEE_SMC_RETURN_RPC_FUNC_MASK 0x0000FFFF
421
422#define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
423 ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
424
425#define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
426
427/*
428 * Allocate memory for RPC parameter passing. The memory is used to hold a
429 * struct optee_msg_arg.
430 *
431 * "Call" register usage:
432 * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC
433 * a1 Size in bytes of required argument memory
434 * a2 Not used
435 * a3 Resume information, must be preserved
436 * a4-5 Not used
437 * a6-7 Resume information, must be preserved
438 *
439 * "Return" register usage:
440 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
Jens Wiklander617d8e82021-01-20 11:14:12 +0100441 * a1 Upper 32 bits of 64-bit physical pointer to allocated
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200442 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
443 * be allocated.
Jens Wiklander617d8e82021-01-20 11:14:12 +0100444 * a2 Lower 32 bits of 64-bit physical pointer to allocated
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200445 * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
446 * be allocated
447 * a3 Preserved
Jens Wiklander617d8e82021-01-20 11:14:12 +0100448 * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200449 * the memory or doing an RPC
Jens Wiklander617d8e82021-01-20 11:14:12 +0100450 * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200451 * the memory or doing an RPC
452 * a6-7 Preserved
453 */
454#define OPTEE_SMC_RPC_FUNC_ALLOC 0
455#define OPTEE_SMC_RETURN_RPC_ALLOC \
456 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
457
458/*
459 * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
460 *
461 * "Call" register usage:
462 * a0 This value, OPTEE_SMC_RETURN_RPC_FREE
Jens Wiklander617d8e82021-01-20 11:14:12 +0100463 * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200464 * argument memory
Jens Wiklander617d8e82021-01-20 11:14:12 +0100465 * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200466 * argument memory
467 * a3-7 Resume information, must be preserved
468 *
469 * "Return" register usage:
470 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
471 * a1-2 Not used
472 * a3-7 Preserved
473 */
474#define OPTEE_SMC_RPC_FUNC_FREE 2
475#define OPTEE_SMC_RETURN_RPC_FREE \
476 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
477
478/*
Jens Wiklander617d8e82021-01-20 11:14:12 +0100479 * Deliver a foreign interrupt in normal world.
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200480 *
481 * "Call" register usage:
David Wang39e65192017-02-16 16:43:44 +0800482 * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200483 * a1-7 Resume information, must be preserved
484 *
485 * "Return" register usage:
486 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
487 * a1-7 Preserved
488 */
Jens Wiklander617d8e82021-01-20 11:14:12 +0100489#define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4
David Wang39e65192017-02-16 16:43:44 +0800490#define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
491 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200492
493/*
494 * Do an RPC request. The supplied struct optee_msg_arg tells which
495 * request to do and the parameters for the request. The following fields
496 * are used (the rest are unused):
497 * - cmd the Request ID
498 * - ret return value of the request, filled in by normal world
499 * - num_params number of parameters for the request
500 * - params the parameters
501 * - param_attrs attributes of the parameters
502 *
503 * "Call" register usage:
504 * a0 OPTEE_SMC_RETURN_RPC_CMD
Jens Wiklander617d8e82021-01-20 11:14:12 +0100505 * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200506 * struct optee_msg_arg, must be preserved, only the data should
507 * be updated
Jens Wiklander617d8e82021-01-20 11:14:12 +0100508 * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a
Jens Wiklander4fb0a5e2015-04-14 14:33:20 +0200509 * struct optee_msg_arg, must be preserved, only the data should
510 * be updated
511 * a3-7 Resume information, must be preserved
512 *
513 * "Return" register usage:
514 * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
515 * a1-2 Not used
516 * a3-7 Preserved
517 */
518#define OPTEE_SMC_RPC_FUNC_CMD 5
519#define OPTEE_SMC_RETURN_RPC_CMD \
520 OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
521
522/* Returned in a0 */
523#define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
524
525/* Returned in a0 only from Trusted OS functions */
526#define OPTEE_SMC_RETURN_OK 0x0
527#define OPTEE_SMC_RETURN_ETHREAD_LIMIT 0x1
528#define OPTEE_SMC_RETURN_EBUSY 0x2
529#define OPTEE_SMC_RETURN_ERESUME 0x3
530#define OPTEE_SMC_RETURN_EBADADDR 0x4
531#define OPTEE_SMC_RETURN_EBADCMD 0x5
532#define OPTEE_SMC_RETURN_ENOMEM 0x6
533#define OPTEE_SMC_RETURN_ENOTAVAIL 0x7
534#define OPTEE_SMC_RETURN_IS_RPC(ret) __optee_smc_return_is_rpc((ret))
535
536static inline bool __optee_smc_return_is_rpc(u32 ret)
537{
538 return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
539 (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
540 OPTEE_SMC_RETURN_RPC_PREFIX;
541}
542
543#endif /* OPTEE_SMC_H */