191a6c3ceSAndrew Jones /* 291a6c3ceSAndrew Jones * All GIC* defines are lifted from include/linux/irqchip/arm-gic-v3.h 391a6c3ceSAndrew Jones * 491a6c3ceSAndrew Jones * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com> 591a6c3ceSAndrew Jones * 691a6c3ceSAndrew Jones * This work is licensed under the terms of the GNU LGPL, version 2. 791a6c3ceSAndrew Jones */ 891a6c3ceSAndrew Jones #ifndef _ASMARM_GIC_V3_H_ 991a6c3ceSAndrew Jones #define _ASMARM_GIC_V3_H_ 1091a6c3ceSAndrew Jones 1191a6c3ceSAndrew Jones #ifndef _ASMARM_GIC_H_ 1291a6c3ceSAndrew Jones #error Do not directly include <asm/gic-v3.h>. Include <asm/gic.h> 1391a6c3ceSAndrew Jones #endif 1491a6c3ceSAndrew Jones 1591a6c3ceSAndrew Jones /* 1691a6c3ceSAndrew Jones * Distributor registers 1791a6c3ceSAndrew Jones * 1891a6c3ceSAndrew Jones * We expect to be run in Non-secure mode, thus we define the 1991a6c3ceSAndrew Jones * group1 enable bits with respect to that view. 2091a6c3ceSAndrew Jones */ 2191a6c3ceSAndrew Jones #define GICD_CTLR_RWP (1U << 31) 2291a6c3ceSAndrew Jones #define GICD_CTLR_ARE_NS (1U << 4) 2391a6c3ceSAndrew Jones #define GICD_CTLR_ENABLE_G1A (1U << 1) 2491a6c3ceSAndrew Jones #define GICD_CTLR_ENABLE_G1 (1U << 0) 2591a6c3ceSAndrew Jones 2691a6c3ceSAndrew Jones /* Re-Distributor registers, offsets from RD_base */ 2791a6c3ceSAndrew Jones #define GICR_TYPER 0x0008 2891a6c3ceSAndrew Jones 2991a6c3ceSAndrew Jones #define GICR_TYPER_LAST (1U << 4) 3091a6c3ceSAndrew Jones 3191a6c3ceSAndrew Jones /* Re-Distributor registers, offsets from SGI_base */ 3291a6c3ceSAndrew Jones #define GICR_IGROUPR0 GICD_IGROUPR 3391a6c3ceSAndrew Jones #define GICR_ISENABLER0 GICD_ISENABLER 3408ae0906SAlexandru Elisei #define GICR_ICENABLER0 GICD_ICENABLER 35*401c09eaSZenghui Yu #define GICR_ISPENDR0 GICD_ISPENDR 36*401c09eaSZenghui Yu #define GICR_ICPENDR0 GICD_ICPENDR 37*401c09eaSZenghui Yu #define GICR_ISACTIVER0 GICD_ISACTIVER 38*401c09eaSZenghui Yu #define GICR_ICACTIVER0 GICD_ICACTIVER 3991a6c3ceSAndrew Jones #define GICR_IPRIORITYR0 GICD_IPRIORITYR 4091a6c3ceSAndrew Jones 412e2d471dSAndrew Jones #define ICC_SGI1R_AFFINITY_1_SHIFT 16 422e2d471dSAndrew Jones #define ICC_SGI1R_AFFINITY_2_SHIFT 32 432e2d471dSAndrew Jones #define ICC_SGI1R_AFFINITY_3_SHIFT 48 442e2d471dSAndrew Jones #define MPIDR_TO_SGI_AFFINITY(cluster_id, level) \ 452e2d471dSAndrew Jones (MPIDR_AFFINITY_LEVEL(cluster_id, level) << ICC_SGI1R_AFFINITY_## level ## _SHIFT) 462e2d471dSAndrew Jones 4791a6c3ceSAndrew Jones #include <asm/arch_gicv3.h> 4891a6c3ceSAndrew Jones 4991a6c3ceSAndrew Jones #ifndef __ASSEMBLY__ 5091a6c3ceSAndrew Jones #include <asm/setup.h> 5191a6c3ceSAndrew Jones #include <asm/processor.h> 5291a6c3ceSAndrew Jones #include <asm/delay.h> 532e2d471dSAndrew Jones #include <asm/cpumask.h> 5491a6c3ceSAndrew Jones #include <asm/smp.h> 5591a6c3ceSAndrew Jones #include <asm/io.h> 5691a6c3ceSAndrew Jones 57a5a2d35cSAndrew Jones #define GICV3_NR_REDISTS 8 58a5a2d35cSAndrew Jones 5991a6c3ceSAndrew Jones struct gicv3_data { 6091a6c3ceSAndrew Jones void *dist_base; 61a5a2d35cSAndrew Jones void *redist_bases[GICV3_NR_REDISTS]; 6291a6c3ceSAndrew Jones void *redist_base[NR_CPUS]; 6391a6c3ceSAndrew Jones unsigned int irq_nr; 6491a6c3ceSAndrew Jones }; 6591a6c3ceSAndrew Jones extern struct gicv3_data gicv3_data; 6691a6c3ceSAndrew Jones 6791a6c3ceSAndrew Jones #define gicv3_dist_base() (gicv3_data.dist_base) 6891a6c3ceSAndrew Jones #define gicv3_redist_base() (gicv3_data.redist_base[smp_processor_id()]) 6991a6c3ceSAndrew Jones #define gicv3_sgi_base() (gicv3_data.redist_base[smp_processor_id()] + SZ_64K) 7091a6c3ceSAndrew Jones 7191a6c3ceSAndrew Jones extern int gicv3_init(void); 7291a6c3ceSAndrew Jones extern void gicv3_enable_defaults(void); 732e2d471dSAndrew Jones extern u32 gicv3_read_iar(void); 742e2d471dSAndrew Jones extern u32 gicv3_iar_irqnr(u32 iar); 752e2d471dSAndrew Jones extern void gicv3_write_eoir(u32 irqstat); 762e2d471dSAndrew Jones extern void gicv3_ipi_send_single(int irq, int cpu); 772e2d471dSAndrew Jones extern void gicv3_ipi_send_mask(int irq, const cpumask_t *dest); 7891a6c3ceSAndrew Jones extern void gicv3_set_redist_base(size_t stride); 7991a6c3ceSAndrew Jones 8091a6c3ceSAndrew Jones static inline void gicv3_do_wait_for_rwp(void *base) 8191a6c3ceSAndrew Jones { 8291a6c3ceSAndrew Jones int count = 100000; /* 1s */ 8391a6c3ceSAndrew Jones 8491a6c3ceSAndrew Jones while (readl(base + GICD_CTLR) & GICD_CTLR_RWP) { 8591a6c3ceSAndrew Jones if (!--count) { 8691a6c3ceSAndrew Jones printf("GICv3: RWP timeout!\n"); 8791a6c3ceSAndrew Jones abort(); 8891a6c3ceSAndrew Jones } 8991a6c3ceSAndrew Jones cpu_relax(); 9091a6c3ceSAndrew Jones udelay(10); 9191a6c3ceSAndrew Jones }; 9291a6c3ceSAndrew Jones } 9391a6c3ceSAndrew Jones 9491a6c3ceSAndrew Jones static inline void gicv3_dist_wait_for_rwp(void) 9591a6c3ceSAndrew Jones { 9691a6c3ceSAndrew Jones gicv3_do_wait_for_rwp(gicv3_dist_base()); 9791a6c3ceSAndrew Jones } 9891a6c3ceSAndrew Jones 9991a6c3ceSAndrew Jones static inline void gicv3_redist_wait_for_uwp(void) 10091a6c3ceSAndrew Jones { 10191a6c3ceSAndrew Jones /* 10291a6c3ceSAndrew Jones * We can build on gic_do_wait_for_rwp, which uses GICD_ registers 10391a6c3ceSAndrew Jones * because GICD_CTLR == GICR_CTLR and GICD_CTLR_RWP == GICR_CTLR_UWP 10491a6c3ceSAndrew Jones */ 10591a6c3ceSAndrew Jones gicv3_do_wait_for_rwp(gicv3_redist_base()); 10691a6c3ceSAndrew Jones } 10791a6c3ceSAndrew Jones 10891a6c3ceSAndrew Jones static inline u32 mpidr_compress(u64 mpidr) 10991a6c3ceSAndrew Jones { 11091a6c3ceSAndrew Jones u64 compressed = mpidr & MPIDR_HWID_BITMASK; 11191a6c3ceSAndrew Jones 11291a6c3ceSAndrew Jones compressed = (((compressed >> 32) & 0xff) << 24) | compressed; 11391a6c3ceSAndrew Jones return compressed; 11491a6c3ceSAndrew Jones } 11591a6c3ceSAndrew Jones 11691a6c3ceSAndrew Jones static inline u64 mpidr_uncompress(u32 compressed) 11791a6c3ceSAndrew Jones { 11891a6c3ceSAndrew Jones u64 mpidr = ((u64)compressed >> 24) << 32; 11991a6c3ceSAndrew Jones 12091a6c3ceSAndrew Jones mpidr |= compressed & MPIDR_HWID_BITMASK; 12191a6c3ceSAndrew Jones return mpidr; 12291a6c3ceSAndrew Jones } 12391a6c3ceSAndrew Jones 12491a6c3ceSAndrew Jones #endif /* !__ASSEMBLY__ */ 12591a6c3ceSAndrew Jones #endif /* _ASMARM_GIC_V3_H_ */ 126