From 2752149bb0efaca454a955ff4720b55a611c17b7 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Wed, 6 Nov 2024 11:33:20 +0800 Subject: [PATCH] hypervisor: arch: Introduce riscv64 AIA Introduce definitions, traits relate to RISC-V AIA (Advanced Interrupt Architecutre) construction. Signed-off-by: Ruoqing He --- hypervisor/src/arch/riscv64/aia.rs | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 hypervisor/src/arch/riscv64/aia.rs diff --git a/hypervisor/src/arch/riscv64/aia.rs b/hypervisor/src/arch/riscv64/aia.rs new file mode 100644 index 000000000..8f859748f --- /dev/null +++ b/hypervisor/src/arch/riscv64/aia.rs @@ -0,0 +1,65 @@ +// Copyright © 2024 Institute of Software, CAS. All rights reserved. +// +// SPDX-License-Identifier: Apache-2.0 + +use std::any::Any; +use std::result; + +use thiserror::Error; + +use crate::{AiaState, HypervisorDeviceError, HypervisorVmError}; + +/// Errors thrown while setting up the VAIA. +#[derive(Debug, Error)] +pub enum Error { + /// Error while calling KVM ioctl for setting up the global interrupt controller. + #[error("Failed creating AIA device: {0}")] + CreateAia(HypervisorVmError), + /// Error while setting device attributes for the AIA. + #[error("Failed setting device attributes for the AIA: {0}")] + SetDeviceAttribute(HypervisorDeviceError), + /// Error while getting device attributes for the AIA. + #[error("Failed getting device attributes for the AIA: {0}")] + GetDeviceAttribute(HypervisorDeviceError), +} +pub type Result = result::Result; + +#[derive(Debug)] +pub struct VaiaConfig { + pub vcpu_count: u64, + pub aplic_addr: u64, + pub aplic_size: u64, + pub imsic_addr: u64, + pub imsic_size: u64, + pub nr_irqs: u32, +} + +/// Hypervisor agnostic interface for a virtualized AIA +pub trait Vaia: Send + Sync { + /// Returns the compatibility property of APLIC + fn aplic_compatibility(&self) -> &str; + + /// Returns an array with APLIC device properties + fn aplic_properties(&self) -> [u64; 4]; + + /// Returns the compatibility property of IMSIC + fn imsic_compatibility(&self) -> &str; + + /// Returns an array with IMSIC device properties + fn imsic_properties(&self) -> [u64; 4]; + + /// Returns the number of vCPUs this AIA handles + fn vcpu_count(&self) -> u64; + + /// Returns whether the AIA device is MSI compatible or not + fn msi_compatible(&self) -> bool; + + /// Downcast the trait object to its concrete type. + fn as_any_concrete_mut(&mut self) -> &mut dyn Any; + + /// Save the state of AiaImsics. + fn state(&self) -> Result; + + /// Restore the state of AiaImsics. + fn set_state(&mut self, state: &AiaState) -> Result<()>; +}