intr.h revision 1.12.10.1 1 1.12.10.1 sommerfe /* $NetBSD: intr.h,v 1.12.10.1 2000/02/20 17:41:33 sommerfeld 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.12.10.1 sommerfe /*
43 1.12.10.1 sommerfe * Interrupt priority levels.
44 1.12.10.1 sommerfe *
45 1.12.10.1 sommerfe * There are tty, network and disk drivers that use free() at interrupt
46 1.12.10.1 sommerfe * time, so imp > (tty | net | bio).
47 1.12.10.1 sommerfe *
48 1.12.10.1 sommerfe * Since run queues may be manipulated by both the statclock and tty,
49 1.12.10.1 sommerfe * network, and disk drivers, clock > imp.
50 1.12.10.1 sommerfe *
51 1.12.10.1 sommerfe * IPL_HIGH must block everything that can manipulate a run queue.
52 1.12.10.1 sommerfe *
53 1.12.10.1 sommerfe * We need serial drivers to run at the absolute highest priority to
54 1.12.10.1 sommerfe * avoid overruns, so serial > high.
55 1.12.10.1 sommerfe */
56 1.12.10.1 sommerfe #define IPL_NONE 0x00 /* nothing */
57 1.12.10.1 sommerfe #define IPL_SOFTCLOCK 0x50 /* timeouts */
58 1.12.10.1 sommerfe #define IPL_SOFTNET 0x60 /* protocol stacks */
59 1.12.10.1 sommerfe #define IPL_BIO 0x70 /* block I/O */
60 1.12.10.1 sommerfe #define IPL_NET 0x80 /* network */
61 1.12.10.1 sommerfe #define IPL_SOFTSERIAL 0x90 /* serial */
62 1.12.10.1 sommerfe #define IPL_TTY 0xa0 /* terminal */
63 1.12.10.1 sommerfe #define IPL_IMP 0xb0 /* memory allocation */
64 1.12.10.1 sommerfe #define IPL_AUDIO 0xc0 /* audio */
65 1.12.10.1 sommerfe #define IPL_CLOCK 0xd0 /* clock */
66 1.12.10.1 sommerfe #define IPL_HIGH 0xd0 /* everything */
67 1.12.10.1 sommerfe #define IPL_SERIAL 0xe0 /* serial */
68 1.12.10.1 sommerfe #define NIPL 16
69 1.1 mycroft
70 1.1 mycroft /* Interrupt sharing types. */
71 1.1 mycroft #define IST_NONE 0 /* none */
72 1.1 mycroft #define IST_PULSE 1 /* pulsed */
73 1.1 mycroft #define IST_EDGE 2 /* edge-triggered */
74 1.1 mycroft #define IST_LEVEL 3 /* level-triggered */
75 1.3 mycroft
76 1.3 mycroft /* Soft interrupt masks. */
77 1.3 mycroft #define SIR_CLOCK 31
78 1.3 mycroft #define SIR_NET 30
79 1.6 mycroft #define SIR_SERIAL 29
80 1.3 mycroft
81 1.3 mycroft #ifndef _LOCORE
82 1.3 mycroft
83 1.12.10.1 sommerfe #ifdef MULTIPROCESSOR
84 1.12.10.1 sommerfe #include <machine/i82489reg.h>
85 1.12.10.1 sommerfe #include <machine/i82489var.h>
86 1.12.10.1 sommerfe #endif
87 1.12.10.1 sommerfe
88 1.12.10.1 sommerfe extern volatile u_int32_t lapic_tpr;
89 1.12.10.1 sommerfe volatile u_int32_t ipending;
90 1.12.10.1 sommerfe
91 1.12.10.1 sommerfe #ifndef MULTIPROCESSOR
92 1.12.10.1 sommerfe volatile u_int32_t astpending;
93 1.12.10.1 sommerfe #endif
94 1.12.10.1 sommerfe
95 1.12.10.1 sommerfe int imasks[NIPL];
96 1.12.10.1 sommerfe int iunmask[NIPL];
97 1.12.10.1 sommerfe
98 1.12.10.1 sommerfe #define CPSHIFT 4
99 1.12.10.1 sommerfe #define IMASK(level) imasks[(level)>>CPSHIFT]
100 1.12.10.1 sommerfe #define IUNMASK(level) iunmask[(level)>>CPSHIFT]
101 1.3 mycroft
102 1.3 mycroft extern void Xspllower __P((void));
103 1.3 mycroft
104 1.3 mycroft static __inline int splraise __P((int));
105 1.3 mycroft static __inline int spllower __P((int));
106 1.3 mycroft static __inline void splx __P((int));
107 1.12.10.1 sommerfe static __inline void softintr __P((int, int));
108 1.3 mycroft
109 1.3 mycroft /*
110 1.3 mycroft * Add a mask to cpl, and return the old value of cpl.
111 1.3 mycroft */
112 1.3 mycroft static __inline int
113 1.3 mycroft splraise(ncpl)
114 1.3 mycroft register int ncpl;
115 1.3 mycroft {
116 1.12.10.1 sommerfe register int ocpl = lapic_tpr;
117 1.3 mycroft
118 1.12.10.1 sommerfe if (ncpl > ocpl)
119 1.12.10.1 sommerfe lapic_tpr = ncpl;
120 1.3 mycroft return (ocpl);
121 1.3 mycroft }
122 1.3 mycroft
123 1.3 mycroft /*
124 1.3 mycroft * Restore a value to cpl (unmasking interrupts). If any unmasked
125 1.3 mycroft * interrupts are pending, call Xspllower() to process them.
126 1.3 mycroft */
127 1.3 mycroft static __inline void
128 1.3 mycroft splx(ncpl)
129 1.3 mycroft register int ncpl;
130 1.3 mycroft {
131 1.12.10.1 sommerfe register int cmask;
132 1.3 mycroft
133 1.12.10.1 sommerfe lapic_tpr = ncpl;
134 1.12.10.1 sommerfe cmask = IUNMASK(ncpl);
135 1.12.10.1 sommerfe if (ipending & cmask)
136 1.3 mycroft Xspllower();
137 1.3 mycroft }
138 1.3 mycroft
139 1.3 mycroft /*
140 1.3 mycroft * Same as splx(), but we return the old value of spl, for the
141 1.3 mycroft * benefit of some splsoftclock() callers.
142 1.3 mycroft */
143 1.3 mycroft static __inline int
144 1.3 mycroft spllower(ncpl)
145 1.3 mycroft register int ncpl;
146 1.3 mycroft {
147 1.12.10.1 sommerfe register int ocpl = lapic_tpr;
148 1.12.10.1 sommerfe register int cmask;
149 1.12.10.1 sommerfe
150 1.12.10.1 sommerfe lapic_tpr = ncpl;
151 1.12.10.1 sommerfe cmask = IUNMASK(ncpl);
152 1.12.10.1 sommerfe if (ipending & cmask)
153 1.3 mycroft Xspllower();
154 1.3 mycroft return (ocpl);
155 1.3 mycroft }
156 1.3 mycroft
157 1.3 mycroft /*
158 1.3 mycroft * Hardware interrupt masks
159 1.3 mycroft */
160 1.12.10.1 sommerfe #define splbio() splraise(IPL_BIO)
161 1.12.10.1 sommerfe #define splnet() splraise(IPL_NET)
162 1.12.10.1 sommerfe #define spltty() splraise(IPL_TTY)
163 1.12.10.1 sommerfe #define splaudio() splraise(IPL_AUDIO)
164 1.12.10.1 sommerfe #define splclock() splraise(IPL_CLOCK)
165 1.7 mycroft #define splstatclock() splclock()
166 1.12.10.1 sommerfe #define splserial() splraise(IPL_SERIAL)
167 1.8 is
168 1.8 is #define spllpt() spltty()
169 1.3 mycroft
170 1.3 mycroft /*
171 1.3 mycroft * Software interrupt masks
172 1.3 mycroft *
173 1.3 mycroft * NOTE: splsoftclock() is used by hardclock() to lower the priority from
174 1.3 mycroft * clock to softclock before it calls softclock().
175 1.3 mycroft */
176 1.12.10.1 sommerfe #define spllowersoftclock() spllower(IPL_SOFTCLOCK)
177 1.12.10.1 sommerfe
178 1.12.10.1 sommerfe #define splsoftclock() splraise(IPL_SOFTCLOCK)
179 1.12.10.1 sommerfe #define splsoftnet() splraise(IPL_SOFTNET)
180 1.12.10.1 sommerfe #define splsoftserial() splraise(IPL_SOFTSERIAL)
181 1.3 mycroft
182 1.3 mycroft /*
183 1.3 mycroft * Miscellaneous
184 1.3 mycroft */
185 1.12.10.1 sommerfe #define splimp() splraise(IPL_IMP)
186 1.12.10.1 sommerfe #define splhigh() splraise(IPL_HIGH)
187 1.12.10.1 sommerfe #define spl0() spllower(IPL_NONE)
188 1.3 mycroft
189 1.3 mycroft /*
190 1.3 mycroft * Software interrupt registration
191 1.3 mycroft *
192 1.3 mycroft * We hand-code this to ensure that it's atomic.
193 1.3 mycroft */
194 1.3 mycroft static __inline void
195 1.12.10.1 sommerfe softintr(sir, vec)
196 1.12.10.1 sommerfe register int sir;
197 1.12.10.1 sommerfe register int vec;
198 1.3 mycroft {
199 1.12.10.1 sommerfe __asm __volatile("orl %1, %0" : "=m"(ipending) : "ir" (1 << sir));
200 1.12.10.1 sommerfe #ifdef MULTIPROCESSOR
201 1.12.10.1 sommerfe i82489_writereg(LAPIC_ICRLO,
202 1.12.10.1 sommerfe vec | LAPIC_DLMODE_FIXED | LAPIC_LVL_ASSERT | LAPIC_DEST_SELF);
203 1.12.10.1 sommerfe #endif
204 1.3 mycroft }
205 1.3 mycroft
206 1.3 mycroft #define setsoftast() (astpending = 1)
207 1.12.10.1 sommerfe #define setsoftclock() softintr(SIR_CLOCK,IPL_SOFTCLOCK)
208 1.12.10.1 sommerfe #define setsoftnet() softintr(SIR_NET,IPL_SOFTNET)
209 1.12.10.1 sommerfe #define setsoftserial() softintr(SIR_SERIAL,IPL_SOFTSERIAL)
210 1.12.10.1 sommerfe
211 1.12.10.1 sommerfe
212 1.12.10.1 sommerfe #define I386_IPI_HALT 0x00000001
213 1.12.10.1 sommerfe #define I386_IPI_TLB 0x00000002
214 1.12.10.1 sommerfe
215 1.12.10.1 sommerfe /* the following are for debugging.. */
216 1.12.10.1 sommerfe #define I386_IPI_GMTB 0x00000010
217 1.12.10.1 sommerfe #define I386_IPI_NYCHI 0x00000020
218 1.12.10.1 sommerfe
219 1.12.10.1 sommerfe #define I386_NIPI 6
220 1.12.10.1 sommerfe
221 1.12.10.1 sommerfe void i386_send_ipi (int, int);
222 1.12.10.1 sommerfe void i386_broadcast_ipi (int);
223 1.12.10.1 sommerfe void i386_ipi_handler (void);
224 1.3 mycroft
225 1.3 mycroft #endif /* !_LOCORE */
226 1.4 mycroft
227 1.4 mycroft #endif /* !_I386_INTR_H_ */
228