What did driver_register do?

Source: Internet
Author: User

Now go to the driver_register () function. In driver_register (), the driver_find (DRV-> name, DRV-> Bus) function is called. What is this? Here is where the driver is going to be listed first. Check whether the driver has been listed (registered. Where can I find it? The code is clearly written. Go to bus> P> drivers_kset to find it. Here, I decided not to continue the detailed analysis here. Otherwise, the kernel will never be clear, sometimes you must understand the details. Sometimes you only need to understand the working principle of the details. To put it simply, drivers_kset is a klist linked list. All nodes in the chain list are kernel objects, that is, kobject. The kobject in kset can be of different "types" (different "type"). kset only puts a class of kobject that needs to be processed with the same processing. The driver_find function does not actually work. It calls the kset_find_obj function to traverse the chain table and search for it based on DRV-> name. I don't care about the process. If I find driver_find () returns the pointer to the registered driver. If no pointer is found, null is returned.
Return to driver_register (). If the driver has already been registered, exit. If the driver is not registered, call the bus_add_driver (struct device_driver * DRV) function to register the driver. This function is a little long and mainly used to put the DRV at the end of the DRV-> bus-> P-> klist_drivers linked list. The registration is now complete.
I read some veteran notes, read a little kernel code, read LDD, and I guess I have a little idea about the working mechanism of the driver.
The kernel maintains two linked lists, one for recording devices and the other for recording drivers. After the system is powered on, the bus will scan which devices are connected to the computer. Each device corresponds to a device object, and then the device object will be filled in the linked list of the recorded devices. Then the system continues to start, and enters the driver loading process, and fills in all the driver objects in the linked list of the drivers record. Each time a driver is loaded, traverse the devices linked list to see if there is any device that you want to serve. If there is a device, direct the driver pointer of the device object to itself, add the device object to the device linked list maintained by the driver. The device linked list records the device that the driver can serve. This is how the hardware is connected to the computer before the boot, but now it is more practical, that is, hot swapping.
Hot swapping means that no one in the device or driver enters the system first, because it is possible. So the working method is that once a device is inserted, the bus adds the corresponding device object to the linked list of the recorded devices and then searches for the record drivers linked list, see if there are any drivers that can drive the device. If there are drivers and Device objects pointing to each other, the driver can serve the device. What if no driver is found? It's easy. The device does not work. The device has to wait for the driver to be loaded and the driver will look for him. Conversely, the driver may be loaded before the device is inserted. Similarly, the driver does not find the device to be served on the linked list that records the devices, the driver has to wait for the device to be inserted.

Therefore, the previous thought of the driver_register () function calling DRV-> probe is wrong. It is just registration. Only when a device is inserted will DRV-> probe be called, it is used to insert a device and then operate the device, instead of a person in YY when no device is inserted.

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.