1df373737SAchin Gupta /* 24c0d0390SSoby Mathew * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved. 3df373737SAchin Gupta * 4df373737SAchin Gupta * Redistribution and use in source and binary forms, with or without 5df373737SAchin Gupta * modification, are permitted provided that the following conditions are met: 6df373737SAchin Gupta * 7df373737SAchin Gupta * Redistributions of source code must retain the above copyright notice, this 8df373737SAchin Gupta * list of conditions and the following disclaimer. 9df373737SAchin Gupta * 10df373737SAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 11df373737SAchin Gupta * this list of conditions and the following disclaimer in the documentation 12df373737SAchin Gupta * and/or other materials provided with the distribution. 13df373737SAchin Gupta * 14df373737SAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 15df373737SAchin Gupta * to endorse or promote products derived from this software without specific 16df373737SAchin Gupta * prior written permission. 17df373737SAchin Gupta * 18df373737SAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19df373737SAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20df373737SAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21df373737SAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22df373737SAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23df373737SAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24df373737SAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25df373737SAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26df373737SAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27df373737SAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28df373737SAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 29df373737SAchin Gupta */ 30df373737SAchin Gupta 31df373737SAchin Gupta #ifndef __GICV3_H__ 32df373737SAchin Gupta #define __GICV3_H__ 33df373737SAchin Gupta 34df373737SAchin Gupta /******************************************************************************* 35df373737SAchin Gupta * GICv3 miscellaneous definitions 36df373737SAchin Gupta ******************************************************************************/ 37df373737SAchin Gupta /* Interrupt group definitions */ 3803ffb6bdSSoby Mathew #define INTR_GROUP1S 0 3903ffb6bdSSoby Mathew #define INTR_GROUP0 1 4003ffb6bdSSoby Mathew #define INTR_GROUP1NS 2 41df373737SAchin Gupta 42df373737SAchin Gupta /* Interrupt IDs reported by the HPPIR and IAR registers */ 43df373737SAchin Gupta #define PENDING_G1S_INTID 1020 44df373737SAchin Gupta #define PENDING_G1NS_INTID 1021 45df373737SAchin Gupta 46df373737SAchin Gupta /* Constant to categorize LPI interrupt */ 47df373737SAchin Gupta #define MIN_LPI_ID 8192 48df373737SAchin Gupta 49df373737SAchin Gupta /******************************************************************************* 50df373737SAchin Gupta * GICv3 specific Distributor interface register offsets and constants. 51df373737SAchin Gupta ******************************************************************************/ 52df373737SAchin Gupta #define GICD_STATUSR 0x10 53df373737SAchin Gupta #define GICD_SETSPI_NSR 0x40 54df373737SAchin Gupta #define GICD_CLRSPI_NSR 0x48 55df373737SAchin Gupta #define GICD_SETSPI_SR 0x50 56df373737SAchin Gupta #define GICD_CLRSPI_SR 0x50 57df373737SAchin Gupta #define GICD_IGRPMODR 0xd00 5861e30277SSoby Mathew /* 5961e30277SSoby Mathew * GICD_IROUTER<n> register is at 0x6000 + 8n, where n is the interrupt id and 6061e30277SSoby Mathew * n >= 32, making the effective offset as 0x6100. 6161e30277SSoby Mathew */ 6261e30277SSoby Mathew #define GICD_IROUTER 0x6000 63df373737SAchin Gupta #define GICD_PIDR2_GICV3 0xffe8 64df373737SAchin Gupta 65df373737SAchin Gupta #define IGRPMODR_SHIFT 5 66df373737SAchin Gupta 67df373737SAchin Gupta /* GICD_CTLR bit definitions */ 68df373737SAchin Gupta #define CTLR_ENABLE_G1NS_SHIFT 1 69df373737SAchin Gupta #define CTLR_ENABLE_G1S_SHIFT 2 70df373737SAchin Gupta #define CTLR_ARE_S_SHIFT 4 71df373737SAchin Gupta #define CTLR_ARE_NS_SHIFT 5 72df373737SAchin Gupta #define CTLR_DS_SHIFT 6 73df373737SAchin Gupta #define CTLR_E1NWF_SHIFT 7 74df373737SAchin Gupta #define GICD_CTLR_RWP_SHIFT 31 75df373737SAchin Gupta 76df373737SAchin Gupta #define CTLR_ENABLE_G1NS_MASK 0x1 77df373737SAchin Gupta #define CTLR_ENABLE_G1S_MASK 0x1 78df373737SAchin Gupta #define CTLR_ARE_S_MASK 0x1 79df373737SAchin Gupta #define CTLR_ARE_NS_MASK 0x1 80df373737SAchin Gupta #define CTLR_DS_MASK 0x1 81df373737SAchin Gupta #define CTLR_E1NWF_MASK 0x1 82df373737SAchin Gupta #define GICD_CTLR_RWP_MASK 0x1 83df373737SAchin Gupta 84df373737SAchin Gupta #define CTLR_ENABLE_G1NS_BIT (1 << CTLR_ENABLE_G1NS_SHIFT) 85df373737SAchin Gupta #define CTLR_ENABLE_G1S_BIT (1 << CTLR_ENABLE_G1S_SHIFT) 86df373737SAchin Gupta #define CTLR_ARE_S_BIT (1 << CTLR_ARE_S_SHIFT) 87df373737SAchin Gupta #define CTLR_ARE_NS_BIT (1 << CTLR_ARE_NS_SHIFT) 88df373737SAchin Gupta #define CTLR_DS_BIT (1 << CTLR_DS_SHIFT) 89df373737SAchin Gupta #define CTLR_E1NWF_BIT (1 << CTLR_E1NWF_SHIFT) 90df373737SAchin Gupta #define GICD_CTLR_RWP_BIT (1 << GICD_CTLR_RWP_SHIFT) 91df373737SAchin Gupta 92df373737SAchin Gupta /* GICD_IROUTER shifts and masks */ 93df373737SAchin Gupta #define IROUTER_IRM_SHIFT 31 94df373737SAchin Gupta #define IROUTER_IRM_MASK 0x1 95df373737SAchin Gupta 96df373737SAchin Gupta /******************************************************************************* 97df373737SAchin Gupta * GICv3 Re-distributor interface registers & constants 98df373737SAchin Gupta ******************************************************************************/ 99df373737SAchin Gupta #define GICR_PCPUBASE_SHIFT 0x11 100df373737SAchin Gupta #define GICR_SGIBASE_OFFSET (1 << 0x10) /* 64 KB */ 101df373737SAchin Gupta #define GICR_CTLR 0x0 102df373737SAchin Gupta #define GICR_TYPER 0x08 103df373737SAchin Gupta #define GICR_WAKER 0x14 104df373737SAchin Gupta #define GICR_IGROUPR0 (GICR_SGIBASE_OFFSET + 0x80) 105df373737SAchin Gupta #define GICR_ISENABLER0 (GICR_SGIBASE_OFFSET + 0x100) 106df373737SAchin Gupta #define GICR_ICENABLER0 (GICR_SGIBASE_OFFSET + 0x180) 107df373737SAchin Gupta #define GICR_IPRIORITYR (GICR_SGIBASE_OFFSET + 0x400) 108df373737SAchin Gupta #define GICR_ICFGR0 (GICR_SGIBASE_OFFSET + 0xc00) 109df373737SAchin Gupta #define GICR_ICFGR1 (GICR_SGIBASE_OFFSET + 0xc04) 110df373737SAchin Gupta #define GICR_IGRPMODR0 (GICR_SGIBASE_OFFSET + 0xd00) 111df373737SAchin Gupta 112df373737SAchin Gupta /* GICR_CTLR bit definitions */ 113df373737SAchin Gupta #define GICR_CTLR_RWP_SHIFT 3 114df373737SAchin Gupta #define GICR_CTLR_RWP_MASK 0x1 115df373737SAchin Gupta #define GICR_CTLR_RWP_BIT (1 << GICR_CTLR_RWP_SHIFT) 116df373737SAchin Gupta 117df373737SAchin Gupta /* GICR_WAKER bit definitions */ 118df373737SAchin Gupta #define WAKER_CA_SHIFT 2 119df373737SAchin Gupta #define WAKER_PS_SHIFT 1 120df373737SAchin Gupta 121df373737SAchin Gupta #define WAKER_CA_MASK 0x1 122df373737SAchin Gupta #define WAKER_PS_MASK 0x1 123df373737SAchin Gupta 124df373737SAchin Gupta #define WAKER_CA_BIT (1 << WAKER_CA_SHIFT) 125df373737SAchin Gupta #define WAKER_PS_BIT (1 << WAKER_PS_SHIFT) 126df373737SAchin Gupta 127df373737SAchin Gupta /* GICR_TYPER bit definitions */ 128df373737SAchin Gupta #define TYPER_AFF_VAL_SHIFT 32 129df373737SAchin Gupta #define TYPER_PROC_NUM_SHIFT 8 130df373737SAchin Gupta #define TYPER_LAST_SHIFT 4 131df373737SAchin Gupta 132df373737SAchin Gupta #define TYPER_AFF_VAL_MASK 0xffffffff 133df373737SAchin Gupta #define TYPER_PROC_NUM_MASK 0xffff 134df373737SAchin Gupta #define TYPER_LAST_MASK 0x1 135df373737SAchin Gupta 136df373737SAchin Gupta #define TYPER_LAST_BIT (1 << TYPER_LAST_SHIFT) 137df373737SAchin Gupta 138df373737SAchin Gupta /******************************************************************************* 139df373737SAchin Gupta * GICv3 CPU interface registers & constants 140df373737SAchin Gupta ******************************************************************************/ 141df373737SAchin Gupta /* ICC_SRE bit definitions*/ 142df373737SAchin Gupta #define ICC_SRE_EN_BIT (1 << 3) 143df373737SAchin Gupta #define ICC_SRE_DIB_BIT (1 << 2) 144df373737SAchin Gupta #define ICC_SRE_DFB_BIT (1 << 1) 145df373737SAchin Gupta #define ICC_SRE_SRE_BIT (1 << 0) 146df373737SAchin Gupta 147df373737SAchin Gupta /* ICC_IGRPEN1_EL3 bit definitions */ 148df373737SAchin Gupta #define IGRPEN1_EL3_ENABLE_G1NS_SHIFT 0 149df373737SAchin Gupta #define IGRPEN1_EL3_ENABLE_G1S_SHIFT 1 150df373737SAchin Gupta 151df373737SAchin Gupta #define IGRPEN1_EL3_ENABLE_G1NS_BIT (1 << IGRPEN1_EL3_ENABLE_G1NS_SHIFT) 152df373737SAchin Gupta #define IGRPEN1_EL3_ENABLE_G1S_BIT (1 << IGRPEN1_EL3_ENABLE_G1S_SHIFT) 153df373737SAchin Gupta 154df373737SAchin Gupta /* ICC_IGRPEN0_EL1 bit definitions */ 155df373737SAchin Gupta #define IGRPEN1_EL1_ENABLE_G0_SHIFT 0 156df373737SAchin Gupta #define IGRPEN1_EL1_ENABLE_G0_BIT (1 << IGRPEN1_EL1_ENABLE_G0_SHIFT) 157df373737SAchin Gupta 158df373737SAchin Gupta /* ICC_HPPIR0_EL1 bit definitions */ 159df373737SAchin Gupta #define HPPIR0_EL1_INTID_SHIFT 0 160df373737SAchin Gupta #define HPPIR0_EL1_INTID_MASK 0xffffff 161df373737SAchin Gupta 162df373737SAchin Gupta /* ICC_HPPIR1_EL1 bit definitions */ 163df373737SAchin Gupta #define HPPIR1_EL1_INTID_SHIFT 0 164df373737SAchin Gupta #define HPPIR1_EL1_INTID_MASK 0xffffff 165df373737SAchin Gupta 166df373737SAchin Gupta /* ICC_IAR0_EL1 bit definitions */ 167df373737SAchin Gupta #define IAR0_EL1_INTID_SHIFT 0 168df373737SAchin Gupta #define IAR0_EL1_INTID_MASK 0xffffff 169df373737SAchin Gupta 170df373737SAchin Gupta /* ICC_IAR1_EL1 bit definitions */ 171df373737SAchin Gupta #define IAR1_EL1_INTID_SHIFT 0 172df373737SAchin Gupta #define IAR1_EL1_INTID_MASK 0xffffff 173df373737SAchin Gupta 174df373737SAchin Gupta #ifndef __ASSEMBLY__ 175df373737SAchin Gupta 176df373737SAchin Gupta #include <stdint.h> 1774c0d0390SSoby Mathew #include <types.h> 178df373737SAchin Gupta 179df373737SAchin Gupta #define gicv3_is_intr_id_special_identifier(id) \ 180df373737SAchin Gupta (((id) >= PENDING_G1S_INTID) && ((id) <= GIC_SPURIOUS_INTERRUPT)) 181df373737SAchin Gupta 182df373737SAchin Gupta /******************************************************************************* 183df373737SAchin Gupta * Helper GICv3 macros for SEL1 184df373737SAchin Gupta ******************************************************************************/ 185df373737SAchin Gupta #define gicv3_acknowledge_interrupt_sel1() read_icc_iar1_el1() &\ 186df373737SAchin Gupta IAR1_EL1_INTID_MASK 187df373737SAchin Gupta #define gicv3_get_pending_interrupt_id_sel1() read_icc_hppir1_el1() &\ 188df373737SAchin Gupta HPPIR1_EL1_INTID_MASK 189df373737SAchin Gupta #define gicv3_end_of_interrupt_sel1(id) write_icc_eoir1_el1(id) 190df373737SAchin Gupta 191df373737SAchin Gupta 192df373737SAchin Gupta /******************************************************************************* 193df373737SAchin Gupta * Helper GICv3 macros for EL3 194df373737SAchin Gupta ******************************************************************************/ 195df373737SAchin Gupta #define gicv3_acknowledge_interrupt() read_icc_iar0_el1() &\ 196df373737SAchin Gupta IAR0_EL1_INTID_MASK 197df373737SAchin Gupta #define gicv3_end_of_interrupt(id) write_icc_eoir0_el1(id) 198df373737SAchin Gupta 199df373737SAchin Gupta /******************************************************************************* 200df373737SAchin Gupta * This structure describes some of the implementation defined attributes of the 201df373737SAchin Gupta * GICv3 IP. It is used by the platform port to specify these attributes in order 202df373737SAchin Gupta * to initialise the GICV3 driver. The attributes are described below. 203df373737SAchin Gupta * 204df373737SAchin Gupta * 1. The 'gicd_base' field contains the base address of the Distributor 205df373737SAchin Gupta * interface programmer's view. 206df373737SAchin Gupta * 207df373737SAchin Gupta * 2. The 'gicr_base' field contains the base address of the Re-distributor 208df373737SAchin Gupta * interface programmer's view. 209df373737SAchin Gupta * 210df373737SAchin Gupta * 3. The 'g0_interrupt_array' field is a ponter to an array in which each 211df373737SAchin Gupta * entry corresponds to an ID of a Group 0 interrupt. 212df373737SAchin Gupta * 213df373737SAchin Gupta * 4. The 'g0_interrupt_num' field contains the number of entries in the 214df373737SAchin Gupta * 'g0_interrupt_array'. 215df373737SAchin Gupta * 216df373737SAchin Gupta * 5. The 'g1s_interrupt_array' field is a ponter to an array in which each 217df373737SAchin Gupta * entry corresponds to an ID of a Group 1 interrupt. 218df373737SAchin Gupta * 219df373737SAchin Gupta * 6. The 'g1s_interrupt_num' field contains the number of entries in the 220df373737SAchin Gupta * 'g1s_interrupt_array'. 221df373737SAchin Gupta * 222df373737SAchin Gupta * 7. The 'rdistif_num' field contains the number of Redistributor interfaces 223df373737SAchin Gupta * the GIC implements. This is equal to the number of CPUs or CPU interfaces 224df373737SAchin Gupta * instantiated in the GIC. 225df373737SAchin Gupta * 226df373737SAchin Gupta * 8. The 'rdistif_base_addrs' field is a pointer to an array that has an entry 227df373737SAchin Gupta * for storing the base address of the Redistributor interface frame of each 228df373737SAchin Gupta * CPU in the system. The size of the array = 'rdistif_num'. The base 229df373737SAchin Gupta * addresses are detected during driver initialisation. 230df373737SAchin Gupta * 231df373737SAchin Gupta * 9. The 'mpidr_to_core_pos' field is a pointer to a hash function which the 232df373737SAchin Gupta * driver will use to convert an MPIDR value to a linear core index. This 233df373737SAchin Gupta * index will be used for accessing the 'rdistif_base_addrs' array. This is 234df373737SAchin Gupta * an optional field. A GICv3 implementation maps each MPIDR to a linear core 235df373737SAchin Gupta * index as well. This mapping can be found by reading the "Affinity Value" 236df373737SAchin Gupta * and "Processor Number" fields in the GICR_TYPER. It is IMP. DEF. if the 237df373737SAchin Gupta * "Processor Numbers" are suitable to index into an array to access core 238df373737SAchin Gupta * specific information. If this not the case, the platform port must provide 239df373737SAchin Gupta * a hash function. Otherwise, the "Processor Number" field will be used to 240df373737SAchin Gupta * access the array elements. 241df373737SAchin Gupta ******************************************************************************/ 2424c0d0390SSoby Mathew typedef unsigned int (*mpidr_hash_fn)(u_register_t mpidr); 243df373737SAchin Gupta 244df373737SAchin Gupta typedef struct gicv3_driver_data { 245df373737SAchin Gupta uintptr_t gicd_base; 246df373737SAchin Gupta uintptr_t gicr_base; 247df373737SAchin Gupta unsigned int g0_interrupt_num; 248df373737SAchin Gupta unsigned int g1s_interrupt_num; 249df373737SAchin Gupta const unsigned int *g0_interrupt_array; 250df373737SAchin Gupta const unsigned int *g1s_interrupt_array; 251df373737SAchin Gupta unsigned int rdistif_num; 252df373737SAchin Gupta uintptr_t *rdistif_base_addrs; 253df373737SAchin Gupta mpidr_hash_fn mpidr_to_core_pos; 254df373737SAchin Gupta } gicv3_driver_data_t; 255df373737SAchin Gupta 256df373737SAchin Gupta /******************************************************************************* 257df373737SAchin Gupta * GICv3 EL3 driver API 258df373737SAchin Gupta ******************************************************************************/ 259df373737SAchin Gupta void gicv3_driver_init(const gicv3_driver_data_t *plat_driver_data); 260df373737SAchin Gupta void gicv3_distif_init(void); 261df373737SAchin Gupta void gicv3_rdistif_init(unsigned int proc_num); 262*d780699bSJeenu Viswambharan void gicv3_rdistif_on(unsigned int proc_num); 263*d780699bSJeenu Viswambharan void gicv3_rdistif_off(unsigned int proc_num); 264df373737SAchin Gupta void gicv3_cpuif_enable(unsigned int proc_num); 265df373737SAchin Gupta void gicv3_cpuif_disable(unsigned int proc_num); 266df373737SAchin Gupta unsigned int gicv3_get_pending_interrupt_type(void); 267df373737SAchin Gupta unsigned int gicv3_get_pending_interrupt_id(void); 268df373737SAchin Gupta unsigned int gicv3_get_interrupt_type(unsigned int id, 269df373737SAchin Gupta unsigned int proc_num); 270df373737SAchin Gupta 271df373737SAchin Gupta 272df373737SAchin Gupta #endif /* __ASSEMBLY__ */ 273df373737SAchin Gupta #endif /* __GICV3_H__ */ 274