FreeBSD/Linux Kernel Cross Reference
sys/sys/interrupt.h
1 /*-
2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * 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 ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29 #ifndef _SYS_INTERRUPT_H_
30 #define _SYS_INTERRUPT_H_
31
32 #include <sys/_lock.h>
33 #include <sys/_mutex.h>
34
35 struct intr_event;
36 struct intr_thread;
37 struct trapframe;
38
39 /*
40 * Describe a hardware interrupt handler.
41 *
42 * Multiple interrupt handlers for a specific event can be chained
43 * together.
44 */
45 struct intr_handler {
46 driver_filter_t *ih_filter; /* Filter function. */
47 driver_intr_t *ih_handler; /* Handler function. */
48 void *ih_argument; /* Argument to pass to handler. */
49 int ih_flags;
50 char ih_name[MAXCOMLEN + 1]; /* Name of handler. */
51 struct intr_event *ih_event; /* Event we are connected to. */
52 int ih_need; /* Needs service. */
53 TAILQ_ENTRY(intr_handler) ih_next; /* Next handler for this event. */
54 u_char ih_pri; /* Priority of this handler. */
55 struct intr_thread *ih_thread; /* Ithread for filtered handler. */
56 };
57
58 /* Interrupt handle flags kept in ih_flags */
59 #define IH_EXCLUSIVE 0x00000002 /* Exclusive interrupt. */
60 #define IH_ENTROPY 0x00000004 /* Device is a good entropy source. */
61 #define IH_DEAD 0x00000008 /* Handler should be removed. */
62 #define IH_MPSAFE 0x80000000 /* Handler does not need Giant. */
63
64 /*
65 * Describe an interrupt event. An event holds a list of handlers.
66 * The 'pre_ithread', 'post_ithread', 'post_filter', and 'assign_cpu'
67 * hooks are used to invoke MD code for certain operations.
68 *
69 * The 'pre_ithread' hook is called when an interrupt thread for
70 * handlers without filters is scheduled. It is responsible for
71 * ensuring that 1) the system won't be swamped with an interrupt
72 * storm from the associated source while the ithread runs and 2) the
73 * current CPU is able to receive interrupts from other interrupt
74 * sources. The first is usually accomplished by disabling
75 * level-triggered interrupts until the ithread completes. The second
76 * is accomplished on some platforms by acknowledging the interrupt
77 * via an EOI.
78 *
79 * The 'post_ithread' hook is invoked when an ithread finishes. It is
80 * responsible for ensuring that the associated interrupt source will
81 * trigger an interrupt when it is asserted in the future. Usually
82 * this is implemented by enabling a level-triggered interrupt that
83 * was previously disabled via the 'pre_ithread' hook.
84 *
85 * The 'post_filter' hook is invoked when a filter handles an
86 * interrupt. It is responsible for ensuring that the current CPU is
87 * able to receive interrupts again. On some platforms this is done
88 * by acknowledging the interrupts via an EOI.
89 *
90 * The 'assign_cpu' hook is used to bind an interrupt source to a
91 * specific CPU. If the interrupt cannot be bound, this function may
92 * return an error.
93 */
94 struct intr_event {
95 TAILQ_ENTRY(intr_event) ie_list;
96 TAILQ_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */
97 char ie_name[MAXCOMLEN + 1]; /* Individual event name. */
98 char ie_fullname[MAXCOMLEN + 1];
99 struct mtx ie_lock;
100 void *ie_source; /* Cookie used by MD code. */
101 struct intr_thread *ie_thread; /* Thread we are connected to. */
102 void (*ie_pre_ithread)(void *);
103 void (*ie_post_ithread)(void *);
104 void (*ie_post_filter)(void *);
105 int (*ie_assign_cpu)(void *, u_char);
106 int ie_flags;
107 int ie_count; /* Loop counter. */
108 int ie_warncnt; /* Rate-check interrupt storm warns. */
109 struct timeval ie_warntm;
110 int ie_irq; /* Physical irq number if !SOFT. */
111 u_char ie_cpu; /* CPU this event is bound to. */
112 };
113
114 /* Interrupt event flags kept in ie_flags. */
115 #define IE_SOFT 0x000001 /* Software interrupt. */
116 #define IE_ENTROPY 0x000002 /* Interrupt is an entropy source. */
117 #define IE_ADDING_THREAD 0x000004 /* Currently building an ithread. */
118
119 /* Flags to pass to sched_swi. */
120 #define SWI_DELAY 0x2
121
122 /*
123 * Software interrupt numbers in priority order. The priority determines
124 * the priority of the corresponding interrupt thread.
125 */
126 #define SWI_TTY 0
127 #define SWI_NET 1
128 #define SWI_CAMBIO 2
129 #define SWI_VM 3
130 #define SWI_CLOCK 4
131 #define SWI_TQ_FAST 5
132 #define SWI_TQ 6
133 #define SWI_TQ_GIANT 6
134
135 extern struct intr_event *tty_intr_event;
136 extern struct intr_event *clk_intr_event;
137 extern void *softclock_ih;
138 extern void *vm_ih;
139
140 /* Counts and names for statistics (defined in MD code). */
141 extern u_long eintrcnt[]; /* end of intrcnt[] */
142 extern char eintrnames[]; /* end of intrnames[] */
143 extern u_long intrcnt[]; /* counts for for each device and stray */
144 extern char intrnames[]; /* string table containing device names */
145
146 #ifdef DDB
147 void db_dump_intr_event(struct intr_event *ie, int handlers);
148 #endif
149 u_char intr_priority(enum intr_type flags);
150 int intr_event_add_handler(struct intr_event *ie, const char *name,
151 driver_filter_t filter, driver_intr_t handler, void *arg,
152 u_char pri, enum intr_type flags, void **cookiep);
153 int intr_event_bind(struct intr_event *ie, u_char cpu);
154 int intr_event_create(struct intr_event **event, void *source,
155 int flags, int irq, void (*pre_ithread)(void *),
156 void (*post_ithread)(void *), void (*post_filter)(void *),
157 int (*assign_cpu)(void *, u_char), const char *fmt, ...)
158 __printflike(9, 10);
159 int intr_event_describe_handler(struct intr_event *ie, void *cookie,
160 const char *descr);
161 int intr_event_destroy(struct intr_event *ie);
162 int intr_event_handle(struct intr_event *ie, struct trapframe *frame);
163 int intr_event_remove_handler(void *cookie);
164 int intr_getaffinity(int irq, void *mask);
165 void *intr_handler_source(void *cookie);
166 int intr_setaffinity(int irq, void *mask);
167 int swi_add(struct intr_event **eventp, const char *name,
168 driver_intr_t handler, void *arg, int pri, enum intr_type flags,
169 void **cookiep);
170 void swi_sched(void *cookie, int flags);
171 int swi_remove(void *cookie);
172
173 #endif
Cache object: 6bcd4fd39f25674735c3a26e29a4bc62
|