Implementing PCIe Linux device driver (want to access my card registers from kernel driver)

无人久伴 提交于 2019-11-30 05:29:33

Ian,

I wrote a PCI driver for a device (full source). The mapping of the register space should be the same though. Here is how I do it.

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;
}

The address and length values are returned from pci_resource_start() and pci_resource_length() calls.

Then you can access it using ioread32() using dm7820_device->pci[region].virt_addr + <register offset>

Let me know if you have any questions.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!