vr.c revision 1.5 1 /* $NetBSD: vr.c,v 1.5 1999/11/28 04:29:39 takemura Exp $ */
2
3 /*-
4 * Copyright (c) 1999
5 * Shin Takemura and PocketBSD Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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 copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the PocketBSD project
18 * and its contributors.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/reboot.h>
41
42 #include <machine/cpu.h>
43 #include <machine/intr.h>
44 #include <machine/reg.h>
45 #include <machine/psl.h>
46 #include <machine/locore.h>
47 #include <machine/sysconf.h>
48 #include <machine/bus.h>
49 #include <machine/autoconf.h>
50
51 #include <mips/mips_param.h> /* hokey spl()s */
52 #include <mips/mips/mips_mcclock.h> /* mcclock CPUspeed estimation */
53
54 #include <hpcmips/vr/vr.h>
55 #include <hpcmips/vr/vripreg.h>
56 #include <hpcmips/vr/rtcreg.h>
57 #include <hpcmips/hpcmips/machdep.h> /* XXXjrs replace with vectors */
58 #include <machine/bootinfo.h>
59
60 #include "vrdsu.h"
61 #if NVRDSU > 0
62 #include <hpcmips/vr/vrdsuvar.h>
63 #endif
64
65 #include "com.h"
66 #if NCOM > 0
67 #include <sys/termios.h>
68 #include <sys/ttydefaults.h>
69 #include <dev/ic/comreg.h>
70 #include <dev/ic/comvar.h>
71 #include <hpcmips/vr/siureg.h>
72 #include <hpcmips/vr/com_vripvar.h>
73 #ifndef CONSPEED
74 #define CONSPEED TTYDEF_SPEED
75 #endif
76 #endif
77
78 #include "fb.h"
79 #include "vrkiu.h"
80 #if NFB > 0 || NVRKIU > 0
81 #include <dev/rcons/raster.h>
82 #include <dev/wscons/wsdisplayvar.h>
83 #endif
84
85 #if NFB > 0
86 #include <arch/hpcmips/dev/fbvar.h>
87 #endif
88
89 #if NFB > 0
90 #include <arch/hpcmips/vr/vrkiuvar.h>
91 #endif
92
93 void vr_init __P((void));
94 void vr_os_init __P((void));
95 void vr_bus_reset __P((void));
96 int vr_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
97 void vr_cons_init __P((void));
98 void vr_device_register __P((struct device *, void *));
99 void vr_fb_init __P((caddr_t*));
100 int vr_mem_init __P((caddr_t));
101 void vr_reboot __P((int howto, char *bootstr));
102
103 char *vrbcu_vrip_getcpuname __P((void));
104 int vrbcu_vrip_getcpumajor __P((void));
105 int vrbcu_vrip_getcpuminor __P((void));
106
107 extern unsigned nullclkread __P((void));
108 extern unsigned (*clkread) __P((void));
109
110 /*
111 * CPU interrupt dispatch table (HwInt[0:3])
112 */
113 int null_handler __P((void*, u_int32_t, u_int32_t));
114 static int (*intr_handler[4]) __P((void*, u_int32_t, u_int32_t)) =
115 {
116 null_handler,
117 null_handler,
118 null_handler,
119 null_handler
120 };
121 static void *intr_arg[4];
122
123 void
124 vr_init()
125 {
126 /*
127 * Platform Information.
128 */
129
130 /*
131 * Platform Specific Function Hooks
132 */
133 platform.os_init = vr_os_init;
134 platform.bus_reset = vr_bus_reset;
135 platform.cons_init = vr_cons_init;
136 platform.device_register = vr_device_register;
137 platform.fb_init = vr_fb_init;
138 platform.mem_init = vr_mem_init;
139 platform.reboot = vr_reboot;
140
141 sprintf(cpu_model, "NEC %s rev%d.%d",
142 vrbcu_vrip_getcpuname(),
143 vrbcu_vrip_getcpumajor(),
144 vrbcu_vrip_getcpuminor());
145 }
146
147 int
148 vr_mem_init(kernend)
149 caddr_t kernend; /* kseg0 */
150 {
151 u_int32_t startaddr, endaddr, page;
152 int npage;
153 #define VR41_SYSADDR_DRAMSTART 0x0
154 #define VR41_SYSADDR_DRAM_LEN 0x04000000
155 startaddr = MIPS_PHYS_TO_KSEG1(
156 (btoc((u_int32_t)kernend - MIPS_KSEG0_START)) << PGSHIFT);
157 endaddr = MIPS_PHYS_TO_KSEG1(VR41_SYSADDR_DRAMSTART +
158 VR41_SYSADDR_DRAM_LEN);
159 for(page = startaddr, npage = 0; page < endaddr;
160 page+= NBPG, npage++) {
161 if (badaddr((char*)page, 4))
162 break;
163 ((volatile int *)page)[0] = 0xa5a5a5a5;
164 ((volatile int *)page)[4] = 0x5a5a5a5a;
165 wbflush();
166 if (*(volatile int *)page != 0xa5a5a5a5)
167 break;
168 }
169 /* Clear currently unused D-RAM area (For reboot Windows CE clearly)*/
170 memset((void*)startaddr, 0, npage * NBPG);
171 memset((void*)(KERNBASE + 0x400), 0, KERNTEXTOFF - KERNBASE - 0x800);
172
173 return npage;
174 }
175
176 void
177 vr_fb_init(kernend)
178 caddr_t *kernend;
179 {
180 /* Nothing to do */
181 }
182
183 void
184 vr_os_init()
185 {
186 /*
187 * Set up interrupt handling and I/O addresses.
188 */
189 mips_hardware_intr = vr_intr;
190
191 splvec.splbio = MIPS_SPL0;
192 splvec.splnet = MIPS_SPL0;
193 splvec.spltty = MIPS_SPL0;
194 splvec.splimp = MIPS_SPL0;
195 splvec.splclock = MIPS_SPL_0_1;
196 splvec.splstatclock = MIPS_SPL_0_1;
197
198 /* no high resolution timer circuit; possibly never called */
199 clkread = nullclkread;
200
201 #ifdef NOT_YET
202 mcclock_addr = (volatile struct chiptime *)
203 MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
204 mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
205 #else
206 printf("%s(%d): cpuspeed estimation is notimplemented\n",
207 __FILE__, __LINE__);
208 #endif
209 #ifdef HPCMIPS_L1CACHE_DISABLE
210 cpuspeed = 1; /* XXX, CPU is very very slow because L1 cache is */
211 /* disabled. */
212 #endif /* HPCMIPS_L1CAHCE_DISABLE */
213 }
214
215
216 /*
217 * Initalize the memory system and I/O buses.
218 */
219 void
220 vr_bus_reset()
221 {
222 printf("%s(%d): vr_bus_reset() not implemented.\n",
223 __FILE__, __LINE__);
224 }
225
226 void
227 vr_cons_init()
228 {
229 #if NCOM > 0 || NFB > 0 || NVRKIU > 0
230 extern bus_space_tag_t system_bus_iot;
231 extern bus_space_tag_t mb_bus_space_init __P((void));
232 #endif
233
234 #if NCOM > 0
235 if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
236 /* Serial console */
237 mb_bus_space_init(); /* At this time, not initialized yet */
238 if(com_vrip_cnattach(system_bus_iot, 0x0c000000, CONSPEED,
239 VRCOM_FREQ,
240 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
241 printf("%s(%d): can't init serial console", __FILE__, __LINE__);
242 } else {
243 return;
244 }
245 }
246 #endif
247
248 #if NFB > 0
249 mb_bus_space_init(); /* At this time, not initialized yet */
250 if(fb_cnattach(system_bus_iot, 0x0c000000, 0, 0)) {
251 printf("%s(%d): can't init fb console", __FILE__, __LINE__);
252 } else {
253 goto find_keyboard;
254 }
255 #endif
256
257 find_keyboard:
258 #if NVRKIU > 0
259 if (vrkiu_cnattach(system_bus_iot, VRIP_KIU_ADDR)) {
260 printf("%s(%d): can't init vrkiu as console",
261 __FILE__, __LINE__);
262 } else {
263 return;
264 }
265 #endif
266 }
267
268 void
269 vr_device_register(dev, aux)
270 struct device *dev;
271 void *aux;
272 {
273 printf("%s(%d): vr_device_register() not implemented.\n",
274 __FILE__, __LINE__);
275 panic("abort");
276 }
277
278 void
279 vr_reboot(howto, bootstr)
280 int howto;
281 char *bootstr;
282 {
283 splhigh();
284 if ( !(howto & RB_HALT)) {
285 #if NVRDSU
286 vrdsu_reset();
287 #else
288 printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
289 #endif
290 }
291 while (1);
292 }
293
294 void *
295 vr_intr_establish(line, ih_fun, ih_arg)
296 int line;
297 int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
298 void *ih_arg;
299 {
300 if (intr_handler[line] != null_handler) {
301 panic("vr_intr_establish: can't establish duplicated intr handler.");
302 }
303 intr_handler[line] = ih_fun;
304 intr_arg[line] = ih_arg;
305
306 return (void*)line;
307 }
308
309
310 void
311 vr_intr_disestablish(ih)
312 void *ih;
313 {
314 int line = (int)ih;
315 intr_handler[line] = null_handler;
316 intr_arg[line] = NULL;
317 }
318
319 int
320 null_handler(arg, pc, statusReg)
321 void *arg;
322 u_int32_t pc;
323 u_int32_t statusReg;
324 {
325 printf("null_handler\n");
326 return 0;
327 }
328
329 /*
330 * Handle interrupts.
331 */
332 int
333 vr_intr(mask, pc, status, cause)
334 u_int32_t mask;
335 u_int32_t pc;
336 u_int32_t status;
337 u_int32_t cause;
338 {
339 int hwintr;
340
341 hwintr = (ffs(mask >> 10) -1) & 0x3;
342 (*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
343 return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
344 }
345