Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Rohit Mathew | f085b87 | 2023-12-20 17:29:18 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
Antonio Nino Diaz | 05fdb83 | 2018-10-25 16:53:04 +0100 | [diff] [blame] | 6 | #ifndef PLAT_ARM_H |
| 7 | #define PLAT_ARM_H |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 8 | |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 9 | #include <stdbool.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 10 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 12 | #include <common/desc_image_load.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <drivers/arm/tzc_common.h> |
| 14 | #include <lib/bakery_lock.h> |
| 15 | #include <lib/cassert.h> |
| 16 | #include <lib/el3_runtime/cpu_data.h> |
Rohit Mathew | f085b87 | 2023-12-20 17:29:18 +0000 | [diff] [blame] | 17 | #include <lib/gpt_rme/gpt_rme.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 18 | #include <lib/spinlock.h> |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 19 | #include <lib/transfer_list.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 20 | #include <lib/utils_def.h> |
| 21 | #include <lib/xlat_tables/xlat_tables_compat.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 22 | |
Sandrine Bailleux | f402a52 | 2016-09-15 10:09:53 +0100 | [diff] [blame] | 23 | /******************************************************************************* |
| 24 | * Forward declarations |
| 25 | ******************************************************************************/ |
Sandrine Bailleux | f402a52 | 2016-09-15 10:09:53 +0100 | [diff] [blame] | 26 | struct meminfo; |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 27 | struct image_info; |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 28 | struct bl_params; |
Sandrine Bailleux | f402a52 | 2016-09-15 10:09:53 +0100 | [diff] [blame] | 29 | |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 30 | typedef struct arm_tzc_regions_info { |
| 31 | unsigned long long base; |
| 32 | unsigned long long end; |
Antonio Nino Diaz | 5f47579 | 2018-10-15 14:58:11 +0100 | [diff] [blame] | 33 | unsigned int sec_attr; |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 34 | unsigned int nsaid_permissions; |
| 35 | } arm_tzc_regions_info_t; |
| 36 | |
Rohit Mathew | f085b87 | 2023-12-20 17:29:18 +0000 | [diff] [blame] | 37 | typedef struct arm_gpt_info { |
| 38 | pas_region_t *pas_region_base; |
| 39 | unsigned int pas_region_count; |
| 40 | uintptr_t l0_base; |
| 41 | uintptr_t l1_base; |
| 42 | size_t l0_size; |
| 43 | size_t l1_size; |
| 44 | gpccr_pps_e pps; |
| 45 | gpccr_pgs_e pgs; |
| 46 | } arm_gpt_info_t; |
| 47 | |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 48 | /******************************************************************************* |
| 49 | * Default mapping definition of the TrustZone Controller for ARM standard |
| 50 | * platforms. |
| 51 | * Configure: |
| 52 | * - Region 0 with no access; |
| 53 | * - Region 1 with secure access only; |
| 54 | * - the remaining DRAM regions access from the given Non-Secure masters. |
| 55 | ******************************************************************************/ |
Manish V Badarkhe | 19c7218 | 2023-09-01 07:54:33 +0100 | [diff] [blame] | 56 | |
| 57 | #if ENABLE_RME |
| 58 | #define ARM_TZC_RME_REGIONS_DEF \ |
| 59 | {ARM_AP_TZC_DRAM1_BASE, ARM_AP_TZC_DRAM1_END, TZC_REGION_S_RDWR, 0},\ |
| 60 | {ARM_EL3_TZC_DRAM1_BASE, ARM_L1_GPT_END, TZC_REGION_S_RDWR, 0}, \ |
| 61 | {ARM_NS_DRAM1_BASE, ARM_NS_DRAM1_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 62 | PLAT_ARM_TZC_NS_DEV_ACCESS}, \ |
| 63 | /* Realm and Shared area share the same PAS */ \ |
| 64 | {ARM_REALM_BASE, ARM_EL3_RMM_SHARED_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 65 | PLAT_ARM_TZC_NS_DEV_ACCESS}, \ |
| 66 | {ARM_DRAM2_BASE, ARM_DRAM2_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 67 | PLAT_ARM_TZC_NS_DEV_ACCESS} |
| 68 | #endif |
| 69 | |
Nishant Sharma | e78ef3d | 2023-10-12 10:37:54 +0100 | [diff] [blame] | 70 | #if SPM_MM || (SPMC_AT_EL3 && SPMC_AT_EL3_SEL0_SP) |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 71 | #define ARM_TZC_REGIONS_DEF \ |
Zelalem Aweke | c43c563 | 2021-07-12 23:41:05 -0500 | [diff] [blame] | 72 | {ARM_AP_TZC_DRAM1_BASE, ARM_EL3_TZC_DRAM1_END + ARM_L1_GPT_SIZE,\ |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 73 | TZC_REGION_S_RDWR, 0}, \ |
| 74 | {ARM_NS_DRAM1_BASE, ARM_NS_DRAM1_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 75 | PLAT_ARM_TZC_NS_DEV_ACCESS}, \ |
| 76 | {ARM_DRAM2_BASE, ARM_DRAM2_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 77 | PLAT_ARM_TZC_NS_DEV_ACCESS}, \ |
Ard Biesheuvel | 8b034fc | 2018-12-29 19:43:21 +0100 | [diff] [blame] | 78 | {PLAT_SP_IMAGE_NS_BUF_BASE, (PLAT_SP_IMAGE_NS_BUF_BASE + \ |
| 79 | PLAT_SP_IMAGE_NS_BUF_SIZE) - 1, TZC_REGION_S_NONE, \ |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 80 | PLAT_ARM_TZC_NS_DEV_ACCESS} |
| 81 | |
Zelalem Aweke | c43c563 | 2021-07-12 23:41:05 -0500 | [diff] [blame] | 82 | #elif ENABLE_RME |
Manish V Badarkhe | 19c7218 | 2023-09-01 07:54:33 +0100 | [diff] [blame] | 83 | #if (defined(SPD_tspd) || defined(SPD_opteed) || defined(SPD_spmd)) && \ |
| 84 | MEASURED_BOOT |
| 85 | #define ARM_TZC_REGIONS_DEF \ |
| 86 | ARM_TZC_RME_REGIONS_DEF, \ |
| 87 | {ARM_EVENT_LOG_DRAM1_BASE, ARM_EVENT_LOG_DRAM1_END, \ |
| 88 | TZC_REGION_S_RDWR, 0} |
| 89 | #else |
| 90 | #define ARM_TZC_REGIONS_DEF \ |
| 91 | ARM_TZC_RME_REGIONS_DEF |
| 92 | #endif |
Zelalem Aweke | c43c563 | 2021-07-12 23:41:05 -0500 | [diff] [blame] | 93 | |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 94 | #else |
| 95 | #define ARM_TZC_REGIONS_DEF \ |
Zelalem Aweke | c43c563 | 2021-07-12 23:41:05 -0500 | [diff] [blame] | 96 | {ARM_AP_TZC_DRAM1_BASE, ARM_EL3_TZC_DRAM1_END + ARM_L1_GPT_SIZE,\ |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 97 | TZC_REGION_S_RDWR, 0}, \ |
| 98 | {ARM_NS_DRAM1_BASE, ARM_NS_DRAM1_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 99 | PLAT_ARM_TZC_NS_DEV_ACCESS}, \ |
| 100 | {ARM_DRAM2_BASE, ARM_DRAM2_END, ARM_TZC_NS_DRAM_S_ACCESS, \ |
| 101 | PLAT_ARM_TZC_NS_DEV_ACCESS} |
| 102 | #endif |
| 103 | |
Chris Kay | 2b54c0c | 2018-05-09 15:46:07 +0100 | [diff] [blame] | 104 | #define ARM_CASSERT_MMAP \ |
| 105 | CASSERT((ARRAY_SIZE(plat_arm_mmap) - 1) <= PLAT_ARM_MMAP_ENTRIES, \ |
| 106 | assert_plat_arm_mmap_mismatch); \ |
| 107 | CASSERT((PLAT_ARM_MMAP_ENTRIES + ARM_BL_REGIONS) \ |
| 108 | <= MAX_MMAP_REGIONS, \ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 109 | assert_max_mmap_regions); |
| 110 | |
Roberto Vargas | e3adc37 | 2018-05-23 09:27:06 +0100 | [diff] [blame] | 111 | void arm_setup_romlib(void); |
| 112 | |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 113 | #if defined(IMAGE_BL31) || (!defined(__aarch64__) && defined(IMAGE_BL32)) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Use this macro to instantiate lock before it is used in below |
| 116 | * arm_lock_xxx() macros |
| 117 | */ |
Sandrine Bailleux | ceb258e | 2018-07-11 13:59:18 +0200 | [diff] [blame] | 118 | #define ARM_INSTANTIATE_LOCK static DEFINE_BAKERY_LOCK(arm_lock) |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 119 | #define ARM_LOCK_GET_INSTANCE (&arm_lock) |
Roberto Vargas | 0099694 | 2017-11-13 13:41:58 +0000 | [diff] [blame] | 120 | |
| 121 | #if !HW_ASSISTED_COHERENCY |
| 122 | #define ARM_SCMI_INSTANTIATE_LOCK DEFINE_BAKERY_LOCK(arm_scmi_lock) |
| 123 | #else |
| 124 | #define ARM_SCMI_INSTANTIATE_LOCK spinlock_t arm_scmi_lock |
| 125 | #endif |
| 126 | #define ARM_SCMI_LOCK_GET_INSTANCE (&arm_scmi_lock) |
| 127 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 128 | /* |
| 129 | * These are wrapper macros to the Coherent Memory Bakery Lock API. |
| 130 | */ |
| 131 | #define arm_lock_init() bakery_lock_init(&arm_lock) |
| 132 | #define arm_lock_get() bakery_lock_get(&arm_lock) |
| 133 | #define arm_lock_release() bakery_lock_release(&arm_lock) |
| 134 | |
| 135 | #else |
| 136 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 137 | /* |
Yatharth Kochar | 2694cba | 2016-11-14 12:00:41 +0000 | [diff] [blame] | 138 | * Empty macros for all other BL stages other than BL31 and BL32 |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 139 | */ |
Jeenu Viswambharan | 749d25b | 2017-08-23 14:12:59 +0100 | [diff] [blame] | 140 | #define ARM_INSTANTIATE_LOCK static int arm_lock __unused |
Soby Mathew | ea26bad | 2016-11-14 12:25:45 +0000 | [diff] [blame] | 141 | #define ARM_LOCK_GET_INSTANCE 0 |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 142 | #define arm_lock_init() |
| 143 | #define arm_lock_get() |
| 144 | #define arm_lock_release() |
| 145 | |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 146 | #endif /* defined(IMAGE_BL31) || (!defined(__aarch64__) && defined(IMAGE_BL32)) */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 147 | |
Soby Mathew | 7799cf7 | 2015-04-16 14:49:09 +0100 | [diff] [blame] | 148 | #if ARM_RECOM_STATE_ID_ENC |
| 149 | /* |
| 150 | * Macros used to parse state information from State-ID if it is using the |
| 151 | * recommended encoding for State-ID. |
| 152 | */ |
| 153 | #define ARM_LOCAL_PSTATE_WIDTH 4 |
| 154 | #define ARM_LOCAL_PSTATE_MASK ((1 << ARM_LOCAL_PSTATE_WIDTH) - 1) |
| 155 | |
Wing Li | 05364b9 | 2023-01-26 18:33:43 -0800 | [diff] [blame] | 156 | #if PSCI_OS_INIT_MODE |
| 157 | #define ARM_LAST_AT_PLVL_MASK (ARM_LOCAL_PSTATE_MASK << \ |
| 158 | (ARM_LOCAL_PSTATE_WIDTH * \ |
| 159 | (PLAT_MAX_PWR_LVL + 1))) |
| 160 | #endif /* __PSCI_OS_INIT_MODE__ */ |
| 161 | |
Soby Mathew | 7799cf7 | 2015-04-16 14:49:09 +0100 | [diff] [blame] | 162 | /* Macros to construct the composite power state */ |
| 163 | |
| 164 | /* Make composite power state parameter till power level 0 */ |
| 165 | #if PSCI_EXTENDED_STATE_ID |
| 166 | |
| 167 | #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \ |
| 168 | (((lvl0_state) << PSTATE_ID_SHIFT) | ((type) << PSTATE_TYPE_SHIFT)) |
| 169 | #else |
| 170 | #define arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type) \ |
| 171 | (((lvl0_state) << PSTATE_ID_SHIFT) | \ |
| 172 | ((pwr_lvl) << PSTATE_PWR_LVL_SHIFT) | \ |
| 173 | ((type) << PSTATE_TYPE_SHIFT)) |
| 174 | #endif /* __PSCI_EXTENDED_STATE_ID__ */ |
| 175 | |
| 176 | /* Make composite power state parameter till power level 1 */ |
| 177 | #define arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type) \ |
| 178 | (((lvl1_state) << ARM_LOCAL_PSTATE_WIDTH) | \ |
| 179 | arm_make_pwrstate_lvl0(lvl0_state, pwr_lvl, type)) |
| 180 | |
Soby Mathew | a869de1 | 2015-05-08 10:18:59 +0100 | [diff] [blame] | 181 | /* Make composite power state parameter till power level 2 */ |
| 182 | #define arm_make_pwrstate_lvl2(lvl2_state, lvl1_state, lvl0_state, pwr_lvl, type) \ |
| 183 | (((lvl2_state) << (ARM_LOCAL_PSTATE_WIDTH * 2)) | \ |
| 184 | arm_make_pwrstate_lvl1(lvl1_state, lvl0_state, pwr_lvl, type)) |
| 185 | |
Soby Mathew | 7799cf7 | 2015-04-16 14:49:09 +0100 | [diff] [blame] | 186 | #endif /* __ARM_RECOM_STATE_ID_ENC__ */ |
| 187 | |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 188 | /* ARM State switch error codes */ |
| 189 | #define STATE_SW_E_PARAM (-2) |
| 190 | #define STATE_SW_E_DENIED (-3) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 191 | |
Max Shvetsov | 06dba29 | 2019-12-06 11:50:12 +0000 | [diff] [blame] | 192 | /* plat_get_rotpk_info() flags */ |
laurenw-arm | 0216953 | 2023-08-15 14:57:56 -0500 | [diff] [blame] | 193 | #define ARM_ROTPK_REGS_ID 1 |
| 194 | #define ARM_ROTPK_DEVEL_RSA_ID 2 |
| 195 | #define ARM_ROTPK_DEVEL_ECDSA_ID 3 |
laurenw-arm | 055199b | 2022-10-28 11:26:32 -0500 | [diff] [blame] | 196 | #define ARM_ROTPK_DEVEL_FULL_DEV_RSA_KEY_ID 4 |
laurenw-arm | 0216953 | 2023-08-15 14:57:56 -0500 | [diff] [blame] | 197 | #define ARM_ROTPK_DEVEL_FULL_DEV_ECDSA_KEY_ID 5 |
| 198 | |
| 199 | #define ARM_USE_DEVEL_ROTPK \ |
| 200 | (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_RSA_ID) || \ |
| 201 | (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_ECDSA_ID) || \ |
| 202 | (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_FULL_DEV_RSA_KEY_ID) || \ |
| 203 | (ARM_ROTPK_LOCATION_ID == ARM_ROTPK_DEVEL_FULL_DEV_ECDSA_KEY_ID) |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 204 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 205 | /* IO storage utility functions */ |
Louis Mayencourt | 7d24ce1 | 2020-01-29 14:43:06 +0000 | [diff] [blame] | 206 | int arm_io_setup(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 207 | |
Manish V Badarkhe | dd6f252 | 2021-02-22 17:30:17 +0000 | [diff] [blame] | 208 | /* Set image specification in IO block policy */ |
Manish V Badarkhe | d2f0a7a | 2021-06-25 23:43:33 +0100 | [diff] [blame] | 209 | int arm_set_image_source(unsigned int image_id, const char *part_name, |
| 210 | uintptr_t *dev_handle, uintptr_t *image_spec); |
| 211 | void arm_set_fip_addr(uint32_t active_fw_bank_idx); |
Manish V Badarkhe | dd6f252 | 2021-02-22 17:30:17 +0000 | [diff] [blame] | 212 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 213 | /* Security utility functions */ |
Suyash Pathak | b71a9e6 | 2020-02-04 13:55:20 +0530 | [diff] [blame] | 214 | void arm_tzc400_setup(uintptr_t tzc_base, |
| 215 | const arm_tzc_regions_info_t *tzc_regions); |
Vikram Kanigiri | 510d87b | 2016-01-29 12:32:58 +0000 | [diff] [blame] | 216 | struct tzc_dmc500_driver_data; |
Summer Qin | 5ce394c | 2018-03-12 11:28:26 +0800 | [diff] [blame] | 217 | void arm_tzc_dmc500_setup(struct tzc_dmc500_driver_data *plat_driver_data, |
| 218 | const arm_tzc_regions_info_t *tzc_regions); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 219 | |
Antonio Nino Diaz | 23ede6a | 2018-06-19 09:29:36 +0100 | [diff] [blame] | 220 | /* Console utility functions */ |
| 221 | void arm_console_boot_init(void); |
| 222 | void arm_console_boot_end(void); |
| 223 | void arm_console_runtime_init(void); |
| 224 | void arm_console_runtime_end(void); |
| 225 | |
Soby Mathew | 61e8d0b | 2015-10-12 17:32:29 +0100 | [diff] [blame] | 226 | /* Systimer utility function */ |
| 227 | void arm_configure_sys_timer(void); |
| 228 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 229 | /* PM utility functions */ |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 230 | int arm_validate_power_state(unsigned int power_state, |
| 231 | psci_power_state_t *req_state); |
Jeenu Viswambharan | 59424d8 | 2017-09-19 09:27:18 +0100 | [diff] [blame] | 232 | int arm_validate_psci_entrypoint(uintptr_t entrypoint); |
Soby Mathew | 0d9e852 | 2015-07-15 13:36:24 +0100 | [diff] [blame] | 233 | int arm_validate_ns_entrypoint(uintptr_t entrypoint); |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 234 | void arm_system_pwr_domain_save(void); |
Soby Mathew | 61e8d0b | 2015-10-12 17:32:29 +0100 | [diff] [blame] | 235 | void arm_system_pwr_domain_resume(void); |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 236 | int arm_psci_read_mem_protect(int *enabled); |
Roberto Vargas | a1c16b6 | 2017-08-03 09:16:43 +0100 | [diff] [blame] | 237 | int arm_nor_psci_write_mem_protect(int val); |
Roberto Vargas | 550eb08 | 2018-01-05 16:00:05 +0000 | [diff] [blame] | 238 | void arm_nor_psci_do_static_mem_protect(void); |
| 239 | void arm_nor_psci_do_dyn_mem_protect(void); |
Roberto Vargas | a1c16b6 | 2017-08-03 09:16:43 +0100 | [diff] [blame] | 240 | int arm_psci_mem_protect_chk(uintptr_t base, u_register_t length); |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 241 | |
| 242 | /* Topology utility function */ |
| 243 | int arm_check_mpidr(u_register_t mpidr); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 244 | |
| 245 | /* BL1 utility functions */ |
| 246 | void arm_bl1_early_platform_setup(void); |
| 247 | void arm_bl1_platform_setup(void); |
| 248 | void arm_bl1_plat_arch_setup(void); |
| 249 | |
| 250 | /* BL2 utility functions */ |
Manish V Badarkhe | 99a8e14 | 2020-06-11 22:32:11 +0100 | [diff] [blame] | 251 | void arm_bl2_early_platform_setup(uintptr_t fw_config, struct meminfo *mem_layout); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 252 | void arm_bl2_platform_setup(void); |
| 253 | void arm_bl2_plat_arch_setup(void); |
| 254 | uint32_t arm_get_spsr_for_bl32_entry(void); |
| 255 | uint32_t arm_get_spsr_for_bl33_entry(void); |
Ambroise Vincent | b237bca | 2019-02-13 15:58:00 +0000 | [diff] [blame] | 256 | int arm_bl2_plat_handle_post_image_load(unsigned int image_id); |
Yatharth Kochar | ede39cb | 2016-11-14 12:01:04 +0000 | [diff] [blame] | 257 | int arm_bl2_handle_post_image_load(unsigned int image_id); |
Sathees Balya | 9095009 | 2018-11-15 14:22:30 +0000 | [diff] [blame] | 258 | struct bl_params *arm_get_next_bl_params(void); |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 259 | void arm_bl2_setup_next_ep_info(bl_mem_params_node_t *next_param_node); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 260 | |
Roberto Vargas | 5220780 | 2017-11-17 13:22:18 +0000 | [diff] [blame] | 261 | /* BL2 at EL3 functions */ |
| 262 | void arm_bl2_el3_early_platform_setup(void); |
| 263 | void arm_bl2_el3_plat_arch_setup(void); |
| 264 | |
Yatharth Kochar | 3a11eda | 2015-10-14 15:28:11 +0100 | [diff] [blame] | 265 | /* BL2U utility functions */ |
| 266 | void arm_bl2u_early_platform_setup(struct meminfo *mem_layout, |
| 267 | void *plat_info); |
| 268 | void arm_bl2u_platform_setup(void); |
| 269 | void arm_bl2u_plat_arch_setup(void); |
| 270 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 271 | /* BL31 utility functions */ |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 272 | #if TRANSFER_LIST |
| 273 | void arm_bl31_early_platform_setup(u_register_t arg0, u_register_t arg1, |
| 274 | u_register_t arg2, u_register_t arg3); |
| 275 | #else |
Soby Mathew | 7d5a2e7 | 2018-01-10 15:59:31 +0000 | [diff] [blame] | 276 | void arm_bl31_early_platform_setup(void *from_bl2, uintptr_t soc_fw_config, |
| 277 | uintptr_t hw_config, void *plat_params_from_bl2); |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 278 | #endif |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 279 | void arm_bl31_platform_setup(void); |
Soby Mathew | 2fd66be | 2015-12-09 11:38:43 +0000 | [diff] [blame] | 280 | void arm_bl31_plat_runtime_setup(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 281 | void arm_bl31_plat_arch_setup(void); |
| 282 | |
Harrison Mutai | 91ce7c9 | 2023-12-01 15:50:00 +0000 | [diff] [blame] | 283 | /* Firmware Handoff utility functions */ |
| 284 | void arm_transfer_list_dyn_cfg_init(struct transfer_list_header *secure_tl); |
| 285 | void arm_transfer_list_populate_ep_info(bl_mem_params_node_t *next_param_node, |
| 286 | struct transfer_list_header *secure_tl, |
| 287 | struct transfer_list_header *ns_tl); |
| 288 | void arm_transfer_list_copy_hw_config(struct transfer_list_header *secure_tl, |
| 289 | struct transfer_list_header *ns_tl); |
| 290 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 291 | /* TSP utility functions */ |
| 292 | void arm_tsp_early_platform_setup(void); |
| 293 | |
Soby Mathew | 7b75418 | 2016-07-11 14:15:27 +0100 | [diff] [blame] | 294 | /* SP_MIN utility functions */ |
Soby Mathew | 7d5a2e7 | 2018-01-10 15:59:31 +0000 | [diff] [blame] | 295 | void arm_sp_min_early_platform_setup(void *from_bl2, uintptr_t tos_fw_config, |
| 296 | uintptr_t hw_config, void *plat_params_from_bl2); |
Dimitris Papastamos | 52323b0 | 2017-06-07 13:45:41 +0100 | [diff] [blame] | 297 | void arm_sp_min_plat_runtime_setup(void); |
Madhukar Pappireddy | ae9677b | 2020-01-27 13:37:51 -0600 | [diff] [blame] | 298 | void arm_sp_min_plat_arch_setup(void); |
Soby Mathew | 7b75418 | 2016-07-11 14:15:27 +0100 | [diff] [blame] | 299 | |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 300 | /* FIP TOC validity check */ |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 301 | bool arm_io_is_toc_valid(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 302 | |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 303 | /* Utility functions for Dynamic Config */ |
Chris Kay | f3c0fe1 | 2024-02-06 16:03:24 +0000 | [diff] [blame] | 304 | |
John Tsichritzis | c34341a | 2018-07-30 13:41:52 +0100 | [diff] [blame] | 305 | void arm_bl1_set_mbedtls_heap(void); |
| 306 | int arm_get_mbedtls_heap(void **heap_addr, size_t *heap_size); |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 307 | |
Chris Kay | f3c0fe1 | 2024-02-06 16:03:24 +0000 | [diff] [blame] | 308 | #if IMAGE_BL2 |
| 309 | void arm_bl2_dyn_cfg_init(void); |
| 310 | #endif /* IMAGE_BL2 */ |
| 311 | |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 312 | #if MEASURED_BOOT |
Tamas Ban | f879bf1 | 2023-06-12 11:26:28 +0200 | [diff] [blame] | 313 | #if DICE_PROTECTION_ENVIRONMENT |
| 314 | int arm_set_nt_fw_info(int *ctx_handle); |
| 315 | int arm_set_tb_fw_info(int *ctx_handle); |
| 316 | int arm_get_tb_fw_info(int *ctx_handle); |
| 317 | #else |
| 318 | /* Specific to event log backend */ |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 319 | int arm_set_tos_fw_info(uintptr_t log_addr, size_t log_size); |
| 320 | int arm_set_nt_fw_info( |
Alexei Fedorov | c717617 | 2020-07-13 12:11:05 +0100 | [diff] [blame] | 321 | /* |
| 322 | * Currently OP-TEE does not support reading DTBs from Secure memory |
| 323 | * and this option should be removed when feature is supported. |
| 324 | */ |
| 325 | #ifdef SPD_opteed |
| 326 | uintptr_t log_addr, |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 327 | #endif |
Alexei Fedorov | c717617 | 2020-07-13 12:11:05 +0100 | [diff] [blame] | 328 | size_t log_size, uintptr_t *ns_log_addr); |
Manish V Badarkhe | 6e6df44 | 2023-03-20 14:58:06 +0000 | [diff] [blame] | 329 | int arm_set_tb_fw_info(uintptr_t log_addr, size_t log_size, |
| 330 | size_t log_max_size); |
| 331 | int arm_get_tb_fw_info(uint64_t *log_addr, size_t *log_size, |
| 332 | size_t *log_max_size); |
Tamas Ban | f879bf1 | 2023-06-12 11:26:28 +0200 | [diff] [blame] | 333 | #endif /* DICE_PROTECTION_ENVIRONMENT */ |
Alexei Fedorov | c717617 | 2020-07-13 12:11:05 +0100 | [diff] [blame] | 334 | #endif /* MEASURED_BOOT */ |
Alexei Fedorov | 25d7c88 | 2020-03-20 18:38:55 +0000 | [diff] [blame] | 335 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 336 | /* |
Daniel Boulby | b1b058d | 2018-09-18 11:52:49 +0100 | [diff] [blame] | 337 | * Free the memory storing initialization code only used during an images boot |
| 338 | * time so it can be reclaimed for runtime data |
| 339 | */ |
| 340 | void arm_free_init_memory(void); |
| 341 | |
| 342 | /* |
Petre-Ionut Tudor | e5a6fef | 2019-11-07 15:18:03 +0000 | [diff] [blame] | 343 | * Make the higher level translation tables read-only |
| 344 | */ |
| 345 | void arm_xlat_make_tables_readonly(void); |
| 346 | |
| 347 | /* |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 348 | * Mandatory functions required in ARM standard platforms |
| 349 | */ |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 350 | unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr); |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 351 | void plat_arm_gic_driver_init(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 352 | void plat_arm_gic_init(void); |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 353 | void plat_arm_gic_cpuif_enable(void); |
| 354 | void plat_arm_gic_cpuif_disable(void); |
Jeenu Viswambharan | 78132c9 | 2016-12-09 11:12:34 +0000 | [diff] [blame] | 355 | void plat_arm_gic_redistif_on(void); |
| 356 | void plat_arm_gic_redistif_off(void); |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 357 | void plat_arm_gic_pcpu_init(void); |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 358 | void plat_arm_gic_save(void); |
| 359 | void plat_arm_gic_resume(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 360 | void plat_arm_security_setup(void); |
| 361 | void plat_arm_pwrc_setup(void); |
Vikram Kanigiri | fbb1301 | 2016-02-15 11:54:14 +0000 | [diff] [blame] | 362 | void plat_arm_interconnect_init(void); |
| 363 | void plat_arm_interconnect_enter_coherency(void); |
| 364 | void plat_arm_interconnect_exit_coherency(void); |
Dimitris Papastamos | d7a3651 | 2018-06-18 13:01:06 +0100 | [diff] [blame] | 365 | void plat_arm_program_trusted_mailbox(uintptr_t address); |
Louis Mayencourt | 70d7c09 | 2020-01-29 11:42:31 +0000 | [diff] [blame] | 366 | bool plat_arm_bl1_fwu_needed(void); |
Ambroise Vincent | fa42c9e | 2019-07-04 14:58:45 +0100 | [diff] [blame] | 367 | __dead2 void plat_arm_error_handler(int err); |
Manish V Badarkhe | fcfe431 | 2022-07-12 21:48:04 +0100 | [diff] [blame] | 368 | __dead2 void plat_arm_system_reset(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 369 | |
Vijayenthiran Subramaniam | 2dfa764 | 2019-10-11 14:01:25 +0530 | [diff] [blame] | 370 | /* |
Max Shvetsov | 06dba29 | 2019-12-06 11:50:12 +0000 | [diff] [blame] | 371 | * Optional functions in ARM standard platforms |
Vijayenthiran Subramaniam | 2dfa764 | 2019-10-11 14:01:25 +0530 | [diff] [blame] | 372 | */ |
| 373 | void plat_arm_override_gicr_frames(const uintptr_t *plat_gicr_frames); |
Sandrine Bailleux | 7b7a41c | 2020-02-06 14:34:44 +0100 | [diff] [blame] | 374 | int arm_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len, |
Max Shvetsov | 06dba29 | 2019-12-06 11:50:12 +0000 | [diff] [blame] | 375 | unsigned int *flags); |
| 376 | int arm_get_rotpk_info_regs(void **key_ptr, unsigned int *key_len, |
| 377 | unsigned int *flags); |
| 378 | int arm_get_rotpk_info_cc(void **key_ptr, unsigned int *key_len, |
| 379 | unsigned int *flags); |
| 380 | int arm_get_rotpk_info_dev(void **key_ptr, unsigned int *key_len, |
| 381 | unsigned int *flags); |
Vijayenthiran Subramaniam | 2dfa764 | 2019-10-11 14:01:25 +0530 | [diff] [blame] | 382 | |
Summer Qin | 93c812f | 2017-02-28 16:46:17 +0000 | [diff] [blame] | 383 | #if ARM_PLAT_MT |
| 384 | unsigned int plat_arm_get_cpu_pe_count(u_register_t mpidr); |
| 385 | #endif |
| 386 | |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 387 | /* |
| 388 | * This function is called after loading SCP_BL2 image and it is used to perform |
| 389 | * any platform-specific actions required to handle the SCP firmware. |
| 390 | */ |
| 391 | int plat_arm_bl2_handle_scp_bl2(struct image_info *scp_bl2_image_info); |
Yatharth Kochar | f9a0f16 | 2016-09-13 17:07:57 +0100 | [diff] [blame] | 392 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 393 | /* |
| 394 | * Optional functions required in ARM standard platforms |
| 395 | */ |
| 396 | void plat_arm_io_setup(void); |
| 397 | int plat_arm_get_alt_image_source( |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 398 | unsigned int image_id, |
| 399 | uintptr_t *dev_handle, |
| 400 | uintptr_t *image_spec); |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 401 | unsigned int plat_arm_calc_core_pos(u_register_t mpidr); |
Vikram Kanigiri | 0703543 | 2015-11-12 18:52:34 +0000 | [diff] [blame] | 402 | const mmap_region_t *plat_arm_get_mmap(void); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 403 | |
Rohit Mathew | f085b87 | 2023-12-20 17:29:18 +0000 | [diff] [blame] | 404 | const arm_gpt_info_t *plat_arm_get_gpt_info(void); |
Rohit Mathew | f6f02da | 2024-01-21 22:49:08 +0000 | [diff] [blame] | 405 | void arm_gpt_setup(void); |
Rohit Mathew | f085b87 | 2023-12-20 17:29:18 +0000 | [diff] [blame] | 406 | |
Soby Mathew | 0b4c5a3 | 2016-10-21 17:51:22 +0100 | [diff] [blame] | 407 | /* Allow platform to override psci_pm_ops during runtime */ |
| 408 | const plat_psci_ops_t *plat_arm_psci_override_pm_ops(plat_psci_ops_t *ops); |
| 409 | |
Jeenu Viswambharan | bc1a929 | 2017-02-16 14:55:15 +0000 | [diff] [blame] | 410 | /* Execution state switch in ARM platforms */ |
| 411 | int arm_execution_state_switch(unsigned int smc_fid, |
| 412 | uint32_t pc_hi, |
| 413 | uint32_t pc_lo, |
| 414 | uint32_t cookie_hi, |
| 415 | uint32_t cookie_lo, |
| 416 | void *handle); |
| 417 | |
Soby Mathew | 6d07e67 | 2018-03-01 10:53:33 +0000 | [diff] [blame] | 418 | /* Optional functions for SP_MIN */ |
| 419 | void plat_arm_sp_min_early_platform_setup(u_register_t arg0, u_register_t arg1, |
| 420 | u_register_t arg2, u_register_t arg3); |
| 421 | |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 422 | /* global variables */ |
| 423 | extern plat_psci_ops_t plat_arm_psci_pm_ops; |
| 424 | extern const mmap_region_t plat_arm_mmap[]; |
Jeenu Viswambharan | 4542cfe | 2018-07-19 08:03:46 +0100 | [diff] [blame] | 425 | extern const unsigned int arm_pm_idle_states[]; |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 426 | |
Aditya Angadi | 20b4841 | 2019-04-16 11:29:14 +0530 | [diff] [blame] | 427 | /* secure watchdog */ |
| 428 | void plat_arm_secure_wdt_start(void); |
| 429 | void plat_arm_secure_wdt_stop(void); |
Madhukar Pappireddy | e108df2 | 2023-03-22 15:40:40 -0500 | [diff] [blame] | 430 | void plat_arm_secure_wdt_refresh(void); |
Aditya Angadi | 20b4841 | 2019-04-16 11:29:14 +0530 | [diff] [blame] | 431 | |
Manish V Badarkhe | f809c6e | 2020-02-22 08:43:00 +0000 | [diff] [blame] | 432 | /* Get SOC-ID of ARM platform */ |
| 433 | uint32_t plat_arm_get_soc_id(void); |
| 434 | |
Antonio Nino Diaz | 05fdb83 | 2018-10-25 16:53:04 +0100 | [diff] [blame] | 435 | #endif /* PLAT_ARM_H */ |