hikey_bl31_setup.c 3.94 KB
Newer Older
Haojian Zhuang's avatar
Haojian Zhuang committed
1
/*
Haojian Zhuang's avatar
Haojian Zhuang committed
2
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Haojian Zhuang's avatar
Haojian Zhuang committed
3
4
5
6
7
8
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
#include <errno.h>
9
10
11
12
13
14
15
16
17
18
19
20

#include <platform_def.h>

#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <common/interrupt_props.h>
#include <drivers/arm/cci.h>
#include <drivers/arm/gicv2.h>
#include <drivers/arm/pl011.h>
#include <lib/mmio.h>

Haojian Zhuang's avatar
Haojian Zhuang committed
21
#include <hi6220.h>
22
#include <hikey_def.h>
Haojian Zhuang's avatar
Haojian Zhuang committed
23
24
25
26
27
28
29
#include <hisi_ipc.h>
#include <hisi_pwrc.h>

#include "hikey_private.h"

static entry_point_info_t bl32_ep_info;
static entry_point_info_t bl33_ep_info;
30
static console_t console;
Haojian Zhuang's avatar
Haojian Zhuang committed
31
32
33
34
35

/******************************************************************************
 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
 * interrupts.
 *****************************************************************************/
36
37
38
39
40
static const interrupt_prop_t g0_interrupt_props[] = {
	INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
	INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
Haojian Zhuang's avatar
Haojian Zhuang committed
41
42
43
44
45
46
47
48
49
50
};

/*
 * Ideally `arm_gic_data` structure definition should be a `const` but it is
 * kept as modifiable for overwriting with different GICD and GICC base when
 * running on FVP with VE memory map.
 */
gicv2_driver_data_t hikey_gic_data = {
	.gicd_base = PLAT_ARM_GICD_BASE,
	.gicc_base = PLAT_ARM_GICC_BASE,
51
52
	.interrupt_props = g0_interrupt_props,
	.interrupt_props_num = ARRAY_SIZE(g0_interrupt_props),
Haojian Zhuang's avatar
Haojian Zhuang committed
53
54
55
56
57
58
59
};

static const int cci_map[] = {
	CCI400_SL_IFACE3_CLUSTER_IX,
	CCI400_SL_IFACE4_CLUSTER_IX
};

60
entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
Haojian Zhuang's avatar
Haojian Zhuang committed
61
62
63
64
65
66
67
68
69
70
71
{
	entry_point_info_t *next_image_info;

	next_image_info = (type == NON_SECURE) ? &bl33_ep_info : &bl32_ep_info;

	/* None of the images on this platform can have 0x0 as the entrypoint */
	if (next_image_info->pc)
		return next_image_info;
	return NULL;
}

72
73
void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
				u_register_t arg2, u_register_t arg3)
Haojian Zhuang's avatar
Haojian Zhuang committed
74
{
75
76
77
78
	void *from_bl2;

	from_bl2 = (void *) arg0;

Haojian Zhuang's avatar
Haojian Zhuang committed
79
	/* Initialize the console to provide early debug support */
Jerome Forissier's avatar
Jerome Forissier committed
80
81
	console_pl011_register(CONSOLE_BASE, PL011_UART_CLK_IN_HZ,
			       PL011_BAUDRATE, &console);
Haojian Zhuang's avatar
Haojian Zhuang committed
82
83
84

	/* Initialize CCI driver */
	cci_init(CCI400_BASE, cci_map, ARRAY_SIZE(cci_map));
85
	cci_enable_snoop_dvm_reqs(MPIDR_AFFLVL1_VAL(read_mpidr_el1()));
Haojian Zhuang's avatar
Haojian Zhuang committed
86

87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	/*
	 * Check params passed from BL2 should not be NULL,
	 */
	bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
	assert(params_from_bl2 != NULL);
	assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
	assert(params_from_bl2->h.version >= VERSION_2);

	bl_params_node_t *bl_params = params_from_bl2->head;

	/*
	 * Copy BL33 and BL32 (if present), entry point information.
	 * They are stored in Secure RAM, in BL2's address space.
	 */
	while (bl_params) {
		if (bl_params->image_id == BL32_IMAGE_ID)
			bl32_ep_info = *bl_params->ep_info;

		if (bl_params->image_id == BL33_IMAGE_ID)
			bl33_ep_info = *bl_params->ep_info;

		bl_params = bl_params->next_params_info;
	}

	if (bl33_ep_info.pc == 0)
		panic();
Haojian Zhuang's avatar
Haojian Zhuang committed
113
114
115
116
117
118
}

void bl31_plat_arch_setup(void)
{
	hikey_init_mmu_el3(BL31_BASE,
			   BL31_LIMIT - BL31_BASE,
119
120
121
122
			   BL_CODE_BASE,
			   BL_CODE_END,
			   BL_COHERENT_RAM_BASE,
			   BL_COHERENT_RAM_END);
Haojian Zhuang's avatar
Haojian Zhuang committed
123
124
}

125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* Initialize EDMAC controller with non-secure mode. */
static void hikey_edma_init(void)
{
	int i;
	uint32_t non_secure;

	non_secure = EDMAC_SEC_CTRL_INTR_SEC | EDMAC_SEC_CTRL_GLOBAL_SEC;
	mmio_write_32(EDMAC_SEC_CTRL, non_secure);

	for (i = 0; i < EDMAC_CHANNEL_NUMS; i++) {
		mmio_write_32(EDMAC_AXI_CONF(i), (1 << 6) | (1 << 18));
	}
}

Haojian Zhuang's avatar
Haojian Zhuang committed
139
140
141
142
143
144
145
146
void bl31_platform_setup(void)
{
	/* Initialize the GIC driver, cpu and distributor interfaces */
	gicv2_driver_init(&hikey_gic_data);
	gicv2_distif_init();
	gicv2_pcpu_distif_init();
	gicv2_cpuif_enable();

147
148
	hikey_edma_init();

Haojian Zhuang's avatar
Haojian Zhuang committed
149
150
151
152
153
154
155
	hisi_ipc_init();
	hisi_pwrc_setup();
}

void bl31_plat_runtime_setup(void)
{
}