footbridge_intr.h revision 1.9 1 /* $NetBSD: footbridge_intr.h,v 1.9 2006/12/21 15:55:22 yamt Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #ifndef _FOOTBRIDGE_INTR_H_
39 #define _FOOTBRIDGE_INTR_H_
40
41 #include <arm/armreg.h>
42
43 /* Define the various Interrupt Priority Levels */
44
45 /* Hardware Interrupt Priority Levels are not mutually exclusive. */
46
47 #define IPL_NONE 0 /* nothing */
48 #define IPL_SOFT 1 /* generic soft interrupts */
49 #define IPL_SOFTCLOCK 2 /* clock software interrupts */
50 #define IPL_SOFTNET 3 /* network software interrupts */
51 #define IPL_BIO 4 /* block I/O */
52 #define IPL_NET 5 /* network */
53 #define IPL_SOFTSERIAL 6 /* serial software interrupts */
54 #define IPL_TTY 7 /* terminal */
55 #define IPL_LPT IPL_TTY
56 #define IPL_VM 8 /* memory allocation */
57 #define IPL_AUDIO 9 /* audio */
58 #define IPL_CLOCK 10 /* clock */
59 #define IPL_STATCLOCK 11 /* statclock */
60 #define IPL_HIGH 12 /* everything */
61 #define IPL_SCHED IPL_HIGH
62 #define IPL_LOCK IPL_HIGH
63 #define IPL_SERIAL 13 /* serial */
64
65 #define NIPL 14
66
67 #define IST_UNUSABLE -1 /* interrupt cannot be used */
68 #define IST_NONE 0 /* none (dummy) */
69 #define IST_PULSE 1 /* pulsed */
70 #define IST_EDGE 2 /* edge-triggered */
71 #define IST_LEVEL 3 /* level-triggered */
72
73 #define __NEWINTR /* enables new hooks in cpu_fork()/cpu_switch() */
74
75 #define ARM_IRQ_HANDLER _C_LABEL(footbridge_intr_dispatch)
76
77 #ifndef _LOCORE
78 #include <arm/cpufunc.h>
79
80 #include <arm/footbridge/dc21285mem.h>
81 #include <arm/footbridge/dc21285reg.h>
82
83 #define INT_SWMASK \
84 ((1U << IRQ_SOFTINT) | (1U << IRQ_RESERVED0) | \
85 (1U << IRQ_RESERVED1) | (1U << IRQ_RESERVED2))
86 #define ICU_INT_HWMASK (0xffffffff & ~(INT_SWMASK | (1U << IRQ_RESERVED3)))
87
88 /* only call this with interrupts off */
89 static inline void __attribute__((__unused__))
90 footbridge_set_intrmask(void)
91 {
92 extern volatile uint32_t intr_enabled;
93 /* fetch once so we write the same number to both registers */
94 uint32_t tmp = intr_enabled & ICU_INT_HWMASK;
95
96 ((volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_SET>>2] = tmp;
97 ((volatile uint32_t*)(DC21285_ARMCSR_VBASE))[IRQ_ENABLE_CLEAR>>2] = ~tmp;
98 }
99
100 static inline void __attribute__((__unused__))
101 footbridge_splx(int newspl)
102 {
103 extern volatile uint32_t intr_enabled;
104 extern volatile int current_spl_level;
105 extern volatile int footbridge_ipending;
106 extern void footbridge_do_pending(void);
107 int oldirqstate, hwpend;
108
109 /* Don't let the compiler re-order this code with preceding code */
110 __insn_barrier();
111
112 current_spl_level = newspl;
113
114 hwpend = (footbridge_ipending & ICU_INT_HWMASK) & ~newspl;
115 if (hwpend != 0) {
116 oldirqstate = disable_interrupts(I32_bit);
117 intr_enabled |= hwpend;
118 footbridge_set_intrmask();
119 restore_interrupts(oldirqstate);
120 }
121
122 if ((footbridge_ipending & INT_SWMASK) & ~newspl)
123 footbridge_do_pending();
124 }
125
126 static inline int __attribute__((__unused__))
127 footbridge_splraise(int ipl)
128 {
129 extern volatile int current_spl_level;
130 extern int footbridge_imask[];
131 int old;
132
133 old = current_spl_level;
134 current_spl_level |= footbridge_imask[ipl];
135
136 /* Don't let the compiler re-order this code with subsequent code */
137 __insn_barrier();
138
139 return (old);
140 }
141
142 static inline int __attribute__((__unused__))
143 footbridge_spllower(int ipl)
144 {
145 extern volatile int current_spl_level;
146 extern int footbridge_imask[];
147 int old = current_spl_level;
148
149 footbridge_splx(footbridge_imask[ipl]);
150 return(old);
151 }
152
153 /* should only be defined in footbridge_intr.c */
154 #if !defined(ARM_SPL_NOINLINE)
155
156 #define splx(newspl) footbridge_splx(newspl)
157 #define _spllower(ipl) footbridge_spllower(ipl)
158 #define _splraise(ipl) footbridge_splraise(ipl)
159 void _setsoftintr(int);
160
161 #else
162
163 int _splraise(int);
164 int _spllower(int);
165 void splx(int);
166 void _setsoftintr(int);
167
168 #endif /* ! ARM_SPL_NOINLINE */
169
170 #include <sys/device.h>
171 #include <sys/queue.h>
172 #include <machine/irqhandler.h>
173
174 #define splsoft() _splraise(IPL_SOFT)
175
176 #define spl0() (void)_spllower(IPL_NONE)
177 #define spllowersoftclock() (void)_spllower(IPL_SOFTCLOCK)
178
179 typedef int ipl_t;
180 typedef struct {
181 ipl_t _ipl;
182 } ipl_cookie_t;
183
184 static inline ipl_cookie_t
185 makeiplcookie(ipl_t ipl)
186 {
187
188 return (ipl_cookie_t){._ipl = ipl};
189 }
190
191 static inline int
192 splraiseipl(ipl_cookie_t icookie)
193 {
194
195 return _splraise(icookie._ipl);
196 }
197
198 #include <sys/spl.h>
199
200 /* Use generic software interrupt support. */
201 #include <arm/softintr.h>
202
203 /* footbridge has 32 interrupt lines */
204 #define NIRQ 32
205
206 struct intrhand {
207 TAILQ_ENTRY(intrhand) ih_list; /* link on intrq list */
208 int (*ih_func)(void *); /* handler */
209 void *ih_arg; /* arg for handler */
210 int ih_ipl; /* IPL_* */
211 int ih_irq; /* IRQ number */
212 };
213
214 #define IRQNAMESIZE sizeof("footbridge irq 31")
215
216 struct intrq {
217 TAILQ_HEAD(, intrhand) iq_list; /* handler list */
218 struct evcnt iq_ev; /* event counter */
219 int iq_mask; /* IRQs to mask while handling */
220 int iq_levels; /* IPL_*'s this IRQ has */
221 int iq_ist; /* share type */
222 char iq_name[IRQNAMESIZE]; /* interrupt name */
223 };
224
225 #endif /* _LOCORE */
226
227 #endif /* _FOOTBRIDGE_INTR_H */
228