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