16fc729afSOlivier Houchard /* $NetBSD: intr.h,v 1.7 2003/06/16 20:01:00 thorpej Exp $ */ 26fc729afSOlivier Houchard 3d8315c79SWarner Losh /*- 46fc729afSOlivier Houchard * Copyright (c) 1997 Mark Brinicombe. 56fc729afSOlivier Houchard * All rights reserved. 66fc729afSOlivier Houchard * 76fc729afSOlivier Houchard * Redistribution and use in source and binary forms, with or without 86fc729afSOlivier Houchard * modification, are permitted provided that the following conditions 96fc729afSOlivier Houchard * are met: 106fc729afSOlivier Houchard * 1. Redistributions of source code must retain the above copyright 116fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer. 126fc729afSOlivier Houchard * 2. Redistributions in binary form must reproduce the above copyright 136fc729afSOlivier Houchard * notice, this list of conditions and the following disclaimer in the 146fc729afSOlivier Houchard * documentation and/or other materials provided with the distribution. 156fc729afSOlivier Houchard * 3. All advertising materials mentioning features or use of this software 166fc729afSOlivier Houchard * must display the following acknowledgement: 176fc729afSOlivier Houchard * This product includes software developed by Mark Brinicombe 186fc729afSOlivier Houchard * for the NetBSD Project. 196fc729afSOlivier Houchard * 4. The name of the company nor the name of the author may be used to 206fc729afSOlivier Houchard * endorse or promote products derived from this software without specific 216fc729afSOlivier Houchard * prior written permission. 226fc729afSOlivier Houchard * 236fc729afSOlivier Houchard * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 246fc729afSOlivier Houchard * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 256fc729afSOlivier Houchard * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 266fc729afSOlivier Houchard * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 276fc729afSOlivier Houchard * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 286fc729afSOlivier Houchard * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 296fc729afSOlivier Houchard * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 306fc729afSOlivier Houchard * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 316fc729afSOlivier Houchard * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 326fc729afSOlivier Houchard * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 336fc729afSOlivier Houchard * SUCH DAMAGE. 346fc729afSOlivier Houchard * 356fc729afSOlivier Houchard * $FreeBSD$ 366fc729afSOlivier Houchard * 376fc729afSOlivier Houchard */ 386fc729afSOlivier Houchard 396fc729afSOlivier Houchard #ifndef _MACHINE_INTR_H_ 406fc729afSOlivier Houchard #define _MACHINE_INTR_H_ 416fc729afSOlivier Houchard 42ec7d251eSAndrew Turner #ifdef FDT 43ec7d251eSAndrew Turner #include <dev/ofw/openfirm.h> 44ec7d251eSAndrew Turner #endif 45ec7d251eSAndrew Turner 46*686450c8SIan Lepore #ifdef ARM_INTRNG 47*686450c8SIan Lepore 48*686450c8SIan Lepore #ifndef NIRQ 49*686450c8SIan Lepore #define NIRQ 1024 /* XXX - It should be an option. */ 50*686450c8SIan Lepore #endif 51*686450c8SIan Lepore 52*686450c8SIan Lepore #ifdef notyet 53*686450c8SIan Lepore #define INTR_SOLO INTR_MD1 54*686450c8SIan Lepore typedef int arm_irq_filter_t(void *arg, struct trapframe *tf); 55*686450c8SIan Lepore #else 56*686450c8SIan Lepore typedef int arm_irq_filter_t(void *arg); 57*686450c8SIan Lepore #endif 58*686450c8SIan Lepore 59*686450c8SIan Lepore #define ARM_ISRC_NAMELEN (MAXCOMLEN + 1) 60*686450c8SIan Lepore 61*686450c8SIan Lepore typedef void arm_ipi_filter_t(void *arg); 62*686450c8SIan Lepore 63*686450c8SIan Lepore enum arm_isrc_type { 64*686450c8SIan Lepore ARM_ISRCT_NAMESPACE, 65*686450c8SIan Lepore ARM_ISRCT_FDT 66*686450c8SIan Lepore }; 67*686450c8SIan Lepore 68*686450c8SIan Lepore #define ARM_ISRCF_REGISTERED 0x01 /* registered in a controller */ 69*686450c8SIan Lepore #define ARM_ISRCF_PERCPU 0x02 /* per CPU interrupt */ 70*686450c8SIan Lepore #define ARM_ISRCF_BOUND 0x04 /* bound to a CPU */ 71*686450c8SIan Lepore 72*686450c8SIan Lepore /* Interrupt source definition. */ 73*686450c8SIan Lepore struct arm_irqsrc { 74*686450c8SIan Lepore device_t isrc_dev; /* where isrc is mapped */ 75*686450c8SIan Lepore intptr_t isrc_xref; /* device reference key */ 76*686450c8SIan Lepore uintptr_t isrc_data; /* device data for isrc */ 77*686450c8SIan Lepore u_int isrc_irq; /* unique identificator */ 78*686450c8SIan Lepore enum arm_isrc_type isrc_type; /* how is isrc decribed */ 79*686450c8SIan Lepore u_int isrc_flags; 80*686450c8SIan Lepore char isrc_name[ARM_ISRC_NAMELEN]; 81*686450c8SIan Lepore uint16_t isrc_nspc_type; 82*686450c8SIan Lepore uint16_t isrc_nspc_num; 83*686450c8SIan Lepore enum intr_trigger isrc_trig; 84*686450c8SIan Lepore enum intr_polarity isrc_pol; 85*686450c8SIan Lepore cpuset_t isrc_cpu; /* on which CPUs is enabled */ 86*686450c8SIan Lepore u_int isrc_index; 87*686450c8SIan Lepore u_long * isrc_count; 88*686450c8SIan Lepore u_int isrc_handlers; 89*686450c8SIan Lepore struct intr_event * isrc_event; 90*686450c8SIan Lepore arm_irq_filter_t * isrc_filter; 91*686450c8SIan Lepore arm_ipi_filter_t * isrc_ipifilter; 92*686450c8SIan Lepore void * isrc_arg; 93*686450c8SIan Lepore #ifdef FDT 94*686450c8SIan Lepore u_int isrc_ncells; 95*686450c8SIan Lepore pcell_t isrc_cells[]; /* leave it last */ 96*686450c8SIan Lepore #endif 97*686450c8SIan Lepore }; 98*686450c8SIan Lepore 99*686450c8SIan Lepore void arm_irq_set_name(struct arm_irqsrc *isrc, const char *fmt, ...) 100*686450c8SIan Lepore __printflike(2, 3); 101*686450c8SIan Lepore 102*686450c8SIan Lepore void arm_irq_dispatch(struct arm_irqsrc *isrc, struct trapframe *tf); 103*686450c8SIan Lepore 104*686450c8SIan Lepore #define ARM_IRQ_NSPC_NONE 0 105*686450c8SIan Lepore #define ARM_IRQ_NSPC_PLAIN 1 106*686450c8SIan Lepore #define ARM_IRQ_NSPC_IRQ 2 107*686450c8SIan Lepore #define ARM_IRQ_NSPC_IPI 3 108*686450c8SIan Lepore 109*686450c8SIan Lepore u_int arm_namespace_map_irq(device_t dev, uint16_t type, uint16_t num); 110*686450c8SIan Lepore #ifdef FDT 111*686450c8SIan Lepore u_int arm_fdt_map_irq(phandle_t, pcell_t *, u_int); 112*686450c8SIan Lepore #endif 113*686450c8SIan Lepore 114*686450c8SIan Lepore int arm_pic_register(device_t dev, intptr_t xref); 115*686450c8SIan Lepore int arm_pic_unregister(device_t dev, intptr_t xref); 116*686450c8SIan Lepore int arm_pic_claim_root(device_t dev, intptr_t xref, arm_irq_filter_t *filter, 117*686450c8SIan Lepore void *arg, u_int ipicount); 118*686450c8SIan Lepore 119*686450c8SIan Lepore int arm_irq_add_handler(device_t dev, driver_filter_t, driver_intr_t, void *, 120*686450c8SIan Lepore u_int, int, void **); 121*686450c8SIan Lepore int arm_irq_remove_handler(device_t dev, u_int, void *); 122*686450c8SIan Lepore int arm_irq_config(u_int, enum intr_trigger, enum intr_polarity); 123*686450c8SIan Lepore int arm_irq_describe(u_int, void *, const char *); 124*686450c8SIan Lepore 125*686450c8SIan Lepore u_int arm_irq_next_cpu(u_int current_cpu, cpuset_t *cpumask); 126*686450c8SIan Lepore 127*686450c8SIan Lepore #ifdef SMP 128*686450c8SIan Lepore int arm_irq_bind(u_int, int); 129*686450c8SIan Lepore 130*686450c8SIan Lepore void arm_ipi_dispatch(struct arm_irqsrc *isrc, struct trapframe *tf); 131*686450c8SIan Lepore 132*686450c8SIan Lepore #define AISHF_NOALLOC 0x0001 133*686450c8SIan Lepore 134*686450c8SIan Lepore int arm_ipi_set_handler(u_int ipi, const char *name, arm_ipi_filter_t *filter, 135*686450c8SIan Lepore void *arg, u_int flags); 136*686450c8SIan Lepore 137*686450c8SIan Lepore void arm_pic_init_secondary(void); 138*686450c8SIan Lepore #endif 139*686450c8SIan Lepore 140*686450c8SIan Lepore #else /* ARM_INTRNG */ 141*686450c8SIan Lepore 142d2120224SSam Leffler /* XXX move to std.* files? */ 143d076bcf2SOlivier Houchard #ifdef CPU_XSCALE_81342 144d076bcf2SOlivier Houchard #define NIRQ 128 1459722a615SBenno Rice #elif defined(CPU_XSCALE_PXA2X0) 1469722a615SBenno Rice #include <arm/xscale/pxa/pxareg.h> 1479722a615SBenno Rice #define NIRQ IRQ_GPIO_MAX 148373bbe25SRafal Jaworowski #elif defined(SOC_MV_DISCOVERY) 149373bbe25SRafal Jaworowski #define NIRQ 96 150d2120224SSam Leffler #elif defined(CPU_ARM9) || defined(SOC_MV_KIRKWOOD) || \ 151d2120224SSam Leffler defined(CPU_XSCALE_IXP435) 15231d0686dSOlivier Houchard #define NIRQ 64 153cf1a573fSOleksandr Tymoshenko #elif defined(CPU_CORTEXA) 15499d7e0a9SRuslan Bukin #define NIRQ 1020 155543c9e95SGanbold Tsagaankhuu #elif defined(CPU_KRAIT) 156543c9e95SGanbold Tsagaankhuu #define NIRQ 288 157930798f3SAndrew Turner #elif defined(CPU_ARM1176) 15846ad39d5SOleksandr Tymoshenko #define NIRQ 128 159d65cdf4bSGrzegorz Bernacki #elif defined(SOC_MV_ARMADAXP) 160aa0ea9d0SGrzegorz Bernacki #define MAIN_IRQ_NUM 116 161aa0ea9d0SGrzegorz Bernacki #define ERR_IRQ_NUM 32 162aa0ea9d0SGrzegorz Bernacki #define ERR_IRQ (MAIN_IRQ_NUM) 163aa0ea9d0SGrzegorz Bernacki #define MSI_IRQ_NUM 32 164aa0ea9d0SGrzegorz Bernacki #define MSI_IRQ (ERR_IRQ + ERR_IRQ_NUM) 165aa0ea9d0SGrzegorz Bernacki #define NIRQ (MAIN_IRQ_NUM + ERR_IRQ_NUM + MSI_IRQ_NUM) 16631d0686dSOlivier Houchard #else 1677c320e5bSOlivier Houchard #define NIRQ 32 16831d0686dSOlivier Houchard #endif 1696fc729afSOlivier Houchard 170272489feSMarcel Moolenaar int arm_get_next_irq(int); 171f60e923bSOlivier Houchard void arm_mask_irq(uintptr_t); 172f60e923bSOlivier Houchard void arm_unmask_irq(uintptr_t); 173ae4f863cSIan Lepore void arm_intrnames_init(void); 174ef544f63SPaolo Pisati void arm_setup_irqhandler(const char *, int (*)(void*), void (*)(void*), 175ef544f63SPaolo Pisati void *, int, int, void **); 176f4e42148SRafal Jaworowski int arm_remove_irqhandler(int, void *); 177e19357d3SOlivier Houchard extern void (*arm_post_filter)(void *); 1784acd62c5SZbigniew Bodek extern int (*arm_config_irq)(int irq, enum intr_trigger trig, 1794acd62c5SZbigniew Bodek enum intr_polarity pol); 180cf1a573fSOleksandr Tymoshenko 1817ce00ee7SIan Lepore void arm_pic_init_secondary(void); 1820e390441SIan Lepore int gic_decode_fdt(uint32_t iparentnode, uint32_t *intrcells, int *interrupt, 1830e390441SIan Lepore int *trig, int *pol); 184cf1a573fSOleksandr Tymoshenko 185ec7d251eSAndrew Turner #ifdef FDT 186ec7d251eSAndrew Turner int arm_fdt_map_irq(phandle_t, pcell_t *, int); 187ec7d251eSAndrew Turner #endif 188ec7d251eSAndrew Turner 189*686450c8SIan Lepore #endif /* ARM_INTRNG */ 190*686450c8SIan Lepore 191*686450c8SIan Lepore void arm_irq_memory_barrier(uintptr_t); 192*686450c8SIan Lepore 1936fc729afSOlivier Houchard #endif /* _MACHINE_INTR_H */ 194