xref: /rk3399_ARM-atf/docs/components/el3-spmc.rst (revision 77a53b8fe48a7c1d7c6927b30c21b6b467684661)
1*4090ac33SShruti GuptaEL3 Secure Partition Manager
2*4090ac33SShruti Gupta****************************
3*4090ac33SShruti Gupta
4*4090ac33SShruti Gupta.. contents::
5*4090ac33SShruti Gupta
6*4090ac33SShruti GuptaForeword
7*4090ac33SShruti Gupta========
8*4090ac33SShruti Gupta
9*4090ac33SShruti GuptaThis document describes the design of the EL3 SPMC based on the FF-A specification.
10*4090ac33SShruti GuptaEL3 SPMC provides reference FF-A compliant implementation without S-EL2 virtualization support,
11*4090ac33SShruti Guptato help adopt and migrate to FF-A early.
12*4090ac33SShruti GuptaEL3 SPMC implementation in TF-A:
13*4090ac33SShruti Gupta
14*4090ac33SShruti Gupta- Manages a single S-EL1 Secure Partition
15*4090ac33SShruti Gupta- Provides a standard protocol for communication and memory sharing between FF-A endpoints.
16*4090ac33SShruti Gupta- Provides support for EL3 Logical Partitions to support easy migration from EL3 to S-EL1.
17*4090ac33SShruti Gupta
18*4090ac33SShruti GuptaSample reference stack
19*4090ac33SShruti Gupta======================
20*4090ac33SShruti Gupta
21*4090ac33SShruti GuptaThe following diagram illustrates a possible configuration when the
22*4090ac33SShruti GuptaFEAT_SEL2 architecture extension is not implemented, showing the SPMD
23*4090ac33SShruti Guptaand SPMC at EL3, one S-EL1 secure partition, with an optional
24*4090ac33SShruti GuptaHypervisor:
25*4090ac33SShruti Gupta
26*4090ac33SShruti Gupta.. image:: ../resources/diagrams/ff-a-spm-at-el3.png
27*4090ac33SShruti Gupta
28*4090ac33SShruti GuptaTF-A build options
29*4090ac33SShruti Gupta==================
30*4090ac33SShruti Gupta
31*4090ac33SShruti GuptaThis section explains the TF-A build options involved in building
32*4090ac33SShruti Guptaan FF-A based SPM where the SPMD and SPMC are located at EL3:
33*4090ac33SShruti Gupta
34*4090ac33SShruti Gupta- **SPD=spmd**: this option selects the SPMD component to relay the FF-A
35*4090ac33SShruti Gupta  protocol from NWd to SWd back and forth. It is not possible to
36*4090ac33SShruti Gupta  enable another Secure Payload Dispatcher when this option is chosen.
37*4090ac33SShruti Gupta- **SPMC_AT_EL3**: this option adjusts the SPMC exception level to being
38*4090ac33SShruti Gupta  at EL3.
39*4090ac33SShruti Gupta- **ARM_SPMC_MANIFEST_DTS**: this option specifies a manifest file
40*4090ac33SShruti Gupta  providing SP description. It is required when
41*4090ac33SShruti Gupta  ``SPMC_AT_EL3`` is enabled, the secure partitions are loaded
42*4090ac33SShruti Gupta  by BL2 on behalf of the SPMC.
43*4090ac33SShruti Gupta
44*4090ac33SShruti GuptaNotes:
45*4090ac33SShruti Gupta
46*4090ac33SShruti Gupta- BL32 option is re-purposed to specify the S-EL1 TEE or SP image.
47*4090ac33SShruti Gupta  BL32 option can be omitted if using TF-A Test Secure Payload as SP.
48*4090ac33SShruti Gupta- BL33 option can specify the TFTF binary or a normal world loader
49*4090ac33SShruti Gupta  such as U-Boot or the UEFI framework payload.
50*4090ac33SShruti Gupta
51*4090ac33SShruti GuptaSample TF-A build command line when the SPMC is located at EL3:
52*4090ac33SShruti Gupta
53*4090ac33SShruti Gupta.. code:: shell
54*4090ac33SShruti Gupta
55*4090ac33SShruti Gupta    make \
56*4090ac33SShruti Gupta    CROSS_COMPILE=aarch64-none-elf- \
57*4090ac33SShruti Gupta    SPD=spmd \
58*4090ac33SShruti Gupta    SPMD_SPM_AT_SEL2=0 \
59*4090ac33SShruti Gupta    SPMC_AT_EL3=1 \
60*4090ac33SShruti Gupta    BL32=<path-to-tee-binary> (opt for TSP) \
61*4090ac33SShruti Gupta    BL33=<path-to-bl33-binary> \
62*4090ac33SShruti Gupta    PLAT=fvp \
63*4090ac33SShruti Gupta    all fip
64*4090ac33SShruti Gupta
65*4090ac33SShruti GuptaFVP model invocation
66*4090ac33SShruti Gupta====================
67*4090ac33SShruti Gupta
68*4090ac33SShruti GuptaSample FVP command line invocation:
69*4090ac33SShruti Gupta
70*4090ac33SShruti Gupta.. code:: shell
71*4090ac33SShruti Gupta
72*4090ac33SShruti Gupta    <path-to-fvp-model>/FVP_Base_RevC-2xAEMvA -C pctl.startup=0.0.0.0 \
73*4090ac33SShruti Gupta    -C cluster0.NUM_CORES=4 -C cluster1.NUM_CORES=4 -C bp.secure_memory=1 \
74*4090ac33SShruti Gupta    -C bp.secureflashloader.fname=trusted-firmware-a/build/fvp/debug/bl1.bin \
75*4090ac33SShruti Gupta    -C bp.flashloader0.fname=trusted-firmware-a/build/fvp/debug/fip.bin \
76*4090ac33SShruti Gupta    -C bp.pl011_uart0.out_file=fvp-uart0.log -C bp.pl011_uart1.out_file=fvp-uart1.log \
77*4090ac33SShruti Gupta    -C bp.pl011_uart2.out_file=fvp-uart2.log -C bp.vis.disable_visualisation=1
78*4090ac33SShruti Gupta
79*4090ac33SShruti Gupta
80*4090ac33SShruti GuptaPlatform Guide
81*4090ac33SShruti Gupta==============
82*4090ac33SShruti Gupta
83*4090ac33SShruti Gupta- Platform Hooks  See - `[4]`_
84*4090ac33SShruti Gupta
85*4090ac33SShruti Gupta  - plat_spmc_shmem_begin
86*4090ac33SShruti Gupta  - plat_spmc_shmem_reclaim
87*4090ac33SShruti Gupta
88*4090ac33SShruti GuptaSPMC provides platform hooks related to memory management interfaces.
89*4090ac33SShruti GuptaThese hooks can be used for platform specific implementations like
90*4090ac33SShruti Guptafor managing access control, programming TZ Controller or MPUs.
91*4090ac33SShruti GuptaThese hooks are called by SPMC before the initial share request completes,
92*4090ac33SShruti Guptaand after the final reclaim has been completed.
93*4090ac33SShruti Gupta
94*4090ac33SShruti Gupta- Datastore
95*4090ac33SShruti Gupta
96*4090ac33SShruti Gupta  - plat_spmc_shmem_datastore_get
97*4090ac33SShruti Gupta
98*4090ac33SShruti Gupta    EL3 SPMC uses datastore for tracking memory transaction descriptors.
99*4090ac33SShruti Gupta    On FVP platform datastore is allocated from TZC DRAM section.
100*4090ac33SShruti Gupta    Other platforms need to allocate a similar secure memory region
101*4090ac33SShruti Gupta    to be used as shared memory datastore.
102*4090ac33SShruti Gupta
103*4090ac33SShruti Gupta    The accessor function is used during SPMC initialization to obtain
104*4090ac33SShruti Gupta    address and size of the datastore.
105*4090ac33SShruti Gupta    SPMC will also zero out the provided memory region.
106*4090ac33SShruti Gupta
107*4090ac33SShruti Gupta- Platform Defines See - `[5]`_
108*4090ac33SShruti Gupta
109*4090ac33SShruti Gupta  - SECURE_PARTITION_COUNT
110*4090ac33SShruti Gupta    Number of Secure Partitions supported: must be 1.
111*4090ac33SShruti Gupta
112*4090ac33SShruti Gupta  - NS_PARTITION_COUNT
113*4090ac33SShruti Gupta    Number of NWd Partitions supported.
114*4090ac33SShruti Gupta
115*4090ac33SShruti Gupta  - MAX_EL3_LP_DESCS_COUNT
116*4090ac33SShruti Gupta    Number of Logical Partitions supported.
117*4090ac33SShruti Gupta
118*4090ac33SShruti GuptaLogical Secure Partition (LSP)
119*4090ac33SShruti Gupta==============================
120*4090ac33SShruti Gupta
121*4090ac33SShruti Gupta- The SPMC provides support for statically allocated EL3 Logical Secure Partitions
122*4090ac33SShruti Gupta  as per FF-A v1.1 specification.
123*4090ac33SShruti Gupta- The DECLARE_LOGICAL_PARTITION macro can be used to add a LSP.
124*4090ac33SShruti Gupta- For reference implementation See - `[2]`_
125*4090ac33SShruti Gupta
126*4090ac33SShruti Gupta.. image:: ../resources/diagrams/ff-a-lsp-at-el3.png
127*4090ac33SShruti Gupta
128*4090ac33SShruti GuptaSPMC boot
129*4090ac33SShruti Gupta=========
130*4090ac33SShruti Gupta
131*4090ac33SShruti GuptaThe SPMD and SPMC are built into the BL31 image along with TF-A's runtime components.
132*4090ac33SShruti GuptaBL2 loads the BL31 image as a part of (secure) boot process.
133*4090ac33SShruti Gupta
134*4090ac33SShruti GuptaThe SPMC manifest is loaded by BL2 as the ``TOS_FW_CONFIG`` image `[9]`_.
135*4090ac33SShruti Gupta
136*4090ac33SShruti GuptaBL2 passes the SPMC manifest address to BL31 through a register.
137*4090ac33SShruti Gupta
138*4090ac33SShruti GuptaAt boot time, the SPMD in BL31 runs from the primary core, initializes the core
139*4090ac33SShruti Guptacontexts and launches the SPMC passing the following information through
140*4090ac33SShruti Guptaregisters:
141*4090ac33SShruti Gupta
142*4090ac33SShruti Gupta- X0 holds the SPMC manifest blob address.
143*4090ac33SShruti Gupta- X4 holds the currently running core linear id.
144*4090ac33SShruti Gupta
145*4090ac33SShruti GuptaParsing SP partition manifests
146*4090ac33SShruti Gupta------------------------------
147*4090ac33SShruti Gupta
148*4090ac33SShruti GuptaSPMC consumes the SP manifest, as defined in `[7]`_.
149*4090ac33SShruti GuptaSP manifest fields align with Hafnium SP manifest for easy porting.
150*4090ac33SShruti Gupta
151*4090ac33SShruti Gupta.. code:: shell
152*4090ac33SShruti Gupta
153*4090ac33SShruti Gupta	compatible = "arm,ffa-manifest-1.0";
154*4090ac33SShruti Gupta
155*4090ac33SShruti Gupta	ffa-version = <0x00010001>; /* 31:16 - Major, 15:0 - Minor */
156*4090ac33SShruti Gupta	id = <0x8001>;
157*4090ac33SShruti Gupta	uuid = <0x6b43b460 0x74a24b78 0xade24502 0x40682886>;
158*4090ac33SShruti Gupta	messaging-method = <0x3>; /* Direct Messaging Only */
159*4090ac33SShruti Gupta	exception-level = <0x2>;  /* S-EL1 */
160*4090ac33SShruti Gupta	execution-state = <0>;
161*4090ac33SShruti Gupta	execution-ctx-count = <8>;
162*4090ac33SShruti Gupta	gp-register-num = <0>;
163*4090ac33SShruti Gupta	power-management-messages = <0x7>;
164*4090ac33SShruti Gupta
165*4090ac33SShruti Gupta
166*4090ac33SShruti GuptaPassing boot data to the SP
167*4090ac33SShruti Gupta---------------------------
168*4090ac33SShruti Gupta
169*4090ac33SShruti GuptaIn `[1]`_ , the section  "Boot information protocol" defines a method for passing
170*4090ac33SShruti Guptadata to the SPs at boot time. It specifies the format for the boot information
171*4090ac33SShruti Guptadescriptor and boot information header structures, which describe the data to be
172*4090ac33SShruti Guptaexchanged between SPMC and SP.
173*4090ac33SShruti GuptaThe specification also defines the types of data that can be passed.
174*4090ac33SShruti GuptaThe aggregate of both the boot info structures and the data itself is designated
175*4090ac33SShruti Guptathe boot information blob, and is passed to a Partition as a contiguous memory
176*4090ac33SShruti Guptaregion.
177*4090ac33SShruti Gupta
178*4090ac33SShruti GuptaCurrently, the SPM implementation supports the FDT type which is used to pass the
179*4090ac33SShruti Guptapartition's DTB manifest.
180*4090ac33SShruti Gupta
181*4090ac33SShruti GuptaThe region for the boot information blob is statically allocated (4K) by SPMC.
182*4090ac33SShruti GuptaBLOB contains Boot Info Header, followed by SP Manifest contents.
183*4090ac33SShruti Gupta
184*4090ac33SShruti GuptaThe configuration of the boot protocol is done in the SP manifest. As defined by
185*4090ac33SShruti Guptathe specification, the manifest field 'gp-register-num' configures the GP register
186*4090ac33SShruti Guptawhich shall be used to pass the address to the partitions boot information blob when
187*4090ac33SShruti Guptabooting the partition.
188*4090ac33SShruti Gupta
189*4090ac33SShruti GuptaSupported interfaces
190*4090ac33SShruti Gupta====================
191*4090ac33SShruti Gupta
192*4090ac33SShruti GuptaThe following interfaces are exposed to SPs only:
193*4090ac33SShruti Gupta
194*4090ac33SShruti Gupta-  ``FFA_MSG_WAIT``
195*4090ac33SShruti Gupta-  ``FFA_MEM_RETRIEVE_REQ``
196*4090ac33SShruti Gupta-  ``FFA_MEM_RETRIEVE_RESP``
197*4090ac33SShruti Gupta-  ``FFA_MEM_RELINQUISH``
198*4090ac33SShruti Gupta-  ``FFA_SECONDARY_EP_REGISTER``
199*4090ac33SShruti Gupta
200*4090ac33SShruti GuptaThe following interfaces are exposed to both NS Client and SPs:
201*4090ac33SShruti Gupta
202*4090ac33SShruti Gupta-  ``FFA_VERSION``
203*4090ac33SShruti Gupta-  ``FFA_FEATURES``
204*4090ac33SShruti Gupta-  ``FFA_RX_RELEASE``
205*4090ac33SShruti Gupta-  ``FFA_RXTX_MAP``
206*4090ac33SShruti Gupta-  ``FFA_RXTX_UNMAP``
207*4090ac33SShruti Gupta-  ``FFA_PARTITION_INFO_GET``
208*4090ac33SShruti Gupta-  ``FFA_ID_GET``
209*4090ac33SShruti Gupta-  ``FFA_MSG_SEND_DIRECT_REQ``
210*4090ac33SShruti Gupta-  ``FFA_MSG_SEND_DIRECT_RESP``
211*4090ac33SShruti Gupta-  ``FFA_MEM_FRAG_TX``
212*4090ac33SShruti Gupta-  ``FFA_SPM_ID_GET``
213*4090ac33SShruti Gupta
214*4090ac33SShruti GuptaThe following additional interfaces are forwarded from SPMD to support NS Client:
215*4090ac33SShruti Gupta
216*4090ac33SShruti Gupta-  ``FFA_RUN``
217*4090ac33SShruti Gupta-  ``FFA_MEM_LEND``
218*4090ac33SShruti Gupta-  ``FFA_MEM_SHARE``
219*4090ac33SShruti Gupta-  ``FFA_MEM_FRAG_RX``
220*4090ac33SShruti Gupta-  ``FFA_MEM_RECLAIM``
221*4090ac33SShruti Gupta
222*4090ac33SShruti Gupta
223*4090ac33SShruti GuptaFFA_VERSION
224*4090ac33SShruti Gupta-----------
225*4090ac33SShruti Gupta
226*4090ac33SShruti Gupta``FFA_VERSION`` requires a *requested_version* parameter from the caller.
227*4090ac33SShruti GuptaSPMD forwards call to SPMC, the SPMC returns its own implemented version.
228*4090ac33SShruti GuptaSPMC asserts SP and SPMC are at same FF-A Version.
229*4090ac33SShruti Gupta
230*4090ac33SShruti GuptaFFA_FEATURES
231*4090ac33SShruti Gupta------------
232*4090ac33SShruti Gupta
233*4090ac33SShruti GuptaFF-A features supported by the SPMC may be discovered by secure partitions at
234*4090ac33SShruti Guptaboot (that is prior to NWd is booted) or run-time.
235*4090ac33SShruti Gupta
236*4090ac33SShruti GuptaThe SPMC calling FFA_FEATURES at secure physical FF-A instance always get
237*4090ac33SShruti GuptaFFA_SUCCESS from the SPMD.
238*4090ac33SShruti Gupta
239*4090ac33SShruti GuptaThe request made by an Hypervisor or OS kernel is forwarded to the SPMC and
240*4090ac33SShruti Guptathe response relayed back to the NWd.
241*4090ac33SShruti Gupta
242*4090ac33SShruti Gupta
243*4090ac33SShruti GuptaFFA_RXTX_MAP
244*4090ac33SShruti Gupta------------
245*4090ac33SShruti Gupta
246*4090ac33SShruti GuptaFFA_RXTX_UNMAP
247*4090ac33SShruti Gupta--------------
248*4090ac33SShruti Gupta
249*4090ac33SShruti GuptaWhen invoked from a secure partition FFA_RXTX_MAP maps the provided send and
250*4090ac33SShruti Guptareceive buffers described by their PAs to the EL3 translation regime
251*4090ac33SShruti Guptaas secure buffers in the MMU descriptors.
252*4090ac33SShruti Gupta
253*4090ac33SShruti GuptaWhen invoked from the Hypervisor or OS kernel, the buffers are mapped into the
254*4090ac33SShruti GuptaSPMC EL3 translation regime and marked as NS buffers in the MMU
255*4090ac33SShruti Guptadescriptors.
256*4090ac33SShruti Gupta
257*4090ac33SShruti GuptaThe FFA_RXTX_UNMAP unmaps the RX/TX pair from the translation regime of the
258*4090ac33SShruti Guptacaller, either it being the Hypervisor or OS kernel, as well as a secure
259*4090ac33SShruti Guptapartition.
260*4090ac33SShruti Gupta
261*4090ac33SShruti GuptaFFA_PARTITION_INFO_GET
262*4090ac33SShruti Gupta----------------------
263*4090ac33SShruti Gupta
264*4090ac33SShruti GuptaPartition info get call can originate:
265*4090ac33SShruti Gupta
266*4090ac33SShruti Gupta- from SP to SPMC
267*4090ac33SShruti Gupta- from Hypervisor or OS kernel to SPMC. The request is relayed by the SPMD.
268*4090ac33SShruti Gupta
269*4090ac33SShruti GuptaThe format (v1.0 or v1.1) of the populated data structure returned is based upon the
270*4090ac33SShruti GuptaFFA version of the calling entity.
271*4090ac33SShruti Gupta
272*4090ac33SShruti GuptaEL3 SPMC also supports returning only the count of partitions deployed.
273*4090ac33SShruti Gupta
274*4090ac33SShruti GuptaAll LSPs and SP are discoverable from FFA_PARTITION_INFO_GET call made by
275*4090ac33SShruti Guptaeither SP or NWd entities.
276*4090ac33SShruti Gupta
277*4090ac33SShruti GuptaFFA_ID_GET
278*4090ac33SShruti Gupta----------
279*4090ac33SShruti Gupta
280*4090ac33SShruti GuptaThe FF-A ID space is split into a non-secure space and secure space:
281*4090ac33SShruti Gupta
282*4090ac33SShruti Gupta- FF-A ID with bit 15 clear relates to VMs.
283*4090ac33SShruti Gupta- FF-A ID with bit 15 set related to SPs or LSPs.
284*4090ac33SShruti Gupta- FF-A IDs 0, 0xffff, 0x8000 are assigned respectively to the Hypervisor
285*4090ac33SShruti Gupta  (or OS Kernel if Hyp is absent), SPMD and SPMC.
286*4090ac33SShruti Gupta
287*4090ac33SShruti GuptaThis convention helps the SPM to determine the origin and destination worlds in
288*4090ac33SShruti Guptaan FF-A ABI invocation. In particular the SPM shall filter unauthorized
289*4090ac33SShruti Guptatransactions in its world switch routine. It must not be permitted for a VM to
290*4090ac33SShruti Guptause a secure FF-A ID as origin world by spoofing:
291*4090ac33SShruti Gupta
292*4090ac33SShruti Gupta- A VM-to-SP direct request/response shall set the origin world to be non-secure
293*4090ac33SShruti Gupta  (FF-A ID bit 15 clear) and destination world to be secure (FF-A ID bit 15
294*4090ac33SShruti Gupta  set).
295*4090ac33SShruti Gupta- Similarly, an SP-to-LSP direct request/response shall set the FF-A ID bit 15
296*4090ac33SShruti Gupta  for both origin and destination IDs.
297*4090ac33SShruti Gupta
298*4090ac33SShruti GuptaAn incoming direct message request arriving at SPMD from NWd is forwarded to
299*4090ac33SShruti GuptaSPMC without a specific check. The SPMC is resumed through eret and "knows" the
300*4090ac33SShruti Guptamessage is coming from normal world in this specific code path. Thus the origin
301*4090ac33SShruti Guptaendpoint ID must be checked by SPMC for being a normal world ID.
302*4090ac33SShruti Gupta
303*4090ac33SShruti GuptaAn SP sending a direct message request must have bit 15 set in its origin
304*4090ac33SShruti Guptaendpoint ID and this can be checked by the SPMC when the SP invokes the ABI.
305*4090ac33SShruti Gupta
306*4090ac33SShruti GuptaThe SPMC shall reject the direct message if the claimed world in origin endpoint
307*4090ac33SShruti GuptaID is not consistent:
308*4090ac33SShruti Gupta
309*4090ac33SShruti Gupta-  It is either forwarded by SPMD and thus origin endpoint ID must be a "normal
310*4090ac33SShruti Gupta   world ID",
311*4090ac33SShruti Gupta-  or initiated by an SP and thus origin endpoint ID must be a "secure world ID".
312*4090ac33SShruti Gupta
313*4090ac33SShruti Gupta
314*4090ac33SShruti GuptaFFA_MSG_SEND_DIRECT_REQ
315*4090ac33SShruti Gupta-----------------------
316*4090ac33SShruti Gupta
317*4090ac33SShruti GuptaFFA_MSG_SEND_DIRECT_RESP
318*4090ac33SShruti Gupta------------------------
319*4090ac33SShruti Gupta
320*4090ac33SShruti GuptaThis is a mandatory interface for secure partitions participating in direct request
321*4090ac33SShruti Guptaand responses with the following rules:
322*4090ac33SShruti Gupta
323*4090ac33SShruti Gupta- An SP can send a direct request to LSP.
324*4090ac33SShruti Gupta- An LSP can send a direct response to SP.
325*4090ac33SShruti Gupta- An SP cannot send a direct request to an Hypervisor or OS kernel.
326*4090ac33SShruti Gupta- An Hypervisor or OS kernel can send a direct request to an SP or LSP.
327*4090ac33SShruti Gupta- An SP and LSP can send a direct response to an Hypervisor or OS kernel.
328*4090ac33SShruti Gupta- SPMD can send direct request to SPMC.
329*4090ac33SShruti Gupta
330*4090ac33SShruti GuptaFFA_SPM_ID_GET
331*4090ac33SShruti Gupta--------------
332*4090ac33SShruti Gupta
333*4090ac33SShruti GuptaReturns the FF-A ID allocated to an SPM component which can be one of SPMD
334*4090ac33SShruti Guptaor SPMC.
335*4090ac33SShruti Gupta
336*4090ac33SShruti GuptaAt initialization, the SPMC queries the SPMD for the SPMC ID, using the
337*4090ac33SShruti GuptaFFA_ID_GET interface, and records it. The SPMC can also query the SPMD ID using
338*4090ac33SShruti Guptathe FFA_SPM_ID_GET interface at the secure physical FF-A instance.
339*4090ac33SShruti Gupta
340*4090ac33SShruti GuptaSecure partitions call this interface at the virtual FF-A instance, to which
341*4090ac33SShruti Guptathe SPMC returns the SPMC ID.
342*4090ac33SShruti Gupta
343*4090ac33SShruti GuptaThe Hypervisor or OS kernel can issue the FFA_SPM_ID_GET call handled by the
344*4090ac33SShruti GuptaSPMD, which returns the SPMC ID.
345*4090ac33SShruti Gupta
346*4090ac33SShruti GuptaFFA_ID_GET
347*4090ac33SShruti Gupta----------
348*4090ac33SShruti Gupta
349*4090ac33SShruti GuptaReturns the FF-A ID of the calling endpoint.
350*4090ac33SShruti Gupta
351*4090ac33SShruti GuptaFFA_MEM_SHARE
352*4090ac33SShruti Gupta-------------
353*4090ac33SShruti Gupta
354*4090ac33SShruti GuptaFFA_MEM_LEND
355*4090ac33SShruti Gupta------------
356*4090ac33SShruti Gupta
357*4090ac33SShruti Gupta- If SP is borrower in the memory transaction, these calls are forwarded to SPMC.
358*4090ac33SShruti Gupta  SPMC performs Relayer responsibilities, caches the memory descriptors in the datastore,
359*4090ac33SShruti Gupta  and allocates FF-A memory handle.
360*4090ac33SShruti Gupta- If format of descriptor was v1.0, SPMC converts the descriptor to v1.1 before caching.
361*4090ac33SShruti Gupta  In case of fragmented sharing, conversion of memory descriptors happens after last
362*4090ac33SShruti Gupta  fragment has been received.
363*4090ac33SShruti Gupta- Multiple borrowers (including NWd endpoint) and fragmented memory sharing are supported.
364*4090ac33SShruti Gupta
365*4090ac33SShruti GuptaFFA_MEM_RETRIEVE_REQ
366*4090ac33SShruti Gupta--------------------
367*4090ac33SShruti Gupta
368*4090ac33SShruti GuptaFFA_MEM_RETRIEVE_RESP
369*4090ac33SShruti Gupta---------------------
370*4090ac33SShruti Gupta
371*4090ac33SShruti Gupta- Memory retrieve is supported only from SP.
372*4090ac33SShruti Gupta- SPMC fetches the cached memory descriptor from the datastore,
373*4090ac33SShruti Gupta- Performs Relayer responsiilities and sends FFA_MEM_RETRIEVE_RESP back to SP.
374*4090ac33SShruti Gupta- If descriptor size is more than RX buffer size, SPMC will send the descriptor in fragments.
375*4090ac33SShruti Gupta- SPMC will set NS Bit to 1 in memory descriptor response.
376*4090ac33SShruti Gupta
377*4090ac33SShruti GuptaFFA_MEM_FRAG_RX
378*4090ac33SShruti Gupta---------------
379*4090ac33SShruti Gupta
380*4090ac33SShruti GuptaFFA_MEM_FRAG_TX
381*4090ac33SShruti Gupta---------------
382*4090ac33SShruti Gupta
383*4090ac33SShruti GuptaFFA_MEM_FRAG_RX is to be used by:
384*4090ac33SShruti Gupta
385*4090ac33SShruti Gupta- SP if FFA_MEM_RETRIEVE_RESP returned descriptor with fragment length less than total length.
386*4090ac33SShruti Gupta- or by SPMC if FFA_MEM_SHARE/FFA_MEM_LEND is called with fragment length less than total length.
387*4090ac33SShruti Gupta
388*4090ac33SShruti GuptaSPMC validates handle and Endpoint ID and returns response with FFA_MEM_FRAG_TX.
389*4090ac33SShruti Gupta
390*4090ac33SShruti GuptaFFA_SECONDARY_EP_REGISTER
391*4090ac33SShruti Gupta-------------------------
392*4090ac33SShruti Gupta
393*4090ac33SShruti GuptaWhen the SPMC boots, secure partition is initialized on its primary
394*4090ac33SShruti GuptaExecution Context.
395*4090ac33SShruti Gupta
396*4090ac33SShruti GuptaThe FFA_SECONDARY_EP_REGISTER interface is to be used by a secure partition
397*4090ac33SShruti Guptafrom its first execution context, to provide the entry point address for
398*4090ac33SShruti Guptasecondary execution contexts.
399*4090ac33SShruti Gupta
400*4090ac33SShruti GuptaA secondary EC is first resumed either upon invocation of PSCI_CPU_ON from
401*4090ac33SShruti Guptathe NWd or by invocation of FFA_RUN.
402*4090ac33SShruti Gupta
403*4090ac33SShruti GuptaPower management
404*4090ac33SShruti Gupta================
405*4090ac33SShruti Gupta
406*4090ac33SShruti GuptaIn platforms with or without secure virtualization:
407*4090ac33SShruti Gupta
408*4090ac33SShruti Gupta- The NWd owns the platform PM policy.
409*4090ac33SShruti Gupta- The Hypervisor or OS kernel is the component initiating PSCI service calls.
410*4090ac33SShruti Gupta- The EL3 PSCI library is in charge of the PM coordination and control
411*4090ac33SShruti Gupta  (eventually writing to platform registers).
412*4090ac33SShruti Gupta- While coordinating PM events, the PSCI library calls backs into the Secure
413*4090ac33SShruti Gupta  Payload Dispatcher for events the latter has statically registered to.
414*4090ac33SShruti Gupta
415*4090ac33SShruti GuptaWhen using the SPMD as a Secure Payload Dispatcher:
416*4090ac33SShruti Gupta
417*4090ac33SShruti Gupta- A power management event is relayed through the SPD hook to the SPMC.
418*4090ac33SShruti Gupta- In the current implementation CPU_ON (svc_on_finish), CPU_OFF
419*4090ac33SShruti Gupta  (svc_off), CPU_SUSPEND (svc_suspend) and CPU_SUSPEND_RESUME (svc_suspend_finish)
420*4090ac33SShruti Gupta  hooks are registered.
421*4090ac33SShruti Gupta
422*4090ac33SShruti GuptaSecure partitions scheduling
423*4090ac33SShruti Gupta============================
424*4090ac33SShruti Gupta
425*4090ac33SShruti GuptaThe FF-A specification `[1]`_ provides two ways to relinquinsh CPU time to
426*4090ac33SShruti Guptasecure partitions. For this a VM (Hypervisor or OS kernel), or SP invokes one of:
427*4090ac33SShruti Gupta
428*4090ac33SShruti Gupta- the FFA_MSG_SEND_DIRECT_REQ interface.
429*4090ac33SShruti Gupta- the FFA_RUN interface.
430*4090ac33SShruti Gupta
431*4090ac33SShruti GuptaAdditionally a secure interrupt can pre-empt the normal world execution and give
432*4090ac33SShruti GuptaCPU cycles by transitioning to EL3.
433*4090ac33SShruti Gupta
434*4090ac33SShruti GuptaPartition Runtime State and Model
435*4090ac33SShruti Gupta=================================
436*4090ac33SShruti Gupta
437*4090ac33SShruti GuptaEL3 SPMC implements Partition runtime states are described in v1.1 FF-A specification `[1]`_
438*4090ac33SShruti Gupta
439*4090ac33SShruti GuptaAn SP can be in one of the following state:
440*4090ac33SShruti Gupta
441*4090ac33SShruti Gupta- RT_STATE_WAITING
442*4090ac33SShruti Gupta- RT_STATE_RUNNING
443*4090ac33SShruti Gupta- RT_STATE_PREEMPTED
444*4090ac33SShruti Gupta- RT_STATE_BLOCKED
445*4090ac33SShruti Gupta
446*4090ac33SShruti GuptaAn SP will transition to one of the following runtime model when not in waiting state:
447*4090ac33SShruti Gupta
448*4090ac33SShruti Gupta- RT_MODEL_DIR_REQ
449*4090ac33SShruti Gupta- RT_MODEL_RUN
450*4090ac33SShruti Gupta- RT_MODEL_INIT
451*4090ac33SShruti Gupta- RT_MODEL_INTR
452*4090ac33SShruti Gupta
453*4090ac33SShruti GuptaPlatform topology
454*4090ac33SShruti Gupta=================
455*4090ac33SShruti Gupta
456*4090ac33SShruti GuptaSPMC only supports a single Pinned MP S-EL1 SP. The *execution-ctx-count*
457*4090ac33SShruti GuptaSP manifest field should match the number of physical PE.
458*4090ac33SShruti Gupta
459*4090ac33SShruti GuptaInterrupt handling
460*4090ac33SShruti Gupta==================
461*4090ac33SShruti Gupta
462*4090ac33SShruti GuptaSecure Interrupt handling
463*4090ac33SShruti Gupta-------------------------
464*4090ac33SShruti Gupta
465*4090ac33SShruti Gupta- SPMC is capable of forwarding Secure interrupt to S-EL1 SP
466*4090ac33SShruti Gupta  which has preempted the normal world.
467*4090ac33SShruti Gupta- Interrupt is forwarded to SP using FFA_INTERRUPT interface.
468*4090ac33SShruti Gupta- Interrupt Number is not passed, S-EL1 SP can access the GIC registers directly.
469*4090ac33SShruti Gupta- Upon completion of Interrupt handling SP is expected to return to
470*4090ac33SShruti Gupta  SPMC using FFA_MSG_WAIT interface.
471*4090ac33SShruti Gupta- SPMC returns to normal world after interrupt handling is completed.
472*4090ac33SShruti Gupta
473*4090ac33SShruti GuptaIn the scenario when secure interrupt occurs while the secure partition is running,
474*4090ac33SShruti Guptathe SPMC is not involved and the handling is implementation defined in the TOS.
475*4090ac33SShruti Gupta
476*4090ac33SShruti GuptaNon-Secure Interrupt handling
477*4090ac33SShruti Gupta-----------------------------
478*4090ac33SShruti Gupta
479*4090ac33SShruti GuptaThe 'managed exit' scenario is the responsibility of the TOS and the SPMC is not involved.
480*4090ac33SShruti Gupta
481*4090ac33SShruti GuptaTest Secure Payload (TSP)
482*4090ac33SShruti Gupta=========================
483*4090ac33SShruti Gupta
484*4090ac33SShruti Gupta- TSP provides reference implementation of FF-A programming model.
485*4090ac33SShruti Gupta- TSP has the following support:
486*4090ac33SShruti Gupta
487*4090ac33SShruti Gupta  - SP initialization on all CPUs.
488*4090ac33SShruti Gupta  - Consuming Power Messages including CPU_ON, CPU_OFF, CPU_SUSPEND, CPU_SUSPEND_RESUME.
489*4090ac33SShruti Gupta  - Event Loop to receive Direct Requests.
490*4090ac33SShruti Gupta  - Sending Direct Response.
491*4090ac33SShruti Gupta  - Memory Sharing helper library.
492*4090ac33SShruti Gupta  - Ability to handle secure interrupt (timer).
493*4090ac33SShruti Gupta
494*4090ac33SShruti GuptaTSP Tests in CI
495*4090ac33SShruti Gupta---------------
496*4090ac33SShruti Gupta
497*4090ac33SShruti Gupta- TSP Tests are exercised in the TF-A CI using prebuilt FF-A Linux Test driver in NWd.
498*4090ac33SShruti Gupta- Expected output:
499*4090ac33SShruti Gupta
500*4090ac33SShruti Gupta.. code:: shell
501*4090ac33SShruti Gupta
502*4090ac33SShruti Gupta        #ioctl 255
503*4090ac33SShruti Gupta        Test: Echo Message to SP.
504*4090ac33SShruti Gupta        Status: Completed Test Case: 1
505*4090ac33SShruti Gupta        Test Executed Successfully
506*4090ac33SShruti Gupta
507*4090ac33SShruti Gupta        Test: Message Relay vis SP to EL3 LSP.
508*4090ac33SShruti Gupta        Status: Completed Test Case: 2
509*4090ac33SShruti Gupta        Test Executed Successfully
510*4090ac33SShruti Gupta
511*4090ac33SShruti Gupta        Test: Memory Send.
512*4090ac33SShruti Gupta        Verified 1 constituents successfully
513*4090ac33SShruti Gupta        Status: Completed Test Case: 3
514*4090ac33SShruti Gupta        Test Executed Successfully
515*4090ac33SShruti Gupta
516*4090ac33SShruti Gupta        Test: Memory Send in Fragments.
517*4090ac33SShruti Gupta        Verified 256 constituents successfully
518*4090ac33SShruti Gupta        Status: Completed Test Case: 4
519*4090ac33SShruti Gupta        Test Executed Successfully
520*4090ac33SShruti Gupta
521*4090ac33SShruti Gupta        Test: Memory Lend.
522*4090ac33SShruti Gupta        Verified 1 constituents successfully
523*4090ac33SShruti Gupta        Status: Completed Test Case: 5
524*4090ac33SShruti Gupta        Test Executed Successfully
525*4090ac33SShruti Gupta
526*4090ac33SShruti Gupta        Test: Memory Lend in Fragments.
527*4090ac33SShruti Gupta        Verified 256 constituents successfully
528*4090ac33SShruti Gupta        Status: Completed Test Case: 6
529*4090ac33SShruti Gupta        Test Executed Successfully
530*4090ac33SShruti Gupta
531*4090ac33SShruti Gupta        Test: Memory Send with Multiple Endpoints.
532*4090ac33SShruti Gupta        random: fast init done
533*4090ac33SShruti Gupta        Verified 256 constituents successfully
534*4090ac33SShruti Gupta        Status: Completed Test Case: 7
535*4090ac33SShruti Gupta        Test Executed Successfully
536*4090ac33SShruti Gupta
537*4090ac33SShruti Gupta        Test: Memory Lend with Multiple Endpoints.
538*4090ac33SShruti Gupta        Verified 256 constituents successfully
539*4090ac33SShruti Gupta        Status: Completed Test Case: 8
540*4090ac33SShruti Gupta        Test Executed Successfully
541*4090ac33SShruti Gupta
542*4090ac33SShruti Gupta        Test: Ensure Duplicate Memory Send Requests are Rejected.
543*4090ac33SShruti Gupta        Status: Completed Test Case: 9
544*4090ac33SShruti Gupta        Test Executed Successfully
545*4090ac33SShruti Gupta
546*4090ac33SShruti Gupta        Test: Ensure Duplicate Memory Lend Requests are Rejected.
547*4090ac33SShruti Gupta        Status: Completed Test Case: 10
548*4090ac33SShruti Gupta        Test Executed Successfully
549*4090ac33SShruti Gupta
550*4090ac33SShruti Gupta        0 Tests Failed
551*4090ac33SShruti Gupta
552*4090ac33SShruti Gupta        Exiting Test Application -  Total Failures: 0
553*4090ac33SShruti Gupta
554*4090ac33SShruti Gupta
555*4090ac33SShruti GuptaReferences
556*4090ac33SShruti Gupta==========
557*4090ac33SShruti Gupta
558*4090ac33SShruti Gupta.. _[1]:
559*4090ac33SShruti Gupta
560*4090ac33SShruti Gupta[1] `Arm Firmware Framework for Arm A-profile <https://developer.arm.com/docs/den0077/latest>`__
561*4090ac33SShruti Gupta
562*4090ac33SShruti Gupta.. _[2]:
563*4090ac33SShruti Gupta
564*4090ac33SShruti Gupta[2] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fvp_el3_spmc_logical_sp.c
565*4090ac33SShruti Gupta
566*4090ac33SShruti Gupta.. _[3]:
567*4090ac33SShruti Gupta
568*4090ac33SShruti Gupta[3] `Trusted Boot Board Requirements
569*4090ac33SShruti GuptaClient <https://developer.arm.com/documentation/den0006/d/>`__
570*4090ac33SShruti Gupta
571*4090ac33SShruti Gupta.. _[4]:
572*4090ac33SShruti Gupta
573*4090ac33SShruti Gupta[4] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fvp_el3_spmc.c
574*4090ac33SShruti Gupta
575*4090ac33SShruti Gupta.. _[5]:
576*4090ac33SShruti Gupta
577*4090ac33SShruti Gupta[5] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/include/platform_def.h
578*4090ac33SShruti Gupta
579*4090ac33SShruti Gupta.. _[6]:
580*4090ac33SShruti Gupta
581*4090ac33SShruti Gupta[6] https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html
582*4090ac33SShruti Gupta
583*4090ac33SShruti Gupta.. _[7]:
584*4090ac33SShruti Gupta
585*4090ac33SShruti Gupta[7] https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/plat/arm/board/fvp/fdts/fvp_tsp_sp_manifest.dts
586*4090ac33SShruti Gupta
587*4090ac33SShruti Gupta.. _[8]:
588*4090ac33SShruti Gupta
589*4090ac33SShruti Gupta[8] https://lists.trustedfirmware.org/archives/list/tf-a@lists.trustedfirmware.org/thread/CFQFGU6H2D5GZYMUYGTGUSXIU3OYZP6U/
590*4090ac33SShruti Gupta
591*4090ac33SShruti Gupta.. _[9]:
592*4090ac33SShruti Gupta
593*4090ac33SShruti Gupta[9] https://trustedfirmware-a.readthedocs.io/en/latest/design/firmware-design.html#dynamic-configuration-during-cold-boot
594*4090ac33SShruti Gupta
595*4090ac33SShruti Gupta--------------
596*4090ac33SShruti Gupta
597*4090ac33SShruti Gupta*Copyright (c) 2020-2022, Arm Limited and Contributors. All rights reserved.*
598