consinit.c revision 1.1 1 /* $NetBSD: consinit.c,v 1.1 1999/05/23 02:46:35 eeh 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 /*
32 * Default console driver. Uses the PROM or whatever
33 * driver(s) are appropriate.
34 */
35
36 #include "opt_ddb.h"
37
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>
49
50 #include <machine/autoconf.h>
51 #include <machine/openfirm.h>
52 #include <machine/bsd_openprom.h>
53 #include <machine/conf.h>
54 #include <machine/cpu.h>
55 #include <machine/eeprom.h>
56 #include <machine/psl.h>
57 #include <machine/z8530var.h>
58
59 #include <dev/cons.h>
60
61 #include <sparc64/sparc64/vaddrs.h>
62 #include <sparc64/sparc64/auxreg.h>
63 #include <sparc64/dev/cons.h>
64
65
66
67 static void prom_cninit __P((struct consdev *));
68 static int prom_cngetc __P((dev_t));
69 static void prom_cnputc __P((dev_t, int));
70
71 int stdin = NULL, stdout = NULL;
72
73 /*
74 * The console is set to this one initially,
75 * which lets us use the PROM until consinit()
76 * is called to select a real console.
77 */
78 struct consdev consdev_prom = {
79 nullcnprobe,
80 prom_cninit,
81 prom_cngetc,
82 prom_cnputc,
83 nullcnpollc,
84 };
85
86 /*
87 * The console table pointer is statically initialized
88 * to point to the PROM (output only) table, so that
89 * early calls to printf will work.
90 */
91 struct consdev *cn_tab = &consdev_prom;
92
93 void
94 nullcnprobe(cn)
95 struct consdev *cn;
96 {
97 }
98
99 static void
100 prom_cninit(cn)
101 struct consdev *cn;
102 {
103 if (!stdin) {
104 int node = OF_finddevice("/chosen");
105 OF_getprop(node, "stdin", &stdin, sizeof(stdin));
106 }
107 if (!stdout) {
108 int node = OF_finddevice("/chosen");
109 OF_getprop(node, "stdout", &stdout, sizeof(stdout));
110 }
111 }
112
113 /*
114 * PROM console input putchar.
115 * (dummy - this is output only)
116 */
117 static int
118 prom_cngetc(dev)
119 dev_t dev;
120 {
121 char c0;
122
123 if (!stdin) {
124 int node = OF_finddevice("/chosen");
125 OF_getprop(node, "stdin", &stdin, sizeof(stdin));
126 }
127 if (OF_read(stdin, &c0, 1) == 1)
128 return (c0);
129 return -1;
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 if (!stdout) {
144 int node = OF_finddevice("/chosen");
145 OF_getprop(node, "stdout", &stdout, sizeof(stdout));
146 }
147
148 s = splhigh();
149 OF_write(stdout, &c0, 1);
150 splx(s);
151 }
152
153 /*****************************************************************/
154
155 #ifdef DEBUG
156 #define DBPRINT(x) printf x
157 #else
158 #define DBPRINT(x)
159 #endif
160
161 /*
162 * This function replaces sys/dev/cninit.c
163 * Determine which device is the console using
164 * the PROM "input source" and "output sink".
165 */
166 void
167 consinit()
168 {
169 register int chosen;
170 char buffer[128];
171 extern int stdinnode, fbnode;
172 char *consname = "unknown";
173
174 DBPRINT(("consinit()\r\n"));
175 if (cn_tab != &consdev_prom) return;
176
177 DBPRINT(("setting up stdin\r\n"));
178 chosen = OF_finddevice("/chosen");
179 OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
180 DBPRINT(("stdin instance = %x\r\n", stdin));
181
182 if ((stdinnode = OF_instance_to_package(stdin)) == 0) {
183 printf("WARNING: no PROM stdin\n");
184 }
185
186 DBPRINT(("setting up stdout\r\n"));
187 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
188
189 DBPRINT(("stdout instance = %x\r\n", stdout));
190
191 if ((fbnode = OF_instance_to_package(stdout)) == 0)
192 printf("WARNING: no PROM stdout\n");
193
194 DBPRINT(("stdout package = %x\r\n", fbnode));
195
196 if (stdinnode && (OF_getproplen(stdinnode,"keyboard") >= 0)) {
197 #if NKBD > 0
198 printf("cninit: kdb/display not configured\n");
199 #endif
200 consname = "keyboard/display";
201 } else if (fbnode &&
202 (OF_instance_to_path(stdinnode, buffer, sizeof(buffer) >= 0))) {
203 consname = buffer;
204 }
205 printf("console is %s\n", consname);
206
207 /* Defer the rest to the device attach */
208 }
209
210