ttycons.c revision 1.5 1 /* $NetBSD: ttycons.c,v 1.5 2011/08/28 21:21:05 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
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 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
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
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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
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
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ttycons.c,v 1.5 2011/08/28 21:21:05 jmcneill Exp $");
31
32 #include <sys/param.h>
33 #include <sys/proc.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 #include <sys/termios.h>
37
38 #include <dev/cons.h>
39
40 #include <machine/mainbus.h>
41 #include <machine/thunk.h>
42
43 static int ttycons_match(device_t, cfdata_t, void *);
44 static void ttycons_attach(device_t, device_t, void *);
45
46 void ttycons_consinit(void);
47
48 typedef struct ttycons_softc {
49 device_t sc_dev;
50 } ttycons_softc_t;
51
52 dev_type_cngetc(ttycons_cngetc);
53 dev_type_cnputc(ttycons_cnputc);
54 dev_type_cnpollc(ttycons_cnpollc);
55
56 static struct cnm_state ttycons_cnm_state;
57 struct consdev ttycons_consdev = {
58 .cn_getc = ttycons_cngetc,
59 .cn_putc = ttycons_cnputc,
60 .cn_pollc = ttycons_cnpollc,
61 };
62
63 CFATTACH_DECL_NEW(ttycons, sizeof(ttycons_softc_t),
64 ttycons_match, ttycons_attach, NULL, NULL);
65
66 static int
67 ttycons_match(device_t parent, cfdata_t match, void *opaque)
68 {
69 struct thunkbus_attach_args *taa = opaque;
70
71 if (taa->taa_type != THUNKBUS_TYPE_TTYCONS)
72 return 0;
73
74 return 1;
75 }
76
77 static void
78 ttycons_attach(device_t parent, device_t self, void *opaque)
79 {
80 ttycons_softc_t *sc = device_private(self);
81
82 aprint_naive("\n");
83 aprint_normal(": console\n");
84
85 sc->sc_dev = self;
86 }
87
88 void
89 ttycons_consinit(void)
90 {
91 struct thunk_termios t;
92
93 thunk_tcgetattr(0, &t);
94 t.c_lflag &= ~(ECHO|ICANON);
95 t.c_cc[VTIME] = 0;
96 t.c_cc[VMIN] = 1;
97 thunk_tcsetattr(0, TCSANOW, &t);
98
99 cn_tab = &ttycons_consdev;
100 cn_init_magic(&ttycons_cnm_state);
101 cn_set_magic("\047\001");
102
103
104 }
105
106 int
107 ttycons_cngetc(dev_t dev)
108 {
109 return thunk_getchar();
110 }
111
112 void
113 ttycons_cnputc(dev_t dev, int c)
114 {
115 thunk_putchar(c);
116 }
117
118 void
119 ttycons_cnpollc(dev_t dev, int on)
120 {
121 }
122