1 /*- 2 * Copyright (c) 2016 The FreeBSD Foundation 3 * 4 * This software was developed by Andrew Turner under 5 * the sponsorship of the FreeBSD Foundation. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _GIC_COMMON_H_ 30 #define _GIC_COMMON_H_ 31 32 struct arm_gic_range { 33 uint64_t bus; 34 uint64_t host; 35 uint64_t size; 36 }; 37 38 #define GIC_IVAR_HW_REV 500 39 #define GIC_IVAR_BUS 501 40 #define GIC_IVAR_VGIC 502 41 42 /* GIC_IVAR_BUS values */ 43 #define GIC_BUS_UNKNOWN 0 44 #define GIC_BUS_FDT 1 45 #define GIC_BUS_ACPI 2 46 #define GIC_BUS_MAX 2 47 48 __BUS_ACCESSOR(gic, hw_rev, GIC, HW_REV, u_int); 49 __BUS_ACCESSOR(gic, bus, GIC, BUS, u_int); 50 __BUS_ACCESSOR(gic, vgic, GIC, VGIC, u_int); 51 52 /* Software Generated Interrupts */ 53 #define GIC_FIRST_SGI 0 /* Irqs 0-15 are SGIs/IPIs. */ 54 #define GIC_LAST_SGI 15 55 /* Private Peripheral Interrupts */ 56 #define GIC_FIRST_PPI 16 /* Irqs 16-31 are private (per */ 57 #define GIC_LAST_PPI 31 /* core) peripheral interrupts. */ 58 /* Shared Peripheral Interrupts */ 59 #define GIC_FIRST_SPI 32 /* Irqs 32+ are shared peripherals. */ 60 61 /* Common register values */ 62 #define GICD_CTLR 0x0000 /* v1 ICDDCR */ 63 #define GICD_TYPER 0x0004 /* v1 ICDICTR */ 64 #define GICD_TYPER_ITLINESNUM_MASK 0x1f 65 #define GICD_TYPER_I_NUM(n) ((((n) & 0x1F) + 1) * 32) 66 #define GICD_IIDR 0x0008 /* v1 ICDIIDR */ 67 #define GICD_IIDR_PROD_SHIFT 24 68 #define GICD_IIDR_PROD_MASK 0xff000000 69 #define GICD_IIDR_PROD(x) \ 70 (((x) & GICD_IIDR_PROD_MASK) >> GICD_IIDR_PROD_SHIFT) 71 #define GICD_IIDR_VAR_SHIFT 16 72 #define GICD_IIDR_VAR_MASK 0x000f0000 73 #define GICD_IIDR_VAR(x) \ 74 (((x) & GICD_IIDR_VAR_MASK) >> GICD_IIDR_VAR_SHIFT) 75 #define GICD_IIDR_REV_SHIFT 12 76 #define GICD_IIDR_REV_MASK 0x0000f000 77 #define GICD_IIDR_REV(x) \ 78 (((x) & GICD_IIDR_REV_MASK) >> GICD_IIDR_REV_SHIFT) 79 #define GICD_IIDR_IMPL_SHIFT 0 80 #define GICD_IIDR_IMPL_MASK 0x00000fff 81 #define GICD_IIDR_IMPL(x) \ 82 (((x) & GICD_IIDR_IMPL_MASK) >> GICD_IIDR_IMPL_SHIFT) 83 #define GICD_IGROUPR(n) (0x0080 + (((n) >> 5) * 4)) /* v1 ICDISER */ 84 #define GICD_I_PER_IGROUPRn 32 85 #define GICD_ISENABLER(n) (0x0100 + (((n) >> 5) * 4)) /* v1 ICDISER */ 86 #define GICD_I_MASK(n) (1ul << ((n) & 0x1f)) 87 #define GICD_I_PER_ISENABLERn 32 88 #define GICD_ICENABLER(n) (0x0180 + (((n) >> 5) * 4)) /* v1 ICDICER */ 89 #define GICD_ISPENDR(n) (0x0200 + (((n) >> 5) * 4)) /* v1 ICDISPR */ 90 #define GICD_ICPENDR(n) (0x0280 + (((n) >> 5) * 4)) /* v1 ICDICPR */ 91 #define GICD_ISACTIVER(n) (0x0300 + (((n) >> 5) * 4)) /* v1 ICDABR */ 92 #define GICD_ICACTIVER(n) (0x0380 + (((n) >> 5) * 4)) 93 #define GICD_IPRIORITYR(n) (0x0400 + (((n) >> 2) * 4)) /* v1 ICDIPR */ 94 #define GICD_I_PER_IPRIORITYn 4 95 #define GICD_ITARGETSR(n) (0x0800 + (((n) >> 2) * 4)) /* v1 ICDIPTR */ 96 #define GICD_ICFGR(n) (0x0C00 + (((n) >> 4) * 4)) /* v1 ICDICFR */ 97 #define GICD_I_PER_ICFGRn 16 98 /* First bit is a polarity bit (0 - low, 1 - high) */ 99 #define GICD_ICFGR_POL_LOW (0 << 0) 100 #define GICD_ICFGR_POL_HIGH (1 << 0) 101 #define GICD_ICFGR_POL_MASK 0x1 102 /* Second bit is a trigger bit (0 - level, 1 - edge) */ 103 #define GICD_ICFGR_TRIG_LVL (0 << 1) 104 #define GICD_ICFGR_TRIG_EDGE (1 << 1) 105 #define GICD_ICFGR_TRIG_MASK 0x2 106 #define GICD_SGIR 0x0F00 /* v1 ICDSGIR */ 107 #define GICD_SGI_TARGET_SHIFT 16 108 109 #endif /* _GIC_COMMON_H_ */ 110