linux - PCI 设备(64 位)配置内存访问

标签 linux linux-device-driver pci

我正在使用通过 PCI 连接的 64 位 FPGA。我正在使用下一个功能:

unsigned long pci_resource_[start|len|end|flags](struct pci_dev *pdev, int bar); 

但是,我没有得到正确的结果,因为这些函数是针对 32 位 PCI 设备的。

是否有其他功能适用于 64 位?你可以看到我从lspci得到的信息

0002:01:00.0 Memory controller: Xilinx Corporation Device 7022
    Subsystem: Xilinx Corporation Device 0007
    Flags: bus master, fast devsel, latency 0
    Memory at <ignored> (64-bit, prefetchable)
    Memory at c40000000 (64-bit, prefetchable) [size=64K]
    Capabilities: [40] Power Management version 3
    Capabilities: [48] MSI: Enable- Count=1/8 Maskable- 64bit+
    Capabilities: [60] Express Endpoint, MSI 00
    Capabilities: [100] Device Serial Number 00-00-00-00-00-00-00-00

最佳答案

我不确定你说的是哪个 Linux 版本。但是在当前的Linux树(4.5)中,pci_resource_start定义为:

#define pci_resource_start(dev, bar)    ((dev)->resource[(bar)].start)

嵌入结构是

/* Linux/include/linux/pci.h */
struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */

/* Linux/include/linux/ioport.h */
struct resource {
    resource_size_t start;
    resource_size_t end;
    const char *name;
    unsigned long flags;
    struct resource *parent, *sibling, *child;
};

/* Linux/include/linux/types.h */
typedef phys_addr_t resource_size_t;

/* Linux/include/linux/types.h */
#ifdef CONFIG_PHYS_ADDR_T_64BIT
typedef u64 phys_addr_t;
#else
typedef u32 phys_addr_t;
#endif

因此,如果您使用的是 64 位系统并且 Linux 是使用 CONFIG_PHYS_ADDR_T_64BIT 编译的,那么您就可以了。

关于linux - PCI 设备(64 位)配置内存访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36772838/

相关文章:

linux - *用于 Eclipse 的 nix Shell 编辑器

linux - 为什么没有适用于 Linux 的 DirectX API?

c++ - 在带有 openGL 和 SDL 的 Linux 上使用 C++ 时出现 SIGSEGV 错误

linux - gdb 回溯

linux - 索尼爱立信在连接到 USB 端口时注册两个设备

crash - Oracle Solaris 11.2 在引导时崩溃

Linux 内核 : invoke call back function in user space from kernel space

c - 使用 cat 读取字符设备驱动程序时参数无效

c - 如何在 Windows 中获取 PCI 区域大小?