consinit.c revision 1.9 1 1.9 mrg /* $NetBSD: consinit.c,v 1.9 2000/10/20 05:32:35 mrg Exp $ */
2 1.1 eeh
3 1.1 eeh /*-
4 1.1 eeh * Copyright (c) 1999 Eduardo E. Horvath
5 1.1 eeh * All rights reserved.
6 1.1 eeh *
7 1.1 eeh * Redistribution and use in source and binary forms, with or without
8 1.1 eeh * modification, are permitted provided that the following conditions
9 1.1 eeh * are met:
10 1.1 eeh * 1. Redistributions of source code must retain the above copyright
11 1.1 eeh * notice, this list of conditions and the following disclaimer.
12 1.1 eeh * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 eeh * notice, this list of conditions and the following disclaimer in the
14 1.1 eeh * documentation and/or other materials provided with the distribution.
15 1.1 eeh * 3. The name of the author may not be used to endorse or promote products
16 1.1 eeh * derived from this software without specific prior written permission.
17 1.1 eeh *
18 1.1 eeh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 eeh * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 eeh * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 eeh * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 eeh * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 1.1 eeh * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 1.1 eeh * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 1.1 eeh * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 1.1 eeh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.1 eeh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.1 eeh * SUCH DAMAGE.
29 1.1 eeh */
30 1.1 eeh
31 1.1 eeh #include "opt_ddb.h"
32 1.5 eeh #include "pcons.h"
33 1.1 eeh
34 1.1 eeh #include <sys/param.h>
35 1.1 eeh #include <sys/systm.h>
36 1.1 eeh #include <sys/conf.h>
37 1.1 eeh #include <sys/device.h>
38 1.1 eeh #include <sys/file.h>
39 1.1 eeh #include <sys/ioctl.h>
40 1.1 eeh #include <sys/kernel.h>
41 1.1 eeh #include <sys/proc.h>
42 1.1 eeh #include <sys/tty.h>
43 1.1 eeh #include <sys/time.h>
44 1.1 eeh #include <sys/syslog.h>
45 1.1 eeh
46 1.1 eeh #include <machine/autoconf.h>
47 1.1 eeh #include <machine/openfirm.h>
48 1.1 eeh #include <machine/bsd_openprom.h>
49 1.1 eeh #include <machine/conf.h>
50 1.1 eeh #include <machine/cpu.h>
51 1.1 eeh #include <machine/eeprom.h>
52 1.1 eeh #include <machine/psl.h>
53 1.1 eeh #include <machine/z8530var.h>
54 1.9 mrg #include <machine/sparc64.h>
55 1.1 eeh
56 1.1 eeh #include <dev/cons.h>
57 1.1 eeh
58 1.1 eeh #include <sparc64/dev/cons.h>
59 1.1 eeh
60 1.5 eeh static void prom_cnprobe __P((struct consdev *));
61 1.1 eeh static void prom_cninit __P((struct consdev *));
62 1.5 eeh int prom_cngetc __P((dev_t));
63 1.5 eeh static void prom_cnputc __P((dev_t, int));
64 1.5 eeh static void prom_cnpollc __P((dev_t, int));
65 1.1 eeh static void prom_cnputc __P((dev_t, int));
66 1.1 eeh
67 1.1 eeh int stdin = NULL, stdout = NULL;
68 1.1 eeh
69 1.1 eeh /*
70 1.1 eeh * The console is set to this one initially,
71 1.1 eeh * which lets us use the PROM until consinit()
72 1.1 eeh * is called to select a real console.
73 1.1 eeh */
74 1.1 eeh struct consdev consdev_prom = {
75 1.5 eeh prom_cnprobe,
76 1.1 eeh prom_cninit,
77 1.1 eeh prom_cngetc,
78 1.1 eeh prom_cnputc,
79 1.5 eeh prom_cnpollc,
80 1.2 thorpej NULL,
81 1.1 eeh };
82 1.1 eeh
83 1.1 eeh /*
84 1.1 eeh * The console table pointer is statically initialized
85 1.1 eeh * to point to the PROM (output only) table, so that
86 1.1 eeh * early calls to printf will work.
87 1.1 eeh */
88 1.1 eeh struct consdev *cn_tab = &consdev_prom;
89 1.1 eeh
90 1.1 eeh void
91 1.5 eeh prom_cnprobe(cd)
92 1.5 eeh struct consdev *cd;
93 1.1 eeh {
94 1.5 eeh #if NPCONS > 0
95 1.5 eeh int maj;
96 1.1 eeh
97 1.5 eeh for (maj = 0; maj < nchrdev; maj++)
98 1.5 eeh if (cdevsw[maj].d_open == pconsopen)
99 1.5 eeh break;
100 1.5 eeh cd->cn_dev = makedev(maj, 0);
101 1.5 eeh cd->cn_pri = CN_INTERNAL;
102 1.5 eeh #endif
103 1.1 eeh }
104 1.1 eeh
105 1.5 eeh int
106 1.1 eeh prom_cngetc(dev)
107 1.1 eeh dev_t dev;
108 1.1 eeh {
109 1.5 eeh unsigned char ch = '\0';
110 1.5 eeh int l;
111 1.7 eeh #ifdef DDB
112 1.7 eeh static int nplus = 0;
113 1.7 eeh #endif
114 1.5 eeh
115 1.5 eeh while ((l = OF_read(stdin, &ch, 1)) != 1)
116 1.5 eeh /* void */;
117 1.7 eeh #ifdef DDB
118 1.7 eeh if (ch == '+') {
119 1.7 eeh if (nplus++ > 3) Debugger();
120 1.7 eeh } else nplus = 0;
121 1.7 eeh #endif
122 1.5 eeh if (ch == '\r')
123 1.5 eeh ch = '\n';
124 1.5 eeh return ch;
125 1.5 eeh }
126 1.1 eeh
127 1.5 eeh static void
128 1.5 eeh prom_cninit(cn)
129 1.5 eeh struct consdev *cn;
130 1.5 eeh {
131 1.5 eeh if (!stdin) stdin = OF_stdin();
132 1.5 eeh if (!stdout) stdout = OF_stdout();
133 1.1 eeh }
134 1.1 eeh
135 1.1 eeh /*
136 1.1 eeh * PROM console output putchar.
137 1.1 eeh */
138 1.1 eeh static void
139 1.1 eeh prom_cnputc(dev, c)
140 1.1 eeh dev_t dev;
141 1.1 eeh int c;
142 1.1 eeh {
143 1.1 eeh int s;
144 1.1 eeh char c0 = (c & 0x7f);
145 1.1 eeh
146 1.5 eeh #if 0
147 1.5 eeh if (!stdout) stdout = OF_stdout();
148 1.5 eeh #endif
149 1.1 eeh s = splhigh();
150 1.1 eeh OF_write(stdout, &c0, 1);
151 1.1 eeh splx(s);
152 1.1 eeh }
153 1.1 eeh
154 1.5 eeh void
155 1.5 eeh prom_cnpollc(dev, on)
156 1.5 eeh dev_t dev;
157 1.5 eeh int on;
158 1.5 eeh {
159 1.5 eeh if (on) {
160 1.5 eeh /* Entering debugger. */
161 1.5 eeh #if NFB > 0
162 1.5 eeh fb_unblank();
163 1.5 eeh #endif
164 1.5 eeh } else {
165 1.5 eeh /* Resuming kernel. */
166 1.5 eeh }
167 1.5 eeh #if NPCONS > 0
168 1.5 eeh pcons_cnpollc(dev, on);
169 1.5 eeh #endif
170 1.5 eeh }
171 1.5 eeh
172 1.1 eeh /*****************************************************************/
173 1.1 eeh
174 1.1 eeh #ifdef DEBUG
175 1.8 eeh #define DBPRINT(x) prom_printf x
176 1.1 eeh #else
177 1.1 eeh #define DBPRINT(x)
178 1.1 eeh #endif
179 1.1 eeh
180 1.1 eeh /*
181 1.1 eeh * This function replaces sys/dev/cninit.c
182 1.1 eeh * Determine which device is the console using
183 1.1 eeh * the PROM "input source" and "output sink".
184 1.1 eeh */
185 1.1 eeh void
186 1.1 eeh consinit()
187 1.1 eeh {
188 1.1 eeh register int chosen;
189 1.1 eeh char buffer[128];
190 1.1 eeh extern int stdinnode, fbnode;
191 1.1 eeh char *consname = "unknown";
192 1.1 eeh
193 1.1 eeh DBPRINT(("consinit()\r\n"));
194 1.1 eeh if (cn_tab != &consdev_prom) return;
195 1.1 eeh
196 1.1 eeh DBPRINT(("setting up stdin\r\n"));
197 1.1 eeh chosen = OF_finddevice("/chosen");
198 1.1 eeh OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
199 1.1 eeh DBPRINT(("stdin instance = %x\r\n", stdin));
200 1.1 eeh
201 1.1 eeh if ((stdinnode = OF_instance_to_package(stdin)) == 0) {
202 1.1 eeh printf("WARNING: no PROM stdin\n");
203 1.1 eeh }
204 1.1 eeh
205 1.1 eeh DBPRINT(("setting up stdout\r\n"));
206 1.1 eeh OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
207 1.1 eeh
208 1.1 eeh DBPRINT(("stdout instance = %x\r\n", stdout));
209 1.1 eeh
210 1.1 eeh if ((fbnode = OF_instance_to_package(stdout)) == 0)
211 1.1 eeh printf("WARNING: no PROM stdout\n");
212 1.1 eeh
213 1.1 eeh DBPRINT(("stdout package = %x\r\n", fbnode));
214 1.1 eeh
215 1.1 eeh if (stdinnode && (OF_getproplen(stdinnode,"keyboard") >= 0)) {
216 1.1 eeh #if NKBD > 0
217 1.1 eeh printf("cninit: kdb/display not configured\n");
218 1.1 eeh #endif
219 1.1 eeh consname = "keyboard/display";
220 1.1 eeh } else if (fbnode &&
221 1.1 eeh (OF_instance_to_path(stdinnode, buffer, sizeof(buffer) >= 0))) {
222 1.1 eeh consname = buffer;
223 1.1 eeh }
224 1.1 eeh printf("console is %s\n", consname);
225 1.1 eeh
226 1.5 eeh /* Initialize PROM console */
227 1.5 eeh (*cn_tab->cn_probe)(cn_tab);
228 1.5 eeh (*cn_tab->cn_init)(cn_tab);
229 1.1 eeh }
230 1.1 eeh
231