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