Skip to content

Commit

Permalink
collect configuration of mmio devices
Browse files Browse the repository at this point in the history
Firecracker pass the configuration of all mmio device by a Linux kernel parameter
This parameter is defined as followd:

virtio_mmio.device=
   [VMMIO] Memory mapped virtio (platform) device.

      <size>@<baseaddr>:<irq>[:<id>]
   where:
      <size>     := size (can use standard suffixes like K, M and G)
      <baseaddr> := physical base address
      <irq>      := interrupt number (as passed to request_irq())
      <id>       := (optional) platform device id
   example:
                 virtio_mmio.device=1K@0x100b0000:48:7
   Can be used multiple times for multiple devices.

This patch parse the command line and store the string
<size>@<baseaddr>:<irq>[:<id>] in a vector, which is part of CLI.

This PR based on preliminary work of @duanyu-yu
  • Loading branch information
stlankes authored and mkroening committed Nov 9, 2023
1 parent 15c2b9c commit 7932411
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Central parsing of the command-line parameters.

use alloc::string::String;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::str;

Expand All @@ -27,6 +27,8 @@ struct Cli {
freq: Option<u16>,
env_vars: HashMap<String, String, RandomState>,
args: Vec<String>,
#[allow(dead_code)]
mmio: Vec<String>,
}

/// Whether Hermit is running under the "uhyve" hypervisor.
Expand All @@ -43,6 +45,7 @@ impl Default for Cli {
RandomState::with_seeds(0, 0, 0, 0),
);
let mut args = Vec::new();
let mut mmio = Vec::new();

let words = shell_words::split(kernel::args().unwrap_or_default()).unwrap();
debug!("cli_words = {words:?}");
Expand All @@ -54,6 +57,12 @@ impl Default for Cli {
})
};
while let Some(word) = words.next() {
if word.as_str().starts_with("virtio_mmio.device=") {
let v: Vec<&str> = word.as_str().split('=').collect();
mmio.push(v[1].to_string());
continue;
}

match word.as_str() {
#[cfg(not(target_arch = "riscv64"))]
"-freq" => {
Expand Down Expand Up @@ -88,6 +97,8 @@ impl Default for Cli {
freq,
env_vars,
args,
#[allow(dead_code)]
mmio,
}
}
}
Expand All @@ -111,3 +122,9 @@ pub fn vars() -> Iter<'static, String, String> {
pub fn args() -> &'static [String] {
CLI.get().unwrap().args.as_slice()
}

/// Returns the configuration of all mmio devices
#[allow(dead_code)]
pub fn mmio() -> &'static [String] {
CLI.get().unwrap().mmio.as_slice()
}

0 comments on commit 7932411

Please sign in to comment.