- Introduction
- What is Device Model?
- Why Do We Need Device Model?
- Goals of Device Model
- Components of Device Model
- Bus
- Device
- Driver
- Class
- Kobject
- Kset
- Sysfs
- How Device Model Works
- Device Registration Flow
- Driver Binding Process
- Memory Representation
- Real Embedded Example
- Advantages
- Disadvantages
- Common Mistakes
- Interview Questions
- Quick Revision
- Conclusion
The Linux Device Model is a framework used by the Linux kernel to represent:
- Devices
- Device Drivers
- Buses
- Classes
It provides:
- Uniform device representation
- Automatic device-driver matching
- Power management
- Sysfs interface
- Hotplug support
The Linux Device Model is widely used in:
- Embedded Linux
- Linux Device Drivers
- Android Kernel
- Automotive Linux
- IoT Systems
The Linux Device Model is a framework that manages the relationship between:
- Devices
- Drivers
- Buses
- Classes
and exposes them through Sysfs.
The Linux Device Model is a kernel framework used to organize devices, drivers, buses, and classes, providing automatic driver binding and sysfs representation.
Without Device Model:
Device
↓
Driver
(No standard structure)
Difficult to manage
No sysfs
No hotplug
With Device Model:
Device
↓
Bus
↓
Driver
↓
Class
↓
Sysfs
↓
User Space
- Standard representation
- Automatic matching
- Power management
- Dynamic device creation
- Sysfs interface
- Device Management
- Driver Binding
- Hotplug Support
- Power Management
- Sysfs Representation
- Standardized Architecture
Linux Device Model
│
├── Bus
├── Device
├── Driver
├── Class
├── Kobject
├── Kset
└── Sysfs
A bus connects devices and drivers.
Examples:
- PCI
- USB
- I2C
- SPI
- Platform Bus
struct bus_type
{
const char *name;
int (*match)(...);
int (*probe)(...);
void (*remove)(...);
};- Device registration
- Driver registration
- Device-driver matching
Represents a physical or virtual hardware component.
Examples:
- UART
- SPI Controller
- Ethernet Controller
- GPIO Controller
struct device
{
struct kobject kobj;
struct bus_type *bus;
struct device_driver *driver;
struct device *parent;
};- Device Information
- Parent-child hierarchy
- Sysfs representation
Software component controlling a device.
struct device_driver
{
const char *name;
struct bus_type *bus;
int (*probe)(...);
void (*remove)(...);
};-
Initialize device
-
Configure hardware
-
Interrupt handling
-
Data transfer
Groups similar devices together.
Examples:
-
net
-
tty
-
input
-
block
/sys/class/
├── net
├── tty
├── input
└── block
Kernel object providing:
-
Object hierarchy
-
Reference counting
-
Sysfs support
struct kobject
{
const char *name;
struct kref kref;
struct kset *kset;
};Collection of kobjects.
Kset
│
├── Device1
├── Device2
└── Device3
Virtual filesystem exposing kernel objects.
Mounted at:
/sys
/sys
├── bus
├── devices
├── class
└── firmware
-
User space visibility
-
Device information
-
Runtime configuration
-
Debugging
Device Registered
↓
Bus Registered
↓
Driver Registered
↓
Bus Match Function
↓
Probe Function Called
↓
Driver Attached
↓
Sysfs Entries Created
device_register(dev);Internally:
device_register()
↓
device_initialize()
↓
kobject_init()
↓
bus_add_device()
↓
sysfs_create()
↓
Device Ready
Device Appears
↓
Bus Searches Driver
↓
match()
↓
probe()
↓
Driver Bound
↓
Operational
RAM
------------------------------------------------
struct device
|
+--- kobject
|
+--- bus
|
+--- driver
|
+--- parent
------------------------------------------------
struct device_driver
|
+--- name
|
+--- probe
|
+--- remove
------------------------------------------------
I2C Bus
│
├── EEPROM
├── RTC
└── Temperature Sensor
Driver:
static struct i2c_driver temp_driver =
{
.probe = temp_probe,
.remove = temp_remove,
};/sys/bus/i2c/devices/
├── 0-0050
├── 0-0068
└── 0-0048
✔ Standardized architecture
✔ Automatic driver binding
✔ Sysfs interface
✔ Power management
✔ Hotplug support
✔ Device hierarchy
✘ Complex structures
✘ Difficult debugging
✘ Steep learning curve
✘ Many layers of abstraction
❌ Forgetting device registration
❌ Missing probe function
❌ Incorrect bus matching
❌ Reference count leaks
❌ Improper sysfs cleanup
Framework managing devices, drivers, buses, and classes.
For:
-
Driver binding
-
Sysfs
-
Power management
-
Hotplug support
-
Device
-
Driver
-
Bus
-
Class
-
Kobject
-
Kset
-
Sysfs
Called when device matches driver.
Virtual filesystem exposing kernel objects.
Device Model
↓
Bus
↓
Device
↓
Driver
↓
Class
↓
Kobject
↓
Kset
↓
Sysfs
↓
Automatic Driver Binding
↓
Embedded Linux
The Linux Device Model is the backbone of Linux device management.
It organizes:
- Devices
- Drivers
- Buses
- Classes
and provides:
- Automatic driver matching
- Sysfs representation
- Power management
- Hotplug support
Understanding the Device Model is essential for:
- Linux Device Drivers
- Embedded Linux
- Android Kernel
- Automotive Linux
- System Programming