arm-trusted-firmware/lib/cpus/aarch64
Boyan Karatotev 2b5e00d4ea feat(psci): allow cores to wake up from powerdown
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>
2025-02-03 14:29:47 +00:00
..
a64fx.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
aem_generic.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a35.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a53.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a55.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a57.S chore(cpus): optimise runtime errata applications 2024-10-16 13:59:57 +01:00
cortex_a65.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a65ae.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a72.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a73.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a75.S fix(cpus): modify the fix for Cortex-A75 erratum 764081 2024-10-03 10:07:47 -05:00
cortex_a75_pubsub.c chore: update to use Arm word across TF-A 2023-08-08 15:12:30 +01:00
cortex_a76.S chore(cpus): optimise runtime errata applications 2024-10-16 13:59:57 +01:00
cortex_a76ae.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a77.S fix(cpus): workaround for CVE-2024-5660 for Cortex-A77 2024-12-17 10:28:09 -06:00
cortex_a78.S fix(cpus): workaround for CVE-2024-5660 for Cortex-A78 2024-12-17 10:28:09 -06:00
cortex_a78_ae.S fix(cpus): workaround for CVE-2024-5660 for Cortex-A78_AE 2024-12-17 10:28:09 -06:00
cortex_a78c.S fix(cpus): workaround for CVE-2024-5660 for Cortex-A78C 2024-12-17 10:28:09 -06:00
cortex_a510.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a520.S Merge changes from topic "clean-up-errata-compatibility" into integration 2024-08-27 16:23:58 +02:00
cortex_a710.S refactor(cpus): undo errata mitigations 2025-02-03 07:37:58 +00:00
cortex_a715.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_a720.S Merge changes from topic "clean-up-errata-compatibility" into integration 2024-08-27 16:23:58 +02:00
cortex_a720_ae.S feat(cpus): add support for cortex-a720ae 2024-10-21 15:20:34 +01:00
cortex_a725.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
cortex_alto.S feat(cpus): add support for Alto CPU 2024-12-05 16:22:29 +01:00
cortex_arcadia.S feat(cpus): add support for arcadia cpu 2024-10-17 09:34:03 -05:00
cortex_gelas.S feat(psci): allow cores to wake up from powerdown 2025-02-03 14:29:47 +00:00
cortex_x1.S fix(cpus): workaround for CVE-2024-5660 for Cortex-X1 2024-12-17 10:28:09 -06:00
cortex_x2.S fix(cpus): workaround for CVE-2024-5660 for Cortex-X2 2024-12-17 10:28:09 -06:00
cortex_x3.S refactor(cpus): undo errata mitigations 2025-02-03 07:37:58 +00:00
cortex_x4.S fix(security): apply SMCCC_ARCH_WORKAROUND_4 to affected cpus 2025-01-30 16:45:35 -06:00
cortex_x925.S fix(security): apply SMCCC_ARCH_WORKAROUND_4 to affected cpus 2025-01-30 16:45:35 -06:00
cpu_helpers.S fix(security): apply SMCCC_ARCH_WORKAROUND_4 to affected cpus 2025-01-30 16:45:35 -06:00
cpuamu.c Sanitise includes across codebase 2019-01-04 10:43:17 +00:00
cpuamu_helpers.S chore: update to use Arm word across TF-A 2023-08-08 15:12:30 +01:00
denver.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
dsu_helpers.S feat(rockchip): add RK3566/RK3568 Socs support 2024-06-07 11:59:46 +02:00
generic.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
neoverse_e1.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
neoverse_n1.S chore(cpus): optimise runtime errata applications 2024-10-16 13:59:57 +01:00
neoverse_n1_pubsub.c chore: update to use Arm word across TF-A 2023-08-08 15:12:30 +01:00
neoverse_n2.S refactor(cpus): undo errata mitigations 2025-02-03 07:37:58 +00:00
neoverse_n3.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
neoverse_n_common.S Add support for Neoverse-N2 CPUs. 2020-11-30 19:12:56 +00:00
neoverse_v1.S fix(cpus): workaround for CVE-2024-5660 for Neoverse-V1 2024-12-17 10:28:09 -06:00
neoverse_v2.S fix(security): apply SMCCC_ARCH_WORKAROUND_4 to affected cpus 2025-01-30 16:45:35 -06:00
neoverse_v3.S fix(security): apply SMCCC_ARCH_WORKAROUND_4 to affected cpus 2025-01-30 16:45:35 -06:00
nevis.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
qemu_max.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
rainier.S refactor(cpus): remove cpu specific errata funcs 2024-07-26 11:19:52 +01:00
travis.S feat(psci): allow cores to wake up from powerdown 2025-02-03 14:29:47 +00:00
wa_cve_2017_5715_bpiall.S chore: update to use Arm word across TF-A 2023-08-08 15:12:30 +01:00
wa_cve_2017_5715_mmu.S chore: update to use Arm word across TF-A 2023-08-08 15:12:30 +01:00
wa_cve_2022_23960_bhb.S chore: update to use Arm word across TF-A 2023-08-08 15:12:30 +01:00
wa_cve_2022_23960_bhb_vector.S fix(security): workaround for CVE-2022-23960 2022-03-10 23:57:14 -06:00