news5000.c revision 1.2 1 /* $NetBSD: news5000.c,v 1.2 1999/12/23 06:52:31 tsubai Exp $ */
2
3 /*-
4 * Copyright (C) 1999 SHIMIZU Ryo. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32
33 #include <machine/adrsmap.h>
34 #include <machine/cpu.h>
35 #include <machine/intr.h>
36
37 #include <newsmips/apbus/apbusvar.h>
38 #include <newsmips/newsmips/machid.h>
39
40 static void level1_intr __P((void));
41 static void level0_intr __P((void));
42
43 /*
44 * Handle news5000 interrupts.
45 */
46 int
47 news5000_intr(mask, pc, status, cause)
48 u_int mask;
49 u_int pc; /* program counter where to continue */
50 u_int status; /* status register at time of the exception */
51 u_int cause; /* cause register at time of exception */
52 {
53 if (mask & MIPS_INT_MASK_2) {
54 #ifdef DEBUG
55 static int l2cnt = 0;
56 #endif
57 u_int int2stat;
58 struct clockframe cf;
59
60 int2stat = *(volatile u_int *)NEWS5000_INTST2;
61
62 #ifdef DEBUG
63 l2cnt++;
64 if (l2cnt == 50) {
65 *(volatile u_int *)NEWS5000_LED_SEC = 1;
66 }
67 if (l2cnt == 100) {
68 *(volatile u_int *)NEWS5000_LED_SEC = 0;
69 l2cnt = 0;
70 }
71 #endif
72
73 if (int2stat & NEWS5000_INT2_TIMER0) {
74 *(volatile u_int *)NEWS5000_TIMER0 = 1;
75
76 cf.pc = pc;
77 cf.sr = status;
78
79 hardclock(&cf);
80 intrcnt[HARDCLOCK_INTR]++;
81 }
82
83 apbus_wbflush();
84 cause &= ~MIPS_INT_MASK_2;
85 }
86 /* If clock interrupts were enabled, re-enable them ASAP. */
87 splx(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_2));
88
89 if (mask & MIPS_INT_MASK_5) {
90 u_int int5stat = *(volatile u_int *)NEWS5000_INTST5;
91 printf("level5 interrupt (%08x)\n", int5stat);
92
93 apbus_wbflush();
94 cause &= ~MIPS_INT_MASK_5;
95 }
96
97 if (mask & MIPS_INT_MASK_4) {
98 u_int int4stat = *(volatile u_int *)NEWS5000_INTST4;
99 printf("level4 interrupt (%08x)\n", int4stat);
100
101 apbus_wbflush();
102 cause &= ~MIPS_INT_MASK_4;
103 }
104
105 if (mask & MIPS_INT_MASK_3) {
106 u_int int3stat = *(volatile u_int *)NEWS5000_INTST3;
107 printf("level3 interrupt (%08x)\n", int3stat);
108
109 apbus_wbflush();
110 cause &= ~MIPS_INT_MASK_3;
111 }
112
113 if (mask & MIPS_INT_MASK_1) {
114 level1_intr();
115 apbus_wbflush();
116 cause &= ~MIPS_INT_MASK_1;
117 }
118
119 if (mask & MIPS_INT_MASK_0) {
120 level0_intr();
121 apbus_wbflush();
122 cause &= ~MIPS_INT_MASK_0;
123 }
124
125 return (status & ~cause & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE;
126 }
127
128
129 void
130 level1_intr()
131 {
132 u_int int1stat;
133
134 int1stat = *(volatile u_int *)NEWS5000_INTST1;
135
136 if (int1stat) {
137 if (apbus_intr_call(1, int1stat) == 0)
138 printf("level1_intr: no andler (mask 0x%04x)\n",
139 int1stat);
140 } else
141 printf("level1 stray interrupt?\n");
142 }
143
144 void
145 level0_intr()
146 {
147 u_int int0stat;
148
149 int0stat = *(volatile u_int *)NEWS5000_INTST0;
150
151 if (int0stat) {
152 if (apbus_intr_call(0, int0stat) == 0)
153 printf("level0_intr: no handler (mask 0x%04x)\n",
154 int0stat);
155 } else
156 printf("level0 stray interrupt?\n");
157 }
158
159 void
160 enable_intr_5000()
161 {
162 volatile u_int *inten0 = (void *)NEWS5000_INTEN0;
163 volatile u_int *inten1 = (void *)NEWS5000_INTEN1;
164
165 *inten0 = NEWS5000_INT0_DMAC | NEWS5000_INT0_SONIC |
166 NEWS5000_INT0_FDC;
167 *inten1 = NEWS5000_INT1_KBD | NEWS5000_INT1_SCC |
168 NEWS5000_INT1_AUDIO0 | NEWS5000_INT1_AUDIO1 |
169 NEWS5000_INT1_PARALLEL | NEWS5000_INT1_FB;
170
171 /* It's not a time to enable timer yet. */
172 /* *(volatile u_int *)NEWS5000_INTEN2 = 0; */
173
174 /* currently INT3-INT5 are not used */
175 *(volatile u_int *)NEWS5000_INTEN3 = 0;
176 *(volatile u_int *)NEWS5000_INTEN4 = 0;
177 *(volatile u_int *)NEWS5000_INTEN5 = 0;
178 }
179
180 void
181 disable_intr_5000()
182 {
183 *(volatile u_int *)NEWS5000_INTEN0 = 0;
184 *(volatile u_int *)NEWS5000_INTEN1 = 0;
185 *(volatile u_int *)NEWS5000_INTEN2 = 0;
186 *(volatile u_int *)NEWS5000_INTEN3 = 0;
187 *(volatile u_int *)NEWS5000_INTEN4 = 0;
188 *(volatile u_int *)NEWS5000_INTEN5 = 0;
189 }
190
191 void
192 readidrom_5000(rom)
193 u_char *rom;
194 {
195 u_int32_t *p = (void *)NEWS5000_IDROM;
196 int i;
197
198 for (i = 0; i < sizeof (struct idrom); i++, p += 2)
199 *rom++ = ((*p & 0x0f) << 4) + (*(p + 1) & 0x0f);
200 }
201
202 extern struct idrom idrom;
203
204 void
205 news5000_init()
206 {
207 enable_intr = enable_intr_5000;
208 disable_intr = disable_intr_5000;
209
210 readidrom_5000((u_char *)&idrom);
211 }
212