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