How to start a Linux bus driver with cainiao

Source: Internet
Author: User

I suddenly felt that the kernel driver I had learned for so long was not very deeply focused on the implementation of the kernel bus. After reading the source code of the kernel of the lowest version, we can finally clarify some clues. Now let's look back and add this part of knowledge.

Linux device models include bus, device, driver, and class ). The bus is the channel between the processor and the device. In the device model, all devices are connected through the bus. The device is a detailed description of a device, and the driver is the driver of the device. The basic relationship is as follows: Bus is equivalent to a container, which is the management mechanism of device and device_driver. It contains a collection of devices and a driver. The device set contains all the devices attached to the bus. These devices are linked through a linked list. The driver set contains all the drivers attached to the bus, these drivers are linked through a linked list.

The bus is the channel between the processor and one or more devices. In the device model, all devices are connected through the bus, or even the internal virtual "Platform" bus. You can see all the bus loaded by the system through LS-L/sys/bus. The bus can be inserted into each other. The device model shows the actual connection between the bus and the devices they control.

A class is a high-level view of a device. It abstracts the implementation details of the underlying layer, allowing the user space to use the features provided by the device without worrying about how the device connects and works. Class Members are generally controlled by the upper-Layer Code, without explicit support from the driver. However, in some cases, the driver also needs to directly process the class.

Almost all classes are displayed in the/sys/class directory and can be displayed through LS-L/sys/class. For historical reasons, the block device is displayed in the/sys/block directory. In many cases, the class subsystem is the best way to export information to a user space. When a class sub-system creates a class, it will have the class completely, and there is no need to worry about which module has those attributes, and the information representation is also friendly. For management, the driver core exports some interfaces. One of the purposes is to provide the attributes containing the device number so that the device node can be automatically created. Therefore, the use of udev is inseparable from the class.

For specific Linux device models, refer to the far-sighted concept of Hua Qing.

For example, the bus is I2C, and the device has an EEPROM I2C device. Also has its own driver. When the device and the driver name are the same and have been registered, the device will match. Then the driver can implement the functions of the device.

 

A good example is the concept of object-oriented.


This metaphor vividly shows the relationship between devices, bus, and classes in the Linux device model. Flowers belong to the category of flowers, and fruits belong to the category of fruits. The corresponding category of plum blossom is like a device. It is like data transmission in the bus.

Today's programs are all based on nature, and object-oriented is wonderful. The rigid process of orientation was so pale and powerless.

I understand some simple concepts in the Linux device model. Then you can start to look at the source code in depth. Fighting!

 

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.