blob: 5c25e437ee93ae3f89f3691abd4b7110b0b548ae [file] [log] [blame]
Tien Hock, Lohab34f742019-02-26 09:25:14 +08001/*
Chee Hong Ang2382b112020-04-24 21:51:00 +08002 * Copyright (c) 2019-2020, ARM Limited and Contributors. All rights reserved.
Abdul Halim, Muhammad Hadi Asyrafi2f94ca42020-08-05 22:40:46 +08003 * Copyright (c) 2019-2022, Intel Corporation. All rights reserved.
Sieu Mun Tangd5d20d32025-03-05 18:58:09 +08004 * Copyright (c) 2025, Altera Corporation. All rights reserved.
Tien Hock, Lohab34f742019-02-26 09:25:14 +08005 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
Tien Hock, Lohab34f742019-02-26 09:25:14 +08009#include <arch.h>
10#include <arch_helpers.h>
Hadi Asyrafi5ae876f2019-10-23 17:58:06 +080011#include <assert.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080012#include <common/bl_common.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080013#include <drivers/arm/gicv2.h>
14#include <drivers/ti/uart/uart_16550.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080015#include <lib/xlat_tables/xlat_tables.h>
16#include <lib/mmio.h>
17#include <plat/common/platform.h>
18#include <platform_def.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080019
Hadi Asyrafi593c4c52019-12-17 19:22:17 +080020#include "socfpga_mailbox.h"
Abdul Halim, Muhammad Hadi Asyrafi2f94ca42020-08-05 22:40:46 +080021#include "socfpga_noc.h"
Hadi Asyrafif0fa8072019-10-23 17:02:55 +080022#include "socfpga_private.h"
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +080023#include "socfpga_reset_manager.h"
Hadi Asyrafi8ebd2372019-12-23 17:58:04 +080024#include "socfpga_system_manager.h"
Tien Hock, Lohab34f742019-02-26 09:25:14 +080025#include "s10_memory_controller.h"
26#include "s10_pinmux.h"
27#include "s10_clock_manager.h"
Tien Hock, Lohab34f742019-02-26 09:25:14 +080028
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +080029
Tien Hock, Lohab34f742019-02-26 09:25:14 +080030static entry_point_info_t bl32_image_ep_info;
31static entry_point_info_t bl33_image_ep_info;
32
33entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
34{
35 entry_point_info_t *next_image_info;
36
37 next_image_info = (type == NON_SECURE) ?
38 &bl33_image_ep_info : &bl32_image_ep_info;
39
40 /* None of the images on this platform can have 0x0 as the entrypoint */
41 if (next_image_info->pc)
42 return next_image_info;
43 else
44 return NULL;
45}
46
47void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
48 u_register_t arg2, u_register_t arg3)
49{
Andre Przywara98b5a112020-01-25 00:58:35 +000050 static console_t console;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080051
Chee Hong Ang2382b112020-04-24 21:51:00 +080052 mmio_write_64(PLAT_SEC_ENTRY, PLAT_SEC_WARM_ENTRY);
53
Boon Khai Ngb19ac612021-08-06 01:16:46 +080054 console_16550_register(PLAT_INTEL_UART_BASE, PLAT_UART_CLOCK,
55 PLAT_BAUDRATE, &console);
Tien Hock, Lohab34f742019-02-26 09:25:14 +080056 /*
57 * Check params passed from BL31 should not be NULL,
58 */
59 void *from_bl2 = (void *) arg0;
60
61 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080062 assert(params_from_bl2 != NULL);
Tien Hock, Lohab34f742019-02-26 09:25:14 +080063
64 /*
65 * Copy BL32 (if populated by BL31) and BL33 entry point information.
66 * They are stored in Secure RAM, in BL31's address space.
67 */
68
Hadi Asyrafic8a281c2019-10-24 16:13:09 +080069 if (params_from_bl2->h.type == PARAM_BL_PARAMS &&
70 params_from_bl2->h.version >= VERSION_2) {
71
72 bl_params_node_t *bl_params = params_from_bl2->head;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080073
Hadi Asyrafic8a281c2019-10-24 16:13:09 +080074 while (bl_params) {
75 if (bl_params->image_id == BL33_IMAGE_ID)
76 bl33_image_ep_info = *bl_params->ep_info;
77
78 bl_params = bl_params->next_params_info;
79 }
80 } else {
81 struct socfpga_bl31_params *arg_from_bl2 =
82 (struct socfpga_bl31_params *) from_bl2;
83
84 assert(arg_from_bl2->h.type == PARAM_BL31);
85 assert(arg_from_bl2->h.version >= VERSION_1);
Tien Hock, Lohab34f742019-02-26 09:25:14 +080086
Hadi Asyrafic8a281c2019-10-24 16:13:09 +080087 bl32_image_ep_info = *arg_from_bl2->bl32_ep_info;
88 bl33_image_ep_info = *arg_from_bl2->bl33_ep_info;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080089 }
90 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
91}
92
93static const interrupt_prop_t s10_interrupt_props[] = {
Hadi Asyrafi9f5dfc92019-10-23 16:26:53 +080094 PLAT_INTEL_SOCFPGA_G1S_IRQ_PROPS(GICV2_INTR_GROUP0),
95 PLAT_INTEL_SOCFPGA_G0_IRQ_PROPS(GICV2_INTR_GROUP0)
Tien Hock, Lohab34f742019-02-26 09:25:14 +080096};
97
98static unsigned int target_mask_array[PLATFORM_CORE_COUNT];
99
100static const gicv2_driver_data_t plat_gicv2_gic_data = {
Hadi Asyrafi9f5dfc92019-10-23 16:26:53 +0800101 .gicd_base = PLAT_INTEL_SOCFPGA_GICD_BASE,
102 .gicc_base = PLAT_INTEL_SOCFPGA_GICC_BASE,
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800103 .interrupt_props = s10_interrupt_props,
104 .interrupt_props_num = ARRAY_SIZE(s10_interrupt_props),
105 .target_masks = target_mask_array,
106 .target_masks_num = ARRAY_SIZE(target_mask_array),
107};
108
109/*******************************************************************************
110 * Perform any BL3-1 platform setup code
111 ******************************************************************************/
112void bl31_platform_setup(void)
113{
Chee Hong Ang64740962020-05-11 00:55:01 +0800114 socfpga_delay_timer_init();
115
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800116 /* Initialize the gic cpu and distributor interfaces */
117 gicv2_driver_init(&plat_gicv2_gic_data);
118 gicv2_distif_init();
119 gicv2_pcpu_distif_init();
120 gicv2_cpuif_enable();
Hadi Asyrafi0563a852019-10-22 12:59:32 +0800121
122 /* Signal secondary CPUs to jump to BL31 (BL2 = U-boot SPL) */
123 mmio_write_64(PLAT_CPU_RELEASE_ADDR,
124 (uint64_t)plat_secondary_cpus_bl31_entry);
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800125
Sieu Mun Tangd5d20d32025-03-05 18:58:09 +0800126#if SIP_SVC_V3
127 /*
128 * Re-initialize the mailbox to include V3 specific routines.
129 * In V3, this re-initialize is required because prior to BL31, U-Boot
130 * SPL has its own mailbox settings and this initialization will
131 * override to those settings as required by the V3 framework.
132 */
133 mailbox_init();
134#endif
135
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800136 mailbox_hps_stage_notify(HPS_EXECUTION_STATE_SSBL);
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800137}
138
139const mmap_region_t plat_stratix10_mmap[] = {
Hadi Asyrafiacee4882019-08-01 11:29:48 +0800140 MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
141 MT_MEMORY | MT_RW | MT_NS),
142 MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
143 MT_DEVICE | MT_RW | MT_NS),
144 MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
145 MT_DEVICE | MT_RW | MT_SECURE),
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800146 MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
147 MT_NON_CACHEABLE | MT_RW | MT_SECURE),
148 MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
149 MT_DEVICE | MT_RW | MT_SECURE),
Hadi Asyrafiacee4882019-08-01 11:29:48 +0800150 MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
151 MT_DEVICE | MT_RW | MT_NS),
152 MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
153 MT_DEVICE | MT_RW | MT_NS),
154 {0}
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800155};
156
157/*******************************************************************************
158 * Perform the very early platform specific architectural setup here. At the
Elyes Haouas2be03c02023-02-13 09:14:48 +0100159 * moment this is only initializes the mmu in a quick and dirty way.
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800160 ******************************************************************************/
161void bl31_plat_arch_setup(void)
162{
163 const mmap_region_t bl_regions[] = {
164 MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
165 MT_MEMORY | MT_RW | MT_SECURE),
166 MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
167 MT_CODE | MT_SECURE),
168 MAP_REGION_FLAT(BL_RO_DATA_BASE,
169 BL_RO_DATA_END - BL_RO_DATA_BASE,
170 MT_RO_DATA | MT_SECURE),
171#if USE_COHERENT_MEM
172 MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
173 BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
174 MT_DEVICE | MT_RW | MT_SECURE),
175#endif
Hadi Asyrafiacee4882019-08-01 11:29:48 +0800176 {0}
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800177 };
178
179 setup_page_tables(bl_regions, plat_stratix10_mmap);
180 enable_mmu_el3(0);
181}
182