diff --git a/Cargo.toml b/Cargo.toml index b7d6b50..05acb49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,3 +39,6 @@ riscv_vcpu = "0.1" arm_vcpu = { git = "https://github.com/arceos-hypervisor/arm_vcpu", branch = "next" } arm_vgic = { version = "0.1", features = ["vgicv3"] } +[patch.crates-io] +axvmconfig = { git = "https://github.com/arceos-hypervisor/axvmconfig.git", branch = "next" } +axvcpu = {git = "https://github.com/arceos-hypervisor/axvcpu.git", branch = "next"} \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index 2bd1289..cda4117 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,8 +7,8 @@ use alloc::vec::Vec; use axaddrspace::GuestPhysAddr; pub use axvmconfig::{ - AxVMCrateConfig, EmulatedDeviceConfig, PassThroughDeviceConfig, VMInterruptMode, VMType, - VmMemConfig, VmMemMappingType, + AxVMCrateConfig, EmulatedDeviceConfig, PassThroughAddressConfig, PassThroughDeviceConfig, + VMInterruptMode, VMType, VmMemConfig, VmMemMappingType, }; // /// A part of `AxVCpuConfig`, which represents an architecture-dependent `VCpu`. @@ -56,6 +56,7 @@ pub struct AxVMConfig { emu_devices: Vec, pass_through_devices: Vec, excluded_devices: Vec>, + pass_through_addresses: Vec, // TODO: improve interrupt passthrough spi_list: Vec, interrupt_mode: VMInterruptMode, @@ -86,6 +87,7 @@ impl From for AxVMConfig { emu_devices: cfg.devices.emu_devices, pass_through_devices: cfg.devices.passthrough_devices, excluded_devices: cfg.devices.excluded_devices, + pass_through_addresses: cfg.devices.passthrough_addresses, spi_list: Vec::new(), interrupt_mode: cfg.devices.interrupt_mode, } @@ -127,6 +129,10 @@ impl AxVMConfig { pub fn excluded_devices(&self) -> &Vec> { &self.excluded_devices } + + pub fn pass_through_addresses(&self) -> &Vec { + &self.pass_through_addresses + } // /// Returns configurations related to VM memory regions. // pub fn memory_regions(&self) -> Vec { // &self.memory_regions diff --git a/src/vm.rs b/src/vm.rs index 7d0661e..4a82cbf 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -161,6 +161,16 @@ impl AxVM { )); } + for pt_addr in inner_mut.config.pass_through_addresses() { + debug!( + "PT addr region: [{:#x}~{:#x}]", + pt_addr.base_gpa, + pt_addr.base_gpa + pt_addr.length, + ); + // Align the base address and length to 4K boundaries. + pt_dev_region.push((align_down_4k(pt_addr.base_gpa), align_up_4k(pt_addr.length))); + } + pt_dev_region.sort_by_key(|(gpa, _)| *gpa); // Merge overlapping regions.