platform.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. /*
  2. * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef PLATFORM_H
  7. #define PLATFORM_H
  8. #include <stdint.h>
  9. #include <lib/psci/psci.h>
  10. #if defined(SPD_spmd)
  11. #include <services/spm_core_manifest.h>
  12. #endif
  13. #if ENABLE_RME
  14. #include <services/rmm_core_manifest.h>
  15. #endif
  16. #if TRNG_SUPPORT
  17. #include "plat_trng.h"
  18. #endif
  19. #include <drivers/fwu/fwu_metadata.h>
  20. #if DRTM_SUPPORT
  21. #include "plat_drtm.h"
  22. #endif /* DRTM_SUPPORT */
  23. /*******************************************************************************
  24. * Forward declarations
  25. ******************************************************************************/
  26. struct auth_img_desc_s;
  27. struct meminfo;
  28. struct image_info;
  29. struct entry_point_info;
  30. struct image_desc;
  31. struct bl_load_info;
  32. struct bl_params;
  33. struct mmap_region;
  34. struct spm_mm_boot_info;
  35. struct sp_res_desc;
  36. enum fw_enc_status_t;
  37. /*******************************************************************************
  38. * plat_get_rotpk_info() flags
  39. ******************************************************************************/
  40. #define ROTPK_IS_HASH (1 << 0)
  41. /* Flag used to skip verification of the certificate ROTPK while the platform
  42. ROTPK is not deployed */
  43. #define ROTPK_NOT_DEPLOYED (1 << 1)
  44. /*******************************************************************************
  45. * plat_get_enc_key_info() flags
  46. ******************************************************************************/
  47. /*
  48. * Flag used to notify caller that information provided in key buffer is an
  49. * identifier rather than an actual key.
  50. */
  51. #define ENC_KEY_IS_IDENTIFIER (1 << 0)
  52. /*******************************************************************************
  53. * Function declarations
  54. ******************************************************************************/
  55. /*******************************************************************************
  56. * Mandatory common functions
  57. ******************************************************************************/
  58. unsigned int plat_get_syscnt_freq2(void);
  59. int plat_get_image_source(unsigned int image_id,
  60. uintptr_t *dev_handle,
  61. uintptr_t *image_spec);
  62. uintptr_t plat_get_ns_image_entrypoint(void);
  63. unsigned int plat_my_core_pos(void);
  64. int plat_core_pos_by_mpidr(u_register_t mpidr);
  65. int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size);
  66. #if STACK_PROTECTOR_ENABLED
  67. /*
  68. * Return a new value to be used for the stack protection's canary.
  69. *
  70. * Ideally, this value is a random number that is impossible to predict by an
  71. * attacker.
  72. */
  73. u_register_t plat_get_stack_protector_canary(void);
  74. #endif /* STACK_PROTECTOR_ENABLED */
  75. /*******************************************************************************
  76. * Mandatory interrupt management functions
  77. ******************************************************************************/
  78. uint32_t plat_ic_get_pending_interrupt_id(void);
  79. uint32_t plat_ic_get_pending_interrupt_type(void);
  80. uint32_t plat_ic_acknowledge_interrupt(void);
  81. uint32_t plat_ic_get_interrupt_type(uint32_t id);
  82. void plat_ic_end_of_interrupt(uint32_t id);
  83. uint32_t plat_interrupt_type_to_line(uint32_t type,
  84. uint32_t security_state);
  85. /*******************************************************************************
  86. * Optional interrupt management functions, depending on chosen EL3 components.
  87. ******************************************************************************/
  88. unsigned int plat_ic_get_running_priority(void);
  89. int plat_ic_is_spi(unsigned int id);
  90. int plat_ic_is_ppi(unsigned int id);
  91. int plat_ic_is_sgi(unsigned int id);
  92. unsigned int plat_ic_get_interrupt_active(unsigned int id);
  93. void plat_ic_disable_interrupt(unsigned int id);
  94. void plat_ic_enable_interrupt(unsigned int id);
  95. int plat_ic_has_interrupt_type(unsigned int type);
  96. void plat_ic_set_interrupt_type(unsigned int id, unsigned int type);
  97. void plat_ic_set_interrupt_priority(unsigned int id, unsigned int priority);
  98. void plat_ic_raise_el3_sgi(int sgi_num, u_register_t target);
  99. void plat_ic_raise_ns_sgi(int sgi_num, u_register_t target);
  100. void plat_ic_raise_s_el1_sgi(int sgi_num, u_register_t target);
  101. void plat_ic_set_spi_routing(unsigned int id, unsigned int routing_mode,
  102. u_register_t mpidr);
  103. void plat_ic_set_interrupt_pending(unsigned int id);
  104. void plat_ic_clear_interrupt_pending(unsigned int id);
  105. unsigned int plat_ic_set_priority_mask(unsigned int mask);
  106. unsigned int plat_ic_get_interrupt_id(unsigned int raw);
  107. /*******************************************************************************
  108. * Optional common functions (may be overridden)
  109. ******************************************************************************/
  110. uintptr_t plat_get_my_stack(void);
  111. void plat_report_exception(unsigned int exception_type);
  112. void plat_report_prefetch_abort(unsigned int fault_address);
  113. void plat_report_data_abort(unsigned int fault_address);
  114. int plat_crash_console_init(void);
  115. int plat_crash_console_putc(int c);
  116. void plat_crash_console_flush(void);
  117. void plat_error_handler(int err) __dead2;
  118. void plat_panic_handler(void) __dead2;
  119. void plat_system_reset(void) __dead2;
  120. const char *plat_log_get_prefix(unsigned int log_level);
  121. void bl2_plat_preload_setup(void);
  122. int plat_try_next_boot_source(void);
  123. #if MEASURED_BOOT
  124. int plat_mboot_measure_image(unsigned int image_id, image_info_t *image_data);
  125. int plat_mboot_measure_critical_data(unsigned int critical_data_id,
  126. const void *base,
  127. size_t size);
  128. #else
  129. static inline int plat_mboot_measure_image(unsigned int image_id __unused,
  130. image_info_t *image_data __unused)
  131. {
  132. return 0;
  133. }
  134. static inline int plat_mboot_measure_critical_data(
  135. unsigned int critical_data_id __unused,
  136. const void *base __unused,
  137. size_t size __unused)
  138. {
  139. return 0;
  140. }
  141. #endif /* MEASURED_BOOT */
  142. /*******************************************************************************
  143. * Mandatory BL1 functions
  144. ******************************************************************************/
  145. void bl1_early_platform_setup(void);
  146. void bl1_plat_arch_setup(void);
  147. void bl1_platform_setup(void);
  148. struct meminfo *bl1_plat_sec_mem_layout(void);
  149. /*******************************************************************************
  150. * Optional EL3 component functions in BL31
  151. ******************************************************************************/
  152. /* SDEI platform functions */
  153. #if SDEI_SUPPORT
  154. void plat_sdei_setup(void);
  155. int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode);
  156. void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr);
  157. #endif
  158. void plat_default_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
  159. void *handle, uint64_t flags);
  160. void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
  161. void *handle, uint64_t flags);
  162. /*
  163. * The following function is mandatory when the
  164. * firmware update feature is used.
  165. */
  166. int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
  167. unsigned int flags);
  168. /*******************************************************************************
  169. * Optional BL1 functions (may be overridden)
  170. ******************************************************************************/
  171. /*
  172. * The following functions are used for image loading process in BL1.
  173. */
  174. void bl1_plat_set_ep_info(unsigned int image_id,
  175. struct entry_point_info *ep_info);
  176. /*
  177. * The following functions are mandatory when firmware update
  178. * feature is used and optional otherwise.
  179. */
  180. unsigned int bl1_plat_get_next_image_id(void);
  181. struct image_desc *bl1_plat_get_image_desc(unsigned int image_id);
  182. /*
  183. * The following functions are used by firmware update
  184. * feature and may optionally be overridden.
  185. */
  186. __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved);
  187. /*
  188. * This BL1 function can be used by the platforms to update/use image
  189. * information for a given `image_id`.
  190. */
  191. int bl1_plat_handle_pre_image_load(unsigned int image_id);
  192. int bl1_plat_handle_post_image_load(unsigned int image_id);
  193. #if MEASURED_BOOT
  194. void bl1_plat_mboot_init(void);
  195. void bl1_plat_mboot_finish(void);
  196. #else
  197. static inline void bl1_plat_mboot_init(void)
  198. {
  199. }
  200. static inline void bl1_plat_mboot_finish(void)
  201. {
  202. }
  203. #endif /* MEASURED_BOOT */
  204. /*******************************************************************************
  205. * Mandatory BL2 functions
  206. ******************************************************************************/
  207. void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3);
  208. void bl2_plat_arch_setup(void);
  209. void bl2_platform_setup(void);
  210. struct meminfo *bl2_plat_sec_mem_layout(void);
  211. /*
  212. * This function can be used by the platforms to update/use image
  213. * information for given `image_id`.
  214. */
  215. int bl2_plat_handle_pre_image_load(unsigned int image_id);
  216. int bl2_plat_handle_post_image_load(unsigned int image_id);
  217. /*******************************************************************************
  218. * Optional BL2 functions (may be overridden)
  219. ******************************************************************************/
  220. #if MEASURED_BOOT
  221. void bl2_plat_mboot_init(void);
  222. void bl2_plat_mboot_finish(void);
  223. #else
  224. static inline void bl2_plat_mboot_init(void)
  225. {
  226. }
  227. static inline void bl2_plat_mboot_finish(void)
  228. {
  229. }
  230. #endif /* MEASURED_BOOT */
  231. /*******************************************************************************
  232. * Mandatory BL2 at EL3 functions: Must be implemented if BL2_AT_EL3 image is
  233. * supported
  234. ******************************************************************************/
  235. void bl2_el3_early_platform_setup(u_register_t arg0, u_register_t arg1,
  236. u_register_t arg2, u_register_t arg3);
  237. void bl2_el3_plat_arch_setup(void);
  238. /*******************************************************************************
  239. * Optional BL2 at EL3 functions (may be overridden)
  240. ******************************************************************************/
  241. void bl2_el3_plat_prepare_exit(void);
  242. /*******************************************************************************
  243. * Mandatory BL2U functions.
  244. ******************************************************************************/
  245. void bl2u_early_platform_setup(struct meminfo *mem_layout,
  246. void *plat_info);
  247. void bl2u_plat_arch_setup(void);
  248. void bl2u_platform_setup(void);
  249. /*******************************************************************************
  250. * Conditionally mandatory BL2U functions for CSS platforms.
  251. ******************************************************************************/
  252. /*
  253. * This function is used to perform any platform-specific actions required to
  254. * handle the BL2U_SCP firmware.
  255. */
  256. int bl2u_plat_handle_scp_bl2u(void);
  257. /*******************************************************************************
  258. * Mandatory BL31 functions
  259. ******************************************************************************/
  260. void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
  261. u_register_t arg2, u_register_t arg3);
  262. void bl31_plat_arch_setup(void);
  263. void bl31_platform_setup(void);
  264. void bl31_plat_runtime_setup(void);
  265. struct entry_point_info *bl31_plat_get_next_image_ep_info(uint32_t type);
  266. /*******************************************************************************
  267. * Mandatory PSCI functions (BL31)
  268. ******************************************************************************/
  269. int plat_setup_psci_ops(uintptr_t sec_entrypoint,
  270. const struct plat_psci_ops **psci_ops);
  271. const unsigned char *plat_get_power_domain_tree_desc(void);
  272. /*******************************************************************************
  273. * Optional PSCI functions (BL31).
  274. ******************************************************************************/
  275. void plat_psci_stat_accounting_start(const psci_power_state_t *state_info);
  276. void plat_psci_stat_accounting_stop(const psci_power_state_t *state_info);
  277. u_register_t plat_psci_stat_get_residency(unsigned int lvl,
  278. const psci_power_state_t *state_info,
  279. unsigned int last_cpu_idx);
  280. plat_local_state_t plat_get_target_pwr_state(unsigned int lvl,
  281. const plat_local_state_t *states,
  282. unsigned int ncpu);
  283. /*******************************************************************************
  284. * Mandatory BL31 functions when ENABLE_RME=1
  285. ******************************************************************************/
  286. #if ENABLE_RME
  287. int plat_rmmd_get_cca_attest_token(uintptr_t buf, size_t *len,
  288. uintptr_t hash, size_t hash_size);
  289. int plat_rmmd_get_cca_realm_attest_key(uintptr_t buf, size_t *len,
  290. unsigned int type);
  291. size_t plat_rmmd_get_el3_rmm_shared_mem(uintptr_t *shared);
  292. int plat_rmmd_load_manifest(rmm_manifest_t *manifest);
  293. #endif
  294. /*******************************************************************************
  295. * Optional BL31 functions (may be overridden)
  296. ******************************************************************************/
  297. void bl31_plat_enable_mmu(uint32_t flags);
  298. /*******************************************************************************
  299. * Optional BL32 functions (may be overridden)
  300. ******************************************************************************/
  301. void bl32_plat_enable_mmu(uint32_t flags);
  302. /*******************************************************************************
  303. * Trusted Board Boot functions
  304. ******************************************************************************/
  305. int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len,
  306. unsigned int *flags);
  307. int plat_get_nv_ctr(void *cookie, unsigned int *nv_ctr);
  308. int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr);
  309. int plat_set_nv_ctr2(void *cookie, const struct auth_img_desc_s *img_desc,
  310. unsigned int nv_ctr);
  311. int get_mbedtls_heap_helper(void **heap_addr, size_t *heap_size);
  312. int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
  313. size_t *key_len, unsigned int *flags,
  314. const uint8_t *img_id, size_t img_id_len);
  315. /*******************************************************************************
  316. * Secure Partitions functions
  317. ******************************************************************************/
  318. const struct mmap_region *plat_get_secure_partition_mmap(void *cookie);
  319. const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
  320. void *cookie);
  321. int plat_spm_sp_rd_load(struct sp_res_desc *rd, const void *ptr, size_t size);
  322. int plat_spm_sp_get_next_address(void **sp_base, size_t *sp_size,
  323. void **rd_base, size_t *rd_size);
  324. #if defined(SPD_spmd)
  325. int plat_spm_core_manifest_load(spmc_manifest_attribute_t *manifest,
  326. const void *pm_addr);
  327. #endif
  328. #if defined(SPMC_AT_EL3)
  329. int plat_spmc_shmem_datastore_get(uint8_t **datastore, size_t *size);
  330. #endif
  331. /*******************************************************************************
  332. * Mandatory BL image load functions(may be overridden).
  333. ******************************************************************************/
  334. /*
  335. * This function returns pointer to the list of images that the
  336. * platform has populated to load.
  337. */
  338. struct bl_load_info *plat_get_bl_image_load_info(void);
  339. /*
  340. * This function returns a pointer to the shared memory that the
  341. * platform has kept aside to pass trusted firmware related
  342. * information that next BL image could need.
  343. */
  344. struct bl_params *plat_get_next_bl_params(void);
  345. /*
  346. * This function flushes to main memory all the params that are
  347. * passed to next image.
  348. */
  349. void plat_flush_next_bl_params(void);
  350. /*
  351. * The below function enable Trusted Firmware components like SPDs which
  352. * haven't migrated to the new platform API to compile on platforms which
  353. * have the compatibility layer disabled.
  354. */
  355. unsigned int platform_core_pos_helper(unsigned long mpidr);
  356. /*
  357. * Optional function to get SOC version
  358. */
  359. int32_t plat_get_soc_version(void);
  360. /*
  361. * Optional function to get SOC revision
  362. */
  363. int32_t plat_get_soc_revision(void);
  364. /*
  365. * Optional function to check for SMCCC function availability for platform
  366. */
  367. int32_t plat_is_smccc_feature_available(u_register_t fid);
  368. /*******************************************************************************
  369. * FWU platform specific functions
  370. ******************************************************************************/
  371. int plat_fwu_set_metadata_image_source(unsigned int image_id,
  372. uintptr_t *dev_handle,
  373. uintptr_t *image_spec);
  374. void plat_fwu_set_images_source(const struct fwu_metadata *metadata);
  375. uint32_t plat_fwu_get_boot_idx(void);
  376. #endif /* PLATFORM_H */