machdep.c revision 1.2 1 /* $NetBSD: machdep.c,v 1.2 2003/03/06 06:04:22 matt Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 * Copyright (C) 1995, 1996 TooLs GmbH.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by TooLs GmbH.
19 * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "opt_marvell.h"
35 #include "opt_compat_netbsd.h"
36 #include "opt_ddb.h"
37 #include "opt_inet.h"
38 #include "opt_ccitt.h"
39 #include "opt_iso.h"
40 #include "opt_ns.h"
41 #include "opt_ipkdb.h"
42
43 #include <sys/param.h>
44 #include <sys/conf.h>
45 #include <sys/device.h>
46 #include <sys/kernel.h>
47 #include <sys/malloc.h>
48 #include <sys/mount.h>
49 #include <sys/msgbuf.h>
50 #include <sys/proc.h>
51 #include <sys/reboot.h>
52 #include <sys/syslog.h>
53 #include <sys/systm.h>
54
55 #include <uvm/uvm.h>
56 #include <uvm/uvm_extern.h>
57
58 #include <net/netisr.h>
59
60 #include <machine/bus.h>
61 #include <machine/db_machdep.h>
62 #include <machine/intr.h>
63 #include <machine/pmap.h>
64 #include <machine/powerpc.h>
65 #include <machine/trap.h>
66
67 #include <powerpc/oea/bat.h>
68 #include <powerpc/marvell/watchdog.h>
69
70 #include <ddb/db_extern.h>
71
72 #include <dev/cons.h>
73
74 #include "vga.h"
75 #if (NVGA > 0)
76 #include <dev/ic/mc6845reg.h>
77 #include <dev/ic/pcdisplayvar.h>
78 #include <dev/ic/vgareg.h>
79 #include <dev/ic/vgavar.h>
80 #endif
81
82 #include "isa.h"
83 #if (NISA > 0)
84 void isa_intr_init(void);
85 #endif
86
87 #include "pckbc.h"
88 #if (NPCKBC > 0)
89 #include <dev/isa/isareg.h>
90 #include <dev/ic/i8042reg.h>
91 #include <dev/ic/pckbcvar.h>
92 #endif
93
94 #include "com.h"
95 #if (NCOM > 0)
96 #include <sys/termios.h>
97 #include <dev/ic/comreg.h>
98 #include <dev/ic/comvar.h>
99 #endif
100
101 #include <dev/marvell/gtreg.h>
102 #include <dev/marvell/gtvar.h>
103
104 /*
105 * Global variables used here and there
106 */
107 extern struct user *proc0paddr;
108
109 struct bat battable[16];
110
111 #define PMONMEMREGIONS 32
112 struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
113
114 char *bootpath;
115
116 paddr_t msgbuf_paddr;
117 vaddr_t msgbuf_vaddr;
118
119 paddr_t avail_end; /* XXX temporary */
120
121 void initppc(u_int, u_int, u_int, void *); /* Called from locore */
122 void strayintr(int);
123 int lcsplx(int);
124
125 cons_decl(gtmpsc);
126
127 struct consdev constab[] = {
128 cons_init_halt(gtmpsc),
129 { 0 }
130 };
131
132 extern void return_to_dink(int);
133
134 void
135 initppc(startkernel, endkernel, args, btinfo)
136 u_int startkernel, endkernel, args;
137 void *btinfo;
138 {
139 #ifdef DDB
140 extern void *startsym, *endsym;
141 #endif
142 extern vaddr_t gtbase;
143 volatile u_int32_t *gt = (volatile u_int32_t *) gtbase;
144
145 #if 1
146 {
147 extern unsigned char edata[], end[];
148 struct cpu_info tmp = cpu_info[0];
149 memset(edata, 0, end - edata);
150 cpu_info[0] = tmp;
151 }
152 #endif
153
154 /*
155 * Relocate Discovery to desired address.
156 */
157 if (gtbase != GT_BASE) {
158 u_int32_t v = inlrb(gt + GT_Internal_Decode);
159 outlrb(gt + GT_Internal_Decode,
160 (GT_BASE >> 20) | (v & ~0xffff));
161 gtbase = GT_BASE;
162 }
163 {
164 extern struct powerpc_bus_space ev64260_gt_mem_bs_tag;
165 ev64260_gt_mem_bs_tag.pbs_base = GT_BASE;
166 ev64260_gt_mem_bs_tag.pbs_limit = GT_BASE + 4096;
167 }
168
169 /*
170 * Hardcode 32MB for now--we should probe for this or get it
171 * from a boot loader, but for now, we are booting via an
172 * S-record loader.
173 */
174 { /* XXX AKB */
175 u_int32_t physmemsize;
176
177 physmemsize = 64 * 1024 * 1024;
178 physmemr[0].start = 0;
179 physmemr[0].size = physmemsize;
180 physmemr[1].size = 0;
181 availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET;
182 availmemr[0].size = physmemsize - availmemr[0].start;
183 availmemr[1].size = 0;
184 }
185 avail_end = physmemr[0].start + physmemr[0].size; /* XXX temporary */
186
187 /*
188 * Get CPU clock
189 */
190 { /* XXX AKB */
191 extern u_long ticks_per_sec, ns_per_tick;
192 extern void calc_delayconst(void);
193
194 ticks_per_sec = 100000000; /* 100 MHz */
195 /* ticks_per_sec = 66000000; * 66 MHz */
196 ticks_per_sec /= 4; /* 4 cycles per DEC tick */
197 cpu_timebase = ticks_per_sec;
198 ns_per_tick = 1000000000 / ticks_per_sec;
199 calc_delayconst();
200 }
201
202 /*
203 * boothowto
204 */
205 boothowto = RB_SINGLE;
206
207 ev64260_bus_space_init();
208
209 oea_batinit(0x80000000, BAT_BL_256M, 0xf0000000, BAT_BL_256M);
210 oea_init((void (*)(void))ext_intr);
211
212 cninit();
213
214 #if (NISA > 0)
215 isa_intr_init();
216 #endif
217
218 /*
219 * Set the page size.
220 */
221 uvm_setpagesize();
222
223 /*
224 * Initialize pmap module.
225 */
226 pmap_bootstrap(startkernel, endkernel);
227
228 #ifdef DDB
229 ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
230 #endif
231 #ifdef IPKDB
232 /*
233 * Now trap to IPKDB
234 */
235 ipkdb_init();
236 if (boothowto & RB_KDB)
237 ipkdb_connect(0);
238 #endif
239 }
240
241 void
242 mem_regions(mem, avail)
243 struct mem_region **mem, **avail;
244 {
245 *mem = physmemr;
246 *avail = availmemr;
247 }
248
249 /*
250 * Machine dependent startup code.
251 */
252 void
253 cpu_startup()
254 {
255 register_t msr;
256
257 oea_startup(NULL);
258
259 /*
260 * Now that we have VM, malloc()s are OK in bus_space.
261 */
262 ev64260_bus_space_mallocok();
263
264 /*
265 * Now allow hardware interrupts.
266 */
267 splhigh();
268 __asm __volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
269 : "=r"(msr)
270 : "K"(PSL_EE));
271 }
272
273 /*
274 * consinit
275 * Initialize system console.
276 */
277 void
278 consinit()
279 {
280 cninit();
281 }
282
283 #if (NPCKBC > 0) && (NPCKBD == 0)
284 /*
285 * glue code to support old console code with the
286 * mi keyboard controller driver
287 */
288 int
289 pckbc_machdep_cnattach(kbctag, kbcslot)
290 pckbc_tag_t kbctag;
291 pckbc_slot_t kbcslot;
292 {
293 #if (NPC > 0)
294 return (pcconskbd_cnattach(kbctag, kbcslot));
295 #else
296 return (ENXIO);
297 #endif
298 }
299 #endif
300
301 /*
302 * Stray interrupts.
303 */
304 void
305 strayintr(int irq)
306 {
307 log(LOG_ERR, "stray interrupt %d\n", irq);
308 }
309
310 /*
311 * Halt or reboot the machine after syncing/dumping according to howto.
312 */
313 void
314 cpu_reboot(howto, what)
315 int howto;
316 char *what;
317 {
318 static int syncing;
319 static char str[256];
320 char *ap = str, *ap1 = ap;
321
322 boothowto = howto;
323 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
324 syncing = 1;
325 vfs_shutdown(); /* sync */
326 resettodr(); /* set wall clock */
327 }
328 splhigh();
329 if (howto & RB_HALT) {
330 doshutdownhooks();
331 printf("halted\n\n");
332 cnhalt();
333 while(1);
334 }
335 if (!cold && (howto & RB_DUMP))
336 oea_dumpsys();
337 doshutdownhooks();
338 printf("rebooting\n\n");
339 if (what && *what) {
340 if (strlen(what) > sizeof str - 5)
341 printf("boot string too large, ignored\n");
342 else {
343 strcpy(str, what);
344 ap1 = ap = str + strlen(str);
345 *ap++ = ' ';
346 }
347 }
348 *ap++ = '-';
349 if (howto & RB_SINGLE)
350 *ap++ = 's';
351 if (howto & RB_KDB)
352 *ap++ = 'd';
353 *ap++ = 0;
354 if (ap[-2] == '-')
355 *ap1 = 0;
356 #if 0
357 {
358 void mvpppc_reboot(void);
359 mvpppc_reboot();
360 }
361 #endif
362 gt_watchdog_reset();
363 /* NOTREACHED */
364 while (1);
365 }
366
367 int
368 lcsplx(ipl)
369 int ipl;
370 {
371 return spllower(ipl);
372 }
373
374 int
375 gtget_macaddr(struct gt_softc *gt, int macno, char *enaddr)
376 {
377 enaddr[0] = 0x02;
378 enaddr[1] = 0x00;
379 enaddr[2] = 0x04;
380 enaddr[3] = 0x00;
381 enaddr[4] = 0x00;
382 enaddr[5] = 0x04 + macno;
383
384 return 0;
385 }
386