blob: 547e13559f4d3846a3ed5f8a92a12525e4cfb721 [file] [log] [blame]
Jens Wiklander52c798e2015-12-07 14:37:10 +01001/*
2 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <assert.h>
32#include <bl_common.h>
33#include <console.h>
34#include <gicv2.h>
35#include <platform_def.h>
36#include "qemu_private.h"
37
38/*
39 * The next 3 constants identify the extents of the code, RO data region and the
40 * limit of the BL3-1 image. These addresses are used by the MMU setup code and
41 * therefore they must be page-aligned. It is the responsibility of the linker
42 * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
43 * refer to page-aligned addresses.
44 */
45#define BL31_RO_BASE (unsigned long)(&__RO_START__)
46#define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
47#define BL31_END (unsigned long)(&__BL31_END__)
48
49/*
Jens Wiklander52c798e2015-12-07 14:37:10 +010050 * Placeholder variables for copying the arguments that have been passed to
51 * BL3-1 from BL2.
52 */
53static entry_point_info_t bl32_image_ep_info;
54static entry_point_info_t bl33_image_ep_info;
55
56/*******************************************************************************
57 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
58 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
59 * they are lost (potentially). This needs to be done before the MMU is
60 * initialized so that the memory layout can be used while creating page
61 * tables. BL2 has flushed this information to memory, so we are guaranteed
62 * to pick up good data.
63 ******************************************************************************/
64void bl31_early_platform_setup(bl31_params_t *from_bl2,
65 void *plat_params_from_bl2)
66{
67 /* Initialize the console to provide early debug support */
68 console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ,
69 PLAT_QEMU_CONSOLE_BAUDRATE);
70
71 /*
72 * Check params passed from BL2 should not be NULL,
73 */
74 assert(from_bl2 != NULL);
75 assert(from_bl2->h.type == PARAM_BL31);
76 assert(from_bl2->h.version >= VERSION_1);
77 /*
78 * In debug builds, we pass a special value in 'plat_params_from_bl2'
79 * to verify platform parameters from BL2 to BL3-1.
80 * In release builds, it's not used.
81 */
82 assert(((unsigned long long)plat_params_from_bl2) ==
83 QEMU_BL31_PLAT_PARAM_VAL);
84
85 /*
86 * Copy BL3-2 (if populated by BL2) and BL3-3 entry point information.
87 * They are stored in Secure RAM, in BL2's address space.
88 */
89 if (from_bl2->bl32_ep_info)
90 bl32_image_ep_info = *from_bl2->bl32_ep_info;
91 bl33_image_ep_info = *from_bl2->bl33_ep_info;
92}
93
94void bl31_plat_arch_setup(void)
95{
96 qemu_configure_mmu_el3(BL31_RO_BASE, (BL31_END - BL31_RO_BASE),
97 BL31_RO_BASE, BL31_RO_LIMIT,
Masahiro Yamada0fac5af2016-12-28 16:11:41 +090098 BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
Jens Wiklander52c798e2015-12-07 14:37:10 +010099}
100
101static const unsigned int irq_sec_array[] = {
102 QEMU_IRQ_SEC_SGI_0,
103 QEMU_IRQ_SEC_SGI_1,
104 QEMU_IRQ_SEC_SGI_2,
105 QEMU_IRQ_SEC_SGI_3,
106 QEMU_IRQ_SEC_SGI_4,
107 QEMU_IRQ_SEC_SGI_5,
108 QEMU_IRQ_SEC_SGI_6,
109 QEMU_IRQ_SEC_SGI_7,
110};
111
112static const struct gicv2_driver_data plat_gicv2_driver_data = {
113 .gicd_base = GICD_BASE,
114 .gicc_base = GICC_BASE,
115 .g0_interrupt_num = ARRAY_SIZE(irq_sec_array),
116 .g0_interrupt_array = irq_sec_array,
117};
118
119void bl31_platform_setup(void)
120{
121 /* Initialize the gic cpu and distributor interfaces */
122 gicv2_driver_init(&plat_gicv2_driver_data);
123 gicv2_distif_init();
124 gicv2_pcpu_distif_init();
125 gicv2_cpuif_enable();
126}
127
128unsigned int plat_get_syscnt_freq2(void)
129{
130 return SYS_COUNTER_FREQ_IN_TICKS;
131}
132
133/*******************************************************************************
134 * Return a pointer to the 'entry_point_info' structure of the next image
135 * for the security state specified. BL3-3 corresponds to the non-secure
136 * image type while BL3-2 corresponds to the secure image type. A NULL
137 * pointer is returned if the image does not exist.
138 ******************************************************************************/
139entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
140{
141 entry_point_info_t *next_image_info;
142
143 assert(sec_state_is_valid(type));
144 next_image_info = (type == NON_SECURE)
145 ? &bl33_image_ep_info : &bl32_image_ep_info;
146 /*
147 * None of the images on the ARM development platforms can have 0x0
148 * as the entrypoint
149 */
150 if (next_image_info->pc)
151 return next_image_info;
152 else
153 return NULL;
154}