obs266_machdep.c revision 1.1.12.2 1 1.1.12.2 riz /* $NetBSD: obs266_machdep.c,v 1.1.12.2 2005/09/15 14:28:44 riz Exp $ */
2 1.1.12.2 riz /* Original: md_machdep.c,v 1.3 2005/01/24 18:47:37 shige Exp $ */
3 1.1.12.2 riz
4 1.1.12.2 riz /*
5 1.1.12.2 riz * Copyright 2001, 2002 Wasabi Systems, Inc.
6 1.1.12.2 riz * All rights reserved.
7 1.1.12.2 riz *
8 1.1.12.2 riz * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
9 1.1.12.2 riz *
10 1.1.12.2 riz * Redistribution and use in source and binary forms, with or without
11 1.1.12.2 riz * modification, are permitted provided that the following conditions
12 1.1.12.2 riz * are met:
13 1.1.12.2 riz * 1. Redistributions of source code must retain the above copyright
14 1.1.12.2 riz * notice, this list of conditions and the following disclaimer.
15 1.1.12.2 riz * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.12.2 riz * notice, this list of conditions and the following disclaimer in the
17 1.1.12.2 riz * documentation and/or other materials provided with the distribution.
18 1.1.12.2 riz * 3. All advertising materials mentioning features or use of this software
19 1.1.12.2 riz * must display the following acknowledgement:
20 1.1.12.2 riz * This product includes software developed for the NetBSD Project by
21 1.1.12.2 riz * Wasabi Systems, Inc.
22 1.1.12.2 riz * 4. The name of Wasabi Systems, Inc. may not be used to endorse
23 1.1.12.2 riz * or promote products derived from this software without specific prior
24 1.1.12.2 riz * written permission.
25 1.1.12.2 riz *
26 1.1.12.2 riz * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
27 1.1.12.2 riz * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.12.2 riz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.12.2 riz * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
30 1.1.12.2 riz * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.12.2 riz * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.12.2 riz * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.12.2 riz * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.12.2 riz * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.12.2 riz * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.12.2 riz * POSSIBILITY OF SUCH DAMAGE.
37 1.1.12.2 riz */
38 1.1.12.2 riz
39 1.1.12.2 riz /*
40 1.1.12.2 riz * Copyright (C) 1995, 1996 Wolfgang Solfrank.
41 1.1.12.2 riz * Copyright (C) 1995, 1996 TooLs GmbH.
42 1.1.12.2 riz * All rights reserved.
43 1.1.12.2 riz *
44 1.1.12.2 riz * Redistribution and use in source and binary forms, with or without
45 1.1.12.2 riz * modification, are permitted provided that the following conditions
46 1.1.12.2 riz * are met:
47 1.1.12.2 riz * 1. Redistributions of source code must retain the above copyright
48 1.1.12.2 riz * notice, this list of conditions and the following disclaimer.
49 1.1.12.2 riz * 2. Redistributions in binary form must reproduce the above copyright
50 1.1.12.2 riz * notice, this list of conditions and the following disclaimer in the
51 1.1.12.2 riz * documentation and/or other materials provided with the distribution.
52 1.1.12.2 riz * 3. All advertising materials mentioning features or use of this software
53 1.1.12.2 riz * must display the following acknowledgement:
54 1.1.12.2 riz * This product includes software developed by TooLs GmbH.
55 1.1.12.2 riz * 4. The name of TooLs GmbH may not be used to endorse or promote products
56 1.1.12.2 riz * derived from this software without specific prior written permission.
57 1.1.12.2 riz *
58 1.1.12.2 riz * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
59 1.1.12.2 riz * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 1.1.12.2 riz * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 1.1.12.2 riz * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62 1.1.12.2 riz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
63 1.1.12.2 riz * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
64 1.1.12.2 riz * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
65 1.1.12.2 riz * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
66 1.1.12.2 riz * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
67 1.1.12.2 riz * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 1.1.12.2 riz */
69 1.1.12.2 riz
70 1.1.12.2 riz #include <sys/cdefs.h>
71 1.1.12.2 riz __KERNEL_RCSID(0, "$NetBSD: obs266_machdep.c,v 1.1.12.2 2005/09/15 14:28:44 riz Exp $");
72 1.1.12.2 riz
73 1.1.12.2 riz #include "opt_compat_netbsd.h"
74 1.1.12.2 riz #include "opt_ddb.h"
75 1.1.12.2 riz #include "opt_ipkdb.h"
76 1.1.12.2 riz
77 1.1.12.2 riz #include <sys/param.h>
78 1.1.12.2 riz #include <sys/kernel.h>
79 1.1.12.2 riz #include <sys/ksyms.h>
80 1.1.12.2 riz #include <sys/mount.h>
81 1.1.12.2 riz #include <sys/reboot.h>
82 1.1.12.2 riz #include <sys/systm.h>
83 1.1.12.2 riz
84 1.1.12.2 riz #include <uvm/uvm.h>
85 1.1.12.2 riz #include <uvm/uvm_extern.h>
86 1.1.12.2 riz
87 1.1.12.2 riz #include <machine/bus.h>
88 1.1.12.2 riz #include <machine/cpu.h>
89 1.1.12.2 riz #include <machine/obs266.h>
90 1.1.12.2 riz #include <powerpc/spr.h>
91 1.1.12.2 riz
92 1.1.12.2 riz #include <powerpc/ibm4xx/dcr405gp.h>
93 1.1.12.2 riz #include <powerpc/ibm4xx/openbios.h>
94 1.1.12.2 riz
95 1.1.12.2 riz #include "ksyms.h"
96 1.1.12.2 riz
97 1.1.12.2 riz /*
98 1.1.12.2 riz * Global variables used here and there
99 1.1.12.2 riz */
100 1.1.12.2 riz char bootpath[256];
101 1.1.12.2 riz
102 1.1.12.2 riz extern paddr_t msgbuf_paddr;
103 1.1.12.2 riz
104 1.1.12.2 riz #if NKSYMS || defined(DDB) || defined(LKM)
105 1.1.12.2 riz void *startsym, *endsym;
106 1.1.12.2 riz #endif
107 1.1.12.2 riz
108 1.1.12.2 riz void initppc(u_int, u_int, char *, void *);
109 1.1.12.2 riz int lcsplx(int);
110 1.1.12.2 riz
111 1.1.12.2 riz
112 1.1.12.2 riz void
113 1.1.12.2 riz initppc(u_int startkernel, u_int endkernel, char *args, void *info_block)
114 1.1.12.2 riz {
115 1.1.12.2 riz u_int memsize;
116 1.1.12.2 riz
117 1.1.12.2 riz /* Disable all external interrupts */
118 1.1.12.2 riz mtdcr(DCR_UIC0_ER, 0);
119 1.1.12.2 riz
120 1.1.12.2 riz /* Setup board from OpenBIOS */
121 1.1.12.2 riz openbios_board_init(info_block, startkernel);
122 1.1.12.2 riz memsize = openbios_board_memsize_get();
123 1.1.12.2 riz
124 1.1.12.2 riz /* Initialize IBM405GPr CPU */
125 1.1.12.2 riz ibm40x_memsize_init(memsize, startkernel);
126 1.1.12.2 riz ibm4xx_init((void (*)(void))ext_intr);
127 1.1.12.2 riz
128 1.1.12.2 riz /*
129 1.1.12.2 riz * Initialize console.
130 1.1.12.2 riz */
131 1.1.12.2 riz consinit();
132 1.1.12.2 riz
133 1.1.12.2 riz /*
134 1.1.12.2 riz * Set the page size.
135 1.1.12.2 riz */
136 1.1.12.2 riz uvm_setpagesize();
137 1.1.12.2 riz
138 1.1.12.2 riz /*
139 1.1.12.2 riz * Initialize pmap module.
140 1.1.12.2 riz */
141 1.1.12.2 riz pmap_bootstrap(startkernel, endkernel);
142 1.1.12.2 riz
143 1.1.12.2 riz #ifdef DEBUG
144 1.1.12.2 riz openbios_board_print();
145 1.1.12.2 riz #endif
146 1.1.12.2 riz
147 1.1.12.2 riz #if NKSYMS || defined(DDB) || defined(LKM)
148 1.1.12.2 riz ksyms_init((int)((u_int)endsym - (u_int)startsym), startsym, endsym);
149 1.1.12.2 riz #endif
150 1.1.12.2 riz #ifdef DDB
151 1.1.12.2 riz if (boothowto & RB_KDB)
152 1.1.12.2 riz Debugger();
153 1.1.12.2 riz #endif
154 1.1.12.2 riz #ifdef IPKDB
155 1.1.12.2 riz /*
156 1.1.12.2 riz * Now trap to IPKDB
157 1.1.12.2 riz */
158 1.1.12.2 riz ipkdb_init();
159 1.1.12.2 riz if (boothowto & RB_KDB)
160 1.1.12.2 riz ipkdb_connect(0);
161 1.1.12.2 riz #endif
162 1.1.12.2 riz }
163 1.1.12.2 riz
164 1.1.12.2 riz void
165 1.1.12.2 riz consinit(void)
166 1.1.12.2 riz {
167 1.1.12.2 riz
168 1.1.12.2 riz obs405_consinit(OBS266_COM_FREQ);
169 1.1.12.2 riz }
170 1.1.12.2 riz
171 1.1.12.2 riz int
172 1.1.12.2 riz lcsplx(int ipl)
173 1.1.12.2 riz {
174 1.1.12.2 riz
175 1.1.12.2 riz return spllower(ipl); /* XXX */
176 1.1.12.2 riz }
177 1.1.12.2 riz
178 1.1.12.2 riz
179 1.1.12.2 riz /*
180 1.1.12.2 riz * Machine dependent startup code.
181 1.1.12.2 riz */
182 1.1.12.2 riz void
183 1.1.12.2 riz cpu_startup(void)
184 1.1.12.2 riz {
185 1.1.12.2 riz
186 1.1.12.2 riz /*
187 1.1.12.2 riz * cpu common startup
188 1.1.12.2 riz */
189 1.1.12.2 riz ibm4xx_cpu_startup("OpenBlockS266 IBM PowerPC 405GPr Board");
190 1.1.12.2 riz
191 1.1.12.2 riz /*
192 1.1.12.2 riz * Set up the board properties database.
193 1.1.12.2 riz */
194 1.1.12.2 riz openbios_board_info_set();
195 1.1.12.2 riz
196 1.1.12.2 riz /*
197 1.1.12.2 riz * Now that we have VM, malloc()s are OK in bus_space.
198 1.1.12.2 riz */
199 1.1.12.2 riz bus_space_mallocok();
200 1.1.12.2 riz
201 1.1.12.2 riz /*
202 1.1.12.2 riz * no fake mapiodev
203 1.1.12.2 riz */
204 1.1.12.2 riz fake_mapiodev = 0;
205 1.1.12.2 riz }
206 1.1.12.2 riz
207 1.1.12.2 riz /*
208 1.1.12.2 riz * Halt or reboot the machine after syncing/dumping according to howto.
209 1.1.12.2 riz */
210 1.1.12.2 riz void
211 1.1.12.2 riz cpu_reboot(int howto, char *what)
212 1.1.12.2 riz {
213 1.1.12.2 riz static int syncing;
214 1.1.12.2 riz static char str[256];
215 1.1.12.2 riz char *ap = str, *ap1 = ap;
216 1.1.12.2 riz
217 1.1.12.2 riz /* obs266_led_set(OBS266_LED_ON); */
218 1.1.12.2 riz
219 1.1.12.2 riz boothowto = howto;
220 1.1.12.2 riz if (!cold && !(howto & RB_NOSYNC) && !syncing) {
221 1.1.12.2 riz syncing = 1;
222 1.1.12.2 riz vfs_shutdown(); /* sync */
223 1.1.12.2 riz resettodr(); /* set wall clock */
224 1.1.12.2 riz }
225 1.1.12.2 riz
226 1.1.12.2 riz splhigh();
227 1.1.12.2 riz
228 1.1.12.2 riz if (!cold && (howto & RB_DUMP))
229 1.1.12.2 riz ibm4xx_dumpsys();
230 1.1.12.2 riz
231 1.1.12.2 riz doshutdownhooks();
232 1.1.12.2 riz
233 1.1.12.2 riz if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
234 1.1.12.2 riz /* Power off here if we know how...*/
235 1.1.12.2 riz }
236 1.1.12.2 riz
237 1.1.12.2 riz if (howto & RB_HALT) {
238 1.1.12.2 riz printf("halted\n\n");
239 1.1.12.2 riz
240 1.1.12.2 riz #if 0
241 1.1.12.2 riz goto reboot; /* XXX for now... */
242 1.1.12.2 riz #endif
243 1.1.12.2 riz
244 1.1.12.2 riz #ifdef DDB
245 1.1.12.2 riz printf("dropping to debugger\n");
246 1.1.12.2 riz while(1)
247 1.1.12.2 riz Debugger();
248 1.1.12.2 riz #endif
249 1.1.12.2 riz }
250 1.1.12.2 riz
251 1.1.12.2 riz printf("rebooting\n\n");
252 1.1.12.2 riz if (what && *what) {
253 1.1.12.2 riz if (strlen(what) > sizeof str - 5)
254 1.1.12.2 riz printf("boot string too large, ignored\n");
255 1.1.12.2 riz else {
256 1.1.12.2 riz strcpy(str, what);
257 1.1.12.2 riz ap1 = ap = str + strlen(str);
258 1.1.12.2 riz *ap++ = ' ';
259 1.1.12.2 riz }
260 1.1.12.2 riz }
261 1.1.12.2 riz *ap++ = '-';
262 1.1.12.2 riz if (howto & RB_SINGLE)
263 1.1.12.2 riz *ap++ = 's';
264 1.1.12.2 riz if (howto & RB_KDB)
265 1.1.12.2 riz *ap++ = 'd';
266 1.1.12.2 riz *ap++ = 0;
267 1.1.12.2 riz if (ap[-2] == '-')
268 1.1.12.2 riz *ap1 = 0;
269 1.1.12.2 riz
270 1.1.12.2 riz /* flush cache for msgbuf */
271 1.1.12.2 riz __syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
272 1.1.12.2 riz
273 1.1.12.2 riz #if 0
274 1.1.12.2 riz reboot:
275 1.1.12.2 riz #endif
276 1.1.12.2 riz ppc4xx_reset();
277 1.1.12.2 riz
278 1.1.12.2 riz printf("ppc4xx_reset() failed!\n");
279 1.1.12.2 riz #ifdef DDB
280 1.1.12.2 riz while(1)
281 1.1.12.2 riz Debugger();
282 1.1.12.2 riz #else
283 1.1.12.2 riz while (1)
284 1.1.12.2 riz /* nothing */;
285 1.1.12.2 riz #endif
286 1.1.12.2 riz }
287