obs266_machdep.c revision 1.12 1 /* $NetBSD: obs266_machdep.c,v 1.12 2010/03/18 13:47:04 kiyohara Exp $ */
2 /* Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $ */
3
4 /*
5 * Copyright 2001, 2002 Wasabi Systems, Inc.
6 * All rights reserved.
7 *
8 * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 *
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.
25 *
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.
37 */
38
39 /*
40 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 * Copyright (C) 1995, 1996 TooLs GmbH.
42 * All rights reserved.
43 *
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.
57 *
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.
68 */
69
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: obs266_machdep.c,v 1.12 2010/03/18 13:47:04 kiyohara Exp $");
72
73 #include "opt_compat_netbsd.h"
74 #include "opt_ddb.h"
75 #include "opt_ipkdb.h"
76 #include "opt_modular.h"
77
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>
85
86 #include <uvm/uvm.h>
87 #include <uvm/uvm_extern.h>
88
89 #include <machine/bus.h>
90 #include <machine/cpu.h>
91 #include <machine/obs266.h>
92 #include <powerpc/spr.h>
93 #include <powerpc/ibm4xx/dcr4xx.h>
94 #include <powerpc/ibm4xx/dev/comopbvar.h>
95 #include <powerpc/ibm4xx/ibm405gp.h>
96 #include <powerpc/ibm4xx/openbios.h>
97 #include <powerpc/ibm4xx/spr.h>
98
99 #include <dev/pci/pcivar.h>
100 #include <dev/pci/pciconf.h>
101
102 #include "ksyms.h"
103
104
105 #define TLB_PG_SIZE (16*1024*1024)
106
107 /*
108 * Global variables used here and there
109 */
110 char bootpath[256];
111
112 extern paddr_t msgbuf_paddr;
113
114 #if NKSYMS || defined(DDB) || defined(MODULAR)
115 void *startsym, *endsym;
116 #endif
117
118 void initppc(u_int, u_int, char *, void *);
119 int lcsplx(int);
120
121
122 void
123 initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
124 {
125 vaddr_t va;
126 u_int memsize;
127
128 /* Setup board from OpenBIOS */
129 openbios_board_init(info_block, startkernel);
130 memsize = openbios_board_memsize_get();
131
132 /* Linear map kernel memory */
133 for (va = 0; va < endkernel; va += TLB_PG_SIZE)
134 ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
135
136 /* Map console after RAM (see pmap_tlbmiss()) */
137 ppc4xx_tlb_reserve(OBS405_CONADDR, roundup(memsize, TLB_PG_SIZE),
138 TLB_PG_SIZE, TLB_I | TLB_G);
139
140 /* Initialize IBM405GPr CPU */
141 ibm40x_memsize_init(memsize, startkernel);
142 ibm4xx_init((void (*)(void))ext_intr);
143
144 /*
145 * Set the page size.
146 */
147 uvm_setpagesize();
148
149 /*
150 * Initialize pmap module.
151 */
152 pmap_bootstrap(startkernel, endkernel);
153
154 #ifdef DEBUG
155 openbios_board_print();
156 #endif
157
158 #if NKSYMS || defined(DDB) || defined(MODULAR)
159 ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
160 #endif
161 #ifdef DDB
162 if (boothowto & RB_KDB)
163 Debugger();
164 #endif
165 #ifdef IPKDB
166 /*
167 * Now trap to IPKDB
168 */
169 ipkdb_init();
170 if (boothowto & RB_KDB)
171 ipkdb_connect(0);
172 #endif
173 }
174
175 void
176 consinit(void)
177 {
178
179 obs405_consinit(OBS266_COM_FREQ);
180 }
181
182 int
183 lcsplx(int ipl)
184 {
185
186 return spllower(ipl); /* XXX */
187 }
188
189
190 /*
191 * Machine dependent startup code.
192 */
193 void
194 cpu_startup(void)
195 {
196
197 /*
198 * cpu common startup
199 */
200 ibm4xx_cpu_startup("OpenBlockS266 IBM PowerPC 405GPr Board");
201
202 /*
203 * Set up the board properties database.
204 */
205 openbios_board_info_set();
206
207 /*
208 * Now that we have VM, malloc()s are OK in bus_space.
209 */
210 bus_space_mallocok();
211
212 /*
213 * no fake mapiodev
214 */
215 fake_mapiodev = 0;
216 }
217
218 /*
219 * Halt or reboot the machine after syncing/dumping according to howto.
220 */
221 void
222 cpu_reboot(int howto, char *what)
223 {
224 static int syncing;
225 static char str[256];
226 char *ap = str, *ap1 = ap;
227
228 boothowto = howto;
229 if (!cold && !(howto & RB_NOSYNC) && !syncing) {
230 syncing = 1;
231 vfs_shutdown(); /* sync */
232 resettodr(); /* set wall clock */
233 }
234
235 splhigh();
236
237 if (!cold && (howto & RB_DUMP))
238 ibm4xx_dumpsys();
239
240 doshutdownhooks();
241
242 pmf_system_shutdown(boothowto);
243
244 if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
245 /* Power off here if we know how...*/
246 }
247
248 if (howto & RB_HALT) {
249 printf("halted\n\n");
250
251 #if 0
252 goto reboot; /* XXX for now... */
253 #endif
254
255 #ifdef DDB
256 printf("dropping to debugger\n");
257 while(1)
258 Debugger();
259 #endif
260 }
261
262 printf("rebooting\n\n");
263 if (what && *what) {
264 if (strlen(what) > sizeof str - 5)
265 printf("boot string too large, ignored\n");
266 else {
267 strcpy(str, what);
268 ap1 = ap = str + strlen(str);
269 *ap++ = ' ';
270 }
271 }
272 *ap++ = '-';
273 if (howto & RB_SINGLE)
274 *ap++ = 's';
275 if (howto & RB_KDB)
276 *ap++ = 'd';
277 *ap++ = 0;
278 if (ap[-2] == '-')
279 *ap1 = 0;
280
281 /* flush cache for msgbuf */
282 __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
283
284 #if 0
285 reboot:
286 #endif
287 ppc4xx_reset();
288
289 printf("ppc4xx_reset() failed!\n");
290 #ifdef DDB
291 while(1)
292 Debugger();
293 #else
294 while (1)
295 /* nothing */;
296 #endif
297 }
298
299 int
300 pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
301 {
302
303 /*
304 * Bus number is irrelevant. Configuration Mechanism 1 is in
305 * use, can have devices 0-32 (i.e. the `normal' range).
306 */
307 return 31;
308 }
309
310 int
311 pci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
312 {
313 /*
314 * We need to map the interrupt pin to the interrupt bit
315 * in the UIC associated with it.
316 *
317 * This platform has 4 PCI devices.
318 *
319 # External IRQ Mappings:
320 * dev 1 (Ext IRQ3): PCI Connector
321 * dev 2 (Ext IRQ4): PCI Connector
322 * dev 3 (Ext IRQ5): HPT IDE Controller
323 * dev 4 (Ext IRQ6): Davicom Ethernet
324 */
325 static const int irqmap[4/*device*/][4/*pin*/] = {
326 { 3, 3, 3, 3 }, /* 1: PCI Connector 1 */
327 { 4, 4, 4, 4 }, /* 2: PCI Connector 2 */
328 { 5, 5, -1, -1 }, /* 3: HPT IDE Controller */
329 { 6, 6, -1, -1 }, /* 4: Damicom Ethernet */
330 };
331
332 int pin, dev, irq;
333
334 pin = pa->pa_intrpin;
335 dev = pa->pa_device;
336 *ihp = -1;
337
338 /* if interrupt pin not used... */
339 if (pin == 0)
340 return 1;
341
342 if (pin > 4) {
343 printf("pci_intr_map: bad interrupt pin %d\n", pin);
344 return 1;
345 }
346
347 if ((dev < 1) || (dev > 4)) {
348 printf("pci_intr_map: bad device %d\n", dev);
349 return 1;
350 }
351
352
353 if ((irq = irqmap[dev - 1][pin - 1]) == -1) {
354 printf("pci_intr_map: no IRQ routing for device %d pin %d\n",
355 dev, pin);
356 return 1;
357 }
358
359 *ihp = irq + 25;
360 return 0;
361 }
362
363 void
364 pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin,
365 int swiz, int *iline)
366 {
367
368 static const int ilinemap[4/*device*/] = {
369 3, 4, 5 ,6
370 };
371
372 if ((dev < 1) || (dev > 4)) {
373 printf("pci_intr_map: bad device %d\n", dev);
374 *iline = 0;
375 return;
376 }
377 *iline = ilinemap[dev - 1] + 25;
378 }
379