intr.h revision 1.3.8.2 1 /* $NetBSD: intr.h,v 1.3.8.2 2006/12/30 20:47:13 yamt Exp $ */
2
3 /*
4 * Copyright (c) 2001 Matt Fredette.
5 * Copyright (c) 1998 Matt Thomas.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the company nor the names of the authors may be used to
17 * endorse or promote products derived from this software without specific
18 * prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
21 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 #ifndef _SUN68K_INTR_H_
34 #define _SUN68K_INTR_H_
35
36 #include <sys/queue.h>
37 #include <m68k/psl.h>
38
39 /*
40 * Interrupt levels.
41 */
42 #define IPL_NONE 0
43 #define IPL_SOFTCLOCK 1
44 #define IPL_SOFTNET 2
45 #define IPL_BIO 3
46 #define IPL_NET 4
47 #define IPL_SOFTSERIAL 5
48 #define IPL_TTY 6
49 #define IPL_LPT 7
50 #define IPL_VM 8
51 #if 0
52 #define IPL_AUDIO 9
53 #endif
54 #define IPL_CLOCK 10
55 #define IPL_STATCLOCK 11
56 #define IPL_SERIAL 12
57 #define IPL_SCHED 13
58 #define IPL_HIGH 14
59 #define IPL_LOCK 15
60 #if 0
61 #define IPL_IPI 16
62 #endif
63
64 #define _IPL_SOFT_LEVEL1 1
65 #define _IPL_SOFT_LEVEL2 2
66 #define _IPL_SOFT_LEVEL3 3
67 #define _IPL_SOFT_LEVEL_MIN 1
68 #define _IPL_SOFT_LEVEL_MAX 3
69
70 #ifdef _KERNEL
71
72 typedef int ipl_t;
73 typedef struct {
74 int _psl;
75 } ipl_cookie_t;
76
77 ipl_cookie_t makeiplcookie(ipl_t ipl);
78
79 static inline int
80 splraiseipl(ipl_cookie_t icookie)
81 {
82
83 return _splraise(icookie._psl);
84 }
85
86 LIST_HEAD(sh_head, softintr_handler);
87
88 struct softintr_head {
89 int shd_ipl;
90 struct sh_head shd_intrs;
91 };
92
93 struct softintr_handler {
94 struct softintr_head *sh_head;
95 LIST_ENTRY(softintr_handler) sh_link;
96 void (*sh_func)(void *);
97 void *sh_arg;
98 int sh_pending;
99 };
100
101 void softintr_init(void);
102 void *softintr_establish(int, void (*)(void *), void *);
103 void softintr_disestablish(void *);
104
105 /* These control the software interrupt register. */
106 void isr_soft_request(int);
107 void isr_soft_clear(int);
108
109 static __inline void
110 softintr_schedule(void *arg)
111 {
112 struct softintr_handler * const sh = arg;
113 if (sh->sh_pending == 0) {
114 sh->sh_pending = 1;
115 isr_soft_request(sh->sh_head->shd_ipl);
116 }
117 }
118
119 extern void *softnet_cookie;
120 #define setsoftnet() softintr_schedule(softnet_cookie)
121
122 /* These connect interrupt handlers. */
123 typedef int (*isr_func_t)(void *);
124 void isr_add_autovect(isr_func_t, void *, int);
125 void isr_add_vectored(isr_func_t, void *, int, int);
126 void isr_add_custom(int, void *);
127
128 /*
129 * Define inline functions for PSL manipulation.
130 * These are as close to macros as one can get.
131 * When not optimizing gcc will call the locore.s
132 * functions by the same names, so breakpoints on
133 * these functions will work normally, etc.
134 * (See the GCC extensions info document.)
135 */
136
137 static __inline int _getsr(void);
138
139 /* Get current sr value. */
140 static __inline int
141 _getsr(void)
142 {
143 int rv;
144
145 __asm volatile ("clrl %0; movew %%sr,%0" : "=&d" (rv));
146 return (rv);
147 }
148
149 /*
150 * The rest of this is sun68k specific, because other ports may
151 * need to do special things in spl0() (i.e. simulate SIR).
152 * Suns have a REAL interrupt register, so spl0() and splx(s)
153 * have no need to check for any simulated interrupts, etc.
154 */
155
156 #define spl0() _spl0() /* we have real software interrupts */
157 #define splx(x) _spl(x)
158
159 /* IPL used by soft interrupts: netintr(), softclock() */
160 #define spllowersoftclock() spl1()
161 #define splsoftclock() splraise1()
162 #define splsoftnet() splraise1()
163 #define splsoftserial() splraise3()
164
165 /* Highest block device (strategy) IPL. */
166 #define splbio() splraise2()
167
168 /* Highest network interface IPL. */
169 #define splnet() splraise3()
170
171 /* Highest tty device IPL. */
172 #define spltty() splraise4()
173
174 /*
175 * Requirement: imp >= (highest network, tty, or disk IPL)
176 * This is used mostly in the VM code.
177 * Note that the VM code runs at spl7 during kernel
178 * initialization, and later at spl0, so we have to
179 * use splraise to avoid enabling interrupts early.
180 */
181 #define splvm() _splraise(PSL_S|PSL_IPL4)
182
183 /* Intersil or Am9513 clock hardware interrupts (hard-wired at 5) */
184 #define splclock() splraise5()
185 #define splstatclock() splclock()
186
187 /* Zilog Serial hardware interrupts (hard-wired at 6) */
188 #define splzs() spl6()
189 #define splserial() spl6()
190
191 /* Block out all interrupts (except NMI of course). */
192 #define splhigh() spl7()
193 #define splsched() spl7()
194 #define spllock() spl7()
195
196 /* This returns true iff the spl given is spl0. */
197 #define is_spl0(s) (((s) & PSL_IPL7) == 0)
198
199 #endif /* _KERNEL */
200
201 #endif /* _SUN68K_INTR_H */
202