intr.h revision 1.12 1 1.12 thorpej /* $NetBSD: intr.h,v 1.12 1999/08/05 18:08:10 thorpej Exp $ */
2 1.1 mycroft
3 1.9 mycroft /*-
4 1.9 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.9 mycroft * All rights reserved.
6 1.9 mycroft *
7 1.9 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.9 mycroft * by Charles M. Hannum.
9 1.1 mycroft *
10 1.1 mycroft * Redistribution and use in source and binary forms, with or without
11 1.1 mycroft * modification, are permitted provided that the following conditions
12 1.1 mycroft * are met:
13 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer.
15 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
17 1.1 mycroft * documentation and/or other materials provided with the distribution.
18 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
19 1.1 mycroft * must display the following acknowledgement:
20 1.9 mycroft * This product includes software developed by the NetBSD
21 1.9 mycroft * Foundation, Inc. and its contributors.
22 1.9 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.9 mycroft * contributors may be used to endorse or promote products derived
24 1.9 mycroft * from this software without specific prior written permission.
25 1.1 mycroft *
26 1.9 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.9 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.9 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.9 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.9 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.9 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.9 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.9 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.9 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.9 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.9 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 mycroft */
38 1.1 mycroft
39 1.4 mycroft #ifndef _I386_INTR_H_
40 1.4 mycroft #define _I386_INTR_H_
41 1.4 mycroft
42 1.6 mycroft /* Interrupt priority `levels'. */
43 1.7 mycroft #define IPL_NONE 9 /* nothing */
44 1.7 mycroft #define IPL_SOFTCLOCK 8 /* timeouts */
45 1.7 mycroft #define IPL_SOFTNET 7 /* protocol stacks */
46 1.7 mycroft #define IPL_BIO 6 /* block I/O */
47 1.7 mycroft #define IPL_NET 5 /* network */
48 1.7 mycroft #define IPL_SOFTSERIAL 4 /* serial */
49 1.7 mycroft #define IPL_TTY 3 /* terminal */
50 1.7 mycroft #define IPL_IMP 3 /* memory allocation */
51 1.7 mycroft #define IPL_AUDIO 2 /* audio */
52 1.6 mycroft #define IPL_CLOCK 1 /* clock */
53 1.6 mycroft #define IPL_HIGH 1 /* everything */
54 1.6 mycroft #define IPL_SERIAL 0 /* serial */
55 1.7 mycroft #define NIPL 10
56 1.1 mycroft
57 1.1 mycroft /* Interrupt sharing types. */
58 1.1 mycroft #define IST_NONE 0 /* none */
59 1.1 mycroft #define IST_PULSE 1 /* pulsed */
60 1.1 mycroft #define IST_EDGE 2 /* edge-triggered */
61 1.1 mycroft #define IST_LEVEL 3 /* level-triggered */
62 1.3 mycroft
63 1.3 mycroft /* Soft interrupt masks. */
64 1.3 mycroft #define SIR_CLOCK 31
65 1.3 mycroft #define SIR_NET 30
66 1.6 mycroft #define SIR_SERIAL 29
67 1.3 mycroft
68 1.3 mycroft #ifndef _LOCORE
69 1.3 mycroft
70 1.3 mycroft volatile int cpl, ipending, astpending;
71 1.6 mycroft int imask[NIPL];
72 1.3 mycroft
73 1.3 mycroft extern void Xspllower __P((void));
74 1.3 mycroft
75 1.3 mycroft static __inline int splraise __P((int));
76 1.3 mycroft static __inline int spllower __P((int));
77 1.3 mycroft static __inline void splx __P((int));
78 1.3 mycroft static __inline void softintr __P((int));
79 1.3 mycroft
80 1.3 mycroft /*
81 1.3 mycroft * Add a mask to cpl, and return the old value of cpl.
82 1.3 mycroft */
83 1.3 mycroft static __inline int
84 1.3 mycroft splraise(ncpl)
85 1.3 mycroft register int ncpl;
86 1.3 mycroft {
87 1.3 mycroft register int ocpl = cpl;
88 1.3 mycroft
89 1.3 mycroft cpl = ocpl | ncpl;
90 1.3 mycroft return (ocpl);
91 1.3 mycroft }
92 1.3 mycroft
93 1.3 mycroft /*
94 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
95 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
96 1.3 mycroft */
97 1.3 mycroft static __inline void
98 1.3 mycroft splx(ncpl)
99 1.3 mycroft register int ncpl;
100 1.3 mycroft {
101 1.3 mycroft
102 1.3 mycroft cpl = ncpl;
103 1.3 mycroft if (ipending & ~ncpl)
104 1.3 mycroft Xspllower();
105 1.3 mycroft }
106 1.3 mycroft
107 1.3 mycroft /*
108 1.3 mycroft * Same as splx(), but we return the old value of spl, for the
109 1.3 mycroft * benefit of some splsoftclock() callers.
110 1.3 mycroft */
111 1.3 mycroft static __inline int
112 1.3 mycroft spllower(ncpl)
113 1.3 mycroft register int ncpl;
114 1.3 mycroft {
115 1.3 mycroft register int ocpl = cpl;
116 1.3 mycroft
117 1.3 mycroft cpl = ncpl;
118 1.3 mycroft if (ipending & ~ncpl)
119 1.3 mycroft Xspllower();
120 1.3 mycroft return (ocpl);
121 1.3 mycroft }
122 1.3 mycroft
123 1.3 mycroft /*
124 1.3 mycroft * Hardware interrupt masks
125 1.3 mycroft */
126 1.3 mycroft #define splbio() splraise(imask[IPL_BIO])
127 1.3 mycroft #define splnet() splraise(imask[IPL_NET])
128 1.3 mycroft #define spltty() splraise(imask[IPL_TTY])
129 1.7 mycroft #define splaudio() splraise(imask[IPL_AUDIO])
130 1.3 mycroft #define splclock() splraise(imask[IPL_CLOCK])
131 1.7 mycroft #define splstatclock() splclock()
132 1.6 mycroft #define splserial() splraise(imask[IPL_SERIAL])
133 1.8 is
134 1.8 is #define spllpt() spltty()
135 1.3 mycroft
136 1.3 mycroft /*
137 1.3 mycroft * Software interrupt masks
138 1.3 mycroft *
139 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
140 1.3 mycroft * clock to softclock before it calls softclock().
141 1.3 mycroft */
142 1.12 thorpej #define spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
143 1.12 thorpej #define splsoftclock() splraise(imask[IPL_SOFTCLOCK])
144 1.6 mycroft #define splsoftnet() splraise(imask[IPL_SOFTNET])
145 1.6 mycroft #define splsoftserial() splraise(imask[IPL_SOFTSERIAL])
146 1.3 mycroft
147 1.3 mycroft /*
148 1.3 mycroft * Miscellaneous
149 1.3 mycroft */
150 1.7 mycroft #define splimp() splraise(imask[IPL_IMP])
151 1.6 mycroft #define splhigh() splraise(imask[IPL_HIGH])
152 1.3 mycroft #define spl0() spllower(0)
153 1.3 mycroft
154 1.3 mycroft /*
155 1.3 mycroft * Software interrupt registration
156 1.3 mycroft *
157 1.3 mycroft * We hand-code this to ensure that it's atomic.
158 1.3 mycroft */
159 1.3 mycroft static __inline void
160 1.3 mycroft softintr(mask)
161 1.3 mycroft register int mask;
162 1.3 mycroft {
163 1.11 christos __asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << mask));
164 1.3 mycroft }
165 1.3 mycroft
166 1.3 mycroft #define setsoftast() (astpending = 1)
167 1.6 mycroft #define setsoftclock() softintr(SIR_CLOCK)
168 1.6 mycroft #define setsoftnet() softintr(SIR_NET)
169 1.6 mycroft #define setsoftserial() softintr(SIR_SERIAL)
170 1.3 mycroft
171 1.3 mycroft #endif /* !_LOCORE */
172 1.4 mycroft
173 1.4 mycroft #endif /* !_I386_INTR_H_ */
174