blob: b2c7bd2768db7f41278a7c2d7240849fc3bc53da [file] [log] [blame]
Dan Handley9df48042015-03-19 18:58:55 +00001/*
Soby Mathew7d5a2e72018-01-10 15:59:31 +00002 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
Dan Handley9df48042015-03-19 18:58:55 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Dan Handley9df48042015-03-19 18:58:55 +00005 */
6#ifndef __PLAT_ARM_H__
7#define __PLAT_ARM_H__
8
Antonio Nino Diazf09d0032017-04-11 14:04:56 +01009#include <arm_xlat_tables.h>
Dan Handley9df48042015-03-19 18:58:55 +000010#include <bakery_lock.h>
Dan Handley9df48042015-03-19 18:58:55 +000011#include <cassert.h>
12#include <cpu_data.h>
13#include <stdint.h>
Scott Brandenbf404c02017-04-10 11:45:52 -070014#include <utils_def.h>
Dan Handley9df48042015-03-19 18:58:55 +000015
Sandrine Bailleuxf402a522016-09-15 10:09:53 +010016/*******************************************************************************
17 * Forward declarations
18 ******************************************************************************/
19struct bl31_params;
20struct meminfo;
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010021struct image_info;
Soby Mathew96a1c6b2018-01-15 14:45:33 +000022struct bl_params;
Sandrine Bailleuxf402a522016-09-15 10:09:53 +010023
Dan Handley9df48042015-03-19 18:58:55 +000024#define ARM_CASSERT_MMAP \
25 CASSERT((ARRAY_SIZE(plat_arm_mmap) + ARM_BL_REGIONS) \
26 <= MAX_MMAP_REGIONS, \
27 assert_max_mmap_regions);
28
29/*
30 * Utility functions common to ARM standard platforms
31 */
Soby Mathewa0fedc42016-06-16 14:52:04 +010032void arm_setup_page_tables(uintptr_t total_base,
33 size_t total_size,
34 uintptr_t code_start,
35 uintptr_t code_limit,
36 uintptr_t rodata_start,
37 uintptr_t rodata_limit
Dan Handley9df48042015-03-19 18:58:55 +000038#if USE_COHERENT_MEM
Soby Mathewa0fedc42016-06-16 14:52:04 +010039 , uintptr_t coh_start,
40 uintptr_t coh_limit
Dan Handley9df48042015-03-19 18:58:55 +000041#endif
42);
43
Soby Mathew074f6932017-02-28 22:58:29 +000044#if defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32))
Dan Handley9df48042015-03-19 18:58:55 +000045/*
46 * Use this macro to instantiate lock before it is used in below
47 * arm_lock_xxx() macros
48 */
Jeenu Viswambharan749d25b2017-08-23 14:12:59 +010049#define ARM_INSTANTIATE_LOCK DEFINE_BAKERY_LOCK(arm_lock)
Soby Mathewea26bad2016-11-14 12:25:45 +000050#define ARM_LOCK_GET_INSTANCE (&arm_lock)
Dan Handley9df48042015-03-19 18:58:55 +000051/*
52 * These are wrapper macros to the Coherent Memory Bakery Lock API.
53 */
54#define arm_lock_init() bakery_lock_init(&arm_lock)
55#define arm_lock_get() bakery_lock_get(&arm_lock)
56#define arm_lock_release() bakery_lock_release(&arm_lock)
57
58#else
59
Dan Handley9df48042015-03-19 18:58:55 +000060/*
Yatharth Kochar2694cba2016-11-14 12:00:41 +000061 * Empty macros for all other BL stages other than BL31 and BL32
Dan Handley9df48042015-03-19 18:58:55 +000062 */
Jeenu Viswambharan749d25b2017-08-23 14:12:59 +010063#define ARM_INSTANTIATE_LOCK static int arm_lock __unused
Soby Mathewea26bad2016-11-14 12:25:45 +000064#define ARM_LOCK_GET_INSTANCE 0
Dan Handley9df48042015-03-19 18:58:55 +000065#define arm_lock_init()
66#define arm_lock_get()
67#define arm_lock_release()
68
Soby Mathew074f6932017-02-28 22:58:29 +000069#endif /* defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32)) */
Dan Handley9df48042015-03-19 18:58:55 +000070
Soby Mathew7799cf72015-04-16 14:49:09 +010071#if ARM_RECOM_STATE_ID_ENC
72/*
73 * Macros used to parse state information from State-ID if it is using the
74 * recommended encoding for State-ID.
75 */
76#define ARM_LOCAL_PSTATE_WIDTH 4
77#define ARM_LOCAL_PSTATE_MASK ((1 << ARM_LOCAL_PSTATE_WIDTH) - 1)
78
79/* Macros to construct the composite power state */
80
81/* Make composite power state parameter till power level 0 */
82#if PSCI_EXTENDED_STATE_ID
83
84#define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
85 (((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT))
86#else
87#define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \
88 (((lvl0_state) << PSTATE_ID_SHIFT) | \
89 ((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \
90 ((type) << PSTATE_TYPE_SHIFT))
91#endif /* __PSCI_EXTENDED_STATE_ID__ */
92
93/* Make composite power state parameter till power level 1 */
94#define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \
95 (((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \
96 arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type))
97
Soby Mathewa869de12015-05-08 10:18:59 +010098/* Make composite power state parameter till power level 2 */
99#define arm_make_pwrstate_lvl2(lvl2_state, lvl1_state, lvl0_state, pwr_lvl, type) \
100 (((lvl2_state) << (ARM_LOCAL_PSTATE_WIDTH * 2)) | \
101 arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type))
102
Soby Mathew7799cf72015-04-16 14:49:09 +0100103#endif /* __ARM_RECOM_STATE_ID_ENC__ */
104
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000105/* ARM State switch error codes */
106#define STATE_SW_E_PARAM (-2)
107#define STATE_SW_E_DENIED (-3)
Dan Handley9df48042015-03-19 18:58:55 +0000108
Dan Handley9df48042015-03-19 18:58:55 +0000109/* IO storage utility functions */
110void arm_io_setup(void);
111
112/* Security utility functions */
Soby Mathew9c708b52016-02-26 14:23:19 +0000113void arm_tzc400_setup(void);
Vikram Kanigiri510d87b2016-01-29 12:32:58 +0000114struct tzc_dmc500_driver_data;
115void arm_tzc_dmc500_setup(struct tzc_dmc500_driver_data *plat_driver_data);
Dan Handley9df48042015-03-19 18:58:55 +0000116
Soby Mathew61e8d0b2015-10-12 17:32:29 +0100117/* Systimer utility function */
118void arm_configure_sys_timer(void);
119
Dan Handley9df48042015-03-19 18:58:55 +0000120/* PM utility functions */
Soby Mathewfec4eb72015-07-01 16:16:20 +0100121int arm_validate_power_state(unsigned int power_state,
122 psci_power_state_t *req_state);
Jeenu Viswambharan59424d82017-09-19 09:27:18 +0100123int arm_validate_psci_entrypoint(uintptr_t entrypoint);
Soby Mathew0d9e8522015-07-15 13:36:24 +0100124int arm_validate_ns_entrypoint(uintptr_t entrypoint);
Soby Mathew9ca28062017-10-11 16:08:58 +0100125void arm_system_pwr_domain_save(void);
Soby Mathew61e8d0b2015-10-12 17:32:29 +0100126void arm_system_pwr_domain_resume(void);
Sandrine Bailleux03897bb2015-11-26 16:31:34 +0000127void arm_program_trusted_mailbox(uintptr_t address);
Roberto Vargasa1c16b62017-08-03 09:16:43 +0100128int arm_psci_read_mem_protect(int *val);
129int arm_nor_psci_write_mem_protect(int val);
130void arm_nor_psci_do_mem_protect(void);
131int arm_psci_mem_protect_chk(uintptr_t base, u_register_t length);
Soby Mathewfec4eb72015-07-01 16:16:20 +0100132
133/* Topology utility function */
134int arm_check_mpidr(u_register_t mpidr);
Dan Handley9df48042015-03-19 18:58:55 +0000135
136/* BL1 utility functions */
137void arm_bl1_early_platform_setup(void);
138void arm_bl1_platform_setup(void);
139void arm_bl1_plat_arch_setup(void);
140
141/* BL2 utility functions */
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000142void arm_bl2_early_platform_setup(uintptr_t tb_fw_config, struct meminfo *mem_layout);
Dan Handley9df48042015-03-19 18:58:55 +0000143void arm_bl2_platform_setup(void);
144void arm_bl2_plat_arch_setup(void);
145uint32_t arm_get_spsr_for_bl32_entry(void);
146uint32_t arm_get_spsr_for_bl33_entry(void);
Yatharth Kocharede39cb2016-11-14 12:01:04 +0000147int arm_bl2_handle_post_image_load(unsigned int image_id);
Dan Handley9df48042015-03-19 18:58:55 +0000148
Roberto Vargas52207802017-11-17 13:22:18 +0000149/* BL2 at EL3 functions */
150void arm_bl2_el3_early_platform_setup(void);
151void arm_bl2_el3_plat_arch_setup(void);
152
Yatharth Kochar3a11eda2015-10-14 15:28:11 +0100153/* BL2U utility functions */
154void arm_bl2u_early_platform_setup(struct meminfo *mem_layout,
155 void *plat_info);
156void arm_bl2u_platform_setup(void);
157void arm_bl2u_plat_arch_setup(void);
158
Juan Castillo7d199412015-12-14 09:35:25 +0000159/* BL31 utility functions */
Yatharth Kocharf9a0f162016-09-13 17:07:57 +0100160#if LOAD_IMAGE_V2
Soby Mathew7d5a2e72018-01-10 15:59:31 +0000161void arm_bl31_early_platform_setup(void *from_bl2, uintptr_t soc_fw_config,
162 uintptr_t hw_config, void *plat_params_from_bl2);
Yatharth Kocharf9a0f162016-09-13 17:07:57 +0100163#else
Soby Mathew7d5a2e72018-01-10 15:59:31 +0000164void arm_bl31_early_platform_setup(struct bl31_params *from_bl2, uintptr_t soc_fw_config,
165 uintptr_t hw_config, void *plat_params_from_bl2);
Yatharth Kocharf9a0f162016-09-13 17:07:57 +0100166#endif /* LOAD_IMAGE_V2 */
Dan Handley9df48042015-03-19 18:58:55 +0000167void arm_bl31_platform_setup(void);
Soby Mathew2fd66be2015-12-09 11:38:43 +0000168void arm_bl31_plat_runtime_setup(void);
Dan Handley9df48042015-03-19 18:58:55 +0000169void arm_bl31_plat_arch_setup(void);
170
171/* TSP utility functions */
172void arm_tsp_early_platform_setup(void);
173
Soby Mathew7b754182016-07-11 14:15:27 +0100174/* SP_MIN utility functions */
Soby Mathew7d5a2e72018-01-10 15:59:31 +0000175void arm_sp_min_early_platform_setup(void *from_bl2, uintptr_t tos_fw_config,
176 uintptr_t hw_config, void *plat_params_from_bl2);
Dimitris Papastamos52323b02017-06-07 13:45:41 +0100177void arm_sp_min_plat_runtime_setup(void);
Soby Mathew7b754182016-07-11 14:15:27 +0100178
Yatharth Kochar736a3bf2015-10-11 14:14:55 +0100179/* FIP TOC validity check */
180int arm_io_is_toc_valid(void);
Dan Handley9df48042015-03-19 18:58:55 +0000181
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000182/* Utility functions for Dynamic Config */
183void arm_load_tb_fw_config(void);
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000184void arm_bl2_set_tb_cfg_addr(void *dtb);
185void arm_bl2_dyn_cfg_init(void);
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000186
Dan Handley9df48042015-03-19 18:58:55 +0000187/*
188 * Mandatory functions required in ARM standard platforms
189 */
Soby Mathew47e43f22016-02-01 14:04:34 +0000190unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr);
Achin Gupta1fa7eb62015-11-03 14:18:34 +0000191void plat_arm_gic_driver_init(void);
Dan Handley9df48042015-03-19 18:58:55 +0000192void plat_arm_gic_init(void);
Achin Gupta1fa7eb62015-11-03 14:18:34 +0000193void plat_arm_gic_cpuif_enable(void);
194void plat_arm_gic_cpuif_disable(void);
Jeenu Viswambharan78132c92016-12-09 11:12:34 +0000195void plat_arm_gic_redistif_on(void);
196void plat_arm_gic_redistif_off(void);
Achin Gupta1fa7eb62015-11-03 14:18:34 +0000197void plat_arm_gic_pcpu_init(void);
Soby Mathew9ca28062017-10-11 16:08:58 +0100198void plat_arm_gic_save(void);
199void plat_arm_gic_resume(void);
Dan Handley9df48042015-03-19 18:58:55 +0000200void plat_arm_security_setup(void);
201void plat_arm_pwrc_setup(void);
Vikram Kanigirifbb13012016-02-15 11:54:14 +0000202void plat_arm_interconnect_init(void);
203void plat_arm_interconnect_enter_coherency(void);
204void plat_arm_interconnect_exit_coherency(void);
Dan Handley9df48042015-03-19 18:58:55 +0000205
Summer Qin93c812f2017-02-28 16:46:17 +0000206#if ARM_PLAT_MT
207unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr);
208#endif
209
Yatharth Kocharf9a0f162016-09-13 17:07:57 +0100210#if LOAD_IMAGE_V2
211/*
212 * This function is called after loading SCP_BL2 image and it is used to perform
213 * any platform-specific actions required to handle the SCP firmware.
214 */
215int plat_arm_bl2_handle_scp_bl2(struct image_info *scp_bl2_image_info);
216#endif
217
Dan Handley9df48042015-03-19 18:58:55 +0000218/*
219 * Optional functions required in ARM standard platforms
220 */
221void plat_arm_io_setup(void);
222int plat_arm_get_alt_image_source(
Juan Castillo3a66aca2015-04-13 17:36:19 +0100223 unsigned int image_id,
224 uintptr_t *dev_handle,
225 uintptr_t *image_spec);
Soby Mathewfec4eb72015-07-01 16:16:20 +0100226unsigned int plat_arm_calc_core_pos(u_register_t mpidr);
Vikram Kanigiri07035432015-11-12 18:52:34 +0000227const mmap_region_t *plat_arm_get_mmap(void);
Dan Handley9df48042015-03-19 18:58:55 +0000228
Soby Mathew0b4c5a32016-10-21 17:51:22 +0100229/* Allow platform to override psci_pm_ops during runtime */
230const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops);
231
Jeenu Viswambharanbc1a9292017-02-16 14:55:15 +0000232/* Execution state switch in ARM platforms */
233int arm_execution_state_switch(unsigned int smc_fid,
234 uint32_t pc_hi,
235 uint32_t pc_lo,
236 uint32_t cookie_hi,
237 uint32_t cookie_lo,
238 void *handle);
239
Dan Handley9df48042015-03-19 18:58:55 +0000240#endif /* __PLAT_ARM_H__ */