| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: ttycons.c,v 1.14 2011/12/21 10:02:45 reinoud Exp $ */ | | 1 | /* $NetBSD: ttycons.c,v 1.15 2011/12/21 11:53:07 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,52 +17,53 @@ | | | @@ -17,52 +17,53 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.14 2011/12/21 10:02:45 reinoud Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.15 2011/12/21 11:53:07 jmcneill Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/conf.h> | | 33 | #include <sys/conf.h> |
34 | #include <sys/proc.h> | | 34 | #include <sys/proc.h> |
35 | #include <sys/systm.h> | | 35 | #include <sys/systm.h> |
36 | #include <sys/device.h> | | 36 | #include <sys/device.h> |
37 | #include <sys/kauth.h> | | 37 | #include <sys/kauth.h> |
38 | #include <sys/termios.h> | | 38 | #include <sys/termios.h> |
39 | #include <sys/tty.h> | | 39 | #include <sys/tty.h> |
40 | | | 40 | |
41 | #include <dev/cons.h> | | 41 | #include <dev/cons.h> |
42 | | | 42 | |
43 | #include <machine/mainbus.h> | | 43 | #include <machine/mainbus.h> |
44 | #include <machine/thunk.h> | | 44 | #include <machine/thunk.h> |
45 | | | 45 | |
46 | static int ttycons_match(device_t, cfdata_t, void *); | | 46 | static int ttycons_match(device_t, cfdata_t, void *); |
47 | static void ttycons_attach(device_t, device_t, void *); | | 47 | static void ttycons_attach(device_t, device_t, void *); |
48 | | | 48 | |
49 | void ttycons_consinit(void); | | 49 | void ttycons_consinit(void); |
50 | | | 50 | |
51 | struct ttycons_softc { | | 51 | struct ttycons_softc { |
52 | device_t sc_dev; | | 52 | device_t sc_dev; |
53 | struct tty *sc_tty; | | 53 | struct tty *sc_tty; |
54 | void *sc_rd_sih; | | 54 | void *sc_rd_sih; |
55 | void *sc_ctrlc_sih; | | 55 | void *sc_ctrlc_sih; |
| | | 56 | u_char sc_buf[1024]; |
56 | }; | | 57 | }; |
57 | | | 58 | |
58 | dev_type_cngetc(ttycons_cngetc); | | 59 | dev_type_cngetc(ttycons_cngetc); |
59 | dev_type_cnputc(ttycons_cnputc); | | 60 | dev_type_cnputc(ttycons_cnputc); |
60 | dev_type_cnpollc(ttycons_cnpollc); | | 61 | dev_type_cnpollc(ttycons_cnpollc); |
61 | | | 62 | |
62 | static struct cnm_state ttycons_cnm_state; | | 63 | static struct cnm_state ttycons_cnm_state; |
63 | struct consdev ttycons_consdev = { | | 64 | struct consdev ttycons_consdev = { |
64 | .cn_getc = ttycons_cngetc, | | 65 | .cn_getc = ttycons_cngetc, |
65 | .cn_putc = ttycons_cnputc, | | 66 | .cn_putc = ttycons_cnputc, |
66 | .cn_pollc = ttycons_cnpollc, | | 67 | .cn_pollc = ttycons_cnpollc, |
67 | .cn_dev = NODEV, | | 68 | .cn_dev = NODEV, |
68 | .cn_pri = CN_NORMAL, | | 69 | .cn_pri = CN_NORMAL, |
| @@ -119,26 +120,27 @@ static void | | | @@ -119,26 +120,27 @@ static void |
119 | ttycons_attach(device_t parent, device_t self, void *opaque) | | 120 | ttycons_attach(device_t parent, device_t self, void *opaque) |
120 | { | | 121 | { |
121 | struct ttycons_softc *sc = device_private(self); | | 122 | struct ttycons_softc *sc = device_private(self); |
122 | int maj; | | 123 | int maj; |
123 | | | 124 | |
124 | aprint_naive("\n"); | | 125 | aprint_naive("\n"); |
125 | aprint_normal(": console\n"); | | 126 | aprint_normal(": console\n"); |
126 | | | 127 | |
127 | sc->sc_dev = self; | | 128 | sc->sc_dev = self; |
128 | sc->sc_tty = tty_alloc(); | | 129 | sc->sc_tty = tty_alloc(); |
129 | tty_attach(sc->sc_tty); | | 130 | tty_attach(sc->sc_tty); |
130 | sc->sc_tty->t_oproc = ttycons_start; | | 131 | sc->sc_tty->t_oproc = ttycons_start; |
131 | sc->sc_tty->t_param = ttycons_param; | | 132 | sc->sc_tty->t_param = ttycons_param; |
| | | 133 | sc->sc_tty->t_sc = sc; |
132 | | | 134 | |
133 | maj = cdevsw_lookup_major(&ttycons_cdevsw); | | 135 | maj = cdevsw_lookup_major(&ttycons_cdevsw); |
134 | cn_tab->cn_dev = makedev(maj, device_unit(self)); | | 136 | cn_tab->cn_dev = makedev(maj, device_unit(self)); |
135 | sc->sc_tty->t_dev = cn_tab->cn_dev; | | 137 | sc->sc_tty->t_dev = cn_tab->cn_dev; |
136 | | | 138 | |
137 | sc->sc_rd_sih = softint_establish(SOFTINT_SERIAL, | | 139 | sc->sc_rd_sih = softint_establish(SOFTINT_SERIAL, |
138 | ttycons_softintr, sc); | | 140 | ttycons_softintr, sc); |
139 | if (sc->sc_rd_sih == NULL) | | 141 | if (sc->sc_rd_sih == NULL) |
140 | panic("couldn't establish ttycons intr handler\n"); | | 142 | panic("couldn't establish ttycons intr handler\n"); |
141 | | | 143 | |
142 | sc->sc_ctrlc_sih = softint_establish(SOFTINT_SERIAL, | | 144 | sc->sc_ctrlc_sih = softint_establish(SOFTINT_SERIAL, |
143 | ttycons_softctrlc, sc); | | 145 | ttycons_softctrlc, sc); |
144 | if (sc->sc_ctrlc_sih == NULL) | | 146 | if (sc->sc_ctrlc_sih == NULL) |
| @@ -291,39 +293,39 @@ ttycons_ioctl(dev_t dev, u_long cmd, voi | | | @@ -291,39 +293,39 @@ ttycons_ioctl(dev_t dev, u_long cmd, voi |
291 | if (error != EPASSTHROUGH) | | 293 | if (error != EPASSTHROUGH) |
292 | return error; | | 294 | return error; |
293 | | | 295 | |
294 | error = ttioctl(t, cmd, data, flag, l); | | 296 | error = ttioctl(t, cmd, data, flag, l); |
295 | if (error != EPASSTHROUGH) | | 297 | if (error != EPASSTHROUGH) |
296 | return error; | | 298 | return error; |
297 | | | 299 | |
298 | return EPASSTHROUGH; | | 300 | return EPASSTHROUGH; |
299 | } | | 301 | } |
300 | | | 302 | |
301 | static void | | 303 | static void |
302 | ttycons_start(struct tty *t) | | 304 | ttycons_start(struct tty *t) |
303 | { | | 305 | { |
304 | u_char buf[1024+1]; | | 306 | struct ttycons_softc *sc = t->t_sc; |
305 | u_char *p = buf; | | 307 | u_char *p = sc->sc_buf; |
306 | int s, len, brem; | | 308 | int s, len, brem; |
307 | | | 309 | |
308 | s = spltty(); | | 310 | s = spltty(); |
309 | if (t->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) { | | 311 | if (t->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) { |
310 | splx(s); | | 312 | splx(s); |
311 | return; | | 313 | return; |
312 | } | | 314 | } |
313 | t->t_state |= TS_BUSY; | | 315 | t->t_state |= TS_BUSY; |
314 | splx(s); | | 316 | splx(s); |
315 | | | 317 | |
316 | brem = q_to_b(&t->t_outq, buf, sizeof(buf) - 1); | | 318 | brem = q_to_b(&t->t_outq, sc->sc_buf, sizeof(sc->sc_buf)); |
317 | | | 319 | |
318 | while (brem > 0) { | | 320 | while (brem > 0) { |
319 | len = thunk_write(1, p, brem); | | 321 | len = thunk_write(1, p, brem); |
320 | if (len > 0) { | | 322 | if (len > 0) { |
321 | p += len; | | 323 | p += len; |
322 | brem -= len; | | 324 | brem -= len; |
323 | } | | 325 | } |
324 | } | | 326 | } |
325 | | | 327 | |
326 | s = spltty(); | | 328 | s = spltty(); |
327 | t->t_state &= ~TS_BUSY; | | 329 | t->t_state &= ~TS_BUSY; |
328 | if (ttypull(t)) { | | 330 | if (ttypull(t)) { |
329 | t->t_state |= TS_TIMEOUT; | | 331 | t->t_state |= TS_TIMEOUT; |