xref: /rk3399_ARM-atf/include/plat/arm/common/plat_arm.h (revision 32aee8415dac5ef71d53cacc28e25a8d312cc47b)
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>
14*32aee841SRoberto Vargas #include <spinlock.h>
1523411d2cSSummer Qin #include <tzc_common.h>
1653d9c9c8SScott Branden #include <utils_def.h>
17b4315306SDan Handley 
18afc931f5SSandrine Bailleux /*******************************************************************************
19afc931f5SSandrine Bailleux  * Forward declarations
20afc931f5SSandrine Bailleux  ******************************************************************************/
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)
84*32aee841SRoberto Vargas 
85*32aee841SRoberto Vargas #if !HW_ASSISTED_COHERENCY
86*32aee841SRoberto Vargas #define ARM_SCMI_INSTANTIATE_LOCK	DEFINE_BAKERY_LOCK(arm_scmi_lock)
87*32aee841SRoberto Vargas #else
88*32aee841SRoberto Vargas #define ARM_SCMI_INSTANTIATE_LOCK	spinlock_t arm_scmi_lock
89*32aee841SRoberto Vargas #endif
90*32aee841SRoberto Vargas #define ARM_SCMI_LOCK_GET_INSTANCE	(&arm_scmi_lock)
91*32aee841SRoberto Vargas 
92b4315306SDan Handley /*
93b4315306SDan Handley  * These are wrapper macros to the Coherent Memory Bakery Lock API.
94b4315306SDan Handley  */
95b4315306SDan Handley #define arm_lock_init()		bakery_lock_init(&arm_lock)
96b4315306SDan Handley #define arm_lock_get()		bakery_lock_get(&arm_lock)
97b4315306SDan Handley #define arm_lock_release()	bakery_lock_release(&arm_lock)
98b4315306SDan Handley 
99b4315306SDan Handley #else
100b4315306SDan Handley 
101b4315306SDan Handley /*
1026f249345SYatharth Kochar  * Empty macros for all other BL stages other than BL31 and BL32
103b4315306SDan Handley  */
10419583169SJeenu Viswambharan #define ARM_INSTANTIATE_LOCK	static int arm_lock __unused
105c04a3b6cSSoby Mathew #define ARM_LOCK_GET_INSTANCE	0
106b4315306SDan Handley #define arm_lock_init()
107b4315306SDan Handley #define arm_lock_get()
108b4315306SDan Handley #define arm_lock_release()
109b4315306SDan Handley 
110e40e075fSSoby Mathew #endif /* defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32)) */
111b4315306SDan Handley 
1122204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC
1132204afdeSSoby Mathew /*
1142204afdeSSoby Mathew  * Macros used to parse state information from State-ID if it is using the
1152204afdeSSoby Mathew  * recommended encoding for State-ID.
1162204afdeSSoby Mathew  */
1172204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_WIDTH		4
1182204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_MASK		((1 << ARM_LOCAL_PSTATE_WIDTH) - 1)
1192204afdeSSoby Mathew 
1202204afdeSSoby Mathew /* Macros to construct the composite power state */
1212204afdeSSoby Mathew 
1222204afdeSSoby Mathew /* Make composite power state parameter till power level 0 */
1232204afdeSSoby Mathew #if PSCI_EXTENDED_STATE_ID
1242204afdeSSoby Mathew 
1252204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
1262204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT))
1272204afdeSSoby Mathew #else
1282204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
1292204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | \
1302204afdeSSoby Mathew 		((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \
1312204afdeSSoby Mathew 		((type) << PSTATE_TYPE_SHIFT))
1322204afdeSSoby Mathew #endif /* __PSCI_EXTENDED_STATE_ID__ */
1332204afdeSSoby Mathew 
1342204afdeSSoby Mathew /* Make composite power state parameter till power level 1 */
1352204afdeSSoby Mathew #define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \
1362204afdeSSoby Mathew 		(((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \
1372204afdeSSoby Mathew 		arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type))
1382204afdeSSoby Mathew 
1395f3a6030SSoby Mathew /* Make composite power state parameter till power level 2 */
1405f3a6030SSoby Mathew #define arm_make_pwrstate_lvl2(lvl2_state, lvl1_state, lvl0_state, pwr_lvl, type) \
1415f3a6030SSoby Mathew 		(((lvl2_state) << (ARM_LOCAL_PSTATE_WIDTH * 2)) | \
1425f3a6030SSoby Mathew 		arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type))
1435f3a6030SSoby Mathew 
1442204afdeSSoby Mathew #endif /* __ARM_RECOM_STATE_ID_ENC__ */
1452204afdeSSoby Mathew 
146b10d4499SJeenu Viswambharan /* ARM State switch error codes */
147b10d4499SJeenu Viswambharan #define STATE_SW_E_PARAM		(-2)
148b10d4499SJeenu Viswambharan #define STATE_SW_E_DENIED		(-3)
149b4315306SDan Handley 
150b4315306SDan Handley /* IO storage utility functions */
151b4315306SDan Handley void arm_io_setup(void);
152b4315306SDan Handley 
153b4315306SDan Handley /* Security utility functions */
15423411d2cSSummer Qin void arm_tzc400_setup(const arm_tzc_regions_info_t *tzc_regions);
155618f0feeSVikram Kanigiri struct tzc_dmc500_driver_data;
15623411d2cSSummer Qin void arm_tzc_dmc500_setup(struct tzc_dmc500_driver_data *plat_driver_data,
15723411d2cSSummer Qin 			const arm_tzc_regions_info_t *tzc_regions);
158b4315306SDan Handley 
15988a0523eSAntonio Nino Diaz /* Console utility functions */
16088a0523eSAntonio Nino Diaz void arm_console_boot_init(void);
16188a0523eSAntonio Nino Diaz void arm_console_boot_end(void);
16288a0523eSAntonio Nino Diaz void arm_console_runtime_init(void);
16388a0523eSAntonio Nino Diaz void arm_console_runtime_end(void);
16488a0523eSAntonio Nino Diaz 
165c1bb8a05SSoby Mathew /* Systimer utility function */
166c1bb8a05SSoby Mathew void arm_configure_sys_timer(void);
167c1bb8a05SSoby Mathew 
168b4315306SDan Handley /* PM utility functions */
16938dce70fSSoby Mathew int arm_validate_power_state(unsigned int power_state,
17038dce70fSSoby Mathew 			    psci_power_state_t *req_state);
17171e7a4e5SJeenu Viswambharan int arm_validate_psci_entrypoint(uintptr_t entrypoint);
172f9e858b1SSoby Mathew int arm_validate_ns_entrypoint(uintptr_t entrypoint);
173e35a3fb5SSoby Mathew void arm_system_pwr_domain_save(void);
174c1bb8a05SSoby Mathew void arm_system_pwr_domain_resume(void);
175dc6aad2eSRoberto Vargas int arm_psci_read_mem_protect(int *enabled);
176f145403cSRoberto Vargas int arm_nor_psci_write_mem_protect(int val);
177638b034cSRoberto Vargas void arm_nor_psci_do_static_mem_protect(void);
178638b034cSRoberto Vargas void arm_nor_psci_do_dyn_mem_protect(void);
179f145403cSRoberto Vargas int arm_psci_mem_protect_chk(uintptr_t base, u_register_t length);
18038dce70fSSoby Mathew 
18138dce70fSSoby Mathew /* Topology utility function */
18238dce70fSSoby Mathew int arm_check_mpidr(u_register_t mpidr);
183b4315306SDan Handley 
184b4315306SDan Handley /* BL1 utility functions */
185b4315306SDan Handley void arm_bl1_early_platform_setup(void);
186b4315306SDan Handley void arm_bl1_platform_setup(void);
187b4315306SDan Handley void arm_bl1_plat_arch_setup(void);
188b4315306SDan Handley 
189b4315306SDan Handley /* BL2 utility functions */
190cab0b5b0SSoby Mathew void arm_bl2_early_platform_setup(uintptr_t tb_fw_config, struct meminfo *mem_layout);
191b4315306SDan Handley void arm_bl2_platform_setup(void);
192b4315306SDan Handley void arm_bl2_plat_arch_setup(void);
193b4315306SDan Handley uint32_t arm_get_spsr_for_bl32_entry(void);
194b4315306SDan Handley uint32_t arm_get_spsr_for_bl33_entry(void);
19507570d59SYatharth Kochar int arm_bl2_handle_post_image_load(unsigned int image_id);
196b4315306SDan Handley 
19781528dbcSRoberto Vargas /* BL2 at EL3 functions */
19881528dbcSRoberto Vargas void arm_bl2_el3_early_platform_setup(void);
19981528dbcSRoberto Vargas void arm_bl2_el3_plat_arch_setup(void);
20081528dbcSRoberto Vargas 
201dcda29f6SYatharth Kochar /* BL2U utility functions */
202dcda29f6SYatharth Kochar void arm_bl2u_early_platform_setup(struct meminfo *mem_layout,
203dcda29f6SYatharth Kochar 				void *plat_info);
204dcda29f6SYatharth Kochar void arm_bl2u_platform_setup(void);
205dcda29f6SYatharth Kochar void arm_bl2u_plat_arch_setup(void);
206dcda29f6SYatharth Kochar 
207d178637dSJuan Castillo /* BL31 utility functions */
2080c306cc0SSoby Mathew void arm_bl31_early_platform_setup(void *from_bl2, uintptr_t soc_fw_config,
2090c306cc0SSoby Mathew 				uintptr_t hw_config, void *plat_params_from_bl2);
210b4315306SDan Handley void arm_bl31_platform_setup(void);
211080225daSSoby Mathew void arm_bl31_plat_runtime_setup(void);
212b4315306SDan Handley void arm_bl31_plat_arch_setup(void);
213b4315306SDan Handley 
214b4315306SDan Handley /* TSP utility functions */
215b4315306SDan Handley void arm_tsp_early_platform_setup(void);
216b4315306SDan Handley 
217181bbd41SSoby Mathew /* SP_MIN utility functions */
2180c306cc0SSoby Mathew void arm_sp_min_early_platform_setup(void *from_bl2, uintptr_t tos_fw_config,
2190c306cc0SSoby Mathew 				uintptr_t hw_config, void *plat_params_from_bl2);
22021568304SDimitris Papastamos void arm_sp_min_plat_runtime_setup(void);
221181bbd41SSoby Mathew 
222436223deSYatharth Kochar /* FIP TOC validity check */
223436223deSYatharth Kochar int arm_io_is_toc_valid(void);
224b4315306SDan Handley 
225c228956aSSoby Mathew /* Utility functions for Dynamic Config */
226c228956aSSoby Mathew void arm_load_tb_fw_config(void);
227cab0b5b0SSoby Mathew void arm_bl2_set_tb_cfg_addr(void *dtb);
228cab0b5b0SSoby Mathew void arm_bl2_dyn_cfg_init(void);
229ba597da7SJohn Tsichritzis void arm_bl1_set_mbedtls_heap(void);
230ba597da7SJohn Tsichritzis int arm_get_mbedtls_heap(void **heap_addr, size_t *heap_size);
231c228956aSSoby Mathew 
232b4315306SDan Handley /*
233cb4adb0dSDaniel Boulby  * Free the memory storing initialization code only used during an images boot
234cb4adb0dSDaniel Boulby  * time so it can be reclaimed for runtime data
235cb4adb0dSDaniel Boulby  */
236cb4adb0dSDaniel Boulby void arm_free_init_memory(void);
237cb4adb0dSDaniel Boulby 
238cb4adb0dSDaniel Boulby /*
239b4315306SDan Handley  * Mandatory functions required in ARM standard platforms
240b4315306SDan Handley  */
2410108047aSSoby Mathew unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr);
24227573c59SAchin Gupta void plat_arm_gic_driver_init(void);
243b4315306SDan Handley void plat_arm_gic_init(void);
24427573c59SAchin Gupta void plat_arm_gic_cpuif_enable(void);
24527573c59SAchin Gupta void plat_arm_gic_cpuif_disable(void);
246d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_on(void);
247d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_off(void);
24827573c59SAchin Gupta void plat_arm_gic_pcpu_init(void);
249e35a3fb5SSoby Mathew void plat_arm_gic_save(void);
250e35a3fb5SSoby Mathew void plat_arm_gic_resume(void);
251b4315306SDan Handley void plat_arm_security_setup(void);
252b4315306SDan Handley void plat_arm_pwrc_setup(void);
2536355f234SVikram Kanigiri void plat_arm_interconnect_init(void);
2546355f234SVikram Kanigiri void plat_arm_interconnect_enter_coherency(void);
2556355f234SVikram Kanigiri void plat_arm_interconnect_exit_coherency(void);
2562a246d2eSDimitris Papastamos void plat_arm_program_trusted_mailbox(uintptr_t address);
2574da6f6cdSSathees Balya int plat_arm_bl1_fwu_needed(void);
2584da6f6cdSSathees Balya void plat_arm_error_handler(int err);
259b4315306SDan Handley 
260d8d6cf24SSummer Qin #if ARM_PLAT_MT
261d8d6cf24SSummer Qin unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr);
262d8d6cf24SSummer Qin #endif
263d8d6cf24SSummer Qin 
264a8aa7fecSYatharth Kochar /*
265a8aa7fecSYatharth Kochar  * This function is called after loading SCP_BL2 image and it is used to perform
266a8aa7fecSYatharth Kochar  * any platform-specific actions required to handle the SCP firmware.
267a8aa7fecSYatharth Kochar  */
268a8aa7fecSYatharth Kochar int plat_arm_bl2_handle_scp_bl2(struct image_info *scp_bl2_image_info);
269a8aa7fecSYatharth Kochar 
270b4315306SDan Handley /*
271b4315306SDan Handley  * Optional functions required in ARM standard platforms
272b4315306SDan Handley  */
273b4315306SDan Handley void plat_arm_io_setup(void);
274b4315306SDan Handley int plat_arm_get_alt_image_source(
27516948ae1SJuan Castillo 	unsigned int image_id,
27616948ae1SJuan Castillo 	uintptr_t *dev_handle,
27716948ae1SJuan Castillo 	uintptr_t *image_spec);
27838dce70fSSoby Mathew unsigned int plat_arm_calc_core_pos(u_register_t mpidr);
27965cb1c4cSVikram Kanigiri const mmap_region_t *plat_arm_get_mmap(void);
280b4315306SDan Handley 
2815486a965SSoby Mathew /* Allow platform to override psci_pm_ops during runtime */
2825486a965SSoby Mathew const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops);
2835486a965SSoby Mathew 
284b10d4499SJeenu Viswambharan /* Execution state switch in ARM platforms */
285b10d4499SJeenu Viswambharan int arm_execution_state_switch(unsigned int smc_fid,
286b10d4499SJeenu Viswambharan 		uint32_t pc_hi,
287b10d4499SJeenu Viswambharan 		uint32_t pc_lo,
288b10d4499SJeenu Viswambharan 		uint32_t cookie_hi,
289b10d4499SJeenu Viswambharan 		uint32_t cookie_lo,
290b10d4499SJeenu Viswambharan 		void *handle);
291b10d4499SJeenu Viswambharan 
2920ed8c001SSoby Mathew /* Optional functions for SP_MIN */
2930ed8c001SSoby Mathew void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1,
2940ed8c001SSoby Mathew 			u_register_t arg2, u_register_t arg3);
2950ed8c001SSoby Mathew 
2961af540efSRoberto Vargas /* global variables */
2971af540efSRoberto Vargas extern plat_psci_ops_t plat_arm_psci_pm_ops;
2981af540efSRoberto Vargas extern const mmap_region_t plat_arm_mmap[];
299ecd62429SJeenu Viswambharan extern const unsigned int arm_pm_idle_states[];
3001af540efSRoberto Vargas 
301b4315306SDan Handley #endif /* __PLAT_ARM_H__ */
302