intr.h revision 1.7 1 /* $NetBSD: intr.h,v 1.7 2006/12/21 15:55:24 yamt Exp $ */
2
3 /*
4 * Copyright 2001 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Copyright (C) 1995-1997 Wolfgang Solfrank.
40 * Copyright (C) 1995-1997 TooLs GmbH.
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by TooLs GmbH.
54 * 4. The name of TooLs GmbH may not be used to endorse or promote products
55 * derived from this software without specific prior written permission.
56 *
57 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
61 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
62 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
63 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
64 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
65 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
66 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 */
68
69 #ifndef _MACHINE_INTR_H_
70 #define _MACHINE_INTR_H_
71
72 /* Interrupt priority "levels". */
73 #define IPL_NONE 0 /* nothing */
74 #define IPL_SOFT 1 /* generic software interrupts */
75 #define IPL_SOFTCLOCK 2 /* software clock interrupt */
76 #define IPL_SOFTNET 3 /* software network interrupt */
77 #define IPL_BIO 4 /* block I/O */
78 #define IPL_NET 5 /* network */
79 #define IPL_SOFTSERIAL 6 /* software serial interrupt */
80 #define IPL_TTY 7 /* terminals */
81 #define IPL_VM 8 /* memory allocation */
82 #define IPL_AUDIO 9 /* audio device */
83 #define IPL_CLOCK 10 /* clock interrupt */
84 #define IPL_STATCLOCK IPL_CLOCK
85 #define IPL_HIGH 11 /* everything */
86 #define IPL_SCHED IPL_HIGH
87 #define IPL_LOCK IPL_HIGH
88 #define IPL_SERIAL 12 /* serial device */
89
90 #define NIPL 13
91
92 /* Interrupt sharing types. */
93 #define IST_NONE 0 /* none */
94 #define IST_PULSE 1 /* pulsed */
95 #define IST_EDGE 2 /* edge-triggered */
96 #define IST_LEVEL 3 /* level-triggered */
97
98 #ifdef _KERNEL
99 #ifndef _LOCORE
100 #define CLKF_BASEPRI(frame) ((frame)->pri == IPL_NONE)
101
102 struct clockframe;
103
104 extern int imask[];
105 extern long ticks_per_intr;
106 extern volatile u_long lasttb;
107
108 struct machvec {
109 int (*mvec_splraise)(int);
110 int (*mvec_spllower)(int);
111 void (*mvec_splx)(int);
112 void (*mvec_setsoft)(int);
113 void (*mvec_clock_return)(struct clockframe *, int, long);
114 void *(*mvec_intr_establish)(int, int, int, int (*)(void *), void *);
115 void (*mvec_intr_disestablish)(void *);
116 };
117
118 extern struct machvec machine_interface;
119
120 #define _splraise(x) ((*machine_interface.mvec_splraise)(x))
121 #define _spllower(x) ((*machine_interface.mvec_spllower)(x))
122 #define splx(x) ((*machine_interface.mvec_splx)(x))
123 #define setsoftintr(x) ((*machine_interface.mvec_setsoft)(x))
124 #define clock_return(x, y, z) ((*machine_interface.mvec_clock_return)(x, y, z))
125 #define intr_establish(irq, lvl, ist, func, arg) \
126 ((*machine_interface.mvec_intr_establish)((irq), (lvl), (ist), \
127 (func), (arg)))
128 #define intr_disestablish(cookie) \
129 ((*machine_interface.mvec_intr_disestablish)((cookie)))
130
131 #define splsoft() _splraise(imask[IPL_SOFT])
132
133 #define spl0() _spllower(imask[IPL_NONE])
134 #define spllowersoftclock() _spllower(imask[IPL_SOFTCLOCK])
135
136 #define setsoftnet() setsoftintr(IPL_SOFTNET)
137 #define setsoftclock() setsoftintr(IPL_SOFTCLOCK)
138
139 /*
140 * Software interrupt support.
141 */
142
143 #define SI_SOFT 0 /* for IPL_SOFT */
144 #define SI_SOFTCLOCK 1 /* for IPL_SOFTCLOCK */
145 #define SI_SOFTNET 2 /* for IPL_SOFTNET */
146 #define SI_SOFTSERIAL 3 /* for IPL_SOFTSERIAL */
147
148 #define SI_NQUEUES 4
149
150 #define SI_QUEUENAMES { \
151 "generic", \
152 "clock", \
153 "net", \
154 "serial", \
155 }
156
157 typedef int ipl_t;
158 typedef struct {
159 ipl_t _ipl;
160 } ipl_cookie_t;
161
162 static inline ipl_cookie_t
163 makeiplcookie(ipl_t ipl)
164 {
165
166 return (ipl_cookie_t){._ipl = ipl};
167 }
168
169 static inline int
170 splraiseipl(ipl_cookie_t icookie)
171 {
172
173 return _splraise(imask[icookie._ipl]);
174 }
175
176 #include <sys/spl.h>
177
178 #endif /* _LOCORE */
179
180 #endif /* _KERNEL */
181
182 #endif /* _MACHINE_INTR_H_ */
183