Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <bl_common.h> |
Etienne Carriere | 84aa3a7 | 2017-11-02 12:05:12 +0100 | [diff] [blame] | 9 | #include <gic_common.h> |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 10 | #include <gicv2.h> |
| 11 | #include <platform_def.h> |
| 12 | #include "qemu_private.h" |
| 13 | |
| 14 | /* |
| 15 | * The next 3 constants identify the extents of the code, RO data region and the |
| 16 | * limit of the BL3-1 image. These addresses are used by the MMU setup code and |
| 17 | * therefore they must be page-aligned. It is the responsibility of the linker |
| 18 | * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols |
| 19 | * refer to page-aligned addresses. |
| 20 | */ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 21 | #define BL31_END (unsigned long)(&__BL31_END__) |
| 22 | |
| 23 | /* |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 24 | * Placeholder variables for copying the arguments that have been passed to |
| 25 | * BL3-1 from BL2. |
| 26 | */ |
| 27 | static entry_point_info_t bl32_image_ep_info; |
| 28 | static entry_point_info_t bl33_image_ep_info; |
| 29 | |
| 30 | /******************************************************************************* |
| 31 | * Perform any BL3-1 early platform setup. Here is an opportunity to copy |
| 32 | * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before |
| 33 | * they are lost (potentially). This needs to be done before the MMU is |
| 34 | * initialized so that the memory layout can be used while creating page |
| 35 | * tables. BL2 has flushed this information to memory, so we are guaranteed |
| 36 | * to pick up good data. |
| 37 | ******************************************************************************/ |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 38 | #if LOAD_IMAGE_V2 |
| 39 | void bl31_early_platform_setup(void *from_bl2, |
| 40 | void *plat_params_from_bl2) |
| 41 | #else |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 42 | void bl31_early_platform_setup(bl31_params_t *from_bl2, |
| 43 | void *plat_params_from_bl2) |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 44 | #endif |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 45 | { |
| 46 | /* Initialize the console to provide early debug support */ |
Michalis Pappas | cca6cb7 | 2018-03-04 15:43:38 +0800 | [diff] [blame] | 47 | qemu_console_init(); |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 48 | |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 49 | #if LOAD_IMAGE_V2 |
| 50 | /* |
| 51 | * Check params passed from BL2 |
| 52 | */ |
| 53 | bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2; |
| 54 | |
| 55 | assert(params_from_bl2); |
| 56 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 57 | assert(params_from_bl2->h.version >= VERSION_2); |
| 58 | |
| 59 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 60 | |
| 61 | /* |
| 62 | * Copy BL33 and BL32 (if present), entry point information. |
| 63 | * They are stored in Secure RAM, in BL2's address space. |
| 64 | */ |
| 65 | while (bl_params) { |
| 66 | if (bl_params->image_id == BL32_IMAGE_ID) |
| 67 | bl32_image_ep_info = *bl_params->ep_info; |
| 68 | |
| 69 | if (bl_params->image_id == BL33_IMAGE_ID) |
| 70 | bl33_image_ep_info = *bl_params->ep_info; |
| 71 | |
| 72 | bl_params = bl_params->next_params_info; |
| 73 | } |
| 74 | |
| 75 | if (!bl33_image_ep_info.pc) |
| 76 | panic(); |
| 77 | |
| 78 | #else /* LOAD_IMAGE_V2 */ |
| 79 | |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 80 | /* |
| 81 | * Check params passed from BL2 should not be NULL, |
| 82 | */ |
| 83 | assert(from_bl2 != NULL); |
| 84 | assert(from_bl2->h.type == PARAM_BL31); |
| 85 | assert(from_bl2->h.version >= VERSION_1); |
| 86 | /* |
| 87 | * In debug builds, we pass a special value in 'plat_params_from_bl2' |
| 88 | * to verify platform parameters from BL2 to BL3-1. |
| 89 | * In release builds, it's not used. |
| 90 | */ |
| 91 | assert(((unsigned long long)plat_params_from_bl2) == |
| 92 | QEMU_BL31_PLAT_PARAM_VAL); |
| 93 | |
| 94 | /* |
| 95 | * Copy BL3-2 (if populated by BL2) and BL3-3 entry point information. |
| 96 | * They are stored in Secure RAM, in BL2's address space. |
| 97 | */ |
| 98 | if (from_bl2->bl32_ep_info) |
| 99 | bl32_image_ep_info = *from_bl2->bl32_ep_info; |
| 100 | bl33_image_ep_info = *from_bl2->bl33_ep_info; |
Fu Wei | c2f7844 | 2017-05-27 21:21:42 +0800 | [diff] [blame] | 101 | |
| 102 | #endif /* !LOAD_IMAGE_V2 */ |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void bl31_plat_arch_setup(void) |
| 106 | { |
Michalis Pappas | ba86112 | 2018-02-28 14:36:03 +0800 | [diff] [blame] | 107 | qemu_configure_mmu_el3(BL31_BASE, (BL31_END - BL31_BASE), |
| 108 | BL_CODE_BASE, BL_CODE_END, |
| 109 | BL_RO_DATA_BASE, BL_RO_DATA_END, |
Masahiro Yamada | 0fac5af | 2016-12-28 16:11:41 +0900 | [diff] [blame] | 110 | BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END); |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Etienne Carriere | 84aa3a7 | 2017-11-02 12:05:12 +0100 | [diff] [blame] | 113 | /****************************************************************************** |
| 114 | * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0 |
| 115 | * interrupts. |
| 116 | *****************************************************************************/ |
| 117 | #define PLATFORM_G1S_PROPS(grp) \ |
| 118 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \ |
| 119 | grp, GIC_INTR_CFG_EDGE), \ |
| 120 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \ |
| 121 | grp, GIC_INTR_CFG_EDGE), \ |
| 122 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \ |
| 123 | grp, GIC_INTR_CFG_EDGE), \ |
| 124 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \ |
| 125 | grp, GIC_INTR_CFG_EDGE), \ |
| 126 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \ |
| 127 | grp, GIC_INTR_CFG_EDGE), \ |
| 128 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \ |
| 129 | grp, GIC_INTR_CFG_EDGE), \ |
| 130 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \ |
| 131 | grp, GIC_INTR_CFG_EDGE), \ |
| 132 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \ |
| 133 | grp, GIC_INTR_CFG_EDGE) |
| 134 | |
| 135 | #define PLATFORM_G0_PROPS(grp) |
| 136 | |
| 137 | static const interrupt_prop_t qemu_interrupt_props[] = { |
| 138 | PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0), |
| 139 | PLATFORM_G0_PROPS(GICV2_INTR_GROUP0) |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | static const struct gicv2_driver_data plat_gicv2_driver_data = { |
| 143 | .gicd_base = GICD_BASE, |
| 144 | .gicc_base = GICC_BASE, |
Etienne Carriere | 84aa3a7 | 2017-11-02 12:05:12 +0100 | [diff] [blame] | 145 | .interrupt_props = qemu_interrupt_props, |
| 146 | .interrupt_props_num = ARRAY_SIZE(qemu_interrupt_props), |
Jens Wiklander | 52c798e | 2015-12-07 14:37:10 +0100 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | void bl31_platform_setup(void) |
| 150 | { |
| 151 | /* Initialize the gic cpu and distributor interfaces */ |
| 152 | gicv2_driver_init(&plat_gicv2_driver_data); |
| 153 | gicv2_distif_init(); |
| 154 | gicv2_pcpu_distif_init(); |
| 155 | gicv2_cpuif_enable(); |
| 156 | } |
| 157 | |
| 158 | unsigned int plat_get_syscnt_freq2(void) |
| 159 | { |
| 160 | return SYS_COUNTER_FREQ_IN_TICKS; |
| 161 | } |
| 162 | |
| 163 | /******************************************************************************* |
| 164 | * Return a pointer to the 'entry_point_info' structure of the next image |
| 165 | * for the security state specified. BL3-3 corresponds to the non-secure |
| 166 | * image type while BL3-2 corresponds to the secure image type. A NULL |
| 167 | * pointer is returned if the image does not exist. |
| 168 | ******************************************************************************/ |
| 169 | entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) |
| 170 | { |
| 171 | entry_point_info_t *next_image_info; |
| 172 | |
| 173 | assert(sec_state_is_valid(type)); |
| 174 | next_image_info = (type == NON_SECURE) |
| 175 | ? &bl33_image_ep_info : &bl32_image_ep_info; |
| 176 | /* |
| 177 | * None of the images on the ARM development platforms can have 0x0 |
| 178 | * as the entrypoint |
| 179 | */ |
| 180 | if (next_image_info->pc) |
| 181 | return next_image_info; |
| 182 | else |
| 183 | return NULL; |
| 184 | } |