C - How Does Linux Kernel Discover PCI Devices - Stack Overflow
C - How Does Linux Kernel Discover PCI Devices - Stack Overflow
Asked 4 years, 2 months ago Modified 4 years, 2 months ago Viewed 3k times
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.)
0
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?
Share Improve this question Follow edited Jan 17, 2020 at 2:10 asked Jan 16, 2020 at 3:21
QnA
1,073 12 30
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
7
hotplug controller or even manually, via /sys/bus/pci/rescan (see pci_rescan_bus).
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).
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.
Share Improve this answer Follow answered Jan 16, 2020 at 5:27
oakad
7,125 1 23 33
Actually BIOS affects the resulting resource management in Linux (and AFAIK in Windows) on x86. That said, OS does BIOS assisted PCI resource management.
– 0andriy Jan 21, 2020 at 21:06
Linux and PCI are used on many platforms, most of which have nothing resembling PC BIOS or ACPI altogether. :-) – oakad Jan 22, 2020 at 1:14
My point is your first sentence is incorrect for general answer – 0andriy Jan 22, 2020 at 7:31
BIOS need not be involved. Your root PCI bridge can be an USB device or sit on the other side of a network, for what PCI is concerned. Also, Intel x86 is not
synonymous with Intel PC (consider numerous embedded devices, HPC nodes and curious beasts like SGi Visual Workstation). – oakad Jan 22, 2020 at 8:14
1 If you are pretending to answer in general way, you need to cover many possibilities, one of which is BIOS assisted resource handling. – 0andriy Jan 22, 2020 at 8:40