From 2f33b23382c23dc0bd9800dec6f4bae9074f0229 Mon Sep 17 00:00:00 2001 From: David Cerdeira Date: Wed, 2 Oct 2024 16:42:14 +0100 Subject: [PATCH] feat(armv8/psci): Handle unexpected standby behavior The development target zcu104 does not wake up on interrupts after emiting PSCI standby calls to TF-A. We should understand why. To circunvent this, we allow platforms to delcare standby is not supported and fallback to wfi Signed-off-by: David Cerdeira --- src/arch/armv8/armv8-a/psci.c | 6 ++++++ src/arch/armv8/psci.c | 13 +++++-------- src/platform/zcu102/inc/plat/psci.h | 2 ++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/arch/armv8/armv8-a/psci.c b/src/arch/armv8/armv8-a/psci.c index 941ca164f..449b57bea 100644 --- a/src/arch/armv8/armv8-a/psci.c +++ b/src/arch/armv8/armv8-a/psci.c @@ -82,6 +82,12 @@ void psci_wake(uint32_t handler_id) int32_t psci_standby() { + /* We've observed that some platforms behave unexpectedly when performing + * standby. In these cases, after standby, the CPU cores are not awaken + * by interrupts. */ + if (!DEFINED(PLAT_PSCI_STANDBY_NOT_SUPPORTED)) { + return PSCI_E_NOT_SUPPORTED + } /* only apply request to core level */ uint32_t pwr_state_aux = PSCI_POWER_STATE_LVL_0 | PSCI_STATE_TYPE_STANDBY; diff --git a/src/arch/armv8/psci.c b/src/arch/armv8/psci.c index 7479bc68a..b47404771 100644 --- a/src/arch/armv8/psci.c +++ b/src/arch/armv8/psci.c @@ -69,14 +69,11 @@ static int32_t psci_cpu_suspend_handler(uint32_t power_state, unsigned long entr ret = psci_power_down(PSCI_WAKEUP_POWERDOWN); } else { // PSCI_STATE_TYPE_STANDBY: - /** - * TODO: ideally we would emmit a standby request to PSCI (currently, ATF), but when we - * do, we do not wake up on interrupts on the current development target zcu104. We should - * understand why. To circunvent this, we directly emmit a wfi - */ - // ret = psci_standby(); - __asm__ volatile("wfi\n\r"); - ret = PSCI_E_SUCCESS; + ret = psci_standby(); + if(ret == PSCI_E_NOT_SUPPORTED){ + __asm__ volatile("wfi\n\r"); + ret = PSCI_E_SUCCESS; + } } return ret; diff --git a/src/platform/zcu102/inc/plat/psci.h b/src/platform/zcu102/inc/plat/psci.h index 372a7390e..3e18bb6dc 100644 --- a/src/platform/zcu102/inc/plat/psci.h +++ b/src/platform/zcu102/inc/plat/psci.h @@ -13,4 +13,6 @@ #define PSCI_STATE_TYPE_POWERDOWN (1UL << 30) #define PSCI_STATE_TYPE_BIT (1UL << 30) +#define PLAT_PSCI_STANDBY_NOT_SUPPORTED + #endif // __PLAT_PSCI_H__