intr.h revision 300149
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 300149 2016-05-18 15:05:44Z andrew $ 28 */ 29 30#ifndef _SYS_INTR_H_ 31#define _SYS_INTR_H_ 32 33#include <sys/systm.h> 34 35#define INTR_IRQ_INVALID 0xFFFFFFFF 36 37enum intr_map_data_type { 38 INTR_MAP_DATA_ACPI, 39 INTR_MAP_DATA_FDT, 40 INTR_MAP_DATA_GPIO, 41}; 42 43struct intr_map_data { 44 enum intr_map_data_type type; 45 size_t size; 46}; 47 48#ifdef DEV_ACPI 49struct intr_map_data_acpi { 50 struct intr_map_data hdr; 51 u_int irq; 52 enum intr_polarity pol; 53 enum intr_trigger trig; 54}; 55#endif 56#ifdef FDT 57struct intr_map_data_fdt { 58 struct intr_map_data hdr; 59 u_int ncells; 60 pcell_t cells[0]; 61}; 62#endif 63 64struct intr_map_data_gpio { 65 struct intr_map_data hdr; 66 u_int gpio_pin_num; 67 u_int gpio_pin_flags; 68 u_int gpio_intr_mode; 69}; 70 71#ifdef notyet 72#define INTR_SOLO INTR_MD1 73typedef int intr_irq_filter_t(void *arg, struct trapframe *tf); 74#else 75typedef int intr_irq_filter_t(void *arg); 76#endif 77 78#define INTR_ISRC_NAMELEN (MAXCOMLEN + 1) 79 80#define INTR_ISRCF_IPI 0x01 /* IPI interrupt */ 81#define INTR_ISRCF_PPI 0x02 /* PPI interrupt */ 82#define INTR_ISRCF_BOUND 0x04 /* bound to a CPU */ 83 84/* Interrupt source definition. */ 85struct intr_irqsrc { 86 device_t isrc_dev; /* where isrc is mapped */ 87 u_int isrc_irq; /* unique identificator */ 88 u_int isrc_flags; 89 char isrc_name[INTR_ISRC_NAMELEN]; 90 cpuset_t isrc_cpu; /* on which CPUs is enabled */ 91 u_int isrc_index; 92 u_long * isrc_count; 93 u_int isrc_handlers; 94 struct intr_event * isrc_event; 95#ifdef INTR_SOLO 96 intr_irq_filter_t * isrc_filter; 97 void * isrc_arg; 98#endif 99}; 100 101/* Intr interface for PIC. */ 102int intr_isrc_deregister(struct intr_irqsrc *); 103int intr_isrc_register(struct intr_irqsrc *, device_t, u_int, const char *, ...) 104 __printflike(4, 5); 105 106#ifdef SMP 107bool intr_isrc_init_on_cpu(struct intr_irqsrc *isrc, u_int cpu); 108#endif 109 110int intr_isrc_dispatch(struct intr_irqsrc *, struct trapframe *); 111u_int intr_irq_next_cpu(u_int current_cpu, cpuset_t *cpumask); 112 113struct intr_pic *intr_pic_register(device_t, intptr_t); 114int intr_pic_deregister(device_t, intptr_t); 115int intr_pic_claim_root(device_t, intptr_t, intr_irq_filter_t *, void *, u_int); 116 117extern device_t intr_irq_root_dev; 118 119/* Intr interface for BUS. */ 120int intr_map_irq(device_t, intptr_t, struct intr_map_data *, u_int *); 121 122int intr_alloc_irq(device_t, struct resource *); 123int intr_release_irq(device_t, struct resource *); 124 125int intr_setup_irq(device_t, struct resource *, driver_filter_t, driver_intr_t, 126 void *, int, void **); 127int intr_teardown_irq(device_t, struct resource *, void *); 128 129int intr_describe_irq(device_t, struct resource *, void *, const char *); 130 131/* MSI/MSI-X handling */ 132int intr_msi_register(device_t, intptr_t); 133int intr_alloc_msi(device_t, device_t, intptr_t, int, int, int *); 134int intr_release_msi(device_t, device_t, intptr_t, int, int *); 135int intr_map_msi(device_t, device_t, intptr_t, int, uint64_t *, uint32_t *); 136int intr_alloc_msix(device_t, device_t, intptr_t, int *); 137int intr_release_msix(device_t, device_t, intptr_t, int); 138 139#ifdef DEV_ACPI 140u_int intr_acpi_map_irq(device_t, u_int, enum intr_polarity, 141 enum intr_trigger); 142#endif 143#ifdef FDT 144u_int intr_fdt_map_irq(phandle_t, pcell_t *, u_int); 145#endif 146u_int intr_gpio_map_irq(device_t dev, u_int pin_num, u_int pin_flags, 147 u_int intr_mode); 148 149#ifdef SMP 150int intr_bind_irq(device_t, struct resource *, int); 151 152void intr_pic_init_secondary(void); 153 154/* Virtualization for interrupt source IPI counter increment. */ 155static inline void 156intr_ipi_increment_count(u_long *counter, u_int cpu) 157{ 158 159 KASSERT(cpu < MAXCPU, ("%s: too big cpu %u", __func__, cpu)); 160 counter[cpu]++; 161} 162 163/* Virtualization for interrupt source IPI counters setup. */ 164u_long * intr_ipi_setup_counters(const char *name); 165 166#endif 167#endif /* _SYS_INTR_H */ 168