3

I am trying to access a PCI BAR (#5) for a PCIe SATA bridge from userspace, but whenever I mmap() from the BAR via the /sys/bus/pci/devices/.../resource5, I get 0xFF at every offset in the file. Other devices such as an Intel SATA controller respond with sensible data.

The BAR is shown in lspci -vv just the same as for the Intel controller (only the address is different).

Region 5: Memory at f7b10000 (32-bit, non-prefetchable) [size=2K]

Both devices are are matched by the ahci driver, and the SATA controller works otherwise - I can access the attached disks.

I am trying to access from user space because I just want to poke at the registers experimentally for now. To do this, I am using a modified form of pcimem, changed to access the registers I care about. However, any offset returns 0xFF, so even with plain pcimem:

pcimem /sys/bus/pci/devices/0000\:01\:00.0/resource5 0 w

returns 0xFFFFFFFF ("w" indicates a "word" read, hence the 4 bytes).

What is it that is preventing the BAR5 for this device being accessible, when other devices are? Does it even make sense to make this kind of userspace access to PCI BARs?

Inductiveload
  • 6,094
  • 4
  • 29
  • 55

2 Answers2

2

Not certain how helpful this is going to be, but I saw the same thing when I was writing a driver for a new PCIe FPGA device.

The MMAP-ed PCI BAR memory space would return 0xFFFFFFFF (-1) when there was an error on the device. The only way I was able to resolve this was to reset the card by a full power reset of the computer.

Sean Madden
  • 1,069
  • 2
  • 10
  • 22
  • I was also thinking about a horrible device error, but the disks appear to be visible and can be mounted, so the bridge is working, I just can't read the BAR. I have rebooted several times, but same result each time. – Inductiveload Mar 21 '13 at 14:00
  • 1
    Then for that matter, it could just be an inactive BAR region that they exposed and never ended up using. – Sean Madden Mar 21 '13 at 15:18
  • But the registers for the hardware modules (for example the GPIO, I2C and SPI interfaces) I want to use are in BAR5. It is the only BAR which is a memory region, the size and number match what the datasheet advertises, and the datasheet lists dozens of registers which I'm supposed to be able to access to fiddle with the hardware. – Inductiveload Mar 21 '13 at 15:47
0

I've encountered the same issue debugging NVMe hdds hotplug. If before GRUB prompt there was a hdd in PCIe slot, you can hotplug other drives in that slot, and if not, pci_ioremap_bar() returns memory region reading all 0xffffffff. Strange shit.

an146
  • 23
  • 5