blob: 7c87ce33843531d4ddbe485482d3c72dd94d6c8e [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 {
27 bl31_params_t bl31_params;
28 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 */
71bl31_params_t *bl2_plat_get_bl31_params(void)
72{
73 bl31_params_t *bl2_to_bl31_params;
74
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
112 return bl2_to_bl31_params;
113}
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
156void bl2_early_platform_setup(meminfo_t *mem_layout)
157{
158 marvell_bl2_early_platform_setup(mem_layout);
159}
160
161void bl2_platform_setup(void)
162{
163 /* Nothing to do */
164}
165
166/*****************************************************************************
167 * Perform the very early platform specific architectural setup here. At the
168 * moment this is only initializes the mmu in a quick and dirty way.
169 *****************************************************************************
170 */
171void marvell_bl2_plat_arch_setup(void)
172{
173 marvell_setup_page_tables(bl2_tzram_layout.total_base,
174 bl2_tzram_layout.total_size,
175 BL_CODE_BASE,
176 BL_CODE_END,
177 BL_RO_DATA_BASE,
178 BL_RO_DATA_END
179#if USE_COHERENT_MEM
180 , BL_COHERENT_RAM_BASE,
181 BL_COHERENT_RAM_END
182#endif
183 );
184 enable_mmu_el1(0);
185}
186
187void bl2_plat_arch_setup(void)
188{
189 marvell_bl2_plat_arch_setup();
190}
191
192/*****************************************************************************
193 * Populate the extents of memory available for loading SCP_BL2 (if used),
194 * i.e. anywhere in trusted RAM as long as it doesn't overwrite BL2.
195 *****************************************************************************
196 */
197void bl2_plat_get_scp_bl2_meminfo(meminfo_t *scp_bl2_meminfo)
198{
199 *scp_bl2_meminfo = bl2_tzram_layout;
200}
201
202/*****************************************************************************
203 * Before calling this function BL31 is loaded in memory and its entrypoint
204 * is set by load_image. This is a placeholder for the platform to change
205 * the entrypoint of BL31 and set SPSR and security state.
206 * On MARVELL std. platforms we only set the security state of the entrypoint
207 *****************************************************************************
208 */
209void bl2_plat_set_bl31_ep_info(image_info_t *bl31_image_info,
210 entry_point_info_t *bl31_ep_info)
211{
212 SET_SECURITY_STATE(bl31_ep_info->h.attr, SECURE);
213 bl31_ep_info->spsr = SPSR_64(MODE_EL3, MODE_SP_ELX,
214 DISABLE_ALL_EXCEPTIONS);
215}
216
217/*****************************************************************************
218 * Populate the extents of memory available for loading BL32
219 *****************************************************************************
220 */
221#ifdef BL32_BASE
222void bl2_plat_get_bl32_meminfo(meminfo_t *bl32_meminfo)
223{
224 /*
225 * Populate the extents of memory available for loading BL32.
226 */
227 bl32_meminfo->total_base = BL32_BASE;
228 bl32_meminfo->free_base = BL32_BASE;
229 bl32_meminfo->total_size =
230 (TRUSTED_DRAM_BASE + TRUSTED_DRAM_SIZE) - BL32_BASE;
231 bl32_meminfo->free_size =
232 (TRUSTED_DRAM_BASE + TRUSTED_DRAM_SIZE) - BL32_BASE;
233}
234#endif
235
236/*****************************************************************************
237 * Before calling this function BL32 is loaded in memory and its entrypoint
238 * is set by load_image. This is a placeholder for the platform to change
239 * the entrypoint of BL32 and set SPSR and security state.
240 * On MARVELL std. platforms we only set the security state of the entrypoint
241 *****************************************************************************
242 */
243void bl2_plat_set_bl32_ep_info(image_info_t *bl32_image_info,
244 entry_point_info_t *bl32_ep_info)
245{
246 SET_SECURITY_STATE(bl32_ep_info->h.attr, SECURE);
247 bl32_ep_info->spsr = marvell_get_spsr_for_bl32_entry();
248}
249
250/*****************************************************************************
251 * Before calling this function BL33 is loaded in memory and its entrypoint
252 * is set by load_image. This is a placeholder for the platform to change
253 * the entrypoint of BL33 and set SPSR and security state.
254 * On MARVELL std. platforms we only set the security state of the entrypoint
255 *****************************************************************************
256 */
257void bl2_plat_set_bl33_ep_info(image_info_t *image,
258 entry_point_info_t *bl33_ep_info)
259{
260
261 SET_SECURITY_STATE(bl33_ep_info->h.attr, NON_SECURE);
262 bl33_ep_info->spsr = marvell_get_spsr_for_bl33_entry();
263}
264
265/*****************************************************************************
266 * Populate the extents of memory available for loading BL33
267 *****************************************************************************
268 */
269void bl2_plat_get_bl33_meminfo(meminfo_t *bl33_meminfo)
270{
271 bl33_meminfo->total_base = MARVELL_DRAM_BASE;
272 bl33_meminfo->total_size = MARVELL_DRAM_SIZE;
273 bl33_meminfo->free_base = MARVELL_DRAM_BASE;
274 bl33_meminfo->free_size = MARVELL_DRAM_SIZE;
275}