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