debugginglinux-kernelpci-e

Debugging PCIe Switch Configuration in Linux Kernel Code


I’m debugging PCIe enumeration and configuration on x86-64 with a PCIe switch between the RC and endpoints. I want to add printks in Linux kernel to observe CONFIG 0 and CONFIG 1 TLP handling.

Which kernel source files are responsible for triggering and processing these TLPs?

I’ve reviewed drivers/pci but need guidance on pinpointing the code paths. Any debugging tips or references to related documentation would be appreciated.


Solution

  • If I understood your question correctly:

    1. Kernel files: PCIe enum and config typically involve files in drivers/pci/ directory. Important files:

      • pci.c for core enumeration logic.
      • setup-bus.c for PCI bus setup.
      • access.c for configuration space access.
    2. TLP handling: AFAIK CONFIG 0 and CONFIG 1 TLPs relate to PCI config transactions, processed in arch-specific code: arch/x86/.

    3. And debugging:

      • Use printk() in related functions like pci_scan_bus() or pci_read_config_*.
      • Enable kernel debugging (CONFIG_DEBUG_KERNEL) and PCI debugging logs.

    Related docs: https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt , https://www.kernel.org/doc/html/v5.5/PCI/index.html