1 // Copyright 2022 Arm Limited (or its affiliates). All rights reserved. 2 3 use crate::{CpuState, GicState, HypervisorDeviceError, HypervisorVmError}; 4 use std::any::Any; 5 use std::result; 6 7 /// Errors thrown while setting up the VGIC. 8 #[derive(Debug)] 9 pub enum Error { 10 /// Error while calling KVM ioctl for setting up the global interrupt controller. 11 CreateGic(HypervisorVmError), 12 /// Error while setting device attributes for the GIC. 13 SetDeviceAttribute(HypervisorDeviceError), 14 /// Error while getting device attributes for the GIC. 15 GetDeviceAttribute(HypervisorDeviceError), 16 } 17 pub type Result<T> = result::Result<T, Error>; 18 19 #[derive(Debug)] 20 pub struct VgicConfig { 21 pub vcpu_count: u64, 22 pub dist_addr: u64, 23 pub dist_size: u64, 24 pub redists_addr: u64, 25 pub redists_size: u64, 26 pub msi_addr: u64, 27 pub msi_size: u64, 28 pub nr_irqs: u32, 29 } 30 31 /// Hypervisor agnostic interface for a virtualized GIC 32 pub trait Vgic: Send + Sync { 33 /// Returns the fdt compatibility property of the device 34 fn fdt_compatibility(&self) -> &str; 35 36 /// Returns the maint_irq fdt property of the device 37 fn fdt_maint_irq(&self) -> u32; 38 39 /// Returns an array with GIC device properties 40 fn device_properties(&self) -> [u64; 4]; 41 42 /// Returns the number of vCPUs this GIC handles 43 fn vcpu_count(&self) -> u64; 44 45 /// Returns whether the GIC device is MSI compatible or not 46 fn msi_compatible(&self) -> bool; 47 48 /// Returns the MSI compatibility property of the device 49 fn msi_compatibility(&self) -> &str; 50 51 /// Returns the MSI reg property of the device 52 fn msi_properties(&self) -> [u64; 2]; 53 54 /// Get the values of GICR_TYPER for each vCPU. 55 fn set_gicr_typers(&mut self, vcpu_states: &[CpuState]); 56 57 /// Downcast the trait object to its concrete type. 58 fn as_any_concrete_mut(&mut self) -> &mut dyn Any; 59 60 /// Save the state of GICv3ITS. 61 fn state(&self) -> Result<GicState>; 62 63 /// Restore the state of GICv3ITS. 64 fn set_state(&mut self, state: &GicState) -> Result<()>; 65 66 /// Saves GIC internal data tables into RAM. 67 fn save_data_tables(&self) -> Result<()>; 68 } 69