secure-partition-manager-mm.rst 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. Secure Partition Manager (MM)
  2. *****************************
  3. Foreword
  4. ========
  5. This document describes the implementation where the Secure Partition Manager
  6. resides at EL3 and management services run from isolated Secure Partitions at
  7. S-EL0. The communication protocol is established through the Management Mode
  8. (MM) interface.
  9. Background
  10. ==========
  11. In some market segments that primarily deal with client-side devices like mobile
  12. phones, tablets, STBs and embedded devices, a Trusted OS instantiates trusted
  13. applications to provide security services like DRM, secure payment and
  14. authentication. The Global Platform TEE Client API specification defines the API
  15. used by Non-secure world applications to access these services. A Trusted OS
  16. fulfils the requirements of a security service as described above.
  17. Management services are typically implemented at the highest level of privilege
  18. in the system, i.e. EL3 in Trusted Firmware-A (TF-A). The service requirements are
  19. fulfilled by the execution environment provided by TF-A.
  20. The following diagram illustrates the corresponding software stack:
  21. |Image 1|
  22. In other market segments that primarily deal with server-side devices (e.g. data
  23. centres and enterprise servers) the secure software stack typically does not
  24. include a Global Platform Trusted OS. Security functions are accessed through
  25. other interfaces (e.g. ACPI TCG TPM interface, UEFI runtime variable service).
  26. Placement of management and security functions with diverse requirements in a
  27. privileged Exception Level (i.e. EL3 or S-EL1) makes security auditing of
  28. firmware more difficult and does not allow isolation of unrelated services from
  29. each other either.
  30. Introduction
  31. ============
  32. A **Secure Partition** is a software execution environment instantiated in
  33. S-EL0 that can be used to implement simple management and security services.
  34. Since S-EL0 is an unprivileged Exception Level, a Secure Partition relies on
  35. privileged firmware (i.e. TF-A) to be granted access to system and processor
  36. resources. Essentially, it is a software sandbox in the Secure world that runs
  37. under the control of privileged software, provides one or more services and
  38. accesses the following system resources:
  39. - Memory and device regions in the system address map.
  40. - PE system registers.
  41. - A range of synchronous exceptions (e.g. SMC function identifiers).
  42. Note that currently TF-A only supports handling one Secure Partition.
  43. A Secure Partition enables TF-A to implement only the essential secure
  44. services in EL3 and instantiate the rest in a partition in S-EL0.
  45. Furthermore, multiple Secure Partitions can be used to isolate unrelated
  46. services from each other.
  47. The following diagram illustrates the place of a Secure Partition in a typical
  48. Armv8-A software stack. A single or multiple Secure Partitions provide secure
  49. services to software components in the Non-secure world and other Secure
  50. Partitions.
  51. |Image 2|
  52. The TF-A build system is responsible for including the Secure Partition image
  53. in the FIP. During boot, BL2 includes support to authenticate and load the
  54. Secure Partition image. A BL31 component called **Secure Partition Manager
  55. (SPM)** is responsible for managing the partition. This is semantically
  56. similar to a hypervisor managing a virtual machine.
  57. The SPM is responsible for the following actions during boot:
  58. - Allocate resources requested by the Secure Partition.
  59. - Perform architectural and system setup required by the Secure Partition to
  60. fulfil a service request.
  61. - Implement a standard interface that is used for initialising a Secure
  62. Partition.
  63. The SPM is responsible for the following actions during runtime:
  64. - Implement a standard interface that is used by a Secure Partition to fulfil
  65. service requests.
  66. - Implement a standard interface that is used by the Non-secure world for
  67. accessing the services exported by a Secure Partition. A service can be
  68. invoked through a SMC.
  69. Alternatively, a partition can be viewed as a thread of execution running under
  70. the control of the SPM. Hence common programming concepts described below are
  71. applicable to a partition.
  72. Description
  73. ===========
  74. The previous section introduced some general aspects of the software
  75. architecture of a Secure Partition. This section describes the specific choices
  76. made in the current implementation of this software architecture. Subsequent
  77. revisions of the implementation will include a richer set of features that
  78. enable a more flexible architecture.
  79. Building TF-A with Secure Partition support
  80. -------------------------------------------
  81. SPM is supported on the Arm FVP exclusively at the moment. The current
  82. implementation supports inclusion of only a single Secure Partition in which a
  83. service always runs to completion (e.g. the requested services cannot be
  84. preempted to give control back to the Normal world).
  85. It is not currently possible for BL31 to integrate SPM support and a Secure
  86. Payload Dispatcher (SPD) at the same time; they are mutually exclusive. In the
  87. SPM bootflow, a Secure Partition image executing at S-EL0 replaces the Secure
  88. Payload image executing at S-EL1 (e.g. a Trusted OS). Both are referred to as
  89. BL32.
  90. A working prototype of a SP has been implemented by re-purposing the EDK2 code
  91. and tools, leveraging the concept of the *Standalone Management Mode (MM)* in
  92. the UEFI specification (see the PI v1.6 Volume 4: Management Mode Core
  93. Interface). This will be referred to as the *Standalone MM Secure Partition* in
  94. the rest of this document.
  95. To enable SPM support in TF-A, the source code must be compiled with the build
  96. flag ``SPM_MM=1``, along with ``EL3_EXCEPTION_HANDLING=1`` and ``ENABLE_SVE_FOR_NS=0``.
  97. On Arm platforms the build option ``ARM_BL31_IN_DRAM`` must be set to 1. Also, the
  98. location of the binary that contains the BL32 image
  99. (``BL32=path/to/image.bin``) must be specified.
  100. First, build the Standalone MM Secure Partition. To build it, refer to the
  101. `instructions in the EDK2 repository`_.
  102. Then build TF-A with SPM support and include the Standalone MM Secure Partition
  103. image in the FIP:
  104. .. code:: shell
  105. BL32=path/to/standalone/mm/sp BL33=path/to/bl33.bin \
  106. make PLAT=fvp SPM_MM=1 EL3_EXCEPTION_HANDLING=1 ENABLE_SVE_FOR_NS=0 ARM_BL31_IN_DRAM=1 all fip
  107. Describing Secure Partition resources
  108. -------------------------------------
  109. TF-A exports a porting interface that enables a platform to specify the system
  110. resources required by the Secure Partition. Some instructions are given below.
  111. However, this interface is under development and it may change as new features
  112. are implemented.
  113. - A Secure Partition is considered a BL32 image, so the same defines that apply
  114. to BL32 images apply to a Secure Partition: ``BL32_BASE`` and ``BL32_LIMIT``.
  115. - The following defines are needed to allocate space for the translation tables
  116. used by the Secure Partition: ``PLAT_SP_IMAGE_MMAP_REGIONS`` and
  117. ``PLAT_SP_IMAGE_MAX_XLAT_TABLES``.
  118. - The functions ``plat_get_secure_partition_mmap()`` and
  119. ``plat_get_secure_partition_boot_info()`` have to be implemented. The file
  120. ``plat/arm/board/fvp/fvp_common.c`` can be used as an example. It uses the
  121. defines in ``include/plat/arm/common/arm_spm_def.h``.
  122. - ``plat_get_secure_partition_mmap()`` returns an array of mmap regions that
  123. describe the memory regions that the SPM needs to allocate for a Secure
  124. Partition.
  125. - ``plat_get_secure_partition_boot_info()`` returns a
  126. ``spm_mm_boot_info_t`` struct that is populated by the platform
  127. with information about the memory map of the Secure Partition.
  128. For an example of all the changes in context, you may refer to commit
  129. ``e29efeb1b4``, in which the port for FVP was introduced.
  130. Accessing Secure Partition services
  131. -----------------------------------
  132. The `SMC Calling Convention`_ (*Arm DEN 0028B*) describes SMCs as a conduit for
  133. accessing services implemented in the Secure world. The ``MM_COMMUNICATE``
  134. interface defined in the `Management Mode Interface Specification`_ (*Arm DEN
  135. 0060A*) is used to invoke a Secure Partition service as a Fast Call.
  136. The mechanism used to identify a service within the partition depends on the
  137. service implementation. It is assumed that the caller of the service will be
  138. able to discover this mechanism through standard platform discovery mechanisms
  139. like ACPI and Device Trees. For example, *Volume 4: Platform Initialisation
  140. Specification v1.6. Management Mode Core Interface* specifies that a GUID is
  141. used to identify a management mode service. A client populates the GUID in the
  142. ``EFI_MM_COMMUNICATE_HEADER``. The header is populated in the communication
  143. buffer shared with the Secure Partition.
  144. A Fast Call appears to be atomic from the perspective of the caller and returns
  145. when the requested operation has completed. A service invoked through the
  146. ``MM_COMMUNICATE`` SMC will run to completion in the partition on a given CPU.
  147. The SPM is responsible for guaranteeing this behaviour. This means that there
  148. can only be a single outstanding Fast Call in a partition on a given CPU.
  149. Exchanging data with the Secure Partition
  150. -----------------------------------------
  151. The exchange of data between the Non-secure world and the partition takes place
  152. through a shared memory region. The location of data in the shared memory area
  153. is passed as a parameter to the ``MM_COMMUNICATE`` SMC. The shared memory area
  154. is statically allocated by the SPM and is expected to be either implicitly known
  155. to the Non-secure world or discovered through a platform discovery mechanism
  156. e.g. ACPI table or device tree. It is possible for the Non-secure world to
  157. exchange data with a partition only if it has been populated in this shared
  158. memory area. The shared memory area is implemented as per the guidelines
  159. specified in Section 3.2.3 of the `Management Mode Interface Specification`_
  160. (*Arm DEN 0060A*).
  161. The format of data structures used to encapsulate data in the shared memory is
  162. agreed between the Non-secure world and the Secure Partition. For example, in
  163. the `Management Mode Interface specification`_ (*Arm DEN 0060A*), Section 4
  164. describes that the communication buffer shared between the Non-secure world and
  165. the Management Mode (MM) in the Secure world must be of the type
  166. ``EFI_MM_COMMUNICATE_HEADER``. This data structure is defined in *Volume 4:
  167. Platform Initialisation Specification v1.6. Management Mode Core Interface*.
  168. Any caller of a MM service will have to use the ``EFI_MM_COMMUNICATE_HEADER``
  169. data structure.
  170. Runtime model of the Secure Partition
  171. =====================================
  172. This section describes how the Secure Partition interfaces with the SPM.
  173. Interface with SPM
  174. ------------------
  175. In order to instantiate one or more secure services in the Secure Partition in
  176. S-EL0, the SPM should define the following types of interfaces:
  177. - Interfaces that enable access to privileged operations from S-EL0. These
  178. operations typically require access to system resources that are either shared
  179. amongst multiple software components in the Secure world or cannot be directly
  180. accessed from an unprivileged Exception Level.
  181. - Interfaces that establish the control path between the SPM and the Secure
  182. Partition.
  183. This section describes the APIs currently exported by the SPM that enable a
  184. Secure Partition to initialise itself and export its services in S-EL0. These
  185. interfaces are not accessible from the Non-secure world.
  186. Conduit
  187. ^^^^^^^
  188. The `SMC Calling Convention`_ (*Arm DEN 0028B*) specification describes the SMC
  189. and HVC conduits for accessing firmware services and their availability
  190. depending on the implemented Exception levels. In S-EL0, the Supervisor Call
  191. exception (SVC) is the only architectural mechanism available for unprivileged
  192. software to make a request for an operation implemented in privileged software.
  193. Hence, the SVC conduit must be used by the Secure Partition to access interfaces
  194. implemented by the SPM.
  195. A SVC causes an exception to be taken to S-EL1. TF-A assumes ownership of S-EL1
  196. and installs a simple exception vector table in S-EL1 that relays a SVC request
  197. from a Secure Partition as a SMC request to the SPM in EL3. Upon servicing the
  198. SMC request, Trusted Firmware-A returns control directly to S-EL0 through an
  199. ERET instruction.
  200. Calling conventions
  201. ^^^^^^^^^^^^^^^^^^^
  202. The `SMC Calling Convention`_ (*Arm DEN 0028B*) specification describes the
  203. 32-bit and 64-bit calling conventions for the SMC and HVC conduits. The SVC
  204. conduit introduces the concept of SVC32 and SVC64 calling conventions. The SVC32
  205. and SVC64 calling conventions are equivalent to the 32-bit (SMC32) and the
  206. 64-bit (SMC64) calling conventions respectively.
  207. Communication initiated by SPM
  208. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  209. A service request is initiated from the SPM through an exception return
  210. instruction (ERET) to S-EL0. Later, the Secure Partition issues an SVC
  211. instruction to signal completion of the request. Some example use cases are
  212. given below:
  213. - A request to initialise the Secure Partition during system boot.
  214. - A request to handle a runtime service request.
  215. Communication initiated by Secure Partition
  216. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  217. A request is initiated from the Secure Partition by executing a SVC instruction.
  218. An ERET instruction is used by TF-A to return to S-EL0 with the result of the
  219. request.
  220. For instance, a request to perform privileged operations on behalf of a
  221. partition (e.g. management of memory attributes in the translation tables for
  222. the Secure EL1&0 translation regime).
  223. Interfaces
  224. ^^^^^^^^^^
  225. The current implementation reserves function IDs for Fast Calls in the Standard
  226. Secure Service calls range (see `SMC Calling Convention`_ (*Arm DEN 0028B*)
  227. specification) for each API exported by the SPM. This section defines the
  228. function prototypes for each function ID. The function IDs specify whether one
  229. or both of the SVC32 and SVC64 calling conventions can be used to invoke the
  230. corresponding interface.
  231. Secure Partition Event Management
  232. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  233. The Secure Partition provides an Event Management interface that is used by the
  234. SPM to delegate service requests to the Secure Partition. The interface also
  235. allows the Secure Partition to:
  236. - Register with the SPM a service that it provides.
  237. - Indicate completion of a service request delegated by the SPM
  238. Miscellaneous interfaces
  239. ------------------------
  240. ``SPM_MM_VERSION_AARCH32``
  241. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  242. - Description
  243. Returns the version of the interface exported by SPM.
  244. - Parameters
  245. - **uint32** - Function ID
  246. - SVC32 Version: **0x84000060**
  247. - Return parameters
  248. - **int32** - Status
  249. On success, the format of the value is as follows:
  250. - Bit [31]: Must be 0
  251. - Bits [30:16]: Major Version. Must be 0 for this revision of the SPM
  252. interface.
  253. - Bits [15:0]: Minor Version. Must be 1 for this revision of the SPM
  254. interface.
  255. On error, the format of the value is as follows:
  256. - ``NOT_SUPPORTED``: SPM interface is not supported or not available for the
  257. client.
  258. - Usage
  259. This function returns the version of the Secure Partition Manager
  260. implementation. The major version is 0 and the minor version is 1. The version
  261. number is a 31-bit unsigned integer, with the upper 15 bits denoting the major
  262. revision, and the lower 16 bits denoting the minor revision. The following
  263. rules apply to the version numbering:
  264. - Different major revision values indicate possibly incompatible functions.
  265. - For two revisions, A and B, for which the major revision values are
  266. identical, if the minor revision value of revision B is greater than the
  267. minor revision value of revision A, then every function in revision A must
  268. work in a compatible way with revision B. However, it is possible for
  269. revision B to have a higher function count than revision A.
  270. - Implementation responsibilities
  271. If this function returns a valid version number, all the functions that are
  272. described subsequently must be implemented, unless it is explicitly stated
  273. that a function is optional.
  274. See `Error Codes`_ for integer values that are associated with each return
  275. code.
  276. Secure Partition Initialisation
  277. -------------------------------
  278. The SPM is responsible for initialising the architectural execution context to
  279. enable initialisation of a service in S-EL0. The responsibilities of the SPM are
  280. listed below. At the end of initialisation, the partition issues a
  281. ``MM_SP_EVENT_COMPLETE_AARCH64`` call (described later) to signal readiness for
  282. handling requests for services implemented by the Secure Partition. The
  283. initialisation event is executed as a Fast Call.
  284. Entry point invocation
  285. ^^^^^^^^^^^^^^^^^^^^^^
  286. The entry point for service requests that should be handled as Fast Calls is
  287. used as the target of the ERET instruction to start initialisation of the Secure
  288. Partition.
  289. Architectural Setup
  290. ^^^^^^^^^^^^^^^^^^^
  291. At cold boot, system registers accessible from S-EL0 will be in their reset
  292. state unless otherwise specified. The SPM will perform the following
  293. architectural setup to enable execution in S-EL0
  294. MMU setup
  295. ^^^^^^^^^
  296. The platform port of a Secure Partition specifies to the SPM a list of regions
  297. that it needs access to and their attributes. The SPM validates this resource
  298. description and initialises the Secure EL1&0 translation regime as follows.
  299. 1. Device regions are mapped with nGnRE attributes and Execute Never
  300. instruction access permissions.
  301. 2. Code memory regions are mapped with RO data and Executable instruction access
  302. permissions.
  303. 3. Read Only data memory regions are mapped with RO data and Execute Never
  304. instruction access permissions.
  305. 4. Read Write data memory regions are mapped with RW data and Execute Never
  306. instruction access permissions.
  307. 5. If the resource description does not explicitly describe the type of memory
  308. regions then all memory regions will be marked with Code memory region
  309. attributes.
  310. 6. The ``UXN`` and ``PXN`` bits are set for regions that are not executable by
  311. S-EL0 or S-EL1.
  312. System Register Setup
  313. ^^^^^^^^^^^^^^^^^^^^^
  314. System registers that influence software execution in S-EL0 are setup by the SPM
  315. as follows:
  316. 1. ``SCTLR_EL1``
  317. - ``UCI=1``
  318. - ``EOE=0``
  319. - ``WXN=1``
  320. - ``nTWE=1``
  321. - ``nTWI=1``
  322. - ``UCT=1``
  323. - ``DZE=1``
  324. - ``I=1``
  325. - ``UMA=0``
  326. - ``SA0=1``
  327. - ``C=1``
  328. - ``A=1``
  329. - ``M=1``
  330. 2. ``CPACR_EL1``
  331. - ``FPEN=b'11``
  332. 3. ``PSTATE``
  333. - ``D,A,I,F=1``
  334. - ``CurrentEL=0`` (EL0)
  335. - ``SpSel=0`` (Thread mode)
  336. - ``NRW=0`` (AArch64)
  337. General Purpose Register Setup
  338. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  339. SPM will invoke the entry point of a service by executing an ERET instruction.
  340. This transition into S-EL0 is special since it is not in response to a previous
  341. request through a SVC instruction. This is the first entry into S-EL0. The
  342. general purpose register usage at the time of entry will be as specified in the
  343. "Return State" column of Table 3-1 in Section 3.1 "Register use in AArch64 SMC
  344. calls" of the `SMC Calling Convention`_ (*Arm DEN 0028B*) specification. In
  345. addition, certain other restrictions will be applied as described below.
  346. 1. ``SP_EL0``
  347. A non-zero value will indicate that the SPM has initialised the stack pointer
  348. for the current CPU.
  349. The value will be 0 otherwise.
  350. 2. ``X4-X30``
  351. The values of these registers will be 0.
  352. 3. ``X0-X3``
  353. Parameters passed by the SPM.
  354. - ``X0``: Virtual address of a buffer shared between EL3 and S-EL0. The
  355. buffer will be mapped in the Secure EL1&0 translation regime with read-only
  356. memory attributes described earlier.
  357. - ``X1``: Size of the buffer in bytes.
  358. - ``X2``: Cookie value (*IMPLEMENTATION DEFINED*).
  359. - ``X3``: Cookie value (*IMPLEMENTATION DEFINED*).
  360. Runtime Event Delegation
  361. ------------------------
  362. The SPM receives requests for Secure Partition services through a synchronous
  363. invocation (i.e. a SMC from the Non-secure world). These requests are delegated
  364. to the partition by programming a return from the last
  365. ``MM_SP_EVENT_COMPLETE_AARCH64`` call received from the partition. The last call
  366. was made to signal either completion of Secure Partition initialisation or
  367. completion of a partition service request.
  368. ``MM_SP_EVENT_COMPLETE_AARCH64``
  369. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  370. - Description
  371. Signal completion of the last SP service request.
  372. - Parameters
  373. - **uint32** - Function ID
  374. - SVC64 Version: **0xC4000061**
  375. - **int32** - Event Status Code
  376. Zero or a positive value indicates that the event was handled successfully.
  377. The values depend upon the original event that was delegated to the Secure
  378. partition. They are described as follows.
  379. - ``SUCCESS`` : Used to indicate that the Secure Partition was initialised
  380. or a runtime request was handled successfully.
  381. - Any other value greater than 0 is used to pass a specific Event Status
  382. code in response to a runtime event.
  383. A negative value indicates an error. The values of Event Status code depend
  384. on the original event.
  385. - Return parameters
  386. - **int32** - Event ID/Return Code
  387. Zero or a positive value specifies the unique ID of the event being
  388. delegated to the partition by the SPM.
  389. In the current implementation, this parameter contains the function ID of
  390. the ``MM_COMMUNICATE`` SMC. This value indicates to the partition that an
  391. event has been delegated to it in response to an ``MM_COMMUNICATE`` request
  392. from the Non-secure world.
  393. A negative value indicates an error. The format of the value is as follows:
  394. - ``NOT_SUPPORTED``: Function was called from the Non-secure world.
  395. See `Error Codes`_ for integer values that are associated with each return
  396. code.
  397. - **uint32** - Event Context Address
  398. Address of a buffer shared between the SPM and Secure Partition to pass
  399. event specific information. The format of the data populated in the buffer
  400. is implementation defined.
  401. The buffer is mapped in the Secure EL1&0 translation regime with read-only
  402. memory attributes described earlier.
  403. For the SVC64 version, this parameter is a 64-bit Virtual Address (VA).
  404. For the SVC32 version, this parameter is a 32-bit Virtual Address (VA).
  405. - **uint32** - Event context size
  406. Size of the memory starting at Event Address.
  407. - **uint32/uint64** - Event Cookie
  408. This is an optional parameter. If unused its value is SBZ.
  409. - Usage
  410. This function signals to the SPM that the handling of the last event delegated
  411. to a partition has completed. The partition is ready to handle its next event.
  412. A return from this function is in response to the next event that will be
  413. delegated to the partition. The return parameters describe the next event.
  414. - Caller responsibilities
  415. A Secure Partition must only call ``MM_SP_EVENT_COMPLETE_AARCH64`` to signal
  416. completion of a request that was delegated to it by the SPM.
  417. - Callee responsibilities
  418. When the SPM receives this call from a Secure Partition, the corresponding
  419. syndrome information can be used to return control through an ERET
  420. instruction, to the instruction immediately after the call in the Secure
  421. Partition context. This syndrome information comprises of general purpose and
  422. system register values when the call was made.
  423. The SPM must save this syndrome information and use it to delegate the next
  424. event to the Secure Partition. The return parameters of this interface must
  425. specify the properties of the event and be populated in ``X0-X3/W0-W3``
  426. registers.
  427. Secure Partition Memory Management
  428. ----------------------------------
  429. A Secure Partition executes at S-EL0, which is an unprivileged Exception Level.
  430. The SPM is responsible for enabling access to regions of memory in the system
  431. address map from a Secure Partition. This is done by mapping these regions in
  432. the Secure EL1&0 Translation regime with appropriate memory attributes.
  433. Attributes refer to memory type, permission, cacheability and shareability
  434. attributes used in the Translation tables. The definitions of these attributes
  435. and their usage can be found in the `Armv8-A ARM`_ (*Arm DDI 0487*).
  436. All memory required by the Secure Partition is allocated upfront in the SPM,
  437. even before handing over to the Secure Partition for the first time. The initial
  438. access permissions of the memory regions are statically provided by the platform
  439. port and should allow the Secure Partition to run its initialisation code.
  440. However, they might not suit the final needs of the Secure Partition because its
  441. final memory layout might not be known until the Secure Partition initialises
  442. itself. As the Secure Partition initialises its runtime environment it might,
  443. for example, load dynamically some modules. For instance, a Secure Partition
  444. could implement a loader for a standard executable file format (e.g. an PE-COFF
  445. loader for loading executable files at runtime). These executable files will be
  446. a part of the Secure Partition image. The location of various sections in an
  447. executable file and their permission attributes (e.g. read-write data, read-only
  448. data and code) will be known only when the file is loaded into memory.
  449. In this case, the Secure Partition needs a way to change the access permissions
  450. of its memory regions. The SPM provides this feature through the
  451. ``MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64`` SVC interface. This interface is
  452. available to the Secure Partition during a specific time window: from the first
  453. entry into the Secure Partition up to the first ``SP_EVENT_COMPLETE`` call that
  454. signals the Secure Partition has finished its initialisation. Once the
  455. initialisation is complete, the SPM does not allow changes to the memory
  456. attributes.
  457. This section describes the standard SVC interface that is implemented by the SPM
  458. to determine and change permission attributes of memory regions that belong to a
  459. Secure Partition.
  460. ``MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64``
  461. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  462. - Description
  463. Request the permission attributes of a memory region from S-EL0.
  464. - Parameters
  465. - **uint32** Function ID
  466. - SVC64 Version: **0xC4000064**
  467. - **uint64** Base Address
  468. This parameter is a 64-bit Virtual Address (VA).
  469. There are no alignment restrictions on the Base Address. The permission
  470. attributes of the translation granule it lies in are returned.
  471. - Return parameters
  472. - **int32** - Memory Attributes/Return Code
  473. On success the format of the Return Code is as follows:
  474. - Bits[1:0] : Data access permission
  475. - b'00 : No access
  476. - b'01 : Read-Write access
  477. - b'10 : Reserved
  478. - b'11 : Read-only access
  479. - Bit[2]: Instruction access permission
  480. - b'0 : Executable
  481. - b'1 : Non-executable
  482. - Bit[30:3] : Reserved. SBZ.
  483. - Bit[31] : Must be 0
  484. On failure the following error codes are returned:
  485. - ``INVALID_PARAMETERS``: The Secure Partition is not allowed to access the
  486. memory region the Base Address lies in.
  487. - ``NOT_SUPPORTED`` : The SPM does not support retrieval of attributes of
  488. any memory page that is accessible by the Secure Partition, or the
  489. function was called from the Non-secure world. Also returned if it is
  490. used after ``MM_SP_EVENT_COMPLETE_AARCH64``.
  491. See `Error Codes`_ for integer values that are associated with each return
  492. code.
  493. - Usage
  494. This function is used to request the permission attributes for S-EL0 on a
  495. memory region accessible from a Secure Partition. The size of the memory
  496. region is equal to the Translation Granule size used in the Secure EL1&0
  497. translation regime. Requests to retrieve other memory region attributes are
  498. not currently supported.
  499. - Caller responsibilities
  500. The caller must obtain the Translation Granule Size of the Secure EL1&0
  501. translation regime from the SPM through an implementation defined method.
  502. - Callee responsibilities
  503. The SPM must not return the memory access controls for a page of memory that
  504. is not accessible from a Secure Partition.
  505. ``MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64``
  506. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  507. - Description
  508. Set the permission attributes of a memory region from S-EL0.
  509. - Parameters
  510. - **uint32** - Function ID
  511. - SVC64 Version: **0xC4000065**
  512. - **uint64** - Base Address
  513. This parameter is a 64-bit Virtual Address (VA).
  514. The alignment of the Base Address must be greater than or equal to the size
  515. of the Translation Granule Size used in the Secure EL1&0 translation
  516. regime.
  517. - **uint32** - Page count
  518. Number of pages starting from the Base Address whose memory attributes
  519. should be changed. The page size is equal to the Translation Granule Size.
  520. - **uint32** - Memory Access Controls
  521. - Bits[1:0] : Data access permission
  522. - b'00 : No access
  523. - b'01 : Read-Write access
  524. - b'10 : Reserved
  525. - b'11 : Read-only access
  526. - Bit[2] : Instruction access permission
  527. - b'0 : Executable
  528. - b'1 : Non-executable
  529. - Bits[31:3] : Reserved. SBZ.
  530. A combination of attributes that mark the region with RW and Executable
  531. permissions is prohibited. A request to mark a device memory region with
  532. Executable permissions is prohibited.
  533. - Return parameters
  534. - **int32** - Return Code
  535. - ``SUCCESS``: The Memory Access Controls were changed successfully.
  536. - ``DENIED``: The SPM is servicing a request to change the attributes of a
  537. memory region that overlaps with the region specified in this request.
  538. - ``INVALID_PARAMETER``: An invalid combination of Memory Access Controls
  539. has been specified. The Base Address is not correctly aligned. The Secure
  540. Partition is not allowed to access part or all of the memory region
  541. specified in the call.
  542. - ``NO_MEMORY``: The SPM does not have memory resources to change the
  543. attributes of the memory region in the translation tables.
  544. - ``NOT_SUPPORTED``: The SPM does not permit change of attributes of any
  545. memory region that is accessible by the Secure Partition. Function was
  546. called from the Non-secure world. Also returned if it is used after
  547. ``MM_SP_EVENT_COMPLETE_AARCH64``.
  548. See `Error Codes`_ for integer values that are associated with each return
  549. code.
  550. - Usage
  551. This function is used to change the permission attributes for S-EL0 on a
  552. memory region accessible from a Secure Partition. The size of the memory
  553. region is equal to the Translation Granule size used in the Secure EL1&0
  554. translation regime. Requests to change other memory region attributes are not
  555. currently supported.
  556. This function is only available at boot time. This interface is revoked after
  557. the Secure Partition sends the first ``MM_SP_EVENT_COMPLETE_AARCH64`` to
  558. signal that it is initialised and ready to receive run-time requests.
  559. - Caller responsibilities
  560. The caller must obtain the Translation Granule Size of the Secure EL1&0
  561. translation regime from the SPM through an implementation defined method.
  562. - Callee responsibilities
  563. The SPM must preserve the original memory access controls of the region of
  564. memory in case of an unsuccessful call.  The SPM must preserve the consistency
  565. of the S-EL1 translation regime if this function is called on different PEs
  566. concurrently and the memory regions specified overlap.
  567. Error Codes
  568. -----------
  569. .. csv-table::
  570. :header: "Name", "Value"
  571. ``SUCCESS``,0
  572. ``NOT_SUPPORTED``,-1
  573. ``INVALID_PARAMETER``,-2
  574. ``DENIED``,-3
  575. ``NO_MEMORY``,-5
  576. ``NOT_PRESENT``,-7
  577. --------------
  578. *Copyright (c) 2017-2021, Arm Limited and Contributors. All rights reserved.*
  579. .. _Armv8-A ARM: https://developer.arm.com/docs/ddi0487/latest/arm-architecture-reference-manual-armv8-for-armv8-a-architecture-profile
  580. .. _instructions in the EDK2 repository: https://github.com/tianocore/edk2-staging/blob/AArch64StandaloneMm/HowtoBuild.MD
  581. .. _Management Mode Interface Specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0060a/DEN0060A_ARM_MM_Interface_Specification.pdf
  582. .. _SDEI Specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0054a/ARM_DEN0054A_Software_Delegated_Exception_Interface.pdf
  583. .. _SMC Calling Convention: https://developer.arm.com/docs/den0028/latest
  584. .. |Image 1| image:: ../resources/diagrams/secure_sw_stack_tos.png
  585. .. |Image 2| image:: ../resources/diagrams/secure_sw_stack_sp.png