1 /* $NetBSD: nullcons_subr.c,v 1.1 2003/10/17 20:27:38 cdi Exp $ */
2
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the NetBSD
18 * Foundation, Inc. and its contributors.
19 * 4. Neither the name of The NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: nullcons_subr.c,v 1.1 2003/10/17 20:27:38 cdi Exp $");
38
39 #include <sys/param.h>
40 #include <sys/proc.h>
41 #include <sys/user.h>
42 #include <sys/systm.h>
43 #include <sys/buf.h>
44 #include <sys/ioctl.h>
45 #include <sys/tty.h>
46 #include <sys/file.h>
47 #include <sys/conf.h>
48 #include <sys/vnode.h>
49
50 #include <dev/cons.h>
51
52
53 extern struct consdev *cn_tab; /* physical console device info */
54
55 static struct tty *nulltty; /* null console tty */
56
57 cons_decl(null);
58
59 dev_type_read(nullcndev_read);
60 dev_type_ioctl(nullcndev_ioctl);
61 dev_type_tty(nullcndev_tty);
62
63 static int nullcons_newdev __P((struct consdev *));
64
65 const struct cdevsw nullcn_devsw = {
66 nullopen, nullclose, nullcndev_read, nullwrite, nullcndev_ioctl,
67 nullstop, nullcndev_tty, nopoll, nommap, ttykqfilter, D_TTY
68 };
69
70 /*
71 * null console device. We need it because of the ioctl() it handles,
72 * which in particular allows control terminal allocation through
73 * TIOCSCTTY ioctl. Without the latter, system won't even boot past init(8)
74 * invocation.
75 */
76 int
77 nullcndev_read(dev, uio, flag)
78 dev_t dev;
79 struct uio *uio;
80 int flag;
81 {
82
83 for(;;);
84 return (0);
85 }
86
87 int
88 nullcndev_ioctl(dev, cmd, data, flag, p)
89 dev_t dev;
90 u_long cmd;
91 caddr_t data;
92 int flag;
93 struct proc *p;
94 {
95 int error;
96
97 error = (*nulltty->t_linesw->l_ioctl)(nulltty, cmd, data, flag, p);
98 if (error != EPASSTHROUGH)
99 return (error);
100
101 error = ttioctl(nulltty, cmd, data, flag, p);
102 if (error != EPASSTHROUGH)
103 return (error);
104
105 return (0);
106 }
107
108 struct tty*
109 nullcndev_tty(dev)
110 dev_t dev;
111 {
112
113 return nulltty;
114 }
115
116 /*
117 * Mark console as no-op (null) console. Proper initialization is deferred
118 * to nullconsattach().
119 */
120 void
121 nullcnprobe(cn)
122 struct consdev *cn;
123 {
124
125 cn->cn_pri = CN_NULL;
126 cn->cn_dev = NODEV;
127 }
128
129 /*
130 * null console initialization. This includes allocation of a new device and
131 * a new tty.
132 */
133 void
134 nullcninit(cn)
135 struct consdev *cn;
136 {
137 static struct consdev nullcn = cons_init(null);
138
139 nullcnprobe(&nullcn);
140 cn_tab = &nullcn;
141 }
142
143 /*
144 * Dumb getc() implementation. Simply blocks on call.
145 */
146 int
147 nullcngetc(dev)
148 dev_t dev;
149 {
150
151 for(;;);
152 return (0);
153 }
154
155 /*
156 * Dumb putc() implementation.
157 */
158 void
159 nullcnputc(dev, c)
160 dev_t dev;
161 int c;
162 {
163
164 }
165
166 /*
167 * Allocate a new console device and a tty to handle console ioctls.
168 */
169 int
170 nullcons_newdev(cn)
171 struct consdev *cn;
172 {
173 int error;
174 int bmajor = -1, cmajor = -1;
175
176 if ((cn == NULL) || (cn->cn_pri != CN_NULL) || (cn->cn_dev != NODEV))
177 return (0);
178
179 /*
180 * Attach no-op device to the device list.
181 */
182 error = devsw_attach("nullcn", NULL, &bmajor, &nullcn_devsw, &cmajor);
183 if (error != 0)
184 return (error);
185
186 /*
187 * Allocate tty (mostly to have sane ioctl()).
188 */
189 nulltty = ttymalloc();
190 nulltty->t_dev = makedev(cmajor, 0);
191 tty_attach(nulltty);
192 cn->cn_dev = nulltty->t_dev;
193
194 return (0);
195 }
196
197 /*
198 * Pseudo-device attach function -- it's the right time to do the rest of
199 * initialization.
200 */
201 void
202 nullconsattach(pdev_count)
203 int pdev_count;
204 {
205
206 nullcons_newdev(cn_tab);
207 }
Cache object: 74d9132c5fa213b8a7b703f0a1dde6a4
|