Do I need to enable a PCIe memory region in a Linux 3.12 driver?
You definitely have to enable it. These are the basic steps:
pci_enable_device(dev);
pci_request_regions(dev, "driver/device name");
bar0 = pci_iomap(dev, 0, 0);
x = ioread(bar0 + offset); /* there you are */
Error checking is required for all the pci_*
calls. If the device needs to do DMA you also need to call pci_set_master
and pci_set_dma_mask
.
To elaborate, bypassing the PCI kernel code and directly ioremapping the BARs may have worked a long time ago. I'm not sure if it is even legal anymore in current code but it certainly isn't advisable.
Implementing PCIe Linux device driver (want to access my card registers from kernel driver)
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.
Linux PCIe Driver: What to use for private data structure?
That function is used for associating with the device private data that cannot be supplied any other way. If there is no such data then the function should simply not be used.
Related Topics
Graphing The Dag Generated by Make
Git: Can't Push (Strange Config Issue)
Apache Cgi in User Directory "End of Script Output Before Headers"
How to Take Advantage of The Vdso Object with Your Own Programming Language
How to Execute Shell Builtin from Scala
How to Add an Icon to The Bash Prompt
Receiving Multicast on a Server with Multiple Interfaces (Linux)
List Directory Entries in The Svn Repository
Getting Android Sdk Tools to Work on Raspberry Pi
Linux: Disable Using Loopback and Send Data via Wire Between 2 Eth Cards of One Comp
Vs Code Ssh Remote Connection Issues
Understanding /Boot/Config File
Reusing Custom Makefile for Static Library with Cmake
Linux Desktop Shortcut and Icon from Install
Read Serial Data Without High CPU Use