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
# Conflicts:
#	src/lib/hardware/pci.lua
  • Loading branch information
Alexander Gall authored and eugeneia committed Apr 19, 2022
1 parent 7c269fa commit 1c7497c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/lib/hardware/pci.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,20 @@ end

function map_pci_memory (f)
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)
end

Expand Down

0 comments on commit 1c7497c

Please sign in to comment.