1 /* $NetBSD: nullcons_subr.c,v 1.9 2009/04/16 12:57:22 tsutsui Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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>
34 #include <sys/systm.h>
36 #include <sys/ioctl.h>
40 #include <sys/vnode.h>
44 static struct tty
*nulltty
; /* null console tty */
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)
66 nullcndev_read(dev_t dev
, struct uio
*uio
, int flag
)
73 nullcndev_ioctl(dev_t dev
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
77 error
= (*nulltty
->t_linesw
->l_ioctl
)(nulltty
, cmd
, data
, flag
, l
);
78 if (error
!= EPASSTHROUGH
)
81 error
= ttioctl(nulltty
, cmd
, data
, flag
, l
);
82 if (error
!= EPASSTHROUGH
)
89 nullcndev_tty(dev_t dev
)
96 * Mark console as no-op (null) console. Proper initialization is deferred
97 * to nullconsattach().
100 nullcnprobe(struct consdev
*cn
)
103 cn
->cn_pri
= CN_NULL
;
108 * null console initialization. This includes allocation of a new device and
112 nullcninit(struct consdev
*cn
)
114 static struct consdev nullcn
= cons_init(null
);
116 nullcnprobe(&nullcn
);
121 * Dumb getc() implementation. Simply blocks on call.
124 nullcngetc(dev_t dev
)
133 * Dumb putc() implementation.
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
)
148 int bmajor
= -1, cmajor
= -1;
150 if ((cn
== NULL
) || (cn
->cn_pri
!= CN_NULL
) || (cn
->cn_dev
!= NODEV
))
154 * Attach no-op device to the device list.
156 error
= devsw_attach("nullcn", NULL
, &bmajor
, &nullcn_devsw
, &cmajor
);
161 * Allocate tty (mostly to have sane ioctl()).
163 nulltty
= ttymalloc();
164 nulltty
->t_dev
= makedev(cmajor
, 0);
166 cn
->cn_dev
= nulltty
->t_dev
;
172 * Pseudo-device attach function -- it's the right time to do the rest of
176 nullconsattach(int pdev_count
)
179 nullcons_newdev(cn_tab
);