blob: e2c2b20609d2897a11cb7357297be21cb5f5f80e [file] [log] [blame]
Yann Gautier9d135e42018-07-16 19:36:06 +02001/*
Yann Gautierf9d40d52019-01-17 14:41:46 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Yann Gautier9d135e42018-07-16 19:36:06 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Yann Gautier9d135e42018-07-16 19:36:06 +02007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#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 Gautier9d135e42018-07-16 19:36:06 +020015#include <context.h>
Yann Gautierf9d40d52019-01-17 14:41:46 +010016#include <drivers/arm/gicv2.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <drivers/arm/tzc400.h>
18#include <drivers/generic_delay_timer.h>
Yann Gautier52448ab2019-01-17 14:53:24 +010019#include <drivers/st/bsec.h>
Etienne Carrieree96162e2020-04-10 11:32:54 +020020#include <drivers/st/etzpc.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021#include <drivers/st/stm32_console.h>
Yann Gautier14d769c2019-01-18 11:13:15 +010022#include <drivers/st/stm32_gpio.h>
Yann Gautier091eab52019-06-04 18:06:34 +020023#include <drivers/st/stm32_iwdg.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000024#include <drivers/st/stm32mp1_clk.h>
Yann Gautier9d135e42018-07-16 19:36:06 +020025#include <dt-bindings/clock/stm32mp1-clks.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000026#include <lib/el3_runtime/context_mgmt.h>
27#include <lib/mmio.h>
28#include <lib/xlat_tables/xlat_tables_v2.h>
29#include <plat/common/platform.h>
30
Yann Gautier9d135e42018-07-16 19:36:06 +020031#include <platform_sp_min.h>
Yann Gautier9d135e42018-07-16 19:36:06 +020032
33/******************************************************************************
34 * Placeholder variables for copying the arguments that have been passed to
35 * BL32 from BL2.
36 ******************************************************************************/
37static entry_point_info_t bl33_image_ep_info;
38
Andre Przywara678c6fa2020-01-25 00:58:35 +000039static console_t console;
Yann Gautier8593e442018-11-14 18:46:15 +010040
Yann Gautier9d135e42018-07-16 19:36:06 +020041/*******************************************************************************
42 * Interrupt handler for FIQ (secure IRQ)
43 ******************************************************************************/
44void sp_min_plat_fiq_handler(uint32_t id)
45{
Yann Gautierf9d40d52019-01-17 14:41:46 +010046 switch (id & INT_ID_MASK) {
Yann Gautier9d135e42018-07-16 19:36:06 +020047 case STM32MP1_IRQ_TZC400:
48 ERROR("STM32MP1_IRQ_TZC400 generated\n");
49 panic();
50 break;
51 case STM32MP1_IRQ_AXIERRIRQ:
52 ERROR("STM32MP1_IRQ_AXIERRIRQ generated\n");
53 panic();
54 break;
55 default:
Yann Gautierf9d40d52019-01-17 14:41:46 +010056 ERROR("SECURE IT handler not define for it : %u", id);
Yann Gautier9d135e42018-07-16 19:36:06 +020057 break;
58 }
59}
60
61/*******************************************************************************
62 * Return a pointer to the 'entry_point_info' structure of the next image for
63 * the security state specified. BL33 corresponds to the non-secure image type
64 * while BL32 corresponds to the secure image type. A NULL pointer is returned
65 * if the image does not exist.
66 ******************************************************************************/
67entry_point_info_t *sp_min_plat_get_bl33_ep_info(void)
68{
69 entry_point_info_t *next_image_info;
70
71 next_image_info = &bl33_image_ep_info;
72
73 if (next_image_info->pc == 0U) {
74 return NULL;
75 }
76
77 return next_image_info;
78}
79
Etienne Carrieree96162e2020-04-10 11:32:54 +020080#define TZMA1_SECURE_RANGE STM32MP1_ETZPC_TZMA_ALL_SECURE
81#define TZMA0_SECURE_RANGE STM32MP1_ETZPC_TZMA_ALL_SECURE
82
83static void stm32mp1_etzpc_early_setup(void)
84{
Etienne Carrieree96162e2020-04-10 11:32:54 +020085 if (etzpc_init() != 0) {
86 panic();
87 }
88
89 etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_ROM, TZMA0_SECURE_RANGE);
90 etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_SYSRAM, TZMA1_SECURE_RANGE);
Etienne Carrieree96162e2020-04-10 11:32:54 +020091}
92
Yann Gautier9d135e42018-07-16 19:36:06 +020093/*******************************************************************************
94 * Perform any BL32 specific platform actions.
95 ******************************************************************************/
96void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1,
97 u_register_t arg2, u_register_t arg3)
98{
Yann Gautierf9d40d52019-01-17 14:41:46 +010099 struct dt_node_info dt_uart_info;
Yann Gautier9d135e42018-07-16 19:36:06 +0200100 int result;
101 bl_params_t *params_from_bl2 = (bl_params_t *)arg0;
102
103 /* Imprecise aborts can be masked in NonSecure */
104 write_scr(read_scr() | SCR_AW_BIT);
105
Yann Gautier7ffe84b2019-07-11 10:45:09 +0200106 mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
107 BL_CODE_END - BL_CODE_BASE,
108 MT_CODE | MT_SECURE);
109
110 configure_mmu();
111
Yann Gautier9d135e42018-07-16 19:36:06 +0200112 assert(params_from_bl2 != NULL);
113 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
114 assert(params_from_bl2->h.version >= VERSION_2);
115
116 bl_params_node_t *bl_params = params_from_bl2->head;
117
118 /*
119 * Copy BL33 entry point information.
120 * They are stored in Secure RAM, in BL2's address space.
121 */
122 while (bl_params != NULL) {
123 if (bl_params->image_id == BL33_IMAGE_ID) {
124 bl33_image_ep_info = *bl_params->ep_info;
125 break;
126 }
127
128 bl_params = bl_params->next_params_info;
129 }
130
131 if (dt_open_and_check() < 0) {
132 panic();
133 }
134
Yann Gautier52448ab2019-01-17 14:53:24 +0100135 if (bsec_probe() != 0) {
136 panic();
137 }
138
Yann Gautier9d135e42018-07-16 19:36:06 +0200139 if (stm32mp1_clk_probe() < 0) {
140 panic();
141 }
142
Yann Gautierf9d40d52019-01-17 14:41:46 +0100143 result = dt_get_stdout_uart_info(&dt_uart_info);
Yann Gautier9d135e42018-07-16 19:36:06 +0200144
Yann Gautier038bff22019-01-17 19:17:47 +0100145 if ((result > 0) && (dt_uart_info.status != 0U)) {
Yann Gautiera30e5f72019-09-04 11:55:10 +0200146 unsigned int console_flags;
147
Yann Gautierf9d40d52019-01-17 14:41:46 +0100148 if (console_stm32_register(dt_uart_info.base, 0,
Yann Gautiera2e2a302019-02-14 11:13:39 +0100149 STM32MP_UART_BAUDRATE, &console) ==
Yann Gautier8593e442018-11-14 18:46:15 +0100150 0) {
Yann Gautier9d135e42018-07-16 19:36:06 +0200151 panic();
152 }
Yann Gautier738df262019-04-24 16:14:22 +0200153
Yann Gautiera30e5f72019-09-04 11:55:10 +0200154 console_flags = CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH |
155 CONSOLE_FLAG_TRANSLATE_CRLF;
Yann Gautier738df262019-04-24 16:14:22 +0200156#ifdef DEBUG
Yann Gautiera30e5f72019-09-04 11:55:10 +0200157 console_flags |= CONSOLE_FLAG_RUNTIME;
Yann Gautier738df262019-04-24 16:14:22 +0200158#endif
Andre Przywara678c6fa2020-01-25 00:58:35 +0000159 console_set_scope(&console, console_flags);
Yann Gautier9d135e42018-07-16 19:36:06 +0200160 }
Etienne Carrieree96162e2020-04-10 11:32:54 +0200161
162 stm32mp1_etzpc_early_setup();
Yann Gautier9d135e42018-07-16 19:36:06 +0200163}
164
165/*******************************************************************************
166 * Initialize the MMU, security and the GIC.
167 ******************************************************************************/
168void sp_min_platform_setup(void)
169{
Yann Gautier9d135e42018-07-16 19:36:06 +0200170 /* Initialize tzc400 after DDR initialization */
171 stm32mp1_security_setup();
172
173 generic_delay_timer_init();
174
175 stm32mp1_gic_init();
Yann Gautier14d769c2019-01-18 11:13:15 +0100176
Yann Gautier091eab52019-06-04 18:06:34 +0200177 if (stm32_iwdg_init() < 0) {
178 panic();
179 }
Etienne Carriere7a4a34f2020-05-13 10:07:45 +0200180
181 stm32mp_lock_periph_registering();
Yann Gautier9d135e42018-07-16 19:36:06 +0200182}
183
184void sp_min_plat_arch_setup(void)
185{
186}