2 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
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.
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.
29 #ifndef _SYS_INTERRUPT_H_
30 #define _SYS_INTERRUPT_H_
32 #include <sys/_lock.h>
33 #include <sys/_mutex.h>
39 * Describe a hardware interrupt handler.
41 * Multiple interrupt handlers for a specific event can be chained
45 driver_intr_t *ih_handler; /* Handler function. */
46 void *ih_argument; /* Argument to pass to handler. */
48 const char *ih_name; /* Name of handler. */
49 struct intr_event *ih_event; /* Event we are connected to. */
50 int ih_need; /* Needs service. */
51 TAILQ_ENTRY(intr_handler) ih_next; /* Next handler for this event. */
52 u_char ih_pri; /* Priority of this handler. */
55 /* Interrupt handle flags kept in ih_flags */
56 #define IH_FAST 0x00000001 /* Fast interrupt. */
57 #define IH_EXCLUSIVE 0x00000002 /* Exclusive interrupt. */
58 #define IH_ENTROPY 0x00000004 /* Device is a good entropy source. */
59 #define IH_DEAD 0x00000008 /* Handler should be removed. */
60 #define IH_MPSAFE 0x80000000 /* Handler does not need Giant. */
63 * Describe an interrupt event. An event holds a list of handlers.
66 TAILQ_ENTRY(intr_event) ie_list;
67 TAILQ_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */
68 char ie_name[MAXCOMLEN]; /* Individual event name. */
69 char ie_fullname[MAXCOMLEN];
71 void *ie_source; /* Cookie used by MD code. */
72 struct intr_thread *ie_thread; /* Thread we are connected to. */
73 void (*ie_enable)(void *);
75 int ie_count; /* Loop counter. */
76 int ie_warned; /* Warned about interrupt storm. */
79 /* Interrupt event flags kept in ie_flags. */
80 #define IE_SOFT 0x000001 /* Software interrupt. */
81 #define IE_ENTROPY 0x000002 /* Interrupt is an entropy source. */
82 #define IE_ADDING_THREAD 0x000004 /* Currently building an ithread. */
84 /* Flags to pass to sched_swi. */
88 * Software interrupt numbers in priority order. The priority determines
89 * the priority of the corresponding interrupt thread.
98 #define SWI_TQ_GIANT 6
100 extern struct intr_event *tty_intr_event;
101 extern struct intr_event *clk_intr_event;
102 extern void *softclock_ih;
105 /* Counts and names for statistics (defined in MD code). */
106 extern u_long eintrcnt[]; /* end of intrcnt[] */
107 extern char eintrnames[]; /* end of intrnames[] */
108 extern u_long intrcnt[]; /* counts for for each device and stray */
109 extern char intrnames[]; /* string table containing device names */
112 void db_dump_intr_event(struct intr_event *ie, int handlers);
114 u_char intr_priority(enum intr_type flags);
115 int intr_event_add_handler(struct intr_event *ie, const char *name,
116 driver_intr_t handler, void *arg, u_char pri, enum intr_type flags,
118 int intr_event_create(struct intr_event **event, void *source,
119 int flags, void (*enable)(void *), const char *fmt, ...)
121 int intr_event_destroy(struct intr_event *ie);
122 int intr_event_remove_handler(void *cookie);
123 int intr_event_schedule_thread(struct intr_event *ie);
124 void *intr_handler_source(void *cookie);
125 int swi_add(struct intr_event **eventp, const char *name,
126 driver_intr_t handler, void *arg, int pri, enum intr_type flags,
128 void swi_sched(void *cookie, int flags);
129 int swi_remove(void *cookie);