17.4 Secondary cores and CPU power states
After cold boot, one core is running and the rest are held somewhere. This section follows a secondary core from that holding state into the OS, and then follows any core from the OS into a low-power state and back. The PSCI interface itself (function IDs, the coordination rules at the interface level) is in 12.3. The cache and coherency steps of power-down are covered once, in 8.8. This section is about the sequence that connects them.
Naming a core: MPIDR_EL1 and affinity
PSCI, the GIC and the OS all address cores by affinity, taken from MPIDR_EL1:
| Field | Bits | Meaning |
|---|---|---|
Aff0 | [7:0] | Lowest affinity level |
Aff1 | [15:8] | |
Aff2 | [23:16] | |
MT | [24] | 1: Aff0 identifies threads of a multithreaded core, so the lowest level shares a core |
U | [30] | 1: uniprocessor system |
Aff3 | [39:32] | Highest affinity level |
The values are IMPLEMENTATION DEFINED and fixed (by hardware configuration inputs). The architecture says only that affinity levels form a hierarchy and that lower levels are more closely coupled. Two layouts appear in practice, and code that hard-codes one breaks on the other:
- Pre-DynamIQ (Cortex-A53/A57/A72 clusters):
MT=0,Aff0= core,Aff1= cluster. - DynamIQ (Cortex-A55/A76 and later, Neoverse):
MT=1even on single-threaded cores,Aff0= 0 (thread),Aff1= core,Aff2= cluster, andAff3is often used for a chip or socket (17.5).
TF-A maps an MPIDR to a linear core index with plat_core_pos_by_mpidr(). That function must reject MPIDRs that don’t exist, because PSCI CPU_ON takes an MPIDR from the Normal world and the index is used to address per-core arrays at EL3.
Security note:
plat_core_pos_by_mpidr()is an EL3 bounds check on an attacker-controlled value. A version that masks fields instead of validating them can map a craftedtarget_cpuonto another core’s index or past the end of thepsci_cpu_pd_nodesarray. When you review a new platform port, this is one of the first functions to read.
Where secondaries wait: hold pens and power-off
On cold boot, every core may leave reset together, or only the primary may. TF-A’s plat_secondary_cold_boot_setup() (step 7 in 17.1) decides what non-primary cores do:
- Powered off (FVP, most production SoCs). The secondary programs the power controller to turn itself off and executes
WFI. It comes back only throughCPU_ON, which powers it up from reset. This is the cleanest option: no code runs, and the core takes a fresh reset atRVBAR_EL3. - Hold pen (platforms without per-core power control). The secondary spins in EL3 in a
WFEloop on a per-core mailbox in Secure memory, with caches off.CPU_ONwrites the mailbox and issuesSEV. Mailbox writes must be visible to a core that reads with the MMU and caches off, so the writer cleans the line to the PoC (or the mailbox is mapped Non-cacheable), then issuesDSBandSEV(7.10).
Linux supports two enable methods (17.6):
enable-method = "psci" | enable-method = "spin-table" | |
|---|---|---|
| Where the secondary waits | In firmware (powered off or in a Secure pen) | In Normal-world reserved memory, polling cpu-release-addr |
| Release | CPU_ON(target_mpidr, entry, context_id) SMC/HVC | Kernel writes the entry address, then SEV |
CPU hotplug, CPU_OFF, deep idle | Yes | No: a released core can never return to firmware |
| Errata and EL3 init on the secondary | Done by BL31 on the core’s own reset path | Must have been done before the core entered the spin loop |
| Fit | Any system with EL3 firmware | Simple systems with no PSCI implementation |
CPU_ON end to end in TF-A
Caller core (Normal world) Target core
-------------------------- -----------
SMC CPU_ON(mpidr, ep, ctx_id)
psci_cpu_on()
validate ep (plat validate_ns_entrypoint)
validate mpidr -> core index
psci_cpu_on_start():
aff_info state OFF? else ALREADY_ON / ON_PENDING
set ON_PENDING, clean it to PoC (target reads it with caches off)
cm_init_context_by_index(idx, ep) (target's NS context built here)
SPD hook (svc_on)
plat_psci_ops->pwr_domain_on(mpidr) ---> power controller releases reset
return PSCI_E_SUCCESS RVBAR_EL3 -> bl31_warm_entrypoint
el3_entrypoint_common (SCTLR, vectors,
reset_handler: errata, SMPEN)
enable EL3 MMU and caches
psci_warmboot_entrypoint()
psci_cpu_on_finish():
plat pwr_domain_on_finish
(GIC Redistributor + CPU interface)
SPD hook (svc_on_finished)
aff_info state := ON
cm_prepare_el3_exit_ns()
el3_exit: ERET to ep, x0 = ctx_id
Three details matter in bring-up:
CPU_ONreturning success does not mean the core is running. It means the power-on request was accepted. The OS uses its own handshake (Linux waits on a completion signalled by the secondary), and can pollAFFINITY_INFO.- The context is built by the caller. The target’s
cpu_context_t(SCR_EL3,SPSR_EL3,ELR_EL3=ep) is written by the calling core into memory the target will read after enabling its MMU and caches. TF-A relies on the system being coherent at that point (HW_ASSISTED_COHERENCY, or explicit cleaning of the shared PSCI data when it is not). - Coherency entry happens on the target’s reset path, before its caches are enabled. On Cortex-A53/A57/A72-class cores, the CPU reset handler sets
CPUECTLR_EL1.SMPEN. On DynamIQ cores there is noSMPEN: the core joins the cluster’s coherency domain automatically when it is powered on, under PPU and DSU control. If the cluster itself was off, the platform’spwr_domain_onmust first power the cluster and, on older interconnects, add it to the snoop and DVM domains (for example TF-A’scci_enable_snoop_dvm_reqs()on CCI-400 platforms) (8.8, 17.5).
CPU_SUSPEND and CPU_OFF
CPU_SUSPEND(power_state, entry, context_id) asks for a low-power state described by power_state. In the original format, StateID is in bits [15:0], StateType in bit 16 (0 = standby or retention, 1 = power-down) and PowerLevel in [25:24]. In the extended format (PSCI 1.0 and later; which format the firmware uses is reported by PSCI_FEATURES(CPU_SUSPEND)), StateType is bit 30 and StateID is [27:0]. The difference between the two types determines the whole path:
| Retention (standby) | Power-down | |
|---|---|---|
| PE state | Preserved; clocks gated, possibly reduced voltage | Lost; the core takes a Cold reset on wake-up |
| Caches | Normally retained, still coherent or not per TRM | Must be cleaned (or flushed by hardware on DynamIQ) |
| Return | Execution continues after the WFI; CPU_SUSPEND returns SUCCESS to the caller | Never returns on success: the core restarts at entry with x0 = context_id |
| EL3 work | Program the power controller, WFI | Save context, cache steps, GIC sleep, program the power controller, WFI |
In TF-A, a CPU-level retention state goes straight to plat_psci_ops->cpu_standby(), which is essentially a WFI with a power-controller hint. Anything deeper goes through psci_cpu_suspend_start():
- Coordinate. Under the power-domain locks,
psci_do_state_coordination()computes, for each affected level (cluster, system), the shallowest state that every child has requested. This is platform-coordinated mode, the default. The last core of a cluster to request power-down is the one that powers the cluster down. In OS-initiated mode (PSCI_SET_SUSPEND_MODE, PSCI 1.0) the OS makes that decision and firmware checks it. - Notify the SPD (
svc_suspend) so that OP-TEE or the SPMC can save state or refuse. - Power-down sequence for each level that loses power:
psci_do_pwrdown_sequence()calls the CPU-specificcore_pwr_dwn/cluster_pwr_dwnroutines, which are the cache and coherency exit steps of 8.8. The EL3 context is already in memory. Extensions with state not in the context (for example AMU counters) are saved here. - Platform suspend (
pwr_domain_suspend): mark the Redistributor asleep, disable the GIC CPU interface, program the power controller (often through SCMI to an SCP) with the target state and the wake-up conditions. DSBandWFI(psci_power_down_wfi()). If theWFIfalls through, for example because an interrupt was already pending and the power controller refused the request, TF-A treats it as an immediate wake-up.
CPU_OFF follows steps 1–5 with no entry point and no wake-up condition other than a later CPU_ON.
On wake-up from power-down, the core takes the same path as the target core of CPU_ON above. psci_warmboot_entrypoint() then calls psci_cpu_suspend_finish() instead of the CPU_ON finisher: it restores the extension state, lets the SPD resume, and ERETs to the entry given in CPU_SUSPEND. The Normal world sees this as a fresh entry, not a return from the SMC, which is why Linux’s cpu_suspend() saves its own context before the call and restores it at cpu_resume.
The wake-up path: GIC and timer
A powered-off core cannot see its interrupt signals, so something outside the core power domain has to wake it.
- GIC Redistributor. Before power-down, firmware sets
GICR_WAKER.ProcessorSleep=1and waits forGICR_WAKER.ChildrenAsleep=1. While the bit is set, the Redistributor does not signal interrupts to the CPU interface. Instead, when an interrupt targeting that PE becomes pending, it raises a wake request to the power controller. The signal is IMPLEMENTATION DEFINED, but GIC-600/700 provide one per core. On resume, firmware clearsProcessorSleep, waits forChildrenAsleep=0, then re-enables the CPU interface (4.5). An SPI with 1-of-N routing (GICD_IROUTER.IRM=1) can be delivered to an awake PE instead; whether the IRI chooses an awake PE in preference to waking a sleeping one is IMPLEMENTATION DEFINED. WhereGICR_TYPER.DPGS=1, software can setGICR_CTLR.{DPG0,DPG1NS,DPG1S}before sleeping to exclude that PE from 1-of-N selection for each group, and clear them on resume. - Generic Timer. The per-PE timers (
CNTP_*,CNTV_*) live in the core power domain. Their comparators stop and their state is lost when the core powers down, so a core-local timer interrupt cannot wake a core from a power-down state. The system counter is in an always-on domain and keeps counting, soCNTPCT_EL0is continuous across suspend. The OS must therefore hand its next timer event to a timer that stays powered before entering such a state. Linux uses a broadcast timer for this, typically a memory-mapped timer frame (CNTBaseN), and the device-treelocal-timer-stopproperty on the idle state tells it when this is required (4.6). On retention states, whether the local timer keeps running is IMPLEMENTATION DEFINED, so check the TRM. - Lower-EL timer state.
CNTV_CVAL_EL0,CNTKCTL_EL1and, at EL2,CNTHCTL_EL2andCNTVOFF_EL2are lost with the core. Whichever EL owns them must restore them.CNTFRQ_EL0is lost too, and EL3 rewrites it on the warm-boot path.
Validation note: the PSCI stress test is a loop that randomly chooses a core and a state (retention, core power-down, cluster power-down,
CPU_OFF/CPU_ON) while other cores generate SGIs, SPIs with 1-of-N routing, and timer interrupts aimed at the sleeping core. Check three things on each cycle: the core wakes for every interrupt aimed at it (a lost wake-up appears as a core that never returns, usually withGICR_WAKER.ProcessorSleepstill 1); interrupts are neither lost nor duplicated (count them per core); and memory patterns survive (8.8). TFTF’s PSCI test suites implement much of this. PSCI’sPSCI_STAT_COUNT/PSCI_STAT_RESIDENCY(when implemented) and the AMU constant-frequency counter confirm that the core actually entered the state rather than falling throughWFI.
Checkpoint
Q17.4.1 Linux calls CPU_SUSPEND with a power-down state. The SMC returns PSCI_E_SUCCESS to the instruction after the SMC, the core did not lose state, and the residency counters show no time in the state. What happened?
- A. Normal behaviour: a power-down suspend always returns to the caller on wake-up
- B. The request did not complete as a power-down. For example, an interrupt was already pending, the
WFIfell through, and firmware treated it as an immediate wake-up. A real power-down wake-up restarts the core at theentryaddress, not after theSMC - C. The core entered power-down, but TF-A restored its registers and returned to the SMC site
- D. The
power_statewas in the extended format, which only supports retention
Answer
B. Under PSCI, a power-down state that is actually entered never returns on success: execution resumes at the entry point given in the call. A return to the call site means retention or an aborted entry. TF-A does not resume the Normal world at the SMC site after a real power-down (C). It ERETs to the registered entry point. The extended format encodes both types (D).
Read more: PSCI (DEN0022), CPU_SUSPEND; TF-A psci_cpu_suspend_start
Q17.4.2 A core enters a core power-down idle state, and its next scheduled timer event is 2 ms away. It sleeps for 300 ms, until an unrelated device interrupt wakes it. GICR_WAKER handling is correct. What is the most likely cause?
- A.
CNTFRQ_EL0was lost and the counter ran slow - B. The system counter stopped while the core was off
- C.
SCR_EL3.IRQrouted the timer interrupt to EL3 - D. The core-local Generic Timer is in the core power domain and cannot raise its PPI while the core is off. The OS should have moved the event to an always-on broadcast timer (the idle state lacks
local-timer-stop, or no broadcast timer is registered)
Answer
D. The Redistributor can only wake the core for an interrupt that becomes pending, and a powered-off core timer never makes its PPI pending. The system counter is always-on (B), so time stays correct after wake-up. A lost CNTFRQ_EL0 (A) affects time conversion after resume, not the wake-up. Routing to EL3 (C) would still produce a wake-up, just a different handler.
Read more: Arm ARM (DDI0487), The Generic Timer, power and reset; Linux DT bindings, arm,idle-state local-timer-stop
Q17.4.3 A platform ported from Cortex-A72 to Cortex-A78 clusters keeps its secondary release code. That code computes the core index as MPIDR_EL1.Aff0 + 4 * MPIDR_EL1.Aff1. On the new SoC, at most one secondary core starts, and CPU_ON to the others returns INVALID_PARAMETERS or ALREADY_ON. Why?
- A. DynamIQ cores report
MT=1withAff0=0and the core number inAff1, so the old formula maps cores 0, 1, 2… to indices 0, 4, 8… Most indices run past the number of cores (rejected), and any that land in range alias another core’s PSCI state - B. Cortex-A78 lacks
CPUECTLR_EL1.SMPEN, so secondaries cannot become coherent - C.
CPU_ONrequiresAff3to be non-zero - D. The A78 requires spin-table instead of PSCI
Answer
A. The affinity layout changed between pre-DynamIQ and DynamIQ cores. The index function must derive positions from the platform’s actual topology and reject impossible values. SMPEN (B) is indeed absent on DynamIQ cores, but coherency entry is then automatic, so it would not produce these PSCI errors. Nothing in PSCI requires Aff3 to be non-zero (C) or forbids PSCI on any core (D).
Read more: Arm ARM (DDI0487), MPIDR_EL1; Cortex-A78 TRM, MPIDR_EL1; TF-A porting guide, plat_core_pos_by_mpidr