xref: /rk3399_ARM-atf/include/plat/arm/common/plat_arm.h (revision b10d44995eb652675863c2cc6a7726683613da0d)
1b4315306SDan Handley /*
2bf75a371SAntonio Nino Diaz  * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
3b4315306SDan Handley  *
4b4315306SDan Handley  * Redistribution and use in source and binary forms, with or without
5b4315306SDan Handley  * modification, are permitted provided that the following conditions are met:
6b4315306SDan Handley  *
7b4315306SDan Handley  * Redistributions of source code must retain the above copyright notice, this
8b4315306SDan Handley  * list of conditions and the following disclaimer.
9b4315306SDan Handley  *
10b4315306SDan Handley  * Redistributions in binary form must reproduce the above copyright notice,
11b4315306SDan Handley  * this list of conditions and the following disclaimer in the documentation
12b4315306SDan Handley  * and/or other materials provided with the distribution.
13b4315306SDan Handley  *
14b4315306SDan Handley  * Neither the name of ARM nor the names of its contributors may be used
15b4315306SDan Handley  * to endorse or promote products derived from this software without specific
16b4315306SDan Handley  * prior written permission.
17b4315306SDan Handley  *
18b4315306SDan Handley  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19b4315306SDan Handley  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b4315306SDan Handley  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b4315306SDan Handley  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22b4315306SDan Handley  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23b4315306SDan Handley  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24b4315306SDan Handley  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25b4315306SDan Handley  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26b4315306SDan Handley  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27b4315306SDan Handley  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28b4315306SDan Handley  * POSSIBILITY OF SUCH DAMAGE.
29b4315306SDan Handley  */
30b4315306SDan Handley #ifndef __PLAT_ARM_H__
31b4315306SDan Handley #define __PLAT_ARM_H__
32b4315306SDan Handley 
333b211ff5SAntonio Nino Diaz #include <arm_xlat_tables.h>
34b4315306SDan Handley #include <bakery_lock.h>
35b4315306SDan Handley #include <cassert.h>
36b4315306SDan Handley #include <cpu_data.h>
37b4315306SDan Handley #include <stdint.h>
3853d9c9c8SScott Branden #include <utils_def.h>
39b4315306SDan Handley 
40afc931f5SSandrine Bailleux /*******************************************************************************
41afc931f5SSandrine Bailleux  * Forward declarations
42afc931f5SSandrine Bailleux  ******************************************************************************/
43afc931f5SSandrine Bailleux struct bl31_params;
44afc931f5SSandrine Bailleux struct meminfo;
45a8aa7fecSYatharth Kochar struct image_info;
46afc931f5SSandrine Bailleux 
47b4315306SDan Handley #define ARM_CASSERT_MMAP						\
48b4315306SDan Handley 	CASSERT((ARRAY_SIZE(plat_arm_mmap) + ARM_BL_REGIONS)		\
49b4315306SDan Handley 		<= MAX_MMAP_REGIONS,					\
50b4315306SDan Handley 		assert_max_mmap_regions);
51b4315306SDan Handley 
52b4315306SDan Handley /*
53b4315306SDan Handley  * Utility functions common to ARM standard platforms
54b4315306SDan Handley  */
554c0d0390SSoby Mathew void arm_setup_page_tables(uintptr_t total_base,
564c0d0390SSoby Mathew 			size_t total_size,
574c0d0390SSoby Mathew 			uintptr_t code_start,
584c0d0390SSoby Mathew 			uintptr_t code_limit,
594c0d0390SSoby Mathew 			uintptr_t rodata_start,
604c0d0390SSoby Mathew 			uintptr_t rodata_limit
61b4315306SDan Handley #if USE_COHERENT_MEM
624c0d0390SSoby Mathew 			, uintptr_t coh_start,
634c0d0390SSoby Mathew 			uintptr_t coh_limit
64b4315306SDan Handley #endif
65b4315306SDan Handley );
66b4315306SDan Handley 
67e40e075fSSoby Mathew #if defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32))
68b4315306SDan Handley /*
69b4315306SDan Handley  * Use this macro to instantiate lock before it is used in below
70b4315306SDan Handley  * arm_lock_xxx() macros
71b4315306SDan Handley  */
72e25e6f41SVikram Kanigiri #define ARM_INSTANTIATE_LOCK	DEFINE_BAKERY_LOCK(arm_lock);
73b4315306SDan Handley 
74b4315306SDan Handley /*
75b4315306SDan Handley  * These are wrapper macros to the Coherent Memory Bakery Lock API.
76b4315306SDan Handley  */
77b4315306SDan Handley #define arm_lock_init()		bakery_lock_init(&arm_lock)
78b4315306SDan Handley #define arm_lock_get()		bakery_lock_get(&arm_lock)
79b4315306SDan Handley #define arm_lock_release()	bakery_lock_release(&arm_lock)
80b4315306SDan Handley 
81b4315306SDan Handley #else
82b4315306SDan Handley 
83b4315306SDan Handley /*
846f249345SYatharth Kochar  * Empty macros for all other BL stages other than BL31 and BL32
85b4315306SDan Handley  */
86b4315306SDan Handley #define ARM_INSTANTIATE_LOCK
87b4315306SDan Handley #define arm_lock_init()
88b4315306SDan Handley #define arm_lock_get()
89b4315306SDan Handley #define arm_lock_release()
90b4315306SDan Handley 
91e40e075fSSoby Mathew #endif /* defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32)) */
92b4315306SDan Handley 
932204afdeSSoby Mathew #if ARM_RECOM_STATE_ID_ENC
942204afdeSSoby Mathew /*
952204afdeSSoby Mathew  * Macros used to parse state information from State-ID if it is using the
962204afdeSSoby Mathew  * recommended encoding for State-ID.
972204afdeSSoby Mathew  */
982204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_WIDTH		4
992204afdeSSoby Mathew #define ARM_LOCAL_PSTATE_MASK		((1 << ARM_LOCAL_PSTATE_WIDTH) - 1)
1002204afdeSSoby Mathew 
1012204afdeSSoby Mathew /* Macros to construct the composite power state */
1022204afdeSSoby Mathew 
1032204afdeSSoby Mathew /* Make composite power state parameter till power level 0 */
1042204afdeSSoby Mathew #if PSCI_EXTENDED_STATE_ID
1052204afdeSSoby Mathew 
1062204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
1072204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT))
1082204afdeSSoby Mathew #else
1092204afdeSSoby Mathew #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
1102204afdeSSoby Mathew 		(((lvl0_state) << PSTATE_ID_SHIFT) | \
1112204afdeSSoby Mathew 		((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \
1122204afdeSSoby Mathew 		((type) << PSTATE_TYPE_SHIFT))
1132204afdeSSoby Mathew #endif /* __PSCI_EXTENDED_STATE_ID__ */
1142204afdeSSoby Mathew 
1152204afdeSSoby Mathew /* Make composite power state parameter till power level 1 */
1162204afdeSSoby Mathew #define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \
1172204afdeSSoby Mathew 		(((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \
1182204afdeSSoby Mathew 		arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type))
1192204afdeSSoby Mathew 
1205f3a6030SSoby Mathew /* Make composite power state parameter till power level 2 */
1215f3a6030SSoby Mathew #define arm_make_pwrstate_lvl2(lvl2_state, lvl1_state, lvl0_state, pwr_lvl, type) \
1225f3a6030SSoby Mathew 		(((lvl2_state) << (ARM_LOCAL_PSTATE_WIDTH * 2)) | \
1235f3a6030SSoby Mathew 		arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type))
1245f3a6030SSoby Mathew 
1252204afdeSSoby Mathew #endif /* __ARM_RECOM_STATE_ID_ENC__ */
1262204afdeSSoby Mathew 
127*b10d4499SJeenu Viswambharan /* ARM State switch error codes */
128*b10d4499SJeenu Viswambharan #define STATE_SW_E_PARAM		(-2)
129*b10d4499SJeenu Viswambharan #define STATE_SW_E_DENIED		(-3)
130b4315306SDan Handley 
131b4315306SDan Handley /* IO storage utility functions */
132b4315306SDan Handley void arm_io_setup(void);
133b4315306SDan Handley 
134b4315306SDan Handley /* Security utility functions */
13557f78201SSoby Mathew void arm_tzc400_setup(void);
136618f0feeSVikram Kanigiri struct tzc_dmc500_driver_data;
137618f0feeSVikram Kanigiri void arm_tzc_dmc500_setup(struct tzc_dmc500_driver_data *plat_driver_data);
138b4315306SDan Handley 
139c1bb8a05SSoby Mathew /* Systimer utility function */
140c1bb8a05SSoby Mathew void arm_configure_sys_timer(void);
141c1bb8a05SSoby Mathew 
142b4315306SDan Handley /* PM utility functions */
14338dce70fSSoby Mathew int arm_validate_power_state(unsigned int power_state,
14438dce70fSSoby Mathew 			    psci_power_state_t *req_state);
145f9e858b1SSoby Mathew int arm_validate_ns_entrypoint(uintptr_t entrypoint);
146c1bb8a05SSoby Mathew void arm_system_pwr_domain_resume(void);
1474c117f6cSSandrine Bailleux void arm_program_trusted_mailbox(uintptr_t address);
14838dce70fSSoby Mathew 
14938dce70fSSoby Mathew /* Topology utility function */
15038dce70fSSoby Mathew int arm_check_mpidr(u_register_t mpidr);
151b4315306SDan Handley 
152b4315306SDan Handley /* BL1 utility functions */
153b4315306SDan Handley void arm_bl1_early_platform_setup(void);
154b4315306SDan Handley void arm_bl1_platform_setup(void);
155b4315306SDan Handley void arm_bl1_plat_arch_setup(void);
156b4315306SDan Handley 
157b4315306SDan Handley /* BL2 utility functions */
158afc931f5SSandrine Bailleux void arm_bl2_early_platform_setup(struct meminfo *mem_layout);
159b4315306SDan Handley void arm_bl2_platform_setup(void);
160b4315306SDan Handley void arm_bl2_plat_arch_setup(void);
161b4315306SDan Handley uint32_t arm_get_spsr_for_bl32_entry(void);
162b4315306SDan Handley uint32_t arm_get_spsr_for_bl33_entry(void);
16307570d59SYatharth Kochar int arm_bl2_handle_post_image_load(unsigned int image_id);
164b4315306SDan Handley 
165dcda29f6SYatharth Kochar /* BL2U utility functions */
166dcda29f6SYatharth Kochar void arm_bl2u_early_platform_setup(struct meminfo *mem_layout,
167dcda29f6SYatharth Kochar 				void *plat_info);
168dcda29f6SYatharth Kochar void arm_bl2u_platform_setup(void);
169dcda29f6SYatharth Kochar void arm_bl2u_plat_arch_setup(void);
170dcda29f6SYatharth Kochar 
171d178637dSJuan Castillo /* BL31 utility functions */
172a8aa7fecSYatharth Kochar #if LOAD_IMAGE_V2
173a8aa7fecSYatharth Kochar void arm_bl31_early_platform_setup(void *from_bl2,
174a8aa7fecSYatharth Kochar 				void *plat_params_from_bl2);
175a8aa7fecSYatharth Kochar #else
176afc931f5SSandrine Bailleux void arm_bl31_early_platform_setup(struct bl31_params *from_bl2,
177b4315306SDan Handley 				void *plat_params_from_bl2);
178a8aa7fecSYatharth Kochar #endif /* LOAD_IMAGE_V2 */
179b4315306SDan Handley void arm_bl31_platform_setup(void);
180080225daSSoby Mathew void arm_bl31_plat_runtime_setup(void);
181b4315306SDan Handley void arm_bl31_plat_arch_setup(void);
182b4315306SDan Handley 
183b4315306SDan Handley /* TSP utility functions */
184b4315306SDan Handley void arm_tsp_early_platform_setup(void);
185b4315306SDan Handley 
186181bbd41SSoby Mathew /* SP_MIN utility functions */
187d9915518SYatharth Kochar void arm_sp_min_early_platform_setup(void *from_bl2,
188d9915518SYatharth Kochar 		void *plat_params_from_bl2);
189181bbd41SSoby Mathew 
190436223deSYatharth Kochar /* FIP TOC validity check */
191436223deSYatharth Kochar int arm_io_is_toc_valid(void);
192b4315306SDan Handley 
193b4315306SDan Handley /*
194b4315306SDan Handley  * Mandatory functions required in ARM standard platforms
195b4315306SDan Handley  */
1960108047aSSoby Mathew unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr);
19727573c59SAchin Gupta void plat_arm_gic_driver_init(void);
198b4315306SDan Handley void plat_arm_gic_init(void);
19927573c59SAchin Gupta void plat_arm_gic_cpuif_enable(void);
20027573c59SAchin Gupta void plat_arm_gic_cpuif_disable(void);
201d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_on(void);
202d17b953aSJeenu Viswambharan void plat_arm_gic_redistif_off(void);
20327573c59SAchin Gupta void plat_arm_gic_pcpu_init(void);
204b4315306SDan Handley void plat_arm_security_setup(void);
205b4315306SDan Handley void plat_arm_pwrc_setup(void);
2066355f234SVikram Kanigiri void plat_arm_interconnect_init(void);
2076355f234SVikram Kanigiri void plat_arm_interconnect_enter_coherency(void);
2086355f234SVikram Kanigiri void plat_arm_interconnect_exit_coherency(void);
209b4315306SDan Handley 
210d8d6cf24SSummer Qin #if ARM_PLAT_MT
211d8d6cf24SSummer Qin unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr);
212d8d6cf24SSummer Qin #endif
213d8d6cf24SSummer Qin 
214a8aa7fecSYatharth Kochar #if LOAD_IMAGE_V2
215a8aa7fecSYatharth Kochar /*
216a8aa7fecSYatharth Kochar  * This function is called after loading SCP_BL2 image and it is used to perform
217a8aa7fecSYatharth Kochar  * any platform-specific actions required to handle the SCP firmware.
218a8aa7fecSYatharth Kochar  */
219a8aa7fecSYatharth Kochar int plat_arm_bl2_handle_scp_bl2(struct image_info *scp_bl2_image_info);
220a8aa7fecSYatharth Kochar #endif
221a8aa7fecSYatharth Kochar 
222b4315306SDan Handley /*
223b4315306SDan Handley  * Optional functions required in ARM standard platforms
224b4315306SDan Handley  */
225b4315306SDan Handley void plat_arm_io_setup(void);
226b4315306SDan Handley int plat_arm_get_alt_image_source(
22716948ae1SJuan Castillo 	unsigned int image_id,
22816948ae1SJuan Castillo 	uintptr_t *dev_handle,
22916948ae1SJuan Castillo 	uintptr_t *image_spec);
23038dce70fSSoby Mathew unsigned int plat_arm_calc_core_pos(u_register_t mpidr);
23165cb1c4cSVikram Kanigiri const mmap_region_t *plat_arm_get_mmap(void);
232b4315306SDan Handley 
2335486a965SSoby Mathew /* Allow platform to override psci_pm_ops during runtime */
2345486a965SSoby Mathew const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops);
2355486a965SSoby Mathew 
236*b10d4499SJeenu Viswambharan /* Execution state switch in ARM platforms */
237*b10d4499SJeenu Viswambharan int arm_execution_state_switch(unsigned int smc_fid,
238*b10d4499SJeenu Viswambharan 		uint32_t pc_hi,
239*b10d4499SJeenu Viswambharan 		uint32_t pc_lo,
240*b10d4499SJeenu Viswambharan 		uint32_t cookie_hi,
241*b10d4499SJeenu Viswambharan 		uint32_t cookie_lo,
242*b10d4499SJeenu Viswambharan 		void *handle);
243*b10d4499SJeenu Viswambharan 
244b4315306SDan Handley #endif /* __PLAT_ARM_H__ */
245