blob: d9b2b1b7ceb569d459679339c6c1ad041319151a [file] [log] [blame]
Olivier Deprezecb2fe52020-04-02 15:38:02 +02001Secure Partition Manager (MM)
2*****************************
3
4Foreword
5========
6
Olivier Deprez370f3a12023-09-05 09:48:43 +02007This document describes the implementation where the Secure Partition Manager
8resides at EL3 and management services run from isolated Secure Partitions at
9S-EL0. The communication protocol is established through the Management Mode
10(MM) interface.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000011
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000012Background
13==========
14
15In some market segments that primarily deal with client-side devices like mobile
16phones, tablets, STBs and embedded devices, a Trusted OS instantiates trusted
17applications to provide security services like DRM, secure payment and
18authentication. The Global Platform TEE Client API specification defines the API
19used by Non-secure world applications to access these services. A Trusted OS
20fulfils the requirements of a security service as described above.
21
22Management services are typically implemented at the highest level of privilege
Dan Handley610e7e12018-03-01 18:44:00 +000023in the system, i.e. EL3 in Trusted Firmware-A (TF-A). The service requirements are
24fulfilled by the execution environment provided by TF-A.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000025
26The following diagram illustrates the corresponding software stack:
27
28|Image 1|
29
30In other market segments that primarily deal with server-side devices (e.g. data
31centres and enterprise servers) the secure software stack typically does not
32include a Global Platform Trusted OS. Security functions are accessed through
33other interfaces (e.g. ACPI TCG TPM interface, UEFI runtime variable service).
34
35Placement of management and security functions with diverse requirements in a
36privileged Exception Level (i.e. EL3 or S-EL1) makes security auditing of
37firmware more difficult and does not allow isolation of unrelated services from
38each other either.
39
40Introduction
41============
42
43A **Secure Partition** is a software execution environment instantiated in
44S-EL0 that can be used to implement simple management and security services.
45Since S-EL0 is an unprivileged Exception Level, a Secure Partition relies on
Dan Handley610e7e12018-03-01 18:44:00 +000046privileged firmware (i.e. TF-A) to be granted access to system and processor
47resources. Essentially, it is a software sandbox in the Secure world that runs
48under the control of privileged software, provides one or more services and
49accesses the following system resources:
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000050
51- Memory and device regions in the system address map.
52
53- PE system registers.
54
55- A range of synchronous exceptions (e.g. SMC function identifiers).
56
Dan Handley610e7e12018-03-01 18:44:00 +000057Note that currently TF-A only supports handling one Secure Partition.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000058
Dan Handley610e7e12018-03-01 18:44:00 +000059A Secure Partition enables TF-A to implement only the essential secure
60services in EL3 and instantiate the rest in a partition in S-EL0.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000061Furthermore, multiple Secure Partitions can be used to isolate unrelated
62services from each other.
63
64The following diagram illustrates the place of a Secure Partition in a typical
Dan Handley610e7e12018-03-01 18:44:00 +000065Armv8-A software stack. A single or multiple Secure Partitions provide secure
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000066services to software components in the Non-secure world and other Secure
67Partitions.
68
69|Image 2|
70
Dan Handley610e7e12018-03-01 18:44:00 +000071The TF-A build system is responsible for including the Secure Partition image
72in the FIP. During boot, BL2 includes support to authenticate and load the
73Secure Partition image. A BL31 component called **Secure Partition Manager
74(SPM)** is responsible for managing the partition. This is semantically
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000075similar to a hypervisor managing a virtual machine.
76
77The SPM is responsible for the following actions during boot:
78
79- Allocate resources requested by the Secure Partition.
80
81- Perform architectural and system setup required by the Secure Partition to
82 fulfil a service request.
83
84- Implement a standard interface that is used for initialising a Secure
85 Partition.
86
87The SPM is responsible for the following actions during runtime:
88
89- Implement a standard interface that is used by a Secure Partition to fulfil
90 service requests.
91
92- Implement a standard interface that is used by the Non-secure world for
93 accessing the services exported by a Secure Partition. A service can be
94 invoked through a SMC.
95
96Alternatively, a partition can be viewed as a thread of execution running under
97the control of the SPM. Hence common programming concepts described below are
98applicable to a partition.
99
100Description
101===========
102
103The previous section introduced some general aspects of the software
104architecture of a Secure Partition. This section describes the specific choices
105made in the current implementation of this software architecture. Subsequent
106revisions of the implementation will include a richer set of features that
107enable a more flexible architecture.
108
Dan Handley610e7e12018-03-01 18:44:00 +0000109Building TF-A with Secure Partition support
110-------------------------------------------
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000111
112SPM is supported on the Arm FVP exclusively at the moment. The current
113implementation supports inclusion of only a single Secure Partition in which a
114service always runs to completion (e.g. the requested services cannot be
115preempted to give control back to the Normal world).
116
117It is not currently possible for BL31 to integrate SPM support and a Secure
118Payload Dispatcher (SPD) at the same time; they are mutually exclusive. In the
119SPM bootflow, a Secure Partition image executing at S-EL0 replaces the Secure
120Payload image executing at S-EL1 (e.g. a Trusted OS). Both are referred to as
121BL32.
122
123A working prototype of a SP has been implemented by re-purposing the EDK2 code
124and tools, leveraging the concept of the *Standalone Management Mode (MM)* in
125the UEFI specification (see the PI v1.6 Volume 4: Management Mode Core
126Interface). This will be referred to as the *Standalone MM Secure Partition* in
127the rest of this document.
128
Dan Handley610e7e12018-03-01 18:44:00 +0000129To enable SPM support in TF-A, the source code must be compiled with the build
Manish Pandey247e5c32021-11-15 15:29:08 +0000130flag ``SPM_MM=1``, along with ``EL3_EXCEPTION_HANDLING=1`` and ``ENABLE_SVE_FOR_NS=0``.
131On Arm platforms the build option ``ARM_BL31_IN_DRAM`` must be set to 1. Also, the
Sughosh Ganudf4db9c2018-11-14 10:40:33 +0530132location of the binary that contains the BL32 image
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000133(``BL32=path/to/image.bin``) must be specified.
134
135First, build the Standalone MM Secure Partition. To build it, refer to the
136`instructions in the EDK2 repository`_.
137
Dan Handley610e7e12018-03-01 18:44:00 +0000138Then build TF-A with SPM support and include the Standalone MM Secure Partition
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000139image in the FIP:
140
Paul Beesley493e3492019-03-13 15:11:04 +0000141.. code:: shell
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000142
143 BL32=path/to/standalone/mm/sp BL33=path/to/bl33.bin \
Manish Pandey247e5c32021-11-15 15:29:08 +0000144 make PLAT=fvp SPM_MM=1 EL3_EXCEPTION_HANDLING=1 ENABLE_SVE_FOR_NS=0 ARM_BL31_IN_DRAM=1 all fip
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000145
146Describing Secure Partition resources
147-------------------------------------
148
Dan Handley610e7e12018-03-01 18:44:00 +0000149TF-A exports a porting interface that enables a platform to specify the system
150resources required by the Secure Partition. Some instructions are given below.
151However, this interface is under development and it may change as new features
152are implemented.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000153
154- A Secure Partition is considered a BL32 image, so the same defines that apply
155 to BL32 images apply to a Secure Partition: ``BL32_BASE`` and ``BL32_LIMIT``.
156
157- The following defines are needed to allocate space for the translation tables
158 used by the Secure Partition: ``PLAT_SP_IMAGE_MMAP_REGIONS`` and
159 ``PLAT_SP_IMAGE_MAX_XLAT_TABLES``.
160
161- The functions ``plat_get_secure_partition_mmap()`` and
162 ``plat_get_secure_partition_boot_info()`` have to be implemented. The file
163 ``plat/arm/board/fvp/fvp_common.c`` can be used as an example. It uses the
164 defines in ``include/plat/arm/common/arm_spm_def.h``.
165
166 - ``plat_get_secure_partition_mmap()`` returns an array of mmap regions that
167 describe the memory regions that the SPM needs to allocate for a Secure
168 Partition.
169
170 - ``plat_get_secure_partition_boot_info()`` returns a
Paul Beesley45f40282019-10-15 10:57:42 +0000171 ``spm_mm_boot_info_t`` struct that is populated by the platform
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000172 with information about the memory map of the Secure Partition.
173
174For an example of all the changes in context, you may refer to commit
175``e29efeb1b4``, in which the port for FVP was introduced.
176
177Accessing Secure Partition services
178-----------------------------------
179
Dan Handley610e7e12018-03-01 18:44:00 +0000180The `SMC Calling Convention`_ (*Arm DEN 0028B*) describes SMCs as a conduit for
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000181accessing services implemented in the Secure world. The ``MM_COMMUNICATE``
Dan Handley610e7e12018-03-01 18:44:00 +0000182interface defined in the `Management Mode Interface Specification`_ (*Arm DEN
Antonio Nino Diaz352c8522017-12-15 11:41:17 +00001830060A*) is used to invoke a Secure Partition service as a Fast Call.
184
185The mechanism used to identify a service within the partition depends on the
186service implementation. It is assumed that the caller of the service will be
187able to discover this mechanism through standard platform discovery mechanisms
188like ACPI and Device Trees. For example, *Volume 4: Platform Initialisation
189Specification v1.6. Management Mode Core Interface* specifies that a GUID is
190used to identify a management mode service. A client populates the GUID in the
191``EFI_MM_COMMUNICATE_HEADER``. The header is populated in the communication
192buffer shared with the Secure Partition.
193
194A Fast Call appears to be atomic from the perspective of the caller and returns
195when the requested operation has completed. A service invoked through the
196``MM_COMMUNICATE`` SMC will run to completion in the partition on a given CPU.
197The SPM is responsible for guaranteeing this behaviour. This means that there
198can only be a single outstanding Fast Call in a partition on a given CPU.
199
200Exchanging data with the Secure Partition
201-----------------------------------------
202
203The exchange of data between the Non-secure world and the partition takes place
204through a shared memory region. The location of data in the shared memory area
205is passed as a parameter to the ``MM_COMMUNICATE`` SMC. The shared memory area
206is statically allocated by the SPM and is expected to be either implicitly known
207to the Non-secure world or discovered through a platform discovery mechanism
208e.g. ACPI table or device tree. It is possible for the Non-secure world to
209exchange data with a partition only if it has been populated in this shared
210memory area. The shared memory area is implemented as per the guidelines
211specified in Section 3.2.3 of the `Management Mode Interface Specification`_
Dan Handley610e7e12018-03-01 18:44:00 +0000212(*Arm DEN 0060A*).
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000213
214The format of data structures used to encapsulate data in the shared memory is
215agreed between the Non-secure world and the Secure Partition. For example, in
Dan Handley610e7e12018-03-01 18:44:00 +0000216the `Management Mode Interface specification`_ (*Arm DEN 0060A*), Section 4
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000217describes that the communication buffer shared between the Non-secure world and
218the Management Mode (MM) in the Secure world must be of the type
219``EFI_MM_COMMUNICATE_HEADER``. This data structure is defined in *Volume 4:
220Platform Initialisation Specification v1.6. Management Mode Core Interface*.
221Any caller of a MM service will have to use the ``EFI_MM_COMMUNICATE_HEADER``
222data structure.
223
224Runtime model of the Secure Partition
225=====================================
226
227This section describes how the Secure Partition interfaces with the SPM.
228
229Interface with SPM
230------------------
231
232In order to instantiate one or more secure services in the Secure Partition in
233S-EL0, the SPM should define the following types of interfaces:
234
235- Interfaces that enable access to privileged operations from S-EL0. These
236 operations typically require access to system resources that are either shared
237 amongst multiple software components in the Secure world or cannot be directly
238 accessed from an unprivileged Exception Level.
239
240- Interfaces that establish the control path between the SPM and the Secure
241 Partition.
242
243This section describes the APIs currently exported by the SPM that enable a
244Secure Partition to initialise itself and export its services in S-EL0. These
245interfaces are not accessible from the Non-secure world.
246
247Conduit
248^^^^^^^
249
Dan Handley610e7e12018-03-01 18:44:00 +0000250The `SMC Calling Convention`_ (*Arm DEN 0028B*) specification describes the SMC
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000251and HVC conduits for accessing firmware services and their availability
252depending on the implemented Exception levels. In S-EL0, the Supervisor Call
253exception (SVC) is the only architectural mechanism available for unprivileged
254software to make a request for an operation implemented in privileged software.
255Hence, the SVC conduit must be used by the Secure Partition to access interfaces
256implemented by the SPM.
257
Dan Handley610e7e12018-03-01 18:44:00 +0000258A SVC causes an exception to be taken to S-EL1. TF-A assumes ownership of S-EL1
259and installs a simple exception vector table in S-EL1 that relays a SVC request
260from a Secure Partition as a SMC request to the SPM in EL3. Upon servicing the
John Tsichritzis63801cd2019-07-05 14:22:12 +0100261SMC request, Trusted Firmware-A returns control directly to S-EL0 through an
Dan Handley610e7e12018-03-01 18:44:00 +0000262ERET instruction.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000263
264Calling conventions
265^^^^^^^^^^^^^^^^^^^
266
Dan Handley610e7e12018-03-01 18:44:00 +0000267The `SMC Calling Convention`_ (*Arm DEN 0028B*) specification describes the
Antonio Nino Diaz352c8522017-12-15 11:41:17 +000026832-bit and 64-bit calling conventions for the SMC and HVC conduits. The SVC
269conduit introduces the concept of SVC32 and SVC64 calling conventions. The SVC32
270and SVC64 calling conventions are equivalent to the 32-bit (SMC32) and the
27164-bit (SMC64) calling conventions respectively.
272
273Communication initiated by SPM
274^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275
276A service request is initiated from the SPM through an exception return
277instruction (ERET) to S-EL0. Later, the Secure Partition issues an SVC
278instruction to signal completion of the request. Some example use cases are
279given below:
280
281- A request to initialise the Secure Partition during system boot.
282
283- A request to handle a runtime service request.
284
285Communication initiated by Secure Partition
286^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287
288A request is initiated from the Secure Partition by executing a SVC instruction.
Dan Handley610e7e12018-03-01 18:44:00 +0000289An ERET instruction is used by TF-A to return to S-EL0 with the result of the
290request.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000291
292For instance, a request to perform privileged operations on behalf of a
293partition (e.g. management of memory attributes in the translation tables for
294the Secure EL1&0 translation regime).
295
296Interfaces
297^^^^^^^^^^
298
299The current implementation reserves function IDs for Fast Calls in the Standard
Dan Handley610e7e12018-03-01 18:44:00 +0000300Secure Service calls range (see `SMC Calling Convention`_ (*Arm DEN 0028B*)
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000301specification) for each API exported by the SPM. This section defines the
302function prototypes for each function ID. The function IDs specify whether one
303or both of the SVC32 and SVC64 calling conventions can be used to invoke the
304corresponding interface.
305
306Secure Partition Event Management
307^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
308
309The Secure Partition provides an Event Management interface that is used by the
310SPM to delegate service requests to the Secure Partition. The interface also
311allows the Secure Partition to:
312
313- Register with the SPM a service that it provides.
Paul Beesley1fbc97b2019-01-11 18:26:51 +0000314- Indicate completion of a service request delegated by the SPM
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000315
316Miscellaneous interfaces
317------------------------
318
Paul Beesleye9754e62019-10-15 12:51:55 +0000319``SPM_MM_VERSION_AARCH32``
320^^^^^^^^^^^^^^^^^^^^^^^^^^
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000321
322- Description
323
324 Returns the version of the interface exported by SPM.
325
326- Parameters
327
328 - **uint32** - Function ID
329
330 - SVC32 Version: **0x84000060**
331
332- Return parameters
333
334 - **int32** - Status
335
336 On success, the format of the value is as follows:
337
338 - Bit [31]: Must be 0
339 - Bits [30:16]: Major Version. Must be 0 for this revision of the SPM
340 interface.
341 - Bits [15:0]: Minor Version. Must be 1 for this revision of the SPM
342 interface.
343
344 On error, the format of the value is as follows:
345
346 - ``NOT_SUPPORTED``: SPM interface is not supported or not available for the
347 client.
348
349- Usage
350
351 This function returns the version of the Secure Partition Manager
352 implementation. The major version is 0 and the minor version is 1. The version
353 number is a 31-bit unsigned integer, with the upper 15 bits denoting the major
354 revision, and the lower 16 bits denoting the minor revision. The following
355 rules apply to the version numbering:
356
357 - Different major revision values indicate possibly incompatible functions.
358
359 - For two revisions, A and B, for which the major revision values are
360 identical, if the minor revision value of revision B is greater than the
361 minor revision value of revision A, then every function in revision A must
362 work in a compatible way with revision B. However, it is possible for
363 revision B to have a higher function count than revision A.
364
365- Implementation responsibilities
366
367 If this function returns a valid version number, all the functions that are
368 described subsequently must be implemented, unless it is explicitly stated
369 that a function is optional.
370
371See `Error Codes`_ for integer values that are associated with each return
372code.
373
374Secure Partition Initialisation
375-------------------------------
376
377The SPM is responsible for initialising the architectural execution context to
378enable initialisation of a service in S-EL0. The responsibilities of the SPM are
379listed below. At the end of initialisation, the partition issues a
Paul Beesleye9754e62019-10-15 12:51:55 +0000380``MM_SP_EVENT_COMPLETE_AARCH64`` call (described later) to signal readiness for
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000381handling requests for services implemented by the Secure Partition. The
382initialisation event is executed as a Fast Call.
383
384Entry point invocation
385^^^^^^^^^^^^^^^^^^^^^^
386
387The entry point for service requests that should be handled as Fast Calls is
388used as the target of the ERET instruction to start initialisation of the Secure
389Partition.
390
391Architectural Setup
392^^^^^^^^^^^^^^^^^^^
393
394At cold boot, system registers accessible from S-EL0 will be in their reset
395state unless otherwise specified. The SPM will perform the following
396architectural setup to enable execution in S-EL0
397
398MMU setup
399^^^^^^^^^
400
401The platform port of a Secure Partition specifies to the SPM a list of regions
402that it needs access to and their attributes. The SPM validates this resource
403description and initialises the Secure EL1&0 translation regime as follows.
404
4051. Device regions are mapped with nGnRE attributes and Execute Never
406 instruction access permissions.
407
4082. Code memory regions are mapped with RO data and Executable instruction access
409 permissions.
410
4113. Read Only data memory regions are mapped with RO data and Execute Never
412 instruction access permissions.
413
4144. Read Write data memory regions are mapped with RW data and Execute Never
415 instruction access permissions.
416
4175. If the resource description does not explicitly describe the type of memory
418 regions then all memory regions will be marked with Code memory region
419 attributes.
420
4216. The ``UXN`` and ``PXN`` bits are set for regions that are not executable by
422 S-EL0 or S-EL1.
423
424System Register Setup
425^^^^^^^^^^^^^^^^^^^^^
426
427System registers that influence software execution in S-EL0 are setup by the SPM
428as follows:
429
4301. ``SCTLR_EL1``
431
432 - ``UCI=1``
433 - ``EOE=0``
434 - ``WXN=1``
435 - ``nTWE=1``
436 - ``nTWI=1``
437 - ``UCT=1``
438 - ``DZE=1``
439 - ``I=1``
440 - ``UMA=0``
441 - ``SA0=1``
442 - ``C=1``
443 - ``A=1``
444 - ``M=1``
445
4462. ``CPACR_EL1``
447
448 - ``FPEN=b'11``
449
4503. ``PSTATE``
451
452 - ``D,A,I,F=1``
453 - ``CurrentEL=0`` (EL0)
454 - ``SpSel=0`` (Thread mode)
455 - ``NRW=0`` (AArch64)
456
457General Purpose Register Setup
458^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
459
460SPM will invoke the entry point of a service by executing an ERET instruction.
461This transition into S-EL0 is special since it is not in response to a previous
462request through a SVC instruction. This is the first entry into S-EL0. The
463general purpose register usage at the time of entry will be as specified in the
464"Return State" column of Table 3-1 in Section 3.1 "Register use in AArch64 SMC
Dan Handley610e7e12018-03-01 18:44:00 +0000465calls" of the `SMC Calling Convention`_ (*Arm DEN 0028B*) specification. In
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000466addition, certain other restrictions will be applied as described below.
467
4681. ``SP_EL0``
469
470 A non-zero value will indicate that the SPM has initialised the stack pointer
471 for the current CPU.
472
473 The value will be 0 otherwise.
474
4752. ``X4-X30``
476
477 The values of these registers will be 0.
478
4793. ``X0-X3``
480
481 Parameters passed by the SPM.
482
483 - ``X0``: Virtual address of a buffer shared between EL3 and S-EL0. The
484 buffer will be mapped in the Secure EL1&0 translation regime with read-only
485 memory attributes described earlier.
486
487 - ``X1``: Size of the buffer in bytes.
488
489 - ``X2``: Cookie value (*IMPLEMENTATION DEFINED*).
490
491 - ``X3``: Cookie value (*IMPLEMENTATION DEFINED*).
492
493Runtime Event Delegation
494------------------------
495
496The SPM receives requests for Secure Partition services through a synchronous
497invocation (i.e. a SMC from the Non-secure world). These requests are delegated
498to the partition by programming a return from the last
Paul Beesleye9754e62019-10-15 12:51:55 +0000499``MM_SP_EVENT_COMPLETE_AARCH64`` call received from the partition. The last call
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000500was made to signal either completion of Secure Partition initialisation or
501completion of a partition service request.
502
Paul Beesleye9754e62019-10-15 12:51:55 +0000503``MM_SP_EVENT_COMPLETE_AARCH64``
504^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000505
506- Description
507
508 Signal completion of the last SP service request.
509
510- Parameters
511
512 - **uint32** - Function ID
513
514 - SVC64 Version: **0xC4000061**
515
516 - **int32** - Event Status Code
517
518 Zero or a positive value indicates that the event was handled successfully.
519 The values depend upon the original event that was delegated to the Secure
520 partition. They are described as follows.
521
522 - ``SUCCESS`` : Used to indicate that the Secure Partition was initialised
523 or a runtime request was handled successfully.
524
525 - Any other value greater than 0 is used to pass a specific Event Status
526 code in response to a runtime event.
527
528 A negative value indicates an error. The values of Event Status code depend
529 on the original event.
530
531- Return parameters
532
533 - **int32** - Event ID/Return Code
534
535 Zero or a positive value specifies the unique ID of the event being
536 delegated to the partition by the SPM.
537
538 In the current implementation, this parameter contains the function ID of
539 the ``MM_COMMUNICATE`` SMC. This value indicates to the partition that an
540 event has been delegated to it in response to an ``MM_COMMUNICATE`` request
541 from the Non-secure world.
542
543 A negative value indicates an error. The format of the value is as follows:
544
545 - ``NOT_SUPPORTED``: Function was called from the Non-secure world.
546
547 See `Error Codes`_ for integer values that are associated with each return
548 code.
549
550 - **uint32** - Event Context Address
551
552 Address of a buffer shared between the SPM and Secure Partition to pass
553 event specific information. The format of the data populated in the buffer
554 is implementation defined.
555
556 The buffer is mapped in the Secure EL1&0 translation regime with read-only
557 memory attributes described earlier.
558
559 For the SVC64 version, this parameter is a 64-bit Virtual Address (VA).
560
561 For the SVC32 version, this parameter is a 32-bit Virtual Address (VA).
562
563 - **uint32** - Event context size
564
565 Size of the memory starting at Event Address.
566
567 - **uint32/uint64** - Event Cookie
568
569 This is an optional parameter. If unused its value is SBZ.
570
571- Usage
572
573 This function signals to the SPM that the handling of the last event delegated
574 to a partition has completed. The partition is ready to handle its next event.
575 A return from this function is in response to the next event that will be
576 delegated to the partition. The return parameters describe the next event.
577
578- Caller responsibilities
579
Paul Beesleye9754e62019-10-15 12:51:55 +0000580 A Secure Partition must only call ``MM_SP_EVENT_COMPLETE_AARCH64`` to signal
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000581 completion of a request that was delegated to it by the SPM.
582
583- Callee responsibilities
584
585 When the SPM receives this call from a Secure Partition, the corresponding
586 syndrome information can be used to return control through an ERET
587 instruction, to the instruction immediately after the call in the Secure
588 Partition context. This syndrome information comprises of general purpose and
589 system register values when the call was made.
590
591 The SPM must save this syndrome information and use it to delegate the next
592 event to the Secure Partition. The return parameters of this interface must
593 specify the properties of the event and be populated in ``X0-X3/W0-W3``
594 registers.
595
596Secure Partition Memory Management
597----------------------------------
598
599A Secure Partition executes at S-EL0, which is an unprivileged Exception Level.
600The SPM is responsible for enabling access to regions of memory in the system
601address map from a Secure Partition. This is done by mapping these regions in
602the Secure EL1&0 Translation regime with appropriate memory attributes.
603Attributes refer to memory type, permission, cacheability and shareability
604attributes used in the Translation tables. The definitions of these attributes
Dan Handley610e7e12018-03-01 18:44:00 +0000605and their usage can be found in the `Armv8-A ARM`_ (*Arm DDI 0487*).
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000606
607All memory required by the Secure Partition is allocated upfront in the SPM,
608even before handing over to the Secure Partition for the first time. The initial
609access permissions of the memory regions are statically provided by the platform
610port and should allow the Secure Partition to run its initialisation code.
611
612However, they might not suit the final needs of the Secure Partition because its
613final memory layout might not be known until the Secure Partition initialises
614itself. As the Secure Partition initialises its runtime environment it might,
615for example, load dynamically some modules. For instance, a Secure Partition
616could implement a loader for a standard executable file format (e.g. an PE-COFF
617loader for loading executable files at runtime). These executable files will be
618a part of the Secure Partition image. The location of various sections in an
619executable file and their permission attributes (e.g. read-write data, read-only
620data and code) will be known only when the file is loaded into memory.
621
622In this case, the Secure Partition needs a way to change the access permissions
623of its memory regions. The SPM provides this feature through the
Paul Beesleye9754e62019-10-15 12:51:55 +0000624``MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64`` SVC interface. This interface is
625available to the Secure Partition during a specific time window: from the first
626entry into the Secure Partition up to the first ``SP_EVENT_COMPLETE`` call that
627signals the Secure Partition has finished its initialisation. Once the
628initialisation is complete, the SPM does not allow changes to the memory
629attributes.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000630
631This section describes the standard SVC interface that is implemented by the SPM
632to determine and change permission attributes of memory regions that belong to a
633Secure Partition.
634
Paul Beesleye9754e62019-10-15 12:51:55 +0000635``MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64``
636^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000637
638- Description
639
640 Request the permission attributes of a memory region from S-EL0.
641
642- Parameters
643
644 - **uint32** Function ID
645
646 - SVC64 Version: **0xC4000064**
647
648 - **uint64** Base Address
649
650 This parameter is a 64-bit Virtual Address (VA).
651
652 There are no alignment restrictions on the Base Address. The permission
653 attributes of the translation granule it lies in are returned.
654
655- Return parameters
656
657 - **int32** - Memory Attributes/Return Code
658
659 On success the format of the Return Code is as follows:
660
661 - Bits[1:0] : Data access permission
662
663 - b'00 : No access
664 - b'01 : Read-Write access
665 - b'10 : Reserved
666 - b'11 : Read-only access
667
668 - Bit[2]: Instruction access permission
669
670 - b'0 : Executable
671 - b'1 : Non-executable
672
673 - Bit[30:3] : Reserved. SBZ.
674
675 - Bit[31] : Must be 0
676
677 On failure the following error codes are returned:
678
679 - ``INVALID_PARAMETERS``: The Secure Partition is not allowed to access the
680 memory region the Base Address lies in.
681
682 - ``NOT_SUPPORTED`` : The SPM does not support retrieval of attributes of
683 any memory page that is accessible by the Secure Partition, or the
684 function was called from the Non-secure world. Also returned if it is
Paul Beesleye9754e62019-10-15 12:51:55 +0000685 used after ``MM_SP_EVENT_COMPLETE_AARCH64``.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000686
687 See `Error Codes`_ for integer values that are associated with each return
688 code.
689
690- Usage
691
692 This function is used to request the permission attributes for S-EL0 on a
693 memory region accessible from a Secure Partition. The size of the memory
694 region is equal to the Translation Granule size used in the Secure EL1&0
695 translation regime. Requests to retrieve other memory region attributes are
696 not currently supported.
697
698- Caller responsibilities
699
700 The caller must obtain the Translation Granule Size of the Secure EL1&0
701 translation regime from the SPM through an implementation defined method.
702
703- Callee responsibilities
704
705 The SPM must not return the memory access controls for a page of memory that
706 is not accessible from a Secure Partition.
707
Paul Beesleye9754e62019-10-15 12:51:55 +0000708``MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64``
709^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000710
711- Description
712
713 Set the permission attributes of a memory region from S-EL0.
714
715- Parameters
716
717 - **uint32** - Function ID
718
719 - SVC64 Version: **0xC4000065**
720
721 - **uint64** - Base Address
722
723 This parameter is a 64-bit Virtual Address (VA).
724
725 The alignment of the Base Address must be greater than or equal to the size
726 of the Translation Granule Size used in the Secure EL1&0 translation
727 regime.
728
729 - **uint32** - Page count
730
731 Number of pages starting from the Base Address whose memory attributes
732 should be changed. The page size is equal to the Translation Granule Size.
733
734 - **uint32** - Memory Access Controls
735
736 - Bits[1:0] : Data access permission
737
738 - b'00 : No access
739 - b'01 : Read-Write access
740 - b'10 : Reserved
741 - b'11 : Read-only access
742
743 - Bit[2] : Instruction access permission
744
745 - b'0 : Executable
746 - b'1 : Non-executable
747
748 - Bits[31:3] : Reserved. SBZ.
749
750 A combination of attributes that mark the region with RW and Executable
751 permissions is prohibited. A request to mark a device memory region with
752 Executable permissions is prohibited.
753
754- Return parameters
755
756 - **int32** - Return Code
757
758 - ``SUCCESS``: The Memory Access Controls were changed successfully.
759
760 - ``DENIED``: The SPM is servicing a request to change the attributes of a
761 memory region that overlaps with the region specified in this request.
762
763 - ``INVALID_PARAMETER``: An invalid combination of Memory Access Controls
764 has been specified. The Base Address is not correctly aligned. The Secure
765 Partition is not allowed to access part or all of the memory region
766 specified in the call.
767
768 - ``NO_MEMORY``: The SPM does not have memory resources to change the
769 attributes of the memory region in the translation tables.
770
771 - ``NOT_SUPPORTED``: The SPM does not permit change of attributes of any
772 memory region that is accessible by the Secure Partition. Function was
773 called from the Non-secure world. Also returned if it is used after
Paul Beesleye9754e62019-10-15 12:51:55 +0000774 ``MM_SP_EVENT_COMPLETE_AARCH64``.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000775
776 See `Error Codes`_ for integer values that are associated with each return
777 code.
778
779- Usage
780
781 This function is used to change the permission attributes for S-EL0 on a
782 memory region accessible from a Secure Partition. The size of the memory
783 region is equal to the Translation Granule size used in the Secure EL1&0
784 translation regime. Requests to change other memory region attributes are not
785 currently supported.
786
787 This function is only available at boot time. This interface is revoked after
Paul Beesleye9754e62019-10-15 12:51:55 +0000788 the Secure Partition sends the first ``MM_SP_EVENT_COMPLETE_AARCH64`` to
789 signal that it is initialised and ready to receive run-time requests.
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000790
791- Caller responsibilities
792
793 The caller must obtain the Translation Granule Size of the Secure EL1&0
794 translation regime from the SPM through an implementation defined method.
795
796- Callee responsibilities
797
798 The SPM must preserve the original memory access controls of the region of
799 memory in case of an unsuccessful call.  The SPM must preserve the consistency
800 of the S-EL1 translation regime if this function is called on different PEs
801 concurrently and the memory regions specified overlap.
802
803Error Codes
804-----------
805
806.. csv-table::
807 :header: "Name", "Value"
808
809 ``SUCCESS``,0
810 ``NOT_SUPPORTED``,-1
811 ``INVALID_PARAMETER``,-2
812 ``DENIED``,-3
813 ``NO_MEMORY``,-5
814 ``NOT_PRESENT``,-7
815
816--------------
817
Olivier Deprez9938c132021-04-21 11:22:23 +0200818*Copyright (c) 2017-2021, Arm Limited and Contributors. All rights reserved.*
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000819
Dan Handley610e7e12018-03-01 18:44:00 +0000820.. _Armv8-A ARM: https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000821.. _instructions in the EDK2 repository: https://github.com/tianocore/edk2-staging/blob/AArch64StandaloneMm/HowtoBuild.MD
822.. _Management Mode Interface Specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0060a/DEN0060A_ARM_MM_Interface_Specification.pdf
823.. _SDEI Specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0054a/ARM_DEN0054A_Software_Delegated_Exception_Interface.pdf
laurenw-arm03e7e612020-04-16 10:02:17 -0500824.. _SMC Calling Convention: https://developer.arm.com/docs/den0028/latest
Antonio Nino Diaz352c8522017-12-15 11:41:17 +0000825
Paul Beesley814f8c02019-03-13 15:49:27 +0000826.. |Image 1| image:: ../resources/diagrams/secure_sw_stack_tos.png
827.. |Image 2| image:: ../resources/diagrams/secure_sw_stack_sp.png