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