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