kernel - Fix excessive call stack depth on stuck interrupt
[dragonfly.git] / sys / kern / tty_conf.c
blob11c86e5daf0c1a1340d942308053eb39e9d1c57b
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 <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/tty.h>
43 #include <sys/conf.h>
45 #ifndef MAXLDISC
46 #define MAXLDISC 9
47 #endif
49 static l_open_t l_noopen;
50 static l_close_t l_noclose;
51 static l_rint_t l_norint;
52 static l_start_t l_nostart;
55 * XXX it probably doesn't matter what the entries other than the l_open
56 * entry are here. The l_nullioctl and ttymodem entries still look fishy.
57 * Reconsider the removal of nullmodem anyway. It was too much like
58 * ttymodem, but a completely null version might be useful.
60 #define NODISC(n) \
61 { l_noopen, l_noclose, l_noread, l_nowrite, \
62 l_nullioctl, l_norint, l_nostart, ttymodem }
64 struct linesw linesw[MAXLDISC] =
66 /* 0- termios */
67 { ttyopen, ttylclose, ttread, ttwrite,
68 l_nullioctl, ttyinput, ttstart, ttymodem },
69 NODISC(1), /* 1- defunct */
70 NODISC(2), /* 2- NTTYDISC */
71 NODISC(3), /* loadable */
72 NODISC(4), /* SLIPDISC */
73 NODISC(5), /* PPPDISC */
74 NODISC(6), /* NETGRAPHDISC */
75 NODISC(7), /* loadable */
76 NODISC(8), /* loadable */
79 int nlinesw = NELEM(linesw);
81 static struct linesw nodisc = NODISC(0);
83 #define LOADABLE_LDISC 7
85 * ldisc_register: Register a line discipline.
87 * discipline: Index for discipline to load, or LDISC_LOAD for us to choose.
88 * linesw_p: Pointer to linesw_p.
90 * Returns: Index used or -1 on failure.
92 int
93 ldisc_register(int discipline, struct linesw *linesw_p)
95 int slot = -1;
97 lwkt_gettoken(&tty_token);
98 if (discipline == LDISC_LOAD) {
99 int i;
100 for (i = LOADABLE_LDISC; i < MAXLDISC; i++)
101 if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) {
102 slot = i;
105 else if (discipline >= 0 && discipline < MAXLDISC) {
106 slot = discipline;
109 if (slot != -1 && linesw_p)
110 linesw[slot] = *linesw_p;
112 lwkt_reltoken(&tty_token);
113 return slot;
117 * ldisc_deregister: Deregister a line discipline obtained with
118 * ldisc_register.
120 * discipline: Index for discipline to unload.
122 void
123 ldisc_deregister(int discipline)
125 lwkt_gettoken(&tty_token);
126 if (discipline < MAXLDISC) {
127 linesw[discipline] = nodisc;
129 lwkt_reltoken(&tty_token);
132 static int
133 l_noopen(cdev_t dev, struct tty *tp)
136 return (ENODEV);
139 static int
140 l_noclose(struct tty *tp, int flag)
143 return (ENODEV);
147 l_noread(struct tty *tp, struct uio *uio, int flag)
150 return (ENODEV);
154 l_nowrite(struct tty *tp, struct uio *uio, int flag)
157 return (ENODEV);
160 static int
161 l_norint(int c, struct tty *tp)
164 return (ENODEV);
167 static int
168 l_nostart(struct tty *tp)
171 return (ENODEV);
175 * Do nothing specific version of line
176 * discipline specific ioctl command.
179 l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags,
180 struct ucred *cred)
183 return (ENOIOCTL);