arm-trusted-firmware/drivers
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
..
allwinner refactor(allwinner): use fdt_node_is_enabled() in AXP driver 2023-02-03 13:31:28 +00:00
amlogic refactor(console): disable getc() by default 2023-10-11 08:40:14 +02:00
arm feat(psci): allow cores to wake up from powerdown 2025-02-03 14:29:47 +00:00
auth refactor(mbedtls): rename default mbedtls confs 2024-12-09 15:59:45 +00:00
brcm fix(tree): correct some typos 2023-05-09 15:57:12 +01:00
cadence fix(intel): refactor SDMMC driver for Altera products 2024-10-25 09:38:51 +08:00
cfi/v2m coverity: fix MISRA violations 2020-02-18 10:47:46 -06:00
clk feat(clk): add set_rate callback 2024-06-18 17:18:31 +03:00
console refactor(console): disable getc() by default 2023-10-11 08:40:14 +02:00
coreboot/cbmem_console/aarch64 Don't return error information from console_flush 2020-10-09 10:21:50 -05:00
delay_timer refactor(delay-timer): add timer callback functions 2024-10-16 10:33:03 +02:00
fwu feat(fwu): add a function to obtain an alternate FWU bank to boot 2024-03-01 14:40:05 +05:30
gpio Sanitise includes across codebase 2019-01-04 10:43:17 +00:00
imx fix: unify fallthrough annotations 2022-12-01 16:17:24 +00:00
intel/soc/stratix10/io io: change seek offset to signed long long 2020-01-10 21:14:57 +01:00
io chore(io): remove io_dummy driver 2023-04-28 15:45:43 +02:00
marvell refactor(console): disable getc() by default 2023-10-11 08:40:14 +02:00
measured_boot feat(tc): provide target_locality info of AP FW components 2024-07-03 15:03:20 +02:00
mentor/i2c Enable -Wlogical-op always 2019-11-19 08:53:21 -06:00
mmc fix(mmc): initialises response buffer with zeros 2023-09-16 10:42:39 +00:00
mtd fix(nand): reset the SLC NAND 2023-09-27 16:21:58 +02:00
nxp feat(s32g274a): split early clock initialization 2025-01-14 13:02:51 +02:00
partition fix(guid-partition): fix unaligned access in load_mbr_header() 2024-07-04 12:33:15 +01:00
rambus drivers/rambus: add TRNG-IP-76 driver 2021-02-11 09:43:18 +00:00
renesas fix(rcar3-drivers): disable A/B loader support by default 2024-11-10 16:09:55 +01:00
rpi3 fix(rpi3): use correct define for GPIO reg_clr 2024-08-21 11:53:27 -05:00
scmi-msg feat(scmi): add scmi sensor support 2024-02-27 14:29:53 +08:00
st fix(st-ddr): move skipddc_dat definition 2024-11-04 18:45:26 +01:00
synopsys Merge changes from topic "jc/shift-overflow" into integration 2019-07-16 10:11:27 +00:00
ti/uart refactor(console): disable getc() by default 2023-10-11 08:40:14 +02:00
ufs chore(ufs): refactor ufs_get_device_info 2024-02-20 02:19:19 -08:00
usb fix(usb): correct type in message 2022-02-15 18:09:51 +01:00