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