From 7932411bff467ac5a2abe215aaf4d87a85ad5ca9 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sun, 29 Oct 2023 23:17:12 +0000 Subject: [PATCH] collect configuration of mmio devices 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. @:[:] where: := size (can use standard suffixes like K, M and G) := physical base address := interrupt number (as passed to request_irq()) := (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 @:[:] in a vector, which is part of CLI. This PR based on preliminary work of @duanyu-yu --- src/env.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/env.rs b/src/env.rs index d85c5f152d..4ca18d5558 100644 --- a/src/env.rs +++ b/src/env.rs @@ -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; @@ -27,6 +27,8 @@ struct Cli { freq: Option, env_vars: HashMap, args: Vec, + #[allow(dead_code)] + mmio: Vec, } /// Whether Hermit is running under the "uhyve" hypervisor. @@ -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:?}"); @@ -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" => { @@ -88,6 +97,8 @@ impl Default for Cli { freq, env_vars, args, + #[allow(dead_code)] + mmio, } } } @@ -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() +}