blob: fe60ddcb110535ab5c63999abeab12741404ff01 [file] [log] [blame]
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02001/*
Julius Wernerefd09a72019-07-23 20:00:13 -07002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02007#include <assert.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02008#include <errno.h>
Scott Brandene5dcf982020-08-25 13:49:32 -07009#include <inttypes.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020010#include <stddef.h>
Scott Brandene5dcf982020-08-25 13:49:32 -070011#include <stdint.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020012#include <string.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013
14#include <platform_def.h>
15
16#include <arch.h>
17#include <arch_helpers.h>
18#include <bl31/bl31.h>
19#include <common/bl_common.h>
20#include <common/debug.h>
21#include <cortex_a53.h>
22#include <drivers/arm/pl011.h>
23#include <drivers/generic_delay_timer.h>
24#include <lib/mmio.h>
25#include <plat/common/platform.h>
26
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020027#include "hi3798cv200.h"
28#include "plat_private.h"
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020029
Jiancheng Xueb88b08a2017-08-28 18:55:43 +080030#define TZPC_SEC_ATTR_CTRL_VALUE (0x9DB98D45)
31
Victor Chong662556a2017-10-28 01:59:41 +090032static entry_point_info_t bl32_image_ep_info;
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020033static entry_point_info_t bl33_image_ep_info;
Andre Przywara2b1b1a52020-01-25 00:58:35 +000034static console_t console;
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020035
Jiancheng Xueb88b08a2017-08-28 18:55:43 +080036static void hisi_tzpc_sec_init(void)
37{
38 mmio_write_32(HISI_TZPC_SEC_ATTR_CTRL, TZPC_SEC_ATTR_CTRL_VALUE);
39}
40
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020041entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
42{
Victor Chong662556a2017-10-28 01:59:41 +090043 entry_point_info_t *next_image_info;
44
45 assert(sec_state_is_valid(type));
46 next_image_info = (type == NON_SECURE)
47 ? &bl33_image_ep_info : &bl32_image_ep_info;
48 /*
49 * None of the images on the ARM development platforms can have 0x0
50 * as the entrypoint
51 */
52 if (next_image_info->pc)
53 return next_image_info;
54 else
55 return NULL;
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020056}
57
Victor Chong175dd8a2018-02-01 00:35:22 +090058/*******************************************************************************
59 * Perform any BL31 early platform setup common to ARM standard platforms.
60 * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
John Tsichritzisd653d332018-09-14 10:34:57 +010061 * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
Victor Chong175dd8a2018-02-01 00:35:22 +090062 * done before the MMU is initialized so that the memory layout can be used
63 * while creating page tables. BL2 has flushed this information to memory, so
64 * we are guaranteed to pick up good data.
65 ******************************************************************************/
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010066void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
67 u_register_t arg2, u_register_t arg3)
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020068{
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010069 void *from_bl2;
70
71 from_bl2 = (void *) arg0;
72
Jerome Forissier74a19f22018-11-08 11:57:30 +000073 console_pl011_register(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ,
74 PL011_BAUDRATE, &console);
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020075
76 /* Init console for crash report */
77 plat_crash_console_init();
78
Victor Chong175dd8a2018-02-01 00:35:22 +090079 /*
80 * Check params passed from BL2 should not be NULL,
81 */
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010082 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
83
Victor Chong175dd8a2018-02-01 00:35:22 +090084 assert(params_from_bl2 != NULL);
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010085 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
86 assert(params_from_bl2->h.version >= VERSION_2);
87
88 bl_params_node_t *bl_params = params_from_bl2->head;
Victor Chong662556a2017-10-28 01:59:41 +090089
90 /*
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010091 * Copy BL33 and BL32 (if present), entry point information.
Victor Chong662556a2017-10-28 01:59:41 +090092 * They are stored in Secure RAM, in BL2's address space.
93 */
Antonio Nino Diaze93cde12018-09-24 17:15:15 +010094 while (bl_params) {
95 if (bl_params->image_id == BL32_IMAGE_ID)
96 bl32_image_ep_info = *bl_params->ep_info;
97
98 if (bl_params->image_id == BL33_IMAGE_ID)
99 bl33_image_ep_info = *bl_params->ep_info;
100
101 bl_params = bl_params->next_params_info;
102 }
103
104 if (bl33_image_ep_info.pc == 0)
105 panic();
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200106}
107
108void bl31_platform_setup(void)
109{
110 /* Init arch timer */
111 generic_delay_timer_init();
112
113 /* Init GIC distributor and CPU interface */
Antonio Nino Diaz6766bb12018-10-26 11:12:31 +0100114 poplar_gic_driver_init();
115 poplar_gic_init();
Jiancheng Xueb88b08a2017-08-28 18:55:43 +0800116
117 /* Init security properties of IP blocks */
118 hisi_tzpc_sec_init();
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200119}
120
121void bl31_plat_runtime_setup(void)
122{
123 /* do nothing */
124}
125
126void bl31_plat_arch_setup(void)
127{
Victor Chong175dd8a2018-02-01 00:35:22 +0900128 plat_configure_mmu_el3(BL31_BASE,
129 (BL31_LIMIT - BL31_BASE),
Antonio Nino Diazde97ff32019-01-25 13:28:38 +0000130 BL_CODE_BASE,
131 BL_CODE_END,
132 BL_COHERENT_RAM_BASE,
133 BL_COHERENT_RAM_END);
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200134
Scott Brandene5dcf982020-08-25 13:49:32 -0700135 INFO("Boot BL33 from 0x%lx for %" PRIu64 " Bytes\n",
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200136 bl33_image_ep_info.pc, bl33_image_ep_info.args.arg2);
137}