news5000.c revision 1.16 1 1.16 tsutsui /* $NetBSD: news5000.c,v 1.16 2006/09/13 14:50:42 tsutsui Exp $ */
2 1.1 tsubai
3 1.1 tsubai /*-
4 1.1 tsubai * Copyright (C) 1999 SHIMIZU Ryo. All rights reserved.
5 1.1 tsubai *
6 1.1 tsubai * Redistribution and use in source and binary forms, with or without
7 1.1 tsubai * modification, are permitted provided that the following conditions
8 1.1 tsubai * are met:
9 1.1 tsubai * 1. Redistributions of source code must retain the above copyright
10 1.1 tsubai * notice, this list of conditions and the following disclaimer.
11 1.1 tsubai * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 tsubai * notice, this list of conditions and the following disclaimer in the
13 1.1 tsubai * documentation and/or other materials provided with the distribution.
14 1.1 tsubai * 3. The name of the author may not be used to endorse or promote products
15 1.1 tsubai * derived from this software without specific prior written permission.
16 1.1 tsubai *
17 1.1 tsubai * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 tsubai * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 tsubai * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 tsubai * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 tsubai * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 tsubai * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 tsubai * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 tsubai * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 tsubai * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 1.1 tsubai * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 tsubai */
28 1.11 lukem
29 1.11 lukem #include <sys/cdefs.h>
30 1.16 tsutsui __KERNEL_RCSID(0, "$NetBSD: news5000.c,v 1.16 2006/09/13 14:50:42 tsutsui Exp $");
31 1.1 tsubai
32 1.1 tsubai #include <sys/param.h>
33 1.1 tsubai #include <sys/systm.h>
34 1.1 tsubai #include <sys/kernel.h>
35 1.16 tsutsui #include <sys/timetc.h>
36 1.1 tsubai
37 1.1 tsubai #include <machine/adrsmap.h>
38 1.1 tsubai #include <machine/cpu.h>
39 1.1 tsubai #include <machine/intr.h>
40 1.1 tsubai
41 1.1 tsubai #include <newsmips/apbus/apbusvar.h>
42 1.1 tsubai #include <newsmips/newsmips/machid.h>
43 1.1 tsubai
44 1.9 tsutsui static void news5000_level1_intr(void);
45 1.9 tsutsui static void news5000_level0_intr(void);
46 1.7 matt
47 1.9 tsutsui static void news5000_enable_intr(void);
48 1.9 tsutsui static void news5000_disable_intr(void);
49 1.12 tsutsui static void news5000_enable_timer(void);
50 1.14 tsutsui static void news5000_readidrom(uint8_t *);
51 1.16 tsutsui static void news5000_tc_init(void);
52 1.16 tsutsui static uint32_t news5000_getfreerun(struct timecounter *);
53 1.6 onoe
54 1.1 tsubai /*
55 1.1 tsubai * Handle news5000 interrupts.
56 1.1 tsubai */
57 1.4 tsubai void
58 1.14 tsutsui news5000_intr(uint32_t status, uint32_t cause, uint32_t pc, uint32_t ipending)
59 1.1 tsubai {
60 1.4 tsubai if (ipending & MIPS_INT_MASK_2) {
61 1.2 tsubai #ifdef DEBUG
62 1.2 tsubai static int l2cnt = 0;
63 1.2 tsubai #endif
64 1.14 tsutsui uint32_t int2stat;
65 1.2 tsubai struct clockframe cf;
66 1.2 tsubai
67 1.14 tsutsui int2stat = *(volatile uint32_t *)NEWS5000_INTST2;
68 1.2 tsubai
69 1.2 tsubai #ifdef DEBUG
70 1.2 tsubai l2cnt++;
71 1.2 tsubai if (l2cnt == 50) {
72 1.14 tsutsui *(volatile uint32_t *)NEWS5000_LED_SEC = 1;
73 1.2 tsubai }
74 1.2 tsubai if (l2cnt == 100) {
75 1.14 tsutsui *(volatile uint32_t *)NEWS5000_LED_SEC = 0;
76 1.2 tsubai l2cnt = 0;
77 1.2 tsubai }
78 1.2 tsubai #endif
79 1.2 tsubai
80 1.2 tsubai if (int2stat & NEWS5000_INT2_TIMER0) {
81 1.14 tsutsui *(volatile uint32_t *)NEWS5000_TIMER0 = 1;
82 1.2 tsubai
83 1.2 tsubai cf.pc = pc;
84 1.2 tsubai cf.sr = status;
85 1.2 tsubai
86 1.2 tsubai hardclock(&cf);
87 1.2 tsubai intrcnt[HARDCLOCK_INTR]++;
88 1.2 tsubai }
89 1.2 tsubai
90 1.1 tsubai apbus_wbflush();
91 1.2 tsubai cause &= ~MIPS_INT_MASK_2;
92 1.1 tsubai }
93 1.1 tsubai /* If clock interrupts were enabled, re-enable them ASAP. */
94 1.4 tsubai _splset(MIPS_SR_INT_IE | (status & MIPS_INT_MASK_2));
95 1.1 tsubai
96 1.4 tsubai if (ipending & MIPS_INT_MASK_5) {
97 1.14 tsutsui uint32_t int5stat;
98 1.14 tsutsui
99 1.14 tsutsui int5stat = *(volatile u_int *)NEWS5000_INTST5;
100 1.2 tsubai printf("level5 interrupt (%08x)\n", int5stat);
101 1.2 tsubai
102 1.1 tsubai apbus_wbflush();
103 1.2 tsubai cause &= ~MIPS_INT_MASK_5;
104 1.1 tsubai }
105 1.1 tsubai
106 1.4 tsubai if (ipending & MIPS_INT_MASK_4) {
107 1.14 tsutsui uint32_t int4stat;
108 1.14 tsutsui
109 1.14 tsutsui int4stat = *(volatile uint32_t *)NEWS5000_INTST4;
110 1.2 tsubai printf("level4 interrupt (%08x)\n", int4stat);
111 1.6 onoe if (int4stat & NEWS5000_INT4_APBUS) {
112 1.14 tsutsui uint32_t stat;
113 1.14 tsutsui
114 1.14 tsutsui stat = *(volatile uint32_t *)NEWS5000_APBUS_INTST;
115 1.6 onoe printf("APbus error 0x%04x\n", stat & 0xffff);
116 1.6 onoe if (stat & NEWS5000_APBUS_INT_DMAADDR) {
117 1.9 tsutsui printf("DMA Address Error: "
118 1.9 tsutsui "slot=%x, addr=0x%08x\n",
119 1.14 tsutsui *(volatile uint32_t *)NEWS5000_APBUS_DER_S,
120 1.14 tsutsui *(volatile uint32_t *)NEWS5000_APBUS_DER_A);
121 1.6 onoe }
122 1.6 onoe if (stat & NEWS5000_APBUS_INT_RDTIMEO)
123 1.6 onoe printf("IO Read Timeout: addr=0x%08x\n",
124 1.14 tsutsui *(volatile uint32_t *)NEWS5000_APBUS_BER_A);
125 1.6 onoe if (stat & NEWS5000_APBUS_INT_WRTIMEO)
126 1.6 onoe printf("IO Write Timeout: addr=0x%08x\n",
127 1.14 tsutsui *(volatile uint32_t *)NEWS5000_APBUS_BER_A);
128 1.14 tsutsui *(volatile uint32_t *)0xb4c00014 = stat;
129 1.6 onoe }
130 1.2 tsubai
131 1.1 tsubai apbus_wbflush();
132 1.2 tsubai cause &= ~MIPS_INT_MASK_4;
133 1.1 tsubai }
134 1.1 tsubai
135 1.4 tsubai if (ipending & MIPS_INT_MASK_3) {
136 1.14 tsutsui uint32_t int3stat;
137 1.14 tsutsui
138 1.14 tsutsui int3stat = *(volatile uint32_t *)NEWS5000_INTST3;
139 1.2 tsubai printf("level3 interrupt (%08x)\n", int3stat);
140 1.2 tsubai
141 1.1 tsubai apbus_wbflush();
142 1.2 tsubai cause &= ~MIPS_INT_MASK_3;
143 1.1 tsubai }
144 1.1 tsubai
145 1.4 tsubai if (ipending & MIPS_INT_MASK_1) {
146 1.9 tsutsui news5000_level1_intr();
147 1.1 tsubai apbus_wbflush();
148 1.2 tsubai cause &= ~MIPS_INT_MASK_1;
149 1.1 tsubai }
150 1.1 tsubai
151 1.4 tsubai if (ipending & MIPS_INT_MASK_0) {
152 1.9 tsutsui news5000_level0_intr();
153 1.1 tsubai apbus_wbflush();
154 1.2 tsubai cause &= ~MIPS_INT_MASK_0;
155 1.1 tsubai }
156 1.1 tsubai
157 1.4 tsubai _splset((status & ~cause & MIPS_HARD_INT_MASK) | MIPS_SR_INT_IE);
158 1.1 tsubai }
159 1.1 tsubai
160 1.1 tsubai
161 1.7 matt static void
162 1.9 tsutsui news5000_level1_intr(void)
163 1.1 tsubai {
164 1.14 tsutsui uint32_t int1stat;
165 1.1 tsubai
166 1.14 tsutsui int1stat = *(volatile uint32_t *)NEWS5000_INTST1;
167 1.1 tsubai
168 1.1 tsubai if (int1stat) {
169 1.10 tsutsui if (apbus_intr_dispatch(1, int1stat) == 0)
170 1.3 tsubai printf("level1_intr: no handler (mask 0x%04x)\n",
171 1.2 tsubai int1stat);
172 1.2 tsubai } else
173 1.1 tsubai printf("level1 stray interrupt?\n");
174 1.1 tsubai }
175 1.1 tsubai
176 1.7 matt static void
177 1.9 tsutsui news5000_level0_intr(void)
178 1.1 tsubai {
179 1.14 tsutsui uint32_t int0stat;
180 1.1 tsubai
181 1.14 tsutsui int0stat = *(volatile uint32_t *)NEWS5000_INTST0;
182 1.1 tsubai
183 1.1 tsubai if (int0stat) {
184 1.10 tsutsui if (apbus_intr_dispatch(0, int0stat) == 0)
185 1.2 tsubai printf("level0_intr: no handler (mask 0x%04x)\n",
186 1.2 tsubai int0stat);
187 1.2 tsubai } else
188 1.1 tsubai printf("level0 stray interrupt?\n");
189 1.1 tsubai }
190 1.1 tsubai
191 1.7 matt static void
192 1.9 tsutsui news5000_enable_intr(void)
193 1.1 tsubai {
194 1.2 tsubai
195 1.6 onoe /* INT0 and INT1 has been enabled at attach */
196 1.6 onoe /* INT2 -- It's not a time to enable timer yet. */
197 1.6 onoe /* INT3 -- not used for NWS-5000 */
198 1.2 tsubai
199 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN4 = NEWS5000_INT4_APBUS;
200 1.14 tsutsui *(volatile uint32_t *)NEWS5000_APBUS_INTMSK = 0xffff;
201 1.2 tsubai
202 1.6 onoe /* INT5 -- currently ignored */
203 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN5 = 0;
204 1.1 tsubai }
205 1.1 tsubai
206 1.7 matt static void
207 1.9 tsutsui news5000_disable_intr(void)
208 1.1 tsubai {
209 1.9 tsutsui
210 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN0 = 0;
211 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN1 = 0;
212 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN2 = 0;
213 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN3 = 0;
214 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN4 = 0;
215 1.14 tsutsui *(volatile uint32_t *)NEWS5000_INTEN5 = 0;
216 1.1 tsubai }
217 1.1 tsubai
218 1.7 matt static void
219 1.12 tsutsui news5000_enable_timer(void)
220 1.12 tsutsui {
221 1.12 tsutsui
222 1.16 tsutsui news5000_tc_init();
223 1.16 tsutsui
224 1.12 tsutsui /* enable timer interrpt */
225 1.13 tsutsui *(volatile uint32_t *)NEWS5000_INTEN2 = NEWS5000_INT2_TIMER0;
226 1.12 tsutsui }
227 1.12 tsutsui
228 1.16 tsutsui static uint32_t
229 1.16 tsutsui news5000_getfreerun(struct timecounter *tc)
230 1.16 tsutsui {
231 1.16 tsutsui return *(volatile uint32_t *)NEWS5000_FREERUN;
232 1.16 tsutsui }
233 1.16 tsutsui
234 1.12 tsutsui static void
235 1.16 tsutsui news5000_tc_init(void)
236 1.6 onoe {
237 1.16 tsutsui static struct timecounter tc = {
238 1.16 tsutsui .tc_get_timecount = news5000_getfreerun,
239 1.16 tsutsui .tc_frequency = 1000000,
240 1.16 tsutsui .tc_counter_mask = ~0,
241 1.16 tsutsui .tc_name = "news5000_freerun",
242 1.16 tsutsui .tc_quality = 100,
243 1.16 tsutsui };
244 1.6 onoe
245 1.16 tsutsui tc_init(&tc);
246 1.6 onoe }
247 1.16 tsutsui
248 1.6 onoe
249 1.7 matt static void
250 1.14 tsutsui news5000_readidrom(uint8_t *rom)
251 1.1 tsubai {
252 1.13 tsutsui uint32_t *p = (void *)NEWS5000_IDROM;
253 1.1 tsubai int i;
254 1.1 tsubai
255 1.14 tsutsui for (i = 0; i < sizeof(struct idrom); i++, p += 2)
256 1.1 tsubai *rom++ = ((*p & 0x0f) << 4) + (*(p + 1) & 0x0f);
257 1.1 tsubai }
258 1.1 tsubai
259 1.1 tsubai extern struct idrom idrom;
260 1.1 tsubai
261 1.1 tsubai void
262 1.7 matt news5000_init(void)
263 1.1 tsubai {
264 1.1 tsubai
265 1.9 tsutsui enable_intr = news5000_enable_intr;
266 1.9 tsutsui disable_intr = news5000_disable_intr;
267 1.12 tsutsui enable_timer = news5000_enable_timer;
268 1.9 tsutsui
269 1.14 tsutsui news5000_readidrom((uint8_t *)&idrom);
270 1.5 tsubai hostid = idrom.id_serial;
271 1.8 tsutsui
272 1.8 tsutsui /* XXX reset uPD72067 FDC to avoid spurious interrupts */
273 1.8 tsutsui #define NEWS5000_FDC_FDOUT 0xbed20000
274 1.8 tsutsui #define FDO_FRST 0x04
275 1.13 tsutsui *(volatile uint8_t *)NEWS5000_FDC_FDOUT = FDO_FRST;
276 1.1 tsubai }
277