intr.h revision 1.2.2.2 1 1.2.2.2 nathanw /* $NetBSD: intr.h,v 1.2.2.2 2002/02/28 04:11:00 nathanw Exp $ */
2 1.2.2.2 nathanw
3 1.2.2.2 nathanw /*-
4 1.2.2.2 nathanw * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
5 1.2.2.2 nathanw * All rights reserved.
6 1.2.2.2 nathanw *
7 1.2.2.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 nathanw * by Charles M. Hannum.
9 1.2.2.2 nathanw *
10 1.2.2.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 nathanw * modification, are permitted provided that the following conditions
12 1.2.2.2 nathanw * are met:
13 1.2.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.2.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 nathanw * must display the following acknowledgement:
20 1.2.2.2 nathanw * This product includes software developed by the NetBSD
21 1.2.2.2 nathanw * Foundation, Inc. and its contributors.
22 1.2.2.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 nathanw * contributors may be used to endorse or promote products derived
24 1.2.2.2 nathanw * from this software without specific prior written permission.
25 1.2.2.2 nathanw *
26 1.2.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 nathanw */
38 1.2.2.2 nathanw /*
39 1.2.2.2 nathanw * Sandpoint-specific code developed
40 1.2.2.2 nathanw * by Allen Briggs for Wasabi Systems, Inc.
41 1.2.2.2 nathanw *
42 1.2.2.2 nathanw * OpenPIC code derived from code with the following notice.
43 1.2.2.2 nathanw */
44 1.2.2.2 nathanw /*-
45 1.2.2.2 nathanw * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
46 1.2.2.2 nathanw *
47 1.2.2.2 nathanw * Redistribution and use in source and binary forms, with or without
48 1.2.2.2 nathanw * modification, are permitted provided that the following conditions
49 1.2.2.2 nathanw * are met:
50 1.2.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
51 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer.
52 1.2.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
53 1.2.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
54 1.2.2.2 nathanw * documentation and/or other materials provided with the distribution.
55 1.2.2.2 nathanw * 3. The name of the author may not be used to endorse or promote products
56 1.2.2.2 nathanw * derived from this software without specific prior written permission.
57 1.2.2.2 nathanw *
58 1.2.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 1.2.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.2.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.2.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 1.2.2.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 1.2.2.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 1.2.2.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 1.2.2.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 1.2.2.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
67 1.2.2.2 nathanw * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 1.2.2.2 nathanw */
69 1.2.2.2 nathanw
70 1.2.2.2 nathanw #ifndef _MVMEPPC_INTR_H_
71 1.2.2.2 nathanw #define _MVMEPPC_INTR_H_
72 1.2.2.2 nathanw
73 1.2.2.2 nathanw /* Interrupt priority `levels'. */
74 1.2.2.2 nathanw #define IPL_NONE 9 /* nothing */
75 1.2.2.2 nathanw #define IPL_SOFTCLOCK 8 /* software clock interrupt */
76 1.2.2.2 nathanw #define IPL_SOFTNET 7 /* software network interrupt */
77 1.2.2.2 nathanw #define IPL_BIO 6 /* block I/O */
78 1.2.2.2 nathanw #define IPL_NET 5 /* network */
79 1.2.2.2 nathanw #define IPL_SOFTSERIAL 4 /* software serial interrupt */
80 1.2.2.2 nathanw #define IPL_TTY 3 /* terminal */
81 1.2.2.2 nathanw #define IPL_IMP 3 /* memory allocation */
82 1.2.2.2 nathanw #define IPL_AUDIO 2 /* audio */
83 1.2.2.2 nathanw #define IPL_CLOCK 1 /* clock */
84 1.2.2.2 nathanw #define IPL_HIGH 1 /* everything */
85 1.2.2.2 nathanw #define IPL_SERIAL 0 /* serial */
86 1.2.2.2 nathanw #define NIPL 10
87 1.2.2.2 nathanw
88 1.2.2.2 nathanw /* Interrupt sharing types. */
89 1.2.2.2 nathanw #define IST_NONE 0 /* none */
90 1.2.2.2 nathanw #define IST_PULSE 1 /* pulsed */
91 1.2.2.2 nathanw #define IST_EDGE 2 /* edge-triggered */
92 1.2.2.2 nathanw #define IST_LEVEL 3 /* level-triggered */
93 1.2.2.2 nathanw
94 1.2.2.2 nathanw #ifndef _LOCORE
95 1.2.2.2 nathanw
96 1.2.2.2 nathanw /*
97 1.2.2.2 nathanw * Interrupt handler chains. intr_establish() inserts a handler into
98 1.2.2.2 nathanw * the list. The handler is called with its (single) argument.
99 1.2.2.2 nathanw */
100 1.2.2.2 nathanw struct intrhand {
101 1.2.2.2 nathanw int (*ih_fun)(void *);
102 1.2.2.2 nathanw void *ih_arg;
103 1.2.2.2 nathanw u_long ih_count;
104 1.2.2.2 nathanw struct intrhand *ih_next;
105 1.2.2.2 nathanw int ih_level;
106 1.2.2.2 nathanw int ih_irq;
107 1.2.2.2 nathanw };
108 1.2.2.2 nathanw
109 1.2.2.2 nathanw void setsoftclock(void);
110 1.2.2.2 nathanw void clearsoftclock(void);
111 1.2.2.2 nathanw int splsoftclock(void);
112 1.2.2.2 nathanw void setsoftnet(void);
113 1.2.2.2 nathanw void clearsoftnet(void);
114 1.2.2.2 nathanw int splsoftnet(void);
115 1.2.2.2 nathanw void softnet(void);
116 1.2.2.2 nathanw
117 1.2.2.2 nathanw void ext_intr(void);
118 1.2.2.2 nathanw
119 1.2.2.2 nathanw void do_pending_int(void);
120 1.2.2.2 nathanw void *intr_establish(int, int, int, int (*)(void *), void *);
121 1.2.2.2 nathanw void intr_disestablish(void *);
122 1.2.2.2 nathanw
123 1.2.2.2 nathanw void softserial(void);
124 1.2.2.2 nathanw int isa_intr(void);
125 1.2.2.2 nathanw void isa_intr_mask(int);
126 1.2.2.2 nathanw void isa_intr_clr(int);
127 1.2.2.2 nathanw void isa_setirqstat(int, int, int);
128 1.2.2.2 nathanw
129 1.2.2.2 nathanw
130 1.2.2.2 nathanw extern volatile int cpl, ipending, astpending, tickspending;
131 1.2.2.2 nathanw extern int imask[];
132 1.2.2.2 nathanw extern long intrcnt[];
133 1.2.2.2 nathanw extern int intrtype[];
134 1.2.2.2 nathanw extern struct intrhand *intrhand[];
135 1.2.2.2 nathanw
136 1.2.2.2 nathanw static __inline int splraise(int);
137 1.2.2.2 nathanw static __inline int spllower(int);
138 1.2.2.2 nathanw static __inline void splx(int);
139 1.2.2.2 nathanw static __inline void set_sint(int);
140 1.2.2.2 nathanw
141 1.2.2.2 nathanw /*
142 1.2.2.2 nathanw * Reorder protection in the following inline functions is
143 1.2.2.2 nathanw * protected with the "eieio" instruction.
144 1.2.2.2 nathanw */
145 1.2.2.2 nathanw static __inline int
146 1.2.2.2 nathanw splraise(newcpl)
147 1.2.2.2 nathanw int newcpl;
148 1.2.2.2 nathanw {
149 1.2.2.2 nathanw int oldcpl;
150 1.2.2.2 nathanw
151 1.2.2.2 nathanw __asm__ volatile("sync; eieio\n"); /* don't reorder.... */
152 1.2.2.2 nathanw oldcpl = cpl;
153 1.2.2.2 nathanw cpl = oldcpl | newcpl;
154 1.2.2.2 nathanw __asm__ volatile("sync; eieio\n"); /* reorder protect */
155 1.2.2.2 nathanw return(oldcpl);
156 1.2.2.2 nathanw }
157 1.2.2.2 nathanw
158 1.2.2.2 nathanw static __inline void
159 1.2.2.2 nathanw splx(newcpl)
160 1.2.2.2 nathanw int newcpl;
161 1.2.2.2 nathanw {
162 1.2.2.2 nathanw __asm__ volatile("sync; eieio\n"); /* reorder protect */
163 1.2.2.2 nathanw cpl = newcpl;
164 1.2.2.2 nathanw if(ipending & ~newcpl)
165 1.2.2.2 nathanw do_pending_int();
166 1.2.2.2 nathanw __asm__ volatile("sync; eieio\n"); /* reorder protect */
167 1.2.2.2 nathanw }
168 1.2.2.2 nathanw
169 1.2.2.2 nathanw static __inline int
170 1.2.2.2 nathanw spllower(newcpl)
171 1.2.2.2 nathanw int newcpl;
172 1.2.2.2 nathanw {
173 1.2.2.2 nathanw int oldcpl;
174 1.2.2.2 nathanw
175 1.2.2.2 nathanw __asm__ volatile("sync; eieio\n"); /* reorder protect */
176 1.2.2.2 nathanw oldcpl = cpl;
177 1.2.2.2 nathanw cpl = newcpl;
178 1.2.2.2 nathanw if(ipending & ~newcpl)
179 1.2.2.2 nathanw do_pending_int();
180 1.2.2.2 nathanw __asm__ volatile("sync; eieio\n"); /* reorder protect */
181 1.2.2.2 nathanw return(oldcpl);
182 1.2.2.2 nathanw }
183 1.2.2.2 nathanw
184 1.2.2.2 nathanw /* Following code should be implemented with lwarx/stwcx to avoid
185 1.2.2.2 nathanw * the disable/enable. i need to read the manual once more.... */
186 1.2.2.2 nathanw static __inline void
187 1.2.2.2 nathanw set_sint(pending)
188 1.2.2.2 nathanw int pending;
189 1.2.2.2 nathanw {
190 1.2.2.2 nathanw int msrsave;
191 1.2.2.2 nathanw
192 1.2.2.2 nathanw __asm__ ("mfmsr %0" : "=r"(msrsave));
193 1.2.2.2 nathanw __asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
194 1.2.2.2 nathanw ipending |= pending;
195 1.2.2.2 nathanw __asm__ volatile ("mtmsr %0" :: "r"(msrsave));
196 1.2.2.2 nathanw }
197 1.2.2.2 nathanw
198 1.2.2.2 nathanw #define ICU_LEN 32
199 1.2.2.2 nathanw #define IRQ_SLAVE 2
200 1.2.2.2 nathanw #define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
201 1.2.2.2 nathanw
202 1.2.2.2 nathanw #define MVMEPPC_INTR_REG 0xbffff000
203 1.2.2.2 nathanw #define INTR_VECTOR_REG 0xff0
204 1.2.2.2 nathanw
205 1.2.2.2 nathanw #define SINT_CLOCK 0x20000000
206 1.2.2.2 nathanw #define SINT_NET 0x40000000
207 1.2.2.2 nathanw #define SINT_SERIAL 0x80000000
208 1.2.2.2 nathanw #define SPL_CLOCK 0x00000001
209 1.2.2.2 nathanw #define SINT_MASK (SINT_CLOCK|SINT_NET|SINT_SERIAL)
210 1.2.2.2 nathanw
211 1.2.2.2 nathanw #define CNT_SINT_NET 29
212 1.2.2.2 nathanw #define CNT_SINT_CLOCK 30
213 1.2.2.2 nathanw #define CNT_SINT_SERIAL 31
214 1.2.2.2 nathanw #define CNT_CLOCK 0
215 1.2.2.2 nathanw
216 1.2.2.2 nathanw #define spl0() spllower(0)
217 1.2.2.2 nathanw #define splbio() splraise(imask[IPL_BIO])
218 1.2.2.2 nathanw #define splnet() splraise(imask[IPL_NET])
219 1.2.2.2 nathanw #define spltty() splraise(imask[IPL_TTY])
220 1.2.2.2 nathanw #define spllpt() spltty()
221 1.2.2.2 nathanw #define splclock() splraise(imask[IPL_CLOCK])
222 1.2.2.2 nathanw #define splvm() splraise(imask[IPL_IMP])
223 1.2.2.2 nathanw #define splserial() splraise(imask[IPL_SERIAL])
224 1.2.2.2 nathanw #define splstatclock() splclock()
225 1.2.2.2 nathanw #define spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
226 1.2.2.2 nathanw #define splsoftclock() splraise(imask[IPL_SOFTCLOCK])
227 1.2.2.2 nathanw #define splsoftnet() splraise(imask[IPL_SOFTNET])
228 1.2.2.2 nathanw #define splsoftserial() splraise(imask[IPL_SOFTSERIAL])
229 1.2.2.2 nathanw #define splhigh() splraise(imask[IPL_HIGH])
230 1.2.2.2 nathanw #define splsched() splhigh()
231 1.2.2.2 nathanw #define spllock() splhigh()
232 1.2.2.2 nathanw
233 1.2.2.2 nathanw #if 1
234 1.2.2.2 nathanw #define setsoftisa() set_sint(SINT_ISA);
235 1.2.2.2 nathanw #define setsoftclock() set_sint(SINT_CLOCK);
236 1.2.2.2 nathanw #define setsoftnet() set_sint(SINT_NET);
237 1.2.2.2 nathanw #define setsoftserial() set_sint(SINT_SERIAL);
238 1.2.2.2 nathanw #endif
239 1.2.2.2 nathanw
240 1.2.2.2 nathanw #endif /* !_LOCORE */
241 1.2.2.2 nathanw
242 1.2.2.2 nathanw #endif /* !_MVMEPPC_INTR_H_ */
243