In This Chapter
Overview of a General USB Host Stack Architecture
Overview of Linux USB Host Stack Architecture
The universal serial bus (USB) protocol is a host-driven system consisting of three major layers: the USB interface, the USB system, and the client software. The USB system software is implemented as part of the Linux kernel; the rest of the layer is outside the scope of this chapter. The USB system software consists mostly of the host controller driver (HCD) and a framework for the USB protocol. The system software sometimes adds functionality that is specific to the implementation, which makes the system more functional. You will learn about additional functionality that the Linux USB host stack provides in the subsequent chapters of this part.
This chapter initially explores the generic USB host software, detailing what a host stack looks like. It subsequently explores the Linux host stack architecture and provides a starting point to study the USB host stack.
On a typical USB host system, the hardware implements most of the USB protocol and the physical layer. The system software consists of host controller software and modules to manage device enumerations and data transfers, along with USB drivers that support USB devices. Figure 4.1 illustrates a typical USB host stack.
The host software module implements the USB host protocol requirements of the USB specification. This includes detecting the attachment and removal of devices, supporting the enumeration process, and transferring data. The operating systems running on the platform for managing devices generally provide the host software.
The USB driver (USBD) module implements the necessary protocol interface between the client application and the system software—the USBDI—and provides the necessary interface between the HCD and the system software: the Host Controller Driver Interface (HCDI). The HCDI is designed to provide a generic interface between the HCD and the system software. This allows the system to work with any HCD without modifying the system software design. The USBD also implements the necessary infrastructure for transfer of data between the client application and the HCD.
The HCD implements the driver for Enhanced Host Controller Interface (EHCI), Open Host Controller Interface (OHCI), and other custom USB host controllers. It also provides the necessary abstraction to the hardware below. In general, the HCDs are based on the type of interface they use to connect to the main processor. On a personal computer, the host controllers primarily interface using Peripheral Component Interconnect (PCI); therefore, the HCDs are based on the PCI framework. On an embedded setup, the interfaces vary, depending on the system requirement and the interface availability.
The Linux USB host stack consists of two major parts: the usbcore
available in the /drivers/usb/core
folder and the HCDs available in /drivers/usb/host/.
The usbcore
module implements both the host software and the USBD functionalities. Figure 4.2 represents the Linux USB host stack in a simple way.
The USB system software module is named usbcore and consists of the following modules: device management, power management, USB hub driver, USB host driver, and HCD interfaces.
As part of device management, the Linux USB subsystem implements functionalities that help manage USB devices connected to the host. The USB devices that are connected to the host share information via virtual file systems (VFSs) of Linux as part of the sysfs
and procfs
file systems. The devices also implement frameworks such as device notification, allowing the host system to report the addition or removal of devices to other modules.
The USB specification defines methods to save power on USB devices and is implemented as part of the usbcore
. The power management framework on Linux is part of the usbcore
, which implements USB requirements such as remote wakeup. The power management framework also provides a VFS to manage the framework from user space.
The USB hub driver framework implements the USB hub requirements and is part of the usbcore
. The hub framework is responsible for resetting the device and announcing new devices to other modules.
The USB host driver framework implements USB transfers and other USB host requirements. The host driver also manages USB Request Block (URB) transfer from the class drivers to the HCDs.
The USB HCD implements drivers for the USB host controllers. The USB host controllers are based on EHCI or OHCI specification or sometimes custom host controller implementation. The HCD implements the necessary abstraction between the hardware and the Linux USB system software: the usbcore
.
The USB host system software stack is complex compared to the device counterpart, because USB is a host-driven system. This chapter provided a brief overview of the Linux USB host architecture and a simple view of the USB host stack. The Linux USB host framework is layered and designed with clean interfaces that help you design similar software frameworks. The subsequent chapters detail the internal layers of the Linux USB host framework.
The USB host software architecture consists of application software and drivers that are specific to the operating systems. The application software is mostly USB-class specific; it determines the system configuration. The Linux documentation on the USB subsystem is available on Documentation/usb
. You can read about how USB devices are notified of other modules in Chapter 5, “USB Device Notification.” Chapter 6, “Device File System,” offers a detailed study of the USB device file system. That’s followed by USB host power management internals in Chapter 7, “Power Management,” and USB hub implementation in Chapter 8, “Hub.” You can take a detailed look at a generic USB host implementation in Chapter 9, “Generic Driver.” Finally, you can study details of USB HCD implementation in Chapter 10, “Host Driver for Embedded Controller.”
联系客服