consinit.c revision 1.1.4.2 1 1.1.4.2 nathanw /* $NetBSD: consinit.c,v 1.1.4.2 2002/04/01 07:43:17 nathanw Exp $ */
2 1.1.4.2 nathanw
3 1.1.4.2 nathanw /*-
4 1.1.4.2 nathanw * Copyright (c) 2001 Matthew Fredette
5 1.1.4.2 nathanw * Copyright (c) 1999 Eduardo E. Horvath
6 1.1.4.2 nathanw * All rights reserved.
7 1.1.4.2 nathanw *
8 1.1.4.2 nathanw * Redistribution and use in source and binary forms, with or without
9 1.1.4.2 nathanw * modification, are permitted provided that the following conditions
10 1.1.4.2 nathanw * are met:
11 1.1.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
12 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer.
13 1.1.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
15 1.1.4.2 nathanw * documentation and/or other materials provided with the distribution.
16 1.1.4.2 nathanw * 3. The name of the author may not be used to endorse or promote products
17 1.1.4.2 nathanw * derived from this software without specific prior written permission.
18 1.1.4.2 nathanw *
19 1.1.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.1.4.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.1.4.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.1.4.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1.4.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 1.1.4.2 nathanw * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 1.1.4.2 nathanw * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 1.1.4.2 nathanw * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 1.1.4.2 nathanw * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1.4.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1.4.2 nathanw * SUCH DAMAGE.
30 1.1.4.2 nathanw */
31 1.1.4.2 nathanw
32 1.1.4.2 nathanw #include "opt_ddb.h"
33 1.1.4.2 nathanw #include "opt_kgdb.h"
34 1.1.4.2 nathanw #include "pcons.h"
35 1.1.4.2 nathanw #include "kbd.h"
36 1.1.4.2 nathanw #include "zs.h"
37 1.1.4.2 nathanw
38 1.1.4.2 nathanw #include <sys/param.h>
39 1.1.4.2 nathanw #include <sys/systm.h>
40 1.1.4.2 nathanw #include <sys/conf.h>
41 1.1.4.2 nathanw #include <sys/device.h>
42 1.1.4.2 nathanw #include <sys/file.h>
43 1.1.4.2 nathanw #include <sys/ioctl.h>
44 1.1.4.2 nathanw #include <sys/kernel.h>
45 1.1.4.2 nathanw #include <sys/proc.h>
46 1.1.4.2 nathanw #include <sys/tty.h>
47 1.1.4.2 nathanw #include <sys/time.h>
48 1.1.4.2 nathanw #include <sys/syslog.h>
49 1.1.4.2 nathanw #include <sys/kgdb.h>
50 1.1.4.2 nathanw
51 1.1.4.2 nathanw #include <machine/autoconf.h>
52 1.1.4.2 nathanw #include <machine/promlib.h>
53 1.1.4.2 nathanw #include <machine/conf.h>
54 1.1.4.2 nathanw #include <machine/cpu.h>
55 1.1.4.2 nathanw #include <machine/eeprom.h>
56 1.1.4.2 nathanw #include <machine/psl.h>
57 1.1.4.2 nathanw #include <machine/z8530var.h>
58 1.1.4.2 nathanw
59 1.1.4.2 nathanw #include <dev/cons.h>
60 1.1.4.2 nathanw
61 1.1.4.2 nathanw #include <sun2/dev/cons.h>
62 1.1.4.2 nathanw
63 1.1.4.2 nathanw static void prom_cnprobe __P((struct consdev *));
64 1.1.4.2 nathanw static void prom_cninit __P((struct consdev *));
65 1.1.4.2 nathanw int prom_cngetc __P((dev_t));
66 1.1.4.2 nathanw static void prom_cnputc __P((dev_t, int));
67 1.1.4.2 nathanw static void prom_cnpollc __P((dev_t, int));
68 1.1.4.2 nathanw static void prom_cnputc __P((dev_t, int));
69 1.1.4.2 nathanw
70 1.1.4.2 nathanw #ifdef PROM_OBP_V2
71 1.1.4.2 nathanw /*
72 1.1.4.2 nathanw * The following several variables are related to
73 1.1.4.2 nathanw * the configuration process, and are used in initializing
74 1.1.4.2 nathanw * the machine.
75 1.1.4.2 nathanw */
76 1.1.4.2 nathanw int prom_stdin_node; /* node ID of ROM's console input device */
77 1.1.4.2 nathanw int prom_stdout_node; /* node ID of ROM's console output device */
78 1.1.4.2 nathanw char prom_stdin_args[16];
79 1.1.4.2 nathanw char prom_stdout_args[16];
80 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
81 1.1.4.2 nathanw
82 1.1.4.2 nathanw /*
83 1.1.4.2 nathanw * The console is set to this one initially,
84 1.1.4.2 nathanw * which lets us use the PROM until consinit()
85 1.1.4.2 nathanw * is called to select a real console.
86 1.1.4.2 nathanw */
87 1.1.4.2 nathanw struct consdev consdev_prom = {
88 1.1.4.2 nathanw prom_cnprobe,
89 1.1.4.2 nathanw prom_cninit,
90 1.1.4.2 nathanw prom_cngetc,
91 1.1.4.2 nathanw prom_cnputc,
92 1.1.4.2 nathanw prom_cnpollc,
93 1.1.4.2 nathanw NULL,
94 1.1.4.2 nathanw };
95 1.1.4.2 nathanw
96 1.1.4.2 nathanw /*
97 1.1.4.2 nathanw * The console table pointer is statically initialized
98 1.1.4.2 nathanw * to point to the PROM (output only) table, so that
99 1.1.4.2 nathanw * early calls to printf will work.
100 1.1.4.2 nathanw */
101 1.1.4.2 nathanw struct consdev *cn_tab = &consdev_prom;
102 1.1.4.2 nathanw
103 1.1.4.2 nathanw void
104 1.1.4.2 nathanw prom_cnprobe(cd)
105 1.1.4.2 nathanw struct consdev *cd;
106 1.1.4.2 nathanw {
107 1.1.4.2 nathanw #if NPCONS > 0
108 1.1.4.2 nathanw int maj;
109 1.1.4.2 nathanw
110 1.1.4.2 nathanw for (maj = 0; maj < nchrdev; maj++)
111 1.1.4.2 nathanw if (cdevsw[maj].d_open == pconsopen)
112 1.1.4.2 nathanw break;
113 1.1.4.2 nathanw cd->cn_dev = makedev(maj, 0);
114 1.1.4.2 nathanw cd->cn_pri = CN_INTERNAL;
115 1.1.4.2 nathanw #endif
116 1.1.4.2 nathanw }
117 1.1.4.2 nathanw
118 1.1.4.2 nathanw int
119 1.1.4.2 nathanw prom_cngetc(dev)
120 1.1.4.2 nathanw dev_t dev;
121 1.1.4.2 nathanw {
122 1.1.4.2 nathanw int ch;
123 1.1.4.2 nathanw #ifdef DDB
124 1.1.4.2 nathanw static int nplus = 0;
125 1.1.4.2 nathanw #endif
126 1.1.4.2 nathanw
127 1.1.4.2 nathanw ch = prom_getchar();
128 1.1.4.2 nathanw #ifdef DDB
129 1.1.4.2 nathanw if (ch == '+') {
130 1.1.4.2 nathanw if (nplus++ > 3) Debugger();
131 1.1.4.2 nathanw } else nplus = 0;
132 1.1.4.2 nathanw #endif
133 1.1.4.2 nathanw return ch;
134 1.1.4.2 nathanw }
135 1.1.4.2 nathanw
136 1.1.4.2 nathanw static void
137 1.1.4.2 nathanw prom_cninit(cn)
138 1.1.4.2 nathanw struct consdev *cn;
139 1.1.4.2 nathanw {
140 1.1.4.2 nathanw }
141 1.1.4.2 nathanw
142 1.1.4.2 nathanw /*
143 1.1.4.2 nathanw * PROM console output putchar.
144 1.1.4.2 nathanw */
145 1.1.4.2 nathanw static void
146 1.1.4.2 nathanw prom_cnputc(dev, c)
147 1.1.4.2 nathanw dev_t dev;
148 1.1.4.2 nathanw int c;
149 1.1.4.2 nathanw {
150 1.1.4.2 nathanw int s;
151 1.1.4.2 nathanw
152 1.1.4.2 nathanw s = splhigh();
153 1.1.4.2 nathanw prom_putchar(c);
154 1.1.4.2 nathanw splx(s);
155 1.1.4.2 nathanw }
156 1.1.4.2 nathanw
157 1.1.4.2 nathanw void
158 1.1.4.2 nathanw prom_cnpollc(dev, on)
159 1.1.4.2 nathanw dev_t dev;
160 1.1.4.2 nathanw int on;
161 1.1.4.2 nathanw {
162 1.1.4.2 nathanw if (on) {
163 1.1.4.2 nathanw /* Entering debugger. */
164 1.1.4.2 nathanw #if NFB > 0
165 1.1.4.2 nathanw fb_unblank();
166 1.1.4.2 nathanw #endif
167 1.1.4.2 nathanw } else {
168 1.1.4.2 nathanw /* Resuming kernel. */
169 1.1.4.2 nathanw }
170 1.1.4.2 nathanw #if NPCONS > 0
171 1.1.4.2 nathanw pcons_cnpollc(dev, on);
172 1.1.4.2 nathanw #endif
173 1.1.4.2 nathanw }
174 1.1.4.2 nathanw
175 1.1.4.2 nathanw /*****************************************************************/
176 1.1.4.2 nathanw
177 1.1.4.2 nathanw #ifdef DEBUG
178 1.1.4.2 nathanw #define DBPRINT(x) prom_printf x
179 1.1.4.2 nathanw #else
180 1.1.4.2 nathanw #define DBPRINT(x)
181 1.1.4.2 nathanw #endif
182 1.1.4.2 nathanw
183 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
184 1.1.4.2 nathanw void
185 1.1.4.2 nathanw prom_get_device_args(prop, dev, dev_sz, args, args_sz)
186 1.1.4.2 nathanw const char *prop;
187 1.1.4.2 nathanw char *dev;
188 1.1.4.2 nathanw unsigned int dev_sz;
189 1.1.4.2 nathanw char *args;
190 1.1.4.2 nathanw unsigned int args_sz;
191 1.1.4.2 nathanw {
192 1.1.4.2 nathanw char *cp, buffer[128];
193 1.1.4.2 nathanw
194 1.1.4.2 nathanw getpropstringA(prom_findroot(), (char *)prop, buffer, sizeof buffer);
195 1.1.4.2 nathanw
196 1.1.4.2 nathanw /*
197 1.1.4.2 nathanw * Extract device-specific arguments from a PROM device path (if any)
198 1.1.4.2 nathanw */
199 1.1.4.2 nathanw cp = buffer + strlen(buffer);
200 1.1.4.2 nathanw while (cp >= buffer) {
201 1.1.4.2 nathanw if (*cp == ':') {
202 1.1.4.2 nathanw strncpy(args, cp+1, args_sz);
203 1.1.4.2 nathanw *cp = '\0';
204 1.1.4.2 nathanw strncpy(dev, buffer, dev_sz);
205 1.1.4.2 nathanw break;
206 1.1.4.2 nathanw }
207 1.1.4.2 nathanw cp--;
208 1.1.4.2 nathanw }
209 1.1.4.2 nathanw }
210 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
211 1.1.4.2 nathanw
212 1.1.4.2 nathanw /*
213 1.1.4.2 nathanw * This function replaces sys/dev/cninit.c
214 1.1.4.2 nathanw * Determine which device is the console using
215 1.1.4.2 nathanw * the PROM "input source" and "output sink".
216 1.1.4.2 nathanw */
217 1.1.4.2 nathanw void
218 1.1.4.2 nathanw consinit()
219 1.1.4.2 nathanw {
220 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
221 1.1.4.2 nathanw char buffer[128];
222 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
223 1.1.4.2 nathanw char *consname = "unknown";
224 1.1.4.2 nathanw
225 1.1.4.2 nathanw DBPRINT(("consinit()\r\n"));
226 1.1.4.2 nathanw if (cn_tab != &consdev_prom) return;
227 1.1.4.2 nathanw
228 1.1.4.2 nathanw switch(prom_version()) {
229 1.1.4.2 nathanw #ifdef PROM_OLDMON
230 1.1.4.2 nathanw case PROM_OLDMON:
231 1.1.4.2 nathanw case PROM_OBP_V0:
232 1.1.4.2 nathanw switch(prom_stdin()) {
233 1.1.4.2 nathanw case PROMDEV_KBD:
234 1.1.4.2 nathanw consname = "keyboard/display";
235 1.1.4.2 nathanw break;
236 1.1.4.2 nathanw case PROMDEV_TTYA:
237 1.1.4.2 nathanw consname = "ttya";
238 1.1.4.2 nathanw break;
239 1.1.4.2 nathanw case PROMDEV_TTYB:
240 1.1.4.2 nathanw consname = "ttyb";
241 1.1.4.2 nathanw break;
242 1.1.4.2 nathanw }
243 1.1.4.2 nathanw break;
244 1.1.4.2 nathanw #endif /* PROM_OLDMON */
245 1.1.4.2 nathanw
246 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
247 1.1.4.2 nathanw case PROM_OBP_V2:
248 1.1.4.2 nathanw case PROM_OBP_V3:
249 1.1.4.2 nathanw case PROM_OPENFIRM:
250 1.1.4.2 nathanw
251 1.1.4.2 nathanw /* Save PROM arguments for device matching */
252 1.1.4.2 nathanw prom_get_device_args("stdin-path",
253 1.1.4.2 nathanw buffer,
254 1.1.4.2 nathanw sizeof(buffer),
255 1.1.4.2 nathanw prom_stdin_args,
256 1.1.4.2 nathanw sizeof(prom_stdin_args));
257 1.1.4.2 nathanw prom_get_device_args("stdout-path",
258 1.1.4.2 nathanw buffer,
259 1.1.4.2 nathanw sizeof(buffer),
260 1.1.4.2 nathanw prom_stdout_args,
261 1.1.4.2 nathanw sizeof(prom_stdout_args));
262 1.1.4.2 nathanw
263 1.1.4.2 nathanw /*
264 1.1.4.2 nathanw * Translate the STDIO package instance (`ihandle') -- that
265 1.1.4.2 nathanw * the PROM has already opened for us -- to a device tree
266 1.1.4.2 nathanw * node (i.e. a `phandle').
267 1.1.4.2 nathanw */
268 1.1.4.2 nathanw DBPRINT(("stdin instance = %x\r\n", prom_stdin()));
269 1.1.4.2 nathanw if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
270 1.1.4.2 nathanw printf("WARNING: no PROM stdin\n");
271 1.1.4.2 nathanw }
272 1.1.4.2 nathanw DBPRINT(("stdin package = %x\r\n", prom_stdin_node));
273 1.1.4.2 nathanw
274 1.1.4.2 nathanw DBPRINT(("stdout instance = %x\r\n", prom_stdout()));
275 1.1.4.2 nathanw if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0) {
276 1.1.4.2 nathanw printf("WARNING: no PROM stdout\n");
277 1.1.4.2 nathanw }
278 1.1.4.2 nathanw DBPRINT(("stdout package = %x\r\n", prom_stdout_node));
279 1.1.4.2 nathanw DBPRINT(("buffer @ %p\r\n", buffer));
280 1.1.4.2 nathanw
281 1.1.4.2 nathanw if (prom_stdin_node && prom_node_has_property(prom_stdin_node, "keyboard") {
282 1.1.4.2 nathanw #if NKBD == 0
283 1.1.4.2 nathanw printf("cninit: kdb/display not configured\n");
284 1.1.4.2 nathanw #endif
285 1.1.4.2 nathanw consname = "keyboard/display";
286 1.1.4.2 nathanw } else if (prom_stdout_node)
287 1.1.4.2 nathanw consname = buffer;
288 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
289 1.1.4.2 nathanw }
290 1.1.4.2 nathanw printf("console is %s\n", consname);
291 1.1.4.2 nathanw
292 1.1.4.2 nathanw /* Initialize PROM console */
293 1.1.4.2 nathanw (*cn_tab->cn_probe)(cn_tab);
294 1.1.4.2 nathanw (*cn_tab->cn_init)(cn_tab);
295 1.1.4.2 nathanw
296 1.1.4.2 nathanw #ifdef KGDB
297 1.1.4.2 nathanw /* Set up KGDB */
298 1.1.4.2 nathanw #if NZS > 0
299 1.1.4.2 nathanw if (cdevsw[major(kgdb_dev)].d_open == zsopen)
300 1.1.4.2 nathanw zs_kgdb_init();
301 1.1.4.2 nathanw #endif /* NZS > 0 */
302 1.1.4.2 nathanw #endif /* KGDB */
303 1.1.4.2 nathanw }
304 1.1.4.2 nathanw
305