1 // Copyright © 2024 Institute of Software, CAS. All rights reserved. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 use std::any::Any; 6 use std::result; 7 8 use thiserror::Error; 9 10 use crate::{AiaState, HypervisorDeviceError, HypervisorVmError}; 11 12 /// Errors thrown while setting up the VAIA. 13 #[derive(Debug, Error)] 14 pub enum Error { 15 /// Error while calling KVM ioctl for setting up the global interrupt controller. 16 #[error("Failed creating AIA device: {0}")] 17 CreateAia(HypervisorVmError), 18 /// Error while setting device attributes for the AIA. 19 #[error("Failed setting device attributes for the AIA: {0}")] 20 SetDeviceAttribute(HypervisorDeviceError), 21 /// Error while getting device attributes for the AIA. 22 #[error("Failed getting device attributes for the AIA: {0}")] 23 GetDeviceAttribute(HypervisorDeviceError), 24 } 25 pub type Result<T> = result::Result<T, Error>; 26 27 #[derive(Debug)] 28 pub struct VaiaConfig { 29 pub vcpu_count: u32, 30 pub aplic_addr: u64, 31 pub imsic_addr: u64, 32 pub nr_irqs: u32, 33 } 34 35 /// Hypervisor agnostic interface for a virtualized AIA 36 pub trait Vaia: Send + Sync { 37 /// Returns the compatibility property of APLIC 38 fn aplic_compatibility(&self) -> &str; 39 40 /// Returns an array with APLIC device properties 41 fn aplic_properties(&self) -> [u32; 4]; 42 43 /// Returns the compatibility property of IMSIC 44 fn imsic_compatibility(&self) -> &str; 45 46 /// Returns an array with IMSIC device properties 47 fn imsic_properties(&self) -> [u32; 4]; 48 49 /// Returns the number of vCPUs this AIA handles 50 fn vcpu_count(&self) -> u32; 51 52 /// Returns whether the AIA device is MSI compatible or not 53 fn msi_compatible(&self) -> bool; 54 55 /// Downcast the trait object to its concrete type. 56 fn as_any_concrete_mut(&mut self) -> &mut dyn Any; 57 58 /// Save the state of AiaImsics. 59 fn state(&self) -> Result<AiaState>; 60 61 /// Restore the state of AiaImsics. 62 fn set_state(&mut self, state: &AiaState) -> Result<()>; 63 } 64