On this page
Device Model
Coverage: kobject/kset → device/driver/bus/class → sysfs binding → probe lifecycle → udev → device tree (DT) → ACPI → platform device Kernel versions: 2.6 ~ 6.x
Overview
The Linux device model is an internal kernel framework that provides a unified representation and lifecycle management for all devices, drivers, and buses. Its core value lies not in "how devices work," but in "how devices and drivers find each other"—namely, device-driver binding.
kobject: The Basic Building Block
// include/linux/kobject.h
;
// kobject itself does not manage devices — it provides:
// 1. Directory/file representation in sysfs
// 2. Reference counting → automatic release
// 3. Parent-child hierarchical relationships
kset: A Collection of kobjects
;
// Example: /sys/devices/ → devices_kset
// /sys/bus/ → bus_kset
Device / Driver / Bus
struct device
// include/linux/device.h
;
struct device_driver
;
struct bus_type
;
Binding Flow
// drivers/base/dd.c
// Device registration:
→
→ // Attach to bus->p->klist_devices
→
→
→
→ // Iterate through all registered drivers
→ // bus->match() or of_match/acpi_match
→
→
→
→ → drv->
Key Point: Binding is bidirectional—when a new device arrives, it iterates through drivers; when a new driver registers, it iterates through devices. Regardless of who registers first, the match will occur.
sysfs and Attributes
// Each directory under /sys = one kobject
// Attribute files = struct device_attribute
;
// Macros: DEVICE_ATTR_RO(name) → generates read-only attribute
// DEVICE_ATTR_WO(name) → write-only
// DEVICE_ATTR_RW(name) → read-write
Device Tree vs ACPI
udev
References
- Source Code:
drivers/base/core.c,drivers/base/bus.c,drivers/base/dd.c,include/linux/device.h - Kernel Documentation:
Documentation/driver-api/driver-model/
Keywords: kobject, device, driver, bus, probe, sysfs, device tree, ACPI, udev, modalias