sed(1): Move regex.h to be the last included
[dragonfly.git] / sys / kern / tty_conf.c
blob26d29edf43d4b2b3a1373c6cba3a221637b6f6f1
1 /*-
2 * (MPSAFE)
4 * Copyright (c) 1982, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
36 * @(#)tty_conf.c 8.4 (Berkeley) 1/21/94
37 * $FreeBSD: src/sys/kern/tty_conf.c,v 1.16.2.1 2002/03/11 01:14:55 dd Exp $
40 #include "opt_compat.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/tty.h>
45 #include <sys/conf.h>
47 #ifndef MAXLDISC
48 #define MAXLDISC 9
49 #endif
51 static l_open_t l_noopen;
52 static l_close_t l_noclose;
53 static l_rint_t l_norint;
54 static l_start_t l_nostart;
57 * XXX it probably doesn't matter what the entries other than the l_open
58 * entry are here. The l_nullioctl and ttymodem entries still look fishy.
59 * Reconsider the removal of nullmodem anyway. It was too much like
60 * ttymodem, but a completely null version might be useful.
62 #define NODISC(n) \
63 { l_noopen, l_noclose, l_noread, l_nowrite, \
64 l_nullioctl, l_norint, l_nostart, ttymodem }
66 struct linesw linesw[MAXLDISC] =
68 /* 0- termios */
69 { ttyopen, ttylclose, ttread, ttwrite,
70 l_nullioctl, ttyinput, ttstart, ttymodem },
71 NODISC(1), /* 1- defunct */
72 /* 2- NTTYDISC */
73 #ifdef COMPAT_43
74 { ttyopen, ttylclose, ttread, ttwrite,
75 l_nullioctl, ttyinput, ttstart, ttymodem },
76 #else
77 NODISC(2),
78 #endif
79 NODISC(3), /* loadable */
80 NODISC(4), /* SLIPDISC */
81 NODISC(5), /* PPPDISC */
82 NODISC(6), /* NETGRAPHDISC */
83 NODISC(7), /* loadable */
84 NODISC(8), /* loadable */
87 int nlinesw = NELEM(linesw);
89 static struct linesw nodisc = NODISC(0);
91 #define LOADABLE_LDISC 7
93 * ldisc_register: Register a line discipline.
95 * discipline: Index for discipline to load, or LDISC_LOAD for us to choose.
96 * linesw_p: Pointer to linesw_p.
98 * Returns: Index used or -1 on failure.
101 ldisc_register(int discipline, struct linesw *linesw_p)
103 int slot = -1;
105 lwkt_gettoken(&tty_token);
106 if (discipline == LDISC_LOAD) {
107 int i;
108 for (i = LOADABLE_LDISC; i < MAXLDISC; i++)
109 if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) {
110 slot = i;
113 else if (discipline >= 0 && discipline < MAXLDISC) {
114 slot = discipline;
117 if (slot != -1 && linesw_p)
118 linesw[slot] = *linesw_p;
120 lwkt_reltoken(&tty_token);
121 return slot;
125 * ldisc_deregister: Deregister a line discipline obtained with
126 * ldisc_register.
128 * discipline: Index for discipline to unload.
130 void
131 ldisc_deregister(int discipline)
133 lwkt_gettoken(&tty_token);
134 if (discipline < MAXLDISC) {
135 linesw[discipline] = nodisc;
137 lwkt_reltoken(&tty_token);
140 static int
141 l_noopen(cdev_t dev, struct tty *tp)
144 return (ENODEV);
147 static int
148 l_noclose(struct tty *tp, int flag)
151 return (ENODEV);
155 l_noread(struct tty *tp, struct uio *uio, int flag)
158 return (ENODEV);
162 l_nowrite(struct tty *tp, struct uio *uio, int flag)
165 return (ENODEV);
168 static int
169 l_norint(int c, struct tty *tp)
172 return (ENODEV);
175 static int
176 l_nostart(struct tty *tp)
179 return (ENODEV);
183 * Do nothing specific version of line
184 * discipline specific ioctl command.
187 l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags,
188 struct ucred *cred)
191 return (ENOIOCTL);