4

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

/proc/iomem

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

因此,阅读 ldd/etc 我编写了对request_mem_regionat 的调用80000000,并通过请求指向它的指针ioremap_nocache

1)我是否需要request_mem_region以及ioremap_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

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

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

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

4

1 回答 1

6

伊恩,

我为设备编写了一个 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>

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

于 2011-03-04T14:32:05.890 回答