xref: /rk3399_ARM-atf/include/plat/arm/common/plat_arm.h (revision 4da6f6cde3c72bd9786fc20141848c770c84f784)
1b4315306SDan Handley /*
20c306cc0SSoby Mathew  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5b4315306SDan Handley  */
6b4315306SDan Handley #ifndef __PLAT_ARM_H__
7b4315306SDan Handley #define __PLAT_ARM_H__
8b4315306SDan Handley 
93b211ff5SAntonio Nino Diaz #include <arm_xlat_tables.h>
10b4315306SDan Handley #include <bakery_lock.h>
11b4315306SDan Handley #include <cassert.h>
12b4315306SDan Handley #include <cpu_data.h>
13b4315306SDan Handley #include <stdint.h>
1423411d2cSSummer Qin #include <tzc_common.h>
1553d9c9c8SScott Branden #include <utils_def.h>
16b4315306SDan Handley 
17afc931f5SSandrine Bailleux /*******************************************************************************
18afc931f5SSandrine Bailleux  * Forward declarations
19afc931f5SSandrine Bailleux  ******************************************************************************/
20afc931f5SSandrine Bailleux struct bl31_params;
21afc931f5SSandrine Bailleux struct meminfo;
22a8aa7fecSYatharth Kochar struct image_info;
23cab0b5b0SSoby Mathew struct bl_params;
24afc931f5SSandrine Bailleux 
2523411d2cSSummer Qin typedef struct arm_tzc_regions_info {
2623411d2cSSummer Qin 	unsigned long long base;
2723411d2cSSummer Qin 	unsigned long long end;
2823411d2cSSummer Qin 	tzc_region_attributes_t sec_attr;
2923411d2cSSummer Qin 	unsigned int nsaid_permissions;
3023411d2cSSummer Qin } arm_tzc_regions_info_t;
3123411d2cSSummer Qin 
3223411d2cSSummer Qin /*******************************************************************************
3323411d2cSSummer Qin  * Default mapping definition of the TrustZone Controller for ARM standard
3423411d2cSSummer Qin  * platforms.
3523411d2cSSummer Qin  * Configure:
3623411d2cSSummer Qin  *   - Region 0 with no access;
3723411d2cSSummer Qin  *   - Region 1 with secure access only;
3823411d2cSSummer Qin  *   - the remaining DRAM regions access from the given Non-Secure masters.
3923411d2cSSummer Qin  ******************************************************************************/
4023411d2cSSummer Qin #if ENABLE_SPM
4123411d2cSSummer Qin #define ARM_TZC_REGIONS_DEF						\
4223411d2cSSummer Qin 	{ARM_AP_TZC_DRAM1_BASE, ARM_EL3_TZC_DRAM1_END,			\
4323411d2cSSummer Qin 		TZC_REGION_S_RDWR, 0},					\
4423411d2cSSummer Qin 	{ARM_NS_DRAM1_BASE, ARM_NS_DRAM1_END, ARM_TZC_NS_DRAM_S_ACCESS, \
4523411d2cSSummer Qin 		PLAT_ARM_TZC_NS_DEV_ACCESS}, 				\
4623411d2cSSummer Qin 	{ARM_DRAM2_BASE, ARM_DRAM2_END, ARM_TZC_NS_DRAM_S_ACCESS,	\
4723411d2cSSummer Qin 		PLAT_ARM_TZC_NS_DEV_ACCESS},				\
4823411d2cSSummer Qin 	{ARM_SP_IMAGE_NS_BUF_BASE, (ARM_SP_IMAGE_NS_BUF_BASE +		\
4923411d2cSSummer Qin 		ARM_SP_IMAGE_NS_BUF_SIZE) - 1, TZC_REGION_S_NONE,	\
5023411d2cSSummer Qin 		PLAT_ARM_TZC_NS_DEV_ACCESS}
5123411d2cSSummer Qin 
5223411d2cSSummer Qin #else
5323411d2cSSummer Qin #define ARM_TZC_REGIONS_DEF						\
5423411d2cSSummer Qin 	{ARM_AP_TZC_DRAM1_BASE, ARM_EL3_TZC_DRAM1_END,			\
5523411d2cSSummer Qin 		TZC_REGION_S_RDWR, 0},					\
5623411d2cSSummer Qin 	{ARM_NS_DRAM1_BASE, ARM_NS_DRAM1_END, ARM_TZC_NS_DRAM_S_ACCESS, \
5723411d2cSSummer Qin 		PLAT_ARM_TZC_NS_DEV_ACCESS},	 			\
5823411d2cSSummer Qin 	{ARM_DRAM2_BASE, ARM_DRAM2_END, ARM_TZC_NS_DRAM_S_ACCESS,	\
5923411d2cSSummer Qin 		PLAT_ARM_TZC_NS_DEV_ACCESS}
6023411d2cSSummer Qin #endif
6123411d2cSSummer Qin 
62b4315306SDan Handley #define ARM_CASSERT_MMAP						  \
63053b4f92SChris Kay 	CASSERT((ARRAY_SIZE(plat_arm_mmap) - 1) <= PLAT_ARM_MMAP_ENTRIES, \
64053b4f92SChris Kay 		assert_plat_arm_mmap_mismatch);				  \
65053b4f92SChris Kay 	CASSERT((PLAT_ARM_MMAP_ENTRIES + ARM_BL_REGIONS)		  \
66b4315306SDan Handley 		<= MAX_MMAP_REGIONS,					  \
67b4315306SDan Handley 		assert_max_mmap_regions);
68b4315306SDan Handley 
69b4315306SDan Handley /*
70b4315306SDan Handley  * Utility functions common to ARM standard platforms
71b4315306SDan Handley  */
72d323af9eSDaniel Boulby void arm_setup_page_tables(const mmap_region_t bl_regions[],
73d323af9eSDaniel Boulby 			   const mmap_region_t plat_regions[]);
74b4315306SDan Handley 
751eb735d7SRoberto Vargas void arm_setup_romlib(void);
761eb735d7SRoberto Vargas 
77e40e075fSSoby Mathew #if defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32))
78b4315306SDan Handley /*
79b4315306SDan Handley  * Use this macro to instantiate lock before it is used in below
80b4315306SDan Handley  * arm_lock_xxx() macros
81b4315306SDan Handley  */
821931d1d7SSandrine Bailleux #define ARM_INSTANTIATE_LOCK	static DEFINE_BAKERY_LOCK(arm_lock)
83c04a3b6cSSoby Mathew #define ARM_LOCK_GET_INSTANCE	(&arm_lock)
84b4315306SDan Handley /*
85b4315306SDan Handley  * These are wrapper macros to the Coherent Memory Bakery Lock API.
86b4315306SDan Handley  */
87b4315306SDan Handley #define arm_lock_init()		bakery_lock_init(&arm_lock)
88b4315306SDan Handley #define arm_lock_get()		bakery_lock_get(&arm_lock)
89b4315306SDan Handley #define arm_lock_release()	bakery_lock_release(&arm_lock)
90b4315306SDan Handley 
91b4315306SDan Handley #else
92b4315306SDan Handley 
93b4315306SDan Handley /*
946f249345SYatharth Kochar  * Empty macros for all other BL stages other than BL31 and BL32
95b4315306SDan Handley  */
9619583169SJeenu Viswambharan #define ARM_INSTANTIATE_LOCK	static int arm_lock __unused
97c04a3b6cSSoby Mathew #define ARM_LOCK_GET_INSTANCE	0
98b4315306SDan Handley #define arm_lock_init()
99b4315306SDan Handley #define arm_lock_get()
100b4315306SDan Handley #define arm_lock_release()
101b4315306SDan Handley 
102e40e075fSSoby Mathew #endif /* defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32)) */
103b4315306SDan Handley 
1042204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC
1052204afdeSSoby Mathew /*
1062204afdeSSoby Mathew  * Macros used to parse state information from State-ID if it is using the
1072204afdeSSoby Mathew  * recommended encoding for State-ID.
1082204afdeSSoby Mathew  */
1092204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_WIDTH		4
1102204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_MASK		((1 << ARM_LOCAL_PSTATE_WIDTH) - 1)
1112204afdeSSoby Mathew 
1122204afdeSSoby Mathew /* Macros to construct the composite power state */
1132204afdeSSoby Mathew 
1142204afdeSSoby Mathew /* Make composite power state parameter till power level 0 */
1152204afdeSSoby Mathew #if PSCI_EXTENDED_STATE_ID
1162204afdeSSoby Mathew 
1172204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
1182204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT))
1192204afdeSSoby Mathew #else
1202204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
1212204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | \
1222204afdeSSoby Mathew 		((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \
1232204afdeSSoby Mathew 		((type) << PSTATE_TYPE_SHIFT))
1242204afdeSSoby Mathew #endif /* __PSCI_EXTENDED_STATE_ID__ */
1252204afdeSSoby Mathew 
1262204afdeSSoby Mathew /* Make composite power state parameter till power level 1 */
1272204afdeSSoby Mathew #define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \
1282204afdeSSoby Mathew 		(((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \
1292204afdeSSoby Mathew 		arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type))
1302204afdeSSoby Mathew 
1315f3a6030SSoby Mathew /* Make composite power state parameter till power level 2 */
1325f3a6030SSoby Mathew #define arm_make_pwrstate_lvl2(lvl2_state, lvl1_state, lvl0_state, pwr_lvl, type) \
1335f3a6030SSoby Mathew 		(((lvl2_state) << (ARM_LOCAL_PSTATE_WIDTH * 2)) | \
1345f3a6030SSoby Mathew 		arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type))
1355f3a6030SSoby Mathew 
1362204afdeSSoby Mathew #endif /* __ARM_RECOM_STATE_ID_ENC__ */
1372204afdeSSoby Mathew 
138b10d4499SJeenu Viswambharan /* ARM State switch error codes */
139b10d4499SJeenu Viswambharan #define STATE_SW_E_PARAM		(-2)
140b10d4499SJeenu Viswambharan #define STATE_SW_E_DENIED		(-3)
141b4315306SDan Handley 
142b4315306SDan Handley /* IO storage utility functions */
143b4315306SDan Handley void arm_io_setup(void);
144b4315306SDan Handley 
145b4315306SDan Handley /* Security utility functions */
14623411d2cSSummer Qin void arm_tzc400_setup(const arm_tzc_regions_info_t *tzc_regions);
147618f0feeSVikram Kanigiri struct tzc_dmc500_driver_data;
14823411d2cSSummer Qin void arm_tzc_dmc500_setup(struct tzc_dmc500_driver_data *plat_driver_data,
14923411d2cSSummer Qin 			const arm_tzc_regions_info_t *tzc_regions);
150b4315306SDan Handley 
15188a0523eSAntonio Nino Diaz /* Console utility functions */
15288a0523eSAntonio Nino Diaz void arm_console_boot_init(void);
15388a0523eSAntonio Nino Diaz void arm_console_boot_end(void);
15488a0523eSAntonio Nino Diaz void arm_console_runtime_init(void);
15588a0523eSAntonio Nino Diaz void arm_console_runtime_end(void);
15688a0523eSAntonio Nino Diaz 
157c1bb8a05SSoby Mathew /* Systimer utility function */
158c1bb8a05SSoby Mathew void arm_configure_sys_timer(void);
159c1bb8a05SSoby Mathew 
160b4315306SDan Handley /* PM utility functions */
16138dce70fSSoby Mathew int arm_validate_power_state(unsigned int power_state,
16238dce70fSSoby Mathew 			    psci_power_state_t *req_state);
16371e7a4e5SJeenu Viswambharan int arm_validate_psci_entrypoint(uintptr_t entrypoint);
164f9e858b1SSoby Mathew int arm_validate_ns_entrypoint(uintptr_t entrypoint);
165e35a3fb5SSoby Mathew void arm_system_pwr_domain_save(void);
166c1bb8a05SSoby Mathew void arm_system_pwr_domain_resume(void);
167dc6aad2eSRoberto Vargas int arm_psci_read_mem_protect(int *enabled);
168f145403cSRoberto Vargas int arm_nor_psci_write_mem_protect(int val);
169638b034cSRoberto Vargas void arm_nor_psci_do_static_mem_protect(void);
170638b034cSRoberto Vargas void arm_nor_psci_do_dyn_mem_protect(void);
171f145403cSRoberto Vargas int arm_psci_mem_protect_chk(uintptr_t base, u_register_t length);
17238dce70fSSoby Mathew 
17338dce70fSSoby Mathew /* Topology utility function */
17438dce70fSSoby Mathew int arm_check_mpidr(u_register_t mpidr);
175b4315306SDan Handley 
176b4315306SDan Handley /* BL1 utility functions */
177b4315306SDan Handley void arm_bl1_early_platform_setup(void);
178b4315306SDan Handley void arm_bl1_platform_setup(void);
179b4315306SDan Handley void arm_bl1_plat_arch_setup(void);
180b4315306SDan Handley 
181b4315306SDan Handley /* BL2 utility functions */
182cab0b5b0SSoby Mathew void arm_bl2_early_platform_setup(uintptr_t tb_fw_config, struct meminfo *mem_layout);
183b4315306SDan Handley void arm_bl2_platform_setup(void);
184b4315306SDan Handley void arm_bl2_plat_arch_setup(void);
185b4315306SDan Handley uint32_t arm_get_spsr_for_bl32_entry(void);
186b4315306SDan Handley uint32_t arm_get_spsr_for_bl33_entry(void);
18707570d59SYatharth Kochar int arm_bl2_handle_post_image_load(unsigned int image_id);
188b4315306SDan Handley 
18981528dbcSRoberto Vargas /* BL2 at EL3 functions */
19081528dbcSRoberto Vargas void arm_bl2_el3_early_platform_setup(void);
19181528dbcSRoberto Vargas void arm_bl2_el3_plat_arch_setup(void);
19281528dbcSRoberto Vargas 
193dcda29f6SYatharth Kochar /* BL2U utility functions */
194dcda29f6SYatharth Kochar void arm_bl2u_early_platform_setup(struct meminfo *mem_layout,
195dcda29f6SYatharth Kochar 				void *plat_info);
196dcda29f6SYatharth Kochar void arm_bl2u_platform_setup(void);
197dcda29f6SYatharth Kochar void arm_bl2u_plat_arch_setup(void);
198dcda29f6SYatharth Kochar 
199d178637dSJuan Castillo /* BL31 utility functions */
200a8aa7fecSYatharth Kochar #if LOAD_IMAGE_V2
2010c306cc0SSoby Mathew void arm_bl31_early_platform_setup(void *from_bl2, uintptr_t soc_fw_config,
2020c306cc0SSoby Mathew 				uintptr_t hw_config, void *plat_params_from_bl2);
203a8aa7fecSYatharth Kochar #else
2040c306cc0SSoby Mathew void arm_bl31_early_platform_setup(struct bl31_params *from_bl2, uintptr_t soc_fw_config,
2050c306cc0SSoby Mathew 				uintptr_t hw_config, void *plat_params_from_bl2);
206a8aa7fecSYatharth Kochar #endif /* LOAD_IMAGE_V2 */
207b4315306SDan Handley void arm_bl31_platform_setup(void);
208080225daSSoby Mathew void arm_bl31_plat_runtime_setup(void);
209b4315306SDan Handley void arm_bl31_plat_arch_setup(void);
210b4315306SDan Handley 
211b4315306SDan Handley /* TSP utility functions */
212b4315306SDan Handley void arm_tsp_early_platform_setup(void);
213b4315306SDan Handley 
214181bbd41SSoby Mathew /* SP_MIN utility functions */
2150c306cc0SSoby Mathew void arm_sp_min_early_platform_setup(void *from_bl2, uintptr_t tos_fw_config,
2160c306cc0SSoby Mathew 				uintptr_t hw_config, void *plat_params_from_bl2);
21721568304SDimitris Papastamos void arm_sp_min_plat_runtime_setup(void);
218181bbd41SSoby Mathew 
219436223deSYatharth Kochar /* FIP TOC validity check */
220436223deSYatharth Kochar int arm_io_is_toc_valid(void);
221b4315306SDan Handley 
222c228956aSSoby Mathew /* Utility functions for Dynamic Config */
223c228956aSSoby Mathew void arm_load_tb_fw_config(void);
224cab0b5b0SSoby Mathew void arm_bl2_set_tb_cfg_addr(void *dtb);
225cab0b5b0SSoby Mathew void arm_bl2_dyn_cfg_init(void);
226ba597da7SJohn Tsichritzis void arm_bl1_set_mbedtls_heap(void);
227ba597da7SJohn Tsichritzis int arm_get_mbedtls_heap(void **heap_addr, size_t *heap_size);
228c228956aSSoby Mathew 
229b4315306SDan Handley /*
230b4315306SDan Handley  * Mandatory functions required in ARM standard platforms
231b4315306SDan Handley  */
2320108047aSSoby Mathew unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr);
23327573c59SAchin Gupta void plat_arm_gic_driver_init(void);
234b4315306SDan Handley void plat_arm_gic_init(void);
23527573c59SAchin Gupta void plat_arm_gic_cpuif_enable(void);
23627573c59SAchin Gupta void plat_arm_gic_cpuif_disable(void);
237d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_on(void);
238d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_off(void);
23927573c59SAchin Gupta void plat_arm_gic_pcpu_init(void);
240e35a3fb5SSoby Mathew void plat_arm_gic_save(void);
241e35a3fb5SSoby Mathew void plat_arm_gic_resume(void);
242b4315306SDan Handley void plat_arm_security_setup(void);
243b4315306SDan Handley void plat_arm_pwrc_setup(void);
2446355f234SVikram Kanigiri void plat_arm_interconnect_init(void);
2456355f234SVikram Kanigiri void plat_arm_interconnect_enter_coherency(void);
2466355f234SVikram Kanigiri void plat_arm_interconnect_exit_coherency(void);
2472a246d2eSDimitris Papastamos void plat_arm_program_trusted_mailbox(uintptr_t address);
248*4da6f6cdSSathees Balya int plat_arm_bl1_fwu_needed(void);
249*4da6f6cdSSathees Balya void plat_arm_error_handler(int err);
250b4315306SDan Handley 
251d8d6cf24SSummer Qin #if ARM_PLAT_MT
252d8d6cf24SSummer Qin unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr);
253d8d6cf24SSummer Qin #endif
254d8d6cf24SSummer Qin 
255a8aa7fecSYatharth Kochar #if LOAD_IMAGE_V2
256a8aa7fecSYatharth Kochar /*
257a8aa7fecSYatharth Kochar  * This function is called after loading SCP_BL2 image and it is used to perform
258a8aa7fecSYatharth Kochar  * any platform-specific actions required to handle the SCP firmware.
259a8aa7fecSYatharth Kochar  */
260a8aa7fecSYatharth Kochar int plat_arm_bl2_handle_scp_bl2(struct image_info *scp_bl2_image_info);
261a8aa7fecSYatharth Kochar #endif
262a8aa7fecSYatharth Kochar 
263b4315306SDan Handley /*
264b4315306SDan Handley  * Optional functions required in ARM standard platforms
265b4315306SDan Handley  */
266b4315306SDan Handley void plat_arm_io_setup(void);
267b4315306SDan Handley int plat_arm_get_alt_image_source(
26816948ae1SJuan Castillo 	unsigned int image_id,
26916948ae1SJuan Castillo 	uintptr_t *dev_handle,
27016948ae1SJuan Castillo 	uintptr_t *image_spec);
27138dce70fSSoby Mathew unsigned int plat_arm_calc_core_pos(u_register_t mpidr);
27265cb1c4cSVikram Kanigiri const mmap_region_t *plat_arm_get_mmap(void);
273b4315306SDan Handley 
2745486a965SSoby Mathew /* Allow platform to override psci_pm_ops during runtime */
2755486a965SSoby Mathew const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops);
2765486a965SSoby Mathew 
277b10d4499SJeenu Viswambharan /* Execution state switch in ARM platforms */
278b10d4499SJeenu Viswambharan int arm_execution_state_switch(unsigned int smc_fid,
279b10d4499SJeenu Viswambharan 		uint32_t pc_hi,
280b10d4499SJeenu Viswambharan 		uint32_t pc_lo,
281b10d4499SJeenu Viswambharan 		uint32_t cookie_hi,
282b10d4499SJeenu Viswambharan 		uint32_t cookie_lo,
283b10d4499SJeenu Viswambharan 		void *handle);
284b10d4499SJeenu Viswambharan 
2850ed8c001SSoby Mathew /* Optional functions for SP_MIN */
2860ed8c001SSoby Mathew void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1,
2870ed8c001SSoby Mathew 			u_register_t arg2, u_register_t arg3);
2880ed8c001SSoby Mathew 
2891af540efSRoberto Vargas /* global variables */
2901af540efSRoberto Vargas extern plat_psci_ops_t plat_arm_psci_pm_ops;
2911af540efSRoberto Vargas extern const mmap_region_t plat_arm_mmap[];
292ecd62429SJeenu Viswambharan extern const unsigned int arm_pm_idle_states[];
2931af540efSRoberto Vargas 
294b4315306SDan Handley #endif /* __PLAT_ARM_H__ */
295