blob: 7a48358c1ecb4bc06d95b13232488ced0dd999f1 [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/*
50 * The next 2 constants identify the extents of the coherent memory region.
51 * These addresses are used by the MMU setup code and therefore they must be
52 * page-aligned. It is the responsibility of the linker script to ensure that
53 * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols
54 * refer to page-aligned addresses.
55 */
56#define BL31_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__)
57#define BL31_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__)
58
59/*
60 * Placeholder variables for copying the arguments that have been passed to
61 * BL3-1 from BL2.
62 */
63static entry_point_info_t bl32_image_ep_info;
64static entry_point_info_t bl33_image_ep_info;
65
66/*******************************************************************************
67 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
68 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
69 * they are lost (potentially). This needs to be done before the MMU is
70 * initialized so that the memory layout can be used while creating page
71 * tables. BL2 has flushed this information to memory, so we are guaranteed
72 * to pick up good data.
73 ******************************************************************************/
74void bl31_early_platform_setup(bl31_params_t *from_bl2,
75 void *plat_params_from_bl2)
76{
77 /* Initialize the console to provide early debug support */
78 console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ,
79 PLAT_QEMU_CONSOLE_BAUDRATE);
80
81 /*
82 * Check params passed from BL2 should not be NULL,
83 */
84 assert(from_bl2 != NULL);
85 assert(from_bl2->h.type == PARAM_BL31);
86 assert(from_bl2->h.version >= VERSION_1);
87 /*
88 * In debug builds, we pass a special value in 'plat_params_from_bl2'
89 * to verify platform parameters from BL2 to BL3-1.
90 * In release builds, it's not used.
91 */
92 assert(((unsigned long long)plat_params_from_bl2) ==
93 QEMU_BL31_PLAT_PARAM_VAL);
94
95 /*
96 * Copy BL3-2 (if populated by BL2) and BL3-3 entry point information.
97 * They are stored in Secure RAM, in BL2's address space.
98 */
99 if (from_bl2->bl32_ep_info)
100 bl32_image_ep_info = *from_bl2->bl32_ep_info;
101 bl33_image_ep_info = *from_bl2->bl33_ep_info;
102}
103
104void bl31_plat_arch_setup(void)
105{
106 qemu_configure_mmu_el3(BL31_RO_BASE, (BL31_END - BL31_RO_BASE),
107 BL31_RO_BASE, BL31_RO_LIMIT,
108 BL31_COHERENT_RAM_BASE, BL31_COHERENT_RAM_LIMIT);
109}
110
111static const unsigned int irq_sec_array[] = {
112 QEMU_IRQ_SEC_SGI_0,
113 QEMU_IRQ_SEC_SGI_1,
114 QEMU_IRQ_SEC_SGI_2,
115 QEMU_IRQ_SEC_SGI_3,
116 QEMU_IRQ_SEC_SGI_4,
117 QEMU_IRQ_SEC_SGI_5,
118 QEMU_IRQ_SEC_SGI_6,
119 QEMU_IRQ_SEC_SGI_7,
120};
121
122static const struct gicv2_driver_data plat_gicv2_driver_data = {
123 .gicd_base = GICD_BASE,
124 .gicc_base = GICC_BASE,
125 .g0_interrupt_num = ARRAY_SIZE(irq_sec_array),
126 .g0_interrupt_array = irq_sec_array,
127};
128
129void bl31_platform_setup(void)
130{
131 /* Initialize the gic cpu and distributor interfaces */
132 gicv2_driver_init(&plat_gicv2_driver_data);
133 gicv2_distif_init();
134 gicv2_pcpu_distif_init();
135 gicv2_cpuif_enable();
136}
137
138unsigned int plat_get_syscnt_freq2(void)
139{
140 return SYS_COUNTER_FREQ_IN_TICKS;
141}
142
143/*******************************************************************************
144 * Return a pointer to the 'entry_point_info' structure of the next image
145 * for the security state specified. BL3-3 corresponds to the non-secure
146 * image type while BL3-2 corresponds to the secure image type. A NULL
147 * pointer is returned if the image does not exist.
148 ******************************************************************************/
149entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
150{
151 entry_point_info_t *next_image_info;
152
153 assert(sec_state_is_valid(type));
154 next_image_info = (type == NON_SECURE)
155 ? &bl33_image_ep_info : &bl32_image_ep_info;
156 /*
157 * None of the images on the ARM development platforms can have 0x0
158 * as the entrypoint
159 */
160 if (next_image_info->pc)
161 return next_image_info;
162 else
163 return NULL;
164}