1fcb1398fSOlivier DeprezSecure Partition Manager 2fcb1398fSOlivier Deprez************************ 3fcb1398fSOlivier Deprez 4fcb1398fSOlivier Deprez.. contents:: 5fcb1398fSOlivier Deprez 69eea92a1SOlivier Deprez.. toctree:: 79eea92a1SOlivier Deprez ffa-manifest-binding 89eea92a1SOlivier 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+--------+--------------------------------------+ 299eea92a1SOlivier Deprez| JOP | Jump-Oriented Programming | 309eea92a1SOlivier 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+--------+--------------------------------------+ 459eea92a1SOlivier Deprez| ROP | Return-Oriented Programming | 469eea92a1SOlivier 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 739eea92a1SOlivier DeprezThree implementations of a Secure Partition Manager co-exist in the TF-A 749eea92a1SOlivier Deprezcodebase: 75fcb1398fSOlivier Deprez 769eea92a1SOlivier Deprez#. S-EL2 SPMC based on the FF-A specification `[1]`_, enabling virtualization in 779eea92a1SOlivier Deprez the secure world, managing multiple S-EL1 or S-EL0 partitions. 789eea92a1SOlivier Deprez#. EL3 SPMC based on the FF-A specification, managing a single S-EL1 partition 799eea92a1SOlivier Deprez without virtualization in the secure world. 809eea92a1SOlivier Deprez#. EL3 SPM based on the MM specification, legacy implementation managing a 819eea92a1SOlivier Deprez single S-EL0 partition `[2]`_. 82fcb1398fSOlivier Deprez 839eea92a1SOlivier DeprezThese implementations differ in their respective SW architecture and only one 849eea92a1SOlivier Deprezcan be selected at build time. This document: 85fcb1398fSOlivier Deprez 869eea92a1SOlivier 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. 899eea92a1SOlivier Deprez- covers the implications to TF-A used as a bootloader, and Hafnium used as a 909eea92a1SOlivier Deprez reference code base for an S-EL2/SPMC secure firmware on platforms 919eea92a1SOlivier 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 1099eea92a1SOlivier DeprezThe SPM is split into a dispatcher and a core component (respectively SPMD and 1109eea92a1SOlivier DeprezSPMC) residing at different exception levels. To permit the FF-A specification 1119eea92a1SOlivier Deprezadoption and a smooth migration, the SPMD supports an SPMC residing either at 1129eea92a1SOlivier DeprezS-EL1 or S-EL2: 113fcb1398fSOlivier Deprez 1149eea92a1SOlivier Deprez- The SPMD is located at EL3 and mainly relays the FF-A protocol from NWd 1159eea92a1SOlivier Deprez (Hypervisor or OS kernel) to the SPMC. 1169eea92a1SOlivier Deprez- The same SPMD component is used for both S-EL1 and S-EL2 SPMC configurations. 1179eea92a1SOlivier Deprez- The SPMC exception level is a build time choice. 118fcb1398fSOlivier Deprez 1199eea92a1SOlivier DeprezTF-A supports both cases: 1209eea92a1SOlivier Deprez 1219eea92a1SOlivier 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. 1239eea92a1SOlivier 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. 1519eea92a1SOlivier Deprez- If neither ``SPMD_SPM_AT_SEL2`` or ``SPMC_AT_EL3`` are enabled the SPMC 1521d63ae4dSMarc Bonnici exception level is set to S-EL1. 153b5dd2422SOlivier Deprez ``SPMD_SPM_AT_SEL2`` is enabled. The context save/restore routine 154b5dd2422SOlivier Deprez and exhaustive list of registers is visible at `[4]`_. 155801cd3c8SNishant Sharma- **SPMC_AT_EL3_SEL0_SP**: this option enables the support to load SEL0 SP 156801cd3c8SNishant Sharma when SPMC at EL3 support is enabled. 157b5dd2422SOlivier Deprez- **SP_LAYOUT_FILE**: this option specifies a text description file 158b5dd2422SOlivier Deprez providing paths to SP binary images and manifests in DTS format 159b5dd2422SOlivier Deprez (see `Describing secure partitions`_). It 160fcb1398fSOlivier Deprez is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple 1619eea92a1SOlivier Deprez secure partitions are to be loaded by BL2 on behalf of the SPMC. 162fcb1398fSOlivier Deprez 163f1910cc1SGovindraj Raja+---------------+------------------+-------------+-------------------------+ 164f1910cc1SGovindraj Raja| | SPMD_SPM_AT_SEL2 | SPMC_AT_EL3 | CTX_INCLUDE_EL2_REGS(*) | 165f1910cc1SGovindraj Raja+---------------+------------------+-------------+-------------------------+ 1661d63ae4dSMarc Bonnici| SPMC at S-EL1 | 0 | 0 | 0 | 167f1910cc1SGovindraj Raja+---------------+------------------+-------------+-------------------------+ 168f1910cc1SGovindraj Raja| SPMC at S-EL2 | 1 (default when | 0 | 1 | 169f1910cc1SGovindraj Raja| | SPD=spmd) | | | 170f1910cc1SGovindraj Raja+---------------+------------------+-------------+-------------------------+ 171f1910cc1SGovindraj Raja| SPMC at EL3 | 0 | 1 | 0 | 172f1910cc1SGovindraj Raja+---------------+------------------+-------------+-------------------------+ 173fcb1398fSOlivier Deprez 174fcb1398fSOlivier DeprezOther combinations of such build options either break the build or are not 175fcb1398fSOlivier Deprezsupported. 176fcb1398fSOlivier Deprez 177b5dd2422SOlivier DeprezNotes: 178b5dd2422SOlivier Deprez 179b5dd2422SOlivier Deprez- Only Arm's FVP platform is supported to use with the TF-A reference software 180b5dd2422SOlivier Deprez stack. 1819eea92a1SOlivier Deprez- When ``SPMD_SPM_AT_SEL2=1``, the reference software stack assumes enablement 1829eea92a1SOlivier Deprez of FEAT_PAuth, FEAT_BTI and FEAT_MTE architecture extensions. 183f1910cc1SGovindraj Raja- ``(*) CTX_INCLUDE_EL2_REGS``, this flag is |TF-A| internal and informational 184f1910cc1SGovindraj Raja in this table. When set, it provides the generic support for saving/restoring 185f1910cc1SGovindraj Raja EL2 registers required when S-EL2 firmware is present. 186b5dd2422SOlivier Deprez- BL32 option is re-purposed to specify the SPMC image. It can specify either 187b5dd2422SOlivier Deprez the Hafnium binary path (built for the secure world) or the path to a TEE 188b5dd2422SOlivier Deprez binary implementing FF-A interfaces. 189b5dd2422SOlivier Deprez- BL33 option can specify the TFTF binary or a normal world loader 1909eea92a1SOlivier Deprez such as U-Boot or the UEFI framework payload. 191fcb1398fSOlivier Deprez 1929eea92a1SOlivier DeprezSample TF-A build command line when the SPMC is located at S-EL1 1939eea92a1SOlivier Deprez(e.g. when the FEAT_SEL2 architecture extension is not implemented): 194fcb1398fSOlivier Deprez 195fcb1398fSOlivier Deprez.. code:: shell 196fcb1398fSOlivier Deprez 197fcb1398fSOlivier Deprez make \ 198fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 199fcb1398fSOlivier Deprez SPD=spmd \ 200fcb1398fSOlivier Deprez SPMD_SPM_AT_SEL2=0 \ 201fcb1398fSOlivier Deprez BL32=<path-to-tee-binary> \ 202b5dd2422SOlivier Deprez BL33=<path-to-bl33-binary> \ 203fcb1398fSOlivier Deprez PLAT=fvp \ 204fcb1398fSOlivier Deprez all fip 205fcb1398fSOlivier Deprez 2069eea92a1SOlivier DeprezSample TF-A build command line when FEAT_SEL2 architecture extension is 2079eea92a1SOlivier Deprezimplemented and the SPMC is located at S-EL2: 208b2836dfeSNicola Mazzucato 209fcb1398fSOlivier Deprez.. code:: shell 210fcb1398fSOlivier Deprez 211fcb1398fSOlivier Deprez make \ 212fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 213b5dd2422SOlivier Deprez PLAT=fvp \ 214fcb1398fSOlivier Deprez SPD=spmd \ 215b5dd2422SOlivier Deprez ARM_ARCH_MINOR=5 \ 216b5dd2422SOlivier Deprez BRANCH_PROTECTION=1 \ 217b5dd2422SOlivier Deprez CTX_INCLUDE_PAUTH_REGS=1 \ 218*0a33adc0SGovindraj Raja ENABLE_FEAT_MTE=1 \ 219b5dd2422SOlivier Deprez BL32=<path-to-hafnium-binary> \ 220b5dd2422SOlivier Deprez BL33=<path-to-bl33-binary> \ 221fcb1398fSOlivier Deprez SP_LAYOUT_FILE=sp_layout.json \ 222fcb1398fSOlivier Deprez all fip 223fcb1398fSOlivier Deprez 2249eea92a1SOlivier DeprezSample TF-A build command line when FEAT_SEL2 architecture extension is 2259eea92a1SOlivier Deprezimplemented, the SPMC is located at S-EL2, and enabling secure boot: 226b2836dfeSNicola Mazzucato 227fcb1398fSOlivier Deprez.. code:: shell 228fcb1398fSOlivier Deprez 229fcb1398fSOlivier Deprez make \ 230fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 231b5dd2422SOlivier Deprez PLAT=fvp \ 232fcb1398fSOlivier Deprez SPD=spmd \ 233b5dd2422SOlivier Deprez ARM_ARCH_MINOR=5 \ 234b5dd2422SOlivier Deprez BRANCH_PROTECTION=1 \ 235b5dd2422SOlivier Deprez CTX_INCLUDE_PAUTH_REGS=1 \ 236*0a33adc0SGovindraj Raja ENABLE_FEAT_MTE=1 \ 237b5dd2422SOlivier Deprez BL32=<path-to-hafnium-binary> \ 238b5dd2422SOlivier Deprez BL33=<path-to-bl33-binary> \ 239b5dd2422SOlivier Deprez SP_LAYOUT_FILE=sp_layout.json \ 240fcb1398fSOlivier Deprez MBEDTLS_DIR=<path-to-mbedtls-lib> \ 241fcb1398fSOlivier Deprez TRUSTED_BOARD_BOOT=1 \ 242fcb1398fSOlivier Deprez COT=dualroot \ 243fcb1398fSOlivier Deprez ARM_ROTPK_LOCATION=devel_rsa \ 244fcb1398fSOlivier Deprez ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \ 245fcb1398fSOlivier Deprez GENERATE_COT=1 \ 246fcb1398fSOlivier Deprez all fip 247fcb1398fSOlivier Deprez 2489eea92a1SOlivier DeprezSample TF-A build command line when the SPMC is located at EL3: 2491d63ae4dSMarc Bonnici 2501d63ae4dSMarc Bonnici.. code:: shell 2511d63ae4dSMarc Bonnici 2521d63ae4dSMarc Bonnici make \ 2531d63ae4dSMarc Bonnici CROSS_COMPILE=aarch64-none-elf- \ 2541d63ae4dSMarc Bonnici SPD=spmd \ 2551d63ae4dSMarc Bonnici SPMD_SPM_AT_SEL2=0 \ 2561d63ae4dSMarc Bonnici SPMC_AT_EL3=1 \ 2571d63ae4dSMarc Bonnici BL32=<path-to-tee-binary> \ 2581d63ae4dSMarc Bonnici BL33=<path-to-bl33-binary> \ 2591d63ae4dSMarc Bonnici PLAT=fvp \ 2601d63ae4dSMarc Bonnici all fip 2611d63ae4dSMarc Bonnici 262801cd3c8SNishant SharmaSample TF-A build command line when the SPMC is located at EL3 and SEL0 SP is 263801cd3c8SNishant Sharmaenabled: 264801cd3c8SNishant Sharma 265801cd3c8SNishant Sharma.. code:: shell 266801cd3c8SNishant Sharma 267801cd3c8SNishant Sharma make \ 268801cd3c8SNishant Sharma CROSS_COMPILE=aarch64-none-elf- \ 269801cd3c8SNishant Sharma SPD=spmd \ 270801cd3c8SNishant Sharma SPMD_SPM_AT_SEL2=0 \ 271801cd3c8SNishant Sharma SPMC_AT_EL3=1 \ 272801cd3c8SNishant Sharma SPMC_AT_EL3_SEL0_SP=1 \ 273801cd3c8SNishant Sharma BL32=<path-to-tee-binary> \ 274801cd3c8SNishant Sharma BL33=<path-to-bl33-binary> \ 275801cd3c8SNishant Sharma PLAT=fvp \ 276801cd3c8SNishant Sharma all fip 277801cd3c8SNishant Sharma 278b5dd2422SOlivier DeprezFVP model invocation 279b5dd2422SOlivier Deprez==================== 280b5dd2422SOlivier Deprez 281b5dd2422SOlivier DeprezThe FVP command line needs the following options to exercise the S-EL2 SPMC: 282b5dd2422SOlivier Deprez 283b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 284b5dd2422SOlivier Deprez| - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, | 285b5dd2422SOlivier Deprez| - cluster1.has_arm_v8-5=1 | and FEAT_BTI. | 286b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 287b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the | 288b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. | 289b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | | 290b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | | 291b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | | 292b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | | 293b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | | 294b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | | 295b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 296b5dd2422SOlivier Deprez| - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. | 297b5dd2422SOlivier Deprez| - cluster1.has_branch_target_exception=1 | | 298b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 2999eea92a1SOlivier Deprez| - cluster0.has_pointer_authentication=2 | Implements FEAT_PAuth | 3009eea92a1SOlivier Deprez| - cluster1.has_pointer_authentication=2 | | 3019eea92a1SOlivier Deprez+---------------------------------------------------+------------------------------------+ 3029eea92a1SOlivier Deprez| - cluster0.memory_tagging_support_level=2 | Implements FEAT_MTE2 | 3039eea92a1SOlivier Deprez| - cluster1.memory_tagging_support_level=2 | | 3049eea92a1SOlivier Deprez| - bp.dram_metadata.is_enabled=1 | | 305b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+ 306b5dd2422SOlivier Deprez 307b5dd2422SOlivier DeprezSample FVP command line invocation: 308b5dd2422SOlivier Deprez 309b5dd2422SOlivier Deprez.. code:: shell 310b5dd2422SOlivier Deprez 3119eea92a1SOlivier Deprez <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \ 312b5dd2422SOlivier Deprez -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \ 313b5dd2422SOlivier Deprez -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \ 314b5dd2422SOlivier Deprez -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \ 315b5dd2422SOlivier Deprez -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \ 316b5dd2422SOlivier Deprez -C bp.pl011_uart2.out_file=fvp-uart2.log \ 3179eea92a1SOlivier Deprez -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 \ 3189eea92a1SOlivier Deprez -C cluster0.has_pointer_authentication=2 -C cluster1.has_pointer_authentication=2 \ 3199eea92a1SOlivier Deprez -C cluster0.has_branch_target_exception=1 -C cluster1.has_branch_target_exception=1 \ 3209eea92a1SOlivier Deprez -C cluster0.memory_tagging_support_level=2 -C cluster1.memory_tagging_support_level=2 \ 3219eea92a1SOlivier Deprez -C bp.dram_metadata.is_enabled=1 \ 3229eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B \ 3239eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 \ 3249eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 \ 3259eea92a1SOlivier Deprez -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 326b5dd2422SOlivier Deprez 327fcb1398fSOlivier DeprezBoot process 328fcb1398fSOlivier Deprez============ 329fcb1398fSOlivier Deprez 330b5dd2422SOlivier DeprezLoading Hafnium and secure partitions in the secure world 331fcb1398fSOlivier Deprez--------------------------------------------------------- 332fcb1398fSOlivier Deprez 333b5dd2422SOlivier DeprezTF-A BL2 is the bootlader for the SPMC and SPs in the secure world. 334fcb1398fSOlivier Deprez 335fcb1398fSOlivier DeprezSPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.). 336b5dd2422SOlivier DeprezThus they are supplied as distinct signed entities within the FIP flash 337b5dd2422SOlivier Deprezimage. The FIP image itself is not signed hence this provides the ability 338b5dd2422SOlivier Deprezto upgrade SPs in the field. 339fcb1398fSOlivier Deprez 340fcb1398fSOlivier DeprezBooting through TF-A 341fcb1398fSOlivier Deprez-------------------- 342fcb1398fSOlivier Deprez 343fcb1398fSOlivier DeprezSP manifests 344fcb1398fSOlivier Deprez~~~~~~~~~~~~ 345fcb1398fSOlivier Deprez 346fcb1398fSOlivier DeprezAn SP manifest describes SP attributes as defined in `[1]`_ 347b5dd2422SOlivier Deprez(partition manifest at virtual FF-A instance) in DTS format. It is 348b5dd2422SOlivier Deprezrepresented as a single file associated with the SP. A sample is 349fcb1398fSOlivier Deprezprovided by `[5]`_. A binding document is provided by `[6]`_. 350fcb1398fSOlivier Deprez 351fcb1398fSOlivier DeprezSecure Partition packages 352fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~ 353fcb1398fSOlivier Deprez 354b5dd2422SOlivier DeprezSecure partitions are bundled as independent package files consisting 355fcb1398fSOlivier Deprezof: 356fcb1398fSOlivier Deprez 357fcb1398fSOlivier Deprez- a header 358fcb1398fSOlivier Deprez- a DTB 359fcb1398fSOlivier Deprez- an image payload 360fcb1398fSOlivier Deprez 361fcb1398fSOlivier DeprezThe header starts with a magic value and offset values to SP DTB and 362fcb1398fSOlivier Deprezimage payload. Each SP package is loaded independently by BL2 loader 363fcb1398fSOlivier Deprezand verified for authenticity and integrity. 364fcb1398fSOlivier Deprez 365b5dd2422SOlivier DeprezThe SP package identified by its UUID (matching FF-A uuid property) is 366b5dd2422SOlivier Deprezinserted as a single entry into the FIP at end of the TF-A build flow 367b5dd2422SOlivier Deprezas shown: 368fcb1398fSOlivier Deprez 369fcb1398fSOlivier Deprez.. code:: shell 370fcb1398fSOlivier Deprez 371fcb1398fSOlivier Deprez Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw" 372fcb1398fSOlivier Deprez EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw" 373fcb1398fSOlivier Deprez Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw" 374fcb1398fSOlivier Deprez Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw" 375fcb1398fSOlivier Deprez HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config" 376fcb1398fSOlivier Deprez TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config" 377fcb1398fSOlivier Deprez SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config" 378fcb1398fSOlivier Deprez TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config" 379fcb1398fSOlivier Deprez NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config" 380fcb1398fSOlivier Deprez B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob" 381fcb1398fSOlivier Deprez D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob" 382fcb1398fSOlivier Deprez 383fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml 384fcb1398fSOlivier Deprez 385b5dd2422SOlivier DeprezDescribing secure partitions 386b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 387fcb1398fSOlivier Deprez 388b5dd2422SOlivier DeprezA json-formatted description file is passed to the build flow specifying paths 389b5dd2422SOlivier Deprezto the SP binary image and associated DTS partition manifest file. The latter 390b5dd2422SOlivier Deprezis processed by the dtc compiler to generate a DTB fed into the SP package. 391573ac373SJ-AlvesOptionally, the partition's json description can contain offsets for both 392573ac373SJ-Alvesthe image and partition manifest within the SP package. Both offsets need to be 393573ac373SJ-Alves4KB aligned, because it is the translation granule supported by Hafnium SPMC. 394573ac373SJ-AlvesThese fields can be leveraged to support SPs with S1 translation granules that 395573ac373SJ-Alvesdiffer from 4KB, and to configure the regions allocated within the SP package, 396573ac373SJ-Alvesas well as to comply with the requirements for the implementation of the boot 397573ac373SJ-Alvesinformation protocol (see `Passing boot data to the SP`_ for more details). In 398573ac373SJ-Alvescase the offsets are absent in their json node, they default to 0x1000 and 399573ac373SJ-Alves0x4000 for the manifest offset and image offset respectively. 400b5dd2422SOlivier DeprezThis file also specifies the SP owner (as an optional field) identifying the 401b5dd2422SOlivier Deprezsigning domain in case of dual root CoT. 402b5dd2422SOlivier DeprezThe SP owner can either be the silicon or the platform provider. The 403b5dd2422SOlivier Deprezcorresponding "owner" field value can either take the value of "SiP" or "Plat". 404b5dd2422SOlivier DeprezIn absence of "owner" field, it defaults to "SiP" owner. 4055ac60ea1SImre KisThe UUID of the partition can be specified as a field in the description file or 4065ac60ea1SImre Kisif it does not exist there the UUID is extracted from the DTS partition 4075ac60ea1SImre Kismanifest. 408fcb1398fSOlivier Deprez 409fcb1398fSOlivier Deprez.. code:: shell 410fcb1398fSOlivier Deprez 411fcb1398fSOlivier Deprez { 412fcb1398fSOlivier Deprez "tee1" : { 413fcb1398fSOlivier Deprez "image": "tee1.bin", 4140901d339SManish Pandey "pm": "tee1.dts", 4155ac60ea1SImre Kis "owner": "SiP", 4165ac60ea1SImre Kis "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f" 417fcb1398fSOlivier Deprez }, 418fcb1398fSOlivier Deprez 419fcb1398fSOlivier Deprez "tee2" : { 420fcb1398fSOlivier Deprez "image": "tee2.bin", 4210901d339SManish Pandey "pm": "tee2.dts", 4220901d339SManish Pandey "owner": "Plat" 423573ac373SJ-Alves }, 424573ac373SJ-Alves 425573ac373SJ-Alves "tee3" : { 426573ac373SJ-Alves "image": { 427573ac373SJ-Alves "file": "tee3.bin", 428573ac373SJ-Alves "offset":"0x2000" 429573ac373SJ-Alves }, 430573ac373SJ-Alves "pm": { 431573ac373SJ-Alves "file": "tee3.dts", 432573ac373SJ-Alves "offset":"0x6000" 433573ac373SJ-Alves }, 434573ac373SJ-Alves "owner": "Plat" 435573ac373SJ-Alves }, 436fcb1398fSOlivier Deprez } 437fcb1398fSOlivier Deprez 438fcb1398fSOlivier DeprezSPMC manifest 439fcb1398fSOlivier Deprez~~~~~~~~~~~~~ 440fcb1398fSOlivier Deprez 441b5dd2422SOlivier DeprezThis manifest contains the SPMC *attribute* node consumed by the SPMD at boot 442b5dd2422SOlivier Depreztime. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves 443b5dd2422SOlivier Depreztwo different cases: 444fcb1398fSOlivier Deprez 445b5dd2422SOlivier Deprez- The SPMC resides at S-EL1: the SPMC manifest is used by the SPMD to setup a 446b5dd2422SOlivier Deprez SP that co-resides with the SPMC and executes at S-EL1 or Secure Supervisor 447b5dd2422SOlivier Deprez mode. 448b5dd2422SOlivier Deprez- The SPMC resides at S-EL2: the SPMC manifest is used by the SPMD to setup 449b5dd2422SOlivier Deprez the environment required by the SPMC to run at S-EL2. SPs run at S-EL1 or 450b5dd2422SOlivier Deprez S-EL0. 451fcb1398fSOlivier Deprez 452fcb1398fSOlivier Deprez.. code:: shell 453fcb1398fSOlivier Deprez 454fcb1398fSOlivier Deprez attribute { 455fcb1398fSOlivier Deprez spmc_id = <0x8000>; 456fcb1398fSOlivier Deprez maj_ver = <0x1>; 4579eea92a1SOlivier Deprez min_ver = <0x1>; 458fcb1398fSOlivier Deprez exec_state = <0x0>; 459fcb1398fSOlivier Deprez load_address = <0x0 0x6000000>; 460fcb1398fSOlivier Deprez entrypoint = <0x0 0x6000000>; 461fcb1398fSOlivier Deprez binary_size = <0x60000>; 462fcb1398fSOlivier Deprez }; 463fcb1398fSOlivier Deprez 464fcb1398fSOlivier Deprez- *spmc_id* defines the endpoint ID value that SPMC can query through 465fcb1398fSOlivier Deprez ``FFA_ID_GET``. 466fcb1398fSOlivier Deprez- *maj_ver/min_ver*. SPMD checks provided version versus its internal 467fcb1398fSOlivier Deprez version and aborts if not matching. 468b5dd2422SOlivier Deprez- *exec_state* defines the SPMC execution state (AArch64 or AArch32). 469b5dd2422SOlivier Deprez Notice Hafnium used as a SPMC only supports AArch64. 470fcb1398fSOlivier Deprez- *load_address* and *binary_size* are mostly used to verify secondary 471fcb1398fSOlivier Deprez entry points fit into the loaded binary image. 472fcb1398fSOlivier Deprez- *entrypoint* defines the cold boot primary core entry point used by 473b5dd2422SOlivier Deprez SPMD (currently matches ``BL32_BASE``) to enter the SPMC. 474fcb1398fSOlivier Deprez 475fcb1398fSOlivier DeprezOther nodes in the manifest are consumed by Hafnium in the secure world. 4769eea92a1SOlivier DeprezA sample can be found at `[7]`_: 477fcb1398fSOlivier Deprez 478b5dd2422SOlivier Deprez- The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute 479b5dd2422SOlivier Deprez indicates a FF-A compliant SP. The *load_address* field specifies the load 4809eea92a1SOlivier Deprez address at which BL2 loaded the SP package. 481b5dd2422SOlivier Deprez- *cpus* node provide the platform topology and allows MPIDR to VMPIDR mapping. 4829eea92a1SOlivier Deprez Note the primary core is declared first, then secondary cores are declared 483b5dd2422SOlivier Deprez in reverse order. 484433f6d2bSJ-Alves- The *memory* nodes provide platform information on the ranges of memory 485433f6d2bSJ-Alves available for use by SPs at runtime. These ranges relate to either 486433f6d2bSJ-Alves secure or non-secure memory, depending on the *device_type* field. 487433f6d2bSJ-Alves If the field specifies "memory" the range is secure, else if it specifies 488433f6d2bSJ-Alves "ns-memory" the memory is non-secure. The system integrator must exclude 489433f6d2bSJ-Alves the memory used by other components that are not SPs, such as the monitor, 490433f6d2bSJ-Alves or the SPMC itself, the OS Kernel/Hypervisor, or other NWd VMs. The SPMC 491433f6d2bSJ-Alves limits the SP's address space such that they do not access memory outside 492433f6d2bSJ-Alves of those ranges. 493fcb1398fSOlivier Deprez 494fcb1398fSOlivier DeprezSPMC boot 495fcb1398fSOlivier Deprez~~~~~~~~~ 496fcb1398fSOlivier Deprez 497fcb1398fSOlivier DeprezThe SPMC is loaded by BL2 as the BL32 image. 498fcb1398fSOlivier Deprez 499f2dcf418SOlivier DeprezThe SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_. 500fcb1398fSOlivier Deprez 501fcb1398fSOlivier DeprezBL2 passes the SPMC manifest address to BL31 through a register. 502fcb1398fSOlivier Deprez 503b5dd2422SOlivier DeprezAt boot time, the SPMD in BL31 runs from the primary core, initializes the core 504f2dcf418SOlivier Deprezcontexts and launches the SPMC (BL32) passing the following information through 505f2dcf418SOlivier Deprezregisters: 506f2dcf418SOlivier Deprez 507f2dcf418SOlivier Deprez- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob). 508f2dcf418SOlivier Deprez- X1 holds the ``HW_CONFIG`` physical address. 509f2dcf418SOlivier Deprez- X4 holds the currently running core linear id. 510fcb1398fSOlivier Deprez 511fcb1398fSOlivier DeprezLoading of SPs 512fcb1398fSOlivier Deprez~~~~~~~~~~~~~~ 513fcb1398fSOlivier Deprez 514b5dd2422SOlivier DeprezAt boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted 515b5dd2422SOlivier Deprezbelow: 516b5dd2422SOlivier Deprez 517fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml 518fcb1398fSOlivier Deprez 519b5dd2422SOlivier DeprezNote this boot flow is an implementation sample on Arm's FVP platform. 520b5dd2422SOlivier DeprezPlatforms not using TF-A's *Firmware CONFiguration* framework would adjust to a 5219eea92a1SOlivier Deprezdifferent boot flow. The flow restricts to a maximum of 8 secure partitions. 522fcb1398fSOlivier Deprez 523fcb1398fSOlivier DeprezSecure boot 524fcb1398fSOlivier Deprez~~~~~~~~~~~ 525fcb1398fSOlivier Deprez 526fcb1398fSOlivier DeprezThe SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC, 527b5dd2422SOlivier DeprezSPMC manifest, secure partitions and verifies them for authenticity and integrity. 528fcb1398fSOlivier DeprezRefer to TBBR specification `[3]`_. 529fcb1398fSOlivier Deprez 530b5dd2422SOlivier DeprezThe multiple-signing domain feature (in current state dual signing domain `[8]`_) allows 531b5dd2422SOlivier Deprezthe use of two root keys namely S-ROTPK and NS-ROTPK: 532fcb1398fSOlivier Deprez 5330901d339SManish Pandey- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK. 534fcb1398fSOlivier Deprez- BL33 may be signed by the OEM using NS-ROTPK. 5350901d339SManish Pandey- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK). 5369eea92a1SOlivier Deprez- A maximum of 4 partitions can be signed with the S-ROTPK key and 4 partitions 5379eea92a1SOlivier Deprez signed with the NS-ROTPK key. 538fcb1398fSOlivier Deprez 539b5dd2422SOlivier DeprezAlso refer to `Describing secure partitions`_ and `TF-A build options`_ sections. 540fcb1398fSOlivier Deprez 541fcb1398fSOlivier DeprezHafnium in the secure world 542fcb1398fSOlivier Deprez=========================== 543fcb1398fSOlivier Deprez 544fcb1398fSOlivier DeprezGeneral considerations 545fcb1398fSOlivier Deprez---------------------- 546fcb1398fSOlivier Deprez 547fcb1398fSOlivier DeprezBuild platform for the secure world 548fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 549fcb1398fSOlivier Deprez 550b5dd2422SOlivier DeprezIn the Hafnium reference implementation specific code parts are only relevant to 551b5dd2422SOlivier Deprezthe secure world. Such portions are isolated in architecture specific files 552b5dd2422SOlivier Deprezand/or enclosed by a ``SECURE_WORLD`` macro. 553fcb1398fSOlivier Deprez 5549eea92a1SOlivier DeprezSecure partitions scheduling 5559eea92a1SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 556fcb1398fSOlivier Deprez 5579eea92a1SOlivier DeprezThe FF-A specification `[1]`_ provides two ways to relinquinsh CPU time to 558b5dd2422SOlivier Deprezsecure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of: 559fcb1398fSOlivier Deprez 560b5dd2422SOlivier Deprez- the FFA_MSG_SEND_DIRECT_REQ interface. 561b5dd2422SOlivier Deprez- the FFA_RUN interface. 562fcb1398fSOlivier Deprez 5639eea92a1SOlivier DeprezAdditionally a secure interrupt can pre-empt the normal world execution and give 5649eea92a1SOlivier DeprezCPU cycles by transitioning to EL3 and S-EL2. 5659eea92a1SOlivier Deprez 566fcb1398fSOlivier DeprezPlatform topology 567fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~ 568fcb1398fSOlivier Deprez 569b5dd2422SOlivier DeprezThe *execution-ctx-count* SP manifest field can take the value of one or the 5709eea92a1SOlivier Depreztotal number of PEs. The FF-A specification `[1]`_ recommends the 571fcb1398fSOlivier Deprezfollowing SP types: 572fcb1398fSOlivier Deprez 573b5dd2422SOlivier Deprez- Pinned MP SPs: an execution context matches a physical PE. MP SPs must 574b5dd2422SOlivier Deprez implement the same number of ECs as the number of PEs in the platform. 575b5dd2422SOlivier Deprez- Migratable UP SPs: a single execution context can run and be migrated on any 576b5dd2422SOlivier Deprez physical PE. Such SP declares a single EC in its SP manifest. An UP SP can 577b5dd2422SOlivier Deprez receive a direct message request originating from any physical core targeting 578b5dd2422SOlivier Deprez the single execution context. 579fcb1398fSOlivier Deprez 580fcb1398fSOlivier DeprezParsing SP partition manifests 581fcb1398fSOlivier Deprez------------------------------ 582fcb1398fSOlivier Deprez 583b5dd2422SOlivier DeprezHafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_. 584b5dd2422SOlivier DeprezNote the current implementation may not implement all optional fields. 585fcb1398fSOlivier Deprez 586b5dd2422SOlivier DeprezThe SP manifest may contain memory and device regions nodes. In case of 587b5dd2422SOlivier Deprezan S-EL2 SPMC: 588fcb1398fSOlivier Deprez 589b5dd2422SOlivier Deprez- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at 590b5dd2422SOlivier Deprez load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can 591b5dd2422SOlivier Deprez specify RX/TX buffer regions in which case it is not necessary for an SP 592433f6d2bSJ-Alves to explicitly invoke the ``FFA_RXTX_MAP`` interface. The memory referred 593433f6d2bSJ-Alves shall be contained within the memory ranges defined in SPMC manifest. The 594433f6d2bSJ-Alves NS bit in the attributes field should be consistent with the security 595433f6d2bSJ-Alves state of the range that it relates to. I.e. non-secure memory shall be 596433f6d2bSJ-Alves part of a non-secure memory range, and secure memory shall be contained 597433f6d2bSJ-Alves in a secure memory range of a given platform. 598b5dd2422SOlivier Deprez- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or 599b5dd2422SOlivier Deprez EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate 600b5dd2422SOlivier Deprez additional resources (e.g. interrupts). 601fcb1398fSOlivier Deprez 602b5dd2422SOlivier DeprezFor the S-EL2 SPMC, base addresses for memory and device region nodes are IPAs 603b5dd2422SOlivier Deprezprovided the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation 604b5dd2422SOlivier Deprezregime. 605fcb1398fSOlivier Deprez 606b5dd2422SOlivier DeprezNote: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the 607b5dd2422SOlivier Deprezsame set of page tables. It is still open whether two sets of page tables shall 608b5dd2422SOlivier Deprezbe provided per SP. The memory region node as defined in the specification 609fcb1398fSOlivier Deprezprovides a memory security attribute hinting to map either to the secure or 610b5dd2422SOlivier Depreznon-secure EL1&0 Stage-2 table if it exists. 611fcb1398fSOlivier Deprez 612fcb1398fSOlivier DeprezPassing boot data to the SP 613fcb1398fSOlivier Deprez--------------------------- 614fcb1398fSOlivier Deprez 615573ac373SJ-AlvesIn `[1]`_ , the section "Boot information protocol" defines a method for passing 616573ac373SJ-Alvesdata to the SPs at boot time. It specifies the format for the boot information 617573ac373SJ-Alvesdescriptor and boot information header structures, which describe the data to be 618573ac373SJ-Alvesexchanged between SPMC and SP. 619573ac373SJ-AlvesThe specification also defines the types of data that can be passed. 620573ac373SJ-AlvesThe aggregate of both the boot info structures and the data itself is designated 621573ac373SJ-Alvesthe boot information blob, and is passed to a Partition as a contiguous memory 622573ac373SJ-Alvesregion. 623fcb1398fSOlivier Deprez 624573ac373SJ-AlvesCurrently, the SPM implementation supports the FDT type which is used to pass the 625573ac373SJ-Alvespartition's DTB manifest. 626573ac373SJ-Alves 627573ac373SJ-AlvesThe region for the boot information blob is allocated through the SP package. 628573ac373SJ-Alves 629573ac373SJ-Alves.. image:: ../resources/diagrams/partition-package.png 630573ac373SJ-Alves 631573ac373SJ-AlvesTo adjust the space allocated for the boot information blob, the json description 632573ac373SJ-Alvesof the SP (see section `Describing secure partitions`_) shall be updated to contain 633573ac373SJ-Alvesthe manifest offset. If no offset is provided the manifest offset defaults to 0x1000, 634573ac373SJ-Alveswhich is the page size in the Hafnium SPMC. 635573ac373SJ-Alves 636573ac373SJ-AlvesThe configuration of the boot protocol is done in the SPs manifest. As defined by 637573ac373SJ-Alvesthe specification, the manifest field 'gp-register-num' configures the GP register 638573ac373SJ-Alveswhich shall be used to pass the address to the partitions boot information blob when 639573ac373SJ-Alvesbooting the partition. 640573ac373SJ-AlvesIn addition, the Hafnium SPMC implementation requires the boot information arguments 641573ac373SJ-Alvesto be listed in a designated DT node: 642573ac373SJ-Alves 643573ac373SJ-Alves.. code:: shell 644573ac373SJ-Alves 645573ac373SJ-Alves boot-info { 646573ac373SJ-Alves compatible = "arm,ffa-manifest-boot-info"; 647573ac373SJ-Alves ffa_manifest; 648573ac373SJ-Alves }; 649573ac373SJ-Alves 650573ac373SJ-AlvesThe whole secure partition package image (see `Secure Partition packages`_) is 651573ac373SJ-Alvesmapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can 652573ac373SJ-Alvesretrieve the address for the boot information blob in the designated GP register, 653573ac373SJ-Alvesprocess the boot information header and descriptors, access its own manifest 654573ac373SJ-AlvesDTB blob and extract its partition manifest properties. 655fcb1398fSOlivier Deprez 656fcb1398fSOlivier DeprezSP Boot order 657fcb1398fSOlivier Deprez------------- 658fcb1398fSOlivier Deprez 659fcb1398fSOlivier DeprezSP manifests provide an optional boot order attribute meant to resolve 660fcb1398fSOlivier Deprezdependencies such as an SP providing a service required to properly boot 661c1ff1791SJ-Alvesanother SP. SPMC boots the SPs in accordance to the boot order attribute, 662c1ff1791SJ-Alveslowest to the highest value. If the boot order attribute is absent from the FF-A 663c1ff1791SJ-Alvesmanifest, the SP is treated as if it had the highest boot order value 664c1ff1791SJ-Alves(i.e. lowest booting priority). 665fcb1398fSOlivier Deprez 666b5dd2422SOlivier DeprezIt is possible for an SP to call into another SP through a direct request 667b5dd2422SOlivier Deprezprovided the latter SP has already been booted. 668b5dd2422SOlivier Deprez 669fcb1398fSOlivier DeprezBoot phases 670fcb1398fSOlivier Deprez----------- 671fcb1398fSOlivier Deprez 672fcb1398fSOlivier DeprezPrimary core boot-up 673fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~ 674fcb1398fSOlivier Deprez 675b5dd2422SOlivier DeprezUpon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical 676b5dd2422SOlivier Deprezcore. The SPMC performs its platform initializations and registers the SPMC 677b5dd2422SOlivier Deprezsecondary physical core entry point physical address by the use of the 67816c1c453SJ-Alves`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD 67916c1c453SJ-Alvesat secure physical FF-A instance). 680fcb1398fSOlivier Deprez 681b5dd2422SOlivier DeprezThe SPMC then creates secure partitions based on SP packages and manifests. Each 682b5dd2422SOlivier Deprezsecure partition is launched in sequence (`SP Boot order`_) on their "primary" 683b5dd2422SOlivier Deprezexecution context. If the primary boot physical core linear id is N, an MP SP is 684b5dd2422SOlivier Deprezstarted using EC[N] on PE[N] (see `Platform topology`_). If the partition is a 685b5dd2422SOlivier DeprezUP SP, it is started using its unique EC0 on PE[N]. 686fcb1398fSOlivier Deprez 687b5dd2422SOlivier DeprezThe SP primary EC (or the EC used when the partition is booted as described 688b5dd2422SOlivier Deprezabove): 689fcb1398fSOlivier Deprez 690b5dd2422SOlivier Deprez- Performs the overall SP boot time initialization, and in case of a MP SP, 691b5dd2422SOlivier Deprez prepares the SP environment for other execution contexts. 692b5dd2422SOlivier Deprez- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure 693b5dd2422SOlivier Deprez virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA 694b5dd2422SOlivier Deprez entry point for other execution contexts. 695b5dd2422SOlivier Deprez- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or 696b5dd2422SOlivier Deprez ``FFA_ERROR`` in case of failure. 697fcb1398fSOlivier Deprez 698b5dd2422SOlivier DeprezSecondary cores boot-up 699b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~ 700fcb1398fSOlivier Deprez 701b5dd2422SOlivier DeprezOnce the system is started and NWd brought up, a secondary physical core is 702b5dd2422SOlivier Deprezwoken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism 703b5dd2422SOlivier Deprezcalls into the SPMD on the newly woken up physical core. Then the SPMC is 704b5dd2422SOlivier Deprezentered at the secondary physical core entry point. 705fcb1398fSOlivier Deprez 706b5dd2422SOlivier DeprezIn the current implementation, the first SP is resumed on the coresponding EC 707b5dd2422SOlivier Deprez(the virtual CPU which matches the physical core). The implication is that the 708b5dd2422SOlivier Deprezfirst SP must be a MP SP. 709fcb1398fSOlivier Deprez 710b5dd2422SOlivier DeprezIn a linux based system, once secure and normal worlds are booted but prior to 711b5dd2422SOlivier Depreza NWd FF-A driver has been loaded: 712fcb1398fSOlivier Deprez 713b5dd2422SOlivier Deprez- The first SP has initialized all its ECs in response to primary core boot up 714b5dd2422SOlivier Deprez (at system initialization) and secondary core boot up (as a result of linux 715b5dd2422SOlivier Deprez invoking PSCI_CPU_ON for all secondary cores). 716b5dd2422SOlivier Deprez- Other SPs have their first execution context initialized as a result of secure 717b5dd2422SOlivier Deprez world initialization on the primary boot core. Other ECs for those SPs have to 718b5dd2422SOlivier Deprez be run first through ffa_run to complete their initialization (which results 719b5dd2422SOlivier Deprez in the EC completing with FFA_MSG_WAIT). 720fcb1398fSOlivier Deprez 721b5dd2422SOlivier DeprezRefer to `Power management`_ for further details. 722fcb1398fSOlivier Deprez 72316c1c453SJ-AlvesNotifications 72416c1c453SJ-Alves------------- 72516c1c453SJ-Alves 72616c1c453SJ-AlvesThe FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous 72716c1c453SJ-Alvescommunication mechanism with non-blocking semantics. It allows for one FF-A 72816c1c453SJ-Alvesendpoint to signal another for service provision, without hindering its current 72916c1c453SJ-Alvesprogress. 73016c1c453SJ-Alves 73116c1c453SJ-AlvesHafnium currently supports 64 notifications. The IDs of each notification define 73216c1c453SJ-Alvesa position in a 64-bit bitmap. 73316c1c453SJ-Alves 73416c1c453SJ-AlvesThe signaling of notifications can interchangeably happen between NWd and SWd 73516c1c453SJ-AlvesFF-A endpoints. 73616c1c453SJ-Alves 73716c1c453SJ-AlvesThe SPMC is in charge of managing notifications from SPs to SPs, from SPs to 73816c1c453SJ-AlvesVMs, and from VMs to SPs. An hypervisor component would only manage 73916c1c453SJ-Alvesnotifications from VMs to VMs. Given the SPMC has no visibility of the endpoints 74016c1c453SJ-Alvesdeployed in NWd, the Hypervisor or OS kernel must invoke the interface 74116c1c453SJ-AlvesFFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A 74216c1c453SJ-Alvesendpoint in the NWd that supports it. 74316c1c453SJ-Alves 74416c1c453SJ-AlvesA sender can signal notifications once the receiver has provided it with 74516c1c453SJ-Alvespermissions. Permissions are provided by invoking the interface 74616c1c453SJ-AlvesFFA_NOTIFICATION_BIND. 74716c1c453SJ-Alves 74816c1c453SJ-AlvesNotifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth 74916c1c453SJ-Alvesthey are considered to be in a pending sate. The receiver can retrieve its 75016c1c453SJ-Alvespending notifications invoking FFA_NOTIFICATION_GET, which, from that moment, 75116c1c453SJ-Alvesare considered to be handled. 75216c1c453SJ-Alves 75316c1c453SJ-AlvesPer the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler 75416c1c453SJ-Alvesthat is in charge of donating CPU cycles for notifications handling. The 75516c1c453SJ-AlvesFF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about 75616c1c453SJ-Alveswhich FF-A endpoints have pending notifications. The receiver scheduler is 75716c1c453SJ-Alvescalled and informed by the FF-A driver, and it should allocate CPU cycles to the 75816c1c453SJ-Alvesreceiver. 75916c1c453SJ-Alves 76016c1c453SJ-AlvesThere are two types of notifications supported: 7619eea92a1SOlivier Deprez 76216c1c453SJ-Alves- Global, which are targeted to a FF-A endpoint and can be handled within any of 76316c1c453SJ-Alves its execution contexts, as determined by the scheduler of the system. 76416c1c453SJ-Alves- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a 76516c1c453SJ-Alves a specific execution context, as determined by the sender. 76616c1c453SJ-Alves 76716c1c453SJ-AlvesThe type of a notification is set when invoking FFA_NOTIFICATION_BIND to give 76816c1c453SJ-Alvespermissions to the sender. 76916c1c453SJ-Alves 77016c1c453SJ-AlvesNotification signaling resorts to two interrupts: 7719eea92a1SOlivier Deprez 7729eea92a1SOlivier Deprez- Schedule Receiver Interrupt: non-secure physical interrupt to be handled by 7739eea92a1SOlivier Deprez the FF-A driver within the receiver scheduler. At initialization the SPMC 7749eea92a1SOlivier Deprez donates a SGI ID chosen from the secure SGI IDs range and configures it as 7759eea92a1SOlivier Deprez non-secure. The SPMC triggers this SGI on the currently running core when 7769eea92a1SOlivier Deprez there are pending notifications, and the respective receivers need CPU cycles 7779eea92a1SOlivier Deprez to handle them. 7789eea92a1SOlivier Deprez- Notifications Pending Interrupt: virtual interrupt to be handled by the 7799eea92a1SOlivier Deprez receiver of the notification. Set when there are pending notifications for the 7809eea92a1SOlivier Deprez given secure partition. The NPI is pended when the NWd relinquishes CPU cycles 7819eea92a1SOlivier Deprez to an SP. 78216c1c453SJ-Alves 78316c1c453SJ-AlvesThe notifications receipt support is enabled in the partition FF-A manifest. 78416c1c453SJ-Alves 785fcb1398fSOlivier DeprezMandatory interfaces 786fcb1398fSOlivier Deprez-------------------- 787fcb1398fSOlivier Deprez 788b5dd2422SOlivier DeprezThe following interfaces are exposed to SPs: 789fcb1398fSOlivier Deprez 790fcb1398fSOlivier Deprez- ``FFA_VERSION`` 791fcb1398fSOlivier Deprez- ``FFA_FEATURES`` 792fcb1398fSOlivier Deprez- ``FFA_RX_RELEASE`` 793fcb1398fSOlivier Deprez- ``FFA_RXTX_MAP`` 79416c1c453SJ-Alves- ``FFA_RXTX_UNMAP`` 795fcb1398fSOlivier Deprez- ``FFA_PARTITION_INFO_GET`` 796fcb1398fSOlivier Deprez- ``FFA_ID_GET`` 797b5dd2422SOlivier Deprez- ``FFA_MSG_WAIT`` 798b5dd2422SOlivier Deprez- ``FFA_MSG_SEND_DIRECT_REQ`` 799b5dd2422SOlivier Deprez- ``FFA_MSG_SEND_DIRECT_RESP`` 800b5dd2422SOlivier Deprez- ``FFA_MEM_DONATE`` 801b5dd2422SOlivier Deprez- ``FFA_MEM_LEND`` 802b5dd2422SOlivier Deprez- ``FFA_MEM_SHARE`` 803b5dd2422SOlivier Deprez- ``FFA_MEM_RETRIEVE_REQ`` 804b5dd2422SOlivier Deprez- ``FFA_MEM_RETRIEVE_RESP`` 805b5dd2422SOlivier Deprez- ``FFA_MEM_RELINQUISH`` 8069eea92a1SOlivier Deprez- ``FFA_MEM_FRAG_RX`` 8079eea92a1SOlivier Deprez- ``FFA_MEM_FRAG_TX`` 808b5dd2422SOlivier Deprez- ``FFA_MEM_RECLAIM`` 8099eea92a1SOlivier Deprez- ``FFA_RUN`` 81016c1c453SJ-Alves 8119eea92a1SOlivier DeprezAs part of the FF-A v1.1 support, the following interfaces were added: 81216c1c453SJ-Alves 81316c1c453SJ-Alves - ``FFA_NOTIFICATION_BITMAP_CREATE`` 81416c1c453SJ-Alves - ``FFA_NOTIFICATION_BITMAP_DESTROY`` 81516c1c453SJ-Alves - ``FFA_NOTIFICATION_BIND`` 81616c1c453SJ-Alves - ``FFA_NOTIFICATION_UNBIND`` 81716c1c453SJ-Alves - ``FFA_NOTIFICATION_SET`` 81816c1c453SJ-Alves - ``FFA_NOTIFICATION_GET`` 81916c1c453SJ-Alves - ``FFA_NOTIFICATION_INFO_GET`` 82016c1c453SJ-Alves - ``FFA_SPM_ID_GET`` 821b5dd2422SOlivier Deprez - ``FFA_SECONDARY_EP_REGISTER`` 8229eea92a1SOlivier Deprez - ``FFA_MEM_PERM_GET`` 8239eea92a1SOlivier Deprez - ``FFA_MEM_PERM_SET`` 82453e3b385SJ-Alves - ``FFA_MSG_SEND2`` 82553e3b385SJ-Alves - ``FFA_RX_ACQUIRE`` 826fcb1398fSOlivier Deprez 827fcb1398fSOlivier DeprezFFA_VERSION 828fcb1398fSOlivier Deprez~~~~~~~~~~~ 829fcb1398fSOlivier Deprez 830b5dd2422SOlivier Deprez``FFA_VERSION`` requires a *requested_version* parameter from the caller. 831b5dd2422SOlivier DeprezThe returned value depends on the caller: 832fcb1398fSOlivier Deprez 833b5dd2422SOlivier Deprez- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version 834b5dd2422SOlivier Deprez specified in the SPMC manifest. 835b5dd2422SOlivier Deprez- SP: the SPMC returns its own implemented version. 836b5dd2422SOlivier Deprez- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version. 837fcb1398fSOlivier Deprez 838fcb1398fSOlivier DeprezFFA_FEATURES 839fcb1398fSOlivier Deprez~~~~~~~~~~~~ 840fcb1398fSOlivier Deprez 841b5dd2422SOlivier DeprezFF-A features supported by the SPMC may be discovered by secure partitions at 842b5dd2422SOlivier Deprezboot (that is prior to NWd is booted) or run-time. 843fcb1398fSOlivier Deprez 844b5dd2422SOlivier DeprezThe SPMC calling FFA_FEATURES at secure physical FF-A instance always get 845b5dd2422SOlivier DeprezFFA_SUCCESS from the SPMD. 846b5dd2422SOlivier Deprez 847b5dd2422SOlivier DeprezThe request made by an Hypervisor or OS kernel is forwarded to the SPMC and 848b5dd2422SOlivier Deprezthe response relayed back to the NWd. 849fcb1398fSOlivier Deprez 850fcb1398fSOlivier DeprezFFA_RXTX_MAP/FFA_RXTX_UNMAP 851fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~ 852fcb1398fSOlivier Deprez 853b5dd2422SOlivier DeprezWhen invoked from a secure partition FFA_RXTX_MAP maps the provided send and 854b5dd2422SOlivier Deprezreceive buffers described by their IPAs to the SP EL1&0 Stage-2 translation 855b5dd2422SOlivier Deprezregime as secure buffers in the MMU descriptors. 856fcb1398fSOlivier Deprez 857b5dd2422SOlivier DeprezWhen invoked from the Hypervisor or OS kernel, the buffers are mapped into the 858b5dd2422SOlivier DeprezSPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU 85953e3b385SJ-Alvesdescriptors. The provided addresses may be owned by a VM in the normal world, 86053e3b385SJ-Alveswhich is expected to receive messages from the secure world. The SPMC will in 86153e3b385SJ-Alvesthis case allocate internal state structures to facilitate RX buffer access 86253e3b385SJ-Alvessynchronization (through FFA_RX_ACQUIRE interface), and to permit SPs to send 86353e3b385SJ-Alvesmessages. 864b5dd2422SOlivier Deprez 86516c1c453SJ-AlvesThe FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the 86616c1c453SJ-Alvescaller, either it being the Hypervisor or OS kernel, as well as a secure 86716c1c453SJ-Alvespartition. 868fcb1398fSOlivier Deprez 869fcb1398fSOlivier DeprezFFA_PARTITION_INFO_GET 870fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~ 871fcb1398fSOlivier Deprez 872b5dd2422SOlivier DeprezPartition info get call can originate: 873fcb1398fSOlivier Deprez 874b5dd2422SOlivier Deprez- from SP to SPMC 875b5dd2422SOlivier Deprez- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD. 876fcb1398fSOlivier Deprez 877fcb1398fSOlivier DeprezFFA_ID_GET 878fcb1398fSOlivier Deprez~~~~~~~~~~ 879fcb1398fSOlivier Deprez 880b5dd2422SOlivier DeprezThe FF-A id space is split into a non-secure space and secure space: 881b5dd2422SOlivier Deprez 882b5dd2422SOlivier Deprez- FF-A ID with bit 15 clear relates to VMs. 883b5dd2422SOlivier Deprez- FF-A ID with bit 15 set related to SPs. 884b5dd2422SOlivier Deprez- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD 885b5dd2422SOlivier Deprez and SPMC. 886b5dd2422SOlivier Deprez 887fcb1398fSOlivier DeprezThe SPMD returns: 888fcb1398fSOlivier Deprez 889b5dd2422SOlivier Deprez- The default zero value on invocation from the Hypervisor. 890fcb1398fSOlivier Deprez- The ``spmc_id`` value specified in the SPMC manifest on invocation from 891fcb1398fSOlivier Deprez the SPMC (see `SPMC manifest`_) 892fcb1398fSOlivier Deprez 893b5dd2422SOlivier DeprezThis convention helps the SPMC to determine the origin and destination worlds in 894b5dd2422SOlivier Deprezan FF-A ABI invocation. In particular the SPMC shall filter unauthorized 895fcb1398fSOlivier Depreztransactions in its world switch routine. It must not be permitted for a VM to 896b5dd2422SOlivier Deprezuse a secure FF-A ID as origin world by spoofing: 897fcb1398fSOlivier Deprez 898b5dd2422SOlivier Deprez- A VM-to-SP direct request/response shall set the origin world to be non-secure 899b5dd2422SOlivier Deprez (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15 900fcb1398fSOlivier Deprez set). 901b5dd2422SOlivier Deprez- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15 902b5dd2422SOlivier Deprez for both origin and destination IDs. 903fcb1398fSOlivier Deprez 904fcb1398fSOlivier DeprezAn incoming direct message request arriving at SPMD from NWd is forwarded to 905fcb1398fSOlivier DeprezSPMC without a specific check. The SPMC is resumed through eret and "knows" the 906fcb1398fSOlivier Deprezmessage is coming from normal world in this specific code path. Thus the origin 907b5dd2422SOlivier Deprezendpoint ID must be checked by SPMC for being a normal world ID. 908fcb1398fSOlivier Deprez 909fcb1398fSOlivier DeprezAn SP sending a direct message request must have bit 15 set in its origin 910b5dd2422SOlivier Deprezendpoint ID and this can be checked by the SPMC when the SP invokes the ABI. 911fcb1398fSOlivier Deprez 912fcb1398fSOlivier DeprezThe SPMC shall reject the direct message if the claimed world in origin endpoint 913b5dd2422SOlivier DeprezID is not consistent: 914fcb1398fSOlivier Deprez 915b5dd2422SOlivier Deprez- It is either forwarded by SPMD and thus origin endpoint ID must be a "normal 916b5dd2422SOlivier Deprez world ID", 917b5dd2422SOlivier Deprez- or initiated by an SP and thus origin endpoint ID must be a "secure world ID". 918fcb1398fSOlivier Deprez 919fcb1398fSOlivier Deprez 920b5dd2422SOlivier DeprezFFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP 921b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 922fcb1398fSOlivier Deprez 923b5dd2422SOlivier DeprezThis is a mandatory interface for secure partitions consisting in direct request 924b5dd2422SOlivier Deprezand responses with the following rules: 925fcb1398fSOlivier Deprez 926b5dd2422SOlivier Deprez- An SP can send a direct request to another SP. 927b5dd2422SOlivier Deprez- An SP can receive a direct request from another SP. 928b5dd2422SOlivier Deprez- An SP can send a direct response to another SP. 929b5dd2422SOlivier Deprez- An SP cannot send a direct request to an Hypervisor or OS kernel. 930b5dd2422SOlivier Deprez- An Hypervisor or OS kernel can send a direct request to an SP. 931b5dd2422SOlivier Deprez- An SP can send a direct response to an Hypervisor or OS kernel. 932fcb1398fSOlivier Deprez 93316c1c453SJ-AlvesFFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY 93416c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 93516c1c453SJ-Alves 93616c1c453SJ-AlvesThe secure partitions notifications bitmap are statically allocated by the SPMC. 93716c1c453SJ-AlvesHence, this interface is not to be issued by secure partitions. 93816c1c453SJ-Alves 93916c1c453SJ-AlvesAt initialization, the SPMC is not aware of VMs/partitions deployed in the 94016c1c453SJ-Alvesnormal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC 94116c1c453SJ-Alvesto be prepared to handle notifications for the provided VM ID. 94216c1c453SJ-Alves 94316c1c453SJ-AlvesFFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND 94416c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 94516c1c453SJ-Alves 94616c1c453SJ-AlvesPair of interfaces to manage permissions to signal notifications. Prior to 94716c1c453SJ-Alveshandling notifications, an FF-A endpoint must allow a given sender to signal a 94816c1c453SJ-Alvesbitmap of notifications. 94916c1c453SJ-Alves 95016c1c453SJ-AlvesIf the receiver doesn't have notification support enabled in its FF-A manifest, 95116c1c453SJ-Alvesit won't be able to bind notifications, hence forbidding it to receive any 95216c1c453SJ-Alvesnotifications. 95316c1c453SJ-Alves 95416c1c453SJ-AlvesFFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET 95516c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 95616c1c453SJ-Alves 9579eea92a1SOlivier DeprezFFA_NOTIFICATION_GET retrieves all pending global notifications and 9589eea92a1SOlivier Deprezper-vCPU notifications targeted to the current vCPU. 95916c1c453SJ-Alves 9609eea92a1SOlivier DeprezHafnium maintains a global count of pending notifications which gets incremented 9619eea92a1SOlivier Deprezand decremented when handling FFA_NOTIFICATION_SET and FFA_NOTIFICATION_GET 9629eea92a1SOlivier Deprezrespectively. A delayed SRI is triggered if the counter is non-zero when the 9639eea92a1SOlivier DeprezSPMC returns to normal world. 96416c1c453SJ-Alves 96516c1c453SJ-AlvesFFA_NOTIFICATION_INFO_GET 96616c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~ 96716c1c453SJ-Alves 9689eea92a1SOlivier DeprezHafnium maintains a global count of pending notifications whose information 9699eea92a1SOlivier Deprezhas been retrieved by this interface. The count is incremented and decremented 9709eea92a1SOlivier Deprezwhen handling FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET respectively. 9719eea92a1SOlivier DeprezIt also tracks notifications whose information has been retrieved individually, 97216c1c453SJ-Alvessuch that it avoids duplicating returned information for subsequent calls to 97316c1c453SJ-AlvesFFA_NOTIFICATION_INFO_GET. For each notification, this state information is 97416c1c453SJ-Alvesreset when receiver called FFA_NOTIFICATION_GET to retrieve them. 97516c1c453SJ-Alves 97616c1c453SJ-AlvesFFA_SPM_ID_GET 97716c1c453SJ-Alves~~~~~~~~~~~~~~ 97816c1c453SJ-Alves 9799eea92a1SOlivier DeprezReturns the FF-A ID allocated to an SPM component which can be one of SPMD 9809eea92a1SOlivier Deprezor SPMC. 98116c1c453SJ-Alves 9829eea92a1SOlivier DeprezAt initialization, the SPMC queries the SPMD for the SPMC ID, using the 9839eea92a1SOlivier DeprezFFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using 9849eea92a1SOlivier Deprezthe FFA_SPM_ID_GET interface at the secure physical FF-A instance. 98516c1c453SJ-Alves 9869eea92a1SOlivier DeprezSecure partitions call this interface at the virtual FF-A instance, to which 9879eea92a1SOlivier Deprezthe SPMC returns the priorly retrieved SPMC ID. 98816c1c453SJ-Alves 9899eea92a1SOlivier DeprezThe Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the 9909eea92a1SOlivier DeprezSPMD, which returns the SPMC ID. 99116c1c453SJ-Alves 99216c1c453SJ-AlvesFFA_SECONDARY_EP_REGISTER 99316c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~ 99416c1c453SJ-Alves 99516c1c453SJ-AlvesWhen the SPMC boots, all secure partitions are initialized on their primary 99616c1c453SJ-AlvesExecution Context. 99716c1c453SJ-Alves 9989eea92a1SOlivier DeprezThe FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition 99916c1c453SJ-Alvesfrom its first execution context, to provide the entry point address for 100016c1c453SJ-Alvessecondary execution contexts. 100116c1c453SJ-Alves 100216c1c453SJ-AlvesA secondary EC is first resumed either upon invocation of PSCI_CPU_ON from 100316c1c453SJ-Alvesthe NWd or by invocation of FFA_RUN. 100416c1c453SJ-Alves 100553e3b385SJ-AlvesFFA_RX_ACQUIRE/FFA_RX_RELEASE 100653e3b385SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 100753e3b385SJ-Alves 100853e3b385SJ-AlvesThe RX buffers can be used to pass information to an FF-A endpoint in the 100953e3b385SJ-Alvesfollowing scenarios: 101053e3b385SJ-Alves 101153e3b385SJ-Alves - When it was targetted by a FFA_MSG_SEND2 invokation from another endpoint. 101253e3b385SJ-Alves - Return the result of calling ``FFA_PARTITION_INFO_GET``. 101353e3b385SJ-Alves - In a memory share operation, as part of the ``FFA_MEM_RETRIEVE_RESP``, 101453e3b385SJ-Alves with the memory descriptor of the shared memory. 101553e3b385SJ-Alves 101653e3b385SJ-AlvesIf a normal world VM is expected to exchange messages with secure world, 101753e3b385SJ-Alvesits RX/TX buffer addresses are forwarded to the SPMC via FFA_RXTX_MAP ABI, 101853e3b385SJ-Alvesand are from this moment owned by the SPMC. 101953e3b385SJ-AlvesThe hypervisor must call the FFA_RX_ACQUIRE interface before attempting 102053e3b385SJ-Alvesto use the RX buffer, in any of the aforementioned scenarios. A successful 102153e3b385SJ-Alvescall to FFA_RX_ACQUIRE transfers ownership of RX buffer to hypervisor, such 102253e3b385SJ-Alvesthat it can be safely used. 102353e3b385SJ-Alves 102453e3b385SJ-AlvesThe FFA_RX_RELEASE interface is used after the FF-A endpoint is done with 102553e3b385SJ-Alvesprocessing the data received in its RX buffer. If the RX buffer has been 102653e3b385SJ-Alvesacquired by the hypervisor, the FFA_RX_RELEASE call must be forwarded to 102753e3b385SJ-Alvesthe SPMC to reestablish SPMC's RX ownership. 102853e3b385SJ-Alves 102953e3b385SJ-AlvesAn attempt from an SP to send a message to a normal world VM whose RX buffer 103053e3b385SJ-Alveswas acquired by the hypervisor fails with error code FFA_BUSY, to preserve 103153e3b385SJ-Alvesthe RX buffer integrity. 103253e3b385SJ-AlvesThe operation could then be conducted after FFA_RX_RELEASE. 103353e3b385SJ-Alves 103453e3b385SJ-AlvesFFA_MSG_SEND2 103553e3b385SJ-Alves~~~~~~~~~~~~~ 103653e3b385SJ-Alves 103753e3b385SJ-AlvesHafnium copies a message from the sender TX buffer into receiver's RX buffer. 103853e3b385SJ-AlvesFor messages from SPs to VMs, operation is only possible if the SPMC owns 103953e3b385SJ-Alvesthe receiver's RX buffer. 104053e3b385SJ-Alves 104153e3b385SJ-AlvesBoth receiver and sender need to enable support for indirect messaging, 104253e3b385SJ-Alvesin their respective partition manifest. The discovery of support 104353e3b385SJ-Alvesof such feature can be done via FFA_PARTITION_INFO_GET. 104453e3b385SJ-Alves 104553e3b385SJ-AlvesOn a successful message send, Hafnium pends an RX buffer full framework 104653e3b385SJ-Alvesnotification for the receiver, to inform it about a message in the RX buffer. 104753e3b385SJ-Alves 104853e3b385SJ-AlvesThe handling of framework notifications is similar to that of 104953e3b385SJ-Alvesglobal notifications. Binding of these is not necessary, as these are 105053e3b385SJ-Alvesreserved to be used by the hypervisor or SPMC. 105153e3b385SJ-Alves 1052b5dd2422SOlivier DeprezSPMC-SPMD direct requests/responses 1053b5dd2422SOlivier Deprez----------------------------------- 1054fcb1398fSOlivier Deprez 1055b5dd2422SOlivier DeprezImplementation-defined FF-A IDs are allocated to the SPMC and SPMD. 1056b5dd2422SOlivier DeprezUsing those IDs in source/destination fields of a direct request/response 1057b5dd2422SOlivier Deprezpermits SPMD to SPMC communication and either way. 1058fcb1398fSOlivier Deprez 1059b5dd2422SOlivier Deprez- SPMC to SPMD direct request/response uses SMC conduit. 1060b5dd2422SOlivier Deprez- SPMD to SPMC direct request/response uses ERET conduit. 1061fcb1398fSOlivier Deprez 10629eea92a1SOlivier DeprezThis is used in particular to convey power management messages. 10639eea92a1SOlivier Deprez 1064cc63ff97SJ-AlvesMemory Sharing 1065cc63ff97SJ-Alves-------------- 1066cc63ff97SJ-Alves 1067cc63ff97SJ-AlvesHafnium implements the following memory sharing interfaces: 1068cc63ff97SJ-Alves 1069cc63ff97SJ-Alves - ``FFA_MEM_SHARE`` - for shared access between lender and borrower. 1070cc63ff97SJ-Alves - ``FFA_MEM_LEND`` - borrower to obtain exclusive access, though lender 1071cc63ff97SJ-Alves retains ownership of the memory. 1072cc63ff97SJ-Alves - ``FFA_MEM_DONATE`` - lender permanently relinquishes ownership of memory 1073cc63ff97SJ-Alves to the borrower. 1074cc63ff97SJ-Alves 1075cc63ff97SJ-AlvesThe ``FFA_MEM_RETRIEVE_REQ`` interface is for the borrower to request the 1076cc63ff97SJ-Alvesmemory to be mapped into its address space: for S-EL1 partitions the SPM updates 1077cc63ff97SJ-Alvestheir stage 2 translation regime; for S-EL0 partitions the SPM updates their 1078cc63ff97SJ-Alvesstage 1 translation regime. On a successful call, the SPMC responds back with 1079cc63ff97SJ-Alves``FFA_MEM_RETRIEVE_RESP``. 1080cc63ff97SJ-Alves 1081cc63ff97SJ-AlvesThe ``FFA_MEM_RELINQUISH`` interface is for when the borrower is done with using 1082cc63ff97SJ-Alvesa memory region. 1083cc63ff97SJ-Alves 1084cc63ff97SJ-AlvesThe ``FFA_MEM_RECLAIM`` interface is for the owner of the memory to reestablish 1085cc63ff97SJ-Alvesits ownership and exclusive access to the memory shared. 1086cc63ff97SJ-Alves 1087cc63ff97SJ-AlvesThe memory transaction descriptors are transmitted via RX/TX buffers. In 1088cc63ff97SJ-Alvessituations where the size of the memory transaction descriptor exceeds the 1089cc63ff97SJ-Alvessize of the RX/TX buffers, Hafnium provides support for fragmented transmission 1090cc63ff97SJ-Alvesof the full transaction descriptor. The ``FFA_MEM_FRAG_RX`` and ``FFA_MEM_FRAG_TX`` 1091cc63ff97SJ-Alvesinterfaces are for receiving and transmitting the next fragment, respectively. 1092cc63ff97SJ-Alves 1093cc63ff97SJ-AlvesIf lender and borrower(s) are SPs, all memory sharing operations are supported. 1094cc63ff97SJ-Alves 1095cc63ff97SJ-AlvesHafnium also supports memory sharing operations between the normal world and the 1096cc63ff97SJ-Alvessecure world. If there is an SP involved, the SPMC allocates data to track the 1097cc63ff97SJ-Alvesstate of the operation. 1098cc63ff97SJ-Alves 1099cc63ff97SJ-AlvesThe SPMC is also the designated allocator for the memory handle. The hypervisor 1100cc63ff97SJ-Alvesor OS kernel has the possibility to rely on the SPMC to maintain the state 1101cc63ff97SJ-Alvesof the operation, thus saving memory. 1102cc63ff97SJ-AlvesA lender SP can only donate NS memory to a borrower from the normal world. 1103cc63ff97SJ-Alves 1104cc63ff97SJ-AlvesThe SPMC supports the hypervisor retrieve request, as defined by the FF-A 1105cc63ff97SJ-Alvesv1.1 EAC0 specification, in section 16.4.3. The intent is to aid with operations 1106cc63ff97SJ-Alvesthat the hypervisor must do for a VM retriever. For example, when handling 1107cc63ff97SJ-Alvesan FFA_MEM_RECLAIM, if the hypervisor relies on SPMC to keep the state 1108cc63ff97SJ-Alvesof the operation, the hypervisor retrieve request can be used to obtain 1109cc63ff97SJ-Alvesthat state information, do the necessary validations, and update stage 2 1110cc63ff97SJ-Alvesmemory translation. 1111cc63ff97SJ-Alves 1112cc63ff97SJ-AlvesHafnium also supports memory lend and share targetting multiple borrowers. 1113cc63ff97SJ-AlvesThis is the case for a lender SP to multiple SPs, and for a lender VM to 1114cc63ff97SJ-Alvesmultiple endpoints (from both secure world and normal world). If there is 1115cc63ff97SJ-Alvesat least one borrower VM, the hypervisor is in charge of managing its 1116cc63ff97SJ-Alvesstage 2 translation on a successful memory retrieve. 1117cc63ff97SJ-AlvesThe semantics of ``FFA_MEM_DONATE`` implies ownership transmission, 1118cc63ff97SJ-Alveswhich should target only one partition. 1119cc63ff97SJ-Alves 1120cc63ff97SJ-AlvesThe memory share interfaces are backwards compatible with memory transaction 1121cc63ff97SJ-Alvesdescriptors from FF-A v1.0. These get translated to FF-A v1.1 descriptors for 1122cc63ff97SJ-AlvesHafnium's internal processing of the operation. If the FF-A version of a 1123cc63ff97SJ-Alvesborrower is v1.0, Hafnium provides FF-A v1.0 compliant memory transaction 1124cc63ff97SJ-Alvesdescriptors on memory retrieve response. 1125cc63ff97SJ-Alves 1126b5dd2422SOlivier DeprezPE MMU configuration 1127b5dd2422SOlivier Deprez-------------------- 1128fcb1398fSOlivier Deprez 11299eea92a1SOlivier DeprezWith secure virtualization enabled (``HCR_EL2.VM = 1``) and for S-EL1 11309eea92a1SOlivier Deprezpartitions, two IPA spaces (secure and non-secure) are output from the 11319eea92a1SOlivier Deprezsecure EL1&0 Stage-1 translation. 11329eea92a1SOlivier DeprezThe EL1&0 Stage-2 translation hardware is fed by: 1133fcb1398fSOlivier Deprez 11349eea92a1SOlivier Deprez- A secure IPA when the SP EL1&0 Stage-1 MMU is disabled. 11359eea92a1SOlivier Deprez- One of secure or non-secure IPA when the secure EL1&0 Stage-1 MMU is enabled. 1136fcb1398fSOlivier Deprez 1137b5dd2422SOlivier Deprez``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the 11389eea92a1SOlivier DeprezNS/S IPA translations. The following controls are set up: 11399eea92a1SOlivier Deprez``VSTCR_EL2.SW = 0`` , ``VSTCR_EL2.SA = 0``, ``VTCR_EL2.NSW = 0``, 11409eea92a1SOlivier Deprez``VTCR_EL2.NSA = 1``: 1141fcb1398fSOlivier Deprez 1142b5dd2422SOlivier Deprez- Stage-2 translations for the NS IPA space access the NS PA space. 1143b5dd2422SOlivier Deprez- Stage-2 translation table walks for the NS IPA space are to the secure PA space. 1144fcb1398fSOlivier Deprez 11459eea92a1SOlivier DeprezSecure and non-secure IPA regions (rooted to by ``VTTBR_EL2`` and ``VSTTBR_EL2``) 11469eea92a1SOlivier Deprezuse the same set of Stage-2 page tables within a SP. 11479eea92a1SOlivier Deprez 11489eea92a1SOlivier DeprezThe ``VTCR_EL2/VSTCR_EL2/VTTBR_EL2/VSTTBR_EL2`` virtual address space 11499eea92a1SOlivier Deprezconfiguration is made part of a vCPU context. 11509eea92a1SOlivier Deprez 11519eea92a1SOlivier DeprezFor S-EL0 partitions with VHE enabled, a single secure EL2&0 Stage-1 translation 11529eea92a1SOlivier Deprezregime is used for both Hafnium and the partition. 1153fcb1398fSOlivier Deprez 115403997f18SMadhukar PappireddySchedule modes and SP Call chains 115503997f18SMadhukar Pappireddy--------------------------------- 115603997f18SMadhukar Pappireddy 115703997f18SMadhukar PappireddyAn SP execution context is said to be in SPMC scheduled mode if CPU cycles are 115803997f18SMadhukar Pappireddyallocated to it by SPMC. Correspondingly, an SP execution context is said to be 115903997f18SMadhukar Pappireddyin Normal world scheduled mode if CPU cycles are allocated by the normal world. 116003997f18SMadhukar Pappireddy 116103997f18SMadhukar PappireddyA call chain represents all SPs in a sequence of invocations of a direct message 116203997f18SMadhukar Pappireddyrequest. When execution on a PE is in the secure state, only a single call chain 116303997f18SMadhukar Pappireddythat runs in the Normal World scheduled mode can exist. FF-A v1.1 spec allows 116403997f18SMadhukar Pappireddyany number of call chains to run in the SPMC scheduled mode but the Hafnium 116503997f18SMadhukar PappireddySPMC restricts the number of call chains in SPMC scheduled mode to only one for 116603997f18SMadhukar Pappireddykeeping the implementation simple. 116703997f18SMadhukar Pappireddy 116803997f18SMadhukar PappireddyPartition runtime models 116903997f18SMadhukar Pappireddy------------------------ 117003997f18SMadhukar Pappireddy 117103997f18SMadhukar PappireddyThe runtime model of an endpoint describes the transitions permitted for an 117203997f18SMadhukar Pappireddyexecution context between various states. These are the four partition runtime 117303997f18SMadhukar Pappireddymodels supported (refer to `[1]`_ section 7): 117403997f18SMadhukar Pappireddy 117503997f18SMadhukar Pappireddy - RTM_FFA_RUN: runtime model presented to an execution context that is 117603997f18SMadhukar Pappireddy allocated CPU cycles through FFA_RUN interface. 117703997f18SMadhukar Pappireddy - RTM_FFA_DIR_REQ: runtime model presented to an execution context that is 117803997f18SMadhukar Pappireddy allocated CPU cycles through FFA_MSG_SEND_DIRECT_REQ interface. 117903997f18SMadhukar Pappireddy - RTM_SEC_INTERRUPT: runtime model presented to an execution context that is 118003997f18SMadhukar Pappireddy allocated CPU cycles by SPMC to handle a secure interrupt. 118103997f18SMadhukar Pappireddy - RTM_SP_INIT: runtime model presented to an execution context that is 118203997f18SMadhukar Pappireddy allocated CPU cycles by SPMC to initialize its state. 118303997f18SMadhukar Pappireddy 118403997f18SMadhukar PappireddyIf an endpoint execution context attempts to make an invalid transition or a 118503997f18SMadhukar Pappireddyvalid transition that could lead to a loop in the call chain, SPMC denies the 118603997f18SMadhukar Pappireddytransition with the help of above runtime models. 118703997f18SMadhukar Pappireddy 1188fcb1398fSOlivier DeprezInterrupt management 1189fcb1398fSOlivier Deprez-------------------- 1190fcb1398fSOlivier Deprez 1191b5dd2422SOlivier DeprezGIC ownership 1192b5dd2422SOlivier Deprez~~~~~~~~~~~~~ 1193fcb1398fSOlivier Deprez 1194b5dd2422SOlivier DeprezThe SPMC owns the GIC configuration. Secure and non-secure interrupts are 1195b5dd2422SOlivier Depreztrapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt 1196b5dd2422SOlivier DeprezIDs based on SP manifests. The SPMC acknowledges physical interrupts and injects 1197b5dd2422SOlivier Deprezvirtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP. 1198fcb1398fSOlivier Deprez 119906afdd1eSMadhukar PappireddyAbbreviations: 120006afdd1eSMadhukar Pappireddy 120106afdd1eSMadhukar Pappireddy - NS-Int: A non-secure physical interrupt. It requires a switch to the normal 120206afdd1eSMadhukar Pappireddy world to be handled if it triggers while execution is in secure world. 120306afdd1eSMadhukar Pappireddy - Other S-Int: A secure physical interrupt targeted to an SP different from 120406afdd1eSMadhukar Pappireddy the one that is currently running. 120506afdd1eSMadhukar Pappireddy - Self S-Int: A secure physical interrupt targeted to the SP that is currently 120606afdd1eSMadhukar Pappireddy running. 120706afdd1eSMadhukar Pappireddy 1208b5dd2422SOlivier DeprezNon-secure interrupt handling 1209b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1210fcb1398fSOlivier Deprez 121106afdd1eSMadhukar PappireddyThis section documents the actions supported in SPMC in response to a non-secure 121206afdd1eSMadhukar Pappireddyinterrupt as per the guidance provided by FF-A v1.1 EAC0 specification. 121306afdd1eSMadhukar PappireddyAn SP specifies one of the following actions in its partition manifest: 1214fcb1398fSOlivier Deprez 121506afdd1eSMadhukar Pappireddy - Non-secure interrupt is signaled. 121606afdd1eSMadhukar Pappireddy - Non-secure interrupt is signaled after a managed exit. 121706afdd1eSMadhukar Pappireddy - Non-secure interrupt is queued. 1218b5dd2422SOlivier Deprez 121906afdd1eSMadhukar PappireddyAn SP execution context in a call chain could specify a less permissive action 122006afdd1eSMadhukar Pappireddythan subsequent SP execution contexts in the same call chain. The less 122106afdd1eSMadhukar Pappireddypermissive action takes precedence over the more permissive actions specified 122206afdd1eSMadhukar Pappireddyby the subsequent execution contexts. Please refer to FF-A v1.1 EAC0 section 122306afdd1eSMadhukar Pappireddy8.3.1 for further explanation. 1224b5dd2422SOlivier Deprez 1225b5dd2422SOlivier DeprezSecure interrupt handling 122606afdd1eSMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~ 1227b5dd2422SOlivier Deprez 122852558e08SMadhukar PappireddyThis section documents the support implemented for secure interrupt handling in 122906afdd1eSMadhukar PappireddySPMC as per the guidance provided by FF-A v1.1 EAC0 specification. 123052558e08SMadhukar PappireddyThe following assumptions are made about the system configuration: 123152558e08SMadhukar Pappireddy 123252558e08SMadhukar Pappireddy - In the current implementation, S-EL1 SPs are expected to use the para 123306afdd1eSMadhukar Pappireddy virtualized ABIs for interrupt management rather than accessing the virtual 123406afdd1eSMadhukar Pappireddy GIC interface. 123552558e08SMadhukar Pappireddy - Unless explicitly stated otherwise, this support is applicable only for 123652558e08SMadhukar Pappireddy S-EL1 SPs managed by SPMC. 123752558e08SMadhukar Pappireddy - Secure interrupts are configured as G1S or G0 interrupts. 123852558e08SMadhukar Pappireddy - All physical interrupts are routed to SPMC when running a secure partition 123952558e08SMadhukar Pappireddy execution context. 124006afdd1eSMadhukar Pappireddy - All endpoints with multiple execution contexts have their contexts pinned 124106afdd1eSMadhukar Pappireddy to corresponding CPUs. Hence, a secure virtual interrupt cannot be signaled 124206afdd1eSMadhukar Pappireddy to a target vCPU that is currently running or blocked on a different 124306afdd1eSMadhukar Pappireddy physical CPU. 124452558e08SMadhukar Pappireddy 124506afdd1eSMadhukar PappireddyA physical secure interrupt could trigger while CPU is executing in normal world 124606afdd1eSMadhukar Pappireddyor secure world. 124706afdd1eSMadhukar PappireddyThe action of SPMC for a secure interrupt depends on: the state of the target 124806afdd1eSMadhukar Pappireddyexecution context of the SP that is responsible for handling the interrupt; 124906afdd1eSMadhukar Pappireddywhether the interrupt triggered while execution was in normal world or secure 125006afdd1eSMadhukar Pappireddyworld. 125152558e08SMadhukar Pappireddy 125252558e08SMadhukar PappireddySecure interrupt signaling mechanisms 125352558e08SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 125452558e08SMadhukar Pappireddy 125552558e08SMadhukar PappireddySignaling refers to the mechanisms used by SPMC to indicate to the SP execution 125652558e08SMadhukar Pappireddycontext that it has a pending virtual interrupt and to further run the SP 125752558e08SMadhukar Pappireddyexecution context, such that it can handle the virtual interrupt. SPMC uses 125852558e08SMadhukar Pappireddyeither the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling 125952558e08SMadhukar Pappireddyto S-EL1 SPs. When normal world execution is preempted by a secure interrupt, 126052558e08SMadhukar Pappireddythe SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC 126152558e08SMadhukar Pappireddyrunning in S-EL2. 126252558e08SMadhukar Pappireddy 126352558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 126452558e08SMadhukar Pappireddy| SP State | Conduit | Interface and | Description | 126552558e08SMadhukar Pappireddy| | | parameters | | 126652558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 126752558e08SMadhukar Pappireddy| WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending | 126852558e08SMadhukar Pappireddy| | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and | 126952558e08SMadhukar Pappireddy| | | | resumes execution context of SP | 127052558e08SMadhukar Pappireddy| | | | through ERET. | 127152558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 127252558e08SMadhukar Pappireddy| BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt | 127352558e08SMadhukar Pappireddy| | vIRQ | | is pending. It pends vIRQ signal and | 127452558e08SMadhukar Pappireddy| | | | resumes execution context of SP | 127552558e08SMadhukar Pappireddy| | | | through ERET. | 127652558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 127752558e08SMadhukar Pappireddy| PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does | 127852558e08SMadhukar Pappireddy| | | | not resume execution context of SP. | 127952558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 128052558e08SMadhukar Pappireddy| RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes| 128152558e08SMadhukar Pappireddy| | vIRQ | | execution context of SP through ERET. | 128252558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+ 128352558e08SMadhukar Pappireddy 128452558e08SMadhukar PappireddySecure interrupt completion mechanisms 128552558e08SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 128652558e08SMadhukar Pappireddy 128752558e08SMadhukar PappireddyA SP signals secure interrupt handling completion to the SPMC through the 128852558e08SMadhukar Pappireddyfollowing mechanisms: 128952558e08SMadhukar Pappireddy 129052558e08SMadhukar Pappireddy - ``FFA_MSG_WAIT`` ABI if it was in WAITING state. 129152558e08SMadhukar Pappireddy - ``FFA_RUN`` ABI if its was in BLOCKED state. 129252558e08SMadhukar Pappireddy 129306afdd1eSMadhukar PappireddyThis is a remnant of SPMC implementation based on the FF-A v1.0 specification. 129406afdd1eSMadhukar PappireddyIn the current implementation, S-EL1 SPs use the para-virtualized HVC interface 129506afdd1eSMadhukar Pappireddyimplemented by SPMC to perform priority drop and interrupt deactivation (SPMC 129606afdd1eSMadhukar Pappireddyconfigures EOImode = 0, i.e. priority drop and deactivation are done together). 129706afdd1eSMadhukar PappireddyThe SPMC performs checks to deny the state transition upon invocation of 129806afdd1eSMadhukar Pappireddyeither FFA_MSG_WAIT or FFA_RUN interface if the SP didn't perform the 129906afdd1eSMadhukar Pappireddydeactivation of the secure virtual interrupt. 130052558e08SMadhukar Pappireddy 130106afdd1eSMadhukar PappireddyIf the current SP execution context was preempted by a secure interrupt to be 130206afdd1eSMadhukar Pappireddyhandled by execution context of target SP, SPMC resumes current SP after signal 130306afdd1eSMadhukar Pappireddycompletion by target SP execution context. 130406afdd1eSMadhukar Pappireddy 130506afdd1eSMadhukar PappireddyActions for a secure interrupt triggered while execution is in normal world 130606afdd1eSMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 130706afdd1eSMadhukar Pappireddy 130806afdd1eSMadhukar Pappireddy+-------------------+----------+-----------------------------------------------+ 130906afdd1eSMadhukar Pappireddy| State of target | Action | Description | 131006afdd1eSMadhukar Pappireddy| execution context | | | 131106afdd1eSMadhukar Pappireddy+-------------------+----------+-----------------------------------------------+ 131206afdd1eSMadhukar Pappireddy| WAITING | Signaled | This starts a new call chain in SPMC scheduled| 131306afdd1eSMadhukar Pappireddy| | | mode. | 131406afdd1eSMadhukar Pappireddy+-------------------+----------+-----------------------------------------------+ 131506afdd1eSMadhukar Pappireddy| PREEMPTED | Queued | The target execution must have been preempted | 131606afdd1eSMadhukar Pappireddy| | | by a non-secure interrupt. SPMC queues the | 131706afdd1eSMadhukar Pappireddy| | | secure virtual interrupt now. It is signaled | 131806afdd1eSMadhukar Pappireddy| | | when the target execution context next enters | 131906afdd1eSMadhukar Pappireddy| | | the RUNNING state. | 132006afdd1eSMadhukar Pappireddy+-------------------+----------+-----------------------------------------------+ 132106afdd1eSMadhukar Pappireddy| BLOCKED, RUNNING | NA | The target execution context is blocked or | 132206afdd1eSMadhukar Pappireddy| | | running on a different CPU. This is not | 132306afdd1eSMadhukar Pappireddy| | | supported by current SPMC implementation and | 132406afdd1eSMadhukar Pappireddy| | | execution hits panic. | 132506afdd1eSMadhukar Pappireddy+-------------------+----------+-----------------------------------------------+ 132606afdd1eSMadhukar Pappireddy 132706afdd1eSMadhukar PappireddyIf normal world execution was preempted by a secure interrupt, SPMC uses 132852558e08SMadhukar PappireddyFFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling 132906afdd1eSMadhukar Pappireddyand further returns execution to normal world. 133052558e08SMadhukar Pappireddy 133106afdd1eSMadhukar PappireddyThe following figure describes interrupt handling flow when a secure interrupt 133206afdd1eSMadhukar Pappireddytriggers while execution is in normal world: 133352558e08SMadhukar Pappireddy 133452558e08SMadhukar Pappireddy.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png 133552558e08SMadhukar Pappireddy 133652558e08SMadhukar PappireddyA brief description of the events: 133752558e08SMadhukar Pappireddy 133852558e08SMadhukar Pappireddy - 1) Secure interrupt triggers while normal world is running. 133952558e08SMadhukar Pappireddy - 2) FIQ gets trapped to EL3. 134052558e08SMadhukar Pappireddy - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI. 134152558e08SMadhukar Pappireddy - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends 134252558e08SMadhukar Pappireddy vIRQ). 134306afdd1eSMadhukar Pappireddy - 5) Assuming SP1 vCPU is in WAITING state, SPMC signals virtual interrupt 134406afdd1eSMadhukar Pappireddy using FFA_INTERRUPT with interrupt id as an argument and resumes the SP1 134506afdd1eSMadhukar Pappireddy vCPU using ERET in SPMC scheduled mode. 134606afdd1eSMadhukar Pappireddy - 6) Execution traps to vIRQ handler in SP1 provided that the virtual 134706afdd1eSMadhukar Pappireddy interrupt is not masked i.e., PSTATE.I = 0 134806afdd1eSMadhukar Pappireddy - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized 134906afdd1eSMadhukar Pappireddy HVC call. SPMC clears the pending virtual interrupt state management 135006afdd1eSMadhukar Pappireddy and returns the pending virtual interrupt id. 135106afdd1eSMadhukar Pappireddy - 8) SP1 services the virtual interrupt and invokes the paravirtualized 135206afdd1eSMadhukar Pappireddy de-activation HVC call. SPMC de-activates the physical interrupt, 135306afdd1eSMadhukar Pappireddy clears the fields tracking the secure interrupt and resumes SP1 vCPU. 135406afdd1eSMadhukar Pappireddy - 9) SP1 performs secure interrupt completion through FFA_MSG_WAIT ABI. 135552558e08SMadhukar Pappireddy - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME. 135652558e08SMadhukar Pappireddy - 11) EL3 resumes normal world execution. 135752558e08SMadhukar Pappireddy 135806afdd1eSMadhukar PappireddyActions for a secure interrupt triggered while execution is in secure world 135906afdd1eSMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 136006afdd1eSMadhukar Pappireddy 136106afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 136206afdd1eSMadhukar Pappireddy| State of target | Action | Description | 136306afdd1eSMadhukar Pappireddy| execution context | | | 136406afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 136506afdd1eSMadhukar Pappireddy| WAITING | Signaled | This starts a new call chain in SPMC scheduled | 136606afdd1eSMadhukar Pappireddy| | | mode. | 136706afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 136806afdd1eSMadhukar Pappireddy| PREEMPTED by Self | Signaled | The target execution context reenters the | 136906afdd1eSMadhukar Pappireddy| S-Int | | RUNNING state to handle the secure virtual | 137006afdd1eSMadhukar Pappireddy| | | interrupt. | 137106afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 137206afdd1eSMadhukar Pappireddy| PREEMPTED by | Queued | SPMC queues the secure virtual interrupt now. | 137306afdd1eSMadhukar Pappireddy| NS-Int | | It is signaled when the target execution | 137406afdd1eSMadhukar Pappireddy| | | context next enters the RUNNING state. | 137506afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 137606afdd1eSMadhukar Pappireddy| BLOCKED | Signaled | Both preempted and target execution contexts | 137706afdd1eSMadhukar Pappireddy| | | must have been part of the Normal world | 137806afdd1eSMadhukar Pappireddy| | | scheduled call chain. Refer scenario 1 of | 137906afdd1eSMadhukar Pappireddy| | | Table 8.4 in the FF-A v1.1 EAC0 spec. | 138006afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 138106afdd1eSMadhukar Pappireddy| RUNNING | NA | The target execution context is running on a | 138206afdd1eSMadhukar Pappireddy| | | different CPU. This scenario is not supported | 138306afdd1eSMadhukar Pappireddy| | | by current SPMC implementation and execution | 138406afdd1eSMadhukar Pappireddy| | | hits panic. | 138506afdd1eSMadhukar Pappireddy+-------------------+----------+------------------------------------------------+ 138606afdd1eSMadhukar Pappireddy 138706afdd1eSMadhukar PappireddyThe following figure describes interrupt handling flow when a secure interrupt 138806afdd1eSMadhukar Pappireddytriggers while execution is in secure world. We assume OS kernel sends a direct 138906afdd1eSMadhukar Pappireddyrequest message to SP1. Further, SP1 sends a direct request message to SP2. SP1 139006afdd1eSMadhukar Pappireddyenters BLOCKED state and SPMC resumes SP2. 139152558e08SMadhukar Pappireddy 139252558e08SMadhukar Pappireddy.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png 139352558e08SMadhukar Pappireddy 139452558e08SMadhukar PappireddyA brief description of the events: 139552558e08SMadhukar Pappireddy 139606afdd1eSMadhukar Pappireddy - 1) Secure interrupt triggers while SP2 is running. 139706afdd1eSMadhukar Pappireddy - 2) SP2 gets preempted and execution traps to SPMC as IRQ. 139852558e08SMadhukar Pappireddy - 3) SPMC finds the target vCPU of secure partition responsible for handling 139952558e08SMadhukar Pappireddy this secure interrupt. In this scenario, it is SP1. 140052558e08SMadhukar Pappireddy - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface. 140106afdd1eSMadhukar Pappireddy SPMC further resumes SP1 through ERET conduit. Note that SP1 remains in 140206afdd1eSMadhukar Pappireddy Normal world schedule mode. 140306afdd1eSMadhukar Pappireddy - 6) Execution traps to vIRQ handler in SP1 provided that the virtual 140406afdd1eSMadhukar Pappireddy interrupt is not masked i.e., PSTATE.I = 0 140506afdd1eSMadhukar Pappireddy - 7) SP1 queries for the pending virtual interrupt id using a paravirtualized 140606afdd1eSMadhukar Pappireddy HVC call. SPMC clears the pending virtual interrupt state management 140706afdd1eSMadhukar Pappireddy and returns the pending virtual interrupt id. 140806afdd1eSMadhukar Pappireddy - 8) SP1 services the virtual interrupt and invokes the paravirtualized 140906afdd1eSMadhukar Pappireddy de-activation HVC call. SPMC de-activates the physical interrupt and 141006afdd1eSMadhukar Pappireddy clears the fields tracking the secure interrupt and resumes SP1 vCPU. 141106afdd1eSMadhukar Pappireddy - 9) Since SP1 direct request completed with FFA_INTERRUPT, it resumes the 141206afdd1eSMadhukar Pappireddy direct request to SP2 by invoking FFA_RUN. 141352558e08SMadhukar Pappireddy - 9) SPMC resumes the pre-empted vCPU of SP2. 141452558e08SMadhukar Pappireddy 1415e6017291SMadhukar PappireddyEL3 interrupt handling 1416e6017291SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~ 1417e6017291SMadhukar Pappireddy 1418e6017291SMadhukar PappireddyIn GICv3 based systems, EL3 interrupts are configured as Group0 secure 1419e6017291SMadhukar Pappireddyinterrupts. Execution traps to SPMC when a Group0 interrupt triggers while an 1420e6017291SMadhukar PappireddySP is running. Further, SPMC running at S-EL2 uses FFA_EL3_INTR_HANDLE ABI to 1421e6017291SMadhukar Pappireddyrequest EL3 platform firmware to handle a pending Group0 interrupt. 1422e6017291SMadhukar PappireddySimilarly, SPMD registers a handler with interrupt management framework to 1423e6017291SMadhukar Pappireddydelegate handling of Group0 interrupt to the platform if the interrupt triggers 1424e6017291SMadhukar Pappireddyin normal world. 1425e6017291SMadhukar Pappireddy 1426e6017291SMadhukar Pappireddy - Platform hook 1427e6017291SMadhukar Pappireddy 1428e6017291SMadhukar Pappireddy - plat_spmd_handle_group0_interrupt 1429e6017291SMadhukar Pappireddy 1430e6017291SMadhukar Pappireddy SPMD provides platform hook to handle Group0 secure interrupts. In the 1431e6017291SMadhukar Pappireddy current design, SPMD expects the platform not to delegate handling to the 1432e6017291SMadhukar Pappireddy NWd (such as through SDEI) while processing Group0 interrupts. 1433e6017291SMadhukar Pappireddy 1434fcb1398fSOlivier DeprezPower management 1435fcb1398fSOlivier Deprez---------------- 1436fcb1398fSOlivier Deprez 1437b5dd2422SOlivier DeprezIn platforms with or without secure virtualization: 1438fcb1398fSOlivier Deprez 1439b5dd2422SOlivier Deprez- The NWd owns the platform PM policy. 1440b5dd2422SOlivier Deprez- The Hypervisor or OS kernel is the component initiating PSCI service calls. 1441b5dd2422SOlivier Deprez- The EL3 PSCI library is in charge of the PM coordination and control 1442b5dd2422SOlivier Deprez (eventually writing to platform registers). 1443b5dd2422SOlivier Deprez- While coordinating PM events, the PSCI library calls backs into the Secure 1444b5dd2422SOlivier Deprez Payload Dispatcher for events the latter has statically registered to. 1445fcb1398fSOlivier Deprez 1446b5dd2422SOlivier DeprezWhen using the SPMD as a Secure Payload Dispatcher: 1447fcb1398fSOlivier Deprez 1448b5dd2422SOlivier Deprez- A power management event is relayed through the SPD hook to the SPMC. 1449b5dd2422SOlivier Deprez- In the current implementation only cpu on (svc_on_finish) and cpu off 1450b5dd2422SOlivier Deprez (svc_off) hooks are registered. 1451b5dd2422SOlivier Deprez- The behavior for the cpu on event is described in `Secondary cores boot-up`_. 1452b5dd2422SOlivier Deprez The SPMC is entered through its secondary physical core entry point. 14539eea92a1SOlivier Deprez- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The PM event is 14549eea92a1SOlivier Deprez signaled to the SPMC through a power management framework message. 14559eea92a1SOlivier Deprez It consists in a SPMD-to-SPMC direct request/response (`SPMC-SPMD direct 14569eea92a1SOlivier Deprez requests/responses`_) conveying the event details and SPMC response. 1457b5dd2422SOlivier Deprez The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and 1458b5dd2422SOlivier Deprez updates its internal state to reflect the physical core is being turned off. 1459b5dd2422SOlivier Deprez In the current implementation no SP is resumed as a consequence. This behavior 1460b5dd2422SOlivier Deprez ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux 1461b5dd2422SOlivier Deprez userspace. 1462fcb1398fSOlivier Deprez 14639eea92a1SOlivier DeprezArm architecture extensions for security hardening 14649eea92a1SOlivier Deprez================================================== 14659eea92a1SOlivier Deprez 14669eea92a1SOlivier DeprezHafnium supports the following architecture extensions for security hardening: 14679eea92a1SOlivier Deprez 14689eea92a1SOlivier Deprez- Pointer authentication (FEAT_PAuth): the extension permits detection of forged 14699eea92a1SOlivier Deprez pointers used by ROP type of attacks through the signing of the pointer 14709eea92a1SOlivier Deprez value. Hafnium is built with the compiler branch protection option to permit 14719eea92a1SOlivier Deprez generation of a pointer authentication code for return addresses (pointer 14729eea92a1SOlivier Deprez authentication for instructions). The APIA key is used while Hafnium runs. 14739eea92a1SOlivier Deprez A random key is generated at boot time and restored upon entry into Hafnium 14749eea92a1SOlivier Deprez at run-time. APIA and other keys (APIB, APDA, APDB, APGA) are saved/restored 14759eea92a1SOlivier Deprez in vCPU contexts permitting to enable pointer authentication in VMs/SPs. 14769eea92a1SOlivier Deprez- Branch Target Identification (FEAT_BTI): the extension permits detection of 14779eea92a1SOlivier Deprez unexpected indirect branches used by JOP type of attacks. Hafnium is built 14789eea92a1SOlivier Deprez with the compiler branch protection option, inserting land pads at function 14799eea92a1SOlivier Deprez prologues that are reached by indirect branch instructions (BR/BLR). 14809eea92a1SOlivier Deprez Hafnium code pages are marked as guarded in the EL2 Stage-1 MMU descriptors 14819eea92a1SOlivier Deprez such that an indirect branch must always target a landpad. A fault is 14829eea92a1SOlivier Deprez triggered otherwise. VMs/SPs can (independently) mark their code pages as 14839eea92a1SOlivier Deprez guarded in the EL1&0 Stage-1 translation regime. 14849eea92a1SOlivier Deprez- Memory Tagging Extension (FEAT_MTE): the option permits detection of out of 14859eea92a1SOlivier Deprez bound memory array accesses or re-use of an already freed memory region. 14869eea92a1SOlivier Deprez Hafnium enables the compiler option permitting to leverage MTE stack tagging 14879eea92a1SOlivier Deprez applied to core stacks. Core stacks are marked as normal tagged memory in the 14889eea92a1SOlivier Deprez EL2 Stage-1 translation regime. A synchronous data abort is generated upon tag 14899eea92a1SOlivier Deprez check failure on load/stores. A random seed is generated at boot time and 14909eea92a1SOlivier Deprez restored upon entry into Hafnium. MTE system registers are saved/restored in 14919eea92a1SOlivier Deprez vCPU contexts permitting MTE usage from VMs/SPs. 14929eea92a1SOlivier Deprez 1493b5dd2422SOlivier DeprezSMMUv3 support in Hafnium 1494b5dd2422SOlivier Deprez========================= 14954ec3ccb4SMadhukar Pappireddy 14964ec3ccb4SMadhukar PappireddyAn SMMU is analogous to an MMU in a CPU. It performs address translations for 14974ec3ccb4SMadhukar PappireddyDirect Memory Access (DMA) requests from system I/O devices. 14984ec3ccb4SMadhukar PappireddyThe responsibilities of an SMMU include: 14994ec3ccb4SMadhukar Pappireddy 15004ec3ccb4SMadhukar Pappireddy- Translation: Incoming DMA requests are translated from bus address space to 15014ec3ccb4SMadhukar Pappireddy system physical address space using translation tables compliant to 15024ec3ccb4SMadhukar Pappireddy Armv8/Armv7 VMSA descriptor format. 15034ec3ccb4SMadhukar Pappireddy- Protection: An I/O device can be prohibited from read, write access to a 15044ec3ccb4SMadhukar Pappireddy memory region or allowed. 15054ec3ccb4SMadhukar Pappireddy- Isolation: Traffic from each individial device can be independently managed. 15064ec3ccb4SMadhukar Pappireddy The devices are differentiated from each other using unique translation 15074ec3ccb4SMadhukar Pappireddy tables. 15084ec3ccb4SMadhukar Pappireddy 15094ec3ccb4SMadhukar PappireddyThe following diagram illustrates a typical SMMU IP integrated in a SoC with 15104ec3ccb4SMadhukar Pappireddyseveral I/O devices along with Interconnect and Memory system. 15114ec3ccb4SMadhukar Pappireddy 15124ec3ccb4SMadhukar Pappireddy.. image:: ../resources/diagrams/MMU-600.png 15134ec3ccb4SMadhukar Pappireddy 15144ec3ccb4SMadhukar PappireddySMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides 1515b5dd2422SOlivier Deprezsupport for SMMUv3 driver in both normal and secure world. A brief introduction 15164ec3ccb4SMadhukar Pappireddyof SMMUv3 functionality and the corresponding software support in Hafnium is 15174ec3ccb4SMadhukar Pappireddyprovided here. 15184ec3ccb4SMadhukar Pappireddy 15194ec3ccb4SMadhukar PappireddySMMUv3 features 15204ec3ccb4SMadhukar Pappireddy--------------- 15214ec3ccb4SMadhukar Pappireddy 15224ec3ccb4SMadhukar Pappireddy- SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2) 15234ec3ccb4SMadhukar Pappireddy translation support. It can either bypass or abort incoming translations as 15244ec3ccb4SMadhukar Pappireddy well. 15254ec3ccb4SMadhukar Pappireddy- Traffic (memory transactions) from each upstream I/O peripheral device, 15264ec3ccb4SMadhukar Pappireddy referred to as Stream, can be independently managed using a combination of 15274ec3ccb4SMadhukar Pappireddy several memory based configuration structures. This allows the SMMUv3 to 15284ec3ccb4SMadhukar Pappireddy support a large number of streams with each stream assigned to a unique 15294ec3ccb4SMadhukar Pappireddy translation context. 15304ec3ccb4SMadhukar Pappireddy- Support for Armv8.1 VMSA where the SMMU shares the translation tables with 15314ec3ccb4SMadhukar Pappireddy a Processing Element. AArch32(LPAE) and AArch64 translation table format 15324ec3ccb4SMadhukar Pappireddy are supported by SMMUv3. 15334ec3ccb4SMadhukar Pappireddy- SMMUv3 offers non-secure stream support with secure stream support being 15344ec3ccb4SMadhukar Pappireddy optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU 15354ec3ccb4SMadhukar Pappireddy instance for secure and non-secure stream support. 15364ec3ccb4SMadhukar Pappireddy- It also supports sub-streams to differentiate traffic from a virtualized 15374ec3ccb4SMadhukar Pappireddy peripheral associated with a VM/SP. 15384ec3ccb4SMadhukar Pappireddy- Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A 15394ec3ccb4SMadhukar Pappireddy extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2 15404ec3ccb4SMadhukar Pappireddy for providing Secure Stage2 translation support to upstream peripheral 15414ec3ccb4SMadhukar Pappireddy devices. 15424ec3ccb4SMadhukar Pappireddy 15434ec3ccb4SMadhukar PappireddySMMUv3 Programming Interfaces 15444ec3ccb4SMadhukar Pappireddy----------------------------- 15454ec3ccb4SMadhukar Pappireddy 15464ec3ccb4SMadhukar PappireddySMMUv3 has three software interfaces that are used by the Hafnium driver to 15474ec3ccb4SMadhukar Pappireddyconfigure the behaviour of SMMUv3 and manage the streams. 15484ec3ccb4SMadhukar Pappireddy 15494ec3ccb4SMadhukar Pappireddy- Memory based data strutures that provide unique translation context for 15504ec3ccb4SMadhukar Pappireddy each stream. 15514ec3ccb4SMadhukar Pappireddy- Memory based circular buffers for command queue and event queue. 15524ec3ccb4SMadhukar Pappireddy- A large number of SMMU configuration registers that are memory mapped during 15534ec3ccb4SMadhukar Pappireddy boot time by Hafnium driver. Except a few registers, all configuration 15544ec3ccb4SMadhukar Pappireddy registers have independent secure and non-secure versions to configure the 15554ec3ccb4SMadhukar Pappireddy behaviour of SMMUv3 for translation of secure and non-secure streams 15564ec3ccb4SMadhukar Pappireddy respectively. 15574ec3ccb4SMadhukar Pappireddy 15584ec3ccb4SMadhukar PappireddyPeripheral device manifest 15594ec3ccb4SMadhukar Pappireddy-------------------------- 15604ec3ccb4SMadhukar Pappireddy 15614ec3ccb4SMadhukar PappireddyCurrently, SMMUv3 driver in Hafnium only supports dependent peripheral devices. 15624ec3ccb4SMadhukar PappireddyThese devices are dependent on PE endpoint to initiate and receive memory 15634ec3ccb4SMadhukar Pappireddymanagement transactions on their behalf. The acccess to the MMIO regions of 15644ec3ccb4SMadhukar Pappireddyany such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver 15654ec3ccb4SMadhukar Pappireddyuses the same stage 2 translations for the device as those used by partition 15664ec3ccb4SMadhukar Pappireddymanager on behalf of the PE endpoint. This ensures that the peripheral device 15674ec3ccb4SMadhukar Pappireddyhas the same visibility of the physical address space as the endpoint. The 15684ec3ccb4SMadhukar Pappireddydevice node of the corresponding partition manifest (refer to `[1]`_ section 3.2 15694ec3ccb4SMadhukar Pappireddy) must specify these additional properties for each peripheral device in the 15704ec3ccb4SMadhukar Pappireddysystem : 15714ec3ccb4SMadhukar Pappireddy 15724ec3ccb4SMadhukar Pappireddy- smmu-id: This field helps to identify the SMMU instance that this device is 15734ec3ccb4SMadhukar Pappireddy upstream of. 15744ec3ccb4SMadhukar Pappireddy- stream-ids: List of stream IDs assigned to this device. 15754ec3ccb4SMadhukar Pappireddy 15764ec3ccb4SMadhukar Pappireddy.. code:: shell 15774ec3ccb4SMadhukar Pappireddy 15784ec3ccb4SMadhukar Pappireddy smmuv3-testengine { 15794ec3ccb4SMadhukar Pappireddy base-address = <0x00000000 0x2bfe0000>; 15804ec3ccb4SMadhukar Pappireddy pages-count = <32>; 15814ec3ccb4SMadhukar Pappireddy attributes = <0x3>; 15824ec3ccb4SMadhukar Pappireddy smmu-id = <0>; 15834ec3ccb4SMadhukar Pappireddy stream-ids = <0x0 0x1>; 15844ec3ccb4SMadhukar Pappireddy interrupts = <0x2 0x3>, <0x4 0x5>; 15854ec3ccb4SMadhukar Pappireddy exclusive-access; 15864ec3ccb4SMadhukar Pappireddy }; 15874ec3ccb4SMadhukar Pappireddy 15884ec3ccb4SMadhukar PappireddySMMUv3 driver limitations 15894ec3ccb4SMadhukar Pappireddy------------------------- 15904ec3ccb4SMadhukar Pappireddy 15914ec3ccb4SMadhukar PappireddyThe primary design goal for the Hafnium SMMU driver is to support secure 15924ec3ccb4SMadhukar Pappireddystreams. 15934ec3ccb4SMadhukar Pappireddy 15944ec3ccb4SMadhukar Pappireddy- Currently, the driver only supports Stage2 translations. No support for 15954ec3ccb4SMadhukar Pappireddy Stage1 or nested translations. 15964ec3ccb4SMadhukar Pappireddy- Supports only AArch64 translation format. 15974ec3ccb4SMadhukar Pappireddy- No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS, 15984ec3ccb4SMadhukar Pappireddy Fault handling, Performance Monitor Extensions, Event Handling, MPAM. 15994ec3ccb4SMadhukar Pappireddy- No support for independent peripheral devices. 16004ec3ccb4SMadhukar Pappireddy 1601aeea04d4SRaghu KrishnamurthyS-EL0 Partition support 16029eea92a1SOlivier Deprez======================= 1603aeea04d4SRaghu KrishnamurthyThe SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using 1604aeea04d4SRaghu KrishnamurthyFEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world 1605aeea04d4SRaghu Krishnamurthywith ARMv8.4 and FEAT_SEL2). 1606aeea04d4SRaghu Krishnamurthy 1607aeea04d4SRaghu KrishnamurthyS-EL0 partitions are useful for simple partitions that don't require full 1608aeea04d4SRaghu KrishnamurthyTrusted OS functionality. It is also useful to reduce jitter and cycle 1609aeea04d4SRaghu Krishnamurthystealing from normal world since they are more lightweight than VMs. 1610aeea04d4SRaghu Krishnamurthy 1611aeea04d4SRaghu KrishnamurthyS-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by 1612aeea04d4SRaghu Krishnamurthythe SPMC. They are differentiated primarily by the 'exception-level' property 1613aeea04d4SRaghu Krishnamurthyand the 'execution-ctx-count' property in the SP manifest. They are host apps 1614aeea04d4SRaghu Krishnamurthyunder the single EL2&0 Stage-1 translation regime controlled by the SPMC and 1615aeea04d4SRaghu Krishnamurthycall into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions 1616aeea04d4SRaghu Krishnamurthycan use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions 1617aeea04d4SRaghu Krishnamurthyfor memory regions. 1618aeea04d4SRaghu Krishnamurthy 1619aeea04d4SRaghu KrishnamurthyS-EL0 partitions are required by the FF-A specification to be UP endpoints, 1620aeea04d4SRaghu Krishnamurthycapable of migrating, and the SPMC enforces this requirement. The SPMC allows 1621aeea04d4SRaghu Krishnamurthya S-EL0 partition to accept a direct message from secure world and normal world, 1622aeea04d4SRaghu Krishnamurthyand generate direct responses to them. 1623c8e49504SJ-AlvesAll S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not supported. 1624aeea04d4SRaghu Krishnamurthy 1625c8e49504SJ-AlvesMemory sharing, indirect messaging, and notifications functionality with S-EL0 1626c8e49504SJ-Alvespartitions is supported. 1627aeea04d4SRaghu Krishnamurthy 1628c8e49504SJ-AlvesInterrupt handling is not supported with S-EL0 partitions and is work in 1629c8e49504SJ-Alvesprogress. 1630aeea04d4SRaghu Krishnamurthy 1631fcb1398fSOlivier DeprezReferences 1632fcb1398fSOlivier Deprez========== 1633fcb1398fSOlivier Deprez 1634fcb1398fSOlivier Deprez.. _[1]: 1635fcb1398fSOlivier Deprez 16368a5bd3cfSOlivier Deprez[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__ 1637fcb1398fSOlivier Deprez 1638fcb1398fSOlivier Deprez.. _[2]: 1639fcb1398fSOlivier Deprez 16406844c347SMadhukar Pappireddy[2] :ref:`Secure Partition Manager using MM interface<Secure Partition Manager (MM)>` 1641fcb1398fSOlivier Deprez 1642fcb1398fSOlivier Deprez.. _[3]: 1643fcb1398fSOlivier Deprez 1644fcb1398fSOlivier Deprez[3] `Trusted Boot Board Requirements 1645b5dd2422SOlivier DeprezClient <https://developer.arm.com/documentation/den0006/d/>`__ 1646fcb1398fSOlivier Deprez 1647fcb1398fSOlivier Deprez.. _[4]: 1648fcb1398fSOlivier Deprez 1649fcb1398fSOlivier Deprez[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45 1650fcb1398fSOlivier Deprez 1651fcb1398fSOlivier Deprez.. _[5]: 1652fcb1398fSOlivier Deprez 1653b5dd2422SOlivier Deprez[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts 1654fcb1398fSOlivier Deprez 1655fcb1398fSOlivier Deprez.. _[6]: 1656fcb1398fSOlivier Deprez 16571b17f4f1SOlivier Deprez[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html 1658fcb1398fSOlivier Deprez 1659fcb1398fSOlivier Deprez.. _[7]: 1660fcb1398fSOlivier Deprez 1661fcb1398fSOlivier Deprez[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts 1662fcb1398fSOlivier Deprez 1663fcb1398fSOlivier Deprez.. _[8]: 1664fcb1398fSOlivier Deprez 1665f4a55e6bSSandrine Bailleux[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/ 1666fcb1398fSOlivier Deprez 1667f2dcf418SOlivier Deprez.. _[9]: 1668f2dcf418SOlivier Deprez 1669f2dcf418SOlivier Deprez[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot 1670f2dcf418SOlivier Deprez 1671fcb1398fSOlivier Deprez-------------- 1672fcb1398fSOlivier Deprez 1673*0a33adc0SGovindraj Raja*Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved.* 1674