From owner-freebsd-hackers Sun Oct 4 18:27:00 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA03254 for freebsd-hackers-outgoing; Sun, 4 Oct 1998 18:27:00 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from camel14.mindspring.com (camel14.mindspring.com [207.69.200.64]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA03244 for ; Sun, 4 Oct 1998 18:26:58 -0700 (PDT) (envelope-from tom@chattpiano.com) Received: from chattpiano.com (user-38lc7od.dialup.mindspring.com [209.86.31.13]) by camel14.mindspring.com (8.8.5/8.8.5) with ESMTP id VAA01356 for ; Sun, 4 Oct 1998 21:26:34 -0400 (EDT) Received: (from tom@localhost) by chattpiano.com (8.8.8/8.8.7) id VAA00729 for freebsd-hackers@FreeBSD.ORG; Sun, 4 Oct 1998 21:24:42 -0400 (EDT) (envelope-from tom) From: Tom Rush Message-Id: <199810050124.VAA00729@chattpiano.com> X-Mailer: XFMail 1.3 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Sun, 04 Oct 1998 21:24:42 -0400 (EDT) To: freebsd-hackers@FreeBSD.ORG Subject: Loadable line disciplines Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I have written a pseudo-device driver and assorted support programs for using IP on an Amateur Packet Radio network, and have been running it since about 2.1.5-RELEASE (I'm using -stable now). The driver uses a variant of the SLIP line discipline to communicate with a TNC, a kind of "radio modem". Since writing the driver, I have had a couple of ideas about the line discipline handling. One, putting the "hotchar" in the linesw struct and thus eliminating the check for SLIPDISC and PPPDISC in the serial drivers, has already been implemented in -current by someone else. The other, concerning the loadable line discipline setup, has not been dealt with; a search of the -hackers archive shows that the topic came up earlier this year, but nothing has changed. The problem, basically, is that if the "ldisc_register()" function is used for a non-standard line discipline, a user program cannot determine which slot in the linesw table it was assigned to, and thus cannot set up the tty to use that discipline. Obviously, no one has been losing sleep over this, since there aren't too many line discipline implementations being written these days; and if you aren't involved with maintaining tty drivers, you might want to move on to the next message. But if the loadable discipline feature is going to be in there, it ought to at least be useful; and it may have application for some of the current discussions about graphics tablets, etc. (see kern/tty_tb.c; it's apparently broken now, but how badly?) In order to fix this in a way that affects the smallest number of lines of code, I think a couple of fields should be added to the linesw struct, (sys/conf.h) as follows: struct linesw { l_open_t *l_open; l_close_t *l_close; l_read_t *l_read; l_write_t *l_write; l_ioctl_t *l_ioctl; l_rint_t *l_rint; l_start_t *l_start; l_modem_t *l_modem; + int l_disc; + char l_name[7]; u_char l_hotchar; }; "l_disc" would be used as an identifier, e.g., TTYDISC or SLIPDISC. This would allow any discipline to occupy any position in the table. Any positive integer (not just 0-7) would be a valid ID; an empty slot in the table would have l_disc = NULLDISC, #define'd as -1. "l_name" would contain a name for the discipline, e.g. "ppp" or "slip". This field is not necessary, but it eliminates the switch statement in pstat that displays the discipline name. (This means that a discipline would not have to have it's ID in ttycom.h, and a case added to that switch statement, to have it's name displayed.) In kern/tty_conf.c, only TTYDISC (termios), and NTTYDISC if COMPAT_43 is defined, are loaded by default. TTYDISC must be #define'd as 0 and go in slot 0; it is the only discipline that maintains the original "discipline = slot" relationship. "ldisc_register()" (which could get rid of the "discipline" argument, since that would be contained in the linesw struct) would check for a valid discipline ID, and then check the linesw table for duplicate ID's. The first vacant slot would be used for the new discipline if no dupes were found. In kern/tty.c, TIOCGETD would return linesw[tp->t_line].l_disc rather than tp->t_line. TIOCSETD would scan the linesw table looking for a matching discipline, then set tp->t_line to the corresponding slot number. Each line discipline module would have to call ldisc_register() in it's init routine to be assigned a slot in the linesw table. After that, the main things to look for are references to t_line (in the tty struct) that use it as a value rather than just an index. There are actually not too many of these, particularly since the hotchar field was placed in the linesw struct. Rather that post a bunch of diffs here, I packaged them up and put them at ftp://ftp.mindspring.com/users/tarush/ldiscload.tar.gz. Note that these diffs are for -stable; they may or may not patch cleanly on -current. If anyone cares, please take a look at these and let me know what you think. Thanks, --- Tom Rush tom@chattpiano.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message