intr.h revision 1.16 1 /* $NetBSD: intr.h,v 1.16 2006/12/21 15:55:22 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1999 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 #ifndef _HP300_INTR_H_
40 #define _HP300_INTR_H_
41
42 #include <sys/device.h>
43 #include <sys/queue.h>
44 #include <machine/psl.h>
45
46 /*
47 * Interrupt "levels". These are a more abstract representation
48 * of interrupt levels, and do not have the same meaning as m68k
49 * CPU interrupt levels. They serve the following purposes:
50 *
51 * - properly order ISRs in the list for that CPU ipl
52 * - compute CPU PSL values for the spl*() calls.
53 * - used to create cookie for the splraiseipl().
54 */
55 #define IPL_NONE 0
56 #define IPL_SOFTCLOCK 1
57 #define IPL_SOFTNET 2
58 #define IPL_SOFTSERIAL 3
59 #define IPL_SOFT 4 /* disable all software interrupts */
60 #define IPL_BIO 5
61 #define IPL_NET 6
62 #define IPL_TTY 7
63 #define IPL_TTYNOBUF 8 /* IPL_TTY + higher ISR priority */
64 #define IPL_VM 9
65 #define IPL_CLOCK 10
66 #define IPL_STATCLOCK IPL_CLOCK
67 #define IPL_HIGH 11
68 #define IPL_SCHED IPL_HIGH
69 #define IPL_LOCK IPL_HIGH
70 #define NIPL 12
71
72 #define _IPL_SOFTSERIAL 0 /* serial software interrupts */
73 #define _IPL_SOFTNET 1 /* network software interrupts */
74 #define _IPL_SOFTCLOCK 2 /* clock software interrupts */
75 #define _IPL_SOFT 3 /* other software interrupts */
76 #define IPL_NSOFT 4
77
78 #define IPL_SOFTNAMES { \
79 "serial", \
80 "net", \
81 "clock", \
82 "misc", \
83 }
84
85 /*
86 * Convert PSL values to m68k CPU IPLs and vice-versa.
87 * Note: CPU IPL values are different from IPL_* used by splraiseipl().
88 */
89 #define PSLTOIPL(x) (((x) >> 8) & 0xf)
90 #define IPLTOPSL(x) ((((x) & 0xf) << 8) | PSL_S)
91
92 #ifdef _KERNEL
93
94 extern u_short hp300_ipl2psl[];
95
96 typedef int ipl_t;
97 typedef struct {
98 int _psl;
99 } ipl_cookie_t;
100
101 static inline ipl_cookie_t
102 makeiplcookie(ipl_t ipl)
103 {
104
105 return (ipl_cookie_t){._psl = hp300_ipl2psl[ipl]};
106 }
107
108 static inline int
109 splraiseipl(ipl_cookie_t icookie)
110 {
111
112 return _splraise(icookie._psl);
113 }
114
115 /* These spl calls are _not_ to be used by machine-independent code. */
116 #define splhil() splraise1()
117 #define splkbd() splhil()
118
119 /* These spl calls are used by machine-independent code. */
120 /* spl0 requires checking for software interrupts */
121 #define spllowersoftclock() spl1()
122 #define splsoft() splraise1()
123 #define splsoftclock() splsoft()
124 #define splsoftnet() splsoft()
125 #define splsoftserial() splsoft()
126 #define splbio() _splraise(hp300_ipl2psl[IPL_BIO])
127 #define splnet() _splraise(hp300_ipl2psl[IPL_NET])
128 #define spltty() _splraise(hp300_ipl2psl[IPL_TTY])
129 #define splserial() _splraise(hp300_ipl2psl[IPL_TTY])
130 #define splvm() _splraise(hp300_ipl2psl[IPL_VM])
131 #define splclock() spl6()
132 #define splstatclock() splclock()
133 #define splhigh() spl7()
134 #define splsched() spl7()
135 #define spllock() spl7()
136
137 /* watch out for side effects */
138 #define splx(s) ((s) & PSL_IPL ? _spl((s)) : spl0())
139
140 struct hp300_intrhand {
141 LIST_ENTRY(hp300_intrhand) ih_q;
142 int (*ih_fn)(void *);
143 void *ih_arg;
144 int ih_ipl;
145 int ih_priority;
146 };
147
148 struct hp300_intr {
149 LIST_HEAD(, hp300_intrhand) hi_q;
150 struct evcnt hi_evcnt;
151 };
152
153 /*
154 * Software Interrupts.
155 */
156
157 struct hp300_soft_intrhand {
158 LIST_ENTRY(hp300_soft_intrhand) sih_q;
159 struct hp300_soft_intr *sih_intrhead;
160 void (*sih_fn)(void *);
161 void *sih_arg;
162 volatile int sih_pending;
163 };
164
165 struct hp300_soft_intr {
166 LIST_HEAD(, hp300_soft_intrhand) hsi_q;
167 struct evcnt hsi_evcnt;
168 uint8_t hsi_ipl;
169 };
170
171 void *softintr_establish(int, void (*)(void *), void *);
172 void softintr_disestablish(void *);
173 void softintr_init(void);
174 void softintr_dispatch(void);
175
176 extern volatile uint8_t ssir;
177 #define setsoft(x) ssir |= (1<<(x))
178
179 #define softintr_schedule(arg) \
180 do { \
181 struct hp300_soft_intrhand *__sih = (arg); \
182 __sih->sih_pending = 1; \
183 setsoft(__sih->sih_intrhead->hsi_ipl); \
184 } while (0)
185
186 /* XXX For legacy software interrupts */
187 extern struct hp300_soft_intrhand *softnet_intrhand;
188 #define setsoftnet() softintr_schedule(softnet_intrhand)
189
190 /* locore.s */
191 int spl0(void);
192
193 /* intr.c */
194 void intr_init(void);
195 void *intr_establish(int (*)(void *), void *, int, int);
196 void intr_disestablish(void *);
197 void intr_dispatch(int);
198 void intr_printlevels(void);
199 void netintr(void);
200
201 #endif /* _KERNEL */
202
203 #endif /* _HP300_INTR_H_ */
204