mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-21 20:15:21 +00:00
vmm: vm, device_manager: Trigger a power button notification via ACPI
Use the ACPI GED device to trigger a notitifcation of type POWER_BUTTON_CHANGED which will ultimately lead to the guest being notified. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
c381b36b87
commit
843a010163
@ -366,6 +366,9 @@ pub enum DeviceManagerError {
|
||||
|
||||
/// Missing virtio-balloon, can't proceed as expected.
|
||||
MissingVirtioBalloon,
|
||||
|
||||
/// Failed to do power button notification
|
||||
PowerButtonNotification(io::Error),
|
||||
}
|
||||
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
|
||||
|
||||
@ -3177,6 +3180,18 @@ impl DeviceManager {
|
||||
pub fn device_tree(&self) -> Arc<Mutex<DeviceTree>> {
|
||||
self.device_tree.clone()
|
||||
}
|
||||
|
||||
#[cfg(feature = "acpi")]
|
||||
pub fn notify_power_button(&self) -> DeviceManagerResult<()> {
|
||||
return self
|
||||
.ged_notification_device
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.notify(AcpiNotificationFlags::POWER_BUTTON_CHANGED)
|
||||
.map_err(DeviceManagerError::PowerButtonNotification);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "acpi")]
|
||||
|
@ -234,6 +234,12 @@ pub enum Error {
|
||||
|
||||
/// Cannot activate virtio devices
|
||||
ActivateVirtioDevices(device_manager::DeviceManagerError),
|
||||
|
||||
/// Power button not supported
|
||||
PowerButtonNotSupported,
|
||||
|
||||
/// Error triggering power button
|
||||
PowerButton(device_manager::DeviceManagerError),
|
||||
}
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
@ -1762,6 +1768,18 @@ impl Vm {
|
||||
.activate_virtio_devices()
|
||||
.map_err(Error::ActivateVirtioDevices)
|
||||
}
|
||||
|
||||
pub fn power_button(&self) -> Result<()> {
|
||||
#[cfg(feature = "acpi")]
|
||||
return self
|
||||
.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.notify_power_button()
|
||||
.map_err(Error::PowerButton);
|
||||
#[cfg(not(feature = "acpi"))]
|
||||
Err(Error::PowerButtonNotSupported)
|
||||
}
|
||||
}
|
||||
|
||||
impl Pausable for Vm {
|
||||
|
Loading…
x
Reference in New Issue
Block a user