blob: 4d36b039192a2ab9932fea46d4d5a0d8c2fdc51a [file] [log] [blame]
Jens Wiklander52c798e2015-12-07 14:37:10 +01001/*
Hongbo Zhang32338ec2018-04-19 13:06:07 +08002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Jens Wiklander52c798e2015-12-07 14:37:10 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Jens Wiklander52c798e2015-12-07 14:37:10 +01005 */
6
7#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009#include <common/bl_common.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <plat/common/platform.h>
11
Jens Wiklander52c798e2015-12-07 14:37:10 +010012#include "qemu_private.h"
13
14/*
Jens Wiklander52c798e2015-12-07 14:37:10 +010015 * Placeholder variables for copying the arguments that have been passed to
16 * BL3-1 from BL2.
17 */
18static entry_point_info_t bl32_image_ep_info;
19static entry_point_info_t bl33_image_ep_info;
20
21/*******************************************************************************
22 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
John Tsichritzisd653d332018-09-14 10:34:57 +010023 * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before
Jens Wiklander52c798e2015-12-07 14:37:10 +010024 * they are lost (potentially). This needs to be done before the MMU is
25 * initialized so that the memory layout can be used while creating page
26 * tables. BL2 has flushed this information to memory, so we are guaranteed
27 * to pick up good data.
28 ******************************************************************************/
Jens Wiklandere22b91e2018-09-04 14:07:19 +020029void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
30 u_register_t arg2, u_register_t arg3)
Jens Wiklander52c798e2015-12-07 14:37:10 +010031{
32 /* Initialize the console to provide early debug support */
Michalis Pappascca6cb72018-03-04 15:43:38 +080033 qemu_console_init();
Jens Wiklander52c798e2015-12-07 14:37:10 +010034
Fu Weic2f78442017-05-27 21:21:42 +080035 /*
36 * Check params passed from BL2
37 */
Jens Wiklandere22b91e2018-09-04 14:07:19 +020038 bl_params_t *params_from_bl2 = (bl_params_t *)arg0;
Fu Weic2f78442017-05-27 21:21:42 +080039
40 assert(params_from_bl2);
41 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
42 assert(params_from_bl2->h.version >= VERSION_2);
43
44 bl_params_node_t *bl_params = params_from_bl2->head;
45
46 /*
47 * Copy BL33 and BL32 (if present), entry point information.
48 * They are stored in Secure RAM, in BL2's address space.
49 */
50 while (bl_params) {
51 if (bl_params->image_id == BL32_IMAGE_ID)
52 bl32_image_ep_info = *bl_params->ep_info;
53
54 if (bl_params->image_id == BL33_IMAGE_ID)
55 bl33_image_ep_info = *bl_params->ep_info;
56
57 bl_params = bl_params->next_params_info;
58 }
59
60 if (!bl33_image_ep_info.pc)
61 panic();
Jens Wiklander52c798e2015-12-07 14:37:10 +010062}
63
64void bl31_plat_arch_setup(void)
65{
Michalis Pappasba861122018-02-28 14:36:03 +080066 qemu_configure_mmu_el3(BL31_BASE, (BL31_END - BL31_BASE),
67 BL_CODE_BASE, BL_CODE_END,
68 BL_RO_DATA_BASE, BL_RO_DATA_END,
Masahiro Yamada0fac5af2016-12-28 16:11:41 +090069 BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
Jens Wiklander52c798e2015-12-07 14:37:10 +010070}
71
Jens Wiklander52c798e2015-12-07 14:37:10 +010072void bl31_platform_setup(void)
73{
Hongbo Zhang32338ec2018-04-19 13:06:07 +080074 plat_qemu_gic_init();
Jens Wiklander52c798e2015-12-07 14:37:10 +010075}
76
77unsigned int plat_get_syscnt_freq2(void)
78{
79 return SYS_COUNTER_FREQ_IN_TICKS;
80}
81
82/*******************************************************************************
83 * Return a pointer to the 'entry_point_info' structure of the next image
84 * for the security state specified. BL3-3 corresponds to the non-secure
85 * image type while BL3-2 corresponds to the secure image type. A NULL
86 * pointer is returned if the image does not exist.
87 ******************************************************************************/
88entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
89{
90 entry_point_info_t *next_image_info;
91
92 assert(sec_state_is_valid(type));
93 next_image_info = (type == NON_SECURE)
94 ? &bl33_image_ep_info : &bl32_image_ep_info;
95 /*
96 * None of the images on the ARM development platforms can have 0x0
97 * as the entrypoint
98 */
99 if (next_image_info->pc)
100 return next_image_info;
101 else
102 return NULL;
103}