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