No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / sparc64 / dev / consinit.c
blobcd184c6fc308c1586ebbc2cb6d134cfb81dfd3d2
1 /* $NetBSD: consinit.c,v 1.24 2007/10/17 19:57:28 garbled Exp $ */
3 /*-
4 * Copyright (c) 1999 Eduardo E. Horvath
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.24 2007/10/17 19:57:28 garbled Exp $");
34 #include "opt_ddb.h"
35 #include "pcons.h"
36 #include "ukbd.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/conf.h>
41 #include <sys/device.h>
42 #include <sys/file.h>
43 #include <sys/ioctl.h>
44 #include <sys/kernel.h>
45 #include <sys/proc.h>
46 #include <sys/tty.h>
47 #include <sys/time.h>
48 #include <sys/syslog.h>
50 #include <machine/autoconf.h>
51 #include <machine/openfirm.h>
52 #include <machine/bsd_openprom.h>
53 #include <machine/cpu.h>
54 #include <machine/eeprom.h>
55 #include <machine/psl.h>
56 #include <machine/z8530var.h>
57 #include <machine/sparc64.h>
59 #include <dev/cons.h>
61 #include <sparc64/dev/cons.h>
63 #include <dev/usb/ukbdvar.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);
72 * The console is set to this one initially,
73 * which lets us use the PROM until consinit()
74 * is called to select a real console.
76 struct consdev consdev_prom = {
77 .cn_probe = prom_cnprobe,
78 .cn_init = prom_cninit,
79 .cn_getc = prom_cngetc,
80 .cn_putc = prom_cnputc,
81 .cn_pollc = prom_cnpollc,
85 * The console table pointer is statically initialized
86 * to point to the PROM (output only) table, so that
87 * early calls to printf will work.
89 struct consdev *cn_tab = &consdev_prom;
91 void
92 prom_cnprobe(struct consdev *cd)
94 #if NPCONS > 0
95 int maj;
96 extern const struct cdevsw pcons_cdevsw;
98 maj = cdevsw_lookup_major(&pcons_cdevsw);
99 cd->cn_dev = makedev(maj, 0);
100 cd->cn_pri = CN_INTERNAL;
101 #endif
105 prom_cngetc(dev_t dev)
107 unsigned char ch = '\0';
108 int l;
109 #ifdef DDB
110 static int nplus = 0;
111 #endif
113 while ((l = prom_read(prom_stdin(), &ch, 1)) != 1)
114 /* void */;
115 #ifdef DDB
116 if (ch == '+') {
117 if (nplus++ > 3) Debugger();
118 } else nplus = 0;
119 #endif
120 if (ch == '\r')
121 ch = '\n';
122 return ch;
125 static void
126 prom_cninit(struct consdev *cn)
131 * PROM console output putchar.
133 static void
134 prom_cnputc(dev_t dev, int c)
136 int s;
137 char c0 = (c & 0x7f);
139 s = splhigh();
140 prom_write(prom_stdout(), &c0, 1);
141 splx(s);
144 void
145 prom_cnpollc(dev_t dev, int on)
147 if (on) {
148 /* Entering debugger. */
149 #if NFB > 0
150 fb_unblank();
151 #endif
152 } else {
153 /* Resuming kernel. */
155 #if NPCONS > 0
156 pcons_cnpollc(dev, on);
157 #endif
160 /*****************************************************************/
162 #ifdef DEBUG
163 #define DBPRINT(x) prom_printf x
164 #else
165 #define DBPRINT(x)
166 #endif
168 int prom_stdin_node;
169 int prom_stdout_node;
172 * This function replaces sys/dev/cninit.c
173 * Determine which device is the console using
174 * the PROM "input source" and "output sink".
176 void
177 consinit(void)
179 int chosen;
180 char buffer[128];
181 const char *consname = "unknown";
183 DBPRINT(("consinit()\r\n"));
185 if (cn_tab != &consdev_prom)
186 return;
188 chosen = prom_finddevice("/chosen");
190 if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
191 printf("WARNING: no PROM stdin\n");
193 DBPRINT(("stdin node = %x\r\n", prom_stdin_node));
195 if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0)
196 printf("WARNING: no PROM stdout\n");
197 DBPRINT(("stdout package = %x\r\n", prom_stdout_node));
199 DBPRINT(("buffer @ %p\r\n", buffer));
201 if (prom_stdin_node != 0 &&
202 (prom_getproplen(prom_stdin_node, "keyboard") >= 0)) {
203 #if NUKBD > 0
204 if ((OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0) &&
205 (strstr(buffer, "/usb@") != NULL)) {
207 * If we have a USB keyboard, it will show up as (e.g.)
208 * /pci@1f,0/usb@c,3/keyboard@1 (Blade 100)
210 consname = "usb-keyboard/display";
211 ukbd_cnattach();
212 } else
213 #endif
214 consname = "sun-keyboard/display";
215 } else if (prom_stdin_node != 0 &&
216 (OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0)) {
217 consname = buffer;
219 DBPRINT(("console is %s\n", consname));
221 /* Initialize PROM console */
222 (*cn_tab->cn_probe)(cn_tab);
223 (*cn_tab->cn_init)(cn_tab);