Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | d782056 | 2019-04-25 13:29:12 +0200 | [diff] [blame] | 2 | * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
| 10 | #include <platform_def.h> |
| 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <common/bl_common.h> |
| 14 | #include <common/debug.h> |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 15 | #include <context.h> |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 16 | #include <drivers/arm/gicv2.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <drivers/arm/tzc400.h> |
| 18 | #include <drivers/generic_delay_timer.h> |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 19 | #include <drivers/st/bsec.h> |
Etienne Carriere | e96162e | 2020-04-10 11:32:54 +0200 | [diff] [blame] | 20 | #include <drivers/st/etzpc.h> |
Yann Gautier | 14d769c | 2019-01-18 11:13:15 +0100 | [diff] [blame] | 21 | #include <drivers/st/stm32_gpio.h> |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 22 | #include <drivers/st/stm32_iwdg.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | #include <drivers/st/stm32mp1_clk.h> |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 24 | #include <dt-bindings/clock/stm32mp1-clks.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 25 | #include <lib/el3_runtime/context_mgmt.h> |
| 26 | #include <lib/mmio.h> |
| 27 | #include <lib/xlat_tables/xlat_tables_v2.h> |
| 28 | #include <plat/common/platform.h> |
| 29 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 30 | #include <platform_sp_min.h> |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 31 | |
| 32 | /****************************************************************************** |
| 33 | * Placeholder variables for copying the arguments that have been passed to |
| 34 | * BL32 from BL2. |
| 35 | ******************************************************************************/ |
| 36 | static entry_point_info_t bl33_image_ep_info; |
| 37 | |
| 38 | /******************************************************************************* |
| 39 | * Interrupt handler for FIQ (secure IRQ) |
| 40 | ******************************************************************************/ |
| 41 | void sp_min_plat_fiq_handler(uint32_t id) |
| 42 | { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 43 | switch (id & INT_ID_MASK) { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 44 | case STM32MP1_IRQ_TZC400: |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 45 | tzc400_init(STM32MP1_TZC_BASE); |
Yann Gautier | d782056 | 2019-04-25 13:29:12 +0200 | [diff] [blame] | 46 | (void)tzc400_it_handler(); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 47 | panic(); |
| 48 | break; |
| 49 | case STM32MP1_IRQ_AXIERRIRQ: |
| 50 | ERROR("STM32MP1_IRQ_AXIERRIRQ generated\n"); |
| 51 | panic(); |
| 52 | break; |
| 53 | default: |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 54 | ERROR("SECURE IT handler not define for it : %u", id); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /******************************************************************************* |
| 60 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 61 | * the security state specified. BL33 corresponds to the non-secure image type |
| 62 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 63 | * if the image does not exist. |
| 64 | ******************************************************************************/ |
| 65 | entry_point_info_t *sp_min_plat_get_bl33_ep_info(void) |
| 66 | { |
| 67 | entry_point_info_t *next_image_info; |
| 68 | |
| 69 | next_image_info = &bl33_image_ep_info; |
| 70 | |
| 71 | if (next_image_info->pc == 0U) { |
| 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | return next_image_info; |
| 76 | } |
| 77 | |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 78 | CASSERT((STM32MP_SEC_SYSRAM_BASE == STM32MP_SYSRAM_BASE) && |
| 79 | ((STM32MP_SEC_SYSRAM_BASE + STM32MP_SEC_SYSRAM_SIZE) <= |
| 80 | (STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE)), |
| 81 | assert_secure_sysram_fits_at_begining_of_sysram); |
| 82 | |
| 83 | #ifdef STM32MP_NS_SYSRAM_BASE |
| 84 | CASSERT((STM32MP_NS_SYSRAM_BASE >= STM32MP_SEC_SYSRAM_BASE) && |
| 85 | ((STM32MP_NS_SYSRAM_BASE + STM32MP_NS_SYSRAM_SIZE) == |
| 86 | (STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE)), |
| 87 | assert_non_secure_sysram_fits_at_end_of_sysram); |
| 88 | |
| 89 | CASSERT((STM32MP_NS_SYSRAM_BASE & (PAGE_SIZE_4KB - U(1))) == 0U, |
| 90 | assert_non_secure_sysram_base_is_4kbyte_aligned); |
| 91 | |
| 92 | #define TZMA1_SECURE_RANGE \ |
| 93 | (((STM32MP_NS_SYSRAM_BASE - STM32MP_SYSRAM_BASE) >> FOUR_KB_SHIFT) - 1U) |
| 94 | #else |
Etienne Carriere | e96162e | 2020-04-10 11:32:54 +0200 | [diff] [blame] | 95 | #define TZMA1_SECURE_RANGE STM32MP1_ETZPC_TZMA_ALL_SECURE |
Etienne Carriere | 72369b1 | 2019-12-08 08:17:56 +0100 | [diff] [blame] | 96 | #endif /* STM32MP_NS_SYSRAM_BASE */ |
Etienne Carriere | e96162e | 2020-04-10 11:32:54 +0200 | [diff] [blame] | 97 | #define TZMA0_SECURE_RANGE STM32MP1_ETZPC_TZMA_ALL_SECURE |
| 98 | |
| 99 | static void stm32mp1_etzpc_early_setup(void) |
| 100 | { |
Etienne Carriere | e96162e | 2020-04-10 11:32:54 +0200 | [diff] [blame] | 101 | if (etzpc_init() != 0) { |
| 102 | panic(); |
| 103 | } |
| 104 | |
| 105 | etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_ROM, TZMA0_SECURE_RANGE); |
| 106 | etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_SYSRAM, TZMA1_SECURE_RANGE); |
Etienne Carriere | e96162e | 2020-04-10 11:32:54 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 109 | /******************************************************************************* |
| 110 | * Perform any BL32 specific platform actions. |
| 111 | ******************************************************************************/ |
| 112 | void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 113 | u_register_t arg2, u_register_t arg3) |
| 114 | { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 115 | bl_params_t *params_from_bl2 = (bl_params_t *)arg0; |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 116 | #if STM32MP_USE_STM32IMAGE |
| 117 | uintptr_t dt_addr = STM32MP_DTB_BASE; |
| 118 | #else |
| 119 | uintptr_t dt_addr = arg1; |
| 120 | #endif |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 121 | |
| 122 | /* Imprecise aborts can be masked in NonSecure */ |
| 123 | write_scr(read_scr() | SCR_AW_BIT); |
| 124 | |
Yann Gautier | 7ffe84b | 2019-07-11 10:45:09 +0200 | [diff] [blame] | 125 | mmap_add_region(BL_CODE_BASE, BL_CODE_BASE, |
| 126 | BL_CODE_END - BL_CODE_BASE, |
| 127 | MT_CODE | MT_SECURE); |
| 128 | |
| 129 | configure_mmu(); |
| 130 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 131 | assert(params_from_bl2 != NULL); |
| 132 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 133 | assert(params_from_bl2->h.version >= VERSION_2); |
| 134 | |
| 135 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 136 | |
| 137 | /* |
| 138 | * Copy BL33 entry point information. |
| 139 | * They are stored in Secure RAM, in BL2's address space. |
| 140 | */ |
| 141 | while (bl_params != NULL) { |
| 142 | if (bl_params->image_id == BL33_IMAGE_ID) { |
| 143 | bl33_image_ep_info = *bl_params->ep_info; |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 144 | /* |
| 145 | * Check if hw_configuration is given to BL32 and |
| 146 | * share it to BL33. |
| 147 | */ |
| 148 | if (arg2 != 0U) { |
| 149 | bl33_image_ep_info.args.arg0 = 0U; |
| 150 | bl33_image_ep_info.args.arg1 = 0U; |
| 151 | bl33_image_ep_info.args.arg2 = arg2; |
| 152 | } |
| 153 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 154 | break; |
| 155 | } |
| 156 | |
| 157 | bl_params = bl_params->next_params_info; |
| 158 | } |
| 159 | |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame] | 160 | if (dt_open_and_check(dt_addr) < 0) { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 161 | panic(); |
| 162 | } |
| 163 | |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 164 | if (bsec_probe() != 0) { |
| 165 | panic(); |
| 166 | } |
| 167 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 168 | if (stm32mp1_clk_probe() < 0) { |
| 169 | panic(); |
| 170 | } |
| 171 | |
Yann Gautier | 414f17c | 2021-10-18 15:50:05 +0200 | [diff] [blame] | 172 | (void)stm32mp_uart_console_setup(); |
Etienne Carriere | e96162e | 2020-04-10 11:32:54 +0200 | [diff] [blame] | 173 | |
| 174 | stm32mp1_etzpc_early_setup(); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /******************************************************************************* |
| 178 | * Initialize the MMU, security and the GIC. |
| 179 | ******************************************************************************/ |
| 180 | void sp_min_platform_setup(void) |
| 181 | { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 182 | generic_delay_timer_init(); |
| 183 | |
| 184 | stm32mp1_gic_init(); |
Yann Gautier | 14d769c | 2019-01-18 11:13:15 +0100 | [diff] [blame] | 185 | |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 186 | if (stm32_iwdg_init() < 0) { |
| 187 | panic(); |
| 188 | } |
Etienne Carriere | 7a4a34f | 2020-05-13 10:07:45 +0200 | [diff] [blame] | 189 | |
| 190 | stm32mp_lock_periph_registering(); |
Etienne Carriere | 34f0e93 | 2020-07-16 17:36:18 +0200 | [diff] [blame] | 191 | |
| 192 | stm32mp1_init_scmi_server(); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | void sp_min_plat_arch_setup(void) |
| 196 | { |
| 197 | } |