Device Driver basics 1: Bus, driver, and device of the device model

Source: Internet
Author: User

Kobject and kset are the basic structures of the device model. The device model uses these two structures to perform device hierarchies. However, in actual device driver writing, we basically cannot use kobject, the kset struct is embedded in a larger struct, because kobject and kset struct can only represent the hierarchical relationship between devices, but the driver of a device, it is not a simple hierarchical relationship. Therefore, you must embed the kobject and kset struct into a larger struct and use kobject and kset to characterize the hierarchy, use other members to indicate the specific features of the device driver.

In the device model, we can see that the device driver consists of three parts: Bus, driver, and device, to simplify the compilation of device drivers, that is, the device drivers we have compiled are actually only a small part of the three parts.

 

The device driver we wrote must first belong to a bus driver, such as a USB bus, a PCI bus, or an I2C bus. Because of the device driver we wrote, when registering and installing the driver to the system, the system first checks which bus the driver belongs to (the device driver was defined at the time of writing) and adds the driver to the kset of the corresponding bus, add the kobject driven by the current device to the kset of the corresponding bus to form a hierarchical association. When the system detects that a device exists (hardware), it first determines which bus the device belongs to (hardware connection) and then traverses all the device drivers under the current bus, by using the bus detection function, you can find whether the device driver matches the current device that can drive the device (generally by obtaining the PID, vid, PID, and vid of the device, if a driver can drive the device, add the current device to the kset of the bus. If no driver is available, it can only exist in the device linked list of the bus. If the devices cannot match through the bus, there is no way to exist in the device linked list of the bus. Because a bus needs to manage all drivers on the bus and all devices on the bus, you need to separate all devices from all drivers, A device kset and a device driver kset are set up to manage all devices and device drivers. In this way, the bus kset actually contains two ksets (device kset, device driver kset ), the device kset contains the kobject of all the devices of the current bus. The device-driven kset contains the kobject of the device-driven devices of all the current bus, the kset of the bus is formed, and the hierarchical relationship is formed as a result:

Each device is mounted to a different bus. when the device is mounted to the corresponding bus, the corresponding bus type is determined, when the device is mounted to the bus, the bus first needs to scan the device to see if the device is suitable for the bus requirements. If so, then it needs to scan the device driver Chain List on the entire bus, find out whether a driver can manage the device. If yes, point the corresponding pointer member in the device struct to the corresponding driver. If no corresponding device driver is found, the pointer to the driver in the device struct is empty, indicating that there is no device driver and it is still waiting in the device queue of the bus. If the device cannot pass the bus inspection, that is, it will not appear on the device list of the bus, and will not scan the device driver linked list to find the matching driver.

Each device driver is installed on the corresponding bus. Whether it is manual or automatic installation, the so-called installation means to mount the driver to the driver chain table of the corresponding bus, mounting to the corresponding bus driver linked list must first meet the bus matching requirements. Only when the requirements are met can the driver linked list be mounted to the bus, the system will scan the device linked list of the entire bus to find out whether there is a device that needs this driver to manage. If this device is found, the device management linked list in the driver will, the device address is recorded to manage the device.

After the above-mentioned device insertion or driver installation, the system will show only the device, but no device driver, it will also appear, only the device driver, if no corresponding device exists, the device or device driver will wait in the queue temporarily. Once a driver is installed or a new device is inserted, it will automatically scan the corresponding linked list to detect the possibility of pairing.

Based on the relationship between the above three,

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.