Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
linux中从用户空间访问pci设备信息_Linux_Linux Kernel_Pci E_Pci Bus - Fatal编程技术网

linux中从用户空间访问pci设备信息

linux中从用户空间访问pci设备信息,linux,linux-kernel,pci-e,pci-bus,Linux,Linux Kernel,Pci E,Pci Bus,我想通过编程方式从用户空间访问pci设备树信息。比如根复合体和连接到它的设备。我怎么做请告诉我 问候,, 从命令行尝试使用lspci-tv命令。 但据我所知,这个命令只是解析/proc。。。如果您需要从程序执行任务,可以查看lspci源代码。您可以通过浏览sysfs访问许多信息。还可以写入sysfs中的某些文件以执行某些命令,如PCI总线重新枚举;) 例如,列出所有PCI设备可以通过以下方式完成: paebbels@debian8:/sys/bus/pci/devices$ ll /sys/bu

我想通过编程方式从用户空间访问pci设备树信息。比如根复合体和连接到它的设备。我怎么做请告诉我

问候,,
从命令行尝试使用lspci-tv命令。
但据我所知,这个命令只是解析/proc。。。如果您需要从程序执行任务,可以查看lspci源代码。

您可以通过浏览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->平面PCI层次结构中的Debian

以下是设备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”

很好的浏览:)

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


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

 # which lspci
/usr/sbin/lspci
如果您是一个普通用户,您可能会得到如下结果:

 $ lspci
-bash: lspci: command not found
如果指定绝对文件路径(root执行的“which”的输出),您仍然可以使用它(从用户空间或程序):


我以为procfs已经过时了?是的,我听说过。可能是现代内核根本不使用prosf。但是流行的linux发行版中的内核仍然包含procfs。procfsapi中也有一些变化(例如,for entries create),但我还没有看到切割procfs的代码或linux内核。
 $ /usr/sbin/lspci