如何在64位Linux内核环境中读取32位PCI内存 [英] How to read 32-bit PCI bar memory in 64-bit linux kernel environment
问题描述
我想在我的PCIe设备上进行I/O.我正在运行带有Linux内核4.4.0的Ubuntu 16.0.4 LTS
I want to do I/O on my PCIe device.I am running Ubuntu 16.0.4 LTS with linux kernel 4.4.0
lspci -v
命令的输出为:
06:00.0 Unclassified device [00ff]: Device 1aa1:2000 (rev 01)
Subsystem: Device 1aa1:2000
Physical Slot: 1-4
Flags: bus master, fast devsel, latency 0, IRQ 16
Memory at f1008000 (32-bit, non-prefetchable) [size=8K]
Memory at ee000000 (32-bit, non-prefetchable) [size=32M]
Memory at f100a000 (32-bit, non-prefetchable) [size=4K]
Memory at f0000000 (32-bit, non-prefetchable) [size=16M]
Memory at f1000000 (32-bit, non-prefetchable) [size=32K]
Capabilities: <access denied>
Kernel driver in use: my_pci
Kernel modules: my_pci
很显然,PCI地址是32位的.
Clearly, PCI addresses are 32-bit.
我想知道如何使用ioread32/iowrite32函数读取/写入BAR地址.我机器上的 unsigned char __iomem * mem
类型将是64位,如果我使用以下说法:
I want to know how to use ioread32/iowrite32 functions to read/write into the BAR addresses.
unsigned char __iomem *mem
types on my machine would be 64-bit and if I use the following say :
ioread32(mem + some_offset);
表达式 mem + some_offset
将是64位,并导致崩溃.
The expression mem + some_offset
would be 64-bit and result into crash.
我将如何执行I/O?
推荐答案
正在使用的PCI设备使用32位寻址模式.当您的PC枚举BAR并将物理地址写入BAR时.它写入一个掩码值,仅是64位的低32位(在主机地址空间中)在驱动程序上打印OS/BIOS分配给此BAR的物理地址并进行比较.
The PCI devices you're working with works using 32bit addressing mode. when your PC enumerates the BARs and writes the physical address onto the BAR. it writes a masked values, only the lower 32 bit of the 64 bit (in host address space) Print the physical address the OS/BIOS has assigned to this BAR on the driver and compare it.
此外,这是一个物理地址,因此您无论如何都不能对其进行 iowrite
.
besides, this is a physical address, so you can't iowrite
to it anyway.
所以我不太了解你的目标.
So I don't really understand your goal.
这篇关于如何在64位Linux内核环境中读取32位PCI内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!