xref: /arm-trusted-firmware/plat/hisilicon/poplar/bl31_plat_setup.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <assert.h>
8*91f16700Schasinglulu #include <errno.h>
9*91f16700Schasinglulu #include <inttypes.h>
10*91f16700Schasinglulu #include <stddef.h>
11*91f16700Schasinglulu #include <stdint.h>
12*91f16700Schasinglulu #include <string.h>
13*91f16700Schasinglulu 
14*91f16700Schasinglulu #include <platform_def.h>
15*91f16700Schasinglulu 
16*91f16700Schasinglulu #include <arch.h>
17*91f16700Schasinglulu #include <arch_helpers.h>
18*91f16700Schasinglulu #include <bl31/bl31.h>
19*91f16700Schasinglulu #include <common/bl_common.h>
20*91f16700Schasinglulu #include <common/debug.h>
21*91f16700Schasinglulu #include <cortex_a53.h>
22*91f16700Schasinglulu #include <drivers/arm/pl011.h>
23*91f16700Schasinglulu #include <drivers/generic_delay_timer.h>
24*91f16700Schasinglulu #include <lib/mmio.h>
25*91f16700Schasinglulu #include <plat/common/platform.h>
26*91f16700Schasinglulu 
27*91f16700Schasinglulu #include "hi3798cv200.h"
28*91f16700Schasinglulu #include "plat_private.h"
29*91f16700Schasinglulu 
30*91f16700Schasinglulu #define TZPC_SEC_ATTR_CTRL_VALUE (0x9DB98D45)
31*91f16700Schasinglulu 
32*91f16700Schasinglulu static entry_point_info_t bl32_image_ep_info;
33*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info;
34*91f16700Schasinglulu static console_t console;
35*91f16700Schasinglulu 
36*91f16700Schasinglulu static void hisi_tzpc_sec_init(void)
37*91f16700Schasinglulu {
38*91f16700Schasinglulu 	mmio_write_32(HISI_TZPC_SEC_ATTR_CTRL, TZPC_SEC_ATTR_CTRL_VALUE);
39*91f16700Schasinglulu }
40*91f16700Schasinglulu 
41*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
42*91f16700Schasinglulu {
43*91f16700Schasinglulu 	entry_point_info_t *next_image_info;
44*91f16700Schasinglulu 
45*91f16700Schasinglulu 	assert(sec_state_is_valid(type));
46*91f16700Schasinglulu 	next_image_info = (type == NON_SECURE)
47*91f16700Schasinglulu 			? &bl33_image_ep_info : &bl32_image_ep_info;
48*91f16700Schasinglulu 	/*
49*91f16700Schasinglulu 	 * None of the images on the ARM development platforms can have 0x0
50*91f16700Schasinglulu 	 * as the entrypoint
51*91f16700Schasinglulu 	 */
52*91f16700Schasinglulu 	if (next_image_info->pc)
53*91f16700Schasinglulu 		return next_image_info;
54*91f16700Schasinglulu 	else
55*91f16700Schasinglulu 		return NULL;
56*91f16700Schasinglulu }
57*91f16700Schasinglulu 
58*91f16700Schasinglulu /*******************************************************************************
59*91f16700Schasinglulu  * Perform any BL31 early platform setup common to ARM standard platforms.
60*91f16700Schasinglulu  * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
61*91f16700Schasinglulu  * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
62*91f16700Schasinglulu  * done before the MMU is initialized so that the memory layout can be used
63*91f16700Schasinglulu  * while creating page tables. BL2 has flushed this information to memory, so
64*91f16700Schasinglulu  * we are guaranteed to pick up good data.
65*91f16700Schasinglulu  ******************************************************************************/
66*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
67*91f16700Schasinglulu 				u_register_t arg2, u_register_t arg3)
68*91f16700Schasinglulu {
69*91f16700Schasinglulu 	void *from_bl2;
70*91f16700Schasinglulu 
71*91f16700Schasinglulu 	from_bl2 = (void *) arg0;
72*91f16700Schasinglulu 
73*91f16700Schasinglulu 	console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
74*91f16700Schasinglulu 			       PL011_BAUDRATE, &console);
75*91f16700Schasinglulu 
76*91f16700Schasinglulu 	/* Init console for crash report */
77*91f16700Schasinglulu 	plat_crash_console_init();
78*91f16700Schasinglulu 
79*91f16700Schasinglulu 	/*
80*91f16700Schasinglulu 	 * Check params passed from BL2 should not be NULL,
81*91f16700Schasinglulu 	 */
82*91f16700Schasinglulu 	bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
83*91f16700Schasinglulu 
84*91f16700Schasinglulu 	assert(params_from_bl2 != NULL);
85*91f16700Schasinglulu 	assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
86*91f16700Schasinglulu 	assert(params_from_bl2->h.version >= VERSION_2);
87*91f16700Schasinglulu 
88*91f16700Schasinglulu 	bl_params_node_t *bl_params = params_from_bl2->head;
89*91f16700Schasinglulu 
90*91f16700Schasinglulu 	/*
91*91f16700Schasinglulu 	 * Copy BL33 and BL32 (if present), entry point information.
92*91f16700Schasinglulu 	 * They are stored in Secure RAM, in BL2's address space.
93*91f16700Schasinglulu 	 */
94*91f16700Schasinglulu 	while (bl_params) {
95*91f16700Schasinglulu 		if (bl_params->image_id == BL32_IMAGE_ID)
96*91f16700Schasinglulu 			bl32_image_ep_info = *bl_params->ep_info;
97*91f16700Schasinglulu 
98*91f16700Schasinglulu 		if (bl_params->image_id == BL33_IMAGE_ID)
99*91f16700Schasinglulu 			bl33_image_ep_info = *bl_params->ep_info;
100*91f16700Schasinglulu 
101*91f16700Schasinglulu 		bl_params = bl_params->next_params_info;
102*91f16700Schasinglulu 	}
103*91f16700Schasinglulu 
104*91f16700Schasinglulu 	if (bl33_image_ep_info.pc == 0)
105*91f16700Schasinglulu 		panic();
106*91f16700Schasinglulu }
107*91f16700Schasinglulu 
108*91f16700Schasinglulu void bl31_platform_setup(void)
109*91f16700Schasinglulu {
110*91f16700Schasinglulu 	/* Init arch timer */
111*91f16700Schasinglulu 	generic_delay_timer_init();
112*91f16700Schasinglulu 
113*91f16700Schasinglulu 	/* Init GIC distributor and CPU interface */
114*91f16700Schasinglulu 	poplar_gic_driver_init();
115*91f16700Schasinglulu 	poplar_gic_init();
116*91f16700Schasinglulu 
117*91f16700Schasinglulu 	/* Init security properties of IP blocks */
118*91f16700Schasinglulu 	hisi_tzpc_sec_init();
119*91f16700Schasinglulu }
120*91f16700Schasinglulu 
121*91f16700Schasinglulu void bl31_plat_runtime_setup(void)
122*91f16700Schasinglulu {
123*91f16700Schasinglulu 	/* do nothing */
124*91f16700Schasinglulu }
125*91f16700Schasinglulu 
126*91f16700Schasinglulu void bl31_plat_arch_setup(void)
127*91f16700Schasinglulu {
128*91f16700Schasinglulu 	plat_configure_mmu_el3(BL31_BASE,
129*91f16700Schasinglulu 			       (BL31_LIMIT - BL31_BASE),
130*91f16700Schasinglulu 			       BL_CODE_BASE,
131*91f16700Schasinglulu 			       BL_CODE_END,
132*91f16700Schasinglulu 			       BL_COHERENT_RAM_BASE,
133*91f16700Schasinglulu 			       BL_COHERENT_RAM_END);
134*91f16700Schasinglulu 
135*91f16700Schasinglulu 	INFO("Boot BL33 from 0x%lx for %" PRIu64 " Bytes\n",
136*91f16700Schasinglulu 	     bl33_image_ep_info.pc, bl33_image_ep_info.args.arg2);
137*91f16700Schasinglulu }
138