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