Skip to content

Commit

Permalink
Merge PR #1476 (map_pci_memory: workaround) into max-next
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Jun 22, 2022
2 parents 36f44d7 + 6dd5418 commit d15b45f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/hardware/pci.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,19 @@ end

function map_pci_memory (f)
local st = assert(f:stat())
local mem = assert(f:mmap(nil, st.size, "read, write", "shared", 0))
local 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.
if not mem and err.INVAL then
lib.waitfor2("mmap of "..filepath,
function ()
mem, err = f:mmap(nil, st.size, "read, write", "shared", 0)
return mem ~= nil or not err.INVAL
end, 5, 1000000)
end
assert(mem, err)
return ffi.cast("uint32_t *", mem)
end

Expand Down

0 comments on commit d15b45f

Please sign in to comment.