【问题标题】:Implementing PCIe Linux device driver (want to access my card registers from kernel driver)实现 PCIe Linux 设备驱动(想从内核驱动访问我的卡寄存器)
【发布时间】:2011-03-03 19:18:37
【问题描述】:

我正在编写一个设备驱动程序来访问 PCIe 卡上 FPGA 中的内存。
卡启动并被探测/找到:-

/proc/iomem

80000000-840fffff : PCI Bus #03
  80000000-83ffffff : 0000:03:00.0
  84000000-840fffff : 0000:03:00.0

所以阅读 ldd/etc 我在80000000 编写了对request_mem_region 的调用,并通过ioremap_nocache 请求指向它的指针

1) 我需要request_mem_regionioremap_nocache,我不能只使用后者吗?

/proc/iomem 在insmod 我的设备驱动程序之后:-

80000000-840fffff : PCI Bus #03
  80000000-83ffffff : 0000:03:00.0
    80000000-8003ffff : fp2
  84000000-840fffff : 0000:03:00.0

2) 我觉得不太对劲...?

无论如何,读取不起作用(它没有像下面那样编码,它有检查等):-

#define BAR_ADDR 0x80000000
void *base = ioremap_nocache(BAR_ADDR, 0x40000);
void *address = base + KNOWN_REG_LOCATION;
int data = ioread32(address);
printk("fp2: address:0x%08x, data:0x%08x\n", address, data);

输出:-

address:0xfd500000, data:0xffffffff

我可以从 mmap 用户空间读取x80000000+KNOWN_REG_LOCATION

3) 我试过__raw_readl/readl 也没有运气。

4) 我可以在当前映射的地址x80000000处读取吗?

【问题讨论】:

  • 您的 .tar 文件需要密码。审查代码会很有帮助。
  • 我认为你的评论应该指向@willtake

标签: linux-kernel pci


【解决方案1】:

伊恩,

我为设备 (full source) 编写了一个 PCI 驱动程序。寄存器空间的映射应该是一样的。这是我的做法。

dm7820_device->pci[region].virt_addr = ioremap_nocache(address, length);
if (dm7820_device->pci[region].virt_addr == NULL) {
    printk(KERN_ERR "%s: ERROR: BAR%u remapping FAILED\n",
        &((dm7820_device->device_name)[0]), region);
    dm7820_release_resources();
    return -ENOMEM;
}

if (request_mem_region(address, length, &((dm7820_device->device_name)[0])) == NULL) {
    printk(KERN_ERR "%s: ERROR: I/O memory range %#lx-%#lx allocation FAILED\n",
        &((dm7820_device->device_name)[0]), address, (address + length - 1));
    dm7820_release_resources();
    return -EBUSY;
}

地址和长度值从pci_resource_start()pci_resource_length() 调用返回。

然后您可以使用ioread32() 使用dm7820_device->pci[region].virt_addr + <register offset> 访问它

如果您有任何问题,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-28
    • 2012-03-12
    • 1970-01-01
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2019-11-19
    相关资源
    最近更新 更多