optee_smc.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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. #include <linux/arm-smccc.h>
  8. #include <linux/bitops.h>
  9. #define OPTEE_SMC_STD_CALL_VAL(func_num) \
  10. ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \
  11. ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
  12. #define OPTEE_SMC_FAST_CALL_VAL(func_num) \
  13. ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
  14. ARM_SMCCC_OWNER_TRUSTED_OS, (func_num))
  15. /*
  16. * Function specified by SMC Calling convention.
  17. */
  18. #define OPTEE_SMC_FUNCID_CALLS_COUNT 0xFF00
  19. #define OPTEE_SMC_CALLS_COUNT \
  20. ARM_SMCCC_CALL_VAL(OPTEE_SMC_FAST_CALL, SMCCC_SMC_32, \
  21. SMCCC_OWNER_TRUSTED_OS_END, \
  22. OPTEE_SMC_FUNCID_CALLS_COUNT)
  23. /*
  24. * Normal cached memory (write-back), shareable for SMP systems and not
  25. * shareable for UP systems.
  26. */
  27. #define OPTEE_SMC_SHM_CACHED 1
  28. /*
  29. * a0..a7 is used as register names in the descriptions below, on arm32
  30. * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's
  31. * 32-bit registers.
  32. */
  33. /*
  34. * Function specified by SMC Calling convention
  35. *
  36. * Return the following UID if using API specified in this file
  37. * without further extensions:
  38. * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b.
  39. * see also OPTEE_MSG_UID_* in optee_msg.h
  40. */
  41. #define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID
  42. #define OPTEE_SMC_CALLS_UID \
  43. ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
  44. ARM_SMCCC_OWNER_TRUSTED_OS_END, \
  45. OPTEE_SMC_FUNCID_CALLS_UID)
  46. /*
  47. * Function specified by SMC Calling convention
  48. *
  49. * Returns 2.0 if using API specified in this file without further extensions.
  50. * see also OPTEE_MSG_REVISION_* in optee_msg.h
  51. */
  52. #define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION
  53. #define OPTEE_SMC_CALLS_REVISION \
  54. ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
  55. ARM_SMCCC_OWNER_TRUSTED_OS_END, \
  56. OPTEE_SMC_FUNCID_CALLS_REVISION)
  57. struct optee_smc_calls_revision_result {
  58. unsigned long major;
  59. unsigned long minor;
  60. unsigned long reserved0;
  61. unsigned long reserved1;
  62. };
  63. /*
  64. * Get UUID of Trusted OS.
  65. *
  66. * Used by non-secure world to figure out which Trusted OS is installed.
  67. * Note that returned UUID is the UUID of the Trusted OS, not of the API.
  68. *
  69. * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID
  70. * described above.
  71. */
  72. #define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID
  73. #define OPTEE_SMC_CALL_GET_OS_UUID \
  74. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID)
  75. /*
  76. * Get revision of Trusted OS.
  77. *
  78. * Used by non-secure world to figure out which version of the Trusted OS
  79. * is installed. Note that the returned revision is the revision of the
  80. * Trusted OS, not of the API.
  81. *
  82. * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION
  83. * described above. May optionally return a 32-bit build identifier in a2,
  84. * with zero meaning unspecified.
  85. */
  86. #define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION
  87. #define OPTEE_SMC_CALL_GET_OS_REVISION \
  88. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION)
  89. struct optee_smc_call_get_os_revision_result {
  90. unsigned long major;
  91. unsigned long minor;
  92. unsigned long build_id;
  93. unsigned long reserved1;
  94. };
  95. /*
  96. * Load Trusted OS from optee/tee.bin in the Linux firmware.
  97. *
  98. * WARNING: Use this cautiously as it could lead to insecure loading of the
  99. * Trusted OS.
  100. * This SMC instructs EL3 to load a binary and execute it as the Trusted OS.
  101. *
  102. * Call register usage:
  103. * a0 SMC Function ID, OPTEE_SMC_CALL_LOAD_IMAGE
  104. * a1 Upper 32bit of a 64bit size for the payload
  105. * a2 Lower 32bit of a 64bit size for the payload
  106. * a3 Upper 32bit of the physical address for the payload
  107. * a4 Lower 32bit of the physical address for the payload
  108. *
  109. * The payload is in the OP-TEE image format.
  110. *
  111. * Returns result in a0, 0 on success and an error code otherwise.
  112. */
  113. #define OPTEE_SMC_FUNCID_LOAD_IMAGE 2
  114. #define OPTEE_SMC_CALL_LOAD_IMAGE \
  115. ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
  116. ARM_SMCCC_OWNER_TRUSTED_OS_END, \
  117. OPTEE_SMC_FUNCID_LOAD_IMAGE)
  118. /*
  119. * Call with struct optee_msg_arg as argument
  120. *
  121. * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or
  122. * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg
  123. * following after the first struct optee_msg_arg. The RPC struct
  124. * optee_msg_arg has reserved space for the number of RPC parameters as
  125. * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES.
  126. *
  127. * When calling these functions, normal world has a few responsibilities:
  128. * 1. It must be able to handle eventual RPCs
  129. * 2. Non-secure interrupts should not be masked
  130. * 3. If asynchronous notifications has been negotiated successfully, then
  131. * the interrupt for asynchronous notifications should be unmasked
  132. * during this call.
  133. *
  134. * Call register usage, OPTEE_SMC_CALL_WITH_ARG and
  135. * OPTEE_SMC_CALL_WITH_RPC_ARG:
  136. * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_ARG or OPTEE_SMC_CALL_WITH_RPC_ARG
  137. * a1 Upper 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
  138. * a2 Lower 32 bits of a 64-bit physical pointer to a struct optee_msg_arg
  139. * a3 Cache settings, not used if physical pointer is in a predefined shared
  140. * memory area else per OPTEE_SMC_SHM_*
  141. * a4-6 Not used
  142. * a7 Hypervisor Client ID register
  143. *
  144. * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG:
  145. * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG
  146. * a1 Upper 32 bits of a 64-bit shared memory cookie
  147. * a2 Lower 32 bits of a 64-bit shared memory cookie
  148. * a3 Offset of the struct optee_msg_arg in the shared memory with the
  149. * supplied cookie
  150. * a4-6 Not used
  151. * a7 Hypervisor Client ID register
  152. *
  153. * Normal return register usage:
  154. * a0 Return value, OPTEE_SMC_RETURN_*
  155. * a1-3 Not used
  156. * a4-7 Preserved
  157. *
  158. * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage:
  159. * a0 Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT
  160. * a1-3 Preserved
  161. * a4-7 Preserved
  162. *
  163. * RPC return register usage:
  164. * a0 Return value, OPTEE_SMC_RETURN_IS_RPC(val)
  165. * a1-2 RPC parameters
  166. * a3-7 Resume information, must be preserved
  167. *
  168. * Possible return values:
  169. * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
  170. * function.
  171. * OPTEE_SMC_RETURN_OK Call completed, result updated in
  172. * the previously supplied struct
  173. * optee_msg_arg.
  174. * OPTEE_SMC_RETURN_ETHREAD_LIMIT Number of Trusted OS threads exceeded,
  175. * try again later.
  176. * OPTEE_SMC_RETURN_EBADADDR Bad physical pointer to struct
  177. * optee_msg_arg.
  178. * OPTEE_SMC_RETURN_EBADCMD Bad/unknown cmd in struct optee_msg_arg
  179. * OPTEE_SMC_RETURN_IS_RPC() Call suspended by RPC call to normal
  180. * world.
  181. */
  182. #define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG
  183. #define OPTEE_SMC_CALL_WITH_ARG \
  184. OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG)
  185. #define OPTEE_SMC_CALL_WITH_RPC_ARG \
  186. OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG)
  187. #define OPTEE_SMC_CALL_WITH_REGD_ARG \
  188. OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG)
  189. /*
  190. * Get Shared Memory Config
  191. *
  192. * Returns the Secure/Non-secure shared memory config.
  193. *
  194. * Call register usage:
  195. * a0 SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG
  196. * a1-6 Not used
  197. * a7 Hypervisor Client ID register
  198. *
  199. * Have config return register usage:
  200. * a0 OPTEE_SMC_RETURN_OK
  201. * a1 Physical address of start of SHM
  202. * a2 Size of SHM
  203. * a3 Cache settings of memory, as defined by the
  204. * OPTEE_SMC_SHM_* values above
  205. * a4-7 Preserved
  206. *
  207. * Not available register usage:
  208. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  209. * a1-3 Not used
  210. * a4-7 Preserved
  211. */
  212. #define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7
  213. #define OPTEE_SMC_GET_SHM_CONFIG \
  214. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG)
  215. struct optee_smc_get_shm_config_result {
  216. unsigned long status;
  217. unsigned long start;
  218. unsigned long size;
  219. unsigned long settings;
  220. };
  221. /*
  222. * Exchanges capabilities between normal world and secure world
  223. *
  224. * Call register usage:
  225. * a0 SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES
  226. * a1 bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_*
  227. * a2-6 Not used
  228. * a7 Hypervisor Client ID register
  229. *
  230. * Normal return register usage:
  231. * a0 OPTEE_SMC_RETURN_OK
  232. * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
  233. * a2 The maximum secure world notification number
  234. * a3 Bit[7:0]: Number of parameters needed for RPC to be supplied
  235. * as the second MSG arg struct for
  236. * OPTEE_SMC_CALL_WITH_ARG
  237. * Bit[31:8]: Reserved (MBZ)
  238. * a4-7 Preserved
  239. *
  240. * Error return register usage:
  241. * a0 OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world
  242. * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_*
  243. * a2-7 Preserved
  244. */
  245. /* Normal world works as a uniprocessor system */
  246. #define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR BIT(0)
  247. /* Secure world has reserved shared memory for normal world to use */
  248. #define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0)
  249. /* Secure world can communicate via previously unregistered shared memory */
  250. #define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM BIT(1)
  251. /*
  252. * Secure world supports commands "register/unregister shared memory",
  253. * secure world accepts command buffers located in any parts of non-secure RAM
  254. */
  255. #define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2)
  256. /* Secure world is built with virtualization support */
  257. #define OPTEE_SMC_SEC_CAP_VIRTUALIZATION BIT(3)
  258. /* Secure world supports Shared Memory with a NULL reference */
  259. #define OPTEE_SMC_SEC_CAP_MEMREF_NULL BIT(4)
  260. /* Secure world supports asynchronous notification of normal world */
  261. #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF BIT(5)
  262. /* Secure world supports pre-allocating RPC arg struct */
  263. #define OPTEE_SMC_SEC_CAP_RPC_ARG BIT(6)
  264. /* Secure world supports probing for RPMB device if needed */
  265. #define OPTEE_SMC_SEC_CAP_RPMB_PROBE BIT(7)
  266. #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9
  267. #define OPTEE_SMC_EXCHANGE_CAPABILITIES \
  268. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
  269. struct optee_smc_exchange_capabilities_result {
  270. unsigned long status;
  271. unsigned long capabilities;
  272. unsigned long max_notif_value;
  273. unsigned long data;
  274. };
  275. /*
  276. * Disable and empties cache of shared memory objects
  277. *
  278. * Secure world can cache frequently used shared memory objects, for
  279. * example objects used as RPC arguments. When secure world is idle this
  280. * function returns one shared memory reference to free. To disable the
  281. * cache and free all cached objects this function has to be called until
  282. * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
  283. *
  284. * Call register usage:
  285. * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
  286. * a1-6 Not used
  287. * a7 Hypervisor Client ID register
  288. *
  289. * Normal return register usage:
  290. * a0 OPTEE_SMC_RETURN_OK
  291. * a1 Upper 32 bits of a 64-bit Shared memory cookie
  292. * a2 Lower 32 bits of a 64-bit Shared memory cookie
  293. * a3-7 Preserved
  294. *
  295. * Cache empty return register usage:
  296. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  297. * a1-7 Preserved
  298. *
  299. * Not idle return register usage:
  300. * a0 OPTEE_SMC_RETURN_EBUSY
  301. * a1-7 Preserved
  302. */
  303. #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE 10
  304. #define OPTEE_SMC_DISABLE_SHM_CACHE \
  305. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
  306. struct optee_smc_disable_shm_cache_result {
  307. unsigned long status;
  308. unsigned long shm_upper32;
  309. unsigned long shm_lower32;
  310. unsigned long reserved0;
  311. };
  312. /*
  313. * Enable cache of shared memory objects
  314. *
  315. * Secure world can cache frequently used shared memory objects, for
  316. * example objects used as RPC arguments. When secure world is idle this
  317. * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
  318. * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
  319. *
  320. * Call register usage:
  321. * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
  322. * a1-6 Not used
  323. * a7 Hypervisor Client ID register
  324. *
  325. * Normal return register usage:
  326. * a0 OPTEE_SMC_RETURN_OK
  327. * a1-7 Preserved
  328. *
  329. * Not idle return register usage:
  330. * a0 OPTEE_SMC_RETURN_EBUSY
  331. * a1-7 Preserved
  332. */
  333. #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE 11
  334. #define OPTEE_SMC_ENABLE_SHM_CACHE \
  335. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
  336. /*
  337. * Query OP-TEE about number of supported threads
  338. *
  339. * Normal World OS or Hypervisor issues this call to find out how many
  340. * threads OP-TEE supports. That is how many standard calls can be issued
  341. * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
  342. *
  343. * Call requests usage:
  344. * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
  345. * a1-6 Not used
  346. * a7 Hypervisor Client ID register
  347. *
  348. * Normal return register usage:
  349. * a0 OPTEE_SMC_RETURN_OK
  350. * a1 Number of threads
  351. * a2-7 Preserved
  352. *
  353. * Error return:
  354. * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented
  355. * a1-7 Preserved
  356. */
  357. #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT 15
  358. #define OPTEE_SMC_GET_THREAD_COUNT \
  359. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
  360. /*
  361. * Inform OP-TEE that normal world is able to receive asynchronous
  362. * notifications.
  363. *
  364. * Call requests usage:
  365. * a0 SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
  366. * a1-6 Not used
  367. * a7 Hypervisor Client ID register
  368. *
  369. * Normal return register usage:
  370. * a0 OPTEE_SMC_RETURN_OK
  371. * a1-7 Preserved
  372. *
  373. * Not supported return register usage:
  374. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  375. * a1-7 Preserved
  376. */
  377. #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16
  378. #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
  379. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
  380. /*
  381. * Retrieve a value of notifications pending since the last call of this
  382. * function.
  383. *
  384. * OP-TEE keeps a record of all posted values. When an interrupt is
  385. * received which indicates that there are posted values this function
  386. * should be called until all pended values have been retrieved. When a
  387. * value is retrieved, it's cleared from the record in secure world.
  388. *
  389. * It is expected that this function is called from an interrupt handler
  390. * in normal world.
  391. *
  392. * Call requests usage:
  393. * a0 SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
  394. * a1-6 Not used
  395. * a7 Hypervisor Client ID register
  396. *
  397. * Normal return register usage:
  398. * a0 OPTEE_SMC_RETURN_OK
  399. * a1 value
  400. * a2 Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
  401. * valid, else 0 if no values where pending
  402. * a2 Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
  403. * pending, else 0.
  404. * Bit[31:2]: MBZ
  405. * a3-7 Preserved
  406. *
  407. * Not supported return register usage:
  408. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  409. * a1-7 Preserved
  410. */
  411. #define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID BIT(0)
  412. #define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING BIT(1)
  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. #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE 17
  419. #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
  420. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
  421. /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */
  422. #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG 18
  423. /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */
  424. #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG 19
  425. /*
  426. * Resume from RPC (for example after processing a foreign interrupt)
  427. *
  428. * Call register usage:
  429. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
  430. * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
  431. * OPTEE_SMC_RETURN_RPC in a0
  432. *
  433. * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
  434. *
  435. * Possible return values
  436. * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
  437. * function.
  438. * OPTEE_SMC_RETURN_OK Original call completed, result
  439. * updated in the previously supplied.
  440. * struct optee_msg_arg
  441. * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal
  442. * world.
  443. * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume
  444. * information was corrupt.
  445. */
  446. #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC 3
  447. #define OPTEE_SMC_CALL_RETURN_FROM_RPC \
  448. OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
  449. #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000
  450. #define OPTEE_SMC_RETURN_RPC_PREFIX 0xFFFF0000
  451. #define OPTEE_SMC_RETURN_RPC_FUNC_MASK 0x0000FFFF
  452. #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
  453. ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
  454. #define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
  455. /*
  456. * Allocate memory for RPC parameter passing. The memory is used to hold a
  457. * struct optee_msg_arg.
  458. *
  459. * "Call" register usage:
  460. * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC
  461. * a1 Size in bytes of required argument memory
  462. * a2 Not used
  463. * a3 Resume information, must be preserved
  464. * a4-5 Not used
  465. * a6-7 Resume information, must be preserved
  466. *
  467. * "Return" register usage:
  468. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  469. * a1 Upper 32 bits of 64-bit physical pointer to allocated
  470. * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
  471. * be allocated.
  472. * a2 Lower 32 bits of 64-bit physical pointer to allocated
  473. * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
  474. * be allocated
  475. * a3 Preserved
  476. * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing
  477. * the memory or doing an RPC
  478. * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing
  479. * the memory or doing an RPC
  480. * a6-7 Preserved
  481. */
  482. #define OPTEE_SMC_RPC_FUNC_ALLOC 0
  483. #define OPTEE_SMC_RETURN_RPC_ALLOC \
  484. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
  485. /*
  486. * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
  487. *
  488. * "Call" register usage:
  489. * a0 This value, OPTEE_SMC_RETURN_RPC_FREE
  490. * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this
  491. * argument memory
  492. * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this
  493. * argument memory
  494. * a3-7 Resume information, must be preserved
  495. *
  496. * "Return" register usage:
  497. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  498. * a1-2 Not used
  499. * a3-7 Preserved
  500. */
  501. #define OPTEE_SMC_RPC_FUNC_FREE 2
  502. #define OPTEE_SMC_RETURN_RPC_FREE \
  503. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
  504. /*
  505. * Deliver a foreign interrupt in normal world.
  506. *
  507. * "Call" register usage:
  508. * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
  509. * a1-7 Resume information, must be preserved
  510. *
  511. * "Return" register usage:
  512. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  513. * a1-7 Preserved
  514. */
  515. #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4
  516. #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
  517. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
  518. /*
  519. * Do an RPC request. The supplied struct optee_msg_arg tells which
  520. * request to do and the parameters for the request. The following fields
  521. * are used (the rest are unused):
  522. * - cmd the Request ID
  523. * - ret return value of the request, filled in by normal world
  524. * - num_params number of parameters for the request
  525. * - params the parameters
  526. * - param_attrs attributes of the parameters
  527. *
  528. * "Call" register usage:
  529. * a0 OPTEE_SMC_RETURN_RPC_CMD
  530. * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a
  531. * struct optee_msg_arg, must be preserved, only the data should
  532. * be updated
  533. * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a
  534. * struct optee_msg_arg, must be preserved, only the data should
  535. * be updated
  536. * a3-7 Resume information, must be preserved
  537. *
  538. * "Return" register usage:
  539. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  540. * a1-2 Not used
  541. * a3-7 Preserved
  542. */
  543. #define OPTEE_SMC_RPC_FUNC_CMD 5
  544. #define OPTEE_SMC_RETURN_RPC_CMD \
  545. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
  546. /* Returned in a0 */
  547. #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
  548. /* Returned in a0 only from Trusted OS functions */
  549. #define OPTEE_SMC_RETURN_OK 0x0
  550. #define OPTEE_SMC_RETURN_ETHREAD_LIMIT 0x1
  551. #define OPTEE_SMC_RETURN_EBUSY 0x2
  552. #define OPTEE_SMC_RETURN_ERESUME 0x3
  553. #define OPTEE_SMC_RETURN_EBADADDR 0x4
  554. #define OPTEE_SMC_RETURN_EBADCMD 0x5
  555. #define OPTEE_SMC_RETURN_ENOMEM 0x6
  556. #define OPTEE_SMC_RETURN_ENOTAVAIL 0x7
  557. #define OPTEE_SMC_RETURN_IS_RPC(ret) __optee_smc_return_is_rpc((ret))
  558. static inline bool __optee_smc_return_is_rpc(u32 ret)
  559. {
  560. return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
  561. (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
  562. OPTEE_SMC_RETURN_RPC_PREFIX;
  563. }
  564. #endif /* OPTEE_SMC_H */