vr.c revision 1.3 1 /* $NetBSD: vr.c,v 1.3 1999/10/24 08:37:30 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
41 #include <machine/cpu.h>
42 #include <machine/intr.h>
43 #include <machine/reg.h>
44 #include <machine/psl.h>
45 #include <machine/locore.h>
46 #include <machine/sysconf.h>
47 #include <machine/bus.h>
48 #include <machine/autoconf.h>
49
50 #include <mips/mips_param.h> /* hokey spl()s */
51 #include <mips/mips/mips_mcclock.h> /* mcclock CPUspeed estimation */
52
53 #include <hpcmips/vr/vr.h>
54 #include <hpcmips/vr/vripreg.h>
55 #include <hpcmips/vr/rtcreg.h>
56 #include <hpcmips/hpcmips/machdep.h> /* XXXjrs replace with vectors */
57 #include <machine/bootinfo.h>
58
59 #include "com.h"
60 #if NCOM > 0
61 #include <sys/termios.h>
62 #include <sys/ttydefaults.h>
63 #include <dev/ic/comreg.h>
64 #include <dev/ic/comvar.h>
65 #include <hpcmips/vr/siureg.h>
66 #include <hpcmips/vr/com_vripvar.h>
67 #ifndef CONSPEED
68 #define CONSPEED TTYDEF_SPEED
69 #endif
70 #endif
71
72 #include "fb.h"
73 #include "vrkiu.h"
74 #if NFB > 0 || NVRKIU > 0
75 #include <dev/rcons/raster.h>
76 #include <dev/wscons/wsdisplayvar.h>
77 #endif
78
79 #if NFB > 0
80 #include <arch/hpcmips/dev/fbvar.h>
81 #endif
82
83 #if NFB > 0
84 #include <arch/hpcmips/vr/vrkiuvar.h>
85 #endif
86
87 void vr_init __P((void));
88 void vr_os_init __P((void));
89 void vr_bus_reset __P((void));
90 int vr_intr __P((u_int32_t mask, u_int32_t pc, u_int32_t statusReg, u_int32_t causeReg));
91 void vr_cons_init __P((void));
92 void vr_device_register __P((struct device *, void *));
93
94 char *vrbcu_vrip_getcpuname __P((void));
95 int vrbcu_vrip_getcpumajor __P((void));
96 int vrbcu_vrip_getcpuminor __P((void));
97
98 extern unsigned nullclkread __P((void));
99 extern unsigned (*clkread) __P((void));
100
101 /*
102 * CPU interrupt dispatch table (HwInt[0:3])
103 */
104 int null_handler __P((void*, u_int32_t, u_int32_t));
105 static int (*intr_handler[4]) __P((void*, u_int32_t, u_int32_t)) =
106 {
107 null_handler,
108 null_handler,
109 null_handler,
110 null_handler
111 };
112 static void *intr_arg[4];
113
114 void
115 vr_init()
116 {
117 /*
118 * Platform Information.
119 */
120
121 /*
122 * Platform Specific Function Hooks
123 */
124 platform.os_init = vr_os_init;
125 platform.bus_reset = vr_bus_reset;
126 platform.cons_init = vr_cons_init;
127 platform.device_register = vr_device_register;
128
129 sprintf(cpu_model, "NEC %s rev%d.%d",
130 vrbcu_vrip_getcpuname(),
131 vrbcu_vrip_getcpumajor(),
132 vrbcu_vrip_getcpuminor());
133 }
134
135 void
136 vr_os_init()
137 {
138 /*
139 * Set up interrupt handling and I/O addresses.
140 */
141 mips_hardware_intr = vr_intr;
142
143 splvec.splbio = MIPS_SPL0;
144 splvec.splnet = MIPS_SPL0;
145 splvec.spltty = MIPS_SPL0;
146 splvec.splimp = MIPS_SPL0;
147 splvec.splclock = MIPS_SPL_0_1;
148 splvec.splstatclock = MIPS_SPL_0_1;
149
150 /* no high resolution timer circuit; possibly never called */
151 clkread = nullclkread;
152
153 #ifdef NOT_YET
154 mcclock_addr = (volatile struct chiptime *)
155 MIPS_PHYS_TO_KSEG1(Vr_SYS_CLOCK);
156 mc_cpuspeed(mcclock_addr, MIPS_INT_MASK_1);
157 #else
158 printf("%s(%d): cpuspeed estimation is notimplemented\n",
159 __FILE__, __LINE__);
160 #endif
161 #ifdef HPCMIPS_L1CACHE_DISABLE
162 cpuspeed = 1; /* XXX, CPU is very very slow because L1 cache is */
163 /* disabled. */
164 #endif /* HPCMIPS_L1CAHCE_DISABLE */
165 }
166
167
168 /*
169 * Initalize the memory system and I/O buses.
170 */
171 void
172 vr_bus_reset()
173 {
174 printf("%s(%d): vr_bus_reset() not implemented.\n",
175 __FILE__, __LINE__);
176 }
177
178 void
179 vr_cons_init()
180 {
181 #if NCOM > 0 || NFB > 0 || NVRKIU > 0
182 extern bus_space_tag_t system_bus_iot;
183 extern bus_space_tag_t mb_bus_space_init __P((void));
184 #endif
185
186 #if NCOM > 0
187 if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
188 /* Serial console */
189 mb_bus_space_init(); /* At this time, not initialized yet */
190 if(com_vrip_cnattach(system_bus_iot, 0x0c000000, CONSPEED,
191 VRCOM_FREQ,
192 (TTYDEF_CFLAG & ~(CSIZE | PARENB)) | CS8)) {
193 printf("%s(%d): can't init serial console", __FILE__, __LINE__);
194 } else {
195 return;
196 }
197 }
198 #endif
199
200 #if NFB > 0
201 mb_bus_space_init(); /* At this time, not initialized yet */
202 if(fb_cnattach(system_bus_iot, 0x0c000000, 0, 0)) {
203 printf("%s(%d): can't init fb console", __FILE__, __LINE__);
204 } else {
205 goto find_keyboard;
206 }
207 #endif
208
209 find_keyboard:
210 #if NVRKIU > 0
211 if (vrkiu_cnattach(system_bus_iot, VRIP_KIU_ADDR)) {
212 printf("%s(%d): can't init vrkiu as console",
213 __FILE__, __LINE__);
214 } else {
215 return;
216 }
217 #endif
218 }
219
220 void
221 vr_device_register(dev, aux)
222 struct device *dev;
223 void *aux;
224 {
225 printf("%s(%d): vr_device_register() not implemented.\n",
226 __FILE__, __LINE__);
227 panic("abort");
228 }
229
230 void *
231 vr_intr_establish(line, ih_fun, ih_arg)
232 int line;
233 int (*ih_fun) __P((void*, u_int32_t, u_int32_t));
234 void *ih_arg;
235 {
236 if (intr_handler[line] != null_handler) {
237 panic("vr_intr_establish: can't establish duplicated intr handler.");
238 }
239 intr_handler[line] = ih_fun;
240 intr_arg[line] = ih_arg;
241
242 return (void*)line;
243 }
244
245
246 void
247 vr_intr_disestablish(ih)
248 void *ih;
249 {
250 int line = (int)ih;
251 intr_handler[line] = null_handler;
252 intr_arg[line] = NULL;
253 }
254
255 int
256 null_handler(arg, pc, statusReg)
257 void *arg;
258 u_int32_t pc;
259 u_int32_t statusReg;
260 {
261 printf("null_handler\n");
262 return 0;
263 }
264
265 /*
266 * Handle interrupts.
267 */
268 int
269 vr_intr(mask, pc, status, cause)
270 u_int32_t mask;
271 u_int32_t pc;
272 u_int32_t status;
273 u_int32_t cause;
274 {
275 int hwintr;
276
277 hwintr = (ffs(mask >> 10) -1) & 0x3;
278 (*intr_handler[hwintr])(intr_arg[hwintr], pc, status);
279 return (MIPS_SR_INT_IE | (status & ~cause & MIPS_HARD_INT_MASK));
280 }
281