blob: 5dadc913b518ced19b31b19c0abc0bf65cabf5cb [file] [log] [blame]
Olivier Deprez8c4cb2d2023-10-27 16:07:11 +02001Foreword
2========
3
4- This document describes the FF-A implementation from `[1]`_ for the
5 configuration where the SPMC resides at S-EL2 on platforms implementing the
6 FEAT_SEL2 architecture extension.
7- It is not an architecture specification and it might provide assumptions on
8 sections mandated as implementation-defined in the specification.
9- It covers the implications of TF-A used as a bootloader, and Hafnium used as a
10 reference code base for an SPMC.
11
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020012Terminology
J-Alvesf7490db2023-10-19 17:57:22 +010013===========
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020014
15- The term Hypervisor refers to the NS-EL2 component managing Virtual Machines
16 (or partitions) in the normal world.
17- The term SPMC refers to the S-EL2 component managing secure partitions in
18 the secure world when the FEAT_SEL2 architecture extension is implemented.
19- Alternatively, SPMC can refer to an S-EL1 component, itself being a secure
20 partition and implementing the FF-A ABI on platforms not implementing the
21 FEAT_SEL2 architecture extension.
22- The term VM refers to a normal world Virtual Machine managed by an Hypervisor.
23- The term SP refers to a secure world "Virtual Machine" managed by an SPMC.
24
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020025Sample reference stack
26======================
27
28The following diagram illustrates a possible configuration when the
J-Alves5eafd222023-10-26 14:19:21 +010029FEAT_SEL2 architecture extension is implemented, showing the |SPMD|
30and |SPMC|, one or multiple secure partitions, with an optional
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020031Hypervisor:
32
J-Alvesc1693772023-10-26 12:41:53 +010033.. image:: ../resources/diagrams/Hafnium_overview_SPMD.png
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020034
J-Alves5eafd222023-10-26 14:19:21 +010035Integration with TF-A (Bootloader and SPMD)
36===========================================
37
38The `TF-A project`_ provides the reference implementation for the secure monitor
39for Arm A class devices, executing at EL3. It includes the implementation of the
40|SPMD|, which manages the world-switch, to relay the FF-A calls to the |SPMC|.
41
42TF-A also serves as the system bootlader, and it was used in the reference
J-Alvesd547d6d2024-05-14 14:59:54 +010043implementation for the SPMC and SPs.
J-Alves5eafd222023-10-26 14:19:21 +010044SPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.).
45Thus they are supplied as distinct signed entities within the FIP flash
46image. The FIP image itself is not signed hence this provides the ability
47to upgrade SPs in the field.
48
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020049TF-A build options
J-Alves5eafd222023-10-26 14:19:21 +010050------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020051
J-Alvesd8094162023-10-26 12:44:33 +010052This section explains the TF-A build options for an FF-A based SPM, in which SPMD
53is located at EL3.
54
55This is a step needed for integrating Hafnium as the S-EL2 SPMC and
56the TF-A as SPMD, together making the SPM component.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020057
58- **SPD=spmd**: this option selects the SPMD component to relay the FF-A
59 protocol from NWd to SWd back and forth. It is not possible to
60 enable another Secure Payload Dispatcher when this option is chosen.
61- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception
62 level to being at S-EL2. It defaults to enabled (value 1) when
J-Alvesd8094162023-10-26 12:44:33 +010063 SPD=spmd is chosen.The context save/restore routine and exhaustive list
64 of registers is visible at `[4]`_. When set the reference software stack
65 assumes enablement of FEAT_PAuth, FEAT_BTI and FEAT_MTE architecture
66 extensions.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020067- **SP_LAYOUT_FILE**: this option specifies a text description file
68 providing paths to SP binary images and manifests in DTS format
J-Alves5eafd222023-10-26 14:19:21 +010069 (see `Secure Partitions Layout File`_). It is required when ``SPMD_SPM_AT_SEL2``
J-Alvesd8094162023-10-26 12:44:33 +010070 is enabled, i.e. when multiple secure partitions are to be loaded by BL2 on
71 behalf of the SPMC.
72- **BL32** option is re-purposed to specify the SPMC image. It can specify either
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020073 the Hafnium binary path (built for the secure world) or the path to a TEE
74 binary implementing FF-A interfaces.
J-Alvesd8094162023-10-26 12:44:33 +010075- **BL33** option to specify normal world loader such as U-Boot or the UEFI
76 framework payload, which would use FF-A calls during runtime to interact with
77 Hafnium as the SPMC.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020078
J-Alvesd8094162023-10-26 12:44:33 +010079As a result of configuring ``SPD=spmd`` and ``SPMD_SPM_AT_SEL2`` TF-A provides
80context save/restore operations when entering/exiting an EL2 execution context.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020081
J-Alvesd8094162023-10-26 12:44:33 +010082There are other build options that relate support other valid FF-A
83system configurations where the SPMC is implemented at S-EL1 and EL3.
84Note that they conflict with those needed to integrate with Hafnium as the SPMC.
85For more details refer to |TF-A| build options `[10]`_.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020086
87Sample TF-A build command line when FEAT_SEL2 architecture extension is
J-Alvesd8094162023-10-26 12:44:33 +010088implemented and the SPMC is located at S-EL2, for Arm's FVP platform:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020089
90.. code:: shell
91
92 make \
93 CROSS_COMPILE=aarch64-none-elf- \
94 PLAT=fvp \
95 SPD=spmd \
96 ARM_ARCH_MINOR=5 \
97 BRANCH_PROTECTION=1 \
J-Alves874737a2024-03-20 17:30:24 +000098 ENABLE_FEAT_MTE2=1 \
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020099 BL32=<path-to-hafnium-binary> \
100 BL33=<path-to-bl33-binary> \
101 SP_LAYOUT_FILE=sp_layout.json \
102 all fip
103
104Sample TF-A build command line when FEAT_SEL2 architecture extension is
105implemented, the SPMC is located at S-EL2, and enabling secure boot:
106
107.. code:: shell
108
109 make \
110 CROSS_COMPILE=aarch64-none-elf- \
111 PLAT=fvp \
112 SPD=spmd \
113 ARM_ARCH_MINOR=5 \
114 BRANCH_PROTECTION=1 \
J-Alves874737a2024-03-20 17:30:24 +0000115 ENABLE_FEAT_MTE2=1 \
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200116 BL32=<path-to-hafnium-binary> \
117 BL33=<path-to-bl33-binary> \
118 SP_LAYOUT_FILE=sp_layout.json \
119 MBEDTLS_DIR=<path-to-mbedtls-lib> \
120 TRUSTED_BOARD_BOOT=1 \
121 COT=dualroot \
122 ARM_ROTPK_LOCATION=devel_rsa \
123 ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
124 GENERATE_COT=1 \
125 all fip
126
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200127FVP model invocation
J-Alves5eafd222023-10-26 14:19:21 +0100128--------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200129
130The FVP command line needs the following options to exercise the S-EL2 SPMC:
131
132+---------------------------------------------------+------------------------------------+
133| - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, |
134| - cluster1.has_arm_v8-5=1 | and FEAT_BTI. |
135+---------------------------------------------------+------------------------------------+
136| - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the |
137| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. |
138| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | |
139| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | |
140| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | |
141| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | |
142| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | |
143| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | |
144+---------------------------------------------------+------------------------------------+
145| - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. |
146| - cluster1.has_branch_target_exception=1 | |
147+---------------------------------------------------+------------------------------------+
148| - cluster0.has_pointer_authentication=2 | Implements FEAT_PAuth |
149| - cluster1.has_pointer_authentication=2 | |
150+---------------------------------------------------+------------------------------------+
151| - cluster0.memory_tagging_support_level=2 | Implements FEAT_MTE2 |
152| - cluster1.memory_tagging_support_level=2 | |
153| - bp.dram_metadata.is_enabled=1 | |
154+---------------------------------------------------+------------------------------------+
155
156Sample FVP command line invocation:
157
158.. code:: shell
159
160 <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \
161 -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \
162 -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \
163 -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \
164 -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \
165 -C bp.pl011_uart2.out_file=fvp-uart2.log \
166 -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 \
167 -C cluster0.has_pointer_authentication=2 -C cluster1.has_pointer_authentication=2 \
168 -C cluster0.has_branch_target_exception=1 -C cluster1.has_branch_target_exception=1 \
169 -C cluster0.memory_tagging_support_level=2 -C cluster1.memory_tagging_support_level=2 \
170 -C bp.dram_metadata.is_enabled=1 \
171 -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \
172 -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \
173 -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \
174 -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0
175
J-Alves5eafd222023-10-26 14:19:21 +0100176SPMC Configuration
177==================
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200178
J-Alves5eafd222023-10-26 14:19:21 +0100179This section details the configuration files required to deploy Hafnium as the SPMC,
180along with those required to configure each secure partion.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200181
J-Alves5eafd222023-10-26 14:19:21 +0100182SPMC Manifest
183-------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200184
J-Alves5eafd222023-10-26 14:19:21 +0100185This manifest contains the SPMC *attribute* node consumed by the SPMD at boot
186time. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves
187two different cases:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200188
J-Alves5eafd222023-10-26 14:19:21 +0100189The SPMC manifest is used by the SPMD to setup the environment required by the
190SPMC to run at S-EL2. SPs run at S-EL1 or S-EL0.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200191
J-Alves5eafd222023-10-26 14:19:21 +0100192.. code:: shell
193
194 attribute {
195 spmc_id = <0x8000>;
196 maj_ver = <0x1>;
197 min_ver = <0x1>;
198 exec_state = <0x0>;
199 load_address = <0x0 0x6000000>;
200 entrypoint = <0x0 0x6000000>;
201 binary_size = <0x60000>;
202 };
203
J-Alvesc28ee3e2024-05-14 18:29:26 +0100204* *spmc_id* defines the endpoint ID value that SPMC can query through
J-Alves5eafd222023-10-26 14:19:21 +0100205 ``FFA_ID_GET``.
J-Alvesc28ee3e2024-05-14 18:29:26 +0100206* *maj_ver/min_ver*. SPMD checks provided FF-A version versus its internal
J-Alves5eafd222023-10-26 14:19:21 +0100207 version and aborts if not matching.
J-Alvesc28ee3e2024-05-14 18:29:26 +0100208* *exec_state* defines the SPMC execution state (AArch64 or AArch32).
J-Alves5eafd222023-10-26 14:19:21 +0100209 Notice Hafnium used as a SPMC only supports AArch64.
J-Alvesc28ee3e2024-05-14 18:29:26 +0100210* *load_address* and *binary_size* are mostly used to verify secondary
J-Alves5eafd222023-10-26 14:19:21 +0100211 entry points fit into the loaded binary image.
J-Alvesc28ee3e2024-05-14 18:29:26 +0100212* *entrypoint* defines the cold boot primary core entry point used by
J-Alves5eafd222023-10-26 14:19:21 +0100213 SPMD (currently matches ``BL32_BASE``) to enter the SPMC.
214
215Other nodes in the manifest are consumed by Hafnium in the secure world.
216A sample can be found at `[7]`_:
217
J-Alvesc28ee3e2024-05-14 18:29:26 +0100218* The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute
219 indicates a |FF-A| compliant SP. The *load_address* field specifies the load
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500220 address at which BL2 loaded the partition package.
J-Alvesc28ee3e2024-05-14 18:29:26 +0100221* The *cpus* node provides the platform topology and allows MPIDR to VMPIDR mapping.
J-Alves5eafd222023-10-26 14:19:21 +0100222 Note the primary core is declared first, then secondary cores are declared
223 in reverse order.
J-Alvesc28ee3e2024-05-14 18:29:26 +0100224* The *memory* nodes provide platform information on the ranges of memory
J-Alves5eafd222023-10-26 14:19:21 +0100225 available for use by SPs at runtime. These ranges relate to either
J-Alvesc28ee3e2024-05-14 18:29:26 +0100226 normal or device and secure or non-secure memory, depending on the *device_type*
227 field. The system integrator must exclude the memory used by other components
228 that are not SPs, such as the monitor, or the SPMC itself, the OS Kernel/Hypervisor,
229 NWd VMs, or peripherals that shall not be used by any of the SPs. The following are
230 the supported *device_type* fields:
231
232 * "memory": normal secure memory.
233 * "ns-memory": normal non-secure memory.
234 * "device-memory": device secure memory.
235 * "ns-device-memory": device non-secure memory.
236
237 The SPMC limits the SP's address space such that they can only refer to memory
238 inside of those ranges, either by defining memory region or device region nodes in
239 their manifest as well as memory starting at the load address until the limit
240 defined by the memory size. The SPMC also checks for overlaps between the regions.
241 Thus, the SPMC prevents rogue SPs from tampering with memory from other
J-Alves5eafd222023-10-26 14:19:21 +0100242 components.
243
J-Alvesc143a342023-11-07 12:17:44 +0000244.. code:: shell
245
246 memory@0 {
247 device_type = "memory";
248 reg = <0x0 0x6000000 0x2000000 0x0 0xff000000 0x1000000>;
249 };
250
251 memory@1 {
252 device_type = "ns-memory";
253 reg = <0x0 0x90010000 0x70000000>;
254 };
255
J-Alvesc28ee3e2024-05-14 18:29:26 +0100256 memory@2 {
257 device_type = "device-memory";
258 reg = <0x0 0x1c090000 0x0 0x40000>, /* UART */
259 <0x0 0x2bfe0000 0x0 0x20000>, /* SMMUv3TestEngine */
260 <0x0 0x2a490000 0x0 0x20000>, /* SP805 Trusted Watchdog */
261 <0x0 0x1c130000 0x0 0x10000>; /* Virtio block device */
262 };
263
264 memory@3 {
265 device_type = "ns-device-memory";
266 reg = <0x0 0x1C1F0000 0x0 0x10000>; /* LCD */
267 };
268
J-Alvesc143a342023-11-07 12:17:44 +0000269Above find an example representation of the referred memory description. The
270ranges are described in a list of unsigned 32-bit values, in which the first
271two addresses relate to the based physical address, followed by the respective
272page size. The first secure range defined in the node below has base address
273`0x0 0x6000000` and size `0x2000000`; following there is another range with
274base address `0x0 0xff000000` and size `0x1000000`.
275
Olivier Deprez052fa622024-08-01 15:07:42 +0200276The interrupt-controller node contains the address ranges of GICD and GICR
Jerry Wang99fe2432024-06-17 14:02:32 +0100277so that non-contiguous GICR frames can be probed during boot flow. The GICD
Jerry Wang88bec722025-05-06 20:17:05 +0100278addresses are defined first in the cells, followed by the GICR addresses, then
279SPI ID ranges for all chips.
280"distributor-regions" is used to define the number of GICD addresses.
Jerry Wang99fe2432024-06-17 14:02:32 +0100281"redistributor-regions" is used to define the number of GICR addresses.
Jerry Wang88bec722025-05-06 20:17:05 +0100282"spi_regions" is used to define the number of SPI ID ranges.
Jerry Wang99fe2432024-06-17 14:02:32 +0100283
284This node is optional. When absent, the default configuration assumes there is
Jerry Wang88bec722025-05-06 20:17:05 +0100285one distributor, redistributor and SPI region.
286The default GICD memory range is from ``GICD_BASE`` to ``GICD_BASE + GICD_SIZE``.
287The default GICR memory range is from ``GICR_BASE`` to ``GICR_BASE + GICR_FRAMES * GIC_REDIST_SIZE_PER_PE``.
288All SPIs are directed to chip 0.
289
290To enable support on multi chip platforms, this node is mandatory. Each chip
291need to have one GICD memory range, one or more GICR memory ranges and one SPI ID range.
292
293The sum of `distributor-regions`, `redistributor-regions` and `spi-regions` must
294equal the number of entries in field `reg`.
295
Jerry Wang99fe2432024-06-17 14:02:32 +0100296
297.. code:: shell
298
299 gic: interrupt-controller@0x30000000 {
300 compatible = "arm,gic-v3";
301 #address-cells = <2>;
302 #size-cells = <1>;
Jerry Wang88bec722025-05-06 20:17:05 +0100303 #distributor-regions = <2>;
304 #redistributor-regions = <2>;
305 #spi-regions = <2>;
306 reg = <0x00 0x30000000 0x10000>, // GICD 0: Chip 0
307 <0x10 0x30000000 0x10000>, // GICD 1: Chip 1
Jerry Wang99fe2432024-06-17 14:02:32 +0100308 <0x00 0x301C0000 0x400000>, // GICR 0: Chip 0
309 <0x10 0x301C0000 0x400000>, // GICR 1: Chip 1
Jerry Wang88bec722025-05-06 20:17:05 +0100310 <0x00 0x00000020 0x0001DF>, // SPI: Chip 0
311 <0x00 0x00000200 0x0001DF>; // SPI: Chip 1
Jerry Wang99fe2432024-06-17 14:02:32 +0100312 };
313
314The above is an example representation of the referred interrupt controller
315description. The cells are made up of three values. The first two 32-bit values
316make up a 64-bit value representing the address of the GIC redistributor. The
317third value represents the size of this region. In this example,
Jerry Wang88bec722025-05-06 20:17:05 +0100318redistributor-regions states there are 2 GICD cell, GICR cells and SPI cells.
319The address of GICD 0 is `0x0030000000` and the size of that region is `0x10000`.
320The address of GICR 0 is `0x00301C0000` and the size of that region is `0x400000`.
321The SPI block of Chip 0 starts from `0x20` and contains `0x1DF` SPIs.
Jerry Wang99fe2432024-06-17 14:02:32 +0100322
J-Alves5eafd222023-10-26 14:19:21 +0100323Secure Partitions Configuration
324-------------------------------
325
326SP Manifests
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200327~~~~~~~~~~~~
328
329An SP manifest describes SP attributes as defined in `[1]`_
330(partition manifest at virtual FF-A instance) in DTS format. It is
331represented as a single file associated with the SP. A sample is
332provided by `[5]`_. A binding document is provided by `[6]`_.
333
J-Alves5eafd222023-10-26 14:19:21 +0100334Platform topology
335~~~~~~~~~~~~~~~~~
336
337The *execution-ctx-count* SP manifest field can take the value of one or the
338total number of PEs. The FF-A specification `[1]`_ recommends the
339following SP types:
340
341- Pinned MP SPs: an execution context matches a physical PE. MP SPs must
342 implement the same number of ECs as the number of PEs in the platform.
343- Migratable UP SPs: a single execution context can run and be migrated on any
344 physical PE. Such SP declares a single EC in its SP manifest. An UP SP can
345 receive a direct message request originating from any physical core targeting
346 the single execution context.
347
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200348Secure Partition packages
349~~~~~~~~~~~~~~~~~~~~~~~~~
350
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500351Secure partitions are bundled as independent package files. Current supported
352partition package types are a Secure Partition Package or a Transfer List Package.
353
354The partition package type can be specified in the SP Layout of the SP (see section
355`Secure Partitions Layout File`_).
356
357A Secure Partition package is an implementation defined format that includes:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200358
359- a header
360- a DTB
361- an image payload
362
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500363A Transfer List (TL) package type should include an entry for the image and an entry for the DTB
364using the Transfer Entry format. The TL package can also use other Transfer Entry types to include
365optional platform-specific boot information to be passed to the SP, such as a HOB list. More
366information on Transfer Lists can be found in the `Firmware Handoff specification`_.
367
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200368The header starts with a magic value and offset values to SP DTB and
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500369image payload. Each partition package is loaded independently by BL2 loader
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200370and verified for authenticity and integrity.
371
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500372The partition package identified by its UUID (matching FF-A uuid property) is
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200373inserted as a single entry into the FIP at end of the TF-A build flow
374as shown:
375
376.. code:: shell
377
378 Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw"
379 EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw"
380 Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw"
381 Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw"
382 HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config"
383 TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config"
384 SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config"
385 TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config"
386 NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config"
387 B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob"
388 D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob"
389
390.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml
391
J-Alves5eafd222023-10-26 14:19:21 +0100392Secure Partitions Layout File
393~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200394
395A json-formatted description file is passed to the build flow specifying paths
396to the SP binary image and associated DTS partition manifest file. The latter
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500397is processed by the dtc compiler to generate a DTB fed into the partition package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100398Each partition can be configured with the following fields:
399
400:code:`image`
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500401 - Specifies the filename and offset of the image within the partition package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100402 - Can be written as :code:`"image": { "file": "path", "offset": 0x1234 }` to
403 give both :code:`image.file` and :code:`image.offset` values explicitly, or
404 can be written as :code:`"image": "path"` to give :code:`image.file` and value
405 and leave :code:`image.offset` absent.
406
407 :code:`image.file`
408 - Specifies the filename of the image.
409
410 :code:`image.offset`
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500411 - Specifies the offset of the image within the partiton package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100412 - Must be 4KB aligned, because that is the translation granule supported by Hafnium SPMC.
413 - Optional. Defaults to :code:`0x4000`.
414
415:code:`pm`
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500416 - Specifies the filename and offset of the partition manifest within the partition package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100417 - Can be written as :code:`"pm": { "file": "path", "offset": 0x1234 }` to
418 give both :code:`pm.file` and :code:`pm.offset` values explicitly, or
419 can be written as :code:`"pm": "path"` to give :code:`pm.file` and value
420 and leave :code:`pm.offset` absent.
421
422 :code:`pm.file`
423 - Specifies the filename of the partition manifest.
424
425 :code:`pm.offset`
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500426 - Specifies the offset of the partition manifest within the partition package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100427 - Must be 4KB aligned, because that is the translation granule supported by Hafnium SPMC.
428 - Optional. Defaults to :code:`0x1000`.
429
430:code:`image.offset` and :code:`pm.offset` can be leveraged to support SPs with
431S1 translation granules that differ from 4KB, and to configure the regions
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500432allocated within the partition package, as well as to comply with the requirements for
Karl Meakin82593ce2023-08-30 16:38:28 +0100433the implementation of the boot information protocol (see `Passing boot data to
434the SP`_ for more details).
435
436:code:`owner`
437 - Specifies the SP owner, identifying the signing domain in case of dual root CoT.
438 - Possible values are :code:`SiP` (silicon owner) or :code:`Plat` (platform owner).
439 - Optional. Defaults to :code:`SiP`.
440
441:code:`uuid`
442 - Specifies the UUID of the partition.
443 - Optional. Defaults to the value of the :code:`uuid` field from the DTS partition manifest.
444
445:code:`physical-load-address`
446 - Specifies the :code:`load_address` field of the generated DTS fragment.
447 - Optional. Defaults to the value of the :code:`load-address` from the DTS partition manifest.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200448
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500449:code:`package`
450 - Specifies the package type of the partition package.
451 - Optional. Defaults to the value of :code:`sp_pkg`.
452
453:code:`size`
454 - Specifies the size in bytes of the partition package.
455 - Optional. Defaults to :code:`0x100000`.
456
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200457.. code:: shell
458
459 {
460 "tee1" : {
461 "image": "tee1.bin",
462 "pm": "tee1.dts",
463 "owner": "SiP",
464 "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f"
465 },
466
467 "tee2" : {
468 "image": "tee2.bin",
469 "pm": "tee2.dts",
470 "owner": "Plat"
471 },
472
473 "tee3" : {
474 "image": {
475 "file": "tee3.bin",
476 "offset":"0x2000"
477 },
478 "pm": {
479 "file": "tee3.dts",
480 "offset":"0x6000"
481 },
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500482 "owner": "Plat",
483 "package": "tl_pkg",
484 "size": "0x100000"
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200485 },
486 }
487
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200488SPMC boot
J-Alves5eafd222023-10-26 14:19:21 +0100489=========
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200490
491The SPMC is loaded by BL2 as the BL32 image.
492
493The SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_.
494
495BL2 passes the SPMC manifest address to BL31 through a register.
496
497At boot time, the SPMD in BL31 runs from the primary core, initializes the core
498contexts and launches the SPMC (BL32) passing the following information through
499registers:
500
501- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob).
502- X1 holds the ``HW_CONFIG`` physical address.
503- X4 holds the currently running core linear id.
504
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200505Secure boot
J-Alves5eafd222023-10-26 14:19:21 +0100506-----------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200507
508The SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC,
509SPMC manifest, secure partitions and verifies them for authenticity and integrity.
510Refer to TBBR specification `[3]`_.
511
512The multiple-signing domain feature (in current state dual signing domain `[8]`_) allows
513the use of two root keys namely S-ROTPK and NS-ROTPK:
514
515- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK.
516- BL33 may be signed by the OEM using NS-ROTPK.
517- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK).
518- A maximum of 4 partitions can be signed with the S-ROTPK key and 4 partitions
519 signed with the NS-ROTPK key.
520
J-Alves5eafd222023-10-26 14:19:21 +0100521Also refer to `Secure Partitions Configuration`_ and `TF-A build options`_ sections.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200522
523Boot phases
524-----------
525
526Primary core boot-up
527~~~~~~~~~~~~~~~~~~~~
528
529Upon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical
530core. The SPMC performs its platform initializations and registers the SPMC
531secondary physical core entry point physical address by the use of the
532`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD
533at secure physical FF-A instance).
534
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500535The SPMC then creates secure partitions based on partition packages and manifests. Each
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200536secure partition is launched in sequence (`SP Boot order`_) on their "primary"
537execution context. If the primary boot physical core linear id is N, an MP SP is
538started using EC[N] on PE[N] (see `Platform topology`_). If the partition is a
539UP SP, it is started using its unique EC0 on PE[N].
540
541The SP primary EC (or the EC used when the partition is booted as described
542above):
543
544- Performs the overall SP boot time initialization, and in case of a MP SP,
545 prepares the SP environment for other execution contexts.
546- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure
547 virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA
548 entry point for other execution contexts.
549- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or
550 ``FFA_ERROR`` in case of failure.
551
552Secondary cores boot-up
553~~~~~~~~~~~~~~~~~~~~~~~
554
555Once the system is started and NWd brought up, a secondary physical core is
556woken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism
557calls into the SPMD on the newly woken up physical core. Then the SPMC is
558entered at the secondary physical core entry point.
559
Madhukar Pappireddyb08e89b2025-04-21 12:49:53 -0500560As per secondary boot protocol described in section 18.2.2 of the FF-A v1.3ALP1
561specification, each pinned execution context of every MP SP is woken up by SPMC,
562thereby giving an opportunity to the MP SP's EC on secondary core to initialize
563itself. Upon successful initialization, the EC relinquishes CPU cycles through
564FFA_MSG_WAIT ABI and moves to WAITING state.
565
566Note that an UP SP does not have a pinned execution context. Hence, if a system
567only has UP SPs, then there are no pinned execution contexts to be resumed on
568secondary cores.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200569
570In a linux based system, once secure and normal worlds are booted but prior to
571a NWd FF-A driver has been loaded:
572
Madhukar Pappireddyb08e89b2025-04-21 12:49:53 -0500573- Every MP SP has initialized its primary EC in response to primary core boot up
574 (at system initialization) and secondary ECs in response to secondary cores
575 boot up (as a result of linux invoking PSCI_CPU_ON for all secondary cores).
576 If there are multiple MP SPs deployed, the order in which their respective
577 ECs are woken up is determined by the boot-order field in the partition
578 manifests.
579- Every UP SP has its only EC initialized as a result of secure world
580 initialization on the primary boot core.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200581
582Refer to `Power management`_ for further details.
583
J-Alves5eafd222023-10-26 14:19:21 +0100584Loading of SPs
585--------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200586
J-Alves5eafd222023-10-26 14:19:21 +0100587At boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted
588below:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200589
J-Alves5eafd222023-10-26 14:19:21 +0100590.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200591
J-Alves5eafd222023-10-26 14:19:21 +0100592Note this boot flow is an implementation sample on Arm's FVP platform.
593Platforms not using TF-A's *Firmware CONFiguration* framework would adjust to a
594different boot flow. The flow restricts to a maximum of 8 secure partitions.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200595
J-Alves5eafd222023-10-26 14:19:21 +0100596SP Boot order
597~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200598
J-Alves5eafd222023-10-26 14:19:21 +0100599SP manifests provide an optional boot order attribute meant to resolve
600dependencies such as an SP providing a service required to properly boot
601another SP. SPMC boots the SPs in accordance to the boot order attribute,
602lowest to the highest value. If the boot order attribute is absent from the FF-A
603manifest, the SP is treated as if it had the highest boot order value
604(i.e. lowest booting priority). The FF-A specification mandates this field
605is unique to each SP.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200606
J-Alves5eafd222023-10-26 14:19:21 +0100607It is possible for an SP to call into another SP through a direct request
608provided the latter SP has already been booted.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200609
J-Alves5eafd222023-10-26 14:19:21 +0100610Passing boot data to the SP
611~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200612
J-Alves5eafd222023-10-26 14:19:21 +0100613In `[1]`_ , the section "Boot information protocol" defines a method for passing
614data to the SPs at boot time. It specifies the format for the boot information
615descriptor and boot information header structures, which describe the data to be
616exchanged between SPMC and SP.
617The specification also defines the types of data that can be passed.
618The aggregate of both the boot info structures and the data itself is designated
619the boot information blob, and is passed to a Partition as a contiguous memory
620region.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200621
Kathleen Capellaa10727d2025-01-31 16:19:03 -0500622Currently, the SPM implementation supports the FDT type, which is used to pass the
623partition's DTB manifest, and the Hand-off Block (HOB) list type.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200624
Kathleen Capella14dc3bc2025-01-31 18:09:54 -0500625The region for the boot information blob is allocated through the partition package.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200626
J-Alves5eafd222023-10-26 14:19:21 +0100627.. image:: ../resources/diagrams/partition-package.png
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200628
J-Alves5eafd222023-10-26 14:19:21 +0100629To adjust the space allocated for the boot information blob, the json description
630of the SP (see section `Secure Partitions Layout File`_) shall be updated to contain
631the manifest offset. If no offset is provided the manifest offset defaults to 0x1000,
632which is the page size in the Hafnium SPMC.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200633
Kathleen Capellaa10727d2025-01-31 16:19:03 -0500634Currently, the SPM implementation does not yet support specifying the offset for the
635HOB list in the json description of the SP. A default value of 0x2000 is used.
636
J-Alves5eafd222023-10-26 14:19:21 +0100637The configuration of the boot protocol is done in the SPs manifest. As defined by
638the specification, the manifest field 'gp-register-num' configures the GP register
639which shall be used to pass the address to the partitions boot information blob when
640booting the partition.
641In addition, the Hafnium SPMC implementation requires the boot information arguments
642to be listed in a designated DT node:
643
644.. code:: shell
645
646 boot-info {
647 compatible = "arm,ffa-manifest-boot-info";
648 ffa_manifest;
649 };
650
Kathleen Capellaa10727d2025-01-31 16:19:03 -0500651.. code:: shell
652
653 boot-info {
654 compatible = "arm,ffa-manifest-boot-info";
655 hob_list;
656 };
657
J-Alves5eafd222023-10-26 14:19:21 +0100658The whole secure partition package image (see `Secure Partition packages`_) is
659mapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can
660retrieve the address for the boot information blob in the designated GP register,
661process the boot information header and descriptors, access its own manifest
Kathleen Capellaa10727d2025-01-31 16:19:03 -0500662DTB blob or HOB list and extract its properties.
J-Alves5eafd222023-10-26 14:19:21 +0100663
664SPMC Runtime
665============
666
667Parsing SP partition manifests
668------------------------------
669
670Hafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_.
671Note the current implementation may not implement all optional fields.
672
673The SP manifest may contain memory and device regions nodes:
674
675- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at
676 load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can
677 specify RX/TX buffer regions in which case it is not necessary for an SP
678 to explicitly invoke the ``FFA_RXTX_MAP`` interface. The memory referred
679 shall be contained within the memory ranges defined in SPMC manifest. The
680 NS bit in the attributes field should be consistent with the security
681 state of the range that it relates to. I.e. non-secure memory shall be
682 part of a non-secure memory range, and secure memory shall be contained
683 in a secure memory range of a given platform.
684- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or
685 EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate
686 additional resources (e.g. interrupts).
687
688For the SPMC, base addresses for memory and device region nodes are IPAs provided
689the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation regime.
690
Olivier Deprezb8bd7d72023-10-27 16:14:13 +0200691ote: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the
J-Alves5eafd222023-10-26 14:19:21 +0100692same set of page tables. It is still open whether two sets of page tables shall
693be provided per SP. The memory region node as defined in the specification
694provides a memory security attribute hinting to map either to the secure or
695non-secure EL1&0 Stage-2 table if it exists.
696
697Secure partitions scheduling
698----------------------------
699
Olivier Deprez8c4cb2d2023-10-27 16:07:11 +0200700The FF-A specification `[1]`_ provides two ways to allocate CPU cycles to
J-Alves5eafd222023-10-26 14:19:21 +0100701secure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of:
702
Kathleen Capella6e3abcf2024-02-05 16:17:35 -0500703- the FFA_MSG_SEND_DIRECT_REQ (or FFA_MSG_SEND_DIRECT_REQ2) interface.
J-Alves5eafd222023-10-26 14:19:21 +0100704- the FFA_RUN interface.
705
706Additionally a secure interrupt can pre-empt the normal world execution and give
707CPU cycles by transitioning to EL3 and S-EL2.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200708
709Mandatory interfaces
710--------------------
711
712The following interfaces are exposed to SPs:
713
714- ``FFA_VERSION``
715- ``FFA_FEATURES``
716- ``FFA_RX_RELEASE``
717- ``FFA_RXTX_MAP``
718- ``FFA_RXTX_UNMAP``
719- ``FFA_PARTITION_INFO_GET``
720- ``FFA_ID_GET``
721- ``FFA_MSG_WAIT``
722- ``FFA_MSG_SEND_DIRECT_REQ``
723- ``FFA_MSG_SEND_DIRECT_RESP``
724- ``FFA_MEM_DONATE``
725- ``FFA_MEM_LEND``
726- ``FFA_MEM_SHARE``
727- ``FFA_MEM_RETRIEVE_REQ``
728- ``FFA_MEM_RETRIEVE_RESP``
729- ``FFA_MEM_RELINQUISH``
730- ``FFA_MEM_FRAG_RX``
731- ``FFA_MEM_FRAG_TX``
732- ``FFA_MEM_RECLAIM``
733- ``FFA_RUN``
734
735As part of the FF-A v1.1 support, the following interfaces were added:
736
737 - ``FFA_NOTIFICATION_BITMAP_CREATE``
738 - ``FFA_NOTIFICATION_BITMAP_DESTROY``
739 - ``FFA_NOTIFICATION_BIND``
740 - ``FFA_NOTIFICATION_UNBIND``
741 - ``FFA_NOTIFICATION_SET``
742 - ``FFA_NOTIFICATION_GET``
743 - ``FFA_NOTIFICATION_INFO_GET``
744 - ``FFA_SPM_ID_GET``
745 - ``FFA_SECONDARY_EP_REGISTER``
746 - ``FFA_MEM_PERM_GET``
747 - ``FFA_MEM_PERM_SET``
748 - ``FFA_MSG_SEND2``
749 - ``FFA_RX_ACQUIRE``
750
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700751As part of the FF-A v1.2 support, the following interfaces were added:
Kathleen Capella6e3abcf2024-02-05 16:17:35 -0500752
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700753- ``FFA_PARTITION_INFO_GET_REGS``
Kathleen Capella6e3abcf2024-02-05 16:17:35 -0500754- ``FFA_MSG_SEND_DIRECT_REQ2``
755- ``FFA_MSG_SEND_DIRECT_RESP2``
Karl Meakind40979f2024-05-13 10:21:56 +0100756- ``FFA_CONSOLE_LOG``
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700757
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200758FFA_VERSION
759~~~~~~~~~~~
760
761``FFA_VERSION`` requires a *requested_version* parameter from the caller.
762The returned value depends on the caller:
763
764- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version
765 specified in the SPMC manifest.
766- SP: the SPMC returns its own implemented version.
767- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version.
768
Karl Meakin67196c72024-05-15 09:39:35 +0100769The FF-A version can only be changed by calls to ``FFA_VERSION`` before other
770calls to other FF-A ABIs have been made. Calls to ``FFA_VERSION`` after
771subsequent ABI calls will fail.
772
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200773FFA_FEATURES
774~~~~~~~~~~~~
775
776FF-A features supported by the SPMC may be discovered by secure partitions at
777boot (that is prior to NWd is booted) or run-time.
778
779The SPMC calling FFA_FEATURES at secure physical FF-A instance always get
780FFA_SUCCESS from the SPMD.
781
Karl Meakin963a5d72024-05-13 10:32:29 +0100782S-EL1 partitions calling FFA_FEATURES at virtual FF-A instance with NPI and MEI
783interrupt feature IDs get FFA_SUCCESS.
784
785S-EL0 partitions are not supported for NPI: ``FFA_NOT_SUPPORTED`` will be
786returned.
787
788Physical FF-A instances are not supported for NPI and MEI: ``FFA_NOT_SUPPORTED``
789will be returned.
790
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200791The request made by an Hypervisor or OS kernel is forwarded to the SPMC and
792the response relayed back to the NWd.
793
794FFA_RXTX_MAP/FFA_RXTX_UNMAP
795~~~~~~~~~~~~~~~~~~~~~~~~~~~
796
797When invoked from a secure partition FFA_RXTX_MAP maps the provided send and
798receive buffers described by their IPAs to the SP EL1&0 Stage-2 translation
799regime as secure buffers in the MMU descriptors.
800
801When invoked from the Hypervisor or OS kernel, the buffers are mapped into the
802SPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU
803descriptors. The provided addresses may be owned by a VM in the normal world,
804which is expected to receive messages from the secure world. The SPMC will in
805this case allocate internal state structures to facilitate RX buffer access
806synchronization (through FFA_RX_ACQUIRE interface), and to permit SPs to send
Karl Meakinb1dbca92024-01-24 16:51:22 +0000807messages. The addresses used must be contained in the SPMC manifest NS memory
808node (see `SPMC manifest`_).
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200809
810The FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the
811caller, either it being the Hypervisor or OS kernel, as well as a secure
Karl Meakinb1dbca92024-01-24 16:51:22 +0000812partition, and restores them in the VM's translation regime so that they can be
813used for memory sharing operations from the normal world again.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200814
Karl Meakin963a5d72024-05-13 10:32:29 +0100815The minimum and maximum buffer sizes supported by the FF-A instance can be
816queried by calling ``FFA_FEATURES`` with the ``FFA_RXTX_MAP`` function ID.
817
J-Alvesbaaf9e52024-10-18 11:41:36 +0100818FFA_PARTITION_INFO_GET/FFA_PARTITION_INFO_GET_REGS
819~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200820
821Partition info get call can originate:
822
823- from SP to SPMC
824- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD.
J-Alvesbaaf9e52024-10-18 11:41:36 +0100825- from SPMC to SPMD (FFA_PARTITION_INFO_GET_REGS only)
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200826
J-Alvesbaaf9e52024-10-18 11:41:36 +0100827The primary use of the FFA_PARTITION_INFO_GET_REGS is to return partition
828information via registers as opposed to via RX/TX buffers and is useful in
829cases where sharing memory is difficult.
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700830
J-Alvesbaaf9e52024-10-18 11:41:36 +0100831The SPMC reports the features supported by an SP in accordance to the caller.
832E.g. SPs can't issue direct message requests to the Normal World. As such,
833even though SP may have enabled sending direct message requests in the manifest,
834the respective SP's properties information will hint that the SP doesn't support
835sending direct message requests.
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700836
J-Alvesbaaf9e52024-10-18 11:41:36 +0100837The information is also filtered by FF-A version. E.g. indirect message support
838in Hafnium was added in FF-A v1.1. An FF-A v1.0 caller will not get indirect
839message support for an SP, even if the SP is v1.1 or higher, and has enabled
840indirect messaging in its manifest.
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700841
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200842FFA_ID_GET
843~~~~~~~~~~
844
845The FF-A id space is split into a non-secure space and secure space:
846
847- FF-A ID with bit 15 clear relates to VMs.
848- FF-A ID with bit 15 set related to SPs.
849- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD
850 and SPMC.
851
852The SPMD returns:
853
854- The default zero value on invocation from the Hypervisor.
855- The ``spmc_id`` value specified in the SPMC manifest on invocation from
856 the SPMC (see `SPMC manifest`_)
857
858This convention helps the SPMC to determine the origin and destination worlds in
859an FF-A ABI invocation. In particular the SPMC shall filter unauthorized
860transactions in its world switch routine. It must not be permitted for a VM to
861use a secure FF-A ID as origin world by spoofing:
862
863- A VM-to-SP direct request/response shall set the origin world to be non-secure
864 (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15
865 set).
866- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15
867 for both origin and destination IDs.
868
869An incoming direct message request arriving at SPMD from NWd is forwarded to
870SPMC without a specific check. The SPMC is resumed through eret and "knows" the
871message is coming from normal world in this specific code path. Thus the origin
872endpoint ID must be checked by SPMC for being a normal world ID.
873
874An SP sending a direct message request must have bit 15 set in its origin
875endpoint ID and this can be checked by the SPMC when the SP invokes the ABI.
876
877The SPMC shall reject the direct message if the claimed world in origin endpoint
878ID is not consistent:
879
880- It is either forwarded by SPMD and thus origin endpoint ID must be a "normal
881 world ID",
882- or initiated by an SP and thus origin endpoint ID must be a "secure world ID".
883
Kathleen Capellaccbf26c2024-09-19 17:33:10 -0400884FFA_MSG_WAIT
885~~~~~~~~~~~~
886
887FFA_MSG_WAIT is used to transition the calling execution context from the
888RUNNING state to the WAITING state, subject to the restrictions of the
889partition's current runtime model (see `Partition runtime models`_).
890
891Secondarily, an invocation of FFA_MSG_WAIT will relinquish ownership of the
892caller's RX buffer to the buffer's producer. FF-A v1.2 introduces the ability to
893optionally retain the buffer on an invocation of FFA_MSG_WAIT through use of a
894flag.
895
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200896
897FFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP
898~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
899
900This is a mandatory interface for secure partitions consisting in direct request
901and responses with the following rules:
902
903- An SP can send a direct request to another SP.
904- An SP can receive a direct request from another SP.
905- An SP can send a direct response to another SP.
906- An SP cannot send a direct request to an Hypervisor or OS kernel.
907- An Hypervisor or OS kernel can send a direct request to an SP.
908- An SP can send a direct response to an Hypervisor or OS kernel.
Karl Meakine06384d2024-11-01 18:48:53 +0000909- An SP cannot reply to a framework direct request with a non-framework direct response.
910
911The hypervisor can inform SPs when a VM is created or destroyed by sending **VM
912availability messages** via the ``FFA_MSG_SEND_DIRECT_REQ`` ABI.
913
914A SP subscribes to receiving VM created and/or VM destroyed messages by
915specifying the ``vm-availability-messages`` field in its manifest (see
Daniel Boulby0a697182024-11-15 11:46:26 +0000916`partition properties`_). The SPM will only forward messages to the SP if the SP
Karl Meakine06384d2024-11-01 18:48:53 +0000917is subscribed to the message kind. The SP must reply with the corresponding
918direct message response (via the ``FFA_MSG_SEND_DIRECT_RESP`` ABI) after it has
919handled the message.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200920
Kathleen Capella6e3abcf2024-02-05 16:17:35 -0500921FFA_MSG_SEND_DIRECT_REQ2/FFA_MSG_SEND_DIRECT_RESP2
922~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
923
924The primary usage of these ABIs is to send a direct request to a specified
925UUID within an SP that has multiple UUIDs declared in its manifest.
926
927Secondarily, it can be used to send a direct request with an extended
928set of message payload arguments.
929
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200930FFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY
931~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
932
933The secure partitions notifications bitmap are statically allocated by the SPMC.
934Hence, this interface is not to be issued by secure partitions.
935
936At initialization, the SPMC is not aware of VMs/partitions deployed in the
937normal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC
938to be prepared to handle notifications for the provided VM ID.
939
940FFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND
941~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
942
943Pair of interfaces to manage permissions to signal notifications. Prior to
944handling notifications, an FF-A endpoint must allow a given sender to signal a
945bitmap of notifications.
946
947If the receiver doesn't have notification support enabled in its FF-A manifest,
948it won't be able to bind notifications, hence forbidding it to receive any
949notifications.
950
951FFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET
952~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
953
954FFA_NOTIFICATION_GET retrieves all pending global notifications and
955per-vCPU notifications targeted to the current vCPU.
956
957Hafnium maintains a global count of pending notifications which gets incremented
958and decremented when handling FFA_NOTIFICATION_SET and FFA_NOTIFICATION_GET
959respectively. A delayed SRI is triggered if the counter is non-zero when the
960SPMC returns to normal world.
961
962FFA_NOTIFICATION_INFO_GET
963~~~~~~~~~~~~~~~~~~~~~~~~~
964
965Hafnium maintains a global count of pending notifications whose information
966has been retrieved by this interface. The count is incremented and decremented
967when handling FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET respectively.
968It also tracks notifications whose information has been retrieved individually,
969such that it avoids duplicating returned information for subsequent calls to
970FFA_NOTIFICATION_INFO_GET. For each notification, this state information is
971reset when receiver called FFA_NOTIFICATION_GET to retrieve them.
972
973FFA_SPM_ID_GET
974~~~~~~~~~~~~~~
975
976Returns the FF-A ID allocated to an SPM component which can be one of SPMD
977or SPMC.
978
979At initialization, the SPMC queries the SPMD for the SPMC ID, using the
980FFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using
981the FFA_SPM_ID_GET interface at the secure physical FF-A instance.
982
983Secure partitions call this interface at the virtual FF-A instance, to which
984the SPMC returns the priorly retrieved SPMC ID.
985
986The Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the
987SPMD, which returns the SPMC ID.
988
989FFA_SECONDARY_EP_REGISTER
990~~~~~~~~~~~~~~~~~~~~~~~~~
991
992When the SPMC boots, all secure partitions are initialized on their primary
993Execution Context.
994
995The FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition
996from its first execution context, to provide the entry point address for
997secondary execution contexts.
998
999A secondary EC is first resumed either upon invocation of PSCI_CPU_ON from
1000the NWd or by invocation of FFA_RUN.
1001
1002FFA_RX_ACQUIRE/FFA_RX_RELEASE
1003~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1004
1005The RX buffers can be used to pass information to an FF-A endpoint in the
1006following scenarios:
1007
1008 - When it was targetted by a FFA_MSG_SEND2 invokation from another endpoint.
1009 - Return the result of calling ``FFA_PARTITION_INFO_GET``.
1010 - In a memory share operation, as part of the ``FFA_MEM_RETRIEVE_RESP``,
1011 with the memory descriptor of the shared memory.
1012
1013If a normal world VM is expected to exchange messages with secure world,
1014its RX/TX buffer addresses are forwarded to the SPMC via FFA_RXTX_MAP ABI,
1015and are from this moment owned by the SPMC.
1016The hypervisor must call the FFA_RX_ACQUIRE interface before attempting
1017to use the RX buffer, in any of the aforementioned scenarios. A successful
1018call to FFA_RX_ACQUIRE transfers ownership of RX buffer to hypervisor, such
1019that it can be safely used.
1020
1021The FFA_RX_RELEASE interface is used after the FF-A endpoint is done with
1022processing the data received in its RX buffer. If the RX buffer has been
1023acquired by the hypervisor, the FFA_RX_RELEASE call must be forwarded to
1024the SPMC to reestablish SPMC's RX ownership.
1025
1026An attempt from an SP to send a message to a normal world VM whose RX buffer
1027was acquired by the hypervisor fails with error code FFA_BUSY, to preserve
1028the RX buffer integrity.
1029The operation could then be conducted after FFA_RX_RELEASE.
1030
1031FFA_MSG_SEND2
1032~~~~~~~~~~~~~
1033
1034Hafnium copies a message from the sender TX buffer into receiver's RX buffer.
1035For messages from SPs to VMs, operation is only possible if the SPMC owns
1036the receiver's RX buffer.
1037
1038Both receiver and sender need to enable support for indirect messaging,
1039in their respective partition manifest. The discovery of support
1040of such feature can be done via FFA_PARTITION_INFO_GET.
1041
1042On a successful message send, Hafnium pends an RX buffer full framework
1043notification for the receiver, to inform it about a message in the RX buffer.
1044
1045The handling of framework notifications is similar to that of
1046global notifications. Binding of these is not necessary, as these are
1047reserved to be used by the hypervisor or SPMC.
1048
Karl Meakind40979f2024-05-13 10:21:56 +01001049FFA_CONSOLE_LOG
1050~~~~~~~~~~~~~~~
1051
1052``FFA_CONSOLE_LOG`` allows debug logging to the UART console.
1053Characters are packed into registers:
Olivier Deprez0b45a2e2024-05-17 15:50:20 +02001054
1055- `w2-w7` (|SMCCC| 32-bit)
1056- `x2-x7` (|SMCCC| 64-bit, before v1.2)
1057- `x2-x17` (|SMCCC| 64-bit, v1.2 or later)
Karl Meakind40979f2024-05-13 10:21:56 +01001058
Madhukar Pappireddy0b2304b2023-08-15 18:05:21 -05001059Paravirtualized interfaces
1060--------------------------
1061
1062Hafnium SPMC implements the following implementation-defined interface(s):
1063
1064HF_INTERRUPT_ENABLE
1065~~~~~~~~~~~~~~~~~~~
1066
1067Enables or disables the given virtual interrupt for the calling execution
1068context. Returns 0 on success, or -1 if the interrupt id is invalid.
1069
1070HF_INTERRUPT_GET
1071~~~~~~~~~~~~~~~~
1072
1073Returns the ID of the next pending virtual interrupt for the calling execution
1074context, and acknowledges it (i.e. marks it as no longer pending). Returns
1075HF_INVALID_INTID if there are no pending interrupts.
1076
1077HF_INTERRUPT_DEACTIVATE
1078~~~~~~~~~~~~~~~~~~~~~~~
1079
1080Drops the current interrupt priority and deactivates the given virtual and
1081physical interrupt ID for the calling execution context. Returns 0 on success,
1082or -1 otherwise.
1083
1084HF_INTERRUPT_RECONFIGURE
1085~~~~~~~~~~~~~~~~~~~~~~~~
1086
1087An SP specifies the list of interrupts it owns through its partition manifest.
1088This paravirtualized interface allows an SP to reconfigure a physical interrupt
1089in runtime. It accepts three arguments, namely, interrupt ID, command and value.
1090The command & value pair signify what change is being requested by the current
1091Secure Partition for the given interrupt.
1092
1093SPMC returns 0 to indicate that the command was processed successfully or -1 if
1094it failed to do so. At present, this interface only supports the following
1095commands:
1096
1097 - ``INT_RECONFIGURE_TARGET_PE``
1098 - Change the target CPU of the interrupt.
1099 - Value represents linear CPU index in the range 0 to (MAX_CPUS - 1).
1100
1101 - ``INT_RECONFIGURE_SEC_STATE``
1102 - Change the security state of the interrupt.
1103 - Value must be either 0 (Non-secure) or 1 (Secure).
1104
1105 - ``INT_RECONFIGURE_ENABLE``
1106 - Enable or disable the physical interrupt.
1107 - Value must be either 0 (Disable) or 1 (Enable).
1108
Daniel Boulbyc9866ab2024-11-12 16:37:02 +00001109HF_INTERRUPT_SEND_IPI
1110~~~~~~~~~~~~~~~~~~~~~
1111Inter-Processor Interrupts (IPIs) are a mechanism for an SP to send an interrupt to
1112itself on another CPU in a multiprocessor system. The details are described below
1113in the section `Inter-Processor Interrupts`_.
1114
1115HF_INTERRUPT_SEND_IPI is the interface that the SP can use to trigger an IPI,
1116giving the vCPU ID it wishes to target. 0 is returned if the IPI is successfully sent.
1117Otherwise -1 is returned if the target vCPU ID was invalid (the current vCPU ID or
1118greater than the vCPU count).
1119
1120The interface is only available through the HVC conduit for S-EL1 MP partitions. Since
1121S-SEL0 or S-EL1 UP partitions only have a single vCPU they cannot target a different
1122vCPU and therefore have no need for IPIs.
1123
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001124SPMC-SPMD direct requests/responses
1125-----------------------------------
1126
1127Implementation-defined FF-A IDs are allocated to the SPMC and SPMD.
1128Using those IDs in source/destination fields of a direct request/response
1129permits SPMD to SPMC communication and either way.
1130
1131- SPMC to SPMD direct request/response uses SMC conduit.
1132- SPMD to SPMC direct request/response uses ERET conduit.
1133
1134This is used in particular to convey power management messages.
1135
J-Alves5eafd222023-10-26 14:19:21 +01001136Notifications
1137-------------
1138
1139The FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous
1140communication mechanism with non-blocking semantics. It allows for one FF-A
1141endpoint to signal another for service provision, without hindering its current
1142progress.
1143
1144Hafnium currently supports 64 notifications. The IDs of each notification define
1145a position in a 64-bit bitmap.
1146
1147The signaling of notifications can interchangeably happen between NWd and SWd
1148FF-A endpoints.
1149
1150The SPMC is in charge of managing notifications from SPs to SPs, from SPs to
1151VMs, and from VMs to SPs. An hypervisor component would only manage
1152notifications from VMs to VMs. Given the SPMC has no visibility of the endpoints
1153deployed in NWd, the Hypervisor or OS kernel must invoke the interface
1154FFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A
1155endpoint in the NWd that supports it.
1156
1157A sender can signal notifications once the receiver has provided it with
1158permissions. Permissions are provided by invoking the interface
1159FFA_NOTIFICATION_BIND.
1160
1161Notifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth
1162they are considered to be in a pending sate. The receiver can retrieve its
1163pending notifications invoking FFA_NOTIFICATION_GET, which, from that moment,
1164are considered to be handled.
1165
1166Per the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler
1167that is in charge of donating CPU cycles for notifications handling. The
1168FF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about
1169which FF-A endpoints have pending notifications. The receiver scheduler is
1170called and informed by the FF-A driver, and it should allocate CPU cycles to the
1171receiver.
1172
1173There are two types of notifications supported:
1174
Olivier Deprezb8bd7d72023-10-27 16:14:13 +02001175- Global, which are targeted to an FF-A endpoint and can be handled within any
1176 of its execution contexts, as determined by the scheduler of the system.
J-Alves5eafd222023-10-26 14:19:21 +01001177- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a
1178 a specific execution context, as determined by the sender.
1179
1180The type of a notification is set when invoking FFA_NOTIFICATION_BIND to give
1181permissions to the sender.
1182
1183Notification signaling resorts to two interrupts:
1184
1185- Schedule Receiver Interrupt: non-secure physical interrupt to be handled by
1186 the FF-A driver within the receiver scheduler. At initialization the SPMC
1187 donates an SGI ID chosen from the secure SGI IDs range and configures it as
1188 non-secure. The SPMC triggers this SGI on the currently running core when
1189 there are pending notifications, and the respective receivers need CPU cycles
1190 to handle them.
1191- Notifications Pending Interrupt: virtual interrupt to be handled by the
1192 receiver of the notification. Set when there are pending notifications for the
1193 given secure partition. The NPI is pended when the NWd relinquishes CPU cycles
1194 to an SP.
1195
1196The notifications receipt support is enabled in the partition FF-A manifest.
1197
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001198Memory Sharing
1199--------------
1200
J-Alvesd547d6d2024-05-14 14:59:54 +01001201The Hafnium implementation aligns with FF-A v1.2 ALP0 specification,
1202'FF-A Memory Management Protocol' supplement `[11]`_. Hafnium supports
1203the following ABIs:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001204
1205 - ``FFA_MEM_SHARE`` - for shared access between lender and borrower.
1206 - ``FFA_MEM_LEND`` - borrower to obtain exclusive access, though lender
1207 retains ownership of the memory.
1208 - ``FFA_MEM_DONATE`` - lender permanently relinquishes ownership of memory
1209 to the borrower.
1210
1211The ``FFA_MEM_RETRIEVE_REQ`` interface is for the borrower to request the
1212memory to be mapped into its address space: for S-EL1 partitions the SPM updates
1213their stage 2 translation regime; for S-EL0 partitions the SPM updates their
1214stage 1 translation regime. On a successful call, the SPMC responds back with
1215``FFA_MEM_RETRIEVE_RESP``.
1216
1217The ``FFA_MEM_RELINQUISH`` interface is for when the borrower is done with using
1218a memory region.
1219
1220The ``FFA_MEM_RECLAIM`` interface is for the owner of the memory to reestablish
1221its ownership and exclusive access to the memory shared.
1222
1223The memory transaction descriptors are transmitted via RX/TX buffers. In
1224situations where the size of the memory transaction descriptor exceeds the
1225size of the RX/TX buffers, Hafnium provides support for fragmented transmission
1226of the full transaction descriptor. The ``FFA_MEM_FRAG_RX`` and ``FFA_MEM_FRAG_TX``
1227interfaces are for receiving and transmitting the next fragment, respectively.
1228
1229If lender and borrower(s) are SPs, all memory sharing operations are supported.
1230
1231Hafnium also supports memory sharing operations between the normal world and the
1232secure world. If there is an SP involved, the SPMC allocates data to track the
1233state of the operation.
1234
J-Alvesda82a1a2023-10-17 11:45:49 +01001235An SP can not share, lend or donate memory to the NWd.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001236
J-Alvesd547d6d2024-05-14 14:59:54 +01001237The SPMC is also the designated allocator for the memory handle, when borrowers
1238include at least an SP. The SPMC doesn't support the hypervisor to be allocator
1239to the memory handle.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001240
1241Hafnium also supports memory lend and share targetting multiple borrowers.
1242This is the case for a lender SP to multiple SPs, and for a lender VM to
1243multiple endpoints (from both secure world and normal world). If there is
1244at least one borrower VM, the hypervisor is in charge of managing its
J-Alvesd547d6d2024-05-14 14:59:54 +01001245stage 2 translation on a successful memory retrieve. However, the hypervisor could
1246rely on the SPMC to keep track of the state of the operation, namely:
1247if all fragments to the memory descriptors have been sent, and if the retrievers
1248are still using the memory at any given moment. In this case, the hypervisor might
1249need to request the SPMC to obtain a description of the used memory regions.
1250For example, when handling an ``FFA_MEM_RECLAIM`` the hypervisor retrieve request
1251can be used to obtain that state information, do the necessary validations,
1252and update stage-2 memory translation of the lender.
1253Hafnium currently only supports one borrower from the NWd, in a multiple borrower
1254scenario as described. If there is only a single borrower VM, the SPMC will
1255return error to the lender on call to either share, lend or donate ABIs.
1256
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001257The semantics of ``FFA_MEM_DONATE`` implies ownership transmission,
1258which should target only one partition.
1259
1260The memory share interfaces are backwards compatible with memory transaction
Daniel Boulbyd5041122024-01-31 14:24:54 +00001261descriptors from FF-A v1.0. Starting from FF-A v1.1, with the introduction
1262of the `Endpoint memory access descriptor size` and
1263`Endpoint memory access descriptor access offset` fields (from Table 11.20 of the
1264FF-A v1.2 ALP0 specification), memory transaction descriptors are forward
1265compatible, so can be used internally by Hafnium as they are sent.
1266These fields must be valid for a memory access descriptor defined for a compatible
1267FF-A version to the SPMC FF-A version. For a transaction from an FF-A v1.0 endpoint
1268the memory transaction descriptor will be translated to an FF-A v1.1 descriptor for
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001269Hafnium's internal processing of the operation. If the FF-A version of a
1270borrower is v1.0, Hafnium provides FF-A v1.0 compliant memory transaction
1271descriptors on memory retrieve response.
1272
J-Alvesffc82062023-11-07 14:19:00 +00001273In the section :ref:`SPMC Configuration` there is a mention of non-secure memory
1274range, that limit the memory region nodes the SP can define. Whatever is left of
1275the memory region node carve-outs, the SPMC utilizes the memory to create a set of
1276page tables it associates with the NWd. The memory sharing operations incoming from
1277the NWd should refer to addresses belonging to these page tables. The intent
1278is for SPs not to be able to get access to regions they are not intended to access.
1279This requires special care from the system integrator to configure the memory ranges
1280correctly, such that any SP can't be given access and interfere with execution of
1281other components. More information in the :ref:`Threat Model`.
1282
Daniel Boulbydfc312e2024-05-14 17:10:01 +01001283Hafnium SPMC supports memory management transactions for device memory regions.
1284Currently this is limited to only the ``FFA_MEM_LEND`` interface and
1285to a single borrower. The device memory region used in the transaction must have
1286been decalared in the SPMC manifest as described above. Memory defined in a device
1287region node is given the attributes Device-nGnRnE, since this is the most restrictive
1288memory type the memory must be lent with these attrbutes as well.
1289
J-Alvesd547d6d2024-05-14 14:59:54 +01001290In |RME| enabled platforms, there is the ability to change the |PAS|
1291of a given memory region `[12]`_. The SPMC can leverage this feature to fulfill the
1292semantics of the ``FFA_MEM_LEND`` and ``FFA_MEM_DONATE`` from the NWd into the SWd.
1293Currently, there is the implementation for the FVP platform to issue a
1294platform-specific SMC call to the EL3 monitor to change the PAS of the regions being
1295lent/donated. This shall guarantee the NWd can't tamper with the memory whilst
1296the SWd software expects exclusive access. For any other platform, the API under
1297the 'src/memory_protect' module can be redefined to leverage an equivalent platform
1298specific mechanism. For reference, check the `SPMC FVP build configuration`_.
1299
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001300PE MMU configuration
1301--------------------
1302
1303With secure virtualization enabled (``HCR_EL2.VM = 1``) and for S-EL1
1304partitions, two IPA spaces (secure and non-secure) are output from the
1305secure EL1&0 Stage-1 translation.
1306The EL1&0 Stage-2 translation hardware is fed by:
1307
1308- A secure IPA when the SP EL1&0 Stage-1 MMU is disabled.
1309- One of secure or non-secure IPA when the secure EL1&0 Stage-1 MMU is enabled.
1310
1311``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the
1312NS/S IPA translations. The following controls are set up:
1313``VSTCR_EL2.SW = 0`` , ``VSTCR_EL2.SA = 0``, ``VTCR_EL2.NSW = 0``,
1314``VTCR_EL2.NSA = 1``:
1315
1316- Stage-2 translations for the NS IPA space access the NS PA space.
1317- Stage-2 translation table walks for the NS IPA space are to the secure PA space.
1318
1319Secure and non-secure IPA regions (rooted to by ``VTTBR_EL2`` and ``VSTTBR_EL2``)
1320use the same set of Stage-2 page tables within a SP.
1321
1322The ``VTCR_EL2/VSTCR_EL2/VTTBR_EL2/VSTTBR_EL2`` virtual address space
1323configuration is made part of a vCPU context.
1324
1325For S-EL0 partitions with VHE enabled, a single secure EL2&0 Stage-1 translation
1326regime is used for both Hafnium and the partition.
1327
1328Schedule modes and SP Call chains
1329---------------------------------
1330
1331An SP execution context is said to be in SPMC scheduled mode if CPU cycles are
1332allocated to it by SPMC. Correspondingly, an SP execution context is said to be
1333in Normal world scheduled mode if CPU cycles are allocated by the normal world.
1334
1335A call chain represents all SPs in a sequence of invocations of a direct message
1336request. When execution on a PE is in the secure state, only a single call chain
1337that runs in the Normal World scheduled mode can exist. FF-A v1.1 spec allows
1338any number of call chains to run in the SPMC scheduled mode but the Hafnium
1339SPMC restricts the number of call chains in SPMC scheduled mode to only one for
1340keeping the implementation simple.
1341
1342Partition runtime models
1343------------------------
1344
1345The runtime model of an endpoint describes the transitions permitted for an
1346execution context between various states. These are the four partition runtime
1347models supported (refer to `[1]`_ section 7):
1348
1349 - RTM_FFA_RUN: runtime model presented to an execution context that is
1350 allocated CPU cycles through FFA_RUN interface.
1351 - RTM_FFA_DIR_REQ: runtime model presented to an execution context that is
Kathleen Capella6e3abcf2024-02-05 16:17:35 -05001352 allocated CPU cycles through FFA_MSG_SEND_DIRECT_REQ or FFA_MSG_SEND_DIRECT_REQ2
1353 interface.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001354 - RTM_SEC_INTERRUPT: runtime model presented to an execution context that is
1355 allocated CPU cycles by SPMC to handle a secure interrupt.
1356 - RTM_SP_INIT: runtime model presented to an execution context that is
1357 allocated CPU cycles by SPMC to initialize its state.
1358
1359If an endpoint execution context attempts to make an invalid transition or a
1360valid transition that could lead to a loop in the call chain, SPMC denies the
1361transition with the help of above runtime models.
1362
1363Interrupt management
1364--------------------
1365
1366GIC ownership
1367~~~~~~~~~~~~~
1368
1369The SPMC owns the GIC configuration. Secure and non-secure interrupts are
1370trapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt
1371IDs based on SP manifests. The SPMC acknowledges physical interrupts and injects
1372virtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP.
1373
1374Abbreviations:
1375
1376 - NS-Int: A non-secure physical interrupt. It requires a switch to the normal
1377 world to be handled if it triggers while execution is in secure world.
1378 - Other S-Int: A secure physical interrupt targeted to an SP different from
1379 the one that is currently running.
1380 - Self S-Int: A secure physical interrupt targeted to the SP that is currently
1381 running.
1382
1383Non-secure interrupt handling
1384~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1385
1386This section documents the actions supported in SPMC in response to a non-secure
1387interrupt as per the guidance provided by FF-A v1.1 EAC0 specification.
1388An SP specifies one of the following actions in its partition manifest:
1389
1390 - Non-secure interrupt is signaled.
1391 - Non-secure interrupt is signaled after a managed exit.
1392 - Non-secure interrupt is queued.
1393
1394An SP execution context in a call chain could specify a less permissive action
1395than subsequent SP execution contexts in the same call chain. The less
1396permissive action takes precedence over the more permissive actions specified
1397by the subsequent execution contexts. Please refer to FF-A v1.1 EAC0 section
13988.3.1 for further explanation.
1399
1400Secure interrupt handling
1401~~~~~~~~~~~~~~~~~~~~~~~~~
1402
1403This section documents the support implemented for secure interrupt handling in
1404SPMC as per the guidance provided by FF-A v1.1 EAC0 specification.
1405The following assumptions are made about the system configuration:
1406
1407 - In the current implementation, S-EL1 SPs are expected to use the para
1408 virtualized ABIs for interrupt management rather than accessing the virtual
1409 GIC interface.
1410 - Unless explicitly stated otherwise, this support is applicable only for
1411 S-EL1 SPs managed by SPMC.
1412 - Secure interrupts are configured as G1S or G0 interrupts.
1413 - All physical interrupts are routed to SPMC when running a secure partition
1414 execution context.
1415 - All endpoints with multiple execution contexts have their contexts pinned
1416 to corresponding CPUs. Hence, a secure virtual interrupt cannot be signaled
1417 to a target vCPU that is currently running or blocked on a different
1418 physical CPU.
1419
1420A physical secure interrupt could trigger while CPU is executing in normal world
1421or secure world.
1422The action of SPMC for a secure interrupt depends on: the state of the target
1423execution context of the SP that is responsible for handling the interrupt;
1424whether the interrupt triggered while execution was in normal world or secure
1425world.
1426
1427Secure interrupt signaling mechanisms
1428~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1429
1430Signaling refers to the mechanisms used by SPMC to indicate to the SP execution
1431context that it has a pending virtual interrupt and to further run the SP
1432execution context, such that it can handle the virtual interrupt. SPMC uses
1433either the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling
1434to S-EL1 SPs. When normal world execution is preempted by a secure interrupt,
1435the SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC
1436running in S-EL2.
1437
1438+-----------+---------+---------------+---------------------------------------+
1439| SP State | Conduit | Interface and | Description |
1440| | | parameters | |
1441+-----------+---------+---------------+---------------------------------------+
1442| WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending |
1443| | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and |
1444| | | | resumes execution context of SP |
1445| | | | through ERET. |
1446+-----------+---------+---------------+---------------------------------------+
1447| BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt |
1448| | vIRQ | | is pending. It pends vIRQ signal and |
1449| | | | resumes execution context of SP |
1450| | | | through ERET. |
1451+-----------+---------+---------------+---------------------------------------+
1452| PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does |
1453| | | | not resume execution context of SP. |
1454+-----------+---------+---------------+---------------------------------------+
1455| RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes|
1456| | vIRQ | | execution context of SP through ERET. |
1457+-----------+---------+---------------+---------------------------------------+
1458
1459Secure interrupt completion mechanisms
1460~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1461
1462A SP signals secure interrupt handling completion to the SPMC through the
1463following mechanisms:
1464
1465 - ``FFA_MSG_WAIT`` ABI if it was in WAITING state.
1466 - ``FFA_RUN`` ABI if its was in BLOCKED state.
1467
1468This is a remnant of SPMC implementation based on the FF-A v1.0 specification.
1469In the current implementation, S-EL1 SPs use the para-virtualized HVC interface
1470implemented by SPMC to perform priority drop and interrupt deactivation (SPMC
1471configures EOImode = 0, i.e. priority drop and deactivation are done together).
1472The SPMC performs checks to deny the state transition upon invocation of
1473either FFA_MSG_WAIT or FFA_RUN interface if the SP didn't perform the
1474deactivation of the secure virtual interrupt.
1475
1476If the current SP execution context was preempted by a secure interrupt to be
1477handled by execution context of target SP, SPMC resumes current SP after signal
1478completion by target SP execution context.
1479
1480Actions for a secure interrupt triggered while execution is in normal world
1481~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1482
1483+-------------------+----------+-----------------------------------------------+
1484| State of target | Action | Description |
1485| execution context | | |
1486+-------------------+----------+-----------------------------------------------+
1487| WAITING | Signaled | This starts a new call chain in SPMC scheduled|
1488| | | mode. |
1489+-------------------+----------+-----------------------------------------------+
1490| PREEMPTED | Queued | The target execution must have been preempted |
1491| | | by a non-secure interrupt. SPMC queues the |
1492| | | secure virtual interrupt now. It is signaled |
1493| | | when the target execution context next enters |
1494| | | the RUNNING state. |
1495+-------------------+----------+-----------------------------------------------+
1496| BLOCKED, RUNNING | NA | The target execution context is blocked or |
1497| | | running on a different CPU. This is not |
1498| | | supported by current SPMC implementation and |
1499| | | execution hits panic. |
1500+-------------------+----------+-----------------------------------------------+
1501
1502If normal world execution was preempted by a secure interrupt, SPMC uses
1503FFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling
1504and further returns execution to normal world.
1505
1506The following figure describes interrupt handling flow when a secure interrupt
1507triggers while execution is in normal world:
1508
1509.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png
1510
1511A brief description of the events:
1512
1513 - 1) Secure interrupt triggers while normal world is running.
1514 - 2) FIQ gets trapped to EL3.
1515 - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI.
1516 - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends
1517 vIRQ).
1518 - 5) Assuming SP1 vCPU is in WAITING state, SPMC signals virtual interrupt
1519 using FFA_INTERRUPT with interrupt id as an argument and resumes the SP1
1520 vCPU using ERET in SPMC scheduled mode.
1521 - 6) Execution traps to vIRQ handler in SP1 provided that the virtual
1522 interrupt is not masked i.e., PSTATE.I = 0
1523 - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized
1524 HVC call. SPMC clears the pending virtual interrupt state management
1525 and returns the pending virtual interrupt id.
1526 - 8) SP1 services the virtual interrupt and invokes the paravirtualized
1527 de-activation HVC call. SPMC de-activates the physical interrupt,
1528 clears the fields tracking the secure interrupt and resumes SP1 vCPU.
1529 - 9) SP1 performs secure interrupt completion through FFA_MSG_WAIT ABI.
1530 - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME.
1531 - 11) EL3 resumes normal world execution.
1532
1533Actions for a secure interrupt triggered while execution is in secure world
1534~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1535
1536+-------------------+----------+------------------------------------------------+
1537| State of target | Action | Description |
1538| execution context | | |
1539+-------------------+----------+------------------------------------------------+
1540| WAITING | Signaled | This starts a new call chain in SPMC scheduled |
1541| | | mode. |
1542+-------------------+----------+------------------------------------------------+
1543| PREEMPTED by Self | Signaled | The target execution context reenters the |
1544| S-Int | | RUNNING state to handle the secure virtual |
1545| | | interrupt. |
1546+-------------------+----------+------------------------------------------------+
1547| PREEMPTED by | Queued | SPMC queues the secure virtual interrupt now. |
1548| NS-Int | | It is signaled when the target execution |
1549| | | context next enters the RUNNING state. |
1550+-------------------+----------+------------------------------------------------+
1551| BLOCKED | Signaled | Both preempted and target execution contexts |
1552| | | must have been part of the Normal world |
1553| | | scheduled call chain. Refer scenario 1 of |
1554| | | Table 8.4 in the FF-A v1.1 EAC0 spec. |
1555+-------------------+----------+------------------------------------------------+
1556| RUNNING | NA | The target execution context is running on a |
1557| | | different CPU. This scenario is not supported |
1558| | | by current SPMC implementation and execution |
1559| | | hits panic. |
1560+-------------------+----------+------------------------------------------------+
1561
1562The following figure describes interrupt handling flow when a secure interrupt
1563triggers while execution is in secure world. We assume OS kernel sends a direct
1564request message to SP1. Further, SP1 sends a direct request message to SP2. SP1
1565enters BLOCKED state and SPMC resumes SP2.
1566
1567.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png
1568
1569A brief description of the events:
1570
1571 - 1) Secure interrupt triggers while SP2 is running.
1572 - 2) SP2 gets preempted and execution traps to SPMC as IRQ.
1573 - 3) SPMC finds the target vCPU of secure partition responsible for handling
1574 this secure interrupt. In this scenario, it is SP1.
1575 - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface.
1576 SPMC further resumes SP1 through ERET conduit. Note that SP1 remains in
1577 Normal world schedule mode.
1578 - 6) Execution traps to vIRQ handler in SP1 provided that the virtual
1579 interrupt is not masked i.e., PSTATE.I = 0
1580 - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized
1581 HVC call. SPMC clears the pending virtual interrupt state management
1582 and returns the pending virtual interrupt id.
1583 - 8) SP1 services the virtual interrupt and invokes the paravirtualized
1584 de-activation HVC call. SPMC de-activates the physical interrupt and
1585 clears the fields tracking the secure interrupt and resumes SP1 vCPU.
1586 - 9) Since SP1 direct request completed with FFA_INTERRUPT, it resumes the
1587 direct request to SP2 by invoking FFA_RUN.
1588 - 9) SPMC resumes the pre-empted vCPU of SP2.
1589
1590EL3 interrupt handling
1591~~~~~~~~~~~~~~~~~~~~~~
1592
1593In GICv3 based systems, EL3 interrupts are configured as Group0 secure
1594interrupts. Execution traps to SPMC when a Group0 interrupt triggers while an
1595SP is running. Further, SPMC running at S-EL2 uses FFA_EL3_INTR_HANDLE ABI to
1596request EL3 platform firmware to handle a pending Group0 interrupt.
1597Similarly, SPMD registers a handler with interrupt management framework to
1598delegate handling of Group0 interrupt to the platform if the interrupt triggers
1599in normal world.
1600
1601 - Platform hook
1602
1603 - plat_spmd_handle_group0_interrupt
1604
1605 SPMD provides platform hook to handle Group0 secure interrupts. In the
1606 current design, SPMD expects the platform not to delegate handling to the
1607 NWd (such as through SDEI) while processing Group0 interrupts.
1608
Daniel Boulbyc9866ab2024-11-12 16:37:02 +00001609Inter-Processor Interrupts
1610~~~~~~~~~~~~~~~~~~~~~~~~~~
1611Inter-Processor Interrupts (IPIs) are a mechanism for an SP to send an interrupt
1612to to itself on another CPU in a multiprocessor system.
1613
Daniel Boulbyc9866ab2024-11-12 16:37:02 +00001614If an SP wants to send an IPI from vCPU0 on CPU0 to vCPU1 on CPU1 it uses the HVC
Daniel Boulby49b95f02024-11-12 16:58:35 +00001615paravirtualized interface `HF_INTERRUPT_SEND_IPI`_, specifying the ID of vCPU1 as the target.
Daniel Boulbyc9866ab2024-11-12 16:37:02 +00001616The SPMC on CPU0 records the vCPU1 as the target vCPU the IPI is intended for, and requests
1617the GIC to send a secure interrupt to the CPU1 (interrupt ID 9 has been assigned for IPIs).
1618This secure interrupt is caught by the SPMC on CPU1 and enters the secure interrupt handler.
1619Here the handling of the IPI depends on the current state of the target vCPU1 as follows:
1620
1621- RUNNING: The IPI is injected to vCPU1 and normal secure interrupt handling handles
1622 the IPI.
1623- WAITING: The IPI is injected to vCPU1 and an SRI is triggered to notify the Normal
1624 World scheduler the SP vCPU1 has a pending IPI and requires cycles to handle it.
1625 This SRI is received in the Normal World on CPU1, here the notifications interface
Daniel Boulby49b95f02024-11-12 16:58:35 +00001626 has been extended so that `FFA_NOTIFICATION_INFO_GET`_ will also return the SP ID and
Daniel Boulbyc9866ab2024-11-12 16:37:02 +00001627 vCPU ID of any vCPUs with pending IPIs. Using this information the Normal World can
1628 use FFA_RUN to allocate vCPU1 CPU cycles.
1629- PREEMPTED/BLOCKED: Inject and queue the virtual interrupt for vCPU1. We know,
1630 for these states, the vCPU will eventually resumed by the Normal World Scheduler
1631 and the IPI virtual interrupt will then be serviced by the target vCPU.
1632
Daniel Boulby49b95f02024-11-12 16:58:35 +00001633Supporting multiple services targeting vCPUs on the same CPU adds some complexity to the
1634handling of IPIs. The intention behind the implementation choices is to fulfil the
1635following requirements:
1636
16371. All target vCPUs should receive an IPI.
16382. The running vCPU should be prioritized if it has a pending IPI, so that it isn’t
1639 preempted by another vCPU, just to be later run again to handle its IPI.
1640
1641To achieve this, a queue of vCPUs with pending IPIs is maintained for each CPU.
1642When handling the IPI SGI, the list of vCPUs with pending IPIs for the current CPU
1643is emptied and each vCPU is handled as described above, fulfilling requirement 1.
1644To ensure the running vCPU is prioritized, as specified in requirement 2, if there
1645is a vCPU with a pending IPI in the WAITING state, and the current (running) vCPU
1646also has a pending IPI, Hafnium will send the SRI at the next context switch to the
1647NWd. This means the running vCPU can handle it's IPI before the NWd is interrupted
1648by the SRI to schedule the waiting vCPUs. If the current (running) vCPU does not
1649have a pending IPI the SRI is immediately sent.
1650
1651As an example this diagram shows the flow for an SP sending an IPI to a vCPU in the
1652waiting state.
1653
1654.. image:: ../resources/diagrams/ipi_nwd_waiting_vcpu.png
1655
1656The transactions in the diagram above are as follows:
1657
16581. SP1 running on vCPU0 sends the IPI targeting itself on vCPU1 using the
1659 paravirtualised interface `HF_INTERRUPT_SEND_IPI`_.
16602. Hafnium records that there is a pending IPI for SP1 vCPU1 and triggers
1661 an IPI SGI, via the interrupt controller, for CPU1.
16623. FFA_SUCCESS is returned to SP1 vCPU0 to show the IPI has been sent.
16634. The interrupt controller triggers the IPI SGI targeted at CPU1.
1664 As described above, when handing the interrupt, the list of vCPUs on this CPU with
1665 pending IPIs is traversed. In the case of this example SP1 vCPU1 will be in the list
1666 and is in the WAITING state. If the current (RUNNING) vCPU also has a pending IPI then
1667 the flow follows the Case A on the diagram. Set the IPI virtual interrupt
1668 as pending on the target vCPU and set the delayed SRI flag for the current CPU.
1669 Otherwise the flow follows the Case B: simply set the IPI virtual interrupt as pending
1670 on the target vCPU.
16715. For the Case B the SPM sends the Schedule Receiver Interrupt (SRI) SGI through the
1672 interrupt controller.
16736. In both cases the interrupt controller will eventually send an SRI SGI targeted
1674 at CPU1. This will be received by the FF-A driver in the NWd.
16757. This FF-A driver can use `FFA_NOTIFICATION_INFO_GET`_ to find more information about the
1676 cause of the SRI.
16778. For this test, the IPI targeted at SP1 vCPU1 so this is returned in the list of partitions
1678 returned in FFA_SUCCESS.
16799. From the information given by `FFA_NOTIFICATION_INFO_GET`_, the FF-A driver knows to
1680 allocate SP1 vCPU1 cycles to handle the IPI. It does this through FFA_RUN.
168110. Hafnium resumes the target vCPU and injects the IPI virtual interrupts.
168211. The execution is preempted to the IRQ handlers by the pending virtual interrupt.
168312. The SP calls HF_INTERRUPT_GET to obtain the respective interrupt ID.
168413. Hafnium return the IPI interrupt ID via eret. Handling can then continue as required.
1685
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001686Power management
1687----------------
1688
1689In platforms with or without secure virtualization:
1690
1691- The NWd owns the platform PM policy.
1692- The Hypervisor or OS kernel is the component initiating PSCI service calls.
1693- The EL3 PSCI library is in charge of the PM coordination and control
1694 (eventually writing to platform registers).
1695- While coordinating PM events, the PSCI library calls backs into the Secure
1696 Payload Dispatcher for events the latter has statically registered to.
1697
1698When using the SPMD as a Secure Payload Dispatcher:
1699
1700- A power management event is relayed through the SPD hook to the SPMC.
1701- In the current implementation only cpu on (svc_on_finish) and cpu off
1702 (svc_off) hooks are registered.
1703- The behavior for the cpu on event is described in `Secondary cores boot-up`_.
1704 The SPMC is entered through its secondary physical core entry point.
1705- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The PM event is
1706 signaled to the SPMC through a power management framework message.
1707 It consists in a SPMD-to-SPMC direct request/response (`SPMC-SPMD direct
1708 requests/responses`_) conveying the event details and SPMC response.
Madhukar Pappireddye7b47272025-04-21 13:21:57 -05001709 The SPMD performs a synchronous entry into the SPMC. Once the SPMC is entered:
1710
1711 * It updates the internal state to reflect the physical core is being turned
1712 off.
1713 * It relays the PSCI CPU_OFF power management operation as a framework direct
1714 request message to the pinned execution context of the first MP SP
1715 provided:
1716
1717 * The SP has subscribed to the CPU_OFF operation explicitly through its
1718 partition manifest. Refer to `[6]`_ for details of corresponding FF-A
1719 binding.
1720 * The pinned execution context is in the WAITING state.
1721
1722 * Else, it sends a framework direct response to SPMD with success status code.
1723 * SPMC receives the direct response from the SP for the direct request
1724 framework message it had sent earlier.
1725 * If the status code in the message from SP is not SUCCESS, then SPMC
1726 sends a framework direct response to SPMD with DENIED status code. SPMD
1727 will eventually panic and stop the execution.
1728 * Else, SPMC continues to relay PSCI CPU_OFF power management operation to
1729 other subscribed MP SPs.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001730
1731Arm architecture extensions for security hardening
J-Alves5eafd222023-10-26 14:19:21 +01001732--------------------------------------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001733
1734Hafnium supports the following architecture extensions for security hardening:
1735
1736- Pointer authentication (FEAT_PAuth): the extension permits detection of forged
1737 pointers used by ROP type of attacks through the signing of the pointer
1738 value. Hafnium is built with the compiler branch protection option to permit
1739 generation of a pointer authentication code for return addresses (pointer
1740 authentication for instructions). The APIA key is used while Hafnium runs.
1741 A random key is generated at boot time and restored upon entry into Hafnium
1742 at run-time. APIA and other keys (APIB, APDA, APDB, APGA) are saved/restored
1743 in vCPU contexts permitting to enable pointer authentication in VMs/SPs.
1744- Branch Target Identification (FEAT_BTI): the extension permits detection of
1745 unexpected indirect branches used by JOP type of attacks. Hafnium is built
1746 with the compiler branch protection option, inserting land pads at function
1747 prologues that are reached by indirect branch instructions (BR/BLR).
1748 Hafnium code pages are marked as guarded in the EL2 Stage-1 MMU descriptors
1749 such that an indirect branch must always target a landpad. A fault is
1750 triggered otherwise. VMs/SPs can (independently) mark their code pages as
1751 guarded in the EL1&0 Stage-1 translation regime.
1752- Memory Tagging Extension (FEAT_MTE): the option permits detection of out of
1753 bound memory array accesses or re-use of an already freed memory region.
1754 Hafnium enables the compiler option permitting to leverage MTE stack tagging
1755 applied to core stacks. Core stacks are marked as normal tagged memory in the
1756 EL2 Stage-1 translation regime. A synchronous data abort is generated upon tag
1757 check failure on load/stores. A random seed is generated at boot time and
1758 restored upon entry into Hafnium. MTE system registers are saved/restored in
1759 vCPU contexts permitting MTE usage from VMs/SPs.
J-Alvesd547d6d2024-05-14 14:59:54 +01001760- Realm Management Extension (FEAT_RME): can be deployed in platforms that leverage
1761 RME for physical address isolation. The SPMC is capable of recovering from a
1762 Granule Protection Fault, if inadvertently accessing a region with the wrong security
1763 state setting. Also, the ability to change dynamically the physical address space of
1764 a region, can be used to enhance the handling of ``FFA_MEM_LEND`` and ``FFA_MEM_DONATE``.
1765 More details in the section about `Memory Sharing`_.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001766
Olivier Deprez2aea7482024-05-17 12:15:52 +02001767SIMD support
1768------------
1769
1770In this section, the generic term |SIMD| is used to refer to vector and matrix
1771processing units offered by the Arm architecture. This concerns the optional
1772architecture extensions: Advanced SIMD (formerly FPU / NEON) / |SVE| / |SME|.
1773
1774The SPMC preserves the |SIMD| state according to the |SMCCC| (ARM DEN 0028F
17751.5F section 10 Appendix C: SME, SVE, SIMD and FP live state preservation by
1776the |SMCCC| implementation).
1777
1778The SPMC implements the |SIMD| support in the following way:
1779
1780- SPs are allowed to use Advanced SIMD instructions and manipulate
1781 the Advanced SIMD state.
1782- The SPMC saves and restores vCPU Advanced SIMD state when switching vCPUs.
1783- SPs are restricted from using |SVE| and |SME| instructions and manipulating
1784 associated system registers and state. Doing so, traps to the same or higher
1785 EL.
1786- Entry from the normal world into the SPMC and exit from the SPMC to the normal
1787 world preserve the |SIMD| state.
1788- Corollary to the above, the normal world is free to use any of the referred
1789 |SIMD| extensions and emit FF-A SMCs. The SPMC as a callee preserves the live
1790 |SIMD| state according to the rules mentioned in the |SMCCC|.
1791- This is also true for the case of a secure interrupt pre-empting the normal
1792 world while it is currently processing |SIMD| instructions.
1793- |SVE| and |SME| traps are enabled while S-EL2/1/0 run. Traps are temporarily
1794 disabled on the narrow window of the context save/restore operation within
1795 S-EL2. Traps are enabled again after those operations.
1796
1797Supported configurations
1798~~~~~~~~~~~~~~~~~~~~~~~~
1799
1800The SPMC assumes Advanced SIMD is always implemented (despite being an Arm
1801optional architecture extension). The SPMC dynamically detects whether |SVE|
1802and |SME| are implemented in the platform, then saves and restores the |SIMD|
1803state according to the different combinations:
1804
1805+--------------+--------------------+--------------------+---------------+
1806| FEAT_AdvSIMD | FEAT_SVE/FEAT_SVE2 | FEAT_SME/FEAT_SME2 | FEAT_SME_FA64 |
1807+--------------+--------------------+--------------------+---------------+
1808| Y | N | N | N |
1809+--------------+--------------------+--------------------+---------------+
1810| Y | Y | N | N |
1811+--------------+--------------------+--------------------+---------------+
1812| Y | Y | Y | N |
1813+--------------+--------------------+--------------------+---------------+
1814| Y | Y | Y | Y |
1815+--------------+--------------------+--------------------+---------------+
1816| Y | N | Y | N |
1817+--------------+--------------------+--------------------+---------------+
1818| Y | N | Y | Y |
1819+--------------+--------------------+--------------------+---------------+
1820
1821Y: architectural feature implemented
1822N: architectural feature not implemented
1823
1824SIMD save/restore operations
1825~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1826
1827The SPMC considers the following SIMD registers state:
1828
1829- Advanced SIMD consists of 32 ``Vn`` 128b vectors. Vector's lower 128b is
1830 shared with the larger |SVE| / |SME| variable length vectors.
1831- |SVE| consists of 32 ``Zn`` variable length vectors, ``Px`` predicates,
1832 ``FFR`` fault status register.
1833- |SME| when Streaming SVE is enabled consists of 32 ``Zn`` variable length
1834 vectors, ``Px`` predicates, ``FFR`` fault status register (when FEAT_SME_FA64
1835 extension is implemented and enabled), ZA array (when enabled).
1836- Status and control registers (FPCR/FPSR) common to all above.
1837
1838For the purpose of supporting the maximum vector length (or Streaming SVE
1839vector length) supported by the architecture, the SPMC sets ``SCR_EL2.LEN``
1840and ``SMCR_EL2.LEN`` to the maximum permitted value (2048 bits). This makes
1841save/restore operations independent from the vector length constrained by EL3
1842(by ``ZCR_EL3``), or the ``ZCR_EL2.LEN`` value set by the normal world itself.
1843
1844For performance reasons, the normal world might let the secure world know it
1845doesn't depend on the |SVE| or |SME| live state while doing an SMC. It does
1846so by setting the |SMCCC| SVE hint bit. In which case, the secure world limits
1847the normal world context save/restore operations to the Advanced SIMD state
1848even if either one of |SVE| or |SME|, or both, are implemented.
1849
1850The following additional design choices were made related to SME save/restore
1851operations:
1852
1853- When FEAT_SME_FA64 is implemented, ``SMCR_EL2.FA64`` is set and FFR register
1854 saved/restored when Streaming SVE mode is enabled.
1855- For power saving reasons, if Streaming SVE mode is enabled while entering the
1856 SPMC, this state is recorded, Streaming SVE state saved and the mode disabled.
1857 Streaming SVE is enabled again while restoring the SME state on exiting the
1858 SPMC.
1859- The ZA array state is left untouched while the SPMC runs. As neither SPMC
1860 and SPs alter the ZA array state, this is a conservative approach in terms
1861 of memory footprint consumption.
1862
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001863SMMUv3 support in Hafnium
J-Alves5eafd222023-10-26 14:19:21 +01001864-------------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001865
1866An SMMU is analogous to an MMU in a CPU. It performs address translations for
1867Direct Memory Access (DMA) requests from system I/O devices.
1868The responsibilities of an SMMU include:
1869
1870- Translation: Incoming DMA requests are translated from bus address space to
1871 system physical address space using translation tables compliant to
1872 Armv8/Armv7 VMSA descriptor format.
1873- Protection: An I/O device can be prohibited from read, write access to a
1874 memory region or allowed.
1875- Isolation: Traffic from each individial device can be independently managed.
1876 The devices are differentiated from each other using unique translation
1877 tables.
1878
1879The following diagram illustrates a typical SMMU IP integrated in a SoC with
1880several I/O devices along with Interconnect and Memory system.
1881
1882.. image:: ../resources/diagrams/MMU-600.png
1883
1884SMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides
1885support for SMMUv3 driver in both normal and secure world. A brief introduction
1886of SMMUv3 functionality and the corresponding software support in Hafnium is
1887provided here.
1888
1889SMMUv3 features
J-Alves5eafd222023-10-26 14:19:21 +01001890~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001891
1892- SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2)
1893 translation support. It can either bypass or abort incoming translations as
1894 well.
1895- Traffic (memory transactions) from each upstream I/O peripheral device,
1896 referred to as Stream, can be independently managed using a combination of
1897 several memory based configuration structures. This allows the SMMUv3 to
1898 support a large number of streams with each stream assigned to a unique
1899 translation context.
1900- Support for Armv8.1 VMSA where the SMMU shares the translation tables with
1901 a Processing Element. AArch32(LPAE) and AArch64 translation table format
1902 are supported by SMMUv3.
1903- SMMUv3 offers non-secure stream support with secure stream support being
1904 optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU
1905 instance for secure and non-secure stream support.
1906- It also supports sub-streams to differentiate traffic from a virtualized
1907 peripheral associated with a VM/SP.
1908- Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A
1909 extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2
1910 for providing Secure Stage2 translation support to upstream peripheral
1911 devices.
1912
1913SMMUv3 Programming Interfaces
J-Alves5eafd222023-10-26 14:19:21 +01001914~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001915
1916SMMUv3 has three software interfaces that are used by the Hafnium driver to
1917configure the behaviour of SMMUv3 and manage the streams.
1918
1919- Memory based data strutures that provide unique translation context for
1920 each stream.
1921- Memory based circular buffers for command queue and event queue.
1922- A large number of SMMU configuration registers that are memory mapped during
1923 boot time by Hafnium driver. Except a few registers, all configuration
1924 registers have independent secure and non-secure versions to configure the
1925 behaviour of SMMUv3 for translation of secure and non-secure streams
1926 respectively.
1927
1928Peripheral device manifest
J-Alves5eafd222023-10-26 14:19:21 +01001929~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001930
1931Currently, SMMUv3 driver in Hafnium only supports dependent peripheral devices.
Madhukar Pappireddy555f8882023-10-16 13:45:29 -05001932These DMA devices are dependent on PE endpoint to initiate and receive memory
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001933management transactions on their behalf. The acccess to the MMIO regions of
Madhukar Pappireddy555f8882023-10-16 13:45:29 -05001934any such device is assigned to the endpoint during boot.
Madhukar Pappireddya2c79222024-08-29 15:05:18 -05001935The `device node`_ of the corresponding partition manifest must specify these
1936additional properties for each peripheral device in the system:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001937
1938- smmu-id: This field helps to identify the SMMU instance that this device is
1939 upstream of.
1940- stream-ids: List of stream IDs assigned to this device.
1941
1942.. code:: shell
1943
1944 smmuv3-testengine {
1945 base-address = <0x00000000 0x2bfe0000>;
1946 pages-count = <32>;
1947 attributes = <0x3>;
1948 smmu-id = <0>;
1949 stream-ids = <0x0 0x1>;
1950 interrupts = <0x2 0x3>, <0x4 0x5>;
1951 exclusive-access;
1952 };
1953
Madhukar Pappireddy555f8882023-10-16 13:45:29 -05001954DMA isolation
1955-------------
1956
1957Hafnium, with help of SMMUv3 driver, enables the support for static DMA
1958isolation. The DMA device is explicitly granted access to a specific
1959memory region only if the partition requests it by declaring the following
Madhukar Pappireddya2c79222024-08-29 15:05:18 -05001960properties of the DMA device in the `memory region node`_ of the partition
1961manifest:
Madhukar Pappireddy555f8882023-10-16 13:45:29 -05001962
1963- smmu-id
1964- stream-ids
1965- stream-ids-access-permissions
1966
1967SMMUv3 driver uses a unqiue set of stage 2 translations for the DMA device
1968rather than those used on behalf of the PE endpoint. This ensures that the DMA
1969device has a limited visibility of the physical address space.
1970
1971.. code:: shell
1972
1973 smmuv3-memcpy-src {
1974 description = "smmuv3-memcpy-source";
1975 pages-count = <4>;
1976 base-address = <0x00000000 0x7400000>;
1977 attributes = <0x3>; /* read-write */
1978 smmu-id = <0>;
1979 stream-ids = <0x0 0x1>;
1980 stream-ids-access-permissions = <0x3 0x3>;
1981 };
1982
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001983SMMUv3 driver limitations
J-Alves5eafd222023-10-26 14:19:21 +01001984~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001985
1986The primary design goal for the Hafnium SMMU driver is to support secure
1987streams.
1988
1989- Currently, the driver only supports Stage2 translations. No support for
1990 Stage1 or nested translations.
1991- Supports only AArch64 translation format.
1992- No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS,
1993 Fault handling, Performance Monitor Extensions, Event Handling, MPAM.
1994- No support for independent peripheral devices.
1995
1996S-EL0 Partition support
J-Alves5eafd222023-10-26 14:19:21 +01001997-----------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001998The SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using
1999FEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world
2000with ARMv8.4 and FEAT_SEL2).
2001
2002S-EL0 partitions are useful for simple partitions that don't require full
2003Trusted OS functionality. It is also useful to reduce jitter and cycle
2004stealing from normal world since they are more lightweight than VMs.
2005
2006S-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by
2007the SPMC. They are differentiated primarily by the 'exception-level' property
2008and the 'execution-ctx-count' property in the SP manifest. They are host apps
2009under the single EL2&0 Stage-1 translation regime controlled by the SPMC and
2010call into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions
2011can use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions
2012for memory regions.
2013
2014S-EL0 partitions are required by the FF-A specification to be UP endpoints,
2015capable of migrating, and the SPMC enforces this requirement. The SPMC allows
2016a S-EL0 partition to accept a direct message from secure world and normal world,
2017and generate direct responses to them.
2018All S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not supported.
2019
Olivier Deprezb8bd7d72023-10-27 16:14:13 +02002020Interrupt handling, Memory sharing, indirect messaging, and notifications features
2021in context of S-EL0 partitions are supported.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02002022
Madhukar Pappireddy9243e772024-10-24 16:52:23 -05002023Support for arch timer and system counter
2024-----------------------------------------
2025Secure Partitions can configure the EL1 physical timer (CNTP_*_EL0) to generate
2026a virtual interrupt in the future. SPs have access to CNTPCT_EL0 (system count
2027value) and CNTFRQ_EL0 (frequency of the system count). Once the deadline set by
2028the timer expires, the SPMC injects a virtual interrupt (ID=3) and resumes
2029the SP's execution context at the earliest opportunity as allowed by the secure
2030interrupt signaling rules outlined in the FF-A specification. Hence, it is
2031likely that time could have passed between the moment the deadline expired and
2032the interrupt is subsequently signaled.
2033
2034Any access from an SP to EL1 physical timer registers is trapped and emulated
2035by SPMC behind the scenes, though this is completely oblivious to the SP.
2036This ensures that any EL1 physical timer deadline set by a normal world endpoint
2037is not overriden by either SPs or SPMC.
2038
2039Note: As per Arm ARM, assuming no support for FEAT_ECV, S-EL1 has direct access
2040to EL1 virtual timer registers but S-EL0 accesses are trapped to higher ELs.
2041Consequently, any attempt by an S-EL0 partition to access EL1 virtual timer
2042registers leads to a crash while such an attempt by S-EL1 partition effectively
2043has no impact on its execution context.
2044
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02002045References
2046==========
2047
J-Alves5eafd222023-10-26 14:19:21 +01002048.. _TF-A project: https://trustedfirmware-a.readthedocs.io/en/latest/
2049
J-Alvesd547d6d2024-05-14 14:59:54 +01002050.. _SPMC FVP build configuration: https://github.com/TF-Hafnium/hafnium-project-reference/blob/main/BUILD.gn#L143
2051
Daniel Boulby0a697182024-11-15 11:46:26 +00002052.. _partition properties: https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties
2053
Madhukar Pappireddya2c79222024-08-29 15:05:18 -05002054.. _device node: https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#device-regions
2055
2056.. _memory region node: https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#memory-regions
2057
Kathleen Capella14dc3bc2025-01-31 18:09:54 -05002058.. _Firmware Handoff specification: https://github.com/FirmwareHandoff/firmware_handoff/
2059
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02002060.. _[1]:
2061
2062[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__
2063
2064.. _[2]:
2065
2066[2] `Secure Partition Manager using MM interface <https://trustedfirmware-a.readthedocs.io/en/latest/components/secure-partition-manager-mm.html>`__
2067
2068.. _[3]:
2069
2070[3] `Trusted Boot Board Requirements
2071Client <https://developer.arm.com/documentation/den0006/d/>`__
2072
2073.. _[4]:
2074
2075[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45
2076
2077.. _[5]:
2078
2079[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts
2080
2081.. _[6]:
2082
2083[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html
2084
2085.. _[7]:
2086
2087[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts
2088
2089.. _[8]:
2090
2091[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/
2092
2093.. _[9]:
2094
2095[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot
2096
J-Alvesd8094162023-10-26 12:44:33 +01002097.. _[10]:
2098
2099[10] https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/build-options.html#
2100
J-Alvesd547d6d2024-05-14 14:59:54 +01002101 .. _[11]:
2102
2103[11] https://developer.arm.com/documentation/den0140/a
2104
2105 .. _[12]:
2106
2107[12] https://developer.arm.com/documentation/den0129/latest/
2108
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02002109--------------
2110
2111*Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.*