xref: /netbsd-src/sys/arch/amigappc/include/intr.h (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: intr.h,v 1.12 2003/06/16 20:00:57 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Ignatios Souvatzis.
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  * machine/intr.h for the Amiga port.
41  * Currently, only a wrapper, for most of the stuff, around the old
42  * include files.
43  */
44 
45 #ifndef _MACHINE_INTR_H_
46 #define _MACHINE_INTR_H_
47 
48 #include <amiga/amiga/isr.h>
49 #include <amiga/include/mtpr.h>
50 
51 /* ADAM: commented out
52 #define IPL_SOFTSERIAL 1
53 #define IPL_SOFTNET 1
54 */
55 
56 #ifdef splaudio
57 #undef splaudio
58 #define splaudio spl6
59 #endif
60 
61 #define spllpt()	spl6()
62 
63 /* ADAM: from macppc/intr.h */
64 /* Interrupt priority `levels'. */
65 #define	IPL_NONE	9	/* nothing */
66 #define	IPL_SOFTCLOCK	8	/* timeouts */
67 #define	IPL_SOFTNET	7	/* protocol stacks */
68 #define	IPL_BIO		6	/* block I/O */
69 #define	IPL_NET		5	/* network */
70 #define	IPL_SOFTSERIAL	4	/* serial */
71 #define	IPL_TTY		3	/* terminal */
72 #define	IPL_VM		3	/* memory allocation */
73 #define	IPL_AUDIO	2	/* audio */
74 #define	IPL_CLOCK	1	/* clock */
75 #define	IPL_HIGH	1	/* everything */
76 #define	IPL_SERIAL	0	/* serial */
77 #define	NIPL		10
78 
79 /* Interrupt sharing types. */
80 #define	IST_NONE	0	/* none */
81 #define	IST_PULSE	1	/* pulsed */
82 #define	IST_EDGE	2	/* edge-triggered */
83 #define	IST_LEVEL	3	/* level-triggered */
84 
85 #ifndef _LOCORE
86 
87 /*
88  * Interrupt handler chains.  intr_establish() inserts a handler into
89  * the list.  The handler is called with its (single) argument.
90  */
91 struct intrhand {
92 	int	(*ih_fun) __P((void *));
93 	void	*ih_arg;
94 	u_long	ih_count;
95 	struct	intrhand *ih_next;
96 	int	ih_level;
97 	int	ih_irq;
98 };
99 
100 void do_pending_int __P((void));
101 
102 static __inline int splraise __P((int));
103 static __inline int spllower __P((int));
104 static __inline void splx __P((int));
105 static __inline void softintr __P((int));
106 
107 extern volatile int cpl, ipending, astpending, tickspending;
108 extern int imask[];
109 
110 /*
111  *  Reorder protection in the following inline functions is
112  * achieved with the "eieio" instruction which the assembler
113  * seems to detect and then doesn't move instructions past....
114  */
115 static __inline int
116 splraise(ncpl)
117 	int ncpl;
118 {
119 	int ocpl;
120 
121 	__asm__ volatile("sync; eieio\n");	/* don't reorder.... */
122 	ocpl = cpl;
123 	cpl = ocpl | ncpl;
124 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
125 	return (ocpl);
126 }
127 
128 static __inline void
129 splx(ncpl)
130 	int ncpl;
131 {
132 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
133 	cpl = ncpl;
134 	if (ipending & ~ncpl)
135 		do_pending_int();
136 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
137 }
138 
139 static __inline int
140 spllower(ncpl)
141 	int ncpl;
142 {
143 	int ocpl;
144 
145 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
146 	ocpl = cpl;
147 	cpl = ncpl;
148 	if (ipending & ~ncpl)
149 		do_pending_int();
150 	__asm__ volatile("sync; eieio\n");	/* reorder protect */
151 	return (ocpl);
152 }
153 
154 /* Following code should be implemented with lwarx/stwcx to avoid
155  * the disable/enable. i need to read the manual once more.... */
156 static __inline void
157 softintr(ipl)
158 	int ipl;
159 {
160 	int msrsave;
161 
162 	__asm__ volatile("mfmsr %0" : "=r"(msrsave));
163 	__asm__ volatile("mtmsr %0" :: "r"(msrsave & ~PSL_EE));
164 	ipending |= 1 << ipl;
165 	__asm__ volatile("mtmsr %0" :: "r"(msrsave));
166 }
167 
168 #define	ICU_LEN		32
169 
170 /* Soft interrupt masks. */
171 /*
172 #define SIR_CLOCK	28
173 #define SIR_NET		29
174 #define SIR_SERIAL	30
175 */
176 #define SPL_CLOCK	31
177 
178 /*
179  * Hardware interrupt masks
180  */
181 #define splbio()	splraise(imask[IPL_BIO])
182 #define splnet()	splraise(imask[IPL_NET])
183 #define spltty()	splraise(imask[IPL_TTY])
184 #define	splaudio()	splraise(imask[IPL_AUDIO])
185 #define splclock()	splraise(imask[IPL_CLOCK])
186 #define splstatclock()	splclock()
187 #define	splserial()	splraise(imask[IPL_SERIAL])
188 
189 /* ADAM: see above
190 #define spllpt()	spltty()
191 */
192 
193 /*
194  * Software interrupt masks
195  *
196  * NOTE: splsoftclock() is used by hardclock() to lower the priority from
197  * clock to softclock before it calls softclock().
198  */
199 #define	spllowersoftclock() spllower(imask[IPL_SOFTCLOCK])
200 #define	splsoftclock()	splraise(imask[IPL_SOFTCLOCK])
201 #define	splsoftnet()	splraise(imask[IPL_SOFTNET])
202 #define	splsoftserial()	splraise(imask[IPL_SOFTSERIAL])
203 
204 /*
205  * Miscellaneous
206  */
207 #define splvm()		splraise(imask[IPL_VM])
208 #define	splhigh()	splraise(imask[IPL_HIGH])
209 #define	splsched()	splhigh()
210 #define	spllock()	splhigh()
211 #define	spl0()		spllower(0)
212 
213 /*
214 #define	setsoftnet()	softintr(SIR_NET)
215 #define	setsoftserial()	softintr(SIR_SERIAL)
216 */
217 extern long intrcnt[];
218 
219 #define CNT_IRQ0	0
220 #define CNT_CLOCK	64
221 #define CNT_SOFTCLOCK	65
222 #define CNT_SOFTNET	66
223 #define CNT_SOFTSERIAL	67
224 
225 #endif /* !_LOCORE */
226 
227 #endif /* !_MACPPC_INTR_H_ */
228