Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, 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> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 20 | #include <drivers/st/stm32_console.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 | |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 38 | static struct console_stm32 console; |
| 39 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 40 | /******************************************************************************* |
| 41 | * Interrupt handler for FIQ (secure IRQ) |
| 42 | ******************************************************************************/ |
| 43 | void sp_min_plat_fiq_handler(uint32_t id) |
| 44 | { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 45 | switch (id & INT_ID_MASK) { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 46 | case STM32MP1_IRQ_TZC400: |
| 47 | ERROR("STM32MP1_IRQ_TZC400 generated\n"); |
| 48 | panic(); |
| 49 | break; |
| 50 | case STM32MP1_IRQ_AXIERRIRQ: |
| 51 | ERROR("STM32MP1_IRQ_AXIERRIRQ generated\n"); |
| 52 | panic(); |
| 53 | break; |
| 54 | default: |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 55 | ERROR("SECURE IT handler not define for it : %u", id); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 56 | break; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /******************************************************************************* |
| 61 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 62 | * the security state specified. BL33 corresponds to the non-secure image type |
| 63 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 64 | * if the image does not exist. |
| 65 | ******************************************************************************/ |
| 66 | entry_point_info_t *sp_min_plat_get_bl33_ep_info(void) |
| 67 | { |
| 68 | entry_point_info_t *next_image_info; |
| 69 | |
| 70 | next_image_info = &bl33_image_ep_info; |
| 71 | |
| 72 | if (next_image_info->pc == 0U) { |
| 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | return next_image_info; |
| 77 | } |
| 78 | |
| 79 | /******************************************************************************* |
| 80 | * Perform any BL32 specific platform actions. |
| 81 | ******************************************************************************/ |
| 82 | void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 83 | u_register_t arg2, u_register_t arg3) |
| 84 | { |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 85 | struct dt_node_info dt_uart_info; |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 86 | int result; |
| 87 | bl_params_t *params_from_bl2 = (bl_params_t *)arg0; |
| 88 | |
| 89 | /* Imprecise aborts can be masked in NonSecure */ |
| 90 | write_scr(read_scr() | SCR_AW_BIT); |
| 91 | |
Yann Gautier | 7ffe84b | 2019-07-11 10:45:09 +0200 | [diff] [blame] | 92 | mmap_add_region(BL_CODE_BASE, BL_CODE_BASE, |
| 93 | BL_CODE_END - BL_CODE_BASE, |
| 94 | MT_CODE | MT_SECURE); |
| 95 | |
| 96 | configure_mmu(); |
| 97 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 98 | assert(params_from_bl2 != NULL); |
| 99 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 100 | assert(params_from_bl2->h.version >= VERSION_2); |
| 101 | |
| 102 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 103 | |
| 104 | /* |
| 105 | * Copy BL33 entry point information. |
| 106 | * They are stored in Secure RAM, in BL2's address space. |
| 107 | */ |
| 108 | while (bl_params != NULL) { |
| 109 | if (bl_params->image_id == BL33_IMAGE_ID) { |
| 110 | bl33_image_ep_info = *bl_params->ep_info; |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | bl_params = bl_params->next_params_info; |
| 115 | } |
| 116 | |
| 117 | if (dt_open_and_check() < 0) { |
| 118 | panic(); |
| 119 | } |
| 120 | |
Yann Gautier | 52448ab | 2019-01-17 14:53:24 +0100 | [diff] [blame] | 121 | if (bsec_probe() != 0) { |
| 122 | panic(); |
| 123 | } |
| 124 | |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 125 | if (stm32mp1_clk_probe() < 0) { |
| 126 | panic(); |
| 127 | } |
| 128 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 129 | result = dt_get_stdout_uart_info(&dt_uart_info); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 130 | |
Yann Gautier | 038bff2 | 2019-01-17 19:17:47 +0100 | [diff] [blame] | 131 | if ((result > 0) && (dt_uart_info.status != 0U)) { |
Yann Gautier | a30e5f7 | 2019-09-04 11:55:10 +0200 | [diff] [blame] | 132 | unsigned int console_flags; |
| 133 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 134 | if (console_stm32_register(dt_uart_info.base, 0, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 135 | STM32MP_UART_BAUDRATE, &console) == |
Yann Gautier | 8593e44 | 2018-11-14 18:46:15 +0100 | [diff] [blame] | 136 | 0) { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 137 | panic(); |
| 138 | } |
Yann Gautier | 738df26 | 2019-04-24 16:14:22 +0200 | [diff] [blame] | 139 | |
Yann Gautier | a30e5f7 | 2019-09-04 11:55:10 +0200 | [diff] [blame] | 140 | console_flags = CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH | |
| 141 | CONSOLE_FLAG_TRANSLATE_CRLF; |
Yann Gautier | 738df26 | 2019-04-24 16:14:22 +0200 | [diff] [blame] | 142 | #ifdef DEBUG |
Yann Gautier | a30e5f7 | 2019-09-04 11:55:10 +0200 | [diff] [blame] | 143 | console_flags |= CONSOLE_FLAG_RUNTIME; |
Yann Gautier | 738df26 | 2019-04-24 16:14:22 +0200 | [diff] [blame] | 144 | #endif |
Yann Gautier | a30e5f7 | 2019-09-04 11:55:10 +0200 | [diff] [blame] | 145 | console_set_scope(&console.console, console_flags); |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | /******************************************************************************* |
| 150 | * Initialize the MMU, security and the GIC. |
| 151 | ******************************************************************************/ |
| 152 | void sp_min_platform_setup(void) |
| 153 | { |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 154 | /* Initialize tzc400 after DDR initialization */ |
| 155 | stm32mp1_security_setup(); |
| 156 | |
| 157 | generic_delay_timer_init(); |
| 158 | |
| 159 | stm32mp1_gic_init(); |
Yann Gautier | 14d769c | 2019-01-18 11:13:15 +0100 | [diff] [blame] | 160 | |
| 161 | /* Unlock ETZPC securable peripherals */ |
| 162 | #define STM32MP1_ETZPC_BASE 0x5C007000U |
| 163 | #define ETZPC_DECPROT0 0x010U |
| 164 | mmio_write_32(STM32MP1_ETZPC_BASE + ETZPC_DECPROT0, 0xFFFFFFFF); |
| 165 | |
| 166 | /* Set GPIO bank Z as non secure */ |
| 167 | for (uint32_t pin = 0U; pin < STM32MP_GPIOZ_PIN_MAX_COUNT; pin++) { |
| 168 | set_gpio_secure_cfg(GPIO_BANK_Z, pin, false); |
| 169 | } |
Yann Gautier | 091eab5 | 2019-06-04 18:06:34 +0200 | [diff] [blame] | 170 | |
| 171 | if (stm32_iwdg_init() < 0) { |
| 172 | panic(); |
| 173 | } |
Yann Gautier | 9d135e4 | 2018-07-16 19:36:06 +0200 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void sp_min_plat_arch_setup(void) |
| 177 | { |
| 178 | } |