diff options
author | Peter Marheine <pmarheine@chromium.org> | 2022-07-07 10:23:49 +1000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-15 01:21:39 +0000 |
commit | d6d63d208d734097b75d9d66c1bfc657b6176db9 (patch) | |
tree | 45ad711f7d2011aa0f6f205468dfe50d68b40531 /zephyr/subsys | |
parent | 6bbe76ff8b057d62f0f84dd2e9a36a7f525d25f0 (diff) | |
download | chrome-ec-d6d63d208d734097b75d9d66c1bfc657b6176db9.tar.gz |
ap_pwrseq: add an explicit "uninitialized" state
It's possible for callers to request the AP state before the power state
machine is ready, which without an UNINIT state can cause incorrect
behavior because the initial (zero-initialized) state is G3.
BUG=none
TEST=zmake build nereid
BRANCH=none
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: Ib6e9158214c321943a63fff05e0f69224c5f9ae9
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3750257
Reviewed-by: Andrew McRae <amcrae@google.com>
Diffstat (limited to 'zephyr/subsys')
-rw-r--r-- | zephyr/subsys/ap_pwrseq/ap_power_interface.c | 10 | ||||
-rw-r--r-- | zephyr/subsys/ap_pwrseq/x86_non_dsx_common_pwrseq_sm_handler.c | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/zephyr/subsys/ap_pwrseq/ap_power_interface.c b/zephyr/subsys/ap_pwrseq/ap_power_interface.c index 69b2ddab9e..6186e299dd 100644 --- a/zephyr/subsys/ap_pwrseq/ap_power_interface.c +++ b/zephyr/subsys/ap_pwrseq/ap_power_interface.c @@ -6,11 +6,17 @@ #include <ap_power/ap_power_interface.h> #include <x86_non_dsx_common_pwrseq_sm_handler.h> +LOG_MODULE_DECLARE(ap_pwrseq, CONFIG_AP_PWRSEQ_LOG_LEVEL); + bool ap_power_in_state(enum ap_power_state_mask state_mask) { int need_mask = 0; switch (pwr_sm_get_state()) { + case SYS_POWER_STATE_UNINIT: + LOG_WRN("%s: init not yet complete; AP state is unknown", + __func__); + return false; case SYS_POWER_STATE_G3: need_mask = AP_POWER_STATE_HARD_OFF; break; @@ -59,6 +65,10 @@ bool ap_power_in_state(enum ap_power_state_mask state_mask) bool ap_power_in_or_transitioning_to_state(enum ap_power_state_mask state_mask) { switch (pwr_sm_get_state()) { + case SYS_POWER_STATE_UNINIT: + LOG_WRN("%s: init not yet complete; AP state is unknown", + __func__); + return 0; case SYS_POWER_STATE_G3: case SYS_POWER_STATE_S5G3: return state_mask & AP_POWER_STATE_HARD_OFF; diff --git a/zephyr/subsys/ap_pwrseq/x86_non_dsx_common_pwrseq_sm_handler.c b/zephyr/subsys/ap_pwrseq/x86_non_dsx_common_pwrseq_sm_handler.c index 2bbcce4d39..dd4b2e4e66 100644 --- a/zephyr/subsys/ap_pwrseq/x86_non_dsx_common_pwrseq_sm_handler.c +++ b/zephyr/subsys/ap_pwrseq/x86_non_dsx_common_pwrseq_sm_handler.c @@ -10,7 +10,9 @@ static K_KERNEL_STACK_DEFINE(pwrseq_thread_stack, CONFIG_AP_PWRSEQ_STACK_SIZE); static struct k_thread pwrseq_thread_data; -static struct pwrseq_context pwrseq_ctx; +static struct pwrseq_context pwrseq_ctx = { + .power_state = SYS_POWER_STATE_UNINIT, +}; /* S5 inactive timer*/ K_TIMER_DEFINE(s5_inactive_timer, NULL, NULL); /* @@ -31,6 +33,7 @@ LOG_MODULE_REGISTER(ap_pwrseq, CONFIG_AP_PWRSEQ_LOG_LEVEL); * @brief power_state names for debug */ static const char *const pwrsm_dbg[] = { + [SYS_POWER_STATE_UNINIT] = "Unknown", [SYS_POWER_STATE_G3] = "G3", [SYS_POWER_STATE_S5] = "S5", [SYS_POWER_STATE_S4] = "S4", |