Read Documentation/IO-mapping.txt (search for "iomap") and/or Chapter 15 of LDD3.
request_mem_region
just ensures no other driver has already grabbed that memory region. You still need to map it into the kernel's VM space using iomap
before you can read/write it.
Note that the whole pci_resource_start
etc. dance is somewhat deprecated. I believe the recommended approach these days is:
pci_request_regions(pdev, "myname"); /* to request regions for all BARs */
Then:
void __iomem *base = pci_iomap(pdev, 0, pci_resources_len(pdev,0)); /* to map BAR 0 */
Then:
ioread32(base + offset); /* Or readl(base + offset), but this is more generic */
And finally, at the end:
pci_iounmap(pdev, base); /* Release kernel VM mapping (undoes pci_iomap) */
pci_release_regions(pdev); /* Release all regions (undoes pci_request_regions) */
You can do the first two manually by combining pci_resource_start
, pci_resource_len
, request_mem_region
, and iomap
. But the above is (a) shorter and (b) generic between memory-mapped devices and those that use the old x86 I/O space. (Not that there are a whole lot of those around anymore.)