xref: /rk3399_ARM-atf/include/plat/common/platform.h (revision cbf9e84a193883f11a99b2f61417710a69e36e0d)
15f0cdb05SDan Handley /*
20cb64d01SAchin Gupta  * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved.
35f0cdb05SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
55f0cdb05SDan Handley  */
65f0cdb05SDan Handley 
72bc3dba9SAntonio Nino Diaz #ifndef PLATFORM_H
82bc3dba9SAntonio Nino Diaz #define PLATFORM_H
95f0cdb05SDan Handley 
105f0cdb05SDan Handley #include <stdint.h>
115f0cdb05SDan Handley 
1209d40e0eSAntonio Nino Diaz #include <lib/psci/psci.h>
130cb64d01SAchin Gupta #if defined(SPD_spmd)
140cb64d01SAchin Gupta  #include <services/spm_core_manifest.h>
150cb64d01SAchin Gupta #endif
1609d40e0eSAntonio Nino Diaz 
175f0cdb05SDan Handley /*******************************************************************************
185f0cdb05SDan Handley  * Forward declarations
195f0cdb05SDan Handley  ******************************************************************************/
20d35dee23Sdp-arm struct auth_img_desc_s;
215f0cdb05SDan Handley struct meminfo;
225f0cdb05SDan Handley struct image_info;
235f0cdb05SDan Handley struct entry_point_info;
247baff11fSYatharth Kochar struct image_desc;
2572600226SYatharth Kochar struct bl_load_info;
2672600226SYatharth Kochar struct bl_params;
272fccb228SAntonio Nino Diaz struct mmap_region;
28aeaa225cSPaul Beesley struct spm_mm_boot_info;
29e458302bSAntonio Nino Diaz struct sp_res_desc;
302be57b86SSumit Garg enum fw_enc_status_t;
315f0cdb05SDan Handley 
325f0cdb05SDan Handley /*******************************************************************************
3395cfd4adSJuan Castillo  * plat_get_rotpk_info() flags
3495cfd4adSJuan Castillo  ******************************************************************************/
3595cfd4adSJuan Castillo #define ROTPK_IS_HASH			(1 << 0)
3604943d33SSoby Mathew /* Flag used to skip verification of the certificate ROTPK while the platform
3704943d33SSoby Mathew    ROTPK is not deployed */
3804943d33SSoby Mathew #define ROTPK_NOT_DEPLOYED		(1 << 1)
3995cfd4adSJuan Castillo 
4095cfd4adSJuan Castillo /*******************************************************************************
417cda17bbSSumit Garg  * plat_get_enc_key_info() flags
427cda17bbSSumit Garg  ******************************************************************************/
437cda17bbSSumit Garg /*
447cda17bbSSumit Garg  * Flag used to notify caller that information provided in key buffer is an
457cda17bbSSumit Garg  * identifier rather than an actual key.
467cda17bbSSumit Garg  */
477cda17bbSSumit Garg #define ENC_KEY_IS_IDENTIFIER		(1 << 0)
487cda17bbSSumit Garg 
497cda17bbSSumit Garg /*******************************************************************************
50dec5e0d1SDan Handley  * Function declarations
515f0cdb05SDan Handley  ******************************************************************************/
52dec5e0d1SDan Handley /*******************************************************************************
53dec5e0d1SDan Handley  * Mandatory common functions
54dec5e0d1SDan Handley  ******************************************************************************/
55d4486391SAntonio Nino Diaz unsigned int plat_get_syscnt_freq2(void);
56d4486391SAntonio Nino Diaz 
5716948ae1SJuan Castillo int plat_get_image_source(unsigned int image_id,
58dec5e0d1SDan Handley 			uintptr_t *dev_handle,
59dec5e0d1SDan Handley 			uintptr_t *image_spec);
60a0ad6019SSoby Mathew uintptr_t plat_get_ns_image_entrypoint(void);
6167487846SSoby Mathew unsigned int plat_my_core_pos(void);
6267487846SSoby Mathew int plat_core_pos_by_mpidr(u_register_t mpidr);
632374ab17SAmbroise Vincent int plat_get_mbedtls_heap(void **heap_addr, size_t *heap_size);
64dec5e0d1SDan Handley 
6551faada7SDouglas Raillard #if STACK_PROTECTOR_ENABLED
6651faada7SDouglas Raillard /*
6751faada7SDouglas Raillard  * Return a new value to be used for the stack protection's canary.
6851faada7SDouglas Raillard  *
6951faada7SDouglas Raillard  * Ideally, this value is a random number that is impossible to predict by an
7051faada7SDouglas Raillard  * attacker.
7151faada7SDouglas Raillard  */
7251faada7SDouglas Raillard u_register_t plat_get_stack_protector_canary(void);
7351faada7SDouglas Raillard #endif /* STACK_PROTECTOR_ENABLED */
7451faada7SDouglas Raillard 
75dec5e0d1SDan Handley /*******************************************************************************
76dec5e0d1SDan Handley  * Mandatory interrupt management functions
77dec5e0d1SDan Handley  ******************************************************************************/
789865ac15SDan Handley uint32_t plat_ic_get_pending_interrupt_id(void);
799865ac15SDan Handley uint32_t plat_ic_get_pending_interrupt_type(void);
809865ac15SDan Handley uint32_t plat_ic_acknowledge_interrupt(void);
819865ac15SDan Handley uint32_t plat_ic_get_interrupt_type(uint32_t id);
829865ac15SDan Handley void plat_ic_end_of_interrupt(uint32_t id);
835f0cdb05SDan Handley uint32_t plat_interrupt_type_to_line(uint32_t type,
845f0cdb05SDan Handley 				     uint32_t security_state);
855f0cdb05SDan Handley 
86dec5e0d1SDan Handley /*******************************************************************************
87eb68ea9bSJeenu Viswambharan  * Optional interrupt management functions, depending on chosen EL3 components.
88eb68ea9bSJeenu Viswambharan  ******************************************************************************/
89eb68ea9bSJeenu Viswambharan unsigned int plat_ic_get_running_priority(void);
90ca43b55dSJeenu Viswambharan int plat_ic_is_spi(unsigned int id);
91ca43b55dSJeenu Viswambharan int plat_ic_is_ppi(unsigned int id);
92ca43b55dSJeenu Viswambharan int plat_ic_is_sgi(unsigned int id);
93cbd3f370SJeenu Viswambharan unsigned int plat_ic_get_interrupt_active(unsigned int id);
94979225f4SJeenu Viswambharan void plat_ic_disable_interrupt(unsigned int id);
95979225f4SJeenu Viswambharan void plat_ic_enable_interrupt(unsigned int id);
9674dce7faSJeenu Viswambharan int plat_ic_has_interrupt_type(unsigned int type);
9774dce7faSJeenu Viswambharan void plat_ic_set_interrupt_type(unsigned int id, unsigned int type);
98f3a86600SJeenu Viswambharan void plat_ic_set_interrupt_priority(unsigned int id, unsigned int priority);
998db978b5SJeenu Viswambharan void plat_ic_raise_el3_sgi(int sgi_num, u_register_t target);
100fc529feeSJeenu Viswambharan void plat_ic_set_spi_routing(unsigned int id, unsigned int routing_mode,
101fc529feeSJeenu Viswambharan 		u_register_t mpidr);
102a2816a16SJeenu Viswambharan void plat_ic_set_interrupt_pending(unsigned int id);
103a2816a16SJeenu Viswambharan void plat_ic_clear_interrupt_pending(unsigned int id);
104d55a4450SJeenu Viswambharan unsigned int plat_ic_set_priority_mask(unsigned int mask);
1054ee8d0beSJeenu Viswambharan unsigned int plat_ic_get_interrupt_id(unsigned int raw);
106eb68ea9bSJeenu Viswambharan 
107eb68ea9bSJeenu Viswambharan /*******************************************************************************
108dec5e0d1SDan Handley  * Optional common functions (may be overridden)
109dec5e0d1SDan Handley  ******************************************************************************/
1104c0d0390SSoby Mathew uintptr_t plat_get_my_stack(void);
1111a0a3f06SYatharth Kochar void plat_report_exception(unsigned int exception_type);
11244804252SSandrine Bailleux int plat_crash_console_init(void);
113c67b09bdSSoby Mathew int plat_crash_console_putc(int c);
114801cf93cSAntonio Nino Diaz int plat_crash_console_flush(void);
11540fc6cd1SJuan Castillo void plat_error_handler(int err) __dead2;
1161c3ea103SAntonio Nino Diaz void plat_panic_handler(void) __dead2;
1177f56e9a3SSoby Mathew const char *plat_log_get_prefix(unsigned int log_level);
11801f62b6dSRoberto Vargas void bl2_plat_preload_setup(void);
11901f62b6dSRoberto Vargas int plat_try_next_boot_source(void);
120dec5e0d1SDan Handley 
121dec5e0d1SDan Handley /*******************************************************************************
122dec5e0d1SDan Handley  * Mandatory BL1 functions
123dec5e0d1SDan Handley  ******************************************************************************/
1245a06bb7eSDan Handley void bl1_early_platform_setup(void);
125dec5e0d1SDan Handley void bl1_plat_arch_setup(void);
126dec5e0d1SDan Handley void bl1_platform_setup(void);
127dec5e0d1SDan Handley struct meminfo *bl1_plat_sec_mem_layout(void);
1285f0cdb05SDan Handley 
129b7cb133eSJeenu Viswambharan /*******************************************************************************
130b7cb133eSJeenu Viswambharan  * Optional EL3 component functions in BL31
131b7cb133eSJeenu Viswambharan  ******************************************************************************/
132b7cb133eSJeenu Viswambharan 
133b7cb133eSJeenu Viswambharan /* SDEI platform functions */
134b7cb133eSJeenu Viswambharan #if SDEI_SUPPORT
135*cbf9e84aSBalint Dobszay void plat_sdei_setup(void);
136b7cb133eSJeenu Viswambharan int plat_sdei_validate_entry_point(uintptr_t ep, unsigned int client_mode);
137b7cb133eSJeenu Viswambharan void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr);
138b7cb133eSJeenu Viswambharan #endif
139b7cb133eSJeenu Viswambharan 
14076454abfSJeenu Viswambharan void plat_ea_handler(unsigned int ea_reason, uint64_t syndrome, void *cookie,
14176454abfSJeenu Viswambharan 		void *handle, uint64_t flags);
14276454abfSJeenu Viswambharan 
14348bfb88eSYatharth Kochar /*
14448bfb88eSYatharth Kochar  * The following function is mandatory when the
14548bfb88eSYatharth Kochar  * firmware update feature is used.
14648bfb88eSYatharth Kochar  */
14748bfb88eSYatharth Kochar int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
14848bfb88eSYatharth Kochar 		unsigned int flags);
14948bfb88eSYatharth Kochar 
150dec5e0d1SDan Handley /*******************************************************************************
151dec5e0d1SDan Handley  * Optional BL1 functions (may be overridden)
152dec5e0d1SDan Handley  ******************************************************************************/
1537baff11fSYatharth Kochar /*
1547baff11fSYatharth Kochar  * The following functions are used for image loading process in BL1.
1557baff11fSYatharth Kochar  */
1567baff11fSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id,
1577baff11fSYatharth Kochar 		struct entry_point_info *ep_info);
15848bfb88eSYatharth Kochar /*
15948bfb88eSYatharth Kochar  * The following functions are mandatory when firmware update
16048bfb88eSYatharth Kochar  * feature is used and optional otherwise.
16148bfb88eSYatharth Kochar  */
1627baff11fSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void);
1637baff11fSYatharth Kochar struct image_desc *bl1_plat_get_image_desc(unsigned int image_id);
164dec5e0d1SDan Handley 
16548bfb88eSYatharth Kochar /*
16648bfb88eSYatharth Kochar  * The following functions are used by firmware update
16748bfb88eSYatharth Kochar  * feature and may optionally be overridden.
16848bfb88eSYatharth Kochar  */
1691f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved);
17048bfb88eSYatharth Kochar 
17111f001cbSMasahiro Yamada /*
172566034fcSSoby Mathew  * This BL1 function can be used by the platforms to update/use image
173566034fcSSoby Mathew  * information for a given `image_id`.
17411f001cbSMasahiro Yamada  */
175566034fcSSoby Mathew int bl1_plat_handle_pre_image_load(unsigned int image_id);
176566034fcSSoby Mathew int bl1_plat_handle_post_image_load(unsigned int image_id);
17748bfb88eSYatharth Kochar 
178dec5e0d1SDan Handley /*******************************************************************************
179dec5e0d1SDan Handley  * Mandatory BL2 functions
180dec5e0d1SDan Handley  ******************************************************************************/
181a6f340feSSoby Mathew void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1, u_register_t arg2, u_register_t arg3);
182dec5e0d1SDan Handley void bl2_plat_arch_setup(void);
183dec5e0d1SDan Handley void bl2_platform_setup(void);
184dec5e0d1SDan Handley struct meminfo *bl2_plat_sec_mem_layout(void);
185dec5e0d1SDan Handley 
18672600226SYatharth Kochar /*
18772600226SYatharth Kochar  * This function can be used by the platforms to update/use image
18872600226SYatharth Kochar  * information for given `image_id`.
18972600226SYatharth Kochar  */
190ba68ef55SMasahiro Yamada int bl2_plat_handle_pre_image_load(unsigned int image_id);
19172600226SYatharth Kochar int bl2_plat_handle_post_image_load(unsigned int image_id);
19272600226SYatharth Kochar 
19372600226SYatharth Kochar 
19493d81d64SSandrine Bailleux /*******************************************************************************
195dec5e0d1SDan Handley  * Optional BL2 functions (may be overridden)
196dec5e0d1SDan Handley  ******************************************************************************/
197dec5e0d1SDan Handley 
198b1d27b48SRoberto Vargas 
199b1d27b48SRoberto Vargas /*******************************************************************************
200b1d27b48SRoberto Vargas  * Mandatory BL2 at EL3 functions: Must be implemented if BL2_AT_EL3 image is
201b1d27b48SRoberto Vargas  * supported
202b1d27b48SRoberto Vargas  ******************************************************************************/
203b1d27b48SRoberto Vargas void bl2_el3_early_platform_setup(u_register_t arg0, u_register_t arg1,
204b1d27b48SRoberto Vargas 				  u_register_t arg2, u_register_t arg3);
205b1d27b48SRoberto Vargas void bl2_el3_plat_arch_setup(void);
206b1d27b48SRoberto Vargas 
207b1d27b48SRoberto Vargas 
208b1d27b48SRoberto Vargas /*******************************************************************************
209b1d27b48SRoberto Vargas  * Optional BL2 at EL3 functions (may be overridden)
210b1d27b48SRoberto Vargas  ******************************************************************************/
211b1d27b48SRoberto Vargas void bl2_el3_plat_prepare_exit(void);
212b1d27b48SRoberto Vargas 
213dec5e0d1SDan Handley /*******************************************************************************
2149003fa0bSYatharth Kochar  * Mandatory BL2U functions.
2159003fa0bSYatharth Kochar  ******************************************************************************/
2169003fa0bSYatharth Kochar void bl2u_early_platform_setup(struct meminfo *mem_layout,
2179003fa0bSYatharth Kochar 		void *plat_info);
2189003fa0bSYatharth Kochar void bl2u_plat_arch_setup(void);
2199003fa0bSYatharth Kochar void bl2u_platform_setup(void);
2209003fa0bSYatharth Kochar 
2219003fa0bSYatharth Kochar /*******************************************************************************
2229003fa0bSYatharth Kochar  * Conditionally mandatory BL2U functions for CSS platforms.
2239003fa0bSYatharth Kochar  ******************************************************************************/
2249003fa0bSYatharth Kochar /*
2259003fa0bSYatharth Kochar  * This function is used to perform any platform-specific actions required to
2269003fa0bSYatharth Kochar  * handle the BL2U_SCP firmware.
2279003fa0bSYatharth Kochar  */
2289003fa0bSYatharth Kochar int bl2u_plat_handle_scp_bl2u(void);
2299003fa0bSYatharth Kochar 
2309003fa0bSYatharth Kochar /*******************************************************************************
231d178637dSJuan Castillo  * Mandatory BL31 functions
232dec5e0d1SDan Handley  ******************************************************************************/
233a6f340feSSoby Mathew void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
234a6f340feSSoby Mathew 		u_register_t arg2, u_register_t arg3);
235dec5e0d1SDan Handley void bl31_plat_arch_setup(void);
236dec5e0d1SDan Handley void bl31_platform_setup(void);
23778e61613SSoby Mathew void bl31_plat_runtime_setup(void);
2389865ac15SDan Handley struct entry_point_info *bl31_plat_get_next_image_ep_info(uint32_t type);
239dec5e0d1SDan Handley 
240dec5e0d1SDan Handley /*******************************************************************************
241d178637dSJuan Castillo  * Mandatory PSCI functions (BL31)
242dec5e0d1SDan Handley  ******************************************************************************/
24367487846SSoby Mathew int plat_setup_psci_ops(uintptr_t sec_entrypoint,
2449fb8af33SRoberto Vargas 			const struct plat_psci_ops **psci_ops);
24567487846SSoby Mathew const unsigned char *plat_get_power_domain_tree_desc(void);
24667487846SSoby Mathew 
24767487846SSoby Mathew /*******************************************************************************
248d178637dSJuan Castillo  * Optional PSCI functions (BL31).
24967487846SSoby Mathew  ******************************************************************************/
25004c1db1eSdp-arm void plat_psci_stat_accounting_start(const psci_power_state_t *state_info);
25104c1db1eSdp-arm void plat_psci_stat_accounting_stop(const psci_power_state_t *state_info);
25204c1db1eSdp-arm u_register_t plat_psci_stat_get_residency(unsigned int lvl,
25304c1db1eSdp-arm 			const psci_power_state_t *state_info,
2545b33ad17SDeepika Bhavnani 			unsigned int last_cpu_idx);
25567487846SSoby Mathew plat_local_state_t plat_get_target_pwr_state(unsigned int lvl,
25667487846SSoby Mathew 			const plat_local_state_t *states,
25767487846SSoby Mathew 			unsigned int ncpu);
258dec5e0d1SDan Handley 
259dec5e0d1SDan Handley /*******************************************************************************
260d178637dSJuan Castillo  * Optional BL31 functions (may be overridden)
261dff8e47aSDan Handley  ******************************************************************************/
262afff8cbdSAchin Gupta void bl31_plat_enable_mmu(uint32_t flags);
263dff8e47aSDan Handley 
264dff8e47aSDan Handley /*******************************************************************************
265d178637dSJuan Castillo  * Optional BL32 functions (may be overridden)
266dff8e47aSDan Handley  ******************************************************************************/
267afff8cbdSAchin Gupta void bl32_plat_enable_mmu(uint32_t flags);
268dff8e47aSDan Handley 
2696eadf762SJuan Castillo /*******************************************************************************
27095cfd4adSJuan Castillo  * Trusted Board Boot functions
2716eadf762SJuan Castillo  ******************************************************************************/
27295cfd4adSJuan Castillo int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len,
27395cfd4adSJuan Castillo 			unsigned int *flags);
27448279d52SJuan Castillo int plat_get_nv_ctr(void *cookie, unsigned int *nv_ctr);
27548279d52SJuan Castillo int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr);
276d35dee23Sdp-arm int plat_set_nv_ctr2(void *cookie, const struct auth_img_desc_s *img_desc,
277d35dee23Sdp-arm 		unsigned int nv_ctr);
2782374ab17SAmbroise Vincent int get_mbedtls_heap_helper(void **heap_addr, size_t *heap_size);
2792be57b86SSumit Garg int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
2802be57b86SSumit Garg 			  size_t *key_len, unsigned int *flags,
2812be57b86SSumit Garg 			  const uint8_t *img_id, size_t img_id_len);
2826eadf762SJuan Castillo 
2832fccb228SAntonio Nino Diaz /*******************************************************************************
2842fccb228SAntonio Nino Diaz  * Secure Partitions functions
2852fccb228SAntonio Nino Diaz  ******************************************************************************/
2862fccb228SAntonio Nino Diaz const struct mmap_region *plat_get_secure_partition_mmap(void *cookie);
287aeaa225cSPaul Beesley const struct spm_mm_boot_info *plat_get_secure_partition_boot_info(
2882fccb228SAntonio Nino Diaz 		void *cookie);
289e458302bSAntonio Nino Diaz int plat_spm_sp_rd_load(struct sp_res_desc *rd, const void *ptr, size_t size);
290680389a6SAntonio Nino Diaz int plat_spm_sp_get_next_address(void **sp_base, size_t *sp_size,
291680389a6SAntonio Nino Diaz 				 void **rd_base, size_t *rd_size);
2920cb64d01SAchin Gupta #if defined(SPD_spmd)
29352696946SOlivier Deprez int plat_spm_core_manifest_load(spmc_manifest_attribute_t *manifest,
29423d5ba86SOlivier Deprez 				const void *pm_addr);
2950cb64d01SAchin Gupta #endif
29672600226SYatharth Kochar /*******************************************************************************
29772600226SYatharth Kochar  * Mandatory BL image load functions(may be overridden).
29872600226SYatharth Kochar  ******************************************************************************/
29972600226SYatharth Kochar /*
30072600226SYatharth Kochar  * This function returns pointer to the list of images that the
30172600226SYatharth Kochar  * platform has populated to load.
30272600226SYatharth Kochar  */
30372600226SYatharth Kochar struct bl_load_info *plat_get_bl_image_load_info(void);
30472600226SYatharth Kochar 
30572600226SYatharth Kochar /*
30672600226SYatharth Kochar  * This function returns a pointer to the shared memory that the
30772600226SYatharth Kochar  * platform has kept aside to pass trusted firmware related
30872600226SYatharth Kochar  * information that next BL image could need.
30972600226SYatharth Kochar  */
31072600226SYatharth Kochar struct bl_params *plat_get_next_bl_params(void);
31172600226SYatharth Kochar 
31272600226SYatharth Kochar /*
31372600226SYatharth Kochar  * This function flushes to main memory all the params that are
31472600226SYatharth Kochar  * passed to next image.
31572600226SYatharth Kochar  */
31672600226SYatharth Kochar void plat_flush_next_bl_params(void);
31772600226SYatharth Kochar 
3185c8babcdSSoby Mathew /*
3195c8babcdSSoby Mathew  * The below function enable Trusted Firmware components like SPDs which
3205c8babcdSSoby Mathew  * haven't migrated to the new platform API to compile on platforms which
3215c8babcdSSoby Mathew  * have the compatibility layer disabled.
3225c8babcdSSoby Mathew  */
3237fabe1a8SRoberto Vargas unsigned int platform_core_pos_helper(unsigned long mpidr);
32451faada7SDouglas Raillard 
3250e753437SManish V Badarkhe /*
3260e753437SManish V Badarkhe  * Optional function to get SOC version
3270e753437SManish V Badarkhe  */
3280e753437SManish V Badarkhe int32_t plat_get_soc_version(void);
3290e753437SManish V Badarkhe 
3300e753437SManish V Badarkhe /*
3310e753437SManish V Badarkhe  * Optional function to get SOC revision
3320e753437SManish V Badarkhe  */
3330e753437SManish V Badarkhe int32_t plat_get_soc_revision(void);
3340e753437SManish V Badarkhe 
3352bc3dba9SAntonio Nino Diaz #endif /* PLATFORM_H */
336