consinit.c revision 1.18 1 /* $NetBSD: consinit.c,v 1.18 2005/05/31 00:50:28 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1999 Eduardo E. Horvath
5 * All rights reserved.
6 *
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.
17 *
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.
29 */
30
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.18 2005/05/31 00:50:28 christos Exp $");
33
34 #include "opt_ddb.h"
35 #include "pcons.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/conf.h>
40 #include <sys/device.h>
41 #include <sys/file.h>
42 #include <sys/ioctl.h>
43 #include <sys/kernel.h>
44 #include <sys/proc.h>
45 #include <sys/tty.h>
46 #include <sys/time.h>
47 #include <sys/syslog.h>
48
49 #include <machine/autoconf.h>
50 #include <machine/openfirm.h>
51 #include <machine/bsd_openprom.h>
52 #include <machine/cpu.h>
53 #include <machine/eeprom.h>
54 #include <machine/psl.h>
55 #include <machine/z8530var.h>
56 #include <machine/sparc64.h>
57
58 #include <dev/cons.h>
59
60 #include <sparc64/dev/cons.h>
61
62 static void prom_cnprobe __P((struct consdev *));
63 static void prom_cninit __P((struct consdev *));
64 int prom_cngetc __P((dev_t));
65 static void prom_cnputc __P((dev_t, int));
66 static void prom_cnpollc __P((dev_t, int));
67 static void prom_cnputc __P((dev_t, int));
68
69 /*
70 * The console is set to this one initially,
71 * which lets us use the PROM until consinit()
72 * is called to select a real console.
73 */
74 struct consdev consdev_prom = {
75 prom_cnprobe,
76 prom_cninit,
77 prom_cngetc,
78 prom_cnputc,
79 prom_cnpollc,
80 NULL,
81 };
82
83 /*
84 * The console table pointer is statically initialized
85 * to point to the PROM (output only) table, so that
86 * early calls to printf will work.
87 */
88 struct consdev *cn_tab = &consdev_prom;
89
90 void
91 prom_cnprobe(cd)
92 struct consdev *cd;
93 {
94 #if NPCONS > 0
95 int maj;
96 extern const struct cdevsw pcons_cdevsw;
97
98 maj = cdevsw_lookup_major(&pcons_cdevsw);
99 cd->cn_dev = makedev(maj, 0);
100 cd->cn_pri = CN_INTERNAL;
101 #endif
102 }
103
104 int
105 prom_cngetc(dev)
106 dev_t dev;
107 {
108 unsigned char ch = '\0';
109 int l;
110 #ifdef DDB
111 static int nplus = 0;
112 #endif
113
114 while ((l = prom_read(prom_stdin(), &ch, 1)) != 1)
115 /* void */;
116 #ifdef DDB
117 if (ch == '+') {
118 if (nplus++ > 3) Debugger();
119 } else nplus = 0;
120 #endif
121 if (ch == '\r')
122 ch = '\n';
123 return ch;
124 }
125
126 static void
127 prom_cninit(cn)
128 struct consdev *cn;
129 {
130 }
131
132 /*
133 * PROM console output putchar.
134 */
135 static void
136 prom_cnputc(dev, c)
137 dev_t dev;
138 int c;
139 {
140 int s;
141 char c0 = (c & 0x7f);
142
143 s = splhigh();
144 prom_write(prom_stdout(), &c0, 1);
145 splx(s);
146 }
147
148 void
149 prom_cnpollc(dev, on)
150 dev_t dev;
151 int on;
152 {
153 if (on) {
154 /* Entering debugger. */
155 #if NFB > 0
156 fb_unblank();
157 #endif
158 } else {
159 /* Resuming kernel. */
160 }
161 #if NPCONS > 0
162 pcons_cnpollc(dev, on);
163 #endif
164 }
165
166 /*****************************************************************/
167
168 #ifdef DEBUG
169 #define DBPRINT(x) prom_printf x
170 #else
171 #define DBPRINT(x)
172 #endif
173
174 int prom_stdin_node;
175 int prom_stdout_node;
176
177 /*
178 * This function replaces sys/dev/cninit.c
179 * Determine which device is the console using
180 * the PROM "input source" and "output sink".
181 */
182 void
183 consinit()
184 {
185 int chosen;
186 char buffer[128];
187 const char *consname = "unknown";
188
189 DBPRINT(("consinit()\r\n"));
190
191 if (cn_tab != &consdev_prom)
192 return;
193
194 chosen = prom_finddevice("/chosen");
195
196 if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
197 printf("WARNING: no PROM stdin\n");
198 }
199 DBPRINT(("stdin node = %x\r\n", prom_stdin_node));
200
201 if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0)
202 printf("WARNING: no PROM stdout\n");
203 DBPRINT(("stdout package = %x\r\n", prom_stdout_node));
204
205 DBPRINT(("buffer @ %p\r\n", buffer));
206
207 if (prom_stdin_node != 0 &&
208 (prom_getproplen(prom_stdin_node, "keyboard") >= 0)) {
209 #if NKBD > 0
210 printf("cninit: kdb/display not configured\n");
211 #endif
212 consname = "keyboard/display";
213 } else if (prom_stdout_node != 0 &&
214 (OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0)) {
215 consname = buffer;
216 }
217 printf("console is %s\n", consname);
218
219 /* Initialize PROM console */
220 (*cn_tab->cn_probe)(cn_tab);
221 (*cn_tab->cn_init)(cn_tab);
222 }
223
224