blob: 2261470617be288c90ea6eb8b7d3ebe9bc36808b [file] [log] [blame]
Haojian Zhuang1b5c2252017-06-01 15:20:46 +08001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
Haojian Zhuang1b5c2252017-06-01 15:20:46 +08008#include <assert.h>
9#include <bl_common.h>
10#include <cci.h>
11#include <console.h>
12#include <debug.h>
13#include <errno.h>
14#include <generic_delay_timer.h>
15#include <gicv2.h>
16#include <hi3660.h>
Ryan Grachek44f8d652018-11-29 12:45:55 -060017#include <mmio.h>
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080018#include <hisi_ipc.h>
Leo Yanaf316a32018-01-22 12:40:25 +080019#include <interrupt_mgmt.h>
Antonio Nino Diaz582c2d72018-09-24 17:23:47 +010020#include <interrupt_props.h>
Jerome Forissier3fb19df2018-11-08 09:59:29 +010021#include <pl011.h>
Leo Yanaf316a32018-01-22 12:40:25 +080022#include <platform.h>
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080023#include <platform_def.h>
24
25#include "hikey960_def.h"
26#include "hikey960_private.h"
27
28/*
29 * The next 2 constants identify the extents of the code & RO data region.
30 * These addresses are used by the MMU setup code and therefore they must be
31 * page-aligned. It is the responsibility of the linker script to ensure that
32 * __RO_START__ and __RO_END__ linker symbols refer to page-aligned addresses.
33 */
34#define BL31_RO_BASE (unsigned long)(&__RO_START__)
35#define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
36
37/*
38 * The next 2 constants identify the extents of the coherent memory region.
39 * These addresses are used by the MMU setup code and therefore they must be
40 * page-aligned. It is the responsibility of the linker script to ensure that
41 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols refer to
42 * page-aligned addresses.
43 */
44#define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
45#define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
46
47static entry_point_info_t bl32_ep_info;
48static entry_point_info_t bl33_ep_info;
Jerome Forissier3fb19df2018-11-08 09:59:29 +010049static console_pl011_t console;
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080050
51/******************************************************************************
52 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
53 * interrupts.
54 *****************************************************************************/
Antonio Nino Diaz582c2d72018-09-24 17:23:47 +010055static const interrupt_prop_t g0_interrupt_props[] = {
56 INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
57 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
58 INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
59 GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080060};
61
62const gicv2_driver_data_t hikey960_gic_data = {
63 .gicd_base = GICD_REG_BASE,
64 .gicc_base = GICC_REG_BASE,
Antonio Nino Diaz582c2d72018-09-24 17:23:47 +010065 .interrupt_props = g0_interrupt_props,
66 .interrupt_props_num = ARRAY_SIZE(g0_interrupt_props),
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080067};
68
69static const int cci_map[] = {
70 CCI400_SL_IFACE3_CLUSTER_IX,
71 CCI400_SL_IFACE4_CLUSTER_IX
72};
73
Victor Chong7d787f52017-08-16 13:53:56 +090074entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080075{
76 entry_point_info_t *next_image_info;
77
78 next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;
79
80 /* None of the images on this platform can have 0x0 as the entrypoint */
81 if (next_image_info->pc)
82 return next_image_info;
83 return NULL;
84}
85
Antonio Nino Diaz582c2d72018-09-24 17:23:47 +010086void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
87 u_register_t arg2, u_register_t arg3)
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080088{
89 unsigned int id, uart_base;
Antonio Nino Diaz582c2d72018-09-24 17:23:47 +010090 void *from_bl2;
91
92 from_bl2 = (void *) arg0;
Haojian Zhuang1b5c2252017-06-01 15:20:46 +080093
94 generic_delay_timer_init();
95 hikey960_read_boardid(&id);
96 if (id == 5300)
97 uart_base = PL011_UART5_BASE;
98 else
99 uart_base = PL011_UART6_BASE;
100
101 /* Initialize the console to provide early debug support */
Jerome Forissier3fb19df2018-11-08 09:59:29 +0100102 console_pl011_register(uart_base, PL011_UART_CLK_IN_HZ,
103 PL011_BAUDRATE, &console);
Haojian Zhuang1b5c2252017-06-01 15:20:46 +0800104
105 /* Initialize CCI driver */
106 cci_init(CCI400_REG_BASE, cci_map, ARRAY_SIZE(cci_map));
107 cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
108
Victor Chong2d9a42d2017-08-17 15:21:10 +0900109 /*
110 * Check params passed from BL2 should not be NULL,
111 */
112 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
113 assert(params_from_bl2 != NULL);
114 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
115 assert(params_from_bl2->h.version >= VERSION_2);
116
117 bl_params_node_t *bl_params = params_from_bl2->head;
118
119 /*
120 * Copy BL33 and BL32 (if present), entry point information.
121 * They are stored in Secure RAM, in BL2's address space.
122 */
123 while (bl_params) {
124 if (bl_params->image_id == BL32_IMAGE_ID)
125 bl32_ep_info = *bl_params->ep_info;
126
127 if (bl_params->image_id == BL33_IMAGE_ID)
128 bl33_ep_info = *bl_params->ep_info;
129
130 bl_params = bl_params->next_params_info;
131 }
132
133 if (bl33_ep_info.pc == 0)
134 panic();
Haojian Zhuang1b5c2252017-06-01 15:20:46 +0800135}
136
137void bl31_plat_arch_setup(void)
138{
139 hikey960_init_mmu_el3(BL31_BASE,
140 BL31_LIMIT - BL31_BASE,
141 BL31_RO_BASE,
142 BL31_RO_LIMIT,
143 BL31_COHERENT_RAM_BASE,
144 BL31_COHERENT_RAM_LIMIT);
145}
146
Ryan Grachek44f8d652018-11-29 12:45:55 -0600147static void hikey960_edma_init(void)
148{
149 int i;
150 uint32_t non_secure;
151
152 non_secure = EDMAC_SEC_CTRL_INTR_SEC | EDMAC_SEC_CTRL_GLOBAL_SEC;
153 mmio_write_32(EDMAC_SEC_CTRL, non_secure);
154
155 for (i = 0; i < EDMAC_CHANNEL_NUMS; i++) {
156 mmio_write_32(EDMAC_AXI_CONF(i), (1 << 6) | (1 << 18));
157 }
158}
159
Haojian Zhuang1b5c2252017-06-01 15:20:46 +0800160void bl31_platform_setup(void)
161{
162 /* Initialize the GIC driver, cpu and distributor interfaces */
163 gicv2_driver_init(&hikey960_gic_data);
164 gicv2_distif_init();
165 gicv2_pcpu_distif_init();
166 gicv2_cpuif_enable();
167
Ryan Grachek44f8d652018-11-29 12:45:55 -0600168 hikey960_edma_init();
169
Haojian Zhuang1b5c2252017-06-01 15:20:46 +0800170 hisi_ipc_init();
171}
172
Leo Yanaf316a32018-01-22 12:40:25 +0800173#ifdef SPD_none
174static uint64_t hikey_debug_fiq_handler(uint32_t id,
175 uint32_t flags,
176 void *handle,
177 void *cookie)
178{
179 int intr, intr_raw;
180
181 /* Acknowledge interrupt */
182 intr_raw = plat_ic_acknowledge_interrupt();
183 intr = plat_ic_get_interrupt_id(intr_raw);
184 ERROR("Invalid interrupt: intr=%d\n", intr);
185 console_flush();
186 panic();
187
188 return 0;
189}
190#endif
191
Haojian Zhuang1b5c2252017-06-01 15:20:46 +0800192void bl31_plat_runtime_setup(void)
193{
Leo Yanaf316a32018-01-22 12:40:25 +0800194#ifdef SPD_none
195 uint32_t flags;
196 int32_t rc;
197
198 flags = 0;
199 set_interrupt_rm_flag(flags, NON_SECURE);
200 rc = register_interrupt_type_handler(INTR_TYPE_S_EL1,
201 hikey_debug_fiq_handler,
202 flags);
203 if (rc != 0)
204 panic();
205#endif
Haojian Zhuang1b5c2252017-06-01 15:20:46 +0800206}