next
Driver on

Device Drivers

Gadget Drivers
next up previous contents
Subsequent: Polling and Interrupts
Up: tlk-html.html
Earlier: Initializing the Interrupt Dealing with

 

One of many functions of an working system is to cover the peculiarities of the systme’s {hardware}
gadgets from its customers.
For instance the Digital File System presents a uniform view of the mounted filesystems irrespective
of the underlying bodily gadgets.
This chapter describes how the Linux kernel manages the bodily gadgets within the system.

The CPU isn’t the one clever gadget within the system, each bodily
gadget has a {hardware} controller. The keyboard, mouse and serial ports
are managed by a SuperIO chip, the IDE disks by an IDE controller, SCSI disks by a SCSI
controller and so forth.
Every {hardware} controller has its personal management and standing registers (CSRs)
and these differ between gadgets.
The CSRs for an Adaptec 2940 SCSI controller are utterly completely different from these
of an NCR 810 SCSI controller.
These CSRs are used to begin and cease the gadget, to initialize it and to diagnose
any issues with it.
As a substitute of placing code to handle the {hardware} controllers within the
system into each utility, the code is stored within the Linux kernel.
The software program that handles or manages a {hardware} controller is named a tool
driver.
The Linux kernel gadget drivers are, basically, a shared library of privileged,
reminiscence resident, low degree {hardware} dealing with routines.
It’s Linux’s gadget drivers which every deal with the peculiarities of the gadgets that they
are managing.

Each gadget within the system is represented by a gadget particular file, for instance the primary
IDE disk within the system is represented by /dev/hda.
These gadget particular recordsdata are created by the mknod  command they usually describe the gadget utilizing
main and minor gadget numbers.
All gadgets managed by the identical gadget driver have a standard main gadget quantity.
The minor gadget numbers are used to distinquish between completely different gadgets, for instance
every partition on the first IDE disk has a special minor gadget quantity.
So, /dev/hda2, the second partition of the first IDE disk has a serious variety of three and
a minor variety of 2.
One of many fundamental options of Unix is that it abstracts the dealing with of gadgets.
All {hardware} gadgets seem like common recordsdata; they are often opened, closed, learn and
written utilizing the identical, customary, system calls which might be used to govern recordsdata.
Linux’s Digital File System maps the gadget particular file handed within the system calls to the
gadget’s gadget driver utilizing the key gadget quantity.

Linux helps three kinds of {hardware} gadgets: character, block and community.
Character gadgets are learn and written immediately with out buffering, for instance the system’s
serial ports /dev/cua0 and /dev/cua1.
Block gadgets can solely be written to and browse from in multiples of the block measurement, sometimes
512 or 1024 bytes.
Block gadgets are accessed by way of the buffer cache and could also be randomly accessed, that’s
any block will be learn or written regardless of the place it’s on the gadget.
Block gadgets will be accessed by way of their gadget particular file however extra generally they’re accessed by way of the filesystem.
Solely a block gadget can assist a mounted file system.
There are lots of completely different gadget drivers within the Linux kernel (that’s one in all
Linux’s strengths) however all of them share some frequent attributes:

kernel code
Gadget drivers are a part of the kernel and, like different code
throughout the kernel, in the event that they go improper they will severely harm the system.
A badly written driver might even crash the system, probably corrupting
file techniques and shedding knowledge,
Interfaces
A tool driver should present a typical interface to the kernel.
The kernel makes use of this interface to work together with the gadgets that this gadget
driver controls.
That interface is completely different relying on the category of gadget driver. So, for
instance, the interface supplied by a SCSI gadget is completely different from that supplied
by an ethernet gadget. The kernel can also present entry to the system gadgets
to processes within the system by way of customary interfaces. For instance, the socket
interface can be utilized to hook up with the system’s ethernet gadgets.
Kernel companies
Gadget drivers make use of normal
kernel companies similar to reminiscence allocation, interrupt supply and wait queues
to function,
Loadable
A lot of the Linux gadget drivers will be loaded on demand as kernel
modules when
they’re wanted and unloaded when they’re now not getting used. This makes the
kernel very adaptable and environment friendly with the system’s assets,
Configurable
Linux gadget drivers will be constructed into the kernel. Which
gadgets are constructed is configurable when the kernel is compiled,
Dynamic
Because the system boots and every gadget driver is initialized it appears to be like
for the {hardware} gadgets that it’s controlling.
It doesn’t matter if the gadget being managed by a selected gadget driver
doesn’t exist. In
this case the gadget driver is solely redundant and causes no hurt other than
occupying slightly of the system’s reminiscence.



next up previous contents
Subsequent: Polling and Interrupts
Up: tlk-html.html
Earlier: Initializing the Interrupt Dealing with

David A. Rusling
[email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *