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