Chapter 8
210
the top of the stack is a client driver that the operating system has assigned to
the device. Another term for client driver is function driver. USB class drivers
and vendor-specific device drivers are client drivers. Applications access a USB
device by communicating with the client driver. The client driver in turn com-
municates with lower-level bus and port drivers that access the hardware. One
or more filter drivers can supplement a client driver or bus driver.
Dividing communications into layers is efficient because devices that have tasks
in common can use the same driver for those tasks. For example, it makes sense
to have one set of drivers that handle tasks common to all USB devices. An
operating system can provide these drivers so device vendors don’t have to do so
with much duplication of effort.
7UGTCPF-GTPGN/QFGU
Under Windows, program code runs in either user mode or kernel mode. Each
mode allows a different level of privilege in accessing memory and other system
resources. Figure 8-1 shows the major components of user and kernel modes in
USB communications. Applications run in user mode. A USB device must have
a kernel-mode client driver, which can have a supplementary user-mode driver.
User mode has limited access to memory and other system resources. Applica-
tions and user-mode client drivers can’t access memory that the operating sys-
tem has designated as protected. Limiting access to memory in this way enables
the PC to run multiple applications at the same time. If an application crashes,
other applications shouldn’t be affected.
Kernel-mode code has unrestricted access to system resources, including the
ability to execute memory-management instructions and control access to I/O
ports. A kernel-mode driver can allow any application to use a device or allow a
single application to have exclusive use. Other abilities that Windows reserves
for kernel-mode drivers include DMA transfers and responding to hardware
interrupts.
The specifics vary with the driver, but in general, ways that applications may
communicate with kernel-mode drivers include Windows API functions, other
functions exposed by a user-mode driver, and the properties, methods, and
events of classes defined by the .NET Framework. To communicate with a USB
device, an application often doesn’t have to know anything about the USB pro-
tocol or whether a device uses USB at all.
Kernel-mode drivers communicate using structures called I/O request packets
(IRPs) supported by the operating system. Each IRP requests a single input or