epics-modules / devlib2

Helper library for memory mapped bus access
http://epics-modules.github.io/devlib2/
Other
4 stars 8 forks source link

Fix pci map failure #4

Closed dirk-zimoch closed 5 years ago

dirk-zimoch commented 5 years ago

This fixes the case that mapping a pci BAR resource file fails for any other reason than permissions on the resource file. One example is that mmap fails even though opening the resource file was successful. This can happen in newer kernel versions when a kernel driver (including uio) uses the device. In that case try to map the BAR through uio like it would have happened if already opening the resource file had failed.

Also avoid mapping the same BAR twice. Instead re-use the existing map.

mdavidsaver commented 5 years ago

So I played the role of stupid user and tried to re-run the mmap() after it failed. The 0xffffffffffffffff is MAP_FAILED. The fix is to reset to NULL when mmap() fails (eee80e0f9f6e26945f577e885cdd7509940c3cb7).

epics> pcidiagset 0 4
Looking for 0:4.0
Mapping 0:4.0
Can neither mmap resource file nor uio file of PCI device 0000:00:04.0 BAR 0
Failed to map BAR
epics> pcidiagset 0 4
Looking for 0:4.0
Mapping 0:4.0
BAR 0 from 0xffffffffffffffff for 262144 bytes
mdavidsaver commented 5 years ago

I don't immediately see why the R3.14.12.2 travis job is failing. However, it isn't due to this change.