Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


❑ If the file is a regular file,file_ioctlis invoked. The function first checks a number of stan-
dard ioctls that are always implemented for this file type (FIGETBSZ, for example, to query the
blocksizeusedbythefile).do_ioctlis then used to invoke the file-specificioctlfunction in the
file_operations(if it exists) to process the ioctl (regular files do not usually provide aioctl
function so that the system call returns an error code).
❑ If the file is not a regular file,do_ioctland therefore the file-specificioctlmethods are invoked
immediately; the method for block device files isblkdev_ioctl.

blkdev_ioctlalso implements some ioctls that must be available for all block devices; for instance,
a request to read the partitioning data or a method of determining the total size of the device. There-
after the device-specific ioctls are processed by invoking theioctlmethod in thefile_operationsof
thegendiskinstance. This is where driver-specific commands, such as the eject medium command for
CD-ROMs, are implemented.

6.6 Resource Reservation


I/O portsandI/O memoryare two conceptual ways of supporting communication between device drivers
and devices. So that the various drivers do not interfere with each other, it is essential toreserveports and
I/O memory ranges prior to use by a driver. This ensures that several device drivers do not attempt to
access the same resources.

6.6.1 Resource Management


Let us first examine the data structures and functions for managing resources.

Tree Data Structures


Linux provides a generalized framework to help build data structures in memory. These structures
describe the resources available in the system and enable the kernel code to manage and allocate the
resources. Significantly, the name of the key structure isresource; it is defined as follows:

<ioport.h>
struct resource {
resource_size_t start;
resource_size_t end;
const char *name;
unsigned long flags;
struct resource *parent, *sibling, *child;
};

namestores a string so that the resource can be given a meaningful name. It has no relevance for the
kernel but is useful when a resource list (in theprocfilesystem) is output in readable form.

The resource itself is characterized by the three parameters below.startandendspecify a general area
marked by unsignedlongnumbers; even though theoretically the contents of the two numbers can be
interpreted freely, they usually represent an area in an address space.flagsenables the resource and its
current state to be described more precisely.
Free download pdf