How do PCI / PCIe devices get started / registered in Linux kernel?
When the kernel starts up, the PCI subsystem creates a PCI pci_bus
for each physical bus, then pci_bus
adds it to pci_root_buses
(with PCI configuration). But the PCI device driver registers the drivers with pci_register_driver
, and it adds the PCI driver to pci_bus_type
.
My questions:
- As
pci_bus_type
knows PCI configuration. - What is the relationship between
pci_bus_type
andpci_root_buses
.
source to share
Since the question is partially incomplete, but the comments are too small to provide an answer, I'll try to mix it up a bit.
So, the kernel is trying to distract the physical implementation of the PCI (e) bus from the driver developer. Hence, the PCI bus on NVidia Tegra is different from the PCI bus on Freescale ARM and PCI bus x86_64, but it should be possible to register devices against them regardless of the actual bus implementation.
The structure pci_root_buses
is a list of abstract PCI buses, where the implementation can be different.
This can be seen in the bus type structure, where function pointers are defined to allow each real bus to have a different implementation of how to handle the device. I think it is best if you read the PCI chapter in LDD3 and pay special attention to Boot Time .. p>
Also see Config Time to see how the kernel maps drivers to hardware. The rough idea of PCI is that the kernel can detect bus and card memory for each physical PCI device, which allows access to the PCI device's configuration space. The driver developer registers the device class, calling pci_register_driver
and therefore telling the kernel which driver to use for specific vendor IDs.
Looking at LDD3 again, it seems that the missing mapping you might be looking for is the probe function:
int (*probe) (struct pci_dev *dev, const struct pci_device_id *id);
Pointer to the probe function in the PCI driver. This function is called by the PCI kernel when it has struct pci_dev
which it thinks this driver wants to control. A pointer to struct pci_device_id
which PCI core used to make this decision is also passed to this function. If the PCI driver claims to be passed to it struct pci_dev
, it must properly initialize the device and return 0
. If the driver does not want to claim the device or an error occurs, it must return a negative error value. More information on this feature is provided later in this chapter.
Kernel data structures
Further reading
source to share