blob: 27991d38186a685bc45efcaee2b3b56053ed0d30 [file] [log] [blame]
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +05301/*
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -07002 * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +05303 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +05308#include <errno.h>
Tejas Patel54d13192019-02-27 18:44:55 +05309#include <plat_arm.h>
Tejas Patel69409962018-12-14 00:55:29 -080010#include <plat_private.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <bl31/bl31.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <drivers/arm/pl011.h>
15#include <drivers/console.h>
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -070016#include <lib/mmio.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <lib/xlat_tables/xlat_tables.h>
18#include <plat/common/platform.h>
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -070019#include <versal_def.h>
20#include <plat_private.h>
21#include <plat_startup.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000022
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053023static entry_point_info_t bl32_image_ep_info;
24static entry_point_info_t bl33_image_ep_info;
Andre Przywara2b1b1a52020-01-25 00:58:35 +000025static console_t versal_runtime_console;
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053026
27/*
28 * Return a pointer to the 'entry_point_info' structure of the next image for
29 * the security state specified. BL33 corresponds to the non-secure image type
30 * while BL32 corresponds to the secure image type. A NULL pointer is returned
31 * if the image does not exist.
32 */
33entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
34{
35 assert(sec_state_is_valid(type));
36
37 if (type == NON_SECURE)
38 return &bl33_image_ep_info;
39
40 return &bl32_image_ep_info;
41}
42
43/*
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -070044 * Set the build time defaults,if we can't find any config data.
45 */
46static inline void bl31_set_default_config(void)
47{
48 bl32_image_ep_info.pc = BL32_BASE;
49 bl32_image_ep_info.spsr = arm_get_spsr_for_bl32_entry();
50 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
51 bl33_image_ep_info.spsr = SPSR_64(MODE_EL2, MODE_SP_ELX,
52 DISABLE_ALL_EXCEPTIONS);
53}
54
55/*
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053056 * Perform any BL31 specific platform actions. Here is an opportunity to copy
57 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before they
58 * are lost (potentially). This needs to be done before the MMU is initialized
59 * so that the memory layout can be used while creating page tables.
60 */
61void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
62 u_register_t arg2, u_register_t arg3)
63{
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -070064 uint64_t atf_handoff_addr;
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053065
66 /* Initialize the console to provide early debug support */
67 int rc = console_pl011_register(VERSAL_UART_BASE,
68 VERSAL_UART_CLOCK,
69 VERSAL_UART_BAUDRATE,
70 &versal_runtime_console);
71 if (rc == 0)
72 panic();
73
Andre Przywara2b1b1a52020-01-25 00:58:35 +000074 console_set_scope(&versal_runtime_console, CONSOLE_FLAG_BOOT |
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +053075 CONSOLE_FLAG_RUNTIME);
76
77 /* Initialize the platform config for future decision making */
78 versal_config_setup();
79 /* There are no parameters from BL2 if BL31 is a reset vector */
80 assert(arg0 == 0U);
81 assert(arg1 == 0U);
82
83 /*
84 * Do initial security configuration to allow DRAM/device access. On
85 * Base VERSAL only DRAM security is programmable (via TrustZone), but
86 * other platforms might have more programmable security devices
87 * present.
88 */
89
90 /* Populate common information for BL32 and BL33 */
91 SET_PARAM_HEAD(&bl32_image_ep_info, PARAM_EP, VERSION_1, 0);
92 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
93 SET_PARAM_HEAD(&bl33_image_ep_info, PARAM_EP, VERSION_1, 0);
94 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
95
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -070096 atf_handoff_addr = mmio_read_32(PMC_GLOBAL_GLOB_GEN_STORAGE4);
97 enum fsbl_handoff ret = fsbl_atf_handover(&bl32_image_ep_info,
98 &bl33_image_ep_info,
99 atf_handoff_addr);
Venkatesh Yadav Abbarapuef75de02020-11-23 03:29:51 -0800100 if (ret == FSBL_HANDOFF_NO_STRUCT || ret == FSBL_HANDOFF_INVAL_STRUCT) {
Venkatesh Yadav Abbarapu9156ffd2020-01-22 21:23:20 -0700101 bl31_set_default_config();
102 } else if (ret != FSBL_HANDOFF_SUCCESS) {
103 panic();
104 }
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +0530105
106 NOTICE("BL31: Secure code at 0x%lx\n", bl32_image_ep_info.pc);
107 NOTICE("BL31: Non secure code at 0x%lx\n", bl33_image_ep_info.pc);
108}
109
110void bl31_platform_setup(void)
111{
112 /* Initialize the gic cpu and distributor interfaces */
113 plat_versal_gic_driver_init();
114 plat_versal_gic_init();
115}
116
117void bl31_plat_runtime_setup(void)
118{
119}
120
121/*
122 * Perform the very early platform specific architectural setup here.
123 */
124void bl31_plat_arch_setup(void)
125{
Tejas Patel54d13192019-02-27 18:44:55 +0530126 plat_arm_interconnect_init();
127 plat_arm_interconnect_enter_coherency();
128
Siva Durga Prasad Paladugufe4af662018-09-25 18:44:58 +0530129 const mmap_region_t bl_regions[] = {
130 MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
131 MT_MEMORY | MT_RW | MT_SECURE),
132 MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
133 MT_CODE | MT_SECURE),
134 MAP_REGION_FLAT(BL_RO_DATA_BASE, BL_RO_DATA_END - BL_RO_DATA_BASE,
135 MT_RO_DATA | MT_SECURE),
136 MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
137 BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
138 MT_DEVICE | MT_RW | MT_SECURE),
139 {0}
140 };
141
142 setup_page_tables(bl_regions, plat_versal_get_mmap());
143 enable_mmu_el3(0);
144}