vfio.rs0.00%
1
// Copyright 2024 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
pub mod cdev;16
pub mod container;17
pub mod device;18
pub mod group;19
pub mod iommu;20
pub mod pci;21
22
use std::path::Path;23
24
use serde::Deserialize;25
use serde_aco::Help;26
use snafu::Snafu;27
28
use crate::errors::{DebugTrace, trace_error};29
use crate::sys::vfio::VfioIommu;30
31
#[trace_error]32
#[derive(Snafu, DebugTrace)]33
#[snafu(module, context(suffix(false)))]34
pub enum Error {35
#[snafu(display("Hypervisor internal error"), context(false))]36
HvError { source: Box<crate::hv::Error> },37
#[snafu(display("Failed to access guest memory"), context(false))]38
Memory { source: Box<crate::mem::Error> },39
#[snafu(display("Error from OS"), context(false))]40
System { error: std::io::Error },41
#[snafu(display("Cannot access device {path:?}"))]42
AccessDevice {43
path: Box<Path>,44
error: std::io::Error,45
},46
#[snafu(display("Not supported PCI header type {ty:#x}"))]47
NotSupportedHeader { ty: u8 },48
#[snafu(display("Setting container iommu to {new:?}, but it already has {current:?}"))]49
SetContainerIommu { current: VfioIommu, new: VfioIommu },50
}51
52
pub type Result<T, E = Error> = std::result::Result<T, E>;53
54
#[derive(Debug, PartialEq, Eq, Deserialize, Help)]55
pub struct CdevParam {56
/// Path to a VFIO cdev, e.g. /dev/vfio/devices/vfio0.57
pub path: Box<Path>,58
/// Name of the IO Address space to which this device should be attached.59
pub ioas: Option<Box<str>>,60
}61
62
#[derive(Debug, PartialEq, Eq, Deserialize, Help)]63
pub struct IoasParam {64
/// Name of the IO Address space.65
pub name: Box<str>,66
/// Path to the iommu device. [default: /dev/iommu]67
pub dev_iommu: Option<Box<Path>>,68
}69
70
#[derive(Debug, PartialEq, Eq, Deserialize, Help)]71
pub struct GroupParam {72
/// Path to a VFIO group file, e.g. /dev/vfio/12.73
pub path: Box<Path>,74
/// Device ID, e.g. 0000:06:0d.0.75
#[serde(default)]76
pub devices: Vec<Box<str>>,77
/// Name of the container to which this device should be attached.78
pub container: Option<Box<str>>,79
}80
81
#[derive(Debug, PartialEq, Eq, Deserialize, Help)]82
pub struct ContainerParam {83
/// Name of the Container.84
pub name: Box<str>,85
/// Path to the vfio device. [default: /dev/vfio/vfio]86
pub dev_vfio: Option<Box<Path>>,87
}88