vmm: Implement the power button method for AArch64

This commit implements the power button method for AArch64 using
the PL061 GPIO controller.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
This commit is contained in:
Henry Wang
2021-03-07 21:39:11 +08:00
committed by Michael
parent c853ed3fdc
commit 2bb153de2b
3 changed files with 28 additions and 0 deletions
+2
View File
@@ -25,6 +25,8 @@ pub use self::fwdebug::FwDebugDevice;
pub use self::i8042::I8042Device; pub use self::i8042::I8042Device;
pub use self::serial::Serial; pub use self::serial::Serial;
#[cfg(target_arch = "aarch64")]
pub use self::gpio_pl061::Error as GPIODeviceError;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
pub use self::gpio_pl061::GPIO; pub use self::gpio_pl061::GPIO;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
+16
View File
@@ -403,6 +403,10 @@ pub enum DeviceManagerError {
/// Failed to do power button notification /// Failed to do power button notification
PowerButtonNotification(io::Error), PowerButtonNotification(io::Error),
/// Failed to do AArch64 GPIO power button notification
#[cfg(target_arch = "aarch64")]
AArch64PowerButtonNotification(devices::legacy::GPIODeviceError),
/// Failed to set O_DIRECT flag to file descriptor /// Failed to set O_DIRECT flag to file descriptor
SetDirectIo, SetDirectIo,
@@ -3521,6 +3525,7 @@ impl DeviceManager {
} }
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
#[cfg(target_arch = "x86_64")]
pub fn notify_power_button(&self) -> DeviceManagerResult<()> { pub fn notify_power_button(&self) -> DeviceManagerResult<()> {
self.ged_notification_device self.ged_notification_device
.as_ref() .as_ref()
@@ -3530,6 +3535,17 @@ impl DeviceManager {
.notify(AcpiNotificationFlags::POWER_BUTTON_CHANGED) .notify(AcpiNotificationFlags::POWER_BUTTON_CHANGED)
.map_err(DeviceManagerError::PowerButtonNotification) .map_err(DeviceManagerError::PowerButtonNotification)
} }
#[cfg(target_arch = "aarch64")]
pub fn notify_power_button(&self) -> DeviceManagerResult<()> {
self.gpio_device
.as_ref()
.unwrap()
.lock()
.unwrap()
.trigger_key(3)
.map_err(DeviceManagerError::AArch64PowerButtonNotification)
}
} }
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
+10
View File
@@ -2038,6 +2038,7 @@ impl Vm {
.map_err(Error::ActivateVirtioDevices) .map_err(Error::ActivateVirtioDevices)
} }
#[cfg(target_arch = "x86_64")]
pub fn power_button(&self) -> Result<()> { pub fn power_button(&self) -> Result<()> {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
return self return self
@@ -2049,6 +2050,15 @@ impl Vm {
#[cfg(not(feature = "acpi"))] #[cfg(not(feature = "acpi"))]
Err(Error::PowerButtonNotSupported) Err(Error::PowerButtonNotSupported)
} }
#[cfg(target_arch = "aarch64")]
pub fn power_button(&self) -> Result<()> {
self.device_manager
.lock()
.unwrap()
.notify_power_button()
.map_err(Error::PowerButton)
}
} }
impl Pausable for Vm { impl Pausable for Vm {