blob: 46c2dc284f3af0b7c91abb15be98e86a1688b81f [file] [log] [blame]
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +00001/*
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +00002 * Copyright (c) 2018-2025, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +00006#include <assert.h>
7#include <common/bl_common.h>
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +00008#ifdef AML_STDPARAMS
9#include <common/desc_image_load.h>
10#endif
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000011#include <common/interrupt_props.h>
Carlo Caioneb5621872019-09-03 12:38:58 +010012#include <drivers/arm/gicv2.h>
Remi Pommarel43d4a292019-04-04 23:12:56 +020013#include <lib/mmio.h>
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000014#include <lib/xlat_tables/xlat_mmu_helpers.h>
Carlo Caioneb5621872019-09-03 12:38:58 +010015#include <plat/common/platform.h>
16#include <platform_def.h>
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000017
Carlo Caionee26864a2019-08-24 17:31:51 +010018#include "aml_private.h"
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000019
20/*
21 * Placeholder variables for copying the arguments that have been passed to
22 * BL31 from BL2.
23 */
24static entry_point_info_t bl33_image_ep_info;
Remi Pommarel327ad292019-03-28 20:55:13 +010025static image_info_t bl30_image_info;
26static image_info_t bl301_image_info;
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000027
28/*******************************************************************************
29 * Return a pointer to the 'entry_point_info' structure of the next image for
30 * the security state specified. BL33 corresponds to the non-secure image type
31 * while BL32 corresponds to the secure image type. A NULL pointer is returned
32 * if the image does not exist.
33 ******************************************************************************/
34entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
35{
36 entry_point_info_t *next_image_info;
37
38 assert(type == NON_SECURE);
39
40 next_image_info = &bl33_image_ep_info;
41
42 /* None of the images can have 0x0 as the entrypoint. */
43 if (next_image_info->pc != 0U) {
44 return next_image_info;
45 } else {
46 return NULL;
47 }
48}
49
50/*******************************************************************************
51 * Perform any BL31 early platform setup. Here is an opportunity to copy
52 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
53 * they are lost (potentially). This needs to be done before the MMU is
54 * initialized so that the memory layout can be used while creating page
55 * tables. BL2 has flushed this information to memory, so we are guaranteed
56 * to pick up good data.
57 ******************************************************************************/
Remi Pommarel327ad292019-03-28 20:55:13 +010058struct gxl_bl31_param {
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000059 param_header_t h;
60 image_info_t *bl31_image_info;
61 entry_point_info_t *bl32_ep_info;
62 image_info_t *bl32_image_info;
63 entry_point_info_t *bl33_ep_info;
64 image_info_t *bl33_image_info;
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +000065#ifndef AML_STDPARAMS
Remi Pommarel327ad292019-03-28 20:55:13 +010066 image_info_t *scp_image_info[];
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +000067#endif
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000068};
69
70void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
71 u_register_t arg2, u_register_t arg3)
72{
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +000073#ifndef AML_STDPARAMS
Remi Pommarel327ad292019-03-28 20:55:13 +010074 struct gxl_bl31_param *from_bl2;
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +000075#endif
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000076
77 /* Initialize the console to provide early debug support */
Carlo Caione010fdc12019-08-25 18:09:03 +010078 aml_console_init();
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000079
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +000080#ifdef AML_STDPARAMS
81 /* Parse arguments passed to BL31 from U-Boot SPL */
82 bl31_params_parse_helper(arg0, &bl33_image_ep_info,
83 &bl33_image_ep_info);
84#else
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000085 /* Check that params passed from BL2 are not NULL. */
Remi Pommarel327ad292019-03-28 20:55:13 +010086 from_bl2 = (struct gxl_bl31_param *) arg0;
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000087
88 /* Check params passed from BL2 are not NULL. */
89 assert(from_bl2 != NULL);
90 assert(from_bl2->h.type == PARAM_BL31);
91 assert(from_bl2->h.version >= VERSION_1);
92
93 /*
94 * Copy BL33 entry point information. It is stored in Secure RAM, in
95 * BL2's address space.
96 */
97 bl33_image_ep_info = *from_bl2->bl33_ep_info;
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +000098#endif
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +000099
100 if (bl33_image_ep_info.pc == 0U) {
101 ERROR("BL31: BL33 entrypoint not obtained from BL2\n");
102 panic();
103 }
Remi Pommarel327ad292019-03-28 20:55:13 +0100104
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +0000105#ifdef AML_STDPARAMS
106 /* Hardcode SCP_BL2 image info */
107 bl30_image_info.image_base = 0x13c0000;
108 bl30_image_info.image_size = 0xa000;
109 bl301_image_info.image_base = 0x13ca000;
110 bl301_image_info.image_size = 0x3400;
111#else
Remi Pommarel327ad292019-03-28 20:55:13 +0100112 bl30_image_info = *from_bl2->scp_image_info[0];
113 bl301_image_info = *from_bl2->scp_image_info[1];
Ferass El Hafidi8dca65d2025-01-08 13:57:35 +0000114#endif
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000115}
116
117void bl31_plat_arch_setup(void)
118{
Carlo Caione010fdc12019-08-25 18:09:03 +0100119 aml_setup_page_tables();
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000120
121 enable_mmu_el3(0);
122}
123
Remi Pommarel43d4a292019-04-04 23:12:56 +0200124static inline bool gxl_scp_ready(void)
125{
Carlo Caione91588542019-08-28 15:32:22 +0100126 return AML_AO_RTI_SCP_IS_READY(mmio_read_32(AML_AO_RTI_SCP_STAT));
Remi Pommarel43d4a292019-04-04 23:12:56 +0200127}
128
Remi Pommarel327ad292019-03-28 20:55:13 +0100129static inline void gxl_scp_boot(void)
130{
Carlo Caione9a5616f2019-08-28 10:08:24 +0100131 aml_scpi_upload_scp_fw(bl30_image_info.image_base,
132 bl30_image_info.image_size, 0);
133 aml_scpi_upload_scp_fw(bl301_image_info.image_base,
134 bl301_image_info.image_size, 1);
Remi Pommarel43d4a292019-04-04 23:12:56 +0200135 while (!gxl_scp_ready())
136 ;
Remi Pommarel327ad292019-03-28 20:55:13 +0100137}
138
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000139/*******************************************************************************
140 * GICv2 driver setup information
141 ******************************************************************************/
Carlo Caione91588542019-08-28 15:32:22 +0100142static const interrupt_prop_t gxl_interrupt_props[] = {
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000143 INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
144 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
145 INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
146 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
147 INTR_PROP_DESC(IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY,
148 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
149 INTR_PROP_DESC(IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY,
150 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
151 INTR_PROP_DESC(IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY,
152 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
153 INTR_PROP_DESC(IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY,
154 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
155 INTR_PROP_DESC(IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY,
156 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
157 INTR_PROP_DESC(IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY,
158 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
159 INTR_PROP_DESC(IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY,
160 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
161};
162
Carlo Caione91588542019-08-28 15:32:22 +0100163static const gicv2_driver_data_t gxl_gic_data = {
Carlo Caione821781f2019-08-24 18:51:48 +0100164 .gicd_base = AML_GICD_BASE,
165 .gicc_base = AML_GICC_BASE,
Carlo Caione91588542019-08-28 15:32:22 +0100166 .interrupt_props = gxl_interrupt_props,
167 .interrupt_props_num = ARRAY_SIZE(gxl_interrupt_props),
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000168};
169
170void bl31_platform_setup(void)
171{
Carlo Caionecbaad532019-08-28 09:46:18 +0100172 aml_mhu_secure_init();
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000173
Carlo Caione91588542019-08-28 15:32:22 +0100174 gicv2_driver_init(&gxl_gic_data);
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000175 gicv2_distif_init();
176 gicv2_pcpu_distif_init();
177 gicv2_cpuif_enable();
178
Remi Pommarel327ad292019-03-28 20:55:13 +0100179 gxl_scp_boot();
180
Carlo Caione73f6d052019-08-25 18:09:59 +0100181 aml_thermal_unknown();
Antonio Nino Diaz95d0d132018-12-05 00:09:30 +0000182}