The Design and Implementation of the FreeBSD Operating System

   

10.2. Line Disciplines

Most of the character processing done for terminal interfaces is independent of whether it is associated with a pseudo-terminal or a real hardware device. Therefore, most of this processing is done by common routines in the tty driver, or terminal handler. A hardware interface is supported by a specific device driver. The hardware driver is a device driver like those described in Chapter 6. It is responsible for receiving and transmitting characters and for handling some of the synchronization with the process doing output. The hardware driver is called by the tty driver to do output; in turn, it calls the tty driver with input characters as they are received. The pseudo-terminal interface acts as a software emulation of an asynchronous serial interface. Thus, a pseudo-terminal is indistinguishable from real hardware to the layers above and below it in the kernel.

The tty driver interfaces with the rest of the system as a line discipline. A line discipline is a processing module used to provide semantics on an asynchronous serial interface. It is described by a procedural interface, the linesw (line-switch) structure. The linesw structure specifies the entry points of a line discipline, much as the character-device switch cdevsw lists the entry points of a character device driver (see Section 6.2). The entry points of a line discipline are listed in Table 10.1 (on page 416). Like all device drivers, a terminal driver is divided into the top half, which runs synchronously when called to process a system call, and the bottom half, which runs asynchronously when characters are presented to it from a pseudo-terminal or hardware device. The line discipline provides routines that do common terminal processing for both the top and bottom halves of a terminal driver.

Table 10.1. Entry points of a line discipline.

Routine

Called from

Usage

l_open

above

initial entry to discipline

l_close

above

exit from discipline

l_read

above

read from line

l_write

above

write to line

l_ioctl

above

control operations

l_rint

below

received character

l_start

below

completion of transmission

I_modem

below

modem carrier transition

The serial terminal interface supports the normal set of character device-driver entry points specified by the character-device switch. Several of the standard driver entry points (read, write, and ioctl) immediately transfer control to the line discipline when called. (The standard tty polling routine ttypoll() usually is used as the device driver poll entry in the character-device switch.) The open and close routines are similar; the line-discipline open entry is called when a line first enters a discipline, either at initial open of the line or when the discipline is changed. Similarly, the discipline close routine is called to exit from a discipline. All these routines are called from above in response to a corresponding system call. The remaining line-discipline entries are called by the bottom half of the device driver to report input or status changes detected at interrupt time. The l_rint (receiver interrupt) entry is called with each character received on a line. The corresponding entry for transmit-complete interrupts is the l_start routine, which is called when output operations complete. This entry gives the line discipline a chance to start additional output operations. For the normal terminal line discipline, this routine simply calls the driver's output routine to start the next block of output. Transitions in modem-control lines (see Section 10.7) may be detected by the hardware driver, in which case the l_modem routine is called with an indication of the new state.

The system includes several different types of line disciplines. Most lines use the terminal-oriented discipline described in Section 10.3. Other disciplines in the system support various asynchronous serial network interface protocols.


   
 

Категории