1*54fd6939SJiyong ParkSecure Partition Manager 2*54fd6939SJiyong Park************************ 3*54fd6939SJiyong Park 4*54fd6939SJiyong Park.. contents:: 5*54fd6939SJiyong Park 6*54fd6939SJiyong ParkAcronyms 7*54fd6939SJiyong Park======== 8*54fd6939SJiyong Park 9*54fd6939SJiyong Park+--------+--------------------------------------+ 10*54fd6939SJiyong Park| CoT | Chain of Trust | 11*54fd6939SJiyong Park+--------+--------------------------------------+ 12*54fd6939SJiyong Park| DMA | Direct Memory Access | 13*54fd6939SJiyong Park+--------+--------------------------------------+ 14*54fd6939SJiyong Park| DTB | Device Tree Blob | 15*54fd6939SJiyong Park+--------+--------------------------------------+ 16*54fd6939SJiyong Park| DTS | Device Tree Source | 17*54fd6939SJiyong Park+--------+--------------------------------------+ 18*54fd6939SJiyong Park| EC | Execution Context | 19*54fd6939SJiyong Park+--------+--------------------------------------+ 20*54fd6939SJiyong Park| FIP | Firmware Image Package | 21*54fd6939SJiyong Park+--------+--------------------------------------+ 22*54fd6939SJiyong Park| FF-A | Firmware Framework for Arm A-profile | 23*54fd6939SJiyong Park+--------+--------------------------------------+ 24*54fd6939SJiyong Park| IPA | Intermediate Physical Address | 25*54fd6939SJiyong Park+--------+--------------------------------------+ 26*54fd6939SJiyong Park| NWd | Normal World | 27*54fd6939SJiyong Park+--------+--------------------------------------+ 28*54fd6939SJiyong Park| ODM | Original Design Manufacturer | 29*54fd6939SJiyong Park+--------+--------------------------------------+ 30*54fd6939SJiyong Park| OEM | Original Equipment Manufacturer | 31*54fd6939SJiyong Park+--------+--------------------------------------+ 32*54fd6939SJiyong Park| PA | Physical Address | 33*54fd6939SJiyong Park+--------+--------------------------------------+ 34*54fd6939SJiyong Park| PE | Processing Element | 35*54fd6939SJiyong Park+--------+--------------------------------------+ 36*54fd6939SJiyong Park| PM | Power Management | 37*54fd6939SJiyong Park+--------+--------------------------------------+ 38*54fd6939SJiyong Park| PVM | Primary VM | 39*54fd6939SJiyong Park+--------+--------------------------------------+ 40*54fd6939SJiyong Park| SMMU | System Memory Management Unit | 41*54fd6939SJiyong Park+--------+--------------------------------------+ 42*54fd6939SJiyong Park| SP | Secure Partition | 43*54fd6939SJiyong Park+--------+--------------------------------------+ 44*54fd6939SJiyong Park| SPD | Secure Payload Dispatcher | 45*54fd6939SJiyong Park+--------+--------------------------------------+ 46*54fd6939SJiyong Park| SPM | Secure Partition Manager | 47*54fd6939SJiyong Park+--------+--------------------------------------+ 48*54fd6939SJiyong Park| SPMC | SPM Core | 49*54fd6939SJiyong Park+--------+--------------------------------------+ 50*54fd6939SJiyong Park| SPMD | SPM Dispatcher | 51*54fd6939SJiyong Park+--------+--------------------------------------+ 52*54fd6939SJiyong Park| SiP | Silicon Provider | 53*54fd6939SJiyong Park+--------+--------------------------------------+ 54*54fd6939SJiyong Park| SWd | Secure World | 55*54fd6939SJiyong Park+--------+--------------------------------------+ 56*54fd6939SJiyong Park| TLV | Tag-Length-Value | 57*54fd6939SJiyong Park+--------+--------------------------------------+ 58*54fd6939SJiyong Park| TOS | Trusted Operating System | 59*54fd6939SJiyong Park+--------+--------------------------------------+ 60*54fd6939SJiyong Park| VM | Virtual Machine | 61*54fd6939SJiyong Park+--------+--------------------------------------+ 62*54fd6939SJiyong Park 63*54fd6939SJiyong ParkForeword 64*54fd6939SJiyong Park======== 65*54fd6939SJiyong Park 66*54fd6939SJiyong ParkTwo implementations of a Secure Partition Manager co-exist in the TF-A codebase: 67*54fd6939SJiyong Park 68*54fd6939SJiyong Park- SPM based on the FF-A specification `[1]`_. 69*54fd6939SJiyong Park- SPM based on the MM interface to communicate with an S-EL0 partition `[2]`_. 70*54fd6939SJiyong Park 71*54fd6939SJiyong ParkBoth implementations differ in their architectures and only one can be selected 72*54fd6939SJiyong Parkat build time. 73*54fd6939SJiyong Park 74*54fd6939SJiyong ParkThis document: 75*54fd6939SJiyong Park 76*54fd6939SJiyong Park- describes the FF-A implementation where the Secure Partition Manager 77*54fd6939SJiyong Park resides at EL3 and S-EL2 (or EL3 and S-EL1). 78*54fd6939SJiyong Park- is not an architecture specification and it might provide assumptions 79*54fd6939SJiyong Park on sections mandated as implementation-defined in the specification. 80*54fd6939SJiyong Park- covers the implications to TF-A used as a bootloader, and Hafnium 81*54fd6939SJiyong Park used as a reference code base for an S-EL2 secure firmware on 82*54fd6939SJiyong Park platforms implementing the FEAT_SEL2 (formerly Armv8.4 Secure EL2) 83*54fd6939SJiyong Park architecture extension. 84*54fd6939SJiyong Park 85*54fd6939SJiyong ParkTerminology 86*54fd6939SJiyong Park----------- 87*54fd6939SJiyong Park 88*54fd6939SJiyong Park- The term Hypervisor refers to the NS-EL2 component managing Virtual Machines 89*54fd6939SJiyong Park (or partitions) in the normal world. 90*54fd6939SJiyong Park- The term SPMC refers to the S-EL2 component managing secure partitions in 91*54fd6939SJiyong Park the secure world when the FEAT_SEL2 architecture extension is implemented. 92*54fd6939SJiyong Park- Alternatively, SPMC can refer to an S-EL1 component, itself being a secure 93*54fd6939SJiyong Park partition and implementing the FF-A ABI on platforms not implementing the 94*54fd6939SJiyong Park FEAT_SEL2 architecture extension. 95*54fd6939SJiyong Park- The term VM refers to a normal world Virtual Machine managed by an Hypervisor. 96*54fd6939SJiyong Park- The term SP refers to a secure world "Virtual Machine" managed by an SPMC. 97*54fd6939SJiyong Park 98*54fd6939SJiyong ParkSupport for legacy platforms 99*54fd6939SJiyong Park---------------------------- 100*54fd6939SJiyong Park 101*54fd6939SJiyong ParkIn the implementation, the SPM is split into SPMD and SPMC components. 102*54fd6939SJiyong ParkThe SPMD is located at EL3 and mainly relays FF-A messages from 103*54fd6939SJiyong ParkNWd (Hypervisor or OS kernel) to SPMC located either at S-EL1 or S-EL2. 104*54fd6939SJiyong Park 105*54fd6939SJiyong ParkHence TF-A supports both cases where the SPMC is located either at: 106*54fd6939SJiyong Park 107*54fd6939SJiyong Park- S-EL1 supporting platforms not implementing the FEAT_SEL2 architecture 108*54fd6939SJiyong Park extension. The SPMD relays the FF-A protocol from EL3 to S-EL1. 109*54fd6939SJiyong Park- or S-EL2 supporting platforms implementing the FEAT_SEL2 architecture 110*54fd6939SJiyong Park extension. The SPMD relays the FF-A protocol from EL3 to S-EL2. 111*54fd6939SJiyong Park 112*54fd6939SJiyong ParkThe same TF-A SPMD component is used to support both configurations. 113*54fd6939SJiyong ParkThe SPMC exception level is a build time choice. 114*54fd6939SJiyong Park 115*54fd6939SJiyong ParkSample reference stack 116*54fd6939SJiyong Park====================== 117*54fd6939SJiyong Park 118*54fd6939SJiyong ParkThe following diagram illustrates a possible configuration when the 119*54fd6939SJiyong ParkFEAT_SEL2 architecture extension is implemented, showing the SPMD 120*54fd6939SJiyong Parkand SPMC, one or multiple secure partitions, with an optional 121*54fd6939SJiyong ParkHypervisor: 122*54fd6939SJiyong Park 123*54fd6939SJiyong Park.. image:: ../resources/diagrams/ff-a-spm-sel2.png 124*54fd6939SJiyong Park 125*54fd6939SJiyong ParkTF-A build options 126*54fd6939SJiyong Park================== 127*54fd6939SJiyong Park 128*54fd6939SJiyong ParkThis section explains the TF-A build options involved in building with 129*54fd6939SJiyong Parksupport for an FF-A based SPM where the SPMD is located at EL3 and the 130*54fd6939SJiyong ParkSPMC located at S-EL1 or S-EL2: 131*54fd6939SJiyong Park 132*54fd6939SJiyong Park- **SPD=spmd**: this option selects the SPMD component to relay the FF-A 133*54fd6939SJiyong Park protocol from NWd to SWd back and forth. It is not possible to 134*54fd6939SJiyong Park enable another Secure Payload Dispatcher when this option is chosen. 135*54fd6939SJiyong Park- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception 136*54fd6939SJiyong Park level to being S-EL1 or S-EL2. It defaults to enabled (value 1) when 137*54fd6939SJiyong Park SPD=spmd is chosen. 138*54fd6939SJiyong Park- **CTX_INCLUDE_EL2_REGS**: this option permits saving (resp. 139*54fd6939SJiyong Park restoring) the EL2 system register context before entering (resp. 140*54fd6939SJiyong Park after leaving) the SPMC. It is mandatorily enabled when 141*54fd6939SJiyong Park ``SPMD_SPM_AT_SEL2`` is enabled. The context save/restore routine 142*54fd6939SJiyong Park and exhaustive list of registers is visible at `[4]`_. 143*54fd6939SJiyong Park- **SP_LAYOUT_FILE**: this option specifies a text description file 144*54fd6939SJiyong Park providing paths to SP binary images and manifests in DTS format 145*54fd6939SJiyong Park (see `Describing secure partitions`_). It 146*54fd6939SJiyong Park is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple 147*54fd6939SJiyong Park secure partitions are to be loaded on behalf of the SPMC. 148*54fd6939SJiyong Park 149*54fd6939SJiyong Park+---------------+----------------------+------------------+ 150*54fd6939SJiyong Park| | CTX_INCLUDE_EL2_REGS | SPMD_SPM_AT_SEL2 | 151*54fd6939SJiyong Park+---------------+----------------------+------------------+ 152*54fd6939SJiyong Park| SPMC at S-EL1 | 0 | 0 | 153*54fd6939SJiyong Park+---------------+----------------------+------------------+ 154*54fd6939SJiyong Park| SPMC at S-EL2 | 1 | 1 (default when | 155*54fd6939SJiyong Park| | | SPD=spmd) | 156*54fd6939SJiyong Park+---------------+----------------------+------------------+ 157*54fd6939SJiyong Park 158*54fd6939SJiyong ParkOther combinations of such build options either break the build or are not 159*54fd6939SJiyong Parksupported. 160*54fd6939SJiyong Park 161*54fd6939SJiyong ParkNotes: 162*54fd6939SJiyong Park 163*54fd6939SJiyong Park- Only Arm's FVP platform is supported to use with the TF-A reference software 164*54fd6939SJiyong Park stack. 165*54fd6939SJiyong Park- The reference software stack uses FEAT_PAuth (formerly Armv8.3-PAuth) and 166*54fd6939SJiyong Park FEAT_BTI (formerly Armv8.5-BTI) architecture extensions by default at EL3 167*54fd6939SJiyong Park and S-EL2. 168*54fd6939SJiyong Park- The ``CTX_INCLUDE_EL2_REGS`` option provides the generic support for 169*54fd6939SJiyong Park barely saving/restoring EL2 registers from an Arm arch perspective. As such 170*54fd6939SJiyong Park it is decoupled from the ``SPD=spmd`` option. 171*54fd6939SJiyong Park- BL32 option is re-purposed to specify the SPMC image. It can specify either 172*54fd6939SJiyong Park the Hafnium binary path (built for the secure world) or the path to a TEE 173*54fd6939SJiyong Park binary implementing FF-A interfaces. 174*54fd6939SJiyong Park- BL33 option can specify the TFTF binary or a normal world loader 175*54fd6939SJiyong Park such as U-Boot or the UEFI framework. 176*54fd6939SJiyong Park 177*54fd6939SJiyong ParkSample TF-A build command line when SPMC is located at S-EL1 178*54fd6939SJiyong Park(e.g. when the FEAT_EL2 architecture extension is not implemented): 179*54fd6939SJiyong Park 180*54fd6939SJiyong Park.. code:: shell 181*54fd6939SJiyong Park 182*54fd6939SJiyong Park make \ 183*54fd6939SJiyong Park CROSS_COMPILE=aarch64-none-elf- \ 184*54fd6939SJiyong Park SPD=spmd \ 185*54fd6939SJiyong Park SPMD_SPM_AT_SEL2=0 \ 186*54fd6939SJiyong Park BL32=<path-to-tee-binary> \ 187*54fd6939SJiyong Park BL33=<path-to-bl33-binary> \ 188*54fd6939SJiyong Park PLAT=fvp \ 189*54fd6939SJiyong Park all fip 190*54fd6939SJiyong Park 191*54fd6939SJiyong ParkSample TF-A build command line for a FEAT_SEL2 enabled system where the SPMC is 192*54fd6939SJiyong Parklocated at S-EL2: 193*54fd6939SJiyong Park 194*54fd6939SJiyong Park.. code:: shell 195*54fd6939SJiyong Park 196*54fd6939SJiyong Park make \ 197*54fd6939SJiyong Park CROSS_COMPILE=aarch64-none-elf- \ 198*54fd6939SJiyong Park PLAT=fvp \ 199*54fd6939SJiyong Park SPD=spmd \ 200*54fd6939SJiyong Park CTX_INCLUDE_EL2_REGS=1 \ 201*54fd6939SJiyong Park ARM_ARCH_MINOR=5 \ 202*54fd6939SJiyong Park BRANCH_PROTECTION=1 \ 203*54fd6939SJiyong Park CTX_INCLUDE_PAUTH_REGS=1 \ 204*54fd6939SJiyong Park BL32=<path-to-hafnium-binary> \ 205*54fd6939SJiyong Park BL33=<path-to-bl33-binary> \ 206*54fd6939SJiyong Park SP_LAYOUT_FILE=sp_layout.json \ 207*54fd6939SJiyong Park all fip 208*54fd6939SJiyong Park 209*54fd6939SJiyong ParkSame as above with enabling secure boot in addition: 210*54fd6939SJiyong Park 211*54fd6939SJiyong Park.. code:: shell 212*54fd6939SJiyong Park 213*54fd6939SJiyong Park make \ 214*54fd6939SJiyong Park CROSS_COMPILE=aarch64-none-elf- \ 215*54fd6939SJiyong Park PLAT=fvp \ 216*54fd6939SJiyong Park SPD=spmd \ 217*54fd6939SJiyong Park CTX_INCLUDE_EL2_REGS=1 \ 218*54fd6939SJiyong Park ARM_ARCH_MINOR=5 \ 219*54fd6939SJiyong Park BRANCH_PROTECTION=1 \ 220*54fd6939SJiyong Park CTX_INCLUDE_PAUTH_REGS=1 \ 221*54fd6939SJiyong Park BL32=<path-to-hafnium-binary> \ 222*54fd6939SJiyong Park BL33=<path-to-bl33-binary> \ 223*54fd6939SJiyong Park SP_LAYOUT_FILE=sp_layout.json \ 224*54fd6939SJiyong Park MBEDTLS_DIR=<path-to-mbedtls-lib> \ 225*54fd6939SJiyong Park TRUSTED_BOARD_BOOT=1 \ 226*54fd6939SJiyong Park COT=dualroot \ 227*54fd6939SJiyong Park ARM_ROTPK_LOCATION=devel_rsa \ 228*54fd6939SJiyong Park ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \ 229*54fd6939SJiyong Park GENERATE_COT=1 \ 230*54fd6939SJiyong Park all fip 231*54fd6939SJiyong Park 232*54fd6939SJiyong ParkFVP model invocation 233*54fd6939SJiyong Park==================== 234*54fd6939SJiyong Park 235*54fd6939SJiyong ParkThe FVP command line needs the following options to exercise the S-EL2 SPMC: 236*54fd6939SJiyong Park 237*54fd6939SJiyong Park+---------------------------------------------------+------------------------------------+ 238*54fd6939SJiyong Park| - cluster0.has_arm_v8-5=1 | Implements FEAT_SEL2, FEAT_PAuth, | 239*54fd6939SJiyong Park| - cluster1.has_arm_v8-5=1 | and FEAT_BTI. | 240*54fd6939SJiyong Park+---------------------------------------------------+------------------------------------+ 241*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_AIDR=2 | Parameters required for the | 242*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B | SMMUv3.2 modeling. | 243*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 | | 244*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 | | 245*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 | | 246*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 | | 247*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 | | 248*54fd6939SJiyong Park| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 | | 249*54fd6939SJiyong Park+---------------------------------------------------+------------------------------------+ 250*54fd6939SJiyong Park| - cluster0.has_branch_target_exception=1 | Implements FEAT_BTI. | 251*54fd6939SJiyong Park| - cluster1.has_branch_target_exception=1 | | 252*54fd6939SJiyong Park+---------------------------------------------------+------------------------------------+ 253*54fd6939SJiyong Park| - cluster0.restriction_on_speculative_execution=2 | Required by the EL2 context | 254*54fd6939SJiyong Park| - cluster1.restriction_on_speculative_execution=2 | save/restore routine. | 255*54fd6939SJiyong Park+---------------------------------------------------+------------------------------------+ 256*54fd6939SJiyong Park 257*54fd6939SJiyong ParkSample FVP command line invocation: 258*54fd6939SJiyong Park 259*54fd6939SJiyong Park.. code:: shell 260*54fd6939SJiyong Park 261*54fd6939SJiyong Park <path-to-fvp-model>/FVP_Base_RevC-2xAEMv8A -C pctl.startup=0.0.0.0 262*54fd6939SJiyong Park -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \ 263*54fd6939SJiyong Park -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \ 264*54fd6939SJiyong Park -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \ 265*54fd6939SJiyong Park -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \ 266*54fd6939SJiyong Park -C bp.pl011_uart2.out_file=fvp-uart2.log \ 267*54fd6939SJiyong Park -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 \ 268*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 \ 269*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 \ 270*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 \ 271*54fd6939SJiyong Park -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 \ 272*54fd6939SJiyong Park -C cluster0.has_branch_target_exception=1 \ 273*54fd6939SJiyong Park -C cluster1.has_branch_target_exception=1 \ 274*54fd6939SJiyong Park -C cluster0.restriction_on_speculative_execution=2 \ 275*54fd6939SJiyong Park -C cluster1.restriction_on_speculative_execution=2 276*54fd6939SJiyong Park 277*54fd6939SJiyong ParkBoot process 278*54fd6939SJiyong Park============ 279*54fd6939SJiyong Park 280*54fd6939SJiyong ParkLoading Hafnium and secure partitions in the secure world 281*54fd6939SJiyong Park--------------------------------------------------------- 282*54fd6939SJiyong Park 283*54fd6939SJiyong ParkTF-A BL2 is the bootlader for the SPMC and SPs in the secure world. 284*54fd6939SJiyong Park 285*54fd6939SJiyong ParkSPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.). 286*54fd6939SJiyong ParkThus they are supplied as distinct signed entities within the FIP flash 287*54fd6939SJiyong Parkimage. The FIP image itself is not signed hence this provides the ability 288*54fd6939SJiyong Parkto upgrade SPs in the field. 289*54fd6939SJiyong Park 290*54fd6939SJiyong ParkBooting through TF-A 291*54fd6939SJiyong Park-------------------- 292*54fd6939SJiyong Park 293*54fd6939SJiyong ParkSP manifests 294*54fd6939SJiyong Park~~~~~~~~~~~~ 295*54fd6939SJiyong Park 296*54fd6939SJiyong ParkAn SP manifest describes SP attributes as defined in `[1]`_ 297*54fd6939SJiyong Park(partition manifest at virtual FF-A instance) in DTS format. It is 298*54fd6939SJiyong Parkrepresented as a single file associated with the SP. A sample is 299*54fd6939SJiyong Parkprovided by `[5]`_. A binding document is provided by `[6]`_. 300*54fd6939SJiyong Park 301*54fd6939SJiyong ParkSecure Partition packages 302*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~ 303*54fd6939SJiyong Park 304*54fd6939SJiyong ParkSecure partitions are bundled as independent package files consisting 305*54fd6939SJiyong Parkof: 306*54fd6939SJiyong Park 307*54fd6939SJiyong Park- a header 308*54fd6939SJiyong Park- a DTB 309*54fd6939SJiyong Park- an image payload 310*54fd6939SJiyong Park 311*54fd6939SJiyong ParkThe header starts with a magic value and offset values to SP DTB and 312*54fd6939SJiyong Parkimage payload. Each SP package is loaded independently by BL2 loader 313*54fd6939SJiyong Parkand verified for authenticity and integrity. 314*54fd6939SJiyong Park 315*54fd6939SJiyong ParkThe SP package identified by its UUID (matching FF-A uuid property) is 316*54fd6939SJiyong Parkinserted as a single entry into the FIP at end of the TF-A build flow 317*54fd6939SJiyong Parkas shown: 318*54fd6939SJiyong Park 319*54fd6939SJiyong Park.. code:: shell 320*54fd6939SJiyong Park 321*54fd6939SJiyong Park Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw" 322*54fd6939SJiyong Park EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw" 323*54fd6939SJiyong Park Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw" 324*54fd6939SJiyong Park Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw" 325*54fd6939SJiyong Park HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config" 326*54fd6939SJiyong Park TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config" 327*54fd6939SJiyong Park SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config" 328*54fd6939SJiyong Park TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config" 329*54fd6939SJiyong Park NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config" 330*54fd6939SJiyong Park B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob" 331*54fd6939SJiyong Park D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob" 332*54fd6939SJiyong Park 333*54fd6939SJiyong Park.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml 334*54fd6939SJiyong Park 335*54fd6939SJiyong ParkDescribing secure partitions 336*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 337*54fd6939SJiyong Park 338*54fd6939SJiyong ParkA json-formatted description file is passed to the build flow specifying paths 339*54fd6939SJiyong Parkto the SP binary image and associated DTS partition manifest file. The latter 340*54fd6939SJiyong Parkis processed by the dtc compiler to generate a DTB fed into the SP package. 341*54fd6939SJiyong ParkThis file also specifies the SP owner (as an optional field) identifying the 342*54fd6939SJiyong Parksigning domain in case of dual root CoT. 343*54fd6939SJiyong ParkThe SP owner can either be the silicon or the platform provider. The 344*54fd6939SJiyong Parkcorresponding "owner" field value can either take the value of "SiP" or "Plat". 345*54fd6939SJiyong ParkIn absence of "owner" field, it defaults to "SiP" owner. 346*54fd6939SJiyong Park 347*54fd6939SJiyong Park.. code:: shell 348*54fd6939SJiyong Park 349*54fd6939SJiyong Park { 350*54fd6939SJiyong Park "tee1" : { 351*54fd6939SJiyong Park "image": "tee1.bin", 352*54fd6939SJiyong Park "pm": "tee1.dts", 353*54fd6939SJiyong Park "owner": "SiP" 354*54fd6939SJiyong Park }, 355*54fd6939SJiyong Park 356*54fd6939SJiyong Park "tee2" : { 357*54fd6939SJiyong Park "image": "tee2.bin", 358*54fd6939SJiyong Park "pm": "tee2.dts", 359*54fd6939SJiyong Park "owner": "Plat" 360*54fd6939SJiyong Park } 361*54fd6939SJiyong Park } 362*54fd6939SJiyong Park 363*54fd6939SJiyong ParkSPMC manifest 364*54fd6939SJiyong Park~~~~~~~~~~~~~ 365*54fd6939SJiyong Park 366*54fd6939SJiyong ParkThis manifest contains the SPMC *attribute* node consumed by the SPMD at boot 367*54fd6939SJiyong Parktime. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves 368*54fd6939SJiyong Parktwo different cases: 369*54fd6939SJiyong Park 370*54fd6939SJiyong Park- The SPMC resides at S-EL1: the SPMC manifest is used by the SPMD to setup a 371*54fd6939SJiyong Park SP that co-resides with the SPMC and executes at S-EL1 or Secure Supervisor 372*54fd6939SJiyong Park mode. 373*54fd6939SJiyong Park- The SPMC resides at S-EL2: the SPMC manifest is used by the SPMD to setup 374*54fd6939SJiyong Park the environment required by the SPMC to run at S-EL2. SPs run at S-EL1 or 375*54fd6939SJiyong Park S-EL0. 376*54fd6939SJiyong Park 377*54fd6939SJiyong Park.. code:: shell 378*54fd6939SJiyong Park 379*54fd6939SJiyong Park attribute { 380*54fd6939SJiyong Park spmc_id = <0x8000>; 381*54fd6939SJiyong Park maj_ver = <0x1>; 382*54fd6939SJiyong Park min_ver = <0x0>; 383*54fd6939SJiyong Park exec_state = <0x0>; 384*54fd6939SJiyong Park load_address = <0x0 0x6000000>; 385*54fd6939SJiyong Park entrypoint = <0x0 0x6000000>; 386*54fd6939SJiyong Park binary_size = <0x60000>; 387*54fd6939SJiyong Park }; 388*54fd6939SJiyong Park 389*54fd6939SJiyong Park- *spmc_id* defines the endpoint ID value that SPMC can query through 390*54fd6939SJiyong Park ``FFA_ID_GET``. 391*54fd6939SJiyong Park- *maj_ver/min_ver*. SPMD checks provided version versus its internal 392*54fd6939SJiyong Park version and aborts if not matching. 393*54fd6939SJiyong Park- *exec_state* defines the SPMC execution state (AArch64 or AArch32). 394*54fd6939SJiyong Park Notice Hafnium used as a SPMC only supports AArch64. 395*54fd6939SJiyong Park- *load_address* and *binary_size* are mostly used to verify secondary 396*54fd6939SJiyong Park entry points fit into the loaded binary image. 397*54fd6939SJiyong Park- *entrypoint* defines the cold boot primary core entry point used by 398*54fd6939SJiyong Park SPMD (currently matches ``BL32_BASE``) to enter the SPMC. 399*54fd6939SJiyong Park 400*54fd6939SJiyong ParkOther nodes in the manifest are consumed by Hafnium in the secure world. 401*54fd6939SJiyong ParkA sample can be found at [7]: 402*54fd6939SJiyong Park 403*54fd6939SJiyong Park- The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute 404*54fd6939SJiyong Park indicates a FF-A compliant SP. The *load_address* field specifies the load 405*54fd6939SJiyong Park address at which TF-A loaded the SP package. 406*54fd6939SJiyong Park- *cpus* node provide the platform topology and allows MPIDR to VMPIDR mapping. 407*54fd6939SJiyong Park Note the primary core is declared first, then secondary core are declared 408*54fd6939SJiyong Park in reverse order. 409*54fd6939SJiyong Park- The *memory* node provides platform information on the ranges of memory 410*54fd6939SJiyong Park available to the SPMC. 411*54fd6939SJiyong Park 412*54fd6939SJiyong ParkSPMC boot 413*54fd6939SJiyong Park~~~~~~~~~ 414*54fd6939SJiyong Park 415*54fd6939SJiyong ParkThe SPMC is loaded by BL2 as the BL32 image. 416*54fd6939SJiyong Park 417*54fd6939SJiyong ParkThe SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_. 418*54fd6939SJiyong Park 419*54fd6939SJiyong ParkBL2 passes the SPMC manifest address to BL31 through a register. 420*54fd6939SJiyong Park 421*54fd6939SJiyong ParkAt boot time, the SPMD in BL31 runs from the primary core, initializes the core 422*54fd6939SJiyong Parkcontexts and launches the SPMC (BL32) passing the following information through 423*54fd6939SJiyong Parkregisters: 424*54fd6939SJiyong Park 425*54fd6939SJiyong Park- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob). 426*54fd6939SJiyong Park- X1 holds the ``HW_CONFIG`` physical address. 427*54fd6939SJiyong Park- X4 holds the currently running core linear id. 428*54fd6939SJiyong Park 429*54fd6939SJiyong ParkLoading of SPs 430*54fd6939SJiyong Park~~~~~~~~~~~~~~ 431*54fd6939SJiyong Park 432*54fd6939SJiyong ParkAt boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted 433*54fd6939SJiyong Parkbelow: 434*54fd6939SJiyong Park 435*54fd6939SJiyong Park.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml 436*54fd6939SJiyong Park 437*54fd6939SJiyong ParkNote this boot flow is an implementation sample on Arm's FVP platform. 438*54fd6939SJiyong ParkPlatforms not using TF-A's *Firmware CONFiguration* framework would adjust to a 439*54fd6939SJiyong Parkdifferent implementation. 440*54fd6939SJiyong Park 441*54fd6939SJiyong ParkSecure boot 442*54fd6939SJiyong Park~~~~~~~~~~~ 443*54fd6939SJiyong Park 444*54fd6939SJiyong ParkThe SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC, 445*54fd6939SJiyong ParkSPMC manifest, secure partitions and verifies them for authenticity and integrity. 446*54fd6939SJiyong ParkRefer to TBBR specification `[3]`_. 447*54fd6939SJiyong Park 448*54fd6939SJiyong ParkThe multiple-signing domain feature (in current state dual signing domain `[8]`_) allows 449*54fd6939SJiyong Parkthe use of two root keys namely S-ROTPK and NS-ROTPK: 450*54fd6939SJiyong Park 451*54fd6939SJiyong Park- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK. 452*54fd6939SJiyong Park- BL33 may be signed by the OEM using NS-ROTPK. 453*54fd6939SJiyong Park- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK). 454*54fd6939SJiyong Park 455*54fd6939SJiyong ParkAlso refer to `Describing secure partitions`_ and `TF-A build options`_ sections. 456*54fd6939SJiyong Park 457*54fd6939SJiyong ParkHafnium in the secure world 458*54fd6939SJiyong Park=========================== 459*54fd6939SJiyong Park 460*54fd6939SJiyong ParkGeneral considerations 461*54fd6939SJiyong Park---------------------- 462*54fd6939SJiyong Park 463*54fd6939SJiyong ParkBuild platform for the secure world 464*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 465*54fd6939SJiyong Park 466*54fd6939SJiyong ParkIn the Hafnium reference implementation specific code parts are only relevant to 467*54fd6939SJiyong Parkthe secure world. Such portions are isolated in architecture specific files 468*54fd6939SJiyong Parkand/or enclosed by a ``SECURE_WORLD`` macro. 469*54fd6939SJiyong Park 470*54fd6939SJiyong ParkSecure partitions CPU scheduling 471*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 472*54fd6939SJiyong Park 473*54fd6939SJiyong ParkThe FF-A v1.0 specification `[1]`_ provides two ways to relinquinsh CPU time to 474*54fd6939SJiyong Parksecure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of: 475*54fd6939SJiyong Park 476*54fd6939SJiyong Park- the FFA_MSG_SEND_DIRECT_REQ interface. 477*54fd6939SJiyong Park- the FFA_RUN interface. 478*54fd6939SJiyong Park 479*54fd6939SJiyong ParkPlatform topology 480*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~ 481*54fd6939SJiyong Park 482*54fd6939SJiyong ParkThe *execution-ctx-count* SP manifest field can take the value of one or the 483*54fd6939SJiyong Parktotal number of PEs. The FF-A v1.0 specification `[1]`_ recommends the 484*54fd6939SJiyong Parkfollowing SP types: 485*54fd6939SJiyong Park 486*54fd6939SJiyong Park- Pinned MP SPs: an execution context matches a physical PE. MP SPs must 487*54fd6939SJiyong Park implement the same number of ECs as the number of PEs in the platform. 488*54fd6939SJiyong Park- Migratable UP SPs: a single execution context can run and be migrated on any 489*54fd6939SJiyong Park physical PE. Such SP declares a single EC in its SP manifest. An UP SP can 490*54fd6939SJiyong Park receive a direct message request originating from any physical core targeting 491*54fd6939SJiyong Park the single execution context. 492*54fd6939SJiyong Park 493*54fd6939SJiyong ParkParsing SP partition manifests 494*54fd6939SJiyong Park------------------------------ 495*54fd6939SJiyong Park 496*54fd6939SJiyong ParkHafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_. 497*54fd6939SJiyong ParkNote the current implementation may not implement all optional fields. 498*54fd6939SJiyong Park 499*54fd6939SJiyong ParkThe SP manifest may contain memory and device regions nodes. In case of 500*54fd6939SJiyong Parkan S-EL2 SPMC: 501*54fd6939SJiyong Park 502*54fd6939SJiyong Park- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at 503*54fd6939SJiyong Park load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can 504*54fd6939SJiyong Park specify RX/TX buffer regions in which case it is not necessary for an SP 505*54fd6939SJiyong Park to explicitly invoke the ``FFA_RXTX_MAP`` interface. 506*54fd6939SJiyong Park- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or 507*54fd6939SJiyong Park EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate 508*54fd6939SJiyong Park additional resources (e.g. interrupts). 509*54fd6939SJiyong Park 510*54fd6939SJiyong ParkFor the S-EL2 SPMC, base addresses for memory and device region nodes are IPAs 511*54fd6939SJiyong Parkprovided the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation 512*54fd6939SJiyong Parkregime. 513*54fd6939SJiyong Park 514*54fd6939SJiyong ParkNote: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the 515*54fd6939SJiyong Parksame set of page tables. It is still open whether two sets of page tables shall 516*54fd6939SJiyong Parkbe provided per SP. The memory region node as defined in the specification 517*54fd6939SJiyong Parkprovides a memory security attribute hinting to map either to the secure or 518*54fd6939SJiyong Parknon-secure EL1&0 Stage-2 table if it exists. 519*54fd6939SJiyong Park 520*54fd6939SJiyong ParkPassing boot data to the SP 521*54fd6939SJiyong Park--------------------------- 522*54fd6939SJiyong Park 523*54fd6939SJiyong ParkIn `[1]`_ , the "Protocol for passing data" section defines a method for passing 524*54fd6939SJiyong Parkboot data to SPs (not currently implemented). 525*54fd6939SJiyong Park 526*54fd6939SJiyong ParkProvided that the whole secure partition package image (see 527*54fd6939SJiyong Park`Secure Partition packages`_) is mapped to the SP secure EL1&0 Stage-2 528*54fd6939SJiyong Parktranslation regime, an SP can access its own manifest DTB blob and extract its 529*54fd6939SJiyong Parkpartition manifest properties. 530*54fd6939SJiyong Park 531*54fd6939SJiyong ParkSP Boot order 532*54fd6939SJiyong Park------------- 533*54fd6939SJiyong Park 534*54fd6939SJiyong ParkSP manifests provide an optional boot order attribute meant to resolve 535*54fd6939SJiyong Parkdependencies such as an SP providing a service required to properly boot 536*54fd6939SJiyong Parkanother SP. 537*54fd6939SJiyong Park 538*54fd6939SJiyong ParkIt is possible for an SP to call into another SP through a direct request 539*54fd6939SJiyong Parkprovided the latter SP has already been booted. 540*54fd6939SJiyong Park 541*54fd6939SJiyong ParkBoot phases 542*54fd6939SJiyong Park----------- 543*54fd6939SJiyong Park 544*54fd6939SJiyong ParkPrimary core boot-up 545*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~ 546*54fd6939SJiyong Park 547*54fd6939SJiyong ParkUpon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical 548*54fd6939SJiyong Parkcore. The SPMC performs its platform initializations and registers the SPMC 549*54fd6939SJiyong Parksecondary physical core entry point physical address by the use of the 550*54fd6939SJiyong Park`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD 551*54fd6939SJiyong Parkat secure physical FF-A instance). 552*54fd6939SJiyong Park 553*54fd6939SJiyong ParkThe SPMC then creates secure partitions based on SP packages and manifests. Each 554*54fd6939SJiyong Parksecure partition is launched in sequence (`SP Boot order`_) on their "primary" 555*54fd6939SJiyong Parkexecution context. If the primary boot physical core linear id is N, an MP SP is 556*54fd6939SJiyong Parkstarted using EC[N] on PE[N] (see `Platform topology`_). If the partition is a 557*54fd6939SJiyong ParkUP SP, it is started using its unique EC0 on PE[N]. 558*54fd6939SJiyong Park 559*54fd6939SJiyong ParkThe SP primary EC (or the EC used when the partition is booted as described 560*54fd6939SJiyong Parkabove): 561*54fd6939SJiyong Park 562*54fd6939SJiyong Park- Performs the overall SP boot time initialization, and in case of a MP SP, 563*54fd6939SJiyong Park prepares the SP environment for other execution contexts. 564*54fd6939SJiyong Park- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure 565*54fd6939SJiyong Park virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA 566*54fd6939SJiyong Park entry point for other execution contexts. 567*54fd6939SJiyong Park- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or 568*54fd6939SJiyong Park ``FFA_ERROR`` in case of failure. 569*54fd6939SJiyong Park 570*54fd6939SJiyong ParkSecondary cores boot-up 571*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~ 572*54fd6939SJiyong Park 573*54fd6939SJiyong ParkOnce the system is started and NWd brought up, a secondary physical core is 574*54fd6939SJiyong Parkwoken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism 575*54fd6939SJiyong Parkcalls into the SPMD on the newly woken up physical core. Then the SPMC is 576*54fd6939SJiyong Parkentered at the secondary physical core entry point. 577*54fd6939SJiyong Park 578*54fd6939SJiyong ParkIn the current implementation, the first SP is resumed on the coresponding EC 579*54fd6939SJiyong Park(the virtual CPU which matches the physical core). The implication is that the 580*54fd6939SJiyong Parkfirst SP must be a MP SP. 581*54fd6939SJiyong Park 582*54fd6939SJiyong ParkIn a linux based system, once secure and normal worlds are booted but prior to 583*54fd6939SJiyong Parka NWd FF-A driver has been loaded: 584*54fd6939SJiyong Park 585*54fd6939SJiyong Park- The first SP has initialized all its ECs in response to primary core boot up 586*54fd6939SJiyong Park (at system initialization) and secondary core boot up (as a result of linux 587*54fd6939SJiyong Park invoking PSCI_CPU_ON for all secondary cores). 588*54fd6939SJiyong Park- Other SPs have their first execution context initialized as a result of secure 589*54fd6939SJiyong Park world initialization on the primary boot core. Other ECs for those SPs have to 590*54fd6939SJiyong Park be run first through ffa_run to complete their initialization (which results 591*54fd6939SJiyong Park in the EC completing with FFA_MSG_WAIT). 592*54fd6939SJiyong Park 593*54fd6939SJiyong ParkRefer to `Power management`_ for further details. 594*54fd6939SJiyong Park 595*54fd6939SJiyong ParkNotifications 596*54fd6939SJiyong Park------------- 597*54fd6939SJiyong Park 598*54fd6939SJiyong ParkThe FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous 599*54fd6939SJiyong Parkcommunication mechanism with non-blocking semantics. It allows for one FF-A 600*54fd6939SJiyong Parkendpoint to signal another for service provision, without hindering its current 601*54fd6939SJiyong Parkprogress. 602*54fd6939SJiyong Park 603*54fd6939SJiyong ParkHafnium currently supports 64 notifications. The IDs of each notification define 604*54fd6939SJiyong Parka position in a 64-bit bitmap. 605*54fd6939SJiyong Park 606*54fd6939SJiyong ParkThe signaling of notifications can interchangeably happen between NWd and SWd 607*54fd6939SJiyong ParkFF-A endpoints. 608*54fd6939SJiyong Park 609*54fd6939SJiyong ParkThe SPMC is in charge of managing notifications from SPs to SPs, from SPs to 610*54fd6939SJiyong ParkVMs, and from VMs to SPs. An hypervisor component would only manage 611*54fd6939SJiyong Parknotifications from VMs to VMs. Given the SPMC has no visibility of the endpoints 612*54fd6939SJiyong Parkdeployed in NWd, the Hypervisor or OS kernel must invoke the interface 613*54fd6939SJiyong ParkFFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A 614*54fd6939SJiyong Parkendpoint in the NWd that supports it. 615*54fd6939SJiyong Park 616*54fd6939SJiyong ParkA sender can signal notifications once the receiver has provided it with 617*54fd6939SJiyong Parkpermissions. Permissions are provided by invoking the interface 618*54fd6939SJiyong ParkFFA_NOTIFICATION_BIND. 619*54fd6939SJiyong Park 620*54fd6939SJiyong ParkNotifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth 621*54fd6939SJiyong Parkthey are considered to be in a pending sate. The receiver can retrieve its 622*54fd6939SJiyong Parkpending notifications invoking FFA_NOTIFICATION_GET, which, from that moment, 623*54fd6939SJiyong Parkare considered to be handled. 624*54fd6939SJiyong Park 625*54fd6939SJiyong ParkPer the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler 626*54fd6939SJiyong Parkthat is in charge of donating CPU cycles for notifications handling. The 627*54fd6939SJiyong ParkFF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about 628*54fd6939SJiyong Parkwhich FF-A endpoints have pending notifications. The receiver scheduler is 629*54fd6939SJiyong Parkcalled and informed by the FF-A driver, and it should allocate CPU cycles to the 630*54fd6939SJiyong Parkreceiver. 631*54fd6939SJiyong Park 632*54fd6939SJiyong ParkThere are two types of notifications supported: 633*54fd6939SJiyong Park- Global, which are targeted to a FF-A endpoint and can be handled within any of 634*54fd6939SJiyong Parkits execution contexts, as determined by the scheduler of the system. 635*54fd6939SJiyong Park- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a 636*54fd6939SJiyong Parka specific execution context, as determined by the sender. 637*54fd6939SJiyong Park 638*54fd6939SJiyong ParkThe type of a notification is set when invoking FFA_NOTIFICATION_BIND to give 639*54fd6939SJiyong Parkpermissions to the sender. 640*54fd6939SJiyong Park 641*54fd6939SJiyong ParkNotification signaling resorts to two interrupts: 642*54fd6939SJiyong Park- Schedule Receiver Interrupt: Non-secure physical interrupt to be handled by 643*54fd6939SJiyong Parkthe FF-A 'transport' driver within the receiver scheduler. At initialization 644*54fd6939SJiyong Parkthe SPMC (as suggested by the spec) configures a secure SGI, as non-secure, and 645*54fd6939SJiyong Parktriggers it when there are pending notifications, and the respective receivers 646*54fd6939SJiyong Parkneed CPU cycles to handle them. 647*54fd6939SJiyong Park- Notifications Pending Interrupt: Virtual Interrupt to be handled by the 648*54fd6939SJiyong Parkreceiver of the notification. Set when there are pending notifications. For 649*54fd6939SJiyong Parkper-vCPU the NPI is pended at the handling of FFA_NOTIFICATION_SET interface. 650*54fd6939SJiyong Park 651*54fd6939SJiyong ParkThe notifications receipt support is enabled in the partition FF-A manifest. 652*54fd6939SJiyong Park 653*54fd6939SJiyong ParkThe subsequent section provides more details about the each one of the 654*54fd6939SJiyong ParkFF-A interfaces for notifications support. 655*54fd6939SJiyong Park 656*54fd6939SJiyong ParkMandatory interfaces 657*54fd6939SJiyong Park-------------------- 658*54fd6939SJiyong Park 659*54fd6939SJiyong ParkThe following interfaces are exposed to SPs: 660*54fd6939SJiyong Park 661*54fd6939SJiyong Park- ``FFA_VERSION`` 662*54fd6939SJiyong Park- ``FFA_FEATURES`` 663*54fd6939SJiyong Park- ``FFA_RX_RELEASE`` 664*54fd6939SJiyong Park- ``FFA_RXTX_MAP`` 665*54fd6939SJiyong Park- ``FFA_RXTX_UNMAP`` 666*54fd6939SJiyong Park- ``FFA_PARTITION_INFO_GET`` 667*54fd6939SJiyong Park- ``FFA_ID_GET`` 668*54fd6939SJiyong Park- ``FFA_MSG_WAIT`` 669*54fd6939SJiyong Park- ``FFA_MSG_SEND_DIRECT_REQ`` 670*54fd6939SJiyong Park- ``FFA_MSG_SEND_DIRECT_RESP`` 671*54fd6939SJiyong Park- ``FFA_MEM_DONATE`` 672*54fd6939SJiyong Park- ``FFA_MEM_LEND`` 673*54fd6939SJiyong Park- ``FFA_MEM_SHARE`` 674*54fd6939SJiyong Park- ``FFA_MEM_RETRIEVE_REQ`` 675*54fd6939SJiyong Park- ``FFA_MEM_RETRIEVE_RESP`` 676*54fd6939SJiyong Park- ``FFA_MEM_RELINQUISH`` 677*54fd6939SJiyong Park- ``FFA_MEM_RECLAIM`` 678*54fd6939SJiyong Park 679*54fd6939SJiyong ParkAs part of the support of FF-A v1.1, the following interfaces were added: 680*54fd6939SJiyong Park 681*54fd6939SJiyong Park - ``FFA_NOTIFICATION_BITMAP_CREATE`` 682*54fd6939SJiyong Park - ``FFA_NOTIFICATION_BITMAP_DESTROY`` 683*54fd6939SJiyong Park - ``FFA_NOTIFICATION_BIND`` 684*54fd6939SJiyong Park - ``FFA_NOTIFICATION_UNBIND`` 685*54fd6939SJiyong Park - ``FFA_NOTIFICATION_SET`` 686*54fd6939SJiyong Park - ``FFA_NOTIFICATION_GET`` 687*54fd6939SJiyong Park - ``FFA_NOTIFICATION_INFO_GET`` 688*54fd6939SJiyong Park - ``FFA_SPM_ID_GET`` 689*54fd6939SJiyong Park - ``FFA_SECONDARY_EP_REGISTER`` 690*54fd6939SJiyong Park 691*54fd6939SJiyong ParkFFA_VERSION 692*54fd6939SJiyong Park~~~~~~~~~~~ 693*54fd6939SJiyong Park 694*54fd6939SJiyong Park``FFA_VERSION`` requires a *requested_version* parameter from the caller. 695*54fd6939SJiyong ParkThe returned value depends on the caller: 696*54fd6939SJiyong Park 697*54fd6939SJiyong Park- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version 698*54fd6939SJiyong Park specified in the SPMC manifest. 699*54fd6939SJiyong Park- SP: the SPMC returns its own implemented version. 700*54fd6939SJiyong Park- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version. 701*54fd6939SJiyong Park 702*54fd6939SJiyong ParkFFA_FEATURES 703*54fd6939SJiyong Park~~~~~~~~~~~~ 704*54fd6939SJiyong Park 705*54fd6939SJiyong ParkFF-A features supported by the SPMC may be discovered by secure partitions at 706*54fd6939SJiyong Parkboot (that is prior to NWd is booted) or run-time. 707*54fd6939SJiyong Park 708*54fd6939SJiyong ParkThe SPMC calling FFA_FEATURES at secure physical FF-A instance always get 709*54fd6939SJiyong ParkFFA_SUCCESS from the SPMD. 710*54fd6939SJiyong Park 711*54fd6939SJiyong ParkThe request made by an Hypervisor or OS kernel is forwarded to the SPMC and 712*54fd6939SJiyong Parkthe response relayed back to the NWd. 713*54fd6939SJiyong Park 714*54fd6939SJiyong ParkFFA_RXTX_MAP/FFA_RXTX_UNMAP 715*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~ 716*54fd6939SJiyong Park 717*54fd6939SJiyong ParkWhen invoked from a secure partition FFA_RXTX_MAP maps the provided send and 718*54fd6939SJiyong Parkreceive buffers described by their IPAs to the SP EL1&0 Stage-2 translation 719*54fd6939SJiyong Parkregime as secure buffers in the MMU descriptors. 720*54fd6939SJiyong Park 721*54fd6939SJiyong ParkWhen invoked from the Hypervisor or OS kernel, the buffers are mapped into the 722*54fd6939SJiyong ParkSPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU 723*54fd6939SJiyong Parkdescriptors. 724*54fd6939SJiyong Park 725*54fd6939SJiyong ParkThe FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the 726*54fd6939SJiyong Parkcaller, either it being the Hypervisor or OS kernel, as well as a secure 727*54fd6939SJiyong Parkpartition. 728*54fd6939SJiyong Park 729*54fd6939SJiyong ParkFFA_PARTITION_INFO_GET 730*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~ 731*54fd6939SJiyong Park 732*54fd6939SJiyong ParkPartition info get call can originate: 733*54fd6939SJiyong Park 734*54fd6939SJiyong Park- from SP to SPMC 735*54fd6939SJiyong Park- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD. 736*54fd6939SJiyong Park 737*54fd6939SJiyong ParkFFA_ID_GET 738*54fd6939SJiyong Park~~~~~~~~~~ 739*54fd6939SJiyong Park 740*54fd6939SJiyong ParkThe FF-A id space is split into a non-secure space and secure space: 741*54fd6939SJiyong Park 742*54fd6939SJiyong Park- FF-A ID with bit 15 clear relates to VMs. 743*54fd6939SJiyong Park- FF-A ID with bit 15 set related to SPs. 744*54fd6939SJiyong Park- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD 745*54fd6939SJiyong Park and SPMC. 746*54fd6939SJiyong Park 747*54fd6939SJiyong ParkThe SPMD returns: 748*54fd6939SJiyong Park 749*54fd6939SJiyong Park- The default zero value on invocation from the Hypervisor. 750*54fd6939SJiyong Park- The ``spmc_id`` value specified in the SPMC manifest on invocation from 751*54fd6939SJiyong Park the SPMC (see `SPMC manifest`_) 752*54fd6939SJiyong Park 753*54fd6939SJiyong ParkThis convention helps the SPMC to determine the origin and destination worlds in 754*54fd6939SJiyong Parkan FF-A ABI invocation. In particular the SPMC shall filter unauthorized 755*54fd6939SJiyong Parktransactions in its world switch routine. It must not be permitted for a VM to 756*54fd6939SJiyong Parkuse a secure FF-A ID as origin world by spoofing: 757*54fd6939SJiyong Park 758*54fd6939SJiyong Park- A VM-to-SP direct request/response shall set the origin world to be non-secure 759*54fd6939SJiyong Park (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15 760*54fd6939SJiyong Park set). 761*54fd6939SJiyong Park- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15 762*54fd6939SJiyong Park for both origin and destination IDs. 763*54fd6939SJiyong Park 764*54fd6939SJiyong ParkAn incoming direct message request arriving at SPMD from NWd is forwarded to 765*54fd6939SJiyong ParkSPMC without a specific check. The SPMC is resumed through eret and "knows" the 766*54fd6939SJiyong Parkmessage is coming from normal world in this specific code path. Thus the origin 767*54fd6939SJiyong Parkendpoint ID must be checked by SPMC for being a normal world ID. 768*54fd6939SJiyong Park 769*54fd6939SJiyong ParkAn SP sending a direct message request must have bit 15 set in its origin 770*54fd6939SJiyong Parkendpoint ID and this can be checked by the SPMC when the SP invokes the ABI. 771*54fd6939SJiyong Park 772*54fd6939SJiyong ParkThe SPMC shall reject the direct message if the claimed world in origin endpoint 773*54fd6939SJiyong ParkID is not consistent: 774*54fd6939SJiyong Park 775*54fd6939SJiyong Park- It is either forwarded by SPMD and thus origin endpoint ID must be a "normal 776*54fd6939SJiyong Park world ID", 777*54fd6939SJiyong Park- or initiated by an SP and thus origin endpoint ID must be a "secure world ID". 778*54fd6939SJiyong Park 779*54fd6939SJiyong Park 780*54fd6939SJiyong ParkFFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP 781*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 782*54fd6939SJiyong Park 783*54fd6939SJiyong ParkThis is a mandatory interface for secure partitions consisting in direct request 784*54fd6939SJiyong Parkand responses with the following rules: 785*54fd6939SJiyong Park 786*54fd6939SJiyong Park- An SP can send a direct request to another SP. 787*54fd6939SJiyong Park- An SP can receive a direct request from another SP. 788*54fd6939SJiyong Park- An SP can send a direct response to another SP. 789*54fd6939SJiyong Park- An SP cannot send a direct request to an Hypervisor or OS kernel. 790*54fd6939SJiyong Park- An Hypervisor or OS kernel can send a direct request to an SP. 791*54fd6939SJiyong Park- An SP can send a direct response to an Hypervisor or OS kernel. 792*54fd6939SJiyong Park 793*54fd6939SJiyong ParkFFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY 794*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 795*54fd6939SJiyong Park 796*54fd6939SJiyong ParkThe secure partitions notifications bitmap are statically allocated by the SPMC. 797*54fd6939SJiyong ParkHence, this interface is not to be issued by secure partitions. 798*54fd6939SJiyong Park 799*54fd6939SJiyong ParkAt initialization, the SPMC is not aware of VMs/partitions deployed in the 800*54fd6939SJiyong Parknormal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC 801*54fd6939SJiyong Parkto be prepared to handle notifications for the provided VM ID. 802*54fd6939SJiyong Park 803*54fd6939SJiyong ParkFFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND 804*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 805*54fd6939SJiyong Park 806*54fd6939SJiyong ParkPair of interfaces to manage permissions to signal notifications. Prior to 807*54fd6939SJiyong Parkhandling notifications, an FF-A endpoint must allow a given sender to signal a 808*54fd6939SJiyong Parkbitmap of notifications. 809*54fd6939SJiyong Park 810*54fd6939SJiyong ParkIf the receiver doesn't have notification support enabled in its FF-A manifest, 811*54fd6939SJiyong Parkit won't be able to bind notifications, hence forbidding it to receive any 812*54fd6939SJiyong Parknotifications. 813*54fd6939SJiyong Park 814*54fd6939SJiyong ParkFFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET 815*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 816*54fd6939SJiyong Park 817*54fd6939SJiyong ParkIf the notifications set are per-vCPU, the NPI interrupt is set as pending 818*54fd6939SJiyong Parkfor a given receiver partition. 819*54fd6939SJiyong Park 820*54fd6939SJiyong ParkThe FFA_NOTIFICATION_GET will retrieve all pending global notifications and all 821*54fd6939SJiyong Parkpending per-vCPU notifications targeted to the current vCPU. 822*54fd6939SJiyong Park 823*54fd6939SJiyong ParkHafnium keeps the global counting of the pending notifications, which is 824*54fd6939SJiyong Parkincremented and decremented at the handling of FFA_NOTIFICATION_SET and 825*54fd6939SJiyong ParkFFA_NOTIFICATION_GET, respectively. If the counter reaches zero, prior to SPMC 826*54fd6939SJiyong Parktriggering the SRI, it won't be triggered. 827*54fd6939SJiyong Park 828*54fd6939SJiyong ParkFFA_NOTIFICATION_INFO_GET 829*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~ 830*54fd6939SJiyong Park 831*54fd6939SJiyong ParkHafnium keeps the global counting of pending notifications whose info has been 832*54fd6939SJiyong Parkretrieved by this interface. The counting is incremented and decremented at the 833*54fd6939SJiyong Parkhandling of FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET, respectively. 834*54fd6939SJiyong ParkIt also tracks the notifications whose info has been retrieved individually, 835*54fd6939SJiyong Parksuch that it avoids duplicating returned information for subsequent calls to 836*54fd6939SJiyong ParkFFA_NOTIFICATION_INFO_GET. For each notification, this state information is 837*54fd6939SJiyong Parkreset when receiver called FFA_NOTIFICATION_GET to retrieve them. 838*54fd6939SJiyong Park 839*54fd6939SJiyong ParkFFA_SPM_ID_GET 840*54fd6939SJiyong Park~~~~~~~~~~~~~~ 841*54fd6939SJiyong Park 842*54fd6939SJiyong ParkReturns the FF-A ID allocated to the SPM component (which includes SPMC + SPMD). 843*54fd6939SJiyong ParkAt initialization, the SPMC queries the SPMD for the SPM ID, using this 844*54fd6939SJiyong Parksame interface, and saves it. 845*54fd6939SJiyong Park 846*54fd6939SJiyong ParkThe call emitted at NS and secure physical FF-A instances returns the SPM ID 847*54fd6939SJiyong Parkspecified in the SPMC manifest. 848*54fd6939SJiyong Park 849*54fd6939SJiyong ParkSecure partitions call this interface at the virtual instance, to which the SPMC 850*54fd6939SJiyong Parkshall return the priorly retrieved SPM ID. 851*54fd6939SJiyong Park 852*54fd6939SJiyong ParkThe Hypervisor or OS kernel can issue an FFA_SPM_ID_GET call handled by the 853*54fd6939SJiyong ParkSPMD, which returns the SPM ID. 854*54fd6939SJiyong Park 855*54fd6939SJiyong ParkFFA_SECONDARY_EP_REGISTER 856*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~ 857*54fd6939SJiyong Park 858*54fd6939SJiyong ParkWhen the SPMC boots, all secure partitions are initialized on their primary 859*54fd6939SJiyong ParkExecution Context. 860*54fd6939SJiyong Park 861*54fd6939SJiyong ParkThe interface FFA_SECONDARY_EP_REGISTER is to be used by a secure partitions 862*54fd6939SJiyong Parkfrom its first execution context, to provide the entry point address for 863*54fd6939SJiyong Parksecondary execution contexts. 864*54fd6939SJiyong Park 865*54fd6939SJiyong ParkA secondary EC is first resumed either upon invocation of PSCI_CPU_ON from 866*54fd6939SJiyong Parkthe NWd or by invocation of FFA_RUN. 867*54fd6939SJiyong Park 868*54fd6939SJiyong ParkSPMC-SPMD direct requests/responses 869*54fd6939SJiyong Park----------------------------------- 870*54fd6939SJiyong Park 871*54fd6939SJiyong ParkImplementation-defined FF-A IDs are allocated to the SPMC and SPMD. 872*54fd6939SJiyong ParkUsing those IDs in source/destination fields of a direct request/response 873*54fd6939SJiyong Parkpermits SPMD to SPMC communication and either way. 874*54fd6939SJiyong Park 875*54fd6939SJiyong Park- SPMC to SPMD direct request/response uses SMC conduit. 876*54fd6939SJiyong Park- SPMD to SPMC direct request/response uses ERET conduit. 877*54fd6939SJiyong Park 878*54fd6939SJiyong ParkPE MMU configuration 879*54fd6939SJiyong Park-------------------- 880*54fd6939SJiyong Park 881*54fd6939SJiyong ParkWith secure virtualization enabled, two IPA spaces are output from the secure 882*54fd6939SJiyong ParkEL1&0 Stage-1 translation (secure and non-secure). The EL1&0 Stage-2 translation 883*54fd6939SJiyong Parkhardware is fed by: 884*54fd6939SJiyong Park 885*54fd6939SJiyong Park- A single secure IPA space when the SP EL1&0 Stage-1 MMU is disabled. 886*54fd6939SJiyong Park- Two IPA spaces (secure and non-secure) when the SP EL1&0 Stage-1 MMU is 887*54fd6939SJiyong Park enabled. 888*54fd6939SJiyong Park 889*54fd6939SJiyong Park``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the 890*54fd6939SJiyong ParkNS/S IPA translations. 891*54fd6939SJiyong Park``VSTCR_EL2.SW`` = 0, ``VSTCR_EL2.SA`` = 0,``VTCR_EL2.NSW`` = 0, ``VTCR_EL2.NSA`` = 1: 892*54fd6939SJiyong Park 893*54fd6939SJiyong Park- Stage-2 translations for the NS IPA space access the NS PA space. 894*54fd6939SJiyong Park- Stage-2 translation table walks for the NS IPA space are to the secure PA space. 895*54fd6939SJiyong Park 896*54fd6939SJiyong ParkSecure and non-secure IPA regions use the same set of Stage-2 page tables within 897*54fd6939SJiyong Parka SP. 898*54fd6939SJiyong Park 899*54fd6939SJiyong ParkInterrupt management 900*54fd6939SJiyong Park-------------------- 901*54fd6939SJiyong Park 902*54fd6939SJiyong ParkGIC ownership 903*54fd6939SJiyong Park~~~~~~~~~~~~~ 904*54fd6939SJiyong Park 905*54fd6939SJiyong ParkThe SPMC owns the GIC configuration. Secure and non-secure interrupts are 906*54fd6939SJiyong Parktrapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt 907*54fd6939SJiyong ParkIDs based on SP manifests. The SPMC acknowledges physical interrupts and injects 908*54fd6939SJiyong Parkvirtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP. 909*54fd6939SJiyong Park 910*54fd6939SJiyong ParkNon-secure interrupt handling 911*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 912*54fd6939SJiyong Park 913*54fd6939SJiyong ParkThe following illustrate the scenarios of non secure physical interrupts trapped 914*54fd6939SJiyong Parkby the SPMC: 915*54fd6939SJiyong Park 916*54fd6939SJiyong Park- The SP handles a managed exit operation: 917*54fd6939SJiyong Park 918*54fd6939SJiyong Park.. image:: ../resources/diagrams/ffa-ns-interrupt-handling-managed-exit.png 919*54fd6939SJiyong Park 920*54fd6939SJiyong Park- The SP is pre-empted without managed exit: 921*54fd6939SJiyong Park 922*54fd6939SJiyong Park.. image:: ../resources/diagrams/ffa-ns-interrupt-handling-sp-preemption.png 923*54fd6939SJiyong Park 924*54fd6939SJiyong ParkSecure interrupt handling 925*54fd6939SJiyong Park------------------------- 926*54fd6939SJiyong Park 927*54fd6939SJiyong ParkThis section documents the support implemented for secure interrupt handling in 928*54fd6939SJiyong ParkSPMC as per the guidance provided by FF-A v1.1 Beta0 specification. 929*54fd6939SJiyong ParkThe following assumptions are made about the system configuration: 930*54fd6939SJiyong Park 931*54fd6939SJiyong Park - In the current implementation, S-EL1 SPs are expected to use the para 932*54fd6939SJiyong Park virtualized ABIs for interrupt management rather than accessing virtual GIC 933*54fd6939SJiyong Park interface. 934*54fd6939SJiyong Park - Unless explicitly stated otherwise, this support is applicable only for 935*54fd6939SJiyong Park S-EL1 SPs managed by SPMC. 936*54fd6939SJiyong Park - Secure interrupts are configured as G1S or G0 interrupts. 937*54fd6939SJiyong Park - All physical interrupts are routed to SPMC when running a secure partition 938*54fd6939SJiyong Park execution context. 939*54fd6939SJiyong Park 940*54fd6939SJiyong ParkA physical secure interrupt could preempt normal world execution. Moreover, when 941*54fd6939SJiyong Parkthe execution is in secure world, it is highly likely that the target of a 942*54fd6939SJiyong Parksecure interrupt is not the currently running execution context of an SP. It 943*54fd6939SJiyong Parkcould be targeted to another FF-A component. Consequently, secure interrupt 944*54fd6939SJiyong Parkmanagement depends on the state of the target execution context of the SP that 945*54fd6939SJiyong Parkis responsible for handling the interrupt. Hence, the spec provides guidance on 946*54fd6939SJiyong Parkhow to signal start and completion of secure interrupt handling as discussed in 947*54fd6939SJiyong Parkfurther sections. 948*54fd6939SJiyong Park 949*54fd6939SJiyong ParkSecure interrupt signaling mechanisms 950*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 951*54fd6939SJiyong Park 952*54fd6939SJiyong ParkSignaling refers to the mechanisms used by SPMC to indicate to the SP execution 953*54fd6939SJiyong Parkcontext that it has a pending virtual interrupt and to further run the SP 954*54fd6939SJiyong Parkexecution context, such that it can handle the virtual interrupt. SPMC uses 955*54fd6939SJiyong Parkeither the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling 956*54fd6939SJiyong Parkto S-EL1 SPs. When normal world execution is preempted by a secure interrupt, 957*54fd6939SJiyong Parkthe SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC 958*54fd6939SJiyong Parkrunning in S-EL2. 959*54fd6939SJiyong Park 960*54fd6939SJiyong Park+-----------+---------+---------------+---------------------------------------+ 961*54fd6939SJiyong Park| SP State | Conduit | Interface and | Description | 962*54fd6939SJiyong Park| | | parameters | | 963*54fd6939SJiyong Park+-----------+---------+---------------+---------------------------------------+ 964*54fd6939SJiyong Park| WAITING | ERET, | FFA_INTERRUPT,| SPMC signals to SP the ID of pending | 965*54fd6939SJiyong Park| | vIRQ | Interrupt ID | interrupt. It pends vIRQ signal and | 966*54fd6939SJiyong Park| | | | resumes execution context of SP | 967*54fd6939SJiyong Park| | | | through ERET. | 968*54fd6939SJiyong Park+-----------+---------+---------------+---------------------------------------+ 969*54fd6939SJiyong Park| BLOCKED | ERET, | FFA_INTERRUPT | SPMC signals to SP that an interrupt | 970*54fd6939SJiyong Park| | vIRQ | | is pending. It pends vIRQ signal and | 971*54fd6939SJiyong Park| | | | resumes execution context of SP | 972*54fd6939SJiyong Park| | | | through ERET. | 973*54fd6939SJiyong Park+-----------+---------+---------------+---------------------------------------+ 974*54fd6939SJiyong Park| PREEMPTED | vIRQ | NA | SPMC pends the vIRQ signal but does | 975*54fd6939SJiyong Park| | | | not resume execution context of SP. | 976*54fd6939SJiyong Park+-----------+---------+---------------+---------------------------------------+ 977*54fd6939SJiyong Park| RUNNING | ERET, | NA | SPMC pends the vIRQ signal and resumes| 978*54fd6939SJiyong Park| | vIRQ | | execution context of SP through ERET. | 979*54fd6939SJiyong Park+-----------+---------+---------------+---------------------------------------+ 980*54fd6939SJiyong Park 981*54fd6939SJiyong ParkSecure interrupt completion mechanisms 982*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 983*54fd6939SJiyong Park 984*54fd6939SJiyong ParkA SP signals secure interrupt handling completion to the SPMC through the 985*54fd6939SJiyong Parkfollowing mechanisms: 986*54fd6939SJiyong Park 987*54fd6939SJiyong Park - ``FFA_MSG_WAIT`` ABI if it was in WAITING state. 988*54fd6939SJiyong Park - ``FFA_RUN`` ABI if its was in BLOCKED state. 989*54fd6939SJiyong Park 990*54fd6939SJiyong ParkIn the current implementation, S-EL1 SPs use para-virtualized HVC interface 991*54fd6939SJiyong Parkimplemented by SPMC to perform priority drop and interrupt deactivation (we 992*54fd6939SJiyong Parkassume EOImode = 0, i.e. priority drop and deactivation are done together). 993*54fd6939SJiyong Park 994*54fd6939SJiyong ParkIf normal world execution was preempted by secure interrupt, SPMC uses 995*54fd6939SJiyong ParkFFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling 996*54fd6939SJiyong Parkand further return execution to normal world. If the current SP execution 997*54fd6939SJiyong Parkcontext was preempted by a secure interrupt to be handled by execution context 998*54fd6939SJiyong Parkof target SP, SPMC resumes current SP after signal completion by target SP 999*54fd6939SJiyong Parkexecution context. 1000*54fd6939SJiyong Park 1001*54fd6939SJiyong ParkAn action is broadly a set of steps taken by the SPMC in response to a physical 1002*54fd6939SJiyong Parkinterrupt. In order to simplify the design, the current version of secure 1003*54fd6939SJiyong Parkinterrupt management support in SPMC (Hafnium) does not fully implement the 1004*54fd6939SJiyong ParkScheduling models and Partition runtime models. However, the current 1005*54fd6939SJiyong Parkimplementation loosely maps to the following actions that are legally allowed 1006*54fd6939SJiyong Parkby the specification. Please refer to the Table 8.4 in the spec for further 1007*54fd6939SJiyong Parkdescription of actions. The action specified for a type of interrupt when the 1008*54fd6939SJiyong ParkSP is in the message processing running state cannot be less permissive than the 1009*54fd6939SJiyong Parkaction specified for the same type of interrupt when the SP is in the interrupt 1010*54fd6939SJiyong Parkhandling running state. 1011*54fd6939SJiyong Park 1012*54fd6939SJiyong Park+--------------------+--------------------+------------+-------------+ 1013*54fd6939SJiyong Park| Runtime Model | NS-Int | Self S-Int | Other S-Int | 1014*54fd6939SJiyong Park+--------------------+--------------------+------------+-------------+ 1015*54fd6939SJiyong Park| Message Processing | Signalable with ME | Signalable | Signalable | 1016*54fd6939SJiyong Park+--------------------+--------------------+------------+-------------+ 1017*54fd6939SJiyong Park| Interrupt Handling | Queued | Queued | Queued | 1018*54fd6939SJiyong Park+--------------------+--------------------+------------+-------------+ 1019*54fd6939SJiyong Park 1020*54fd6939SJiyong ParkAbbreviations: 1021*54fd6939SJiyong Park 1022*54fd6939SJiyong Park - NS-Int: A Non-secure physical interrupt. It requires a switch to the Normal 1023*54fd6939SJiyong Park world to be handled. 1024*54fd6939SJiyong Park - Other S-Int: A secure physical interrupt targeted to an SP different from 1025*54fd6939SJiyong Park the one that is currently running. 1026*54fd6939SJiyong Park - Self S-Int: A secure physical interrupt targeted to the SP that is currently 1027*54fd6939SJiyong Park running. 1028*54fd6939SJiyong Park 1029*54fd6939SJiyong ParkThe following figure describes interrupt handling flow when secure interrupt 1030*54fd6939SJiyong Parktriggers while in normal world: 1031*54fd6939SJiyong Park 1032*54fd6939SJiyong Park.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png 1033*54fd6939SJiyong Park 1034*54fd6939SJiyong ParkA brief description of the events: 1035*54fd6939SJiyong Park 1036*54fd6939SJiyong Park - 1) Secure interrupt triggers while normal world is running. 1037*54fd6939SJiyong Park - 2) FIQ gets trapped to EL3. 1038*54fd6939SJiyong Park - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI. 1039*54fd6939SJiyong Park - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends 1040*54fd6939SJiyong Park vIRQ). 1041*54fd6939SJiyong Park - 5) Since SP1 vCPU is in WAITING state, SPMC signals using FFA_INTERRUPT with 1042*54fd6939SJiyong Park interrupt id as argument and resume it using ERET. 1043*54fd6939SJiyong Park - 6) Execution traps to vIRQ handler in SP1 provided that interrupt is not 1044*54fd6939SJiyong Park masked i.e., PSTATE.I = 0 1045*54fd6939SJiyong Park - 7) SP1 services the interrupt and invokes the de-activation HVC call. 1046*54fd6939SJiyong Park - 8) SPMC does internal state management and further de-activates the physical 1047*54fd6939SJiyong Park interrupt and resumes SP vCPU. 1048*54fd6939SJiyong Park - 9) SP performs secure interrupt completion through FFA_MSG_WAIT ABI. 1049*54fd6939SJiyong Park - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME. 1050*54fd6939SJiyong Park - 11) EL3 resumes normal world execution. 1051*54fd6939SJiyong Park 1052*54fd6939SJiyong ParkThe following figure describes interrupt handling flow when secure interrupt 1053*54fd6939SJiyong Parktriggers while in secure world: 1054*54fd6939SJiyong Park 1055*54fd6939SJiyong Park.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png 1056*54fd6939SJiyong Park 1057*54fd6939SJiyong ParkA brief description of the events: 1058*54fd6939SJiyong Park 1059*54fd6939SJiyong Park - 1) Secure interrupt triggers while SP2 is running and SP1 is blocked. 1060*54fd6939SJiyong Park - 2) Gets trapped to SPMC as IRQ. 1061*54fd6939SJiyong Park - 3) SPMC finds the target vCPU of secure partition responsible for handling 1062*54fd6939SJiyong Park this secure interrupt. In this scenario, it is SP1. 1063*54fd6939SJiyong Park - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface. 1064*54fd6939SJiyong Park SPMC further resumes SP1 through ERET conduit. 1065*54fd6939SJiyong Park - 5) Execution traps to vIRQ handler in SP1 provided that interrupt is not 1066*54fd6939SJiyong Park masked i.e., PSTATE.I = 0 1067*54fd6939SJiyong Park - 6) SP1 services the secure interrupt and invokes the de-activation HVC call. 1068*54fd6939SJiyong Park - 7) SPMC does internal state management, de-activates the physical interrupt 1069*54fd6939SJiyong Park and resumes SP1 vCPU. 1070*54fd6939SJiyong Park - 8) Assuming SP1 is in BLOCKED state, SP1 performs secure interrupt completion 1071*54fd6939SJiyong Park through FFA_RUN ABI. 1072*54fd6939SJiyong Park - 9) SPMC resumes the pre-empted vCPU of SP2. 1073*54fd6939SJiyong Park 1074*54fd6939SJiyong Park 1075*54fd6939SJiyong ParkPower management 1076*54fd6939SJiyong Park---------------- 1077*54fd6939SJiyong Park 1078*54fd6939SJiyong ParkIn platforms with or without secure virtualization: 1079*54fd6939SJiyong Park 1080*54fd6939SJiyong Park- The NWd owns the platform PM policy. 1081*54fd6939SJiyong Park- The Hypervisor or OS kernel is the component initiating PSCI service calls. 1082*54fd6939SJiyong Park- The EL3 PSCI library is in charge of the PM coordination and control 1083*54fd6939SJiyong Park (eventually writing to platform registers). 1084*54fd6939SJiyong Park- While coordinating PM events, the PSCI library calls backs into the Secure 1085*54fd6939SJiyong Park Payload Dispatcher for events the latter has statically registered to. 1086*54fd6939SJiyong Park 1087*54fd6939SJiyong ParkWhen using the SPMD as a Secure Payload Dispatcher: 1088*54fd6939SJiyong Park 1089*54fd6939SJiyong Park- A power management event is relayed through the SPD hook to the SPMC. 1090*54fd6939SJiyong Park- In the current implementation only cpu on (svc_on_finish) and cpu off 1091*54fd6939SJiyong Park (svc_off) hooks are registered. 1092*54fd6939SJiyong Park- The behavior for the cpu on event is described in `Secondary cores boot-up`_. 1093*54fd6939SJiyong Park The SPMC is entered through its secondary physical core entry point. 1094*54fd6939SJiyong Park- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The method by which 1095*54fd6939SJiyong Park the PM event is conveyed to the SPMC is implementation-defined in context of 1096*54fd6939SJiyong Park FF-A v1.0 (`SPMC-SPMD direct requests/responses`_). It consists in a SPMD-to-SPMC 1097*54fd6939SJiyong Park direct request/response conveying the PM event details and SPMC response. 1098*54fd6939SJiyong Park The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and 1099*54fd6939SJiyong Park updates its internal state to reflect the physical core is being turned off. 1100*54fd6939SJiyong Park In the current implementation no SP is resumed as a consequence. This behavior 1101*54fd6939SJiyong Park ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux 1102*54fd6939SJiyong Park userspace. 1103*54fd6939SJiyong Park 1104*54fd6939SJiyong ParkSMMUv3 support in Hafnium 1105*54fd6939SJiyong Park========================= 1106*54fd6939SJiyong Park 1107*54fd6939SJiyong ParkAn SMMU is analogous to an MMU in a CPU. It performs address translations for 1108*54fd6939SJiyong ParkDirect Memory Access (DMA) requests from system I/O devices. 1109*54fd6939SJiyong ParkThe responsibilities of an SMMU include: 1110*54fd6939SJiyong Park 1111*54fd6939SJiyong Park- Translation: Incoming DMA requests are translated from bus address space to 1112*54fd6939SJiyong Park system physical address space using translation tables compliant to 1113*54fd6939SJiyong Park Armv8/Armv7 VMSA descriptor format. 1114*54fd6939SJiyong Park- Protection: An I/O device can be prohibited from read, write access to a 1115*54fd6939SJiyong Park memory region or allowed. 1116*54fd6939SJiyong Park- Isolation: Traffic from each individial device can be independently managed. 1117*54fd6939SJiyong Park The devices are differentiated from each other using unique translation 1118*54fd6939SJiyong Park tables. 1119*54fd6939SJiyong Park 1120*54fd6939SJiyong ParkThe following diagram illustrates a typical SMMU IP integrated in a SoC with 1121*54fd6939SJiyong Parkseveral I/O devices along with Interconnect and Memory system. 1122*54fd6939SJiyong Park 1123*54fd6939SJiyong Park.. image:: ../resources/diagrams/MMU-600.png 1124*54fd6939SJiyong Park 1125*54fd6939SJiyong ParkSMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides 1126*54fd6939SJiyong Parksupport for SMMUv3 driver in both normal and secure world. A brief introduction 1127*54fd6939SJiyong Parkof SMMUv3 functionality and the corresponding software support in Hafnium is 1128*54fd6939SJiyong Parkprovided here. 1129*54fd6939SJiyong Park 1130*54fd6939SJiyong ParkSMMUv3 features 1131*54fd6939SJiyong Park--------------- 1132*54fd6939SJiyong Park 1133*54fd6939SJiyong Park- SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2) 1134*54fd6939SJiyong Park translation support. It can either bypass or abort incoming translations as 1135*54fd6939SJiyong Park well. 1136*54fd6939SJiyong Park- Traffic (memory transactions) from each upstream I/O peripheral device, 1137*54fd6939SJiyong Park referred to as Stream, can be independently managed using a combination of 1138*54fd6939SJiyong Park several memory based configuration structures. This allows the SMMUv3 to 1139*54fd6939SJiyong Park support a large number of streams with each stream assigned to a unique 1140*54fd6939SJiyong Park translation context. 1141*54fd6939SJiyong Park- Support for Armv8.1 VMSA where the SMMU shares the translation tables with 1142*54fd6939SJiyong Park a Processing Element. AArch32(LPAE) and AArch64 translation table format 1143*54fd6939SJiyong Park are supported by SMMUv3. 1144*54fd6939SJiyong Park- SMMUv3 offers non-secure stream support with secure stream support being 1145*54fd6939SJiyong Park optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU 1146*54fd6939SJiyong Park instance for secure and non-secure stream support. 1147*54fd6939SJiyong Park- It also supports sub-streams to differentiate traffic from a virtualized 1148*54fd6939SJiyong Park peripheral associated with a VM/SP. 1149*54fd6939SJiyong Park- Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A 1150*54fd6939SJiyong Park extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2 1151*54fd6939SJiyong Park for providing Secure Stage2 translation support to upstream peripheral 1152*54fd6939SJiyong Park devices. 1153*54fd6939SJiyong Park 1154*54fd6939SJiyong ParkSMMUv3 Programming Interfaces 1155*54fd6939SJiyong Park----------------------------- 1156*54fd6939SJiyong Park 1157*54fd6939SJiyong ParkSMMUv3 has three software interfaces that are used by the Hafnium driver to 1158*54fd6939SJiyong Parkconfigure the behaviour of SMMUv3 and manage the streams. 1159*54fd6939SJiyong Park 1160*54fd6939SJiyong Park- Memory based data strutures that provide unique translation context for 1161*54fd6939SJiyong Park each stream. 1162*54fd6939SJiyong Park- Memory based circular buffers for command queue and event queue. 1163*54fd6939SJiyong Park- A large number of SMMU configuration registers that are memory mapped during 1164*54fd6939SJiyong Park boot time by Hafnium driver. Except a few registers, all configuration 1165*54fd6939SJiyong Park registers have independent secure and non-secure versions to configure the 1166*54fd6939SJiyong Park behaviour of SMMUv3 for translation of secure and non-secure streams 1167*54fd6939SJiyong Park respectively. 1168*54fd6939SJiyong Park 1169*54fd6939SJiyong ParkPeripheral device manifest 1170*54fd6939SJiyong Park-------------------------- 1171*54fd6939SJiyong Park 1172*54fd6939SJiyong ParkCurrently, SMMUv3 driver in Hafnium only supports dependent peripheral devices. 1173*54fd6939SJiyong ParkThese devices are dependent on PE endpoint to initiate and receive memory 1174*54fd6939SJiyong Parkmanagement transactions on their behalf. The acccess to the MMIO regions of 1175*54fd6939SJiyong Parkany such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver 1176*54fd6939SJiyong Parkuses the same stage 2 translations for the device as those used by partition 1177*54fd6939SJiyong Parkmanager on behalf of the PE endpoint. This ensures that the peripheral device 1178*54fd6939SJiyong Parkhas the same visibility of the physical address space as the endpoint. The 1179*54fd6939SJiyong Parkdevice node of the corresponding partition manifest (refer to `[1]`_ section 3.2 1180*54fd6939SJiyong Park) must specify these additional properties for each peripheral device in the 1181*54fd6939SJiyong Parksystem : 1182*54fd6939SJiyong Park 1183*54fd6939SJiyong Park- smmu-id: This field helps to identify the SMMU instance that this device is 1184*54fd6939SJiyong Park upstream of. 1185*54fd6939SJiyong Park- stream-ids: List of stream IDs assigned to this device. 1186*54fd6939SJiyong Park 1187*54fd6939SJiyong Park.. code:: shell 1188*54fd6939SJiyong Park 1189*54fd6939SJiyong Park smmuv3-testengine { 1190*54fd6939SJiyong Park base-address = <0x00000000 0x2bfe0000>; 1191*54fd6939SJiyong Park pages-count = <32>; 1192*54fd6939SJiyong Park attributes = <0x3>; 1193*54fd6939SJiyong Park smmu-id = <0>; 1194*54fd6939SJiyong Park stream-ids = <0x0 0x1>; 1195*54fd6939SJiyong Park interrupts = <0x2 0x3>, <0x4 0x5>; 1196*54fd6939SJiyong Park exclusive-access; 1197*54fd6939SJiyong Park }; 1198*54fd6939SJiyong Park 1199*54fd6939SJiyong ParkSMMUv3 driver limitations 1200*54fd6939SJiyong Park------------------------- 1201*54fd6939SJiyong Park 1202*54fd6939SJiyong ParkThe primary design goal for the Hafnium SMMU driver is to support secure 1203*54fd6939SJiyong Parkstreams. 1204*54fd6939SJiyong Park 1205*54fd6939SJiyong Park- Currently, the driver only supports Stage2 translations. No support for 1206*54fd6939SJiyong Park Stage1 or nested translations. 1207*54fd6939SJiyong Park- Supports only AArch64 translation format. 1208*54fd6939SJiyong Park- No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS, 1209*54fd6939SJiyong Park Fault handling, Performance Monitor Extensions, Event Handling, MPAM. 1210*54fd6939SJiyong Park- No support for independent peripheral devices. 1211*54fd6939SJiyong Park 1212*54fd6939SJiyong ParkS-EL0 Partition support 1213*54fd6939SJiyong Park========================= 1214*54fd6939SJiyong ParkThe SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using 1215*54fd6939SJiyong ParkFEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world 1216*54fd6939SJiyong Parkwith ARMv8.4 and FEAT_SEL2). 1217*54fd6939SJiyong Park 1218*54fd6939SJiyong ParkS-EL0 partitions are useful for simple partitions that don't require full 1219*54fd6939SJiyong ParkTrusted OS functionality. It is also useful to reduce jitter and cycle 1220*54fd6939SJiyong Parkstealing from normal world since they are more lightweight than VMs. 1221*54fd6939SJiyong Park 1222*54fd6939SJiyong ParkS-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by 1223*54fd6939SJiyong Parkthe SPMC. They are differentiated primarily by the 'exception-level' property 1224*54fd6939SJiyong Parkand the 'execution-ctx-count' property in the SP manifest. They are host apps 1225*54fd6939SJiyong Parkunder the single EL2&0 Stage-1 translation regime controlled by the SPMC and 1226*54fd6939SJiyong Parkcall into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions 1227*54fd6939SJiyong Parkcan use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions 1228*54fd6939SJiyong Parkfor memory regions. 1229*54fd6939SJiyong Park 1230*54fd6939SJiyong ParkS-EL0 partitions are required by the FF-A specification to be UP endpoints, 1231*54fd6939SJiyong Parkcapable of migrating, and the SPMC enforces this requirement. The SPMC allows 1232*54fd6939SJiyong Parka S-EL0 partition to accept a direct message from secure world and normal world, 1233*54fd6939SJiyong Parkand generate direct responses to them. 1234*54fd6939SJiyong Park 1235*54fd6939SJiyong ParkMemory sharing between and with S-EL0 partitions is supported. 1236*54fd6939SJiyong ParkIndirect messaging, Interrupt handling and Notifications are not supported with 1237*54fd6939SJiyong ParkS-EL0 partitions and is work in progress, planned for future releases. 1238*54fd6939SJiyong ParkAll S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not 1239*54fd6939SJiyong Parksupported. 1240*54fd6939SJiyong Park 1241*54fd6939SJiyong Park 1242*54fd6939SJiyong ParkReferences 1243*54fd6939SJiyong Park========== 1244*54fd6939SJiyong Park 1245*54fd6939SJiyong Park.. _[1]: 1246*54fd6939SJiyong Park 1247*54fd6939SJiyong Park[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__ 1248*54fd6939SJiyong Park 1249*54fd6939SJiyong Park.. _[2]: 1250*54fd6939SJiyong Park 1251*54fd6939SJiyong Park[2] :ref:`Secure Partition Manager using MM interface<Secure Partition Manager (MM)>` 1252*54fd6939SJiyong Park 1253*54fd6939SJiyong Park.. _[3]: 1254*54fd6939SJiyong Park 1255*54fd6939SJiyong Park[3] `Trusted Boot Board Requirements 1256*54fd6939SJiyong ParkClient <https://developer.arm.com/documentation/den0006/d/>`__ 1257*54fd6939SJiyong Park 1258*54fd6939SJiyong Park.. _[4]: 1259*54fd6939SJiyong Park 1260*54fd6939SJiyong Park[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45 1261*54fd6939SJiyong Park 1262*54fd6939SJiyong Park.. _[5]: 1263*54fd6939SJiyong Park 1264*54fd6939SJiyong Park[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts 1265*54fd6939SJiyong Park 1266*54fd6939SJiyong Park.. _[6]: 1267*54fd6939SJiyong Park 1268*54fd6939SJiyong Park[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html 1269*54fd6939SJiyong Park 1270*54fd6939SJiyong Park.. _[7]: 1271*54fd6939SJiyong Park 1272*54fd6939SJiyong Park[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts 1273*54fd6939SJiyong Park 1274*54fd6939SJiyong Park.. _[8]: 1275*54fd6939SJiyong Park 1276*54fd6939SJiyong Park[8] https://lists.trustedfirmware.org/pipermail/tf-a/2020-February/000296.html 1277*54fd6939SJiyong Park 1278*54fd6939SJiyong Park.. _[9]: 1279*54fd6939SJiyong Park 1280*54fd6939SJiyong Park[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot 1281*54fd6939SJiyong Park 1282*54fd6939SJiyong Park-------------- 1283*54fd6939SJiyong Park 1284*54fd6939SJiyong Park*Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.* 1285