xref: /dragonfly/sys/kern/tty_conf.c (revision 89a89091)
1 /*-
2  * (MPSAFE)
3  *
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.
11  *
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. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	@(#)tty_conf.c	8.4 (Berkeley) 1/21/94
41  * $FreeBSD: src/sys/kern/tty_conf.c,v 1.16.2.1 2002/03/11 01:14:55 dd Exp $
42  */
43 
44 #include "opt_compat.h"
45 
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/tty.h>
49 #include <sys/conf.h>
50 
51 #ifndef MAXLDISC
52 #define MAXLDISC 9
53 #endif
54 
55 static l_open_t		l_noopen;
56 static l_close_t	l_noclose;
57 static l_rint_t		l_norint;
58 static l_start_t	l_nostart;
59 
60 /*
61  * XXX it probably doesn't matter what the entries other than the l_open
62  * entry are here.  The l_nullioctl and ttymodem entries still look fishy.
63  * Reconsider the removal of nullmodem anyway.  It was too much like
64  * ttymodem, but a completely null version might be useful.
65  */
66 #define NODISC(n) \
67 	{ l_noopen,	l_noclose,	l_noread,	l_nowrite, \
68 	  l_nullioctl,	l_norint,	l_nostart,	ttymodem }
69 
70 struct	linesw linesw[MAXLDISC] =
71 {
72 				/* 0- termios */
73 	{ ttyopen,	ttylclose,	ttread,		ttwrite,
74 	  l_nullioctl,	ttyinput,	ttstart,	ttymodem },
75 	NODISC(1),		/* 1- defunct */
76 	  			/* 2- NTTYDISC */
77 #ifdef COMPAT_43
78 	{ ttyopen,	ttylclose,	ttread,		ttwrite,
79 	  l_nullioctl,	ttyinput,	ttstart,	ttymodem },
80 #else
81 	NODISC(2),
82 #endif
83 	NODISC(3),		/* loadable */
84 	NODISC(4),		/* SLIPDISC */
85 	NODISC(5),		/* PPPDISC */
86 	NODISC(6),		/* NETGRAPHDISC */
87 	NODISC(7),		/* loadable */
88 	NODISC(8),		/* loadable */
89 };
90 
91 int	nlinesw = NELEM(linesw);
92 
93 static struct linesw nodisc = NODISC(0);
94 
95 #define LOADABLE_LDISC 7
96 /*
97  * ldisc_register: Register a line discipline.
98  *
99  * discipline: Index for discipline to load, or LDISC_LOAD for us to choose.
100  * linesw_p:   Pointer to linesw_p.
101  *
102  * Returns: Index used or -1 on failure.
103  */
104 int
105 ldisc_register(int discipline, struct linesw *linesw_p)
106 {
107 	int slot = -1;
108 
109 	lwkt_gettoken(&tty_token);
110 	if (discipline == LDISC_LOAD) {
111 		int i;
112 		for (i = LOADABLE_LDISC; i < MAXLDISC; i++)
113 			if (bcmp(linesw + i, &nodisc, sizeof(nodisc)) == 0) {
114 				slot = i;
115 			}
116 	}
117 	else if (discipline >= 0 && discipline < MAXLDISC) {
118 		slot = discipline;
119 	}
120 
121 	if (slot != -1 && linesw_p)
122 		linesw[slot] = *linesw_p;
123 
124 	lwkt_reltoken(&tty_token);
125 	return slot;
126 }
127 
128 /*
129  * ldisc_deregister: Deregister a line discipline obtained with
130  * ldisc_register.
131  *
132  * discipline: Index for discipline to unload.
133  */
134 void
135 ldisc_deregister(int discipline)
136 {
137 	lwkt_gettoken(&tty_token);
138 	if (discipline < MAXLDISC) {
139 		linesw[discipline] = nodisc;
140 	}
141 	lwkt_reltoken(&tty_token);
142 }
143 
144 static int
145 l_noopen(cdev_t dev, struct tty *tp)
146 {
147 
148 	return (ENODEV);
149 }
150 
151 static int
152 l_noclose(struct tty *tp, int flag)
153 {
154 
155 	return (ENODEV);
156 }
157 
158 int
159 l_noread(struct tty *tp, struct uio *uio, int flag)
160 {
161 
162 	return (ENODEV);
163 }
164 
165 int
166 l_nowrite(struct tty *tp, struct uio *uio, int flag)
167 {
168 
169 	return (ENODEV);
170 }
171 
172 static int
173 l_norint(int c, struct tty *tp)
174 {
175 
176 	return (ENODEV);
177 }
178 
179 static int
180 l_nostart(struct tty *tp)
181 {
182 
183 	return (ENODEV);
184 }
185 
186 /*
187  * Do nothing specific version of line
188  * discipline specific ioctl command.
189  */
190 int
191 l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags,
192 	    struct ucred *cred)
193 {
194 
195 	return (ENOIOCTL);
196 }
197