feat(arm): convert arm platforms to expect a wakeup

Newer cores in upcoming platforms may refuse to power down. The PSCI
library is already prepared for this so convert platform code to also
allow this. This is simple - drop the `wfi` + panic and let common code
deal with the fallout. The end result will be the same (sans the
message) except the platform will have fewer responsibilities. The only
exception is for cores being signalled to power off gracefully ahead of
system reset. That path must also be terminal so replace the end with
the same psci_pwrdown_cpu_end() to behave the same as the generic
implementation. It will handle wakeups and panic, hoping that the system
gets reset from under it. The dmb is upgraded to a dsb so no functional
change.

Change-Id: I381f96bec8532bda6ccdac65de57971aac42e7e8
Signed-off-by: Boyan Karatotev <boyan.karatotev@arm.com>
diff --git a/drivers/arm/css/scp/css_pm_scmi.c b/drivers/arm/css/scp/css_pm_scmi.c
index 84b8bd2..b310ff4 100644
--- a/drivers/arm/css/scp/css_pm_scmi.c
+++ b/drivers/arm/css/scp/css_pm_scmi.c
@@ -298,7 +298,7 @@
 #endif
 }
 
-void __dead2 css_scp_system_off(int state)
+void css_scp_system_off(int state)
 {
 	int ret;
 
@@ -340,15 +340,12 @@
 
 	/* Powerdown of primary core */
 	psci_pwrdown_cpu_start(PLAT_MAX_PWR_LVL);
-	wfi();
-	ERROR("CSS set power state: operation not handled.\n");
-	panic();
 }
 
 /*
  * Helper function to shutdown the system via SCMI.
  */
-void __dead2 css_scp_sys_shutdown(void)
+void css_scp_sys_shutdown(void)
 {
 	css_scp_system_off(SCMI_SYS_PWR_SHUTDOWN);
 }
@@ -356,7 +353,7 @@
 /*
  * Helper function to reset the system via SCMI.
  */
-void __dead2 css_scp_sys_reboot(void)
+void css_scp_sys_reboot(void)
 {
 	css_scp_system_off(SCMI_SYS_PWR_COLD_RESET);
 }
@@ -472,12 +469,8 @@
 		return PSCI_E_INVALID_PARAMS;
 
 	css_scp_system_off(SCMI_SYS_PWR_WARM_RESET);
-	/*
-	 * css_scp_system_off cannot return (it is a __dead function),
-	 * but css_system_reset2 has to return some value, even in
-	 * this case.
-	 */
-	return 0;
+	/* return SUCCESS to finish the powerdown */
+	return PSCI_E_SUCCESS;
 }
 
 #if PROGRAMMABLE_RESET_ADDRESS
diff --git a/drivers/arm/css/scp/css_pm_scpi.c b/drivers/arm/css/scp/css_pm_scpi.c
index b4019ce..02be070 100644
--- a/drivers/arm/css/scp/css_pm_scpi.c
+++ b/drivers/arm/css/scp/css_pm_scpi.c
@@ -117,7 +117,7 @@
 /*
  * Helper function to shutdown the system via SCPI.
  */
-void __dead2 css_scp_sys_shutdown(void)
+void css_scp_sys_shutdown(void)
 {
 	uint32_t response;
 
@@ -134,15 +134,12 @@
 		ERROR("CSS System Off: SCP error %u.\n", response);
 		panic();
 	}
-	wfi();
-	ERROR("CSS System Off: operation not handled.\n");
-	panic();
 }
 
 /*
  * Helper function to reset the system via SCPI.
  */
-void __dead2 css_scp_sys_reboot(void)
+void css_scp_sys_reboot(void)
 {
 	uint32_t response;
 
@@ -159,7 +156,4 @@
 		ERROR("CSS System Reset: SCP error %u.\n", response);
 		panic();
 	}
-	wfi();
-	ERROR("CSS System Reset: operation not handled.\n");
-	panic();
 }
diff --git a/include/drivers/arm/css/css_scp.h b/include/drivers/arm/css/css_scp.h
index 2b506ea..5395546 100644
--- a/include/drivers/arm/css/css_scp.h
+++ b/include/drivers/arm/css/css_scp.h
@@ -22,9 +22,9 @@
 void css_scp_off(const struct psci_power_state *target_state);
 void css_scp_on(u_register_t mpidr);
 int css_scp_get_power_state(u_register_t mpidr, unsigned int power_level);
-void __dead2 css_scp_sys_shutdown(void);
-void __dead2 css_scp_sys_reboot(void);
-void __dead2 css_scp_system_off(int state);
+void css_scp_sys_shutdown(void);
+void css_scp_sys_reboot(void);
+void css_scp_system_off(int state);
 
 /* API for SCP Boot Image transfer. Return 0 on success, -1 on error */
 int css_scp_boot_image_xfer(void *image, unsigned int image_size);
diff --git a/include/plat/arm/css/common/css_pm.h b/include/plat/arm/css/common/css_pm.h
index 84e6b38..d5a3c42 100644
--- a/include/plat/arm/css/common/css_pm.h
+++ b/include/plat/arm/css/common/css_pm.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2022, Arm Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -35,8 +35,8 @@
 void css_pwr_domain_suspend(const psci_power_state_t *target_state);
 void css_pwr_domain_suspend_finish(
 				const psci_power_state_t *target_state);
-void __dead2 css_system_off(void);
-void __dead2 css_system_reset(void);
+void css_system_off(void);
+void css_system_reset(void);
 void css_cpu_standby(plat_local_state_t cpu_state);
 void css_get_sys_suspend_power_state(psci_power_state_t *req_state);
 int css_node_hw_state(u_register_t mpidr, unsigned int power_level);
diff --git a/plat/arm/board/corstone1000/common/corstone1000_pm.c b/plat/arm/board/corstone1000/common/corstone1000_pm.c
index bd3faec..5264187 100644
--- a/plat/arm/board/corstone1000/common/corstone1000_pm.c
+++ b/plat/arm/board/corstone1000/common/corstone1000_pm.c
@@ -14,7 +14,7 @@
  * platform layer will take care of registering the handlers with PSCI.
  ******************************************************************************/
 
-static void __dead2 corstone1000_system_reset(void)
+static void corstone1000_system_reset(void)
 {
 
 	uint32_t volatile * const watchdog_ctrl_reg = (uint32_t *) SECURE_WATCHDOG_ADDR_CTRL_REG;
@@ -31,9 +31,6 @@
 
 	*(watchdog_val_reg) = SECURE_WATCHDOG_COUNTDOWN_VAL;
 	*watchdog_ctrl_reg = SECURE_WATCHDOG_MASK_ENABLE;
-	while (1) {
-		wfi();
-	}
 }
 
 #if defined(CORSTONE1000_FVP_MULTICORE)
diff --git a/plat/arm/board/fvp/fvp_pm.c b/plat/arm/board/fvp/fvp_pm.c
index 80dfd2a..2a0bb93 100644
--- a/plat/arm/board/fvp/fvp_pm.c
+++ b/plat/arm/board/fvp/fvp_pm.c
@@ -295,28 +295,22 @@
 /*******************************************************************************
  * FVP handlers to shutdown/reboot the system
  ******************************************************************************/
-static void __dead2 fvp_system_off(void)
+static void fvp_system_off(void)
 {
 	/* Write the System Configuration Control Register */
 	mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL,
 		V2M_CFGCTRL_START |
 		V2M_CFGCTRL_RW |
 		V2M_CFGCTRL_FUNC(V2M_FUNC_SHUTDOWN));
-	wfi();
-	ERROR("FVP System Off: operation not handled.\n");
-	panic();
 }
 
-static void __dead2 fvp_system_reset(void)
+static void fvp_system_reset(void)
 {
 	/* Write the System Configuration Control Register */
 	mmio_write_32(V2M_SYSREGS_BASE + V2M_SYS_CFGCTRL,
 		V2M_CFGCTRL_START |
 		V2M_CFGCTRL_RW |
 		V2M_CFGCTRL_FUNC(V2M_FUNC_REBOOT));
-	wfi();
-	ERROR("FVP System Reset: operation not handled.\n");
-	panic();
 }
 
 static int fvp_node_hw_state(u_register_t target_cpu,
diff --git a/plat/arm/css/common/css_pm.c b/plat/arm/css/common/css_pm.c
index 8ddd7a4..f8bc542 100644
--- a/plat/arm/css/common/css_pm.c
+++ b/plat/arm/css/common/css_pm.c
@@ -217,12 +217,12 @@
 /*******************************************************************************
  * Handlers to shutdown/reboot the system
  ******************************************************************************/
-void __dead2 css_system_off(void)
+void css_system_off(void)
 {
 	css_scp_sys_shutdown();
 }
 
-void __dead2 css_system_reset(void)
+void css_system_reset(void)
 {
 	css_scp_sys_reboot();
 }
@@ -366,9 +366,7 @@
 
 	psci_pwrdown_cpu_start(PLAT_MAX_PWR_LVL);
 
-	dmbsy();
-
-	wfi();
+	psci_pwrdown_cpu_end_terminal();
 	return 0;
 }