1 /* $NetBSD: adm5120_intr.c,v 1.2 2008/01/15 22:22:37 dyoung Exp $ */
4 * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * 3. The names of the authors may not be used to endorse or promote
17 * products derived from this software without specific prior
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
29 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34 * Copyright (c) 2001 The NetBSD Foundation, Inc.
35 * All rights reserved.
37 * This code is derived from software contributed to The NetBSD Foundation
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
49 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
50 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
51 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
52 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
53 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 * POSSIBILITY OF SUCH DAMAGE.
63 * Platform-specific interrupt support for the Alchemy Semiconductor Pb1000.
65 * The Alchemy Semiconductor Pb1000's interrupts are wired to two internal
66 * interrupt controllers.
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: adm5120_intr.c,v 1.2 2008/01/15 22:22:37 dyoung Exp $");
74 #include <sys/param.h>
75 #include <sys/queue.h>
76 #include <sys/malloc.h>
77 #include <sys/systm.h>
78 #include <sys/device.h>
79 #include <sys/kernel.h>
81 #include <machine/bus.h>
82 #include <machine/intr.h>
84 #include <mips/locore.h>
85 #include <mips/adm5120/include/adm5120reg.h>
86 #include <mips/adm5120/include/adm5120var.h>
88 #include <dev/pci/pcireg.h>
89 #include <dev/pci/pcivar.h>
92 * This is a mask of bits to clear in the SR when we go to a
93 * given hardware interrupt priority level.
95 const uint32_t ipl_sr_bits
[_IPL_N
] = {
97 MIPS_SOFT_INT_MASK_0
, /* 1: IPL_SOFTCLOCK */
98 MIPS_SOFT_INT_MASK_0
, /* 2: IPL_SOFTNET */
100 MIPS_SOFT_INT_MASK_0
|
101 MIPS_SOFT_INT_MASK_1
|
102 MIPS_INT_MASK_0
, /* 3: IPL_VM */
104 MIPS_SOFT_INT_MASK_0
|
105 MIPS_SOFT_INT_MASK_1
|
111 MIPS_INT_MASK_5
, /* 4: IPL_{SCHED,HIGH} */
115 const char *adm5120_intrnames
[NIRQS
] = {
120 "intx0/gpio2", /* 4 */
121 "intx1/gpio4", /* 5 */
150 struct adm5120_intrhead
{
151 struct evcnt intr_count
;
154 struct adm5120_intrhead adm5120_intrtab
[NIRQS
];
157 #define NINTRS 2 /* MIPS INT0 - INT1 */
158 struct adm5120_cpuintr
{
159 LIST_HEAD(, evbmips_intrhand
) cintr_list
;
160 struct evcnt cintr_count
;
162 struct adm5120_cpuintr adm5120_cpuintrs
[NINTRS
];
164 const char *adm5120_cpuintrnames
[NINTRS
] = {
169 #define REG_READ(o) *((volatile uint32_t *)MIPS_PHYS_TO_KSEG1(ADM5120_BASE_ICU + (o)))
170 #define REG_WRITE(o,v) (REG_READ(o)) = (v)
173 evbmips_intr_init(void)
177 for (i
= 0; i
< NINTRS
; i
++) {
178 LIST_INIT(&adm5120_cpuintrs
[i
].cintr_list
);
179 evcnt_attach_dynamic(&adm5120_cpuintrs
[i
].cintr_count
,
180 EVCNT_TYPE_INTR
, NULL
, "mips", adm5120_cpuintrnames
[i
]);
183 for (i
= 0; i
< NIRQS
; i
++) {
184 /* XXX steering - use an irqmap array? */
186 adm5120_intrtab
[i
].intr_refcnt
= 0;
187 evcnt_attach_dynamic(&adm5120_intrtab
[i
].intr_count
,
188 EVCNT_TYPE_INTR
, NULL
, "adm5120", adm5120_intrnames
[i
]);
191 /* disable all interrupts */
192 REG_WRITE(ICU_DISABLE_REG
, ICU_INT_MASK
);
196 adm5120_intr_establish(int irq
, int priority
, int (*func
)(void *), void *arg
)
198 struct evbmips_intrhand
*ih
;
202 if (irq
< 0 || irq
>= NIRQS
)
203 panic("adm5120_intr_establish: bogus IRQ %d", irq
);
205 ih
= malloc(sizeof(*ih
), M_DEVBUF
, M_NOWAIT
);
216 * First, link it into the tables.
217 * XXX do we want a separate list (really, should only be one item, not
218 * a list anyway) per irq, not per CPU interrupt?
221 cpu_int
= (priority
== INTR_FIQ
) ? 1 : 0;
223 LIST_INSERT_HEAD(&adm5120_cpuintrs
[cpu_int
].cintr_list
, ih
, ih_q
);
228 if (adm5120_intrtab
[irq
].intr_refcnt
++ == 0) {
231 /* configure as IRQ or FIQ */
232 if (priority
== INTR_FIQ
) {
233 REG_WRITE(ICU_MODE_REG
,
234 REG_READ(ICU_MODE_REG
) | irqmask
);
236 REG_WRITE(ICU_MODE_REG
,
237 REG_READ(ICU_MODE_REG
) & ~irqmask
);
240 REG_WRITE(ICU_ENABLE_REG
, irqmask
);
248 adm5120_intr_disestablish(void *cookie
)
250 struct evbmips_intrhand
*ih
= cookie
;
259 * First, remove it from the table.
261 LIST_REMOVE(ih
, ih_q
);
264 * Now, disable it, if there is nothing remaining on the
267 if (adm5120_intrtab
[irq
].intr_refcnt
-- == 1) {
268 irqmask
= 1 << irq
; /* only used as a mask from here on */
270 /* disable this irq in HW */
271 REG_WRITE(ICU_DISABLE_REG
, irqmask
);
279 evbmips_iointr(uint32_t status
, uint32_t cause
, uint32_t pc
, uint32_t ipending
)
281 struct evbmips_intrhand
*ih
;
283 uint32_t irqmask
, irqstat
;
285 for (level
= NINTRS
- 1; level
>= 0; level
--) {
286 if ((ipending
& (MIPS_INT_MASK_0
<< level
)) == 0)
290 irqstat
= REG_READ(ICU_FIQ_STATUS_REG
);
292 irqstat
= REG_READ(ICU_STATUS_REG
);
294 adm5120_cpuintrs
[level
].cintr_count
.ev_count
++;
295 LIST_FOREACH(ih
, &adm5120_cpuintrs
[level
].cintr_list
, ih_q
) {
296 irqmask
= 1 << ih
->ih_irq
;
297 if (irqmask
& irqstat
) {
298 adm5120_intrtab
[ih
->ih_irq
].intr_count
.ev_count
++;
299 (*ih
->ih_func
)(ih
->ih_arg
);
302 cause
&= ~(MIPS_INT_MASK_0
<< level
);
305 /* Re-enable anything that we have processed. */
306 _splset(MIPS_SR_INT_IE
| ((status
& ~cause
) & MIPS_HARD_INT_MASK
));