为什么除了init之外,Linux设备驱动程序中还需要探测方法? [英] Why is the probe method needed in Linux device drivers in addition to init?

查看:103
本文介绍了为什么除了init之外,Linux设备驱动程序中还需要探测方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux内核中,驱动程序提供的probe()方法有什么作用?它与驱动程序的init函数有何不同,即为什么不能在驱动程序的init函数中执行probe()函数?

In the linux kernel, what does the probe() method, that the driver provides, do? How different is it from the driver's init function, i.e. why can't the probe() functions actions be performed in the driver's init function ?

推荐答案

不同的设备类型可以具有probe()函数.例如,PCI和USB设备都具有probe()函数.

Different device types can have probe() functions. For example, PCI and USB devices both have probe() functions.

如果您正在谈论PCI设备,我建议您阅读 Linux设备驱动程序,涵盖了驱动程序初始化的这一部分.第13章介绍了USB.

If you're talking about PCI devices, I would recommend you read chapter 12 of Linux Device Drivers, which covers this part of driver initialization. USB is covered in chapter 13.

假设PCI,则答案更短:驱动程序的init函数调用pci_register_driver(),该函数为内核提供了其可以服务的设备列表以及指向probe()函数的指针.然后,内核为每个设备调用一次驱动程序的probe()函数.

Shorter answer, assuming PCI: The driver's init function calls pci_register_driver() which gives the kernel a list of devices it is able to service, along with a pointer to the probe() function. The kernel then calls the driver's probe() function once for each device.

此探测功能启动每个设备的初始化:初始化硬件,分配资源,并将该设备作为块或网络设备或任何其他形式注册到内核.

This probe function starts the per-device initialization: initializing hardware, allocating resources, and registering the device with the kernel as a block or network device or whatever it is.

这使设备驱动程序更容易,因为它们无需搜索设备或担心寻找热插拔的设备.内核会处理该部分,并在有设备供您处理时通知正确的驱动程序.

That makes it easier for device drivers, because they never need to search for devices or worry about finding a device that was hot-plugged. The kernel handles that part and notifies the right driver when it has a device for you to handle.

这篇关于为什么除了init之外,Linux设备驱动程序中还需要探测方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆