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