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