Relationship between bus, device, and driver in inux

Source: Internet
Author: User
Relationship between bus, device, and driver in Linux

1. Bus:

As the connection channel between the host and peripherals, some buses are relatively standard and form many protocols. Such as PCI, USB, 1394, and IIC. Any device can select a suitable bus to connect to the host. Of course, the host may be the CPU itself. The memory is also connected to the host through the bus. The bus that can be used by the memory is not a peripheral bus. Therefore, the device that uses the same type of bus as the memory is vague about the bus.

An ENI is directly connected to the CPU through the memory bus in embedded development. When writing the NIC Driver, It is troublesome to define the bus.

2. DRIVER:

A driver is a software interface that provides operations when the CPU is running. All devices must have drivers to work properly. A driver can drive multiple similar or completely different devices.

3. device:

A device is a physical entity connected to the bus. Devices have different functions. Devices with the same features are classified into a class ). Such as audio equipment (sound-related), input equipment (mouse, keyboard, game pole, etc )....

From a macro perspective, any device must be connected to the host to play its role. When one mouse leaves the computer host, it is no longer a mouse. When it comes to connection, the bus will inevitably appear. Software support is required for the normal operation of any device, and driver is required for all devices. The purpose of a device is to complete the function. According to the function classification, the device must belong to a certain class.

1. The three are defined in include/Linux/device. h.

2. How are the two linked lists in the bus formed:

This requires that each time a device appears, it should be reported to the bus, or registered. Each time a driver appears, it should also be reported to the bus, or registered. For example, when the system is initialized, It scans which devices are connected and creates a variable of struct device for each device. Each time there is a driver, prepare a variable in the struct device_driver structure. Add all these variables to the corresponding linked list, insert device into the devices linked list, and insert driver into the drivers linked list. In this way, each device and driver can be found through the bus. However, if only the device in the computer has no corresponding driver, the device cannot work. In turn, if only the driver has no device, the driver will not play any role.

3. The two linked lists on the bus already exist. How are the device and driver in the linked list linked?

Each device to be used has been inserted before the computer starts. It is inserted to the location where it should be, and then the computer starts, the operating system starts initialization, and the bus starts scanning the device, each time a device is found, a struct device structure is applied for it and mounted to the devices linked list in the bus;

Then, each driver starts initialization and registers its struct device_driver structure. Then, it goes to the devices linked list of the bus to find (traverse) the device that has not bound the driver, that is, the struct device_driver pointer in the struct device is still null, and then it will observe the characteristics of the device to see if it is the device it supports. If yes, call a function called device_bind_driver. In other words
The device_driver driver points to this driver, while the struct device_driver adds the struct device to his struct klist klist_devices linked list. In this way, the bus, device, and driver, or the two of them, are connected.

4. Hot swapping:

The device can be inserted or pulled out after the computer is started. Therefore, it is difficult to say whether device or driver is available first. Because it is possible. The device can appear at any time, and the driver can be loaded at any time. Therefore, when a struct device is created, it will go to the drivers linked list of the bus to find its other half. On the contrary, whenever a struct device_driver is born, it will go to the devices linked list of the bus to find its devices. If a suitable one is found, then OK, call
Device_bind_driver is bound.

Relationship between bus, device, and driver in Linux

1. Bus:

As the connection channel between the host and peripherals, some buses are relatively standard and form many protocols. Such as PCI, USB, 1394, and IIC. Any device can select a suitable bus to connect to the host. Of course, the host may be the CPU itself. The memory is also connected to the host through the bus. The bus that can be used by the memory is not a peripheral bus. Therefore, the device that uses the same type of bus as the memory is vague about the bus.

An ENI is directly connected to the CPU through the memory bus in embedded development. When writing the NIC Driver, It is troublesome to define the bus.

2. DRIVER:

A driver is a software interface that provides operations when the CPU is running. All devices must have drivers to work properly. A driver can drive multiple similar or completely different devices.

3. device:

A device is a physical entity connected to the bus. Devices have different functions. Devices with the same features are classified into a class ). Such as audio equipment (sound-related), input equipment (mouse, keyboard, game pole, etc )....

From a macro perspective, any device must be connected to the host to play its role. When one mouse leaves the computer host, it is no longer a mouse. When it comes to connection, the bus will inevitably appear. Software support is required for the normal operation of any device, and driver is required for all devices. The purpose of a device is to complete the function. According to the function classification, the device must belong to a certain class.

1. The three are defined in include/Linux/device. h.

2. How are the two linked lists in the bus formed:

This requires that each time a device appears, it should be reported to the bus, or registered. Each time a driver appears, it should also be reported to the bus, or registered. For example, when the system is initialized, It scans which devices are connected and creates a variable of struct device for each device. Each time there is a driver, prepare a variable in the struct device_driver structure. Add all these variables to the corresponding linked list, insert device into the devices linked list, and insert driver into the drivers linked list. In this way, each device and driver can be found through the bus. However, if only the device in the computer has no corresponding driver, the device cannot work. In turn, if only the driver has no device, the driver will not play any role.

3. The two linked lists on the bus already exist. How are the device and driver in the linked list linked?

Each device to be used has been inserted before the computer starts. It is inserted to the location where it should be, and then the computer starts, the operating system starts initialization, and the bus starts scanning the device, each time a device is found, a struct device structure is applied for it and mounted to the devices linked list in the bus;

Then, each driver starts initialization and registers its struct device_driver structure. Then, it goes to the devices linked list of the bus to find (traverse) the device that has not bound the driver, that is, the struct device_driver pointer in the struct device is still null, and then it will observe the characteristics of the device to see if it is the device it supports. If yes, call a function called device_bind_driver. In other words
The device_driver driver points to this driver, while the struct device_driver adds the struct device to his struct klist klist_devices linked list. In this way, the bus, device, and driver, or the two of them, are connected.

4. Hot swapping:

The device can be inserted or pulled out after the computer is started. Therefore, it is difficult to say whether device or driver is available first. Because it is possible. The device can appear at any time, and the driver can be loaded at any time. Therefore, when a struct device is created, it will go to the drivers linked list of the bus to find its other half. On the contrary, whenever a struct device_driver is born, it will go to the devices linked list of the bus to find its devices. If a suitable one is found, then OK, call
Device_bind_driver is bound.

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.