linux里面访问pci设备,从用户空间在Linux中访问pci设备信息

您可以通过浏览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->扁平PCI层次结构。

这是设备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'。

尼斯浏览:)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值