bl31_plat_setup.c 3.81 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
9
10
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include <platform_def.h>

#include <arch.h>
#include <arch_helpers.h>
#include <bl31/bl31.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <cortex_a53.h>
#include <drivers/arm/pl011.h>
#include <drivers/generic_delay_timer.h>
#include <lib/mmio.h>
#include <plat/common/platform.h>

25
26
27
28
29
30
31
32
33
34
35
#include "hi3798cv200.h"
#include "plat_private.h"

/* Memory ranges for code and RO data sections */
#define BL31_RO_BASE	(unsigned long)(&__RO_START__)
#define BL31_RO_LIMIT	(unsigned long)(&__RO_END__)

/* Memory ranges for coherent memory section */
#define BL31_COHERENT_RAM_BASE	(unsigned long)(&__COHERENT_RAM_START__)
#define BL31_COHERENT_RAM_LIMIT	(unsigned long)(&__COHERENT_RAM_END__)

36
37
#define TZPC_SEC_ATTR_CTRL_VALUE (0x9DB98D45)

38
static entry_point_info_t bl32_image_ep_info;
39
static entry_point_info_t bl33_image_ep_info;
40
static console_pl011_t console;
41

42
43
44
45
46
static void hisi_tzpc_sec_init(void)
{
	mmio_write_32(HISI_TZPC_SEC_ATTR_CTRL, TZPC_SEC_ATTR_CTRL_VALUE);
}

47
48
entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
{
49
50
51
52
53
54
55
56
57
58
59
60
61
	entry_point_info_t *next_image_info;

	assert(sec_state_is_valid(type));
	next_image_info = (type == NON_SECURE)
			? &bl33_image_ep_info : &bl32_image_ep_info;
	/*
	 * None of the images on the ARM development platforms can have 0x0
	 * as the entrypoint
	 */
	if (next_image_info->pc)
		return next_image_info;
	else
		return NULL;
62
63
}

64
65
66
/*******************************************************************************
 * Perform any BL31 early platform setup common to ARM standard platforms.
 * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
67
 * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
68
69
70
71
 * done before the MMU is initialized so that the memory layout can be used
 * while creating page tables. BL2 has flushed this information to memory, so
 * we are guaranteed to pick up good data.
 ******************************************************************************/
72
73
void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
				u_register_t arg2, u_register_t arg3)
74
{
75
76
77
78
	void *from_bl2;

	from_bl2 = (void *) arg0;

79
80
	console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
			       PL011_BAUDRATE, &console);
81
82
83
84

	/* Init console for crash report */
	plat_crash_console_init();

85
86
87
	/*
	 * Check params passed from BL2 should not be NULL,
	 */
88
89
	bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;

90
	assert(params_from_bl2 != NULL);
91
92
93
94
	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;
95
96

	/*
97
	 * Copy BL33 and BL32 (if present), entry point information.
98
99
	 * They are stored in Secure RAM, in BL2's address space.
	 */
100
101
102
103
104
105
106
107
108
109
110
111
	while (bl_params) {
		if (bl_params->image_id == BL32_IMAGE_ID)
			bl32_image_ep_info = *bl_params->ep_info;

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

		bl_params = bl_params->next_params_info;
	}

	if (bl33_image_ep_info.pc == 0)
		panic();
112
113
114
115
116
117
118
119
}

void bl31_platform_setup(void)
{
	/* Init arch timer */
	generic_delay_timer_init();

	/* Init GIC distributor and CPU interface */
120
121
	poplar_gic_driver_init();
	poplar_gic_init();
122
123
124

	/* Init security properties of IP blocks */
	hisi_tzpc_sec_init();
125
126
127
128
129
130
131
132
133
}

void bl31_plat_runtime_setup(void)
{
	/* do nothing */
}

void bl31_plat_arch_setup(void)
{
134
135
	plat_configure_mmu_el3(BL31_BASE,
			       (BL31_LIMIT - BL31_BASE),
136
137
138
139
140
141
142
143
			       BL31_RO_BASE,
			       BL31_RO_LIMIT,
			       BL31_COHERENT_RAM_BASE,
			       BL31_COHERENT_RAM_LIMIT);

	INFO("Boot BL33 from 0x%lx for %lu Bytes\n",
	     bl33_image_ep_info.pc, bl33_image_ep_info.args.arg2);
}