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