The three important concepts of the Linux device model are bus, device, and driver, that is, bus, device, and driver. In fact, some data structures are defined in the kernel. they are structbus_type, structdevice, and structdevice_driver. these three important data knots...
The three important concepts of the Linux device model are bus, device, and driver, that is, bus, device, and driver. In fact, the kernel also defines such data structures: struct bus_type, struct device, and struct device_driver. these three important data structures come from the same place, include/linux/device. h.
We know that there are many types of bus, such as PCI bus, SCSI bus, and USB bus, so we will see pci_bus_type, scsi_bus_type, and usb_bus_type in the Linux kernel code. they are all struct bus_type variables. In the struct bus_type structure, two very important members are struct kset drivers and struct kset devices. Kset and kobject are the basic elements of the device model in the 2.6 kernel.
Here we only need to know that the existence of drivers and devices makes struct bus_type relate to the two linked lists, one is the devices linked list and the other is the drivers linked list. That is to say, if you know the data structure of a bus, you can find the device associated with the bus and the driver that supports such devices.
To achieve these goals, you must report or register a device to the bus every time it appears. Each time a driver appears, report it to the bus or register it. For example, during system initialization, the system scans the connected devices and creates a struct device variable for each device. each time there is a driver, a variable in the struct device_driver structure must be prepared. Add all these variables to the corresponding linked list, insert the device into the devices linked list, and insert the driver into the drivers linked list. In this way, each device and driver can be found through the bus.
However, if only the device has no corresponding driver in the computer, the device cannot work. In turn, if only the driver has no device, the driver will not play any role. There are more devices and more drivers. They are like two from the world, the devices warm each other, and the drivers get together, but one thing is the same, they are waiting for the other half of their own.