intr.h revision 1.11 1 /* $NetBSD: intr.h,v 1.11 2007/02/16 02:53:49 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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 _MVMEPPC_INTR_H_
40 #define _MVMEPPC_INTR_H_
41
42 /* Interrupt priority `levels'. */
43 #define IPL_NONE 9 /* nothing */
44 #define IPL_SOFTCLOCK 8 /* software clock interrupt */
45 #define IPL_SOFTNET 7 /* software network interrupt */
46 #define IPL_BIO 6 /* block I/O */
47 #define IPL_NET 5 /* network */
48 #define IPL_SOFTSERIAL 4 /* software serial interrupt */
49 #define IPL_TTY 3 /* terminal */
50 #define IPL_LPT IPL_TTY
51 #define IPL_VM 3 /* memory allocation */
52 #define IPL_AUDIO 2 /* audio */
53 #define IPL_CLOCK 1 /* clock */
54 #define IPL_STATCLOCK IPL_CLOCK
55 #define IPL_HIGH 1 /* everything */
56 #define IPL_SCHED IPL_HIGH
57 #define IPL_LOCK IPL_HIGH
58 #define IPL_SERIAL 0 /* serial */
59 #define NIPL 10
60
61
62 /* Interrupt sharing types. */
63 #define IST_NONE 0 /* none */
64 #define IST_PULSE 1 /* pulsed */
65 #define IST_EDGE 2 /* edge-triggered */
66 #define IST_LEVEL 3 /* level-triggered */
67
68 #ifndef _LOCORE
69
70 /*
71 * Interrupt handler chains. intr_establish() inserts a handler into
72 * the list. The handler is called with its (single) argument.
73 */
74 struct intrhand {
75 int (*ih_fun)(void *);
76 void *ih_arg;
77 u_long ih_count;
78 struct intrhand *ih_next;
79 int ih_level;
80 int ih_irq;
81 };
82
83 void do_pending_int(void);
84
85 void ext_intr(void);
86 void ext_intr_ivr(void);
87
88 void enable_intr(void);
89 void disable_intr(void);
90
91 void *intr_establish(int, int, int, int (*)(void *), void *);
92 void intr_disestablish(void *);
93
94 void softnet(int);
95 void softserial(void);
96 int isa_intr(void);
97 void isa_intr_mask(int);
98 void isa_intr_clr(int);
99 void isa_setirqstat(int, int, int);
100
101 static __inline int splraise(int);
102 static __inline void spllower(int);
103 static __inline void set_sint(int);
104
105 extern volatile int cpl, ipending, astpending, tickspending;
106 extern int imen;
107 extern int imask[];
108 extern long intrcnt[];
109 extern unsigned intrcnt2[];
110 extern struct intrhand *intrhand[];
111 extern int intrtype[];
112 extern vaddr_t mvmeppc_intr_reg;
113
114 /*
115 * Reorder protection in the following inline functions is
116 * achieved with the "eieio" instruction which the assembler
117 * seems to detect and then doesn't move instructions past....
118 */
119 static __inline int
120 splraise(int newcpl)
121 {
122 int oldcpl;
123
124 __asm volatile("sync; eieio\n"); /* don't reorder.... */
125 oldcpl = cpl;
126 cpl = oldcpl | newcpl;
127 __asm volatile("sync; eieio\n"); /* reorder protect */
128 return(oldcpl);
129 }
130
131 static __inline void
132 spllower(int newcpl)
133 {
134
135 __asm volatile("sync; eieio\n"); /* reorder protect */
136 cpl = newcpl;
137 if(ipending & ~newcpl)
138 do_pending_int();
139 __asm volatile("sync; eieio\n"); /* reorder protect */
140 }
141
142 /* Following code should be implemented with lwarx/stwcx to avoid
143 * the disable/enable. i need to read the manual once more.... */
144 static __inline void
145 set_sint(int pending)
146 {
147 int msrsave;
148
149 __asm ("mfmsr %0" : "=r"(msrsave));
150 __asm volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
151 ipending |= pending;
152 __asm volatile ("mtmsr %0" :: "r"(msrsave));
153 }
154
155 #define ICU_LEN 32
156 #define IRQ_SLAVE 2
157 #define LEGAL_IRQ(x) ((x) >= 0 && (x) < ICU_LEN && (x) != IRQ_SLAVE)
158
159 #define MVMEPPC_INTR_REG 0xbffff000
160 #define INTR_VECTOR_REG 0xff0
161
162 #define SINT_CLOCK 0x20000000
163 #define SINT_NET 0x40000000
164 #define SINT_SERIAL 0x80000000
165 #define SPL_CLOCK 0x00000001
166 #define SINT_MASK (SINT_CLOCK|SINT_NET|SINT_SERIAL)
167
168 #define CNT_SINT_NET 29
169 #define CNT_SINT_CLOCK 30
170 #define CNT_SINT_SERIAL 31
171 #define CNT_CLOCK 0
172
173 #define setsoftclock() set_sint(SINT_CLOCK);
174 #define setsoftnet() set_sint(SINT_NET);
175 #define setsoftserial() set_sint(SINT_SERIAL);
176
177 #define splx(x) spllower(x)
178 #define spl0() spllower(0)
179
180 typedef int ipl_t;
181 typedef struct {
182 ipl_t _ipl;
183 } ipl_cookie_t;
184
185 static inline ipl_cookie_t
186 makeiplcookie(ipl_t ipl)
187 {
188
189 return (ipl_cookie_t){._ipl = ipl};
190 }
191
192 static inline int
193 splraiseipl(ipl_cookie_t icookie)
194 {
195
196 return splraise(imask[icookie._ipl]);
197 }
198
199 #include <sys/spl.h>
200
201 #endif /* !_LOCORE */
202
203 #endif /* !_MVMEPPC_INTR_H_ */
204