optee_smc.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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. /* Secure world supports protected memory */
  267. #define OPTEE_SMC_SEC_CAP_PROTMEM BIT(8)
  268. /* Secure world supports dynamic protected memory */
  269. #define OPTEE_SMC_SEC_CAP_DYNAMIC_PROTMEM BIT(9)
  270. #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9
  271. #define OPTEE_SMC_EXCHANGE_CAPABILITIES \
  272. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES)
  273. struct optee_smc_exchange_capabilities_result {
  274. unsigned long status;
  275. unsigned long capabilities;
  276. unsigned long max_notif_value;
  277. unsigned long data;
  278. };
  279. /*
  280. * Disable and empties cache of shared memory objects
  281. *
  282. * Secure world can cache frequently used shared memory objects, for
  283. * example objects used as RPC arguments. When secure world is idle this
  284. * function returns one shared memory reference to free. To disable the
  285. * cache and free all cached objects this function has to be called until
  286. * it returns OPTEE_SMC_RETURN_ENOTAVAIL.
  287. *
  288. * Call register usage:
  289. * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE
  290. * a1-6 Not used
  291. * a7 Hypervisor Client ID register
  292. *
  293. * Normal return register usage:
  294. * a0 OPTEE_SMC_RETURN_OK
  295. * a1 Upper 32 bits of a 64-bit Shared memory cookie
  296. * a2 Lower 32 bits of a 64-bit Shared memory cookie
  297. * a3-7 Preserved
  298. *
  299. * Cache empty return register usage:
  300. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  301. * a1-7 Preserved
  302. *
  303. * Not idle return register usage:
  304. * a0 OPTEE_SMC_RETURN_EBUSY
  305. * a1-7 Preserved
  306. */
  307. #define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE 10
  308. #define OPTEE_SMC_DISABLE_SHM_CACHE \
  309. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE)
  310. struct optee_smc_disable_shm_cache_result {
  311. unsigned long status;
  312. unsigned long shm_upper32;
  313. unsigned long shm_lower32;
  314. unsigned long reserved0;
  315. };
  316. /*
  317. * Enable cache of shared memory objects
  318. *
  319. * Secure world can cache frequently used shared memory objects, for
  320. * example objects used as RPC arguments. When secure world is idle this
  321. * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If
  322. * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned.
  323. *
  324. * Call register usage:
  325. * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE
  326. * a1-6 Not used
  327. * a7 Hypervisor Client ID register
  328. *
  329. * Normal return register usage:
  330. * a0 OPTEE_SMC_RETURN_OK
  331. * a1-7 Preserved
  332. *
  333. * Not idle return register usage:
  334. * a0 OPTEE_SMC_RETURN_EBUSY
  335. * a1-7 Preserved
  336. */
  337. #define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE 11
  338. #define OPTEE_SMC_ENABLE_SHM_CACHE \
  339. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE)
  340. /*
  341. * Query OP-TEE about number of supported threads
  342. *
  343. * Normal World OS or Hypervisor issues this call to find out how many
  344. * threads OP-TEE supports. That is how many standard calls can be issued
  345. * in parallel before OP-TEE will return OPTEE_SMC_RETURN_ETHREAD_LIMIT.
  346. *
  347. * Call requests usage:
  348. * a0 SMC Function ID, OPTEE_SMC_GET_THREAD_COUNT
  349. * a1-6 Not used
  350. * a7 Hypervisor Client ID register
  351. *
  352. * Normal return register usage:
  353. * a0 OPTEE_SMC_RETURN_OK
  354. * a1 Number of threads
  355. * a2-7 Preserved
  356. *
  357. * Error return:
  358. * a0 OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Requested call is not implemented
  359. * a1-7 Preserved
  360. */
  361. #define OPTEE_SMC_FUNCID_GET_THREAD_COUNT 15
  362. #define OPTEE_SMC_GET_THREAD_COUNT \
  363. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_THREAD_COUNT)
  364. /*
  365. * Inform OP-TEE that normal world is able to receive asynchronous
  366. * notifications.
  367. *
  368. * Call requests usage:
  369. * a0 SMC Function ID, OPTEE_SMC_ENABLE_ASYNC_NOTIF
  370. * a1-6 Not used
  371. * a7 Hypervisor Client ID register
  372. *
  373. * Normal return register usage:
  374. * a0 OPTEE_SMC_RETURN_OK
  375. * a1-7 Preserved
  376. *
  377. * Not supported return register usage:
  378. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  379. * a1-7 Preserved
  380. */
  381. #define OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF 16
  382. #define OPTEE_SMC_ENABLE_ASYNC_NOTIF \
  383. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_ASYNC_NOTIF)
  384. /*
  385. * Retrieve a value of notifications pending since the last call of this
  386. * function.
  387. *
  388. * OP-TEE keeps a record of all posted values. When an interrupt is
  389. * received which indicates that there are posted values this function
  390. * should be called until all pended values have been retrieved. When a
  391. * value is retrieved, it's cleared from the record in secure world.
  392. *
  393. * It is expected that this function is called from an interrupt handler
  394. * in normal world.
  395. *
  396. * Call requests usage:
  397. * a0 SMC Function ID, OPTEE_SMC_GET_ASYNC_NOTIF_VALUE
  398. * a1-6 Not used
  399. * a7 Hypervisor Client ID register
  400. *
  401. * Normal return register usage:
  402. * a0 OPTEE_SMC_RETURN_OK
  403. * a1 value
  404. * a2 Bit[0]: OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID if the value in a1 is
  405. * valid, else 0 if no values where pending
  406. * a2 Bit[1]: OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING if another value is
  407. * pending, else 0.
  408. * Bit[31:2]: MBZ
  409. * a3-7 Preserved
  410. *
  411. * Not supported return register usage:
  412. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  413. * a1-7 Preserved
  414. */
  415. #define OPTEE_SMC_ASYNC_NOTIF_VALUE_VALID BIT(0)
  416. #define OPTEE_SMC_ASYNC_NOTIF_VALUE_PENDING BIT(1)
  417. /*
  418. * Notification that OP-TEE expects a yielding call to do some bottom half
  419. * work in a driver.
  420. */
  421. #define OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF 0
  422. #define OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE 17
  423. #define OPTEE_SMC_GET_ASYNC_NOTIF_VALUE \
  424. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_ASYNC_NOTIF_VALUE)
  425. /* See OPTEE_SMC_CALL_WITH_RPC_ARG above */
  426. #define OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG 18
  427. /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */
  428. #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG 19
  429. /*
  430. * Get protected memory config
  431. *
  432. * Returns the protected memory config.
  433. *
  434. * Call register usage:
  435. * a0 SMC Function ID, OPTEE_SMC_GET_PROTMEM_CONFIG
  436. * a2-6 Not used, must be zero
  437. * a7 Hypervisor Client ID register
  438. *
  439. * Have config return register usage:
  440. * a0 OPTEE_SMC_RETURN_OK
  441. * a1 Physical address of start of protected memory
  442. * a2 Size of protected memory
  443. * a3 PA width, max 64
  444. * a4-7 Preserved
  445. *
  446. * Not available register usage:
  447. * a0 OPTEE_SMC_RETURN_ENOTAVAIL
  448. * a1-3 Not used
  449. * a4-7 Preserved
  450. */
  451. #define OPTEE_SMC_FUNCID_GET_PROTMEM_CONFIG 20
  452. #define OPTEE_SMC_GET_PROTMEM_CONFIG \
  453. OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_PROTMEM_CONFIG)
  454. struct optee_smc_get_protmem_config_result {
  455. unsigned long status;
  456. unsigned long start;
  457. unsigned long size;
  458. unsigned long pa_width;
  459. };
  460. /*
  461. * Resume from RPC (for example after processing a foreign interrupt)
  462. *
  463. * Call register usage:
  464. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC
  465. * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned
  466. * OPTEE_SMC_RETURN_RPC in a0
  467. *
  468. * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above.
  469. *
  470. * Possible return values
  471. * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this
  472. * function.
  473. * OPTEE_SMC_RETURN_OK Original call completed, result
  474. * updated in the previously supplied.
  475. * struct optee_msg_arg
  476. * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal
  477. * world.
  478. * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume
  479. * information was corrupt.
  480. */
  481. #define OPTEE_SMC_FUNCID_RETURN_FROM_RPC 3
  482. #define OPTEE_SMC_CALL_RETURN_FROM_RPC \
  483. OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC)
  484. #define OPTEE_SMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000
  485. #define OPTEE_SMC_RETURN_RPC_PREFIX 0xFFFF0000
  486. #define OPTEE_SMC_RETURN_RPC_FUNC_MASK 0x0000FFFF
  487. #define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \
  488. ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK)
  489. #define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX)
  490. /*
  491. * Allocate memory for RPC parameter passing. The memory is used to hold a
  492. * struct optee_msg_arg.
  493. *
  494. * "Call" register usage:
  495. * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC
  496. * a1 Size in bytes of required argument memory
  497. * a2 Not used
  498. * a3 Resume information, must be preserved
  499. * a4-5 Not used
  500. * a6-7 Resume information, must be preserved
  501. *
  502. * "Return" register usage:
  503. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  504. * a1 Upper 32 bits of 64-bit physical pointer to allocated
  505. * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
  506. * be allocated.
  507. * a2 Lower 32 bits of 64-bit physical pointer to allocated
  508. * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't
  509. * be allocated
  510. * a3 Preserved
  511. * a4 Upper 32 bits of 64-bit Shared memory cookie used when freeing
  512. * the memory or doing an RPC
  513. * a5 Lower 32 bits of 64-bit Shared memory cookie used when freeing
  514. * the memory or doing an RPC
  515. * a6-7 Preserved
  516. */
  517. #define OPTEE_SMC_RPC_FUNC_ALLOC 0
  518. #define OPTEE_SMC_RETURN_RPC_ALLOC \
  519. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC)
  520. /*
  521. * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC
  522. *
  523. * "Call" register usage:
  524. * a0 This value, OPTEE_SMC_RETURN_RPC_FREE
  525. * a1 Upper 32 bits of 64-bit shared memory cookie belonging to this
  526. * argument memory
  527. * a2 Lower 32 bits of 64-bit shared memory cookie belonging to this
  528. * argument memory
  529. * a3-7 Resume information, must be preserved
  530. *
  531. * "Return" register usage:
  532. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  533. * a1-2 Not used
  534. * a3-7 Preserved
  535. */
  536. #define OPTEE_SMC_RPC_FUNC_FREE 2
  537. #define OPTEE_SMC_RETURN_RPC_FREE \
  538. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE)
  539. /*
  540. * Deliver a foreign interrupt in normal world.
  541. *
  542. * "Call" register usage:
  543. * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR
  544. * a1-7 Resume information, must be preserved
  545. *
  546. * "Return" register usage:
  547. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  548. * a1-7 Preserved
  549. */
  550. #define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4
  551. #define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \
  552. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR)
  553. /*
  554. * Do an RPC request. The supplied struct optee_msg_arg tells which
  555. * request to do and the parameters for the request. The following fields
  556. * are used (the rest are unused):
  557. * - cmd the Request ID
  558. * - ret return value of the request, filled in by normal world
  559. * - num_params number of parameters for the request
  560. * - params the parameters
  561. * - param_attrs attributes of the parameters
  562. *
  563. * "Call" register usage:
  564. * a0 OPTEE_SMC_RETURN_RPC_CMD
  565. * a1 Upper 32 bits of a 64-bit Shared memory cookie holding a
  566. * struct optee_msg_arg, must be preserved, only the data should
  567. * be updated
  568. * a2 Lower 32 bits of a 64-bit Shared memory cookie holding a
  569. * struct optee_msg_arg, must be preserved, only the data should
  570. * be updated
  571. * a3-7 Resume information, must be preserved
  572. *
  573. * "Return" register usage:
  574. * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC.
  575. * a1-2 Not used
  576. * a3-7 Preserved
  577. */
  578. #define OPTEE_SMC_RPC_FUNC_CMD 5
  579. #define OPTEE_SMC_RETURN_RPC_CMD \
  580. OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD)
  581. /* Returned in a0 */
  582. #define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF
  583. /* Returned in a0 only from Trusted OS functions */
  584. #define OPTEE_SMC_RETURN_OK 0x0
  585. #define OPTEE_SMC_RETURN_ETHREAD_LIMIT 0x1
  586. #define OPTEE_SMC_RETURN_EBUSY 0x2
  587. #define OPTEE_SMC_RETURN_ERESUME 0x3
  588. #define OPTEE_SMC_RETURN_EBADADDR 0x4
  589. #define OPTEE_SMC_RETURN_EBADCMD 0x5
  590. #define OPTEE_SMC_RETURN_ENOMEM 0x6
  591. #define OPTEE_SMC_RETURN_ENOTAVAIL 0x7
  592. #define OPTEE_SMC_RETURN_IS_RPC(ret) __optee_smc_return_is_rpc((ret))
  593. static inline bool __optee_smc_return_is_rpc(u32 ret)
  594. {
  595. return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION &&
  596. (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) ==
  597. OPTEE_SMC_RETURN_RPC_PREFIX;
  598. }
  599. #endif /* OPTEE_SMC_H */