mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-23 16:31:16 +00:00
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:
parent
b1285cf528
commit
89a6b63e6e
@ -15,6 +15,8 @@ pub enum Error {
|
|||||||
CreateGIC(hypervisor::HypervisorVmError),
|
CreateGIC(hypervisor::HypervisorVmError),
|
||||||
/// Error while setting device attributes for the GIC.
|
/// Error while setting device attributes for the GIC.
|
||||||
SetDeviceAttribute(hypervisor::HypervisorDeviceError),
|
SetDeviceAttribute(hypervisor::HypervisorDeviceError),
|
||||||
|
/// Error while getting device attributes for the GIC.
|
||||||
|
GetDeviceAttribute(hypervisor::HypervisorDeviceError),
|
||||||
}
|
}
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -111,6 +113,27 @@ pub mod kvm {
|
|||||||
Ok(())
|
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
|
/// Finalize the setup of a GIC device
|
||||||
fn finalize_device(gic_device: &dyn GICDevice) -> Result<()> {
|
fn finalize_device(gic_device: &dyn GICDevice) -> Result<()> {
|
||||||
/* We need to tell the kernel how many irqs to support with this vgic.
|
/* We need to tell the kernel how many irqs to support with this vgic.
|
||||||
|
@ -22,6 +22,11 @@ pub enum HypervisorDeviceError {
|
|||||||
///
|
///
|
||||||
#[error("Failed to set device attribute: {0}")]
|
#[error("Failed to set device attribute: {0}")]
|
||||||
SetDeviceAttribute(#[source] anyhow::Error),
|
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 {
|
pub trait Device: Send + Sync + AsRawFd {
|
||||||
/// Set device attribute.
|
/// Set device attribute.
|
||||||
fn set_device_attr(&self, attr: &DeviceAttr) -> Result<()>;
|
fn set_device_attr(&self, attr: &DeviceAttr) -> Result<()>;
|
||||||
|
/// Get device attribute.
|
||||||
|
fn get_device_attr(&self, attr: &mut DeviceAttr) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
@ -1254,6 +1254,14 @@ impl device::Device for KvmDevice {
|
|||||||
.set_device_attr(attr)
|
.set_device_attr(attr)
|
||||||
.map_err(|e| device::HypervisorDeviceError::SetDeviceAttribute(e.into()))
|
.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 {
|
impl AsRawFd for KvmDevice {
|
||||||
|
Loading…
Reference in New Issue
Block a user