sp_min_setup.c 5.83 KB
Newer Older
1
/*
Yann Gautier's avatar
Yann Gautier committed
2
 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
8
9
10
11
12
13
14
#include <string.h>

#include <platform_def.h>

#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
15
#include <context.h>
Yann Gautier's avatar
Yann Gautier committed
16
#include <drivers/arm/gicv2.h>
17
18
#include <drivers/arm/tzc400.h>
#include <drivers/generic_delay_timer.h>
Yann Gautier's avatar
Yann Gautier committed
19
#include <drivers/st/bsec.h>
20
#include <drivers/st/etzpc.h>
21
#include <drivers/st/stm32_console.h>
22
#include <drivers/st/stm32_gpio.h>
Yann Gautier's avatar
Yann Gautier committed
23
#include <drivers/st/stm32_iwdg.h>
24
#include <drivers/st/stm32mp1_clk.h>
25
#include <dt-bindings/clock/stm32mp1-clks.h>
26
27
28
29
30
#include <lib/el3_runtime/context_mgmt.h>
#include <lib/mmio.h>
#include <lib/xlat_tables/xlat_tables_v2.h>
#include <plat/common/platform.h>

31
32
33
34
35
36
37
38
#include <platform_sp_min.h>

/******************************************************************************
 * Placeholder variables for copying the arguments that have been passed to
 * BL32 from BL2.
 ******************************************************************************/
static entry_point_info_t bl33_image_ep_info;

39
static console_t console;
Yann Gautier's avatar
Yann Gautier committed
40

41
42
43
44
45
/*******************************************************************************
 * Interrupt handler for FIQ (secure IRQ)
 ******************************************************************************/
void sp_min_plat_fiq_handler(uint32_t id)
{
Yann Gautier's avatar
Yann Gautier committed
46
	switch (id & INT_ID_MASK) {
47
48
49
50
51
52
53
54
55
	case STM32MP1_IRQ_TZC400:
		ERROR("STM32MP1_IRQ_TZC400 generated\n");
		panic();
		break;
	case STM32MP1_IRQ_AXIERRIRQ:
		ERROR("STM32MP1_IRQ_AXIERRIRQ generated\n");
		panic();
		break;
	default:
Yann Gautier's avatar
Yann Gautier committed
56
		ERROR("SECURE IT handler not define for it : %u", id);
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
		break;
	}
}

/*******************************************************************************
 * Return a pointer to the 'entry_point_info' structure of the next image for
 * the security state specified. BL33 corresponds to the non-secure image type
 * while BL32 corresponds to the secure image type. A NULL pointer is returned
 * if the image does not exist.
 ******************************************************************************/
entry_point_info_t *sp_min_plat_get_bl33_ep_info(void)
{
	entry_point_info_t *next_image_info;

	next_image_info = &bl33_image_ep_info;

	if (next_image_info->pc == 0U) {
		return NULL;
	}

	return next_image_info;
}

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
CASSERT((STM32MP_SEC_SYSRAM_BASE == STM32MP_SYSRAM_BASE) &&
	((STM32MP_SEC_SYSRAM_BASE + STM32MP_SEC_SYSRAM_SIZE) <=
	 (STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE)),
	assert_secure_sysram_fits_at_begining_of_sysram);

#ifdef STM32MP_NS_SYSRAM_BASE
CASSERT((STM32MP_NS_SYSRAM_BASE >= STM32MP_SEC_SYSRAM_BASE) &&
	((STM32MP_NS_SYSRAM_BASE + STM32MP_NS_SYSRAM_SIZE) ==
	 (STM32MP_SYSRAM_BASE + STM32MP_SYSRAM_SIZE)),
	assert_non_secure_sysram_fits_at_end_of_sysram);

CASSERT((STM32MP_NS_SYSRAM_BASE & (PAGE_SIZE_4KB - U(1))) == 0U,
	assert_non_secure_sysram_base_is_4kbyte_aligned);

#define TZMA1_SECURE_RANGE \
	(((STM32MP_NS_SYSRAM_BASE - STM32MP_SYSRAM_BASE) >> FOUR_KB_SHIFT) - 1U)
#else
97
#define TZMA1_SECURE_RANGE		STM32MP1_ETZPC_TZMA_ALL_SECURE
98
#endif /* STM32MP_NS_SYSRAM_BASE */
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#define TZMA0_SECURE_RANGE		STM32MP1_ETZPC_TZMA_ALL_SECURE

static void stm32mp1_etzpc_early_setup(void)
{
	unsigned int n;

	if (etzpc_init() != 0) {
		panic();
	}

	etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_ROM, TZMA0_SECURE_RANGE);
	etzpc_configure_tzma(STM32MP1_ETZPC_TZMA_SYSRAM, TZMA1_SECURE_RANGE);

	/* Release security on all shared resources */
	for (n = 0; n < STM32MP1_ETZPC_SEC_ID_LIMIT; n++) {
		etzpc_configure_decprot(n, ETZPC_DECPROT_NS_RW);
	}
}

118
119
120
121
122
123
/*******************************************************************************
 * Perform any BL32 specific platform actions.
 ******************************************************************************/
void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1,
				  u_register_t arg2, u_register_t arg3)
{
Yann Gautier's avatar
Yann Gautier committed
124
	struct dt_node_info dt_uart_info;
125
126
127
128
129
130
	int result;
	bl_params_t *params_from_bl2 = (bl_params_t *)arg0;

	/* Imprecise aborts can be masked in NonSecure */
	write_scr(read_scr() | SCR_AW_BIT);

131
132
133
134
135
136
	mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
			BL_CODE_END - BL_CODE_BASE,
			MT_CODE | MT_SECURE);

	configure_mmu();

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	assert(params_from_bl2 != NULL);
	assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
	assert(params_from_bl2->h.version >= VERSION_2);

	bl_params_node_t *bl_params = params_from_bl2->head;

	/*
	 * Copy BL33 entry point information.
	 * They are stored in Secure RAM, in BL2's address space.
	 */
	while (bl_params != NULL) {
		if (bl_params->image_id == BL33_IMAGE_ID) {
			bl33_image_ep_info = *bl_params->ep_info;
			break;
		}

		bl_params = bl_params->next_params_info;
	}

	if (dt_open_and_check() < 0) {
		panic();
	}

Yann Gautier's avatar
Yann Gautier committed
160
161
162
163
	if (bsec_probe() != 0) {
		panic();
	}

164
165
166
167
	if (stm32mp1_clk_probe() < 0) {
		panic();
	}

Yann Gautier's avatar
Yann Gautier committed
168
	result = dt_get_stdout_uart_info(&dt_uart_info);
169

170
	if ((result > 0) && (dt_uart_info.status != 0U)) {
171
172
		unsigned int console_flags;

Yann Gautier's avatar
Yann Gautier committed
173
		if (console_stm32_register(dt_uart_info.base, 0,
174
					   STM32MP_UART_BAUDRATE, &console) ==
Yann Gautier's avatar
Yann Gautier committed
175
		    0) {
176
177
			panic();
		}
178

179
180
		console_flags = CONSOLE_FLAG_BOOT | CONSOLE_FLAG_CRASH |
			CONSOLE_FLAG_TRANSLATE_CRLF;
181
#ifdef DEBUG
182
		console_flags |= CONSOLE_FLAG_RUNTIME;
183
#endif
184
		console_set_scope(&console, console_flags);
185
	}
186
187

	stm32mp1_etzpc_early_setup();
188
189
190
191
192
193
194
195
196
197
198
199
200
}

/*******************************************************************************
 * Initialize the MMU, security and the GIC.
 ******************************************************************************/
void sp_min_platform_setup(void)
{
	/* Initialize tzc400 after DDR initialization */
	stm32mp1_security_setup();

	generic_delay_timer_init();

	stm32mp1_gic_init();
201
202
203
204
205

	/* Set GPIO bank Z as non secure */
	for (uint32_t pin = 0U; pin < STM32MP_GPIOZ_PIN_MAX_COUNT; pin++) {
		set_gpio_secure_cfg(GPIO_BANK_Z, pin, false);
	}
Yann Gautier's avatar
Yann Gautier committed
206
207
208
209

	if (stm32_iwdg_init() < 0) {
		panic();
	}
210
211
212
213
214
}

void sp_min_plat_arch_setup(void)
{
}