intr.h revision 297674
1/*- 2 * Copyright (c) 2015-2016 Svatopluk Kraus 3 * Copyright (c) 2015-2016 Michal Meloun 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD: head/sys/sys/intr.h 297674 2016-04-07 15:00:25Z skra $ 28 */ 29 30#ifndef _SYS_INTR_H_ 31#define _SYS_INTR_H_ 32 33#include <sys/systm.h> 34 35enum intr_map_data_type { 36 INTR_MAP_DATA_ACPI, 37 INTR_MAP_DATA_FDT, 38}; 39 40#ifdef DEV_ACPI 41struct intr_map_data_acpi { 42 u_int irq; 43 enum intr_polarity pol; 44 enum intr_trigger trig; 45}; 46#endif 47#ifdef FDT 48struct intr_map_data_fdt { 49 u_int ncells; 50 pcell_t *cells; 51}; 52#endif 53 54struct intr_map_data { 55 enum intr_map_data_type type; 56 union { 57#ifdef DEV_ACPI 58 struct intr_map_data_acpi acpi; 59#endif 60#ifdef FDT 61 struct intr_map_data_fdt fdt; 62#endif 63 }; 64}; 65 66#ifdef notyet 67#define INTR_SOLO INTR_MD1 68typedef int intr_irq_filter_t(void *arg, struct trapframe *tf); 69#else 70typedef int intr_irq_filter_t(void *arg); 71#endif 72 73#define INTR_ISRC_NAMELEN (MAXCOMLEN + 1) 74 75#define INTR_ISRCF_IPI 0x01 /* IPI interrupt */ 76#define INTR_ISRCF_PPI 0x02 /* PPI interrupt */ 77#define INTR_ISRCF_BOUND 0x04 /* bound to a CPU */ 78 79/* Interrupt source definition. */ 80struct intr_irqsrc { 81 device_t isrc_dev; /* where isrc is mapped */ 82 u_int isrc_irq; /* unique identificator */ 83 u_int isrc_flags; 84 char isrc_name[INTR_ISRC_NAMELEN]; 85 cpuset_t isrc_cpu; /* on which CPUs is enabled */ 86 u_int isrc_index; 87 u_long * isrc_count; 88 u_int isrc_handlers; 89 struct intr_event * isrc_event; 90#ifdef INTR_SOLO 91 intr_irq_filter_t * isrc_filter; 92 void * isrc_arg; 93#endif 94}; 95 96/* Intr interface for PIC. */ 97int intr_isrc_deregister(struct intr_irqsrc *); 98int intr_isrc_register(struct intr_irqsrc *, device_t, u_int, const char *, ...) 99 __printflike(4, 5); 100 101#ifdef SMP 102bool intr_isrc_init_on_cpu(struct intr_irqsrc *isrc, u_int cpu); 103#endif 104 105int intr_isrc_dispatch(struct intr_irqsrc *, struct trapframe *); 106u_int intr_irq_next_cpu(u_int current_cpu, cpuset_t *cpumask); 107 108int intr_pic_register(device_t, intptr_t); 109int intr_pic_deregister(device_t, intptr_t); 110int intr_pic_claim_root(device_t, intptr_t, intr_irq_filter_t *, void *, u_int); 111 112extern device_t intr_irq_root_dev; 113 114/* Intr interface for BUS. */ 115int intr_map_irq(device_t, intptr_t, struct intr_map_data *, u_int *); 116 117int intr_alloc_irq(device_t, struct resource *); 118int intr_release_irq(device_t, struct resource *); 119 120int intr_setup_irq(device_t, struct resource *, driver_filter_t, driver_intr_t, 121 void *, int, void **); 122int intr_teardown_irq(device_t, struct resource *, void *); 123 124int intr_describe_irq(device_t, struct resource *, void *, const char *); 125 126#ifdef DEV_ACPI 127u_int intr_acpi_map_irq(device_t, u_int, enum intr_polarity, 128 enum intr_trigger); 129#endif 130#ifdef FDT 131u_int intr_fdt_map_irq(phandle_t, pcell_t *, u_int); 132#endif 133 134#ifdef SMP 135int intr_bind_irq(device_t, struct resource *, int); 136 137void intr_pic_init_secondary(void); 138 139/* Virtualization for interrupt source IPI counter increment. */ 140static inline void 141intr_ipi_increment_count(u_long *counter, u_int cpu) 142{ 143 144 KASSERT(cpu < MAXCPU, ("%s: too big cpu %u", __func__, cpu)); 145 counter[cpu]++; 146} 147 148/* Virtualization for interrupt source IPI counters setup. */ 149u_long * intr_ipi_setup_counters(const char *name); 150 151#endif 152#endif /* _SYS_INTR_H */ 153