C H A P T E R  15

User-Space USB Drivers

From a user's perspective, an application that requires a kernel driver detracts from the user experience. To begin with, driver installation involves writing to the “Extensions” directory, which requires administrative privileges. Therefore, the user needs to run an installer and enter the password of an administrative account, and then possibly restart before they can begin using the application. If, on the other hand, the application doesn't require a kernel driver, the installation procedure can be as simple as downloading an application from the Mac App Store.

In some cases, an application that would typically require a kernel driver can instead be written without the developer having to write any code that runs inside the kernel. Instead, the actions that would usually be performed by the driver can be done by the application. The advantage of this approach is that there is no kernel driver that needs to be installed, so the user doesn't need administrative privileges to install the application. Another advantage of moving the driver code out of the kernel and into the application is that any bugs that are present in the code can, at worst, crash the application, but they cannot cause a kernel panic that can bring down the entire system.

Not all hardware devices can be controlled through a user-space driver; for example, devices that contain a memory-mapped address range require a kernel driver. Similarly, devices that generate interrupts need a kernel driver, since only kernel code can execute at primary interrupt level. This means that all PCI and Thunderbolt devices need to be supported by a kernel driver. However, USB- and FireWire-based hardware devices are perfect candidates for a user-space driver. In this chapter, we discuss writing a driver that exists solely in user space for a USB device, without the need to write a kernel driver.

Not all USB and FireWire devices are suitable for a user-space driver. In particular, a driver that needs to create a device interface file in the /dev directory, such as a serial port driver or a storage device, needs a kernel driver. Also, a device that can be used by multiple applications simultaneously, or needs to be used by the system, such as an audio driver, should be written as a kernel driver. Thankfully, these cases are the exceptions, and most USB devices that require a custom driver can be controlled by a user-space driver.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.123.106