-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed9d71a
commit 59ba7b0
Showing
13 changed files
with
609 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
--- ### Select bus driver between classic PCI and VFIO | ||
module(...,package.seeall) | ||
|
||
local ffi = require('ffi') | ||
local C = ffi.C | ||
|
||
local lib = require('core.lib') | ||
local pci = require('lib.hardware.pci') | ||
local vfio = require('lib.hardware.vfio') | ||
local memory = require("core.memory") | ||
|
||
|
||
|
||
devices = {} | ||
map_devices = {} | ||
|
||
function scan_devices () | ||
for _,device in ipairs(lib.files_in_directory("/sys/bus/pci/devices")) do | ||
local info = device_info(device) | ||
if info.driver and not map_devices[device] then | ||
table.insert(devices, info) | ||
map_devices[device] = info | ||
end | ||
end | ||
end | ||
|
||
function host_has_vfio() | ||
local files = lib.files_in_directory('/sys/kernel/iommu_groups/') | ||
return files and #files > 0 | ||
end | ||
|
||
|
||
function device_in_vfio(devicepath) | ||
local iommu_group = lib.basename(lib.readlink(devicepath..'/iommu_group')) | ||
if not iommu_group then return false end | ||
local drivername = lib.basename(lib.readlink(devicepath..'/driver')) | ||
return drivername == 'vfio-pci' | ||
end | ||
|
||
|
||
function device_info(pciaddress) | ||
if map_devices[pciaddress] then | ||
return map_devices[pciaddress] | ||
end | ||
|
||
local pcidevpath = pci.path(pciaddress) | ||
if device_in_vfio(pcidevpath) then | ||
info = vfio.device_info(pciaddress) | ||
info.bus = 'vfio' | ||
info.device_info = vfio.device_info | ||
info.map_pci_memory = vfio.map_pci_memory | ||
info.set_bus_master = vfio.set_bus_master | ||
info.dma_alloc = memory.dma_alloc | ||
else | ||
info = pci.device_info(pciaddress) | ||
info.bus = 'pci' | ||
info.device_info = pci.device_info | ||
info.map_pci_memory = pci.map_pci_memory | ||
info.set_bus_master = pci.set_bus_master | ||
info.dma_alloc = memory.dma_alloc | ||
end | ||
return info | ||
end | ||
|
||
function map_pci_memory(pciaddress, n) | ||
return map_devices[pciaddress].map_pci_memory(pciaddress, n) | ||
end | ||
|
||
function set_bus_master(pciaddress, enable) | ||
return map_devices[pciaddress].set_bus_master(pciaddress, enable) | ||
end | ||
|
||
function selftest () | ||
print("selftest: bus") | ||
scan_devices() | ||
for _,info in ipairs(devices) do | ||
print (string.format("device %s: %s", info.pciaddress, info.bus)) | ||
end | ||
end | ||
|
||
if host_has_vfio() then | ||
memory.ram_to_io_addr = vfio.set_mapping(memory.huge_page_size) | ||
else | ||
memory.set_use_physical_memory() | ||
end | ||
memory.set_default_allocator(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.