blob: a253d3fc8a31768fe9ba0d3a4ebdd028a236d86b [file] [log] [blame]
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +02001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <assert.h>
9#include <bl_common.h>
10#include <console.h>
11#include <debug.h>
Victor Chong175dd8a2018-02-01 00:35:22 +090012#include <desc_image_load.h>
Victor Chong539408d2018-01-03 01:53:08 +090013#include <dw_mmc.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020014#include <errno.h>
15#include <generic_delay_timer.h>
Haojian Zhuang3eff4092018-08-04 18:07:26 +080016#include <mmc.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020017#include <mmio.h>
Victor Chongaa033472018-02-01 00:35:39 +090018#include <optee_utils.h>
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +020019#include <partition/partition.h>
20#include <platform.h>
21#include <string.h>
22#include "hi3798cv200.h"
23#include "plat_private.h"
24
25/* Memory ranges for code and read only data sections */
26#define BL2_RO_BASE (unsigned long)(&__RO_START__)
27#define BL2_RO_LIMIT (unsigned long)(&__RO_END__)
28
29/* Memory ranges for coherent memory section */
30#define BL2_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
31#define BL2_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
32
Victor Chong175dd8a2018-02-01 00:35:22 +090033static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
34
Victor Chong175dd8a2018-02-01 00:35:22 +090035/*******************************************************************************
36 * Transfer SCP_BL2 from Trusted RAM using the SCP Download protocol.
37 * Return 0 on success, -1 otherwise.
38 ******************************************************************************/
Victor Chong175dd8a2018-02-01 00:35:22 +090039int plat_poplar_bl2_handle_scp_bl2(image_info_t *scp_bl2_image_info)
Victor Chong175dd8a2018-02-01 00:35:22 +090040{
41 /*
42 * This platform has no SCP_BL2 yet
43 */
44 return 0;
45}
46
47/*******************************************************************************
48 * Gets SPSR for BL32 entry
49 ******************************************************************************/
50uint32_t poplar_get_spsr_for_bl32_entry(void)
51{
52 /*
53 * The Secure Payload Dispatcher service is responsible for
54 * setting the SPSR prior to entry into the BL3-2 image.
55 */
56 return 0;
57}
58
59/*******************************************************************************
60 * Gets SPSR for BL33 entry
61 ******************************************************************************/
62#ifndef AARCH32
63uint32_t poplar_get_spsr_for_bl33_entry(void)
64{
65 unsigned long el_status;
66 unsigned int mode;
67 uint32_t spsr;
68
69 /* Figure out what mode we enter the non-secure world in */
70 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
71 el_status &= ID_AA64PFR0_ELX_MASK;
72
73 mode = (el_status) ? MODE_EL2 : MODE_EL1;
74
75 /*
76 * TODO: Consider the possibility of specifying the SPSR in
77 * the FIP ToC and allowing the platform to have a say as
78 * well.
79 */
80 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
81 return spsr;
82}
83#else
84uint32_t poplar_get_spsr_for_bl33_entry(void)
85{
86 unsigned int hyp_status, mode, spsr;
87
88 hyp_status = GET_VIRT_EXT(read_id_pfr1());
89
90 mode = (hyp_status) ? MODE32_hyp : MODE32_svc;
91
92 /*
93 * TODO: Consider the possibility of specifying the SPSR in
94 * the FIP ToC and allowing the platform to have a say as
95 * well.
96 */
97 spsr = SPSR_MODE32(mode, plat_get_ns_image_entrypoint() & 0x1,
98 SPSR_E_LITTLE, DISABLE_ALL_EXCEPTIONS);
99 return spsr;
100}
101#endif /* AARCH32 */
102
Victor Chong175dd8a2018-02-01 00:35:22 +0900103int poplar_bl2_handle_post_image_load(unsigned int image_id)
104{
105 int err = 0;
106 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Victor Chongaa033472018-02-01 00:35:39 +0900107#ifdef SPD_opteed
108 bl_mem_params_node_t *pager_mem_params = NULL;
109 bl_mem_params_node_t *paged_mem_params = NULL;
110#endif
Victor Chong175dd8a2018-02-01 00:35:22 +0900111
112 assert(bl_mem_params);
113
114 switch (image_id) {
115#ifdef AARCH64
116 case BL32_IMAGE_ID:
Victor Chongaa033472018-02-01 00:35:39 +0900117#ifdef SPD_opteed
118 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
119 assert(pager_mem_params);
120
121 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
122 assert(paged_mem_params);
123
124 err = parse_optee_header(&bl_mem_params->ep_info,
125 &pager_mem_params->image_info,
126 &paged_mem_params->image_info);
127 if (err != 0) {
128 WARN("OPTEE header parse error.\n");
129 }
130
131 /*
132 * OP-TEE expect to receive DTB address in x2.
133 * This will be copied into x2 by dispatcher.
134 * Set this (arg3) if necessary
135 */
136 /* bl_mem_params->ep_info.args.arg3 = PLAT_HIKEY_DT_BASE; */
137#endif
Victor Chong175dd8a2018-02-01 00:35:22 +0900138 bl_mem_params->ep_info.spsr = poplar_get_spsr_for_bl32_entry();
139 break;
140#endif
141
142 case BL33_IMAGE_ID:
143 /* BL33 expects to receive the primary CPU MPID (through r0) */
144 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
145 bl_mem_params->ep_info.spsr = poplar_get_spsr_for_bl33_entry();
146 break;
147
148#ifdef SCP_BL2_BASE
149 case SCP_BL2_IMAGE_ID:
150 /* The subsequent handling of SCP_BL2 is platform specific */
151 err = plat_poplar_bl2_handle_scp_bl2(&bl_mem_params->image_info);
152 if (err) {
153 WARN("Failure in platform-specific handling of SCP_BL2 image.\n");
154 }
155 break;
156#endif
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000157 default:
158 /* Do nothing in default case */
159 break;
Victor Chong175dd8a2018-02-01 00:35:22 +0900160 }
161
162 return err;
163}
164
165/*******************************************************************************
166 * This function can be used by the platforms to update/use image
167 * information for given `image_id`.
168 ******************************************************************************/
169int bl2_plat_handle_post_image_load(unsigned int image_id)
170{
171 return poplar_bl2_handle_post_image_load(image_id);
172}
173
Antonio Nino Diaze93cde12018-09-24 17:15:15 +0100174void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
175 u_register_t arg2, u_register_t arg3)
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200176{
Antonio Nino Diaze93cde12018-09-24 17:15:15 +0100177 struct meminfo *mem_layout = (struct meminfo *)arg1;
Shawn Guod793ff02018-09-27 16:48:00 +0800178#if !POPLAR_RECOVERY
Haojian Zhuang3eff4092018-08-04 18:07:26 +0800179 struct mmc_device_info info;
180
Victor Chong539408d2018-01-03 01:53:08 +0900181 dw_mmc_params_t params = EMMC_INIT_PARAMS(POPLAR_EMMC_DESC_BASE);
Victor Chongf0c7c612018-01-16 00:29:47 +0900182#endif
Victor Chong539408d2018-01-03 01:53:08 +0900183
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200184 console_init(PL011_UART0_BASE, PL011_UART0_CLK_IN_HZ, PL011_BAUDRATE);
185
186 /* Enable arch timer */
187 generic_delay_timer_init();
188
189 bl2_tzram_layout = *mem_layout;
Victor Chong539408d2018-01-03 01:53:08 +0900190
Victor Chongf0c7c612018-01-16 00:29:47 +0900191#if !POPLAR_RECOVERY
Victor Chong539408d2018-01-03 01:53:08 +0900192 /* SoC-specific emmc register are initialized/configured by bootrom */
193 INFO("BL2: initializing emmc\n");
Haojian Zhuang3eff4092018-08-04 18:07:26 +0800194 info.mmc_dev_type = MMC_IS_EMMC;
195 dw_mmc_init(&params, &info);
Victor Chongf0c7c612018-01-16 00:29:47 +0900196#endif
Victor Chong539408d2018-01-03 01:53:08 +0900197
198 plat_io_setup();
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200199}
200
201void bl2_plat_arch_setup(void)
202{
203 plat_configure_mmu_el1(bl2_tzram_layout.total_base,
204 bl2_tzram_layout.total_size,
205 BL2_RO_BASE,
206 BL2_RO_LIMIT,
207 BL2_COHERENT_RAM_BASE,
208 BL2_COHERENT_RAM_LIMIT);
209}
210
211void bl2_platform_setup(void)
212{
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200213}
214
Victor Chong175dd8a2018-02-01 00:35:22 +0900215uintptr_t plat_get_ns_image_entrypoint(void)
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200216{
Victor Chong175dd8a2018-02-01 00:35:22 +0900217#ifdef PRELOADED_BL33_BASE
218 return PRELOADED_BL33_BASE;
219#else
Victor Chong6df271c2017-10-27 00:09:14 +0900220 return PLAT_POPLAR_NS_IMAGE_OFFSET;
Victor Chong175dd8a2018-02-01 00:35:22 +0900221#endif
Jorge Ramirez-Ortiza29d9a62017-06-28 10:11:31 +0200222}