1fcb1398fSOlivier DeprezSecure Partition Manager 2fcb1398fSOlivier Deprez************************ 3fcb1398fSOlivier Deprez 4fcb1398fSOlivier Deprez.. contents:: 5fcb1398fSOlivier Deprez 6*9eea92a1SOlivier Deprez.. toctree:: 7*9eea92a1SOlivier Deprez ffa-manifest-binding 8*9eea92a1SOlivier Deprez 9fcb1398fSOlivier DeprezAcronyms 10fcb1398fSOlivier Deprez======== 11fcb1398fSOlivier Deprez 128a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 13b5dd2422SOlivier Deprez| CoT | Chain of Trust | 148a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 154ec3ccb4SMadhukar Pappireddy| DMA | Direct Memory Access | 168a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 17fcb1398fSOlivier Deprez| DTB | Device Tree Blob | 188a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 19fcb1398fSOlivier Deprez| DTS | Device Tree Source | 208a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 21fcb1398fSOlivier Deprez| EC | Execution Context | 228a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 23fcb1398fSOlivier Deprez| FIP | Firmware Image Package | 248a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 258a5bd3cfSOlivier Deprez| FF-A | Firmware Framework for Arm A-profile | 268a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 27fcb1398fSOlivier Deprez| IPA | Intermediate Physical Address | 288a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 29*9eea92a1SOlivier Deprez| JOP | Jump-Oriented Programming | 30*9eea92a1SOlivier Deprez+--------+--------------------------------------+ 31fcb1398fSOlivier Deprez| NWd | Normal World | 328a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 33fcb1398fSOlivier Deprez| ODM | Original Design Manufacturer | 348a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 35fcb1398fSOlivier Deprez| OEM | Original Equipment Manufacturer | 368a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 37fcb1398fSOlivier Deprez| PA | Physical Address | 388a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 39fcb1398fSOlivier Deprez| PE | Processing Element | 408a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 41b5dd2422SOlivier Deprez| PM | Power Management | 428a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 43fcb1398fSOlivier Deprez| PVM | Primary VM | 448a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 45*9eea92a1SOlivier Deprez| ROP | Return-Oriented Programming | 46*9eea92a1SOlivier Deprez+--------+--------------------------------------+ 474ec3ccb4SMadhukar Pappireddy| SMMU | System Memory Management Unit | 488a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 49fcb1398fSOlivier Deprez| SP | Secure Partition | 508a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 51b5dd2422SOlivier Deprez| SPD | Secure Payload Dispatcher | 528a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 53fcb1398fSOlivier Deprez| SPM | Secure Partition Manager | 548a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 55fcb1398fSOlivier Deprez| SPMC | SPM Core | 568a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 57fcb1398fSOlivier Deprez| SPMD | SPM Dispatcher | 588a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 59fcb1398fSOlivier Deprez| SiP | Silicon Provider | 608a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 61fcb1398fSOlivier Deprez| SWd | Secure World | 628a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 63fcb1398fSOlivier Deprez| TLV | Tag-Length-Value | 648a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 65fcb1398fSOlivier Deprez| TOS | Trusted Operating System | 668a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 67fcb1398fSOlivier Deprez| VM | Virtual Machine | 688a5bd3cfSOlivier Deprez+--------+--------------------------------------+ 69fcb1398fSOlivier Deprez 70fcb1398fSOlivier DeprezForeword 71fcb1398fSOlivier Deprez======== 72fcb1398fSOlivier Deprez 73*9eea92a1SOlivier DeprezThree implementations of a Secure Partition Manager co-exist in the TF-A 74*9eea92a1SOlivier Deprezcodebase: 75fcb1398fSOlivier Deprez 76*9eea92a1SOlivier Deprez#. S-EL2 SPMC based on the FF-A specification `[1]`_, enabling virtualization in 77*9eea92a1SOlivier Deprez the secure world, managing multiple S-EL1 or S-EL0 partitions. 78*9eea92a1SOlivier Deprez#. EL3 SPMC based on the FF-A specification, managing a single S-EL1 partition 79*9eea92a1SOlivier Deprez without virtualization in the secure world. 80*9eea92a1SOlivier Deprez#. EL3 SPM based on the MM specification, legacy implementation managing a 81*9eea92a1SOlivier Deprez single S-EL0 partition `[2]`_. 82fcb1398fSOlivier Deprez 83*9eea92a1SOlivier DeprezThese implementations differ in their respective SW architecture and only one 84*9eea92a1SOlivier Deprezcan be selected at build time. This document: 85fcb1398fSOlivier Deprez 86*9eea92a1SOlivier Deprez- describes the implementation from bullet 1. when the SPMC resides at S-EL2. 87fcb1398fSOlivier Deprez- is not an architecture specification and it might provide assumptions 88fcb1398fSOlivier Deprez on sections mandated as implementation-defined in the specification. 89*9eea92a1SOlivier Deprez- covers the implications to TF-A used as a bootloader, and Hafnium used as a 90*9eea92a1SOlivier Deprez reference code base for an S-EL2/SPMC secure firmware on platforms 91*9eea92a1SOlivier Deprez implementing the FEAT_SEL2 architecture extension. 92fcb1398fSOlivier Deprez 93fcb1398fSOlivier DeprezTerminology 94fcb1398fSOlivier Deprez----------- 95fcb1398fSOlivier Deprez 96b5dd2422SOlivier Deprez- The term Hypervisor refers to the NS-EL2 component managing Virtual Machines 97b5dd2422SOlivier Deprez (or partitions) in the normal world. 98b5dd2422SOlivier Deprez- The term SPMC refers to the S-EL2 component managing secure partitions in 99b5dd2422SOlivier Deprez the secure world when the FEAT_SEL2 architecture extension is implemented. 100b5dd2422SOlivier Deprez- Alternatively, SPMC can refer to an S-EL1 component, itself being a secure 101b5dd2422SOlivier Deprez partition and implementing the FF-A ABI on platforms not implementing the 102b5dd2422SOlivier Deprez FEAT_SEL2 architecture extension. 103b5dd2422SOlivier Deprez- The term VM refers to a normal world Virtual Machine managed by an Hypervisor. 104b5dd2422SOlivier Deprez- The term SP refers to a secure world "Virtual Machine" managed by an SPMC. 105fcb1398fSOlivier Deprez 106fcb1398fSOlivier DeprezSupport for legacy platforms 107fcb1398fSOlivier Deprez---------------------------- 108fcb1398fSOlivier Deprez 109*9eea92a1SOlivier DeprezThe SPM is split into a dispatcher and a core component (respectively SPMD and 110*9eea92a1SOlivier DeprezSPMC) residing at different exception levels. To permit the FF-A specification 111*9eea92a1SOlivier Deprezadoption and a smooth migration, the SPMD supports an SPMC residing either at 112*9eea92a1SOlivier DeprezS-EL1 or S-EL2: 113fcb1398fSOlivier Deprez 114*9eea92a1SOlivier Deprez- The SPMD is located at EL3 and mainly relays the FF-A protocol from NWd 115*9eea92a1SOlivier Deprez (Hypervisor or OS kernel) to the SPMC. 116*9eea92a1SOlivier Deprez- The same SPMD component is used for both S-EL1 and S-EL2 SPMC configurations. 117*9eea92a1SOlivier Deprez- The SPMC exception level is a build time choice. 118fcb1398fSOlivier Deprez 119*9eea92a1SOlivier DeprezTF-A supports both cases: 120*9eea92a1SOlivier Deprez 121*9eea92a1SOlivier Deprez- S-EL1 SPMC for platforms not supporting the FEAT_SEL2 architecture 122b5dd2422SOlivier Deprez extension. The SPMD relays the FF-A protocol from EL3 to S-EL1. 123*9eea92a1SOlivier Deprez- S-EL2 SPMC for platforms implementing the FEAT_SEL2 architecture 124b5dd2422SOlivier Deprez extension. The SPMD relays the FF-A protocol from EL3 to S-EL2. 125fcb1398fSOlivier Deprez 126fcb1398fSOlivier DeprezSample reference stack 127fcb1398fSOlivier Deprez====================== 128fcb1398fSOlivier Deprez 129b5dd2422SOlivier DeprezThe following diagram illustrates a possible configuration when the 130b5dd2422SOlivier DeprezFEAT_SEL2 architecture extension is implemented, showing the SPMD 131b5dd2422SOlivier Deprezand SPMC, one or multiple secure partitions, with an optional 132b5dd2422SOlivier DeprezHypervisor: 133fcb1398fSOlivier Deprez 134fcb1398fSOlivier Deprez.. image:: ../resources/diagrams/ff-a-spm-sel2.png 135fcb1398fSOlivier Deprez 136fcb1398fSOlivier DeprezTF-A build options 137fcb1398fSOlivier Deprez================== 138fcb1398fSOlivier Deprez 139b5dd2422SOlivier DeprezThis section explains the TF-A build options involved in building with 140b5dd2422SOlivier Deprezsupport for an FF-A based SPM where the SPMD is located at EL3 and the 1411d63ae4dSMarc BonniciSPMC located at S-EL1, S-EL2 or EL3: 142fcb1398fSOlivier Deprez 143b5dd2422SOlivier Deprez- **SPD=spmd**: this option selects the SPMD component to relay the FF-A 144fcb1398fSOlivier Deprez protocol from NWd to SWd back and forth. It is not possible to 145fcb1398fSOlivier Deprez enable another Secure Payload Dispatcher when this option is chosen. 146b5dd2422SOlivier Deprez- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception 1471d63ae4dSMarc Bonnici level to being at S-EL2. It defaults to enabled (value 1) when 148fcb1398fSOlivier Deprez SPD=spmd is chosen. 1491d63ae4dSMarc Bonnici- **SPMC_AT_EL3**: this option adjusts the SPMC exception level to being 1501d63ae4dSMarc Bonnici at EL3. 151*9eea92a1SOlivier Deprez- If neither ``SPMD_SPM_AT_SEL2`` or ``SPMC_AT_EL3`` are enabled the SPMC 1521d63ae4dSMarc Bonnici exception level is set to S-EL1. 153fcb1398fSOlivier Deprez- **CTX_INCLUDE_EL2_REGS**: this option permits saving (resp. 154fcb1398fSOlivier Deprez restoring) the EL2 system register context before entering (resp. 155b5dd2422SOlivier Deprez after leaving) the SPMC. It is mandatorily enabled when 156b5dd2422SOlivier Deprez ``SPMD_SPM_AT_SEL2`` is enabled. The context save/restore routine 157b5dd2422SOlivier Deprez and exhaustive list of registers is visible at `[4]`_. 158b5dd2422SOlivier Deprez- **SP_LAYOUT_FILE**: this option specifies a text description file 159b5dd2422SOlivier Deprez providing paths to SP binary images and manifests in DTS format 160b5dd2422SOlivier Deprez (see `Describing secure partitions`_). It 161fcb1398fSOlivier Deprez is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple 162*9eea92a1SOlivier Deprez secure partitions are to be loaded by BL2 on behalf of the SPMC. 163fcb1398fSOlivier Deprez 1641d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+ 1651d63ae4dSMarc Bonnici| | CTX_INCLUDE_EL2_REGS | SPMD_SPM_AT_SEL2 | SPMC_AT_EL3 | 1661d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+ 1671d63ae4dSMarc Bonnici| SPMC at S-EL1 | 0 | 0 | 0 | 1681d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+ 1691d63ae4dSMarc Bonnici| SPMC at S-EL2 | 1 | 1 (default when | 0 | 1701d63ae4dSMarc Bonnici| | | SPD=spmd) | | 1711d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+ 1721d63ae4dSMarc Bonnici| SPMC at EL3 | 0 | 0 | 1 | 1731d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+ 174fcb1398fSOlivier Deprez 175fcb1398fSOlivier DeprezOther combinations of such build options either break the build or are not 176fcb1398fSOlivier Deprezsupported. 177fcb1398fSOlivier Deprez 178b5dd2422SOlivier DeprezNotes: 179b5dd2422SOlivier Deprez 180b5dd2422SOlivier Deprez- Only Arm's FVP platform is supported to use with the TF-A reference software 181b5dd2422SOlivier Deprez stack. 182*9eea92a1SOlivier Deprez- When ``SPMD_SPM_AT_SEL2=1``, the reference software stack assumes enablement 183*9eea92a1SOlivier Deprez of FEAT_PAuth, FEAT_BTI and FEAT_MTE architecture extensions. 184b5dd2422SOlivier Deprez- The ``CTX_INCLUDE_EL2_REGS`` option provides the generic support for 185fcb1398fSOlivier Deprez barely saving/restoring EL2 registers from an Arm arch perspective. As such 186fcb1398fSOlivier Deprez it is decoupled from the ``SPD=spmd`` option. 187b5dd2422SOlivier Deprez- BL32 option is re-purposed to specify the SPMC image. It can specify either 188b5dd2422SOlivier Deprez the Hafnium binary path (built for the secure world) or the path to a TEE 189b5dd2422SOlivier Deprez binary implementing FF-A interfaces. 190b5dd2422SOlivier Deprez- BL33 option can specify the TFTF binary or a normal world loader 191*9eea92a1SOlivier Deprez such as U-Boot or the UEFI framework payload. 192fcb1398fSOlivier Deprez 193*9eea92a1SOlivier DeprezSample TF-A build command line when the SPMC is located at S-EL1 194*9eea92a1SOlivier Deprez(e.g. when the FEAT_SEL2 architecture extension is not implemented): 195fcb1398fSOlivier Deprez 196fcb1398fSOlivier Deprez.. code:: shell 197fcb1398fSOlivier Deprez 198fcb1398fSOlivier Deprez make \ 199fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 200fcb1398fSOlivier Deprez SPD=spmd \ 201fcb1398fSOlivier Deprez SPMD_SPM_AT_SEL2=0 \ 202fcb1398fSOlivier Deprez BL32=<path-to-tee-binary> \ 203b5dd2422SOlivier Deprez BL33=<path-to-bl33-binary> \ 204fcb1398fSOlivier Deprez PLAT=fvp \ 205fcb1398fSOlivier Deprez all fip 206fcb1398fSOlivier Deprez 207*9eea92a1SOlivier DeprezSample TF-A build command line when FEAT_SEL2 architecture extension is 208*9eea92a1SOlivier Deprezimplemented and the SPMC is located at S-EL2: 209fcb1398fSOlivier Deprez.. code:: shell 210fcb1398fSOlivier Deprez 211fcb1398fSOlivier Deprez make \ 212fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 213b5dd2422SOlivier Deprez PLAT=fvp \ 214fcb1398fSOlivier Deprez SPD=spmd \ 215fcb1398fSOlivier Deprez CTX_INCLUDE_EL2_REGS=1 \ 216b5dd2422SOlivier Deprez ARM_ARCH_MINOR=5 \ 217b5dd2422SOlivier Deprez BRANCH_PROTECTION=1 \ 218b5dd2422SOlivier Deprez CTX_INCLUDE_PAUTH_REGS=1 \ 219*9eea92a1SOlivier Deprez CTX_INCLUDE_MTE_REGS=1 \ 220b5dd2422SOlivier Deprez BL32=<path-to-hafnium-binary> \ 221b5dd2422SOlivier Deprez BL33=<path-to-bl33-binary> \ 222fcb1398fSOlivier Deprez SP_LAYOUT_FILE=sp_layout.json \ 223fcb1398fSOlivier Deprez all fip 224fcb1398fSOlivier Deprez 225*9eea92a1SOlivier DeprezSample TF-A build command line when FEAT_SEL2 architecture extension is 226*9eea92a1SOlivier Deprezimplemented, the SPMC is located at S-EL2, and enabling secure boot: 227fcb1398fSOlivier Deprez.. code:: shell 228fcb1398fSOlivier Deprez 229fcb1398fSOlivier Deprez make \ 230fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 231b5dd2422SOlivier Deprez PLAT=fvp \ 232fcb1398fSOlivier Deprez SPD=spmd \ 233fcb1398fSOlivier Deprez CTX_INCLUDE_EL2_REGS=1 \ 234b5dd2422SOlivier Deprez ARM_ARCH_MINOR=5 \ 235b5dd2422SOlivier Deprez BRANCH_PROTECTION=1 \ 236b5dd2422SOlivier Deprez CTX_INCLUDE_PAUTH_REGS=1 \ 237*9eea92a1SOlivier Deprez CTX_INCLUDE_MTE_REGS=1 \ 238b5dd2422SOlivier Deprez BL32=<path-to-hafnium-binary> \ 239b5dd2422SOlivier Deprez BL33=<path-to-bl33-binary> \ 240b5dd2422SOlivier Deprez SP_LAYOUT_FILE=sp_layout.json \ 241fcb1398fSOlivier Deprez MBEDTLS_DIR=<path-to-mbedtls-lib> \ 242fcb1398fSOlivier Deprez TRUSTED_BOARD_BOOT=1 \ 243fcb1398fSOlivier Deprez COT=dualroot \ 244fcb1398fSOlivier Deprez ARM_ROTPK_LOCATION=devel_rsa \ 245fcb1398fSOlivier Deprez ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \ 246fcb1398fSOlivier Deprez GENERATE_COT=1 \ 247fcb1398fSOlivier Deprez all fip 248fcb1398fSOlivier Deprez 249*9eea92a1SOlivier DeprezSample TF-A build command line when the SPMC is located at EL3: 2501d63ae4dSMarc Bonnici 2511d63ae4dSMarc Bonnici.. code:: shell 2521d63ae4dSMarc Bonnici 2531d63ae4dSMarc Bonnici make \ 2541d63ae4dSMarc Bonnici CROSS_COMPILE=aarch64-none-elf- \ 2551d63ae4dSMarc Bonnici SPD=spmd \ 2561d63ae4dSMarc Bonnici SPMD_SPM_AT_SEL2=0 \ 2571d63ae4dSMarc Bonnici SPMC_AT_EL3=1 \ 2581d63ae4dSMarc Bonnici BL32=<path-to-tee-binary> \ 2591d63ae4dSMarc Bonnici BL33=<path-to-bl33-binary> \ 2601d63ae4dSMarc Bonnici PLAT=fvp \ 2611d63ae4dSMarc Bonnici all fip 2621d63ae4dSMarc Bonnici 263b5dd2422SOlivier DeprezFVP model invocation 264b5dd2422SOlivier Deprez==================== 265b5dd2422SOlivier Deprez 266b5dd2422SOlivier DeprezThe FVP command line needs the following options to exercise the S-EL2 SPMC: 267b5dd2422SOlivier Deprez 268b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 269b5dd2422SOlivier Deprez| - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, | 270b5dd2422SOlivier Deprez| - cluster1.has_arm_v8-5=1 | and FEAT_BTI. | 271b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 272b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the | 273b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. | 274b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | | 275b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | | 276b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | | 277b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | | 278b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | | 279b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | | 280b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 281b5dd2422SOlivier Deprez| - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. | 282b5dd2422SOlivier Deprez| - cluster1.has_branch_target_exception=1 | | 283b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 284*9eea92a1SOlivier Deprez| - cluster0.has_pointer_authentication=2 | Implements FEAT_PAuth | 285*9eea92a1SOlivier Deprez| - cluster1.has_pointer_authentication=2 | | 286*9eea92a1SOlivier Deprez+---------------------------------------------------+------------------------------------+ 287*9eea92a1SOlivier Deprez| - cluster0.memory_tagging_support_level=2 | Implements FEAT_MTE2 | 288*9eea92a1SOlivier Deprez| - cluster1.memory_tagging_support_level=2 | | 289*9eea92a1SOlivier Deprez| - bp.dram_metadata.is_enabled=1 | | 290b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 291b5dd2422SOlivier Deprez 292b5dd2422SOlivier DeprezSample FVP command line invocation: 293b5dd2422SOlivier Deprez 294b5dd2422SOlivier Deprez.. code:: shell 295b5dd2422SOlivier Deprez 296*9eea92a1SOlivier Deprez <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \ 297b5dd2422SOlivier Deprez -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \ 298b5dd2422SOlivier Deprez -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \ 299b5dd2422SOlivier Deprez -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \ 300b5dd2422SOlivier Deprez -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \ 301b5dd2422SOlivier Deprez -C bp.pl011_uart2.out_file=fvp-uart2.log \ 302*9eea92a1SOlivier Deprez -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 \ 303*9eea92a1SOlivier Deprez -C cluster0.has_pointer_authentication=2 -C cluster1.has_pointer_authentication=2 \ 304*9eea92a1SOlivier Deprez -C cluster0.has_branch_target_exception=1 -C cluster1.has_branch_target_exception=1 \ 305*9eea92a1SOlivier Deprez -C cluster0.memory_tagging_support_level=2 -C cluster1.memory_tagging_support_level=2 \ 306*9eea92a1SOlivier Deprez -C bp.dram_metadata.is_enabled=1 \ 307*9eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \ 308*9eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \ 309*9eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \ 310*9eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 311b5dd2422SOlivier Deprez 312fcb1398fSOlivier DeprezBoot process 313fcb1398fSOlivier Deprez============ 314fcb1398fSOlivier Deprez 315b5dd2422SOlivier DeprezLoading Hafnium and secure partitions in the secure world 316fcb1398fSOlivier Deprez--------------------------------------------------------- 317fcb1398fSOlivier Deprez 318b5dd2422SOlivier DeprezTF-A BL2 is the bootlader for the SPMC and SPs in the secure world. 319fcb1398fSOlivier Deprez 320fcb1398fSOlivier DeprezSPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.). 321b5dd2422SOlivier DeprezThus they are supplied as distinct signed entities within the FIP flash 322b5dd2422SOlivier Deprezimage. The FIP image itself is not signed hence this provides the ability 323b5dd2422SOlivier Deprezto upgrade SPs in the field. 324fcb1398fSOlivier Deprez 325fcb1398fSOlivier DeprezBooting through TF-A 326fcb1398fSOlivier Deprez-------------------- 327fcb1398fSOlivier Deprez 328fcb1398fSOlivier DeprezSP manifests 329fcb1398fSOlivier Deprez~~~~~~~~~~~~ 330fcb1398fSOlivier Deprez 331fcb1398fSOlivier DeprezAn SP manifest describes SP attributes as defined in `[1]`_ 332b5dd2422SOlivier Deprez(partition manifest at virtual FF-A instance) in DTS format. It is 333b5dd2422SOlivier Deprezrepresented as a single file associated with the SP. A sample is 334fcb1398fSOlivier Deprezprovided by `[5]`_. A binding document is provided by `[6]`_. 335fcb1398fSOlivier Deprez 336fcb1398fSOlivier DeprezSecure Partition packages 337fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~ 338fcb1398fSOlivier Deprez 339b5dd2422SOlivier DeprezSecure partitions are bundled as independent package files consisting 340fcb1398fSOlivier Deprezof: 341fcb1398fSOlivier Deprez 342fcb1398fSOlivier Deprez- a header 343fcb1398fSOlivier Deprez- a DTB 344fcb1398fSOlivier Deprez- an image payload 345fcb1398fSOlivier Deprez 346fcb1398fSOlivier DeprezThe header starts with a magic value and offset values to SP DTB and 347fcb1398fSOlivier Deprezimage payload. Each SP package is loaded independently by BL2 loader 348fcb1398fSOlivier Deprezand verified for authenticity and integrity. 349fcb1398fSOlivier Deprez 350b5dd2422SOlivier DeprezThe SP package identified by its UUID (matching FF-A uuid property) is 351b5dd2422SOlivier Deprezinserted as a single entry into the FIP at end of the TF-A build flow 352b5dd2422SOlivier Deprezas shown: 353fcb1398fSOlivier Deprez 354fcb1398fSOlivier Deprez.. code:: shell 355fcb1398fSOlivier Deprez 356fcb1398fSOlivier Deprez Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw" 357fcb1398fSOlivier Deprez EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw" 358fcb1398fSOlivier Deprez Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw" 359fcb1398fSOlivier Deprez Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw" 360fcb1398fSOlivier Deprez HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config" 361fcb1398fSOlivier Deprez TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config" 362fcb1398fSOlivier Deprez SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config" 363fcb1398fSOlivier Deprez TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config" 364fcb1398fSOlivier Deprez NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config" 365fcb1398fSOlivier Deprez B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob" 366fcb1398fSOlivier Deprez D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob" 367fcb1398fSOlivier Deprez 368fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml 369fcb1398fSOlivier Deprez 370b5dd2422SOlivier DeprezDescribing secure partitions 371b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 372fcb1398fSOlivier Deprez 373b5dd2422SOlivier DeprezA json-formatted description file is passed to the build flow specifying paths 374b5dd2422SOlivier Deprezto the SP binary image and associated DTS partition manifest file. The latter 375b5dd2422SOlivier Deprezis processed by the dtc compiler to generate a DTB fed into the SP package. 376573ac373SJ-AlvesOptionally, the partition's json description can contain offsets for both 377573ac373SJ-Alvesthe image and partition manifest within the SP package. Both offsets need to be 378573ac373SJ-Alves4KB aligned, because it is the translation granule supported by Hafnium SPMC. 379573ac373SJ-AlvesThese fields can be leveraged to support SPs with S1 translation granules that 380573ac373SJ-Alvesdiffer from 4KB, and to configure the regions allocated within the SP package, 381573ac373SJ-Alvesas well as to comply with the requirements for the implementation of the boot 382573ac373SJ-Alvesinformation protocol (see `Passing boot data to the SP`_ for more details). In 383573ac373SJ-Alvescase the offsets are absent in their json node, they default to 0x1000 and 384573ac373SJ-Alves0x4000 for the manifest offset and image offset respectively. 385b5dd2422SOlivier DeprezThis file also specifies the SP owner (as an optional field) identifying the 386b5dd2422SOlivier Deprezsigning domain in case of dual root CoT. 387b5dd2422SOlivier DeprezThe SP owner can either be the silicon or the platform provider. The 388b5dd2422SOlivier Deprezcorresponding "owner" field value can either take the value of "SiP" or "Plat". 389b5dd2422SOlivier DeprezIn absence of "owner" field, it defaults to "SiP" owner. 3905ac60ea1SImre KisThe UUID of the partition can be specified as a field in the description file or 3915ac60ea1SImre Kisif it does not exist there the UUID is extracted from the DTS partition 3925ac60ea1SImre Kismanifest. 393fcb1398fSOlivier Deprez 394fcb1398fSOlivier Deprez.. code:: shell 395fcb1398fSOlivier Deprez 396fcb1398fSOlivier Deprez { 397fcb1398fSOlivier Deprez "tee1" : { 398fcb1398fSOlivier Deprez "image": "tee1.bin", 3990901d339SManish Pandey "pm": "tee1.dts", 4005ac60ea1SImre Kis "owner": "SiP", 4015ac60ea1SImre Kis "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f" 402fcb1398fSOlivier Deprez }, 403fcb1398fSOlivier Deprez 404fcb1398fSOlivier Deprez "tee2" : { 405fcb1398fSOlivier Deprez "image": "tee2.bin", 4060901d339SManish Pandey "pm": "tee2.dts", 4070901d339SManish Pandey "owner": "Plat" 408573ac373SJ-Alves }, 409573ac373SJ-Alves 410573ac373SJ-Alves "tee3" : { 411573ac373SJ-Alves "image": { 412573ac373SJ-Alves "file": "tee3.bin", 413573ac373SJ-Alves "offset":"0x2000" 414573ac373SJ-Alves }, 415573ac373SJ-Alves "pm": { 416573ac373SJ-Alves "file": "tee3.dts", 417573ac373SJ-Alves "offset":"0x6000" 418573ac373SJ-Alves }, 419573ac373SJ-Alves "owner": "Plat" 420573ac373SJ-Alves }, 421fcb1398fSOlivier Deprez } 422fcb1398fSOlivier Deprez 423fcb1398fSOlivier DeprezSPMC manifest 424fcb1398fSOlivier Deprez~~~~~~~~~~~~~ 425fcb1398fSOlivier Deprez 426b5dd2422SOlivier DeprezThis manifest contains the SPMC *attribute* node consumed by the SPMD at boot 427b5dd2422SOlivier Depreztime. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves 428b5dd2422SOlivier Depreztwo different cases: 429fcb1398fSOlivier Deprez 430b5dd2422SOlivier Deprez- The SPMC resides at S-EL1: the SPMC manifest is used by the SPMD to setup a 431b5dd2422SOlivier Deprez SP that co-resides with the SPMC and executes at S-EL1 or Secure Supervisor 432b5dd2422SOlivier Deprez mode. 433b5dd2422SOlivier Deprez- The SPMC resides at S-EL2: the SPMC manifest is used by the SPMD to setup 434b5dd2422SOlivier Deprez the environment required by the SPMC to run at S-EL2. SPs run at S-EL1 or 435b5dd2422SOlivier Deprez S-EL0. 436fcb1398fSOlivier Deprez 437fcb1398fSOlivier Deprez.. code:: shell 438fcb1398fSOlivier Deprez 439fcb1398fSOlivier Deprez attribute { 440fcb1398fSOlivier Deprez spmc_id = <0x8000>; 441fcb1398fSOlivier Deprez maj_ver = <0x1>; 442*9eea92a1SOlivier Deprez min_ver = <0x1>; 443fcb1398fSOlivier Deprez exec_state = <0x0>; 444fcb1398fSOlivier Deprez load_address = <0x0 0x6000000>; 445fcb1398fSOlivier Deprez entrypoint = <0x0 0x6000000>; 446fcb1398fSOlivier Deprez binary_size = <0x60000>; 447fcb1398fSOlivier Deprez }; 448fcb1398fSOlivier Deprez 449fcb1398fSOlivier Deprez- *spmc_id* defines the endpoint ID value that SPMC can query through 450fcb1398fSOlivier Deprez ``FFA_ID_GET``. 451fcb1398fSOlivier Deprez- *maj_ver/min_ver*. SPMD checks provided version versus its internal 452fcb1398fSOlivier Deprez version and aborts if not matching. 453b5dd2422SOlivier Deprez- *exec_state* defines the SPMC execution state (AArch64 or AArch32). 454b5dd2422SOlivier Deprez Notice Hafnium used as a SPMC only supports AArch64. 455fcb1398fSOlivier Deprez- *load_address* and *binary_size* are mostly used to verify secondary 456fcb1398fSOlivier Deprez entry points fit into the loaded binary image. 457fcb1398fSOlivier Deprez- *entrypoint* defines the cold boot primary core entry point used by 458b5dd2422SOlivier Deprez SPMD (currently matches ``BL32_BASE``) to enter the SPMC. 459fcb1398fSOlivier Deprez 460fcb1398fSOlivier DeprezOther nodes in the manifest are consumed by Hafnium in the secure world. 461*9eea92a1SOlivier DeprezA sample can be found at `[7]`_: 462fcb1398fSOlivier Deprez 463b5dd2422SOlivier Deprez- The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute 464b5dd2422SOlivier Deprez indicates a FF-A compliant SP. The *load_address* field specifies the load 465*9eea92a1SOlivier Deprez address at which BL2 loaded the SP package. 466b5dd2422SOlivier Deprez- *cpus* node provide the platform topology and allows MPIDR to VMPIDR mapping. 467*9eea92a1SOlivier Deprez Note the primary core is declared first, then secondary cores are declared 468b5dd2422SOlivier Deprez in reverse order. 469b5dd2422SOlivier Deprez- The *memory* node provides platform information on the ranges of memory 470b5dd2422SOlivier Deprez available to the SPMC. 471fcb1398fSOlivier Deprez 472fcb1398fSOlivier DeprezSPMC boot 473fcb1398fSOlivier Deprez~~~~~~~~~ 474fcb1398fSOlivier Deprez 475fcb1398fSOlivier DeprezThe SPMC is loaded by BL2 as the BL32 image. 476fcb1398fSOlivier Deprez 477f2dcf418SOlivier DeprezThe SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_. 478fcb1398fSOlivier Deprez 479fcb1398fSOlivier DeprezBL2 passes the SPMC manifest address to BL31 through a register. 480fcb1398fSOlivier Deprez 481b5dd2422SOlivier DeprezAt boot time, the SPMD in BL31 runs from the primary core, initializes the core 482f2dcf418SOlivier Deprezcontexts and launches the SPMC (BL32) passing the following information through 483f2dcf418SOlivier Deprezregisters: 484f2dcf418SOlivier Deprez 485f2dcf418SOlivier Deprez- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob). 486f2dcf418SOlivier Deprez- X1 holds the ``HW_CONFIG`` physical address. 487f2dcf418SOlivier Deprez- X4 holds the currently running core linear id. 488fcb1398fSOlivier Deprez 489fcb1398fSOlivier DeprezLoading of SPs 490fcb1398fSOlivier Deprez~~~~~~~~~~~~~~ 491fcb1398fSOlivier Deprez 492b5dd2422SOlivier DeprezAt boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted 493b5dd2422SOlivier Deprezbelow: 494b5dd2422SOlivier Deprez 495fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml 496fcb1398fSOlivier Deprez 497b5dd2422SOlivier DeprezNote this boot flow is an implementation sample on Arm's FVP platform. 498b5dd2422SOlivier DeprezPlatforms not using TF-A's *Firmware CONFiguration* framework would adjust to a 499*9eea92a1SOlivier Deprezdifferent boot flow. The flow restricts to a maximum of 8 secure partitions. 500fcb1398fSOlivier Deprez 501fcb1398fSOlivier DeprezSecure boot 502fcb1398fSOlivier Deprez~~~~~~~~~~~ 503fcb1398fSOlivier Deprez 504fcb1398fSOlivier DeprezThe SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC, 505b5dd2422SOlivier DeprezSPMC manifest, secure partitions and verifies them for authenticity and integrity. 506fcb1398fSOlivier DeprezRefer to TBBR specification `[3]`_. 507fcb1398fSOlivier Deprez 508b5dd2422SOlivier DeprezThe multiple-signing domain feature (in current state dual signing domain `[8]`_) allows 509b5dd2422SOlivier Deprezthe use of two root keys namely S-ROTPK and NS-ROTPK: 510fcb1398fSOlivier Deprez 5110901d339SManish Pandey- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK. 512fcb1398fSOlivier Deprez- BL33 may be signed by the OEM using NS-ROTPK. 5130901d339SManish Pandey- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK). 514*9eea92a1SOlivier Deprez- A maximum of 4 partitions can be signed with the S-ROTPK key and 4 partitions 515*9eea92a1SOlivier Deprez signed with the NS-ROTPK key. 516fcb1398fSOlivier Deprez 517b5dd2422SOlivier DeprezAlso refer to `Describing secure partitions`_ and `TF-A build options`_ sections. 518fcb1398fSOlivier Deprez 519fcb1398fSOlivier DeprezHafnium in the secure world 520fcb1398fSOlivier Deprez=========================== 521fcb1398fSOlivier Deprez 522fcb1398fSOlivier DeprezGeneral considerations 523fcb1398fSOlivier Deprez---------------------- 524fcb1398fSOlivier Deprez 525fcb1398fSOlivier DeprezBuild platform for the secure world 526fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 527fcb1398fSOlivier Deprez 528b5dd2422SOlivier DeprezIn the Hafnium reference implementation specific code parts are only relevant to 529b5dd2422SOlivier Deprezthe secure world. Such portions are isolated in architecture specific files 530b5dd2422SOlivier Deprezand/or enclosed by a ``SECURE_WORLD`` macro. 531fcb1398fSOlivier Deprez 532*9eea92a1SOlivier DeprezSecure partitions scheduling 533*9eea92a1SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 534fcb1398fSOlivier Deprez 535*9eea92a1SOlivier DeprezThe FF-A specification `[1]`_ provides two ways to relinquinsh CPU time to 536b5dd2422SOlivier Deprezsecure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of: 537fcb1398fSOlivier Deprez 538b5dd2422SOlivier Deprez- the FFA_MSG_SEND_DIRECT_REQ interface. 539b5dd2422SOlivier Deprez- the FFA_RUN interface. 540fcb1398fSOlivier Deprez 541*9eea92a1SOlivier DeprezAdditionally a secure interrupt can pre-empt the normal world execution and give 542*9eea92a1SOlivier DeprezCPU cycles by transitioning to EL3 and S-EL2. 543*9eea92a1SOlivier Deprez 544fcb1398fSOlivier DeprezPlatform topology 545fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~ 546fcb1398fSOlivier Deprez 547b5dd2422SOlivier DeprezThe *execution-ctx-count* SP manifest field can take the value of one or the 548*9eea92a1SOlivier Depreztotal number of PEs. The FF-A specification `[1]`_ recommends the 549fcb1398fSOlivier Deprezfollowing SP types: 550fcb1398fSOlivier Deprez 551b5dd2422SOlivier Deprez- Pinned MP SPs: an execution context matches a physical PE. MP SPs must 552b5dd2422SOlivier Deprez implement the same number of ECs as the number of PEs in the platform. 553b5dd2422SOlivier Deprez- Migratable UP SPs: a single execution context can run and be migrated on any 554b5dd2422SOlivier Deprez physical PE. Such SP declares a single EC in its SP manifest. An UP SP can 555b5dd2422SOlivier Deprez receive a direct message request originating from any physical core targeting 556b5dd2422SOlivier Deprez the single execution context. 557fcb1398fSOlivier Deprez 558fcb1398fSOlivier DeprezParsing SP partition manifests 559fcb1398fSOlivier Deprez------------------------------ 560fcb1398fSOlivier Deprez 561b5dd2422SOlivier DeprezHafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_. 562b5dd2422SOlivier DeprezNote the current implementation may not implement all optional fields. 563fcb1398fSOlivier Deprez 564b5dd2422SOlivier DeprezThe SP manifest may contain memory and device regions nodes. In case of 565b5dd2422SOlivier Deprezan S-EL2 SPMC: 566fcb1398fSOlivier Deprez 567b5dd2422SOlivier Deprez- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at 568b5dd2422SOlivier Deprez load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can 569b5dd2422SOlivier Deprez specify RX/TX buffer regions in which case it is not necessary for an SP 570b5dd2422SOlivier Deprez to explicitly invoke the ``FFA_RXTX_MAP`` interface. 571b5dd2422SOlivier Deprez- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or 572b5dd2422SOlivier Deprez EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate 573b5dd2422SOlivier Deprez additional resources (e.g. interrupts). 574fcb1398fSOlivier Deprez 575b5dd2422SOlivier DeprezFor the S-EL2 SPMC, base addresses for memory and device region nodes are IPAs 576b5dd2422SOlivier Deprezprovided the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation 577b5dd2422SOlivier Deprezregime. 578fcb1398fSOlivier Deprez 579b5dd2422SOlivier DeprezNote: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the 580b5dd2422SOlivier Deprezsame set of page tables. It is still open whether two sets of page tables shall 581b5dd2422SOlivier Deprezbe provided per SP. The memory region node as defined in the specification 582fcb1398fSOlivier Deprezprovides a memory security attribute hinting to map either to the secure or 583b5dd2422SOlivier Depreznon-secure EL1&0 Stage-2 table if it exists. 584fcb1398fSOlivier Deprez 585fcb1398fSOlivier DeprezPassing boot data to the SP 586fcb1398fSOlivier Deprez--------------------------- 587fcb1398fSOlivier Deprez 588573ac373SJ-AlvesIn `[1]`_ , the section "Boot information protocol" defines a method for passing 589573ac373SJ-Alvesdata to the SPs at boot time. It specifies the format for the boot information 590573ac373SJ-Alvesdescriptor and boot information header structures, which describe the data to be 591573ac373SJ-Alvesexchanged between SPMC and SP. 592573ac373SJ-AlvesThe specification also defines the types of data that can be passed. 593573ac373SJ-AlvesThe aggregate of both the boot info structures and the data itself is designated 594573ac373SJ-Alvesthe boot information blob, and is passed to a Partition as a contiguous memory 595573ac373SJ-Alvesregion. 596fcb1398fSOlivier Deprez 597573ac373SJ-AlvesCurrently, the SPM implementation supports the FDT type which is used to pass the 598573ac373SJ-Alvespartition's DTB manifest. 599573ac373SJ-Alves 600573ac373SJ-AlvesThe region for the boot information blob is allocated through the SP package. 601573ac373SJ-Alves 602573ac373SJ-Alves.. image:: ../resources/diagrams/partition-package.png 603573ac373SJ-Alves 604573ac373SJ-AlvesTo adjust the space allocated for the boot information blob, the json description 605573ac373SJ-Alvesof the SP (see section `Describing secure partitions`_) shall be updated to contain 606573ac373SJ-Alvesthe manifest offset. If no offset is provided the manifest offset defaults to 0x1000, 607573ac373SJ-Alveswhich is the page size in the Hafnium SPMC. 608573ac373SJ-Alves 609573ac373SJ-AlvesThe configuration of the boot protocol is done in the SPs manifest. As defined by 610573ac373SJ-Alvesthe specification, the manifest field 'gp-register-num' configures the GP register 611573ac373SJ-Alveswhich shall be used to pass the address to the partitions boot information blob when 612573ac373SJ-Alvesbooting the partition. 613573ac373SJ-AlvesIn addition, the Hafnium SPMC implementation requires the boot information arguments 614573ac373SJ-Alvesto be listed in a designated DT node: 615573ac373SJ-Alves 616573ac373SJ-Alves.. code:: shell 617573ac373SJ-Alves 618573ac373SJ-Alves boot-info { 619573ac373SJ-Alves compatible = "arm,ffa-manifest-boot-info"; 620573ac373SJ-Alves ffa_manifest; 621573ac373SJ-Alves }; 622573ac373SJ-Alves 623573ac373SJ-AlvesThe whole secure partition package image (see `Secure Partition packages`_) is 624573ac373SJ-Alvesmapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can 625573ac373SJ-Alvesretrieve the address for the boot information blob in the designated GP register, 626573ac373SJ-Alvesprocess the boot information header and descriptors, access its own manifest 627573ac373SJ-AlvesDTB blob and extract its partition manifest properties. 628fcb1398fSOlivier Deprez 629fcb1398fSOlivier DeprezSP Boot order 630fcb1398fSOlivier Deprez------------- 631fcb1398fSOlivier Deprez 632fcb1398fSOlivier DeprezSP manifests provide an optional boot order attribute meant to resolve 633fcb1398fSOlivier Deprezdependencies such as an SP providing a service required to properly boot 634c1ff1791SJ-Alvesanother SP. SPMC boots the SPs in accordance to the boot order attribute, 635c1ff1791SJ-Alveslowest to the highest value. If the boot order attribute is absent from the FF-A 636c1ff1791SJ-Alvesmanifest, the SP is treated as if it had the highest boot order value 637c1ff1791SJ-Alves(i.e. lowest booting priority). 638fcb1398fSOlivier Deprez 639b5dd2422SOlivier DeprezIt is possible for an SP to call into another SP through a direct request 640b5dd2422SOlivier Deprezprovided the latter SP has already been booted. 641b5dd2422SOlivier Deprez 642fcb1398fSOlivier DeprezBoot phases 643fcb1398fSOlivier Deprez----------- 644fcb1398fSOlivier Deprez 645fcb1398fSOlivier DeprezPrimary core boot-up 646fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~ 647fcb1398fSOlivier Deprez 648b5dd2422SOlivier DeprezUpon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical 649b5dd2422SOlivier Deprezcore. The SPMC performs its platform initializations and registers the SPMC 650b5dd2422SOlivier Deprezsecondary physical core entry point physical address by the use of the 65116c1c453SJ-Alves`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD 65216c1c453SJ-Alvesat secure physical FF-A instance). 653fcb1398fSOlivier Deprez 654b5dd2422SOlivier DeprezThe SPMC then creates secure partitions based on SP packages and manifests. Each 655b5dd2422SOlivier Deprezsecure partition is launched in sequence (`SP Boot order`_) on their "primary" 656b5dd2422SOlivier Deprezexecution context. If the primary boot physical core linear id is N, an MP SP is 657b5dd2422SOlivier Deprezstarted using EC[N] on PE[N] (see `Platform topology`_). If the partition is a 658b5dd2422SOlivier DeprezUP SP, it is started using its unique EC0 on PE[N]. 659fcb1398fSOlivier Deprez 660b5dd2422SOlivier DeprezThe SP primary EC (or the EC used when the partition is booted as described 661b5dd2422SOlivier Deprezabove): 662fcb1398fSOlivier Deprez 663b5dd2422SOlivier Deprez- Performs the overall SP boot time initialization, and in case of a MP SP, 664b5dd2422SOlivier Deprez prepares the SP environment for other execution contexts. 665b5dd2422SOlivier Deprez- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure 666b5dd2422SOlivier Deprez virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA 667b5dd2422SOlivier Deprez entry point for other execution contexts. 668b5dd2422SOlivier Deprez- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or 669b5dd2422SOlivier Deprez ``FFA_ERROR`` in case of failure. 670fcb1398fSOlivier Deprez 671b5dd2422SOlivier DeprezSecondary cores boot-up 672b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~ 673fcb1398fSOlivier Deprez 674b5dd2422SOlivier DeprezOnce the system is started and NWd brought up, a secondary physical core is 675b5dd2422SOlivier Deprezwoken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism 676b5dd2422SOlivier Deprezcalls into the SPMD on the newly woken up physical core. Then the SPMC is 677b5dd2422SOlivier Deprezentered at the secondary physical core entry point. 678fcb1398fSOlivier Deprez 679b5dd2422SOlivier DeprezIn the current implementation, the first SP is resumed on the coresponding EC 680b5dd2422SOlivier Deprez(the virtual CPU which matches the physical core). The implication is that the 681b5dd2422SOlivier Deprezfirst SP must be a MP SP. 682fcb1398fSOlivier Deprez 683b5dd2422SOlivier DeprezIn a linux based system, once secure and normal worlds are booted but prior to 684b5dd2422SOlivier Depreza NWd FF-A driver has been loaded: 685fcb1398fSOlivier Deprez 686b5dd2422SOlivier Deprez- The first SP has initialized all its ECs in response to primary core boot up 687b5dd2422SOlivier Deprez (at system initialization) and secondary core boot up (as a result of linux 688b5dd2422SOlivier Deprez invoking PSCI_CPU_ON for all secondary cores). 689b5dd2422SOlivier Deprez- Other SPs have their first execution context initialized as a result of secure 690b5dd2422SOlivier Deprez world initialization on the primary boot core. Other ECs for those SPs have to 691b5dd2422SOlivier Deprez be run first through ffa_run to complete their initialization (which results 692b5dd2422SOlivier Deprez in the EC completing with FFA_MSG_WAIT). 693fcb1398fSOlivier Deprez 694b5dd2422SOlivier DeprezRefer to `Power management`_ for further details. 695fcb1398fSOlivier Deprez 69616c1c453SJ-AlvesNotifications 69716c1c453SJ-Alves------------- 69816c1c453SJ-Alves 69916c1c453SJ-AlvesThe FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous 70016c1c453SJ-Alvescommunication mechanism with non-blocking semantics. It allows for one FF-A 70116c1c453SJ-Alvesendpoint to signal another for service provision, without hindering its current 70216c1c453SJ-Alvesprogress. 70316c1c453SJ-Alves 70416c1c453SJ-AlvesHafnium currently supports 64 notifications. The IDs of each notification define 70516c1c453SJ-Alvesa position in a 64-bit bitmap. 70616c1c453SJ-Alves 70716c1c453SJ-AlvesThe signaling of notifications can interchangeably happen between NWd and SWd 70816c1c453SJ-AlvesFF-A endpoints. 70916c1c453SJ-Alves 71016c1c453SJ-AlvesThe SPMC is in charge of managing notifications from SPs to SPs, from SPs to 71116c1c453SJ-AlvesVMs, and from VMs to SPs. An hypervisor component would only manage 71216c1c453SJ-Alvesnotifications from VMs to VMs. Given the SPMC has no visibility of the endpoints 71316c1c453SJ-Alvesdeployed in NWd, the Hypervisor or OS kernel must invoke the interface 71416c1c453SJ-AlvesFFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A 71516c1c453SJ-Alvesendpoint in the NWd that supports it. 71616c1c453SJ-Alves 71716c1c453SJ-AlvesA sender can signal notifications once the receiver has provided it with 71816c1c453SJ-Alvespermissions. Permissions are provided by invoking the interface 71916c1c453SJ-AlvesFFA_NOTIFICATION_BIND. 72016c1c453SJ-Alves 72116c1c453SJ-AlvesNotifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth 72216c1c453SJ-Alvesthey are considered to be in a pending sate. The receiver can retrieve its 72316c1c453SJ-Alvespending notifications invoking FFA_NOTIFICATION_GET, which, from that moment, 72416c1c453SJ-Alvesare considered to be handled. 72516c1c453SJ-Alves 72616c1c453SJ-AlvesPer the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler 72716c1c453SJ-Alvesthat is in charge of donating CPU cycles for notifications handling. The 72816c1c453SJ-AlvesFF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about 72916c1c453SJ-Alveswhich FF-A endpoints have pending notifications. The receiver scheduler is 73016c1c453SJ-Alvescalled and informed by the FF-A driver, and it should allocate CPU cycles to the 73116c1c453SJ-Alvesreceiver. 73216c1c453SJ-Alves 73316c1c453SJ-AlvesThere are two types of notifications supported: 734*9eea92a1SOlivier Deprez 73516c1c453SJ-Alves- Global, which are targeted to a FF-A endpoint and can be handled within any of 73616c1c453SJ-Alves its execution contexts, as determined by the scheduler of the system. 73716c1c453SJ-Alves- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a 73816c1c453SJ-Alves a specific execution context, as determined by the sender. 73916c1c453SJ-Alves 74016c1c453SJ-AlvesThe type of a notification is set when invoking FFA_NOTIFICATION_BIND to give 74116c1c453SJ-Alvespermissions to the sender. 74216c1c453SJ-Alves 74316c1c453SJ-AlvesNotification signaling resorts to two interrupts: 744*9eea92a1SOlivier Deprez 745*9eea92a1SOlivier Deprez- Schedule Receiver Interrupt: non-secure physical interrupt to be handled by 746*9eea92a1SOlivier Deprez the FF-A driver within the receiver scheduler. At initialization the SPMC 747*9eea92a1SOlivier Deprez donates a SGI ID chosen from the secure SGI IDs range and configures it as 748*9eea92a1SOlivier Deprez non-secure. The SPMC triggers this SGI on the currently running core when 749*9eea92a1SOlivier Deprez there are pending notifications, and the respective receivers need CPU cycles 750*9eea92a1SOlivier Deprez to handle them. 751*9eea92a1SOlivier Deprez- Notifications Pending Interrupt: virtual interrupt to be handled by the 752*9eea92a1SOlivier Deprez receiver of the notification. Set when there are pending notifications for the 753*9eea92a1SOlivier Deprez given secure partition. The NPI is pended when the NWd relinquishes CPU cycles 754*9eea92a1SOlivier Deprez to an SP. 75516c1c453SJ-Alves 75616c1c453SJ-AlvesThe notifications receipt support is enabled in the partition FF-A manifest. 75716c1c453SJ-Alves 758fcb1398fSOlivier DeprezMandatory interfaces 759fcb1398fSOlivier Deprez-------------------- 760fcb1398fSOlivier Deprez 761b5dd2422SOlivier DeprezThe following interfaces are exposed to SPs: 762fcb1398fSOlivier Deprez 763fcb1398fSOlivier Deprez- ``FFA_VERSION`` 764fcb1398fSOlivier Deprez- ``FFA_FEATURES`` 765fcb1398fSOlivier Deprez- ``FFA_RX_RELEASE`` 766fcb1398fSOlivier Deprez- ``FFA_RXTX_MAP`` 76716c1c453SJ-Alves- ``FFA_RXTX_UNMAP`` 768fcb1398fSOlivier Deprez- ``FFA_PARTITION_INFO_GET`` 769fcb1398fSOlivier Deprez- ``FFA_ID_GET`` 770b5dd2422SOlivier Deprez- ``FFA_MSG_WAIT`` 771b5dd2422SOlivier Deprez- ``FFA_MSG_SEND_DIRECT_REQ`` 772b5dd2422SOlivier Deprez- ``FFA_MSG_SEND_DIRECT_RESP`` 773b5dd2422SOlivier Deprez- ``FFA_MEM_DONATE`` 774b5dd2422SOlivier Deprez- ``FFA_MEM_LEND`` 775b5dd2422SOlivier Deprez- ``FFA_MEM_SHARE`` 776b5dd2422SOlivier Deprez- ``FFA_MEM_RETRIEVE_REQ`` 777b5dd2422SOlivier Deprez- ``FFA_MEM_RETRIEVE_RESP`` 778b5dd2422SOlivier Deprez- ``FFA_MEM_RELINQUISH`` 779*9eea92a1SOlivier Deprez- ``FFA_MEM_FRAG_RX`` 780*9eea92a1SOlivier Deprez- ``FFA_MEM_FRAG_TX`` 781b5dd2422SOlivier Deprez- ``FFA_MEM_RECLAIM`` 782*9eea92a1SOlivier Deprez- ``FFA_RUN`` 78316c1c453SJ-Alves 784*9eea92a1SOlivier DeprezAs part of the FF-A v1.1 support, the following interfaces were added: 78516c1c453SJ-Alves 78616c1c453SJ-Alves - ``FFA_NOTIFICATION_BITMAP_CREATE`` 78716c1c453SJ-Alves - ``FFA_NOTIFICATION_BITMAP_DESTROY`` 78816c1c453SJ-Alves - ``FFA_NOTIFICATION_BIND`` 78916c1c453SJ-Alves - ``FFA_NOTIFICATION_UNBIND`` 79016c1c453SJ-Alves - ``FFA_NOTIFICATION_SET`` 79116c1c453SJ-Alves - ``FFA_NOTIFICATION_GET`` 79216c1c453SJ-Alves - ``FFA_NOTIFICATION_INFO_GET`` 79316c1c453SJ-Alves - ``FFA_SPM_ID_GET`` 794b5dd2422SOlivier Deprez - ``FFA_SECONDARY_EP_REGISTER`` 795*9eea92a1SOlivier Deprez - ``FFA_MEM_PERM_GET`` 796*9eea92a1SOlivier Deprez - ``FFA_MEM_PERM_SET`` 797fcb1398fSOlivier Deprez 798fcb1398fSOlivier DeprezFFA_VERSION 799fcb1398fSOlivier Deprez~~~~~~~~~~~ 800fcb1398fSOlivier Deprez 801b5dd2422SOlivier Deprez``FFA_VERSION`` requires a *requested_version* parameter from the caller. 802b5dd2422SOlivier DeprezThe returned value depends on the caller: 803fcb1398fSOlivier Deprez 804b5dd2422SOlivier Deprez- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version 805b5dd2422SOlivier Deprez specified in the SPMC manifest. 806b5dd2422SOlivier Deprez- SP: the SPMC returns its own implemented version. 807b5dd2422SOlivier Deprez- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version. 808fcb1398fSOlivier Deprez 809fcb1398fSOlivier DeprezFFA_FEATURES 810fcb1398fSOlivier Deprez~~~~~~~~~~~~ 811fcb1398fSOlivier Deprez 812b5dd2422SOlivier DeprezFF-A features supported by the SPMC may be discovered by secure partitions at 813b5dd2422SOlivier Deprezboot (that is prior to NWd is booted) or run-time. 814fcb1398fSOlivier Deprez 815b5dd2422SOlivier DeprezThe SPMC calling FFA_FEATURES at secure physical FF-A instance always get 816b5dd2422SOlivier DeprezFFA_SUCCESS from the SPMD. 817b5dd2422SOlivier Deprez 818b5dd2422SOlivier DeprezThe request made by an Hypervisor or OS kernel is forwarded to the SPMC and 819b5dd2422SOlivier Deprezthe response relayed back to the NWd. 820fcb1398fSOlivier Deprez 821fcb1398fSOlivier DeprezFFA_RXTX_MAP/FFA_RXTX_UNMAP 822fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~ 823fcb1398fSOlivier Deprez 824b5dd2422SOlivier DeprezWhen invoked from a secure partition FFA_RXTX_MAP maps the provided send and 825b5dd2422SOlivier Deprezreceive buffers described by their IPAs to the SP EL1&0 Stage-2 translation 826b5dd2422SOlivier Deprezregime as secure buffers in the MMU descriptors. 827fcb1398fSOlivier Deprez 828b5dd2422SOlivier DeprezWhen invoked from the Hypervisor or OS kernel, the buffers are mapped into the 829b5dd2422SOlivier DeprezSPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU 830b5dd2422SOlivier Deprezdescriptors. 831b5dd2422SOlivier Deprez 83216c1c453SJ-AlvesThe FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the 83316c1c453SJ-Alvescaller, either it being the Hypervisor or OS kernel, as well as a secure 83416c1c453SJ-Alvespartition. 835fcb1398fSOlivier Deprez 836fcb1398fSOlivier DeprezFFA_PARTITION_INFO_GET 837fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~ 838fcb1398fSOlivier Deprez 839b5dd2422SOlivier DeprezPartition info get call can originate: 840fcb1398fSOlivier Deprez 841b5dd2422SOlivier Deprez- from SP to SPMC 842b5dd2422SOlivier Deprez- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD. 843fcb1398fSOlivier Deprez 844fcb1398fSOlivier DeprezFFA_ID_GET 845fcb1398fSOlivier Deprez~~~~~~~~~~ 846fcb1398fSOlivier Deprez 847b5dd2422SOlivier DeprezThe FF-A id space is split into a non-secure space and secure space: 848b5dd2422SOlivier Deprez 849b5dd2422SOlivier Deprez- FF-A ID with bit 15 clear relates to VMs. 850b5dd2422SOlivier Deprez- FF-A ID with bit 15 set related to SPs. 851b5dd2422SOlivier Deprez- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD 852b5dd2422SOlivier Deprez and SPMC. 853b5dd2422SOlivier Deprez 854fcb1398fSOlivier DeprezThe SPMD returns: 855fcb1398fSOlivier Deprez 856b5dd2422SOlivier Deprez- The default zero value on invocation from the Hypervisor. 857fcb1398fSOlivier Deprez- The ``spmc_id`` value specified in the SPMC manifest on invocation from 858fcb1398fSOlivier Deprez the SPMC (see `SPMC manifest`_) 859fcb1398fSOlivier Deprez 860b5dd2422SOlivier DeprezThis convention helps the SPMC to determine the origin and destination worlds in 861b5dd2422SOlivier Deprezan FF-A ABI invocation. In particular the SPMC shall filter unauthorized 862fcb1398fSOlivier Depreztransactions in its world switch routine. It must not be permitted for a VM to 863b5dd2422SOlivier Deprezuse a secure FF-A ID as origin world by spoofing: 864fcb1398fSOlivier Deprez 865b5dd2422SOlivier Deprez- A VM-to-SP direct request/response shall set the origin world to be non-secure 866b5dd2422SOlivier Deprez (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15 867fcb1398fSOlivier Deprez set). 868b5dd2422SOlivier Deprez- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15 869b5dd2422SOlivier Deprez for both origin and destination IDs. 870fcb1398fSOlivier Deprez 871fcb1398fSOlivier DeprezAn incoming direct message request arriving at SPMD from NWd is forwarded to 872fcb1398fSOlivier DeprezSPMC without a specific check. The SPMC is resumed through eret and "knows" the 873fcb1398fSOlivier Deprezmessage is coming from normal world in this specific code path. Thus the origin 874b5dd2422SOlivier Deprezendpoint ID must be checked by SPMC for being a normal world ID. 875fcb1398fSOlivier Deprez 876fcb1398fSOlivier DeprezAn SP sending a direct message request must have bit 15 set in its origin 877b5dd2422SOlivier Deprezendpoint ID and this can be checked by the SPMC when the SP invokes the ABI. 878fcb1398fSOlivier Deprez 879fcb1398fSOlivier DeprezThe SPMC shall reject the direct message if the claimed world in origin endpoint 880b5dd2422SOlivier DeprezID is not consistent: 881fcb1398fSOlivier Deprez 882b5dd2422SOlivier Deprez- It is either forwarded by SPMD and thus origin endpoint ID must be a "normal 883b5dd2422SOlivier Deprez world ID", 884b5dd2422SOlivier Deprez- or initiated by an SP and thus origin endpoint ID must be a "secure world ID". 885fcb1398fSOlivier Deprez 886fcb1398fSOlivier Deprez 887b5dd2422SOlivier DeprezFFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP 888b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 889fcb1398fSOlivier Deprez 890b5dd2422SOlivier DeprezThis is a mandatory interface for secure partitions consisting in direct request 891b5dd2422SOlivier Deprezand responses with the following rules: 892fcb1398fSOlivier Deprez 893b5dd2422SOlivier Deprez- An SP can send a direct request to another SP. 894b5dd2422SOlivier Deprez- An SP can receive a direct request from another SP. 895b5dd2422SOlivier Deprez- An SP can send a direct response to another SP. 896b5dd2422SOlivier Deprez- An SP cannot send a direct request to an Hypervisor or OS kernel. 897b5dd2422SOlivier Deprez- An Hypervisor or OS kernel can send a direct request to an SP. 898b5dd2422SOlivier Deprez- An SP can send a direct response to an Hypervisor or OS kernel. 899fcb1398fSOlivier Deprez 90016c1c453SJ-AlvesFFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY 90116c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 90216c1c453SJ-Alves 90316c1c453SJ-AlvesThe secure partitions notifications bitmap are statically allocated by the SPMC. 90416c1c453SJ-AlvesHence, this interface is not to be issued by secure partitions. 90516c1c453SJ-Alves 90616c1c453SJ-AlvesAt initialization, the SPMC is not aware of VMs/partitions deployed in the 90716c1c453SJ-Alvesnormal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC 90816c1c453SJ-Alvesto be prepared to handle notifications for the provided VM ID. 90916c1c453SJ-Alves 91016c1c453SJ-AlvesFFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND 91116c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 91216c1c453SJ-Alves 91316c1c453SJ-AlvesPair of interfaces to manage permissions to signal notifications. Prior to 91416c1c453SJ-Alveshandling notifications, an FF-A endpoint must allow a given sender to signal a 91516c1c453SJ-Alvesbitmap of notifications. 91616c1c453SJ-Alves 91716c1c453SJ-AlvesIf the receiver doesn't have notification support enabled in its FF-A manifest, 91816c1c453SJ-Alvesit won't be able to bind notifications, hence forbidding it to receive any 91916c1c453SJ-Alvesnotifications. 92016c1c453SJ-Alves 92116c1c453SJ-AlvesFFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET 92216c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 92316c1c453SJ-Alves 924*9eea92a1SOlivier DeprezFFA_NOTIFICATION_GET retrieves all pending global notifications and 925*9eea92a1SOlivier Deprezper-vCPU notifications targeted to the current vCPU. 92616c1c453SJ-Alves 927*9eea92a1SOlivier DeprezHafnium maintains a global count of pending notifications which gets incremented 928*9eea92a1SOlivier Deprezand decremented when handling FFA_NOTIFICATION_SET and FFA_NOTIFICATION_GET 929*9eea92a1SOlivier Deprezrespectively. A delayed SRI is triggered if the counter is non-zero when the 930*9eea92a1SOlivier DeprezSPMC returns to normal world. 93116c1c453SJ-Alves 93216c1c453SJ-AlvesFFA_NOTIFICATION_INFO_GET 93316c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~ 93416c1c453SJ-Alves 935*9eea92a1SOlivier DeprezHafnium maintains a global count of pending notifications whose information 936*9eea92a1SOlivier Deprezhas been retrieved by this interface. The count is incremented and decremented 937*9eea92a1SOlivier Deprezwhen handling FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET respectively. 938*9eea92a1SOlivier DeprezIt also tracks notifications whose information has been retrieved individually, 93916c1c453SJ-Alvessuch that it avoids duplicating returned information for subsequent calls to 94016c1c453SJ-AlvesFFA_NOTIFICATION_INFO_GET. For each notification, this state information is 94116c1c453SJ-Alvesreset when receiver called FFA_NOTIFICATION_GET to retrieve them. 94216c1c453SJ-Alves 94316c1c453SJ-AlvesFFA_SPM_ID_GET 94416c1c453SJ-Alves~~~~~~~~~~~~~~ 94516c1c453SJ-Alves 946*9eea92a1SOlivier DeprezReturns the FF-A ID allocated to an SPM component which can be one of SPMD 947*9eea92a1SOlivier Deprezor SPMC. 94816c1c453SJ-Alves 949*9eea92a1SOlivier DeprezAt initialization, the SPMC queries the SPMD for the SPMC ID, using the 950*9eea92a1SOlivier DeprezFFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using 951*9eea92a1SOlivier Deprezthe FFA_SPM_ID_GET interface at the secure physical FF-A instance. 95216c1c453SJ-Alves 953*9eea92a1SOlivier DeprezSecure partitions call this interface at the virtual FF-A instance, to which 954*9eea92a1SOlivier Deprezthe SPMC returns the priorly retrieved SPMC ID. 95516c1c453SJ-Alves 956*9eea92a1SOlivier DeprezThe Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the 957*9eea92a1SOlivier DeprezSPMD, which returns the SPMC ID. 95816c1c453SJ-Alves 95916c1c453SJ-AlvesFFA_SECONDARY_EP_REGISTER 96016c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~ 96116c1c453SJ-Alves 96216c1c453SJ-AlvesWhen the SPMC boots, all secure partitions are initialized on their primary 96316c1c453SJ-AlvesExecution Context. 96416c1c453SJ-Alves 965*9eea92a1SOlivier DeprezThe FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition 96616c1c453SJ-Alvesfrom its first execution context, to provide the entry point address for 96716c1c453SJ-Alvessecondary execution contexts. 96816c1c453SJ-Alves 96916c1c453SJ-AlvesA secondary EC is first resumed either upon invocation of PSCI_CPU_ON from 97016c1c453SJ-Alvesthe NWd or by invocation of FFA_RUN. 97116c1c453SJ-Alves 972b5dd2422SOlivier DeprezSPMC-SPMD direct requests/responses 973b5dd2422SOlivier Deprez----------------------------------- 974fcb1398fSOlivier Deprez 975b5dd2422SOlivier DeprezImplementation-defined FF-A IDs are allocated to the SPMC and SPMD. 976b5dd2422SOlivier DeprezUsing those IDs in source/destination fields of a direct request/response 977b5dd2422SOlivier Deprezpermits SPMD to SPMC communication and either way. 978fcb1398fSOlivier Deprez 979b5dd2422SOlivier Deprez- SPMC to SPMD direct request/response uses SMC conduit. 980b5dd2422SOlivier Deprez- SPMD to SPMC direct request/response uses ERET conduit. 981fcb1398fSOlivier Deprez 982*9eea92a1SOlivier DeprezThis is used in particular to convey power management messages. 983*9eea92a1SOlivier Deprez 984b5dd2422SOlivier DeprezPE MMU configuration 985b5dd2422SOlivier Deprez-------------------- 986fcb1398fSOlivier Deprez 987*9eea92a1SOlivier DeprezWith secure virtualization enabled (``HCR_EL2.VM = 1``) and for S-EL1 988*9eea92a1SOlivier Deprezpartitions, two IPA spaces (secure and non-secure) are output from the 989*9eea92a1SOlivier Deprezsecure EL1&0 Stage-1 translation. 990*9eea92a1SOlivier DeprezThe EL1&0 Stage-2 translation hardware is fed by: 991fcb1398fSOlivier Deprez 992*9eea92a1SOlivier Deprez- A secure IPA when the SP EL1&0 Stage-1 MMU is disabled. 993*9eea92a1SOlivier Deprez- One of secure or non-secure IPA when the secure EL1&0 Stage-1 MMU is enabled. 994fcb1398fSOlivier Deprez 995b5dd2422SOlivier Deprez``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the 996*9eea92a1SOlivier DeprezNS/S IPA translations. The following controls are set up: 997*9eea92a1SOlivier Deprez``VSTCR_EL2.SW = 0`` , ``VSTCR_EL2.SA = 0``, ``VTCR_EL2.NSW = 0``, 998*9eea92a1SOlivier Deprez``VTCR_EL2.NSA = 1``: 999fcb1398fSOlivier Deprez 1000b5dd2422SOlivier Deprez- Stage-2 translations for the NS IPA space access the NS PA space. 1001b5dd2422SOlivier Deprez- Stage-2 translation table walks for the NS IPA space are to the secure PA space. 1002fcb1398fSOlivier Deprez 1003*9eea92a1SOlivier DeprezSecure and non-secure IPA regions (rooted to by ``VTTBR_EL2`` and ``VSTTBR_EL2``) 1004*9eea92a1SOlivier Deprezuse the same set of Stage-2 page tables within a SP. 1005*9eea92a1SOlivier Deprez 1006*9eea92a1SOlivier DeprezThe ``VTCR_EL2/VSTCR_EL2/VTTBR_EL2/VSTTBR_EL2`` virtual address space 1007*9eea92a1SOlivier Deprezconfiguration is made part of a vCPU context. 1008*9eea92a1SOlivier Deprez 1009*9eea92a1SOlivier DeprezFor S-EL0 partitions with VHE enabled, a single secure EL2&0 Stage-1 translation 1010*9eea92a1SOlivier Deprezregime is used for both Hafnium and the partition. 1011fcb1398fSOlivier Deprez 1012fcb1398fSOlivier DeprezInterrupt management 1013fcb1398fSOlivier Deprez-------------------- 1014fcb1398fSOlivier Deprez 1015b5dd2422SOlivier DeprezGIC ownership 1016b5dd2422SOlivier Deprez~~~~~~~~~~~~~ 1017fcb1398fSOlivier Deprez 1018b5dd2422SOlivier DeprezThe SPMC owns the GIC configuration. Secure and non-secure interrupts are 1019b5dd2422SOlivier Depreztrapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt 1020b5dd2422SOlivier DeprezIDs based on SP manifests. The SPMC acknowledges physical interrupts and injects 1021b5dd2422SOlivier Deprezvirtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP. 1022fcb1398fSOlivier Deprez 1023b5dd2422SOlivier DeprezNon-secure interrupt handling 1024b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1025fcb1398fSOlivier Deprez 1026b5dd2422SOlivier DeprezThe following illustrate the scenarios of non secure physical interrupts trapped 1027b5dd2422SOlivier Deprezby the SPMC: 1028fcb1398fSOlivier Deprez 1029b5dd2422SOlivier Deprez- The SP handles a managed exit operation: 1030b5dd2422SOlivier Deprez 1031b5dd2422SOlivier Deprez.. image:: ../resources/diagrams/ffa-ns-interrupt-handling-managed-exit.png 1032b5dd2422SOlivier Deprez 1033b5dd2422SOlivier Deprez- The SP is pre-empted without managed exit: 1034b5dd2422SOlivier Deprez 1035b5dd2422SOlivier Deprez.. image:: ../resources/diagrams/ffa-ns-interrupt-handling-sp-preemption.png 1036b5dd2422SOlivier Deprez 1037b5dd2422SOlivier DeprezSecure interrupt handling 103852558e08SMadhukar Pappireddy------------------------- 1039b5dd2422SOlivier Deprez 104052558e08SMadhukar PappireddyThis section documents the support implemented for secure interrupt handling in 104152558e08SMadhukar PappireddySPMC as per the guidance provided by FF-A v1.1 Beta0 specification. 104252558e08SMadhukar PappireddyThe following assumptions are made about the system configuration: 104352558e08SMadhukar Pappireddy 104452558e08SMadhukar Pappireddy - In the current implementation, S-EL1 SPs are expected to use the para 104552558e08SMadhukar Pappireddy virtualized ABIs for interrupt management rather than accessing virtual GIC 104652558e08SMadhukar Pappireddy interface. 104752558e08SMadhukar Pappireddy - Unless explicitly stated otherwise, this support is applicable only for 104852558e08SMadhukar Pappireddy S-EL1 SPs managed by SPMC. 104952558e08SMadhukar Pappireddy - Secure interrupts are configured as G1S or G0 interrupts. 105052558e08SMadhukar Pappireddy - All physical interrupts are routed to SPMC when running a secure partition 105152558e08SMadhukar Pappireddy execution context. 105252558e08SMadhukar Pappireddy 105352558e08SMadhukar PappireddyA physical secure interrupt could preempt normal world execution. Moreover, when 105452558e08SMadhukar Pappireddythe execution is in secure world, it is highly likely that the target of a 105552558e08SMadhukar Pappireddysecure interrupt is not the currently running execution context of an SP. It 105652558e08SMadhukar Pappireddycould be targeted to another FF-A component. Consequently, secure interrupt 105752558e08SMadhukar Pappireddymanagement depends on the state of the target execution context of the SP that 105852558e08SMadhukar Pappireddyis responsible for handling the interrupt. Hence, the spec provides guidance on 105952558e08SMadhukar Pappireddyhow to signal start and completion of secure interrupt handling as discussed in 106052558e08SMadhukar Pappireddyfurther sections. 106152558e08SMadhukar Pappireddy 106252558e08SMadhukar PappireddySecure interrupt signaling mechanisms 106352558e08SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 106452558e08SMadhukar Pappireddy 106552558e08SMadhukar PappireddySignaling refers to the mechanisms used by SPMC to indicate to the SP execution 106652558e08SMadhukar Pappireddycontext that it has a pending virtual interrupt and to further run the SP 106752558e08SMadhukar Pappireddyexecution context, such that it can handle the virtual interrupt. SPMC uses 106852558e08SMadhukar Pappireddyeither the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling 106952558e08SMadhukar Pappireddyto S-EL1 SPs. When normal world execution is preempted by a secure interrupt, 107052558e08SMadhukar Pappireddythe SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC 107152558e08SMadhukar Pappireddyrunning in S-EL2. 107252558e08SMadhukar Pappireddy 107352558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 107452558e08SMadhukar Pappireddy| SP State | Conduit | Interface and | Description | 107552558e08SMadhukar Pappireddy| | | parameters | | 107652558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 107752558e08SMadhukar Pappireddy| WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending | 107852558e08SMadhukar Pappireddy| | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and | 107952558e08SMadhukar Pappireddy| | | | resumes execution context of SP | 108052558e08SMadhukar Pappireddy| | | | through ERET. | 108152558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 108252558e08SMadhukar Pappireddy| BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt | 108352558e08SMadhukar Pappireddy| | vIRQ | | is pending. It pends vIRQ signal and | 108452558e08SMadhukar Pappireddy| | | | resumes execution context of SP | 108552558e08SMadhukar Pappireddy| | | | through ERET. | 108652558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 108752558e08SMadhukar Pappireddy| PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does | 108852558e08SMadhukar Pappireddy| | | | not resume execution context of SP. | 108952558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 109052558e08SMadhukar Pappireddy| RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes| 109152558e08SMadhukar Pappireddy| | vIRQ | | execution context of SP through ERET. | 109252558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 109352558e08SMadhukar Pappireddy 109452558e08SMadhukar PappireddySecure interrupt completion mechanisms 109552558e08SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 109652558e08SMadhukar Pappireddy 109752558e08SMadhukar PappireddyA SP signals secure interrupt handling completion to the SPMC through the 109852558e08SMadhukar Pappireddyfollowing mechanisms: 109952558e08SMadhukar Pappireddy 110052558e08SMadhukar Pappireddy - ``FFA_MSG_WAIT`` ABI if it was in WAITING state. 110152558e08SMadhukar Pappireddy - ``FFA_RUN`` ABI if its was in BLOCKED state. 110252558e08SMadhukar Pappireddy 110352558e08SMadhukar PappireddyIn the current implementation, S-EL1 SPs use para-virtualized HVC interface 110452558e08SMadhukar Pappireddyimplemented by SPMC to perform priority drop and interrupt deactivation (we 110552558e08SMadhukar Pappireddyassume EOImode = 0, i.e. priority drop and deactivation are done together). 110652558e08SMadhukar Pappireddy 110752558e08SMadhukar PappireddyIf normal world execution was preempted by secure interrupt, SPMC uses 110852558e08SMadhukar PappireddyFFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling 110952558e08SMadhukar Pappireddyand further return execution to normal world. If the current SP execution 111052558e08SMadhukar Pappireddycontext was preempted by a secure interrupt to be handled by execution context 111152558e08SMadhukar Pappireddyof target SP, SPMC resumes current SP after signal completion by target SP 111252558e08SMadhukar Pappireddyexecution context. 111352558e08SMadhukar Pappireddy 111452558e08SMadhukar PappireddyAn action is broadly a set of steps taken by the SPMC in response to a physical 111552558e08SMadhukar Pappireddyinterrupt. In order to simplify the design, the current version of secure 111652558e08SMadhukar Pappireddyinterrupt management support in SPMC (Hafnium) does not fully implement the 111752558e08SMadhukar PappireddyScheduling models and Partition runtime models. However, the current 111852558e08SMadhukar Pappireddyimplementation loosely maps to the following actions that are legally allowed 111952558e08SMadhukar Pappireddyby the specification. Please refer to the Table 8.4 in the spec for further 112052558e08SMadhukar Pappireddydescription of actions. The action specified for a type of interrupt when the 112152558e08SMadhukar PappireddySP is in the message processing running state cannot be less permissive than the 112252558e08SMadhukar Pappireddyaction specified for the same type of interrupt when the SP is in the interrupt 112352558e08SMadhukar Pappireddyhandling running state. 112452558e08SMadhukar Pappireddy 112552558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+ 112652558e08SMadhukar Pappireddy| Runtime Model | NS-Int | Self S-Int | Other S-Int | 112752558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+ 112852558e08SMadhukar Pappireddy| Message Processing | Signalable with ME | Signalable | Signalable | 112952558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+ 113052558e08SMadhukar Pappireddy| Interrupt Handling | Queued | Queued | Queued | 113152558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+ 113252558e08SMadhukar Pappireddy 113352558e08SMadhukar PappireddyAbbreviations: 113452558e08SMadhukar Pappireddy 113552558e08SMadhukar Pappireddy - NS-Int: A Non-secure physical interrupt. It requires a switch to the Normal 113652558e08SMadhukar Pappireddy world to be handled. 113752558e08SMadhukar Pappireddy - Other S-Int: A secure physical interrupt targeted to an SP different from 113852558e08SMadhukar Pappireddy the one that is currently running. 113952558e08SMadhukar Pappireddy - Self S-Int: A secure physical interrupt targeted to the SP that is currently 114052558e08SMadhukar Pappireddy running. 114152558e08SMadhukar Pappireddy 114252558e08SMadhukar PappireddyThe following figure describes interrupt handling flow when secure interrupt 114352558e08SMadhukar Pappireddytriggers while in normal world: 114452558e08SMadhukar Pappireddy 114552558e08SMadhukar Pappireddy.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png 114652558e08SMadhukar Pappireddy 114752558e08SMadhukar PappireddyA brief description of the events: 114852558e08SMadhukar Pappireddy 114952558e08SMadhukar Pappireddy - 1) Secure interrupt triggers while normal world is running. 115052558e08SMadhukar Pappireddy - 2) FIQ gets trapped to EL3. 115152558e08SMadhukar Pappireddy - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI. 115252558e08SMadhukar Pappireddy - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends 115352558e08SMadhukar Pappireddy vIRQ). 115452558e08SMadhukar Pappireddy - 5) Since SP1 vCPU is in WAITING state, SPMC signals using FFA_INTERRUPT with 115552558e08SMadhukar Pappireddy interrupt id as argument and resume it using ERET. 115652558e08SMadhukar Pappireddy - 6) Execution traps to vIRQ handler in SP1 provided that interrupt is not 115752558e08SMadhukar Pappireddy masked i.e., PSTATE.I = 0 115852558e08SMadhukar Pappireddy - 7) SP1 services the interrupt and invokes the de-activation HVC call. 115952558e08SMadhukar Pappireddy - 8) SPMC does internal state management and further de-activates the physical 116052558e08SMadhukar Pappireddy interrupt and resumes SP vCPU. 116152558e08SMadhukar Pappireddy - 9) SP performs secure interrupt completion through FFA_MSG_WAIT ABI. 116252558e08SMadhukar Pappireddy - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME. 116352558e08SMadhukar Pappireddy - 11) EL3 resumes normal world execution. 116452558e08SMadhukar Pappireddy 116552558e08SMadhukar PappireddyThe following figure describes interrupt handling flow when secure interrupt 116652558e08SMadhukar Pappireddytriggers while in secure world: 116752558e08SMadhukar Pappireddy 116852558e08SMadhukar Pappireddy.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png 116952558e08SMadhukar Pappireddy 117052558e08SMadhukar PappireddyA brief description of the events: 117152558e08SMadhukar Pappireddy 117252558e08SMadhukar Pappireddy - 1) Secure interrupt triggers while SP2 is running and SP1 is blocked. 117352558e08SMadhukar Pappireddy - 2) Gets trapped to SPMC as IRQ. 117452558e08SMadhukar Pappireddy - 3) SPMC finds the target vCPU of secure partition responsible for handling 117552558e08SMadhukar Pappireddy this secure interrupt. In this scenario, it is SP1. 117652558e08SMadhukar Pappireddy - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface. 117752558e08SMadhukar Pappireddy SPMC further resumes SP1 through ERET conduit. 117852558e08SMadhukar Pappireddy - 5) Execution traps to vIRQ handler in SP1 provided that interrupt is not 117952558e08SMadhukar Pappireddy masked i.e., PSTATE.I = 0 118052558e08SMadhukar Pappireddy - 6) SP1 services the secure interrupt and invokes the de-activation HVC call. 118152558e08SMadhukar Pappireddy - 7) SPMC does internal state management, de-activates the physical interrupt 118252558e08SMadhukar Pappireddy and resumes SP1 vCPU. 118352558e08SMadhukar Pappireddy - 8) Assuming SP1 is in BLOCKED state, SP1 performs secure interrupt completion 118452558e08SMadhukar Pappireddy through FFA_RUN ABI. 118552558e08SMadhukar Pappireddy - 9) SPMC resumes the pre-empted vCPU of SP2. 118652558e08SMadhukar Pappireddy 1187fcb1398fSOlivier Deprez 1188fcb1398fSOlivier DeprezPower management 1189fcb1398fSOlivier Deprez---------------- 1190fcb1398fSOlivier Deprez 1191b5dd2422SOlivier DeprezIn platforms with or without secure virtualization: 1192fcb1398fSOlivier Deprez 1193b5dd2422SOlivier Deprez- The NWd owns the platform PM policy. 1194b5dd2422SOlivier Deprez- The Hypervisor or OS kernel is the component initiating PSCI service calls. 1195b5dd2422SOlivier Deprez- The EL3 PSCI library is in charge of the PM coordination and control 1196b5dd2422SOlivier Deprez (eventually writing to platform registers). 1197b5dd2422SOlivier Deprez- While coordinating PM events, the PSCI library calls backs into the Secure 1198b5dd2422SOlivier Deprez Payload Dispatcher for events the latter has statically registered to. 1199fcb1398fSOlivier Deprez 1200b5dd2422SOlivier DeprezWhen using the SPMD as a Secure Payload Dispatcher: 1201fcb1398fSOlivier Deprez 1202b5dd2422SOlivier Deprez- A power management event is relayed through the SPD hook to the SPMC. 1203b5dd2422SOlivier Deprez- In the current implementation only cpu on (svc_on_finish) and cpu off 1204b5dd2422SOlivier Deprez (svc_off) hooks are registered. 1205b5dd2422SOlivier Deprez- The behavior for the cpu on event is described in `Secondary cores boot-up`_. 1206b5dd2422SOlivier Deprez The SPMC is entered through its secondary physical core entry point. 1207*9eea92a1SOlivier Deprez- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The PM event is 1208*9eea92a1SOlivier Deprez signaled to the SPMC through a power management framework message. 1209*9eea92a1SOlivier Deprez It consists in a SPMD-to-SPMC direct request/response (`SPMC-SPMD direct 1210*9eea92a1SOlivier Deprez requests/responses`_) conveying the event details and SPMC response. 1211b5dd2422SOlivier Deprez The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and 1212b5dd2422SOlivier Deprez updates its internal state to reflect the physical core is being turned off. 1213b5dd2422SOlivier Deprez In the current implementation no SP is resumed as a consequence. This behavior 1214b5dd2422SOlivier Deprez ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux 1215b5dd2422SOlivier Deprez userspace. 1216fcb1398fSOlivier Deprez 1217*9eea92a1SOlivier DeprezArm architecture extensions for security hardening 1218*9eea92a1SOlivier Deprez================================================== 1219*9eea92a1SOlivier Deprez 1220*9eea92a1SOlivier DeprezHafnium supports the following architecture extensions for security hardening: 1221*9eea92a1SOlivier Deprez 1222*9eea92a1SOlivier Deprez- Pointer authentication (FEAT_PAuth): the extension permits detection of forged 1223*9eea92a1SOlivier Deprez pointers used by ROP type of attacks through the signing of the pointer 1224*9eea92a1SOlivier Deprez value. Hafnium is built with the compiler branch protection option to permit 1225*9eea92a1SOlivier Deprez generation of a pointer authentication code for return addresses (pointer 1226*9eea92a1SOlivier Deprez authentication for instructions). The APIA key is used while Hafnium runs. 1227*9eea92a1SOlivier Deprez A random key is generated at boot time and restored upon entry into Hafnium 1228*9eea92a1SOlivier Deprez at run-time. APIA and other keys (APIB, APDA, APDB, APGA) are saved/restored 1229*9eea92a1SOlivier Deprez in vCPU contexts permitting to enable pointer authentication in VMs/SPs. 1230*9eea92a1SOlivier Deprez- Branch Target Identification (FEAT_BTI): the extension permits detection of 1231*9eea92a1SOlivier Deprez unexpected indirect branches used by JOP type of attacks. Hafnium is built 1232*9eea92a1SOlivier Deprez with the compiler branch protection option, inserting land pads at function 1233*9eea92a1SOlivier Deprez prologues that are reached by indirect branch instructions (BR/BLR). 1234*9eea92a1SOlivier Deprez Hafnium code pages are marked as guarded in the EL2 Stage-1 MMU descriptors 1235*9eea92a1SOlivier Deprez such that an indirect branch must always target a landpad. A fault is 1236*9eea92a1SOlivier Deprez triggered otherwise. VMs/SPs can (independently) mark their code pages as 1237*9eea92a1SOlivier Deprez guarded in the EL1&0 Stage-1 translation regime. 1238*9eea92a1SOlivier Deprez- Memory Tagging Extension (FEAT_MTE): the option permits detection of out of 1239*9eea92a1SOlivier Deprez bound memory array accesses or re-use of an already freed memory region. 1240*9eea92a1SOlivier Deprez Hafnium enables the compiler option permitting to leverage MTE stack tagging 1241*9eea92a1SOlivier Deprez applied to core stacks. Core stacks are marked as normal tagged memory in the 1242*9eea92a1SOlivier Deprez EL2 Stage-1 translation regime. A synchronous data abort is generated upon tag 1243*9eea92a1SOlivier Deprez check failure on load/stores. A random seed is generated at boot time and 1244*9eea92a1SOlivier Deprez restored upon entry into Hafnium. MTE system registers are saved/restored in 1245*9eea92a1SOlivier Deprez vCPU contexts permitting MTE usage from VMs/SPs. 1246*9eea92a1SOlivier Deprez 1247b5dd2422SOlivier DeprezSMMUv3 support in Hafnium 1248b5dd2422SOlivier Deprez========================= 12494ec3ccb4SMadhukar Pappireddy 12504ec3ccb4SMadhukar PappireddyAn SMMU is analogous to an MMU in a CPU. It performs address translations for 12514ec3ccb4SMadhukar PappireddyDirect Memory Access (DMA) requests from system I/O devices. 12524ec3ccb4SMadhukar PappireddyThe responsibilities of an SMMU include: 12534ec3ccb4SMadhukar Pappireddy 12544ec3ccb4SMadhukar Pappireddy- Translation: Incoming DMA requests are translated from bus address space to 12554ec3ccb4SMadhukar Pappireddy system physical address space using translation tables compliant to 12564ec3ccb4SMadhukar Pappireddy Armv8/Armv7 VMSA descriptor format. 12574ec3ccb4SMadhukar Pappireddy- Protection: An I/O device can be prohibited from read, write access to a 12584ec3ccb4SMadhukar Pappireddy memory region or allowed. 12594ec3ccb4SMadhukar Pappireddy- Isolation: Traffic from each individial device can be independently managed. 12604ec3ccb4SMadhukar Pappireddy The devices are differentiated from each other using unique translation 12614ec3ccb4SMadhukar Pappireddy tables. 12624ec3ccb4SMadhukar Pappireddy 12634ec3ccb4SMadhukar PappireddyThe following diagram illustrates a typical SMMU IP integrated in a SoC with 12644ec3ccb4SMadhukar Pappireddyseveral I/O devices along with Interconnect and Memory system. 12654ec3ccb4SMadhukar Pappireddy 12664ec3ccb4SMadhukar Pappireddy.. image:: ../resources/diagrams/MMU-600.png 12674ec3ccb4SMadhukar Pappireddy 12684ec3ccb4SMadhukar PappireddySMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides 1269b5dd2422SOlivier Deprezsupport for SMMUv3 driver in both normal and secure world. A brief introduction 12704ec3ccb4SMadhukar Pappireddyof SMMUv3 functionality and the corresponding software support in Hafnium is 12714ec3ccb4SMadhukar Pappireddyprovided here. 12724ec3ccb4SMadhukar Pappireddy 12734ec3ccb4SMadhukar PappireddySMMUv3 features 12744ec3ccb4SMadhukar Pappireddy--------------- 12754ec3ccb4SMadhukar Pappireddy 12764ec3ccb4SMadhukar Pappireddy- SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2) 12774ec3ccb4SMadhukar Pappireddy translation support. It can either bypass or abort incoming translations as 12784ec3ccb4SMadhukar Pappireddy well. 12794ec3ccb4SMadhukar Pappireddy- Traffic (memory transactions) from each upstream I/O peripheral device, 12804ec3ccb4SMadhukar Pappireddy referred to as Stream, can be independently managed using a combination of 12814ec3ccb4SMadhukar Pappireddy several memory based configuration structures. This allows the SMMUv3 to 12824ec3ccb4SMadhukar Pappireddy support a large number of streams with each stream assigned to a unique 12834ec3ccb4SMadhukar Pappireddy translation context. 12844ec3ccb4SMadhukar Pappireddy- Support for Armv8.1 VMSA where the SMMU shares the translation tables with 12854ec3ccb4SMadhukar Pappireddy a Processing Element. AArch32(LPAE) and AArch64 translation table format 12864ec3ccb4SMadhukar Pappireddy are supported by SMMUv3. 12874ec3ccb4SMadhukar Pappireddy- SMMUv3 offers non-secure stream support with secure stream support being 12884ec3ccb4SMadhukar Pappireddy optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU 12894ec3ccb4SMadhukar Pappireddy instance for secure and non-secure stream support. 12904ec3ccb4SMadhukar Pappireddy- It also supports sub-streams to differentiate traffic from a virtualized 12914ec3ccb4SMadhukar Pappireddy peripheral associated with a VM/SP. 12924ec3ccb4SMadhukar Pappireddy- Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A 12934ec3ccb4SMadhukar Pappireddy extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2 12944ec3ccb4SMadhukar Pappireddy for providing Secure Stage2 translation support to upstream peripheral 12954ec3ccb4SMadhukar Pappireddy devices. 12964ec3ccb4SMadhukar Pappireddy 12974ec3ccb4SMadhukar PappireddySMMUv3 Programming Interfaces 12984ec3ccb4SMadhukar Pappireddy----------------------------- 12994ec3ccb4SMadhukar Pappireddy 13004ec3ccb4SMadhukar PappireddySMMUv3 has three software interfaces that are used by the Hafnium driver to 13014ec3ccb4SMadhukar Pappireddyconfigure the behaviour of SMMUv3 and manage the streams. 13024ec3ccb4SMadhukar Pappireddy 13034ec3ccb4SMadhukar Pappireddy- Memory based data strutures that provide unique translation context for 13044ec3ccb4SMadhukar Pappireddy each stream. 13054ec3ccb4SMadhukar Pappireddy- Memory based circular buffers for command queue and event queue. 13064ec3ccb4SMadhukar Pappireddy- A large number of SMMU configuration registers that are memory mapped during 13074ec3ccb4SMadhukar Pappireddy boot time by Hafnium driver. Except a few registers, all configuration 13084ec3ccb4SMadhukar Pappireddy registers have independent secure and non-secure versions to configure the 13094ec3ccb4SMadhukar Pappireddy behaviour of SMMUv3 for translation of secure and non-secure streams 13104ec3ccb4SMadhukar Pappireddy respectively. 13114ec3ccb4SMadhukar Pappireddy 13124ec3ccb4SMadhukar PappireddyPeripheral device manifest 13134ec3ccb4SMadhukar Pappireddy-------------------------- 13144ec3ccb4SMadhukar Pappireddy 13154ec3ccb4SMadhukar PappireddyCurrently, SMMUv3 driver in Hafnium only supports dependent peripheral devices. 13164ec3ccb4SMadhukar PappireddyThese devices are dependent on PE endpoint to initiate and receive memory 13174ec3ccb4SMadhukar Pappireddymanagement transactions on their behalf. The acccess to the MMIO regions of 13184ec3ccb4SMadhukar Pappireddyany such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver 13194ec3ccb4SMadhukar Pappireddyuses the same stage 2 translations for the device as those used by partition 13204ec3ccb4SMadhukar Pappireddymanager on behalf of the PE endpoint. This ensures that the peripheral device 13214ec3ccb4SMadhukar Pappireddyhas the same visibility of the physical address space as the endpoint. The 13224ec3ccb4SMadhukar Pappireddydevice node of the corresponding partition manifest (refer to `[1]`_ section 3.2 13234ec3ccb4SMadhukar Pappireddy) must specify these additional properties for each peripheral device in the 13244ec3ccb4SMadhukar Pappireddysystem : 13254ec3ccb4SMadhukar Pappireddy 13264ec3ccb4SMadhukar Pappireddy- smmu-id: This field helps to identify the SMMU instance that this device is 13274ec3ccb4SMadhukar Pappireddy upstream of. 13284ec3ccb4SMadhukar Pappireddy- stream-ids: List of stream IDs assigned to this device. 13294ec3ccb4SMadhukar Pappireddy 13304ec3ccb4SMadhukar Pappireddy.. code:: shell 13314ec3ccb4SMadhukar Pappireddy 13324ec3ccb4SMadhukar Pappireddy smmuv3-testengine { 13334ec3ccb4SMadhukar Pappireddy base-address = <0x00000000 0x2bfe0000>; 13344ec3ccb4SMadhukar Pappireddy pages-count = <32>; 13354ec3ccb4SMadhukar Pappireddy attributes = <0x3>; 13364ec3ccb4SMadhukar Pappireddy smmu-id = <0>; 13374ec3ccb4SMadhukar Pappireddy stream-ids = <0x0 0x1>; 13384ec3ccb4SMadhukar Pappireddy interrupts = <0x2 0x3>, <0x4 0x5>; 13394ec3ccb4SMadhukar Pappireddy exclusive-access; 13404ec3ccb4SMadhukar Pappireddy }; 13414ec3ccb4SMadhukar Pappireddy 13424ec3ccb4SMadhukar PappireddySMMUv3 driver limitations 13434ec3ccb4SMadhukar Pappireddy------------------------- 13444ec3ccb4SMadhukar Pappireddy 13454ec3ccb4SMadhukar PappireddyThe primary design goal for the Hafnium SMMU driver is to support secure 13464ec3ccb4SMadhukar Pappireddystreams. 13474ec3ccb4SMadhukar Pappireddy 13484ec3ccb4SMadhukar Pappireddy- Currently, the driver only supports Stage2 translations. No support for 13494ec3ccb4SMadhukar Pappireddy Stage1 or nested translations. 13504ec3ccb4SMadhukar Pappireddy- Supports only AArch64 translation format. 13514ec3ccb4SMadhukar Pappireddy- No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS, 13524ec3ccb4SMadhukar Pappireddy Fault handling, Performance Monitor Extensions, Event Handling, MPAM. 13534ec3ccb4SMadhukar Pappireddy- No support for independent peripheral devices. 13544ec3ccb4SMadhukar Pappireddy 1355aeea04d4SRaghu KrishnamurthyS-EL0 Partition support 1356*9eea92a1SOlivier Deprez======================= 1357aeea04d4SRaghu KrishnamurthyThe SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using 1358aeea04d4SRaghu KrishnamurthyFEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world 1359aeea04d4SRaghu Krishnamurthywith ARMv8.4 and FEAT_SEL2). 1360aeea04d4SRaghu Krishnamurthy 1361aeea04d4SRaghu KrishnamurthyS-EL0 partitions are useful for simple partitions that don't require full 1362aeea04d4SRaghu KrishnamurthyTrusted OS functionality. It is also useful to reduce jitter and cycle 1363aeea04d4SRaghu Krishnamurthystealing from normal world since they are more lightweight than VMs. 1364aeea04d4SRaghu Krishnamurthy 1365aeea04d4SRaghu KrishnamurthyS-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by 1366aeea04d4SRaghu Krishnamurthythe SPMC. They are differentiated primarily by the 'exception-level' property 1367aeea04d4SRaghu Krishnamurthyand the 'execution-ctx-count' property in the SP manifest. They are host apps 1368aeea04d4SRaghu Krishnamurthyunder the single EL2&0 Stage-1 translation regime controlled by the SPMC and 1369aeea04d4SRaghu Krishnamurthycall into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions 1370aeea04d4SRaghu Krishnamurthycan use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions 1371aeea04d4SRaghu Krishnamurthyfor memory regions. 1372aeea04d4SRaghu Krishnamurthy 1373aeea04d4SRaghu KrishnamurthyS-EL0 partitions are required by the FF-A specification to be UP endpoints, 1374aeea04d4SRaghu Krishnamurthycapable of migrating, and the SPMC enforces this requirement. The SPMC allows 1375aeea04d4SRaghu Krishnamurthya S-EL0 partition to accept a direct message from secure world and normal world, 1376aeea04d4SRaghu Krishnamurthyand generate direct responses to them. 1377aeea04d4SRaghu Krishnamurthy 1378aeea04d4SRaghu KrishnamurthyMemory sharing between and with S-EL0 partitions is supported. 1379aeea04d4SRaghu KrishnamurthyIndirect messaging, Interrupt handling and Notifications are not supported with 1380aeea04d4SRaghu KrishnamurthyS-EL0 partitions and is work in progress, planned for future releases. 1381aeea04d4SRaghu KrishnamurthyAll S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not 1382aeea04d4SRaghu Krishnamurthysupported. 1383aeea04d4SRaghu Krishnamurthy 1384aeea04d4SRaghu Krishnamurthy 1385fcb1398fSOlivier DeprezReferences 1386fcb1398fSOlivier Deprez========== 1387fcb1398fSOlivier Deprez 1388fcb1398fSOlivier Deprez.. _[1]: 1389fcb1398fSOlivier Deprez 13908a5bd3cfSOlivier Deprez[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__ 1391fcb1398fSOlivier Deprez 1392fcb1398fSOlivier Deprez.. _[2]: 1393fcb1398fSOlivier Deprez 13946844c347SMadhukar Pappireddy[2] :ref:`Secure Partition Manager using MM interface<Secure Partition Manager (MM)>` 1395fcb1398fSOlivier Deprez 1396fcb1398fSOlivier Deprez.. _[3]: 1397fcb1398fSOlivier Deprez 1398fcb1398fSOlivier Deprez[3] `Trusted Boot Board Requirements 1399b5dd2422SOlivier DeprezClient <https://developer.arm.com/documentation/den0006/d/>`__ 1400fcb1398fSOlivier Deprez 1401fcb1398fSOlivier Deprez.. _[4]: 1402fcb1398fSOlivier Deprez 1403fcb1398fSOlivier Deprez[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45 1404fcb1398fSOlivier Deprez 1405fcb1398fSOlivier Deprez.. _[5]: 1406fcb1398fSOlivier Deprez 1407b5dd2422SOlivier Deprez[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts 1408fcb1398fSOlivier Deprez 1409fcb1398fSOlivier Deprez.. _[6]: 1410fcb1398fSOlivier Deprez 14111b17f4f1SOlivier Deprez[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html 1412fcb1398fSOlivier Deprez 1413fcb1398fSOlivier Deprez.. _[7]: 1414fcb1398fSOlivier Deprez 1415fcb1398fSOlivier Deprez[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts 1416fcb1398fSOlivier Deprez 1417fcb1398fSOlivier Deprez.. _[8]: 1418fcb1398fSOlivier Deprez 1419f4a55e6bSSandrine Bailleux[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/ 1420fcb1398fSOlivier Deprez 1421f2dcf418SOlivier Deprez.. _[9]: 1422f2dcf418SOlivier Deprez 1423f2dcf418SOlivier Deprez[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot 1424f2dcf418SOlivier Deprez 1425fcb1398fSOlivier Deprez-------------- 1426fcb1398fSOlivier Deprez 14275ac60ea1SImre Kis*Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.* 1428