Linux内核如何发现PCI设备? [英] How does Linux kernel discover PCI devices?

查看:60
本文介绍了Linux内核如何发现PCI设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在驱动程序端,加载驱动程序模块时或在引导时(如果模块是内置的)调用 pci_register_driver().(无论何时添加设备/驱动程序,都会循环遍历驱动程序/设备列表以查找匹配项,我得到了这一部分.)

On the driver side, pci_register_driver() is called when a driver module is loaded, or at boot time if the module is built-in. (Whenever a device/driver is added, driver/device list is looped to find a match, I get that part.)

但是在哪里/什么时候在总线上发现并注册了pci设备?我想这是特定于架构的,并且会在x86上涉及BIOS,例如-BIOS例行探测PCI设备,然后将结果放在RAM中某个位置的列表中,然后再加载内核,并且每个列表项都包含单个pci的信息.然后包括内核的列表,然后将它们插入 pci_bus_type.p.klist_devices 中.但这纯粹是猜测,任何人都可以提供一些提示吗?

But where/when are pci devices discovered and registered with the bus? I imagine this is arch specific, and would involve BIOS on x86, such as - BIOS routine probe PCI devices and then put the results in a list some where in RAM, before loading the kernel, and each list entry contains information of a single pci device including vendorId/deviceId etc. Kernel then pick up the list and insert them into pci_bus_type.p.klist_devices at some point. But this is pure guess, can anyone give some hints?

推荐答案

实际上,不需要使用BIOS.

Actually, BIOS need not be involved.

PCI标准化了用于发现总线上设备的特定过程.热插拔控制器可以随时(不仅在启动时)触发此过程,甚至可以通过 /sys/bus/pci/rescan 手动触发此过程(请参阅

PCI standardizes a certain procedure for discovery of devices on the bus. This procedure can be triggered at any time (not exclusively on boot) by hotplug controller or even manually, via /sys/bus/pci/rescan (see pci_rescan_bus).

扫描将以递归方式进行,遍历发现的网桥,并从遇到的每个设备中读取配置空间数据(请参见 PCI配置空间).

The scan will proceed recursively, traversing the bridges as discovered and reading the configuration space data off each device encountered (see PCI configuration space).

对于找到的每个设备(如果尚未激活),内核将查找

For each device found, if not yet active, the kernel will look for an instance of pci_driver object with a matching pci_device_id. Then it will call the probe method of that object (the rest is driver implementation specific).

如果找不到合适的 pci_driver 实例,内核将向用户空间守护程序( udev hotpug 或其他)发出事件,可以加载适当的模块并创建必要的 pci_driver 对象.

If appropriate pci_driver instance is not found, kernel will emit an event to an user space daemon (udev or hotpug or whatever), which may load an appropriate module and create the necessary pci_driver object.

这篇关于Linux内核如何发现PCI设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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