blob: 802c01383bde07e524aeebe698570cf791e55a44 [file] [log] [blame]
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +03001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +03008#include <assert.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +03009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <arch.h>
11#include <common/debug.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030012#ifdef USE_CCI
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <drivers/arm/cci.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030014#endif
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015#include <drivers/console.h>
16#include <plat/common/platform.h>
17
18#include <marvell_def.h>
19#include <marvell_plat_priv.h>
20#include <plat_marvell.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030021
22/*
23 * The next 3 constants identify the extents of the code, RO data region and the
24 * limit of the BL31 image. These addresses are used by the MMU setup code and
25 * therefore they must be page-aligned. It is the responsibility of the linker
26 * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
27 * refer to page-aligned addresses.
28 */
29#define BL31_END (unsigned long)(&__BL31_END__)
30
31/*
32 * Placeholder variables for copying the arguments that have been passed to
33 * BL31 from BL2.
34 */
35static entry_point_info_t bl32_image_ep_info;
36static entry_point_info_t bl33_image_ep_info;
37
38/* Weak definitions may be overridden in specific ARM standard platform */
Konstantin Porotchkinacb1dc12018-08-19 10:07:35 +030039#pragma weak bl31_early_platform_setup2
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030040#pragma weak bl31_platform_setup
41#pragma weak bl31_plat_arch_setup
42#pragma weak bl31_plat_get_next_image_ep_info
43#pragma weak plat_get_syscnt_freq2
44
45/*****************************************************************************
46 * Return a pointer to the 'entry_point_info' structure of the next image for
47 * the security state specified. BL33 corresponds to the non-secure image type
48 * while BL32 corresponds to the secure image type. A NULL pointer is returned
49 * if the image does not exist.
50 *****************************************************************************
51 */
52entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
53{
54 entry_point_info_t *next_image_info;
55
56 assert(sec_state_is_valid(type));
57 next_image_info = (type == NON_SECURE)
58 ? &bl33_image_ep_info : &bl32_image_ep_info;
59
60 return next_image_info;
61}
62
63/*****************************************************************************
64 * Perform any BL31 early platform setup common to ARM standard platforms.
65 * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
John Tsichritzisd653d332018-09-14 10:34:57 +010066 * in BL2 & EL3 in BL1) before they are lost (potentially). This needs to be
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030067 * done before the MMU is initialized so that the memory layout can be used
68 * while creating page tables. BL2 has flushed this information to memory, so
69 * we are guaranteed to pick up good data.
70 *****************************************************************************
71 */
Antonio Nino Diaz79662212018-09-24 17:15:46 +010072void marvell_bl31_early_platform_setup(void *from_bl2,
Konstantin Porotchkinacb1dc12018-08-19 10:07:35 +030073 uintptr_t soc_fw_config,
74 uintptr_t hw_config,
75 void *plat_params_from_bl2)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030076{
77 /* Initialize the console to provide early debug support */
Konstantin Porotchkind8e39572018-11-14 17:15:08 +020078 marvell_console_boot_init();
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030079
80#if RESET_TO_BL31
81 /* There are no parameters from BL2 if BL31 is a reset vector */
82 assert(from_bl2 == NULL);
83 assert(plat_params_from_bl2 == NULL);
84
85#ifdef BL32_BASE
86 /* Populate entry point information for BL32 */
87 SET_PARAM_HEAD(&bl32_image_ep_info,
88 PARAM_EP,
89 VERSION_1,
90 0);
91 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
92 bl32_image_ep_info.pc = BL32_BASE;
93 bl32_image_ep_info.spsr = marvell_get_spsr_for_bl32_entry();
94#endif /* BL32_BASE */
95
96 /* Populate entry point information for BL33 */
97 SET_PARAM_HEAD(&bl33_image_ep_info,
98 PARAM_EP,
99 VERSION_1,
100 0);
101 /*
102 * Tell BL31 where the non-trusted software image
103 * is located and the entry state information
104 */
105 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
106 bl33_image_ep_info.spsr = marvell_get_spsr_for_bl33_entry();
107 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
108
109#else
110 /*
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300111 * In debug builds, we pass a special value in 'plat_params_from_bl2'
112 * to verify platform parameters from BL2 to BL31.
113 * In release builds, it's not used.
114 */
115 assert(((unsigned long long)plat_params_from_bl2) ==
116 MARVELL_BL31_PLAT_PARAM_VAL);
117
118 /*
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300119 * Check params passed from BL2 should not be NULL,
120 */
121 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
122 assert(params_from_bl2 != NULL);
123 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
124 assert(params_from_bl2->h.version >= VERSION_2);
125
126 bl_params_node_t *bl_params = params_from_bl2->head;
127
128 /*
129 * Copy BL33 and BL32 (if present), entry point information.
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300130 * They are stored in Secure RAM, in BL2's address space.
131 */
Konstantin Porotchkind973c032018-10-02 17:45:15 +0300132 while (bl_params != NULL) {
133 if (bl_params->image_id == BL32_IMAGE_ID)
134 bl32_image_ep_info = *bl_params->ep_info;
135
136 if (bl_params->image_id == BL33_IMAGE_ID)
137 bl33_image_ep_info = *bl_params->ep_info;
138
139 bl_params = bl_params->next_params_info;
140 }
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300141#endif
142}
143
Konstantin Porotchkinacb1dc12018-08-19 10:07:35 +0300144void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
145 u_register_t arg2, u_register_t arg3)
146
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300147{
Konstantin Porotchkinacb1dc12018-08-19 10:07:35 +0300148 marvell_bl31_early_platform_setup((void *)arg0, arg1, arg2,
149 (void *)arg3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300150
151#ifdef USE_CCI
152 /*
153 * Initialize CCI for this cluster during cold boot.
154 * No need for locks as no other CPU is active.
155 */
156 plat_marvell_interconnect_init();
157
158 /*
159 * Enable CCI coherency for the primary CPU's cluster.
160 * Platform specific PSCI code will enable coherency for other
161 * clusters.
162 */
163 plat_marvell_interconnect_enter_coherency();
164#endif
165}
166
167/*****************************************************************************
168 * Perform any BL31 platform setup common to ARM standard platforms
169 *****************************************************************************
170 */
171void marvell_bl31_platform_setup(void)
172{
173 /* Initialize the GIC driver, cpu and distributor interfaces */
174 plat_marvell_gic_driver_init();
175 plat_marvell_gic_init();
176
177 /* For Armada-8k-plus family, the SoC includes more than
178 * a single AP die, but the default die that boots is AP #0.
179 * For other families there is only one die (#0).
180 * Initialize psci arch from die 0
181 */
182 marvell_psci_arch_init(0);
183}
184
185/*****************************************************************************
186 * Perform any BL31 platform runtime setup prior to BL31 exit common to ARM
187 * standard platforms
188 *****************************************************************************
189 */
190void marvell_bl31_plat_runtime_setup(void)
191{
Konstantin Porotchkind8e39572018-11-14 17:15:08 +0200192 console_switch_state(CONSOLE_FLAG_RUNTIME);
193
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300194 /* Initialize the runtime console */
Konstantin Porotchkind8e39572018-11-14 17:15:08 +0200195 marvell_console_runtime_init();
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300196}
197
198void bl31_platform_setup(void)
199{
200 marvell_bl31_platform_setup();
201}
202
203void bl31_plat_runtime_setup(void)
204{
205 marvell_bl31_plat_runtime_setup();
206}
207
208/*****************************************************************************
209 * Perform the very early platform specific architectural setup shared between
210 * ARM standard platforms. This only does basic initialization. Later
211 * architectural setup (bl31_arch_setup()) does not do anything platform
212 * specific.
213 *****************************************************************************
214 */
215void marvell_bl31_plat_arch_setup(void)
216{
217 marvell_setup_page_tables(BL31_BASE,
218 BL31_END - BL31_BASE,
219 BL_CODE_BASE,
220 BL_CODE_END,
221 BL_RO_DATA_BASE,
222 BL_RO_DATA_END
223#if USE_COHERENT_MEM
224 , BL_COHERENT_RAM_BASE,
225 BL_COHERENT_RAM_END
226#endif
227 );
228
229#if BL31_CACHE_DISABLE
230 enable_mmu_el3(DISABLE_DCACHE);
231 INFO("Cache is disabled in BL3\n");
232#else
233 enable_mmu_el3(0);
234#endif
235}
236
237void bl31_plat_arch_setup(void)
238{
239 marvell_bl31_plat_arch_setup();
240}
241
242unsigned int plat_get_syscnt_freq2(void)
243{
244 return PLAT_REF_CLK_IN_HZ;
245}