Etienne Carriere | 911de8c | 2018-02-02 13:23:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch_helpers.h> |
| 8 | #include <arm_gic.h> |
| 9 | #include <assert.h> |
| 10 | #include <bl_common.h> |
| 11 | #include <console.h> |
| 12 | #include <debug.h> |
| 13 | #include <gic_common.h> |
| 14 | #include <gicv2.h> |
| 15 | #include <mmio.h> |
| 16 | #include <platform.h> |
| 17 | #include <platform_def.h> |
| 18 | #include <string.h> |
| 19 | #include <xlat_tables.h> |
| 20 | #include "../qemu_private.h" |
| 21 | |
| 22 | #if RESET_TO_SP_MIN |
| 23 | #error qemu does not support RESET_TO_SP_MIN |
| 24 | #endif |
| 25 | |
| 26 | static entry_point_info_t bl33_image_ep_info; |
| 27 | |
| 28 | /* |
| 29 | * The next 3 constants identify the extents of the code, RO data region and the |
| 30 | * limit of the BL3-1 image. These addresses are used by the MMU setup code and |
| 31 | * therefore they must be page-aligned. It is the responsibility of the linker |
| 32 | * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols |
| 33 | * refer to page-aligned addresses. |
| 34 | */ |
| 35 | #define BL32_RO_BASE (unsigned long)(&__RO_START__) |
| 36 | #define BL32_RO_LIMIT (unsigned long)(&__RO_END__) |
| 37 | #define BL32_END (unsigned long)(&__BL32_END__) |
| 38 | |
| 39 | #if USE_COHERENT_MEM |
| 40 | /* |
| 41 | * The next 2 constants identify the extents of the coherent memory region. |
| 42 | * These addresses are used by the MMU setup code and therefore they must be |
| 43 | * page-aligned. It is the responsibility of the linker script to ensure that |
| 44 | * __COHERENT_RAM_START__ and __COHERENT_RAM_END__ linker symbols |
| 45 | * refer to page-aligned addresses. |
| 46 | */ |
| 47 | #define BL32_COHERENT_RAM_BASE (unsigned long)(&__COHERENT_RAM_START__) |
| 48 | #define BL32_COHERENT_RAM_LIMIT (unsigned long)(&__COHERENT_RAM_END__) |
| 49 | #endif |
| 50 | |
| 51 | /****************************************************************************** |
| 52 | * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0 |
| 53 | * interrupts. |
| 54 | *****************************************************************************/ |
| 55 | #define PLATFORM_G1S_PROPS(grp) \ |
| 56 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \ |
| 57 | grp, GIC_INTR_CFG_LEVEL), \ |
| 58 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \ |
| 59 | grp, GIC_INTR_CFG_LEVEL), \ |
| 60 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \ |
| 61 | grp, GIC_INTR_CFG_LEVEL), \ |
| 62 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \ |
| 63 | grp, GIC_INTR_CFG_LEVEL), \ |
| 64 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \ |
| 65 | grp, GIC_INTR_CFG_LEVEL), \ |
| 66 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \ |
| 67 | grp, GIC_INTR_CFG_LEVEL), \ |
| 68 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \ |
| 69 | grp, GIC_INTR_CFG_LEVEL), \ |
| 70 | INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \ |
| 71 | grp, GIC_INTR_CFG_LEVEL) |
| 72 | |
| 73 | #define PLATFORM_G0_PROPS(grp) |
| 74 | |
| 75 | static const interrupt_prop_t stih410_interrupt_props[] = { |
| 76 | PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0), |
| 77 | PLATFORM_G0_PROPS(GICV2_INTR_GROUP0) |
| 78 | }; |
| 79 | |
| 80 | static unsigned int target_mask_array[PLATFORM_CORE_COUNT]; |
| 81 | |
| 82 | static const struct gicv2_driver_data plat_gicv2_driver_data = { |
| 83 | .gicd_base = GICD_BASE, |
| 84 | .gicc_base = GICC_BASE, |
| 85 | .interrupt_props = stih410_interrupt_props, |
| 86 | .interrupt_props_num = ARRAY_SIZE(stih410_interrupt_props), |
| 87 | .target_masks = target_mask_array, |
| 88 | .target_masks_num = ARRAY_SIZE(target_mask_array), |
| 89 | }; |
| 90 | |
| 91 | /******************************************************************************* |
| 92 | * Return a pointer to the 'entry_point_info' structure of the next image for |
| 93 | * the security state specified. BL33 corresponds to the non-secure image type |
| 94 | * while BL32 corresponds to the secure image type. A NULL pointer is returned |
| 95 | * if the image does not exist. |
| 96 | ******************************************************************************/ |
| 97 | entry_point_info_t *sp_min_plat_get_bl33_ep_info(void) |
| 98 | { |
| 99 | entry_point_info_t *next_image_info = &bl33_image_ep_info; |
| 100 | |
| 101 | /* |
| 102 | * None of the images on the ARM development platforms can have 0x0 |
| 103 | * as the entrypoint |
| 104 | */ |
| 105 | if (next_image_info->pc) |
| 106 | return next_image_info; |
| 107 | else |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | void sp_min_early_platform_setup(void *from_bl2, void *plat_params_from_bl2) |
| 112 | { |
| 113 | bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2; |
| 114 | |
| 115 | /* Initialize the console to provide early debug support */ |
| 116 | console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ, |
| 117 | PLAT_QEMU_CONSOLE_BAUDRATE); |
| 118 | |
| 119 | ERROR("qemu sp_min, console init\n"); |
| 120 | /* |
| 121 | * Check params passed from BL2 |
| 122 | */ |
| 123 | assert(params_from_bl2); |
| 124 | assert(params_from_bl2->h.type == PARAM_BL_PARAMS); |
| 125 | assert(params_from_bl2->h.version >= VERSION_2); |
| 126 | |
| 127 | bl_params_node_t *bl_params = params_from_bl2->head; |
| 128 | |
| 129 | /* |
| 130 | * Copy BL33 entry point information from BL2's address space. |
| 131 | */ |
| 132 | while (bl_params) { |
| 133 | if (bl_params->image_id == BL33_IMAGE_ID) |
| 134 | bl33_image_ep_info = *bl_params->ep_info; |
| 135 | |
| 136 | bl_params = bl_params->next_params_info; |
| 137 | } |
| 138 | |
| 139 | if (!bl33_image_ep_info.pc) |
| 140 | panic(); |
| 141 | } |
| 142 | |
| 143 | void sp_min_plat_arch_setup(void) |
| 144 | { |
| 145 | qemu_configure_mmu_secure(BL32_RO_BASE, BL32_END - BL32_RO_BASE, |
| 146 | BL32_RO_BASE, BL32_RO_LIMIT, |
| 147 | BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END); |
| 148 | |
| 149 | } |
| 150 | |
| 151 | void sp_min_platform_setup(void) |
| 152 | { |
| 153 | /* Initialize the gic cpu and distributor interfaces */ |
| 154 | gicv2_driver_init(&plat_gicv2_driver_data); |
| 155 | gicv2_distif_init(); |
| 156 | gicv2_pcpu_distif_init(); |
| 157 | gicv2_cpuif_enable(); |
| 158 | } |
| 159 | |
| 160 | unsigned int plat_get_syscnt_freq2(void) |
| 161 | { |
| 162 | return SYS_COUNTER_FREQ_IN_TICKS; |
| 163 | } |
| 164 | |
| 165 | void sp_min_plat_fiq_handler(uint32_t id) |
| 166 | { |
| 167 | VERBOSE("[sp_min] interrupt #%d\n", id); |
| 168 | } |