Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ virtio-console = ["virtio"]
## Enables the virtio-fs driver.
virtio-fs = ["virtio", "dep:fuse-abi", "fuse-abi/num_enum"]

## Enables the virtio-entropy driver.
virtio-entropy = ["virtio"]

## Enables the virtio-vsock driver.
virtio-vsock = ["virtio"]

Expand Down Expand Up @@ -310,7 +313,7 @@ workspace = true

[dependencies]
hermit-macro = { version = "=0.1.0", path = "hermit-macro" }
virtio = { package = "virtio-spec", version = "0.3", optional = true, features = ["alloc", "mmio", "nightly", "zerocopy"] }
virtio = { package = "virtio-spec", git = "https://github.com/sbutz/virtio-spec-rs", branch = "sb/entropy", optional = true, features = ["alloc", "mmio", "nightly", "zerocopy"] }
ahash = { version = "0.8", default-features = false }
align-address = "0.4"
anstyle = { version = "1", default-features = false }
Expand Down
28 changes: 28 additions & 0 deletions src/arch/aarch64/kernel/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use align_address::Align;
use arm_gic::{IntId, Trigger};
#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
))]
Expand All @@ -22,13 +23,16 @@ use crate::drivers::InterruptHandlerMap;
use crate::drivers::console::VirtioConsoleDriver;
#[cfg(feature = "virtio-console")]
use crate::drivers::console::VirtioUART;
#[cfg(feature = "virtio-entropy")]
use crate::drivers::entropy::VirtioEntropyDriver;
#[cfg(feature = "virtio-fs")]
use crate::drivers::fs::VirtioFsDriver;
#[cfg(feature = "virtio-net")]
use crate::drivers::net::virtio::VirtioNetDriver;
use crate::drivers::virtio::transport::mmio as mmio_virtio;
#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-net",
feature = "virtio-vsock",
Expand All @@ -47,6 +51,8 @@ pub(crate) static MMIO_DRIVERS: InitCell<Vec<MmioDriver>> = InitCell::new(Vec::n
pub(crate) enum MmioDriver {
#[cfg(feature = "virtio-console")]
VirtioConsole(InterruptTicketMutex<VirtioConsoleDriver>),
#[cfg(feature = "virtio-entropy")]
VirtioEntropy(InterruptTicketMutex<VirtioEntropyDriver>),
#[cfg(feature = "virtio-fs")]
VirtioFs(InterruptTicketMutex<VirtioFsDriver>),
#[cfg(feature = "virtio-vsock")]
Expand All @@ -63,6 +69,15 @@ impl MmioDriver {
}
}

#[cfg(feature = "virtio-entropy")]
fn get_entropy_driver(&self) -> Option<&InterruptTicketMutex<VirtioEntropyDriver>> {
#[allow(unreachable_patterns)]
match self {
Self::VirtioEntropy(drv) => Some(drv),
_ => None,
}
}

#[cfg(feature = "virtio-fs")]
fn get_filesystem_driver(&self) -> Option<&InterruptTicketMutex<VirtioFsDriver>> {
#[allow(unreachable_patterns)]
Expand All @@ -84,6 +99,7 @@ impl MmioDriver {

#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock"
))]
Expand All @@ -102,6 +118,14 @@ pub(crate) fn get_console_driver() -> Option<&'static InterruptTicketMutex<Virti
.find_map(|drv| drv.get_console_driver())
}

#[cfg(feature = "virtio-entropy")]
pub(crate) fn get_entropy_driver() -> Option<&'static InterruptTicketMutex<VirtioEntropyDriver>> {
MMIO_DRIVERS
.get()?
.iter()
.find_map(|drv| drv.get_entropy_driver())
}

#[cfg(feature = "virtio-fs")]
pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptTicketMutex<VirtioFsDriver>> {
MMIO_DRIVERS
Expand Down Expand Up @@ -234,6 +258,10 @@ pub fn init_drivers(handlers: &mut InterruptHandlerMap) {
VirtioDriver::Console(drv) => register_driver(MmioDriver::VirtioConsole(
InterruptTicketMutex::new(*drv),
)),
#[cfg(feature = "virtio-entropy")]
VirtioDriver::Entropy(drv) => register_driver(MmioDriver::VirtioEntropy(
InterruptTicketMutex::new(*drv),
)),
#[cfg(feature = "virtio-fs")]
VirtioDriver::Fs(drv) => {
register_driver(MmioDriver::VirtioFs(InterruptTicketMutex::new(*drv)));
Expand Down
1 change: 1 addition & 0 deletions src/arch/aarch64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl fmt::Display for CpuFrequency {
}
}

#[cfg_attr(feature = "virtio-entropy", allow(dead_code))]
pub fn seed_entropy() -> Option<[u8; 32]> {
None
}
Expand Down
9 changes: 9 additions & 0 deletions src/arch/riscv64/kernel/devicetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::arch::riscv64::kernel::interrupts::init_plic;
#[cfg(all(
any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
),
Expand All @@ -36,6 +37,7 @@ use crate::drivers::virtio::transport::mmio as mmio_virtio;
#[cfg(all(
any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-net",
feature = "virtio-vsock",
Expand All @@ -49,6 +51,7 @@ use crate::executor::device::NETWORK_DEVICE;
#[cfg(all(
any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
),
Expand Down Expand Up @@ -264,6 +267,12 @@ pub fn init_drivers(handlers: &mut InterruptHandlerMap) {
hermit_sync::InterruptSpinMutex::new(*drv),
));
}
#[cfg(feature = "virtio-entropy")]
Ok(VirtioDriver::Entropy(drv)) => {
register_driver(MmioDriver::VirtioEntropy(
hermit_sync::InterruptSpinMutex::new(*drv),
));
}
#[cfg(feature = "virtio-fs")]
Ok(VirtioDriver::Fs(drv)) => {
register_driver(MmioDriver::VirtioFs(
Expand Down
23 changes: 23 additions & 0 deletions src/arch/riscv64/kernel/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ use alloc::vec::Vec;

#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
))]
use hermit_sync::InterruptSpinMutex;

#[cfg(feature = "virtio-console")]
use crate::drivers::console::VirtioConsoleDriver;
#[cfg(feature = "virtio-entropy")]
use crate::drivers::entropy::VirtioEntropyDriver;
#[cfg(feature = "virtio-fs")]
use crate::drivers::fs::VirtioFsDriver;
#[cfg(feature = "gem-net")]
Expand All @@ -25,6 +28,8 @@ pub(crate) static MMIO_DRIVERS: InitCell<Vec<MmioDriver>> = InitCell::new(Vec::n
pub(crate) enum MmioDriver {
#[cfg(feature = "virtio-console")]
VirtioConsole(InterruptSpinMutex<VirtioConsoleDriver>),
#[cfg(feature = "virtio-entropy")]
VirtioEntropy(InterruptSpinMutex<VirtioEntropyDriver>),
#[cfg(feature = "virtio-fs")]
VirtioFs(InterruptSpinMutex<VirtioFsDriver>),
#[cfg(feature = "virtio-vsock")]
Expand All @@ -41,6 +46,15 @@ impl MmioDriver {
}
}

#[cfg(feature = "virtio-entropy")]
fn get_entropy_driver(&self) -> Option<&InterruptSpinMutex<VirtioEntropyDriver>> {
#[allow(unreachable_patterns)]
match self {
Self::VirtioEntropy(drv) => Some(drv),
_ => None,
}
}

#[cfg(feature = "virtio-fs")]
fn get_filesystem_driver(&self) -> Option<&InterruptSpinMutex<VirtioFsDriver>> {
#[allow(unreachable_patterns)]
Expand All @@ -62,6 +76,7 @@ impl MmioDriver {

#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
))]
Expand All @@ -83,6 +98,14 @@ pub(crate) fn get_console_driver() -> Option<&'static InterruptSpinMutex<VirtioC
.find_map(|drv| drv.get_console_driver())
}

#[cfg(feature = "virtio-entropy")]
pub(crate) fn get_entropy_driver() -> Option<&'static InterruptSpinMutex<VirtioEntropyDriver>> {
MMIO_DRIVERS
.get()?
.iter()
.find_map(|drv| drv.get_entropy_driver())
}

#[cfg(feature = "virtio-fs")]
pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptSpinMutex<VirtioFsDriver>> {
MMIO_DRIVERS
Expand Down
1 change: 1 addition & 0 deletions src/arch/riscv64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl FPUState {
}
}

#[cfg_attr(feature = "virtio-entropy", allow(dead_code))]
pub fn seed_entropy() -> Option<[u8; 32]> {
None
}
Expand Down
28 changes: 28 additions & 0 deletions src/arch/x86_64/kernel/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use align_address::Align;
use free_list::{PageLayout, PageRange};
#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
))]
Expand All @@ -23,13 +24,16 @@ use crate::arch::x86_64::mm::paging::{
use crate::drivers::InterruptHandlerMap;
#[cfg(feature = "virtio-console")]
use crate::drivers::console::VirtioConsoleDriver;
#[cfg(feature = "virtio-entropy")]
use crate::drivers::entropy::VirtioEntropyDriver;
#[cfg(feature = "virtio-fs")]
use crate::drivers::fs::VirtioFsDriver;
#[cfg(feature = "virtio-net")]
use crate::drivers::net::virtio::VirtioNetDriver;
use crate::drivers::virtio::transport::mmio as mmio_virtio;
#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-net",
feature = "virtio-vsock",
Expand All @@ -51,6 +55,8 @@ static MMIO_DRIVERS: InitCell<Vec<MmioDriver>> = InitCell::new(Vec::new());
pub(crate) enum MmioDriver {
#[cfg(feature = "virtio-console")]
VirtioConsole(InterruptTicketMutex<VirtioConsoleDriver>),
#[cfg(feature = "virtio-entropy")]
VirtioEntropy(InterruptTicketMutex<VirtioEntropyDriver>),
#[cfg(feature = "virtio-fs")]
VirtioFs(InterruptTicketMutex<VirtioFsDriver>),
#[cfg(feature = "virtio-vsock")]
Expand All @@ -67,6 +73,15 @@ impl MmioDriver {
}
}

#[cfg(feature = "virtio-entropy")]
fn get_entropy_driver(&self) -> Option<&InterruptTicketMutex<VirtioEntropyDriver>> {
#[allow(unreachable_patterns)]
match self {
Self::VirtioEntropy(drv) => Some(drv),
_ => None,
}
}

#[cfg(feature = "virtio-fs")]
fn get_filesystem_driver(&self) -> Option<&InterruptTicketMutex<VirtioFsDriver>> {
#[allow(unreachable_patterns)]
Expand Down Expand Up @@ -184,6 +199,7 @@ fn guess_device(

#[cfg(any(
feature = "virtio-console",
feature = "virtio-entropy",
feature = "virtio-fs",
feature = "virtio-vsock",
))]
Expand All @@ -202,6 +218,14 @@ pub(crate) fn get_console_driver() -> Option<&'static InterruptTicketMutex<Virti
.find_map(|drv| drv.get_console_driver())
}

#[cfg(feature = "virtio-entropy")]
pub(crate) fn get_entropy_driver() -> Option<&'static InterruptTicketMutex<VirtioEntropyDriver>> {
MMIO_DRIVERS
.get()?
.iter()
.find_map(|drv| drv.get_entropy_driver())
}

#[cfg(feature = "virtio-fs")]
pub(crate) fn get_filesystem_driver() -> Option<&'static InterruptTicketMutex<VirtioFsDriver>> {
MMIO_DRIVERS
Expand All @@ -228,6 +252,10 @@ fn register_mmio(
Ok(VirtioDriver::Console(drv)) => {
register_driver(MmioDriver::VirtioConsole(InterruptTicketMutex::new(*drv)));
}
#[cfg(feature = "virtio-entropy")]
Ok(VirtioDriver::Entropy(drv)) => {
register_driver(MmioDriver::VirtioEntropy(InterruptTicketMutex::new(*drv)));
}
#[cfg(feature = "virtio-fs")]
Ok(VirtioDriver::Fs(drv)) => {
register_driver(MmioDriver::VirtioFs(InterruptTicketMutex::new(*drv)));
Expand Down
1 change: 1 addition & 0 deletions src/arch/x86_64/kernel/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ pub fn print_information() {
infofooter!();
}

#[cfg_attr(feature = "virtio-entropy", allow(dead_code))]
pub fn seed_entropy() -> Option<[u8; 32]> {
let mut buf = [0; 32];

Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ pub(crate) const VSOCK_PACKET_SIZE: u32 = 8192;

#[cfg(feature = "virtio-console")]
pub(crate) const CONSOLE_PACKET_SIZE: u32 = 8192;

#[cfg(feature = "virtio-entropy")]
pub(crate) const ENTROPY_PACKET_SIZE: u32 = 32;
Loading
Loading