hypervisor: Implement get_device_attr method for AArch64

This commit implements the `get_device_attr` method for the
`KVM_GET_DEVICE_ATTR` ioctl. This ioctl will be used in retrieving
the GIC status.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
This commit is contained in:
Henry Wang 2020-08-31 14:04:19 +08:00 committed by Rob Bradford
parent b1285cf528
commit 89a6b63e6e
3 changed files with 38 additions and 0 deletions

View File

@ -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<T> = result::Result<T, Error>;
@ -111,6 +113,27 @@ pub mod kvm {
Ok(())
}
/// Get a GIC device attribute
fn get_device_attribute(
device: &Arc<dyn hypervisor::Device>,
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.

View File

@ -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<T> = std::result::Result<T, HypervisorDeviceError>;
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<()>;
}

View File

@ -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 {