intr.h revision 1.47 1 /* $NetBSD: intr.h,v 1.47 2001/04/28 06:10:50 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved.
41 * Copyright (c) 1996 Carnegie-Mellon University.
42 * All rights reserved.
43 *
44 * Author: Chris G. Demetriou
45 *
46 * Permission to use, copy, modify and distribute this software and
47 * its documentation is hereby granted, provided that both the copyright
48 * notice and this permission notice appear in all copies of the
49 * software, derivative works or modified versions, and any portions
50 * thereof, and that both notices appear in supporting documentation.
51 *
52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
54 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55 *
56 * Carnegie Mellon requests users of this software to return to
57 *
58 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
59 * School of Computer Science
60 * Carnegie Mellon University
61 * Pittsburgh PA 15213-3890
62 *
63 * any improvements or extensions that they make and grant Carnegie the
64 * rights to redistribute these changes.
65 */
66
67 #ifndef _ALPHA_INTR_H_
68 #define _ALPHA_INTR_H_
69
70 #include <sys/device.h>
71 #include <sys/lock.h>
72 #include <sys/queue.h>
73 #include <machine/atomic.h>
74
75 /*
76 * Alpha interrupts come in at one of 4 levels:
77 *
78 * software interrupt level
79 * i/o level 1
80 * i/o level 2
81 * clock level
82 *
83 * However, since we do not have any way to know which hardware
84 * level a particular i/o interrupt comes in on, we have to
85 * whittle it down to 3.
86 */
87
88 #define IPL_NONE 1 /* disable only this interrupt */
89 #define IPL_BIO 1 /* disable block I/O interrupts */
90 #define IPL_NET 1 /* disable network interrupts */
91 #define IPL_TTY 1 /* disable terminal interrupts */
92 #define IPL_CLOCK 2 /* disable clock interrupts */
93 #define IPL_HIGH 3 /* disable all interrupts */
94 #define IPL_SERIAL 1 /* disable serial interrupts */
95
96 #define IPL_SOFTSERIAL 0 /* serial software interrupts */
97 #define IPL_SOFTNET 1 /* network software interrupts */
98 #define IPL_SOFTCLOCK 2 /* clock software interrupts */
99 #define IPL_SOFT 3 /* other software interrupts */
100 #define IPL_NSOFT 4
101
102 #define IPL_SOFTNAMES { \
103 "serial", \
104 "net", \
105 "clock", \
106 "misc", \
107 }
108
109 #define IST_UNUSABLE -1 /* interrupt cannot be used */
110 #define IST_NONE 0 /* none (dummy) */
111 #define IST_PULSE 1 /* pulsed */
112 #define IST_EDGE 2 /* edge-triggered */
113 #define IST_LEVEL 3 /* level-triggered */
114
115 #ifdef _KERNEL
116
117 /* Simulated software interrupt register. */
118 extern __volatile unsigned long ssir;
119
120 /* IPL-lowering/restoring macros */
121 void spl0(void);
122
123 static __inline void
124 splx(int s)
125 {
126 if (s == ALPHA_PSL_IPL_0 && ssir != 0)
127 spl0();
128 else
129 alpha_pal_swpipl(s);
130 }
131 #define spllowersoftclock() ((void)alpha_pal_swpipl(ALPHA_PSL_IPL_SOFT))
132
133 /* IPL-raising functions/macros */
134 static __inline int
135 _splraise(int s)
136 {
137 int cur = alpha_pal_rdps() & ALPHA_PSL_IPL_MASK;
138 return (s > cur ? alpha_pal_swpipl(s) : cur);
139 }
140 #define splsoft() _splraise(ALPHA_PSL_IPL_SOFT)
141 #define splsoftserial() splsoft()
142 #define splsoftclock() splsoft()
143 #define splsoftnet() splsoft()
144 #define splnet() _splraise(ALPHA_PSL_IPL_IO)
145 #define splbio() _splraise(ALPHA_PSL_IPL_IO)
146 #define splvm() _splraise(ALPHA_PSL_IPL_IO)
147 #define spltty() _splraise(ALPHA_PSL_IPL_IO)
148 #define splserial() _splraise(ALPHA_PSL_IPL_IO)
149 #define splclock() _splraise(ALPHA_PSL_IPL_CLOCK)
150 #define splstatclock() _splraise(ALPHA_PSL_IPL_CLOCK)
151 #define splhigh() _splraise(ALPHA_PSL_IPL_HIGH)
152
153 #define splsched() splhigh()
154 #define spllock() splhigh()
155 #define splipi() splclock() /* AARM, 5-2, II-B */
156 #define spllpt() spltty()
157
158 /*
159 * Interprocessor interrupts. In order how we want them processed.
160 */
161 #define ALPHA_IPI_HALT (1UL << 0)
162 #define ALPHA_IPI_MICROSET (1UL << 1)
163 #define ALPHA_IPI_TBIA (1UL << 2)
164 #define ALPHA_IPI_TBIAP (1UL << 3)
165 #define ALPHA_IPI_SHOOTDOWN (1UL << 4)
166 #define ALPHA_IPI_IMB (1UL << 5)
167 #define ALPHA_IPI_AST (1UL << 6)
168 #define ALPHA_IPI_SYNCH_FPU (1UL << 7)
169 #define ALPHA_IPI_DISCARD_FPU (1UL << 8)
170 #define ALPHA_IPI_PAUSE (1UL << 9)
171 #define ALPHA_IPI_PMAP_REACTIVATE (1UL << 10)
172
173 #define ALPHA_NIPIS 11 /* must not exceed 64 */
174
175 struct cpu_info;
176 struct trapframe;
177
178 void alpha_ipi_init(struct cpu_info *);
179 void alpha_ipi_process(struct cpu_info *, struct trapframe *);
180 void alpha_send_ipi(unsigned long, unsigned long);
181 void alpha_broadcast_ipi(unsigned long);
182 void alpha_multicast_ipi(unsigned long, unsigned long);
183
184 /*
185 * Alpha shared-interrupt-line common code.
186 */
187
188 struct alpha_shared_intrhand {
189 TAILQ_ENTRY(alpha_shared_intrhand)
190 ih_q;
191 struct alpha_shared_intr *ih_intrhead;
192 int (*ih_fn)(void *);
193 void *ih_arg;
194 int ih_level;
195 unsigned int ih_num;
196 };
197
198 struct alpha_shared_intr {
199 TAILQ_HEAD(,alpha_shared_intrhand)
200 intr_q;
201 struct evcnt intr_evcnt;
202 char *intr_string;
203 void *intr_private;
204 int intr_sharetype;
205 int intr_dfltsharetype;
206 int intr_nstrays;
207 int intr_maxstrays;
208 };
209
210 #define ALPHA_SHARED_INTR_DISABLE(asi, num) \
211 ((asi)[num].intr_maxstrays != 0 && \
212 (asi)[num].intr_nstrays == (asi)[num].intr_maxstrays)
213
214 #define setsoft(x) atomic_setbits_ulong(&ssir, 1 << (x))
215
216 struct alpha_soft_intrhand {
217 TAILQ_ENTRY(alpha_soft_intrhand)
218 sih_q;
219 struct alpha_soft_intr *sih_intrhead;
220 void (*sih_fn)(void *);
221 void *sih_arg;
222 int sih_pending;
223 };
224
225 struct alpha_soft_intr {
226 TAILQ_HEAD(, alpha_soft_intrhand)
227 softintr_q;
228 struct evcnt softintr_evcnt;
229 struct simplelock softintr_slock;
230 unsigned long softintr_ipl;
231 };
232
233 void *softintr_establish(int, void (*)(void *), void *);
234 void softintr_disestablish(void *);
235 void softintr_init(void);
236 void softintr_dispatch(void);
237
238 #define softintr_schedule(arg) \
239 do { \
240 struct alpha_soft_intrhand *__sih = (arg); \
241 struct alpha_soft_intr *__si = __sih->sih_intrhead; \
242 int __s; \
243 \
244 __s = splhigh(); \
245 simple_lock(&__si->softintr_slock); \
246 if (__sih->sih_pending == 0) { \
247 TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \
248 __sih->sih_pending = 1; \
249 setsoft(__si->softintr_ipl); \
250 } \
251 simple_unlock(&__si->softintr_slock); \
252 splx(__s); \
253 } while (0)
254
255 /* XXX For legacy software interrupts. */
256 extern struct alpha_soft_intrhand *softnet_intrhand;
257
258 #define setsoftnet() softintr_schedule(softnet_intrhand)
259
260 struct alpha_shared_intr *alpha_shared_intr_alloc(unsigned int, unsigned int);
261 int alpha_shared_intr_dispatch(struct alpha_shared_intr *,
262 unsigned int);
263 void *alpha_shared_intr_establish(struct alpha_shared_intr *,
264 unsigned int, int, int, int (*)(void *), void *, const char *);
265 void alpha_shared_intr_disestablish(struct alpha_shared_intr *,
266 void *, const char *);
267 int alpha_shared_intr_get_sharetype(struct alpha_shared_intr *,
268 unsigned int);
269 int alpha_shared_intr_isactive(struct alpha_shared_intr *,
270 unsigned int);
271 void alpha_shared_intr_set_dfltsharetype(struct alpha_shared_intr *,
272 unsigned int, int);
273 void alpha_shared_intr_set_maxstrays(struct alpha_shared_intr *,
274 unsigned int, int);
275 void alpha_shared_intr_stray(struct alpha_shared_intr *, unsigned int,
276 const char *);
277 void alpha_shared_intr_set_private(struct alpha_shared_intr *,
278 unsigned int, void *);
279 void *alpha_shared_intr_get_private(struct alpha_shared_intr *,
280 unsigned int);
281 char *alpha_shared_intr_string(struct alpha_shared_intr *,
282 unsigned int);
283 struct evcnt *alpha_shared_intr_evcnt(struct alpha_shared_intr *,
284 unsigned int);
285
286 void set_iointr(void (*)(void *, unsigned long));
287
288 #endif /* _KERNEL */
289 #endif /* ! _ALPHA_INTR_H_ */
290