Skip to content
Closed
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
33 changes: 17 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
[package]
name = "axvmconfig"
version = "0.1.0"
edition = "2021"
authors = [
"Keyang Hu <[email protected]>",
"Mingxian Su <[email protected]>",
]
keywords = ["axvisor", "config", "toml"]
homepage = "https://github.com/arceos-hypervisor/axvmconfig"
description = "A simple VM configuration tool for ArceOS-Hypervisor."
"Keyang Hu <[email protected]>",
"Mingxian Su <[email protected]>",
]
description = "A simple VM configuration tool for ArceOS-Hypervisor."
edition = "2021"
homepage = "https://github.com/arceos-hypervisor/axvmconfig"
keywords = ["axvisor", "config", "toml"]
license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0" # MulanPubL2 is not included in SPDX
name = "axvmconfig"
version = "0.1.0"

[features]
default = ["std"]
std = ["dep:clap", "dep:env_logger"]
std = ["dep:clap", "dep:env_logger", "dep:schemars"]

[lib]
name = "axvmconfig"
Expand All @@ -24,11 +24,12 @@ name = "axvmconfig"
path = "src/main.rs"

[dependencies]
env_logger = { version = "0.11.3", optional = true }
axerrno = "0.1.0"
clap = {version = "4.5.23", optional = true, features = ["derive"]}
enumerable = {version = "1.2", default-features = false}
env_logger = {version = "0.11.3", optional = true}
log = "0.4.21"
serde = { version = "1.0.204", default-features = false, features = ["derive"] }
schemars = {version = "1.1.0", optional = true}
serde = {version = "1.0.204", default-features = false, features = ["derive"]}
serde_repr = "0.1"
toml = { version = "0.9.5", default-features = false, features = ["serde", "parse", "display"] }
axerrno = "0.1.0"
enumerable = { version = "1.2", default-features = false }
clap = { version = "4.5.23", optional = true, features = ["derive"]}
toml = {version = "0.9.5", default-features = false, features = ["serde", "parse", "display"]}
37 changes: 36 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr};

use axerrno::AxResult;

#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
/// A part of `AxVMConfig`, which represents guest VM type.
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
pub enum VMType {
Expand Down Expand Up @@ -52,13 +53,16 @@ impl From<VMType> for usize {
///
/// Defines how virtual machine memory regions are mapped to host physical memory.
/// This affects memory allocation and management strategies in the hypervisor.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, serde_repr::Serialize_repr, serde_repr::Deserialize_repr)]
#[repr(u8)]
pub enum VmMemMappingType {
/// The memory region is allocated by the VM monitor.
MapAlloc = 0,
/// The memory region is identical to the host physical memory region.
MapIdentical = 1,
/// The memory region is reserved memory for the guest OS.
MapReserved = 2,
}

/// The default value of `VmMemMappingType` is `MapAlloc`.
Expand All @@ -73,6 +77,7 @@ impl Default for VmMemMappingType {
/// Represents a contiguous memory region within the guest's physical address space.
/// Each region has specific properties including address, size, access permissions,
/// and mapping type that determine how it's handled by the hypervisor.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct VmMemConfig {
/// The start address of the memory region in GPA (Guest Physical Address).
Expand All @@ -99,6 +104,7 @@ pub struct VmMemConfig {
/// - 0x80 - 0xDF: Reserved for future use.
/// - 0xE0 - 0xEF: Virtio devices.
/// - 0xF0 - 0xFF: Reserved for future use.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize_repr, Deserialize_repr, Enumerable)]
#[repr(u8)]
pub enum EmulatedDeviceType {
Expand Down Expand Up @@ -216,6 +222,7 @@ impl EmulatedDeviceType {
}

/// A part of `AxVMConfig`, which represents the configuration of an emulated device for a virtual machine.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct EmulatedDeviceConfig {
/// The name of the device.
Expand All @@ -233,21 +240,39 @@ pub struct EmulatedDeviceConfig {
}

/// A part of `AxVMConfig`, which represents the configuration of a pass-through device for a virtual machine.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct PassThroughDeviceConfig {
/// The name of the device.
pub name: String,
/// The base GPA (Guest Physical Address) of the device.
#[serde(default)]
pub base_gpa: usize,
/// The base HPA (Host Physical Address) of the device.
#[serde(default)]
pub base_hpa: usize,
/// The address length of the device.
#[serde(default)]
pub length: usize,
/// The IRQ (Interrupt Request) ID of the device.
#[serde(default)]
pub irq_id: usize,
}

/// A part of `AxVMConfig`, which represents the configuration of a pass-through address for a virtual machine.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct PassThroughAddressConfig {
/// The base GPA (Guest Physical Address).
#[serde(default)]
pub base_gpa: usize,
/// The address length.
#[serde(default)]
pub length: usize,
}

/// The configuration structure for the guest VM base info.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct VMBaseConfig {
/// VM ID.
Expand Down Expand Up @@ -279,6 +304,7 @@ pub struct VMBaseConfig {
}

/// The configuration structure for the guest VM kernel.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct VMKernelConfig {
/// The entry point of the kernel image.
Expand Down Expand Up @@ -310,6 +336,7 @@ pub struct VMKernelConfig {
}

/// Specifies how the VM should handle interrupts and interrupt controllers.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub enum VMInterruptMode {
/// The VM will not handle interrupts, and the guest OS should not use interrupts.
Expand All @@ -330,6 +357,7 @@ impl Default for VMInterruptMode {
}

/// The configuration structure for the guest VM devices.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct VMDevicesConfig {
/// Emu device Information
Expand All @@ -339,10 +367,17 @@ pub struct VMDevicesConfig {
/// How the VM should handle interrupts and interrupt controllers.
#[serde(default)]
pub interrupt_mode: VMInterruptMode,
///we would not like to pass through devices
#[serde(default)]
pub excluded_devices: Vec<Vec<String>>,
///we would like to pass through address
#[serde(default)]
pub passthrough_addresses: Vec<PassThroughAddressConfig>,
}

/// The configuration structure for the guest VM serialized from a toml file provided by user,
/// and then converted to `AxVMConfig` for the VM creation.
#[cfg_attr(feature = "std", derive(schemars::JsonSchema))]
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct AxVMCrateConfig {
/// The base configuration for the VM.
Expand Down
2 changes: 2 additions & 0 deletions src/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub fn get_vm_config_template(
emu_devices: vec![], // No emulated devices by default
passthrough_devices: vec![], // No passthrough devices by default
interrupt_mode: Default::default(), // Use default interrupt mode
excluded_devices: vec![], // No excluded devices by default
passthrough_addresses: vec![], // No passthrough addresses by default
},
}
}