mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-09 06:15:19 +00:00
vfio: Add a public function to retrive VFIO container
The VFIO container is the object needed to update the VFIO mapping associated with a VFIO device. This patch allows the device manager to have access to the VFIO container. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
34bb31791b
commit
3598e603d5
@ -103,7 +103,7 @@ struct vfio_region_info_with_cap {
|
|||||||
cap_info: __IncompleteArrayField<u8>,
|
cap_info: __IncompleteArrayField<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VfioContainer {
|
pub struct VfioContainer {
|
||||||
container: File,
|
container: File,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ impl VfioContainer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vfio_dma_map(&self, iova: u64, size: u64, user_addr: u64) -> Result<()> {
|
pub fn vfio_dma_map(&self, iova: u64, size: u64, user_addr: u64) -> Result<()> {
|
||||||
let dma_map = vfio_iommu_type1_dma_map {
|
let dma_map = vfio_iommu_type1_dma_map {
|
||||||
argsz: mem::size_of::<vfio_iommu_type1_dma_map>() as u32,
|
argsz: mem::size_of::<vfio_iommu_type1_dma_map>() as u32,
|
||||||
flags: VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
|
flags: VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE,
|
||||||
@ -170,7 +170,7 @@ impl VfioContainer {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vfio_dma_unmap(&self, iova: u64, size: u64) -> Result<()> {
|
pub fn vfio_dma_unmap(&self, iova: u64, size: u64) -> Result<()> {
|
||||||
let mut dma_unmap = vfio_iommu_type1_dma_unmap {
|
let mut dma_unmap = vfio_iommu_type1_dma_unmap {
|
||||||
argsz: mem::size_of::<vfio_iommu_type1_dma_unmap>() as u32,
|
argsz: mem::size_of::<vfio_iommu_type1_dma_unmap>() as u32,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
@ -198,7 +198,7 @@ impl AsRawFd for VfioContainer {
|
|||||||
struct VfioGroup {
|
struct VfioGroup {
|
||||||
group: File,
|
group: File,
|
||||||
device: Arc<DeviceFd>,
|
device: Arc<DeviceFd>,
|
||||||
container: VfioContainer,
|
container: Arc<VfioContainer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VfioGroup {
|
impl VfioGroup {
|
||||||
@ -225,7 +225,7 @@ impl VfioGroup {
|
|||||||
return Err(VfioError::GroupViable);
|
return Err(VfioError::GroupViable);
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = VfioContainer::new()?;
|
let container = Arc::new(VfioContainer::new()?);
|
||||||
if container.get_api_version() as u32 != VFIO_API_VERSION {
|
if container.get_api_version() as u32 != VFIO_API_VERSION {
|
||||||
return Err(VfioError::VfioApiVersion);
|
return Err(VfioError::VfioApiVersion);
|
||||||
}
|
}
|
||||||
@ -762,6 +762,10 @@ impl VfioDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_container(&self) -> Arc<VfioContainer> {
|
||||||
|
self.group.container.clone()
|
||||||
|
}
|
||||||
|
|
||||||
fn vfio_dma_map(&self, iova: u64, size: u64, user_addr: u64) -> Result<()> {
|
fn vfio_dma_map(&self, iova: u64, size: u64, user_addr: u64) -> Result<()> {
|
||||||
self.group.container.vfio_dma_map(iova, size, user_addr)
|
self.group.container.vfio_dma_map(iova, size, user_addr)
|
||||||
}
|
}
|
||||||
|
@ -1006,6 +1006,8 @@ impl DeviceManager {
|
|||||||
VfioDevice::new(&device_cfg.path, device_fd.clone(), vm_info.memory.clone())
|
VfioDevice::new(&device_cfg.path, device_fd.clone(), vm_info.memory.clone())
|
||||||
.map_err(DeviceManagerError::VfioCreate)?;
|
.map_err(DeviceManagerError::VfioCreate)?;
|
||||||
|
|
||||||
|
let _vfio_container = vfio_device.get_container();
|
||||||
|
|
||||||
let mut vfio_pci_device = VfioPciDevice::new(vm_info.vm_fd, allocator, vfio_device)
|
let mut vfio_pci_device = VfioPciDevice::new(vm_info.vm_fd, allocator, vfio_device)
|
||||||
.map_err(DeviceManagerError::VfioPciCreate)?;
|
.map_err(DeviceManagerError::VfioPciCreate)?;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user