blob: e8f60fd84f6f08ad7489683bf81ba3b0487402f3 [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
8#include <arch_helpers.h>
9#include <bl_common.h>
10#include <console.h>
11#include <marvell_def.h>
12#include <platform_def.h>
13#include <plat_marvell.h>
14#include <string.h>
15
16/* Data structure which holds the extents of the trusted SRAM for BL2 */
17static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
18
19
20/*****************************************************************************
21 * This structure represents the superset of information that is passed to
22 * BL31, e.g. while passing control to it from BL2, bl31_params
23 * and other platform specific parameters
24 *****************************************************************************
25 */
26typedef struct bl2_to_bl31_params_mem {
Antonio Nino Diaz79662212018-09-24 17:15:46 +010027 struct marvell_bl31_params bl31_params;
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030028 image_info_t bl31_image_info;
29 image_info_t bl32_image_info;
30 image_info_t bl33_image_info;
31 entry_point_info_t bl33_ep_info;
32 entry_point_info_t bl32_ep_info;
33 entry_point_info_t bl31_ep_info;
34} bl2_to_bl31_params_mem_t;
35
36
37static bl2_to_bl31_params_mem_t bl31_params_mem;
38
39
40/* Weak definitions may be overridden in specific MARVELL standard platform */
41#pragma weak bl2_early_platform_setup
42#pragma weak bl2_platform_setup
43#pragma weak bl2_plat_arch_setup
44#pragma weak bl2_plat_sec_mem_layout
45#pragma weak bl2_plat_get_bl31_params
46#pragma weak bl2_plat_get_bl31_ep_info
47#pragma weak bl2_plat_flush_bl31_params
48#pragma weak bl2_plat_set_bl31_ep_info
49#pragma weak bl2_plat_get_scp_bl2_meminfo
50#pragma weak bl2_plat_get_bl32_meminfo
51#pragma weak bl2_plat_set_bl32_ep_info
52#pragma weak bl2_plat_get_bl33_meminfo
53#pragma weak bl2_plat_set_bl33_ep_info
54
55
56meminfo_t *bl2_plat_sec_mem_layout(void)
57{
58 return &bl2_tzram_layout;
59}
60
61/*****************************************************************************
62 * This function assigns a pointer to the memory that the platform has kept
63 * aside to pass platform specific and trusted firmware related information
64 * to BL31. This memory is allocated by allocating memory to
65 * bl2_to_bl31_params_mem_t structure which is a superset of all the
66 * structure whose information is passed to BL31
67 * NOTE: This function should be called only once and should be done
68 * before generating params to BL31
69 *****************************************************************************
70 */
Antonio Nino Diaz79662212018-09-24 17:15:46 +010071void *bl2_plat_get_bl31_params(void)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030072{
Antonio Nino Diaz79662212018-09-24 17:15:46 +010073 struct marvell_bl31_params *bl2_to_bl31_params;
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030074
75 /*
76 * Initialise the memory for all the arguments that needs to
77 * be passed to BL31
78 */
79 memset(&bl31_params_mem, 0, sizeof(bl2_to_bl31_params_mem_t));
80
81 /* Assign memory for TF related information */
82 bl2_to_bl31_params = &bl31_params_mem.bl31_params;
83 SET_PARAM_HEAD(bl2_to_bl31_params, PARAM_BL31, VERSION_1, 0);
84
85 /* Fill BL31 related information */
86 bl2_to_bl31_params->bl31_image_info = &bl31_params_mem.bl31_image_info;
87 SET_PARAM_HEAD(bl2_to_bl31_params->bl31_image_info, PARAM_IMAGE_BINARY,
88 VERSION_1, 0);
89
90 /* Fill BL32 related information if it exists */
91#if BL32_BASE
92 bl2_to_bl31_params->bl32_ep_info = &bl31_params_mem.bl32_ep_info;
93 SET_PARAM_HEAD(bl2_to_bl31_params->bl32_ep_info, PARAM_EP,
94 VERSION_1, 0);
95 bl2_to_bl31_params->bl32_image_info = &bl31_params_mem.bl32_image_info;
96 SET_PARAM_HEAD(bl2_to_bl31_params->bl32_image_info, PARAM_IMAGE_BINARY,
97 VERSION_1, 0);
98#endif
99
100 /* Fill BL33 related information */
101 bl2_to_bl31_params->bl33_ep_info = &bl31_params_mem.bl33_ep_info;
102 SET_PARAM_HEAD(bl2_to_bl31_params->bl33_ep_info,
103 PARAM_EP, VERSION_1, 0);
104
105 /* BL33 expects to receive the primary CPU MPID (through x0) */
106 bl2_to_bl31_params->bl33_ep_info->args.arg0 = 0xffff & read_mpidr();
107
108 bl2_to_bl31_params->bl33_image_info = &bl31_params_mem.bl33_image_info;
109 SET_PARAM_HEAD(bl2_to_bl31_params->bl33_image_info, PARAM_IMAGE_BINARY,
110 VERSION_1, 0);
111
Antonio Nino Diaz79662212018-09-24 17:15:46 +0100112 return (void *)bl2_to_bl31_params;
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300113}
114
115/* Flush the TF params and the TF plat params */
116void bl2_plat_flush_bl31_params(void)
117{
118 flush_dcache_range((unsigned long)&bl31_params_mem,
119 sizeof(bl2_to_bl31_params_mem_t));
120}
121
122/*****************************************************************************
123 * This function returns a pointer to the shared memory that the platform
124 * has kept to point to entry point information of BL31 to BL2
125 *****************************************************************************
126 */
127struct entry_point_info *bl2_plat_get_bl31_ep_info(void)
128{
129#if DEBUG
130 bl31_params_mem.bl31_ep_info.args.arg1 = MARVELL_BL31_PLAT_PARAM_VAL;
131#endif
132
133 return &bl31_params_mem.bl31_ep_info;
134}
135
136/*****************************************************************************
137 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
138 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
139 * Copy it to a safe location before its reclaimed by later BL2 functionality.
140 *****************************************************************************
141 */
142void marvell_bl2_early_platform_setup(meminfo_t *mem_layout)
143{
144 /* Initialize the console to provide early debug support */
145 console_init(PLAT_MARVELL_BOOT_UART_BASE,
146 PLAT_MARVELL_BOOT_UART_CLK_IN_HZ,
147 MARVELL_CONSOLE_BAUDRATE);
148
149 /* Setup the BL2 memory layout */
150 bl2_tzram_layout = *mem_layout;
151
152 /* Initialise the IO layer and register platform IO devices */
153 plat_marvell_io_setup();
154}
155
Antonio Nino Diaz79662212018-09-24 17:15:46 +0100156
157void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
158 u_register_t arg2, u_register_t arg3)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300159{
Antonio Nino Diaz79662212018-09-24 17:15:46 +0100160 struct meminfo *mem_layout = (struct meminfo *)arg1;
161
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300162 marvell_bl2_early_platform_setup(mem_layout);
163}
164
165void bl2_platform_setup(void)
166{
167 /* Nothing to do */
168}
169
170/*****************************************************************************
171 * Perform the very early platform specific architectural setup here. At the
172 * moment this is only initializes the mmu in a quick and dirty way.
173 *****************************************************************************
174 */
175void marvell_bl2_plat_arch_setup(void)
176{
177 marvell_setup_page_tables(bl2_tzram_layout.total_base,
178 bl2_tzram_layout.total_size,
179 BL_CODE_BASE,
180 BL_CODE_END,
181 BL_RO_DATA_BASE,
182 BL_RO_DATA_END
183#if USE_COHERENT_MEM
184 , BL_COHERENT_RAM_BASE,
185 BL_COHERENT_RAM_END
186#endif
187 );
188 enable_mmu_el1(0);
189}
190
191void bl2_plat_arch_setup(void)
192{
193 marvell_bl2_plat_arch_setup();
194}
195
196/*****************************************************************************
197 * Populate the extents of memory available for loading SCP_BL2 (if used),
198 * i.e. anywhere in trusted RAM as long as it doesn't overwrite BL2.
199 *****************************************************************************
200 */
201void bl2_plat_get_scp_bl2_meminfo(meminfo_t *scp_bl2_meminfo)
202{
203 *scp_bl2_meminfo = bl2_tzram_layout;
204}
205
206/*****************************************************************************
207 * Before calling this function BL31 is loaded in memory and its entrypoint
208 * is set by load_image. This is a placeholder for the platform to change
209 * the entrypoint of BL31 and set SPSR and security state.
210 * On MARVELL std. platforms we only set the security state of the entrypoint
211 *****************************************************************************
212 */
213void bl2_plat_set_bl31_ep_info(image_info_t *bl31_image_info,
214 entry_point_info_t *bl31_ep_info)
215{
216 SET_SECURITY_STATE(bl31_ep_info->h.attr, SECURE);
217 bl31_ep_info->spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
218 DISABLE_ALL_EXCEPTIONS);
219}
220
221/*****************************************************************************
222 * Populate the extents of memory available for loading BL32
223 *****************************************************************************
224 */
225#ifdef BL32_BASE
226void bl2_plat_get_bl32_meminfo(meminfo_t *bl32_meminfo)
227{
228 /*
229 * Populate the extents of memory available for loading BL32.
230 */
231 bl32_meminfo->total_base = BL32_BASE;
232 bl32_meminfo->free_base = BL32_BASE;
233 bl32_meminfo->total_size =
234 (TRUSTED_DRAM_BASE + TRUSTED_DRAM_SIZE) - BL32_BASE;
235 bl32_meminfo->free_size =
236 (TRUSTED_DRAM_BASE + TRUSTED_DRAM_SIZE) - BL32_BASE;
237}
238#endif
239
240/*****************************************************************************
241 * Before calling this function BL32 is loaded in memory and its entrypoint
242 * is set by load_image. This is a placeholder for the platform to change
243 * the entrypoint of BL32 and set SPSR and security state.
244 * On MARVELL std. platforms we only set the security state of the entrypoint
245 *****************************************************************************
246 */
247void bl2_plat_set_bl32_ep_info(image_info_t *bl32_image_info,
248 entry_point_info_t *bl32_ep_info)
249{
250 SET_SECURITY_STATE(bl32_ep_info->h.attr, SECURE);
251 bl32_ep_info->spsr = marvell_get_spsr_for_bl32_entry();
252}
253
254/*****************************************************************************
255 * Before calling this function BL33 is loaded in memory and its entrypoint
256 * is set by load_image. This is a placeholder for the platform to change
257 * the entrypoint of BL33 and set SPSR and security state.
258 * On MARVELL std. platforms we only set the security state of the entrypoint
259 *****************************************************************************
260 */
261void bl2_plat_set_bl33_ep_info(image_info_t *image,
262 entry_point_info_t *bl33_ep_info)
263{
264
265 SET_SECURITY_STATE(bl33_ep_info->h.attr, NON_SECURE);
266 bl33_ep_info->spsr = marvell_get_spsr_for_bl33_entry();
267}
268
269/*****************************************************************************
270 * Populate the extents of memory available for loading BL33
271 *****************************************************************************
272 */
273void bl2_plat_get_bl33_meminfo(meminfo_t *bl33_meminfo)
274{
275 bl33_meminfo->total_base = MARVELL_DRAM_BASE;
276 bl33_meminfo->total_size = MARVELL_DRAM_SIZE;
277 bl33_meminfo->free_base = MARVELL_DRAM_BASE;
278 bl33_meminfo->free_size = MARVELL_DRAM_SIZE;
279}