xref: /rk3399_ARM-atf/docs/components/secure-partition-manager-mm.rst (revision 90329375d0f44ad5e68772ae4c63b5482143937e)
1fcb1398fSOlivier DeprezSecure Partition Manager (MM)
2fcb1398fSOlivier Deprez*****************************
3fcb1398fSOlivier Deprez
4fcb1398fSOlivier DeprezForeword
5fcb1398fSOlivier Deprez========
6fcb1398fSOlivier Deprez
7d5be8027SOlivier DeprezThis document describes the implementation where the Secure Partition Manager
8d5be8027SOlivier Deprezresides at EL3 and management services run from isolated Secure Partitions at
9d5be8027SOlivier DeprezS-EL0. The communication protocol is established through the Management Mode
10d5be8027SOlivier Deprez(MM) interface.
11fcb1398fSOlivier Deprez
12fcb1398fSOlivier DeprezBackground
13fcb1398fSOlivier Deprez==========
14fcb1398fSOlivier Deprez
15fcb1398fSOlivier DeprezIn some market segments that primarily deal with client-side devices like mobile
16fcb1398fSOlivier Deprezphones, tablets, STBs and embedded devices, a Trusted OS instantiates trusted
17fcb1398fSOlivier Deprezapplications to provide security services like DRM, secure payment and
18fcb1398fSOlivier Deprezauthentication. The Global Platform TEE Client API specification defines the API
19fcb1398fSOlivier Deprezused by Non-secure world applications to access these services. A Trusted OS
20fcb1398fSOlivier Deprezfulfils the requirements of a security service as described above.
21fcb1398fSOlivier Deprez
22fcb1398fSOlivier DeprezManagement services are typically implemented at the highest level of privilege
23fcb1398fSOlivier Deprezin the system, i.e. EL3 in Trusted Firmware-A (TF-A). The service requirements are
24fcb1398fSOlivier Deprezfulfilled by the execution environment provided by TF-A.
25fcb1398fSOlivier Deprez
26fcb1398fSOlivier DeprezThe following diagram illustrates the corresponding software stack:
27fcb1398fSOlivier Deprez
28fcb1398fSOlivier Deprez|Image 1|
29fcb1398fSOlivier Deprez
30fcb1398fSOlivier DeprezIn other market segments that primarily deal with server-side devices (e.g. data
31fcb1398fSOlivier Deprezcentres and enterprise servers) the secure software stack typically does not
32fcb1398fSOlivier Deprezinclude a Global Platform Trusted OS. Security functions are accessed through
33fcb1398fSOlivier Deprezother interfaces (e.g. ACPI TCG TPM interface, UEFI runtime variable service).
34fcb1398fSOlivier Deprez
35fcb1398fSOlivier DeprezPlacement of management and security functions with diverse requirements in a
36fcb1398fSOlivier Deprezprivileged Exception Level (i.e. EL3 or S-EL1) makes security auditing of
37fcb1398fSOlivier Deprezfirmware more difficult and does not allow isolation of unrelated services from
38fcb1398fSOlivier Deprezeach other either.
39fcb1398fSOlivier Deprez
40fcb1398fSOlivier DeprezIntroduction
41fcb1398fSOlivier Deprez============
42fcb1398fSOlivier Deprez
43fcb1398fSOlivier DeprezA **Secure Partition** is a software execution environment instantiated in
44fcb1398fSOlivier DeprezS-EL0 that can be used to implement simple management and security services.
45fcb1398fSOlivier DeprezSince S-EL0 is an unprivileged Exception Level, a Secure Partition relies on
46fcb1398fSOlivier Deprezprivileged firmware (i.e. TF-A) to be granted access to system and processor
47fcb1398fSOlivier Deprezresources. Essentially, it is a software sandbox in the Secure world that runs
48fcb1398fSOlivier Deprezunder the control of privileged software, provides one or more services and
49fcb1398fSOlivier Deprezaccesses the following system resources:
50fcb1398fSOlivier Deprez
51fcb1398fSOlivier Deprez- Memory and device regions in the system address map.
52fcb1398fSOlivier Deprez
53fcb1398fSOlivier Deprez- PE system registers.
54fcb1398fSOlivier Deprez
55fcb1398fSOlivier Deprez- A range of synchronous exceptions (e.g. SMC function identifiers).
56fcb1398fSOlivier Deprez
57fcb1398fSOlivier DeprezNote that currently TF-A only supports handling one Secure Partition.
58fcb1398fSOlivier Deprez
59fcb1398fSOlivier DeprezA Secure Partition enables TF-A to implement only the essential secure
60fcb1398fSOlivier Deprezservices in EL3 and instantiate the rest in a partition in S-EL0.
61fcb1398fSOlivier DeprezFurthermore, multiple Secure Partitions can be used to isolate unrelated
62fcb1398fSOlivier Deprezservices from each other.
63fcb1398fSOlivier Deprez
64fcb1398fSOlivier DeprezThe following diagram illustrates the place of a Secure Partition in a typical
65fcb1398fSOlivier DeprezArmv8-A software stack. A single or multiple Secure Partitions provide secure
66fcb1398fSOlivier Deprezservices to software components in the Non-secure world and other Secure
67fcb1398fSOlivier DeprezPartitions.
68fcb1398fSOlivier Deprez
69fcb1398fSOlivier Deprez|Image 2|
70fcb1398fSOlivier Deprez
71fcb1398fSOlivier DeprezThe TF-A build system is responsible for including the Secure Partition image
72fcb1398fSOlivier Deprezin the FIP. During boot, BL2 includes support to authenticate and load the
73fcb1398fSOlivier DeprezSecure Partition image. A BL31 component called **Secure Partition Manager
74fcb1398fSOlivier Deprez(SPM)** is responsible for managing the partition. This is semantically
75fcb1398fSOlivier Deprezsimilar to a hypervisor managing a virtual machine.
76fcb1398fSOlivier Deprez
77fcb1398fSOlivier DeprezThe SPM is responsible for the following actions during boot:
78fcb1398fSOlivier Deprez
79fcb1398fSOlivier Deprez- Allocate resources requested by the Secure Partition.
80fcb1398fSOlivier Deprez
81fcb1398fSOlivier Deprez- Perform architectural and system setup required by the Secure Partition to
82fcb1398fSOlivier Deprez  fulfil a service request.
83fcb1398fSOlivier Deprez
84fcb1398fSOlivier Deprez- Implement a standard interface that is used for initialising a Secure
85fcb1398fSOlivier Deprez  Partition.
86fcb1398fSOlivier Deprez
87fcb1398fSOlivier DeprezThe SPM is responsible for the following actions during runtime:
88fcb1398fSOlivier Deprez
89fcb1398fSOlivier Deprez- Implement a standard interface that is used by a Secure Partition to fulfil
90fcb1398fSOlivier Deprez  service requests.
91fcb1398fSOlivier Deprez
92fcb1398fSOlivier Deprez- Implement a standard interface that is used by the Non-secure world for
93fcb1398fSOlivier Deprez  accessing the services exported by a Secure Partition. A service can be
94fcb1398fSOlivier Deprez  invoked through a SMC.
95fcb1398fSOlivier Deprez
96fcb1398fSOlivier DeprezAlternatively, a partition can be viewed as a thread of execution running under
97fcb1398fSOlivier Deprezthe control of the SPM. Hence common programming concepts described below are
98fcb1398fSOlivier Deprezapplicable to a partition.
99fcb1398fSOlivier Deprez
100fcb1398fSOlivier DeprezDescription
101fcb1398fSOlivier Deprez===========
102fcb1398fSOlivier Deprez
103fcb1398fSOlivier DeprezThe previous section introduced some general aspects of the software
104fcb1398fSOlivier Deprezarchitecture of a Secure Partition. This section describes the specific choices
105fcb1398fSOlivier Deprezmade in the current implementation of this software architecture. Subsequent
106fcb1398fSOlivier Deprezrevisions of the implementation will include a richer set of features that
107fcb1398fSOlivier Deprezenable a more flexible architecture.
108fcb1398fSOlivier Deprez
109fcb1398fSOlivier DeprezBuilding TF-A with Secure Partition support
110fcb1398fSOlivier Deprez-------------------------------------------
111fcb1398fSOlivier Deprez
112fcb1398fSOlivier DeprezSPM is supported on the Arm FVP exclusively at the moment. The current
113fcb1398fSOlivier Deprezimplementation supports inclusion of only a single Secure Partition in which a
114fcb1398fSOlivier Deprezservice always runs to completion (e.g. the requested services cannot be
115fcb1398fSOlivier Deprezpreempted to give control back to the Normal world).
116fcb1398fSOlivier Deprez
117fcb1398fSOlivier DeprezIt is not currently possible for BL31 to integrate SPM support and a Secure
118fcb1398fSOlivier DeprezPayload Dispatcher (SPD) at the same time; they are mutually exclusive. In the
119fcb1398fSOlivier DeprezSPM bootflow, a Secure Partition image executing at S-EL0 replaces the Secure
120fcb1398fSOlivier DeprezPayload image executing at S-EL1 (e.g. a Trusted OS). Both are referred to as
121fcb1398fSOlivier DeprezBL32.
122fcb1398fSOlivier Deprez
123fcb1398fSOlivier DeprezA working prototype of a SP has been implemented by re-purposing the EDK2 code
124fcb1398fSOlivier Deprezand tools, leveraging the concept of the *Standalone Management Mode (MM)* in
125fcb1398fSOlivier Deprezthe UEFI specification (see the PI v1.6 Volume 4: Management Mode Core
126fcb1398fSOlivier DeprezInterface). This will be referred to as the *Standalone MM Secure Partition* in
127fcb1398fSOlivier Deprezthe rest of this document.
128fcb1398fSOlivier Deprez
129fcb1398fSOlivier DeprezTo enable SPM support in TF-A, the source code must be compiled with the build
1304333f95bSManish Pandeyflag ``SPM_MM=1``, along with ``EL3_EXCEPTION_HANDLING=1`` and ``ENABLE_SVE_FOR_NS=0``.
1314333f95bSManish PandeyOn Arm platforms the build option ``ARM_BL31_IN_DRAM`` must be set to 1. Also, the
132fcb1398fSOlivier Deprezlocation of the binary that contains the BL32 image
133fcb1398fSOlivier Deprez(``BL32=path/to/image.bin``) must be specified.
134fcb1398fSOlivier Deprez
135fcb1398fSOlivier DeprezFirst, build the Standalone MM Secure Partition. To build it, refer to the
136fcb1398fSOlivier Deprez`instructions in the EDK2 repository`_.
137fcb1398fSOlivier Deprez
138fcb1398fSOlivier DeprezThen build TF-A with SPM support and include the Standalone MM Secure Partition
139fcb1398fSOlivier Deprezimage in the FIP:
140fcb1398fSOlivier Deprez
141fcb1398fSOlivier Deprez.. code:: shell
142fcb1398fSOlivier Deprez
143fcb1398fSOlivier Deprez    BL32=path/to/standalone/mm/sp BL33=path/to/bl33.bin \
1444333f95bSManish Pandey    make PLAT=fvp SPM_MM=1 EL3_EXCEPTION_HANDLING=1 ENABLE_SVE_FOR_NS=0 ARM_BL31_IN_DRAM=1 all fip
145fcb1398fSOlivier Deprez
146fcb1398fSOlivier DeprezDescribing Secure Partition resources
147fcb1398fSOlivier Deprez-------------------------------------
148fcb1398fSOlivier Deprez
149fcb1398fSOlivier DeprezTF-A exports a porting interface that enables a platform to specify the system
150fcb1398fSOlivier Deprezresources required by the Secure Partition. Some instructions are given below.
151fcb1398fSOlivier DeprezHowever, this interface is under development and it may change as new features
152fcb1398fSOlivier Deprezare implemented.
153fcb1398fSOlivier Deprez
154fcb1398fSOlivier Deprez- A Secure Partition is considered a BL32 image, so the same defines that apply
155fcb1398fSOlivier Deprez  to BL32 images apply to a Secure Partition: ``BL32_BASE`` and ``BL32_LIMIT``.
156fcb1398fSOlivier Deprez
157fcb1398fSOlivier Deprez- The following defines are needed to allocate space for the translation tables
158fcb1398fSOlivier Deprez  used by the Secure Partition: ``PLAT_SP_IMAGE_MMAP_REGIONS`` and
159fcb1398fSOlivier Deprez  ``PLAT_SP_IMAGE_MAX_XLAT_TABLES``.
160fcb1398fSOlivier Deprez
161fcb1398fSOlivier Deprez- The functions ``plat_get_secure_partition_mmap()`` and
162fcb1398fSOlivier Deprez  ``plat_get_secure_partition_boot_info()`` have to be implemented. The file
163fcb1398fSOlivier Deprez  ``plat/arm/board/fvp/fvp_common.c`` can be used as an example. It uses the
164fcb1398fSOlivier Deprez  defines in ``include/plat/arm/common/arm_spm_def.h``.
165fcb1398fSOlivier Deprez
166fcb1398fSOlivier Deprez  - ``plat_get_secure_partition_mmap()`` returns an array of mmap regions that
167fcb1398fSOlivier Deprez    describe the memory regions that the SPM needs to allocate for a Secure
168fcb1398fSOlivier Deprez    Partition.
169fcb1398fSOlivier Deprez
170fcb1398fSOlivier Deprez  - ``plat_get_secure_partition_boot_info()`` returns a
171fcb1398fSOlivier Deprez    ``spm_mm_boot_info_t`` struct that is populated by the platform
172fcb1398fSOlivier Deprez    with information about the memory map of the Secure Partition.
173fcb1398fSOlivier Deprez
174fcb1398fSOlivier DeprezFor an example of all the changes in context, you may refer to commit
175fcb1398fSOlivier Deprez``e29efeb1b4``, in which the port for FVP was introduced.
176fcb1398fSOlivier Deprez
177fcb1398fSOlivier DeprezAccessing Secure Partition services
178fcb1398fSOlivier Deprez-----------------------------------
179fcb1398fSOlivier Deprez
180fcb1398fSOlivier DeprezThe `SMC Calling Convention`_ (*Arm DEN 0028B*) describes SMCs as a conduit for
181fcb1398fSOlivier Deprezaccessing services implemented in the Secure world. The ``MM_COMMUNICATE``
182fcb1398fSOlivier Deprezinterface defined in the `Management Mode Interface Specification`_ (*Arm DEN
183fcb1398fSOlivier Deprez0060A*) is used to invoke a Secure Partition service as a Fast Call.
184fcb1398fSOlivier Deprez
185fcb1398fSOlivier DeprezThe mechanism used to identify a service within the partition depends on the
186fcb1398fSOlivier Deprezservice implementation. It is assumed that the caller of the service will be
187fcb1398fSOlivier Deprezable to discover this mechanism through standard platform discovery mechanisms
188fcb1398fSOlivier Deprezlike ACPI and Device Trees. For example, *Volume 4: Platform Initialisation
189fcb1398fSOlivier DeprezSpecification v1.6. Management Mode Core Interface* specifies that a GUID is
190fcb1398fSOlivier Deprezused to identify a management mode service. A client populates the GUID in the
191fcb1398fSOlivier Deprez``EFI_MM_COMMUNICATE_HEADER``. The header is populated in the communication
192fcb1398fSOlivier Deprezbuffer shared with the Secure Partition.
193fcb1398fSOlivier Deprez
194fcb1398fSOlivier DeprezA Fast Call appears to be atomic from the perspective of the caller and returns
195fcb1398fSOlivier Deprezwhen the requested operation has completed. A service invoked through the
196fcb1398fSOlivier Deprez``MM_COMMUNICATE`` SMC will run to completion in the partition on a given CPU.
197fcb1398fSOlivier DeprezThe SPM is responsible for guaranteeing this behaviour. This means that there
198fcb1398fSOlivier Deprezcan only be a single outstanding Fast Call in a partition on a given CPU.
199fcb1398fSOlivier Deprez
200fcb1398fSOlivier DeprezExchanging data with the Secure Partition
201fcb1398fSOlivier Deprez-----------------------------------------
202fcb1398fSOlivier Deprez
203fcb1398fSOlivier DeprezThe exchange of data between the Non-secure world and the partition takes place
204fcb1398fSOlivier Deprezthrough a shared memory region. The location of data in the shared memory area
205fcb1398fSOlivier Deprezis passed as a parameter to the ``MM_COMMUNICATE`` SMC. The shared memory area
206fcb1398fSOlivier Deprezis statically allocated by the SPM and is expected to be either implicitly known
207fcb1398fSOlivier Deprezto the Non-secure world or discovered through a platform discovery mechanism
208fcb1398fSOlivier Depreze.g. ACPI table or device tree. It is possible for the Non-secure world to
209fcb1398fSOlivier Deprezexchange data with a partition only if it has been populated in this shared
210fcb1398fSOlivier Deprezmemory area. The shared memory area is implemented as per the guidelines
211fcb1398fSOlivier Deprezspecified in Section 3.2.3 of the `Management Mode Interface Specification`_
212fcb1398fSOlivier Deprez(*Arm DEN 0060A*).
213fcb1398fSOlivier Deprez
214fcb1398fSOlivier DeprezThe format of data structures used to encapsulate data in the shared memory is
215fcb1398fSOlivier Deprezagreed between the Non-secure world and the Secure Partition. For example, in
216fcb1398fSOlivier Deprezthe `Management Mode Interface specification`_ (*Arm DEN 0060A*), Section 4
217fcb1398fSOlivier Deprezdescribes that the communication buffer shared between the Non-secure world and
218fcb1398fSOlivier Deprezthe Management Mode (MM) in the Secure world must be of the type
219fcb1398fSOlivier Deprez``EFI_MM_COMMUNICATE_HEADER``. This data structure is defined in *Volume 4:
220fcb1398fSOlivier DeprezPlatform Initialisation Specification v1.6. Management Mode Core Interface*.
221fcb1398fSOlivier DeprezAny caller of a MM service will have to use the ``EFI_MM_COMMUNICATE_HEADER``
222fcb1398fSOlivier Deprezdata structure.
223fcb1398fSOlivier Deprez
224fcb1398fSOlivier DeprezRuntime model of the Secure Partition
225fcb1398fSOlivier Deprez=====================================
226fcb1398fSOlivier Deprez
227fcb1398fSOlivier DeprezThis section describes how the Secure Partition interfaces with the SPM.
228fcb1398fSOlivier Deprez
229fcb1398fSOlivier DeprezInterface with SPM
230fcb1398fSOlivier Deprez------------------
231fcb1398fSOlivier Deprez
232fcb1398fSOlivier DeprezIn order to instantiate one or more secure services in the Secure Partition in
233fcb1398fSOlivier DeprezS-EL0, the SPM should define the following types of interfaces:
234fcb1398fSOlivier Deprez
235fcb1398fSOlivier Deprez- Interfaces that enable access to privileged operations from S-EL0. These
236fcb1398fSOlivier Deprez  operations typically require access to system resources that are either shared
237fcb1398fSOlivier Deprez  amongst multiple software components in the Secure world or cannot be directly
238fcb1398fSOlivier Deprez  accessed from an unprivileged Exception Level.
239fcb1398fSOlivier Deprez
240fcb1398fSOlivier Deprez- Interfaces that establish the control path between the SPM and the Secure
241fcb1398fSOlivier Deprez  Partition.
242fcb1398fSOlivier Deprez
243fcb1398fSOlivier DeprezThis section describes the APIs currently exported by the SPM that enable a
244fcb1398fSOlivier DeprezSecure Partition to initialise itself and export its services in S-EL0. These
245fcb1398fSOlivier Deprezinterfaces are not accessible from the Non-secure world.
246fcb1398fSOlivier Deprez
247fcb1398fSOlivier DeprezConduit
248fcb1398fSOlivier Deprez^^^^^^^
249fcb1398fSOlivier Deprez
250fcb1398fSOlivier DeprezThe `SMC Calling Convention`_ (*Arm DEN 0028B*) specification describes the SMC
251fcb1398fSOlivier Deprezand HVC conduits for accessing firmware services and their availability
252fcb1398fSOlivier Deprezdepending on the implemented Exception levels. In S-EL0, the Supervisor Call
253fcb1398fSOlivier Deprezexception (SVC) is the only architectural mechanism available for unprivileged
254fcb1398fSOlivier Deprezsoftware to make a request for an operation implemented in privileged software.
255fcb1398fSOlivier DeprezHence, the SVC conduit must be used by the Secure Partition to access interfaces
256fcb1398fSOlivier Deprezimplemented by the SPM.
257fcb1398fSOlivier Deprez
258fcb1398fSOlivier DeprezA SVC causes an exception to be taken to S-EL1. TF-A assumes ownership of S-EL1
259fcb1398fSOlivier Deprezand installs a simple exception vector table in S-EL1 that relays a SVC request
260fcb1398fSOlivier Deprezfrom a Secure Partition as a SMC request to the SPM in EL3. Upon servicing the
261fcb1398fSOlivier DeprezSMC request, Trusted Firmware-A returns control directly to S-EL0 through an
262fcb1398fSOlivier DeprezERET instruction.
263fcb1398fSOlivier Deprez
264fcb1398fSOlivier DeprezCalling conventions
265fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^
266fcb1398fSOlivier Deprez
267fcb1398fSOlivier DeprezThe `SMC Calling Convention`_ (*Arm DEN 0028B*) specification describes the
268fcb1398fSOlivier Deprez32-bit and 64-bit calling conventions for the SMC and HVC conduits. The SVC
269fcb1398fSOlivier Deprezconduit introduces the concept of SVC32 and SVC64 calling conventions. The SVC32
270fcb1398fSOlivier Deprezand SVC64 calling conventions are equivalent to the 32-bit (SMC32) and the
271fcb1398fSOlivier Deprez64-bit (SMC64) calling conventions respectively.
272fcb1398fSOlivier Deprez
273fcb1398fSOlivier DeprezCommunication initiated by SPM
274fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275fcb1398fSOlivier Deprez
276fcb1398fSOlivier DeprezA service request is initiated from the SPM through an exception return
277fcb1398fSOlivier Deprezinstruction (ERET) to S-EL0. Later, the Secure Partition issues an SVC
278fcb1398fSOlivier Deprezinstruction to signal completion of the request. Some example use cases are
279fcb1398fSOlivier Deprezgiven below:
280fcb1398fSOlivier Deprez
281fcb1398fSOlivier Deprez- A request to initialise the Secure Partition during system boot.
282fcb1398fSOlivier Deprez
283fcb1398fSOlivier Deprez- A request to handle a runtime service request.
284fcb1398fSOlivier Deprez
285fcb1398fSOlivier DeprezCommunication initiated by Secure Partition
286fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287fcb1398fSOlivier Deprez
288fcb1398fSOlivier DeprezA request is initiated from the Secure Partition by executing a SVC instruction.
289fcb1398fSOlivier DeprezAn ERET instruction is used by TF-A to return to S-EL0 with the result of the
290fcb1398fSOlivier Deprezrequest.
291fcb1398fSOlivier Deprez
292fcb1398fSOlivier DeprezFor instance, a request to perform privileged operations on behalf of a
293fcb1398fSOlivier Deprezpartition (e.g.  management of memory attributes in the translation tables for
294fcb1398fSOlivier Deprezthe Secure EL1&0 translation regime).
295fcb1398fSOlivier Deprez
296fcb1398fSOlivier DeprezInterfaces
297fcb1398fSOlivier Deprez^^^^^^^^^^
298fcb1398fSOlivier Deprez
299fcb1398fSOlivier DeprezThe current implementation reserves function IDs for Fast Calls in the Standard
300fcb1398fSOlivier DeprezSecure Service calls range (see `SMC Calling Convention`_ (*Arm DEN 0028B*)
301fcb1398fSOlivier Deprezspecification) for each API exported by the SPM. This section defines the
302fcb1398fSOlivier Deprezfunction prototypes for each function ID. The function IDs specify whether one
303fcb1398fSOlivier Deprezor both of the SVC32 and SVC64 calling conventions can be used to invoke the
304fcb1398fSOlivier Deprezcorresponding interface.
305fcb1398fSOlivier Deprez
306fcb1398fSOlivier DeprezSecure Partition Event Management
307fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
308fcb1398fSOlivier Deprez
309fcb1398fSOlivier DeprezThe Secure Partition provides an Event Management interface that is used by the
310fcb1398fSOlivier DeprezSPM to delegate service requests to the Secure Partition. The interface also
311fcb1398fSOlivier Deprezallows the Secure Partition to:
312fcb1398fSOlivier Deprez
313fcb1398fSOlivier Deprez- Register with the SPM a service that it provides.
314fcb1398fSOlivier Deprez- Indicate completion of a service request delegated by the SPM
315fcb1398fSOlivier Deprez
316fcb1398fSOlivier DeprezMiscellaneous interfaces
317fcb1398fSOlivier Deprez------------------------
318fcb1398fSOlivier Deprez
319fcb1398fSOlivier Deprez``SPM_MM_VERSION_AARCH32``
320fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^
321fcb1398fSOlivier Deprez
322fcb1398fSOlivier Deprez- Description
323fcb1398fSOlivier Deprez
324fcb1398fSOlivier Deprez  Returns the version of the interface exported by SPM.
325fcb1398fSOlivier Deprez
326fcb1398fSOlivier Deprez- Parameters
327fcb1398fSOlivier Deprez
328fcb1398fSOlivier Deprez  - **uint32** - Function ID
329fcb1398fSOlivier Deprez
330fcb1398fSOlivier Deprez    - SVC32 Version: **0x84000060**
331fcb1398fSOlivier Deprez
332fcb1398fSOlivier Deprez- Return parameters
333fcb1398fSOlivier Deprez
334fcb1398fSOlivier Deprez  - **int32** - Status
335fcb1398fSOlivier Deprez
336fcb1398fSOlivier Deprez    On success, the format of the value is as follows:
337fcb1398fSOlivier Deprez
338fcb1398fSOlivier Deprez    - Bit [31]: Must be 0
339fcb1398fSOlivier Deprez    - Bits [30:16]: Major Version. Must be 0 for this revision of the SPM
340fcb1398fSOlivier Deprez      interface.
341fcb1398fSOlivier Deprez    - Bits [15:0]: Minor Version. Must be 1 for this revision of the SPM
342fcb1398fSOlivier Deprez      interface.
343fcb1398fSOlivier Deprez
344fcb1398fSOlivier Deprez    On error, the format of the value is as follows:
345fcb1398fSOlivier Deprez
346fcb1398fSOlivier Deprez    - ``NOT_SUPPORTED``: SPM interface is not supported or not available for the
347fcb1398fSOlivier Deprez      client.
348fcb1398fSOlivier Deprez
349fcb1398fSOlivier Deprez- Usage
350fcb1398fSOlivier Deprez
351fcb1398fSOlivier Deprez  This function returns the version of the Secure Partition Manager
352fcb1398fSOlivier Deprez  implementation. The major version is 0 and the minor version is 1. The version
353fcb1398fSOlivier Deprez  number is a 31-bit unsigned integer, with the upper 15 bits denoting the major
354fcb1398fSOlivier Deprez  revision, and the lower 16 bits denoting the minor revision. The following
355fcb1398fSOlivier Deprez  rules apply to the version numbering:
356fcb1398fSOlivier Deprez
357fcb1398fSOlivier Deprez  - Different major revision values indicate possibly incompatible functions.
358fcb1398fSOlivier Deprez
359fcb1398fSOlivier Deprez  - For two revisions, A and B, for which the major revision values are
360fcb1398fSOlivier Deprez    identical, if the minor revision value of revision B is greater than the
361fcb1398fSOlivier Deprez    minor revision value of revision A, then every function in revision A must
362fcb1398fSOlivier Deprez    work in a compatible way with revision B. However, it is possible for
363fcb1398fSOlivier Deprez    revision B to have a higher function count than revision A.
364fcb1398fSOlivier Deprez
365fcb1398fSOlivier Deprez- Implementation responsibilities
366fcb1398fSOlivier Deprez
367fcb1398fSOlivier Deprez  If this function returns a valid version number, all the functions that are
368fcb1398fSOlivier Deprez  described subsequently must be implemented, unless it is explicitly stated
369fcb1398fSOlivier Deprez  that a function is optional.
370fcb1398fSOlivier Deprez
371fcb1398fSOlivier DeprezSee `Error Codes`_ for integer values that are associated with each return
372fcb1398fSOlivier Deprezcode.
373fcb1398fSOlivier Deprez
374fcb1398fSOlivier DeprezSecure Partition Initialisation
375fcb1398fSOlivier Deprez-------------------------------
376fcb1398fSOlivier Deprez
377fcb1398fSOlivier DeprezThe SPM is responsible for initialising the architectural execution context to
378fcb1398fSOlivier Deprezenable initialisation of a service in S-EL0. The responsibilities of the SPM are
379fcb1398fSOlivier Deprezlisted below. At the end of initialisation, the partition issues a
380fcb1398fSOlivier Deprez``MM_SP_EVENT_COMPLETE_AARCH64`` call (described later) to signal readiness for
381fcb1398fSOlivier Deprezhandling requests for services implemented by the Secure Partition. The
382fcb1398fSOlivier Deprezinitialisation event is executed as a Fast Call.
383fcb1398fSOlivier Deprez
384fcb1398fSOlivier DeprezEntry point invocation
385fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^
386fcb1398fSOlivier Deprez
387fcb1398fSOlivier DeprezThe entry point for service requests that should be handled as Fast Calls is
388fcb1398fSOlivier Deprezused as the target of the ERET instruction to start initialisation of the Secure
389fcb1398fSOlivier DeprezPartition.
390fcb1398fSOlivier Deprez
391fcb1398fSOlivier DeprezArchitectural Setup
392fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^
393fcb1398fSOlivier Deprez
394fcb1398fSOlivier DeprezAt cold boot, system registers accessible from S-EL0 will be in their reset
395fcb1398fSOlivier Deprezstate unless otherwise specified. The SPM will perform the following
396fcb1398fSOlivier Deprezarchitectural setup to enable execution in S-EL0
397fcb1398fSOlivier Deprez
398fcb1398fSOlivier DeprezMMU setup
399fcb1398fSOlivier Deprez^^^^^^^^^
400fcb1398fSOlivier Deprez
401fcb1398fSOlivier DeprezThe platform port of a Secure Partition specifies to the SPM a list of regions
402fcb1398fSOlivier Deprezthat it needs access to and their attributes. The SPM validates this resource
403fcb1398fSOlivier Deprezdescription and initialises the Secure EL1&0 translation regime as follows.
404fcb1398fSOlivier Deprez
405fcb1398fSOlivier Deprez1. Device regions are mapped with nGnRE attributes and Execute Never
406fcb1398fSOlivier Deprez   instruction access permissions.
407fcb1398fSOlivier Deprez
408fcb1398fSOlivier Deprez2. Code memory regions are mapped with RO data and Executable instruction access
409fcb1398fSOlivier Deprez   permissions.
410fcb1398fSOlivier Deprez
411fcb1398fSOlivier Deprez3. Read Only data memory regions are mapped with RO data and Execute Never
412fcb1398fSOlivier Deprez   instruction access permissions.
413fcb1398fSOlivier Deprez
414fcb1398fSOlivier Deprez4. Read Write data memory regions are mapped with RW data and Execute Never
415fcb1398fSOlivier Deprez   instruction access permissions.
416fcb1398fSOlivier Deprez
417fcb1398fSOlivier Deprez5. If the resource description does not explicitly describe the type of memory
418fcb1398fSOlivier Deprez   regions then all memory regions will be marked with Code memory region
419fcb1398fSOlivier Deprez   attributes.
420fcb1398fSOlivier Deprez
421fcb1398fSOlivier Deprez6. The ``UXN`` and ``PXN`` bits are set for regions that are not executable by
422fcb1398fSOlivier Deprez   S-EL0 or S-EL1.
423fcb1398fSOlivier Deprez
424fcb1398fSOlivier DeprezSystem Register Setup
425fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^
426fcb1398fSOlivier Deprez
427fcb1398fSOlivier DeprezSystem registers that influence software execution in S-EL0 are setup by the SPM
428fcb1398fSOlivier Deprezas follows:
429fcb1398fSOlivier Deprez
430fcb1398fSOlivier Deprez1. ``SCTLR_EL1``
431fcb1398fSOlivier Deprez
432fcb1398fSOlivier Deprez   - ``UCI=1``
433fcb1398fSOlivier Deprez   - ``EOE=0``
434fcb1398fSOlivier Deprez   - ``WXN=1``
435fcb1398fSOlivier Deprez   - ``nTWE=1``
436fcb1398fSOlivier Deprez   - ``nTWI=1``
437fcb1398fSOlivier Deprez   - ``UCT=1``
438fcb1398fSOlivier Deprez   - ``DZE=1``
439fcb1398fSOlivier Deprez   - ``I=1``
440fcb1398fSOlivier Deprez   - ``UMA=0``
441fcb1398fSOlivier Deprez   - ``SA0=1``
442fcb1398fSOlivier Deprez   - ``C=1``
443fcb1398fSOlivier Deprez   - ``A=1``
444fcb1398fSOlivier Deprez   - ``M=1``
445fcb1398fSOlivier Deprez
446fcb1398fSOlivier Deprez2. ``CPACR_EL1``
447fcb1398fSOlivier Deprez
448fcb1398fSOlivier Deprez   - ``FPEN=b'11``
449fcb1398fSOlivier Deprez
450fcb1398fSOlivier Deprez3. ``PSTATE``
451fcb1398fSOlivier Deprez
452fcb1398fSOlivier Deprez   - ``D,A,I,F=1``
453fcb1398fSOlivier Deprez   - ``CurrentEL=0`` (EL0)
454fcb1398fSOlivier Deprez   - ``SpSel=0`` (Thread mode)
455fcb1398fSOlivier Deprez   - ``NRW=0`` (AArch64)
456fcb1398fSOlivier Deprez
457fcb1398fSOlivier DeprezGeneral Purpose Register Setup
458fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
459fcb1398fSOlivier Deprez
460fcb1398fSOlivier DeprezSPM will invoke the entry point of a service by executing an ERET instruction.
461fcb1398fSOlivier DeprezThis transition into S-EL0 is special since it is not in response to a previous
462fcb1398fSOlivier Deprezrequest through a SVC instruction. This is the first entry into S-EL0. The
463fcb1398fSOlivier Deprezgeneral purpose register usage at the time of entry will be as specified in the
464fcb1398fSOlivier Deprez"Return State" column of Table 3-1 in Section 3.1 "Register use in AArch64 SMC
465fcb1398fSOlivier Deprezcalls" of the `SMC Calling Convention`_ (*Arm DEN 0028B*) specification. In
466fcb1398fSOlivier Deprezaddition, certain other restrictions will be applied as described below.
467fcb1398fSOlivier Deprez
468fcb1398fSOlivier Deprez1. ``SP_EL0``
469fcb1398fSOlivier Deprez
470fcb1398fSOlivier Deprez   A non-zero value will indicate that the SPM has initialised the stack pointer
471fcb1398fSOlivier Deprez   for the current CPU.
472fcb1398fSOlivier Deprez
473fcb1398fSOlivier Deprez   The value will be 0 otherwise.
474fcb1398fSOlivier Deprez
475fcb1398fSOlivier Deprez2. ``X4-X30``
476fcb1398fSOlivier Deprez
477fcb1398fSOlivier Deprez   The values of these registers will be 0.
478fcb1398fSOlivier Deprez
479fcb1398fSOlivier Deprez3. ``X0-X3``
480fcb1398fSOlivier Deprez
481fcb1398fSOlivier Deprez   Parameters passed by the SPM.
482fcb1398fSOlivier Deprez
483fcb1398fSOlivier Deprez   - ``X0``: Virtual address of a buffer shared between EL3 and S-EL0. The
484fcb1398fSOlivier Deprez     buffer will be mapped in the Secure EL1&0 translation regime with read-only
485fcb1398fSOlivier Deprez     memory attributes described earlier.
486fcb1398fSOlivier Deprez
487fcb1398fSOlivier Deprez   - ``X1``: Size of the buffer in bytes.
488fcb1398fSOlivier Deprez
489fcb1398fSOlivier Deprez   - ``X2``: Cookie value (*IMPLEMENTATION DEFINED*).
490fcb1398fSOlivier Deprez
491fcb1398fSOlivier Deprez   - ``X3``: Cookie value (*IMPLEMENTATION DEFINED*).
492fcb1398fSOlivier Deprez
493fcb1398fSOlivier DeprezRuntime Event Delegation
494fcb1398fSOlivier Deprez------------------------
495fcb1398fSOlivier Deprez
496fcb1398fSOlivier DeprezThe SPM receives requests for Secure Partition services through a synchronous
497fcb1398fSOlivier Deprezinvocation (i.e. a SMC from the Non-secure world). These requests are delegated
498fcb1398fSOlivier Deprezto the partition by programming a return from the last
499fcb1398fSOlivier Deprez``MM_SP_EVENT_COMPLETE_AARCH64`` call received from the partition. The last call
500fcb1398fSOlivier Deprezwas made to signal either completion of Secure Partition initialisation or
501fcb1398fSOlivier Deprezcompletion of a partition service request.
502fcb1398fSOlivier Deprez
503fcb1398fSOlivier Deprez``MM_SP_EVENT_COMPLETE_AARCH64``
504fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
505fcb1398fSOlivier Deprez
506fcb1398fSOlivier Deprez- Description
507fcb1398fSOlivier Deprez
508fcb1398fSOlivier Deprez  Signal completion of the last SP service request.
509fcb1398fSOlivier Deprez
510fcb1398fSOlivier Deprez- Parameters
511fcb1398fSOlivier Deprez
512fcb1398fSOlivier Deprez  - **uint32** - Function ID
513fcb1398fSOlivier Deprez
514fcb1398fSOlivier Deprez    - SVC64 Version: **0xC4000061**
515fcb1398fSOlivier Deprez
516fcb1398fSOlivier Deprez  - **int32** - Event Status Code
517fcb1398fSOlivier Deprez
518fcb1398fSOlivier Deprez    Zero or a positive value indicates that the event was handled successfully.
519fcb1398fSOlivier Deprez    The values depend upon the original event that was delegated to the Secure
520fcb1398fSOlivier Deprez    partition. They are described as follows.
521fcb1398fSOlivier Deprez
522fcb1398fSOlivier Deprez    - ``SUCCESS`` : Used to indicate that the Secure Partition was initialised
523fcb1398fSOlivier Deprez      or a runtime request was handled successfully.
524fcb1398fSOlivier Deprez
525fcb1398fSOlivier Deprez    - Any other value greater than 0 is used to pass a specific Event Status
526fcb1398fSOlivier Deprez      code in response to a runtime event.
527fcb1398fSOlivier Deprez
528fcb1398fSOlivier Deprez    A negative value indicates an error. The values of Event Status code depend
529fcb1398fSOlivier Deprez    on the original event.
530fcb1398fSOlivier Deprez
531fcb1398fSOlivier Deprez- Return parameters
532fcb1398fSOlivier Deprez
533fcb1398fSOlivier Deprez  - **int32** - Event ID/Return Code
534fcb1398fSOlivier Deprez
535fcb1398fSOlivier Deprez    Zero or a positive value specifies the unique ID of the event being
536fcb1398fSOlivier Deprez    delegated to the partition by the SPM.
537fcb1398fSOlivier Deprez
538fcb1398fSOlivier Deprez    In the current implementation, this parameter contains the function ID of
539fcb1398fSOlivier Deprez    the ``MM_COMMUNICATE`` SMC. This value indicates to the partition that an
540fcb1398fSOlivier Deprez    event has been delegated to it in response to an ``MM_COMMUNICATE`` request
541fcb1398fSOlivier Deprez    from the Non-secure world.
542fcb1398fSOlivier Deprez
543fcb1398fSOlivier Deprez    A negative value indicates an error. The format of the value is as follows:
544fcb1398fSOlivier Deprez
545fcb1398fSOlivier Deprez    - ``NOT_SUPPORTED``: Function was called from the Non-secure world.
546fcb1398fSOlivier Deprez
547fcb1398fSOlivier Deprez    See `Error Codes`_ for integer values that are associated with each return
548fcb1398fSOlivier Deprez    code.
549fcb1398fSOlivier Deprez
550fcb1398fSOlivier Deprez  - **uint32** - Event Context Address
551fcb1398fSOlivier Deprez
552fcb1398fSOlivier Deprez    Address of a buffer shared between the SPM and Secure Partition to pass
553fcb1398fSOlivier Deprez    event specific information. The format of the data populated in the buffer
554fcb1398fSOlivier Deprez    is implementation defined.
555fcb1398fSOlivier Deprez
556fcb1398fSOlivier Deprez    The buffer is mapped in the Secure EL1&0 translation regime with read-only
557fcb1398fSOlivier Deprez    memory attributes described earlier.
558fcb1398fSOlivier Deprez
559fcb1398fSOlivier Deprez    For the SVC64 version, this parameter is a 64-bit Virtual Address (VA).
560fcb1398fSOlivier Deprez
561fcb1398fSOlivier Deprez    For the SVC32 version, this parameter is a 32-bit Virtual Address (VA).
562fcb1398fSOlivier Deprez
563fcb1398fSOlivier Deprez  - **uint32** - Event context size
564fcb1398fSOlivier Deprez
565fcb1398fSOlivier Deprez    Size of the memory starting at Event Address.
566fcb1398fSOlivier Deprez
567fcb1398fSOlivier Deprez  - **uint32/uint64** - Event Cookie
568fcb1398fSOlivier Deprez
569fcb1398fSOlivier Deprez    This is an optional parameter. If unused its value is SBZ.
570fcb1398fSOlivier Deprez
571fcb1398fSOlivier Deprez- Usage
572fcb1398fSOlivier Deprez
573fcb1398fSOlivier Deprez  This function signals to the SPM that the handling of the last event delegated
574fcb1398fSOlivier Deprez  to a partition has completed. The partition is ready to handle its next event.
575fcb1398fSOlivier Deprez  A return from this function is in response to the next event that will be
576fcb1398fSOlivier Deprez  delegated to the partition. The return parameters describe the next event.
577fcb1398fSOlivier Deprez
578fcb1398fSOlivier Deprez- Caller responsibilities
579fcb1398fSOlivier Deprez
580fcb1398fSOlivier Deprez  A Secure Partition must only call ``MM_SP_EVENT_COMPLETE_AARCH64`` to signal
581fcb1398fSOlivier Deprez  completion of a request that was delegated to it by the SPM.
582fcb1398fSOlivier Deprez
583fcb1398fSOlivier Deprez- Callee responsibilities
584fcb1398fSOlivier Deprez
585fcb1398fSOlivier Deprez  When the SPM receives this call from a Secure Partition, the corresponding
586fcb1398fSOlivier Deprez  syndrome information can be used to return control through an ERET
587fcb1398fSOlivier Deprez  instruction, to the instruction immediately after the call in the Secure
588fcb1398fSOlivier Deprez  Partition context. This syndrome information comprises of general purpose and
589fcb1398fSOlivier Deprez  system register values when the call was made.
590fcb1398fSOlivier Deprez
591fcb1398fSOlivier Deprez  The SPM must save this syndrome information and use it to delegate the next
592fcb1398fSOlivier Deprez  event to the Secure Partition. The return parameters of this interface must
593fcb1398fSOlivier Deprez  specify the properties of the event and be populated in ``X0-X3/W0-W3``
594fcb1398fSOlivier Deprez  registers.
595fcb1398fSOlivier Deprez
596fcb1398fSOlivier DeprezSecure Partition Memory Management
597fcb1398fSOlivier Deprez----------------------------------
598fcb1398fSOlivier Deprez
599fcb1398fSOlivier DeprezA Secure Partition executes at S-EL0, which is an unprivileged Exception Level.
600fcb1398fSOlivier DeprezThe SPM is responsible for enabling access to regions of memory in the system
601fcb1398fSOlivier Deprezaddress map from a Secure Partition. This is done by mapping these regions in
602fcb1398fSOlivier Deprezthe Secure EL1&0 Translation regime with appropriate memory attributes.
603fcb1398fSOlivier DeprezAttributes refer to memory type, permission, cacheability and shareability
604fcb1398fSOlivier Deprezattributes used in the Translation tables. The definitions of these attributes
605fcb1398fSOlivier Deprezand their usage can be found in the `Armv8-A ARM`_ (*Arm DDI 0487*).
606fcb1398fSOlivier Deprez
607fcb1398fSOlivier DeprezAll memory required by the Secure Partition is allocated upfront in the SPM,
608fcb1398fSOlivier Deprezeven before handing over to the Secure Partition for the first time. The initial
609fcb1398fSOlivier Deprezaccess permissions of the memory regions are statically provided by the platform
610fcb1398fSOlivier Deprezport and should allow the Secure Partition to run its initialisation code.
611fcb1398fSOlivier Deprez
612fcb1398fSOlivier DeprezHowever, they might not suit the final needs of the Secure Partition because its
613fcb1398fSOlivier Deprezfinal memory layout might not be known until the Secure Partition initialises
614fcb1398fSOlivier Deprezitself. As the Secure Partition initialises its runtime environment it might,
615fcb1398fSOlivier Deprezfor example, load dynamically some modules. For instance, a Secure Partition
616fcb1398fSOlivier Deprezcould implement a loader for a standard executable file format (e.g. an PE-COFF
617fcb1398fSOlivier Deprezloader for loading executable files at runtime). These executable files will be
618fcb1398fSOlivier Depreza part of the Secure Partition image. The location of various sections in an
619fcb1398fSOlivier Deprezexecutable file and their permission attributes (e.g. read-write data, read-only
620fcb1398fSOlivier Deprezdata and code) will be known only when the file is loaded into memory.
621fcb1398fSOlivier Deprez
622fcb1398fSOlivier DeprezIn this case, the Secure Partition needs a way to change the access permissions
623fcb1398fSOlivier Deprezof its memory regions. The SPM provides this feature through the
624fcb1398fSOlivier Deprez``MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64`` SVC interface. This interface is
625fcb1398fSOlivier Deprezavailable to the Secure Partition during a specific time window: from the first
626fcb1398fSOlivier Deprezentry into the Secure Partition up to the first ``SP_EVENT_COMPLETE`` call that
627fcb1398fSOlivier Deprezsignals the Secure Partition has finished its initialisation. Once the
628fcb1398fSOlivier Deprezinitialisation is complete, the SPM does not allow changes to the memory
629fcb1398fSOlivier Deprezattributes.
630fcb1398fSOlivier Deprez
631fcb1398fSOlivier DeprezThis section describes the standard SVC interface that is implemented by the SPM
632fcb1398fSOlivier Deprezto determine and change permission attributes of memory regions that belong to a
633fcb1398fSOlivier DeprezSecure Partition.
634fcb1398fSOlivier Deprez
635fcb1398fSOlivier Deprez``MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64``
636fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
637fcb1398fSOlivier Deprez
638fcb1398fSOlivier Deprez- Description
639fcb1398fSOlivier Deprez
640fcb1398fSOlivier Deprez  Request the permission attributes of a memory region from S-EL0.
641fcb1398fSOlivier Deprez
642fcb1398fSOlivier Deprez- Parameters
643fcb1398fSOlivier Deprez
644fcb1398fSOlivier Deprez  - **uint32** Function ID
645fcb1398fSOlivier Deprez
646fcb1398fSOlivier Deprez    - SVC64 Version: **0xC4000064**
647fcb1398fSOlivier Deprez
648fcb1398fSOlivier Deprez  - **uint64** Base Address
649fcb1398fSOlivier Deprez
650fcb1398fSOlivier Deprez    This parameter is a 64-bit Virtual Address (VA).
651fcb1398fSOlivier Deprez
652fcb1398fSOlivier Deprez    There are no alignment restrictions on the Base Address. The permission
653fcb1398fSOlivier Deprez    attributes of the translation granule it lies in are returned.
654fcb1398fSOlivier Deprez
655127bd5b1SLevi Yun  - **uint32** Input Page Count
656127bd5b1SLevi Yun
657127bd5b1SLevi Yun    This parameter is the number of translation granule size pages from
658127bd5b1SLevi Yun    *Base Address* whose permission should be returned.
659127bd5b1SLevi Yun    This is calculated as *Input Page count + 1*.
660127bd5b1SLevi Yun    (i.e. If Input Page Count is 0, then it is calculated as 1).
661127bd5b1SLevi Yun
662fcb1398fSOlivier Deprez- Return parameters
663fcb1398fSOlivier Deprez
664fcb1398fSOlivier Deprez  - **int32** - Memory Attributes/Return Code
665fcb1398fSOlivier Deprez
666fcb1398fSOlivier Deprez    On success the format of the Return Code is as follows:
667fcb1398fSOlivier Deprez
668fcb1398fSOlivier Deprez    - Bits[1:0] : Data access permission
669fcb1398fSOlivier Deprez
670fcb1398fSOlivier Deprez      - b'00 : No access
671fcb1398fSOlivier Deprez      - b'01 : Read-Write access
672fcb1398fSOlivier Deprez      - b'10 : Reserved
673fcb1398fSOlivier Deprez      - b'11 : Read-only access
674fcb1398fSOlivier Deprez
675fcb1398fSOlivier Deprez    - Bit[2]: Instruction access permission
676fcb1398fSOlivier Deprez
677fcb1398fSOlivier Deprez      - b'0 : Executable
678fcb1398fSOlivier Deprez      - b'1 : Non-executable
679fcb1398fSOlivier Deprez
680fcb1398fSOlivier Deprez    - Bit[30:3] : Reserved. SBZ.
681fcb1398fSOlivier Deprez
682fcb1398fSOlivier Deprez    - Bit[31]   : Must be 0
683fcb1398fSOlivier Deprez
684fcb1398fSOlivier Deprez    On failure the following error codes are returned:
685fcb1398fSOlivier Deprez
686fcb1398fSOlivier Deprez    - ``INVALID_PARAMETERS``: The Secure Partition is not allowed to access the
687fcb1398fSOlivier Deprez      memory region the Base Address lies in.
688fcb1398fSOlivier Deprez
689fcb1398fSOlivier Deprez    - ``NOT_SUPPORTED`` : The SPM does not support retrieval of attributes of
690fcb1398fSOlivier Deprez      any memory page that is accessible by the Secure Partition, or the
691fcb1398fSOlivier Deprez      function was called from the Non-secure world. Also returned if it is
692fcb1398fSOlivier Deprez      used after ``MM_SP_EVENT_COMPLETE_AARCH64``.
693fcb1398fSOlivier Deprez
694fcb1398fSOlivier Deprez    See `Error Codes`_ for integer values that are associated with each return
695fcb1398fSOlivier Deprez    code.
696fcb1398fSOlivier Deprez
697127bd5b1SLevi Yun  - **uint32** - Output Page Count
698127bd5b1SLevi Yun
699127bd5b1SLevi Yun    On success, the number of translation granule size pages from
700127bd5b1SLevi Yun    the *Base address* whose permissions match those returned in the
701127bd5b1SLevi Yun    *Memory Attributes* output parameter.
702127bd5b1SLevi Yun    This is calculated as *Output Page count + 1*.
703127bd5b1SLevi Yun    (i.e. If Output Page Count is 0, It is calculated as 1).
704127bd5b1SLevi Yun
705127bd5b1SLevi Yun    On failure, It must be zero:
706127bd5b1SLevi Yun
707fcb1398fSOlivier Deprez- Usage
708fcb1398fSOlivier Deprez
709fcb1398fSOlivier Deprez  This function is used to request the permission attributes for S-EL0 on a
710fcb1398fSOlivier Deprez  memory region accessible from a Secure Partition. The size of the memory
711fcb1398fSOlivier Deprez  region is equal to the Translation Granule size used in the Secure EL1&0
712fcb1398fSOlivier Deprez  translation regime. Requests to retrieve other memory region attributes are
713fcb1398fSOlivier Deprez  not currently supported.
714fcb1398fSOlivier Deprez
715fcb1398fSOlivier Deprez- Caller responsibilities
716fcb1398fSOlivier Deprez
717fcb1398fSOlivier Deprez  The caller must obtain the Translation Granule Size of the Secure EL1&0
718fcb1398fSOlivier Deprez  translation regime from the SPM through an implementation defined method.
719fcb1398fSOlivier Deprez
720fcb1398fSOlivier Deprez- Callee responsibilities
721fcb1398fSOlivier Deprez
722fcb1398fSOlivier Deprez  The SPM must not return the memory access controls for a page of memory that
723fcb1398fSOlivier Deprez  is not accessible from a Secure Partition.
724fcb1398fSOlivier Deprez
725fcb1398fSOlivier Deprez``MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64``
726fcb1398fSOlivier Deprez^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
727fcb1398fSOlivier Deprez
728fcb1398fSOlivier Deprez- Description
729fcb1398fSOlivier Deprez
730fcb1398fSOlivier Deprez  Set the permission attributes of a memory region from S-EL0.
731fcb1398fSOlivier Deprez
732fcb1398fSOlivier Deprez- Parameters
733fcb1398fSOlivier Deprez
734fcb1398fSOlivier Deprez  - **uint32** - Function ID
735fcb1398fSOlivier Deprez
736fcb1398fSOlivier Deprez    - SVC64 Version: **0xC4000065**
737fcb1398fSOlivier Deprez
738fcb1398fSOlivier Deprez  - **uint64** - Base Address
739fcb1398fSOlivier Deprez
740fcb1398fSOlivier Deprez    This parameter is a 64-bit Virtual Address (VA).
741fcb1398fSOlivier Deprez
742fcb1398fSOlivier Deprez    The alignment of the Base Address must be greater than or equal to the size
743fcb1398fSOlivier Deprez    of the Translation Granule Size used in the Secure EL1&0 translation
744fcb1398fSOlivier Deprez    regime.
745fcb1398fSOlivier Deprez
746fcb1398fSOlivier Deprez  - **uint32** - Page count
747fcb1398fSOlivier Deprez
748fcb1398fSOlivier Deprez    Number of pages starting from the Base Address whose memory attributes
749fcb1398fSOlivier Deprez    should be changed. The page size is equal to the Translation Granule Size.
750fcb1398fSOlivier Deprez
751fcb1398fSOlivier Deprez  - **uint32** - Memory Access Controls
752fcb1398fSOlivier Deprez
753fcb1398fSOlivier Deprez    - Bits[1:0] : Data access permission
754fcb1398fSOlivier Deprez
755fcb1398fSOlivier Deprez      - b'00 : No access
756fcb1398fSOlivier Deprez      - b'01 : Read-Write access
757fcb1398fSOlivier Deprez      - b'10 : Reserved
758fcb1398fSOlivier Deprez      - b'11 : Read-only access
759fcb1398fSOlivier Deprez
760fcb1398fSOlivier Deprez    - Bit[2] : Instruction access permission
761fcb1398fSOlivier Deprez
762fcb1398fSOlivier Deprez      - b'0 : Executable
763fcb1398fSOlivier Deprez      - b'1 : Non-executable
764fcb1398fSOlivier Deprez
765fcb1398fSOlivier Deprez    - Bits[31:3] : Reserved. SBZ.
766fcb1398fSOlivier Deprez
767fcb1398fSOlivier Deprez    A combination of attributes that mark the region with RW and Executable
768fcb1398fSOlivier Deprez    permissions is prohibited. A request to mark a device memory region with
769fcb1398fSOlivier Deprez    Executable permissions is prohibited.
770fcb1398fSOlivier Deprez
771fcb1398fSOlivier Deprez- Return parameters
772fcb1398fSOlivier Deprez
773fcb1398fSOlivier Deprez  - **int32** - Return Code
774fcb1398fSOlivier Deprez
775fcb1398fSOlivier Deprez    - ``SUCCESS``: The Memory Access Controls were changed successfully.
776fcb1398fSOlivier Deprez
777fcb1398fSOlivier Deprez    - ``DENIED``: The SPM is servicing a request to change the attributes of a
778fcb1398fSOlivier Deprez      memory region that overlaps with the region specified in this request.
779fcb1398fSOlivier Deprez
780fcb1398fSOlivier Deprez    - ``INVALID_PARAMETER``: An invalid combination of Memory Access Controls
781fcb1398fSOlivier Deprez      has been specified. The Base Address is not correctly aligned. The Secure
782fcb1398fSOlivier Deprez      Partition is not allowed to access part or all of the memory region
783fcb1398fSOlivier Deprez      specified in the call.
784fcb1398fSOlivier Deprez
785fcb1398fSOlivier Deprez    - ``NO_MEMORY``: The SPM does not have memory resources to change the
786fcb1398fSOlivier Deprez      attributes of the memory region in the translation tables.
787fcb1398fSOlivier Deprez
788fcb1398fSOlivier Deprez    - ``NOT_SUPPORTED``: The SPM does not permit change of attributes of any
789fcb1398fSOlivier Deprez      memory region that is accessible by the Secure Partition. Function was
790fcb1398fSOlivier Deprez      called from the Non-secure world. Also returned if it is used after
791fcb1398fSOlivier Deprez      ``MM_SP_EVENT_COMPLETE_AARCH64``.
792fcb1398fSOlivier Deprez
793fcb1398fSOlivier Deprez    See `Error Codes`_ for integer values that are associated with each return
794fcb1398fSOlivier Deprez    code.
795fcb1398fSOlivier Deprez
796fcb1398fSOlivier Deprez- Usage
797fcb1398fSOlivier Deprez
798fcb1398fSOlivier Deprez  This function is used to change the permission attributes for S-EL0 on a
799fcb1398fSOlivier Deprez  memory region accessible from a Secure Partition. The size of the memory
800fcb1398fSOlivier Deprez  region is equal to the Translation Granule size used in the Secure EL1&0
801fcb1398fSOlivier Deprez  translation regime. Requests to change other memory region attributes are not
802fcb1398fSOlivier Deprez  currently supported.
803fcb1398fSOlivier Deprez
804fcb1398fSOlivier Deprez  This function is only available at boot time. This interface is revoked after
805fcb1398fSOlivier Deprez  the Secure Partition sends the first ``MM_SP_EVENT_COMPLETE_AARCH64`` to
806fcb1398fSOlivier Deprez  signal that it is initialised and ready to receive run-time requests.
807fcb1398fSOlivier Deprez
808fcb1398fSOlivier Deprez- Caller responsibilities
809fcb1398fSOlivier Deprez
810fcb1398fSOlivier Deprez  The caller must obtain the Translation Granule Size of the Secure EL1&0
811fcb1398fSOlivier Deprez  translation regime from the SPM through an implementation defined method.
812fcb1398fSOlivier Deprez
813fcb1398fSOlivier Deprez- Callee responsibilities
814fcb1398fSOlivier Deprez
815fcb1398fSOlivier Deprez  The SPM must preserve the original memory access controls of the region of
816fcb1398fSOlivier Deprez  memory in case of an unsuccessful call.  The SPM must preserve the consistency
817fcb1398fSOlivier Deprez  of the S-EL1 translation regime if this function is called on different PEs
818fcb1398fSOlivier Deprez  concurrently and the memory regions specified overlap.
819fcb1398fSOlivier Deprez
820fcb1398fSOlivier DeprezError Codes
821fcb1398fSOlivier Deprez-----------
822fcb1398fSOlivier Deprez
823fcb1398fSOlivier Deprez.. csv-table::
824fcb1398fSOlivier Deprez   :header: "Name", "Value"
825fcb1398fSOlivier Deprez
826fcb1398fSOlivier Deprez   ``SUCCESS``,0
827fcb1398fSOlivier Deprez   ``NOT_SUPPORTED``,-1
828fcb1398fSOlivier Deprez   ``INVALID_PARAMETER``,-2
829fcb1398fSOlivier Deprez   ``DENIED``,-3
830fcb1398fSOlivier Deprez   ``NO_MEMORY``,-5
831fcb1398fSOlivier Deprez   ``NOT_PRESENT``,-7
832fcb1398fSOlivier Deprez
833fcb1398fSOlivier Deprez--------------
834fcb1398fSOlivier Deprez
835*854d199bSGovindraj Raja*Copyright (c) 2017-2025, Arm Limited and Contributors. All rights reserved.*
836fcb1398fSOlivier Deprez
837fcb1398fSOlivier Deprez.. _Armv8-A ARM: https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
838fcb1398fSOlivier Deprez.. _instructions in the EDK2 repository: https://github.com/tianocore/edk2-staging/blob/AArch64StandaloneMm/HowtoBuild.MD
839*854d199bSGovindraj Raja.. _Management Mode Interface Specification: https://developer.arm.com/documentation/den0060
840*854d199bSGovindraj Raja.. _SDEI Specification: https://developer.arm.com/documentation/den0054
841fcb1398fSOlivier Deprez.. _SMC Calling Convention: https://developer.arm.com/docs/den0028/latest
842fcb1398fSOlivier Deprez
843fcb1398fSOlivier Deprez.. |Image 1| image:: ../resources/diagrams/secure_sw_stack_tos.png
844fcb1398fSOlivier Deprez.. |Image 2| image:: ../resources/diagrams/secure_sw_stack_sp.png
845