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