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

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

问题描述

在 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 设备驱动程序,它涵盖了驱动程序初始化的这部分.USB 将在第 13 章中介绍.

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.

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

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