From 0550775207bb29c5fdcc64150456c2011952129d Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 21 Mar 2022 14:23:13 -0700 Subject: [PATCH] devices: acpi: ensure that both direct GPE and host SCI are supplied Rearrange the code to make sure that if direct GPE feature is used then it is enforced that both host SCI events and GPE list are supplied when instantiating ACPIPMResource. BUG=None TEST=./tools/presubmit Change-Id: Ib44e217b09344b1c6bed091312eb196863ca2fee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3537264 Reviewed-by: Daniel Verkamp Tested-by: kokoro Commit-Queue: Dmitry Torokhov --- devices/src/acpi.rs | 16 +++++++++++++--- x86_64/src/lib.rs | 8 +++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/devices/src/acpi.rs b/devices/src/acpi.rs index fa075cc9ff..194cdd5e00 100644 --- a/devices/src/acpi.rs +++ b/devices/src/acpi.rs @@ -67,12 +67,13 @@ pub struct ACPIPMResource { impl ACPIPMResource { /// Constructs ACPI Power Management Resouce. + /// + /// `direct_gpe_info` - tuple of host SCI trigger and resample events, and list of direct GPEs #[allow(dead_code)] pub fn new( sci_evt: Event, sci_evt_resample: Event, - #[cfg(feature = "direct")] sci_direct_evt: Option<(Event, Event)>, - #[cfg(feature = "direct")] direct_gpe: &[u32], + #[cfg(feature = "direct")] direct_gpe_info: Option<(Event, Event, &[u32])>, suspend_evt: Event, exit_evt: Event, ) -> ACPIPMResource { @@ -86,13 +87,22 @@ impl ACPIPMResource { enable: Default::default(), }; + #[cfg(feature = "direct")] + let (sci_direct_evt, direct_gpe) = if let Some(info) = direct_gpe_info { + let (trigger_evt, resample_evt, gpes) = info; + let gpe_vec = gpes.iter().map(|gpe| DirectGpe::new(*gpe)).collect(); + (Some((trigger_evt, resample_evt)), gpe_vec) + } else { + (None, Vec::new()) + }; + ACPIPMResource { sci_evt, sci_evt_resample, #[cfg(feature = "direct")] sci_direct_evt, #[cfg(feature = "direct")] - direct_gpe: direct_gpe.iter().map(|gpe| DirectGpe::new(*gpe)).collect(), + direct_gpe, kill_evt: None, worker_thread: None, suspend_evt, diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs index f41d853467..788fc8e65a 100644 --- a/x86_64/src/lib.rs +++ b/x86_64/src/lib.rs @@ -1317,7 +1317,7 @@ impl X8664arch { .map_err(Error::RegisterIrqfd)?; #[cfg(feature = "direct")] - let sci_direct = if direct_gpe.is_empty() { + let direct_gpe_info = if direct_gpe.is_empty() { None } else { let direct_sci_evt = Event::new().map_err(Error::CreateEvent)?; @@ -1341,16 +1341,14 @@ impl X8664arch { .map_err(Error::CreateGpe)?; } - Some((direct_sci_evt, direct_sci_evt_resample)) + Some((direct_sci_evt, direct_sci_evt_resample, direct_gpe)) }; let mut pmresource = devices::ACPIPMResource::new( pm_sci_evt, pm_sci_evt_resample, #[cfg(feature = "direct")] - sci_direct, - #[cfg(feature = "direct")] - direct_gpe, + direct_gpe_info, suspend_evt, exit_evt, );