diff --git a/arch/src/aarch64/gic/mod.rs b/arch/src/aarch64/gic/mod.rs index fefb498e6..ca4ac4a30 100644 --- a/arch/src/aarch64/gic/mod.rs +++ b/arch/src/aarch64/gic/mod.rs @@ -15,6 +15,8 @@ pub enum Error { CreateGIC(hypervisor::HypervisorVmError), /// Error while setting device attributes for the GIC. SetDeviceAttribute(hypervisor::HypervisorDeviceError), + /// Error while getting device attributes for the GIC. + GetDeviceAttribute(hypervisor::HypervisorDeviceError), } type Result = result::Result; @@ -111,6 +113,27 @@ pub mod kvm { Ok(()) } + /// Get a GIC device attribute + fn get_device_attribute( + device: &Arc, + group: u32, + attr: u64, + addr: u64, + flags: u32, + ) -> Result<()> { + let mut attr = kvm_bindings::kvm_device_attr { + group, + attr, + addr, + flags, + }; + device + .get_device_attr(&mut attr) + .map_err(super::Error::GetDeviceAttribute)?; + + Ok(()) + } + /// Finalize the setup of a GIC device fn finalize_device(gic_device: &dyn GICDevice) -> Result<()> { /* We need to tell the kernel how many irqs to support with this vgic. diff --git a/hypervisor/src/device.rs b/hypervisor/src/device.rs index db380e39f..109ecbaf6 100644 --- a/hypervisor/src/device.rs +++ b/hypervisor/src/device.rs @@ -22,6 +22,11 @@ pub enum HypervisorDeviceError { /// #[error("Failed to set device attribute: {0}")] SetDeviceAttribute(#[source] anyhow::Error), + /// + /// Get device attribute error + /// + #[error("Failed to get device attribute: {0}")] + GetDeviceAttribute(#[source] anyhow::Error), } /// @@ -37,4 +42,6 @@ pub type Result = std::result::Result; pub trait Device: Send + Sync + AsRawFd { /// Set device attribute. fn set_device_attr(&self, attr: &DeviceAttr) -> Result<()>; + /// Get device attribute. + fn get_device_attr(&self, attr: &mut DeviceAttr) -> Result<()>; } diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 7fe25e882..5ca653e54 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -1254,6 +1254,14 @@ impl device::Device for KvmDevice { .set_device_attr(attr) .map_err(|e| device::HypervisorDeviceError::SetDeviceAttribute(e.into())) } + /// + /// Get device attribute + /// + fn get_device_attr(&self, attr: &mut DeviceAttr) -> device::Result<()> { + self.fd + .get_device_attr(attr) + .map_err(|e| device::HypervisorDeviceError::GetDeviceAttribute(e.into())) + } } impl AsRawFd for KvmDevice {