Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 1 | /* |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2025, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 6 | #include <assert.h> |
| 7 | #include <common/bl_common.h> |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 8 | #ifdef AML_STDPARAMS |
| 9 | #include <common/desc_image_load.h> |
| 10 | #endif |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 11 | #include <common/interrupt_props.h> |
Carlo Caione | b562187 | 2019-09-03 12:38:58 +0100 | [diff] [blame] | 12 | #include <drivers/arm/gicv2.h> |
Remi Pommarel | 43d4a29 | 2019-04-04 23:12:56 +0200 | [diff] [blame] | 13 | #include <lib/mmio.h> |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 14 | #include <lib/xlat_tables/xlat_mmu_helpers.h> |
Carlo Caione | b562187 | 2019-09-03 12:38:58 +0100 | [diff] [blame] | 15 | #include <plat/common/platform.h> |
| 16 | #include <platform_def.h> |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 17 | |
Carlo Caione | e26864a | 2019-08-24 17:31:51 +0100 | [diff] [blame] | 18 | #include "aml_private.h" |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 19 | |
| 20 | /* |
| 21 | * Placeholder variables for copying the arguments that have been passed to |
| 22 | * BL31 from BL2. |
| 23 | */ |
| 24 | static entry_point_info_t bl33_image_ep_info; |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 25 | static image_info_t bl30_image_info; |
| 26 | static image_info_t bl301_image_info; |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 27 | |
| 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 | ******************************************************************************/ |
| 34 | entry_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 Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 58 | struct gxl_bl31_param { |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 59 | 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 Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 65 | #ifndef AML_STDPARAMS |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 66 | image_info_t *scp_image_info[]; |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 67 | #endif |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, |
| 71 | u_register_t arg2, u_register_t arg3) |
| 72 | { |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 73 | #ifndef AML_STDPARAMS |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 74 | struct gxl_bl31_param *from_bl2; |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 75 | #endif |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 76 | |
| 77 | /* Initialize the console to provide early debug support */ |
Carlo Caione | 010fdc1 | 2019-08-25 18:09:03 +0100 | [diff] [blame] | 78 | aml_console_init(); |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 79 | |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 80 | #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 Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 85 | /* Check that params passed from BL2 are not NULL. */ |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 86 | from_bl2 = (struct gxl_bl31_param *) arg0; |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 87 | |
| 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 Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 98 | #endif |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 99 | |
| 100 | if (bl33_image_ep_info.pc == 0U) { |
| 101 | ERROR("BL31: BL33 entrypoint not obtained from BL2\n"); |
| 102 | panic(); |
| 103 | } |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 104 | |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 105 | #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 Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 112 | bl30_image_info = *from_bl2->scp_image_info[0]; |
| 113 | bl301_image_info = *from_bl2->scp_image_info[1]; |
Ferass El Hafidi | 8dca65d | 2025-01-08 13:57:35 +0000 | [diff] [blame] | 114 | #endif |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void bl31_plat_arch_setup(void) |
| 118 | { |
Carlo Caione | 010fdc1 | 2019-08-25 18:09:03 +0100 | [diff] [blame] | 119 | aml_setup_page_tables(); |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 120 | |
| 121 | enable_mmu_el3(0); |
| 122 | } |
| 123 | |
Remi Pommarel | 43d4a29 | 2019-04-04 23:12:56 +0200 | [diff] [blame] | 124 | static inline bool gxl_scp_ready(void) |
| 125 | { |
Carlo Caione | 9158854 | 2019-08-28 15:32:22 +0100 | [diff] [blame] | 126 | return AML_AO_RTI_SCP_IS_READY(mmio_read_32(AML_AO_RTI_SCP_STAT)); |
Remi Pommarel | 43d4a29 | 2019-04-04 23:12:56 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 129 | static inline void gxl_scp_boot(void) |
| 130 | { |
Carlo Caione | 9a5616f | 2019-08-28 10:08:24 +0100 | [diff] [blame] | 131 | 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 Pommarel | 43d4a29 | 2019-04-04 23:12:56 +0200 | [diff] [blame] | 135 | while (!gxl_scp_ready()) |
| 136 | ; |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 139 | /******************************************************************************* |
| 140 | * GICv2 driver setup information |
| 141 | ******************************************************************************/ |
Carlo Caione | 9158854 | 2019-08-28 15:32:22 +0100 | [diff] [blame] | 142 | static const interrupt_prop_t gxl_interrupt_props[] = { |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 143 | 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 Caione | 9158854 | 2019-08-28 15:32:22 +0100 | [diff] [blame] | 163 | static const gicv2_driver_data_t gxl_gic_data = { |
Carlo Caione | 821781f | 2019-08-24 18:51:48 +0100 | [diff] [blame] | 164 | .gicd_base = AML_GICD_BASE, |
| 165 | .gicc_base = AML_GICC_BASE, |
Carlo Caione | 9158854 | 2019-08-28 15:32:22 +0100 | [diff] [blame] | 166 | .interrupt_props = gxl_interrupt_props, |
| 167 | .interrupt_props_num = ARRAY_SIZE(gxl_interrupt_props), |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | void bl31_platform_setup(void) |
| 171 | { |
Carlo Caione | cbaad53 | 2019-08-28 09:46:18 +0100 | [diff] [blame] | 172 | aml_mhu_secure_init(); |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 173 | |
Carlo Caione | 9158854 | 2019-08-28 15:32:22 +0100 | [diff] [blame] | 174 | gicv2_driver_init(&gxl_gic_data); |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 175 | gicv2_distif_init(); |
| 176 | gicv2_pcpu_distif_init(); |
| 177 | gicv2_cpuif_enable(); |
| 178 | |
Remi Pommarel | 327ad29 | 2019-03-28 20:55:13 +0100 | [diff] [blame] | 179 | gxl_scp_boot(); |
| 180 | |
Carlo Caione | 73f6d05 | 2019-08-25 18:09:59 +0100 | [diff] [blame] | 181 | aml_thermal_unknown(); |
Antonio Nino Diaz | 95d0d13 | 2018-12-05 00:09:30 +0000 | [diff] [blame] | 182 | } |