简体   繁体   English

通过/ dev / mem与PCI设备通信

[英]communicating with a PCI device through /dev/mem

I'm need to communicate with a memory PCI device through /dev/mem . 我需要通过/dev/mem与内存PCI设备进行通信。 Why? 为什么? There are many reasons, one of which is because my boss told me so. 原因有很多,其中之一是因为我的老板告诉过我。

I think I have my answer here . 我想我在这里有答案。 What I can't figure out however is the MMIO_ADDR in the answer. 我不知道的是答案中的MMIO_ADDR If I want to communicate with a specific memory region, would I use a value stored in a BAR register as my MMIO_ADDR ? 如果我想与特定的内存区域通信,是否可以将BAR寄存器中存储的值用作MMIO_ADDR If no then how do I communicate with my PCI device? 如果没有,我该如何与我的PCI设备通信?

Your BAR will have been assigned an address by the BIOS/kernel. BIOS /内核将为您的BAR分配一个地址。 That address should have been written into the BAR address registers in the PCI configuration header by the time the system is up. 在系统启动时,该地址应该已经写入PCI配置标头中的BAR地址寄存器中。

For example, on a VM I have here, the e1000 device is as follows (from lspci -v ): 例如,在我拥有的VM上,e1000设备如下(来自lspci -v ):

02:03.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
        Subsystem: VMware PRO/1000 MT Single Port Adapter
        Physical Slot: 35
        Flags: bus master, 66MHz, medium devsel, latency 0, IRQ 17
   =>   Memory at fd560000 (64-bit, non-prefetchable) [size=128K]
        Memory at fdfd0000 (64-bit, non-prefetchable) [size=64K]
        I/O ports at 2080 [size=64]
        [virtual] Expansion ROM at fd520000 [disabled] [size=64K]
        Capabilities: <access denied>
        Kernel driver in use: e1000

You'll need to read that info (you can reach it in binary form via /proc/bus/pci/<Bus>/<DevFn> or via /sys/bus/pci/devices/ ) to find the MMIO address. 您需要阅读该信息(可以通过/proc/bus/pci/<Bus>/<DevFn>或通过/sys/bus/pci/devices/以二进制形式获取该信息)以找到MMIO地址。

For example, dumping the binary of the PCI configuration space for the device above shows: 例如,转储上述设备的PCI配置空间的二进制文件显示:

od -tx1z -Ax /proc/bus/pci/02/03.0
000000 86 80 0f 10 17 01 30 02 01 00 00 02 10 00 00 00  >......0.........<
000010 04 00 56 fd 00 00 00 00 04 00 fd fd 00 00 00 00  >..V.............<
000020 81 20 00 00 00 00 00 00 00 00 00 00 ad 15 50 07  >. ............P.<
000030 00 00 00 00 dc 00 00 00 00 00 00 00 0b 01 ff 00  >................<
000040

The first BAR (bar region #0) is at offset 0x10, the second (bar region #2) is at offset 0x18. 第一个BAR(条形区域#0)的偏移量为0x10,第二个BAR形条形区域#2的偏移量为0x18。

See https://en.wikipedia.org/wiki/PCI_configuration_space for description of the layout and interpretation. 有关布局和解释的说明,请参见https://en.wikipedia.org/wiki/PCI_configuration_space

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM