diff options
author | Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> | 2020-02-12 21:58:47 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-19 10:38:04 +0000 |
commit | 546f01cb96b0b2c688257371608c64db78b5d31a (patch) | |
tree | a47c679e7cfff5977b99af7b7444c05f30ebaccb /devices/src | |
parent | 80a8d52fac83f5f6cd0187ebcbab6e1e5bd8586f (diff) | |
download | crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.gz crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.bz2 crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.lz crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.xz crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.tar.zst crosvm-546f01cb96b0b2c688257371608c64db78b5d31a.zip |
acpipm: implement suspend and resume mechanism
For suspend request from VM, will write suspend event and notify crosvm main process to pause VCPUs. For resume request, it is not from VM itself but by the resume command through crosvm socket. Resume request will notify the PM device to fill its wakeup registers with wakeup event so that when VCPUs start to run, VM can know there is wakeup from outside. BUG=chromium:1018674 TEST=cargo test -p devices Change-Id: I4724ffee10150065a62bf520076c16cbc70b7749 Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035169 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
Diffstat (limited to 'devices/src')
-rw-r--r-- | devices/src/acpi.rs | 14 | ||||
-rw-r--r-- | devices/src/bus.rs | 24 | ||||
-rw-r--r-- | devices/src/lib.rs | 2 |
3 files changed, 38 insertions, 2 deletions
diff --git a/devices/src/acpi.rs b/devices/src/acpi.rs index 983e635..6d36353 100644 --- a/devices/src/acpi.rs +++ b/devices/src/acpi.rs @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -use crate::BusDevice; +use crate::{BusDevice, BusResumeDevice}; use sys_util::{error, warn, EventFd}; /// ACPI PM resource for handling OS suspend/resume request @@ -41,6 +41,8 @@ const SLEEP_CONTROL: u16 = 6; const SLEEP_STATUS: u16 = 7; const BITMASK_PM1CNT_SLEEP_ENABLE: u16 = 0x2000; const BITMASK_SLEEPCNT_SLEEP_ENABLE: u8 = 0x20; +const BITMASK_PM1CNT_WAKE_STATUS: u16 = 0x8000; +const BITMASK_SLEEPCNT_WAKE_STATUS: u8 = 0x80; impl BusDevice for ACPIPMResource { fn debug_label(&self) -> String { @@ -113,3 +115,13 @@ impl BusDevice for ACPIPMResource { }; } } + +impl BusResumeDevice for ACPIPMResource { + fn resume_imminent(&mut self) { + let val = self.pm1_status; + self.pm1_status = val | BITMASK_PM1CNT_WAKE_STATUS; + + let val = self.sleep_status; + self.sleep_status = val | BITMASK_SLEEPCNT_WAKE_STATUS; + } +} diff --git a/devices/src/bus.rs b/devices/src/bus.rs index d4b46eb..3f93974 100644 --- a/devices/src/bus.rs +++ b/devices/src/bus.rs @@ -37,6 +37,12 @@ pub trait BusDevice: Send { fn on_sandboxed(&mut self) {} } +pub trait BusResumeDevice: Send { + /// notify the devices which are invoked + /// before the VM resumes form suspend. + fn resume_imminent(&mut self) {} +} + #[derive(Debug)] pub enum Error { /// The insertion failed because the new device overlapped with an old device. @@ -104,9 +110,13 @@ impl PartialOrd for BusRange { /// /// This doesn't have any restrictions on what kind of device or address space this applies to. The /// only restriction is that no two devices can overlap in this address space. +/// +/// the 'resume_notify_devices' contains the devices which requires to be notified before the system +/// resume back from S3 suspended state. #[derive(Clone)] pub struct Bus { devices: BTreeMap<BusRange, Arc<Mutex<dyn BusDevice>>>, + resume_notify_devices: Vec<Arc<Mutex<dyn BusResumeDevice>>>, } impl Bus { @@ -114,6 +124,7 @@ impl Bus { pub fn new() -> Bus { Bus { devices: BTreeMap::new(), + resume_notify_devices: Vec::new(), } } @@ -208,6 +219,19 @@ impl Bus { false } } + + /// Register `device` for notifications of VM resume from suspend. + pub fn notify_on_resume(&mut self, device: Arc<Mutex<dyn BusResumeDevice>>) { + self.resume_notify_devices.push(device); + } + + /// Call `notify_resume` to notify the device that suspend resume is imminent. + pub fn notify_resume(&mut self) { + let devices = self.resume_notify_devices.clone(); + for dev in devices { + dev.lock().resume_imminent(); + } + } } #[cfg(test)] diff --git a/devices/src/lib.rs b/devices/src/lib.rs index 3d6d21f..174b956 100644 --- a/devices/src/lib.rs +++ b/devices/src/lib.rs @@ -25,7 +25,7 @@ pub mod virtio; pub use self::acpi::ACPIPMResource; pub use self::bus::Error as BusError; -pub use self::bus::{Bus, BusDevice, BusRange}; +pub use self::bus::{Bus, BusDevice, BusRange, BusResumeDevice}; pub use self::cmos::Cmos; pub use self::i8042::I8042Device; pub use self::ioapic::Ioapic; |