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