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 <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
This commit is contained in:
Dmitry Torokhov 2022-03-21 14:23:13 -07:00 committed by Commit Bot
parent bc09a2d8aa
commit 0550775207
2 changed files with 16 additions and 8 deletions

View file

@ -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,

View file

@ -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,
);