1 /* $NetBSD: interrupt.c,v 1.19 2011/07/09 17:32:30 matt Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: interrupt.c,v 1.19 2011/07/09 17:32:30 matt Exp $");
34
35 #include <sys/param.h>
36 #include <sys/device.h>
37 #include <sys/cpu.h>
38 #include <sys/intr.h>
39 #include <sys/proc.h>
40
41 #include <mips/locore.h>
42 #include <mips/psl.h>
43 #include <mips/regnum.h>
44
45 #include <pmax/autoconf.h>
46 #include <pmax/sysconf.h>
47
48 struct evcnt pmax_clock_evcnt =
49 EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "clock", "intr");
50 EVCNT_ATTACH_STATIC(pmax_clock_evcnt);
51 #ifndef NOFPU
52 struct evcnt pmax_fpu_evcnt =
53 EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "fpu", "intr");
54 EVCNT_ATTACH_STATIC(pmax_fpu_evcnt);
55 #endif
56 struct evcnt pmax_memerr_evcnt =
57 EVCNT_INITIALIZER(EVCNT_TYPE_INTR, NULL, "memerr", "intr");
58 EVCNT_ATTACH_STATIC(pmax_memerr_evcnt);
59
60 static const char * const intrnames[] = {
61 "serial0",
62 "serial1",
63 "ether",
64 "scsi",
65 "optslot0",
66 "optslot1",
67 "optslot2",
68 "dtop",
69 "isdn",
70 "floppy"
71 };
72
73 void
intr_init(void)74 intr_init(void)
75 {
76 int i;
77
78 for (i = 0; i < MAX_DEV_NCOOKIES; i++)
79 evcnt_attach_dynamic(&intrtab[i].ih_count, EVCNT_TYPE_INTR,
80 NULL, "pmax", intrnames[i]);
81 }
82
83 /*
84 * pmax uses standard mips1 convention, wiring FPU to hard interrupt 5.
85 */
86 void
cpu_intr(int ppl,vaddr_t pc,uint32_t status)87 cpu_intr(int ppl, vaddr_t pc, uint32_t status)
88 {
89 int ipl;
90 uint32_t pending;
91
92 curcpu()->ci_data.cpu_nintr++;
93
94 while (ppl < (ipl = splintr(&pending))) {
95 /* device interrupts */
96 if (pending & (MIPS_INT_MASK_0|MIPS_INT_MASK_1|MIPS_INT_MASK_2|
97 MIPS_INT_MASK_3|MIPS_INT_MASK_4)) {
98 (*platform.iointr)(status, pc, pending);
99 }
100 #if !defined(NOFPU)
101 /* FPU notification */
102 if (pending & MIPS_INT_MASK_5) {
103 if (!USERMODE(status))
104 panic("kernel used FPU: "
105 "PC %#"PRIxVADDR", SR %#x", pc, status);
106
107 pmax_fpu_evcnt.ev_count++;
108 mips_fpu_intr(pc, curlwp->l_md.md_utf);
109 }
110 #endif
111 }
112 }
113