intr.h revision 1.27 1 /* $NetBSD: intr.h,v 1.27 2000/06/04 05:23:18 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000 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/lock.h>
71 #include <sys/queue.h>
72 #include <machine/atomic.h>
73
74 /*
75 * Alpha interrupts come in at one of 4 levels:
76 *
77 * software interrupt level
78 * i/o level 1
79 * i/o level 2
80 * clock level
81 *
82 * However, since we do not have any way to know which hardware
83 * level a particular i/o interrupt comes in on, we have to
84 * whittle it down to 3.
85 */
86
87 #define IPL_NONE 1 /* disable only this interrupt */
88 #define IPL_BIO 1 /* disable block I/O interrupts */
89 #define IPL_NET 1 /* disable network interrupts */
90 #define IPL_TTY 1 /* disable terminal interrupts */
91 #define IPL_CLOCK 2 /* disable clock interrupts */
92 #define IPL_HIGH 3 /* disable all interrupts */
93 #define IPL_SERIAL 1 /* disable serial interrupts */
94
95 #define IPL_SOFTSERIAL 0 /* serial software interrupts */
96 #define IPL_SOFTNET 1 /* network software interrupts */
97 #define IPL_SOFTCLOCK 2 /* clock software interrupts */
98 #define IPL_SOFT 3 /* other software interrupts */
99 #define IPL_NSOFT 4
100
101 #define IST_UNUSABLE -1 /* interrupt cannot be used */
102 #define IST_NONE 0 /* none (dummy) */
103 #define IST_PULSE 1 /* pulsed */
104 #define IST_EDGE 2 /* edge-triggered */
105 #define IST_LEVEL 3 /* level-triggered */
106
107 #ifdef _KERNEL
108
109 /* IPL-lowering/restoring macros */
110 #define splx(s) \
111 ((s) == ALPHA_PSL_IPL_0 ? spl0() : alpha_pal_swpipl(s))
112 #define spllowersoftclock() alpha_pal_swpipl(ALPHA_PSL_IPL_SOFT)
113
114 /* IPL-raising functions/macros */
115 static __inline int
116 _splraise(int s)
117 {
118 int cur = alpha_pal_rdps() & ALPHA_PSL_IPL_MASK;
119 return (s > cur ? alpha_pal_swpipl(s) : cur);
120 }
121 #define splsoft() _splraise(ALPHA_PSL_IPL_SOFT)
122 #define splsoftserial() splsoft()
123 #define splsoftclock() splsoft()
124 #define splsoftnet() splsoft()
125 #define splnet() _splraise(ALPHA_PSL_IPL_IO)
126 #define splbio() _splraise(ALPHA_PSL_IPL_IO)
127 #define splimp() _splraise(ALPHA_PSL_IPL_IO)
128 #define spltty() _splraise(ALPHA_PSL_IPL_IO)
129 #define splserial() _splraise(ALPHA_PSL_IPL_IO)
130 #define splclock() _splraise(ALPHA_PSL_IPL_CLOCK)
131 #define splstatclock() _splraise(ALPHA_PSL_IPL_CLOCK)
132 #define splhigh() _splraise(ALPHA_PSL_IPL_HIGH)
133
134 #define spllpt() spltty()
135
136 /*
137 * Interprocessor interrupts. In order how we want them processed.
138 */
139 #define ALPHA_IPI_HALT 0x0000000000000001UL
140 #define ALPHA_IPI_TBIA 0x0000000000000002UL
141 #define ALPHA_IPI_TBIAP 0x0000000000000004UL
142 #define ALPHA_IPI_SHOOTDOWN 0x0000000000000008UL
143 #define ALPHA_IPI_IMB 0x0000000000000010UL
144 #define ALPHA_IPI_AST 0x0000000000000020UL
145
146 #define ALPHA_NIPIS 6 /* must not exceed 64 */
147
148 typedef void (*ipifunc_t)(void);
149 extern ipifunc_t ipifuncs[ALPHA_NIPIS];
150
151 void alpha_send_ipi(unsigned long, unsigned long);
152 void alpha_broadcast_ipi(unsigned long);
153
154 /*
155 * Alpha shared-interrupt-line common code.
156 */
157
158 struct alpha_shared_intrhand {
159 TAILQ_ENTRY(alpha_shared_intrhand)
160 ih_q;
161 struct alpha_shared_intr *ih_intrhead;
162 int (*ih_fn)(void *);
163 void *ih_arg;
164 int ih_level;
165 unsigned int ih_num;
166 };
167
168 struct alpha_shared_intr {
169 TAILQ_HEAD(,alpha_shared_intrhand)
170 intr_q;
171 void *intr_private;
172 int intr_sharetype;
173 int intr_dfltsharetype;
174 int intr_nstrays;
175 int intr_maxstrays;
176 };
177
178 #define ALPHA_SHARED_INTR_DISABLE(asi, num) \
179 ((asi)[num].intr_maxstrays != 0 && \
180 (asi)[num].intr_nstrays == (asi)[num].intr_maxstrays)
181
182 /*
183 * simulated software interrupt register
184 */
185 extern u_int64_t ssir;
186
187 #define setsoft(x) atomic_setbits_ulong(&ssir, 1 << (x))
188
189 #define __GENERIC_SOFT_INTERRUPTS
190 struct alpha_soft_intrhand {
191 LIST_ENTRY(alpha_soft_intrhand)
192 sih_q;
193 struct alpha_soft_intr *sih_intrhead;
194 void (*sih_fn)(void *);
195 void *sih_arg;
196 int sih_pending;
197 };
198
199 struct alpha_soft_intr {
200 LIST_HEAD(, alpha_soft_intrhand)
201 softintr_q;
202 struct simplelock softintr_slock;
203 unsigned long softintr_ipl;
204 };
205
206 void *softintr_establish(int, void (*)(void *), void *);
207 void softintr_disestablish(void *);
208 void softintr_init(void);
209 void softintr_dispatch(void);
210
211 #define softintr_schedule(arg) \
212 do { \
213 struct alpha_soft_intrhand *__sih = (arg); \
214 __sih->sih_pending = 1; \
215 setsoft(__sih->sih_intrhead->softintr_ipl); \
216 } while (0)
217
218 /* XXX For legacy software interrupts. */
219 extern struct alpha_soft_intrhand *softnet_intrhand;
220 extern struct alpha_soft_intrhand *softclock_intrhand;
221
222 #define setsoftnet() softintr_schedule(softnet_intrhand)
223 #define setsoftclock() softintr_schedule(softclock_intrhand)
224
225 struct alpha_shared_intr *alpha_shared_intr_alloc(unsigned int);
226 int alpha_shared_intr_dispatch(struct alpha_shared_intr *,
227 unsigned int);
228 void *alpha_shared_intr_establish(struct alpha_shared_intr *,
229 unsigned int, int, int, int (*)(void *), void *, const char *);
230 void alpha_shared_intr_disestablish(struct alpha_shared_intr *,
231 void *, const char *);
232 int alpha_shared_intr_get_sharetype(struct alpha_shared_intr *,
233 unsigned int);
234 int alpha_shared_intr_isactive(struct alpha_shared_intr *,
235 unsigned int);
236 void alpha_shared_intr_set_dfltsharetype(struct alpha_shared_intr *,
237 unsigned int, int);
238 void alpha_shared_intr_set_maxstrays(struct alpha_shared_intr *,
239 unsigned int, int);
240 void alpha_shared_intr_stray(struct alpha_shared_intr *, unsigned int,
241 const char *);
242 void alpha_shared_intr_set_private(struct alpha_shared_intr *,
243 unsigned int, void *);
244 void *alpha_shared_intr_get_private(struct alpha_shared_intr *,
245 unsigned int);
246
247 #endif /* _KERNEL */
248 #endif /* ! _ALPHA_INTR_H_ */
249