Skip to content
Merged
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
14 changes: 5 additions & 9 deletions kernel/src/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use svsm::svsm_paging::{
use svsm::task::{KernelThreadStartInfo, schedule_init, start_kernel_task};
use svsm::types::PAGE_SIZE;
use svsm::utils::{MemoryRegion, ScopedRef, round_to_pages};
#[cfg(feature = "virtio-drivers")]
#[cfg(all(feature = "virtio-drivers", feature = "block"))]
use svsm::virtio::probe_mmio_slots;
#[cfg(all(feature = "vtpm", not(test)))]
use svsm::vtpm::vtpm_init;
Expand Down Expand Up @@ -162,12 +162,12 @@ fn mapping_info_init(launch_info: &KernelLaunchInfo) {
/// Returns Ok if initialization is successful or no virtio devices are found
/// Returns an error when a virtio device is found but its driver initialization fails.
#[cfg(feature = "virtio-drivers")]
fn initialize_virtio_mmio() -> Result<(), SvsmError> {
let mut slots = probe_mmio_slots();

fn initialize_virtio_mmio(_config: &SvsmConfig<'_>) -> Result<(), SvsmError> {
#[cfg(feature = "block")]
{
use svsm::block::virtio_blk::initialize_block;

let mut slots = probe_mmio_slots(_config);
initialize_block(&mut slots)?;
}

Expand Down Expand Up @@ -435,11 +435,7 @@ fn svsm_init(launch_info: &KernelLaunchInfo) {
virt_log_usage();

#[cfg(feature = "virtio-drivers")]
if config.has_fw_cfg_port() {
// Virtio cannot exist if there is no fw_cfg, so do not bother to
// attempt initialization if it is not present.
initialize_virtio_mmio().expect("Failed to initialize virtio-mmio drivers");
}
initialize_virtio_mmio(&config).expect("Failed to initialize virtio-mmio drivers");

if let Err(e) = SVSM_PLATFORM.launch_fw(&config) {
panic!("Failed to launch FW: {e:?}");
Expand Down
15 changes: 10 additions & 5 deletions kernel/src/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use virtio_drivers::transport::{DeviceType, Transport, mmio::MmioTransport};

use crate::{
address::PhysAddr,
config::SvsmConfig,
fw_cfg::FwCfg,
mm::{GlobalRangeGuard, map_global_range_4k_shared, pagetable::PTEntryFlags},
platform::SVSM_PLATFORM,
Expand All @@ -25,7 +26,7 @@ pub struct MmioSlot {
pub transport: MmioTransport<SvsmHal>,
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct MmioSlots {
slots: Vec<MmioSlot>,
}
Expand All @@ -47,14 +48,18 @@ pub struct MmioSlots {
/// Returns an [`MmioSlots`] collection containing all discovered virtio-MMIO devices.
/// Returns an empty collection if no devices are found or if the fw_cfg interface
/// is unavailable.
pub fn probe_mmio_slots() -> MmioSlots {
pub fn probe_mmio_slots(config: &SvsmConfig<'_>) -> MmioSlots {
// Virtio MMIO addresses are discovered via fw_cfg, so skip probing
// if it is not present.
if !config.has_fw_cfg_port() {
return MmioSlots::default();
}

virtio_init();

let cfg = FwCfg::new(SVSM_PLATFORM.get_io_port());
let Ok(dev) = cfg.get_virtio_mmio_addresses() else {
return MmioSlots {
slots: Vec::<MmioSlot>::new(),
};
return MmioSlots::default();
};

let mut slots = Vec::with_capacity(dev.len());
Expand Down