blob: 29bd1763fb246f4cf8e489b2cc46a165ddcc5dab [file] [log] [blame]
Tien Hock, Lohab34f742019-02-26 09:25:14 +08001/*
2 * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
Hadi Asyrafi5ae876f2019-10-23 17:58:06 +08003 * Copyright (c) 2019, Intel Corporation. All rights reserved.
Tien Hock, Lohab34f742019-02-26 09:25:14 +08004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
Tien Hock, Lohab34f742019-02-26 09:25:14 +08008#include <arch.h>
9#include <arch_helpers.h>
Hadi Asyrafi5ae876f2019-10-23 17:58:06 +080010#include <assert.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080011#include <common/bl_common.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080012#include <drivers/arm/gicv2.h>
13#include <drivers/ti/uart/uart_16550.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080014#include <lib/xlat_tables/xlat_tables.h>
15#include <lib/mmio.h>
16#include <plat/common/platform.h>
17#include <platform_def.h>
Tien Hock, Lohab34f742019-02-26 09:25:14 +080018
Hadi Asyrafif0fa8072019-10-23 17:02:55 +080019#include "socfpga_private.h"
Tien Hock, Lohab34f742019-02-26 09:25:14 +080020#include "s10_reset_manager.h"
21#include "s10_memory_controller.h"
22#include "s10_pinmux.h"
23#include "s10_clock_manager.h"
24#include "s10_system_manager.h"
25
26static entry_point_info_t bl32_image_ep_info;
27static entry_point_info_t bl33_image_ep_info;
28
29entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
30{
31 entry_point_info_t *next_image_info;
32
33 next_image_info = (type == NON_SECURE) ?
34 &bl33_image_ep_info : &bl32_image_ep_info;
35
36 /* None of the images on this platform can have 0x0 as the entrypoint */
37 if (next_image_info->pc)
38 return next_image_info;
39 else
40 return NULL;
41}
42
43void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
44 u_register_t arg2, u_register_t arg3)
45{
46 static console_16550_t console;
47
48 console_16550_register(PLAT_UART0_BASE, PLAT_UART_CLOCK, PLAT_BAUDRATE,
49 &console);
50 /*
51 * Check params passed from BL31 should not be NULL,
52 */
53 void *from_bl2 = (void *) arg0;
54
55 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080056 assert(params_from_bl2 != NULL);
Tien Hock, Lohab34f742019-02-26 09:25:14 +080057
58 /*
59 * Copy BL32 (if populated by BL31) and BL33 entry point information.
60 * They are stored in Secure RAM, in BL31's address space.
61 */
62
Hadi Asyrafic8a281c2019-10-24 16:13:09 +080063 if (params_from_bl2->h.type == PARAM_BL_PARAMS &&
64 params_from_bl2->h.version >= VERSION_2) {
65
66 bl_params_node_t *bl_params = params_from_bl2->head;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080067
Hadi Asyrafic8a281c2019-10-24 16:13:09 +080068 while (bl_params) {
69 if (bl_params->image_id == BL33_IMAGE_ID)
70 bl33_image_ep_info = *bl_params->ep_info;
71
72 bl_params = bl_params->next_params_info;
73 }
74 } else {
75 struct socfpga_bl31_params *arg_from_bl2 =
76 (struct socfpga_bl31_params *) from_bl2;
77
78 assert(arg_from_bl2->h.type == PARAM_BL31);
79 assert(arg_from_bl2->h.version >= VERSION_1);
Tien Hock, Lohab34f742019-02-26 09:25:14 +080080
Hadi Asyrafic8a281c2019-10-24 16:13:09 +080081 bl32_image_ep_info = *arg_from_bl2->bl32_ep_info;
82 bl33_image_ep_info = *arg_from_bl2->bl33_ep_info;
Tien Hock, Lohab34f742019-02-26 09:25:14 +080083 }
84 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
85}
86
87static const interrupt_prop_t s10_interrupt_props[] = {
Hadi Asyrafi9f5dfc92019-10-23 16:26:53 +080088 PLAT_INTEL_SOCFPGA_G1S_IRQ_PROPS(GICV2_INTR_GROUP0),
89 PLAT_INTEL_SOCFPGA_G0_IRQ_PROPS(GICV2_INTR_GROUP0)
Tien Hock, Lohab34f742019-02-26 09:25:14 +080090};
91
92static unsigned int target_mask_array[PLATFORM_CORE_COUNT];
93
94static const gicv2_driver_data_t plat_gicv2_gic_data = {
Hadi Asyrafi9f5dfc92019-10-23 16:26:53 +080095 .gicd_base = PLAT_INTEL_SOCFPGA_GICD_BASE,
96 .gicc_base = PLAT_INTEL_SOCFPGA_GICC_BASE,
Tien Hock, Lohab34f742019-02-26 09:25:14 +080097 .interrupt_props = s10_interrupt_props,
98 .interrupt_props_num = ARRAY_SIZE(s10_interrupt_props),
99 .target_masks = target_mask_array,
100 .target_masks_num = ARRAY_SIZE(target_mask_array),
101};
102
103/*******************************************************************************
104 * Perform any BL3-1 platform setup code
105 ******************************************************************************/
106void bl31_platform_setup(void)
107{
108 /* Initialize the gic cpu and distributor interfaces */
109 gicv2_driver_init(&plat_gicv2_gic_data);
110 gicv2_distif_init();
111 gicv2_pcpu_distif_init();
112 gicv2_cpuif_enable();
Hadi Asyrafi0563a852019-10-22 12:59:32 +0800113
114 /* Signal secondary CPUs to jump to BL31 (BL2 = U-boot SPL) */
115 mmio_write_64(PLAT_CPU_RELEASE_ADDR,
116 (uint64_t)plat_secondary_cpus_bl31_entry);
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800117}
118
119const mmap_region_t plat_stratix10_mmap[] = {
Hadi Asyrafiacee4882019-08-01 11:29:48 +0800120 MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
121 MT_MEMORY | MT_RW | MT_NS),
122 MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
123 MT_DEVICE | MT_RW | MT_NS),
124 MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
125 MT_DEVICE | MT_RW | MT_SECURE),
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800126 MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
127 MT_NON_CACHEABLE | MT_RW | MT_SECURE),
128 MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
129 MT_DEVICE | MT_RW | MT_SECURE),
Hadi Asyrafiacee4882019-08-01 11:29:48 +0800130 MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
131 MT_DEVICE | MT_RW | MT_NS),
132 MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
133 MT_DEVICE | MT_RW | MT_NS),
134 {0}
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800135};
136
137/*******************************************************************************
138 * Perform the very early platform specific architectural setup here. At the
139 * moment this is only intializes the mmu in a quick and dirty way.
140 ******************************************************************************/
141void bl31_plat_arch_setup(void)
142{
143 const mmap_region_t bl_regions[] = {
144 MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
145 MT_MEMORY | MT_RW | MT_SECURE),
146 MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
147 MT_CODE | MT_SECURE),
148 MAP_REGION_FLAT(BL_RO_DATA_BASE,
149 BL_RO_DATA_END - BL_RO_DATA_BASE,
150 MT_RO_DATA | MT_SECURE),
151#if USE_COHERENT_MEM
152 MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
153 BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
154 MT_DEVICE | MT_RW | MT_SECURE),
155#endif
Hadi Asyrafiacee4882019-08-01 11:29:48 +0800156 {0}
Tien Hock, Lohab34f742019-02-26 09:25:14 +0800157 };
158
159 setup_page_tables(bl_regions, plat_stratix10_mmap);
160 enable_mmu_el3(0);
161}
162