1*fcb1398fSOlivier DeprezSecure Partition Manager 2*fcb1398fSOlivier Deprez************************ 3*fcb1398fSOlivier Deprez 4*fcb1398fSOlivier Deprez.. contents:: 5*fcb1398fSOlivier Deprez 6*fcb1398fSOlivier DeprezAcronyms 7*fcb1398fSOlivier Deprez======== 8*fcb1398fSOlivier Deprez 9*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 10*fcb1398fSOlivier Deprez| DTB | Device Tree Blob | 11*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 12*fcb1398fSOlivier Deprez| DTS | Device Tree Source | 13*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 14*fcb1398fSOlivier Deprez| EC | Execution Context | 15*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 16*fcb1398fSOlivier Deprez| FIP | Firmware Image Package | 17*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 18*fcb1398fSOlivier Deprez| FF-A | Firmware Framework for A-class | 19*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 20*fcb1398fSOlivier Deprez| IPA | Intermediate Physical Address | 21*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 22*fcb1398fSOlivier Deprez| NWd | Normal World | 23*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 24*fcb1398fSOlivier Deprez| ODM | Original Design Manufacturer | 25*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 26*fcb1398fSOlivier Deprez| OEM | Original Equipment Manufacturer | 27*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 28*fcb1398fSOlivier Deprez| PA | Physical Address | 29*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 30*fcb1398fSOlivier Deprez| PE | Processing Element | 31*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 32*fcb1398fSOlivier Deprez| PVM | Primary VM | 33*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 34*fcb1398fSOlivier Deprez| PSA | Platform Security Architecture | 35*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 36*fcb1398fSOlivier Deprez| SP | Secure Partition | 37*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 38*fcb1398fSOlivier Deprez| SPM | Secure Partition Manager | 39*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 40*fcb1398fSOlivier Deprez| SPMC | SPM Core | 41*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 42*fcb1398fSOlivier Deprez| SPMD | SPM Dispatcher | 43*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 44*fcb1398fSOlivier Deprez| SiP | Silicon Provider | 45*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 46*fcb1398fSOlivier Deprez| SWd | Secure World | 47*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 48*fcb1398fSOlivier Deprez| TLV | Tag-Length-Value | 49*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 50*fcb1398fSOlivier Deprez| TOS | Trusted Operating System | 51*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 52*fcb1398fSOlivier Deprez| VM | Virtual Machine | 53*fcb1398fSOlivier Deprez+--------+-----------------------------------+ 54*fcb1398fSOlivier Deprez 55*fcb1398fSOlivier DeprezForeword 56*fcb1398fSOlivier Deprez======== 57*fcb1398fSOlivier Deprez 58*fcb1398fSOlivier DeprezTwo implementations of a Secure Partition Manager co-exist in the TF-A codebase: 59*fcb1398fSOlivier Deprez 60*fcb1398fSOlivier Deprez- SPM based on the PSA FF-A specification `[1]`_. 61*fcb1398fSOlivier Deprez- SPM based on the MM interface to communicate with an S-EL0 partition `[2]`_. 62*fcb1398fSOlivier Deprez 63*fcb1398fSOlivier DeprezBoth implementations differ in their architectures and only one can be selected 64*fcb1398fSOlivier Deprezat build time. 65*fcb1398fSOlivier Deprez 66*fcb1398fSOlivier DeprezThis document: 67*fcb1398fSOlivier Deprez 68*fcb1398fSOlivier Deprez- describes the PSA FF-A implementation where the Secure Partition Manager 69*fcb1398fSOlivier Deprez resides at EL3 and S-EL2 (or EL3 and S-EL1). 70*fcb1398fSOlivier Deprez- is not an architecture specification and it might provide assumptions 71*fcb1398fSOlivier Deprez on sections mandated as implementation-defined in the specification. 72*fcb1398fSOlivier Deprez- covers the implications to TF-A used as a bootloader, and Hafnium 73*fcb1398fSOlivier Deprez used as a reference code base for an S-EL2 secure firmware on 74*fcb1398fSOlivier Deprez platforms implementing Armv8.4-SecEL2. 75*fcb1398fSOlivier Deprez 76*fcb1398fSOlivier DeprezTerminology 77*fcb1398fSOlivier Deprez----------- 78*fcb1398fSOlivier Deprez 79*fcb1398fSOlivier Deprez- Hypervisor refers to the NS-EL2 component managing Virtual Machines (or 80*fcb1398fSOlivier Deprez partitions) in the Normal World. 81*fcb1398fSOlivier Deprez- SPMC refers to the S-EL2 component managing Virtual Machines (or Secure 82*fcb1398fSOlivier Deprez Partitions) in the Secure World when Armv8.4-SecEL2 extension is implemented. 83*fcb1398fSOlivier Deprez- Alternatively, SPMC can refer to an S-EL1 component, itself being a Secure 84*fcb1398fSOlivier Deprez Partition and implementing the FF-A ABI on pre-Armv8.4 platforms. 85*fcb1398fSOlivier Deprez- VM refers to a Normal World Virtual Machine managed by an Hypervisor. 86*fcb1398fSOlivier Deprez- SP refers to a Secure World "Virtual Machine" managed by the SPMC component. 87*fcb1398fSOlivier Deprez 88*fcb1398fSOlivier DeprezSupport for legacy platforms 89*fcb1398fSOlivier Deprez---------------------------- 90*fcb1398fSOlivier Deprez 91*fcb1398fSOlivier DeprezIn the implementation, the SPM is split into SPMD and SPMC components 92*fcb1398fSOlivier Deprez(although not strictly mandated by the specification). SPMD is located 93*fcb1398fSOlivier Deprezat EL3 and principally relays FF-A messages from NWd (Hypervisor or OS 94*fcb1398fSOlivier Deprezkernel) to SPMC located either at S-EL1 or S-EL2. 95*fcb1398fSOlivier Deprez 96*fcb1398fSOlivier DeprezHence TF-A must support both cases where SPMC is either located at: 97*fcb1398fSOlivier Deprez 98*fcb1398fSOlivier Deprez- S-EL1 supporting pre-Armv8.4 platforms. SPMD conveys FF-A protocol 99*fcb1398fSOlivier Deprez from EL3 to S-EL1. 100*fcb1398fSOlivier Deprez- S-EL2 supporting platforms implementing Armv8.4-SecEL2 extension. 101*fcb1398fSOlivier Deprez SPMD conveys FF-A protocol from EL3 to S-EL2. 102*fcb1398fSOlivier Deprez 103*fcb1398fSOlivier DeprezThe same SPMD component is used to support both configurations. The SPMC 104*fcb1398fSOlivier Deprezexecution level is a build time choice. 105*fcb1398fSOlivier Deprez 106*fcb1398fSOlivier DeprezSample reference stack 107*fcb1398fSOlivier Deprez====================== 108*fcb1398fSOlivier Deprez 109*fcb1398fSOlivier DeprezThe following diagram illustrates a possible configuration with SPMD and SPMC, 110*fcb1398fSOlivier Deprezone or multiple Secure Partitions, with or without an optional Hypervisor: 111*fcb1398fSOlivier Deprez 112*fcb1398fSOlivier Deprez.. image:: ../resources/diagrams/ff-a-spm-sel2.png 113*fcb1398fSOlivier Deprez 114*fcb1398fSOlivier DeprezTF-A build options 115*fcb1398fSOlivier Deprez================== 116*fcb1398fSOlivier Deprez 117*fcb1398fSOlivier DeprezThe following TF-A build options are provisioned: 118*fcb1398fSOlivier Deprez 119*fcb1398fSOlivier Deprez- **SPD=spmd**: this option selects the SPMD component to relay FF-A 120*fcb1398fSOlivier Deprez protocol from NWd to SWd back and forth. It is not possible to 121*fcb1398fSOlivier Deprez enable another Secure Payload Dispatcher when this option is chosen. 122*fcb1398fSOlivier Deprez- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC execution 123*fcb1398fSOlivier Deprez level to being S-EL1 or S-EL2. It defaults to enabled (value 1) when 124*fcb1398fSOlivier Deprez SPD=spmd is chosen. 125*fcb1398fSOlivier Deprez- **CTX_INCLUDE_EL2_REGS**: this option permits saving (resp. 126*fcb1398fSOlivier Deprez restoring) the EL2 system register context before entering (resp. 127*fcb1398fSOlivier Deprez after leaving) the SPMC. It is mandatory when ``SPMD_SPM_AT_SEL2`` is 128*fcb1398fSOlivier Deprez enabled. The context save/restore routine and exhaustive list of 129*fcb1398fSOlivier Deprez registers is visible at `[4] <#References>`__. 130*fcb1398fSOlivier Deprez- **SP_LAYOUT_FILE**: this option provides a text description file 131*fcb1398fSOlivier Deprez providing paths to SP binary images and DTS format manifests 132*fcb1398fSOlivier Deprez (see `Specifying partition binary image and DT`_). It 133*fcb1398fSOlivier Deprez is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple 134*fcb1398fSOlivier Deprez secure partitions are to be loaded on behalf of SPMC. 135*fcb1398fSOlivier Deprez 136*fcb1398fSOlivier Deprez+------------------------------+----------------------+------------------+ 137*fcb1398fSOlivier Deprez| | CTX_INCLUDE_EL2_REGS | SPMD_SPM_AT_SEL2 | 138*fcb1398fSOlivier Deprez+------------------------------+----------------------+------------------+ 139*fcb1398fSOlivier Deprez| SPMC at S-EL1 (e.g. OP-TEE) | 0 | 0 | 140*fcb1398fSOlivier Deprez+------------------------------+----------------------+------------------+ 141*fcb1398fSOlivier Deprez| SPMC at S-EL2 (e.g. Hafnium) | 1 | 1 (default when | 142*fcb1398fSOlivier Deprez| | | SPD=spmd) | 143*fcb1398fSOlivier Deprez+------------------------------+----------------------+------------------+ 144*fcb1398fSOlivier Deprez 145*fcb1398fSOlivier DeprezOther combinations of such build options either break the build or are not 146*fcb1398fSOlivier Deprezsupported. 147*fcb1398fSOlivier Deprez 148*fcb1398fSOlivier DeprezNote, the ``CTX_INCLUDE_EL2_REGS`` option provides the generic support for 149*fcb1398fSOlivier Deprezbarely saving/restoring EL2 registers from an Arm arch perspective. As such 150*fcb1398fSOlivier Deprezit is decoupled from the ``SPD=spmd`` option. 151*fcb1398fSOlivier Deprez 152*fcb1398fSOlivier DeprezBL32 option is re-purposed to specify the SPMC image. It can specify either the 153*fcb1398fSOlivier DeprezHafnium binary path (built for the secure world) or the path to a TEE binary 154*fcb1398fSOlivier Deprezimplementing the FF-A protocol. 155*fcb1398fSOlivier Deprez 156*fcb1398fSOlivier DeprezBL33 option can specify either: 157*fcb1398fSOlivier Deprez 158*fcb1398fSOlivier Deprez- the TFTF binary or 159*fcb1398fSOlivier Deprez- the Hafnium binary path (built for the normal world) if VMs were loaded by 160*fcb1398fSOlivier Deprez TF-A beforehand or 161*fcb1398fSOlivier Deprez- a minimal loader performing the loading of VMs and Hafnium. 162*fcb1398fSOlivier Deprez 163*fcb1398fSOlivier DeprezSample TF-A build command line when SPMC is located at S-EL1 164*fcb1398fSOlivier Deprez(typically pre-Armv8.4): 165*fcb1398fSOlivier Deprez 166*fcb1398fSOlivier Deprez.. code:: shell 167*fcb1398fSOlivier Deprez 168*fcb1398fSOlivier Deprez make \ 169*fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 170*fcb1398fSOlivier Deprez SPD=spmd \ 171*fcb1398fSOlivier Deprez SPMD_SPM_AT_SEL2=0 \ 172*fcb1398fSOlivier Deprez BL32=<path-to-tee-binary> \ 173*fcb1398fSOlivier Deprez BL33=<path-to-nwd-binary> \ 174*fcb1398fSOlivier Deprez PLAT=fvp \ 175*fcb1398fSOlivier Deprez all fip 176*fcb1398fSOlivier Deprez 177*fcb1398fSOlivier DeprezSample TF-A build command line for an Armv8.4-SecEL2 enabled system 178*fcb1398fSOlivier Deprezwhere SPMC is located at S-EL2: 179*fcb1398fSOlivier Deprez 180*fcb1398fSOlivier Deprez.. code:: shell 181*fcb1398fSOlivier Deprez 182*fcb1398fSOlivier Deprez make \ 183*fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 184*fcb1398fSOlivier Deprez SPD=spmd \ 185*fcb1398fSOlivier Deprez CTX_INCLUDE_EL2_REGS=1 \ 186*fcb1398fSOlivier Deprez ARM_ARCH_MINOR=4 \ 187*fcb1398fSOlivier Deprez BL32=<path-to-swd-hafnium-binary> 188*fcb1398fSOlivier Deprez BL33=<path-to-nwd-binary> \ 189*fcb1398fSOlivier Deprez SP_LAYOUT_FILE=sp_layout.json \ 190*fcb1398fSOlivier Deprez PLAT=fvp \ 191*fcb1398fSOlivier Deprez all fip 192*fcb1398fSOlivier Deprez 193*fcb1398fSOlivier DeprezBuild options to enable secure boot: 194*fcb1398fSOlivier Deprez 195*fcb1398fSOlivier Deprez.. code:: shell 196*fcb1398fSOlivier Deprez 197*fcb1398fSOlivier Deprez make \ 198*fcb1398fSOlivier Deprez CROSS_COMPILE=aarch64-none-elf- \ 199*fcb1398fSOlivier Deprez SPD=spmd \ 200*fcb1398fSOlivier Deprez CTX_INCLUDE_EL2_REGS=1 \ 201*fcb1398fSOlivier Deprez ARM_ARCH_MINOR=4 \ 202*fcb1398fSOlivier Deprez BL32=<path-to-swd-hafnium-binary> 203*fcb1398fSOlivier Deprez BL33=<path-to-nwd-binary> \ 204*fcb1398fSOlivier Deprez SP_LAYOUT_FILE=../tf-a-tests/build/fvp/debug/sp_layout.json \ 205*fcb1398fSOlivier Deprez MBEDTLS_DIR=<path-to-mbedtls-lib> \ 206*fcb1398fSOlivier Deprez TRUSTED_BOARD_BOOT=1 \ 207*fcb1398fSOlivier Deprez COT=dualroot \ 208*fcb1398fSOlivier Deprez ARM_ROTPK_LOCATION=devel_rsa \ 209*fcb1398fSOlivier Deprez ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \ 210*fcb1398fSOlivier Deprez GENERATE_COT=1 \ 211*fcb1398fSOlivier Deprez PLAT=fvp \ 212*fcb1398fSOlivier Deprez all fip 213*fcb1398fSOlivier Deprez 214*fcb1398fSOlivier DeprezBoot process 215*fcb1398fSOlivier Deprez============ 216*fcb1398fSOlivier Deprez 217*fcb1398fSOlivier DeprezLoading Hafnium and Secure Partitions in the secure world 218*fcb1398fSOlivier Deprez--------------------------------------------------------- 219*fcb1398fSOlivier Deprez 220*fcb1398fSOlivier DeprezThe Hafnium implementation in normal world requires VMs to be loaded in 221*fcb1398fSOlivier Deprezmemory prior to booting. The mechanism upon which VMs are loaded and 222*fcb1398fSOlivier Deprezexposed to Hafnium are either: 223*fcb1398fSOlivier Deprez 224*fcb1398fSOlivier Deprez- by supplying a ramdisk image where VM images are concatenated (1) 225*fcb1398fSOlivier Deprez- or by providing VM load addresses within Hafnium manifest (2) 226*fcb1398fSOlivier Deprez 227*fcb1398fSOlivier DeprezTF-A is the bootlader for the Hafnium and SPs in the secure world. TF-A 228*fcb1398fSOlivier Deprezdoes not provide tooling or libraries manipulating ramdisks as required 229*fcb1398fSOlivier Deprezby (1). Thus BL2 loads SPs payloads independently. 230*fcb1398fSOlivier DeprezSPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.). 231*fcb1398fSOlivier DeprezThus they are supplied as distinct “self-contained” signed entities within 232*fcb1398fSOlivier Deprezthe FIP flash image. The FIP image itself is not signed hence providing 233*fcb1398fSOlivier Deprezability to upgrade SPs in the field. 234*fcb1398fSOlivier Deprez 235*fcb1398fSOlivier DeprezBooting through TF-A 236*fcb1398fSOlivier Deprez-------------------- 237*fcb1398fSOlivier Deprez 238*fcb1398fSOlivier DeprezSP manifests 239*fcb1398fSOlivier Deprez~~~~~~~~~~~~ 240*fcb1398fSOlivier Deprez 241*fcb1398fSOlivier DeprezAn SP manifest describes SP attributes as defined in `[1]`_ 242*fcb1398fSOlivier Deprezsection 3.1 (partition manifest at virtual FF-A instance) in DTS text format. It 243*fcb1398fSOlivier Deprezis represented as a single file associated with the SP. A sample is 244*fcb1398fSOlivier Deprezprovided by `[5]`_. A binding document is provided by `[6]`_. 245*fcb1398fSOlivier Deprez 246*fcb1398fSOlivier DeprezSecure Partition packages 247*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~ 248*fcb1398fSOlivier Deprez 249*fcb1398fSOlivier DeprezSecure Partitions are bundled as independent package files consisting 250*fcb1398fSOlivier Deprezof: 251*fcb1398fSOlivier Deprez 252*fcb1398fSOlivier Deprez- a header 253*fcb1398fSOlivier Deprez- a DTB 254*fcb1398fSOlivier Deprez- an image payload 255*fcb1398fSOlivier Deprez 256*fcb1398fSOlivier DeprezThe header starts with a magic value and offset values to SP DTB and 257*fcb1398fSOlivier Deprezimage payload. Each SP package is loaded independently by BL2 loader 258*fcb1398fSOlivier Deprezand verified for authenticity and integrity. 259*fcb1398fSOlivier Deprez 260*fcb1398fSOlivier DeprezThe SP package identified by its UUID (matching FF-A uuid) is inserted 261*fcb1398fSOlivier Deprezas a single entry into the FIP at end of the TF-A build flow as shown: 262*fcb1398fSOlivier Deprez 263*fcb1398fSOlivier Deprez.. code:: shell 264*fcb1398fSOlivier Deprez 265*fcb1398fSOlivier Deprez Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw" 266*fcb1398fSOlivier Deprez EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw" 267*fcb1398fSOlivier Deprez Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw" 268*fcb1398fSOlivier Deprez Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw" 269*fcb1398fSOlivier Deprez HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config" 270*fcb1398fSOlivier Deprez TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config" 271*fcb1398fSOlivier Deprez SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config" 272*fcb1398fSOlivier Deprez TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config" 273*fcb1398fSOlivier Deprez NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config" 274*fcb1398fSOlivier Deprez B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob" 275*fcb1398fSOlivier Deprez D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob" 276*fcb1398fSOlivier Deprez 277*fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml 278*fcb1398fSOlivier Deprez 279*fcb1398fSOlivier DeprezSpecifying partition binary image and DT 280*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 281*fcb1398fSOlivier Deprez 282*fcb1398fSOlivier DeprezA description file (json format) is passed to the build flow specifying 283*fcb1398fSOlivier Deprezpaths to the SP binary image and associated DTS partition manifest file. 284*fcb1398fSOlivier DeprezThe latter is going through the dtc compiler to generate the dtb fed into 285*fcb1398fSOlivier Deprezthe SP package. 286*fcb1398fSOlivier Deprez 287*fcb1398fSOlivier Deprez.. code:: shell 288*fcb1398fSOlivier Deprez 289*fcb1398fSOlivier Deprez { 290*fcb1398fSOlivier Deprez "tee1" : { 291*fcb1398fSOlivier Deprez "image": "tee1.bin", 292*fcb1398fSOlivier Deprez "pm": "tee1.dts" 293*fcb1398fSOlivier Deprez }, 294*fcb1398fSOlivier Deprez 295*fcb1398fSOlivier Deprez "tee2" : { 296*fcb1398fSOlivier Deprez "image": "tee2.bin", 297*fcb1398fSOlivier Deprez "pm": "tee2.dts" 298*fcb1398fSOlivier Deprez } 299*fcb1398fSOlivier Deprez } 300*fcb1398fSOlivier Deprez 301*fcb1398fSOlivier DeprezSPMC manifest 302*fcb1398fSOlivier Deprez~~~~~~~~~~~~~ 303*fcb1398fSOlivier Deprez 304*fcb1398fSOlivier DeprezThis manifest contains an SPMC attributes node consumed by SPMD at boot time. It 305*fcb1398fSOlivier Deprezis implementing the description from `[1]`_ section 3.2 (SP manifest at physical 306*fcb1398fSOlivier DeprezFF-A instance). The SP manifest at physical FF-A instance is used by the SPMD to 307*fcb1398fSOlivier Deprezsetup a SP that co-resides with the SPMC and executes at S-EL1 or Secure 308*fcb1398fSOlivier DeprezSupervisor mode. 309*fcb1398fSOlivier Deprez 310*fcb1398fSOlivier DeprezIn this implementation its usage is extended to the secure physical FF-A 311*fcb1398fSOlivier Deprezinstance where SPMC executes at S-EL2. 312*fcb1398fSOlivier Deprez 313*fcb1398fSOlivier Deprez.. code:: shell 314*fcb1398fSOlivier Deprez 315*fcb1398fSOlivier Deprez attribute { 316*fcb1398fSOlivier Deprez spmc_id = <0x8000>; 317*fcb1398fSOlivier Deprez maj_ver = <0x1>; 318*fcb1398fSOlivier Deprez min_ver = <0x0>; 319*fcb1398fSOlivier Deprez exec_state = <0x0>; 320*fcb1398fSOlivier Deprez load_address = <0x0 0x6000000>; 321*fcb1398fSOlivier Deprez entrypoint = <0x0 0x6000000>; 322*fcb1398fSOlivier Deprez binary_size = <0x60000>; 323*fcb1398fSOlivier Deprez }; 324*fcb1398fSOlivier Deprez 325*fcb1398fSOlivier Deprez- *spmc_id* defines the endpoint ID value that SPMC can query through 326*fcb1398fSOlivier Deprez ``FFA_ID_GET``. 327*fcb1398fSOlivier Deprez- *maj_ver/min_ver*. SPMD checks provided version versus its internal 328*fcb1398fSOlivier Deprez version and aborts if not matching. 329*fcb1398fSOlivier Deprez- *exec_state* defines SPMC execution state (can be AArch64 for 330*fcb1398fSOlivier Deprez Hafnium, or AArch64/AArch32 for OP-TEE at S-EL1). 331*fcb1398fSOlivier Deprez- *load_address* and *binary_size* are mostly used to verify secondary 332*fcb1398fSOlivier Deprez entry points fit into the loaded binary image. 333*fcb1398fSOlivier Deprez- *entrypoint* defines the cold boot primary core entry point used by 334*fcb1398fSOlivier Deprez SPMD (currently matches ``BL32_BASE``) 335*fcb1398fSOlivier Deprez 336*fcb1398fSOlivier DeprezOther nodes in the manifest are consumed by Hafnium in the secure world. 337*fcb1398fSOlivier DeprezA sample can be found at [7]: 338*fcb1398fSOlivier Deprez 339*fcb1398fSOlivier Deprez- The *chosen* node is currently unused in SWd. It is meant for NWd to 340*fcb1398fSOlivier Deprez specify the init ramdisk image. 341*fcb1398fSOlivier Deprez- The *hypervisor* node describes SPs. *is_ffa_partition* boolean 342*fcb1398fSOlivier Deprez attribute indicates an SP. Load-addr field specifies the load address 343*fcb1398fSOlivier Deprez at which TF-A loaded the SP package. 344*fcb1398fSOlivier Deprez- *cpus* node provide the platform topology and allows MPIDR to VMPIDR 345*fcb1398fSOlivier Deprez mapping. Notice with current implementation primary cpu is declared 346*fcb1398fSOlivier Deprez first, then secondary cpus must be declared in reverse order. 347*fcb1398fSOlivier Deprez 348*fcb1398fSOlivier DeprezSPMC boot 349*fcb1398fSOlivier Deprez~~~~~~~~~ 350*fcb1398fSOlivier Deprez 351*fcb1398fSOlivier DeprezThe SPMC is loaded by BL2 as the BL32 image. 352*fcb1398fSOlivier Deprez 353*fcb1398fSOlivier DeprezThe SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image. 354*fcb1398fSOlivier Deprez 355*fcb1398fSOlivier DeprezBL2 passes the SPMC manifest address to BL31 through a register. 356*fcb1398fSOlivier Deprez 357*fcb1398fSOlivier DeprezBL31(SPMD) runs from primary core, initializes the core contexts and 358*fcb1398fSOlivier Deprezlaunches BL32 passing the SPMC manifest address through a register. 359*fcb1398fSOlivier Deprez 360*fcb1398fSOlivier DeprezLoading of SPs 361*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~ 362*fcb1398fSOlivier Deprez 363*fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml 364*fcb1398fSOlivier Deprez 365*fcb1398fSOlivier Deprez 366*fcb1398fSOlivier DeprezNotice this boot flow is an implementation sample on Arm's FVP platform. Platforms 367*fcb1398fSOlivier Depreznot using FW_CONFIG would adjust to a different implementation. 368*fcb1398fSOlivier Deprez 369*fcb1398fSOlivier DeprezSecure boot 370*fcb1398fSOlivier Deprez~~~~~~~~~~~ 371*fcb1398fSOlivier Deprez 372*fcb1398fSOlivier DeprezThe SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC, 373*fcb1398fSOlivier DeprezSPMC manifest and Secure Partitions and verifies them for authenticity and integrity. 374*fcb1398fSOlivier DeprezRefer to TBBR specification `[3]`_. 375*fcb1398fSOlivier Deprez 376*fcb1398fSOlivier DeprezThe multiple-signing domain feature (in current state dual signing domain) allows 377*fcb1398fSOlivier Deprezthe use of two root keys namely S-ROTPK and NS-ROTPK (see `[8]`_): 378*fcb1398fSOlivier Deprez 379*fcb1398fSOlivier Deprez- SPMC(BL32), SPMC manifest, SPs may be signed by the SiP using the S-ROTPK. 380*fcb1398fSOlivier Deprez- BL33 may be signed by the OEM using NS-ROTPK. 381*fcb1398fSOlivier Deprez 382*fcb1398fSOlivier DeprezLonger term multiple signing domain will allow additional signing keys, e.g. 383*fcb1398fSOlivier Deprezif SPs originate from different parties. 384*fcb1398fSOlivier Deprez 385*fcb1398fSOlivier DeprezSee `TF-A build options`_ for a sample build command line. 386*fcb1398fSOlivier Deprez 387*fcb1398fSOlivier DeprezHafnium in the secure world 388*fcb1398fSOlivier Deprez=========================== 389*fcb1398fSOlivier Deprez 390*fcb1398fSOlivier Deprez**NOTE: this section is work in progress. Descriptions and implementation choices 391*fcb1398fSOlivier Deprezare subject to evolve.** 392*fcb1398fSOlivier Deprez 393*fcb1398fSOlivier DeprezGeneral considerations 394*fcb1398fSOlivier Deprez---------------------- 395*fcb1398fSOlivier Deprez 396*fcb1398fSOlivier DeprezBuild platform for the secure world 397*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 398*fcb1398fSOlivier Deprez 399*fcb1398fSOlivier DeprezThe implementation might add specific code parts only relevant to the 400*fcb1398fSOlivier Deprezsecure world. Such code parts might be isolated into different files 401*fcb1398fSOlivier Deprezand/or conditional code enclosed by a ``SECURE_WORLD`` macro. 402*fcb1398fSOlivier Deprez 403*fcb1398fSOlivier DeprezSecure Partitions CPU scheduling 404*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 405*fcb1398fSOlivier Deprez 406*fcb1398fSOlivier DeprezIn the normal world, VMs are scheduled by the FFA_RUN ABI invoked from the 407*fcb1398fSOlivier Deprezprimary scheduler (in the primary VM), or by a direct message request or 408*fcb1398fSOlivier Deprezresponse. 409*fcb1398fSOlivier Deprez 410*fcb1398fSOlivier DeprezWith the FF-A EAC specification, Secure Partitions are scheduled by direct 411*fcb1398fSOlivier Deprezmessage invocations from a NWd VM or another SP. 412*fcb1398fSOlivier Deprez 413*fcb1398fSOlivier DeprezPlatform topology 414*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~ 415*fcb1398fSOlivier Deprez 416*fcb1398fSOlivier DeprezAs stated in `[1]`_ section 4.4.1 the SPMC implementation assumes the 417*fcb1398fSOlivier Deprezfollowing SP types: 418*fcb1398fSOlivier Deprez 419*fcb1398fSOlivier Deprez- Pinned MP SPs: an Execution Context id matches a physical PE id. MP 420*fcb1398fSOlivier Deprez SPs must implement the same number of ECs as the number of PEs in the 421*fcb1398fSOlivier Deprez platform. Hence the *execution-ctx-count* as defined by 422*fcb1398fSOlivier Deprez `[1]`_ (or NWd-Hafnium *vcpu_count*) can only take the 423*fcb1398fSOlivier Deprez value of one or the number of physical PEs. 424*fcb1398fSOlivier Deprez- Migratable UP SPs: a single execution context can run and be migrated 425*fcb1398fSOlivier Deprez on any physical PE. It declares a single EC in its SP manifest. An UP 426*fcb1398fSOlivier Deprez SP can receive a direct message request on any physical core. 427*fcb1398fSOlivier Deprez 428*fcb1398fSOlivier DeprezUsage of PSCI services in the secure world 429*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 430*fcb1398fSOlivier Deprez 431*fcb1398fSOlivier Deprez- The normal world Hypervisor (optional) or OS kernel issues PSCI service 432*fcb1398fSOlivier Deprez invocations e.g. to request PSCI version, wake-up a secondary core, or request 433*fcb1398fSOlivier Deprez core suspend. This happens at the non-secure physical FF-A instance. In the 434*fcb1398fSOlivier Deprez example case of Hafnium in the normal world, it boots on the primary core and 435*fcb1398fSOlivier Deprez one of the first initialization step is to request the PSCI version. It then 436*fcb1398fSOlivier Deprez launches the primary VM. The primary VM upon initializing performs PSCI service 437*fcb1398fSOlivier Deprez calls (at non-secure virtual FF-A instance) which are trapped by the 438*fcb1398fSOlivier Deprez Hypervisor. Invocation from OS Kernel ends straight at EL3. The PVM issues 439*fcb1398fSOlivier Deprez ``PSCI_CPU_ON`` service calls to wake-up secondary cores by passing an 440*fcb1398fSOlivier Deprez ``MPIDR``, entry point address and a CPU context address. The EL3 PSCI layer 441*fcb1398fSOlivier Deprez then performs an exception return to the secondary core entry point on the 442*fcb1398fSOlivier Deprez targeted core. Other PSCI calls can happen at run-time from the PVM e.g. to 443*fcb1398fSOlivier Deprez request core suspend. 444*fcb1398fSOlivier Deprez- In the existing TF-A PSCI standard library, PSCI service calls are filtered at 445*fcb1398fSOlivier Deprez EL3 to only originate from the NWd. Thus concerning the SPMC (at secure 446*fcb1398fSOlivier Deprez physical FF-A instance) the PSCI service invocations cannot happen as in the 447*fcb1398fSOlivier Deprez normal world. For example, a ``PSCI_CPU_ON`` service invocation from the SPMC 448*fcb1398fSOlivier Deprez does not reach the PSCI layer. 449*fcb1398fSOlivier Deprez 450*fcb1398fSOlivier DeprezParsing SP partition manifests 451*fcb1398fSOlivier Deprez------------------------------ 452*fcb1398fSOlivier Deprez 453*fcb1398fSOlivier DeprezHafnium must be able to consume SP manifests as defined in 454*fcb1398fSOlivier Deprez`[1]`_ section 3.1, at least for the mandatory fields. 455*fcb1398fSOlivier Deprez 456*fcb1398fSOlivier DeprezThe SP manifest may contain memory and device regions nodes. 457*fcb1398fSOlivier Deprez 458*fcb1398fSOlivier Deprez- Memory regions shall be mapped in the SP Stage-2 translation regime at 459*fcb1398fSOlivier Deprez load time. A memory region node can specify RX/TX buffer regions in which 460*fcb1398fSOlivier Deprez case it is not necessary for an SP to explicitly call the ``FFA_RXTX_MAP`` 461*fcb1398fSOlivier Deprez service. 462*fcb1398fSOlivier Deprez- Device regions shall be mapped in SP Stage-2 translation regime as 463*fcb1398fSOlivier Deprez peripherals and possibly allocate additional resources (e.g. interrupts) 464*fcb1398fSOlivier Deprez 465*fcb1398fSOlivier DeprezBase addresses for memory and device region nodes are IPAs provided SPMC 466*fcb1398fSOlivier Deprezidentity maps IPAs to PAs within SP Stage-2 translation regime. 467*fcb1398fSOlivier Deprez 468*fcb1398fSOlivier DeprezNote: currently both VTTBR_EL2 and VSTTBR_EL2 resolve to the same set of page 469*fcb1398fSOlivier Depreztables. It is still open whether two sets of page tables shall be provided per 470*fcb1398fSOlivier DeprezSP. The memory region node as defined in the spec (section 3.1 Table 10) 471*fcb1398fSOlivier Deprezprovides a memory security attribute hinting to map either to the secure or 472*fcb1398fSOlivier Depreznon-secure stage-2 table. 473*fcb1398fSOlivier Deprez 474*fcb1398fSOlivier DeprezPassing boot data to the SP 475*fcb1398fSOlivier Deprez--------------------------- 476*fcb1398fSOlivier Deprez 477*fcb1398fSOlivier Deprez`[1]`_ Section 3.4.2 “Protocol for passing data” defines a 478*fcb1398fSOlivier Deprezmethod to passing boot data to SPs (not currently implemented). 479*fcb1398fSOlivier Deprez 480*fcb1398fSOlivier DeprezProvided that the whole Secure Partition package image (see `Secure 481*fcb1398fSOlivier DeprezPartition packages`_) is mapped to the SP's secure Stage-2 translation 482*fcb1398fSOlivier Deprezregime, an SP can access its own manifest DTB blob and extract its partition 483*fcb1398fSOlivier Deprezmanifest properties. 484*fcb1398fSOlivier Deprez 485*fcb1398fSOlivier DeprezSP Boot order 486*fcb1398fSOlivier Deprez------------- 487*fcb1398fSOlivier Deprez 488*fcb1398fSOlivier DeprezSP manifests provide an optional boot order attribute meant to resolve 489*fcb1398fSOlivier Deprezdependencies such as an SP providing a service required to properly boot 490*fcb1398fSOlivier Deprezanother SP. 491*fcb1398fSOlivier Deprez 492*fcb1398fSOlivier DeprezBoot phases 493*fcb1398fSOlivier Deprez----------- 494*fcb1398fSOlivier Deprez 495*fcb1398fSOlivier DeprezPrimary core boot-up 496*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~ 497*fcb1398fSOlivier Deprez 498*fcb1398fSOlivier DeprezThe SPMC performs its platform initializations then loads and creates 499*fcb1398fSOlivier Deprezsecure partitions based on SP packages and manifests. Then each secure 500*fcb1398fSOlivier Deprezpartition is launched in sequence (see `SP Boot order`_) on their primary 501*fcb1398fSOlivier DeprezExecution Context. 502*fcb1398fSOlivier Deprez 503*fcb1398fSOlivier DeprezNotice the primary physical core may not be core 0. Hence if the primary 504*fcb1398fSOlivier Deprezcore linear id is N, the 1:1 mapping requires MP SPs are launched using 505*fcb1398fSOlivier DeprezEC[N] on PE[N] (see `Platform topology`_). 506*fcb1398fSOlivier Deprez 507*fcb1398fSOlivier DeprezThe SP's primary Execution Context (or the EC used when the partition is booted) 508*fcb1398fSOlivier Deprezexits through ``FFA_MSG_WAIT`` to indicate successful initialization. 509*fcb1398fSOlivier Deprez 510*fcb1398fSOlivier DeprezSecondary physical core boot-up 511*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 512*fcb1398fSOlivier Deprez 513*fcb1398fSOlivier DeprezUpon boot-up, the SPMC running on the primary core performs 514*fcb1398fSOlivier Deprezimplementation-defined SPMD service calls at secure physical FF-A instance 515*fcb1398fSOlivier Deprezto register the secondary physical cores entry points and context information: 516*fcb1398fSOlivier Deprez 517*fcb1398fSOlivier Deprez- This is done through a direct message request invocation to the SPMD 518*fcb1398fSOlivier Deprez (``SET_ENTRY_POINT``). This service call does not wake-up the targeted 519*fcb1398fSOlivier Deprez core immediately. The secondary core is woken up later by a NWd 520*fcb1398fSOlivier Deprez ``PSCI_CPU_ON`` service invocation. A notification is passed from EL3 521*fcb1398fSOlivier Deprez PSCI layer to the SPMD, and then to SPMC through an implementation-defined 522*fcb1398fSOlivier Deprez interface. 523*fcb1398fSOlivier Deprez- The SPMC/SPMD interface can consist of FF-A direct message requests/responses 524*fcb1398fSOlivier Deprez transporting PM events. 525*fcb1398fSOlivier Deprez 526*fcb1398fSOlivier DeprezIf there is no Hypervisor in the normal world, the OS Kernel issues 527*fcb1398fSOlivier Deprez``PSCI_CPU_ON`` calls that are directly trapped to EL3. 528*fcb1398fSOlivier Deprez 529*fcb1398fSOlivier DeprezWhen a secondary physical core wakes-up the SPMD notifies the SPMC which updates 530*fcb1398fSOlivier Deprezits internal states reflecting current physical core is being turned on. 531*fcb1398fSOlivier DeprezIt might then return straight to the SPMD and then to the NWd. 532*fcb1398fSOlivier Deprez 533*fcb1398fSOlivier Deprez*(under discussion)* There may be possibility that an SP registers "PM events" 534*fcb1398fSOlivier Deprez(during primary EC boot stage) through an ad-hoc interface. Such events would 535*fcb1398fSOlivier Deprezbe relayed by SPMC to one or more registered SPs on need basis 536*fcb1398fSOlivier Deprez(see `Power management`_). 537*fcb1398fSOlivier Deprez 538*fcb1398fSOlivier DeprezSecondary virtual core boot-up 539*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 540*fcb1398fSOlivier Deprez 541*fcb1398fSOlivier DeprezIn the example case where Hafnium exists in the normal world, secondary VMs 542*fcb1398fSOlivier Deprezissue a ``PSCI_CPU_ON`` service call which is trapped to the Hypervisor. The 543*fcb1398fSOlivier Deprezlatter then enables the vCPU context for the targeted core, and switches to 544*fcb1398fSOlivier Deprezthe PVM down to the kernel driver with an ``HF_WAKE_UP`` message. The NWd 545*fcb1398fSOlivier Deprezdriver in PVM can then schedule the newly woken up vCPU context. 546*fcb1398fSOlivier Deprez 547*fcb1398fSOlivier DeprezIn the secure world the primary EC of a given SP passes the secondary EC entry 548*fcb1398fSOlivier Deprezpoint and context. The SMC service call is trapped into the SPMC. This can be 549*fcb1398fSOlivier Deprezeither *(under discussion)*: 550*fcb1398fSOlivier Deprez 551*fcb1398fSOlivier Deprez- a specific interface registering the secondary EC entry point, 552*fcb1398fSOlivier Deprez similarly to above ``SET_ENTRY_POINT`` service. 553*fcb1398fSOlivier Deprez- Re-purposing the ``PSCI_CPU_ON`` function id. It is 554*fcb1398fSOlivier Deprez assumed that even if the input arguments are the same as the ones defined in 555*fcb1398fSOlivier Deprez the PSCI standard, the usage deviates by the fact the secondary EC is not 556*fcb1398fSOlivier Deprez woken up immediately. At least for the PSA-FF-A EAC where only 557*fcb1398fSOlivier Deprez direct messaging is allowed, it is only after the first direct 558*fcb1398fSOlivier Deprez message invocation that the secondary EC is entered. This option 559*fcb1398fSOlivier Deprez might be preferred when the same code base is re-used for a VM or 560*fcb1398fSOlivier Deprez an SP. The ABI to wake-up a secondary EC can remain similar. 561*fcb1398fSOlivier Deprez 562*fcb1398fSOlivier DeprezSPs are always scheduled from the NWd, this paradigm did not change from legacy 563*fcb1398fSOlivier DeprezTEEs. There must always be some logic (or driver) in the NWd to relinquish CPU 564*fcb1398fSOlivier Deprezcycles to the SWd. If primary core is 0, an SP EC[x>0] entry point is supplied 565*fcb1398fSOlivier Deprezby the SP EC[0] when the system boots in SWd. But this EC[x] is not immediately 566*fcb1398fSOlivier Deprezentered at boot. Later in the boot process when NWd is up, a direct message 567*fcb1398fSOlivier Deprezrequest issued from physical core 1 ends up in SP EC[1], and only at this stage 568*fcb1398fSOlivier Deprezthis context is effectively scheduled. 569*fcb1398fSOlivier Deprez 570*fcb1398fSOlivier DeprezIt should be possible for an SP to call into another SP through direct message 571*fcb1398fSOlivier Deprezprovided the latter SP has been booted already. The "boot-order" field in 572*fcb1398fSOlivier Deprezpartition manifests (`SP Boot order`_) fulfills the dependency towards availability 573*fcb1398fSOlivier Deprezof a service within an SP offered to another SP. 574*fcb1398fSOlivier Deprez 575*fcb1398fSOlivier DeprezMandatory interfaces 576*fcb1398fSOlivier Deprez-------------------- 577*fcb1398fSOlivier Deprez 578*fcb1398fSOlivier DeprezThe following interfaces must be exposed to any VM or SP: 579*fcb1398fSOlivier Deprez 580*fcb1398fSOlivier Deprez- ``FFA_STATUS`` 581*fcb1398fSOlivier Deprez- ``FFA_ERROR`` 582*fcb1398fSOlivier Deprez- ``FFA_INTERRUPT`` 583*fcb1398fSOlivier Deprez- ``FFA_VERSION`` 584*fcb1398fSOlivier Deprez- ``FFA_FEATURES`` 585*fcb1398fSOlivier Deprez- ``FFA_RX_RELEASE`` 586*fcb1398fSOlivier Deprez- ``FFA_RXTX_MAP`` 587*fcb1398fSOlivier Deprez- ``FFA_RXTX_UNMAP`` 588*fcb1398fSOlivier Deprez- ``FFA_PARTITION_INFO_GET`` 589*fcb1398fSOlivier Deprez- ``FFA_ID_GET`` 590*fcb1398fSOlivier Deprez 591*fcb1398fSOlivier DeprezFFA_VERSION 592*fcb1398fSOlivier Deprez~~~~~~~~~~~ 593*fcb1398fSOlivier Deprez 594*fcb1398fSOlivier DeprezPer `[1]`_ section 8.1 ``FFA_VERSION`` requires a 595*fcb1398fSOlivier Deprez*requested_version* parameter from the caller. 596*fcb1398fSOlivier Deprez 597*fcb1398fSOlivier DeprezIn the current implementation when ``FFA_VERSION`` is invoked from: 598*fcb1398fSOlivier Deprez 599*fcb1398fSOlivier Deprez- Hypervisor in NS-EL2: the SPMD returns the SPMC version specified 600*fcb1398fSOlivier Deprez in the SPMC manifest. 601*fcb1398fSOlivier Deprez- OS kernel in NS-EL1 when NS-EL2 is not present: the SPMD returns the 602*fcb1398fSOlivier Deprez SPMC version specified in the SPMC manifest. 603*fcb1398fSOlivier Deprez- VM in NWd: the Hypervisor returns its implemented version. 604*fcb1398fSOlivier Deprez- SP in SWd: the SPMC returns its implemented version. 605*fcb1398fSOlivier Deprez- SPMC at S-EL1/S-EL2: the SPMD returns its implemented version. 606*fcb1398fSOlivier Deprez 607*fcb1398fSOlivier DeprezFFA_FEATURES 608*fcb1398fSOlivier Deprez~~~~~~~~~~~~ 609*fcb1398fSOlivier Deprez 610*fcb1398fSOlivier DeprezFF-A features may be discovered by Secure Partitions while booting 611*fcb1398fSOlivier Deprezthrough the SPMC. However, SPMC cannot get features from Hypervisor 612*fcb1398fSOlivier Deprezearly at boot time as NS world is not setup yet. 613*fcb1398fSOlivier Deprez 614*fcb1398fSOlivier DeprezThe Hypervisor may decide to gather FF-A features from SPMC through SPMD 615*fcb1398fSOlivier Deprezonce at boot time and store the result. Later when a VM requests FF-A 616*fcb1398fSOlivier Deprezfeatures, the Hypervisor can adjust its own set of features with what 617*fcb1398fSOlivier DeprezSPMC advertised, if necessary. Another approach is to always forward FF-A 618*fcb1398fSOlivier Deprezfeatures to the SPMC when a VM requests it to the Hypervisor. Although 619*fcb1398fSOlivier Deprezthe result is not supposed to change over time so there may not be added 620*fcb1398fSOlivier Deprezvalue doing the systematic forwarding. 621*fcb1398fSOlivier Deprez 622*fcb1398fSOlivier DeprezFFA_RXTX_MAP/FFA_RXTX_UNMAP 623*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~ 624*fcb1398fSOlivier Deprez 625*fcb1398fSOlivier DeprezVM mailboxes are re-purposed to serve as SP RX/TX buffers. The RX/TX 626*fcb1398fSOlivier Deprezmap API maps the send and receive buffer IPAs to the SP Stage-2 translation regime. 627*fcb1398fSOlivier Deprez 628*fcb1398fSOlivier DeprezHafnium in the normal world defines VMs and their attributes as logical structures, 629*fcb1398fSOlivier Deprezincluding a mailbox used for FF-A indirect messaging, memory sharing, or the 630*fcb1398fSOlivier Deprez`FFA_PARTITION_INFO_GET`_ ABI. 631*fcb1398fSOlivier DeprezThis same mailbox structure is re-used in the SPMC. `[1]`_ states only direct 632*fcb1398fSOlivier Deprezmessaging is allowed to SPs. Thus mailbox usage is restricted to implementing 633*fcb1398fSOlivier Deprez`FFA_PARTITION_INFO_GET`_ and memory sharing ABIs. 634*fcb1398fSOlivier Deprez 635*fcb1398fSOlivier DeprezFFA_PARTITION_INFO_GET 636*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~ 637*fcb1398fSOlivier Deprez 638*fcb1398fSOlivier DeprezPartition info get service call can originate: 639*fcb1398fSOlivier Deprez 640*fcb1398fSOlivier Deprez- from SP to SPM 641*fcb1398fSOlivier Deprez- from VM to Hypervisor 642*fcb1398fSOlivier Deprez- from Hypervisor to SPM 643*fcb1398fSOlivier Deprez 644*fcb1398fSOlivier DeprezFor the latter case, the service call must be forwarded through the SPMD. 645*fcb1398fSOlivier Deprez 646*fcb1398fSOlivier DeprezFFA_ID_GET 647*fcb1398fSOlivier Deprez~~~~~~~~~~ 648*fcb1398fSOlivier Deprez 649*fcb1398fSOlivier DeprezThe SPMD returns: 650*fcb1398fSOlivier Deprez 651*fcb1398fSOlivier Deprez- a default zero value on invocation from the Hypervisor. 652*fcb1398fSOlivier Deprez- The ``spmc_id`` value specified in the SPMC manifest on invocation from 653*fcb1398fSOlivier Deprez the SPMC (see `SPMC manifest`_) 654*fcb1398fSOlivier Deprez 655*fcb1398fSOlivier DeprezThe FF-A id space is split into a non-secure space and secure space: 656*fcb1398fSOlivier Deprez 657*fcb1398fSOlivier Deprez- FF-A id with bit 15 clear refer to normal world VMs. 658*fcb1398fSOlivier Deprez- FF-A id with bit 15 set refer to secure world SPs 659*fcb1398fSOlivier Deprez 660*fcb1398fSOlivier DeprezSuch convention helps the SPMC discriminating the origin and destination worlds 661*fcb1398fSOlivier Deprezin an FF-A service invocation. In particular the SPMC shall filter unauthorized 662*fcb1398fSOlivier Depreztransactions in its world switch routine. It must not be permitted for a VM to 663*fcb1398fSOlivier Deprezuse a secure FF-A id as origin world through spoofing: 664*fcb1398fSOlivier Deprez 665*fcb1398fSOlivier Deprez- A VM-to-SP messaging passing shall have an origin world being non-secure 666*fcb1398fSOlivier Deprez (FF-A id bit 15 clear) and destination world being secure (FF-A id bit 15 667*fcb1398fSOlivier Deprez set). 668*fcb1398fSOlivier Deprez- Similarly, an SP-to-SP message shall have FF-A id bit 15 set for both origin 669*fcb1398fSOlivier Deprez and destination ids. 670*fcb1398fSOlivier Deprez 671*fcb1398fSOlivier DeprezAn incoming direct message request arriving at SPMD from NWd is forwarded to 672*fcb1398fSOlivier DeprezSPMC without a specific check. The SPMC is resumed through eret and "knows" the 673*fcb1398fSOlivier Deprezmessage is coming from normal world in this specific code path. Thus the origin 674*fcb1398fSOlivier Deprezendpoint id must be checked by SPMC for being a normal world id. 675*fcb1398fSOlivier Deprez 676*fcb1398fSOlivier DeprezAn SP sending a direct message request must have bit 15 set in its origin 677*fcb1398fSOlivier Deprezendpoint id and this can be checked by the SPMC when the SP invokes the ABI. 678*fcb1398fSOlivier Deprez 679*fcb1398fSOlivier DeprezThe SPMC shall reject the direct message if the claimed world in origin endpoint 680*fcb1398fSOlivier Deprezid is not consistent: 681*fcb1398fSOlivier Deprez 682*fcb1398fSOlivier Deprez- It is either forwarded by SPMD and thus origin endpoint id must be a "normal 683*fcb1398fSOlivier Deprez world id", 684*fcb1398fSOlivier Deprez- or initiated by an SP and thus origin endpoint id must be a "secure world id". 685*fcb1398fSOlivier Deprez 686*fcb1398fSOlivier DeprezDirect messaging 687*fcb1398fSOlivier Deprez---------------- 688*fcb1398fSOlivier Deprez 689*fcb1398fSOlivier DeprezThis is a mandatory interface for Secure Partitions consisting in direct 690*fcb1398fSOlivier Deprezmessage request and responses. 691*fcb1398fSOlivier Deprez 692*fcb1398fSOlivier DeprezThe ``ffa_handler`` Hafnium function may: 693*fcb1398fSOlivier Deprez 694*fcb1398fSOlivier Deprez- trigger a world change e.g. when an SP invokes the direct message 695*fcb1398fSOlivier Deprez response ABI to a VM. 696*fcb1398fSOlivier Deprez- handle multiple requests from the NWd without resuming an SP. 697*fcb1398fSOlivier Deprez 698*fcb1398fSOlivier DeprezSP-to-SP 699*fcb1398fSOlivier Deprez~~~~~~~~ 700*fcb1398fSOlivier Deprez 701*fcb1398fSOlivier Deprez- An SP can send a direct message request to another SP 702*fcb1398fSOlivier Deprez- An SP can receive a direct message response from another SP. 703*fcb1398fSOlivier Deprez 704*fcb1398fSOlivier DeprezVM-to-SP 705*fcb1398fSOlivier Deprez~~~~~~~~ 706*fcb1398fSOlivier Deprez 707*fcb1398fSOlivier Deprez- A VM can send a direct message request to an SP 708*fcb1398fSOlivier Deprez- An SP can send a direct message response to a VM 709*fcb1398fSOlivier Deprez 710*fcb1398fSOlivier DeprezSPMC-SPMD messaging 711*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~ 712*fcb1398fSOlivier Deprez 713*fcb1398fSOlivier DeprezSpecific implementation-defined endpoint IDs are allocated to the SPMC and SPMD. 714*fcb1398fSOlivier DeprezReferring those IDs in source/destination fields of a direct message 715*fcb1398fSOlivier Deprezrequest/response permits SPMD to SPMC messaging back and forth. 716*fcb1398fSOlivier Deprez 717*fcb1398fSOlivier DeprezPer `[1]`_ Table 114 Config No. 1 (physical FF-A instance): 718*fcb1398fSOlivier Deprez 719*fcb1398fSOlivier Deprez- SPMC=>SPMD direct message request uses SMC conduit 720*fcb1398fSOlivier Deprez- SPMD=>SPMC direct message request uses ERET conduit 721*fcb1398fSOlivier Deprez 722*fcb1398fSOlivier DeprezPer `[1]`_ Table 118 Config No. 1 (physical FF-A instance): 723*fcb1398fSOlivier Deprez 724*fcb1398fSOlivier Deprez- SPMC=>SPMD direct message response uses SMC conduit 725*fcb1398fSOlivier Deprez- SPMD=>SPMC direct message response uses ERET conduit 726*fcb1398fSOlivier Deprez 727*fcb1398fSOlivier DeprezMemory management 728*fcb1398fSOlivier Deprez----------------- 729*fcb1398fSOlivier Deprez 730*fcb1398fSOlivier DeprezThis section only deals with the PE MMU configuration. 731*fcb1398fSOlivier Deprez 732*fcb1398fSOlivier DeprezHafnium in the normal world deals with NS buffers only and provisions 733*fcb1398fSOlivier Depreza single root page table directory to VMs. In context of S-EL2 enabled 734*fcb1398fSOlivier Deprezfirmware, two IPA spaces are output from Stage-1 translation (secure 735*fcb1398fSOlivier Deprezand non-secure). The Stage-2 translation handles: 736*fcb1398fSOlivier Deprez 737*fcb1398fSOlivier Deprez- A single secure IPA space when an SP Stage-1 MMU is disabled. 738*fcb1398fSOlivier Deprez- Two IPA spaces (secure and non-secure) when Stage-1 MMU is enabled. 739*fcb1398fSOlivier Deprez 740*fcb1398fSOlivier Deprez``VTCR_EL2`` and ``VSTCR_EL2`` provide additional bits for controlling the 741*fcb1398fSOlivier DeprezNS/S IPA translations (``VSTCR_EL2.SW``, ``VSTCR_EL2.SA``, ``VTCR_EL2.NSW``, 742*fcb1398fSOlivier Deprez``VTCR_EL2.NSA``). There may be two approaches: 743*fcb1398fSOlivier Deprez 744*fcb1398fSOlivier Deprez- secure and non-secure mappings are rooted as two separate root page 745*fcb1398fSOlivier Deprez tables 746*fcb1398fSOlivier Deprez- secure and non-secure mappings use the same root page table. Access 747*fcb1398fSOlivier Deprez from S-EL1 to an NS region translates to a secure physical address 748*fcb1398fSOlivier Deprez space access. 749*fcb1398fSOlivier Deprez 750*fcb1398fSOlivier DeprezInterrupt management 751*fcb1398fSOlivier Deprez-------------------- 752*fcb1398fSOlivier Deprez 753*fcb1398fSOlivier DeprezRoad to a para-virtualized interface 754*fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 755*fcb1398fSOlivier Deprez 756*fcb1398fSOlivier DeprezCurrent Hafnium implementation uses an ad-hoc mechanism for a VM to get 757*fcb1398fSOlivier Depreza pending interrupt number through an hypercall. The PVM injects 758*fcb1398fSOlivier Deprezinterrupts to VMs by delegation from the Hypervisor. The PVM probes a 759*fcb1398fSOlivier Deprezpending interrupt directly from the GIC distributor. 760*fcb1398fSOlivier Deprez 761*fcb1398fSOlivier DeprezThe short-term plan is to have Hafnium/SPMC in the secure world owner 762*fcb1398fSOlivier Deprezof the GIC configuration. 763*fcb1398fSOlivier Deprez 764*fcb1398fSOlivier DeprezThe SPMC fully owns the GIC configuration at S-EL2. The SPMC manages 765*fcb1398fSOlivier Deprezinterrupt resources and allocates interrupt ID based on SP manifests. 766*fcb1398fSOlivier DeprezThe SPMC acknowledges physical interrupts and injects virtual interrupts 767*fcb1398fSOlivier Deprezby setting the vIRQ bit when resuming an SP. A Secure Partition gathers 768*fcb1398fSOlivier Deprezthe interrupt number through an hypercall. 769*fcb1398fSOlivier Deprez 770*fcb1398fSOlivier DeprezNotice the SPMC/SPMD has to handle Group0 secure interrupts in addition 771*fcb1398fSOlivier Deprezto Group1 S/NS interrupts. 772*fcb1398fSOlivier Deprez 773*fcb1398fSOlivier DeprezPower management 774*fcb1398fSOlivier Deprez---------------- 775*fcb1398fSOlivier Deprez 776*fcb1398fSOlivier DeprezAssumption on the Nwd: 777*fcb1398fSOlivier Deprez 778*fcb1398fSOlivier Deprez- NWd is the best candidate to own the platform Power Management 779*fcb1398fSOlivier Deprez policy. It is master to invoking PSCI service calls from physical 780*fcb1398fSOlivier Deprez CPUs. 781*fcb1398fSOlivier Deprez- EL3 monitor is in charge of the PM control part (its PSCI layer 782*fcb1398fSOlivier Deprez actually writing to platform registers). 783*fcb1398fSOlivier Deprez- It is fine for the Hypervisor to trap PSCI calls and relay to EL3, or 784*fcb1398fSOlivier Deprez OS kernel driver to emit PSCI service calls. 785*fcb1398fSOlivier Deprez 786*fcb1398fSOlivier DeprezPSCI notification are relayed through the SPMD/SPD PM hooks to the SPMC. 787*fcb1398fSOlivier DeprezThis can either be through re-use of PSCI FIDs or an FF-A direct message 788*fcb1398fSOlivier Deprezfrom SPMD to SPMC. 789*fcb1398fSOlivier Deprez 790*fcb1398fSOlivier DeprezThe SPMD performs an exception return to the SPMC which is resumed to 791*fcb1398fSOlivier Deprezits ``eret_handler`` routine. It is then either consuming a PSCI FID or 792*fcb1398fSOlivier Deprezan FF-A FID. Depending on the servicing, the SPMC may return directly to 793*fcb1398fSOlivier Deprezthe SPMD (and then NWd) without resuming an SP at this stage. An example 794*fcb1398fSOlivier Deprezof this is invocation of ``FFA_PARTITION_INFO_GET`` from NWd relayed by 795*fcb1398fSOlivier Deprezthe SPMD to the SPMC. The SPMC returns the needed partition information 796*fcb1398fSOlivier Deprezto the SPMD (then NWd) without actually resuming a partition in secure world. 797*fcb1398fSOlivier Deprez 798*fcb1398fSOlivier Deprez*(under discussion)* 799*fcb1398fSOlivier DeprezAbout using PSCI FIDs from SPMD to SPMC to notify of PM events, it is still 800*fcb1398fSOlivier Deprezquestioned what to use as the return code from the SPMC. 801*fcb1398fSOlivier DeprezIf the function ID used by the SPMC is not an FF-A ID when doing SMC, then the 802*fcb1398fSOlivier DeprezEL3 std svc handler won't route the response to the SPMD. That's where comes the 803*fcb1398fSOlivier Deprezidea to embed the notification into an FF-A message. The SPMC can discriminate 804*fcb1398fSOlivier Deprezthis message as being a PSCI event, process it, and reply with an FF-A return 805*fcb1398fSOlivier Deprezmessage that the SPMD receives as an acknowledgement. 806*fcb1398fSOlivier Deprez 807*fcb1398fSOlivier DeprezSP notification 808*fcb1398fSOlivier Deprez--------------- 809*fcb1398fSOlivier Deprez 810*fcb1398fSOlivier DeprezPower management notifications are conveyed from PSCI library to the 811*fcb1398fSOlivier DeprezSPMD / SPD hooks. A range of events can be relayed to SPMC. 812*fcb1398fSOlivier Deprez 813*fcb1398fSOlivier DeprezSPs may need to be notified about specific PM events. 814*fcb1398fSOlivier Deprez 815*fcb1398fSOlivier Deprez- SPs might register PM events to the SPMC 816*fcb1398fSOlivier Deprez- On SPMD to SPMC notification, a limited range of SPs may be notified 817*fcb1398fSOlivier Deprez through a direct message. 818*fcb1398fSOlivier Deprez- This assumes the mentioned SPs supports managed exit. 819*fcb1398fSOlivier Deprez 820*fcb1398fSOlivier DeprezThe SPMC is the first to be notified about PM events from the SPMD. It is up 821*fcb1398fSOlivier Deprezto the SPMC to arbitrate to which SP it needs to send PM events. 822*fcb1398fSOlivier DeprezAn SP explicitly registers to receive notifications to specific PM events. 823*fcb1398fSOlivier DeprezThe register operation can either be an implementation-defined service call 824*fcb1398fSOlivier Deprezto the SPMC when the primary SP EC boots, or be supplied through the SP 825*fcb1398fSOlivier Deprezmanifest. 826*fcb1398fSOlivier Deprez 827*fcb1398fSOlivier DeprezReferences 828*fcb1398fSOlivier Deprez========== 829*fcb1398fSOlivier Deprez 830*fcb1398fSOlivier Deprez.. _[1]: 831*fcb1398fSOlivier Deprez 832*fcb1398fSOlivier Deprez[1] `Platform Security Architecture Firmware Framework for Arm® v8-A 1.0 Platform Design Document <https://developer.arm.com/docs/den0077/latest>`__ 833*fcb1398fSOlivier Deprez 834*fcb1398fSOlivier Deprez.. _[2]: 835*fcb1398fSOlivier Deprez 836*fcb1398fSOlivier Deprez[2] `Secure Partition Manager using MM interface`__ 837*fcb1398fSOlivier Deprez 838*fcb1398fSOlivier Deprez.. __: secure-partition-manager-mm.html 839*fcb1398fSOlivier Deprez 840*fcb1398fSOlivier Deprez.. _[3]: 841*fcb1398fSOlivier Deprez 842*fcb1398fSOlivier Deprez[3] `Trusted Boot Board Requirements 843*fcb1398fSOlivier DeprezClient <https://developer.arm.com/docs/den0006/latest/trusted-board-boot-requirements-client-tbbr-client-armv8-a>`__ 844*fcb1398fSOlivier Deprez 845*fcb1398fSOlivier Deprez.. _[4]: 846*fcb1398fSOlivier Deprez 847*fcb1398fSOlivier Deprez[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45 848*fcb1398fSOlivier Deprez 849*fcb1398fSOlivier Deprez.. _[5]: 850*fcb1398fSOlivier Deprez 851*fcb1398fSOlivier Deprez[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/cactus.dts 852*fcb1398fSOlivier Deprez 853*fcb1398fSOlivier Deprez.. _[6]: 854*fcb1398fSOlivier Deprez 855*fcb1398fSOlivier Deprez[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/psa-ffa-manifest-binding.html 856*fcb1398fSOlivier Deprez 857*fcb1398fSOlivier Deprez.. _[7]: 858*fcb1398fSOlivier Deprez 859*fcb1398fSOlivier Deprez[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts 860*fcb1398fSOlivier Deprez 861*fcb1398fSOlivier Deprez.. _[8]: 862*fcb1398fSOlivier Deprez 863*fcb1398fSOlivier Deprez[8] https://developer.trustedfirmware.org/w/tf_a/poc-multiple-signing-domains/ 864*fcb1398fSOlivier Deprez 865*fcb1398fSOlivier Deprez-------------- 866*fcb1398fSOlivier Deprez 867*fcb1398fSOlivier Deprez*Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.* 868