blob: 3e1f85028188275757157290beab64f8f83c4fa5 [file] [log] [blame]
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001Terminology
J-Alvesf7490db2023-10-19 17:57:22 +01002===========
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02003
4- The term Hypervisor refers to the NS-EL2 component managing Virtual Machines
5 (or partitions) in the normal world.
6- The term SPMC refers to the S-EL2 component managing secure partitions in
7 the secure world when the FEAT_SEL2 architecture extension is implemented.
8- Alternatively, SPMC can refer to an S-EL1 component, itself being a secure
9 partition and implementing the FF-A ABI on platforms not implementing the
10 FEAT_SEL2 architecture extension.
11- The term VM refers to a normal world Virtual Machine managed by an Hypervisor.
12- The term SP refers to a secure world "Virtual Machine" managed by an SPMC.
13
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020014Sample reference stack
15======================
16
17The following diagram illustrates a possible configuration when the
J-Alves5eafd222023-10-26 14:19:21 +010018FEAT_SEL2 architecture extension is implemented, showing the |SPMD|
19and |SPMC|, one or multiple secure partitions, with an optional
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020020Hypervisor:
21
J-Alvesc1693772023-10-26 12:41:53 +010022.. image:: ../resources/diagrams/Hafnium_overview_SPMD.png
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020023
J-Alves5eafd222023-10-26 14:19:21 +010024Integration with TF-A (Bootloader and SPMD)
25===========================================
26
27The `TF-A project`_ provides the reference implementation for the secure monitor
28for Arm A class devices, executing at EL3. It includes the implementation of the
29|SPMD|, which manages the world-switch, to relay the FF-A calls to the |SPMC|.
30
31TF-A also serves as the system bootlader, and it was used in the reference
32implemenation for the SPMC and SPs.
33SPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.).
34Thus they are supplied as distinct signed entities within the FIP flash
35image. The FIP image itself is not signed hence this provides the ability
36to upgrade SPs in the field.
37
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020038TF-A build options
J-Alves5eafd222023-10-26 14:19:21 +010039------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020040
J-Alvesd8094162023-10-26 12:44:33 +010041This section explains the TF-A build options for an FF-A based SPM, in which SPMD
42is located at EL3.
43
44This is a step needed for integrating Hafnium as the S-EL2 SPMC and
45the TF-A as SPMD, together making the SPM component.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020046
47- **SPD=spmd**: this option selects the SPMD component to relay the FF-A
48 protocol from NWd to SWd back and forth. It is not possible to
49 enable another Secure Payload Dispatcher when this option is chosen.
50- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception
51 level to being at S-EL2. It defaults to enabled (value 1) when
J-Alvesd8094162023-10-26 12:44:33 +010052 SPD=spmd is chosen.The context save/restore routine and exhaustive list
53 of registers is visible at `[4]`_. When set the reference software stack
54 assumes enablement of FEAT_PAuth, FEAT_BTI and FEAT_MTE architecture
55 extensions.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020056- **SP_LAYOUT_FILE**: this option specifies a text description file
57 providing paths to SP binary images and manifests in DTS format
J-Alves5eafd222023-10-26 14:19:21 +010058 (see `Secure Partitions Layout File`_). It is required when ``SPMD_SPM_AT_SEL2``
J-Alvesd8094162023-10-26 12:44:33 +010059 is enabled, i.e. when multiple secure partitions are to be loaded by BL2 on
60 behalf of the SPMC.
61- **BL32** option is re-purposed to specify the SPMC image. It can specify either
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020062 the Hafnium binary path (built for the secure world) or the path to a TEE
63 binary implementing FF-A interfaces.
J-Alvesd8094162023-10-26 12:44:33 +010064- **BL33** option to specify normal world loader such as U-Boot or the UEFI
65 framework payload, which would use FF-A calls during runtime to interact with
66 Hafnium as the SPMC.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020067
J-Alvesd8094162023-10-26 12:44:33 +010068As a result of configuring ``SPD=spmd`` and ``SPMD_SPM_AT_SEL2`` TF-A provides
69context save/restore operations when entering/exiting an EL2 execution context.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020070
J-Alvesd8094162023-10-26 12:44:33 +010071There are other build options that relate support other valid FF-A
72system configurations where the SPMC is implemented at S-EL1 and EL3.
73Note that they conflict with those needed to integrate with Hafnium as the SPMC.
74For more details refer to |TF-A| build options `[10]`_.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020075
76Sample TF-A build command line when FEAT_SEL2 architecture extension is
J-Alvesd8094162023-10-26 12:44:33 +010077implemented and the SPMC is located at S-EL2, for Arm's FVP platform:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +020078
79.. code:: shell
80
81 make \
82 CROSS_COMPILE=aarch64-none-elf- \
83 PLAT=fvp \
84 SPD=spmd \
85 ARM_ARCH_MINOR=5 \
86 BRANCH_PROTECTION=1 \
87 CTX_INCLUDE_PAUTH_REGS=1 \
88 CTX_INCLUDE_MTE_REGS=1 \
89 BL32=<path-to-hafnium-binary> \
90 BL33=<path-to-bl33-binary> \
91 SP_LAYOUT_FILE=sp_layout.json \
92 all fip
93
94Sample TF-A build command line when FEAT_SEL2 architecture extension is
95implemented, the SPMC is located at S-EL2, and enabling secure boot:
96
97.. code:: shell
98
99 make \
100 CROSS_COMPILE=aarch64-none-elf- \
101 PLAT=fvp \
102 SPD=spmd \
103 ARM_ARCH_MINOR=5 \
104 BRANCH_PROTECTION=1 \
105 CTX_INCLUDE_PAUTH_REGS=1 \
106 CTX_INCLUDE_MTE_REGS=1 \
107 BL32=<path-to-hafnium-binary> \
108 BL33=<path-to-bl33-binary> \
109 SP_LAYOUT_FILE=sp_layout.json \
110 MBEDTLS_DIR=<path-to-mbedtls-lib> \
111 TRUSTED_BOARD_BOOT=1 \
112 COT=dualroot \
113 ARM_ROTPK_LOCATION=devel_rsa \
114 ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
115 GENERATE_COT=1 \
116 all fip
117
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200118FVP model invocation
J-Alves5eafd222023-10-26 14:19:21 +0100119--------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200120
121The FVP command line needs the following options to exercise the S-EL2 SPMC:
122
123+---------------------------------------------------+------------------------------------+
124| - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, |
125| - cluster1.has_arm_v8-5=1 | and FEAT_BTI. |
126+---------------------------------------------------+------------------------------------+
127| - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the |
128| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. |
129| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | |
130| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | |
131| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | |
132| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | |
133| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | |
134| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | |
135+---------------------------------------------------+------------------------------------+
136| - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. |
137| - cluster1.has_branch_target_exception=1 | |
138+---------------------------------------------------+------------------------------------+
139| - cluster0.has_pointer_authentication=2 | Implements FEAT_PAuth |
140| - cluster1.has_pointer_authentication=2 | |
141+---------------------------------------------------+------------------------------------+
142| - cluster0.memory_tagging_support_level=2 | Implements FEAT_MTE2 |
143| - cluster1.memory_tagging_support_level=2 | |
144| - bp.dram_metadata.is_enabled=1 | |
145+---------------------------------------------------+------------------------------------+
146
147Sample FVP command line invocation:
148
149.. code:: shell
150
151 <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \
152 -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \
153 -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \
154 -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \
155 -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \
156 -C bp.pl011_uart2.out_file=fvp-uart2.log \
157 -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 \
158 -C cluster0.has_pointer_authentication=2 -C cluster1.has_pointer_authentication=2 \
159 -C cluster0.has_branch_target_exception=1 -C cluster1.has_branch_target_exception=1 \
160 -C cluster0.memory_tagging_support_level=2 -C cluster1.memory_tagging_support_level=2 \
161 -C bp.dram_metadata.is_enabled=1 \
162 -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \
163 -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \
164 -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \
165 -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0
166
J-Alves5eafd222023-10-26 14:19:21 +0100167SPMC Configuration
168==================
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200169
J-Alves5eafd222023-10-26 14:19:21 +0100170This section details the configuration files required to deploy Hafnium as the SPMC,
171along with those required to configure each secure partion.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200172
J-Alves5eafd222023-10-26 14:19:21 +0100173SPMC Manifest
174-------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200175
J-Alves5eafd222023-10-26 14:19:21 +0100176This manifest contains the SPMC *attribute* node consumed by the SPMD at boot
177time. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves
178two different cases:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200179
J-Alves5eafd222023-10-26 14:19:21 +0100180The SPMC manifest is used by the SPMD to setup the environment required by the
181SPMC to run at S-EL2. SPs run at S-EL1 or S-EL0.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200182
J-Alves5eafd222023-10-26 14:19:21 +0100183.. code:: shell
184
185 attribute {
186 spmc_id = <0x8000>;
187 maj_ver = <0x1>;
188 min_ver = <0x1>;
189 exec_state = <0x0>;
190 load_address = <0x0 0x6000000>;
191 entrypoint = <0x0 0x6000000>;
192 binary_size = <0x60000>;
193 };
194
195- *spmc_id* defines the endpoint ID value that SPMC can query through
196 ``FFA_ID_GET``.
197- *maj_ver/min_ver*. SPMD checks provided FF-A version versus its internal
198 version and aborts if not matching.
199- *exec_state* defines the SPMC execution state (AArch64 or AArch32).
200 Notice Hafnium used as a SPMC only supports AArch64.
201- *load_address* and *binary_size* are mostly used to verify secondary
202 entry points fit into the loaded binary image.
203- *entrypoint* defines the cold boot primary core entry point used by
204 SPMD (currently matches ``BL32_BASE``) to enter the SPMC.
205
206Other nodes in the manifest are consumed by Hafnium in the secure world.
207A sample can be found at `[7]`_:
208
209- The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute
210 indicates a FF-A compliant SP. The *load_address* field specifies the load
211 address at which BL2 loaded the SP package.
212- The *cpus* node provides the platform topology and allows MPIDR to VMPIDR mapping.
213 Note the primary core is declared first, then secondary cores are declared
214 in reverse order.
215- The *memory* nodes provide platform information on the ranges of memory
216 available for use by SPs at runtime. These ranges relate to either
217 secure or non-secure memory, depending on the *device_type* field.
218 If the field specifies "memory" the range is secure, else if it specifies
219 "ns-memory" the memory is non-secure. The system integrator must exclude
220 the memory used by other components that are not SPs, such as the monitor,
221 or the SPMC itself, the OS Kernel/Hypervisor, or other NWd VMs.
222 The SPMC limits the SP's address space such that they can only refer to memory
223 inside of those ranges, either by defining memory region nodes in their manifest
224 as well as memory starting at the load address until the limit defined by the memory
225 size. Thus, the SPMC prevents rogue SPs from tampering with memory from other
226 components.
227
228Secure Partitions Configuration
229-------------------------------
230
231SP Manifests
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200232~~~~~~~~~~~~
233
234An SP manifest describes SP attributes as defined in `[1]`_
235(partition manifest at virtual FF-A instance) in DTS format. It is
236represented as a single file associated with the SP. A sample is
237provided by `[5]`_. A binding document is provided by `[6]`_.
238
J-Alves5eafd222023-10-26 14:19:21 +0100239Platform topology
240~~~~~~~~~~~~~~~~~
241
242The *execution-ctx-count* SP manifest field can take the value of one or the
243total number of PEs. The FF-A specification `[1]`_ recommends the
244following SP types:
245
246- Pinned MP SPs: an execution context matches a physical PE. MP SPs must
247 implement the same number of ECs as the number of PEs in the platform.
248- Migratable UP SPs: a single execution context can run and be migrated on any
249 physical PE. Such SP declares a single EC in its SP manifest. An UP SP can
250 receive a direct message request originating from any physical core targeting
251 the single execution context.
252
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200253Secure Partition packages
254~~~~~~~~~~~~~~~~~~~~~~~~~
255
256Secure partitions are bundled as independent package files consisting
257of:
258
259- a header
260- a DTB
261- an image payload
262
263The header starts with a magic value and offset values to SP DTB and
264image payload. Each SP package is loaded independently by BL2 loader
265and verified for authenticity and integrity.
266
267The SP package identified by its UUID (matching FF-A uuid property) is
268inserted as a single entry into the FIP at end of the TF-A build flow
269as shown:
270
271.. code:: shell
272
273 Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw"
274 EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw"
275 Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw"
276 Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw"
277 HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config"
278 TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config"
279 SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config"
280 TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config"
281 NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config"
282 B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob"
283 D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob"
284
285.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml
286
J-Alves5eafd222023-10-26 14:19:21 +0100287Secure Partitions Layout File
288~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200289
290A json-formatted description file is passed to the build flow specifying paths
291to the SP binary image and associated DTS partition manifest file. The latter
292is processed by the dtc compiler to generate a DTB fed into the SP package.
Karl Meakin82593ce2023-08-30 16:38:28 +0100293Each partition can be configured with the following fields:
294
295:code:`image`
296 - Specifies the filename and offset of the image within the SP package.
297 - Can be written as :code:`"image": { "file": "path", "offset": 0x1234 }` to
298 give both :code:`image.file` and :code:`image.offset` values explicitly, or
299 can be written as :code:`"image": "path"` to give :code:`image.file` and value
300 and leave :code:`image.offset` absent.
301
302 :code:`image.file`
303 - Specifies the filename of the image.
304
305 :code:`image.offset`
306 - Specifies the offset of the image within the SP package.
307 - Must be 4KB aligned, because that is the translation granule supported by Hafnium SPMC.
308 - Optional. Defaults to :code:`0x4000`.
309
310:code:`pm`
311 - Specifies the filename and offset of the partition manifest within the SP package.
312 - Can be written as :code:`"pm": { "file": "path", "offset": 0x1234 }` to
313 give both :code:`pm.file` and :code:`pm.offset` values explicitly, or
314 can be written as :code:`"pm": "path"` to give :code:`pm.file` and value
315 and leave :code:`pm.offset` absent.
316
317 :code:`pm.file`
318 - Specifies the filename of the partition manifest.
319
320 :code:`pm.offset`
321 - Specifies the offset of the partition manifest within the SP package.
322 - Must be 4KB aligned, because that is the translation granule supported by Hafnium SPMC.
323 - Optional. Defaults to :code:`0x1000`.
324
325:code:`image.offset` and :code:`pm.offset` can be leveraged to support SPs with
326S1 translation granules that differ from 4KB, and to configure the regions
327allocated within the SP package, as well as to comply with the requirements for
328the implementation of the boot information protocol (see `Passing boot data to
329the SP`_ for more details).
330
331:code:`owner`
332 - Specifies the SP owner, identifying the signing domain in case of dual root CoT.
333 - Possible values are :code:`SiP` (silicon owner) or :code:`Plat` (platform owner).
334 - Optional. Defaults to :code:`SiP`.
335
336:code:`uuid`
337 - Specifies the UUID of the partition.
338 - Optional. Defaults to the value of the :code:`uuid` field from the DTS partition manifest.
339
340:code:`physical-load-address`
341 - Specifies the :code:`load_address` field of the generated DTS fragment.
342 - Optional. Defaults to the value of the :code:`load-address` from the DTS partition manifest.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200343
344.. code:: shell
345
346 {
347 "tee1" : {
348 "image": "tee1.bin",
349 "pm": "tee1.dts",
350 "owner": "SiP",
351 "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f"
352 },
353
354 "tee2" : {
355 "image": "tee2.bin",
356 "pm": "tee2.dts",
357 "owner": "Plat"
358 },
359
360 "tee3" : {
361 "image": {
362 "file": "tee3.bin",
363 "offset":"0x2000"
364 },
365 "pm": {
366 "file": "tee3.dts",
367 "offset":"0x6000"
368 },
369 "owner": "Plat"
370 },
371 }
372
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200373SPMC boot
J-Alves5eafd222023-10-26 14:19:21 +0100374=========
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200375
376The SPMC is loaded by BL2 as the BL32 image.
377
378The SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_.
379
380BL2 passes the SPMC manifest address to BL31 through a register.
381
382At boot time, the SPMD in BL31 runs from the primary core, initializes the core
383contexts and launches the SPMC (BL32) passing the following information through
384registers:
385
386- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob).
387- X1 holds the ``HW_CONFIG`` physical address.
388- X4 holds the currently running core linear id.
389
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200390Secure boot
J-Alves5eafd222023-10-26 14:19:21 +0100391-----------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200392
393The SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC,
394SPMC manifest, secure partitions and verifies them for authenticity and integrity.
395Refer to TBBR specification `[3]`_.
396
397The multiple-signing domain feature (in current state dual signing domain `[8]`_) allows
398the use of two root keys namely S-ROTPK and NS-ROTPK:
399
400- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK.
401- BL33 may be signed by the OEM using NS-ROTPK.
402- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK).
403- A maximum of 4 partitions can be signed with the S-ROTPK key and 4 partitions
404 signed with the NS-ROTPK key.
405
J-Alves5eafd222023-10-26 14:19:21 +0100406Also refer to `Secure Partitions Configuration`_ and `TF-A build options`_ sections.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200407
408Boot phases
409-----------
410
411Primary core boot-up
412~~~~~~~~~~~~~~~~~~~~
413
414Upon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical
415core. The SPMC performs its platform initializations and registers the SPMC
416secondary physical core entry point physical address by the use of the
417`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD
418at secure physical FF-A instance).
419
420The SPMC then creates secure partitions based on SP packages and manifests. Each
421secure partition is launched in sequence (`SP Boot order`_) on their "primary"
422execution context. If the primary boot physical core linear id is N, an MP SP is
423started using EC[N] on PE[N] (see `Platform topology`_). If the partition is a
424UP SP, it is started using its unique EC0 on PE[N].
425
426The SP primary EC (or the EC used when the partition is booted as described
427above):
428
429- Performs the overall SP boot time initialization, and in case of a MP SP,
430 prepares the SP environment for other execution contexts.
431- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure
432 virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA
433 entry point for other execution contexts.
434- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or
435 ``FFA_ERROR`` in case of failure.
436
437Secondary cores boot-up
438~~~~~~~~~~~~~~~~~~~~~~~
439
440Once the system is started and NWd brought up, a secondary physical core is
441woken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism
442calls into the SPMD on the newly woken up physical core. Then the SPMC is
443entered at the secondary physical core entry point.
444
445In the current implementation, the first SP is resumed on the coresponding EC
446(the virtual CPU which matches the physical core). The implication is that the
447first SP must be a MP SP.
448
449In a linux based system, once secure and normal worlds are booted but prior to
450a NWd FF-A driver has been loaded:
451
452- The first SP has initialized all its ECs in response to primary core boot up
453 (at system initialization) and secondary core boot up (as a result of linux
454 invoking PSCI_CPU_ON for all secondary cores).
455- Other SPs have their first execution context initialized as a result of secure
456 world initialization on the primary boot core. Other ECs for those SPs have to
457 be run first through ffa_run to complete their initialization (which results
458 in the EC completing with FFA_MSG_WAIT).
459
460Refer to `Power management`_ for further details.
461
J-Alves5eafd222023-10-26 14:19:21 +0100462Loading of SPs
463--------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200464
J-Alves5eafd222023-10-26 14:19:21 +0100465At boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted
466below:
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200467
J-Alves5eafd222023-10-26 14:19:21 +0100468.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200469
J-Alves5eafd222023-10-26 14:19:21 +0100470Note this boot flow is an implementation sample on Arm's FVP platform.
471Platforms not using TF-A's *Firmware CONFiguration* framework would adjust to a
472different boot flow. The flow restricts to a maximum of 8 secure partitions.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200473
J-Alves5eafd222023-10-26 14:19:21 +0100474SP Boot order
475~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200476
J-Alves5eafd222023-10-26 14:19:21 +0100477SP manifests provide an optional boot order attribute meant to resolve
478dependencies such as an SP providing a service required to properly boot
479another SP. SPMC boots the SPs in accordance to the boot order attribute,
480lowest to the highest value. If the boot order attribute is absent from the FF-A
481manifest, the SP is treated as if it had the highest boot order value
482(i.e. lowest booting priority). The FF-A specification mandates this field
483is unique to each SP.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200484
J-Alves5eafd222023-10-26 14:19:21 +0100485It is possible for an SP to call into another SP through a direct request
486provided the latter SP has already been booted.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200487
J-Alves5eafd222023-10-26 14:19:21 +0100488Passing boot data to the SP
489~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200490
J-Alves5eafd222023-10-26 14:19:21 +0100491In `[1]`_ , the section "Boot information protocol" defines a method for passing
492data to the SPs at boot time. It specifies the format for the boot information
493descriptor and boot information header structures, which describe the data to be
494exchanged between SPMC and SP.
495The specification also defines the types of data that can be passed.
496The aggregate of both the boot info structures and the data itself is designated
497the boot information blob, and is passed to a Partition as a contiguous memory
498region.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200499
J-Alves5eafd222023-10-26 14:19:21 +0100500Currently, the SPM implementation supports the FDT type which is used to pass the
501partition's DTB manifest.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200502
J-Alves5eafd222023-10-26 14:19:21 +0100503The region for the boot information blob is allocated through the SP package.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200504
J-Alves5eafd222023-10-26 14:19:21 +0100505.. image:: ../resources/diagrams/partition-package.png
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200506
J-Alves5eafd222023-10-26 14:19:21 +0100507To adjust the space allocated for the boot information blob, the json description
508of the SP (see section `Secure Partitions Layout File`_) shall be updated to contain
509the manifest offset. If no offset is provided the manifest offset defaults to 0x1000,
510which is the page size in the Hafnium SPMC.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200511
J-Alves5eafd222023-10-26 14:19:21 +0100512The configuration of the boot protocol is done in the SPs manifest. As defined by
513the specification, the manifest field 'gp-register-num' configures the GP register
514which shall be used to pass the address to the partitions boot information blob when
515booting the partition.
516In addition, the Hafnium SPMC implementation requires the boot information arguments
517to be listed in a designated DT node:
518
519.. code:: shell
520
521 boot-info {
522 compatible = "arm,ffa-manifest-boot-info";
523 ffa_manifest;
524 };
525
526The whole secure partition package image (see `Secure Partition packages`_) is
527mapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can
528retrieve the address for the boot information blob in the designated GP register,
529process the boot information header and descriptors, access its own manifest
530DTB blob and extract its partition manifest properties.
531
532SPMC Runtime
533============
534
535Parsing SP partition manifests
536------------------------------
537
538Hafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_.
539Note the current implementation may not implement all optional fields.
540
541The SP manifest may contain memory and device regions nodes:
542
543- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at
544 load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can
545 specify RX/TX buffer regions in which case it is not necessary for an SP
546 to explicitly invoke the ``FFA_RXTX_MAP`` interface. The memory referred
547 shall be contained within the memory ranges defined in SPMC manifest. The
548 NS bit in the attributes field should be consistent with the security
549 state of the range that it relates to. I.e. non-secure memory shall be
550 part of a non-secure memory range, and secure memory shall be contained
551 in a secure memory range of a given platform.
552- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or
553 EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate
554 additional resources (e.g. interrupts).
555
556For the SPMC, base addresses for memory and device region nodes are IPAs provided
557the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation regime.
558
559Note: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the
560same set of page tables. It is still open whether two sets of page tables shall
561be provided per SP. The memory region node as defined in the specification
562provides a memory security attribute hinting to map either to the secure or
563non-secure EL1&0 Stage-2 table if it exists.
564
565Secure partitions scheduling
566----------------------------
567
568The FF-A specification `[1]`_ provides two ways to relinquinsh CPU time to
569secure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of:
570
571- the FFA_MSG_SEND_DIRECT_REQ interface.
572- the FFA_RUN interface.
573
574Additionally a secure interrupt can pre-empt the normal world execution and give
575CPU cycles by transitioning to EL3 and S-EL2.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200576
577Mandatory interfaces
578--------------------
579
580The following interfaces are exposed to SPs:
581
582- ``FFA_VERSION``
583- ``FFA_FEATURES``
584- ``FFA_RX_RELEASE``
585- ``FFA_RXTX_MAP``
586- ``FFA_RXTX_UNMAP``
587- ``FFA_PARTITION_INFO_GET``
588- ``FFA_ID_GET``
589- ``FFA_MSG_WAIT``
590- ``FFA_MSG_SEND_DIRECT_REQ``
591- ``FFA_MSG_SEND_DIRECT_RESP``
592- ``FFA_MEM_DONATE``
593- ``FFA_MEM_LEND``
594- ``FFA_MEM_SHARE``
595- ``FFA_MEM_RETRIEVE_REQ``
596- ``FFA_MEM_RETRIEVE_RESP``
597- ``FFA_MEM_RELINQUISH``
598- ``FFA_MEM_FRAG_RX``
599- ``FFA_MEM_FRAG_TX``
600- ``FFA_MEM_RECLAIM``
601- ``FFA_RUN``
602
603As part of the FF-A v1.1 support, the following interfaces were added:
604
605 - ``FFA_NOTIFICATION_BITMAP_CREATE``
606 - ``FFA_NOTIFICATION_BITMAP_DESTROY``
607 - ``FFA_NOTIFICATION_BIND``
608 - ``FFA_NOTIFICATION_UNBIND``
609 - ``FFA_NOTIFICATION_SET``
610 - ``FFA_NOTIFICATION_GET``
611 - ``FFA_NOTIFICATION_INFO_GET``
612 - ``FFA_SPM_ID_GET``
613 - ``FFA_SECONDARY_EP_REGISTER``
614 - ``FFA_MEM_PERM_GET``
615 - ``FFA_MEM_PERM_SET``
616 - ``FFA_MSG_SEND2``
617 - ``FFA_RX_ACQUIRE``
618
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700619As part of the FF-A v1.2 support, the following interfaces were added:
620- ``FFA_PARTITION_INFO_GET_REGS``
621
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200622FFA_VERSION
623~~~~~~~~~~~
624
625``FFA_VERSION`` requires a *requested_version* parameter from the caller.
626The returned value depends on the caller:
627
628- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version
629 specified in the SPMC manifest.
630- SP: the SPMC returns its own implemented version.
631- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version.
632
633FFA_FEATURES
634~~~~~~~~~~~~
635
636FF-A features supported by the SPMC may be discovered by secure partitions at
637boot (that is prior to NWd is booted) or run-time.
638
639The SPMC calling FFA_FEATURES at secure physical FF-A instance always get
640FFA_SUCCESS from the SPMD.
641
642The request made by an Hypervisor or OS kernel is forwarded to the SPMC and
643the response relayed back to the NWd.
644
645FFA_RXTX_MAP/FFA_RXTX_UNMAP
646~~~~~~~~~~~~~~~~~~~~~~~~~~~
647
648When invoked from a secure partition FFA_RXTX_MAP maps the provided send and
649receive buffers described by their IPAs to the SP EL1&0 Stage-2 translation
650regime as secure buffers in the MMU descriptors.
651
652When invoked from the Hypervisor or OS kernel, the buffers are mapped into the
653SPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU
654descriptors. The provided addresses may be owned by a VM in the normal world,
655which is expected to receive messages from the secure world. The SPMC will in
656this case allocate internal state structures to facilitate RX buffer access
657synchronization (through FFA_RX_ACQUIRE interface), and to permit SPs to send
658messages.
659
660The FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the
661caller, either it being the Hypervisor or OS kernel, as well as a secure
662partition.
663
664FFA_PARTITION_INFO_GET
665~~~~~~~~~~~~~~~~~~~~~~
666
667Partition info get call can originate:
668
669- from SP to SPMC
670- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD.
671
Raghu Krishnamurthy4a793e92023-08-09 10:10:23 -0700672FFA_PARTITION_INFO_GET_REGS
673~~~~~~~~~~~~~~~~~~~~~~~~~~~
674
675This call can originate:
676
677- from SP to SPMC
678- from SPMC to SPMD
679- from Hypervsior or OS kernel to SPMC. The request is relayed by the SPMD.
680
681The primary use of this ABI is to return partition information via registers
682as opposed to via RX/TX buffers and is useful in cases where sharing memory is
683difficult.
684
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200685FFA_ID_GET
686~~~~~~~~~~
687
688The FF-A id space is split into a non-secure space and secure space:
689
690- FF-A ID with bit 15 clear relates to VMs.
691- FF-A ID with bit 15 set related to SPs.
692- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD
693 and SPMC.
694
695The SPMD returns:
696
697- The default zero value on invocation from the Hypervisor.
698- The ``spmc_id`` value specified in the SPMC manifest on invocation from
699 the SPMC (see `SPMC manifest`_)
700
701This convention helps the SPMC to determine the origin and destination worlds in
702an FF-A ABI invocation. In particular the SPMC shall filter unauthorized
703transactions in its world switch routine. It must not be permitted for a VM to
704use a secure FF-A ID as origin world by spoofing:
705
706- A VM-to-SP direct request/response shall set the origin world to be non-secure
707 (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15
708 set).
709- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15
710 for both origin and destination IDs.
711
712An incoming direct message request arriving at SPMD from NWd is forwarded to
713SPMC without a specific check. The SPMC is resumed through eret and "knows" the
714message is coming from normal world in this specific code path. Thus the origin
715endpoint ID must be checked by SPMC for being a normal world ID.
716
717An SP sending a direct message request must have bit 15 set in its origin
718endpoint ID and this can be checked by the SPMC when the SP invokes the ABI.
719
720The SPMC shall reject the direct message if the claimed world in origin endpoint
721ID is not consistent:
722
723- It is either forwarded by SPMD and thus origin endpoint ID must be a "normal
724 world ID",
725- or initiated by an SP and thus origin endpoint ID must be a "secure world ID".
726
727
728FFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP
729~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
730
731This is a mandatory interface for secure partitions consisting in direct request
732and responses with the following rules:
733
734- An SP can send a direct request to another SP.
735- An SP can receive a direct request from another SP.
736- An SP can send a direct response to another SP.
737- An SP cannot send a direct request to an Hypervisor or OS kernel.
738- An Hypervisor or OS kernel can send a direct request to an SP.
739- An SP can send a direct response to an Hypervisor or OS kernel.
740
741FFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY
742~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
743
744The secure partitions notifications bitmap are statically allocated by the SPMC.
745Hence, this interface is not to be issued by secure partitions.
746
747At initialization, the SPMC is not aware of VMs/partitions deployed in the
748normal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC
749to be prepared to handle notifications for the provided VM ID.
750
751FFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND
752~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
753
754Pair of interfaces to manage permissions to signal notifications. Prior to
755handling notifications, an FF-A endpoint must allow a given sender to signal a
756bitmap of notifications.
757
758If the receiver doesn't have notification support enabled in its FF-A manifest,
759it won't be able to bind notifications, hence forbidding it to receive any
760notifications.
761
762FFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET
763~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
764
765FFA_NOTIFICATION_GET retrieves all pending global notifications and
766per-vCPU notifications targeted to the current vCPU.
767
768Hafnium maintains a global count of pending notifications which gets incremented
769and decremented when handling FFA_NOTIFICATION_SET and FFA_NOTIFICATION_GET
770respectively. A delayed SRI is triggered if the counter is non-zero when the
771SPMC returns to normal world.
772
773FFA_NOTIFICATION_INFO_GET
774~~~~~~~~~~~~~~~~~~~~~~~~~
775
776Hafnium maintains a global count of pending notifications whose information
777has been retrieved by this interface. The count is incremented and decremented
778when handling FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET respectively.
779It also tracks notifications whose information has been retrieved individually,
780such that it avoids duplicating returned information for subsequent calls to
781FFA_NOTIFICATION_INFO_GET. For each notification, this state information is
782reset when receiver called FFA_NOTIFICATION_GET to retrieve them.
783
784FFA_SPM_ID_GET
785~~~~~~~~~~~~~~
786
787Returns the FF-A ID allocated to an SPM component which can be one of SPMD
788or SPMC.
789
790At initialization, the SPMC queries the SPMD for the SPMC ID, using the
791FFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using
792the FFA_SPM_ID_GET interface at the secure physical FF-A instance.
793
794Secure partitions call this interface at the virtual FF-A instance, to which
795the SPMC returns the priorly retrieved SPMC ID.
796
797The Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the
798SPMD, which returns the SPMC ID.
799
800FFA_SECONDARY_EP_REGISTER
801~~~~~~~~~~~~~~~~~~~~~~~~~
802
803When the SPMC boots, all secure partitions are initialized on their primary
804Execution Context.
805
806The FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition
807from its first execution context, to provide the entry point address for
808secondary execution contexts.
809
810A secondary EC is first resumed either upon invocation of PSCI_CPU_ON from
811the NWd or by invocation of FFA_RUN.
812
813FFA_RX_ACQUIRE/FFA_RX_RELEASE
814~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
815
816The RX buffers can be used to pass information to an FF-A endpoint in the
817following scenarios:
818
819 - When it was targetted by a FFA_MSG_SEND2 invokation from another endpoint.
820 - Return the result of calling ``FFA_PARTITION_INFO_GET``.
821 - In a memory share operation, as part of the ``FFA_MEM_RETRIEVE_RESP``,
822 with the memory descriptor of the shared memory.
823
824If a normal world VM is expected to exchange messages with secure world,
825its RX/TX buffer addresses are forwarded to the SPMC via FFA_RXTX_MAP ABI,
826and are from this moment owned by the SPMC.
827The hypervisor must call the FFA_RX_ACQUIRE interface before attempting
828to use the RX buffer, in any of the aforementioned scenarios. A successful
829call to FFA_RX_ACQUIRE transfers ownership of RX buffer to hypervisor, such
830that it can be safely used.
831
832The FFA_RX_RELEASE interface is used after the FF-A endpoint is done with
833processing the data received in its RX buffer. If the RX buffer has been
834acquired by the hypervisor, the FFA_RX_RELEASE call must be forwarded to
835the SPMC to reestablish SPMC's RX ownership.
836
837An attempt from an SP to send a message to a normal world VM whose RX buffer
838was acquired by the hypervisor fails with error code FFA_BUSY, to preserve
839the RX buffer integrity.
840The operation could then be conducted after FFA_RX_RELEASE.
841
842FFA_MSG_SEND2
843~~~~~~~~~~~~~
844
845Hafnium copies a message from the sender TX buffer into receiver's RX buffer.
846For messages from SPs to VMs, operation is only possible if the SPMC owns
847the receiver's RX buffer.
848
849Both receiver and sender need to enable support for indirect messaging,
850in their respective partition manifest. The discovery of support
851of such feature can be done via FFA_PARTITION_INFO_GET.
852
853On a successful message send, Hafnium pends an RX buffer full framework
854notification for the receiver, to inform it about a message in the RX buffer.
855
856The handling of framework notifications is similar to that of
857global notifications. Binding of these is not necessary, as these are
858reserved to be used by the hypervisor or SPMC.
859
Madhukar Pappireddy0b2304b2023-08-15 18:05:21 -0500860Paravirtualized interfaces
861--------------------------
862
863Hafnium SPMC implements the following implementation-defined interface(s):
864
865HF_INTERRUPT_ENABLE
866~~~~~~~~~~~~~~~~~~~
867
868Enables or disables the given virtual interrupt for the calling execution
869context. Returns 0 on success, or -1 if the interrupt id is invalid.
870
871HF_INTERRUPT_GET
872~~~~~~~~~~~~~~~~
873
874Returns the ID of the next pending virtual interrupt for the calling execution
875context, and acknowledges it (i.e. marks it as no longer pending). Returns
876HF_INVALID_INTID if there are no pending interrupts.
877
878HF_INTERRUPT_DEACTIVATE
879~~~~~~~~~~~~~~~~~~~~~~~
880
881Drops the current interrupt priority and deactivates the given virtual and
882physical interrupt ID for the calling execution context. Returns 0 on success,
883or -1 otherwise.
884
885HF_INTERRUPT_RECONFIGURE
886~~~~~~~~~~~~~~~~~~~~~~~~
887
888An SP specifies the list of interrupts it owns through its partition manifest.
889This paravirtualized interface allows an SP to reconfigure a physical interrupt
890in runtime. It accepts three arguments, namely, interrupt ID, command and value.
891The command & value pair signify what change is being requested by the current
892Secure Partition for the given interrupt.
893
894SPMC returns 0 to indicate that the command was processed successfully or -1 if
895it failed to do so. At present, this interface only supports the following
896commands:
897
898 - ``INT_RECONFIGURE_TARGET_PE``
899 - Change the target CPU of the interrupt.
900 - Value represents linear CPU index in the range 0 to (MAX_CPUS - 1).
901
902 - ``INT_RECONFIGURE_SEC_STATE``
903 - Change the security state of the interrupt.
904 - Value must be either 0 (Non-secure) or 1 (Secure).
905
906 - ``INT_RECONFIGURE_ENABLE``
907 - Enable or disable the physical interrupt.
908 - Value must be either 0 (Disable) or 1 (Enable).
909
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200910SPMC-SPMD direct requests/responses
911-----------------------------------
912
913Implementation-defined FF-A IDs are allocated to the SPMC and SPMD.
914Using those IDs in source/destination fields of a direct request/response
915permits SPMD to SPMC communication and either way.
916
917- SPMC to SPMD direct request/response uses SMC conduit.
918- SPMD to SPMC direct request/response uses ERET conduit.
919
920This is used in particular to convey power management messages.
921
J-Alves5eafd222023-10-26 14:19:21 +0100922Notifications
923-------------
924
925The FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous
926communication mechanism with non-blocking semantics. It allows for one FF-A
927endpoint to signal another for service provision, without hindering its current
928progress.
929
930Hafnium currently supports 64 notifications. The IDs of each notification define
931a position in a 64-bit bitmap.
932
933The signaling of notifications can interchangeably happen between NWd and SWd
934FF-A endpoints.
935
936The SPMC is in charge of managing notifications from SPs to SPs, from SPs to
937VMs, and from VMs to SPs. An hypervisor component would only manage
938notifications from VMs to VMs. Given the SPMC has no visibility of the endpoints
939deployed in NWd, the Hypervisor or OS kernel must invoke the interface
940FFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A
941endpoint in the NWd that supports it.
942
943A sender can signal notifications once the receiver has provided it with
944permissions. Permissions are provided by invoking the interface
945FFA_NOTIFICATION_BIND.
946
947Notifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth
948they are considered to be in a pending sate. The receiver can retrieve its
949pending notifications invoking FFA_NOTIFICATION_GET, which, from that moment,
950are considered to be handled.
951
952Per the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler
953that is in charge of donating CPU cycles for notifications handling. The
954FF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about
955which FF-A endpoints have pending notifications. The receiver scheduler is
956called and informed by the FF-A driver, and it should allocate CPU cycles to the
957receiver.
958
959There are two types of notifications supported:
960
961- Global, which are targeted to a FF-A endpoint and can be handled within any of
962 its execution contexts, as determined by the scheduler of the system.
963- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a
964 a specific execution context, as determined by the sender.
965
966The type of a notification is set when invoking FFA_NOTIFICATION_BIND to give
967permissions to the sender.
968
969Notification signaling resorts to two interrupts:
970
971- Schedule Receiver Interrupt: non-secure physical interrupt to be handled by
972 the FF-A driver within the receiver scheduler. At initialization the SPMC
973 donates an SGI ID chosen from the secure SGI IDs range and configures it as
974 non-secure. The SPMC triggers this SGI on the currently running core when
975 there are pending notifications, and the respective receivers need CPU cycles
976 to handle them.
977- Notifications Pending Interrupt: virtual interrupt to be handled by the
978 receiver of the notification. Set when there are pending notifications for the
979 given secure partition. The NPI is pended when the NWd relinquishes CPU cycles
980 to an SP.
981
982The notifications receipt support is enabled in the partition FF-A manifest.
983
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +0200984Memory Sharing
985--------------
986
987Hafnium implements the following memory sharing interfaces:
988
989 - ``FFA_MEM_SHARE`` - for shared access between lender and borrower.
990 - ``FFA_MEM_LEND`` - borrower to obtain exclusive access, though lender
991 retains ownership of the memory.
992 - ``FFA_MEM_DONATE`` - lender permanently relinquishes ownership of memory
993 to the borrower.
994
995The ``FFA_MEM_RETRIEVE_REQ`` interface is for the borrower to request the
996memory to be mapped into its address space: for S-EL1 partitions the SPM updates
997their stage 2 translation regime; for S-EL0 partitions the SPM updates their
998stage 1 translation regime. On a successful call, the SPMC responds back with
999``FFA_MEM_RETRIEVE_RESP``.
1000
1001The ``FFA_MEM_RELINQUISH`` interface is for when the borrower is done with using
1002a memory region.
1003
1004The ``FFA_MEM_RECLAIM`` interface is for the owner of the memory to reestablish
1005its ownership and exclusive access to the memory shared.
1006
1007The memory transaction descriptors are transmitted via RX/TX buffers. In
1008situations where the size of the memory transaction descriptor exceeds the
1009size of the RX/TX buffers, Hafnium provides support for fragmented transmission
1010of the full transaction descriptor. The ``FFA_MEM_FRAG_RX`` and ``FFA_MEM_FRAG_TX``
1011interfaces are for receiving and transmitting the next fragment, respectively.
1012
1013If lender and borrower(s) are SPs, all memory sharing operations are supported.
1014
1015Hafnium also supports memory sharing operations between the normal world and the
1016secure world. If there is an SP involved, the SPMC allocates data to track the
1017state of the operation.
1018
1019The SPMC is also the designated allocator for the memory handle. The hypervisor
1020or OS kernel has the possibility to rely on the SPMC to maintain the state
1021of the operation, thus saving memory.
J-Alvesda82a1a2023-10-17 11:45:49 +01001022An SP can not share, lend or donate memory to the NWd.
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001023
1024The SPMC supports the hypervisor retrieve request, as defined by the FF-A
1025v1.1 EAC0 specification, in section 16.4.3. The intent is to aid with operations
1026that the hypervisor must do for a VM retriever. For example, when handling
1027an FFA_MEM_RECLAIM, if the hypervisor relies on SPMC to keep the state
1028of the operation, the hypervisor retrieve request can be used to obtain
1029that state information, do the necessary validations, and update stage 2
1030memory translation.
1031
1032Hafnium also supports memory lend and share targetting multiple borrowers.
1033This is the case for a lender SP to multiple SPs, and for a lender VM to
1034multiple endpoints (from both secure world and normal world). If there is
1035at least one borrower VM, the hypervisor is in charge of managing its
1036stage 2 translation on a successful memory retrieve.
1037The semantics of ``FFA_MEM_DONATE`` implies ownership transmission,
1038which should target only one partition.
1039
1040The memory share interfaces are backwards compatible with memory transaction
1041descriptors from FF-A v1.0. These get translated to FF-A v1.1 descriptors for
1042Hafnium's internal processing of the operation. If the FF-A version of a
1043borrower is v1.0, Hafnium provides FF-A v1.0 compliant memory transaction
1044descriptors on memory retrieve response.
1045
1046PE MMU configuration
1047--------------------
1048
1049With secure virtualization enabled (``HCR_EL2.VM = 1``) and for S-EL1
1050partitions, two IPA spaces (secure and non-secure) are output from the
1051secure EL1&0 Stage-1 translation.
1052The EL1&0 Stage-2 translation hardware is fed by:
1053
1054- A secure IPA when the SP EL1&0 Stage-1 MMU is disabled.
1055- One of secure or non-secure IPA when the secure EL1&0 Stage-1 MMU is enabled.
1056
1057``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the
1058NS/S IPA translations. The following controls are set up:
1059``VSTCR_EL2.SW = 0`` , ``VSTCR_EL2.SA = 0``, ``VTCR_EL2.NSW = 0``,
1060``VTCR_EL2.NSA = 1``:
1061
1062- Stage-2 translations for the NS IPA space access the NS PA space.
1063- Stage-2 translation table walks for the NS IPA space are to the secure PA space.
1064
1065Secure and non-secure IPA regions (rooted to by ``VTTBR_EL2`` and ``VSTTBR_EL2``)
1066use the same set of Stage-2 page tables within a SP.
1067
1068The ``VTCR_EL2/VSTCR_EL2/VTTBR_EL2/VSTTBR_EL2`` virtual address space
1069configuration is made part of a vCPU context.
1070
1071For S-EL0 partitions with VHE enabled, a single secure EL2&0 Stage-1 translation
1072regime is used for both Hafnium and the partition.
1073
1074Schedule modes and SP Call chains
1075---------------------------------
1076
1077An SP execution context is said to be in SPMC scheduled mode if CPU cycles are
1078allocated to it by SPMC. Correspondingly, an SP execution context is said to be
1079in Normal world scheduled mode if CPU cycles are allocated by the normal world.
1080
1081A call chain represents all SPs in a sequence of invocations of a direct message
1082request. When execution on a PE is in the secure state, only a single call chain
1083that runs in the Normal World scheduled mode can exist. FF-A v1.1 spec allows
1084any number of call chains to run in the SPMC scheduled mode but the Hafnium
1085SPMC restricts the number of call chains in SPMC scheduled mode to only one for
1086keeping the implementation simple.
1087
1088Partition runtime models
1089------------------------
1090
1091The runtime model of an endpoint describes the transitions permitted for an
1092execution context between various states. These are the four partition runtime
1093models supported (refer to `[1]`_ section 7):
1094
1095 - RTM_FFA_RUN: runtime model presented to an execution context that is
1096 allocated CPU cycles through FFA_RUN interface.
1097 - RTM_FFA_DIR_REQ: runtime model presented to an execution context that is
1098 allocated CPU cycles through FFA_MSG_SEND_DIRECT_REQ interface.
1099 - RTM_SEC_INTERRUPT: runtime model presented to an execution context that is
1100 allocated CPU cycles by SPMC to handle a secure interrupt.
1101 - RTM_SP_INIT: runtime model presented to an execution context that is
1102 allocated CPU cycles by SPMC to initialize its state.
1103
1104If an endpoint execution context attempts to make an invalid transition or a
1105valid transition that could lead to a loop in the call chain, SPMC denies the
1106transition with the help of above runtime models.
1107
1108Interrupt management
1109--------------------
1110
1111GIC ownership
1112~~~~~~~~~~~~~
1113
1114The SPMC owns the GIC configuration. Secure and non-secure interrupts are
1115trapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt
1116IDs based on SP manifests. The SPMC acknowledges physical interrupts and injects
1117virtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP.
1118
1119Abbreviations:
1120
1121 - NS-Int: A non-secure physical interrupt. It requires a switch to the normal
1122 world to be handled if it triggers while execution is in secure world.
1123 - Other S-Int: A secure physical interrupt targeted to an SP different from
1124 the one that is currently running.
1125 - Self S-Int: A secure physical interrupt targeted to the SP that is currently
1126 running.
1127
1128Non-secure interrupt handling
1129~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1130
1131This section documents the actions supported in SPMC in response to a non-secure
1132interrupt as per the guidance provided by FF-A v1.1 EAC0 specification.
1133An SP specifies one of the following actions in its partition manifest:
1134
1135 - Non-secure interrupt is signaled.
1136 - Non-secure interrupt is signaled after a managed exit.
1137 - Non-secure interrupt is queued.
1138
1139An SP execution context in a call chain could specify a less permissive action
1140than subsequent SP execution contexts in the same call chain. The less
1141permissive action takes precedence over the more permissive actions specified
1142by the subsequent execution contexts. Please refer to FF-A v1.1 EAC0 section
11438.3.1 for further explanation.
1144
1145Secure interrupt handling
1146~~~~~~~~~~~~~~~~~~~~~~~~~
1147
1148This section documents the support implemented for secure interrupt handling in
1149SPMC as per the guidance provided by FF-A v1.1 EAC0 specification.
1150The following assumptions are made about the system configuration:
1151
1152 - In the current implementation, S-EL1 SPs are expected to use the para
1153 virtualized ABIs for interrupt management rather than accessing the virtual
1154 GIC interface.
1155 - Unless explicitly stated otherwise, this support is applicable only for
1156 S-EL1 SPs managed by SPMC.
1157 - Secure interrupts are configured as G1S or G0 interrupts.
1158 - All physical interrupts are routed to SPMC when running a secure partition
1159 execution context.
1160 - All endpoints with multiple execution contexts have their contexts pinned
1161 to corresponding CPUs. Hence, a secure virtual interrupt cannot be signaled
1162 to a target vCPU that is currently running or blocked on a different
1163 physical CPU.
1164
1165A physical secure interrupt could trigger while CPU is executing in normal world
1166or secure world.
1167The action of SPMC for a secure interrupt depends on: the state of the target
1168execution context of the SP that is responsible for handling the interrupt;
1169whether the interrupt triggered while execution was in normal world or secure
1170world.
1171
1172Secure interrupt signaling mechanisms
1173~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1174
1175Signaling refers to the mechanisms used by SPMC to indicate to the SP execution
1176context that it has a pending virtual interrupt and to further run the SP
1177execution context, such that it can handle the virtual interrupt. SPMC uses
1178either the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling
1179to S-EL1 SPs. When normal world execution is preempted by a secure interrupt,
1180the SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC
1181running in S-EL2.
1182
1183+-----------+---------+---------------+---------------------------------------+
1184| SP State | Conduit | Interface and | Description |
1185| | | parameters | |
1186+-----------+---------+---------------+---------------------------------------+
1187| WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending |
1188| | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and |
1189| | | | resumes execution context of SP |
1190| | | | through ERET. |
1191+-----------+---------+---------------+---------------------------------------+
1192| BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt |
1193| | vIRQ | | is pending. It pends vIRQ signal and |
1194| | | | resumes execution context of SP |
1195| | | | through ERET. |
1196+-----------+---------+---------------+---------------------------------------+
1197| PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does |
1198| | | | not resume execution context of SP. |
1199+-----------+---------+---------------+---------------------------------------+
1200| RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes|
1201| | vIRQ | | execution context of SP through ERET. |
1202+-----------+---------+---------------+---------------------------------------+
1203
1204Secure interrupt completion mechanisms
1205~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1206
1207A SP signals secure interrupt handling completion to the SPMC through the
1208following mechanisms:
1209
1210 - ``FFA_MSG_WAIT`` ABI if it was in WAITING state.
1211 - ``FFA_RUN`` ABI if its was in BLOCKED state.
1212
1213This is a remnant of SPMC implementation based on the FF-A v1.0 specification.
1214In the current implementation, S-EL1 SPs use the para-virtualized HVC interface
1215implemented by SPMC to perform priority drop and interrupt deactivation (SPMC
1216configures EOImode = 0, i.e. priority drop and deactivation are done together).
1217The SPMC performs checks to deny the state transition upon invocation of
1218either FFA_MSG_WAIT or FFA_RUN interface if the SP didn't perform the
1219deactivation of the secure virtual interrupt.
1220
1221If the current SP execution context was preempted by a secure interrupt to be
1222handled by execution context of target SP, SPMC resumes current SP after signal
1223completion by target SP execution context.
1224
1225Actions for a secure interrupt triggered while execution is in normal world
1226~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1227
1228+-------------------+----------+-----------------------------------------------+
1229| State of target | Action | Description |
1230| execution context | | |
1231+-------------------+----------+-----------------------------------------------+
1232| WAITING | Signaled | This starts a new call chain in SPMC scheduled|
1233| | | mode. |
1234+-------------------+----------+-----------------------------------------------+
1235| PREEMPTED | Queued | The target execution must have been preempted |
1236| | | by a non-secure interrupt. SPMC queues the |
1237| | | secure virtual interrupt now. It is signaled |
1238| | | when the target execution context next enters |
1239| | | the RUNNING state. |
1240+-------------------+----------+-----------------------------------------------+
1241| BLOCKED, RUNNING | NA | The target execution context is blocked or |
1242| | | running on a different CPU. This is not |
1243| | | supported by current SPMC implementation and |
1244| | | execution hits panic. |
1245+-------------------+----------+-----------------------------------------------+
1246
1247If normal world execution was preempted by a secure interrupt, SPMC uses
1248FFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling
1249and further returns execution to normal world.
1250
1251The following figure describes interrupt handling flow when a secure interrupt
1252triggers while execution is in normal world:
1253
1254.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png
1255
1256A brief description of the events:
1257
1258 - 1) Secure interrupt triggers while normal world is running.
1259 - 2) FIQ gets trapped to EL3.
1260 - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI.
1261 - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends
1262 vIRQ).
1263 - 5) Assuming SP1 vCPU is in WAITING state, SPMC signals virtual interrupt
1264 using FFA_INTERRUPT with interrupt id as an argument and resumes the SP1
1265 vCPU using ERET in SPMC scheduled mode.
1266 - 6) Execution traps to vIRQ handler in SP1 provided that the virtual
1267 interrupt is not masked i.e., PSTATE.I = 0
1268 - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized
1269 HVC call. SPMC clears the pending virtual interrupt state management
1270 and returns the pending virtual interrupt id.
1271 - 8) SP1 services the virtual interrupt and invokes the paravirtualized
1272 de-activation HVC call. SPMC de-activates the physical interrupt,
1273 clears the fields tracking the secure interrupt and resumes SP1 vCPU.
1274 - 9) SP1 performs secure interrupt completion through FFA_MSG_WAIT ABI.
1275 - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME.
1276 - 11) EL3 resumes normal world execution.
1277
1278Actions for a secure interrupt triggered while execution is in secure world
1279~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1280
1281+-------------------+----------+------------------------------------------------+
1282| State of target | Action | Description |
1283| execution context | | |
1284+-------------------+----------+------------------------------------------------+
1285| WAITING | Signaled | This starts a new call chain in SPMC scheduled |
1286| | | mode. |
1287+-------------------+----------+------------------------------------------------+
1288| PREEMPTED by Self | Signaled | The target execution context reenters the |
1289| S-Int | | RUNNING state to handle the secure virtual |
1290| | | interrupt. |
1291+-------------------+----------+------------------------------------------------+
1292| PREEMPTED by | Queued | SPMC queues the secure virtual interrupt now. |
1293| NS-Int | | It is signaled when the target execution |
1294| | | context next enters the RUNNING state. |
1295+-------------------+----------+------------------------------------------------+
1296| BLOCKED | Signaled | Both preempted and target execution contexts |
1297| | | must have been part of the Normal world |
1298| | | scheduled call chain. Refer scenario 1 of |
1299| | | Table 8.4 in the FF-A v1.1 EAC0 spec. |
1300+-------------------+----------+------------------------------------------------+
1301| RUNNING | NA | The target execution context is running on a |
1302| | | different CPU. This scenario is not supported |
1303| | | by current SPMC implementation and execution |
1304| | | hits panic. |
1305+-------------------+----------+------------------------------------------------+
1306
1307The following figure describes interrupt handling flow when a secure interrupt
1308triggers while execution is in secure world. We assume OS kernel sends a direct
1309request message to SP1. Further, SP1 sends a direct request message to SP2. SP1
1310enters BLOCKED state and SPMC resumes SP2.
1311
1312.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png
1313
1314A brief description of the events:
1315
1316 - 1) Secure interrupt triggers while SP2 is running.
1317 - 2) SP2 gets preempted and execution traps to SPMC as IRQ.
1318 - 3) SPMC finds the target vCPU of secure partition responsible for handling
1319 this secure interrupt. In this scenario, it is SP1.
1320 - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface.
1321 SPMC further resumes SP1 through ERET conduit. Note that SP1 remains in
1322 Normal world schedule mode.
1323 - 6) Execution traps to vIRQ handler in SP1 provided that the virtual
1324 interrupt is not masked i.e., PSTATE.I = 0
1325 - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized
1326 HVC call. SPMC clears the pending virtual interrupt state management
1327 and returns the pending virtual interrupt id.
1328 - 8) SP1 services the virtual interrupt and invokes the paravirtualized
1329 de-activation HVC call. SPMC de-activates the physical interrupt and
1330 clears the fields tracking the secure interrupt and resumes SP1 vCPU.
1331 - 9) Since SP1 direct request completed with FFA_INTERRUPT, it resumes the
1332 direct request to SP2 by invoking FFA_RUN.
1333 - 9) SPMC resumes the pre-empted vCPU of SP2.
1334
1335EL3 interrupt handling
1336~~~~~~~~~~~~~~~~~~~~~~
1337
1338In GICv3 based systems, EL3 interrupts are configured as Group0 secure
1339interrupts. Execution traps to SPMC when a Group0 interrupt triggers while an
1340SP is running. Further, SPMC running at S-EL2 uses FFA_EL3_INTR_HANDLE ABI to
1341request EL3 platform firmware to handle a pending Group0 interrupt.
1342Similarly, SPMD registers a handler with interrupt management framework to
1343delegate handling of Group0 interrupt to the platform if the interrupt triggers
1344in normal world.
1345
1346 - Platform hook
1347
1348 - plat_spmd_handle_group0_interrupt
1349
1350 SPMD provides platform hook to handle Group0 secure interrupts. In the
1351 current design, SPMD expects the platform not to delegate handling to the
1352 NWd (such as through SDEI) while processing Group0 interrupts.
1353
1354Power management
1355----------------
1356
1357In platforms with or without secure virtualization:
1358
1359- The NWd owns the platform PM policy.
1360- The Hypervisor or OS kernel is the component initiating PSCI service calls.
1361- The EL3 PSCI library is in charge of the PM coordination and control
1362 (eventually writing to platform registers).
1363- While coordinating PM events, the PSCI library calls backs into the Secure
1364 Payload Dispatcher for events the latter has statically registered to.
1365
1366When using the SPMD as a Secure Payload Dispatcher:
1367
1368- A power management event is relayed through the SPD hook to the SPMC.
1369- In the current implementation only cpu on (svc_on_finish) and cpu off
1370 (svc_off) hooks are registered.
1371- The behavior for the cpu on event is described in `Secondary cores boot-up`_.
1372 The SPMC is entered through its secondary physical core entry point.
1373- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The PM event is
1374 signaled to the SPMC through a power management framework message.
1375 It consists in a SPMD-to-SPMC direct request/response (`SPMC-SPMD direct
1376 requests/responses`_) conveying the event details and SPMC response.
1377 The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and
1378 updates its internal state to reflect the physical core is being turned off.
1379 In the current implementation no SP is resumed as a consequence. This behavior
1380 ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux
1381 userspace.
1382
1383Arm architecture extensions for security hardening
J-Alves5eafd222023-10-26 14:19:21 +01001384--------------------------------------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001385
1386Hafnium supports the following architecture extensions for security hardening:
1387
1388- Pointer authentication (FEAT_PAuth): the extension permits detection of forged
1389 pointers used by ROP type of attacks through the signing of the pointer
1390 value. Hafnium is built with the compiler branch protection option to permit
1391 generation of a pointer authentication code for return addresses (pointer
1392 authentication for instructions). The APIA key is used while Hafnium runs.
1393 A random key is generated at boot time and restored upon entry into Hafnium
1394 at run-time. APIA and other keys (APIB, APDA, APDB, APGA) are saved/restored
1395 in vCPU contexts permitting to enable pointer authentication in VMs/SPs.
1396- Branch Target Identification (FEAT_BTI): the extension permits detection of
1397 unexpected indirect branches used by JOP type of attacks. Hafnium is built
1398 with the compiler branch protection option, inserting land pads at function
1399 prologues that are reached by indirect branch instructions (BR/BLR).
1400 Hafnium code pages are marked as guarded in the EL2 Stage-1 MMU descriptors
1401 such that an indirect branch must always target a landpad. A fault is
1402 triggered otherwise. VMs/SPs can (independently) mark their code pages as
1403 guarded in the EL1&0 Stage-1 translation regime.
1404- Memory Tagging Extension (FEAT_MTE): the option permits detection of out of
1405 bound memory array accesses or re-use of an already freed memory region.
1406 Hafnium enables the compiler option permitting to leverage MTE stack tagging
1407 applied to core stacks. Core stacks are marked as normal tagged memory in the
1408 EL2 Stage-1 translation regime. A synchronous data abort is generated upon tag
1409 check failure on load/stores. A random seed is generated at boot time and
1410 restored upon entry into Hafnium. MTE system registers are saved/restored in
1411 vCPU contexts permitting MTE usage from VMs/SPs.
1412
1413SMMUv3 support in Hafnium
J-Alves5eafd222023-10-26 14:19:21 +01001414-------------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001415
1416An SMMU is analogous to an MMU in a CPU. It performs address translations for
1417Direct Memory Access (DMA) requests from system I/O devices.
1418The responsibilities of an SMMU include:
1419
1420- Translation: Incoming DMA requests are translated from bus address space to
1421 system physical address space using translation tables compliant to
1422 Armv8/Armv7 VMSA descriptor format.
1423- Protection: An I/O device can be prohibited from read, write access to a
1424 memory region or allowed.
1425- Isolation: Traffic from each individial device can be independently managed.
1426 The devices are differentiated from each other using unique translation
1427 tables.
1428
1429The following diagram illustrates a typical SMMU IP integrated in a SoC with
1430several I/O devices along with Interconnect and Memory system.
1431
1432.. image:: ../resources/diagrams/MMU-600.png
1433
1434SMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides
1435support for SMMUv3 driver in both normal and secure world. A brief introduction
1436of SMMUv3 functionality and the corresponding software support in Hafnium is
1437provided here.
1438
1439SMMUv3 features
J-Alves5eafd222023-10-26 14:19:21 +01001440~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001441
1442- SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2)
1443 translation support. It can either bypass or abort incoming translations as
1444 well.
1445- Traffic (memory transactions) from each upstream I/O peripheral device,
1446 referred to as Stream, can be independently managed using a combination of
1447 several memory based configuration structures. This allows the SMMUv3 to
1448 support a large number of streams with each stream assigned to a unique
1449 translation context.
1450- Support for Armv8.1 VMSA where the SMMU shares the translation tables with
1451 a Processing Element. AArch32(LPAE) and AArch64 translation table format
1452 are supported by SMMUv3.
1453- SMMUv3 offers non-secure stream support with secure stream support being
1454 optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU
1455 instance for secure and non-secure stream support.
1456- It also supports sub-streams to differentiate traffic from a virtualized
1457 peripheral associated with a VM/SP.
1458- Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A
1459 extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2
1460 for providing Secure Stage2 translation support to upstream peripheral
1461 devices.
1462
1463SMMUv3 Programming Interfaces
J-Alves5eafd222023-10-26 14:19:21 +01001464~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001465
1466SMMUv3 has three software interfaces that are used by the Hafnium driver to
1467configure the behaviour of SMMUv3 and manage the streams.
1468
1469- Memory based data strutures that provide unique translation context for
1470 each stream.
1471- Memory based circular buffers for command queue and event queue.
1472- A large number of SMMU configuration registers that are memory mapped during
1473 boot time by Hafnium driver. Except a few registers, all configuration
1474 registers have independent secure and non-secure versions to configure the
1475 behaviour of SMMUv3 for translation of secure and non-secure streams
1476 respectively.
1477
1478Peripheral device manifest
J-Alves5eafd222023-10-26 14:19:21 +01001479~~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001480
1481Currently, SMMUv3 driver in Hafnium only supports dependent peripheral devices.
1482These devices are dependent on PE endpoint to initiate and receive memory
1483management transactions on their behalf. The acccess to the MMIO regions of
1484any such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver
1485uses the same stage 2 translations for the device as those used by partition
1486manager on behalf of the PE endpoint. This ensures that the peripheral device
1487has the same visibility of the physical address space as the endpoint. The
1488device node of the corresponding partition manifest (refer to `[1]`_ section 3.2
1489) must specify these additional properties for each peripheral device in the
1490system :
1491
1492- smmu-id: This field helps to identify the SMMU instance that this device is
1493 upstream of.
1494- stream-ids: List of stream IDs assigned to this device.
1495
1496.. code:: shell
1497
1498 smmuv3-testengine {
1499 base-address = <0x00000000 0x2bfe0000>;
1500 pages-count = <32>;
1501 attributes = <0x3>;
1502 smmu-id = <0>;
1503 stream-ids = <0x0 0x1>;
1504 interrupts = <0x2 0x3>, <0x4 0x5>;
1505 exclusive-access;
1506 };
1507
1508SMMUv3 driver limitations
J-Alves5eafd222023-10-26 14:19:21 +01001509~~~~~~~~~~~~~~~~~~~~~~~~~
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001510
1511The primary design goal for the Hafnium SMMU driver is to support secure
1512streams.
1513
1514- Currently, the driver only supports Stage2 translations. No support for
1515 Stage1 or nested translations.
1516- Supports only AArch64 translation format.
1517- No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS,
1518 Fault handling, Performance Monitor Extensions, Event Handling, MPAM.
1519- No support for independent peripheral devices.
1520
1521S-EL0 Partition support
J-Alves5eafd222023-10-26 14:19:21 +01001522-----------------------
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001523The SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using
1524FEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world
1525with ARMv8.4 and FEAT_SEL2).
1526
1527S-EL0 partitions are useful for simple partitions that don't require full
1528Trusted OS functionality. It is also useful to reduce jitter and cycle
1529stealing from normal world since they are more lightweight than VMs.
1530
1531S-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by
1532the SPMC. They are differentiated primarily by the 'exception-level' property
1533and the 'execution-ctx-count' property in the SP manifest. They are host apps
1534under the single EL2&0 Stage-1 translation regime controlled by the SPMC and
1535call into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions
1536can use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions
1537for memory regions.
1538
1539S-EL0 partitions are required by the FF-A specification to be UP endpoints,
1540capable of migrating, and the SPMC enforces this requirement. The SPMC allows
1541a S-EL0 partition to accept a direct message from secure world and normal world,
1542and generate direct responses to them.
1543All S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not supported.
1544
1545Memory sharing, indirect messaging, and notifications functionality with S-EL0
1546partitions is supported.
1547
1548Interrupt handling is not supported with S-EL0 partitions and is work in
1549progress.
1550
1551References
1552==========
1553
J-Alves5eafd222023-10-26 14:19:21 +01001554.. _TF-A project: https://trustedfirmware-a.readthedocs.io/en/latest/
1555
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001556.. _[1]:
1557
1558[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__
1559
1560.. _[2]:
1561
1562[2] `Secure Partition Manager using MM interface <https://trustedfirmware-a.readthedocs.io/en/latest/components/secure-partition-manager-mm.html>`__
1563
1564.. _[3]:
1565
1566[3] `Trusted Boot Board Requirements
1567Client <https://developer.arm.com/documentation/den0006/d/>`__
1568
1569.. _[4]:
1570
1571[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45
1572
1573.. _[5]:
1574
1575[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts
1576
1577.. _[6]:
1578
1579[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html
1580
1581.. _[7]:
1582
1583[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts
1584
1585.. _[8]:
1586
1587[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/
1588
1589.. _[9]:
1590
1591[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot
1592
J-Alvesd8094162023-10-26 12:44:33 +01001593.. _[10]:
1594
1595[10] https://trustedfirmware-a.readthedocs.io/en/latest/getting_started/build-options.html#
1596
Olivier Deprezcbf7d5b2023-05-22 12:12:24 +02001597--------------
1598
1599*Copyright (c) 2020-2023, Arm Limited and Contributors. All rights reserved.*