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