1 /* $NetBSD: obs200_machdep.c,v 1.8 2008/11/30 18:21:33 martin Exp $ */
2 /* Original: machdep.c,v 1.3 2005/01/17 17:24:09 shige Exp */
5 * Copyright 2001, 2002 Wasabi Systems, Inc.
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
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
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
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: obs200_machdep.c,v 1.8 2008/11/30 18:21:33 martin Exp $");
73 #include "opt_compat_netbsd.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>
87 #include <uvm/uvm_extern.h>
89 #include <machine/bus.h>
90 #include <machine/cpu.h>
91 #include <machine/obs200.h>
92 #include <machine/century_bios.h>
93 #include <powerpc/spr.h>
95 #include <dev/pci/pcivar.h>
96 #include <dev/pci/pciconf.h>
98 #include <powerpc/ibm4xx/dcr405gp.h>
103 #define TLB_PG_SIZE (16*1024*1024)
106 * Global variables used here and there
110 extern paddr_t msgbuf_paddr
;
112 #if NKSYMS || defined(DDB) || defined(MODULAR)
113 void *startsym
, *endsym
;
116 void initppc(u_int
, u_int
, char *, void *);
121 initppc(u_int startkernel
, u_int endkernel
, char *args
, void *info_block
)
128 /* Disable all external interrupts */
129 mtdcr(DCR_UIC0_ER
, 0);
130 pllmode
= mfdcr(DCR_CPC0_PLLMR
);
131 psr
= mfdcr(DCR_CPC0_PSR
);
133 /* Setup board from BIOS */
134 bios_board_init(info_block
, startkernel
);
135 memsize
= bios_board_memsize_get();
137 /* Linear map kernel memory. */
138 for (va
= 0; va
< endkernel
; va
+= TLB_PG_SIZE
)
139 ppc4xx_tlb_reserve(va
, va
, TLB_PG_SIZE
, TLB_EX
);
141 /* Map console after physmem (see pmap_tlbmiss()). */
142 ppc4xx_tlb_reserve(OBS405_CONADDR
, roundup(memsize
, TLB_PG_SIZE
),
143 TLB_PG_SIZE
, TLB_I
| TLB_G
);
145 /* Initialize IBM405GPr CPU */
146 ibm40x_memsize_init(memsize
, startkernel
);
147 ibm4xx_init((void (*)(void))ext_intr
);
155 * Initialize pmap module.
157 pmap_bootstrap(startkernel
, endkernel
);
161 printf(" PLL Mode Register = 0x%08x\n", pllmode
);
162 printf(" Chip Pin Strapping Register = 0x%08x\n", psr
);
165 #if NKSYMS || defined(DDB) || defined(MODULAR)
166 ksyms_addsyms_elf((int)((u_int
)endsym
- (u_int
)startsym
), startsym
, endsym
);
169 if (boothowto
& RB_KDB
)
177 if (boothowto
& RB_KDB
)
186 obs405_consinit(OBS200_COM_FREQ
);
193 return spllower(ipl
); /* XXX */
198 * Machine dependent startup code.
207 ibm4xx_cpu_startup("OpenBlockS S/R IBM PowerPC 405GP Board");
210 * Set up the board properties database.
212 bios_board_info_set();
215 * Now that we have VM, malloc()s are OK in bus_space.
217 bus_space_mallocok();
226 * Halt or reboot the machine after syncing/dumping according to howto.
229 cpu_reboot(int howto
, char *what
)
232 static char str
[256];
233 char *ap
= str
, *ap1
= ap
;
236 if (!cold
&& !(howto
& RB_NOSYNC
) && !syncing
) {
238 vfs_shutdown(); /* sync */
239 resettodr(); /* set wall clock */
244 if (!cold
&& (howto
& RB_DUMP
))
249 pmf_system_shutdown(boothowto
);
251 if ((howto
& RB_POWERDOWN
) == RB_POWERDOWN
) {
252 /* Power off here if we know how...*/
255 if (howto
& RB_HALT
) {
256 printf("halted\n\n");
259 goto reboot
; /* XXX for now... */
263 printf("dropping to debugger\n");
269 printf("rebooting\n\n");
271 if (strlen(what
) > sizeof str
- 5)
272 printf("boot string too large, ignored\n");
275 ap1
= ap
= str
+ strlen(str
);
280 if (howto
& RB_SINGLE
)
288 /* flush cache for msgbuf */
289 __syncicache((void *)msgbuf_paddr
, round_page(MSGBUFSIZE
));
296 printf("ppc4xx_reset() failed!\n");
307 pci_intr_map(struct pci_attach_args
*pa
, pci_intr_handle_t
*ihp
)
310 * We need to map the interrupt pin to the interrupt bit
311 * in the UIC associated with it.
313 * This platform has 4 PCI devices.
315 # External IRQ Mappings:
316 * dev 7 (Ext IRQ3): Realtek 8139 Ethernet
317 * dev 8 (Ext IRQ0): PCI Connector
319 static const int irqmap
[15/*device*/][4/*pin*/] = {
320 { -1, -1, -1, -1 }, /* 1: none */
321 { -1, -1, -1, -1 }, /* 2: none */
322 { -1, -1, -1, -1 }, /* 3: none */
323 { -1, -1, -1, -1 }, /* 4: none */
324 { -1, -1, -1, -1 }, /* 5: none */
325 { -1, -1, -1, -1 }, /* 6: none */
326 { 3, -1, -1, -1 }, /* 7: none */
327 { 0, -1, -1, -1 }, /* 8: none */
328 { -1, -1, -1, -1 }, /* 9: none */
329 { -1, -1, -1, -1 }, /* 10: none */
330 { -1, -1, -1, -1 }, /* 11: none */
331 { -1, -1, -1, -1 }, /* 12: none */
332 { -1, -1, -1, -1 }, /* 13: none */
333 { -1, -1, -1, -1 }, /* 14: none */
334 { -1, -1, -1, -1 }, /* 15: none */
339 pin
= pa
->pa_intrpin
;
343 /* if interrupt pin not used... */
348 printf("pci_intr_map: bad interrupt pin %d\n", pin
);
352 if ((dev
< 1) || (dev
> 15)) {
353 printf("pci_intr_map: bad device %d\n", dev
);
358 if ((irq
= irqmap
[dev
- 1][pin
- 1]) == -1) {
359 printf("pci_intr_map: no IRQ routing for device %d pin %d\n",
369 pci_conf_interrupt(pci_chipset_tag_t pc
, int bus
, int dev
, int pin
,
370 int swiz
, int *iline
)
372 static const int ilinemap
[15/*device*/] = {
373 -1, -1, -1, -1, /* device 1 - 4 */
374 -1, -1, 28, 25, /* device 5 - 8 */
375 -1, -1, -1, -1, /* device 9 - 12 */
376 -1, -1, -1, /* device 13 - 15 */
380 if ((dev
< 1) || (dev
> 15)) {
381 printf("pci_intr_map: bad device %d\n", dev
);
385 *iline
= ilinemap
[dev
- 1];
387 *iline
= 19 + ((swiz
+ dev
+ 1) & 3);