Day71 - Linux Driver Model Fundamentals¶
Objective¶
Understand how the Linux Driver Core coordinates:
- Bus
- Device
- Driver
and performs:
- Device registration
- Driver registration
- Matching
- Probe
- Remove
without relying on Platform Bus or Device Tree.
Lab Environment¶
Kernel:
Platform:
Module:
Lab 1 - Minimal Driver Core¶
Goal¶
Create a minimal Linux Driver Model implementation using:
without using:
- Platform Bus
- Device Tree
- Overlay
Demo Bus¶
Demo Device¶
static struct device demo_device = {
.init_name = DEMO_DEVICE_NAME,
.bus = &demo_bus_type,
.release = demo_device_release,
};
Demo Driver¶
static struct device_driver demo_driver = {
.name = DEMO_DEVICE_NAME,
.bus = &demo_bus_type,
.probe = demo_drv_probe,
.remove = demo_drv_remove,
};
Registration Flow¶
Result¶
Verified:
Lab 2 - Registration Order¶
Goal¶
Verify that registration order does not matter.
Driver First¶
Result¶
Observation¶
The Linux Driver Core performs matching whenever a new device or driver appears.
Therefore:
and
both work correctly.
Lab 3 - Match Failure¶
Goal¶
Verify that matching controls probe execution.
Driver Name¶
Match Function¶
Result¶
No probe was executed.
Observation¶
Lab 4 - Driver Wrapper¶
Goal¶
Implement a subsystem-style driver wrapper.
Wrapper Definition¶
struct demo_driver {
struct device_driver driver;
int (*probe)(struct device *dev);
void (*remove)(struct device *dev);
};
Bus Probe¶
static int demo_bus_probe(struct device *dev)
{
struct demo_driver *ddrv;
ddrv = to_demo_driver(dev->driver);
return ddrv->probe(dev);
}
Bus Remove¶
static void demo_bus_remove(struct device *dev)
{
struct demo_driver *ddrv;
ddrv = to_demo_driver(dev->driver);
ddrv->remove(dev);
}
Result¶
and
Observation¶
This architecture resembles:
which all extend:
with subsystem-specific callbacks.
Lab 5 - Probe Failure¶
Goal¶
Observe probe failure behavior.
Probe¶
Result¶
Observation¶
Verified:
Driver registration remains successful.
Remove callback is not executed because the device was never bound.
Lab 6 - sysfs Observation¶
Goal¶
Observe the generated sysfs hierarchy.
Commands¶
ls -R /sys/bus/demo_bus
readlink -f \
/sys/bus/demo_bus/devices/demo_device
find /sys/devices -name demo_device
Result¶
Observation¶
Verified:
contains the actual device object.
provides the bus view.
provides the driver view.
Conclusion¶
This lab demonstrated the Linux Driver Core workflow:
and the corresponding removal flow:
The implementation provides a minimal model of how Platform, I2C, SPI, USB, and PCI subsystems interact with the Linux Driver Core.