xref: /rk3399_ARM-atf/include/plat/arm/common/plat_arm.h (revision f145403c2a1a7064cb55670ac0674dc6586398ab)
1b4315306SDan Handley /*
2bf75a371SAntonio Nino Diaz  * Copyright (c) 2015-2017, 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>
1453d9c9c8SScott Branden #include <utils_def.h>
15b4315306SDan Handley 
16afc931f5SSandrine Bailleux /*******************************************************************************
17afc931f5SSandrine Bailleux  * Forward declarations
18afc931f5SSandrine Bailleux  ******************************************************************************/
19afc931f5SSandrine Bailleux struct bl31_params;
20afc931f5SSandrine Bailleux struct meminfo;
21a8aa7fecSYatharth Kochar struct image_info;
22afc931f5SSandrine Bailleux 
23b4315306SDan Handley #define ARM_CASSERT_MMAP						\
24b4315306SDan Handley 	CASSERT((ARRAY_SIZE(plat_arm_mmap) + ARM_BL_REGIONS)		\
25b4315306SDan Handley 		<= MAX_MMAP_REGIONS,					\
26b4315306SDan Handley 		assert_max_mmap_regions);
27b4315306SDan Handley 
28b4315306SDan Handley /*
29b4315306SDan Handley  * Utility functions common to ARM standard platforms
30b4315306SDan Handley  */
314c0d0390SSoby Mathew void arm_setup_page_tables(uintptr_t total_base,
324c0d0390SSoby Mathew 			size_t total_size,
334c0d0390SSoby Mathew 			uintptr_t code_start,
344c0d0390SSoby Mathew 			uintptr_t code_limit,
354c0d0390SSoby Mathew 			uintptr_t rodata_start,
364c0d0390SSoby Mathew 			uintptr_t rodata_limit
37b4315306SDan Handley #if USE_COHERENT_MEM
384c0d0390SSoby Mathew 			, uintptr_t coh_start,
394c0d0390SSoby Mathew 			uintptr_t coh_limit
40b4315306SDan Handley #endif
41b4315306SDan Handley );
42b4315306SDan Handley 
43e40e075fSSoby Mathew #if defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32))
44b4315306SDan Handley /*
45b4315306SDan Handley  * Use this macro to instantiate lock before it is used in below
46b4315306SDan Handley  * arm_lock_xxx() macros
47b4315306SDan Handley  */
4819583169SJeenu Viswambharan #define ARM_INSTANTIATE_LOCK	DEFINE_BAKERY_LOCK(arm_lock)
49c04a3b6cSSoby Mathew #define ARM_LOCK_GET_INSTANCE	(&arm_lock)
50b4315306SDan Handley /*
51b4315306SDan Handley  * These are wrapper macros to the Coherent Memory Bakery Lock API.
52b4315306SDan Handley  */
53b4315306SDan Handley #define arm_lock_init()		bakery_lock_init(&arm_lock)
54b4315306SDan Handley #define arm_lock_get()		bakery_lock_get(&arm_lock)
55b4315306SDan Handley #define arm_lock_release()	bakery_lock_release(&arm_lock)
56b4315306SDan Handley 
57b4315306SDan Handley #else
58b4315306SDan Handley 
59b4315306SDan Handley /*
606f249345SYatharth Kochar  * Empty macros for all other BL stages other than BL31 and BL32
61b4315306SDan Handley  */
6219583169SJeenu Viswambharan #define ARM_INSTANTIATE_LOCK	static int arm_lock __unused
63c04a3b6cSSoby Mathew #define ARM_LOCK_GET_INSTANCE	0
64b4315306SDan Handley #define arm_lock_init()
65b4315306SDan Handley #define arm_lock_get()
66b4315306SDan Handley #define arm_lock_release()
67b4315306SDan Handley 
68e40e075fSSoby Mathew #endif /* defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32)) */
69b4315306SDan Handley 
702204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC
712204afdeSSoby Mathew /*
722204afdeSSoby Mathew  * Macros used to parse state information from State-ID if it is using the
732204afdeSSoby Mathew  * recommended encoding for State-ID.
742204afdeSSoby Mathew  */
752204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_WIDTH		4
762204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_MASK		((1 << ARM_LOCAL_PSTATE_WIDTH) - 1)
772204afdeSSoby Mathew 
782204afdeSSoby Mathew /* Macros to construct the composite power state */
792204afdeSSoby Mathew 
802204afdeSSoby Mathew /* Make composite power state parameter till power level 0 */
812204afdeSSoby Mathew #if PSCI_EXTENDED_STATE_ID
822204afdeSSoby Mathew 
832204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
842204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT))
852204afdeSSoby Mathew #else
862204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
872204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | \
882204afdeSSoby Mathew 		((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \
892204afdeSSoby Mathew 		((type) << PSTATE_TYPE_SHIFT))
902204afdeSSoby Mathew #endif /* __PSCI_EXTENDED_STATE_ID__ */
912204afdeSSoby Mathew 
922204afdeSSoby Mathew /* Make composite power state parameter till power level 1 */
932204afdeSSoby Mathew #define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \
942204afdeSSoby Mathew 		(((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \
952204afdeSSoby Mathew 		arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type))
962204afdeSSoby Mathew 
975f3a6030SSoby Mathew /* Make composite power state parameter till power level 2 */
985f3a6030SSoby Mathew #define arm_make_pwrstate_lvl2(lvl2_state, lvl1_state, lvl0_state, pwr_lvl, type) \
995f3a6030SSoby Mathew 		(((lvl2_state) << (ARM_LOCAL_PSTATE_WIDTH * 2)) | \
1005f3a6030SSoby Mathew 		arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type))
1015f3a6030SSoby Mathew 
1022204afdeSSoby Mathew #endif /* __ARM_RECOM_STATE_ID_ENC__ */
1032204afdeSSoby Mathew 
104b10d4499SJeenu Viswambharan /* ARM State switch error codes */
105b10d4499SJeenu Viswambharan #define STATE_SW_E_PARAM		(-2)
106b10d4499SJeenu Viswambharan #define STATE_SW_E_DENIED		(-3)
107b4315306SDan Handley 
108b4315306SDan Handley /* IO storage utility functions */
109b4315306SDan Handley void arm_io_setup(void);
110b4315306SDan Handley 
111b4315306SDan Handley /* Security utility functions */
11257f78201SSoby Mathew void arm_tzc400_setup(void);
113618f0feeSVikram Kanigiri struct tzc_dmc500_driver_data;
114618f0feeSVikram Kanigiri void arm_tzc_dmc500_setup(struct tzc_dmc500_driver_data *plat_driver_data);
115b4315306SDan Handley 
116c1bb8a05SSoby Mathew /* Systimer utility function */
117c1bb8a05SSoby Mathew void arm_configure_sys_timer(void);
118c1bb8a05SSoby Mathew 
119b4315306SDan Handley /* PM utility functions */
12038dce70fSSoby Mathew int arm_validate_power_state(unsigned int power_state,
12138dce70fSSoby Mathew 			    psci_power_state_t *req_state);
122f9e858b1SSoby Mathew int arm_validate_ns_entrypoint(uintptr_t entrypoint);
123c1bb8a05SSoby Mathew void arm_system_pwr_domain_resume(void);
1244c117f6cSSandrine Bailleux void arm_program_trusted_mailbox(uintptr_t address);
125*f145403cSRoberto Vargas int arm_psci_read_mem_protect(int *val);
126*f145403cSRoberto Vargas int arm_nor_psci_write_mem_protect(int val);
127*f145403cSRoberto Vargas void arm_nor_psci_do_mem_protect(void);
128*f145403cSRoberto Vargas int arm_psci_mem_protect_chk(uintptr_t base, u_register_t length);
12938dce70fSSoby Mathew 
13038dce70fSSoby Mathew /* Topology utility function */
13138dce70fSSoby Mathew int arm_check_mpidr(u_register_t mpidr);
132b4315306SDan Handley 
133b4315306SDan Handley /* BL1 utility functions */
134b4315306SDan Handley void arm_bl1_early_platform_setup(void);
135b4315306SDan Handley void arm_bl1_platform_setup(void);
136b4315306SDan Handley void arm_bl1_plat_arch_setup(void);
137b4315306SDan Handley 
138b4315306SDan Handley /* BL2 utility functions */
139afc931f5SSandrine Bailleux void arm_bl2_early_platform_setup(struct meminfo *mem_layout);
140b4315306SDan Handley void arm_bl2_platform_setup(void);
141b4315306SDan Handley void arm_bl2_plat_arch_setup(void);
142b4315306SDan Handley uint32_t arm_get_spsr_for_bl32_entry(void);
143b4315306SDan Handley uint32_t arm_get_spsr_for_bl33_entry(void);
14407570d59SYatharth Kochar int arm_bl2_handle_post_image_load(unsigned int image_id);
145b4315306SDan Handley 
146dcda29f6SYatharth Kochar /* BL2U utility functions */
147dcda29f6SYatharth Kochar void arm_bl2u_early_platform_setup(struct meminfo *mem_layout,
148dcda29f6SYatharth Kochar 				void *plat_info);
149dcda29f6SYatharth Kochar void arm_bl2u_platform_setup(void);
150dcda29f6SYatharth Kochar void arm_bl2u_plat_arch_setup(void);
151dcda29f6SYatharth Kochar 
152d178637dSJuan Castillo /* BL31 utility functions */
153a8aa7fecSYatharth Kochar #if LOAD_IMAGE_V2
154a8aa7fecSYatharth Kochar void arm_bl31_early_platform_setup(void *from_bl2,
155a8aa7fecSYatharth Kochar 				void *plat_params_from_bl2);
156a8aa7fecSYatharth Kochar #else
157afc931f5SSandrine Bailleux void arm_bl31_early_platform_setup(struct bl31_params *from_bl2,
158b4315306SDan Handley 				void *plat_params_from_bl2);
159a8aa7fecSYatharth Kochar #endif /* LOAD_IMAGE_V2 */
160b4315306SDan Handley void arm_bl31_platform_setup(void);
161080225daSSoby Mathew void arm_bl31_plat_runtime_setup(void);
162b4315306SDan Handley void arm_bl31_plat_arch_setup(void);
163b4315306SDan Handley 
164b4315306SDan Handley /* TSP utility functions */
165b4315306SDan Handley void arm_tsp_early_platform_setup(void);
166b4315306SDan Handley 
167181bbd41SSoby Mathew /* SP_MIN utility functions */
168d9915518SYatharth Kochar void arm_sp_min_early_platform_setup(void *from_bl2,
169d9915518SYatharth Kochar 		void *plat_params_from_bl2);
17021568304SDimitris Papastamos void arm_sp_min_plat_runtime_setup(void);
171181bbd41SSoby Mathew 
172436223deSYatharth Kochar /* FIP TOC validity check */
173436223deSYatharth Kochar int arm_io_is_toc_valid(void);
174b4315306SDan Handley 
175b4315306SDan Handley /*
176b4315306SDan Handley  * Mandatory functions required in ARM standard platforms
177b4315306SDan Handley  */
1780108047aSSoby Mathew unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr);
17927573c59SAchin Gupta void plat_arm_gic_driver_init(void);
180b4315306SDan Handley void plat_arm_gic_init(void);
18127573c59SAchin Gupta void plat_arm_gic_cpuif_enable(void);
18227573c59SAchin Gupta void plat_arm_gic_cpuif_disable(void);
183d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_on(void);
184d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_off(void);
18527573c59SAchin Gupta void plat_arm_gic_pcpu_init(void);
186b4315306SDan Handley void plat_arm_security_setup(void);
187b4315306SDan Handley void plat_arm_pwrc_setup(void);
1886355f234SVikram Kanigiri void plat_arm_interconnect_init(void);
1896355f234SVikram Kanigiri void plat_arm_interconnect_enter_coherency(void);
1906355f234SVikram Kanigiri void plat_arm_interconnect_exit_coherency(void);
191b4315306SDan Handley 
192d8d6cf24SSummer Qin #if ARM_PLAT_MT
193d8d6cf24SSummer Qin unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr);
194d8d6cf24SSummer Qin #endif
195d8d6cf24SSummer Qin 
196a8aa7fecSYatharth Kochar #if LOAD_IMAGE_V2
197a8aa7fecSYatharth Kochar /*
198a8aa7fecSYatharth Kochar  * This function is called after loading SCP_BL2 image and it is used to perform
199a8aa7fecSYatharth Kochar  * any platform-specific actions required to handle the SCP firmware.
200a8aa7fecSYatharth Kochar  */
201a8aa7fecSYatharth Kochar int plat_arm_bl2_handle_scp_bl2(struct image_info *scp_bl2_image_info);
202a8aa7fecSYatharth Kochar #endif
203a8aa7fecSYatharth Kochar 
204b4315306SDan Handley /*
205b4315306SDan Handley  * Optional functions required in ARM standard platforms
206b4315306SDan Handley  */
207b4315306SDan Handley void plat_arm_io_setup(void);
208b4315306SDan Handley int plat_arm_get_alt_image_source(
20916948ae1SJuan Castillo 	unsigned int image_id,
21016948ae1SJuan Castillo 	uintptr_t *dev_handle,
21116948ae1SJuan Castillo 	uintptr_t *image_spec);
21238dce70fSSoby Mathew unsigned int plat_arm_calc_core_pos(u_register_t mpidr);
21365cb1c4cSVikram Kanigiri const mmap_region_t *plat_arm_get_mmap(void);
214b4315306SDan Handley 
2155486a965SSoby Mathew /* Allow platform to override psci_pm_ops during runtime */
2165486a965SSoby Mathew const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops);
2175486a965SSoby Mathew 
218b10d4499SJeenu Viswambharan /* Execution state switch in ARM platforms */
219b10d4499SJeenu Viswambharan int arm_execution_state_switch(unsigned int smc_fid,
220b10d4499SJeenu Viswambharan 		uint32_t pc_hi,
221b10d4499SJeenu Viswambharan 		uint32_t pc_lo,
222b10d4499SJeenu Viswambharan 		uint32_t cookie_hi,
223b10d4499SJeenu Viswambharan 		uint32_t cookie_lo,
224b10d4499SJeenu Viswambharan 		void *handle);
225b10d4499SJeenu Viswambharan 
226d832aee9Sdp-arm /* Disable Statistical Profiling Extensions helper */
227d832aee9Sdp-arm void arm_disable_spe(void);
228d832aee9Sdp-arm 
229b4315306SDan Handley #endif /* __PLAT_ARM_H__ */
230