What a Device Driver Is and How Drivers Talk to Hardware
What a Linux 6.12 device driver is, how it reaches hardware through registers, port I/O, DMA and interrupts, and how it presents the device to user space.

Most software never touches hardware. It calls read() on a file or send() on a socket, and something below it turns that into electrical signals on a disk controller or a network card. That something is a device driver: the piece of the kernel that knows one kind of hardware and translates between it and the rest of the system. This post explains on Linux 6.12 what a driver is made of, how it communicates with a device through registers, ports, DMA and interrupts, and how it exposes the result to programs. It is the foundation for every driver post in this cluster, from the PCI skeleton to the GPIO and LED drivers.
The kernel's own overview is in the driver model documentation.
A driver is kernel code with two faces
A driver has a hardware face and a software face. The hardware face is the code that reads and writes the device's registers, handles its interrupts and sets up its DMA. The software face is the code that registers the device with a kernel subsystem, so that the rest of the system can use it without knowing which chip is underneath.
Take a network card. Its hardware face programs the descriptor rings and reads the status register. Its software face registers a net_device, so the network stack sees an interface called eth0 with the same operations as any other: open, close, transmit. A program that sends a packet never learns that the card is an Intel or a Realtek one. The subsystem defines the contract, and the driver implements it for one piece of hardware.
Most drivers are built as modules, files ending in .ko that can be loaded and unloaded while the system runs. Some are compiled into the kernel image. The minimal driver module shows the structure:
#include <linux/module.h>
#include <linux/init.h>
static int __init hello_init(void)
{
pr_info("hello: loaded\n");
return 0;
}
static void __exit hello_exit(void)
{
pr_info("hello: unloaded\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_DESCRIPTION("Smallest possible module");
MODULE_LICENSE("GPL");Build it with a Kbuild file (obj-m += hello.o), load it and the message appears in the kernel log:
sudo insmod hello.ko
sudo dmesg | tail -n 1
sudo rmmod hello[ 4172.331905] hello: loadedThis module drives nothing. It shows the lifecycle: module_init runs at load and module_exit at unload. A real driver replaces the body of the first with a registration that says "I handle devices matching this table".
How a driver finds its device
On a bus with discoverable devices, such as PCI or USB, the bus code enumerates what is plugged in and offers each device to the registered drivers. A driver declares an ID table, and the match is by vendor and product ID or by class. When one matches, the kernel calls the driver's probe function with a handle to the device, as in the USB skeleton.
On a board with fixed hardware, such as an Arm system on a chip, nothing enumerates. The devices are described in a device tree, a data file that lists each peripheral, its address and its interrupt. The kernel creates a device for each node, and a driver matches on a string in the node's compatible property. The probe call is the same, and what differs is how the match is made.
The effect in both cases is the same. The driver's probe runs once per matching device, with everything the driver needs already assigned: addresses, interrupts, clocks. Its job is to set the device up and register it with a subsystem.
How a driver talks to hardware
A device is not a function you can call. A driver communicates with it in four ways, and nearly every driver uses a mix.
Memory-mapped registers. The device exposes control and status registers at physical addresses. The driver maps them into kernel virtual memory and accesses them with ioread32() and iowrite32(), as in the BAR mapping post. Writing a register commands the device, and reading one reports its state.
iowrite32(CTRL_ENABLE, regs + REG_CTRL);
status = ioread32(regs + REG_STATUS);Port I/O. Some older x86 devices use a separate address space reached with special instructions. The kernel's inb() and outb() wrap them. New hardware seldom uses ports, but legacy devices such as a PC serial port do.
Interrupts. A device cannot call the driver, so it raises a signal when something needs attention: a packet arrived, a transfer finished, a button was pressed. The driver registers a handler with request_irq(), and the kernel runs it when the interrupt fires. The handler is kept short: it reads the cause, acknowledges the device, and defers heavy work to a thread or a workqueue.
DMA. For bulk data, the device reads and writes system memory by itself. The driver prepares a buffer, gives the device its bus address, and starts the transfer. The device interrupts when it finishes. This lets the CPU do other work during a transfer, and the DMA API from the earlier post makes it correct across platforms.
On devices behind a serial bus, such as an I2C temperature sensor or a SPI flash chip, the driver does not touch registers directly. It asks the bus controller driver to send bytes, and the sensor's own registers are reached through that. The layering continues: the sensor driver sits on the I2C subsystem, which sits on the controller driver, which touches real registers.
How a driver presents the device
The software face has three common forms.
A subsystem registration. The best result is that the driver registers with an existing subsystem: input for keyboards and buttons, network for interfaces, block for disks, sound, LED, watchdog, RTC, hwmon for sensors. User space then gets the standard interface for that class, such as /dev/input/event0 or eth0, and existing tools work.
A character device. For hardware that fits no subsystem, a driver can create a device node under /dev with read, write and ioctl operations that it defines itself. The interface is whatever the driver chooses, and that is also the cost: every program must know it.
Attributes in sysfs. Almost every driver exposes configuration and status as small files under /sys. A driver registering a device automatically creates a directory with its basic attributes, and it may add more.
You can see the results of all three on any system. The list of loaded modules, their size and their users:
lsmod | head -n 4Module Size Used by
snd_hda_codec_realtek 200704 1
snd_hda_codec_generic 122880 1 snd_hda_codec_realtek
nvme 69632 3And the driver bound to one device, with the files it exposes:
ls /sys/bus/pci/devices/0000:00:1f.6/
readlink /sys/bus/pci/devices/0000:00:1f.6/driverclass config device driver irq resource vendor ...
../../../bus/pci/drivers/e1000eWhat can go wrong, and why it is serious
A driver runs in kernel mode with full access to memory. A bug in it is not a crashed program but a corrupted kernel, a hung machine or a security hole. That shapes how drivers are written: no unbounded loops waiting for hardware, careful reference counting so a device that disappears while in use does not leave dangling pointers, and no sleeping in interrupt context. The posts that follow return to these rules in each setting.
The same fact explains why drivers have a reputation as hard code. The language is C with a large set of kernel-specific conventions, the hardware is documented in datasheets of variable quality, and the failure modes include "the machine stops responding". The kernel gives you structure to lean on, the subsystems and the device model, and the practical approach is to start from an existing driver for similar hardware.


