Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / evbppc / obs405 / obs266_machdep.c
blobf4a03ffa0223e0009fa163c7a2d2cb13efd095d5
1 /* $NetBSD: obs266_machdep.c,v 1.9 2008/11/30 18:21:33 martin Exp $ */
2 /* Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $ */
4 /*
5 * Copyright 2001, 2002 Wasabi Systems, Inc.
6 * All rights reserved.
8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed for the NetBSD Project by
21 * Wasabi Systems, Inc.
22 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
24 * written permission.
26 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
40 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 * Copyright (C) 1995, 1996 TooLs GmbH.
42 * All rights reserved.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by TooLs GmbH.
55 * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
58 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: obs266_machdep.c,v 1.9 2008/11/30 18:21:33 martin Exp $");
73 #include "opt_compat_netbsd.h"
74 #include "opt_ddb.h"
75 #include "opt_ipkdb.h"
76 #include "opt_modular.h"
78 #include <sys/param.h>
79 #include <sys/kernel.h>
80 #include <sys/ksyms.h>
81 #include <sys/mount.h>
82 #include <sys/reboot.h>
83 #include <sys/systm.h>
84 #include <sys/device.h>
86 #include <uvm/uvm.h>
87 #include <uvm/uvm_extern.h>
89 #include <machine/bus.h>
90 #include <machine/cpu.h>
91 #include <machine/obs266.h>
92 #include <powerpc/spr.h>
94 #include <dev/pci/pcivar.h>
95 #include <dev/pci/pciconf.h>
97 #include <powerpc/ibm4xx/dcr405gp.h>
98 #include <powerpc/ibm4xx/openbios.h>
100 #include "ksyms.h"
103 #define TLB_PG_SIZE (16*1024*1024)
106 * Global variables used here and there
108 char bootpath[256];
110 extern paddr_t msgbuf_paddr;
112 #if NKSYMS || defined(DDB) || defined(MODULAR)
113 void *startsym, *endsym;
114 #endif
116 void initppc(u_int, u_int, char *, void *);
117 int lcsplx(int);
120 void
121 initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
123 vaddr_t va;
124 u_int memsize;
126 /* Disable all external interrupts */
127 mtdcr(DCR_UIC0_ER, 0);
129 /* Setup board from OpenBIOS */
130 openbios_board_init(info_block, startkernel);
131 memsize = openbios_board_memsize_get();
133 /* Linear map kernel memory */
134 for (va = 0; va < endkernel; va += TLB_PG_SIZE)
135 ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
137 /* Map console after RAM (see pmap_tlbmiss()) */
138 ppc4xx_tlb_reserve(OBS405_CONADDR, roundup(memsize, TLB_PG_SIZE),
139 TLB_PG_SIZE, TLB_I | TLB_G);
141 /* Initialize IBM405GPr CPU */
142 ibm40x_memsize_init(memsize, startkernel);
143 ibm4xx_init((void (*)(void))ext_intr);
146 * Set the page size.
148 uvm_setpagesize();
151 * Initialize pmap module.
153 pmap_bootstrap(startkernel, endkernel);
155 #ifdef DEBUG
156 openbios_board_print();
157 #endif
159 #if NKSYMS || defined(DDB) || defined(MODULAR)
160 ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
161 #endif
162 #ifdef DDB
163 if (boothowto & RB_KDB)
164 Debugger();
165 #endif
166 #ifdef IPKDB
168 * Now trap to IPKDB
170 ipkdb_init();
171 if (boothowto & RB_KDB)
172 ipkdb_connect(0);
173 #endif
176 void
177 consinit(void)
180 obs405_consinit(OBS266_COM_FREQ);
184 lcsplx(int ipl)
187 return spllower(ipl); /* XXX */
192 * Machine dependent startup code.
194 void
195 cpu_startup(void)
199 * cpu common startup
201 ibm4xx_cpu_startup("OpenBlockS266 IBM PowerPC 405GPr Board");
204 * Set up the board properties database.
206 openbios_board_info_set();
209 * Now that we have VM, malloc()s are OK in bus_space.
211 bus_space_mallocok();
214 * no fake mapiodev
216 fake_mapiodev = 0;
220 * Halt or reboot the machine after syncing/dumping according to howto.
222 void
223 cpu_reboot(int howto, char *what)
225 static int syncing;
226 static char str[256];
227 char *ap = str, *ap1 = ap;
229 boothowto = howto;
230 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
231 syncing = 1;
232 vfs_shutdown(); /* sync */
233 resettodr(); /* set wall clock */
236 splhigh();
238 if (!cold && (howto & RB_DUMP))
239 ibm4xx_dumpsys();
241 doshutdownhooks();
243 pmf_system_shutdown(boothowto);
245 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
246 /* Power off here if we know how...*/
249 if (howto & RB_HALT) {
250 printf("halted\n\n");
252 #if 0
253 goto reboot; /* XXX for now... */
254 #endif
256 #ifdef DDB
257 printf("dropping to debugger\n");
258 while(1)
259 Debugger();
260 #endif
263 printf("rebooting\n\n");
264 if (what && *what) {
265 if (strlen(what) > sizeof str - 5)
266 printf("boot string too large, ignored\n");
267 else {
268 strcpy(str, what);
269 ap1 = ap = str + strlen(str);
270 *ap++ = ' ';
273 *ap++ = '-';
274 if (howto & RB_SINGLE)
275 *ap++ = 's';
276 if (howto & RB_KDB)
277 *ap++ = 'd';
278 *ap++ = 0;
279 if (ap[-2] == '-')
280 *ap1 = 0;
282 /* flush cache for msgbuf */
283 __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
285 #if 0
286 reboot:
287 #endif
288 ppc4xx_reset();
290 printf("ppc4xx_reset() failed!\n");
291 #ifdef DDB
292 while(1)
293 Debugger();
294 #else
295 while (1)
296 /* nothing */;
297 #endif
301 pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
304 * We need to map the interrupt pin to the interrupt bit
305 * in the UIC associated with it.
307 * This platform has 4 PCI devices.
309 # External IRQ Mappings:
310 * dev 1 (Ext IRQ3): PCI Connector
311 * dev 2 (Ext IRQ4): PCI Connector
312 * dev 3 (Ext IRQ5): HPT IDE Controller
313 * dev 4 (Ext IRQ6): Davicom Ethernet
315 static const int irqmap[4/*device*/][4/*pin*/] = {
316 { 3, 3, 3, 3 }, /* 1: PCI Connector 1 */
317 { 4, 4, 4, 4 }, /* 2: PCI Connector 2 */
318 { 5, 5, -1, -1 }, /* 3: HPT IDE Controller */
319 { 6, 6, -1, -1 }, /* 4: Damicom Ethernet */
322 int pin, dev, irq;
324 pin = pa->pa_intrpin;
325 dev = pa->pa_device;
326 *ihp = -1;
328 /* if interrupt pin not used... */
329 if (pin == 0)
330 return 1;
332 if (pin > 4) {
333 printf("pci_intr_map: bad interrupt pin %d\n", pin);
334 return 1;
337 if ((dev < 1) || (dev > 4)) {
338 printf("pci_intr_map: bad device %d\n", dev);
339 return 1;
343 if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
344 printf("pci_intr_map: no IRQ routing for device %d pin %d\n",
345 dev, pin);
346 return 1;
349 *ihp = irq + 25;
350 return 0;
353 void
354 pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
355 int swiz, int *iline)
358 static const int ilinemap[4/*device*/] = {
359 3, 4, 5 ,6
362 if ((dev < 1) || (dev > 4)) {
363 printf("pci_intr_map: bad device %d\n", dev);
364 *iline = 0;
365 return;
367 *iline = ilinemap[dev - 1] + 25;