From b30ddc08371266e80434b707edd24885ea9916a1 Mon Sep 17 00:00:00 2001 From: Michael Zhao Date: Mon, 6 Sep 2021 21:11:41 +0800 Subject: [PATCH] aarch64: Refactor AArch64 GIC space definitions Move the definition of MSI space to layout.rs, so other crates can reference it. Now it is needed by virtio-iommu. Signed-off-by: Michael Zhao --- arch/src/aarch64/gic/gicv3.rs | 12 +++--------- arch/src/aarch64/gic/gicv3_its.rs | 5 ++--- arch/src/aarch64/layout.rs | 11 +++++++++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/src/aarch64/gic/gicv3.rs b/arch/src/aarch64/gic/gicv3.rs index b94175af7..35ac3ad2a 100644 --- a/arch/src/aarch64/gic/gicv3.rs +++ b/arch/src/aarch64/gic/gicv3.rs @@ -78,23 +78,17 @@ pub mod kvm { impl VersionMapped for Gicv3State {} impl KvmGicV3 { - // Unfortunately bindgen omits defines that are based on other defines. - // See arch/arm64/include/uapi/asm/kvm.h file from the linux kernel. - pub const SZ_64K: u64 = 0x0001_0000; - const KVM_VGIC_V3_DIST_SIZE: u64 = KvmGicV3::SZ_64K; - const KVM_VGIC_V3_REDIST_SIZE: u64 = (2 * KvmGicV3::SZ_64K); - // Device trees specific constants pub const ARCH_GIC_V3_MAINT_IRQ: u32 = 9; /// Get the address of the GIC distributor. pub fn get_dist_addr() -> u64 { - layout::MAPPED_IO_START - KvmGicV3::KVM_VGIC_V3_DIST_SIZE + layout::GIC_V3_DIST_START } /// Get the size of the GIC distributor. pub fn get_dist_size() -> u64 { - KvmGicV3::KVM_VGIC_V3_DIST_SIZE + layout::GIC_V3_DIST_SIZE } /// Get the address of the GIC redistributors. @@ -104,7 +98,7 @@ pub mod kvm { /// Get the size of the GIC redistributors. pub fn get_redists_size(vcpu_count: u64) -> u64 { - vcpu_count * KvmGicV3::KVM_VGIC_V3_REDIST_SIZE + vcpu_count * layout::GIC_V3_REDIST_SIZE } /// Save the state of GIC. diff --git a/arch/src/aarch64/gic/gicv3_its.rs b/arch/src/aarch64/gic/gicv3_its.rs index 5f3d4db2b..f7b97cd10 100644 --- a/arch/src/aarch64/gic/gicv3_its.rs +++ b/arch/src/aarch64/gic/gicv3_its.rs @@ -13,6 +13,7 @@ pub mod kvm { use crate::aarch64::gic::gicv3::kvm::KvmGicV3; use crate::aarch64::gic::kvm::{save_pending_tables, KvmGicDevice}; use crate::aarch64::gic::GicDevice; + use crate::layout; use anyhow::anyhow; use hypervisor::kvm::kvm_bindings; use hypervisor::CpuState; @@ -179,10 +180,8 @@ pub mod kvm { impl VersionMapped for Gicv3ItsState {} impl KvmGicV3Its { - const KVM_VGIC_V3_ITS_SIZE: u64 = (2 * KvmGicV3::SZ_64K); - fn get_msi_size() -> u64 { - KvmGicV3Its::KVM_VGIC_V3_ITS_SIZE + layout::GIC_V3_ITS_SIZE } fn get_msi_addr(vcpu_count: u64) -> u64 { diff --git a/arch/src/aarch64/layout.rs b/arch/src/aarch64/layout.rs index 02792b7fc..f0f17fe5b 100644 --- a/arch/src/aarch64/layout.rs +++ b/arch/src/aarch64/layout.rs @@ -55,6 +55,17 @@ pub const UEFI_SIZE: u64 = 0x040_0000; /// Below this address will reside the GIC, above this address will reside the MMIO devices. pub const MAPPED_IO_START: u64 = 0x0900_0000; +/// See kernel file arch/arm64/include/uapi/asm/kvm.h for the GIC related definitions. +/// 0x08ff_0000 ~ 0x0900_0000 is reserved for GICv3 Distributor +pub const GIC_V3_DIST_SIZE: u64 = 0x01_0000; +pub const GIC_V3_DIST_START: u64 = MAPPED_IO_START - GIC_V3_DIST_SIZE; +/// Below 0x08ff_0000 is reserved for GICv3 Redistributor. +/// The size defined here is for each vcpu. +/// The total size is 'number_of_vcpu * GIC_V3_REDIST_SIZE' +pub const GIC_V3_REDIST_SIZE: u64 = 0x02_0000; +/// Below Redistributor area is GICv3 ITS +pub const GIC_V3_ITS_SIZE: u64 = 0x02_0000; + /// Space 0x0900_0000 ~ 0x0905_0000 is reserved for legacy devices. pub const LEGACY_SERIAL_MAPPED_IO_START: u64 = 0x0900_0000; pub const LEGACY_RTC_MAPPED_IO_START: u64 = 0x0901_0000;