13.4. Character Device Handling

Handling a character device is relatively easy, since no data buffering is needed and no disk caches are involved. Of course, character devices differ in their requirements: some of them must implement a sophisticated communication protocol to drive the hardware device, while others just have to read a few values from a couple of I/O ports of the hardware devices. For instance, the device driver of a multiport serial card device (a hardware device offering many serial ports) is much more complicated than the device driver of a bus mouse.

Let's briefly sketch out the functioning of a very simple character device driver, namely the driver of the Logitech bus mouse. It is associated with the /dev/logibm character device file, which has major number 10 and minor number 0.

Suppose that a process opens the /dev/logibm file; as explained in Section 13.2.2 earlier in this chapter, the VFS ends up invoking the open method of the device file operations common to all character devices having major number 10. This device class covers a series of heterogeneous devices, and hence the method, a function called misc_open( ), installs yet a more specialized set of file operations according to the device's minor number. As the final result, the field f_op of the file object points to the bus_mouse_fops table, and the open_mouse( ) function is invoked. This function performs the following operations:

  1. Checks whether the bus mouse is connected.

  2. Requests the IRQ line ...

Get Understanding the Linux Kernel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.