Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

12.3 Firmware interfaces

Three Arm specifications define almost every call that crosses a privilege boundary on an A-profile system. SMCCC (DEN0028) defines the register-level calling convention and the function ID space. PSCI (DEN0022) is the power-management API built on SMCCC. FF-A (DEN0077) is the partition-messaging and memory-sharing API built on SMCCC. This section covers the interfaces. The firmware sequences behind PSCI (cache flushing, coherency exit, the GIC wake-up path) are in 17.4 and 8.8.

SMCCC: conduits and the function ID

The conduit is SMC #0 (to EL3, or trapped to EL2 by HCR_EL2.TSC) or HVC #0 (to EL2). The immediate is ignored by convention, and the function ID travels in W0. Its layout:

BitsFieldValues
31Call type1 = Fast call (atomic with respect to the caller’s PE: runs to completion, cannot be preempted by the Normal world), 0 = Yielding call (may be interrupted and resumed)
30Convention0 = SMC32/HVC32, 1 = SMC64/HVC64
29:24Owning entity number (OEN)0 Arm Architecture, 1 CPU service, 2 SiP, 3 OEM, 4 Standard Secure service, 5 Standard Hypervisor, 6 Vendor Hypervisor, 7 Vendor EL3 Monitor, 48–49 Trusted Applications, 50–63 Trusted OS
23:17ReservedMust be zero for Fast calls
16SVE hint (SMCCC v1.3)1 = the caller has no live SVE state beyond the FP/SIMD view, so the callee need not preserve Z/P/FFR upper bits
15:0Function numberWithin the OEN

So 0x84000000 is a Fast, SMC32, Standard Secure service call, function 0 (PSCI_VERSION), and 0xC4000003 is the SMC64 form of function 3 (CPU_ON). PSCI, SDEI, TRNG, FF-A and the CCA RMI all live in OEN 4. Arm architecture calls (OEN 0) include SMCCC_VERSION (0x80000000), SMCCC_ARCH_FEATURES (0x80000001), SMCCC_ARCH_SOC_ID (0x80000002) and the Spectre workarounds SMCCC_ARCH_WORKAROUND_1/2/3 (0x80008000, 0x80007FFF, 0x80003FFF; see 14.4). An unknown function ID must return SMC_UNK (−1, 0xFFFFFFFF in W0).

Register usage for SMC64/HVC64:

  • Arguments in X1–X17 and results in X0–X17 (the full range from v1.2; earlier versions used X1–X6 for arguments, with W7 carrying an optional hypervisor client ID, and X0–X3 for results).
  • The callee must preserve X18–X30, SP_EL0 and SP_ELx. From v1.1, it must also preserve the argument/result registers that a given function does not use (X4–X17 for a classic four-result call). That is why Linux’s arm_smccc_1_1_smc() clobbers only X0–X3.
  • SMC32 uses only the W views, and the upper halves are not part of the contract.
  • FP/SIMD/SVE/SME state is preserved by the callee, subject to the SVE hint.

Discovery is layered: check that SMCCC_VERSION exists with PSCI_FEATURES (if it does not, assume v1.0), call it, then SMCCC_ARCH_FEATURES(fid) for each optional call. The conduit itself is chosen by the OS from the device tree (/psci method = "smc" or "hvc") or from the ACPI FADT PSCI_USE_HVC flag.

Security note: an EL3 SMC handler must treat every argument as hostile. Pointers from the Normal world must be range-checked against NS memory, and copied in once before validation (no double fetch). It must never dereference a pointer without checking which PAS it names: on RME systems a forged pointer into Realm memory takes a GPF at EL3 (12.4). Fast calls run with interrupts masked at EL3, so a long fast call is also a denial-of-service and latency problem.

PSCI: the interface and its coordination rules

The calls you will use in bring-up (SMC64 IDs; the SMC32 form replaces 0xC4 with 0x84):

CallIDContract
CPU_ON(target_mpidr, entry, context_id)0xC4000003Powers on the target. It starts at entry, in the caller’s EL and execution state (Non-secure EL2 or EL1), with X0 = context_id, MMU and D-cache off. Errors: ALREADY_ON, ON_PENDING, INVALID_PARAMETERS, INVALID_ADDRESS
CPU_OFF()0x84000002Called by the core itself. Does not return on success. The caller must already have migrated its interrupts and work away
CPU_SUSPEND(power_state, entry, context_id)0xC4000001Retention (standby) states return to the caller. Power-down states resume at entry like a warm boot, with the caller’s context lost
AFFINITY_INFO(mpidr, level)0xC4000004Returns ON (0), OFF (1) or ON_PENDING (2). This is how an OS learns that a CPU_OFF really finished
SYSTEM_OFF / SYSTEM_RESET0x84000008 / 0x84000009Do not return. SYSTEM_RESET is a cold reset
SYSTEM_RESET2(type, cookie)0xC4000012PSCI 1.1. Type 0 = warm reset. Bit 31 set = vendor-specific reset
PSCI_FEATURES(fid)0x8400000AIs a call implemented? For CPU_SUSPEND it also reports the power_state format and whether OS-initiated mode is supported

The power_state parameter comes in two formats:

FormatStateIDStateType (0 = standby/retention, 1 = power-down)PowerLevel
Originalbits [15:0]bit 16bits [25:24]
Extended (PSCI 1.0+)bits [27:0]bit 30encoded in StateID by the platform

Coordination is about deciding when a cluster or system may power down when several cores vote. PSCI defines two modes:

  • Platform-coordinated (the default, required): each core requests its preferred state for every level of its hierarchy. The firmware puts a node into the shallowest state that all its cores have requested, so a node powers down only when the last core asks for it. The OS never has to know who is last.
  • OS-initiated (OSI, PSCI 1.0, optional, selected with PSCI_SET_SUSPEND_MODE): the OS decides. The last core in a node requests the composite state for the node. Firmware checks that the request is consistent with what it knows (for example, that every other core in the node is really idle or off) and returns DENIED if it is not. OSI moves the race condition into the OS, and in exchange the OS’s knowledge of wake-up latency is used.

Both modes follow one rule: a core that has asked to power down must not count as off until firmware has completed its power-down sequence. That is why AFFINITY_INFO exists, and why a CPU_ON aimed at a core still in its CPU_OFF sequence returns ALREADY_ON instead of racing the power-down. (ON_PENDING is different: it means an earlier CPU_ON for that core has not completed yet.)

Validation note: test PSCI as a state machine, not call by call. Useful cases: CPU_ON on a core that is still in its CPU_OFF sequence (must return ALREADY_ON or eventually succeed, never hang); concurrent CPU_SUSPEND power-down requests from every core in a cluster while one core is woken by an SGI (the cluster must not be powered down under a running core); and SYSTEM_SUSPEND with a pending wake-up interrupt. Confirm each with AFFINITY_INFO, with PSCI_STAT_RESIDENCY/PSCI_STAT_COUNT where implemented, and with the power controller’s status registers. TF-A’s TFTF has a PSCI suite that covers most of these.

FF-A: partitions, messaging and memory sharing

FF-A (v1.0 in 2020, then 1.1, 1.2 and 1.3) standardises how endpoints (VMs, the OS, secure partitions) talk to each other through partition managers. Function IDs are in OEN 4, function numbers 0x60 upward (FFA_ERROR = 0x84000060, FFA_SUCCESS = 0x84000061, FFA_VERSION = 0x84000063).

Components. In the Normal world, the hypervisor (if any) is the NS partition manager. In the Secure world, the SPMC manages SPs. The SPMD in BL31 relays FF-A calls between the worlds and saves and restores world context. SPMC placements:

SPMC atExampleIsolation between SPs
S-EL2 (FEAT_SEL2)HafniumStage 2 per SP. SPs at S-EL1 (OP-TEE as an SP) or S-EL0
S-EL1OP-TEE as SPMCStage 1 only. S-EL0 SPs (OP-TEE TAs, or FF-A S-EL0 SPs)
EL3TF-A EL3 SPMCS-EL0 SPs such as StandaloneMM

Each endpoint has a 16-bit ID. In TF-A and Hafnium, secure endpoints have bit 15 set and ID 0 is the Normal world (hypervisor or OS). Discovery uses FFA_VERSION, FFA_FEATURES, FFA_ID_GET and FFA_PARTITION_INFO_GET. SP properties (UUID, EL, execution contexts, memory regions, interrupts) come from partition manifests (device tree) that the SPMC reads at boot.

Messaging.

  • Direct messaging: FFA_MSG_SEND_DIRECT_REQ/RESP (and the REQ2/RESP2 forms from v1.2 that carry more registers and a UUID). This is a synchronous, register-only RPC into a specific SP execution context. It is the path OP-TEE’s Linux driver uses under FF-A.
  • Indirect messaging: FFA_MSG_SEND2 (v1.1) copies the message through the RX/TX buffer pair that each endpoint registers with FFA_RXTX_MAP.
  • Scheduling: FFA_RUN (give CPU time to an SP), FFA_MSG_WAIT (an SP idles), FFA_YIELD, and FFA_INTERRUPT when a secure interrupt preempts. Notifications (v1.1) are the asynchronous, doorbell-like path.

Memory sharing. A lender describes a region (a list of PA ranges, permissions, attributes and receivers) in its TX buffer and calls one of the following:

CallAfter it completes
FFA_MEM_SHARELender and borrower(s) both have access
FFA_MEM_LENDBorrower has access, lender loses it until reclaim
FFA_MEM_DONATEOwnership moves permanently

The partition manager returns a 64-bit handle. The borrower maps the region with FFA_MEM_RETRIEVE_REQ and gives it back with FFA_MEM_RELINQUISH. The lender then recovers it with FFA_MEM_RECLAIM. The SPMC enforces each transfer by editing the stage 2 tables of the parties involved. When a lender loses access, the PM must remove the mapping, broadcast the TLBI and complete it before the call returns: lend is not secure if the lender keeps a stale TLB entry. Lending from the Normal world without a hypervisor is the weak case. Nothing in the Secure world controls the OS’s stage 1, so exclusivity can be enforced only if the SPMC also changes the memory’s PAS (through the TZASC, or the GPT on RME systems). Otherwise the region stays Non-secure and the SP must map it Non-secure, because mapping it NS=0 would create a Secure alias of a Non-secure location (12.1).

Bring-up note: most FF-A bring-up failures are manifest mismatches, not protocol bugs: an SP UUID in the Linux driver that differs from the manifest, an SP’s memory region that overlaps another one, or an interrupt claimed in a manifest but left configured as Non-secure Group 1. Hafnium and the SPMD print the parsed manifest at boot, so compare that log first.

Checkpoint

Q12.3.1 A vendor adds an SMC that copies a 64-byte record into a buffer whose address is passed in X1, and returns status in X0 and a length in X1. Linux calls it with arm_smccc_1_1_smc() and keeps a live value in X5 across the call. EL3’s handler is written in C and uses X5 as scratch, without restoring it before the ERET. Who is wrong?

  • A. Linux: SMCCC lets the callee corrupt X4–X17
  • B. Nobody: X5 is caller-saved under AAPCS64, so Linux should have spilled it
  • C. The EL3 handler: from SMCCC v1.1, registers that a function does not use for results must be preserved, and AAPCS64 caller-saved rules do not apply across the SMC boundary
  • D. Linux: it should have used an SMC32 call, for which only W0–W3 are defined
Answer

C. SMCCC is its own contract, not AAPCS64. From v1.1 the callee must return unused registers unchanged, and Linux’s 1.1 helpers rely on this by clobbering only X0–X3. A was the v1.0 rule. In TF-A this bug cannot arise from C code: the EL3 entry path saves the full GP register context and restores it on exit, so only a hand-written assembly handler could leak X5 this way.

Read more: SMC Calling Convention (DEN0028), register use in AArch64 SMC and HVC calls

Q12.3.2 In platform-coordinated mode, core 0 of a two-core cluster calls CPU_SUSPEND asking for core power-down and cluster power-down. Core 1 is running. What must the firmware do?

  • A. Return DENIED, because a cluster state was requested while another core in the cluster is running
  • B. Power down core 0 only, record its vote for the cluster, and power the cluster down only once core 1 also requests a cluster power-down state
  • C. Power down the whole cluster, because the request came from the last core to ask
  • D. Put core 0 into retention instead, because platform-coordinated mode does not allow power-down
Answer

B. In platform-coordinated mode, each core’s request is a vote and the node enters the shallowest state its cores agree on. DENIED for an inconsistent composite request (A) is OS-initiated mode behaviour. That rule exists because in OSI the OS claims to be the last core.

Read more: Arm PSCI (DEN0022), power state coordination: platform-coordinated and OS-initiated modes

Q12.3.3 Under a Hafnium SPMC at S-EL2, S-EL1 partition SP1 uses FFA_MEM_LEND to give a buffer from its own Secure memory to SP2. Which property must the SPMC enforce before it reports success to SP1?

  • A. None beyond bookkeeping: SP1 is expected to have removed its own stage 1 mapping before the call
  • B. The buffer is cleaned and invalidated to the PoC on every PE, so that SP1’s cached copy cannot be read
  • C. The buffer is moved to the Non-secure PAS, so that both partitions can address it through the same IPA space
  • D. SP1’s stage 2 mapping is removed and the TLB invalidation has completed (TLBI then DSB), so SP1 cannot reach the buffer even through a cached translation
Answer

D. Lend means exclusive access for the borrower. The SPMC owns both partitions’ stage 2 tables, so it enforces this there, and a removal counts only once the TLBI has completed. Relying on the lender’s own stage 1 (A) is not isolation, because the lender is the party being restricted. Cache maintenance (B) does not remove access rights, and moving the buffer to the Non-secure PAS (C) would expose it to the Normal world.

Read more: Arm FF-A (DEN0077), memory management: lend, share and donate transactions; Arm ARM (DDI0487), TLB maintenance requirements