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. 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. 23 * 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. 35 * 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 $ 38 */ 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/tty.h> 43 #include <sys/conf.h> 44 45 #ifndef MAXLDISC 46 #define MAXLDISC 9 47 #endif 48 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; 53 54 /* 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. 59 */ 60 #define NODISC(n) \ 61 { l_noopen, l_noclose, l_noread, l_nowrite, \ 62 l_nullioctl, l_norint, l_nostart, ttymodem } 63 64 struct linesw linesw[MAXLDISC] = 65 { 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 */ 77 }; 78 79 int nlinesw = NELEM(linesw); 80 81 static struct linesw nodisc = NODISC(0); 82 83 #define LOADABLE_LDISC 7 84 /* 85 * ldisc_register: Register a line discipline. 86 * 87 * discipline: Index for discipline to load, or LDISC_LOAD for us to choose. 88 * linesw_p: Pointer to linesw_p. 89 * 90 * Returns: Index used or -1 on failure. 91 */ 92 int 93 ldisc_register(int discipline, struct linesw *linesw_p) 94 { 95 int slot = -1; 96 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; 103 } 104 } 105 else if (discipline >= 0 && discipline < MAXLDISC) { 106 slot = discipline; 107 } 108 109 if (slot != -1 && linesw_p) 110 linesw[slot] = *linesw_p; 111 112 lwkt_reltoken(&tty_token); 113 return slot; 114 } 115 116 /* 117 * ldisc_deregister: Deregister a line discipline obtained with 118 * ldisc_register. 119 * 120 * discipline: Index for discipline to unload. 121 */ 122 void 123 ldisc_deregister(int discipline) 124 { 125 lwkt_gettoken(&tty_token); 126 if (discipline < MAXLDISC) { 127 linesw[discipline] = nodisc; 128 } 129 lwkt_reltoken(&tty_token); 130 } 131 132 static int 133 l_noopen(cdev_t dev, struct tty *tp) 134 { 135 136 return (ENODEV); 137 } 138 139 static int 140 l_noclose(struct tty *tp, int flag) 141 { 142 143 return (ENODEV); 144 } 145 146 int 147 l_noread(struct tty *tp, struct uio *uio, int flag) 148 { 149 150 return (ENODEV); 151 } 152 153 int 154 l_nowrite(struct tty *tp, struct uio *uio, int flag) 155 { 156 157 return (ENODEV); 158 } 159 160 static int 161 l_norint(int c, struct tty *tp) 162 { 163 164 return (ENODEV); 165 } 166 167 static int 168 l_nostart(struct tty *tp) 169 { 170 171 return (ENODEV); 172 } 173 174 /* 175 * Do nothing specific version of line 176 * discipline specific ioctl command. 177 */ 178 int 179 l_nullioctl(struct tty *tp, u_long cmd, char *data, int flags, 180 struct ucred *cred) 181 { 182 183 return (ENOIOCTL); 184 } 185