Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, 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 <arm_def.h> |
| 32 | #include <gicv3.h> |
| 33 | #include <plat_arm.h> |
| 34 | #include <platform.h> |
| 35 | #include <platform_def.h> |
| 36 | |
| 37 | /****************************************************************************** |
| 38 | * The following functions are defined as weak to allow a platform to override |
| 39 | * the way the GICv3 driver is initialised and used. |
| 40 | *****************************************************************************/ |
| 41 | #pragma weak plat_arm_gic_driver_init |
| 42 | #pragma weak plat_arm_gic_init |
| 43 | #pragma weak plat_arm_gic_cpuif_enable |
| 44 | #pragma weak plat_arm_gic_cpuif_disable |
| 45 | #pragma weak plat_arm_gic_pcpu_init |
Jeenu Viswambharan | 78132c9 | 2016-12-09 11:12:34 +0000 | [diff] [blame] | 46 | #pragma weak plat_arm_gic_redistif_on |
| 47 | #pragma weak plat_arm_gic_redistif_off |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 48 | |
| 49 | /* The GICv3 driver only needs to be initialized in EL3 */ |
Soby Mathew | cf022c5 | 2016-01-13 17:06:00 +0000 | [diff] [blame] | 50 | static uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT]; |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 51 | |
| 52 | /* Array of Group1 secure interrupts to be configured by the gic driver */ |
Soby Mathew | cf022c5 | 2016-01-13 17:06:00 +0000 | [diff] [blame] | 53 | static const unsigned int g1s_interrupt_array[] = { |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 54 | PLAT_ARM_G1S_IRQS |
| 55 | }; |
| 56 | |
| 57 | /* Array of Group0 interrupts to be configured by the gic driver */ |
Soby Mathew | cf022c5 | 2016-01-13 17:06:00 +0000 | [diff] [blame] | 58 | static const unsigned int g0_interrupt_array[] = { |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 59 | PLAT_ARM_G0_IRQS |
| 60 | }; |
| 61 | |
| 62 | const gicv3_driver_data_t arm_gic_data = { |
| 63 | .gicd_base = PLAT_ARM_GICD_BASE, |
| 64 | .gicr_base = PLAT_ARM_GICR_BASE, |
| 65 | .g0_interrupt_num = ARRAY_SIZE(g0_interrupt_array), |
| 66 | .g1s_interrupt_num = ARRAY_SIZE(g1s_interrupt_array), |
| 67 | .g0_interrupt_array = g0_interrupt_array, |
| 68 | .g1s_interrupt_array = g1s_interrupt_array, |
| 69 | .rdistif_num = PLATFORM_CORE_COUNT, |
| 70 | .rdistif_base_addrs = rdistif_base_addrs, |
| 71 | .mpidr_to_core_pos = plat_arm_calc_core_pos |
| 72 | }; |
| 73 | |
| 74 | void plat_arm_gic_driver_init(void) |
| 75 | { |
| 76 | /* |
| 77 | * The GICv3 driver is initialized in EL3 and does not need |
| 78 | * to be initialized again in SEL1. This is because the S-EL1 |
| 79 | * can use GIC system registers to manage interrupts and does |
| 80 | * not need GIC interface base addresses to be configured. |
| 81 | */ |
Soby Mathew | 0d268dc | 2016-07-11 14:13:56 +0100 | [diff] [blame] | 82 | #if (AARCH32 && IMAGE_BL32) || (IMAGE_BL31 && !AARCH32) |
Achin Gupta | 1fa7eb6 | 2015-11-03 14:18:34 +0000 | [diff] [blame] | 83 | gicv3_driver_init(&arm_gic_data); |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | /****************************************************************************** |
| 88 | * ARM common helper to initialize the GIC. Only invoked by BL31 |
| 89 | *****************************************************************************/ |
| 90 | void plat_arm_gic_init(void) |
| 91 | { |
| 92 | gicv3_distif_init(); |
| 93 | gicv3_rdistif_init(plat_my_core_pos()); |
| 94 | gicv3_cpuif_enable(plat_my_core_pos()); |
| 95 | } |
| 96 | |
| 97 | /****************************************************************************** |
| 98 | * ARM common helper to enable the GIC CPU interface |
| 99 | *****************************************************************************/ |
| 100 | void plat_arm_gic_cpuif_enable(void) |
| 101 | { |
| 102 | gicv3_cpuif_enable(plat_my_core_pos()); |
| 103 | } |
| 104 | |
| 105 | /****************************************************************************** |
| 106 | * ARM common helper to disable the GIC CPU interface |
| 107 | *****************************************************************************/ |
| 108 | void plat_arm_gic_cpuif_disable(void) |
| 109 | { |
| 110 | gicv3_cpuif_disable(plat_my_core_pos()); |
| 111 | } |
| 112 | |
| 113 | /****************************************************************************** |
| 114 | * ARM common helper to initialize the per-cpu redistributor interface in GICv3 |
| 115 | *****************************************************************************/ |
| 116 | void plat_arm_gic_pcpu_init(void) |
| 117 | { |
| 118 | gicv3_rdistif_init(plat_my_core_pos()); |
| 119 | } |
Jeenu Viswambharan | 78132c9 | 2016-12-09 11:12:34 +0000 | [diff] [blame] | 120 | |
| 121 | /****************************************************************************** |
| 122 | * ARM common helpers to power GIC redistributor interface |
| 123 | *****************************************************************************/ |
| 124 | void plat_arm_gic_redistif_on(void) |
| 125 | { |
| 126 | gicv3_rdistif_on(plat_my_core_pos()); |
| 127 | } |
| 128 | |
| 129 | void plat_arm_gic_redistif_off(void) |
| 130 | { |
| 131 | gicv3_rdistif_off(plat_my_core_pos()); |
| 132 | } |