machdep.c revision 1.95 1 1.95 garbled /* $NetBSD: machdep.c,v 1.95 2007/10/25 16:55:49 garbled Exp $ */
2 1.1 ws
3 1.1 ws /*
4 1.1 ws * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 ws * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 ws * All rights reserved.
7 1.1 ws *
8 1.1 ws * Redistribution and use in source and binary forms, with or without
9 1.1 ws * modification, are permitted provided that the following conditions
10 1.1 ws * are met:
11 1.1 ws * 1. Redistributions of source code must retain the above copyright
12 1.1 ws * notice, this list of conditions and the following disclaimer.
13 1.1 ws * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ws * notice, this list of conditions and the following disclaimer in the
15 1.1 ws * documentation and/or other materials provided with the distribution.
16 1.1 ws * 3. All advertising materials mentioning features or use of this software
17 1.1 ws * must display the following acknowledgement:
18 1.1 ws * This product includes software developed by TooLs GmbH.
19 1.1 ws * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 ws * derived from this software without specific prior written permission.
21 1.1 ws *
22 1.1 ws * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 ws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 ws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 ws * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 ws * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 ws * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 ws * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 ws * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 ws * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 ws * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 ws */
33 1.86 lukem
34 1.86 lukem #include <sys/cdefs.h>
35 1.95 garbled __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.95 2007/10/25 16:55:49 garbled Exp $");
36 1.1 ws
37 1.1 ws #include <sys/param.h>
38 1.1 ws #include <sys/buf.h>
39 1.93 garbled #include <sys/boot_flag.h>
40 1.1 ws #include <sys/mount.h>
41 1.43 thorpej #include <sys/kernel.h>
42 1.1 ws
43 1.19 sakamoto #include <uvm/uvm_extern.h>
44 1.19 sakamoto
45 1.70 thorpej #include <dev/ofw/openfirm.h>
46 1.93 garbled #include <dev/cons.h>
47 1.70 thorpej
48 1.68 matt #include <machine/autoconf.h>
49 1.1 ws #include <machine/pmap.h>
50 1.1 ws #include <machine/powerpc.h>
51 1.1 ws #include <machine/trap.h>
52 1.93 garbled #include <machine/bus.h>
53 1.93 garbled #include <machine/isa_machdep.h>
54 1.54 thorpej
55 1.87 matt #include <powerpc/oea/bat.h>
56 1.93 garbled #include <powerpc/ofw_cons.h>
57 1.71 thorpej
58 1.1 ws
59 1.93 garbled struct pmap ofw_pmap;
60 1.78 chs char bootpath[256];
61 1.1 ws
62 1.93 garbled void ofwppc_batinit(void);
63 1.71 thorpej void ofppc_bootstrap_console(void);
64 1.77 matt
65 1.1 ws void
66 1.93 garbled initppc(u_int startkernel, u_int endkernel, char *args)
67 1.1 ws {
68 1.71 thorpej /* Initialize the bootstrap console. */
69 1.71 thorpej ofppc_bootstrap_console();
70 1.93 garbled ofwoea_initppc(startkernel, endkernel, args);
71 1.1 ws }
72 1.1 ws
73 1.1 ws void
74 1.93 garbled cpu_startup(void)
75 1.1 ws {
76 1.82 matt oea_startup(NULL);
77 1.1 ws }
78 1.1 ws
79 1.93 garbled /*
80 1.1 ws void
81 1.93 garbled consinit(void)
82 1.1 ws {
83 1.93 garbled ofwoea_consinit();
84 1.71 thorpej }
85 1.93 garbled */
86 1.71 thorpej
87 1.71 thorpej void
88 1.93 garbled dumpsys(void)
89 1.71 thorpej {
90 1.93 garbled printf("dumpsys: TBD\n");
91 1.1 ws }
92 1.1 ws
93 1.1 ws /*
94 1.93 garbled * Halt or reboot the machine after syncing/dumping according to howto.
95 1.1 ws */
96 1.95 garbled void rtas_reboot(void);
97 1.1 ws
98 1.1 ws void
99 1.93 garbled cpu_reboot(int howto, char *what)
100 1.1 ws {
101 1.1 ws static int syncing;
102 1.1 ws static char str[256];
103 1.1 ws char *ap = str, *ap1 = ap;
104 1.1 ws
105 1.1 ws boothowto = howto;
106 1.1 ws if (!cold && !(howto & RB_NOSYNC) && !syncing) {
107 1.1 ws syncing = 1;
108 1.93 garbled vfs_shutdown(); /* sync */
109 1.93 garbled resettodr(); /* set wall clock */
110 1.1 ws }
111 1.1 ws splhigh();
112 1.1 ws if (howto & RB_HALT) {
113 1.1 ws doshutdownhooks();
114 1.3 christos printf("halted\n\n");
115 1.1 ws ppc_exit();
116 1.1 ws }
117 1.1 ws if (!cold && (howto & RB_DUMP))
118 1.82 matt oea_dumpsys();
119 1.1 ws doshutdownhooks();
120 1.3 christos printf("rebooting\n\n");
121 1.95 garbled
122 1.95 garbled rtas_reboot();
123 1.95 garbled
124 1.1 ws if (what && *what) {
125 1.1 ws if (strlen(what) > sizeof str - 5)
126 1.3 christos printf("boot string too large, ignored\n");
127 1.1 ws else {
128 1.1 ws strcpy(str, what);
129 1.1 ws ap1 = ap = str + strlen(str);
130 1.1 ws *ap++ = ' ';
131 1.1 ws }
132 1.1 ws }
133 1.1 ws *ap++ = '-';
134 1.1 ws if (howto & RB_SINGLE)
135 1.1 ws *ap++ = 's';
136 1.1 ws if (howto & RB_KDB)
137 1.1 ws *ap++ = 'd';
138 1.1 ws *ap++ = 0;
139 1.1 ws if (ap[-2] == '-')
140 1.1 ws *ap1 = 0;
141 1.1 ws ppc_boot(str);
142 1.1 ws }
143 1.1 ws
144 1.1 ws /*
145 1.93 garbled * XXX
146 1.93 garbled * The following code is subject to die at a later date. This is the only
147 1.93 garbled * remaining code in this file subject to the Tools GmbH copyright.
148 1.1 ws */
149 1.93 garbled
150 1.1 ws void
151 1.93 garbled consinit()
152 1.1 ws {
153 1.93 garbled
154 1.93 garbled (*cn_tab->cn_probe)(cn_tab);
155 1.60 thorpej }
156 1.60 thorpej
157 1.93 garbled void ofcons_cnprobe(struct consdev *);
158 1.93 garbled int ofppc_cngetc(dev_t);
159 1.93 garbled void ofppc_cnputc(dev_t, int);
160 1.93 garbled
161 1.93 garbled struct consdev ofppc_bootcons = {
162 1.93 garbled ofcons_cnprobe, NULL, ofppc_cngetc, ofppc_cnputc, nullcnpollc, NULL,
163 1.93 garbled NULL, NULL, makedev(0,0), 1,
164 1.93 garbled };
165 1.60 thorpej
166 1.93 garbled int ofppc_stdin_ihandle, ofppc_stdout_ihandle;
167 1.93 garbled int ofppc_stdin_phandle, ofppc_stdout_phandle;
168 1.1 ws
169 1.93 garbled void
170 1.93 garbled ofppc_bootstrap_console(void)
171 1.7 thorpej {
172 1.93 garbled int chosen;
173 1.93 garbled char data[4];
174 1.93 garbled
175 1.93 garbled chosen = OF_finddevice("/chosen");
176 1.7 thorpej
177 1.93 garbled if (OF_getprop(chosen, "stdin", data, sizeof(data)) != sizeof(int))
178 1.93 garbled goto nocons;
179 1.93 garbled ofppc_stdin_ihandle = of_decode_int(data);
180 1.93 garbled ofppc_stdin_phandle = OF_instance_to_package(ofppc_stdin_ihandle);
181 1.7 thorpej
182 1.93 garbled if (OF_getprop(chosen, "stdout", data, sizeof(data)) != sizeof(int))
183 1.93 garbled goto nocons;
184 1.93 garbled ofppc_stdout_ihandle = of_decode_int(data);
185 1.93 garbled ofppc_stdout_phandle = OF_instance_to_package(ofppc_stdout_ihandle);
186 1.7 thorpej
187 1.93 garbled cn_tab = &ofppc_bootcons;
188 1.73 thorpej
189 1.93 garbled nocons:
190 1.93 garbled return;
191 1.7 thorpej }
192 1.7 thorpej
193 1.93 garbled int
194 1.93 garbled ofppc_cngetc(dev_t dev)
195 1.7 thorpej {
196 1.93 garbled u_char ch = '\0';
197 1.93 garbled int l;
198 1.93 garbled
199 1.93 garbled while ((l = OF_read(ofppc_stdin_ihandle, &ch, 1)) != 1)
200 1.93 garbled if (l != -2 && l != 0)
201 1.93 garbled return (-1);
202 1.88 nonaka
203 1.93 garbled return (ch);
204 1.1 ws }
205 1.1 ws
206 1.93 garbled void
207 1.93 garbled ofppc_cnputc(dev_t dev, int c)
208 1.73 thorpej {
209 1.93 garbled char ch = c;
210 1.73 thorpej
211 1.93 garbled OF_write(ofppc_stdout_ihandle, &ch, 1);
212 1.73 thorpej }
213 1.73 thorpej
214