1 /* $NetBSD: consinit.c,v 1.6 2005/12/11 12:19:16 christos Exp $ */
4 * Copyright (c) 2001 Matthew Fredette
5 * Copyright (c) 1999 Eduardo E. Horvath
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.6 2005/12/11 12:19:16 christos Exp $");
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/device.h>
46 #include <sys/ioctl.h>
47 #include <sys/kernel.h>
51 #include <sys/syslog.h>
54 #include <machine/autoconf.h>
55 #include <machine/promlib.h>
56 #include <machine/cpu.h>
57 #include <machine/eeprom.h>
58 #include <machine/psl.h>
59 #include <machine/z8530var.h>
63 #include <sun2/dev/cons.h>
65 static void prom_cnprobe(struct consdev
*);
66 static void prom_cninit(struct consdev
*);
67 int prom_cngetc(dev_t
);
68 static void prom_cnputc(dev_t
, int);
69 static void prom_cnpollc(dev_t
, int);
70 static void prom_cnputc(dev_t
, int);
74 * The following several variables are related to
75 * the configuration process, and are used in initializing
78 int prom_stdin_node
; /* node ID of ROM's console input device */
79 int prom_stdout_node
; /* node ID of ROM's console output device */
80 char prom_stdin_args
[16];
81 char prom_stdout_args
[16];
82 #endif /* PROM_OBP_V2 */
85 * The console is set to this one initially,
86 * which lets us use the PROM until consinit()
87 * is called to select a real console.
89 struct consdev consdev_prom
= {
99 * The console table pointer is statically initialized
100 * to point to the PROM (output only) table, so that
101 * early calls to printf will work.
103 struct consdev
*cn_tab
= &consdev_prom
;
106 prom_cnprobe(struct consdev
*cd
)
109 extern const struct cdevsw pcons_cdevsw
;
111 cd
->cn_dev
= makedev(cdevsw_lookup_major(&pcons_cdevsw
), 0);
112 cd
->cn_pri
= CN_INTERNAL
;
117 prom_cngetc(dev_t dev
)
121 static int nplus
= 0;
127 if (nplus
++ > 3) Debugger();
134 prom_cninit(struct consdev
*cn
)
139 * PROM console output putchar.
142 prom_cnputc(dev_t dev
, int c
)
152 prom_cnpollc(dev_t dev
, int on
)
155 /* Entering debugger. */
160 /* Resuming kernel. */
163 pcons_cnpollc(dev
, on
);
167 /*****************************************************************/
170 #define DBPRINT(x) prom_printf x
175 #ifdef notyet /* PROM_OBP_V2 */
177 prom_get_device_args(const char *prop
, char *dev
, unsigned int dev_sz
,
178 char *args
, unsigned int args_sz
)
180 char *cp
, buffer
[128];
182 getpropstringA(prom_findroot(), (char *)prop
, buffer
, sizeof buffer
);
185 * Extract device-specific arguments from a PROM device path (if any)
187 cp
= buffer
+ strlen(buffer
);
188 while (cp
>= buffer
) {
190 strncpy(args
, cp
+1, args_sz
);
192 strncpy(dev
, buffer
, dev_sz
);
198 #endif /* PROM_OBP_V2 */
201 * This function replaces sys/dev/cninit.c
202 * Determine which device is the console using
203 * the PROM "input source" and "output sink".
208 #ifdef notyet /* PROM_OBP_V2 */
210 #endif /* PROM_OBP_V2 */
211 const char *consname
= "unknown";
214 extern const struct cdevsw zstty_cdevsw
;
218 DBPRINT(("consinit()\r\n"));
219 if (cn_tab
!= &consdev_prom
) return;
221 switch(prom_version()) {
225 switch(prom_stdin()) {
227 consname
= "keyboard/display";
237 #endif /* PROM_OLDMON */
239 #ifdef notyet /* PROM_OBP_V2 */
244 /* Save PROM arguments for device matching */
245 prom_get_device_args("stdin-path",
249 sizeof(prom_stdin_args
));
250 prom_get_device_args("stdout-path",
254 sizeof(prom_stdout_args
));
257 * Translate the STDIO package instance (`ihandle') -- that
258 * the PROM has already opened for us -- to a device tree
259 * node (i.e. a `phandle').
261 DBPRINT(("stdin instance = %x\r\n", prom_stdin()));
262 if ((prom_stdin_node
= prom_instance_to_package(prom_stdin())) == 0) {
263 printf("WARNING: no PROM stdin\n");
265 DBPRINT(("stdin package = %x\r\n", prom_stdin_node
));
267 DBPRINT(("stdout instance = %x\r\n", prom_stdout()));
268 if ((prom_stdout_node
= prom_instance_to_package(prom_stdout())) == 0) {
269 printf("WARNING: no PROM stdout\n");
271 DBPRINT(("stdout package = %x\r\n", prom_stdout_node
));
272 DBPRINT(("buffer @ %p\r\n", buffer
));
274 if (prom_stdin_node
&& prom_node_has_property(prom_stdin_node
, "keyboard")) {
276 printf("cninit: kdb/display not configured\n");
278 consname
= "keyboard/display";
279 } else if (prom_stdout_node
)
281 #endif /* PROM_OBP_V2 */
283 printf("console is %s\n", consname
);
285 /* Initialize PROM console */
286 (*cn_tab
->cn_probe
)(cn_tab
);
287 (*cn_tab
->cn_init
)(cn_tab
);
292 if (cdevsw_lookup(kgdb_dev
) == &zstty_cdevsw
)