1RMM-EL3 Communication interface 2******************************* 3 4This document defines the communication interface between RMM and EL3. 5There are two parts in this interface: the boot interface and the runtime 6interface. 7 8The Boot Interface defines the ABI between EL3 and RMM when the CPU enters 9R-EL2 for the first time after boot. The cold boot interface defines the ABI 10for the cold boot path and the warm boot interface defines the same for the 11warm path. 12 13The RMM-EL3 runtime interface defines the ABI for EL3 services which can be 14invoked by RMM as well as the register save-restore convention when handling an 15SMC call from NS. 16 17The below sections discuss these interfaces more in detail. 18 19.. _rmm_el3_ifc_versioning: 20 21RMM-EL3 Interface versioning 22____________________________ 23 24The RMM Boot and Runtime Interface uses a version number to check 25compatibility with the register arguments passed as part of Boot Interface and 26RMM-EL3 runtime interface. 27 28The Boot Manifest, discussed later in section :ref:`rmm_el3_boot_manifest`, 29uses a separate version number but with the same scheme. 30 31The version number is a 32-bit type with the following fields: 32 33.. csv-table:: 34 :header: "Bits", "Value" 35 36 [0:15],``VERSION_MINOR`` 37 [16:30],``VERSION_MAJOR`` 38 [31],RES0 39 40The version numbers are sequentially increased and the rules for updating them 41are explained below: 42 43 - ``VERSION_MAJOR``: This value is increased when changes break 44 compatibility with previous versions. If the changes 45 on the ABI are compatible with the previous one, ``VERSION_MAJOR`` 46 remains unchanged. 47 48 - ``VERSION_MINOR``: This value is increased on any change that is backwards 49 compatible with the previous version. When ``VERSION_MAJOR`` is increased, 50 ``VERSION_MINOR`` must be set to 0. 51 52 - ``RES0``: Bit 31 of the version number is reserved 0 as to maintain 53 consistency with the versioning schemes used in other parts of RMM. 54 55This document specifies the 0.2 version of Boot Interface ABI and RMM-EL3 56services specification and the 0.2 version of the Boot Manifest. 57 58.. _rmm_el3_boot_interface: 59 60RMM Boot Interface 61__________________ 62 63This section deals with the Boot Interface part of the specification. 64 65One of the goals of the Boot Interface is to allow EL3 firmware to pass 66down into RMM certain platform specific information dynamically. This allows 67RMM to be less platform dependent and be more generic across platform 68variations. It also allows RMM to be decoupled from the other boot loader 69images in the boot sequence and remain agnostic of any particular format used 70for configuration files. 71 72The Boot Interface ABI defines a set of register conventions and 73also a memory based manifest file to pass information from EL3 to RMM. The 74Boot Manifest and the associated platform data in it can be dynamically created 75by EL3 and there is no restriction on how the data can be obtained (e.g by DTB, 76hoblist or other). 77 78The register convention and the manifest are versioned separately to manage 79future enhancements and compatibility. 80 81RMM completes the boot by issuing the ``RMM_BOOT_COMPLETE`` SMC (0xC40001CF) 82back to EL3. After the RMM has finished the boot process, it can only be 83entered from EL3 as part of RMI handling. 84 85If RMM returns an error during boot (in any CPU), then RMM must not be entered 86from any CPU. 87 88.. _rmm_cold_boot_interface: 89 90Cold Boot Interface 91~~~~~~~~~~~~~~~~~~~ 92 93During cold boot RMM expects the following register values: 94 95.. csv-table:: 96 :header: "Register", "Value" 97 :widths: 1, 5 98 99 x0,Linear index of this PE. This index starts from 0 and must be less than the maximum number of CPUs to be supported at runtime (see x2). 100 x1,Version for this Boot Interface as defined in :ref:`rmm_el3_ifc_versioning`. 101 x2,Maximum number of CPUs to be supported at runtime. RMM should ensure that it can support this maximum number. 102 x3,Base address for the shared buffer used for communication between EL3 firmware and RMM. This buffer must be of 4KB size (1 page). The Boot Manifest must be present at the base of this shared buffer during cold boot. 103 104During cold boot, EL3 firmware needs to allocate a 4KB page that will be 105passed to RMM in x3. This memory will be used as shared buffer for communication 106between EL3 and RMM. It must be assigned to Realm world and must be mapped with 107Normal memory attributes (IWB-OWB-ISH) at EL3. At boot, this memory will be 108used to populate the Boot Manifest. Since the Boot Manifest can be accessed by 109RMM prior to enabling its MMU, EL3 must ensure that proper cache maintenance 110operations are performed after the Boot Manifest is populated. 111 112EL3 should also ensure that this shared buffer is always available for use by RMM 113during the lifetime of the system and that it can be used for runtime 114communication between RMM and EL3. For example, when RMM invokes attestation 115service commands in EL3, this buffer can be used to exchange data between RMM 116and EL3. It is also allowed for RMM to invoke runtime services provided by EL3 117utilizing this buffer during the boot phase, prior to return back to EL3 via 118RMM_BOOT_COMPLETE SMC. 119 120RMM should map this memory page into its Stage 1 page-tables using Normal 121memory attributes. 122 123During runtime, it is the RMM which initiates any communication with EL3. If that 124communication requires the use of the shared area, it is expected that RMM needs 125to do the necessary concurrency protection to prevent the use of the same buffer 126by other PEs. 127 128The following sequence diagram shows how a generic EL3 Firmware would boot RMM. 129 130.. image:: ../resources/diagrams/rmm_cold_boot_generic.png 131 132Warm Boot Interface 133~~~~~~~~~~~~~~~~~~~ 134 135At warm boot, RMM is already initialized and only some per-CPU initialization 136is still pending. The only argument that is required by RMM at this stage is 137the CPU Id, which will be passed through register x0 whilst x1 to x3 are RES0. 138This is summarized in the following table: 139 140.. csv-table:: 141 :header: "Register", "Value" 142 :widths: 1, 5 143 144 x0,Linear index of this PE. This index starts from 0 and must be less than the maximum number of CPUs to be supported at runtime (see x2). 145 x1 - x3,RES0 146 147Boot error handling and return values 148~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 149 150After boot up and initialization, RMM returns control back to EL3 through a 151``RMM_BOOT_COMPLETE`` SMC call. The only argument of this SMC call will 152be returned in x1 and it will encode a signed integer with the error reason 153as per the following table: 154 155.. csv-table:: 156 :header: "Error code", "Description", "ID" 157 :widths: 2 4 1 158 159 ``E_RMM_BOOT_SUCCESS``,Boot successful,0 160 ``E_RMM_BOOT_ERR_UNKNOWN``,Unknown error,-1 161 ``E_RMM_BOOT_VERSION_NOT_VALID``,Boot Interface version reported by EL3 is not supported by RMM,-2 162 ``E_RMM_BOOT_CPUS_OUT_OF_RANGE``,Number of CPUs reported by EL3 larger than maximum supported by RMM,-3 163 ``E_RMM_BOOT_CPU_ID_OUT_OF_RANGE``,Current CPU Id is higher or equal than the number of CPUs supported by RMM,-4 164 ``E_RMM_BOOT_INVALID_SHARED_BUFFER``,Invalid pointer to shared memory area,-5 165 ``E_RMM_BOOT_MANIFEST_VERSION_NOT_SUPPORTED``,Version reported by the Boot Manifest not supported by RMM,-6 166 ``E_RMM_BOOT_MANIFEST_DATA_ERROR``,Error parsing core Boot Manifest,-7 167 168For any error detected in RMM during cold or warm boot, RMM will return back to 169EL3 using ``RMM_BOOT_COMPLETE`` SMC with an appropriate error code. It is 170expected that EL3 will take necessary action to disable Realm world for further 171entry from NS Host on receiving an error. This will be done across all the PEs 172in the system so as to present a symmetric view to the NS Host. Any further 173warm boot by any PE should not enter RMM using the warm boot interface. 174 175.. _rmm_el3_boot_manifest: 176 177Boot Manifest 178~~~~~~~~~~~~~ 179 180During cold boot, EL3 Firmware passes a memory Boot Manifest to RMM containing 181platform information. 182 183This Boot Manifest is versioned independently of the Boot Interface, to help 184evolve the former independent of the latter. 185The current version for the Boot Manifest is ``v0.2`` and the rules explained 186in :ref:`rmm_el3_ifc_versioning` apply on this version as well. 187 188The Boot Manifest v0.2 has the following fields: 189 190 - version : Version of the Manifest (v0.2) 191 - plat_data : Pointer to the platform specific data and not specified by this 192 document. These data are optional and can be NULL. 193 - plat_dram : Structure encoding the NS DRAM information on the platform. This 194 field is also optional and platform can choose to zero out this structure if 195 RMM does not need EL3 to send this information during the boot. 196 197For the current version of the Boot Manifest, the core manifest contains a pointer 198to the platform data. EL3 must ensure that the whole Boot Manifest, including 199the platform data, if available, fits inside the RMM EL3 shared buffer. 200 201For the data structure specification of Boot Manifest, refer to 202:ref:`rmm_el3_manifest_struct` 203 204.. _runtime_services_and_interface: 205 206RMM-EL3 Runtime Interface 207__________________________ 208 209This section defines the RMM-EL3 runtime interface which specifies the ABI for 210EL3 services expected by RMM at runtime as well as the register save and 211restore convention between EL3 and RMM as part of RMI call handling. It is 212important to note that RMM is allowed to invoke EL3-RMM runtime interface 213services during the boot phase as well. The EL3 runtime service handling must 214not result in a world switch to another world unless specified. Both the RMM 215and EL3 are allowed to make suitable optimizations based on this assumption. 216 217If the interface requires the use of memory, then the memory references should 218be within the shared buffer communicated as part of the boot interface. See 219:ref:`rmm_cold_boot_interface` for properties of this shared buffer which both 220EL3 and RMM must adhere to. 221 222RMM-EL3 runtime service return codes 223~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 224 225The return codes from EL3 to RMM is a 32 bit signed integer which encapsulates 226error condition as described in the following table: 227 228.. csv-table:: 229 :header: "Error code", "Description", "ID" 230 :widths: 2 4 1 231 232 ``E_RMM_OK``,No errors detected,0 233 ``E_RMM_UNK``,Unknown/Generic error,-1 234 ``E_RMM_BAD_ADDR``,The value of an address used as argument was invalid,-2 235 ``E_RMM_BAD_PAS``,Incorrect PAS,-3 236 ``E_RMM_NOMEM``,Not enough memory to perform an operation,-4 237 ``E_RMM_INVAL``,The value of an argument was invalid,-5 238 239If multiple failure conditions are detected in an RMM to EL3 command, then EL3 240is allowed to return an error code corresponding to any of the failure 241conditions. 242 243RMM-EL3 runtime services 244~~~~~~~~~~~~~~~~~~~~~~~~ 245 246The following table summarizes the RMM runtime services that need to be 247implemented by EL3 Firmware. 248 249.. csv-table:: 250 :header: "FID", "Command" 251 :widths: 2 5 252 253 0xC400018F,``RMM_RMI_REQ_COMPLETE`` 254 0xC40001B0,``RMM_GTSI_DELEGATE`` 255 0xC40001B1,``RMM_GTSI_UNDELEGATE`` 256 0xC40001B2,``RMM_ATTEST_GET_REALM_KEY`` 257 0xC40001B3,``RMM_ATTEST_GET_PLAT_TOKEN`` 258 259RMM_RMI_REQ_COMPLETE command 260============================ 261 262Notifies the completion of an RMI call to the Non-Secure world. 263 264This call is the only function currently in RMM-EL3 runtime interface which 265results in a world switch to NS. This call is the reply to the original RMI 266call and it is forwarded by EL3 to the NS world. 267 268FID 269--- 270 271``0xC400018F`` 272 273Input values 274------------ 275 276.. csv-table:: 277 :header: "Name", "Register", "Field", "Type", "Description" 278 :widths: 1 1 1 1 5 279 280 fid,x0,[63:0],UInt64,Command FID 281 err_code,x1,[63:0],RmiCommandReturnCode,Error code returned by the RMI service invoked by NS World. See Realm Management Monitor specification for more info 282 283Output values 284------------- 285 286This call does not return. 287 288Failure conditions 289------------------ 290 291Since this call does not return to RMM, there is no failure condition which 292can be notified back to RMM. 293 294RMM_GTSI_DELEGATE command 295========================= 296 297Delegate a memory granule by changing its PAS from Non-Secure to Realm. 298 299FID 300--- 301 302``0xC40001B0`` 303 304Input values 305------------ 306 307.. csv-table:: 308 :header: "Name", "Register", "Field", "Type", "Description" 309 :widths: 1 1 1 1 5 310 311 fid,x0,[63:0],UInt64,Command FID 312 base_pa,x1,[63:0],Address,PA of the start of the granule to be delegated 313 314Output values 315------------- 316 317.. csv-table:: 318 :header: "Name", "Register", "Field", "Type", "Description" 319 :widths: 1 1 1 2 4 320 321 Result,x0,[63:0],Error Code,Command return status 322 323Failure conditions 324------------------ 325 326The table below shows all the possible error codes returned in ``Result`` upon 327a failure. The errors are ordered by condition check. 328 329.. csv-table:: 330 :header: "ID", "Condition" 331 :widths: 1 5 332 333 ``E_RMM_BAD_ADDR``,``PA`` does not correspond to a valid granule address 334 ``E_RMM_BAD_PAS``,The granule pointed by ``PA`` does not belong to Non-Secure PAS 335 ``E_RMM_OK``,No errors detected 336 337RMM_GTSI_UNDELEGATE command 338=========================== 339 340Undelegate a memory granule by changing its PAS from Realm to Non-Secure. 341 342FID 343--- 344 345``0xC40001B1`` 346 347Input values 348------------ 349 350.. csv-table:: 351 :header: "Name", "Register", "Field", "Type", "Description" 352 :widths: 1 1 1 1 5 353 354 fid,x0,[63:0],UInt64,Command FID 355 base_pa,x1,[63:0],Address,PA of the start of the granule to be undelegated 356 357Output values 358------------- 359 360.. csv-table:: 361 :header: "Name", "Register", "Field", "Type", "Description" 362 :widths: 1 1 1 2 4 363 364 Result,x0,[63:0],Error Code,Command return status 365 366Failure conditions 367------------------ 368 369The table below shows all the possible error codes returned in ``Result`` upon 370a failure. The errors are ordered by condition check. 371 372.. csv-table:: 373 :header: "ID", "Condition" 374 :widths: 1 5 375 376 ``E_RMM_BAD_ADDR``,``PA`` does not correspond to a valid granule address 377 ``E_RMM_BAD_PAS``,The granule pointed by ``PA`` does not belong to Realm PAS 378 ``E_RMM_OK``,No errors detected 379 380RMM_ATTEST_GET_REALM_KEY command 381================================ 382 383Retrieve the Realm Attestation Token Signing key from EL3. 384 385FID 386--- 387 388``0xC40001B2`` 389 390Input values 391------------ 392 393.. csv-table:: 394 :header: "Name", "Register", "Field", "Type", "Description" 395 :widths: 1 1 1 1 5 396 397 fid,x0,[63:0],UInt64,Command FID 398 buf_pa,x1,[63:0],Address,PA where the Realm Attestation Key must be stored by EL3. The PA must belong to the shared buffer 399 buf_size,x2,[63:0],Size,Size in bytes of the Realm Attestation Key buffer. ``bufPa + bufSize`` must lie within the shared buffer 400 ecc_curve,x3,[63:0],Enum,Type of the elliptic curve to which the requested attestation key belongs to. See :ref:`ecc_curves` 401 402Output values 403------------- 404 405.. csv-table:: 406 :header: "Name", "Register", "Field", "Type", "Description" 407 :widths: 1 1 1 1 5 408 409 Result,x0,[63:0],Error Code,Command return status 410 keySize,x1,[63:0],Size,Size of the Realm Attestation Key 411 412Failure conditions 413------------------ 414 415The table below shows all the possible error codes returned in ``Result`` upon 416a failure. The errors are ordered by condition check. 417 418.. csv-table:: 419 :header: "ID", "Condition" 420 :widths: 1 5 421 422 ``E_RMM_BAD_ADDR``,``PA`` is outside the shared buffer 423 ``E_RMM_INVAL``,``PA + BSize`` is outside the shared buffer 424 ``E_RMM_INVAL``,``Curve`` is not one of the listed in :ref:`ecc_curves` 425 ``E_RMM_UNK``,An unknown error occurred whilst processing the command 426 ``E_RMM_OK``,No errors detected 427 428.. _ecc_curves: 429 430Supported ECC Curves 431-------------------- 432 433.. csv-table:: 434 :header: "ID", "Curve" 435 :widths: 1 5 436 437 0,ECC SECP384R1 438 439RMM_ATTEST_GET_PLAT_TOKEN command 440================================= 441 442Retrieve the Platform Token from EL3. 443 444FID 445--- 446 447``0xC40001B3`` 448 449Input values 450------------ 451 452.. csv-table:: 453 :header: "Name", "Register", "Field", "Type", "Description" 454 :widths: 1 1 1 1 5 455 456 fid,x0,[63:0],UInt64,Command FID 457 buf_pa,x1,[63:0],Address,PA of the platform attestation token. The challenge object is passed in this buffer. The PA must belong to the shared buffer 458 buf_size,x2,[63:0],Size,Size in bytes of the platform attestation token buffer. ``bufPa + bufSize`` must lie within the shared buffer 459 c_size,x3,[63:0],Size,Size in bytes of the challenge object. It corresponds to the size of one of the defined SHA algorithms 460 461Output values 462------------- 463 464.. csv-table:: 465 :header: "Name", "Register", "Field", "Type", "Description" 466 :widths: 1 1 1 1 5 467 468 Result,x0,[63:0],Error Code,Command return status 469 tokenSize,x1,[63:0],Size,Size of the platform token 470 471Failure conditions 472------------------ 473 474The table below shows all the possible error codes returned in ``Result`` upon 475a failure. The errors are ordered by condition check. 476 477.. csv-table:: 478 :header: "ID", "Condition" 479 :widths: 1 5 480 481 ``E_RMM_BAD_ADDR``,``PA`` is outside the shared buffer 482 ``E_RMM_INVAL``,``PA + BSize`` is outside the shared buffer 483 ``E_RMM_INVAL``,``CSize`` does not represent the size of a supported SHA algorithm 484 ``E_RMM_UNK``,An unknown error occurred whilst processing the command 485 ``E_RMM_OK``,No errors detected 486 487RMM-EL3 world switch register save restore convention 488_____________________________________________________ 489 490As part of NS world switch, EL3 is expected to maintain a register context 491specific to each world and will save and restore the registers 492appropriately. This section captures the contract between EL3 and RMM on the 493register set to be saved and restored. 494 495EL3 must maintain a separate register context for the following: 496 497 #. General purpose registers (x0-x30) and ``sp_el0``, ``sp_el2`` stack pointers 498 #. EL2 system register context for all enabled features by EL3. These include system registers with the ``_EL2`` prefix. The EL2 physical and virtual timer registers must not be included in this. 499 500As part of SMC forwarding between the NS world and Realm world, EL3 allows x0-x7 to be passed 501as arguments to Realm and x0-x4 to be used for return arguments back to Non Secure. 502As per SMCCCv1.2, x4 must be preserved if not being used as return argument by the SMC function 503and it is the responsibility of RMM to preserve this or use this as a return argument. 504EL3 will always copy x0-x4 from Realm context to NS Context. 505 506EL3 must save and restore the following as part of world switch: 507 #. EL2 system registers with the exception of ``zcr_el2`` register. 508 #. PAuth key registers (APIA, APIB, APDA, APDB, APGA). 509 510EL3 will not save some registers as mentioned in the below list. It is the 511responsibility of RMM to ensure that these are appropriately saved if the 512Realm World makes use of them: 513 514 #. FP/SIMD registers 515 #. SVE registers 516 #. SME registers 517 #. EL1/0 registers with the exception of PAuth key registers as mentioned above. 518 #. zcr_el2 register. 519 520It is essential that EL3 honors this contract to maintain the Confidentiality and integrity 521of the Realm world. 522 523SMCCC v1.3 allows NS world to specify whether SVE context is in use. In this 524case, RMM could choose to not save the incoming SVE context but must ensure 525to clear SVE registers if they have been used in Realm World. The same applies 526to SME registers. 527 528Types 529_____ 530 531.. _rmm_el3_manifest_struct: 532 533RMM-EL3 Boot Manifest structure 534~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 535 536The RMM-EL3 Boot Manifest v0.2 structure contains platform boot information passed 537from EL3 to RMM. The size of the Boot Manifest is 40 bytes. 538 539The members of the RMM-EL3 Boot Manifest structure are shown in the following 540table: 541 542+-----------+--------+----------------+----------------------------------------+ 543| Name | Offset | Type | Description | 544+===========+========+================+========================================+ 545| version | 0 | uint32_t | Boot Manifest version | 546+-----------+--------+----------------+----------------------------------------+ 547| padding | 4 | uint32_t | Reserved, set to 0 | 548+-----------+--------+----------------+----------------------------------------+ 549| plat_data | 8 | uintptr_t | Pointer to Platform Data section | 550+-----------+--------+----------------+----------------------------------------+ 551| plat_dram | 16 | ns_dram_info | NS DRAM Layout Info structure | 552+-----------+--------+----------------+----------------------------------------+ 553 554.. _ns_dram_info_struct: 555 556NS DRAM Layout Info structure 557~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 558 559NS DRAM Layout Info structure contains information about platform Non-secure 560DRAM layout. The members of this structure are shown in the table below: 561 562+-----------+--------+----------------+----------------------------------------+ 563| Name | Offset | Type | Description | 564+===========+========+================+========================================+ 565| num_banks | 0 | uint64_t | Number of NS DRAM banks | 566+-----------+--------+----------------+----------------------------------------+ 567| banks | 8 | ns_dram_bank * | Pointer to 'ns_dram_bank'[] array | 568+-----------+--------+----------------+----------------------------------------+ 569| checksum | 16 | uint64_t | Checksum | 570+-----------+--------+----------------+----------------------------------------+ 571 572Checksum is calculated as two's complement sum of 'num_banks', 'banks' pointer 573and DRAM banks data array pointed by it. 574 575.. _ns_dram_bank_struct: 576 577NS DRAM Bank structure 578~~~~~~~~~~~~~~~~~~~~~~ 579 580NS DRAM Bank structure contains information about each Non-secure DRAM bank: 581 582+-----------+--------+----------------+----------------------------------------+ 583| Name | Offset | Type | Description | 584+===========+========+================+========================================+ 585| base | 0 | uintptr_t | Base address | 586+-----------+--------+----------------+----------------------------------------+ 587| size | 8 | uint64_t | Size of bank in bytes | 588+-----------+--------+----------------+----------------------------------------+ 589 590 591 592