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>
40 * Describe a hardware interrupt handler.
42 * Multiple interrupt handlers for a specific event can be chained
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. */
50 const char *ih_name; /* 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. */
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. */
65 * Describe an interrupt event. An event holds a list of handlers.
68 TAILQ_ENTRY(intr_event) ie_list;
69 TAILQ_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */
70 char ie_name[MAXCOMLEN]; /* Individual event name. */
71 char ie_fullname[MAXCOMLEN];
73 void *ie_source; /* Cookie used by MD code. */
74 struct intr_thread *ie_thread; /* Thread we are connected to. */
75 void (*ie_enable)(void *);
76 int (*ie_assign_cpu)(void *, u_char);
78 void (*ie_eoi)(void *);
79 void (*ie_disab)(void *);
82 int ie_count; /* Loop counter. */
83 int ie_warncnt; /* Rate-check interrupt storm warns. */
84 struct timeval ie_warntm;
85 u_char ie_cpu; /* CPU this event is bound to. */
88 /* Interrupt event flags kept in ie_flags. */
89 #define IE_SOFT 0x000001 /* Software interrupt. */
90 #define IE_ENTROPY 0x000002 /* Interrupt is an entropy source. */
91 #define IE_ADDING_THREAD 0x000004 /* Currently building an ithread. */
93 /* Flags to pass to sched_swi. */
97 * Software interrupt numbers in priority order. The priority determines
98 * the priority of the corresponding interrupt thread.
105 #define SWI_TQ_FAST 5
107 #define SWI_TQ_GIANT 6
109 extern struct intr_event *tty_intr_event;
110 extern struct intr_event *clk_intr_event;
111 extern void *softclock_ih;
114 /* Counts and names for statistics (defined in MD code). */
115 extern u_long eintrcnt[]; /* end of intrcnt[] */
116 extern char eintrnames[]; /* end of intrnames[] */
117 extern u_long intrcnt[]; /* counts for for each device and stray */
118 extern char intrnames[]; /* string table containing device names */
121 void db_dump_intr_event(struct intr_event *ie, int handlers);
124 int intr_filter_loop(struct intr_event *ie, struct trapframe *frame,
125 struct intr_thread **ithd);
126 int intr_event_handle(struct intr_event *ie, struct trapframe *frame);
128 u_char intr_priority(enum intr_type flags);
129 int intr_event_add_handler(struct intr_event *ie, const char *name,
130 driver_filter_t filter, driver_intr_t handler, void *arg,
131 u_char pri, enum intr_type flags, void **cookiep);
132 int intr_event_bind(struct intr_event *ie, u_char cpu);
134 int intr_event_create(struct intr_event **event, void *source,
135 int flags, void (*enable)(void *),
136 int (*assign_cpu)(void *, u_char), const char *fmt, ...)
139 int intr_event_create(struct intr_event **event, void *source,
140 int flags, void (*enable)(void *), void (*eoi)(void *),
141 void (*disab)(void *), int (*assign_cpu)(void *, u_char),
142 const char *fmt, ...)
145 int intr_event_destroy(struct intr_event *ie);
146 int intr_event_remove_handler(void *cookie);
148 int intr_event_schedule_thread(struct intr_event *ie);
150 int intr_event_schedule_thread(struct intr_event *ie,
151 struct intr_thread *ithd);
153 void *intr_handler_source(void *cookie);
154 int swi_add(struct intr_event **eventp, const char *name,
155 driver_intr_t handler, void *arg, int pri, enum intr_type flags,
157 void swi_sched(void *cookie, int flags);
158 int swi_remove(void *cookie);