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