Re: drivers/char/tty_io.c

Theodore Y. Ts'o (tytso@mit.edu)
Thu, 10 Sep 1998 11:45:03 -0400


Date: Thu, 10 Sep 1998 19:07:43 +0530
From: Priyanka Grover <priya@cdac.ernet.in>

In the open code for the tty device in tty_io.c, the driver for the device
being opened is reassigned to the original tty driver on every open.

file ::
drivers/char/tty_io.c
function ::
static int init_dev(kdev_t device, struct tty_struct **ret_tty)
code ::

tty->driver = *driver; /* N.B. why do this every time?? */
======================

You're gravely mistaken; in both Linux 2.0.35, and linux 2.1.120, the
above line of code is only executed if the tty structure has just been
allocated. (See the line of code four lines above, where tty is
assigned to the result of get_free_page(GFP_KERNEL).)

Linux deallocates the tty structure when the last file descriptor
associated with the tty is closed, and reallocates it in init_dev() when
the tty is opened again. In both Linux 2.0.35 and Linux 2.1.120, there
is a "fast_track" code path which avoids reinitializing the tty
structure (including the tty->driver virtual function table) if the tty
is already open.

We feel that this piece of code is redundant. We are providing a patch for this
to support my driver. And it does not affect the normal behaviour of the system.

The above code is certainly not redundant; if you remove this code,
tty->driver will never get properly initialized, and the system will
crash immediately upon boot.

For a short-term fix, you'd be better off changing the pointer to the
driver function table for the console in the tty_drivers linked list;
this way, get_tty_driver() will return your hacked function table.

We would like to put in more work on this to clean up the tty driver code:

- Make keyboard driver independent of console. It should be possible to
attach the keyboard to required console, especially when there are multiple
VGA cards in the system.
- Support multiple logical keyboards. We wish to have system with two VGA
cards and two keyboards - one standard, other one wireless (through
serial port) or USB.

In essence if I have two monitors and two keyboards, I should be able to
attach whichever kbd I want to other. If there is only one keyboard, allow
a hot key to switch the keyboard to other physical console.

At some level, the keyboard driver is already independent of the
console; the only linkage is the fg_console and the ttytab array.
Similarly, allowing some other driver (a virtual logicial keyboard) to
insert characters into the tty is not difficult; that's just a matter of
getting a hold of the tty and then calling tty_insert_flip_char() and
tty_schedule_flip().

The main thing that's missing is the a set of well-defined interfaces
which are exported so that loadable modules would be able to take
advantage of this without needing to modify the kernel base. It's
something that's worthwhile doing for Linux 2.3 (and it shouldn't be
that difficult), but personally, I don't see it happening for Linux 2.2.
We *are* in feature freeze, after all.

- Ted

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html