Alioth Code Coverage

vfio.rs0.00%

1// Copyright 2024 Google LLC
2//
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 at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// 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 and
13// limitations under the License.
14
15pub mod cdev;
16pub mod container;
17pub mod device;
18pub mod group;
19pub mod iommu;
20pub mod pci;
21
22use std::path::Path;
23
24use serde::Deserialize;
25use serde_aco::Help;
26use snafu::Snafu;
27
28use crate::errors::{DebugTrace, trace_error};
29use crate::sys::vfio::VfioIommu;
30
31#[trace_error]
32#[derive(Snafu, DebugTrace)]
33#[snafu(module, context(suffix(false)))]
34pub 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
52pub type Result<T, E = Error> = std::result::Result<T, E>;
53
54#[derive(Debug, PartialEq, Eq, Deserialize, Help)]
55pub 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)]
63pub 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)]
71pub 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)]
82pub 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