1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/* $OpenBSD: intr.h,v 1.12 2001/12/14 08:35:12 niklas Exp $ */
/* $NetBSD: intr.h,v 1.5 1996/05/13 06:11:28 mycroft Exp $ */
/*
* Copyright (c) 1996 Charles M. Hannum. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Charles M. Hannum.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _I386_INTR_H_
#define _I386_INTR_H_
/*
* Intel APICs (advanced programmable interrupt controllers) have
* bytesized priority registers where the upper nibble is the actual
* interrupt priority level (a.k.a. IPL). Interrupt vectors are
* closely tied to these levels as interrupts whose vectors' upper
* nibble is lower than or equal to the current level are blocked.
* Not all 256 possible vectors are available for interrupts in
* APIC systems, only
*
* For systems where instead the older ICU (interrupt controlling
* unit, a.k.a. PIC or 82C59) is used, the IPL is not directly useful,
* since the interrupt blocking is handled via interrupt masks instead
* of levels. However the IPL is easily used as an offset into arrays
* of masks.
*/
#define IPLSHIFT 4 /* The upper nibble of vectors is the IPL. */
#define NIPL 16 /* Four bits of information gives as much. */
#define IPL(level) ((level) >> IPLSHIFT) /* Extract the IPL. */
/* XXX Maybe this IDTVECOFF definition should be elsewhere? */
#define IDTVECOFF 0x20 /* The lower 32 IDT vectors are reserved. */
/*
* This macro is only defined for 0 <= x < 14, i.e. there are fourteen
* distinct priority levels available for interrupts.
*/
#define MAKEIPL(priority) (IDTVECOFF + ((priority) << IPLSHIFT))
/*
* Interrupt priority levels.
* XXX We are somewhat sloppy about what we mean by IPLs, sometimes
* XXX we refer to the eight-bit value suitable for storing into APICs'
* XXX priority registers, other times about the four-bit entity found
* XXX in the former values' upper nibble, which can be used as offsets
* XXX in various arrays of our implementation. We are hoping that
* XXX the context will provide enough information to not make this
* XXX sloppy naming a real problem.
*/
#define IPL_NONE 0 /* nothing */
#define IPL_SOFTCLOCK MAKEIPL(0) /* timeouts */
#define IPL_SOFTNET MAKEIPL(1) /* protocol stacks */
#define IPL_BIO MAKEIPL(2) /* block I/O */
#define IPL_NET MAKEIPL(3) /* network */
#define IPL_SOFTTTY MAKEIPL(4) /* delayed terminal handling */
#define IPL_TTY MAKEIPL(5) /* terminal */
#define IPL_IMP MAKEIPL(6) /* memory allocation */
#define IPL_AUDIO MAKEIPL(7) /* audio */
#define IPL_CLOCK MAKEIPL(8) /* clock */
#define IPL_HIGH MAKEIPL(9) /* everything */
/* Interrupt sharing types. */
#define IST_NONE 0 /* none */
#define IST_PULSE 1 /* pulsed */
#define IST_EDGE 2 /* edge-triggered */
#define IST_LEVEL 3 /* level-triggered */
/* Soft interrupt masks. */
#define SIR_CLOCK 31
#define SIR_NET 30
#define SIR_TTY 29
#ifndef _LOCORE
volatile int cpl; /* Current interrupt priority level. */
volatile int ipending; /* Interrupts pending. */
volatile int astpending;/* Asynchronous software traps (softints) pending. */
int imask[NIPL]; /* Bitmasks telling what interrupts are blocked. */
int iunmask[NIPL]; /* Bitmasks telling what interrupts are accepted. */
#define IMASK(level) imask[IPL(level)]
#define IUNMASK(level) iunmask[IPL(level)]
extern void Xspllower __P((void));
static __inline int splraise __P((int));
static __inline int spllower __P((int));
#define SPLX_DECL void splx __P((int));
static __inline void softintr __P((int));
/*
* Raise current interrupt priority level, and return the old one.
*/
static __inline int
splraise(ncpl)
int ncpl;
{
int ocpl = cpl;
if (ncpl > ocpl)
cpl = ncpl;
__asm __volatile("");
return (ocpl);
}
/*
* Restore an old interrupt priority level. If any thereby unmasked
* interrupts are pending, call Xspllower() to process them.
*/
#define SPLX_BODY \
void \
splx(ncpl) \
int ncpl; \
{ \
__asm __volatile(""); \
cpl = ncpl; \
if (ipending & IUNMASK(ncpl)) \
Xspllower(); \
}
/* If SMALL_KERNEL make splx out of line, otherwise inline it. */
#ifdef SMALL_KERNEL
#define SPLX_INLINED_BODY
#define SPLX_OUTLINED_BODY SPLX_BODY
SPLX_DECL
#else
#define SPLX_INLINED_BODY static __inline SPLX_BODY
#define SPLX_OUTLINED_BODY
static __inline SPLX_DECL
#endif
SPLX_INLINED_BODY
/*
* Same as splx(), but we return the old value of spl, for the
* benefit of some splsoftclock() callers.
*/
static __inline int
spllower(ncpl)
int ncpl;
{
int ocpl = cpl;
splx(ncpl);
return (ocpl);
}
/*
* Hardware interrupt masks
*/
#define splbio() splraise(IPL_BIO)
#define splnet() splraise(IPL_NET)
#define spltty() splraise(IPL_TTY)
#define splaudio() splraise(IPL_AUDIO)
#define splclock() splraise(IPL_CLOCK)
#define splstatclock() splhigh()
/*
* Software interrupt masks
*
* NOTE: spllowersoftclock() is used by hardclock() to lower the priority from
* clock to softclock before it calls softclock().
*/
#define spllowersoftclock() spllower(IPL_SOFTCLOCK)
#define splsoftclock() splraise(IPL_SOFTCLOCK)
#define splsoftnet() splraise(IPL_SOFTNET)
#define splsofttty() splraise(IPL_SOFTTTY)
/*
* Miscellaneous
*/
#define splimp() splraise(IPL_IMP)
#define splvm() splraise(IPL_IMP)
#define splhigh() splraise(IPL_HIGH)
#define spl0() spllower(IPL_NONE)
/*
* Software interrupt registration
*
* We hand-code this to ensure that it's atomic.
*/
static __inline void
softintr(mask)
int mask;
{
__asm __volatile("orl %0,_ipending" : : "ir" (mask));
}
#define setsoftast() (astpending = 1)
#define setsoftclock() softintr(1 << SIR_CLOCK)
#define setsoftnet() softintr(1 << SIR_NET)
#define setsofttty() softintr(1 << SIR_TTY)
#endif /* !_LOCORE */
#endif /* !_I386_INTR_H_ */
|