machdep.c revision 1.1 1 /* $NetBSD: machdep.c,v 1.1 2003/03/05 22:08:27 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/gtvar.h>
102
103 /*
104 * Global variables used here and there
105 */
106 extern struct user *proc0paddr;
107
108 struct bat battable[16];
109
110 #define PMONMEMREGIONS 32
111 struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
112
113 char *bootpath;
114
115 paddr_t msgbuf_paddr;
116 vaddr_t msgbuf_vaddr;
117
118 paddr_t avail_end; /* XXX temporary */
119
120 void initppc(u_int, u_int, u_int, void *); /* Called from locore */
121 void strayintr(int);
122 int lcsplx(int);
123
124 cons_decl(gtmpsc);
125
126 struct consdev constab[] = {
127 cons_init_halt(gtmpsc),
128 { 0 }
129 };
130
131 extern void return_to_dink(int);
132
133 void
134 initppc(startkernel, endkernel, args, btinfo)
135 u_int startkernel, endkernel, args;
136 void *btinfo;
137 {
138 #ifdef DDB
139 extern void *startsym, *endsym;
140 #endif
141 extern vaddr_t gtbase;
142
143 #if 1
144 {
145 extern unsigned char edata[], end[];
146 struct cpu_info tmp = cpu_info[0];
147 memset(edata, 0, end - edata);
148 cpu_info[0] = tmp;
149 }
150 #endif
151
152 gtbase = GT_BASE;
153
154 /*
155 * Hardcode 32MB for now--we should probe for this or get it
156 * from a boot loader, but for now, we are booting via an
157 * S-record loader.
158 */
159 { /* XXX AKB */
160 u_int32_t physmemsize;
161
162 physmemsize = 64 * 1024 * 1024;
163 physmemr[0].start = 0;
164 physmemr[0].size = physmemsize;
165 physmemr[1].size = 0;
166 availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET;
167 availmemr[0].size = physmemsize - availmemr[0].start;
168 availmemr[1].size = 0;
169 }
170 avail_end = physmemr[0].start + physmemr[0].size; /* XXX temporary */
171
172 /*
173 * Get CPU clock
174 */
175 { /* XXX AKB */
176 extern u_long ticks_per_sec, ns_per_tick;
177 extern void calc_delayconst(void);
178
179 ticks_per_sec = 100000000; /* 100 MHz */
180 /* ticks_per_sec = 66000000; * 66 MHz */
181 ticks_per_sec /= 4; /* 4 cycles per DEC tick */
182 cpu_timebase = ticks_per_sec;
183 ns_per_tick = 1000000000 / ticks_per_sec;
184 calc_delayconst();
185 }
186
187 /*
188 * boothowto
189 */
190 boothowto = RB_SINGLE;
191
192 ev64260_bus_space_init();
193
194 oea_batinit(0x10000000, BAT_BL_256M,
195 0x80000000, BAT_BL_256M,
196 0xf0000000, BAT_BL_256M);
197 oea_init((void (*)(void))ext_intr);
198
199 cninit();
200
201 #if (NISA > 0)
202 isa_intr_init();
203 #endif
204
205 /*
206 * Set the page size.
207 */
208 uvm_setpagesize();
209
210 /*
211 * Initialize pmap module.
212 */
213 pmap_bootstrap(startkernel, endkernel);
214
215 #ifdef DDB
216 ddb_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
217 #endif
218 #ifdef IPKDB
219 /*
220 * Now trap to IPKDB
221 */
222 ipkdb_init();
223 if (boothowto & RB_KDB)
224 ipkdb_connect(0);
225 #endif
226 }
227
228 void
229 mem_regions(mem, avail)
230 struct mem_region **mem, **avail;
231 {
232 *mem = physmemr;
233 *avail = availmemr;
234 }
235
236 /*
237 * Machine dependent startup code.
238 */
239 void
240 cpu_startup()
241 {
242 register_t msr;
243
244 oea_startup(NULL);
245
246 /*
247 * Now that we have VM, malloc()s are OK in bus_space.
248 */
249 ev64260_bus_space_mallocok();
250
251 /*
252 * Now allow hardware interrupts.
253 */
254 splhigh();
255 __asm __volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
256 : "=r"(msr)
257 : "K"(PSL_EE));
258 }
259
260 /*
261 * consinit
262 * Initialize system console.
263 */
264 void
265 consinit()
266 {
267 cninit();
268 }
269
270 #if (NPCKBC > 0) && (NPCKBD == 0)
271 /*
272 * glue code to support old console code with the
273 * mi keyboard controller driver
274 */
275 int
276 pckbc_machdep_cnattach(kbctag, kbcslot)
277 pckbc_tag_t kbctag;
278 pckbc_slot_t kbcslot;
279 {
280 #if (NPC > 0)
281 return (pcconskbd_cnattach(kbctag, kbcslot));
282 #else
283 return (ENXIO);
284 #endif
285 }
286 #endif
287
288 /*
289 * Stray interrupts.
290 */
291 void
292 strayintr(int irq)
293 {
294 log(LOG_ERR, "stray interrupt %d\n", irq);
295 }
296
297 /*
298 * Halt or reboot the machine after syncing/dumping according to howto.
299 */
300 void
301 cpu_reboot(howto, what)
302 int howto;
303 char *what;
304 {
305 static int syncing;
306 static char str[256];
307 char *ap = str, *ap1 = ap;
308
309 boothowto = howto;
310 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
311 syncing = 1;
312 vfs_shutdown(); /* sync */
313 resettodr(); /* set wall clock */
314 }
315 splhigh();
316 if (howto & RB_HALT) {
317 doshutdownhooks();
318 printf("halted\n\n");
319 cnhalt();
320 while(1);
321 }
322 if (!cold && (howto & RB_DUMP))
323 oea_dumpsys();
324 doshutdownhooks();
325 printf("rebooting\n\n");
326 if (what && *what) {
327 if (strlen(what) > sizeof str - 5)
328 printf("boot string too large, ignored\n");
329 else {
330 strcpy(str, what);
331 ap1 = ap = str + strlen(str);
332 *ap++ = ' ';
333 }
334 }
335 *ap++ = '-';
336 if (howto & RB_SINGLE)
337 *ap++ = 's';
338 if (howto & RB_KDB)
339 *ap++ = 'd';
340 *ap++ = 0;
341 if (ap[-2] == '-')
342 *ap1 = 0;
343 #if 0
344 {
345 void mvpppc_reboot(void);
346 mvpppc_reboot();
347 }
348 #endif
349 gt_watchdog_reset();
350 /* NOTREACHED */
351 while (1);
352 }
353
354 int
355 lcsplx(ipl)
356 int ipl;
357 {
358 return spllower(ipl);
359 }
360
361 int
362 gtget_macaddr(struct gt_softc *gt, int macno, char *enaddr)
363 {
364 enaddr[0] = 0x02;
365 enaddr[1] = 0x00;
366 enaddr[2] = 0x04;
367 enaddr[3] = 0x00;
368 enaddr[4] = 0x00;
369 enaddr[5] = 0x04 + macno;
370
371 return 0;
372 }
373