Accessing Hardware in Linux
Before proceeding with the Linux examples, it is important to have a basic understanding of hardware access in Linux. Linux, like most desktop operating systems, partitions its memory management into user space and kernel space.
User space is where applications run (including the Linux examples that follow). User space applications are allowed to access the hardware only through kernel-supported functions. Kernel space is typically where device drivers exist. This allows the device drivers to have direct access to the hardware.
The Linux examples use a function called
mmap in order to access a particular address
range. The mmap function asks the
kernel to provide access to a physical address range contained in the
hardware. For details on how we use mmap, refer to the book’s source code.