From 2bb153de2be477be5e222453b4c4ac42868d7317 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Sun, 7 Mar 2021 21:39:11 +0800 Subject: [PATCH] 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 --- devices/src/legacy/mod.rs | 2 ++ vmm/src/device_manager.rs | 16 ++++++++++++++++ vmm/src/vm.rs | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/devices/src/legacy/mod.rs b/devices/src/legacy/mod.rs index 21e254d33..15885e820 100644 --- a/devices/src/legacy/mod.rs +++ b/devices/src/legacy/mod.rs @@ -25,6 +25,8 @@ pub use self::fwdebug::FwDebugDevice; pub use self::i8042::I8042Device; pub use self::serial::Serial; +#[cfg(target_arch = "aarch64")] +pub use self::gpio_pl061::Error as GPIODeviceError; #[cfg(target_arch = "aarch64")] pub use self::gpio_pl061::GPIO; #[cfg(target_arch = "aarch64")] diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 119642813..a138a138c 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -403,6 +403,10 @@ pub enum DeviceManagerError { /// Failed to do power button notification 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 SetDirectIo, @@ -3521,6 +3525,7 @@ impl DeviceManager { } #[cfg(feature = "acpi")] + #[cfg(target_arch = "x86_64")] pub fn notify_power_button(&self) -> DeviceManagerResult<()> { self.ged_notification_device .as_ref() @@ -3530,6 +3535,17 @@ impl DeviceManager { .notify(AcpiNotificationFlags::POWER_BUTTON_CHANGED) .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")] diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 78c55e26c..7ad05864f 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -2038,6 +2038,7 @@ impl Vm { .map_err(Error::ActivateVirtioDevices) } + #[cfg(target_arch = "x86_64")] pub fn power_button(&self) -> Result<()> { #[cfg(feature = "acpi")] return self @@ -2049,6 +2050,15 @@ impl Vm { #[cfg(not(feature = "acpi"))] 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 {