Skip to content

Commit

Permalink
arm64: implement arch_system_halt
Browse files Browse the repository at this point in the history
When PSCI is enabled, implement `arch_system_halt` using
PSCI_SHUTDOWN.

Signed-off-by: Henri Xavier <[email protected]>
  • Loading branch information
Henri Xavier authored and carlescufi committed Nov 23, 2022
1 parent 7668bd3 commit b54ba98
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion arch/arm64/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
* exceptions
*/

#include <zephyr/drivers/pm_cpu_ops.h>
#include <zephyr/exc_handle.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/exc_handle.h>

LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);

Expand Down Expand Up @@ -278,3 +279,17 @@ FUNC_NORETURN void arch_syscall_oops(void *ssf_ptr)
CODE_UNREACHABLE;
}
#endif

#if defined(CONFIG_PM_CPU_OPS_PSCI)
FUNC_NORETURN void arch_system_halt(unsigned int reason)
{
ARG_UNUSED(reason);

(void)arch_irq_lock();
(void)pm_system_off();

for (;;) {
/* Spin endlessly as fallback */
}
}
#endif
14 changes: 14 additions & 0 deletions drivers/pm_cpu_ops/pm_cpu_ops_psci.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ int pm_cpu_on(unsigned long cpuid,
return psci_to_dev_err(ret);
}

int pm_system_off(void)
{
int ret;

if (psci_data.conduit == SMCCC_CONDUIT_NONE) {
return -EINVAL;
}

/* A compliant PSCI implementation will never return from this call */
ret = psci_data.invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);

return psci_to_dev_err(ret);
}

static unsigned long __invoke_psci_fn_hvc(unsigned long function_id,
unsigned long arg0,
unsigned long arg1,
Expand Down
12 changes: 12 additions & 0 deletions include/zephyr/drivers/pm_cpu_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ int pm_cpu_off(void);
*/
int pm_cpu_on(unsigned long cpuid, uintptr_t entry_point);

/**
* @brief Power down the system
*
* This call is used to power down the whole system.
*
* A compliant PSCI implementation will never return, but some real-world
* implementations do return errors in some cases.
*
* @retval does not return on success, a negative errno otherwise
* @retval -ENOTSUP If the operation is not supported
*/
int pm_system_off(void);

#ifdef __cplusplus
}
Expand Down

0 comments on commit b54ba98

Please sign in to comment.