hermit/drivers/virtio/
mod.rs1pub mod transport;
6pub mod virtqueue;
7
8trait VirtioIdExt {
9 fn as_feature(&self) -> Option<&str>;
10}
11
12impl VirtioIdExt for virtio::Id {
13 fn as_feature(&self) -> Option<&str> {
14 let feature = match self {
15 Self::Net => "virtio-net",
16 Self::Console => "console",
17 Self::Fs => "fuse",
18 Self::Vsock => "vsock",
19 _ => return None,
20 };
21
22 Some(feature)
23 }
24}
25pub mod error {
26 use thiserror::Error;
27
28 #[cfg(feature = "console")]
29 pub use crate::drivers::console::error::VirtioConsoleError;
30 #[cfg(feature = "fuse")]
31 pub use crate::drivers::fs::virtio_fs::error::VirtioFsError;
32 #[cfg(all(
33 not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))),
34 not(feature = "rtl8139"),
35 feature = "virtio-net",
36 ))]
37 pub use crate::drivers::net::virtio::error::VirtioNetError;
38 #[cfg(feature = "pci")]
39 use crate::drivers::pci::error::PciError;
40 #[cfg(feature = "vsock")]
41 pub use crate::drivers::vsock::error::VirtioVsockError;
42
43 #[allow(dead_code)]
44 #[derive(Error, Debug)]
45 pub enum VirtioError {
46 #[cfg(feature = "pci")]
47 #[error(transparent)]
48 FromPci(PciError),
49
50 #[cfg(feature = "pci")]
51 #[error(
52 "Virtio driver failed, for device {0:x}, due to a missing or malformed common config!"
53 )]
54 NoComCfg(u16),
55
56 #[cfg(feature = "pci")]
57 #[error(
58 "Virtio driver failed, for device {0:x}, due to a missing or malformed ISR status config!"
59 )]
60 NoIsrCfg(u16),
61
62 #[cfg(feature = "pci")]
63 #[error(
64 "Virtio driver failed, for device {0:x}, due to a missing or malformed notification config!"
65 )]
66 NoNotifCfg(u16),
67
68 #[error("Device with id {0:#x} not supported.")]
69 DevNotSupported(u16),
70
71 #[cfg(all(
72 not(all(target_arch = "riscv64", feature = "gem-net", not(feature = "pci"))),
73 not(feature = "rtl8139"),
74 feature = "virtio-net",
75 ))]
76 #[error(transparent)]
77 NetDriver(VirtioNetError),
78
79 #[cfg(feature = "fuse")]
80 #[error(transparent)]
81 FsDriver(VirtioFsError),
82
83 #[cfg(feature = "vsock")]
84 #[error(transparent)]
85 VsockDriver(VirtioVsockError),
86
87 #[cfg(feature = "console")]
88 #[error(transparent)]
89 ConsoleDriver(VirtioConsoleError),
90
91 #[cfg(not(feature = "pci"))]
92 #[error("Driver failure")]
93 Unknown,
94 }
95}