Skip to content

Commit 42968bd

Browse files
committed
feat: 更新平台数据初始化,添加对 AxVMConfig 的支持
1 parent 8e7cdd8 commit 42968bd

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

src/arch/aarch64/hal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::arch::PlatData;
99
use crate::arch::cpu::CPUState;
1010
use crate::hal::cpu::{CpuHardId, CpuId};
1111
use crate::vdev::VDeviceList;
12-
use crate::{VmWeak, fdt};
12+
use crate::{AxVMConfig, VmWeak, fdt};
1313

1414
pub struct Hal;
1515

@@ -53,7 +53,7 @@ impl crate::hal::HalOp for Hal {
5353
Ok(vcpu)
5454
}
5555

56-
fn new_plat_data(vdevs: &VDeviceList) -> anyhow::Result<Self::PlatData> {
57-
PlatData::new(vdevs)
56+
fn new_plat_data(config: &AxVMConfig, vdevs: &VDeviceList) -> anyhow::Result<Self::PlatData> {
57+
PlatData::new(config, vdevs)
5858
}
5959
}

src/arch/aarch64/plat.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
11
use arm_gic_driver::IntId;
22
use arm_vgic::{IrqChipOp, v3};
33
use axvdev::IrqNum;
4+
use axvmconfig::VMInterruptMode;
45
use rdif_intc::Intc;
56

6-
use crate::{fdt::fdt_edit, hal::Ioremap, vdev::VDeviceList};
7+
use crate::{AxVMConfig, fdt::fdt_edit, hal::Ioremap, vdev::VDeviceList};
78

89
pub struct PlatData {
910
vdev: VDeviceList,
11+
irq_passthrough: bool,
1012
}
1113

1214
impl PlatData {
13-
pub fn new(vdev_manager: &VDeviceList) -> anyhow::Result<Self> {
15+
pub fn new(config: &AxVMConfig, vdev_manager: &VDeviceList) -> anyhow::Result<Self> {
1416
let mut s = Self {
1517
vdev: vdev_manager.clone(),
18+
irq_passthrough: config.interrupt_mode == VMInterruptMode::Passthrough,
1619
};
1720
s.init()?;
1821
Ok(s)
1922
}
2023

2124
fn init(&mut self) -> anyhow::Result<()> {
22-
// self.new_vgic_v3()?;
25+
if !self.irq_passthrough {
26+
info!("Initializing GICv3 for interrupt virtualization");
27+
self.new_vgic_v3()?;
28+
}
2329
Ok(())
2430
}
2531

@@ -85,4 +91,12 @@ impl IrqChipOp for IrqOp {
8591
};
8692
with_gicv3(|gic| gic.set_cfg(covnert_irq(irq), t));
8793
}
94+
95+
fn set_enable(&self, irq: IrqNum, enable: bool) {
96+
with_gicv3(|gic| gic.set_irq_enable(covnert_irq(irq), enable));
97+
}
98+
99+
fn is_enabled(&self, irq: IrqNum) -> bool {
100+
with_gicv3(|gic| gic.is_irq_enable(covnert_irq(irq)))
101+
}
88102
}

src/hal/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ pub mod timer;
1818
use cpu::{CpuHardId, CpuId};
1919

2020
use crate::{
21-
HostPhysAddr, HostVirtAddr, TASK_STACK_SIZE, VmWeak, arch::Hal, vcpu::VCpuOp, vdev::VDeviceList,
21+
AxVMConfig, HostPhysAddr, HostVirtAddr, TASK_STACK_SIZE, VmWeak, arch::Hal, vcpu::VCpuOp,
22+
vdev::VDeviceList,
2223
};
2324

2425
pub trait HalOp: Send + 'static {
@@ -31,7 +32,7 @@ pub trait HalOp: Send + 'static {
3132
fn cpu_hard_id() -> CpuHardId;
3233
fn cpu_list() -> Vec<CpuHardId>;
3334
fn current_cpu_init(id: CpuId) -> anyhow::Result<Self::HCPU>;
34-
fn new_plat_data(vdevs: &VDeviceList) -> anyhow::Result<Self::PlatData>;
35+
fn new_plat_data(config: &AxVMConfig, vdevs: &VDeviceList) -> anyhow::Result<Self::PlatData>;
3536
fn new_vcpu(hard_id: CpuHardId, vm: VmWeak) -> anyhow::Result<Self::VCPU>;
3637
}
3738

src/vm/machine/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<H: HalOp> StateInited<H> {
5454

5555
let vdevs = VDeviceList::new(&vmspace);
5656

57-
let mut plat = H::new_plat_data(&vdevs)?;
57+
let mut plat = H::new_plat_data(config, &vdevs)?;
5858

5959
debug!(
6060
"Mapping memory regions for VM {} ({})",

0 commit comments

Comments
 (0)