2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015-2016 Svatopluk Kraus
5 * Copyright (c) 2015-2016 Michal Meloun
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #error Need INTRNG for this file
38 #include <sys/systm.h>
40 #define INTR_IRQ_INVALID 0xFFFFFFFF
42 enum intr_map_data_type {
43 INTR_MAP_DATA_ACPI = 0,
48 /* Placeholders for platform specific types */
49 INTR_MAP_DATA_PLAT_1 = 1000,
56 struct intr_map_data {
58 enum intr_map_data_type type;
61 struct intr_map_data_msi {
62 struct intr_map_data hdr;
63 struct intr_irqsrc *isrc;
67 #define INTR_SOLO INTR_MD1
68 typedef int intr_irq_filter_t(void *arg, struct trapframe *tf);
70 typedef int intr_irq_filter_t(void *arg);
72 typedef int intr_child_irq_filter_t(void *arg, uintptr_t irq);
74 #define INTR_ISRC_NAMELEN (MAXCOMLEN + 1)
76 #define INTR_ISRCF_IPI 0x01 /* IPI interrupt */
77 #define INTR_ISRCF_PPI 0x02 /* PPI interrupt */
78 #define INTR_ISRCF_BOUND 0x04 /* bound to a CPU */
82 /* Interrupt source definition. */
84 device_t isrc_dev; /* where isrc is mapped */
85 u_int isrc_irq; /* unique identificator */
87 char isrc_name[INTR_ISRC_NAMELEN];
88 cpuset_t isrc_cpu; /* on which CPUs is enabled */
92 struct intr_event * isrc_event;
94 intr_irq_filter_t * isrc_filter;
97 /* Used by MSI interrupts to store the iommu details */
101 /* Intr interface for PIC. */
102 int intr_isrc_deregister(struct intr_irqsrc *);
103 int intr_isrc_register(struct intr_irqsrc *, device_t, u_int, const char *, ...)
107 bool intr_isrc_init_on_cpu(struct intr_irqsrc *isrc, u_int cpu);
110 int intr_isrc_dispatch(struct intr_irqsrc *, struct trapframe *);
111 u_int intr_irq_next_cpu(u_int current_cpu, cpuset_t *cpumask);
113 struct intr_pic *intr_pic_register(device_t, intptr_t);
114 int intr_pic_deregister(device_t, intptr_t);
115 int intr_pic_claim_root(device_t, intptr_t, intr_irq_filter_t *, void *, u_int);
116 struct intr_pic *intr_pic_add_handler(device_t, struct intr_pic *,
117 intr_child_irq_filter_t *, void *, uintptr_t, uintptr_t);
118 bool intr_is_per_cpu(struct resource *);
120 extern device_t intr_irq_root_dev;
122 /* Intr interface for BUS. */
124 int intr_activate_irq(device_t, struct resource *);
125 int intr_deactivate_irq(device_t, struct resource *);
127 int intr_setup_irq(device_t, struct resource *, driver_filter_t, driver_intr_t,
128 void *, int, void **);
129 int intr_teardown_irq(device_t, struct resource *, void *);
131 int intr_describe_irq(device_t, struct resource *, void *, const char *);
132 int intr_child_irq_handler(struct intr_pic *, uintptr_t);
134 /* Intr resources mapping. */
135 struct intr_map_data *intr_alloc_map_data(enum intr_map_data_type, size_t, int);
136 void intr_free_intr_map_data(struct intr_map_data *);
137 u_int intr_map_irq(device_t, intptr_t, struct intr_map_data *);
138 void intr_unmap_irq(u_int );
139 u_int intr_map_clone_irq(u_int );
141 /* MSI/MSI-X handling */
142 int intr_msi_register(device_t, intptr_t);
143 int intr_alloc_msi(device_t, device_t, intptr_t, int, int, int *);
144 int intr_release_msi(device_t, device_t, intptr_t, int, int *);
145 int intr_map_msi(device_t, device_t, intptr_t, int, uint64_t *, uint32_t *);
146 int intr_alloc_msix(device_t, device_t, intptr_t, int *);
147 int intr_release_msix(device_t, device_t, intptr_t, int);
150 int intr_bind_irq(device_t, struct resource *, int);
152 void intr_pic_init_secondary(void);
154 /* Virtualization for interrupt source IPI counter increment. */
156 intr_ipi_increment_count(u_long *counter, u_int cpu)
159 KASSERT(cpu < MAXCPU, ("%s: too big cpu %u", __func__, cpu));
163 /* Virtualization for interrupt source IPI counters setup. */
164 u_long * intr_ipi_setup_counters(const char *name);
167 #endif /* _SYS_INTR_H */