footbridge_intr.h revision 1.18 1 /* $NetBSD: footbridge_intr.h,v 1.18 2016/01/25 16:41:06 christos 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 typedef uint8_t ipl_t;
42 typedef struct {
43 ipl_t _ipl;
44 } ipl_cookie_t;
45
46 #include <arm/mutex.h>
47 #include <arm/cpu.h>
48 #include <arm/armreg.h>
49
50 #define IPL_NONE 0 /* nothing */
51 #define IPL_SOFTCLOCK 1 /* clock soft interrupts */
52 #define IPL_SOFTBIO 2 /* block i/o */
53 #define IPL_SOFTNET 3 /* network software interrupts */
54 #define IPL_SOFTSERIAL 4 /* serial software interrupts */
55 #define IPL_VM 5 /* memory allocation */
56 #define IPL_SCHED 6 /* clock */
57 #define IPL_HIGH 7 /* everything */
58
59 #define NIPL 8
60
61 #define IST_UNUSABLE -1 /* interrupt cannot be used */
62 #define IST_NONE 0 /* none (dummy) */
63 #define IST_PULSE 1 /* pulsed */
64 #define IST_EDGE 2 /* edge-triggered */
65 #define IST_LEVEL 3 /* level-triggered */
66
67 #define ARM_IRQ_HANDLER _C_LABEL(footbridge_intr_dispatch)
68
69 #ifndef _LOCORE
70 #include <arm/cpufunc.h>
71
72 #include <arm/footbridge/dc21285mem.h>
73 #include <arm/footbridge/dc21285reg.h>
74
75 #define INT_SWMASK \
76 ((1U << IRQ_SOFTINT) | (1U << IRQ_RESERVED0) | \
77 (1U << IRQ_RESERVED1) | (1U << IRQ_RESERVED2))
78 #define ICU_INT_HWMASK (0xffffffff & ~(INT_SWMASK | (1U << IRQ_RESERVED3)))
79
80 /* only call this with interrupts off */
81 static inline void __attribute__((__unused__))
82 footbridge_set_intrmask(void)
83 {
84 extern volatile uint32_t intr_enabled;
85 volatile uint32_t * const dc21285_armcsr_vbase =
86 (volatile uint32_t *)(DC21285_ARMCSR_VBASE);
87
88 /* fetch once so we write the same number to both registers */
89 uint32_t tmp = intr_enabled & ICU_INT_HWMASK;
90
91 dc21285_armcsr_vbase[IRQ_ENABLE_SET>>2] = tmp;
92 dc21285_armcsr_vbase[IRQ_ENABLE_CLEAR>>2] = ~tmp;
93 }
94
95 static inline void __attribute__((__unused__))
96 footbridge_splx(int ipl)
97 {
98 extern int footbridge_imask[];
99 extern volatile uint32_t intr_enabled;
100 extern volatile int footbridge_ipending;
101 int oldirqstate, hwpend;
102
103 /* Don't let the compiler re-order this code with preceding code */
104 __insn_barrier();
105
106 set_curcpl(ipl);
107
108 hwpend = footbridge_ipending & ICU_INT_HWMASK & ~footbridge_imask[ipl];
109 if (hwpend != 0) {
110 oldirqstate = disable_interrupts(I32_bit);
111 intr_enabled |= hwpend;
112 footbridge_set_intrmask();
113 restore_interrupts(oldirqstate);
114 }
115
116 #ifdef __HAVE_FAST_SOFTINTS
117 cpu_dosoftints();
118 #endif
119 }
120
121 static inline int __attribute__((__unused__))
122 footbridge_splraise(int ipl)
123 {
124 int old;
125
126 old = curcpl();
127 set_curcpl(ipl);
128
129 /* Don't let the compiler re-order this code with subsequent code */
130 __insn_barrier();
131
132 return (old);
133 }
134
135 static inline int __attribute__((__unused__))
136 footbridge_spllower(int ipl)
137 {
138 int old = curcpl();
139
140 footbridge_splx(ipl);
141 return(old);
142 }
143
144 /* should only be defined in footbridge_intr.c */
145 #if !defined(ARM_SPL_NOINLINE)
146
147 #define splx(newspl) footbridge_splx(newspl)
148 #define _spllower(ipl) footbridge_spllower(ipl)
149 #define _splraise(ipl) footbridge_splraise(ipl)
150
151 #else
152
153 int _splraise(int);
154 int _spllower(int);
155 void splx(int);
156
157 #endif /* ! ARM_SPL_NOINLINE */
158
159 #include <sys/evcnt.h>
160 #include <sys/queue.h>
161 #include <machine/irqhandler.h>
162
163 #define splsoft() _splraise(IPL_SOFT)
164
165 #define spl0() (void)_spllower(IPL_NONE)
166 #define spllowersoftclock() (void)_spllower(IPL_SOFTCLOCK)
167
168
169 static inline ipl_cookie_t
170 makeiplcookie(ipl_t ipl)
171 {
172
173 return (ipl_cookie_t){._ipl = ipl};
174 }
175
176 static inline int
177 splraiseipl(ipl_cookie_t icookie)
178 {
179
180 return _splraise(icookie._ipl);
181 }
182
183 #include <sys/spl.h>
184
185 /* footbridge has 32 interrupt lines */
186 #define NIRQ 32
187
188 struct intrhand {
189 TAILQ_ENTRY(intrhand) ih_list; /* link on intrq list */
190 int (*ih_func)(void *); /* handler */
191 void *ih_arg; /* arg for handler */
192 int ih_ipl; /* IPL_* */
193 int ih_irq; /* IRQ number */
194 };
195
196 #define IRQNAMESIZE sizeof("footbridge irq 31")
197
198 struct intrq {
199 TAILQ_HEAD(, intrhand) iq_list; /* handler list */
200 struct evcnt iq_ev; /* event counter */
201 int iq_mask; /* IRQs to mask while handling */
202 int iq_levels; /* IPL_*'s this IRQ has */
203 int iq_ist; /* share type */
204 int iq_ipl; /* max ipl */
205 char iq_name[IRQNAMESIZE]; /* interrupt name */
206 };
207
208 #endif /* _LOCORE */
209
210 #endif /* _FOOTBRIDGE_INTR_H */
211