Day 71 - Linux Driver Model Fundamentals¶
Today's Goal¶
Understand the Linux Driver Model architecture and the relationship between:
struct devicestruct device_driverstruct bus_type
Learn how the Linux Driver Core performs:
- Device registration
- Driver registration
- Device-driver matching
- Probe and remove lifecycle
- sysfs object hierarchy
What I Learned¶
Linux Driver Model Architecture¶
The Linux Driver Model is built around three core objects:
Where:
struct device
Represents a hardware device
struct device_driver
Represents a driver
struct bus_type
Performs matching between devices and drivers
The driver core coordinates the relationship between these objects.
Device Registration and Driver Registration¶
A device and driver can be registered independently.
The registration order does not matter.
Example:
or
The bus performs matching whenever a new device or driver appears.
Matching and Probe Flow¶
The matching process is controlled by the bus.
Example:
The probe callback is only executed when matching succeeds.
Experiments confirmed:
- Matching success triggers probe
- Matching failure prevents probe
- Registration success does not guarantee probe success
Probe Failure Behavior¶
A driver may register successfully while probe fails.
Example:
Observed behavior:
- Driver remains registered
- Device is not bound
- Remove callback is not called
This demonstrates that:
Driver Wrapper Abstraction¶
Implemented a custom driver wrapper:
struct demo_driver {
struct device_driver driver;
int (*probe)(struct device *dev);
void (*remove)(struct device *dev);
};
This mimics subsystem-specific driver structures such as:
struct platform_driverstruct i2c_driverstruct spi_driver
and illustrates how Linux extends the generic driver core.
sysfs Hierarchy¶
Observed the generated sysfs hierarchy:
Verified:
This demonstrates that:
Labs Completed¶
Lab 1 - Basic Driver Core Registration¶
Implemented:
bus_register()device_register()driver_register()
Observed:
execution flow.
Lab 2 - Driver Wrapper Abstraction¶
Implemented:
and bus-level probe/remove forwarding.
Observed:
and
flow.
Lab 3 - Match Success and Failure¶
Tested:
- Matching success
- Matching failure
Verified that probe is only executed when matching succeeds.
Lab 4 - Probe Failure Behavior¶
Forced probe to return:
Verified:
- Driver registration succeeds
- Device binding fails
- Remove callback is not executed
Lab 5 - sysfs Observation¶
Inspected:
Verified device, driver, and bus relationships inside sysfs.
Key Takeaways¶
- Linux Driver Model consists of device, driver, and bus objects.
- Bus performs matching and controls probe execution.
- Probe success establishes device-driver binding.
- Driver registration is independent from probe success.
- sysfs is a representation of the Linux Device Model.
- Platform, I2C, SPI, USB, and PCI subsystems are built on top of the same driver core concepts.
Next Step¶
Day72 - Platform Bus Internals
Topics:
platform_bus_typeplatform_deviceplatform_driver- Device Tree to Platform Device conversion
of_match_table- Compatible matching flow
- Platform bus probe lifecycle