consinit.c revision 1.1.4.3 1 1.1.4.3 nathanw /* $NetBSD: consinit.c,v 1.1.4.3 2002/09/17 21:18:08 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/cpu.h>
54 1.1.4.2 nathanw #include <machine/eeprom.h>
55 1.1.4.2 nathanw #include <machine/psl.h>
56 1.1.4.2 nathanw #include <machine/z8530var.h>
57 1.1.4.2 nathanw
58 1.1.4.2 nathanw #include <dev/cons.h>
59 1.1.4.2 nathanw
60 1.1.4.2 nathanw #include <sun2/dev/cons.h>
61 1.1.4.2 nathanw
62 1.1.4.2 nathanw static void prom_cnprobe __P((struct consdev *));
63 1.1.4.2 nathanw static void prom_cninit __P((struct consdev *));
64 1.1.4.2 nathanw int prom_cngetc __P((dev_t));
65 1.1.4.2 nathanw static void prom_cnputc __P((dev_t, int));
66 1.1.4.2 nathanw static void prom_cnpollc __P((dev_t, int));
67 1.1.4.2 nathanw static void prom_cnputc __P((dev_t, int));
68 1.1.4.2 nathanw
69 1.1.4.2 nathanw #ifdef PROM_OBP_V2
70 1.1.4.2 nathanw /*
71 1.1.4.2 nathanw * The following several variables are related to
72 1.1.4.2 nathanw * the configuration process, and are used in initializing
73 1.1.4.2 nathanw * the machine.
74 1.1.4.2 nathanw */
75 1.1.4.2 nathanw int prom_stdin_node; /* node ID of ROM's console input device */
76 1.1.4.2 nathanw int prom_stdout_node; /* node ID of ROM's console output device */
77 1.1.4.2 nathanw char prom_stdin_args[16];
78 1.1.4.2 nathanw char prom_stdout_args[16];
79 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
80 1.1.4.2 nathanw
81 1.1.4.2 nathanw /*
82 1.1.4.2 nathanw * The console is set to this one initially,
83 1.1.4.2 nathanw * which lets us use the PROM until consinit()
84 1.1.4.2 nathanw * is called to select a real console.
85 1.1.4.2 nathanw */
86 1.1.4.2 nathanw struct consdev consdev_prom = {
87 1.1.4.2 nathanw prom_cnprobe,
88 1.1.4.2 nathanw prom_cninit,
89 1.1.4.2 nathanw prom_cngetc,
90 1.1.4.2 nathanw prom_cnputc,
91 1.1.4.2 nathanw prom_cnpollc,
92 1.1.4.2 nathanw NULL,
93 1.1.4.2 nathanw };
94 1.1.4.2 nathanw
95 1.1.4.2 nathanw /*
96 1.1.4.2 nathanw * The console table pointer is statically initialized
97 1.1.4.2 nathanw * to point to the PROM (output only) table, so that
98 1.1.4.2 nathanw * early calls to printf will work.
99 1.1.4.2 nathanw */
100 1.1.4.2 nathanw struct consdev *cn_tab = &consdev_prom;
101 1.1.4.2 nathanw
102 1.1.4.2 nathanw void
103 1.1.4.2 nathanw prom_cnprobe(cd)
104 1.1.4.2 nathanw struct consdev *cd;
105 1.1.4.2 nathanw {
106 1.1.4.2 nathanw #if NPCONS > 0
107 1.1.4.3 nathanw extern const struct cdevsw pcons_cdevsw;
108 1.1.4.2 nathanw
109 1.1.4.3 nathanw cd->cn_dev = makedev(cdevsw_lookup_major(&pcons_cdevsw), 0);
110 1.1.4.2 nathanw cd->cn_pri = CN_INTERNAL;
111 1.1.4.2 nathanw #endif
112 1.1.4.2 nathanw }
113 1.1.4.2 nathanw
114 1.1.4.2 nathanw int
115 1.1.4.2 nathanw prom_cngetc(dev)
116 1.1.4.2 nathanw dev_t dev;
117 1.1.4.2 nathanw {
118 1.1.4.2 nathanw int ch;
119 1.1.4.2 nathanw #ifdef DDB
120 1.1.4.2 nathanw static int nplus = 0;
121 1.1.4.2 nathanw #endif
122 1.1.4.2 nathanw
123 1.1.4.2 nathanw ch = prom_getchar();
124 1.1.4.2 nathanw #ifdef DDB
125 1.1.4.2 nathanw if (ch == '+') {
126 1.1.4.2 nathanw if (nplus++ > 3) Debugger();
127 1.1.4.2 nathanw } else nplus = 0;
128 1.1.4.2 nathanw #endif
129 1.1.4.2 nathanw return ch;
130 1.1.4.2 nathanw }
131 1.1.4.2 nathanw
132 1.1.4.2 nathanw static void
133 1.1.4.2 nathanw prom_cninit(cn)
134 1.1.4.2 nathanw struct consdev *cn;
135 1.1.4.2 nathanw {
136 1.1.4.2 nathanw }
137 1.1.4.2 nathanw
138 1.1.4.2 nathanw /*
139 1.1.4.2 nathanw * PROM console output putchar.
140 1.1.4.2 nathanw */
141 1.1.4.2 nathanw static void
142 1.1.4.2 nathanw prom_cnputc(dev, c)
143 1.1.4.2 nathanw dev_t dev;
144 1.1.4.2 nathanw int c;
145 1.1.4.2 nathanw {
146 1.1.4.2 nathanw int s;
147 1.1.4.2 nathanw
148 1.1.4.2 nathanw s = splhigh();
149 1.1.4.2 nathanw prom_putchar(c);
150 1.1.4.2 nathanw splx(s);
151 1.1.4.2 nathanw }
152 1.1.4.2 nathanw
153 1.1.4.2 nathanw void
154 1.1.4.2 nathanw prom_cnpollc(dev, on)
155 1.1.4.2 nathanw dev_t dev;
156 1.1.4.2 nathanw int on;
157 1.1.4.2 nathanw {
158 1.1.4.2 nathanw if (on) {
159 1.1.4.2 nathanw /* Entering debugger. */
160 1.1.4.2 nathanw #if NFB > 0
161 1.1.4.2 nathanw fb_unblank();
162 1.1.4.2 nathanw #endif
163 1.1.4.2 nathanw } else {
164 1.1.4.2 nathanw /* Resuming kernel. */
165 1.1.4.2 nathanw }
166 1.1.4.2 nathanw #if NPCONS > 0
167 1.1.4.2 nathanw pcons_cnpollc(dev, on);
168 1.1.4.2 nathanw #endif
169 1.1.4.2 nathanw }
170 1.1.4.2 nathanw
171 1.1.4.2 nathanw /*****************************************************************/
172 1.1.4.2 nathanw
173 1.1.4.2 nathanw #ifdef DEBUG
174 1.1.4.2 nathanw #define DBPRINT(x) prom_printf x
175 1.1.4.2 nathanw #else
176 1.1.4.2 nathanw #define DBPRINT(x)
177 1.1.4.2 nathanw #endif
178 1.1.4.2 nathanw
179 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
180 1.1.4.2 nathanw void
181 1.1.4.2 nathanw prom_get_device_args(prop, dev, dev_sz, args, args_sz)
182 1.1.4.2 nathanw const char *prop;
183 1.1.4.2 nathanw char *dev;
184 1.1.4.2 nathanw unsigned int dev_sz;
185 1.1.4.2 nathanw char *args;
186 1.1.4.2 nathanw unsigned int args_sz;
187 1.1.4.2 nathanw {
188 1.1.4.2 nathanw char *cp, buffer[128];
189 1.1.4.2 nathanw
190 1.1.4.2 nathanw getpropstringA(prom_findroot(), (char *)prop, buffer, sizeof buffer);
191 1.1.4.2 nathanw
192 1.1.4.2 nathanw /*
193 1.1.4.2 nathanw * Extract device-specific arguments from a PROM device path (if any)
194 1.1.4.2 nathanw */
195 1.1.4.2 nathanw cp = buffer + strlen(buffer);
196 1.1.4.2 nathanw while (cp >= buffer) {
197 1.1.4.2 nathanw if (*cp == ':') {
198 1.1.4.2 nathanw strncpy(args, cp+1, args_sz);
199 1.1.4.2 nathanw *cp = '\0';
200 1.1.4.2 nathanw strncpy(dev, buffer, dev_sz);
201 1.1.4.2 nathanw break;
202 1.1.4.2 nathanw }
203 1.1.4.2 nathanw cp--;
204 1.1.4.2 nathanw }
205 1.1.4.2 nathanw }
206 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
207 1.1.4.2 nathanw
208 1.1.4.2 nathanw /*
209 1.1.4.2 nathanw * This function replaces sys/dev/cninit.c
210 1.1.4.2 nathanw * Determine which device is the console using
211 1.1.4.2 nathanw * the PROM "input source" and "output sink".
212 1.1.4.2 nathanw */
213 1.1.4.2 nathanw void
214 1.1.4.2 nathanw consinit()
215 1.1.4.2 nathanw {
216 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
217 1.1.4.2 nathanw char buffer[128];
218 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
219 1.1.4.2 nathanw char *consname = "unknown";
220 1.1.4.3 nathanw #if KGDB
221 1.1.4.3 nathanw #if NZS > 0
222 1.1.4.3 nathanw extern const struct cdevsw zstty_cdevsw;
223 1.1.4.3 nathanw #endif
224 1.1.4.3 nathanw #endif
225 1.1.4.2 nathanw
226 1.1.4.2 nathanw DBPRINT(("consinit()\r\n"));
227 1.1.4.2 nathanw if (cn_tab != &consdev_prom) return;
228 1.1.4.2 nathanw
229 1.1.4.2 nathanw switch(prom_version()) {
230 1.1.4.2 nathanw #ifdef PROM_OLDMON
231 1.1.4.2 nathanw case PROM_OLDMON:
232 1.1.4.2 nathanw case PROM_OBP_V0:
233 1.1.4.2 nathanw switch(prom_stdin()) {
234 1.1.4.2 nathanw case PROMDEV_KBD:
235 1.1.4.2 nathanw consname = "keyboard/display";
236 1.1.4.2 nathanw break;
237 1.1.4.2 nathanw case PROMDEV_TTYA:
238 1.1.4.2 nathanw consname = "ttya";
239 1.1.4.2 nathanw break;
240 1.1.4.2 nathanw case PROMDEV_TTYB:
241 1.1.4.2 nathanw consname = "ttyb";
242 1.1.4.2 nathanw break;
243 1.1.4.2 nathanw }
244 1.1.4.2 nathanw break;
245 1.1.4.2 nathanw #endif /* PROM_OLDMON */
246 1.1.4.2 nathanw
247 1.1.4.2 nathanw #ifdef notyet /* PROM_OBP_V2 */
248 1.1.4.2 nathanw case PROM_OBP_V2:
249 1.1.4.2 nathanw case PROM_OBP_V3:
250 1.1.4.2 nathanw case PROM_OPENFIRM:
251 1.1.4.2 nathanw
252 1.1.4.2 nathanw /* Save PROM arguments for device matching */
253 1.1.4.2 nathanw prom_get_device_args("stdin-path",
254 1.1.4.2 nathanw buffer,
255 1.1.4.2 nathanw sizeof(buffer),
256 1.1.4.2 nathanw prom_stdin_args,
257 1.1.4.2 nathanw sizeof(prom_stdin_args));
258 1.1.4.2 nathanw prom_get_device_args("stdout-path",
259 1.1.4.2 nathanw buffer,
260 1.1.4.2 nathanw sizeof(buffer),
261 1.1.4.2 nathanw prom_stdout_args,
262 1.1.4.2 nathanw sizeof(prom_stdout_args));
263 1.1.4.2 nathanw
264 1.1.4.2 nathanw /*
265 1.1.4.2 nathanw * Translate the STDIO package instance (`ihandle') -- that
266 1.1.4.2 nathanw * the PROM has already opened for us -- to a device tree
267 1.1.4.2 nathanw * node (i.e. a `phandle').
268 1.1.4.2 nathanw */
269 1.1.4.2 nathanw DBPRINT(("stdin instance = %x\r\n", prom_stdin()));
270 1.1.4.2 nathanw if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
271 1.1.4.2 nathanw printf("WARNING: no PROM stdin\n");
272 1.1.4.2 nathanw }
273 1.1.4.2 nathanw DBPRINT(("stdin package = %x\r\n", prom_stdin_node));
274 1.1.4.2 nathanw
275 1.1.4.2 nathanw DBPRINT(("stdout instance = %x\r\n", prom_stdout()));
276 1.1.4.2 nathanw if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0) {
277 1.1.4.2 nathanw printf("WARNING: no PROM stdout\n");
278 1.1.4.2 nathanw }
279 1.1.4.2 nathanw DBPRINT(("stdout package = %x\r\n", prom_stdout_node));
280 1.1.4.2 nathanw DBPRINT(("buffer @ %p\r\n", buffer));
281 1.1.4.2 nathanw
282 1.1.4.2 nathanw if (prom_stdin_node && prom_node_has_property(prom_stdin_node, "keyboard") {
283 1.1.4.2 nathanw #if NKBD == 0
284 1.1.4.2 nathanw printf("cninit: kdb/display not configured\n");
285 1.1.4.2 nathanw #endif
286 1.1.4.2 nathanw consname = "keyboard/display";
287 1.1.4.2 nathanw } else if (prom_stdout_node)
288 1.1.4.2 nathanw consname = buffer;
289 1.1.4.2 nathanw #endif /* PROM_OBP_V2 */
290 1.1.4.2 nathanw }
291 1.1.4.2 nathanw printf("console is %s\n", consname);
292 1.1.4.2 nathanw
293 1.1.4.2 nathanw /* Initialize PROM console */
294 1.1.4.2 nathanw (*cn_tab->cn_probe)(cn_tab);
295 1.1.4.2 nathanw (*cn_tab->cn_init)(cn_tab);
296 1.1.4.2 nathanw
297 1.1.4.2 nathanw #ifdef KGDB
298 1.1.4.2 nathanw /* Set up KGDB */
299 1.1.4.2 nathanw #if NZS > 0
300 1.1.4.3 nathanw if (cdevsw_lookup(kgdb_dev) == &zstty_cdevsw)
301 1.1.4.2 nathanw zs_kgdb_init();
302 1.1.4.2 nathanw #endif /* NZS > 0 */
303 1.1.4.2 nathanw #endif /* KGDB */
304 1.1.4.2 nathanw }
305 1.1.4.2 nathanw
306