mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-19 11:04:20 +00:00

The simplistic view of a core's powerdown sequence is that power is atomically cut upon calling `wfi`. However, it turns out that it has lots to do - it has to talk to the interconnect to exit coherency, clean caches, check for RAS errors, etc. These take significant amounts of time and are certainly not atomic. As such there is a significant window of opportunity for external events to happen. Many of these steps are not destructive to context, so theoretically, the core can just "give up" half way (or roll certain actions back) and carry on running. The point in this sequence after which roll back is not possible is called the point of no return. One of these actions is the checking for RAS errors. It is possible for one to happen during this lengthy sequence, or at least remain undiscovered until that point. If the core were to continue powerdown when that happens, there would be no (easy) way to inform anyone about it. Rejecting the powerdown and letting software handle the error is the best way to implement this. Arm cores since at least the a510 have included this exact feature. So far it hasn't been deemed necessary to account for it in firmware due to the low likelihood of this happening. However, events like GIC wakeup requests are much more probable. Older cores will powerdown and immediately power back up when this happens. Travis and Gelas include a feature similar to the RAS case above, called powerdown abandon. The idea is that this will improve the latency to service the interrupt by saving on work which the core and software need to do. So far firmware has relied on the `wfi` being the point of no return and if it doesn't explicitly detect a pending interrupt quite early on, it will embark onto a sequence that it expects to end with shutdown. To accommodate for it not being a point of no return, we must undo all of the system management we did, just like in the warm boot entrypoint. To achieve that, the pwr_domain_pwr_down_wfi hook must not be terminal. Most recent platforms do some platform management and finish on the standard `wfi`, followed by a panic or an endless loop as this is expected to not return. To make this generic, any platform that wishes to support wakeups must instead let common code call `psci_power_down_wfi()` right after. Besides wakeups, this lets common code handle powerdown errata better as well. Then, the CPU_OFF case is simple - PSCI does not allow it to return. So the best that can be done is to attempt the `wfi` a few times (the choice of 32 is arbitrary) in the hope that the wakeup is transient. If it isn't, the only choice is to panic, as the system is likely to be in a bad state, eg. interrupts weren't routed away. The same applies for SYSTEM_OFF, SYSTEM_RESET, and SYSTEM_RESET2. There the panic won't matter as the system is going offline one way or another. The RAS case will be considered in a separate patch. Now, the CPU_SUSPEND case is more involved. First, to powerdown it must wipe its context as it is not written on warm boot. But it cannot be overwritten in case of a wakeup. To avoid the catch 22, save a copy that will only be used if powerdown fails. That is about 500 bytes on the stack so it hopefully doesn't tip anyone over any limits. In future that can be avoided by having a core manage its own context. Second, when the core wakes up, it must undo anything it did to prepare for poweroff, which for the cores we care about, is writing CPUPWRCTLR_EL1.CORE_PWRDN_EN. The least intrusive for the cpu library way of doing this is to simply call the power off hook again and have the hook toggle the bit. If in the future there need to be more complex sequences, their direction can be advised on the value of this bit. Third, do the actual "resume". Most of the logic is already there for the retention suspend, so that only needs a small touch up to apply to the powerdown case as well. The missing bit is the powerdown specific state management. Luckily, the warmboot entrypoint does exactly that already too, so steal that and we're done. All of this is hidden behind a FEAT_PABANDON flag since it has a large memory and runtime cost that we don't want to burden non pabandon cores with. Finally, do some function renaming to better reflect their purpose and make names a little bit more consistent. Change-Id: I2405b59300c2e24ce02e266f91b7c51474c1145f Signed-off-by: Boyan Karatotev <boyan.karatotev@arm.com>
104 lines
3.7 KiB
C
104 lines
3.7 KiB
C
/*
|
|
* Copyright (c) 2017-2024, Arm Limited and Contributors. All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef PSCI_LIB_H
|
|
#define PSCI_LIB_H
|
|
|
|
#include <common/ep_info.h>
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
#include <cdefs.h>
|
|
#include <stdint.h>
|
|
|
|
/*******************************************************************************
|
|
* Optional structure populated by the Secure Payload Dispatcher to be given a
|
|
* chance to perform any bookkeeping before PSCI executes a power management
|
|
* operation. It also allows PSCI to determine certain properties of the SP e.g.
|
|
* migrate capability etc.
|
|
******************************************************************************/
|
|
typedef struct spd_pm_ops {
|
|
void (*svc_on)(u_register_t target_cpu);
|
|
int32_t (*svc_off)(u_register_t __unused unused);
|
|
void (*svc_suspend)(u_register_t max_off_pwrlvl);
|
|
void (*svc_on_finish)(u_register_t __unused unused);
|
|
void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
|
|
int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
|
|
int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
|
|
void (*svc_system_off)(void);
|
|
void (*svc_system_reset)(void);
|
|
} spd_pm_ops_t;
|
|
|
|
/*
|
|
* Function prototype for the warmboot entrypoint function which will be
|
|
* programmed in the mailbox by the platform.
|
|
*/
|
|
typedef void (*mailbox_entrypoint_t)(void);
|
|
|
|
/******************************************************************************
|
|
* Structure to pass PSCI Library arguments.
|
|
*****************************************************************************/
|
|
typedef struct psci_lib_args {
|
|
/* The version information of PSCI Library Interface */
|
|
param_header_t h;
|
|
/* The warm boot entrypoint function */
|
|
mailbox_entrypoint_t mailbox_ep;
|
|
} psci_lib_args_t;
|
|
|
|
/* Helper macro to set the psci_lib_args_t structure at runtime */
|
|
#define SET_PSCI_LIB_ARGS_V1(_p, _entry) do { \
|
|
SET_PARAM_HEAD(_p, PARAM_PSCI_LIB_ARGS, VERSION_1, 0); \
|
|
(_p)->mailbox_ep = (_entry); \
|
|
} while (0)
|
|
|
|
/* Helper macro to define the psci_lib_args_t statically */
|
|
#define DEFINE_STATIC_PSCI_LIB_ARGS_V1(_name, _entry) \
|
|
static const psci_lib_args_t (_name) = { \
|
|
.h.type = (uint8_t)PARAM_PSCI_LIB_ARGS, \
|
|
.h.version = (uint8_t)VERSION_1, \
|
|
.h.size = (uint16_t)sizeof(_name), \
|
|
.h.attr = 0U, \
|
|
.mailbox_ep = (_entry) \
|
|
}
|
|
|
|
/* Helper macro to verify the pointer to psci_lib_args_t structure */
|
|
#define VERIFY_PSCI_LIB_ARGS_V1(_p) (((_p) != NULL) \
|
|
&& ((_p)->h.type == PARAM_PSCI_LIB_ARGS) \
|
|
&& ((_p)->h.version == VERSION_1) \
|
|
&& ((_p)->h.size == sizeof(*(_p))) \
|
|
&& ((_p)->h.attr == 0) \
|
|
&& ((_p)->mailbox_ep != NULL))
|
|
|
|
/******************************************************************************
|
|
* PSCI Library Interfaces
|
|
*****************************************************************************/
|
|
u_register_t psci_smc_handler(uint32_t smc_fid,
|
|
u_register_t x1,
|
|
u_register_t x2,
|
|
u_register_t x3,
|
|
u_register_t x4,
|
|
void *cookie,
|
|
void *handle,
|
|
u_register_t flags);
|
|
int psci_setup(const psci_lib_args_t *lib_args);
|
|
int psci_secondaries_brought_up(void);
|
|
void psci_warmboot_entrypoint(void);
|
|
void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
|
|
void psci_prepare_next_non_secure_ctx(
|
|
entry_point_info_t *next_image_info);
|
|
int psci_stop_other_cores(unsigned int this_cpu_idx, unsigned int wait_ms,
|
|
void (*stop_func)(u_register_t mpidr));
|
|
bool psci_is_last_on_cpu_safe(unsigned int this_core);
|
|
bool psci_are_all_cpus_on_safe(unsigned int this_core);
|
|
void psci_pwrdown_cpu(unsigned int power_level);
|
|
void psci_pwrdown_cpu_start(unsigned int power_level);
|
|
void __dead2 psci_pwrdown_cpu_end_terminal(void);
|
|
void psci_pwrdown_cpu_end_wakeup(unsigned int power_level);
|
|
void psci_do_manage_extensions(void);
|
|
|
|
#endif /* __ASSEMBLER__ */
|
|
|
|
#endif /* PSCI_LIB_H */
|