From f8c060fdd8e42ff147c1e43ff5f27a2268cffb88 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 22:06:03 +0800 Subject: [PATCH 1/4] update to newest `axvmconfig`, add vgicv3 creation code. --- Cargo.toml | 2 +- src/device.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7600bb0..2ecb687 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,4 +20,4 @@ axdevice_base = { git = "https://github.com/arceos-hypervisor/axdevice_crates.gi range-alloc = { git = "https://github.com/arceos-hypervisor/range-alloc.git" } [target.'cfg(target_arch = "aarch64")'.dependencies] -arm_vgic = { git = "https://github.com/arceos-hypervisor/arm_vgic.git" } +arm_vgic = { git = "https://github.com/arceos-hypervisor/arm_vgic.git", features = ["vgicv3"] } diff --git a/src/device.rs b/src/device.rs index d587ff1..df7529d 100644 --- a/src/device.rs +++ b/src/device.rs @@ -14,7 +14,7 @@ use axdevice_base::{ }; use axerrno::{AxResult, ax_err}; use axvmconfig::EmulatedDeviceConfig; -use memory_addr::is_aligned_4k; +use memory_addr::{PhysAddr, is_aligned_4k}; use crate::AxVmDeviceConfig; @@ -126,8 +126,8 @@ impl AxVmDevices { /// According the emu_configs to init every specific device fn init(this: &mut Self, emu_configs: &Vec) { for config in emu_configs { - match EmuDeviceType::from_usize(config.emu_type) { - EmuDeviceType::EmuDeviceTInterruptController => { + match config.emu_type { + EmuDeviceType::InterruptController => { #[cfg(target_arch = "aarch64")] { this.add_mmio_dev(Arc::new(Vgic::new())); @@ -140,7 +140,80 @@ impl AxVmDevices { ); } } - EmuDeviceType::EmuDeviceTIVCChannel => { + EmuDeviceType::GPPTRedistributor => { + #[cfg(target_arch = "aarch64")] + { + const GPPT_GICR_ARG_ERR_MSG: &'static str = + "expect 3 args for gppt redistributor (cpu_num, stride)"; + + let cpu_num = config + .cfg_list + .get(0) + .copied() + .expect(GPPT_GICR_ARG_ERR_MSG); + let stride = config + .cfg_list + .get(1) + .copied() + .expect(GPPT_GICR_ARG_ERR_MSG); + + for i in 0..cpu_num { + let addr = config.base_gpa + i * stride; + let size = config.length; + this.add_mmio_dev(Arc::new(arm_vgic::v3::vgicr::VGicR::new( + addr.into(), + size, + i, + ))); + } + } + #[cfg(not(target_arch = "aarch64"))] + { + warn!( + "emu type: {} is not supported on this platform", + config.emu_type + ); + } + } + EmuDeviceType::GPPTDistributor => { + #[cfg(target_arch = "aarch64")] + { + this.add_mmio_dev(Arc::new(arm_vgic::v3::vgicd::VGicD::new( + config.base_gpa.into(), + Some(config.length), + ))); + } + #[cfg(not(target_arch = "aarch64"))] + { + warn!( + "emu type: {} is not supported on this platform", + config.emu_type + ); + } + } + EmuDeviceType::GPPTITS => { + #[cfg(target_arch = "aarch64")] + { + this.add_mmio_dev(Arc::new(arm_vgic::v3::gits::Gits::new( + config.base_gpa.into(), + config.length, + config + .cfg_list + .get(0) + .map(PhysAddr::from_usize) + .expect("expect 1 arg for gppt its (host_gits_base)"), + false, + ))); + } + #[cfg(not(target_arch = "aarch64"))] + { + warn!( + "emu type: {} is not supported on this platform", + config.emu_type + ); + } + } + EmuDeviceType::IVCChannel => { if this.ivc_channel.is_none() { // Initialize the IVC channel range allocator this.ivc_channel = Some(Mutex::new(RangeAllocator::new(Range { From 3f31511472a3c97288598c1bdd0cf642e6c5271a Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sat, 12 Jul 2025 22:08:22 +0800 Subject: [PATCH 2/4] add logs --- src/device.rs | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/device.rs b/src/device.rs index df7529d..12e19df 100644 --- a/src/device.rs +++ b/src/device.rs @@ -165,6 +165,11 @@ impl AxVmDevices { size, i, ))); + + info!( + "GPPT Redistributor initialized for vCPU {} with base GPA {:#x} and length {:#x}", + i, addr, size + ); } } #[cfg(not(target_arch = "aarch64"))] @@ -182,6 +187,11 @@ impl AxVmDevices { config.base_gpa.into(), Some(config.length), ))); + + info!( + "GPPT Distributor initialized with base GPA {:#x} and length {:#x}", + config.base_gpa, config.length + ); } #[cfg(not(target_arch = "aarch64"))] { @@ -194,16 +204,23 @@ impl AxVmDevices { EmuDeviceType::GPPTITS => { #[cfg(target_arch = "aarch64")] { - this.add_mmio_dev(Arc::new(arm_vgic::v3::gits::Gits::new( - config.base_gpa.into(), - config.length, - config + let host_gits_base = config .cfg_list .get(0) .map(PhysAddr::from_usize) - .expect("expect 1 arg for gppt its (host_gits_base)"), + .expect("expect 1 arg for gppt its (host_gits_base)"); + + this.add_mmio_dev(Arc::new(arm_vgic::v3::gits::Gits::new( + config.base_gpa.into(), + config.length, + host_gits_base, false, ))); + + info!( + "GPPT ITS initialized with base GPA {:#x} and length {:#x}, host GITS base {:#x}", + config.base_gpa, config.length, host_gits_base + ); } #[cfg(not(target_arch = "aarch64"))] { From 46f87c9c2125b733852c8c94a65aa6405415451e Mon Sep 17 00:00:00 2001 From: aarkegz Date: Sun, 13 Jul 2025 22:39:05 +0800 Subject: [PATCH 3/4] fix code errors --- src/device.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/device.rs b/src/device.rs index 12e19df..2767eca 100644 --- a/src/device.rs +++ b/src/device.rs @@ -26,7 +26,7 @@ pub struct AxEmuDevices { emu_devices: Vec>>, } -impl AxEmuDevices { +impl AxEmuDevices { /// Creates a new [`AxEmuDevices`] instance. pub fn new() -> Self { Self { @@ -144,7 +144,7 @@ impl AxVmDevices { #[cfg(target_arch = "aarch64")] { const GPPT_GICR_ARG_ERR_MSG: &'static str = - "expect 3 args for gppt redistributor (cpu_num, stride)"; + "expect 3 args for gppt redistributor (cpu_num, stride, pcpu_id)"; let cpu_num = config .cfg_list @@ -156,14 +156,19 @@ impl AxVmDevices { .get(1) .copied() .expect(GPPT_GICR_ARG_ERR_MSG); + let pcpu_id = config + .cfg_list + .get(2) + .copied() + .expect(GPPT_GICR_ARG_ERR_MSG); for i in 0..cpu_num { let addr = config.base_gpa + i * stride; let size = config.length; this.add_mmio_dev(Arc::new(arm_vgic::v3::vgicr::VGicR::new( addr.into(), - size, - i, + Some(size), + pcpu_id + i, ))); info!( @@ -207,12 +212,13 @@ impl AxVmDevices { let host_gits_base = config .cfg_list .get(0) + .copied() .map(PhysAddr::from_usize) .expect("expect 1 arg for gppt its (host_gits_base)"); this.add_mmio_dev(Arc::new(arm_vgic::v3::gits::Gits::new( config.base_gpa.into(), - config.length, + Some(config.length), host_gits_base, false, ))); From a590ad65d588fbd02ef94038f4d970611dc59434 Mon Sep 17 00:00:00 2001 From: aarkegz Date: Mon, 14 Jul 2025 20:02:34 +0800 Subject: [PATCH 4/4] formatted --- src/device.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/device.rs b/src/device.rs index 2767eca..2f6beda 100644 --- a/src/device.rs +++ b/src/device.rs @@ -210,11 +210,11 @@ impl AxVmDevices { #[cfg(target_arch = "aarch64")] { let host_gits_base = config - .cfg_list - .get(0) - .copied() - .map(PhysAddr::from_usize) - .expect("expect 1 arg for gppt its (host_gits_base)"); + .cfg_list + .get(0) + .copied() + .map(PhysAddr::from_usize) + .expect("expect 1 arg for gppt its (host_gits_base)"); this.add_mmio_dev(Arc::new(arm_vgic::v3::gits::Gits::new( config.base_gpa.into(),