devices: gic: use VgicConfig everywhere

Use VgicConfig to initialize Vgic.
Use Gic::create_default_config everywhere so we don't always recompute
redist/msi registers.
Add a helper create_test_vgic_config for tests in hypervisor crate.

Signed-off-by: Nuno Das Neves <nudasnev@microsoft.com>
This commit is contained in:
Nuno Das Neves
2022-08-30 00:49:57 +00:00
committed by Rob Bradford
parent a832033531
commit 784a3aaf3c
7 changed files with 60 additions and 140 deletions

View File

@@ -33,6 +33,8 @@ use anyhow::anyhow;
use arch::aarch64::regs;
use arch::EntryPoint;
use arch::NumaNodes;
#[cfg(target_arch = "aarch64")]
use devices::gic::Gic;
use devices::interrupt_controller::InterruptController;
#[cfg(all(target_arch = "aarch64", feature = "gdb"))]
use gdbstub_arch::aarch64::reg::AArch64CoreRegs as CoreRegs;
@@ -1333,6 +1335,7 @@ impl CpuManager {
madt.append(gicc);
}
let vgic_config = Gic::create_default_config(self.config.boot_vcpus.into());
// GIC Distributor structure. See section 5.2.12.15 in ACPI spec.
let gicd = GicD {
@@ -1340,7 +1343,7 @@ impl CpuManager {
length: 24,
reserved0: 0,
gic_id: 0,
base_address: arch::layout::GIC_V3_DIST_START.0,
base_address: vgic_config.dist_addr,
global_irq_base: 0,
version: 3,
reserved1: [0; 3],
@@ -1348,15 +1351,12 @@ impl CpuManager {
madt.append(gicd);
// See 5.2.12.17 GIC Redistributor (GICR) Structure in ACPI spec.
let gicr_size: u32 =
(arch::layout::GIC_V3_REDIST_SIZE * self.config.boot_vcpus as u64) as u32;
let gicr_base: u64 = arch::layout::GIC_V3_DIST_START.0 - gicr_size as u64;
let gicr = GicR {
r#type: acpi::ACPI_APIC_GENERIC_REDISTRIBUTOR,
length: 16,
reserved: 0,
base_address: gicr_base,
range_length: gicr_size,
base_address: vgic_config.redists_addr,
range_length: vgic_config.redists_size as u32,
};
madt.append(gicr);
@@ -1366,7 +1366,7 @@ impl CpuManager {
length: 20,
reserved0: 0,
translation_id: 0,
base_address: gicr_base - arch::layout::GIC_V3_ITS_SIZE,
base_address: vgic_config.msi_addr,
reserved1: 0,
};
madt.append(gicits);

View File

@@ -1205,11 +1205,11 @@ impl DeviceManager {
#[cfg(target_arch = "aarch64")]
{
let vcpus = self.config.lock().unwrap().cpus.boot_vcpus;
let msi_start = arch::layout::GIC_V3_DIST_START.raw_value()
- arch::layout::GIC_V3_REDIST_SIZE * (vcpus as u64)
- arch::layout::GIC_V3_ITS_SIZE;
let msi_end = msi_start + arch::layout::GIC_V3_ITS_SIZE - 1;
(msi_start, msi_end)
let vgic_config = gic::Gic::create_default_config(vcpus.into());
(
vgic_config.msi_addr,
vgic_config.msi_addr + vgic_config.msi_size - 1,
)
}
#[cfg(target_arch = "x86_64")]
(0xfee0_0000, 0xfeef_ffff)

View File

@@ -47,7 +47,7 @@ use arch::EntryPoint;
use arch::PciSpaceInfo;
use arch::{NumaNode, NumaNodes};
#[cfg(target_arch = "aarch64")]
use devices::gic::GIC_V3_ITS_SNAPSHOT_ID;
use devices::gic::{Gic, GIC_V3_ITS_SNAPSHOT_ID};
#[cfg(target_arch = "aarch64")]
use devices::interrupt_controller::{self, InterruptController};
use devices::AcpiNotificationFlags;
@@ -1262,6 +1262,7 @@ impl Vm {
.as_ref()
.map(|(v, _)| *v);
let vcpu_count = self.cpu_manager.lock().unwrap().boot_vcpus() as u64;
let vgic = self
.device_manager
.lock()
@@ -1272,7 +1273,7 @@ impl Vm {
.unwrap()
.create_vgic(
&self.memory_manager.lock().as_ref().unwrap().vm,
self.cpu_manager.lock().unwrap().boot_vcpus() as u64,
Gic::create_default_config(vcpu_count),
)
.map_err(|_| {
Error::ConfigureSystem(arch::Error::PlatformSpecific(
@@ -2306,6 +2307,7 @@ impl Vm {
// Creating a GIC device here, as the GIC will not be created when
// restoring the device manager. Note that currently only the bare GICv3
// without ITS is supported.
let vcpu_count = vcpu_numbers.try_into().unwrap();
self.device_manager
.lock()
.unwrap()
@@ -2313,7 +2315,7 @@ impl Vm {
.unwrap()
.lock()
.unwrap()
.create_vgic(&self.vm, vcpu_numbers.try_into().unwrap())
.create_vgic(&self.vm, Gic::create_default_config(vcpu_count))
.map_err(|e| MigratableError::Restore(anyhow!("Could not create GIC: {:#?}", e)))?;
// PMU interrupt sticks to PPI, so need to be added by 16 to get real irq number.
@@ -3407,14 +3409,7 @@ mod tests {
let hv = hypervisor::new().unwrap();
let vm = hv.create_vm().unwrap();
let gic = vm
.create_vgic(
1,
0x0900_0000 - 0x01_0000,
0x01_0000,
0x02_0000,
0x02_0000,
256,
)
.create_vgic(Gic::create_default_config(1))
.expect("Cannot create gic");
assert!(create_fdt(
&mem,