如何在 Linux 中读取扩展的 PCIE 配置空间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6341540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:30:50  来源:igfitidea点击:

How to read extended PCIE configuration space in Linux?

linuxlinux-kernellinux-device-driverpci

提问by OliveU

I've tried both reading userspace pci entry under /proc/bus/pci directory and calling kernel space API pci_read_config_word() in the driver. but it seems both can only read pci basic configuration space, offset less than 0x100.

我已经尝试在 /proc/bus/pci 目录下读取用户空间 pci 条目并在驱动程序中调用内核空间 API pci_read_config_word() 。但似乎两者都只能读取 pci 基本配置空间,偏移量小于 0x100。

The offset I want to read is beyond 0x100, could anyone tell me how to do it in Linux? if done in kernel space, telling which API to call would be very appreciated. Thank you very much!

我想读取的偏移量超过 0x100,谁能告诉我如何在 Linux 中做到这一点?如果在内核空间中完成,告诉调用哪个 API 将不胜感激。非常感谢!

采纳答案by Roland

pci_read_config_word()is the correct API, but to access extended configuration space you need to use MMCONFIG. This is not something you set up; the kernel should choose to use MMCONFIG by itself if available. Do you see anything like

pci_read_config_word()是正确的 API,但要访问扩展配置空间,您需要使用 MMCONFIG。这不是你设置的;如果可用,内核应该选择自己使用 MMCONFIG。你看到什么像

e0000000-efffffff : PCI MMCONFIG 0000 [bus 00-ff]

in /proc/iomem? Also in your kernel log, you should see some lines about the ACPI MCFG table and MMCONFIG:

/proc/iomem?同样在您的内核日志中,您应该看到一些关于 ACPI MCFG 表和 MMCONFIG 的行:

ACPI: MCFG 00000000bb7fec63 0003C (v01 LENOVO TP-6U    00001410 LNVO 00000001)
...
PCI: MMCONFIG for domain 0000 [bus 00-ff] at [mem 0xe0000000-0xefffffff] (base 0xe0000000)

and of course your kernel needs to be built with CONFIG_PCI_MMCONFIG=y.

当然,您的内核需要使用CONFIG_PCI_MMCONFIG=y.