Linux系统下PCIe总线、设备的枚举,资源的分配到底是哪里进行的?一直没搞太清楚,安装参考中的方法构建文件系统,编译内核,利用Qemu调试分析这个问题如下:
内核代码是5.15.0-107-generic, 工作环境是ubuntu 22.04 server OS。
Qemu虚拟机中的PCIe相关打印和对应函数如下
[ 1.510805] PCI host bridge to bus 0000:00 [ 1.511680] pci_bus 0000:00: root bus resource [bus 00-ff] [ 1.512317] pci_bus 0000:00: root bus resource [io 0x0000-0x0cf7 window] [ 1.512837] pci_bus 0000:00: root bus resource [io 0x0d00-0xffff window] [ 1.513208] pci_bus 0000:00: root bus resource [mem 0x000a0000-0x000bffff window] [ 1.513717] pci_bus 0000:00: root bus resource [mem 0x08000000-0xfebfffff window] [ 1.514096] pci_bus 0000:00: root bus resource [mem 0x100000000-0x17fffffff window] [ 1.517476] pci 0000:00:00.0: [8086:1237] type 00 class 0x060000 ###pci_setup_device函数中打印 [ 1.533713] pci 0000:00:01.0: [8086:7000] type 00 class 0x060100 [ 1.535804] pci 0000:00:01.1: [8086:7010] type 00 class 0x010180 [ 1.544586] pci 0000:00:01.1: reg 0x20: [io 0xc040-0xc04f] ###__pci_read_base函数中打印,这了打印了地址资源信息 [ 1.560891] pci 0000:00:01.1: legacy IDE quirk: reg 0x10: [io 0x01f0-0x01f7] [ 1.578515] pci 0000:00:01.1: legacy IDE quirk: reg 0x14: [io 0x03f6] [ 1.597623] pci 0000:00:01.1: legacy IDE quirk: reg 0x18: [io 0x0170-0x0177] [ 1.607952] pci 0000:00:01.1: legacy IDE quirk: reg 0x1c: [io 0x0376] [ 1.658439] pci 0000:00:01.3: [8086:7113] type 00 class 0x068000 [ 1.824434] pci 0000:00:01.3: quirk: [io 0x0600-0x063f] claimed by PIIX4 ACPI [ 1.832974] pci 0000:00:01.3: quirk: [io 0x0700-0x070f] claimed by PIIX4 SMB [ 1.833937] pci 0000:00:01.3: quirk_piix4_acpi+0x0/0x170 took 11718 usecs [ 1.893098] pci 0000:00:02.0: [1234:1111] type 00 class 0x030000 [ 1.934991] pci 0000:00:02.0: reg 0x10: [mem 0xfd000000-0xfdffffff pref] [ 1.972973] pci 0000:00:02.0: reg 0x18: [mem 0xfebb0000-0xfebb0fff] [ 2.034454] pci 0000:00:02.0: reg 0x30: [mem 0xfeba0000-0xfebaffff pref] [ 2.063609] pci 0000:00:02.0: Video device with shadowed ROM at [mem 0x000c0000-0x000dffff] [ 2.153403] pci 0000:00:03.0: [8086:100e] type 00 class 0x020000 [ 2.166942] pci 0000:00:03.0: reg 0x10: [mem 0xfeb80000-0xfeb9ffff] [ 2.197049] pci 0000:00:03.0: reg 0x14: [io 0xc000-0xc03f] [ 2.226955] pci 0000:00:03.0: reg 0x30: [mem 0xfeb00000-0xfeb7ffff pref] [ 2.360857] ACPI: PCI: Interrupt link LNKA configured for IRQ 10 [ 2.363395] ACPI: PCI: Interrupt link LNKB configured for IRQ 10 [ 2.365571] ACPI: PCI: Interrupt link LNKC configured for IRQ 11 [ 2.367503] ACPI: PCI: Interrupt link LNKD configured for IRQ 11 [ 2.368623] ACPI: PCI: Interrupt link LNKS configured for IRQ 9 [ 2.402194] iommu: Default domain type: Translated [ 2.402507] iommu: DMA domain TLB invalidation policy: lazy mode
调用栈如下,可见是内核扫描到设备的时候setup device的时候会read pci的config
具体细节需要分析__pci_read_base函数,通过gdb调测发现是函数__pci_read_base中下图所示的199行获取的,所以是内核从配置空间中读取的。那是谁在何时设置的呢?
BIOS配置的。
参考:
Linux Device Driver Part IV. PCI Device | tcbbd的博客
使用 GDB + Qemu 调试 Linux 内核 | Head First eBPF
PCI设备的初始化_pci resource start-CSDN博客
Linux系统总线之PCI扫描流程_linux pcie扫描过程-CSDN博客
Linux PCIe hotplug arch analysis | Sherlock's blog (wangzhou.github.io)
标签:00,0000,bus,reg,PCIe,pci,io,BAR,分配 From: https://www.cnblogs.com/River-blog/p/18248310