]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/kern/tty_conf.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / kern / tty_conf.c
1 /*-
2  * Copyright (c) 2004 Poul-Henning Kamp.  All rights reserved.
3  * Copyright (c) 1982, 1986, 1991, 1993
4  *      The Regents of the University of California.  All rights reserved.
5  * (c) UNIX System Laboratories, Inc.
6  * All or some portions of this file are derived from material licensed
7  * to the University of California by American Telephone and Telegraph
8  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
9  * the permission of UNIX System Laboratories, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *      @(#)tty_conf.c  8.4 (Berkeley) 1/21/94
36  */
37
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
40
41 #include "opt_compat.h"
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/tty.h>
46 #include <sys/conf.h>
47
48 #ifndef MAXLDISC
49 #define MAXLDISC 9
50 #endif
51
52 static l_open_t         l_noopen;
53 static l_close_t        l_noclose;
54 static l_rint_t         l_norint;
55 static l_start_t        l_nostart;
56
57 /*
58  * XXX it probably doesn't matter what the entries other than the l_open
59  * entry are here.  The l_nullioctl and ttymodem entries still look fishy.
60  * Reconsider the removal of nullmodem anyway.  It was too much like
61  * ttymodem, but a completely null version might be useful.
62  */
63
64 static struct linesw nodisc = {
65         .l_open =       l_noopen,
66         .l_close =      l_noclose,
67         .l_read =       l_noread,
68         .l_write =      l_nowrite, 
69         .l_ioctl =      l_nullioctl, 
70         .l_rint =       l_norint, 
71         .l_start =      l_nostart, 
72         .l_modem =      ttymodem
73 };
74
75 static struct linesw termios_disc = {
76         .l_open =       tty_open,
77         .l_close =      ttylclose,
78         .l_read =       ttread,
79         .l_write =      ttwrite, 
80         .l_ioctl =      l_nullioctl, 
81         .l_rint =       ttyinput, 
82         .l_start =      ttstart, 
83         .l_modem =      ttymodem
84 };
85
86 #ifdef COMPAT_43
87 #  define ntty_disc             termios_disc
88 #else
89 #  define ntty_disc             nodisc
90 #endif
91
92 struct linesw *linesw[MAXLDISC] = {
93         &termios_disc,          /* 0 - termios */
94         &nodisc,                /* 1 - defunct */
95         &ntty_disc,             /* 2 - NTTYDISC */
96         &nodisc,                /* 3 - loadable */
97         &nodisc,                /* 4 - SLIPDISC */
98         &nodisc,                /* 5 - PPPDISC */
99         &nodisc,                /* 6 - NETGRAPHDISC */
100         &nodisc,                /* 7 - loadable */
101         &nodisc,                /* 8 - loadable */
102 };
103
104 int     nlinesw = sizeof (linesw) / sizeof (linesw[0]);
105
106 #define LOADABLE_LDISC 7
107
108 /*
109  * ldisc_register: Register a line discipline.
110  *
111  * discipline: Index for discipline to load, or LDISC_LOAD for us to choose.
112  * linesw_p:   Pointer to linesw_p.
113  *
114  * Returns: Index used or -1 on failure.
115  */
116
117 int
118 ldisc_register(int discipline, struct linesw *linesw_p)
119 {
120         int slot = -1;
121
122         if (discipline == LDISC_LOAD) {
123                 int i;
124                 for (i = LOADABLE_LDISC; i < MAXLDISC; i++)
125                         if (linesw[i] == &nodisc) {
126                                 slot = i;
127                                 break;
128                         }
129         } else if (discipline >= 0 && discipline < MAXLDISC) {
130                 slot = discipline;
131         }
132
133         if (slot != -1 && linesw_p)
134                 linesw[slot] = linesw_p;
135
136         return slot;
137 }
138
139 /*
140  * ldisc_deregister: Deregister a line discipline obtained with
141  * ldisc_register.
142  *
143  * discipline: Index for discipline to unload.
144  */
145
146 void
147 ldisc_deregister(int discipline)
148 {
149
150         if (discipline < MAXLDISC)
151                 linesw[discipline] = &nodisc;
152 }
153
154 /*
155  * "no" and "null" versions of line discipline functions
156  */
157
158 static int
159 l_noopen(struct cdev *dev, struct tty *tp)
160 {
161
162         return (ENODEV);
163 }
164
165 static int
166 l_noclose(struct tty *tp, int flag)
167 {
168
169         return (ENODEV);
170 }
171
172 int
173 l_noread(struct tty *tp, struct uio *uio, int flag)
174 {
175
176         return (ENODEV);
177 }
178
179 int
180 l_nowrite(struct tty *tp, struct uio *uio, int flag)
181 {
182
183         return (ENODEV);
184 }
185
186 static int
187 l_norint(int c, struct tty *tp)
188 {
189
190         return (ENODEV);
191 }
192
193 static int
194 l_nostart(struct tty *tp)
195 {
196
197         return (ENODEV);
198 }
199
200 int
201 l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags, struct thread *td)
202 {
203
204         return (ENOIOCTL);
205 }