xref: /rk3399_ARM-atf/docs/components/secure-partition-manager.rst (revision 573ac37373d3e8b2c31b3aaeed759e4656e060ec)
1fcb1398fSOlivier DeprezSecure Partition Manager
2fcb1398fSOlivier Deprez************************
3fcb1398fSOlivier Deprez
4fcb1398fSOlivier Deprez.. contents::
5fcb1398fSOlivier Deprez
6fcb1398fSOlivier DeprezAcronyms
7fcb1398fSOlivier Deprez========
8fcb1398fSOlivier Deprez
98a5bd3cfSOlivier Deprez+--------+--------------------------------------+
10b5dd2422SOlivier Deprez| CoT    | Chain of Trust                       |
118a5bd3cfSOlivier Deprez+--------+--------------------------------------+
124ec3ccb4SMadhukar Pappireddy| DMA    | Direct Memory Access                 |
138a5bd3cfSOlivier Deprez+--------+--------------------------------------+
14fcb1398fSOlivier Deprez| DTB    | Device Tree Blob                     |
158a5bd3cfSOlivier Deprez+--------+--------------------------------------+
16fcb1398fSOlivier Deprez| DTS    | Device Tree Source                   |
178a5bd3cfSOlivier Deprez+--------+--------------------------------------+
18fcb1398fSOlivier Deprez| EC     | Execution Context                    |
198a5bd3cfSOlivier Deprez+--------+--------------------------------------+
20fcb1398fSOlivier Deprez| FIP    | Firmware Image Package               |
218a5bd3cfSOlivier Deprez+--------+--------------------------------------+
228a5bd3cfSOlivier Deprez| FF-A   | Firmware Framework for Arm A-profile |
238a5bd3cfSOlivier Deprez+--------+--------------------------------------+
24fcb1398fSOlivier Deprez| IPA    | Intermediate Physical Address        |
258a5bd3cfSOlivier Deprez+--------+--------------------------------------+
26fcb1398fSOlivier Deprez| NWd    | Normal World                         |
278a5bd3cfSOlivier Deprez+--------+--------------------------------------+
28fcb1398fSOlivier Deprez| ODM    | Original Design Manufacturer         |
298a5bd3cfSOlivier Deprez+--------+--------------------------------------+
30fcb1398fSOlivier Deprez| OEM    | Original Equipment Manufacturer      |
318a5bd3cfSOlivier Deprez+--------+--------------------------------------+
32fcb1398fSOlivier Deprez| PA     | Physical Address                     |
338a5bd3cfSOlivier Deprez+--------+--------------------------------------+
34fcb1398fSOlivier Deprez| PE     | Processing Element                   |
358a5bd3cfSOlivier Deprez+--------+--------------------------------------+
36b5dd2422SOlivier Deprez| PM     | Power Management                     |
378a5bd3cfSOlivier Deprez+--------+--------------------------------------+
38fcb1398fSOlivier Deprez| PVM    | Primary VM                           |
398a5bd3cfSOlivier Deprez+--------+--------------------------------------+
404ec3ccb4SMadhukar Pappireddy| SMMU   | System Memory Management Unit        |
418a5bd3cfSOlivier Deprez+--------+--------------------------------------+
42fcb1398fSOlivier Deprez| SP     | Secure Partition                     |
438a5bd3cfSOlivier Deprez+--------+--------------------------------------+
44b5dd2422SOlivier Deprez| SPD    | Secure Payload Dispatcher            |
458a5bd3cfSOlivier Deprez+--------+--------------------------------------+
46fcb1398fSOlivier Deprez| SPM    | Secure Partition Manager             |
478a5bd3cfSOlivier Deprez+--------+--------------------------------------+
48fcb1398fSOlivier Deprez| SPMC   | SPM Core                             |
498a5bd3cfSOlivier Deprez+--------+--------------------------------------+
50fcb1398fSOlivier Deprez| SPMD   | SPM Dispatcher                       |
518a5bd3cfSOlivier Deprez+--------+--------------------------------------+
52fcb1398fSOlivier Deprez| SiP    | Silicon Provider                     |
538a5bd3cfSOlivier Deprez+--------+--------------------------------------+
54fcb1398fSOlivier Deprez| SWd    | Secure World                         |
558a5bd3cfSOlivier Deprez+--------+--------------------------------------+
56fcb1398fSOlivier Deprez| TLV    | Tag-Length-Value                     |
578a5bd3cfSOlivier Deprez+--------+--------------------------------------+
58fcb1398fSOlivier Deprez| TOS    | Trusted Operating System             |
598a5bd3cfSOlivier Deprez+--------+--------------------------------------+
60fcb1398fSOlivier Deprez| VM     | Virtual Machine                      |
618a5bd3cfSOlivier Deprez+--------+--------------------------------------+
62fcb1398fSOlivier Deprez
63fcb1398fSOlivier DeprezForeword
64fcb1398fSOlivier Deprez========
65fcb1398fSOlivier Deprez
66fcb1398fSOlivier DeprezTwo implementations of a Secure Partition Manager co-exist in the TF-A codebase:
67fcb1398fSOlivier Deprez
681b17f4f1SOlivier Deprez- SPM based on the FF-A specification `[1]`_.
69fcb1398fSOlivier Deprez- SPM based on the MM interface to communicate with an S-EL0 partition `[2]`_.
70fcb1398fSOlivier Deprez
71fcb1398fSOlivier DeprezBoth implementations differ in their architectures and only one can be selected
72fcb1398fSOlivier Deprezat build time.
73fcb1398fSOlivier Deprez
74fcb1398fSOlivier DeprezThis document:
75fcb1398fSOlivier Deprez
761b17f4f1SOlivier Deprez- describes the FF-A implementation where the Secure Partition Manager
77fcb1398fSOlivier Deprez  resides at EL3 and S-EL2 (or EL3 and S-EL1).
78fcb1398fSOlivier Deprez- is not an architecture specification and it might provide assumptions
79fcb1398fSOlivier Deprez  on sections mandated as implementation-defined in the specification.
80fcb1398fSOlivier Deprez- covers the implications to TF-A used as a bootloader, and Hafnium
81fcb1398fSOlivier Deprez  used as a reference code base for an S-EL2 secure firmware on
82b5dd2422SOlivier Deprez  platforms implementing the FEAT_SEL2 (formerly Armv8.4 Secure EL2)
83b5dd2422SOlivier Deprez  architecture extension.
84fcb1398fSOlivier Deprez
85fcb1398fSOlivier DeprezTerminology
86fcb1398fSOlivier Deprez-----------
87fcb1398fSOlivier Deprez
88b5dd2422SOlivier Deprez- The term Hypervisor refers to the NS-EL2 component managing Virtual Machines
89b5dd2422SOlivier Deprez  (or partitions) in the normal world.
90b5dd2422SOlivier Deprez- The term SPMC refers to the S-EL2 component managing secure partitions in
91b5dd2422SOlivier Deprez  the secure world when the FEAT_SEL2 architecture extension is implemented.
92b5dd2422SOlivier Deprez- Alternatively, SPMC can refer to an S-EL1 component, itself being a secure
93b5dd2422SOlivier Deprez  partition and implementing the FF-A ABI on platforms not implementing the
94b5dd2422SOlivier Deprez  FEAT_SEL2 architecture extension.
95b5dd2422SOlivier Deprez- The term VM refers to a normal world Virtual Machine managed by an Hypervisor.
96b5dd2422SOlivier Deprez- The term SP refers to a secure world "Virtual Machine" managed by an SPMC.
97fcb1398fSOlivier Deprez
98fcb1398fSOlivier DeprezSupport for legacy platforms
99fcb1398fSOlivier Deprez----------------------------
100fcb1398fSOlivier Deprez
101b5dd2422SOlivier DeprezIn the implementation, the SPM is split into SPMD and SPMC components.
102b5dd2422SOlivier DeprezThe SPMD is located at EL3 and mainly relays FF-A messages from
103b5dd2422SOlivier DeprezNWd (Hypervisor or OS kernel) to SPMC located either at S-EL1 or S-EL2.
104fcb1398fSOlivier Deprez
105b5dd2422SOlivier DeprezHence TF-A supports both cases where the SPMC is located either at:
106fcb1398fSOlivier Deprez
107b5dd2422SOlivier Deprez- S-EL1 supporting platforms not implementing the FEAT_SEL2 architecture
108b5dd2422SOlivier Deprez  extension. The SPMD relays the FF-A protocol from EL3 to S-EL1.
109b5dd2422SOlivier Deprez- or S-EL2 supporting platforms implementing the FEAT_SEL2 architecture
110b5dd2422SOlivier Deprez  extension. The SPMD relays the FF-A protocol from EL3 to S-EL2.
111fcb1398fSOlivier Deprez
112b5dd2422SOlivier DeprezThe same TF-A SPMD component is used to support both configurations.
113b5dd2422SOlivier DeprezThe SPMC exception level is a build time choice.
114fcb1398fSOlivier Deprez
115fcb1398fSOlivier DeprezSample reference stack
116fcb1398fSOlivier Deprez======================
117fcb1398fSOlivier Deprez
118b5dd2422SOlivier DeprezThe following diagram illustrates a possible configuration when the
119b5dd2422SOlivier DeprezFEAT_SEL2 architecture extension is implemented, showing the SPMD
120b5dd2422SOlivier Deprezand SPMC, one or multiple secure partitions, with an optional
121b5dd2422SOlivier DeprezHypervisor:
122fcb1398fSOlivier Deprez
123fcb1398fSOlivier Deprez.. image:: ../resources/diagrams/ff-a-spm-sel2.png
124fcb1398fSOlivier Deprez
125fcb1398fSOlivier DeprezTF-A build options
126fcb1398fSOlivier Deprez==================
127fcb1398fSOlivier Deprez
128b5dd2422SOlivier DeprezThis section explains the TF-A build options involved in building with
129b5dd2422SOlivier Deprezsupport for an FF-A based SPM where the SPMD is located at EL3 and the
1301d63ae4dSMarc BonniciSPMC located at S-EL1, S-EL2 or EL3:
131fcb1398fSOlivier Deprez
132b5dd2422SOlivier Deprez- **SPD=spmd**: this option selects the SPMD component to relay the FF-A
133fcb1398fSOlivier Deprez  protocol from NWd to SWd back and forth. It is not possible to
134fcb1398fSOlivier Deprez  enable another Secure Payload Dispatcher when this option is chosen.
135b5dd2422SOlivier Deprez- **SPMD_SPM_AT_SEL2**: this option adjusts the SPMC exception
1361d63ae4dSMarc Bonnici  level to being at S-EL2. It defaults to enabled (value 1) when
137fcb1398fSOlivier Deprez  SPD=spmd is chosen.
1381d63ae4dSMarc Bonnici- **SPMC_AT_EL3**: this option adjusts the SPMC exception level to being
1391d63ae4dSMarc Bonnici  at EL3.
1401d63ae4dSMarc Bonnici- If neither **SPMD_SPM_AT_SEL2** or **SPMC_AT_EL3** are enabled the SPMC
1411d63ae4dSMarc Bonnici  exception level is set to S-EL1.
142fcb1398fSOlivier Deprez- **CTX_INCLUDE_EL2_REGS**: this option permits saving (resp.
143fcb1398fSOlivier Deprez  restoring) the EL2 system register context before entering (resp.
144b5dd2422SOlivier Deprez  after leaving) the SPMC. It is mandatorily enabled when
145b5dd2422SOlivier Deprez  ``SPMD_SPM_AT_SEL2`` is enabled. The context save/restore routine
146b5dd2422SOlivier Deprez  and exhaustive list of registers is visible at `[4]`_.
147b5dd2422SOlivier Deprez- **SP_LAYOUT_FILE**: this option specifies a text description file
148b5dd2422SOlivier Deprez  providing paths to SP binary images and manifests in DTS format
149b5dd2422SOlivier Deprez  (see `Describing secure partitions`_). It
150fcb1398fSOlivier Deprez  is required when ``SPMD_SPM_AT_SEL2`` is enabled hence when multiple
151b5dd2422SOlivier Deprez  secure partitions are to be loaded on behalf of the SPMC.
152fcb1398fSOlivier Deprez
1531d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+
1541d63ae4dSMarc Bonnici|               | CTX_INCLUDE_EL2_REGS | SPMD_SPM_AT_SEL2 | SPMC_AT_EL3 |
1551d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+
1561d63ae4dSMarc Bonnici| SPMC at S-EL1 |         0            |        0         |      0      |
1571d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+
1581d63ae4dSMarc Bonnici| SPMC at S-EL2 |         1            | 1 (default when  |      0      |
1591d63ae4dSMarc Bonnici|               |                      |    SPD=spmd)     |             |
1601d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+
1611d63ae4dSMarc Bonnici| SPMC at EL3   |         0            |        0         |      1      |
1621d63ae4dSMarc Bonnici+---------------+----------------------+------------------+-------------+
163fcb1398fSOlivier Deprez
164fcb1398fSOlivier DeprezOther combinations of such build options either break the build or are not
165fcb1398fSOlivier Deprezsupported.
166fcb1398fSOlivier Deprez
167b5dd2422SOlivier DeprezNotes:
168b5dd2422SOlivier Deprez
169b5dd2422SOlivier Deprez- Only Arm's FVP platform is supported to use with the TF-A reference software
170b5dd2422SOlivier Deprez  stack.
171b5dd2422SOlivier Deprez- The reference software stack uses FEAT_PAuth (formerly Armv8.3-PAuth) and
172b5dd2422SOlivier Deprez  FEAT_BTI (formerly Armv8.5-BTI) architecture extensions by default at EL3
173b5dd2422SOlivier Deprez  and S-EL2.
174b5dd2422SOlivier Deprez- The ``CTX_INCLUDE_EL2_REGS`` option provides the generic support for
175fcb1398fSOlivier Deprez  barely saving/restoring EL2 registers from an Arm arch perspective. As such
176fcb1398fSOlivier Deprez  it is decoupled from the ``SPD=spmd`` option.
177b5dd2422SOlivier Deprez- BL32 option is re-purposed to specify the SPMC image. It can specify either
178b5dd2422SOlivier Deprez  the Hafnium binary path (built for the secure world) or the path to a TEE
179b5dd2422SOlivier Deprez  binary implementing FF-A interfaces.
180b5dd2422SOlivier Deprez- BL33 option can specify the TFTF binary or a normal world loader
181b5dd2422SOlivier Deprez  such as U-Boot or the UEFI framework.
182fcb1398fSOlivier Deprez
183fcb1398fSOlivier DeprezSample TF-A build command line when SPMC is located at S-EL1
184b5dd2422SOlivier Deprez(e.g. when the FEAT_EL2 architecture extension is not implemented):
185fcb1398fSOlivier Deprez
186fcb1398fSOlivier Deprez.. code:: shell
187fcb1398fSOlivier Deprez
188fcb1398fSOlivier Deprez    make \
189fcb1398fSOlivier Deprez    CROSS_COMPILE=aarch64-none-elf- \
190fcb1398fSOlivier Deprez    SPD=spmd \
191fcb1398fSOlivier Deprez    SPMD_SPM_AT_SEL2=0 \
192fcb1398fSOlivier Deprez    BL32=<path-to-tee-binary> \
193b5dd2422SOlivier Deprez    BL33=<path-to-bl33-binary> \
194fcb1398fSOlivier Deprez    PLAT=fvp \
195fcb1398fSOlivier Deprez    all fip
196fcb1398fSOlivier Deprez
197b5dd2422SOlivier DeprezSample TF-A build command line for a FEAT_SEL2 enabled system where the SPMC is
198b5dd2422SOlivier Deprezlocated at S-EL2:
199fcb1398fSOlivier Deprez
200fcb1398fSOlivier Deprez.. code:: shell
201fcb1398fSOlivier Deprez
202fcb1398fSOlivier Deprez    make \
203fcb1398fSOlivier Deprez    CROSS_COMPILE=aarch64-none-elf- \
204b5dd2422SOlivier Deprez    PLAT=fvp \
205fcb1398fSOlivier Deprez    SPD=spmd \
206fcb1398fSOlivier Deprez    CTX_INCLUDE_EL2_REGS=1 \
207b5dd2422SOlivier Deprez    ARM_ARCH_MINOR=5 \
208b5dd2422SOlivier Deprez    BRANCH_PROTECTION=1 \
209b5dd2422SOlivier Deprez    CTX_INCLUDE_PAUTH_REGS=1 \
210b5dd2422SOlivier Deprez    BL32=<path-to-hafnium-binary> \
211b5dd2422SOlivier Deprez    BL33=<path-to-bl33-binary> \
212fcb1398fSOlivier Deprez    SP_LAYOUT_FILE=sp_layout.json \
213fcb1398fSOlivier Deprez    all fip
214fcb1398fSOlivier Deprez
215b5dd2422SOlivier DeprezSame as above with enabling secure boot in addition:
216fcb1398fSOlivier Deprez
217fcb1398fSOlivier Deprez.. code:: shell
218fcb1398fSOlivier Deprez
219fcb1398fSOlivier Deprez    make \
220fcb1398fSOlivier Deprez    CROSS_COMPILE=aarch64-none-elf- \
221b5dd2422SOlivier Deprez    PLAT=fvp \
222fcb1398fSOlivier Deprez    SPD=spmd \
223fcb1398fSOlivier Deprez    CTX_INCLUDE_EL2_REGS=1 \
224b5dd2422SOlivier Deprez    ARM_ARCH_MINOR=5 \
225b5dd2422SOlivier Deprez    BRANCH_PROTECTION=1 \
226b5dd2422SOlivier Deprez    CTX_INCLUDE_PAUTH_REGS=1 \
227b5dd2422SOlivier Deprez    BL32=<path-to-hafnium-binary> \
228b5dd2422SOlivier Deprez    BL33=<path-to-bl33-binary> \
229b5dd2422SOlivier Deprez    SP_LAYOUT_FILE=sp_layout.json \
230fcb1398fSOlivier Deprez    MBEDTLS_DIR=<path-to-mbedtls-lib> \
231fcb1398fSOlivier Deprez    TRUSTED_BOARD_BOOT=1 \
232fcb1398fSOlivier Deprez    COT=dualroot \
233fcb1398fSOlivier Deprez    ARM_ROTPK_LOCATION=devel_rsa \
234fcb1398fSOlivier Deprez    ROT_KEY=plat/arm/board/common/rotpk/arm_rotprivk_rsa.pem \
235fcb1398fSOlivier Deprez    GENERATE_COT=1 \
236fcb1398fSOlivier Deprez    all fip
237fcb1398fSOlivier Deprez
2381d63ae4dSMarc BonniciSample TF-A build command line when SPMC is located at EL3:
2391d63ae4dSMarc Bonnici
2401d63ae4dSMarc Bonnici.. code:: shell
2411d63ae4dSMarc Bonnici
2421d63ae4dSMarc Bonnici    make \
2431d63ae4dSMarc Bonnici    CROSS_COMPILE=aarch64-none-elf- \
2441d63ae4dSMarc Bonnici    SPD=spmd \
2451d63ae4dSMarc Bonnici    SPMD_SPM_AT_SEL2=0 \
2461d63ae4dSMarc Bonnici    SPMC_AT_EL3=1 \
2471d63ae4dSMarc Bonnici    BL32=<path-to-tee-binary> \
2481d63ae4dSMarc Bonnici    BL33=<path-to-bl33-binary> \
2491d63ae4dSMarc Bonnici    PLAT=fvp \
2501d63ae4dSMarc Bonnici    all fip
2511d63ae4dSMarc Bonnici
252b5dd2422SOlivier DeprezFVP model invocation
253b5dd2422SOlivier Deprez====================
254b5dd2422SOlivier Deprez
255b5dd2422SOlivier DeprezThe FVP command line needs the following options to exercise the S-EL2 SPMC:
256b5dd2422SOlivier Deprez
257b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+
258b5dd2422SOlivier Deprez| - cluster0.has_arm_v8-5=1                         | Implements FEAT_SEL2, FEAT_PAuth,  |
259b5dd2422SOlivier Deprez| - cluster1.has_arm_v8-5=1                         | and FEAT_BTI.                      |
260b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+
261b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_AIDR=2                  | Parameters required for the        |
262b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B         | SMMUv3.2 modeling.                 |
263b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002         |                                    |
264b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714             |                                    |
265b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472         |                                    |
266b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002       |                                    |
267b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR2=0                |                                    |
268b5dd2422SOlivier Deprez| - pci.pci_smmuv3.mmu.SMMU_S_IDR3=0                |                                    |
269b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+
270b5dd2422SOlivier Deprez| - cluster0.has_branch_target_exception=1          | Implements FEAT_BTI.               |
271b5dd2422SOlivier Deprez| - cluster1.has_branch_target_exception=1          |                                    |
272b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+
273b5dd2422SOlivier Deprez| - cluster0.restriction_on_speculative_execution=2 | Required by the EL2 context        |
274b5dd2422SOlivier Deprez| - cluster1.restriction_on_speculative_execution=2 | save/restore routine.              |
275b5dd2422SOlivier Deprez+---------------------------------------------------+------------------------------------+
276b5dd2422SOlivier Deprez
277b5dd2422SOlivier DeprezSample FVP command line invocation:
278b5dd2422SOlivier Deprez
279b5dd2422SOlivier Deprez.. code:: shell
280b5dd2422SOlivier Deprez
281b5dd2422SOlivier Deprez    <path-to-fvp-model>/FVP_Base_RevC-2xAEMv8A -C pctl.startup=0.0.0.0
282b5dd2422SOlivier Deprez    -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \
283b5dd2422SOlivier Deprez    -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \
284b5dd2422SOlivier Deprez    -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \
285b5dd2422SOlivier Deprez    -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \
286b5dd2422SOlivier Deprez    -C bp.pl011_uart2.out_file=fvp-uart2.log \
287b5dd2422SOlivier Deprez    -C cluster0.has_arm_v8-5=1 -C cluster1.has_arm_v8-5=1 -C pci.pci_smmuv3.mmu.SMMU_AIDR=2 \
288b5dd2422SOlivier Deprez    -C pci.pci_smmuv3.mmu.SMMU_IDR0=0x0046123B -C pci.pci_smmuv3.mmu.SMMU_IDR1=0x00600002 \
289b5dd2422SOlivier Deprez    -C pci.pci_smmuv3.mmu.SMMU_IDR3=0x1714 -C pci.pci_smmuv3.mmu.SMMU_IDR5=0xFFFF0472 \
290b5dd2422SOlivier Deprez    -C pci.pci_smmuv3.mmu.SMMU_S_IDR1=0xA0000002 -C pci.pci_smmuv3.mmu.SMMU_S_IDR2=0 \
291b5dd2422SOlivier Deprez    -C pci.pci_smmuv3.mmu.SMMU_S_IDR3=0 \
292b5dd2422SOlivier Deprez    -C cluster0.has_branch_target_exception=1 \
293b5dd2422SOlivier Deprez    -C cluster1.has_branch_target_exception=1 \
294b5dd2422SOlivier Deprez    -C cluster0.restriction_on_speculative_execution=2 \
295b5dd2422SOlivier Deprez    -C cluster1.restriction_on_speculative_execution=2
296b5dd2422SOlivier Deprez
297fcb1398fSOlivier DeprezBoot process
298fcb1398fSOlivier Deprez============
299fcb1398fSOlivier Deprez
300b5dd2422SOlivier DeprezLoading Hafnium and secure partitions in the secure world
301fcb1398fSOlivier Deprez---------------------------------------------------------
302fcb1398fSOlivier Deprez
303b5dd2422SOlivier DeprezTF-A BL2 is the bootlader for the SPMC and SPs in the secure world.
304fcb1398fSOlivier Deprez
305fcb1398fSOlivier DeprezSPs may be signed by different parties (SiP, OEM/ODM, TOS vendor, etc.).
306b5dd2422SOlivier DeprezThus they are supplied as distinct signed entities within the FIP flash
307b5dd2422SOlivier Deprezimage. The FIP image itself is not signed hence this provides the ability
308b5dd2422SOlivier Deprezto upgrade SPs in the field.
309fcb1398fSOlivier Deprez
310fcb1398fSOlivier DeprezBooting through TF-A
311fcb1398fSOlivier Deprez--------------------
312fcb1398fSOlivier Deprez
313fcb1398fSOlivier DeprezSP manifests
314fcb1398fSOlivier Deprez~~~~~~~~~~~~
315fcb1398fSOlivier Deprez
316fcb1398fSOlivier DeprezAn SP manifest describes SP attributes as defined in `[1]`_
317b5dd2422SOlivier Deprez(partition manifest at virtual FF-A instance) in DTS format. It is
318b5dd2422SOlivier Deprezrepresented as a single file associated with the SP. A sample is
319fcb1398fSOlivier Deprezprovided by `[5]`_. A binding document is provided by `[6]`_.
320fcb1398fSOlivier Deprez
321fcb1398fSOlivier DeprezSecure Partition packages
322fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~
323fcb1398fSOlivier Deprez
324b5dd2422SOlivier DeprezSecure partitions are bundled as independent package files consisting
325fcb1398fSOlivier Deprezof:
326fcb1398fSOlivier Deprez
327fcb1398fSOlivier Deprez- a header
328fcb1398fSOlivier Deprez- a DTB
329fcb1398fSOlivier Deprez- an image payload
330fcb1398fSOlivier Deprez
331fcb1398fSOlivier DeprezThe header starts with a magic value and offset values to SP DTB and
332fcb1398fSOlivier Deprezimage payload. Each SP package is loaded independently by BL2 loader
333fcb1398fSOlivier Deprezand verified for authenticity and integrity.
334fcb1398fSOlivier Deprez
335b5dd2422SOlivier DeprezThe SP package identified by its UUID (matching FF-A uuid property) is
336b5dd2422SOlivier Deprezinserted as a single entry into the FIP at end of the TF-A build flow
337b5dd2422SOlivier Deprezas shown:
338fcb1398fSOlivier Deprez
339fcb1398fSOlivier Deprez.. code:: shell
340fcb1398fSOlivier Deprez
341fcb1398fSOlivier Deprez    Trusted Boot Firmware BL2: offset=0x1F0, size=0x8AE1, cmdline="--tb-fw"
342fcb1398fSOlivier Deprez    EL3 Runtime Firmware BL31: offset=0x8CD1, size=0x13000, cmdline="--soc-fw"
343fcb1398fSOlivier Deprez    Secure Payload BL32 (Trusted OS): offset=0x1BCD1, size=0x15270, cmdline="--tos-fw"
344fcb1398fSOlivier Deprez    Non-Trusted Firmware BL33: offset=0x30F41, size=0x92E0, cmdline="--nt-fw"
345fcb1398fSOlivier Deprez    HW_CONFIG: offset=0x3A221, size=0x2348, cmdline="--hw-config"
346fcb1398fSOlivier Deprez    TB_FW_CONFIG: offset=0x3C569, size=0x37A, cmdline="--tb-fw-config"
347fcb1398fSOlivier Deprez    SOC_FW_CONFIG: offset=0x3C8E3, size=0x48, cmdline="--soc-fw-config"
348fcb1398fSOlivier Deprez    TOS_FW_CONFIG: offset=0x3C92B, size=0x427, cmdline="--tos-fw-config"
349fcb1398fSOlivier Deprez    NT_FW_CONFIG: offset=0x3CD52, size=0x48, cmdline="--nt-fw-config"
350fcb1398fSOlivier Deprez    B4B5671E-4A90-4FE1-B81F-FB13DAE1DACB: offset=0x3CD9A, size=0xC168, cmdline="--blob"
351fcb1398fSOlivier Deprez    D1582309-F023-47B9-827C-4464F5578FC8: offset=0x48F02, size=0xC168, cmdline="--blob"
352fcb1398fSOlivier Deprez
353fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/fip-secure-partitions.puml
354fcb1398fSOlivier Deprez
355b5dd2422SOlivier DeprezDescribing secure partitions
356b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~
357fcb1398fSOlivier Deprez
358b5dd2422SOlivier DeprezA json-formatted description file is passed to the build flow specifying paths
359b5dd2422SOlivier Deprezto the SP binary image and associated DTS partition manifest file. The latter
360b5dd2422SOlivier Deprezis processed by the dtc compiler to generate a DTB fed into the SP package.
361*573ac373SJ-AlvesOptionally, the partition's json description can contain offsets for both
362*573ac373SJ-Alvesthe image and partition manifest within the SP package. Both offsets need to be
363*573ac373SJ-Alves4KB aligned, because it is the translation granule supported by Hafnium SPMC.
364*573ac373SJ-AlvesThese fields can be leveraged to support SPs with S1 translation granules that
365*573ac373SJ-Alvesdiffer from 4KB, and to configure the regions allocated within the SP package,
366*573ac373SJ-Alvesas well as to comply with the requirements for the implementation of the boot
367*573ac373SJ-Alvesinformation protocol (see `Passing boot data to the SP`_ for more details). In
368*573ac373SJ-Alvescase the offsets are absent in their json node, they default to 0x1000 and
369*573ac373SJ-Alves0x4000 for the manifest offset and image offset respectively.
370b5dd2422SOlivier DeprezThis file also specifies the SP owner (as an optional field) identifying the
371b5dd2422SOlivier Deprezsigning domain in case of dual root CoT.
372b5dd2422SOlivier DeprezThe SP owner can either be the silicon or the platform provider. The
373b5dd2422SOlivier Deprezcorresponding "owner" field value can either take the value of "SiP" or "Plat".
374b5dd2422SOlivier DeprezIn absence of "owner" field, it defaults to "SiP" owner.
3755ac60ea1SImre KisThe UUID of the partition can be specified as a field in the description file or
3765ac60ea1SImre Kisif it does not exist there the UUID is extracted from the DTS partition
3775ac60ea1SImre Kismanifest.
378fcb1398fSOlivier Deprez
379fcb1398fSOlivier Deprez.. code:: shell
380fcb1398fSOlivier Deprez
381fcb1398fSOlivier Deprez    {
382fcb1398fSOlivier Deprez        "tee1" : {
383fcb1398fSOlivier Deprez            "image": "tee1.bin",
3840901d339SManish Pandey             "pm": "tee1.dts",
3855ac60ea1SImre Kis             "owner": "SiP",
3865ac60ea1SImre Kis             "uuid": "1b1820fe-48f7-4175-8999-d51da00b7c9f"
387fcb1398fSOlivier Deprez        },
388fcb1398fSOlivier Deprez
389fcb1398fSOlivier Deprez        "tee2" : {
390fcb1398fSOlivier Deprez            "image": "tee2.bin",
3910901d339SManish Pandey            "pm": "tee2.dts",
3920901d339SManish Pandey            "owner": "Plat"
393*573ac373SJ-Alves        },
394*573ac373SJ-Alves
395*573ac373SJ-Alves        "tee3" : {
396*573ac373SJ-Alves            "image": {
397*573ac373SJ-Alves                "file": "tee3.bin",
398*573ac373SJ-Alves                "offset":"0x2000"
399*573ac373SJ-Alves             },
400*573ac373SJ-Alves            "pm": {
401*573ac373SJ-Alves                "file": "tee3.dts",
402*573ac373SJ-Alves                "offset":"0x6000"
403*573ac373SJ-Alves             },
404*573ac373SJ-Alves            "owner": "Plat"
405*573ac373SJ-Alves        },
406fcb1398fSOlivier Deprez    }
407fcb1398fSOlivier Deprez
408fcb1398fSOlivier DeprezSPMC manifest
409fcb1398fSOlivier Deprez~~~~~~~~~~~~~
410fcb1398fSOlivier Deprez
411b5dd2422SOlivier DeprezThis manifest contains the SPMC *attribute* node consumed by the SPMD at boot
412b5dd2422SOlivier Depreztime. It implements `[1]`_ (SP manifest at physical FF-A instance) and serves
413b5dd2422SOlivier Depreztwo different cases:
414fcb1398fSOlivier Deprez
415b5dd2422SOlivier Deprez- The SPMC resides at S-EL1: the SPMC manifest is used by the SPMD to setup a
416b5dd2422SOlivier Deprez  SP that co-resides with the SPMC and executes at S-EL1 or Secure Supervisor
417b5dd2422SOlivier Deprez  mode.
418b5dd2422SOlivier Deprez- The SPMC resides at S-EL2: the SPMC manifest is used by the SPMD to setup
419b5dd2422SOlivier Deprez  the environment required by the SPMC to run at S-EL2. SPs run at S-EL1 or
420b5dd2422SOlivier Deprez  S-EL0.
421fcb1398fSOlivier Deprez
422fcb1398fSOlivier Deprez.. code:: shell
423fcb1398fSOlivier Deprez
424fcb1398fSOlivier Deprez    attribute {
425fcb1398fSOlivier Deprez        spmc_id = <0x8000>;
426fcb1398fSOlivier Deprez        maj_ver = <0x1>;
427fcb1398fSOlivier Deprez        min_ver = <0x0>;
428fcb1398fSOlivier Deprez        exec_state = <0x0>;
429fcb1398fSOlivier Deprez        load_address = <0x0 0x6000000>;
430fcb1398fSOlivier Deprez        entrypoint = <0x0 0x6000000>;
431fcb1398fSOlivier Deprez        binary_size = <0x60000>;
432fcb1398fSOlivier Deprez    };
433fcb1398fSOlivier Deprez
434fcb1398fSOlivier Deprez- *spmc_id* defines the endpoint ID value that SPMC can query through
435fcb1398fSOlivier Deprez  ``FFA_ID_GET``.
436fcb1398fSOlivier Deprez- *maj_ver/min_ver*. SPMD checks provided version versus its internal
437fcb1398fSOlivier Deprez  version and aborts if not matching.
438b5dd2422SOlivier Deprez- *exec_state* defines the SPMC execution state (AArch64 or AArch32).
439b5dd2422SOlivier Deprez  Notice Hafnium used as a SPMC only supports AArch64.
440fcb1398fSOlivier Deprez- *load_address* and *binary_size* are mostly used to verify secondary
441fcb1398fSOlivier Deprez  entry points fit into the loaded binary image.
442fcb1398fSOlivier Deprez- *entrypoint* defines the cold boot primary core entry point used by
443b5dd2422SOlivier Deprez  SPMD (currently matches ``BL32_BASE``) to enter the SPMC.
444fcb1398fSOlivier Deprez
445fcb1398fSOlivier DeprezOther nodes in the manifest are consumed by Hafnium in the secure world.
446fcb1398fSOlivier DeprezA sample can be found at [7]:
447fcb1398fSOlivier Deprez
448b5dd2422SOlivier Deprez- The *hypervisor* node describes SPs. *is_ffa_partition* boolean attribute
449b5dd2422SOlivier Deprez  indicates a FF-A compliant SP. The *load_address* field specifies the load
450b5dd2422SOlivier Deprez  address at which TF-A loaded the SP package.
451b5dd2422SOlivier Deprez- *cpus* node provide the platform topology and allows MPIDR to VMPIDR mapping.
452b5dd2422SOlivier Deprez  Note the primary core is declared first, then secondary core are declared
453b5dd2422SOlivier Deprez  in reverse order.
454b5dd2422SOlivier Deprez- The *memory* node provides platform information on the ranges of memory
455b5dd2422SOlivier Deprez  available to the SPMC.
456fcb1398fSOlivier Deprez
457fcb1398fSOlivier DeprezSPMC boot
458fcb1398fSOlivier Deprez~~~~~~~~~
459fcb1398fSOlivier Deprez
460fcb1398fSOlivier DeprezThe SPMC is loaded by BL2 as the BL32 image.
461fcb1398fSOlivier Deprez
462f2dcf418SOlivier DeprezThe SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_.
463fcb1398fSOlivier Deprez
464fcb1398fSOlivier DeprezBL2 passes the SPMC manifest address to BL31 through a register.
465fcb1398fSOlivier Deprez
466b5dd2422SOlivier DeprezAt boot time, the SPMD in BL31 runs from the primary core, initializes the core
467f2dcf418SOlivier Deprezcontexts and launches the SPMC (BL32) passing the following information through
468f2dcf418SOlivier Deprezregisters:
469f2dcf418SOlivier Deprez
470f2dcf418SOlivier Deprez- X0 holds the ``TOS_FW_CONFIG`` physical address (or SPMC manifest blob).
471f2dcf418SOlivier Deprez- X1 holds the ``HW_CONFIG`` physical address.
472f2dcf418SOlivier Deprez- X4 holds the currently running core linear id.
473fcb1398fSOlivier Deprez
474fcb1398fSOlivier DeprezLoading of SPs
475fcb1398fSOlivier Deprez~~~~~~~~~~~~~~
476fcb1398fSOlivier Deprez
477b5dd2422SOlivier DeprezAt boot time, BL2 loads SPs sequentially in addition to the SPMC as depicted
478b5dd2422SOlivier Deprezbelow:
479b5dd2422SOlivier Deprez
480fcb1398fSOlivier Deprez.. uml:: ../resources/diagrams/plantuml/bl2-loading-sp.puml
481fcb1398fSOlivier Deprez
482b5dd2422SOlivier DeprezNote this boot flow is an implementation sample on Arm's FVP platform.
483b5dd2422SOlivier DeprezPlatforms not using TF-A's *Firmware CONFiguration* framework would adjust to a
484b5dd2422SOlivier Deprezdifferent implementation.
485fcb1398fSOlivier Deprez
486fcb1398fSOlivier DeprezSecure boot
487fcb1398fSOlivier Deprez~~~~~~~~~~~
488fcb1398fSOlivier Deprez
489fcb1398fSOlivier DeprezThe SP content certificate is inserted as a separate FIP item so that BL2 loads SPMC,
490b5dd2422SOlivier DeprezSPMC manifest, secure partitions and verifies them for authenticity and integrity.
491fcb1398fSOlivier DeprezRefer to TBBR specification `[3]`_.
492fcb1398fSOlivier Deprez
493b5dd2422SOlivier DeprezThe multiple-signing domain feature (in current state dual signing domain `[8]`_) allows
494b5dd2422SOlivier Deprezthe use of two root keys namely S-ROTPK and NS-ROTPK:
495fcb1398fSOlivier Deprez
4960901d339SManish Pandey- SPMC (BL32) and SPMC manifest are signed by the SiP using the S-ROTPK.
497fcb1398fSOlivier Deprez- BL33 may be signed by the OEM using NS-ROTPK.
4980901d339SManish Pandey- An SP may be signed either by SiP (using S-ROTPK) or by OEM (using NS-ROTPK).
499fcb1398fSOlivier Deprez
500b5dd2422SOlivier DeprezAlso refer to `Describing secure partitions`_ and `TF-A build options`_ sections.
501fcb1398fSOlivier Deprez
502fcb1398fSOlivier DeprezHafnium in the secure world
503fcb1398fSOlivier Deprez===========================
504fcb1398fSOlivier Deprez
505fcb1398fSOlivier DeprezGeneral considerations
506fcb1398fSOlivier Deprez----------------------
507fcb1398fSOlivier Deprez
508fcb1398fSOlivier DeprezBuild platform for the secure world
509fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
510fcb1398fSOlivier Deprez
511b5dd2422SOlivier DeprezIn the Hafnium reference implementation specific code parts are only relevant to
512b5dd2422SOlivier Deprezthe secure world. Such portions are isolated in architecture specific files
513b5dd2422SOlivier Deprezand/or enclosed by a ``SECURE_WORLD`` macro.
514fcb1398fSOlivier Deprez
515b5dd2422SOlivier DeprezSecure partitions CPU scheduling
516fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
517fcb1398fSOlivier Deprez
518b5dd2422SOlivier DeprezThe FF-A v1.0 specification `[1]`_ provides two ways to relinquinsh CPU time to
519b5dd2422SOlivier Deprezsecure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of:
520fcb1398fSOlivier Deprez
521b5dd2422SOlivier Deprez- the FFA_MSG_SEND_DIRECT_REQ interface.
522b5dd2422SOlivier Deprez- the FFA_RUN interface.
523fcb1398fSOlivier Deprez
524fcb1398fSOlivier DeprezPlatform topology
525fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~
526fcb1398fSOlivier Deprez
527b5dd2422SOlivier DeprezThe *execution-ctx-count* SP manifest field can take the value of one or the
528b5dd2422SOlivier Depreztotal number of PEs. The FF-A v1.0 specification `[1]`_  recommends the
529fcb1398fSOlivier Deprezfollowing SP types:
530fcb1398fSOlivier Deprez
531b5dd2422SOlivier Deprez- Pinned MP SPs: an execution context matches a physical PE. MP SPs must
532b5dd2422SOlivier Deprez  implement the same number of ECs as the number of PEs in the platform.
533b5dd2422SOlivier Deprez- Migratable UP SPs: a single execution context can run and be migrated on any
534b5dd2422SOlivier Deprez  physical PE. Such SP declares a single EC in its SP manifest. An UP SP can
535b5dd2422SOlivier Deprez  receive a direct message request originating from any physical core targeting
536b5dd2422SOlivier Deprez  the single execution context.
537fcb1398fSOlivier Deprez
538fcb1398fSOlivier DeprezParsing SP partition manifests
539fcb1398fSOlivier Deprez------------------------------
540fcb1398fSOlivier Deprez
541b5dd2422SOlivier DeprezHafnium consumes SP manifests as defined in `[1]`_ and `SP manifests`_.
542b5dd2422SOlivier DeprezNote the current implementation may not implement all optional fields.
543fcb1398fSOlivier Deprez
544b5dd2422SOlivier DeprezThe SP manifest may contain memory and device regions nodes. In case of
545b5dd2422SOlivier Deprezan S-EL2 SPMC:
546fcb1398fSOlivier Deprez
547b5dd2422SOlivier Deprez- Memory regions are mapped in the SP EL1&0 Stage-2 translation regime at
548b5dd2422SOlivier Deprez  load time (or EL1&0 Stage-1 for an S-EL1 SPMC). A memory region node can
549b5dd2422SOlivier Deprez  specify RX/TX buffer regions in which case it is not necessary for an SP
550b5dd2422SOlivier Deprez  to explicitly invoke the ``FFA_RXTX_MAP`` interface.
551b5dd2422SOlivier Deprez- Device regions are mapped in the SP EL1&0 Stage-2 translation regime (or
552b5dd2422SOlivier Deprez  EL1&0 Stage-1 for an S-EL1 SPMC) as peripherals and possibly allocate
553b5dd2422SOlivier Deprez  additional resources (e.g. interrupts).
554fcb1398fSOlivier Deprez
555b5dd2422SOlivier DeprezFor the S-EL2 SPMC, base addresses for memory and device region nodes are IPAs
556b5dd2422SOlivier Deprezprovided the SPMC identity maps IPAs to PAs within SP EL1&0 Stage-2 translation
557b5dd2422SOlivier Deprezregime.
558fcb1398fSOlivier Deprez
559b5dd2422SOlivier DeprezNote: in the current implementation both VTTBR_EL2 and VSTTBR_EL2 point to the
560b5dd2422SOlivier Deprezsame set of page tables. It is still open whether two sets of page tables shall
561b5dd2422SOlivier Deprezbe provided per SP. The memory region node as defined in the specification
562fcb1398fSOlivier Deprezprovides a memory security attribute hinting to map either to the secure or
563b5dd2422SOlivier Depreznon-secure EL1&0 Stage-2 table if it exists.
564fcb1398fSOlivier Deprez
565fcb1398fSOlivier DeprezPassing boot data to the SP
566fcb1398fSOlivier Deprez---------------------------
567fcb1398fSOlivier Deprez
568*573ac373SJ-AlvesIn `[1]`_ , the section  "Boot information protocol" defines a method for passing
569*573ac373SJ-Alvesdata to the SPs at boot time. It specifies the format for the boot information
570*573ac373SJ-Alvesdescriptor and boot information header structures, which describe the data to be
571*573ac373SJ-Alvesexchanged between SPMC and SP.
572*573ac373SJ-AlvesThe specification also defines the types of data that can be passed.
573*573ac373SJ-AlvesThe aggregate of both the boot info structures and the data itself is designated
574*573ac373SJ-Alvesthe boot information blob, and is passed to a Partition as a contiguous memory
575*573ac373SJ-Alvesregion.
576fcb1398fSOlivier Deprez
577*573ac373SJ-AlvesCurrently, the SPM implementation supports the FDT type which is used to pass the
578*573ac373SJ-Alvespartition's DTB manifest.
579*573ac373SJ-Alves
580*573ac373SJ-AlvesThe region for the boot information blob is allocated through the SP package.
581*573ac373SJ-Alves
582*573ac373SJ-Alves.. image:: ../resources/diagrams/partition-package.png
583*573ac373SJ-Alves
584*573ac373SJ-AlvesTo adjust the space allocated for the boot information blob, the json description
585*573ac373SJ-Alvesof the SP (see section `Describing secure partitions`_) shall be updated to contain
586*573ac373SJ-Alvesthe manifest offset. If no offset is provided the manifest offset defaults to 0x1000,
587*573ac373SJ-Alveswhich is the page size in the Hafnium SPMC.
588*573ac373SJ-Alves
589*573ac373SJ-AlvesThe configuration of the boot protocol is done in the SPs manifest. As defined by
590*573ac373SJ-Alvesthe specification, the manifest field 'gp-register-num' configures the GP register
591*573ac373SJ-Alveswhich shall be used to pass the address to the partitions boot information blob when
592*573ac373SJ-Alvesbooting the partition.
593*573ac373SJ-AlvesIn addition, the Hafnium SPMC implementation requires the boot information arguments
594*573ac373SJ-Alvesto be listed in a designated DT node:
595*573ac373SJ-Alves
596*573ac373SJ-Alves.. code:: shell
597*573ac373SJ-Alves
598*573ac373SJ-Alves  boot-info {
599*573ac373SJ-Alves      compatible = "arm,ffa-manifest-boot-info";
600*573ac373SJ-Alves      ffa_manifest;
601*573ac373SJ-Alves  };
602*573ac373SJ-Alves
603*573ac373SJ-AlvesThe whole secure partition package image (see `Secure Partition packages`_) is
604*573ac373SJ-Alvesmapped to the SP secure EL1&0 Stage-2 translation regime. As such, the SP can
605*573ac373SJ-Alvesretrieve the address for the boot information blob in the designated GP register,
606*573ac373SJ-Alvesprocess the boot information header and descriptors, access its own manifest
607*573ac373SJ-AlvesDTB blob and extract its partition manifest properties.
608fcb1398fSOlivier Deprez
609fcb1398fSOlivier DeprezSP Boot order
610fcb1398fSOlivier Deprez-------------
611fcb1398fSOlivier Deprez
612fcb1398fSOlivier DeprezSP manifests provide an optional boot order attribute meant to resolve
613fcb1398fSOlivier Deprezdependencies such as an SP providing a service required to properly boot
614c1ff1791SJ-Alvesanother SP. SPMC boots the SPs in accordance to the boot order attribute,
615c1ff1791SJ-Alveslowest to the highest value. If the boot order attribute is absent from the FF-A
616c1ff1791SJ-Alvesmanifest, the SP is treated as if it had the highest boot order value
617c1ff1791SJ-Alves(i.e. lowest booting priority).
618fcb1398fSOlivier Deprez
619b5dd2422SOlivier DeprezIt is possible for an SP to call into another SP through a direct request
620b5dd2422SOlivier Deprezprovided the latter SP has already been booted.
621b5dd2422SOlivier Deprez
622fcb1398fSOlivier DeprezBoot phases
623fcb1398fSOlivier Deprez-----------
624fcb1398fSOlivier Deprez
625fcb1398fSOlivier DeprezPrimary core boot-up
626fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~
627fcb1398fSOlivier Deprez
628b5dd2422SOlivier DeprezUpon boot-up, BL31 hands over to the SPMC (BL32) on the primary boot physical
629b5dd2422SOlivier Deprezcore. The SPMC performs its platform initializations and registers the SPMC
630b5dd2422SOlivier Deprezsecondary physical core entry point physical address by the use of the
63116c1c453SJ-Alves`FFA_SECONDARY_EP_REGISTER`_ interface (SMC invocation from the SPMC to the SPMD
63216c1c453SJ-Alvesat secure physical FF-A instance).
633fcb1398fSOlivier Deprez
634b5dd2422SOlivier DeprezThe SPMC then creates secure partitions based on SP packages and manifests. Each
635b5dd2422SOlivier Deprezsecure partition is launched in sequence (`SP Boot order`_) on their "primary"
636b5dd2422SOlivier Deprezexecution context. If the primary boot physical core linear id is N, an MP SP is
637b5dd2422SOlivier Deprezstarted using EC[N] on PE[N] (see `Platform topology`_). If the partition is a
638b5dd2422SOlivier DeprezUP SP, it is started using its unique EC0 on PE[N].
639fcb1398fSOlivier Deprez
640b5dd2422SOlivier DeprezThe SP primary EC (or the EC used when the partition is booted as described
641b5dd2422SOlivier Deprezabove):
642fcb1398fSOlivier Deprez
643b5dd2422SOlivier Deprez- Performs the overall SP boot time initialization, and in case of a MP SP,
644b5dd2422SOlivier Deprez  prepares the SP environment for other execution contexts.
645b5dd2422SOlivier Deprez- In the case of a MP SP, it invokes the FFA_SECONDARY_EP_REGISTER at secure
646b5dd2422SOlivier Deprez  virtual FF-A instance (SMC invocation from SP to SPMC) to provide the IPA
647b5dd2422SOlivier Deprez  entry point for other execution contexts.
648b5dd2422SOlivier Deprez- Exits through ``FFA_MSG_WAIT`` to indicate successful initialization or
649b5dd2422SOlivier Deprez  ``FFA_ERROR`` in case of failure.
650fcb1398fSOlivier Deprez
651b5dd2422SOlivier DeprezSecondary cores boot-up
652b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~
653fcb1398fSOlivier Deprez
654b5dd2422SOlivier DeprezOnce the system is started and NWd brought up, a secondary physical core is
655b5dd2422SOlivier Deprezwoken up by the ``PSCI_CPU_ON`` service invocation. The TF-A SPD hook mechanism
656b5dd2422SOlivier Deprezcalls into the SPMD on the newly woken up physical core. Then the SPMC is
657b5dd2422SOlivier Deprezentered at the secondary physical core entry point.
658fcb1398fSOlivier Deprez
659b5dd2422SOlivier DeprezIn the current implementation, the first SP is resumed on the coresponding EC
660b5dd2422SOlivier Deprez(the virtual CPU which matches the physical core). The implication is that the
661b5dd2422SOlivier Deprezfirst SP must be a MP SP.
662fcb1398fSOlivier Deprez
663b5dd2422SOlivier DeprezIn a linux based system, once secure and normal worlds are booted but prior to
664b5dd2422SOlivier Depreza NWd FF-A driver has been loaded:
665fcb1398fSOlivier Deprez
666b5dd2422SOlivier Deprez- The first SP has initialized all its ECs in response to primary core boot up
667b5dd2422SOlivier Deprez  (at system initialization) and secondary core boot up (as a result of linux
668b5dd2422SOlivier Deprez  invoking PSCI_CPU_ON for all secondary cores).
669b5dd2422SOlivier Deprez- Other SPs have their first execution context initialized as a result of secure
670b5dd2422SOlivier Deprez  world initialization on the primary boot core. Other ECs for those SPs have to
671b5dd2422SOlivier Deprez  be run first through ffa_run to complete their initialization (which results
672b5dd2422SOlivier Deprez  in the EC completing with FFA_MSG_WAIT).
673fcb1398fSOlivier Deprez
674b5dd2422SOlivier DeprezRefer to `Power management`_ for further details.
675fcb1398fSOlivier Deprez
67616c1c453SJ-AlvesNotifications
67716c1c453SJ-Alves-------------
67816c1c453SJ-Alves
67916c1c453SJ-AlvesThe FF-A v1.1 specification `[1]`_ defines notifications as an asynchronous
68016c1c453SJ-Alvescommunication mechanism with non-blocking semantics. It allows for one FF-A
68116c1c453SJ-Alvesendpoint to signal another for service provision, without hindering its current
68216c1c453SJ-Alvesprogress.
68316c1c453SJ-Alves
68416c1c453SJ-AlvesHafnium currently supports 64 notifications. The IDs of each notification define
68516c1c453SJ-Alvesa position in a 64-bit bitmap.
68616c1c453SJ-Alves
68716c1c453SJ-AlvesThe signaling of notifications can interchangeably happen between NWd and SWd
68816c1c453SJ-AlvesFF-A endpoints.
68916c1c453SJ-Alves
69016c1c453SJ-AlvesThe SPMC is in charge of managing notifications from SPs to SPs, from SPs to
69116c1c453SJ-AlvesVMs, and from VMs to SPs. An hypervisor component would only manage
69216c1c453SJ-Alvesnotifications from VMs to VMs. Given the SPMC has no visibility of the endpoints
69316c1c453SJ-Alvesdeployed in NWd, the Hypervisor or OS kernel must invoke the interface
69416c1c453SJ-AlvesFFA_NOTIFICATION_BITMAP_CREATE to allocate the notifications bitmap per FF-A
69516c1c453SJ-Alvesendpoint in the NWd that supports it.
69616c1c453SJ-Alves
69716c1c453SJ-AlvesA sender can signal notifications once the receiver has provided it with
69816c1c453SJ-Alvespermissions. Permissions are provided by invoking the interface
69916c1c453SJ-AlvesFFA_NOTIFICATION_BIND.
70016c1c453SJ-Alves
70116c1c453SJ-AlvesNotifications are signaled by invoking FFA_NOTIFICATION_SET. Henceforth
70216c1c453SJ-Alvesthey are considered to be in a pending sate. The receiver can retrieve its
70316c1c453SJ-Alvespending notifications invoking FFA_NOTIFICATION_GET, which, from that moment,
70416c1c453SJ-Alvesare considered to be handled.
70516c1c453SJ-Alves
70616c1c453SJ-AlvesPer the FF-A v1.1 spec, each FF-A endpoint must be associated with a scheduler
70716c1c453SJ-Alvesthat is in charge of donating CPU cycles for notifications handling. The
70816c1c453SJ-AlvesFF-A driver calls FFA_NOTIFICATION_INFO_GET to retrieve the information about
70916c1c453SJ-Alveswhich FF-A endpoints have pending notifications. The receiver scheduler is
71016c1c453SJ-Alvescalled and informed by the FF-A driver, and it should allocate CPU cycles to the
71116c1c453SJ-Alvesreceiver.
71216c1c453SJ-Alves
71316c1c453SJ-AlvesThere are two types of notifications supported:
71416c1c453SJ-Alves- Global, which are targeted to a FF-A endpoint and can be handled within any of
71516c1c453SJ-Alvesits execution contexts, as determined by the scheduler of the system.
71616c1c453SJ-Alves- Per-vCPU, which are targeted to a FF-A endpoint and to be handled within a
71716c1c453SJ-Alvesa specific execution context, as determined by the sender.
71816c1c453SJ-Alves
71916c1c453SJ-AlvesThe type of a notification is set when invoking FFA_NOTIFICATION_BIND to give
72016c1c453SJ-Alvespermissions to the sender.
72116c1c453SJ-Alves
72216c1c453SJ-AlvesNotification signaling resorts to two interrupts:
72316c1c453SJ-Alves- Schedule Receiver Interrupt: Non-secure physical interrupt to be handled by
72416c1c453SJ-Alvesthe FF-A 'transport' driver within the receiver scheduler. At initialization
72516c1c453SJ-Alvesthe SPMC (as suggested by the spec) configures a secure SGI, as non-secure, and
72616c1c453SJ-Alvestriggers it when there are pending notifications, and the respective receivers
72716c1c453SJ-Alvesneed CPU cycles to handle them.
72816c1c453SJ-Alves- Notifications Pending Interrupt: Virtual Interrupt to be handled by the
72916c1c453SJ-Alvesreceiver of the notification. Set when there are pending notifications. For
73016c1c453SJ-Alvesper-vCPU the NPI is pended at the handling of FFA_NOTIFICATION_SET interface.
73116c1c453SJ-Alves
73216c1c453SJ-AlvesThe notifications receipt support is enabled in the partition FF-A manifest.
73316c1c453SJ-Alves
73416c1c453SJ-AlvesThe subsequent section provides more details about the each one of the
73516c1c453SJ-AlvesFF-A interfaces for notifications support.
73616c1c453SJ-Alves
737fcb1398fSOlivier DeprezMandatory interfaces
738fcb1398fSOlivier Deprez--------------------
739fcb1398fSOlivier Deprez
740b5dd2422SOlivier DeprezThe following interfaces are exposed to SPs:
741fcb1398fSOlivier Deprez
742fcb1398fSOlivier Deprez-  ``FFA_VERSION``
743fcb1398fSOlivier Deprez-  ``FFA_FEATURES``
744fcb1398fSOlivier Deprez-  ``FFA_RX_RELEASE``
745fcb1398fSOlivier Deprez-  ``FFA_RXTX_MAP``
74616c1c453SJ-Alves-  ``FFA_RXTX_UNMAP``
747fcb1398fSOlivier Deprez-  ``FFA_PARTITION_INFO_GET``
748fcb1398fSOlivier Deprez-  ``FFA_ID_GET``
749b5dd2422SOlivier Deprez-  ``FFA_MSG_WAIT``
750b5dd2422SOlivier Deprez-  ``FFA_MSG_SEND_DIRECT_REQ``
751b5dd2422SOlivier Deprez-  ``FFA_MSG_SEND_DIRECT_RESP``
752b5dd2422SOlivier Deprez-  ``FFA_MEM_DONATE``
753b5dd2422SOlivier Deprez-  ``FFA_MEM_LEND``
754b5dd2422SOlivier Deprez-  ``FFA_MEM_SHARE``
755b5dd2422SOlivier Deprez-  ``FFA_MEM_RETRIEVE_REQ``
756b5dd2422SOlivier Deprez-  ``FFA_MEM_RETRIEVE_RESP``
757b5dd2422SOlivier Deprez-  ``FFA_MEM_RELINQUISH``
758b5dd2422SOlivier Deprez-  ``FFA_MEM_RECLAIM``
75916c1c453SJ-Alves
76016c1c453SJ-AlvesAs part of the support of FF-A v1.1, the following interfaces were added:
76116c1c453SJ-Alves
76216c1c453SJ-Alves - ``FFA_NOTIFICATION_BITMAP_CREATE``
76316c1c453SJ-Alves - ``FFA_NOTIFICATION_BITMAP_DESTROY``
76416c1c453SJ-Alves - ``FFA_NOTIFICATION_BIND``
76516c1c453SJ-Alves - ``FFA_NOTIFICATION_UNBIND``
76616c1c453SJ-Alves - ``FFA_NOTIFICATION_SET``
76716c1c453SJ-Alves - ``FFA_NOTIFICATION_GET``
76816c1c453SJ-Alves - ``FFA_NOTIFICATION_INFO_GET``
76916c1c453SJ-Alves - ``FFA_SPM_ID_GET``
770b5dd2422SOlivier Deprez - ``FFA_SECONDARY_EP_REGISTER``
771fcb1398fSOlivier Deprez
772fcb1398fSOlivier DeprezFFA_VERSION
773fcb1398fSOlivier Deprez~~~~~~~~~~~
774fcb1398fSOlivier Deprez
775b5dd2422SOlivier Deprez``FFA_VERSION`` requires a *requested_version* parameter from the caller.
776b5dd2422SOlivier DeprezThe returned value depends on the caller:
777fcb1398fSOlivier Deprez
778b5dd2422SOlivier Deprez- Hypervisor or OS kernel in NS-EL1/EL2: the SPMD returns the SPMC version
779b5dd2422SOlivier Deprez  specified in the SPMC manifest.
780b5dd2422SOlivier Deprez- SP: the SPMC returns its own implemented version.
781b5dd2422SOlivier Deprez- SPMC at S-EL1/S-EL2: the SPMD returns its own implemented version.
782fcb1398fSOlivier Deprez
783fcb1398fSOlivier DeprezFFA_FEATURES
784fcb1398fSOlivier Deprez~~~~~~~~~~~~
785fcb1398fSOlivier Deprez
786b5dd2422SOlivier DeprezFF-A features supported by the SPMC may be discovered by secure partitions at
787b5dd2422SOlivier Deprezboot (that is prior to NWd is booted) or run-time.
788fcb1398fSOlivier Deprez
789b5dd2422SOlivier DeprezThe SPMC calling FFA_FEATURES at secure physical FF-A instance always get
790b5dd2422SOlivier DeprezFFA_SUCCESS from the SPMD.
791b5dd2422SOlivier Deprez
792b5dd2422SOlivier DeprezThe request made by an Hypervisor or OS kernel is forwarded to the SPMC and
793b5dd2422SOlivier Deprezthe response relayed back to the NWd.
794fcb1398fSOlivier Deprez
795fcb1398fSOlivier DeprezFFA_RXTX_MAP/FFA_RXTX_UNMAP
796fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~
797fcb1398fSOlivier Deprez
798b5dd2422SOlivier DeprezWhen invoked from a secure partition FFA_RXTX_MAP maps the provided send and
799b5dd2422SOlivier Deprezreceive buffers described by their IPAs to the SP EL1&0 Stage-2 translation
800b5dd2422SOlivier Deprezregime as secure buffers in the MMU descriptors.
801fcb1398fSOlivier Deprez
802b5dd2422SOlivier DeprezWhen invoked from the Hypervisor or OS kernel, the buffers are mapped into the
803b5dd2422SOlivier DeprezSPMC EL2 Stage-1 translation regime and marked as NS buffers in the MMU
804b5dd2422SOlivier Deprezdescriptors.
805b5dd2422SOlivier Deprez
80616c1c453SJ-AlvesThe FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the
80716c1c453SJ-Alvescaller, either it being the Hypervisor or OS kernel, as well as a secure
80816c1c453SJ-Alvespartition.
809fcb1398fSOlivier Deprez
810fcb1398fSOlivier DeprezFFA_PARTITION_INFO_GET
811fcb1398fSOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~
812fcb1398fSOlivier Deprez
813b5dd2422SOlivier DeprezPartition info get call can originate:
814fcb1398fSOlivier Deprez
815b5dd2422SOlivier Deprez- from SP to SPMC
816b5dd2422SOlivier Deprez- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD.
817fcb1398fSOlivier Deprez
818fcb1398fSOlivier DeprezFFA_ID_GET
819fcb1398fSOlivier Deprez~~~~~~~~~~
820fcb1398fSOlivier Deprez
821b5dd2422SOlivier DeprezThe FF-A id space is split into a non-secure space and secure space:
822b5dd2422SOlivier Deprez
823b5dd2422SOlivier Deprez- FF-A ID with bit 15 clear relates to VMs.
824b5dd2422SOlivier Deprez- FF-A ID with bit 15 set related to SPs.
825b5dd2422SOlivier Deprez- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor, SPMD
826b5dd2422SOlivier Deprez  and SPMC.
827b5dd2422SOlivier Deprez
828fcb1398fSOlivier DeprezThe SPMD returns:
829fcb1398fSOlivier Deprez
830b5dd2422SOlivier Deprez- The default zero value on invocation from the Hypervisor.
831fcb1398fSOlivier Deprez- The ``spmc_id`` value specified in the SPMC manifest on invocation from
832fcb1398fSOlivier Deprez  the SPMC (see `SPMC manifest`_)
833fcb1398fSOlivier Deprez
834b5dd2422SOlivier DeprezThis convention helps the SPMC to determine the origin and destination worlds in
835b5dd2422SOlivier Deprezan FF-A ABI invocation. In particular the SPMC shall filter unauthorized
836fcb1398fSOlivier Depreztransactions in its world switch routine. It must not be permitted for a VM to
837b5dd2422SOlivier Deprezuse a secure FF-A ID as origin world by spoofing:
838fcb1398fSOlivier Deprez
839b5dd2422SOlivier Deprez- A VM-to-SP direct request/response shall set the origin world to be non-secure
840b5dd2422SOlivier Deprez  (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15
841fcb1398fSOlivier Deprez  set).
842b5dd2422SOlivier Deprez- Similarly, an SP-to-SP direct request/response shall set the FF-A ID bit 15
843b5dd2422SOlivier Deprez  for both origin and destination IDs.
844fcb1398fSOlivier Deprez
845fcb1398fSOlivier DeprezAn incoming direct message request arriving at SPMD from NWd is forwarded to
846fcb1398fSOlivier DeprezSPMC without a specific check. The SPMC is resumed through eret and "knows" the
847fcb1398fSOlivier Deprezmessage is coming from normal world in this specific code path. Thus the origin
848b5dd2422SOlivier Deprezendpoint ID must be checked by SPMC for being a normal world ID.
849fcb1398fSOlivier Deprez
850fcb1398fSOlivier DeprezAn SP sending a direct message request must have bit 15 set in its origin
851b5dd2422SOlivier Deprezendpoint ID and this can be checked by the SPMC when the SP invokes the ABI.
852fcb1398fSOlivier Deprez
853fcb1398fSOlivier DeprezThe SPMC shall reject the direct message if the claimed world in origin endpoint
854b5dd2422SOlivier DeprezID is not consistent:
855fcb1398fSOlivier Deprez
856b5dd2422SOlivier Deprez-  It is either forwarded by SPMD and thus origin endpoint ID must be a "normal
857b5dd2422SOlivier Deprez   world ID",
858b5dd2422SOlivier Deprez-  or initiated by an SP and thus origin endpoint ID must be a "secure world ID".
859fcb1398fSOlivier Deprez
860fcb1398fSOlivier Deprez
861b5dd2422SOlivier DeprezFFA_MSG_SEND_DIRECT_REQ/FFA_MSG_SEND_DIRECT_RESP
862b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
863fcb1398fSOlivier Deprez
864b5dd2422SOlivier DeprezThis is a mandatory interface for secure partitions consisting in direct request
865b5dd2422SOlivier Deprezand responses with the following rules:
866fcb1398fSOlivier Deprez
867b5dd2422SOlivier Deprez- An SP can send a direct request to another SP.
868b5dd2422SOlivier Deprez- An SP can receive a direct request from another SP.
869b5dd2422SOlivier Deprez- An SP can send a direct response to another SP.
870b5dd2422SOlivier Deprez- An SP cannot send a direct request to an Hypervisor or OS kernel.
871b5dd2422SOlivier Deprez- An Hypervisor or OS kernel can send a direct request to an SP.
872b5dd2422SOlivier Deprez- An SP can send a direct response to an Hypervisor or OS kernel.
873fcb1398fSOlivier Deprez
87416c1c453SJ-AlvesFFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY
87516c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87616c1c453SJ-Alves
87716c1c453SJ-AlvesThe secure partitions notifications bitmap are statically allocated by the SPMC.
87816c1c453SJ-AlvesHence, this interface is not to be issued by secure partitions.
87916c1c453SJ-Alves
88016c1c453SJ-AlvesAt initialization, the SPMC is not aware of VMs/partitions deployed in the
88116c1c453SJ-Alvesnormal world. Hence, the Hypervisor or OS kernel must use both ABIs for SPMC
88216c1c453SJ-Alvesto be prepared to handle notifications for the provided VM ID.
88316c1c453SJ-Alves
88416c1c453SJ-AlvesFFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND
88516c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88616c1c453SJ-Alves
88716c1c453SJ-AlvesPair of interfaces to manage permissions to signal notifications. Prior to
88816c1c453SJ-Alveshandling notifications, an FF-A endpoint must allow a given sender to signal a
88916c1c453SJ-Alvesbitmap of notifications.
89016c1c453SJ-Alves
89116c1c453SJ-AlvesIf the receiver doesn't have notification support enabled in its FF-A manifest,
89216c1c453SJ-Alvesit won't be able to bind notifications, hence forbidding it to receive any
89316c1c453SJ-Alvesnotifications.
89416c1c453SJ-Alves
89516c1c453SJ-AlvesFFA_NOTIFICATION_SET/FFA_NOTIFICATION_GET
89616c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89716c1c453SJ-Alves
89816c1c453SJ-AlvesIf the notifications set are per-vCPU, the NPI interrupt is set as pending
89916c1c453SJ-Alvesfor a given receiver partition.
90016c1c453SJ-Alves
90116c1c453SJ-AlvesThe FFA_NOTIFICATION_GET will retrieve all pending global notifications and all
90216c1c453SJ-Alvespending per-vCPU notifications targeted to the current vCPU.
90316c1c453SJ-Alves
90416c1c453SJ-AlvesHafnium keeps the global counting of the pending notifications, which is
90516c1c453SJ-Alvesincremented and decremented at the handling of FFA_NOTIFICATION_SET and
90616c1c453SJ-AlvesFFA_NOTIFICATION_GET, respectively. If the counter reaches zero, prior to SPMC
90716c1c453SJ-Alvestriggering the SRI, it won't be triggered.
90816c1c453SJ-Alves
90916c1c453SJ-AlvesFFA_NOTIFICATION_INFO_GET
91016c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~
91116c1c453SJ-Alves
91216c1c453SJ-AlvesHafnium keeps the global counting of pending notifications whose info has been
91316c1c453SJ-Alvesretrieved by this interface. The counting is incremented and decremented at the
91416c1c453SJ-Alveshandling of FFA_NOTIFICATION_INFO_GET and FFA_NOTIFICATION_GET, respectively.
91516c1c453SJ-AlvesIt also tracks the notifications whose info has been retrieved individually,
91616c1c453SJ-Alvessuch that it avoids duplicating returned information for subsequent calls to
91716c1c453SJ-AlvesFFA_NOTIFICATION_INFO_GET. For each notification, this state information is
91816c1c453SJ-Alvesreset when receiver called FFA_NOTIFICATION_GET to retrieve them.
91916c1c453SJ-Alves
92016c1c453SJ-AlvesFFA_SPM_ID_GET
92116c1c453SJ-Alves~~~~~~~~~~~~~~
92216c1c453SJ-Alves
92316c1c453SJ-AlvesReturns the FF-A ID allocated to the SPM component (which includes SPMC + SPMD).
92416c1c453SJ-AlvesAt initialization, the SPMC queries the SPMD for the SPM ID, using this
92516c1c453SJ-Alvessame interface, and saves it.
92616c1c453SJ-Alves
92716c1c453SJ-AlvesThe call emitted at NS and secure physical FF-A instances returns the SPM ID
92816c1c453SJ-Alvesspecified in the SPMC manifest.
92916c1c453SJ-Alves
93016c1c453SJ-AlvesSecure partitions call this interface at the virtual instance, to which the SPMC
93116c1c453SJ-Alvesshall return the priorly retrieved SPM ID.
93216c1c453SJ-Alves
93316c1c453SJ-AlvesThe Hypervisor or OS kernel can issue an FFA_SPM_ID_GET call handled by the
93416c1c453SJ-AlvesSPMD, which returns the SPM ID.
93516c1c453SJ-Alves
93616c1c453SJ-AlvesFFA_SECONDARY_EP_REGISTER
93716c1c453SJ-Alves~~~~~~~~~~~~~~~~~~~~~~~~~
93816c1c453SJ-Alves
93916c1c453SJ-AlvesWhen the SPMC boots, all secure partitions are initialized on their primary
94016c1c453SJ-AlvesExecution Context.
94116c1c453SJ-Alves
94216c1c453SJ-AlvesThe interface FFA_SECONDARY_EP_REGISTER is to be used by a secure partitions
94316c1c453SJ-Alvesfrom its first execution context, to provide the entry point address for
94416c1c453SJ-Alvessecondary execution contexts.
94516c1c453SJ-Alves
94616c1c453SJ-AlvesA secondary EC is first resumed either upon invocation of PSCI_CPU_ON from
94716c1c453SJ-Alvesthe NWd or by invocation of FFA_RUN.
94816c1c453SJ-Alves
949b5dd2422SOlivier DeprezSPMC-SPMD direct requests/responses
950b5dd2422SOlivier Deprez-----------------------------------
951fcb1398fSOlivier Deprez
952b5dd2422SOlivier DeprezImplementation-defined FF-A IDs are allocated to the SPMC and SPMD.
953b5dd2422SOlivier DeprezUsing those IDs in source/destination fields of a direct request/response
954b5dd2422SOlivier Deprezpermits SPMD to SPMC communication and either way.
955fcb1398fSOlivier Deprez
956b5dd2422SOlivier Deprez- SPMC to SPMD direct request/response uses SMC conduit.
957b5dd2422SOlivier Deprez- SPMD to SPMC direct request/response uses ERET conduit.
958fcb1398fSOlivier Deprez
959b5dd2422SOlivier DeprezPE MMU configuration
960b5dd2422SOlivier Deprez--------------------
961fcb1398fSOlivier Deprez
962b5dd2422SOlivier DeprezWith secure virtualization enabled, two IPA spaces are output from the secure
963b5dd2422SOlivier DeprezEL1&0 Stage-1 translation (secure and non-secure). The EL1&0 Stage-2 translation
964b5dd2422SOlivier Deprezhardware is fed by:
965fcb1398fSOlivier Deprez
966b5dd2422SOlivier Deprez- A single secure IPA space when the SP EL1&0 Stage-1 MMU is disabled.
967b5dd2422SOlivier Deprez- Two IPA spaces (secure and non-secure) when the SP EL1&0 Stage-1 MMU is
968b5dd2422SOlivier Deprez  enabled.
969fcb1398fSOlivier Deprez
970b5dd2422SOlivier Deprez``VTCR_EL2`` and ``VSTCR_EL2`` provide configuration bits for controlling the
971b5dd2422SOlivier DeprezNS/S IPA translations.
972b5dd2422SOlivier Deprez``VSTCR_EL2.SW`` = 0, ``VSTCR_EL2.SA`` = 0,``VTCR_EL2.NSW`` = 0, ``VTCR_EL2.NSA`` = 1:
973fcb1398fSOlivier Deprez
974b5dd2422SOlivier Deprez- Stage-2 translations for the NS IPA space access the NS PA space.
975b5dd2422SOlivier Deprez- Stage-2 translation table walks for the NS IPA space are to the secure PA space.
976fcb1398fSOlivier Deprez
977b5dd2422SOlivier DeprezSecure and non-secure IPA regions use the same set of Stage-2 page tables within
978b5dd2422SOlivier Depreza SP.
979fcb1398fSOlivier Deprez
980fcb1398fSOlivier DeprezInterrupt management
981fcb1398fSOlivier Deprez--------------------
982fcb1398fSOlivier Deprez
983b5dd2422SOlivier DeprezGIC ownership
984b5dd2422SOlivier Deprez~~~~~~~~~~~~~
985fcb1398fSOlivier Deprez
986b5dd2422SOlivier DeprezThe SPMC owns the GIC configuration. Secure and non-secure interrupts are
987b5dd2422SOlivier Depreztrapped at S-EL2. The SPMC manages interrupt resources and allocates interrupt
988b5dd2422SOlivier DeprezIDs based on SP manifests. The SPMC acknowledges physical interrupts and injects
989b5dd2422SOlivier Deprezvirtual interrupts by setting the use of vIRQ/vFIQ bits before resuming a SP.
990fcb1398fSOlivier Deprez
991b5dd2422SOlivier DeprezNon-secure interrupt handling
992b5dd2422SOlivier Deprez~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
993fcb1398fSOlivier Deprez
994b5dd2422SOlivier DeprezThe following illustrate the scenarios of non secure physical interrupts trapped
995b5dd2422SOlivier Deprezby the SPMC:
996fcb1398fSOlivier Deprez
997b5dd2422SOlivier Deprez- The SP handles a managed exit operation:
998b5dd2422SOlivier Deprez
999b5dd2422SOlivier Deprez.. image:: ../resources/diagrams/ffa-ns-interrupt-handling-managed-exit.png
1000b5dd2422SOlivier Deprez
1001b5dd2422SOlivier Deprez- The SP is pre-empted without managed exit:
1002b5dd2422SOlivier Deprez
1003b5dd2422SOlivier Deprez.. image:: ../resources/diagrams/ffa-ns-interrupt-handling-sp-preemption.png
1004b5dd2422SOlivier Deprez
1005b5dd2422SOlivier DeprezSecure interrupt handling
100652558e08SMadhukar Pappireddy-------------------------
1007b5dd2422SOlivier Deprez
100852558e08SMadhukar PappireddyThis section documents the support implemented for secure interrupt handling in
100952558e08SMadhukar PappireddySPMC as per the guidance provided by FF-A v1.1 Beta0 specification.
101052558e08SMadhukar PappireddyThe following assumptions are made about the system configuration:
101152558e08SMadhukar Pappireddy
101252558e08SMadhukar Pappireddy  - In the current implementation, S-EL1 SPs are expected to use the para
101352558e08SMadhukar Pappireddy    virtualized ABIs for interrupt management rather than accessing virtual GIC
101452558e08SMadhukar Pappireddy    interface.
101552558e08SMadhukar Pappireddy  - Unless explicitly stated otherwise, this support is applicable only for
101652558e08SMadhukar Pappireddy    S-EL1 SPs managed by SPMC.
101752558e08SMadhukar Pappireddy  - Secure interrupts are configured as G1S or G0 interrupts.
101852558e08SMadhukar Pappireddy  - All physical interrupts are routed to SPMC when running a secure partition
101952558e08SMadhukar Pappireddy    execution context.
102052558e08SMadhukar Pappireddy
102152558e08SMadhukar PappireddyA physical secure interrupt could preempt normal world execution. Moreover, when
102252558e08SMadhukar Pappireddythe execution is in secure world, it is highly likely that the target of a
102352558e08SMadhukar Pappireddysecure interrupt is not the currently running execution context of an SP. It
102452558e08SMadhukar Pappireddycould be targeted to another FF-A component. Consequently, secure interrupt
102552558e08SMadhukar Pappireddymanagement depends on the state of the target execution context of the SP that
102652558e08SMadhukar Pappireddyis responsible for handling the interrupt. Hence, the spec provides guidance on
102752558e08SMadhukar Pappireddyhow to signal start and completion of secure interrupt handling as discussed in
102852558e08SMadhukar Pappireddyfurther sections.
102952558e08SMadhukar Pappireddy
103052558e08SMadhukar PappireddySecure interrupt signaling mechanisms
103152558e08SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103252558e08SMadhukar Pappireddy
103352558e08SMadhukar PappireddySignaling refers to the mechanisms used by SPMC to indicate to the SP execution
103452558e08SMadhukar Pappireddycontext that it has a pending virtual interrupt and to further run the SP
103552558e08SMadhukar Pappireddyexecution context, such that it can handle the virtual interrupt. SPMC uses
103652558e08SMadhukar Pappireddyeither the FFA_INTERRUPT interface with ERET conduit or vIRQ signal for signaling
103752558e08SMadhukar Pappireddyto S-EL1 SPs. When normal world execution is preempted by a secure interrupt,
103852558e08SMadhukar Pappireddythe SPMD uses the FFA_INTERRUPT ABI with ERET conduit to signal interrupt to SPMC
103952558e08SMadhukar Pappireddyrunning in S-EL2.
104052558e08SMadhukar Pappireddy
104152558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+
104252558e08SMadhukar Pappireddy| SP State  | Conduit | Interface and | Description                           |
104352558e08SMadhukar Pappireddy|           |         | parameters    |                                       |
104452558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+
104552558e08SMadhukar Pappireddy| WAITING   | ERET,   | FFA_INTERRUPT,| SPMC signals to SP the ID of pending  |
104652558e08SMadhukar Pappireddy|           | vIRQ    | Interrupt ID  | interrupt. It pends vIRQ signal and   |
104752558e08SMadhukar Pappireddy|           |         |               | resumes execution context of SP       |
104852558e08SMadhukar Pappireddy|           |         |               | through ERET.                         |
104952558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+
105052558e08SMadhukar Pappireddy| BLOCKED   | ERET,   | FFA_INTERRUPT | SPMC signals to SP that an interrupt  |
105152558e08SMadhukar Pappireddy|           | vIRQ    |               | is pending. It pends vIRQ signal and  |
105252558e08SMadhukar Pappireddy|           |         |               | resumes execution context of SP       |
105352558e08SMadhukar Pappireddy|           |         |               | through ERET.                         |
105452558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+
105552558e08SMadhukar Pappireddy| PREEMPTED | vIRQ    | NA            | SPMC pends the vIRQ signal but does   |
105652558e08SMadhukar Pappireddy|           |         |               | not resume execution context of SP.   |
105752558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+
105852558e08SMadhukar Pappireddy| RUNNING   | ERET,   | NA            | SPMC pends the vIRQ signal and resumes|
105952558e08SMadhukar Pappireddy|           | vIRQ    |               | execution context of SP through ERET. |
106052558e08SMadhukar Pappireddy+-----------+---------+---------------+---------------------------------------+
106152558e08SMadhukar Pappireddy
106252558e08SMadhukar PappireddySecure interrupt completion mechanisms
106352558e08SMadhukar Pappireddy~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106452558e08SMadhukar Pappireddy
106552558e08SMadhukar PappireddyA SP signals secure interrupt handling completion to the SPMC through the
106652558e08SMadhukar Pappireddyfollowing mechanisms:
106752558e08SMadhukar Pappireddy
106852558e08SMadhukar Pappireddy  - ``FFA_MSG_WAIT`` ABI if it was in WAITING state.
106952558e08SMadhukar Pappireddy  - ``FFA_RUN`` ABI if its was in BLOCKED state.
107052558e08SMadhukar Pappireddy
107152558e08SMadhukar PappireddyIn the current implementation, S-EL1 SPs use para-virtualized HVC interface
107252558e08SMadhukar Pappireddyimplemented by SPMC to perform priority drop and interrupt deactivation (we
107352558e08SMadhukar Pappireddyassume EOImode = 0, i.e. priority drop and deactivation are done together).
107452558e08SMadhukar Pappireddy
107552558e08SMadhukar PappireddyIf normal world execution was preempted by secure interrupt, SPMC uses
107652558e08SMadhukar PappireddyFFA_NORMAL_WORLD_RESUME ABI to indicate completion of secure interrupt handling
107752558e08SMadhukar Pappireddyand further return execution to normal world. If the current SP execution
107852558e08SMadhukar Pappireddycontext was preempted by a secure interrupt to be handled by execution context
107952558e08SMadhukar Pappireddyof target SP, SPMC resumes current SP after signal completion by target SP
108052558e08SMadhukar Pappireddyexecution context.
108152558e08SMadhukar Pappireddy
108252558e08SMadhukar PappireddyAn action is broadly a set of steps taken by the SPMC in response to a physical
108352558e08SMadhukar Pappireddyinterrupt. In order to simplify the design, the current version of secure
108452558e08SMadhukar Pappireddyinterrupt management support in SPMC (Hafnium) does not fully implement the
108552558e08SMadhukar PappireddyScheduling models and Partition runtime models. However, the current
108652558e08SMadhukar Pappireddyimplementation loosely maps to the following actions that are legally allowed
108752558e08SMadhukar Pappireddyby the specification. Please refer to the Table 8.4 in the spec for further
108852558e08SMadhukar Pappireddydescription of actions. The action specified for a type of interrupt when the
108952558e08SMadhukar PappireddySP is in the message processing running state cannot be less permissive than the
109052558e08SMadhukar Pappireddyaction specified for the same type of interrupt when the SP is in the interrupt
109152558e08SMadhukar Pappireddyhandling running state.
109252558e08SMadhukar Pappireddy
109352558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+
109452558e08SMadhukar Pappireddy| Runtime Model      | NS-Int             | Self S-Int | Other S-Int |
109552558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+
109652558e08SMadhukar Pappireddy| Message Processing | Signalable with ME | Signalable | Signalable  |
109752558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+
109852558e08SMadhukar Pappireddy| Interrupt Handling | Queued             | Queued     | Queued      |
109952558e08SMadhukar Pappireddy+--------------------+--------------------+------------+-------------+
110052558e08SMadhukar Pappireddy
110152558e08SMadhukar PappireddyAbbreviations:
110252558e08SMadhukar Pappireddy
110352558e08SMadhukar Pappireddy  - NS-Int: A Non-secure physical interrupt. It requires a switch to the Normal
110452558e08SMadhukar Pappireddy    world to be handled.
110552558e08SMadhukar Pappireddy  - Other S-Int: A secure physical interrupt targeted to an SP different from
110652558e08SMadhukar Pappireddy    the one that is currently running.
110752558e08SMadhukar Pappireddy  - Self S-Int: A secure physical interrupt targeted to the SP that is currently
110852558e08SMadhukar Pappireddy    running.
110952558e08SMadhukar Pappireddy
111052558e08SMadhukar PappireddyThe following figure describes interrupt handling flow when secure interrupt
111152558e08SMadhukar Pappireddytriggers while in normal world:
111252558e08SMadhukar Pappireddy
111352558e08SMadhukar Pappireddy.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-nwd.png
111452558e08SMadhukar Pappireddy
111552558e08SMadhukar PappireddyA brief description of the events:
111652558e08SMadhukar Pappireddy
111752558e08SMadhukar Pappireddy  - 1) Secure interrupt triggers while normal world is running.
111852558e08SMadhukar Pappireddy  - 2) FIQ gets trapped to EL3.
111952558e08SMadhukar Pappireddy  - 3) SPMD signals secure interrupt to SPMC at S-EL2 using FFA_INTERRUPT ABI.
112052558e08SMadhukar Pappireddy  - 4) SPMC identifies target vCPU of SP and injects virtual interrupt (pends
112152558e08SMadhukar Pappireddy       vIRQ).
112252558e08SMadhukar Pappireddy  - 5) Since SP1 vCPU is in WAITING state, SPMC signals using FFA_INTERRUPT with
112352558e08SMadhukar Pappireddy       interrupt id as argument and resume it using ERET.
112452558e08SMadhukar Pappireddy  - 6) Execution traps to vIRQ handler in SP1 provided that interrupt is not
112552558e08SMadhukar Pappireddy       masked i.e., PSTATE.I = 0
112652558e08SMadhukar Pappireddy  - 7) SP1 services the interrupt and invokes the de-activation HVC call.
112752558e08SMadhukar Pappireddy  - 8) SPMC does internal state management and further de-activates the physical
112852558e08SMadhukar Pappireddy       interrupt and resumes SP vCPU.
112952558e08SMadhukar Pappireddy  - 9) SP performs secure interrupt completion through FFA_MSG_WAIT ABI.
113052558e08SMadhukar Pappireddy  - 10) SPMC returns control to EL3 using FFA_NORMAL_WORLD_RESUME.
113152558e08SMadhukar Pappireddy  - 11) EL3 resumes normal world execution.
113252558e08SMadhukar Pappireddy
113352558e08SMadhukar PappireddyThe following figure describes interrupt handling flow when secure interrupt
113452558e08SMadhukar Pappireddytriggers while in secure world:
113552558e08SMadhukar Pappireddy
113652558e08SMadhukar Pappireddy.. image:: ../resources/diagrams/ffa-secure-interrupt-handling-swd.png
113752558e08SMadhukar Pappireddy
113852558e08SMadhukar PappireddyA brief description of the events:
113952558e08SMadhukar Pappireddy
114052558e08SMadhukar Pappireddy  - 1) Secure interrupt triggers while SP2 is running and SP1 is blocked.
114152558e08SMadhukar Pappireddy  - 2) Gets trapped to SPMC as IRQ.
114252558e08SMadhukar Pappireddy  - 3) SPMC finds the target vCPU of secure partition responsible for handling
114352558e08SMadhukar Pappireddy       this secure interrupt. In this scenario, it is SP1.
114452558e08SMadhukar Pappireddy  - 4) SPMC pends vIRQ for SP1 and signals through FFA_INTERRUPT interface.
114552558e08SMadhukar Pappireddy       SPMC further resumes SP1 through ERET conduit.
114652558e08SMadhukar Pappireddy  - 5) Execution traps to vIRQ handler in SP1 provided that interrupt is not
114752558e08SMadhukar Pappireddy       masked i.e., PSTATE.I = 0
114852558e08SMadhukar Pappireddy  - 6) SP1 services the secure interrupt and invokes the de-activation HVC call.
114952558e08SMadhukar Pappireddy  - 7) SPMC does internal state management, de-activates the physical interrupt
115052558e08SMadhukar Pappireddy       and resumes SP1 vCPU.
115152558e08SMadhukar Pappireddy  - 8) Assuming SP1 is in BLOCKED state, SP1 performs secure interrupt completion
115252558e08SMadhukar Pappireddy       through FFA_RUN ABI.
115352558e08SMadhukar Pappireddy  - 9) SPMC resumes the pre-empted vCPU of SP2.
115452558e08SMadhukar Pappireddy
1155fcb1398fSOlivier Deprez
1156fcb1398fSOlivier DeprezPower management
1157fcb1398fSOlivier Deprez----------------
1158fcb1398fSOlivier Deprez
1159b5dd2422SOlivier DeprezIn platforms with or without secure virtualization:
1160fcb1398fSOlivier Deprez
1161b5dd2422SOlivier Deprez- The NWd owns the platform PM policy.
1162b5dd2422SOlivier Deprez- The Hypervisor or OS kernel is the component initiating PSCI service calls.
1163b5dd2422SOlivier Deprez- The EL3 PSCI library is in charge of the PM coordination and control
1164b5dd2422SOlivier Deprez  (eventually writing to platform registers).
1165b5dd2422SOlivier Deprez- While coordinating PM events, the PSCI library calls backs into the Secure
1166b5dd2422SOlivier Deprez  Payload Dispatcher for events the latter has statically registered to.
1167fcb1398fSOlivier Deprez
1168b5dd2422SOlivier DeprezWhen using the SPMD as a Secure Payload Dispatcher:
1169fcb1398fSOlivier Deprez
1170b5dd2422SOlivier Deprez- A power management event is relayed through the SPD hook to the SPMC.
1171b5dd2422SOlivier Deprez- In the current implementation only cpu on (svc_on_finish) and cpu off
1172b5dd2422SOlivier Deprez  (svc_off) hooks are registered.
1173b5dd2422SOlivier Deprez- The behavior for the cpu on event is described in `Secondary cores boot-up`_.
1174b5dd2422SOlivier Deprez  The SPMC is entered through its secondary physical core entry point.
1175b5dd2422SOlivier Deprez- The cpu off event occurs when the NWd calls PSCI_CPU_OFF. The method by which
1176b5dd2422SOlivier Deprez  the PM event is conveyed to the SPMC is implementation-defined in context of
1177b5dd2422SOlivier Deprez  FF-A v1.0 (`SPMC-SPMD direct requests/responses`_). It consists in a SPMD-to-SPMC
1178b5dd2422SOlivier Deprez  direct request/response conveying the PM event details and SPMC response.
1179b5dd2422SOlivier Deprez  The SPMD performs a synchronous entry into the SPMC. The SPMC is entered and
1180b5dd2422SOlivier Deprez  updates its internal state to reflect the physical core is being turned off.
1181b5dd2422SOlivier Deprez  In the current implementation no SP is resumed as a consequence. This behavior
1182b5dd2422SOlivier Deprez  ensures a minimal support for CPU hotplug e.g. when initiated by the NWd linux
1183b5dd2422SOlivier Deprez  userspace.
1184fcb1398fSOlivier Deprez
1185b5dd2422SOlivier DeprezSMMUv3 support in Hafnium
1186b5dd2422SOlivier Deprez=========================
11874ec3ccb4SMadhukar Pappireddy
11884ec3ccb4SMadhukar PappireddyAn SMMU is analogous to an MMU in a CPU. It performs address translations for
11894ec3ccb4SMadhukar PappireddyDirect Memory Access (DMA) requests from system I/O devices.
11904ec3ccb4SMadhukar PappireddyThe responsibilities of an SMMU include:
11914ec3ccb4SMadhukar Pappireddy
11924ec3ccb4SMadhukar Pappireddy-  Translation: Incoming DMA requests are translated from bus address space to
11934ec3ccb4SMadhukar Pappireddy   system physical address space using translation tables compliant to
11944ec3ccb4SMadhukar Pappireddy   Armv8/Armv7 VMSA descriptor format.
11954ec3ccb4SMadhukar Pappireddy-  Protection: An I/O device can be prohibited from read, write access to a
11964ec3ccb4SMadhukar Pappireddy   memory region or allowed.
11974ec3ccb4SMadhukar Pappireddy-  Isolation: Traffic from each individial device can be independently managed.
11984ec3ccb4SMadhukar Pappireddy   The devices are differentiated from each other using unique translation
11994ec3ccb4SMadhukar Pappireddy   tables.
12004ec3ccb4SMadhukar Pappireddy
12014ec3ccb4SMadhukar PappireddyThe following diagram illustrates a typical SMMU IP integrated in a SoC with
12024ec3ccb4SMadhukar Pappireddyseveral I/O devices along with Interconnect and Memory system.
12034ec3ccb4SMadhukar Pappireddy
12044ec3ccb4SMadhukar Pappireddy.. image:: ../resources/diagrams/MMU-600.png
12054ec3ccb4SMadhukar Pappireddy
12064ec3ccb4SMadhukar PappireddySMMU has several versions including SMMUv1, SMMUv2 and SMMUv3. Hafnium provides
1207b5dd2422SOlivier Deprezsupport for SMMUv3 driver in both normal and secure world. A brief introduction
12084ec3ccb4SMadhukar Pappireddyof SMMUv3 functionality and the corresponding software support in Hafnium is
12094ec3ccb4SMadhukar Pappireddyprovided here.
12104ec3ccb4SMadhukar Pappireddy
12114ec3ccb4SMadhukar PappireddySMMUv3 features
12124ec3ccb4SMadhukar Pappireddy---------------
12134ec3ccb4SMadhukar Pappireddy
12144ec3ccb4SMadhukar Pappireddy-  SMMUv3 provides Stage1, Stage2 translation as well as nested (Stage1 + Stage2)
12154ec3ccb4SMadhukar Pappireddy   translation support. It can either bypass or abort incoming translations as
12164ec3ccb4SMadhukar Pappireddy   well.
12174ec3ccb4SMadhukar Pappireddy-  Traffic (memory transactions) from each upstream I/O peripheral device,
12184ec3ccb4SMadhukar Pappireddy   referred to as Stream, can be independently managed using a combination of
12194ec3ccb4SMadhukar Pappireddy   several memory based configuration structures. This allows the SMMUv3 to
12204ec3ccb4SMadhukar Pappireddy   support a large number of streams with each stream assigned to a unique
12214ec3ccb4SMadhukar Pappireddy   translation context.
12224ec3ccb4SMadhukar Pappireddy-  Support for Armv8.1 VMSA where the SMMU shares the translation tables with
12234ec3ccb4SMadhukar Pappireddy   a Processing Element. AArch32(LPAE) and AArch64 translation table format
12244ec3ccb4SMadhukar Pappireddy   are supported by SMMUv3.
12254ec3ccb4SMadhukar Pappireddy-  SMMUv3 offers non-secure stream support with secure stream support being
12264ec3ccb4SMadhukar Pappireddy   optional. Logically, SMMUv3 behaves as if there is an indepdendent SMMU
12274ec3ccb4SMadhukar Pappireddy   instance for secure and non-secure stream support.
12284ec3ccb4SMadhukar Pappireddy-  It also supports sub-streams to differentiate traffic from a virtualized
12294ec3ccb4SMadhukar Pappireddy   peripheral associated with a VM/SP.
12304ec3ccb4SMadhukar Pappireddy-  Additionally, SMMUv3.2 provides support for PEs implementing Armv8.4-A
12314ec3ccb4SMadhukar Pappireddy   extensions. Consequently, SPM depends on Secure EL2 support in SMMUv3.2
12324ec3ccb4SMadhukar Pappireddy   for providing Secure Stage2 translation support to upstream peripheral
12334ec3ccb4SMadhukar Pappireddy   devices.
12344ec3ccb4SMadhukar Pappireddy
12354ec3ccb4SMadhukar PappireddySMMUv3 Programming Interfaces
12364ec3ccb4SMadhukar Pappireddy-----------------------------
12374ec3ccb4SMadhukar Pappireddy
12384ec3ccb4SMadhukar PappireddySMMUv3 has three software interfaces that are used by the Hafnium driver to
12394ec3ccb4SMadhukar Pappireddyconfigure the behaviour of SMMUv3 and manage the streams.
12404ec3ccb4SMadhukar Pappireddy
12414ec3ccb4SMadhukar Pappireddy-  Memory based data strutures that provide unique translation context for
12424ec3ccb4SMadhukar Pappireddy   each stream.
12434ec3ccb4SMadhukar Pappireddy-  Memory based circular buffers for command queue and event queue.
12444ec3ccb4SMadhukar Pappireddy-  A large number of SMMU configuration registers that are memory mapped during
12454ec3ccb4SMadhukar Pappireddy   boot time by Hafnium driver. Except a few registers, all configuration
12464ec3ccb4SMadhukar Pappireddy   registers have independent secure and non-secure versions to configure the
12474ec3ccb4SMadhukar Pappireddy   behaviour of SMMUv3 for translation of secure and non-secure streams
12484ec3ccb4SMadhukar Pappireddy   respectively.
12494ec3ccb4SMadhukar Pappireddy
12504ec3ccb4SMadhukar PappireddyPeripheral device manifest
12514ec3ccb4SMadhukar Pappireddy--------------------------
12524ec3ccb4SMadhukar Pappireddy
12534ec3ccb4SMadhukar PappireddyCurrently, SMMUv3 driver in Hafnium only supports dependent peripheral devices.
12544ec3ccb4SMadhukar PappireddyThese devices are dependent on PE endpoint to initiate and receive memory
12554ec3ccb4SMadhukar Pappireddymanagement transactions on their behalf. The acccess to the MMIO regions of
12564ec3ccb4SMadhukar Pappireddyany such device is assigned to the endpoint during boot. Moreover, SMMUv3 driver
12574ec3ccb4SMadhukar Pappireddyuses the same stage 2 translations for the device as those used by partition
12584ec3ccb4SMadhukar Pappireddymanager on behalf of the PE endpoint. This ensures that the peripheral device
12594ec3ccb4SMadhukar Pappireddyhas the same visibility of the physical address space as the endpoint. The
12604ec3ccb4SMadhukar Pappireddydevice node of the corresponding partition manifest (refer to `[1]`_ section 3.2
12614ec3ccb4SMadhukar Pappireddy) must specify these additional properties for each peripheral device in the
12624ec3ccb4SMadhukar Pappireddysystem :
12634ec3ccb4SMadhukar Pappireddy
12644ec3ccb4SMadhukar Pappireddy-  smmu-id: This field helps to identify the SMMU instance that this device is
12654ec3ccb4SMadhukar Pappireddy   upstream of.
12664ec3ccb4SMadhukar Pappireddy-  stream-ids: List of stream IDs assigned to this device.
12674ec3ccb4SMadhukar Pappireddy
12684ec3ccb4SMadhukar Pappireddy.. code:: shell
12694ec3ccb4SMadhukar Pappireddy
12704ec3ccb4SMadhukar Pappireddy    smmuv3-testengine {
12714ec3ccb4SMadhukar Pappireddy        base-address = <0x00000000 0x2bfe0000>;
12724ec3ccb4SMadhukar Pappireddy        pages-count = <32>;
12734ec3ccb4SMadhukar Pappireddy        attributes = <0x3>;
12744ec3ccb4SMadhukar Pappireddy        smmu-id = <0>;
12754ec3ccb4SMadhukar Pappireddy        stream-ids = <0x0 0x1>;
12764ec3ccb4SMadhukar Pappireddy        interrupts = <0x2 0x3>, <0x4 0x5>;
12774ec3ccb4SMadhukar Pappireddy        exclusive-access;
12784ec3ccb4SMadhukar Pappireddy    };
12794ec3ccb4SMadhukar Pappireddy
12804ec3ccb4SMadhukar PappireddySMMUv3 driver limitations
12814ec3ccb4SMadhukar Pappireddy-------------------------
12824ec3ccb4SMadhukar Pappireddy
12834ec3ccb4SMadhukar PappireddyThe primary design goal for the Hafnium SMMU driver is to support secure
12844ec3ccb4SMadhukar Pappireddystreams.
12854ec3ccb4SMadhukar Pappireddy
12864ec3ccb4SMadhukar Pappireddy-  Currently, the driver only supports Stage2 translations. No support for
12874ec3ccb4SMadhukar Pappireddy   Stage1 or nested translations.
12884ec3ccb4SMadhukar Pappireddy-  Supports only AArch64 translation format.
12894ec3ccb4SMadhukar Pappireddy-  No support for features such as PCI Express (PASIDs, ATS, PRI), MSI, RAS,
12904ec3ccb4SMadhukar Pappireddy   Fault handling, Performance Monitor Extensions, Event Handling, MPAM.
12914ec3ccb4SMadhukar Pappireddy-  No support for independent peripheral devices.
12924ec3ccb4SMadhukar Pappireddy
1293aeea04d4SRaghu KrishnamurthyS-EL0 Partition support
1294aeea04d4SRaghu Krishnamurthy=========================
1295aeea04d4SRaghu KrishnamurthyThe SPMC (Hafnium) has limited capability to run S-EL0 FF-A partitions using
1296aeea04d4SRaghu KrishnamurthyFEAT_VHE (mandatory with ARMv8.1 in non-secure state, and in secure world
1297aeea04d4SRaghu Krishnamurthywith ARMv8.4 and FEAT_SEL2).
1298aeea04d4SRaghu Krishnamurthy
1299aeea04d4SRaghu KrishnamurthyS-EL0 partitions are useful for simple partitions that don't require full
1300aeea04d4SRaghu KrishnamurthyTrusted OS functionality. It is also useful to reduce jitter and cycle
1301aeea04d4SRaghu Krishnamurthystealing from normal world since they are more lightweight than VMs.
1302aeea04d4SRaghu Krishnamurthy
1303aeea04d4SRaghu KrishnamurthyS-EL0 partitions are presented, loaded and initialized the same as S-EL1 VMs by
1304aeea04d4SRaghu Krishnamurthythe SPMC. They are differentiated primarily by the 'exception-level' property
1305aeea04d4SRaghu Krishnamurthyand the 'execution-ctx-count' property in the SP manifest. They are host apps
1306aeea04d4SRaghu Krishnamurthyunder the single EL2&0 Stage-1 translation regime controlled by the SPMC and
1307aeea04d4SRaghu Krishnamurthycall into the SPMC through SVCs as opposed to HVCs and SMCs. These partitions
1308aeea04d4SRaghu Krishnamurthycan use FF-A defined services (FFA_MEM_PERM_*) to update or change permissions
1309aeea04d4SRaghu Krishnamurthyfor memory regions.
1310aeea04d4SRaghu Krishnamurthy
1311aeea04d4SRaghu KrishnamurthyS-EL0 partitions are required by the FF-A specification to be UP endpoints,
1312aeea04d4SRaghu Krishnamurthycapable of migrating, and the SPMC enforces this requirement. The SPMC allows
1313aeea04d4SRaghu Krishnamurthya S-EL0 partition to accept a direct message from secure world and normal world,
1314aeea04d4SRaghu Krishnamurthyand generate direct responses to them.
1315aeea04d4SRaghu Krishnamurthy
1316aeea04d4SRaghu KrishnamurthyMemory sharing between and with S-EL0 partitions is supported.
1317aeea04d4SRaghu KrishnamurthyIndirect messaging, Interrupt handling and Notifications are not supported with
1318aeea04d4SRaghu KrishnamurthyS-EL0 partitions and is work in progress, planned for future releases.
1319aeea04d4SRaghu KrishnamurthyAll S-EL0 partitions must use AArch64. AArch32 S-EL0 partitions are not
1320aeea04d4SRaghu Krishnamurthysupported.
1321aeea04d4SRaghu Krishnamurthy
1322aeea04d4SRaghu Krishnamurthy
1323fcb1398fSOlivier DeprezReferences
1324fcb1398fSOlivier Deprez==========
1325fcb1398fSOlivier Deprez
1326fcb1398fSOlivier Deprez.. _[1]:
1327fcb1398fSOlivier Deprez
13288a5bd3cfSOlivier Deprez[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__
1329fcb1398fSOlivier Deprez
1330fcb1398fSOlivier Deprez.. _[2]:
1331fcb1398fSOlivier Deprez
13326844c347SMadhukar Pappireddy[2] :ref:`Secure Partition Manager using MM interface<Secure Partition Manager (MM)>`
1333fcb1398fSOlivier Deprez
1334fcb1398fSOlivier Deprez.. _[3]:
1335fcb1398fSOlivier Deprez
1336fcb1398fSOlivier Deprez[3] `Trusted Boot Board Requirements
1337b5dd2422SOlivier DeprezClient <https://developer.arm.com/documentation/den0006/d/>`__
1338fcb1398fSOlivier Deprez
1339fcb1398fSOlivier Deprez.. _[4]:
1340fcb1398fSOlivier Deprez
1341fcb1398fSOlivier Deprez[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/lib/el3_runtime/aarch64/context.S#n45
1342fcb1398fSOlivier Deprez
1343fcb1398fSOlivier Deprez.. _[5]:
1344fcb1398fSOlivier Deprez
1345b5dd2422SOlivier Deprez[5] https://git.trustedfirmware.org/TF-A/tf-a-tests.git/tree/spm/cactus/plat/arm/fvp/fdts/cactus.dts
1346fcb1398fSOlivier Deprez
1347fcb1398fSOlivier Deprez.. _[6]:
1348fcb1398fSOlivier Deprez
13491b17f4f1SOlivier Deprez[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html
1350fcb1398fSOlivier Deprez
1351fcb1398fSOlivier Deprez.. _[7]:
1352fcb1398fSOlivier Deprez
1353fcb1398fSOlivier Deprez[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_spmc_manifest.dts
1354fcb1398fSOlivier Deprez
1355fcb1398fSOlivier Deprez.. _[8]:
1356fcb1398fSOlivier Deprez
1357f4a55e6bSSandrine Bailleux[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/
1358fcb1398fSOlivier Deprez
1359f2dcf418SOlivier Deprez.. _[9]:
1360f2dcf418SOlivier Deprez
1361f2dcf418SOlivier Deprez[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot
1362f2dcf418SOlivier Deprez
1363fcb1398fSOlivier Deprez--------------
1364fcb1398fSOlivier Deprez
13655ac60ea1SImre Kis*Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.*
1366