No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / nullcons_subr.c
blobba9adba43b1ff6ae0110902660203fee99409cb0
1 /* $NetBSD: nullcons_subr.c,v 1.9 2009/04/16 12:57:22 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: nullcons_subr.c,v 1.9 2009/04/16 12:57:22 tsutsui Exp $");
32 #include <sys/param.h>
33 #include <sys/proc.h>
34 #include <sys/systm.h>
35 #include <sys/buf.h>
36 #include <sys/ioctl.h>
37 #include <sys/tty.h>
38 #include <sys/file.h>
39 #include <sys/conf.h>
40 #include <sys/vnode.h>
42 #include <dev/cons.h>
44 static struct tty *nulltty; /* null console tty */
46 cons_decl(null);
48 dev_type_read(nullcndev_read);
49 dev_type_ioctl(nullcndev_ioctl);
50 dev_type_tty(nullcndev_tty);
52 static int nullcons_newdev(struct consdev *);
54 const struct cdevsw nullcn_devsw = {
55 nullopen, nullclose, nullcndev_read, nullwrite, nullcndev_ioctl,
56 nullstop, nullcndev_tty, nopoll, nommap, ttykqfilter, D_TTY
60 * null console device. We need it because of the ioctl() it handles,
61 * which in particular allows control terminal allocation through
62 * TIOCSCTTY ioctl. Without the latter, system won't even boot past init(8)
63 * invocation.
65 int
66 nullcndev_read(dev_t dev, struct uio *uio, int flag)
69 return EIO;
72 int
73 nullcndev_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
75 int error;
77 error = (*nulltty->t_linesw->l_ioctl)(nulltty, cmd, data, flag, l);
78 if (error != EPASSTHROUGH)
79 return error;
81 error = ttioctl(nulltty, cmd, data, flag, l);
82 if (error != EPASSTHROUGH)
83 return error;
85 return 0;
88 struct tty*
89 nullcndev_tty(dev_t dev)
92 return nulltty;
96 * Mark console as no-op (null) console. Proper initialization is deferred
97 * to nullconsattach().
99 void
100 nullcnprobe(struct consdev *cn)
103 cn->cn_pri = CN_NULL;
104 cn->cn_dev = NODEV;
108 * null console initialization. This includes allocation of a new device and
109 * a new tty.
111 void
112 nullcninit(struct consdev *cn)
114 static struct consdev nullcn = cons_init(null);
116 nullcnprobe(&nullcn);
117 cn_tab = &nullcn;
121 * Dumb getc() implementation. Simply blocks on call.
124 nullcngetc(dev_t dev)
127 for (;;)
129 return 0;
133 * Dumb putc() implementation.
135 void
136 nullcnputc(dev_t dev, int c)
142 * Allocate a new console device and a tty to handle console ioctls.
145 nullcons_newdev(struct consdev *cn)
147 int error;
148 int bmajor = -1, cmajor = -1;
150 if ((cn == NULL) || (cn->cn_pri != CN_NULL) || (cn->cn_dev != NODEV))
151 return 0;
154 * Attach no-op device to the device list.
156 error = devsw_attach("nullcn", NULL, &bmajor, &nullcn_devsw, &cmajor);
157 if (error != 0)
158 return error;
161 * Allocate tty (mostly to have sane ioctl()).
163 nulltty = ttymalloc();
164 nulltty->t_dev = makedev(cmajor, 0);
165 tty_attach(nulltty);
166 cn->cn_dev = nulltty->t_dev;
168 return 0;
172 * Pseudo-device attach function -- it's the right time to do the rest of
173 * initialization.
175 void
176 nullconsattach(int pdev_count)
179 nullcons_newdev(cn_tab);