2

我想以编程方式从用户空间访问 pci 设备树信息。就像根复合体和连接到它的设备一样。我该怎么做,请告诉我。

问候, Pradeep

4

4 回答 4

4

libpci 或 pcilib(lspci 的基础)使用 sysfs、procfs 和可能的其他方式来访问 PCI 信息。您可以查看 pciutils 包源代码以供进一步参考:

https://github.com/gittup/pciutils

https://github.com/gittup/pciutils/blob/gittup/lspci.c

于 2014-12-12T09:52:21.383 回答
1

从命令行尝试使用 lspci -tv 命令。但据我了解,这个命令只是解析 /proc ......如果你需要从程序中完成你的任务,你可以看看 lspci 源代码。

于 2014-12-11T10:44:44.200 回答
1

您可以通过浏览 sysfs 访问许多信息。也可以写入 sysfs 中的某些文件以执行某些命令,例如 PCI 总线重新枚举;)

例如,列出所有 PCI 设备可以通过以下方式完成:

paebbels@debian8:/sys/bus/pci/devices$ ll /sys/bus/pci/devices
insgesamt 0
drwxr-xr-x 2 root root 0 Dez 12 00:33 .
drwxr-xr-x 5 root root 0 Dez 12 00:33 ..
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:00.0 -> ../../../devices/pci0000:00/0000:00:00.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:01.0 -> ../../../devices/pci0000:00/0000:00:01.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:07.0 -> ../../../devices/pci0000:00/0000:00:07.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:07.1 -> ../../../devices/pci0000:00/0000:00:07.1
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:07.3 -> ../../../devices/pci0000:00/0000:00:07.3
...
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:18.2 -> ../../../devices/pci0000:00/0000:00:18.2
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:18.3 -> ../../../devices/pci0000:00/0000:00:18.3
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:18.4 -> ../../../devices/pci0000:00/0000:00:18.4
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:18.5 -> ../../../devices/pci0000:00/0000:00:18.5
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:18.6 -> ../../../devices/pci0000:00/0000:00:18.6
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:00:18.7 -> ../../../devices/pci0000:00/0000:00:18.7
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:02:00.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:02:01.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:01.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:02:02.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:02.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:02:03.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:03.0
lrwxrwxrwx 1 root root 0 Dez 12 00:33 0000:03:00.0 -> ../../../devices/pci0000:00/0000:00:15.0/0000:03:00.0

注意:这是 VMWare 中的 Debian -> flat PCI hierachy。

以下是设备 0000:02:00.0 的示例:

paebbels@debian8:/sys/bus/pci/devices/0000:02:00.0$ ls -ahlL /sys/bus/pci/devices/0000\:02\:00.0
insgesamt 0
drwxr-xr-x 4 root root    0 Dez 12 00:37 .
drwxr-xr-x 8 root root    0 Dez 12 00:37 ..
-r--r--r-- 1 root root 4,0K Dez 12 00:37 acpi_index
-rw-r--r-- 1 root root 4,0K Dez 12 00:37 broken_parity_status
-r--r--r-- 1 root root 4,0K Dez 12 00:37 class
-rw-r--r-- 1 root root  256 Dez 12 00:37 config
-r--r--r-- 1 root root 4,0K Dez 12 00:37 consistent_dma_mask_bits
-rw-r--r-- 1 root root 4,0K Dez 12 00:37 d3cold_allowed
-r--r--r-- 1 root root 4,0K Dez 12 00:37 device
-r--r--r-- 1 root root 4,0K Dez 12 00:37 dma_mask_bits
drwxr-xr-x 2 root root    0 Dez  8 11:18 driver -> ../../../../bus/pci/drivers/uhci_hcd
-rw-r--r-- 1 root root 4,0K Dez 12 00:37 driver_override
-rw-r--r-- 1 root root 4,0K Dez 12 00:37 enabled
drwxr-xr-x 3 root root    0 Dez 12 00:37 firmware_node -> ../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/device:05/device:06
-r--r--r-- 1 root root 4,0K Dez 12 00:37 irq
-r--r--r-- 1 root root 4,0K Dez 12 00:37 label
-r--r--r-- 1 root root 4,0K Dez 12 00:37 local_cpulist
-r--r--r-- 1 root root 4,0K Dez 12 00:37 local_cpus
-r--r--r-- 1 root root 4,0K Dez 12 00:37 modalias
-rw-r--r-- 1 root root 4,0K Dez 12 00:37 msi_bus
-r--r--r-- 1 root root 4,0K Dez 12 00:37 numa_node
-r--r--r-- 1 root root 4,0K Dez 12 00:37 pools
drwxr-xr-x 2 root root    0 Dez 12 00:37 power
--w--w---- 1 root root 4,0K Dez 12 00:37 remove
--w--w---- 1 root root 4,0K Dez 12 00:37 rescan
--w------- 1 root root 4,0K Dez 12 00:37 reset
-r--r--r-- 1 root root 4,0K Dez 12 00:37 resource
-rw------- 1 root root   32 Dez 12 00:37 resource4
drwxr-xr-x 5 root root    0 Dez 12 00:33 subsystem -> ../../../../bus/pci
-r--r--r-- 1 root root 4,0K Dez 12 00:37 subsystem_device
-r--r--r-- 1 root root 4,0K Dez 12 00:37 subsystem_vendor
-rw-r--r-- 1 root root 4,0K Dez 12 00:37 uevent
drwxr-xr-x 5 root root    0 Dez 12 00:37 usb4
-r--r--r-- 1 root root 4,0K Dez 12 00:37 vendor

您可以看到设备 0000:02:00.0 使用驱动程序“uhci_hcd”。

不错的浏览:)

于 2014-12-11T23:45:11.117 回答
0

如果安装了 pciutils,超级用户使用“lspci”。

 # which lspci
/usr/sbin/lspci

如果您是普通用户,您可能会得到如下信息:

 $ lspci
-bash: lspci: command not found

如果您指定绝对文件路径(由 root 执行的 'which' 的输出),您仍然可以使用它(从用户空间或程序):

 $ /usr/sbin/lspci
于 2018-07-01T21:10:54.373 回答