Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 1 | /* |
Madhukar Pappireddy | dc4b8c6 | 2023-08-03 12:13:27 -0500 | [diff] [blame] | 2 | * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved. |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 3 | * Portions copyright (c) 2021-2022, ProvenRun S.A.S. All rights reserved. |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 4 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 8 | #ifndef GICV2_H |
| 9 | #define GICV2_H |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 10 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <drivers/arm/gic_common.h> |
Stephan Gerhold | 1eec909 | 2021-12-01 20:02:22 +0100 | [diff] [blame] | 12 | #include <platform_def.h> |
Antonio Nino Diaz | 29b9f5b | 2018-09-24 17:23:24 +0100 | [diff] [blame] | 13 | |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 14 | /******************************************************************************* |
| 15 | * GICv2 miscellaneous definitions |
| 16 | ******************************************************************************/ |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 17 | |
| 18 | /* Interrupt group definitions */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 19 | #define GICV2_INTR_GROUP0 U(0) |
| 20 | #define GICV2_INTR_GROUP1 U(1) |
Jeenu Viswambharan | c06f05c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 21 | |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 22 | /* Interrupt IDs reported by the HPPIR and IAR registers */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 23 | #define PENDING_G1_INTID U(1022) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 24 | |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 25 | /* GICv2 can only target up to 8 PEs */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 26 | #define GICV2_MAX_TARGET_PE U(8) |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 27 | |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 28 | /******************************************************************************* |
| 29 | * GICv2 specific Distributor interface register offsets and constants. |
| 30 | ******************************************************************************/ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 31 | #define GICD_ITARGETSR U(0x800) |
| 32 | #define GICD_SGIR U(0xF00) |
| 33 | #define GICD_CPENDSGIR U(0xF10) |
| 34 | #define GICD_SPENDSGIR U(0xF20) |
Stephan Gerhold | 1eec909 | 2021-12-01 20:02:22 +0100 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Some GICv2 implementations violate the specification and have this register |
| 38 | * at a different address. Allow overriding it in platform_def.h as workaround. |
| 39 | */ |
| 40 | #ifndef GICD_PIDR2_GICV2 |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 41 | #define GICD_PIDR2_GICV2 U(0xFE8) |
Stephan Gerhold | 1eec909 | 2021-12-01 20:02:22 +0100 | [diff] [blame] | 42 | #endif |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 43 | |
| 44 | #define ITARGETSR_SHIFT 2 |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 45 | #define GIC_TARGET_CPU_MASK U(0xff) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 46 | |
| 47 | #define CPENDSGIR_SHIFT 2 |
| 48 | #define SPENDSGIR_SHIFT CPENDSGIR_SHIFT |
| 49 | |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 50 | #define SGIR_TGTLSTFLT_SHIFT 24 |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 51 | #define SGIR_TGTLSTFLT_MASK U(0x3) |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 52 | #define SGIR_TGTLST_SHIFT 16 |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 53 | #define SGIR_TGTLST_MASK U(0xff) |
Jacob Kroon | aac02a7 | 2024-04-12 14:26:01 +0200 | [diff] [blame] | 54 | #define SGIR_NSATT (U(0x1) << 15) |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 55 | #define SGIR_INTID_MASK ULL(0xf) |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 56 | |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 57 | #define SGIR_TGT_SPECIFIC U(0) |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 58 | |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 59 | #define GICV2_SGIR_VALUE(tgt_lst_flt, tgt, nsatt, intid) \ |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 60 | ((((tgt_lst_flt) & SGIR_TGTLSTFLT_MASK) << SGIR_TGTLSTFLT_SHIFT) | \ |
| 61 | (((tgt) & SGIR_TGTLST_MASK) << SGIR_TGTLST_SHIFT) | \ |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 62 | ((nsatt) ? SGIR_NSATT : U(0)) | \ |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 63 | ((intid) & SGIR_INTID_MASK)) |
| 64 | |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 65 | /******************************************************************************* |
| 66 | * GICv2 specific CPU interface register offsets and constants. |
| 67 | ******************************************************************************/ |
| 68 | /* Physical CPU Interface registers */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 69 | #define GICC_CTLR U(0x0) |
| 70 | #define GICC_PMR U(0x4) |
| 71 | #define GICC_BPR U(0x8) |
| 72 | #define GICC_IAR U(0xC) |
| 73 | #define GICC_EOIR U(0x10) |
| 74 | #define GICC_RPR U(0x14) |
| 75 | #define GICC_HPPIR U(0x18) |
| 76 | #define GICC_AHPPIR U(0x28) |
| 77 | #define GICC_IIDR U(0xFC) |
| 78 | #define GICC_DIR U(0x1000) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 79 | #define GICC_PRIODROP GICC_EOIR |
| 80 | |
| 81 | /* GICC_CTLR bit definitions */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 82 | #define EOI_MODE_NS BIT_32(10) |
| 83 | #define EOI_MODE_S BIT_32(9) |
| 84 | #define IRQ_BYP_DIS_GRP1 BIT_32(8) |
| 85 | #define FIQ_BYP_DIS_GRP1 BIT_32(7) |
| 86 | #define IRQ_BYP_DIS_GRP0 BIT_32(6) |
| 87 | #define FIQ_BYP_DIS_GRP0 BIT_32(5) |
| 88 | #define CBPR BIT_32(4) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 89 | #define FIQ_EN_SHIFT 3 |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 90 | #define FIQ_EN_BIT BIT_32(FIQ_EN_SHIFT) |
| 91 | #define ACK_CTL BIT_32(2) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 92 | |
| 93 | /* GICC_IIDR bit masks and shifts */ |
| 94 | #define GICC_IIDR_PID_SHIFT 20 |
| 95 | #define GICC_IIDR_ARCH_SHIFT 16 |
| 96 | #define GICC_IIDR_REV_SHIFT 12 |
| 97 | #define GICC_IIDR_IMP_SHIFT 0 |
| 98 | |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 99 | #define GICC_IIDR_PID_MASK U(0xfff) |
| 100 | #define GICC_IIDR_ARCH_MASK U(0xf) |
| 101 | #define GICC_IIDR_REV_MASK U(0xf) |
| 102 | #define GICC_IIDR_IMP_MASK U(0xfff) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 103 | |
| 104 | /* HYP view virtual CPU Interface registers */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 105 | #define GICH_CTL U(0x0) |
| 106 | #define GICH_VTR U(0x4) |
| 107 | #define GICH_ELRSR0 U(0x30) |
| 108 | #define GICH_ELRSR1 U(0x34) |
| 109 | #define GICH_APR0 U(0xF0) |
| 110 | #define GICH_LR_BASE U(0x100) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 111 | |
| 112 | /* Virtual CPU Interface registers */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 113 | #define GICV_CTL U(0x0) |
| 114 | #define GICV_PRIMASK U(0x4) |
| 115 | #define GICV_BP U(0x8) |
| 116 | #define GICV_INTACK U(0xC) |
| 117 | #define GICV_EOI U(0x10) |
| 118 | #define GICV_RUNNINGPRI U(0x14) |
| 119 | #define GICV_HIGHESTPEND U(0x18) |
| 120 | #define GICV_DEACTIVATE U(0x1000) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 121 | |
| 122 | /* GICD_CTLR bit definitions */ |
| 123 | #define CTLR_ENABLE_G1_SHIFT 1 |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 124 | #define CTLR_ENABLE_G1_MASK U(0x1) |
| 125 | #define CTLR_ENABLE_G1_BIT BIT_32(CTLR_ENABLE_G1_SHIFT) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 126 | |
| 127 | /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */ |
Antonio Nino Diaz | 2e59071 | 2018-08-24 11:46:33 +0100 | [diff] [blame] | 128 | #define INT_ID_MASK U(0x3ff) |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 129 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 130 | #ifndef __ASSEMBLER__ |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 131 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 132 | #include <cdefs.h> |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 133 | #include <stdbool.h> |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 134 | #include <stdint.h> |
| 135 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 136 | #include <common/interrupt_props.h> |
| 137 | |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 138 | /******************************************************************************* |
| 139 | * This structure describes some of the implementation defined attributes of |
| 140 | * the GICv2 IP. It is used by the platform port to specify these attributes |
| 141 | * in order to initialize the GICv2 driver. The attributes are described |
| 142 | * below. |
| 143 | * |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 144 | * The 'gicd_base' field contains the base address of the Distributor interface |
| 145 | * programmer's view. |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 146 | * |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 147 | * The 'gicc_base' field contains the base address of the CPU Interface |
| 148 | * programmer's view. |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 149 | * |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 150 | * The 'target_masks' is a pointer to an array containing 'target_masks_num' |
| 151 | * elements. The GIC driver will populate the array with per-PE target mask to |
| 152 | * use to when targeting interrupts. |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 153 | * |
| 154 | * The 'interrupt_props' field is a pointer to an array that enumerates secure |
| 155 | * interrupts and their properties. If this field is not NULL, both |
| 156 | * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored. |
| 157 | * |
| 158 | * The 'interrupt_props_num' field contains the number of entries in the |
| 159 | * 'interrupt_props' array. If this field is non-zero, 'g0_interrupt_num' is |
| 160 | * ignored. |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 161 | ******************************************************************************/ |
| 162 | typedef struct gicv2_driver_data { |
| 163 | uintptr_t gicd_base; |
| 164 | uintptr_t gicc_base; |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 165 | unsigned int *target_masks; |
| 166 | unsigned int target_masks_num; |
Jeenu Viswambharan | aeb267c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 167 | const interrupt_prop_t *interrupt_props; |
| 168 | unsigned int interrupt_props_num; |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 169 | } gicv2_driver_data_t; |
| 170 | |
| 171 | /******************************************************************************* |
| 172 | * Function prototypes |
| 173 | ******************************************************************************/ |
| 174 | void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data); |
| 175 | void gicv2_distif_init(void); |
| 176 | void gicv2_pcpu_distif_init(void); |
| 177 | void gicv2_cpuif_enable(void); |
| 178 | void gicv2_cpuif_disable(void); |
| 179 | unsigned int gicv2_is_fiq_enabled(void); |
| 180 | unsigned int gicv2_get_pending_interrupt_type(void); |
| 181 | unsigned int gicv2_get_pending_interrupt_id(void); |
| 182 | unsigned int gicv2_acknowledge_interrupt(void); |
| 183 | void gicv2_end_of_interrupt(unsigned int id); |
| 184 | unsigned int gicv2_get_interrupt_group(unsigned int id); |
Jeenu Viswambharan | b1e957e | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 185 | unsigned int gicv2_get_running_priority(void); |
Jeenu Viswambharan | 393fdd9 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 186 | void gicv2_set_pe_target_mask(unsigned int proc_num); |
Jeenu Viswambharan | 24e7029 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 187 | unsigned int gicv2_get_interrupt_active(unsigned int id); |
Jeenu Viswambharan | 0fcdfff | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 188 | void gicv2_enable_interrupt(unsigned int id); |
| 189 | void gicv2_disable_interrupt(unsigned int id); |
Jeenu Viswambharan | 447b89d | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 190 | void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority); |
Madhukar Pappireddy | dc4b8c6 | 2023-08-03 12:13:27 -0500 | [diff] [blame] | 191 | void gicv2_set_interrupt_group(unsigned int id, unsigned int group); |
Florian Lugou | d4e2503 | 2021-09-08 12:40:24 +0200 | [diff] [blame] | 192 | void gicv2_raise_sgi(int sgi_num, bool ns, int proc_num); |
Jeenu Viswambharan | dce70b3 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 193 | void gicv2_set_spi_routing(unsigned int id, int proc_num); |
Jeenu Viswambharan | eb1c12c | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 194 | void gicv2_set_interrupt_pending(unsigned int id); |
| 195 | void gicv2_clear_interrupt_pending(unsigned int id); |
Jeenu Viswambharan | 6250507 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 196 | unsigned int gicv2_set_pmr(unsigned int mask); |
Marcin Wojtas | dd568dd | 2018-03-21 09:55:47 +0100 | [diff] [blame] | 197 | void gicv2_interrupt_set_cfg(unsigned int id, unsigned int cfg); |
Soby Mathew | e063d3c | 2015-10-07 09:45:27 +0100 | [diff] [blame] | 198 | |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 199 | #endif /* __ASSEMBLER__ */ |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 200 | #endif /* GICV2_H */ |