Skip to content

Commit

Permalink
lib.hardware.pci.map_pci_memory: only wait if first call failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Gall committed May 4, 2020
1 parent da76c64 commit 5f05dab
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib/hardware/pci.lua
Expand Up @@ -176,17 +176,20 @@ function map_pci_memory (device, n, lock)
assert(f:flock("ex, nb"), "failed to lock " .. filepath)
end
local st = assert(f:stat())
local mem
local mem, err
mem, err = f:mmap(nil, st.size, "read, write", "shared", 0)
-- mmap() returns EINVAL on Linux >= 4.5 if the device is still
-- claimed by the kernel driver. We assume that
-- unbind_device_from_linux() has already been called but it may take
-- some time for the driver to release the device.
lib.waitfor2("mmap of "..filepath,
function ()
mem, err = f:mmap(nil, st.size, "read, write", "shared", 0)
assert(not err or err.INVAL)
return mem
end, 5, 1000000)
if not mem then
lib.waitfor2("mmap of "..filepath,
function ()
mem, err = f:mmap(nil, st.size, "read, write", "shared", 0)
assert(not err or err.INVAL)
return mem
end, 5, 1000000)
end
return ffi.cast("uint32_t *", mem), f
end

Expand Down

0 comments on commit 5f05dab

Please sign in to comment.