kd.c revision 1.5.2.2 1 1.5.2.2 bouyer /* $NetBSD: kd.c,v 1.5.2.2 2000/11/22 16:01:37 bouyer Exp $ */
2 1.1 gwr
3 1.1 gwr /*-
4 1.1 gwr * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This code is derived from software contributed to The NetBSD Foundation
8 1.1 gwr * by Gordon W. Ross.
9 1.1 gwr *
10 1.1 gwr * Redistribution and use in source and binary forms, with or without
11 1.1 gwr * modification, are permitted provided that the following conditions
12 1.1 gwr * are met:
13 1.1 gwr * 1. Redistributions of source code must retain the above copyright
14 1.1 gwr * notice, this list of conditions and the following disclaimer.
15 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 gwr * notice, this list of conditions and the following disclaimer in the
17 1.1 gwr * documentation and/or other materials provided with the distribution.
18 1.1 gwr * 3. All advertising materials mentioning features or use of this software
19 1.1 gwr * must display the following acknowledgement:
20 1.1 gwr * This product includes software developed by the NetBSD
21 1.1 gwr * Foundation, Inc. and its contributors.
22 1.1 gwr * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 gwr * contributors may be used to endorse or promote products derived
24 1.1 gwr * from this software without specific prior written permission.
25 1.1 gwr *
26 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 gwr * POSSIBILITY OF SUCH DAMAGE.
37 1.1 gwr */
38 1.1 gwr
39 1.1 gwr /*
40 1.5.2.1 bouyer * Console driver based on PROM primitives.
41 1.1 gwr *
42 1.5.2.1 bouyer * This driver exists to provide a tty device that the indirect
43 1.5.2.1 bouyer * console driver can point to. It also provides a hook that
44 1.5.2.1 bouyer * allows another device to serve console input. This will normally
45 1.5.2.1 bouyer * be a keyboard driver (see sys/dev/sun/kbd.c)
46 1.1 gwr */
47 1.1 gwr
48 1.1 gwr #include <sys/param.h>
49 1.1 gwr #include <sys/proc.h>
50 1.1 gwr #include <sys/systm.h>
51 1.5.2.1 bouyer #include <sys/kernel.h>
52 1.1 gwr #include <sys/ioctl.h>
53 1.1 gwr #include <sys/tty.h>
54 1.1 gwr #include <sys/file.h>
55 1.1 gwr #include <sys/conf.h>
56 1.1 gwr #include <sys/device.h>
57 1.1 gwr
58 1.1 gwr #include <machine/bsd_openprom.h>
59 1.4 pk #include <machine/promlib.h>
60 1.1 gwr #include <machine/eeprom.h>
61 1.1 gwr #include <machine/psl.h>
62 1.1 gwr #include <machine/cpu.h>
63 1.1 gwr #include <machine/kbd.h>
64 1.1 gwr #include <machine/autoconf.h>
65 1.1 gwr #include <machine/conf.h>
66 1.1 gwr
67 1.1 gwr #ifdef RASTERCONSOLE
68 1.5.2.1 bouyer #include <dev/sun/fbio.h>
69 1.5.2.1 bouyer #include <dev/sun/fbvar.h>
70 1.1 gwr #endif
71 1.1 gwr
72 1.1 gwr #include <dev/cons.h>
73 1.1 gwr #include <sparc/dev/cons.h>
74 1.1 gwr
75 1.5.2.1 bouyer #include <dev/sun/event_var.h>
76 1.5.2.1 bouyer #include <dev/sun/kbd_xlate.h>
77 1.5.2.1 bouyer #include <dev/sun/kbdvar.h>
78 1.1 gwr
79 1.1 gwr #define KDMAJOR 1
80 1.1 gwr #define PUT_WSIZE 64
81 1.1 gwr
82 1.1 gwr struct kd_softc {
83 1.1 gwr struct device kd_dev; /* required first: base device */
84 1.1 gwr struct tty *kd_tty;
85 1.1 gwr int rows, cols;
86 1.5.2.1 bouyer
87 1.5.2.1 bouyer /* Console input hook */
88 1.5.2.1 bouyer struct cons_channel *kd_in;
89 1.1 gwr };
90 1.1 gwr
91 1.1 gwr /*
92 1.1 gwr * There is no point in pretending there might be
93 1.1 gwr * more than one keyboard/display device.
94 1.1 gwr */
95 1.1 gwr static struct kd_softc kd_softc;
96 1.1 gwr
97 1.1 gwr static int kdparam(struct tty *, struct termios *);
98 1.1 gwr static void kdstart(struct tty *);
99 1.5.2.1 bouyer static void kd_init __P((struct kd_softc *));
100 1.5.2.1 bouyer static void kd_cons_input __P((int));
101 1.1 gwr
102 1.1 gwr /*
103 1.5.2.1 bouyer * Prepare the console tty; called on first open of /dev/console
104 1.1 gwr */
105 1.1 gwr void
106 1.5.2.1 bouyer kd_init(kd)
107 1.1 gwr struct kd_softc *kd;
108 1.5.2.1 bouyer {
109 1.1 gwr struct tty *tp;
110 1.1 gwr
111 1.1 gwr tp = ttymalloc();
112 1.1 gwr tp->t_oproc = kdstart;
113 1.1 gwr tp->t_param = kdparam;
114 1.5.2.1 bouyer tp->t_dev = makedev(KDMAJOR, 0);
115 1.1 gwr
116 1.1 gwr tty_attach(tp);
117 1.1 gwr kd->kd_tty = tp;
118 1.1 gwr
119 1.1 gwr /*
120 1.5.2.1 bouyer * Get the console struct winsize.
121 1.1 gwr */
122 1.1 gwr #ifdef RASTERCONSOLE
123 1.5.2.1 bouyer /* If the raster console driver is attached, copy its size */
124 1.5.2.1 bouyer kd->rows = fbrcons_rows();
125 1.5.2.1 bouyer kd->cols = fbrcons_cols();
126 1.5.2.1 bouyer rcons_ttyinit(tp);
127 1.1 gwr #endif
128 1.1 gwr
129 1.5.2.1 bouyer /* else, consult the PROM */
130 1.5.2.1 bouyer switch (prom_version()) {
131 1.5.2.1 bouyer char *prop;
132 1.5.2.1 bouyer struct eeprom *ep;
133 1.5.2.1 bouyer case PROM_OLDMON:
134 1.5.2.1 bouyer if ((ep = (struct eeprom *)eeprom_va) == NULL)
135 1.5.2.1 bouyer break;
136 1.5.2.1 bouyer if (kd->rows == 0)
137 1.5.2.1 bouyer kd->rows = (u_short)ep->eeTtyRows;
138 1.5.2.1 bouyer if (kd->cols == 0)
139 1.5.2.1 bouyer kd->cols = (u_short)ep->eeTtyCols;
140 1.5.2.1 bouyer break;
141 1.5.2.1 bouyer case PROM_OBP_V0:
142 1.5.2.1 bouyer case PROM_OBP_V2:
143 1.5.2.1 bouyer case PROM_OBP_V3:
144 1.5.2.1 bouyer case PROM_OPENFIRM:
145 1.1 gwr
146 1.1 gwr if (kd->rows == 0 &&
147 1.1 gwr (prop = getpropstring(optionsnode, "screen-#rows"))) {
148 1.5.2.1 bouyer int i = 0;
149 1.5.2.1 bouyer
150 1.1 gwr while (*prop != '\0')
151 1.1 gwr i = i * 10 + *prop++ - '0';
152 1.1 gwr kd->rows = (unsigned short)i;
153 1.1 gwr }
154 1.1 gwr if (kd->cols == 0 &&
155 1.1 gwr (prop = getpropstring(optionsnode, "screen-#columns"))) {
156 1.5.2.1 bouyer int i = 0;
157 1.5.2.1 bouyer
158 1.1 gwr while (*prop != '\0')
159 1.1 gwr i = i * 10 + *prop++ - '0';
160 1.1 gwr kd->cols = (unsigned short)i;
161 1.1 gwr }
162 1.5.2.1 bouyer break;
163 1.1 gwr }
164 1.1 gwr
165 1.1 gwr return;
166 1.1 gwr }
167 1.1 gwr
168 1.1 gwr struct tty *
169 1.1 gwr kdtty(dev)
170 1.1 gwr dev_t dev;
171 1.1 gwr {
172 1.1 gwr struct kd_softc *kd;
173 1.1 gwr
174 1.1 gwr kd = &kd_softc; /* XXX */
175 1.1 gwr return (kd->kd_tty);
176 1.1 gwr }
177 1.1 gwr
178 1.1 gwr int
179 1.1 gwr kdopen(dev, flag, mode, p)
180 1.1 gwr dev_t dev;
181 1.1 gwr int flag, mode;
182 1.1 gwr struct proc *p;
183 1.1 gwr {
184 1.1 gwr struct kd_softc *kd;
185 1.1 gwr int error, s, unit;
186 1.1 gwr struct tty *tp;
187 1.5.2.1 bouyer static int firstopen = 1;
188 1.5.2.1 bouyer
189 1.1 gwr unit = minor(dev);
190 1.1 gwr if (unit != 0)
191 1.1 gwr return ENXIO;
192 1.1 gwr
193 1.5.2.1 bouyer kd = &kd_softc; /* XXX */
194 1.5.2.1 bouyer if (firstopen) {
195 1.5.2.1 bouyer kd_init(kd);
196 1.5.2.1 bouyer firstopen = 0;
197 1.1 gwr }
198 1.1 gwr
199 1.5.2.1 bouyer tp = kd->kd_tty;
200 1.5.2.1 bouyer
201 1.1 gwr /* It's simpler to do this up here. */
202 1.1 gwr if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
203 1.1 gwr == (TS_ISOPEN | TS_XCLUDE))
204 1.1 gwr && (p->p_ucred->cr_uid != 0) )
205 1.1 gwr {
206 1.1 gwr return (EBUSY);
207 1.1 gwr }
208 1.1 gwr
209 1.1 gwr s = spltty();
210 1.1 gwr if ((tp->t_state & TS_ISOPEN) == 0) {
211 1.1 gwr /* First open. */
212 1.5.2.1 bouyer
213 1.5.2.1 bouyer /* Notify the input device that serves us */
214 1.5.2.1 bouyer struct cons_channel *cc = kd->kd_in;
215 1.5.2.1 bouyer if (cc != NULL &&
216 1.5.2.1 bouyer (error = (*cc->cc_iopen)(cc)) != 0) {
217 1.5.2.1 bouyer return (error);
218 1.5.2.1 bouyer }
219 1.5.2.1 bouyer
220 1.1 gwr ttychars(tp);
221 1.1 gwr tp->t_iflag = TTYDEF_IFLAG;
222 1.1 gwr tp->t_oflag = TTYDEF_OFLAG;
223 1.1 gwr tp->t_cflag = TTYDEF_CFLAG;
224 1.1 gwr tp->t_lflag = TTYDEF_LFLAG;
225 1.1 gwr tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
226 1.1 gwr (void) kdparam(tp, &tp->t_termios);
227 1.1 gwr ttsetwater(tp);
228 1.1 gwr tp->t_winsize.ws_row = kd->rows;
229 1.1 gwr tp->t_winsize.ws_col = kd->cols;
230 1.1 gwr /* Flush pending input? Clear translator? */
231 1.1 gwr /* This (pseudo)device always has SOFTCAR */
232 1.1 gwr tp->t_state |= TS_CARR_ON;
233 1.1 gwr }
234 1.1 gwr
235 1.1 gwr splx(s);
236 1.1 gwr
237 1.5.2.2 bouyer return ((*tp->t_linesw->l_open)(dev, tp));
238 1.1 gwr }
239 1.1 gwr
240 1.1 gwr int
241 1.1 gwr kdclose(dev, flag, mode, p)
242 1.1 gwr dev_t dev;
243 1.1 gwr int flag, mode;
244 1.1 gwr struct proc *p;
245 1.1 gwr {
246 1.1 gwr struct kd_softc *kd;
247 1.1 gwr struct tty *tp;
248 1.5.2.1 bouyer struct cons_channel *cc;
249 1.1 gwr
250 1.1 gwr kd = &kd_softc; /* XXX */
251 1.1 gwr tp = kd->kd_tty;
252 1.1 gwr
253 1.1 gwr /* XXX This is for cons.c. */
254 1.1 gwr if ((tp->t_state & TS_ISOPEN) == 0)
255 1.1 gwr return 0;
256 1.1 gwr
257 1.5.2.2 bouyer (*tp->t_linesw->l_close)(tp, flag);
258 1.1 gwr ttyclose(tp);
259 1.5.2.1 bouyer
260 1.5.2.1 bouyer if ((cc = kd->kd_in) != NULL)
261 1.5.2.1 bouyer (void)(*cc->cc_iclose)(cc);
262 1.5.2.1 bouyer
263 1.1 gwr return (0);
264 1.1 gwr }
265 1.1 gwr
266 1.1 gwr int
267 1.1 gwr kdread(dev, uio, flag)
268 1.1 gwr dev_t dev;
269 1.1 gwr struct uio *uio;
270 1.1 gwr int flag;
271 1.1 gwr {
272 1.1 gwr struct kd_softc *kd;
273 1.1 gwr struct tty *tp;
274 1.1 gwr
275 1.1 gwr kd = &kd_softc; /* XXX */
276 1.1 gwr tp = kd->kd_tty;
277 1.1 gwr
278 1.5.2.2 bouyer return ((*tp->t_linesw->l_read)(tp, uio, flag));
279 1.1 gwr }
280 1.1 gwr
281 1.1 gwr int
282 1.1 gwr kdwrite(dev, uio, flag)
283 1.1 gwr dev_t dev;
284 1.1 gwr struct uio *uio;
285 1.1 gwr int flag;
286 1.1 gwr {
287 1.1 gwr struct kd_softc *kd;
288 1.1 gwr struct tty *tp;
289 1.1 gwr
290 1.1 gwr kd = &kd_softc; /* XXX */
291 1.1 gwr tp = kd->kd_tty;
292 1.1 gwr
293 1.5.2.2 bouyer return ((*tp->t_linesw->l_write)(tp, uio, flag));
294 1.1 gwr }
295 1.1 gwr
296 1.1 gwr int
297 1.1 gwr kdioctl(dev, cmd, data, flag, p)
298 1.1 gwr dev_t dev;
299 1.1 gwr u_long cmd;
300 1.1 gwr caddr_t data;
301 1.1 gwr int flag;
302 1.1 gwr struct proc *p;
303 1.1 gwr {
304 1.1 gwr struct kd_softc *kd;
305 1.1 gwr struct tty *tp;
306 1.1 gwr int error;
307 1.1 gwr
308 1.1 gwr kd = &kd_softc; /* XXX */
309 1.1 gwr tp = kd->kd_tty;
310 1.1 gwr
311 1.5.2.2 bouyer error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
312 1.1 gwr if (error >= 0)
313 1.1 gwr return error;
314 1.1 gwr error = ttioctl(tp, cmd, data, flag, p);
315 1.1 gwr if (error >= 0)
316 1.1 gwr return error;
317 1.1 gwr
318 1.1 gwr /* Handle any ioctl commands specific to kbd/display. */
319 1.1 gwr /* XXX - Send KB* ioctls to kbd module? */
320 1.1 gwr /* XXX - Send FB* ioctls to fb module? */
321 1.1 gwr
322 1.1 gwr return ENOTTY;
323 1.1 gwr }
324 1.1 gwr
325 1.1 gwr void
326 1.1 gwr kdstop(tp, flag)
327 1.1 gwr struct tty *tp;
328 1.1 gwr int flag;
329 1.1 gwr {
330 1.1 gwr
331 1.1 gwr }
332 1.1 gwr
333 1.1 gwr
334 1.1 gwr static int
335 1.1 gwr kdparam(tp, t)
336 1.1 gwr struct tty *tp;
337 1.1 gwr struct termios *t;
338 1.1 gwr {
339 1.1 gwr /* XXX - These are ignored... */
340 1.1 gwr tp->t_ispeed = t->c_ispeed;
341 1.1 gwr tp->t_ospeed = t->c_ospeed;
342 1.1 gwr tp->t_cflag = t->c_cflag;
343 1.1 gwr return 0;
344 1.1 gwr }
345 1.1 gwr
346 1.1 gwr
347 1.1 gwr static void kd_later(void*);
348 1.1 gwr static void kd_putfb(struct tty *);
349 1.1 gwr
350 1.1 gwr static void
351 1.1 gwr kdstart(tp)
352 1.1 gwr struct tty *tp;
353 1.1 gwr {
354 1.1 gwr struct clist *cl;
355 1.5.2.1 bouyer int s;
356 1.1 gwr
357 1.1 gwr s = spltty();
358 1.1 gwr if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
359 1.1 gwr goto out;
360 1.1 gwr
361 1.1 gwr cl = &tp->t_outq;
362 1.1 gwr if (cl->c_cc) {
363 1.5.2.1 bouyer tp->t_state |= TS_BUSY;
364 1.5.2.1 bouyer if ((s & PSR_PIL) == 0) {
365 1.5.2.1 bouyer /* called at level zero - update screen now. */
366 1.5.2.1 bouyer (void) spllowersoftclock();
367 1.5.2.1 bouyer kd_putfb(tp);
368 1.5.2.1 bouyer (void) spltty();
369 1.5.2.1 bouyer tp->t_state &= ~TS_BUSY;
370 1.1 gwr } else {
371 1.5.2.1 bouyer /* called at interrupt level - do it later */
372 1.5.2.1 bouyer callout_reset(&tp->t_rstrt_ch, 0, kd_later, tp);
373 1.1 gwr }
374 1.1 gwr }
375 1.1 gwr if (cl->c_cc <= tp->t_lowat) {
376 1.1 gwr if (tp->t_state & TS_ASLEEP) {
377 1.1 gwr tp->t_state &= ~TS_ASLEEP;
378 1.1 gwr wakeup((caddr_t)cl);
379 1.1 gwr }
380 1.1 gwr selwakeup(&tp->t_wsel);
381 1.1 gwr }
382 1.1 gwr out:
383 1.1 gwr splx(s);
384 1.1 gwr }
385 1.1 gwr
386 1.1 gwr /*
387 1.1 gwr * Timeout function to do delayed writes to the screen.
388 1.1 gwr * Called at splsoftclock when requested by kdstart.
389 1.1 gwr */
390 1.1 gwr static void
391 1.5.2.1 bouyer kd_later(arg)
392 1.5.2.1 bouyer void *arg;
393 1.1 gwr {
394 1.5.2.1 bouyer struct tty *tp = arg;
395 1.5.2.1 bouyer int s;
396 1.1 gwr
397 1.1 gwr kd_putfb(tp);
398 1.1 gwr
399 1.1 gwr s = spltty();
400 1.1 gwr tp->t_state &= ~TS_BUSY;
401 1.5.2.2 bouyer (*tp->t_linesw->l_start)(tp);
402 1.1 gwr splx(s);
403 1.1 gwr }
404 1.1 gwr
405 1.1 gwr /*
406 1.1 gwr * Put text on the screen using the PROM monitor.
407 1.1 gwr * This can take a while, so to avoid missing
408 1.1 gwr * interrupts, this is called at splsoftclock.
409 1.1 gwr */
410 1.1 gwr static void
411 1.1 gwr kd_putfb(tp)
412 1.1 gwr struct tty *tp;
413 1.1 gwr {
414 1.1 gwr char buf[PUT_WSIZE];
415 1.1 gwr struct clist *cl = &tp->t_outq;
416 1.1 gwr char *p, *end;
417 1.1 gwr int len;
418 1.1 gwr
419 1.1 gwr while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
420 1.1 gwr /* PROM will barf if high bits are set. */
421 1.1 gwr p = buf;
422 1.1 gwr end = buf + len;
423 1.1 gwr while (p < end)
424 1.1 gwr *p++ &= 0x7f;
425 1.4 pk
426 1.1 gwr /* Now let the PROM print it. */
427 1.4 pk prom_putstr(buf, len);
428 1.1 gwr }
429 1.1 gwr }
430 1.1 gwr
431 1.1 gwr /*
432 1.1 gwr * Our "interrupt" routine for input. This is called by
433 1.1 gwr * the keyboard driver (dev/sun/kbd.c) at spltty.
434 1.1 gwr */
435 1.1 gwr void
436 1.5.2.1 bouyer kd_cons_input(c)
437 1.1 gwr int c;
438 1.1 gwr {
439 1.1 gwr struct kd_softc *kd = &kd_softc;
440 1.1 gwr struct tty *tp;
441 1.1 gwr
442 1.1 gwr /* XXX: Make sure the device is open. */
443 1.1 gwr tp = kd->kd_tty;
444 1.1 gwr if (tp == NULL)
445 1.1 gwr return;
446 1.1 gwr if ((tp->t_state & TS_ISOPEN) == 0)
447 1.1 gwr return;
448 1.1 gwr
449 1.5.2.2 bouyer (*tp->t_linesw->l_rint)(c, tp);
450 1.1 gwr }
451 1.1 gwr
452 1.5.2.1 bouyer void
453 1.5.2.1 bouyer cons_attach_input(cc, cn)
454 1.5.2.1 bouyer struct cons_channel *cc;
455 1.1 gwr struct consdev *cn;
456 1.1 gwr {
457 1.5.2.1 bouyer struct kd_softc *kd = &kd_softc;
458 1.5.2.1 bouyer
459 1.5.2.1 bouyer kd->kd_in = cc;
460 1.5.2.1 bouyer cc->cc_upstream = kd_cons_input;
461 1.1 gwr }
462 1.1 gwr
463 1.5.2.1 bouyer void kd_attach_input(struct cons_channel *);
464 1.5.2.1 bouyer void
465 1.5.2.1 bouyer kd_attach_input(cc)
466 1.5.2.1 bouyer struct cons_channel *cc;
467 1.1 gwr {
468 1.5.2.1 bouyer struct kd_softc *kd = &kd_softc;
469 1.1 gwr
470 1.5.2.1 bouyer kd->kd_in = cc;
471 1.5.2.1 bouyer cc->cc_upstream = kd_cons_input;
472 1.5.2.1 bouyer }
473 1.1 gwr
474 1.5.2.1 bouyer /*
475 1.5.2.1 bouyer * Default PROM-based console input stream
476 1.5.2.1 bouyer * Since the PROM does not notify us when data is available on the
477 1.5.2.1 bouyer * input channel these functions periodically poll the PROM.
478 1.5.2.1 bouyer */
479 1.5.2.1 bouyer static int kd_rom_iopen __P((struct cons_channel *));
480 1.5.2.1 bouyer static int kd_rom_iclose __P((struct cons_channel *));
481 1.5.2.1 bouyer static void kd_rom_intr __P((void *));
482 1.5.2.1 bouyer
483 1.5.2.1 bouyer static struct cons_channel prom_cons_channel;
484 1.1 gwr
485 1.5.2.1 bouyer int
486 1.5.2.1 bouyer kd_rom_iopen(cc)
487 1.5.2.1 bouyer struct cons_channel *cc;
488 1.5.2.1 bouyer {
489 1.5.2.1 bouyer /* Poll for ROM input 4 times per second */
490 1.5.2.1 bouyer callout_reset(&cc->cc_callout, hz / 4, kd_rom_intr, cc);
491 1.5.2.1 bouyer return (0);
492 1.1 gwr }
493 1.1 gwr
494 1.5.2.1 bouyer int
495 1.5.2.1 bouyer kd_rom_iclose(cc)
496 1.5.2.1 bouyer struct cons_channel *cc;
497 1.1 gwr {
498 1.1 gwr
499 1.5.2.1 bouyer callout_stop(&cc->cc_callout);
500 1.5.2.1 bouyer return (0);
501 1.5.2.1 bouyer }
502 1.1 gwr
503 1.5.2.1 bouyer /*
504 1.5.2.1 bouyer * "Interrupt" routine for input through ROM vectors
505 1.5.2.1 bouyer */
506 1.5.2.1 bouyer void
507 1.5.2.1 bouyer kd_rom_intr(arg)
508 1.5.2.1 bouyer void *arg;
509 1.5.2.1 bouyer {
510 1.5.2.1 bouyer struct cons_channel *cc = arg;
511 1.5.2.1 bouyer int s, c;
512 1.1 gwr
513 1.5.2.1 bouyer /* Re-schedule */
514 1.5.2.1 bouyer callout_reset(&cc->cc_callout, hz / 4, kd_rom_intr, cc);
515 1.5.2.1 bouyer
516 1.5.2.1 bouyer s = spltty();
517 1.5.2.1 bouyer
518 1.5.2.1 bouyer while ((c = prom_peekchar()) >= 0)
519 1.5.2.1 bouyer (*cc->cc_upstream)(c);
520 1.5.2.1 bouyer
521 1.5.2.1 bouyer splx(s);
522 1.1 gwr }
523 1.1 gwr
524 1.5.2.1 bouyer /*****************************************************************/
525 1.1 gwr
526 1.5.2.1 bouyer int prom_stdin_node;
527 1.5.2.1 bouyer int prom_stdout_node;
528 1.5.2.1 bouyer char prom_stdin_args[16];
529 1.5.2.1 bouyer char prom_stdout_args[16];
530 1.5.2.1 bouyer
531 1.5.2.1 bouyer extern void prom_cnprobe __P((struct consdev *));
532 1.5.2.1 bouyer static void prom_cninit __P((struct consdev *));
533 1.5.2.1 bouyer static int prom_cngetc __P((dev_t));
534 1.5.2.1 bouyer static void prom_cnputc __P((dev_t, int));
535 1.5.2.1 bouyer extern void prom_cnpollc __P((dev_t, int));
536 1.5.2.1 bouyer
537 1.5.2.1 bouyer /*
538 1.5.2.1 bouyer * The console is set to this one initially,
539 1.5.2.1 bouyer * which lets us use the PROM until consinit()
540 1.5.2.1 bouyer * is called to select a real console.
541 1.5.2.1 bouyer */
542 1.5.2.1 bouyer struct consdev consdev_prom = {
543 1.5.2.1 bouyer prom_cnprobe,
544 1.5.2.1 bouyer prom_cninit,
545 1.5.2.1 bouyer prom_cngetc,
546 1.5.2.1 bouyer prom_cnputc,
547 1.5.2.1 bouyer prom_cnpollc,
548 1.5.2.1 bouyer NULL,
549 1.5.2.1 bouyer };
550 1.5.2.1 bouyer
551 1.5.2.1 bouyer /*
552 1.5.2.1 bouyer * The console table pointer is statically initialized
553 1.5.2.1 bouyer * to point to the PROM table, so that early calls to printf will work.
554 1.5.2.1 bouyer */
555 1.5.2.1 bouyer struct consdev *cn_tab = &consdev_prom;
556 1.5.2.1 bouyer
557 1.5.2.1 bouyer void
558 1.5.2.1 bouyer prom_cnprobe(cn)
559 1.5.2.1 bouyer struct consdev *cn;
560 1.5.2.1 bouyer {
561 1.1 gwr }
562 1.1 gwr
563 1.1 gwr static void
564 1.5.2.1 bouyer prom_cninit(cn)
565 1.5.2.1 bouyer struct consdev *cn;
566 1.5.2.1 bouyer {
567 1.5.2.1 bouyer }
568 1.5.2.1 bouyer
569 1.5.2.1 bouyer void
570 1.5.2.1 bouyer prom_cnpollc(dev, on)
571 1.1 gwr dev_t dev;
572 1.1 gwr int on;
573 1.1 gwr {
574 1.1 gwr
575 1.1 gwr if (on) {
576 1.1 gwr /* Entering debugger. */
577 1.3 mrg #if NFB > 0
578 1.1 gwr fb_unblank();
579 1.3 mrg #endif
580 1.1 gwr } else {
581 1.1 gwr /* Resuming kernel. */
582 1.1 gwr }
583 1.1 gwr }
584 1.1 gwr
585 1.5.2.1 bouyer
586 1.5.2.1 bouyer /*
587 1.5.2.1 bouyer * PROM console input putchar.
588 1.5.2.1 bouyer */
589 1.5.2.1 bouyer static int
590 1.5.2.1 bouyer prom_cngetc(dev)
591 1.5.2.1 bouyer dev_t dev;
592 1.5.2.1 bouyer {
593 1.5.2.1 bouyer int s, c;
594 1.5.2.1 bouyer
595 1.5.2.1 bouyer s = splhigh();
596 1.5.2.1 bouyer c = prom_getchar();
597 1.5.2.1 bouyer splx(s);
598 1.5.2.1 bouyer return (c);
599 1.5.2.1 bouyer }
600 1.5.2.1 bouyer
601 1.5.2.1 bouyer /*
602 1.5.2.1 bouyer * PROM console output putchar.
603 1.5.2.1 bouyer */
604 1.5.2.1 bouyer static void
605 1.5.2.1 bouyer prom_cnputc(dev, c)
606 1.5.2.1 bouyer dev_t dev;
607 1.5.2.1 bouyer int c;
608 1.5.2.1 bouyer {
609 1.5.2.1 bouyer
610 1.5.2.1 bouyer prom_putchar(c);
611 1.5.2.1 bouyer }
612 1.5.2.1 bouyer
613 1.5.2.1 bouyer
614 1.5.2.1 bouyer /*****************************************************************/
615 1.5.2.1 bouyer
616 1.5.2.1 bouyer static void prom_get_device_args __P((const char *, char *, unsigned int));
617 1.5.2.1 bouyer
618 1.5.2.1 bouyer void
619 1.5.2.1 bouyer prom_get_device_args(prop, args, sz)
620 1.5.2.1 bouyer const char *prop;
621 1.5.2.1 bouyer char *args;
622 1.5.2.1 bouyer unsigned int sz;
623 1.5.2.1 bouyer {
624 1.5.2.1 bouyer char *cp, buffer[128];
625 1.5.2.1 bouyer
626 1.5.2.1 bouyer cp = getpropstringA(findroot(), (char *)prop, buffer, sizeof buffer);
627 1.5.2.1 bouyer
628 1.5.2.1 bouyer /*
629 1.5.2.1 bouyer * Extract device-specific arguments from a PROM device path (if any)
630 1.5.2.1 bouyer */
631 1.5.2.1 bouyer cp = buffer + strlen(buffer);
632 1.5.2.1 bouyer while (cp >= buffer) {
633 1.5.2.1 bouyer if (*cp == ':') {
634 1.5.2.1 bouyer strncpy(args, cp+1, sz);
635 1.5.2.1 bouyer break;
636 1.5.2.1 bouyer }
637 1.5.2.1 bouyer cp--;
638 1.5.2.1 bouyer }
639 1.5.2.1 bouyer }
640 1.5.2.1 bouyer
641 1.5.2.1 bouyer /*
642 1.5.2.1 bouyer *
643 1.5.2.1 bouyer */
644 1.5.2.1 bouyer void
645 1.5.2.1 bouyer consinit()
646 1.5.2.1 bouyer {
647 1.5.2.1 bouyer int inSource, outSink;
648 1.5.2.1 bouyer
649 1.5.2.1 bouyer switch (prom_version()) {
650 1.5.2.1 bouyer case PROM_OLDMON:
651 1.5.2.1 bouyer case PROM_OBP_V0:
652 1.5.2.1 bouyer /* The stdio handles identify the device type */
653 1.5.2.1 bouyer inSource = prom_stdin();
654 1.5.2.1 bouyer outSink = prom_stdout();
655 1.5.2.1 bouyer break;
656 1.5.2.1 bouyer
657 1.5.2.1 bouyer case PROM_OBP_V2:
658 1.5.2.1 bouyer case PROM_OBP_V3:
659 1.5.2.1 bouyer case PROM_OPENFIRM:
660 1.5.2.1 bouyer
661 1.5.2.1 bouyer /* Save PROM arguments for device matching */
662 1.5.2.1 bouyer prom_get_device_args("stdin-path", prom_stdin_args,
663 1.5.2.1 bouyer sizeof(prom_stdin_args));
664 1.5.2.1 bouyer prom_get_device_args("stdout-path", prom_stdout_args,
665 1.5.2.1 bouyer sizeof(prom_stdout_args));
666 1.5.2.1 bouyer
667 1.5.2.1 bouyer /*
668 1.5.2.1 bouyer * Translate the STDIO package instance (`ihandle') -- that
669 1.5.2.1 bouyer * the PROM has already opened for us -- to a device tree
670 1.5.2.1 bouyer * node (i.e. a `phandle').
671 1.5.2.1 bouyer */
672 1.5.2.1 bouyer
673 1.5.2.1 bouyer prom_stdin_node = prom_instance_to_package(prom_stdin());
674 1.5.2.1 bouyer if (prom_stdin_node == 0)
675 1.5.2.1 bouyer printf("consinit: cannot convert stdin ihandle\n");
676 1.5.2.1 bouyer
677 1.5.2.1 bouyer prom_stdout_node = prom_instance_to_package(prom_stdout());
678 1.5.2.1 bouyer if (prom_stdout_node == 0) {
679 1.5.2.1 bouyer printf("consinit: cannot convert stdout ihandle\n");
680 1.5.2.1 bouyer break;
681 1.5.2.1 bouyer }
682 1.5.2.1 bouyer
683 1.5.2.1 bouyer break;
684 1.5.2.1 bouyer
685 1.5.2.1 bouyer default:
686 1.5.2.1 bouyer break;
687 1.5.2.1 bouyer }
688 1.5.2.1 bouyer
689 1.5.2.1 bouyer /* Wire up /dev/console */
690 1.5.2.1 bouyer cn_tab->cn_dev = makedev(KDMAJOR, 0);
691 1.5.2.1 bouyer cn_tab->cn_pri = CN_INTERNAL;
692 1.5.2.1 bouyer
693 1.5.2.1 bouyer /* Set up initial PROM input channel for /dev/console */
694 1.5.2.1 bouyer prom_cons_channel.cc_dev = NULL;
695 1.5.2.1 bouyer prom_cons_channel.cc_iopen = kd_rom_iopen;
696 1.5.2.1 bouyer prom_cons_channel.cc_iclose = kd_rom_iclose;
697 1.5.2.1 bouyer cons_attach_input(&prom_cons_channel, cn_tab);
698 1.5.2.1 bouyer
699 1.5.2.1 bouyer #ifdef KGDB
700 1.5.2.1 bouyer zs_kgdb_init(); /* XXX */
701 1.5.2.1 bouyer #endif
702 1.5.2.1 bouyer }
703