xref: /rk3399_ARM-atf/docs/design/firmware-design.rst (revision ee87353cc41245023e5cf858b6715c5c5cbdc234)
18aa05055SPaul BeesleyFirmware Design
28aa05055SPaul Beesley===============
340d553cfSPaul Beesley
440d553cfSPaul BeesleyTrusted Firmware-A (TF-A) implements a subset of the Trusted Board Boot
534760951SPaul BeesleyRequirements (TBBR) Platform Design Document (PDD) for Arm reference
634760951SPaul Beesleyplatforms.
734760951SPaul Beesley
834760951SPaul BeesleyThe TBB sequence starts when the platform is powered on and runs up
940d553cfSPaul Beesleyto the stage where it hands-off control to firmware running in the normal
1040d553cfSPaul Beesleyworld in DRAM. This is the cold boot path.
1140d553cfSPaul Beesley
123be6b4fbSManish V BadarkheTF-A also implements the `PSCI`_ as a runtime service. PSCI is the interface
133be6b4fbSManish V Badarkhefrom normal world software to firmware implementing power management use-cases
143be6b4fbSManish V Badarkhe(for example, secondary CPU boot, hotplug and idle). Normal world software can
153be6b4fbSManish V Badarkheaccess TF-A runtime services via the Arm SMC (Secure Monitor Call) instruction.
163be6b4fbSManish V BadarkheThe SMC instruction must be used as mandated by the SMC Calling Convention
173be6b4fbSManish V Badarkhe(`SMCCC`_).
1840d553cfSPaul Beesley
1940d553cfSPaul BeesleyTF-A implements a framework for configuring and managing interrupts generated
2040d553cfSPaul Beesleyin either security state. The details of the interrupt management framework
2134760951SPaul Beesleyand its design can be found in :ref:`Interrupt Management Framework`.
2240d553cfSPaul Beesley
2340d553cfSPaul BeesleyTF-A also implements a library for setting up and managing the translation
2434760951SPaul Beesleytables. The details of this library can be found in
2534760951SPaul Beesley:ref:`Translation (XLAT) Tables Library`.
2640d553cfSPaul Beesley
2740d553cfSPaul BeesleyTF-A can be built to support either AArch64 or AArch32 execution state.
287446c266SZelalem Aweke
2924566a3fSHarrison Mutai.. note::
307446c266SZelalem Aweke    The descriptions in this chapter are for the Arm TrustZone architecture.
3124566a3fSHarrison Mutai    For changes to the firmware design for the `Arm Confidential Compute
3224566a3fSHarrison Mutai    Architecture (Arm CCA)`_ please refer to the chapter :ref:`Realm Management
3324566a3fSHarrison Mutai    Extension (RME)`.
347446c266SZelalem Aweke
3540d553cfSPaul BeesleyCold boot
3640d553cfSPaul Beesley---------
3740d553cfSPaul Beesley
3840d553cfSPaul BeesleyThe cold boot path starts when the platform is physically turned on. If
3940d553cfSPaul Beesley``COLD_BOOT_SINGLE_CPU=0``, one of the CPUs released from reset is chosen as the
4040d553cfSPaul Beesleyprimary CPU, and the remaining CPUs are considered secondary CPUs. The primary
4140d553cfSPaul BeesleyCPU is chosen through platform-specific means. The cold boot path is mainly
4240d553cfSPaul Beesleyexecuted by the primary CPU, other than essential CPU initialization executed by
4340d553cfSPaul Beesleyall CPUs. The secondary CPUs are kept in a safe platform-specific state until
4440d553cfSPaul Beesleythe primary CPU has performed enough initialization to boot them.
4540d553cfSPaul Beesley
4634760951SPaul BeesleyRefer to the :ref:`CPU Reset` for more information on the effect of the
4740d553cfSPaul Beesley``COLD_BOOT_SINGLE_CPU`` platform build option.
4840d553cfSPaul Beesley
4940d553cfSPaul BeesleyThe cold boot path in this implementation of TF-A depends on the execution
5040d553cfSPaul Beesleystate. For AArch64, it is divided into five steps (in order of execution):
5140d553cfSPaul Beesley
5240d553cfSPaul Beesley-  Boot Loader stage 1 (BL1) *AP Trusted ROM*
5340d553cfSPaul Beesley-  Boot Loader stage 2 (BL2) *Trusted Boot Firmware*
5440d553cfSPaul Beesley-  Boot Loader stage 3-1 (BL31) *EL3 Runtime Software*
5540d553cfSPaul Beesley-  Boot Loader stage 3-2 (BL32) *Secure-EL1 Payload* (optional)
5640d553cfSPaul Beesley-  Boot Loader stage 3-3 (BL33) *Non-trusted Firmware*
5740d553cfSPaul Beesley
5840d553cfSPaul BeesleyFor AArch32, it is divided into four steps (in order of execution):
5940d553cfSPaul Beesley
6040d553cfSPaul Beesley-  Boot Loader stage 1 (BL1) *AP Trusted ROM*
6140d553cfSPaul Beesley-  Boot Loader stage 2 (BL2) *Trusted Boot Firmware*
6240d553cfSPaul Beesley-  Boot Loader stage 3-2 (BL32) *EL3 Runtime Software*
6340d553cfSPaul Beesley-  Boot Loader stage 3-3 (BL33) *Non-trusted Firmware*
6440d553cfSPaul Beesley
6540d553cfSPaul BeesleyArm development platforms (Fixed Virtual Platforms (FVPs) and Juno) implement a
6640d553cfSPaul Beesleycombination of the following types of memory regions. Each bootloader stage uses
6740d553cfSPaul Beesleyone or more of these memory regions.
6840d553cfSPaul Beesley
6940d553cfSPaul Beesley-  Regions accessible from both non-secure and secure states. For example,
7040d553cfSPaul Beesley   non-trusted SRAM, ROM and DRAM.
7140d553cfSPaul Beesley-  Regions accessible from only the secure state. For example, trusted SRAM and
7240d553cfSPaul Beesley   ROM. The FVPs also implement the trusted DRAM which is statically
7340d553cfSPaul Beesley   configured. Additionally, the Base FVPs and Juno development platform
7440d553cfSPaul Beesley   configure the TrustZone Controller (TZC) to create a region in the DRAM
7540d553cfSPaul Beesley   which is accessible only from the secure state.
7640d553cfSPaul Beesley
7740d553cfSPaul BeesleyThe sections below provide the following details:
7840d553cfSPaul Beesley
7940d553cfSPaul Beesley-  dynamic configuration of Boot Loader stages
8040d553cfSPaul Beesley-  initialization and execution of the first three stages during cold boot
8140d553cfSPaul Beesley-  specification of the EL3 Runtime Software (BL31 for AArch64 and BL32 for
8240d553cfSPaul Beesley   AArch32) entrypoint requirements for use by alternative Trusted Boot
8340d553cfSPaul Beesley   Firmware in place of the provided BL1 and BL2
8440d553cfSPaul Beesley
8540d553cfSPaul BeesleyDynamic Configuration during cold boot
8640d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8740d553cfSPaul Beesley
8840d553cfSPaul BeesleyEach of the Boot Loader stages may be dynamically configured if required by the
8940d553cfSPaul Beesleyplatform. The Boot Loader stage may optionally specify a firmware
9040d553cfSPaul Beesleyconfiguration file and/or hardware configuration file as listed below:
9140d553cfSPaul Beesley
92089fc624SManish V Badarkhe-  FW_CONFIG - The firmware configuration file. Holds properties shared across
93089fc624SManish V Badarkhe   all BLx images.
94089fc624SManish V Badarkhe   An example is the "dtb-registry" node, which contains the information about
95089fc624SManish V Badarkhe   the other device tree configurations (load-address, size, image_id).
9640d553cfSPaul Beesley-  HW_CONFIG - The hardware configuration file. Can be shared by all Boot Loader
9740d553cfSPaul Beesley   stages and also by the Normal World Rich OS.
9840d553cfSPaul Beesley-  TB_FW_CONFIG - Trusted Boot Firmware configuration file. Shared between BL1
9940d553cfSPaul Beesley   and BL2.
10040d553cfSPaul Beesley-  SOC_FW_CONFIG - SoC Firmware configuration file. Used by BL31.
10140d553cfSPaul Beesley-  TOS_FW_CONFIG - Trusted OS Firmware configuration file. Used by Trusted OS
10240d553cfSPaul Beesley   (BL32).
10340d553cfSPaul Beesley-  NT_FW_CONFIG - Non Trusted Firmware configuration file. Used by Non-trusted
10440d553cfSPaul Beesley   firmware (BL33).
10540d553cfSPaul Beesley
10640d553cfSPaul BeesleyThe Arm development platforms use the Flattened Device Tree format for the
10740d553cfSPaul Beesleydynamic configuration files.
10840d553cfSPaul Beesley
10940d553cfSPaul BeesleyEach Boot Loader stage can pass up to 4 arguments via registers to the next
11040d553cfSPaul Beesleystage.  BL2 passes the list of the next images to execute to the *EL3 Runtime
11140d553cfSPaul BeesleySoftware* (BL31 for AArch64 and BL32 for AArch32) via `arg0`. All the other
11240d553cfSPaul Beesleyarguments are platform defined. The Arm development platforms use the following
11340d553cfSPaul Beesleyconvention:
11440d553cfSPaul Beesley
11540d553cfSPaul Beesley-  BL1 passes the address of a meminfo_t structure to BL2 via ``arg1``. This
11640d553cfSPaul Beesley   structure contains the memory layout available to BL2.
11740d553cfSPaul Beesley-  When dynamic configuration files are present, the firmware configuration for
11840d553cfSPaul Beesley   the next Boot Loader stage is populated in the first available argument and
11940d553cfSPaul Beesley   the generic hardware configuration is passed the next available argument.
12040d553cfSPaul Beesley   For example,
12140d553cfSPaul Beesley
122089fc624SManish V Badarkhe   -  FW_CONFIG is loaded by BL1, then its address is passed in ``arg0`` to BL2.
123089fc624SManish V Badarkhe   -  TB_FW_CONFIG address is retrieved by BL2 from FW_CONFIG device tree.
12440d553cfSPaul Beesley   -  If HW_CONFIG is loaded by BL1, then its address is passed in ``arg2`` to
12540d553cfSPaul Beesley      BL2. Note, ``arg1`` is already used for meminfo_t.
12640d553cfSPaul Beesley   -  If SOC_FW_CONFIG is loaded by BL2, then its address is passed in ``arg1``
12740d553cfSPaul Beesley      to BL31. Note, ``arg0`` is used to pass the list of executable images.
12840d553cfSPaul Beesley   -  Similarly, if HW_CONFIG is loaded by BL1 or BL2, then its address is
12940d553cfSPaul Beesley      passed in ``arg2`` to BL31.
13040d553cfSPaul Beesley   -  For other BL3x images, if the firmware configuration file is loaded by
13140d553cfSPaul Beesley      BL2, then its address is passed in ``arg0`` and if HW_CONFIG is loaded
13240d553cfSPaul Beesley      then its address is passed in ``arg1``.
13331dcf234SNishant Sharma   -  In case SPMC_AT_EL3 is enabled, populate the BL32 image base, size and max
13431dcf234SNishant Sharma      limit in the entry point information, since there is no platform function
13531dcf234SNishant Sharma      to retrieve these in generic code. We choose ``arg2``, ``arg3`` and
13631dcf234SNishant Sharma      ``arg4`` since the generic code uses ``arg1`` for stashing the SP manifest
13731dcf234SNishant Sharma      size. The SPMC setup uses these arguments to update SP manifest with
13831dcf234SNishant Sharma      actual SP's base address and it size.
139b4a87836SManish V Badarkhe   -  In case of the Arm FVP platform, FW_CONFIG address passed in ``arg1`` to
140b4a87836SManish V Badarkhe      BL31/SP_MIN, and the SOC_FW_CONFIG and HW_CONFIG details are retrieved
141b4a87836SManish V Badarkhe      from FW_CONFIG device tree.
14240d553cfSPaul Beesley
14340d553cfSPaul BeesleyBL1
14440d553cfSPaul Beesley~~~
14540d553cfSPaul Beesley
14640d553cfSPaul BeesleyThis stage begins execution from the platform's reset vector at EL3. The reset
14740d553cfSPaul Beesleyaddress is platform dependent but it is usually located in a Trusted ROM area.
14840d553cfSPaul BeesleyThe BL1 data section is copied to trusted SRAM at runtime.
14940d553cfSPaul Beesley
15040d553cfSPaul BeesleyOn the Arm development platforms, BL1 code starts execution from the reset
15140d553cfSPaul Beesleyvector defined by the constant ``BL1_RO_BASE``. The BL1 data section is copied
15240d553cfSPaul Beesleyto the top of trusted SRAM as defined by the constant ``BL1_RW_BASE``.
15340d553cfSPaul Beesley
15440d553cfSPaul BeesleyThe functionality implemented by this stage is as follows.
15540d553cfSPaul Beesley
15640d553cfSPaul BeesleyDetermination of boot path
15740d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^
15840d553cfSPaul Beesley
15940d553cfSPaul BeesleyWhenever a CPU is released from reset, BL1 needs to distinguish between a warm
16040d553cfSPaul Beesleyboot and a cold boot. This is done using platform-specific mechanisms (see the
16134760951SPaul Beesley``plat_get_my_entrypoint()`` function in the :ref:`Porting Guide`). In the case
16234760951SPaul Beesleyof a warm boot, a CPU is expected to continue execution from a separate
16340d553cfSPaul Beesleyentrypoint. In the case of a cold boot, the secondary CPUs are placed in a safe
16440d553cfSPaul Beesleyplatform-specific state (see the ``plat_secondary_cold_boot_setup()`` function in
16534760951SPaul Beesleythe :ref:`Porting Guide`) while the primary CPU executes the remaining cold boot
16634760951SPaul Beesleypath as described in the following sections.
16740d553cfSPaul Beesley
16840d553cfSPaul BeesleyThis step only applies when ``PROGRAMMABLE_RESET_ADDRESS=0``. Refer to the
16934760951SPaul Beesley:ref:`CPU Reset` for more information on the effect of the
17040d553cfSPaul Beesley``PROGRAMMABLE_RESET_ADDRESS`` platform build option.
17140d553cfSPaul Beesley
17240d553cfSPaul BeesleyArchitectural initialization
17340d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17440d553cfSPaul Beesley
17540d553cfSPaul BeesleyBL1 performs minimal architectural initialization as follows.
17640d553cfSPaul Beesley
17740d553cfSPaul Beesley-  Exception vectors
17840d553cfSPaul Beesley
17940d553cfSPaul Beesley   BL1 sets up simple exception vectors for both synchronous and asynchronous
18040d553cfSPaul Beesley   exceptions. The default behavior upon receiving an exception is to populate
18140d553cfSPaul Beesley   a status code in the general purpose register ``X0/R0`` and call the
18234760951SPaul Beesley   ``plat_report_exception()`` function (see the :ref:`Porting Guide`). The
18334760951SPaul Beesley   status code is one of:
18440d553cfSPaul Beesley
18540d553cfSPaul Beesley   For AArch64:
18640d553cfSPaul Beesley
18740d553cfSPaul Beesley   ::
18840d553cfSPaul Beesley
18940d553cfSPaul Beesley       0x0 : Synchronous exception from Current EL with SP_EL0
19040d553cfSPaul Beesley       0x1 : IRQ exception from Current EL with SP_EL0
19140d553cfSPaul Beesley       0x2 : FIQ exception from Current EL with SP_EL0
19240d553cfSPaul Beesley       0x3 : System Error exception from Current EL with SP_EL0
19340d553cfSPaul Beesley       0x4 : Synchronous exception from Current EL with SP_ELx
19440d553cfSPaul Beesley       0x5 : IRQ exception from Current EL with SP_ELx
19540d553cfSPaul Beesley       0x6 : FIQ exception from Current EL with SP_ELx
19640d553cfSPaul Beesley       0x7 : System Error exception from Current EL with SP_ELx
19740d553cfSPaul Beesley       0x8 : Synchronous exception from Lower EL using aarch64
19840d553cfSPaul Beesley       0x9 : IRQ exception from Lower EL using aarch64
19940d553cfSPaul Beesley       0xa : FIQ exception from Lower EL using aarch64
20040d553cfSPaul Beesley       0xb : System Error exception from Lower EL using aarch64
20140d553cfSPaul Beesley       0xc : Synchronous exception from Lower EL using aarch32
20240d553cfSPaul Beesley       0xd : IRQ exception from Lower EL using aarch32
20340d553cfSPaul Beesley       0xe : FIQ exception from Lower EL using aarch32
20440d553cfSPaul Beesley       0xf : System Error exception from Lower EL using aarch32
20540d553cfSPaul Beesley
20640d553cfSPaul Beesley   For AArch32:
20740d553cfSPaul Beesley
20840d553cfSPaul Beesley   ::
20940d553cfSPaul Beesley
21040d553cfSPaul Beesley       0x10 : User mode
21140d553cfSPaul Beesley       0x11 : FIQ mode
21240d553cfSPaul Beesley       0x12 : IRQ mode
21340d553cfSPaul Beesley       0x13 : SVC mode
21440d553cfSPaul Beesley       0x16 : Monitor mode
21540d553cfSPaul Beesley       0x17 : Abort mode
21640d553cfSPaul Beesley       0x1a : Hypervisor mode
21740d553cfSPaul Beesley       0x1b : Undefined mode
21840d553cfSPaul Beesley       0x1f : System mode
21940d553cfSPaul Beesley
22040d553cfSPaul Beesley   The ``plat_report_exception()`` implementation on the Arm FVP port programs
22140d553cfSPaul Beesley   the Versatile Express System LED register in the following format to
22240d553cfSPaul Beesley   indicate the occurrence of an unexpected exception:
22340d553cfSPaul Beesley
22440d553cfSPaul Beesley   ::
22540d553cfSPaul Beesley
22640d553cfSPaul Beesley       SYS_LED[0]   - Security state (Secure=0/Non-Secure=1)
22740d553cfSPaul Beesley       SYS_LED[2:1] - Exception Level (EL3=0x3, EL2=0x2, EL1=0x1, EL0=0x0)
22840d553cfSPaul Beesley                      For AArch32 it is always 0x0
22940d553cfSPaul Beesley       SYS_LED[7:3] - Exception Class (Sync/Async & origin). This is the value
23040d553cfSPaul Beesley                      of the status code
23140d553cfSPaul Beesley
23240d553cfSPaul Beesley   A write to the LED register reflects in the System LEDs (S6LED0..7) in the
23340d553cfSPaul Beesley   CLCD window of the FVP.
23440d553cfSPaul Beesley
23540d553cfSPaul Beesley   BL1 does not expect to receive any exceptions other than the SMC exception.
23640d553cfSPaul Beesley   For the latter, BL1 installs a simple stub. The stub expects to receive a
23740d553cfSPaul Beesley   limited set of SMC types (determined by their function IDs in the general
23840d553cfSPaul Beesley   purpose register ``X0/R0``):
23940d553cfSPaul Beesley
24040d553cfSPaul Beesley   -  ``BL1_SMC_RUN_IMAGE``: This SMC is raised by BL2 to make BL1 pass control
24140d553cfSPaul Beesley      to EL3 Runtime Software.
24234760951SPaul Beesley   -  All SMCs listed in section "BL1 SMC Interface" in the :ref:`Firmware Update (FWU)`
24340d553cfSPaul Beesley      Design Guide are supported for AArch64 only. These SMCs are currently
24440d553cfSPaul Beesley      not supported when BL1 is built for AArch32.
24540d553cfSPaul Beesley
24640d553cfSPaul Beesley   Any other SMC leads to an assertion failure.
24740d553cfSPaul Beesley
24840d553cfSPaul Beesley-  CPU initialization
24940d553cfSPaul Beesley
2500d020822SBoyan Karatotev   BL1 calls the ``reset_handler`` macro/function which in turn calls the CPU
25140d553cfSPaul Beesley   specific reset handler function (see the section: "CPU specific operations
25240d553cfSPaul Beesley   framework").
25340d553cfSPaul Beesley
25440d553cfSPaul BeesleyPlatform initialization
25540d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^
25640d553cfSPaul Beesley
25740d553cfSPaul BeesleyOn Arm platforms, BL1 performs the following platform initializations:
25840d553cfSPaul Beesley
25940d553cfSPaul Beesley-  Enable the Trusted Watchdog.
26040d553cfSPaul Beesley-  Initialize the console.
26140d553cfSPaul Beesley-  Configure the Interconnect to enable hardware coherency.
26240d553cfSPaul Beesley-  Enable the MMU and map the memory it needs to access.
26340d553cfSPaul Beesley-  Configure any required platform storage to load the next bootloader image
26440d553cfSPaul Beesley   (BL2).
26540d553cfSPaul Beesley-  If the BL1 dynamic configuration file, ``TB_FW_CONFIG``, is available, then
26640d553cfSPaul Beesley   load it to the platform defined address and make it available to BL2 via
26740d553cfSPaul Beesley   ``arg0``.
26840d553cfSPaul Beesley-  Configure the system timer and program the `CNTFRQ_EL0` for use by NS-BL1U
26940d553cfSPaul Beesley   and NS-BL2U firmware update images.
27040d553cfSPaul Beesley
27140d553cfSPaul BeesleyFirmware Update detection and execution
27240d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27340d553cfSPaul Beesley
27440d553cfSPaul BeesleyAfter performing platform setup, BL1 common code calls
27534760951SPaul Beesley``bl1_plat_get_next_image_id()`` to determine if :ref:`Firmware Update (FWU)` is
27634760951SPaul Beesleyrequired or to proceed with the normal boot process. If the platform code
27734760951SPaul Beesleyreturns ``BL2_IMAGE_ID`` then the normal boot sequence is executed as described
27834760951SPaul Beesleyin the next section, else BL1 assumes that :ref:`Firmware Update (FWU)` is
27934760951SPaul Beesleyrequired and execution passes to the first image in the
28034760951SPaul Beesley:ref:`Firmware Update (FWU)` process. In either case, BL1 retrieves a descriptor
28134760951SPaul Beesleyof the next image by calling ``bl1_plat_get_image_desc()``. The image descriptor
28234760951SPaul Beesleycontains an ``entry_point_info_t`` structure, which BL1 uses to initialize the
28334760951SPaul Beesleyexecution state of the next image.
28440d553cfSPaul Beesley
28540d553cfSPaul BeesleyBL2 image load and execution
28640d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28740d553cfSPaul Beesley
28840d553cfSPaul BeesleyIn the normal boot flow, BL1 execution continues as follows:
28940d553cfSPaul Beesley
29040d553cfSPaul Beesley#. BL1 prints the following string from the primary CPU to indicate successful
29140d553cfSPaul Beesley   execution of the BL1 stage:
29240d553cfSPaul Beesley
29340d553cfSPaul Beesley   ::
29440d553cfSPaul Beesley
29540d553cfSPaul Beesley       "Booting Trusted Firmware"
29640d553cfSPaul Beesley
29740d553cfSPaul Beesley#. BL1 loads a BL2 raw binary image from platform storage, at a
29840d553cfSPaul Beesley   platform-specific base address. Prior to the load, BL1 invokes
29940d553cfSPaul Beesley   ``bl1_plat_handle_pre_image_load()`` which allows the platform to update or
30040d553cfSPaul Beesley   use the image information. If the BL2 image file is not present or if
30140d553cfSPaul Beesley   there is not enough free trusted SRAM the following error message is
30240d553cfSPaul Beesley   printed:
30340d553cfSPaul Beesley
30440d553cfSPaul Beesley   ::
30540d553cfSPaul Beesley
30640d553cfSPaul Beesley       "Failed to load BL2 firmware."
30740d553cfSPaul Beesley
30840d553cfSPaul Beesley#. BL1 invokes ``bl1_plat_handle_post_image_load()`` which again is intended
30940d553cfSPaul Beesley   for platforms to take further action after image load. This function must
31040d553cfSPaul Beesley   populate the necessary arguments for BL2, which may also include the memory
31140d553cfSPaul Beesley   layout. Further description of the memory layout can be found later
31240d553cfSPaul Beesley   in this document.
31340d553cfSPaul Beesley
31440d553cfSPaul Beesley#. BL1 passes control to the BL2 image at Secure EL1 (for AArch64) or at
31540d553cfSPaul Beesley   Secure SVC mode (for AArch32), starting from its load address.
31640d553cfSPaul Beesley
31740d553cfSPaul BeesleyBL2
31840d553cfSPaul Beesley~~~
31940d553cfSPaul Beesley
32040d553cfSPaul BeesleyBL1 loads and passes control to BL2 at Secure-EL1 (for AArch64) or at Secure
32140d553cfSPaul BeesleySVC mode (for AArch32) . BL2 is linked against and loaded at a platform-specific
32240d553cfSPaul Beesleybase address (more information can be found later in this document).
32340d553cfSPaul BeesleyThe functionality implemented by BL2 is as follows.
32440d553cfSPaul Beesley
32540d553cfSPaul BeesleyArchitectural initialization
32640d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32740d553cfSPaul Beesley
32840d553cfSPaul BeesleyFor AArch64, BL2 performs the minimal architectural initialization required
32940d553cfSPaul Beesleyfor subsequent stages of TF-A and normal world software. EL1 and EL0 are given
330093ba62eSPeng Fanaccess to Floating Point and Advanced SIMD registers by setting the
33140d553cfSPaul Beesley``CPACR.FPEN`` bits.
33240d553cfSPaul Beesley
33340d553cfSPaul BeesleyFor AArch32, the minimal architectural initialization required for subsequent
33440d553cfSPaul Beesleystages of TF-A and normal world software is taken care of in BL1 as both BL1
33540d553cfSPaul Beesleyand BL2 execute at PL1.
33640d553cfSPaul Beesley
33740d553cfSPaul BeesleyPlatform initialization
33840d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^
33940d553cfSPaul Beesley
34040d553cfSPaul BeesleyOn Arm platforms, BL2 performs the following platform initializations:
34140d553cfSPaul Beesley
34240d553cfSPaul Beesley-  Initialize the console.
34340d553cfSPaul Beesley-  Configure any required platform storage to allow loading further bootloader
34440d553cfSPaul Beesley   images.
34540d553cfSPaul Beesley-  Enable the MMU and map the memory it needs to access.
34640d553cfSPaul Beesley-  Perform platform security setup to allow access to controlled components.
34740d553cfSPaul Beesley-  Reserve some memory for passing information to the next bootloader image
34840d553cfSPaul Beesley   EL3 Runtime Software and populate it.
34940d553cfSPaul Beesley-  Define the extents of memory available for loading each subsequent
35040d553cfSPaul Beesley   bootloader image.
35140d553cfSPaul Beesley-  If BL1 has passed TB_FW_CONFIG dynamic configuration file in ``arg0``,
35240d553cfSPaul Beesley   then parse it.
35340d553cfSPaul Beesley
35440d553cfSPaul BeesleyImage loading in BL2
35540d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^
35640d553cfSPaul Beesley
35740d553cfSPaul BeesleyBL2 generic code loads the images based on the list of loadable images
35840d553cfSPaul Beesleyprovided by the platform. BL2 passes the list of executable images
35940d553cfSPaul Beesleyprovided by the platform to the next handover BL image.
36040d553cfSPaul Beesley
36140d553cfSPaul BeesleyThe list of loadable images provided by the platform may also contain
36240d553cfSPaul Beesleydynamic configuration files. The files are loaded and can be parsed as
36340d553cfSPaul Beesleyneeded in the ``bl2_plat_handle_post_image_load()`` function. These
36440d553cfSPaul Beesleyconfiguration files can be passed to next Boot Loader stages as arguments
36540d553cfSPaul Beesleyby updating the corresponding entrypoint information in this function.
36640d553cfSPaul Beesley
36740d553cfSPaul BeesleySCP_BL2 (System Control Processor Firmware) image load
36840d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36940d553cfSPaul Beesley
37040d553cfSPaul BeesleySome systems have a separate System Control Processor (SCP) for power, clock,
37140d553cfSPaul Beesleyreset and system control. BL2 loads the optional SCP_BL2 image from platform
37240d553cfSPaul Beesleystorage into a platform-specific region of secure memory. The subsequent
37340d553cfSPaul Beesleyhandling of SCP_BL2 is platform specific. For example, on the Juno Arm
37440d553cfSPaul Beesleydevelopment platform port the image is transferred into SCP's internal memory
37540d553cfSPaul Beesleyusing the Boot Over MHU (BOM) protocol after being loaded in the trusted SRAM
37640d553cfSPaul Beesleymemory. The SCP executes SCP_BL2 and signals to the Application Processor (AP)
37740d553cfSPaul Beesleyfor BL2 execution to continue.
37840d553cfSPaul Beesley
37940d553cfSPaul BeesleyEL3 Runtime Software image load
38040d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38140d553cfSPaul Beesley
38240d553cfSPaul BeesleyBL2 loads the EL3 Runtime Software image from platform storage into a platform-
38340d553cfSPaul Beesleyspecific address in trusted SRAM. If there is not enough memory to load the
38440d553cfSPaul Beesleyimage or image is missing it leads to an assertion failure.
38540d553cfSPaul Beesley
38640d553cfSPaul BeesleyAArch64 BL32 (Secure-EL1 Payload) image load
38740d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38840d553cfSPaul Beesley
38940d553cfSPaul BeesleyBL2 loads the optional BL32 image from platform storage into a platform-
39040d553cfSPaul Beesleyspecific region of secure memory. The image executes in the secure world. BL2
39140d553cfSPaul Beesleyrelies on BL31 to pass control to the BL32 image, if present. Hence, BL2
39240d553cfSPaul Beesleypopulates a platform-specific area of memory with the entrypoint/load-address
39340d553cfSPaul Beesleyof the BL32 image. The value of the Saved Processor Status Register (``SPSR``)
39440d553cfSPaul Beesleyfor entry into BL32 is not determined by BL2, it is initialized by the
39540d553cfSPaul BeesleySecure-EL1 Payload Dispatcher (see later) within BL31, which is responsible for
39640d553cfSPaul Beesleymanaging interaction with BL32. This information is passed to BL31.
39740d553cfSPaul Beesley
39840d553cfSPaul BeesleyBL33 (Non-trusted Firmware) image load
39940d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40040d553cfSPaul Beesley
40140d553cfSPaul BeesleyBL2 loads the BL33 image (e.g. UEFI or other test or boot software) from
40240d553cfSPaul Beesleyplatform storage into non-secure memory as defined by the platform.
40340d553cfSPaul Beesley
40440d553cfSPaul BeesleyBL2 relies on EL3 Runtime Software to pass control to BL33 once secure state
40540d553cfSPaul Beesleyinitialization is complete. Hence, BL2 populates a platform-specific area of
40640d553cfSPaul Beesleymemory with the entrypoint and Saved Program Status Register (``SPSR``) of the
40740d553cfSPaul Beesleynormal world software image. The entrypoint is the load address of the BL33
40840d553cfSPaul Beesleyimage. The ``SPSR`` is determined as specified in Section 5.13 of the
4093be6b4fbSManish V Badarkhe`PSCI`_. This information is passed to the EL3 Runtime Software.
41040d553cfSPaul Beesley
41140d553cfSPaul BeesleyAArch64 BL31 (EL3 Runtime Software) execution
41240d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41340d553cfSPaul Beesley
41440d553cfSPaul BeesleyBL2 execution continues as follows:
41540d553cfSPaul Beesley
41640d553cfSPaul Beesley#. BL2 passes control back to BL1 by raising an SMC, providing BL1 with the
41740d553cfSPaul Beesley   BL31 entrypoint. The exception is handled by the SMC exception handler
41840d553cfSPaul Beesley   installed by BL1.
41940d553cfSPaul Beesley
42040d553cfSPaul Beesley#. BL1 turns off the MMU and flushes the caches. It clears the
42140d553cfSPaul Beesley   ``SCTLR_EL3.M/I/C`` bits, flushes the data cache to the point of coherency
42240d553cfSPaul Beesley   and invalidates the TLBs.
42340d553cfSPaul Beesley
42440d553cfSPaul Beesley#. BL1 passes control to BL31 at the specified entrypoint at EL3.
42540d553cfSPaul Beesley
42640d553cfSPaul BeesleyRunning BL2 at EL3 execution level
42740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42840d553cfSPaul Beesley
42940d553cfSPaul BeesleySome platforms have a non-TF-A Boot ROM that expects the next boot stage
43040d553cfSPaul Beesleyto execute at EL3. On these platforms, TF-A BL1 is a waste of memory
43140d553cfSPaul Beesleyas its only purpose is to ensure TF-A BL2 is entered at S-EL1. To avoid
43240d553cfSPaul Beesleythis waste, a special mode enables BL2 to execute at EL3, which allows
43340d553cfSPaul Beesleya non-TF-A Boot ROM to load and jump directly to BL2. This mode is selected
43442d4d3baSArvind Ram Prakashwhen the build flag RESET_TO_BL2 is enabled.
43542d4d3baSArvind Ram PrakashThe main differences in this mode are:
43640d553cfSPaul Beesley
43740d553cfSPaul Beesley#. BL2 includes the reset code and the mailbox mechanism to differentiate
43840d553cfSPaul Beesley   cold boot and warm boot. It runs at EL3 doing the arch
43940d553cfSPaul Beesley   initialization required for EL3.
44040d553cfSPaul Beesley
44140d553cfSPaul Beesley#. BL2 does not receive the meminfo information from BL1 anymore. This
44240d553cfSPaul Beesley   information can be passed by the Boot ROM or be internal to the
44340d553cfSPaul Beesley   BL2 image.
44440d553cfSPaul Beesley
44540d553cfSPaul Beesley#. Since BL2 executes at EL3, BL2 jumps directly to the next image,
44640d553cfSPaul Beesley   instead of invoking the RUN_IMAGE SMC call.
44740d553cfSPaul Beesley
44840d553cfSPaul Beesley
44940d553cfSPaul BeesleyWe assume 3 different types of BootROM support on the platform:
45040d553cfSPaul Beesley
45140d553cfSPaul Beesley#. The Boot ROM always jumps to the same address, for both cold
45240d553cfSPaul Beesley   and warm boot. In this case, we will need to keep a resident part
45340d553cfSPaul Beesley   of BL2 whose memory cannot be reclaimed by any other image. The
45440d553cfSPaul Beesley   linker script defines the symbols __TEXT_RESIDENT_START__ and
45540d553cfSPaul Beesley   __TEXT_RESIDENT_END__ that allows the platform to configure
45640d553cfSPaul Beesley   correctly the memory map.
45740d553cfSPaul Beesley#. The platform has some mechanism to indicate the jump address to the
45840d553cfSPaul Beesley   Boot ROM. Platform code can then program the jump address with
45940d553cfSPaul Beesley   psci_warmboot_entrypoint during cold boot.
46040d553cfSPaul Beesley#. The platform has some mechanism to program the reset address using
46140d553cfSPaul Beesley   the PROGRAMMABLE_RESET_ADDRESS feature. Platform code can then
46240d553cfSPaul Beesley   program the reset address with psci_warmboot_entrypoint during
46340d553cfSPaul Beesley   cold boot, bypassing the boot ROM for warm boot.
46440d553cfSPaul Beesley
46540d553cfSPaul BeesleyIn the last 2 cases, no part of BL2 needs to remain resident at
46640d553cfSPaul Beesleyruntime. In the first 2 cases, we expect the Boot ROM to be able to
46740d553cfSPaul Beesleydifferentiate between warm and cold boot, to avoid loading BL2 again
46840d553cfSPaul Beesleyduring warm boot.
46940d553cfSPaul Beesley
47040d553cfSPaul BeesleyThis functionality can be tested with FVP loading the image directly
47140d553cfSPaul Beesleyin memory and changing the address where the system jumps at reset.
47240d553cfSPaul BeesleyFor example:
47340d553cfSPaul Beesley
47440d553cfSPaul Beesley	-C cluster0.cpu0.RVBAR=0x4022000
47540d553cfSPaul Beesley	--data cluster0.cpu0=bl2.bin@0x4022000
47640d553cfSPaul Beesley
47740d553cfSPaul BeesleyWith this configuration, FVP is like a platform of the first case,
47840d553cfSPaul Beesleywhere the Boot ROM jumps always to the same address. For simplification,
47940d553cfSPaul BeesleyBL32 is loaded in DRAM in this case, to avoid other images reclaiming
48040d553cfSPaul BeesleyBL2 memory.
48140d553cfSPaul Beesley
48240d553cfSPaul Beesley
48340d553cfSPaul BeesleyAArch64 BL31
48440d553cfSPaul Beesley~~~~~~~~~~~~
48540d553cfSPaul Beesley
48640d553cfSPaul BeesleyThe image for this stage is loaded by BL2 and BL1 passes control to BL31 at
48740d553cfSPaul BeesleyEL3. BL31 executes solely in trusted SRAM. BL31 is linked against and
48840d553cfSPaul Beesleyloaded at a platform-specific base address (more information can be found later
48940d553cfSPaul Beesleyin this document). The functionality implemented by BL31 is as follows.
49040d553cfSPaul Beesley
49140d553cfSPaul BeesleyArchitectural initialization
49240d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49340d553cfSPaul Beesley
49440d553cfSPaul BeesleyCurrently, BL31 performs a similar architectural initialization to BL1 as
49540d553cfSPaul Beesleyfar as system register settings are concerned. Since BL1 code resides in ROM,
49640d553cfSPaul Beesleyarchitectural initialization in BL31 allows override of any previous
49740d553cfSPaul Beesleyinitialization done by BL1.
49840d553cfSPaul Beesley
49940d553cfSPaul BeesleyBL31 initializes the per-CPU data framework, which provides a cache of
50040d553cfSPaul Beesleyfrequently accessed per-CPU data optimised for fast, concurrent manipulation
50140d553cfSPaul Beesleyon different CPUs. This buffer includes pointers to per-CPU contexts, crash
50240d553cfSPaul Beesleybuffer, CPU reset and power down operations, PSCI data, platform data and so on.
50340d553cfSPaul Beesley
50440d553cfSPaul BeesleyIt then replaces the exception vectors populated by BL1 with its own. BL31
50540d553cfSPaul Beesleyexception vectors implement more elaborate support for handling SMCs since this
50640d553cfSPaul Beesleyis the only mechanism to access the runtime services implemented by BL31 (PSCI
50740d553cfSPaul Beesleyfor example). BL31 checks each SMC for validity as specified by the
50871ac931fSSandrine Bailleux`SMC Calling Convention`_ before passing control to the required SMC
50940d553cfSPaul Beesleyhandler routine.
51040d553cfSPaul Beesley
51140d553cfSPaul BeesleyBL31 programs the ``CNTFRQ_EL0`` register with the clock frequency of the system
51240d553cfSPaul Beesleycounter, which is provided by the platform.
51340d553cfSPaul Beesley
51440d553cfSPaul BeesleyPlatform initialization
51540d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^
51640d553cfSPaul Beesley
51740d553cfSPaul BeesleyBL31 performs detailed platform initialization, which enables normal world
51840d553cfSPaul Beesleysoftware to function correctly.
51940d553cfSPaul Beesley
52040d553cfSPaul BeesleyOn Arm platforms, this consists of the following:
52140d553cfSPaul Beesley
52240d553cfSPaul Beesley-  Initialize the console.
52340d553cfSPaul Beesley-  Configure the Interconnect to enable hardware coherency.
52440d553cfSPaul Beesley-  Enable the MMU and map the memory it needs to access.
52540d553cfSPaul Beesley-  Initialize the generic interrupt controller.
52640d553cfSPaul Beesley-  Initialize the power controller device.
52740d553cfSPaul Beesley-  Detect the system topology.
52840d553cfSPaul Beesley
52940d553cfSPaul BeesleyRuntime services initialization
53040d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53140d553cfSPaul Beesley
53240d553cfSPaul BeesleyBL31 is responsible for initializing the runtime services. One of them is PSCI.
53340d553cfSPaul Beesley
53440d553cfSPaul BeesleyAs part of the PSCI initializations, BL31 detects the system topology. It also
53540d553cfSPaul Beesleyinitializes the data structures that implement the state machine used to track
53640d553cfSPaul Beesleythe state of power domain nodes. The state can be one of ``OFF``, ``RUN`` or
53740d553cfSPaul Beesley``RETENTION``. All secondary CPUs are initially in the ``OFF`` state. The cluster
53840d553cfSPaul Beesleythat the primary CPU belongs to is ``ON``; any other cluster is ``OFF``. It also
53940d553cfSPaul Beesleyinitializes the locks that protect them. BL31 accesses the state of a CPU or
54040d553cfSPaul Beesleycluster immediately after reset and before the data cache is enabled in the
54140d553cfSPaul Beesleywarm boot path. It is not currently possible to use 'exclusive' based spinlocks,
54240d553cfSPaul Beesleytherefore BL31 uses locks based on Lamport's Bakery algorithm instead.
54340d553cfSPaul Beesley
54440d553cfSPaul BeesleyThe runtime service framework and its initialization is described in more
54540d553cfSPaul Beesleydetail in the "EL3 runtime services framework" section below.
54640d553cfSPaul Beesley
54740d553cfSPaul BeesleyDetails about the status of the PSCI implementation are provided in the
54840d553cfSPaul Beesley"Power State Coordination Interface" section below.
54940d553cfSPaul Beesley
55040d553cfSPaul BeesleyAArch64 BL32 (Secure-EL1 Payload) image initialization
55140d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55240d553cfSPaul Beesley
55340d553cfSPaul BeesleyIf a BL32 image is present then there must be a matching Secure-EL1 Payload
55440d553cfSPaul BeesleyDispatcher (SPD) service (see later for details). During initialization
55540d553cfSPaul Beesleythat service must register a function to carry out initialization of BL32
55640d553cfSPaul Beesleyonce the runtime services are fully initialized. BL31 invokes such a
55740d553cfSPaul Beesleyregistered function to initialize BL32 before running BL33. This initialization
55840d553cfSPaul Beesleyis not necessary for AArch32 SPs.
55940d553cfSPaul Beesley
56040d553cfSPaul BeesleyDetails on BL32 initialization and the SPD's role are described in the
56143f35ef5SPaul Beesley:ref:`firmware_design_sel1_spd` section below.
56240d553cfSPaul Beesley
56340d553cfSPaul BeesleyBL33 (Non-trusted Firmware) execution
56440d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56540d553cfSPaul Beesley
56640d553cfSPaul BeesleyEL3 Runtime Software initializes the EL2 or EL1 processor context for normal-
56740d553cfSPaul Beesleyworld cold boot, ensuring that no secure state information finds its way into
56840d553cfSPaul Beesleythe non-secure execution state. EL3 Runtime Software uses the entrypoint
56940d553cfSPaul Beesleyinformation provided by BL2 to jump to the Non-trusted firmware image (BL33)
57040d553cfSPaul Beesleyat the highest available Exception Level (EL2 if available, otherwise EL1).
57140d553cfSPaul Beesley
57240d553cfSPaul BeesleyUsing alternative Trusted Boot Firmware in place of BL1 & BL2 (AArch64 only)
57340d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57440d553cfSPaul Beesley
57540d553cfSPaul BeesleySome platforms have existing implementations of Trusted Boot Firmware that
57640d553cfSPaul Beesleywould like to use TF-A BL31 for the EL3 Runtime Software. To enable this
57740d553cfSPaul Beesleyfirmware architecture it is important to provide a fully documented and stable
57840d553cfSPaul Beesleyinterface between the Trusted Boot Firmware and BL31.
57940d553cfSPaul Beesley
58040d553cfSPaul BeesleyFuture changes to the BL31 interface will be done in a backwards compatible
58140d553cfSPaul Beesleyway, and this enables these firmware components to be independently enhanced/
58240d553cfSPaul Beesleyupdated to develop and exploit new functionality.
58340d553cfSPaul Beesley
58440d553cfSPaul BeesleyRequired CPU state when calling ``bl31_entrypoint()`` during cold boot
58540d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58640d553cfSPaul Beesley
58740d553cfSPaul BeesleyThis function must only be called by the primary CPU.
58840d553cfSPaul Beesley
58940d553cfSPaul BeesleyOn entry to this function the calling primary CPU must be executing in AArch64
59040d553cfSPaul BeesleyEL3, little-endian data access, and all interrupt sources masked:
59140d553cfSPaul Beesley
59240d553cfSPaul Beesley::
59340d553cfSPaul Beesley
59440d553cfSPaul Beesley    PSTATE.EL = 3
59540d553cfSPaul Beesley    PSTATE.RW = 1
59640d553cfSPaul Beesley    PSTATE.DAIF = 0xf
59740d553cfSPaul Beesley    SCTLR_EL3.EE = 0
59840d553cfSPaul Beesley
59940d553cfSPaul BeesleyX0 and X1 can be used to pass information from the Trusted Boot Firmware to the
60040d553cfSPaul Beesleyplatform code in BL31:
60140d553cfSPaul Beesley
60240d553cfSPaul Beesley::
60340d553cfSPaul Beesley
60440d553cfSPaul Beesley    X0 : Reserved for common TF-A information
60540d553cfSPaul Beesley    X1 : Platform specific information
60640d553cfSPaul Beesley
60740d553cfSPaul BeesleyBL31 zero-init sections (e.g. ``.bss``) should not contain valid data on entry,
60840d553cfSPaul Beesleythese will be zero filled prior to invoking platform setup code.
60940d553cfSPaul Beesley
61040d553cfSPaul BeesleyUse of the X0 and X1 parameters
61140d553cfSPaul Beesley'''''''''''''''''''''''''''''''
61240d553cfSPaul Beesley
61340d553cfSPaul BeesleyThe parameters are platform specific and passed from ``bl31_entrypoint()`` to
61440d553cfSPaul Beesley``bl31_early_platform_setup()``. The value of these parameters is never directly
61540d553cfSPaul Beesleyused by the common BL31 code.
61640d553cfSPaul Beesley
61740d553cfSPaul BeesleyThe convention is that ``X0`` conveys information regarding the BL31, BL32 and
61840d553cfSPaul BeesleyBL33 images from the Trusted Boot firmware and ``X1`` can be used for other
61940d553cfSPaul Beesleyplatform specific purpose. This convention allows platforms which use TF-A's
62040d553cfSPaul BeesleyBL1 and BL2 images to transfer additional platform specific information from
62140d553cfSPaul BeesleySecure Boot without conflicting with future evolution of TF-A using ``X0`` to
62240d553cfSPaul Beesleypass a ``bl31_params`` structure.
62340d553cfSPaul Beesley
62440d553cfSPaul BeesleyBL31 common and SPD initialization code depends on image and entrypoint
62540d553cfSPaul Beesleyinformation about BL33 and BL32, which is provided via BL31 platform APIs.
62640d553cfSPaul BeesleyThis information is required until the start of execution of BL33. This
62740d553cfSPaul Beesleyinformation can be provided in a platform defined manner, e.g. compiled into
62840d553cfSPaul Beesleythe platform code in BL31, or provided in a platform defined memory location
62940d553cfSPaul Beesleyby the Trusted Boot firmware, or passed from the Trusted Boot Firmware via the
63040d553cfSPaul BeesleyCold boot Initialization parameters. This data may need to be cleaned out of
63140d553cfSPaul Beesleythe CPU caches if it is provided by an earlier boot stage and then accessed by
63240d553cfSPaul BeesleyBL31 platform code before the caches are enabled.
63340d553cfSPaul Beesley
63440d553cfSPaul BeesleyTF-A's BL2 implementation passes a ``bl31_params`` structure in
63540d553cfSPaul Beesley``X0`` and the Arm development platforms interpret this in the BL31 platform
63640d553cfSPaul Beesleycode.
63740d553cfSPaul Beesley
63840d553cfSPaul BeesleyMMU, Data caches & Coherency
63940d553cfSPaul Beesley''''''''''''''''''''''''''''
64040d553cfSPaul Beesley
64140d553cfSPaul BeesleyBL31 does not depend on the enabled state of the MMU, data caches or
64240d553cfSPaul Beesleyinterconnect coherency on entry to ``bl31_entrypoint()``. If these are disabled
64340d553cfSPaul Beesleyon entry, these should be enabled during ``bl31_plat_arch_setup()``.
64440d553cfSPaul Beesley
64540d553cfSPaul BeesleyData structures used in the BL31 cold boot interface
64640d553cfSPaul Beesley''''''''''''''''''''''''''''''''''''''''''''''''''''
64740d553cfSPaul Beesley
6482839a3c4SHarrison MutaiIn the cold boot flow, ``entry_point_info`` is used to represent the execution
6492839a3c4SHarrison Mutaistate of an image; that is, the state of general purpose registers, PC, and
6502839a3c4SHarrison MutaiSPSR.
6512839a3c4SHarrison Mutai
6522839a3c4SHarrison MutaiThere are two variants of this structure, for AArch64:
6532839a3c4SHarrison Mutai
6542839a3c4SHarrison Mutai.. code:: c
6552839a3c4SHarrison Mutai
6562839a3c4SHarrison Mutai   typedef struct entry_point_info {
6572839a3c4SHarrison Mutai        param_header_t h;
6582839a3c4SHarrison Mutai        uintptr_t pc;
6592839a3c4SHarrison Mutai        uint32_t spsr;
6602839a3c4SHarrison Mutai
6612839a3c4SHarrison Mutai        aapcs64_params_t args;
6622839a3c4SHarrison Mutai   }
6632839a3c4SHarrison Mutai
6642839a3c4SHarrison Mutaiand, AArch32:
6652839a3c4SHarrison Mutai
6662839a3c4SHarrison Mutai.. code:: c
6672839a3c4SHarrison Mutai
6682839a3c4SHarrison Mutai   typedef struct entry_point_info {
6692839a3c4SHarrison Mutai      param_header_t h;
6702839a3c4SHarrison Mutai      uintptr_t pc;
6712839a3c4SHarrison Mutai      uint32_t spsr;
6722839a3c4SHarrison Mutai
6732839a3c4SHarrison Mutai      uintptr_t lr_svc;
6742839a3c4SHarrison Mutai      aapcs32_params_t args;
6752839a3c4SHarrison Mutai   } entry_point_info_t;
6762839a3c4SHarrison Mutai
67740d553cfSPaul BeesleyThese structures are designed to support compatibility and independent
67840d553cfSPaul Beesleyevolution of the structures and the firmware images. For example, a version of
67940d553cfSPaul BeesleyBL31 that can interpret the BL3x image information from different versions of
68040d553cfSPaul BeesleyBL2, a platform that uses an extended entry_point_info structure to convey
68140d553cfSPaul Beesleyadditional register information to BL31, or a ELF image loader that can convey
68240d553cfSPaul Beesleymore details about the firmware images.
68340d553cfSPaul Beesley
68440d553cfSPaul BeesleyTo support these scenarios the structures are versioned and sized, which enables
68540d553cfSPaul BeesleyBL31 to detect which information is present and respond appropriately. The
68640d553cfSPaul Beesley``param_header`` is defined to capture this information:
68740d553cfSPaul Beesley
68840d553cfSPaul Beesley.. code:: c
68940d553cfSPaul Beesley
69040d553cfSPaul Beesley    typedef struct param_header {
69140d553cfSPaul Beesley        uint8_t type;       /* type of the structure */
69240d553cfSPaul Beesley        uint8_t version;    /* version of this structure */
69340d553cfSPaul Beesley        uint16_t size;      /* size of this structure in bytes */
6942839a3c4SHarrison Mutai        uint32_t attr;      /* attributes */
69540d553cfSPaul Beesley    } param_header_t;
69640d553cfSPaul Beesley
6972839a3c4SHarrison MutaiIn `entry_point_info`, Bits 0 and 5 of ``attr`` field are used to encode the
6982839a3c4SHarrison Mutaisecurity state; in other words, whether the image is to be executed in Secure,
6992839a3c4SHarrison MutaiNon-Secure, or Realm mode.
7002839a3c4SHarrison Mutai
7012839a3c4SHarrison MutaiOther structures using this format are ``image_info`` and ``bl31_params``. The
7022839a3c4SHarrison Mutaicode that allocates and populates these structures must set the header fields
7032839a3c4SHarrison Mutaiappropriately, the ``SET_PARAM_HEAD()`` macro is defined to simplify this
7042839a3c4SHarrison Mutaiaction.
70540d553cfSPaul Beesley
70640d553cfSPaul BeesleyRequired CPU state for BL31 Warm boot initialization
70740d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70840d553cfSPaul Beesley
70940d553cfSPaul BeesleyWhen requesting a CPU power-on, or suspending a running CPU, TF-A provides
71040d553cfSPaul Beesleythe platform power management code with a Warm boot initialization
71140d553cfSPaul Beesleyentry-point, to be invoked by the CPU immediately after the reset handler.
71240d553cfSPaul BeesleyOn entry to the Warm boot initialization function the calling CPU must be in
71340d553cfSPaul BeesleyAArch64 EL3, little-endian data access and all interrupt sources masked:
71440d553cfSPaul Beesley
71540d553cfSPaul Beesley::
71640d553cfSPaul Beesley
71740d553cfSPaul Beesley    PSTATE.EL = 3
71840d553cfSPaul Beesley    PSTATE.RW = 1
71940d553cfSPaul Beesley    PSTATE.DAIF = 0xf
72040d553cfSPaul Beesley    SCTLR_EL3.EE = 0
72140d553cfSPaul Beesley
72240d553cfSPaul BeesleyThe PSCI implementation will initialize the processor state and ensure that the
72340d553cfSPaul Beesleyplatform power management code is then invoked as required to initialize all
72440d553cfSPaul Beesleynecessary system, cluster and CPU resources.
72540d553cfSPaul Beesley
72640d553cfSPaul BeesleyAArch32 EL3 Runtime Software entrypoint interface
72740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72840d553cfSPaul Beesley
72940d553cfSPaul BeesleyTo enable this firmware architecture it is important to provide a fully
73040d553cfSPaul Beesleydocumented and stable interface between the Trusted Boot Firmware and the
73140d553cfSPaul BeesleyAArch32 EL3 Runtime Software.
73240d553cfSPaul Beesley
73340d553cfSPaul BeesleyFuture changes to the entrypoint interface will be done in a backwards
73440d553cfSPaul Beesleycompatible way, and this enables these firmware components to be independently
73540d553cfSPaul Beesleyenhanced/updated to develop and exploit new functionality.
73640d553cfSPaul Beesley
73740d553cfSPaul BeesleyRequired CPU state when entering during cold boot
73840d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73940d553cfSPaul Beesley
74040d553cfSPaul BeesleyThis function must only be called by the primary CPU.
74140d553cfSPaul Beesley
74240d553cfSPaul BeesleyOn entry to this function the calling primary CPU must be executing in AArch32
74340d553cfSPaul BeesleyEL3, little-endian data access, and all interrupt sources masked:
74440d553cfSPaul Beesley
74540d553cfSPaul Beesley::
74640d553cfSPaul Beesley
74740d553cfSPaul Beesley    PSTATE.AIF = 0x7
74840d553cfSPaul Beesley    SCTLR.EE = 0
74940d553cfSPaul Beesley
75040d553cfSPaul BeesleyR0 and R1 are used to pass information from the Trusted Boot Firmware to the
75140d553cfSPaul Beesleyplatform code in AArch32 EL3 Runtime Software:
75240d553cfSPaul Beesley
75340d553cfSPaul Beesley::
75440d553cfSPaul Beesley
75540d553cfSPaul Beesley    R0 : Reserved for common TF-A information
75640d553cfSPaul Beesley    R1 : Platform specific information
75740d553cfSPaul Beesley
75840d553cfSPaul BeesleyUse of the R0 and R1 parameters
75940d553cfSPaul Beesley'''''''''''''''''''''''''''''''
76040d553cfSPaul Beesley
76140d553cfSPaul BeesleyThe parameters are platform specific and the convention is that ``R0`` conveys
76240d553cfSPaul Beesleyinformation regarding the BL3x images from the Trusted Boot firmware and ``R1``
76340d553cfSPaul Beesleycan be used for other platform specific purpose. This convention allows
76440d553cfSPaul Beesleyplatforms which use TF-A's BL1 and BL2 images to transfer additional platform
76540d553cfSPaul Beesleyspecific information from Secure Boot without conflicting with future
76640d553cfSPaul Beesleyevolution of TF-A using ``R0`` to pass a ``bl_params`` structure.
76740d553cfSPaul Beesley
76840d553cfSPaul BeesleyThe AArch32 EL3 Runtime Software is responsible for entry into BL33. This
76940d553cfSPaul Beesleyinformation can be obtained in a platform defined manner, e.g. compiled into
77040d553cfSPaul Beesleythe AArch32 EL3 Runtime Software, or provided in a platform defined memory
77140d553cfSPaul Beesleylocation by the Trusted Boot firmware, or passed from the Trusted Boot Firmware
77240d553cfSPaul Beesleyvia the Cold boot Initialization parameters. This data may need to be cleaned
77340d553cfSPaul Beesleyout of the CPU caches if it is provided by an earlier boot stage and then
77440d553cfSPaul Beesleyaccessed by AArch32 EL3 Runtime Software before the caches are enabled.
77540d553cfSPaul Beesley
77640d553cfSPaul BeesleyWhen using AArch32 EL3 Runtime Software, the Arm development platforms pass a
77740d553cfSPaul Beesley``bl_params`` structure in ``R0`` from BL2 to be interpreted by AArch32 EL3 Runtime
77840d553cfSPaul BeesleySoftware platform code.
77940d553cfSPaul Beesley
78040d553cfSPaul BeesleyMMU, Data caches & Coherency
78140d553cfSPaul Beesley''''''''''''''''''''''''''''
78240d553cfSPaul Beesley
78340d553cfSPaul BeesleyAArch32 EL3 Runtime Software must not depend on the enabled state of the MMU,
78440d553cfSPaul Beesleydata caches or interconnect coherency in its entrypoint. They must be explicitly
78540d553cfSPaul Beesleyenabled if required.
78640d553cfSPaul Beesley
78740d553cfSPaul BeesleyData structures used in cold boot interface
78840d553cfSPaul Beesley'''''''''''''''''''''''''''''''''''''''''''
78940d553cfSPaul Beesley
79040d553cfSPaul BeesleyThe AArch32 EL3 Runtime Software cold boot interface uses ``bl_params`` instead
79140d553cfSPaul Beesleyof ``bl31_params``. The ``bl_params`` structure is based on the convention
79240d553cfSPaul Beesleydescribed in AArch64 BL31 cold boot interface section.
79340d553cfSPaul Beesley
79440d553cfSPaul BeesleyRequired CPU state for warm boot initialization
79540d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79640d553cfSPaul Beesley
79740d553cfSPaul BeesleyWhen requesting a CPU power-on, or suspending a running CPU, AArch32 EL3
79840d553cfSPaul BeesleyRuntime Software must ensure execution of a warm boot initialization entrypoint.
79940d553cfSPaul BeesleyIf TF-A BL1 is used and the PROGRAMMABLE_RESET_ADDRESS build flag is false,
80040d553cfSPaul Beesleythen AArch32 EL3 Runtime Software must ensure that BL1 branches to the warm
80140d553cfSPaul Beesleyboot entrypoint by arranging for the BL1 platform function,
80240d553cfSPaul Beesleyplat_get_my_entrypoint(), to return a non-zero value.
80340d553cfSPaul Beesley
80440d553cfSPaul BeesleyIn this case, the warm boot entrypoint must be in AArch32 EL3, little-endian
80540d553cfSPaul Beesleydata access and all interrupt sources masked:
80640d553cfSPaul Beesley
80740d553cfSPaul Beesley::
80840d553cfSPaul Beesley
80940d553cfSPaul Beesley    PSTATE.AIF = 0x7
81040d553cfSPaul Beesley    SCTLR.EE = 0
81140d553cfSPaul Beesley
81240d553cfSPaul BeesleyThe warm boot entrypoint may be implemented by using TF-A
81340d553cfSPaul Beesley``psci_warmboot_entrypoint()`` function. In that case, the platform must fulfil
814*b5f120b5SBoyan Karatotevthe pre-requisites mentioned in the :ref:`Porting Guide`.
81540d553cfSPaul Beesley
81640d553cfSPaul BeesleyEL3 runtime services framework
81740d553cfSPaul Beesley------------------------------
81840d553cfSPaul Beesley
81940d553cfSPaul BeesleySoftware executing in the non-secure state and in the secure state at exception
82040d553cfSPaul Beesleylevels lower than EL3 will request runtime services using the Secure Monitor
82140d553cfSPaul BeesleyCall (SMC) instruction. These requests will follow the convention described in
82240d553cfSPaul Beesleythe SMC Calling Convention PDD (`SMCCC`_). The `SMCCC`_ assigns function
82340d553cfSPaul Beesleyidentifiers to each SMC request and describes how arguments are passed and
82440d553cfSPaul Beesleyreturned.
82540d553cfSPaul Beesley
82640d553cfSPaul BeesleyThe EL3 runtime services framework enables the development of services by
82740d553cfSPaul Beesleydifferent providers that can be easily integrated into final product firmware.
82840d553cfSPaul BeesleyThe following sections describe the framework which facilitates the
82940d553cfSPaul Beesleyregistration, initialization and use of runtime services in EL3 Runtime
83040d553cfSPaul BeesleySoftware (BL31).
83140d553cfSPaul Beesley
83240d553cfSPaul BeesleyThe design of the runtime services depends heavily on the concepts and
83340d553cfSPaul Beesleydefinitions described in the `SMCCC`_, in particular SMC Function IDs, Owning
83440d553cfSPaul BeesleyEntity Numbers (OEN), Fast and Yielding calls, and the SMC32 and SMC64 calling
83540d553cfSPaul Beesleyconventions. Please refer to that document for more detailed explanation of
83640d553cfSPaul Beesleythese terms.
83740d553cfSPaul Beesley
83840d553cfSPaul BeesleyThe following runtime services are expected to be implemented first. They have
83940d553cfSPaul Beesleynot all been instantiated in the current implementation.
84040d553cfSPaul Beesley
84140d553cfSPaul Beesley#. Standard service calls
84240d553cfSPaul Beesley
84340d553cfSPaul Beesley   This service is for management of the entire system. The Power State
84440d553cfSPaul Beesley   Coordination Interface (`PSCI`_) is the first set of standard service calls
84540d553cfSPaul Beesley   defined by Arm (see PSCI section later).
84640d553cfSPaul Beesley
84740d553cfSPaul Beesley#. Secure-EL1 Payload Dispatcher service
84840d553cfSPaul Beesley
84940d553cfSPaul Beesley   If a system runs a Trusted OS or other Secure-EL1 Payload (SP) then
85040d553cfSPaul Beesley   it also requires a *Secure Monitor* at EL3 to switch the EL1 processor
85140d553cfSPaul Beesley   context between the normal world (EL1/EL2) and trusted world (Secure-EL1).
85240d553cfSPaul Beesley   The Secure Monitor will make these world switches in response to SMCs. The
85340d553cfSPaul Beesley   `SMCCC`_ provides for such SMCs with the Trusted OS Call and Trusted
85440d553cfSPaul Beesley   Application Call OEN ranges.
85540d553cfSPaul Beesley
85640d553cfSPaul Beesley   The interface between the EL3 Runtime Software and the Secure-EL1 Payload is
85740d553cfSPaul Beesley   not defined by the `SMCCC`_ or any other standard. As a result, each
85840d553cfSPaul Beesley   Secure-EL1 Payload requires a specific Secure Monitor that runs as a runtime
85940d553cfSPaul Beesley   service - within TF-A this service is referred to as the Secure-EL1 Payload
86040d553cfSPaul Beesley   Dispatcher (SPD).
86140d553cfSPaul Beesley
86240d553cfSPaul Beesley   TF-A provides a Test Secure-EL1 Payload (TSP) and its associated Dispatcher
86340d553cfSPaul Beesley   (TSPD). Details of SPD design and TSP/TSPD operation are described in the
86443f35ef5SPaul Beesley   :ref:`firmware_design_sel1_spd` section below.
86540d553cfSPaul Beesley
86640d553cfSPaul Beesley#. CPU implementation service
86740d553cfSPaul Beesley
86840d553cfSPaul Beesley   This service will provide an interface to CPU implementation specific
86940d553cfSPaul Beesley   services for a given platform e.g. access to processor errata workarounds.
87040d553cfSPaul Beesley   This service is currently unimplemented.
87140d553cfSPaul Beesley
87240d553cfSPaul BeesleyAdditional services for Arm Architecture, SiP and OEM calls can be implemented.
87340d553cfSPaul BeesleyEach implemented service handles a range of SMC function identifiers as
87440d553cfSPaul Beesleydescribed in the `SMCCC`_.
87540d553cfSPaul Beesley
87640d553cfSPaul BeesleyRegistration
87740d553cfSPaul Beesley~~~~~~~~~~~~
87840d553cfSPaul Beesley
87940d553cfSPaul BeesleyA runtime service is registered using the ``DECLARE_RT_SVC()`` macro, specifying
88040d553cfSPaul Beesleythe name of the service, the range of OENs covered, the type of service and
88140d553cfSPaul Beesleyinitialization and call handler functions. This macro instantiates a ``const struct rt_svc_desc`` for the service with these details (see ``runtime_svc.h``).
882da04341eSChris KayThis structure is allocated in a special ELF section ``.rt_svc_descs``, enabling
88340d553cfSPaul Beesleythe framework to find all service descriptors included into BL31.
88440d553cfSPaul Beesley
88540d553cfSPaul BeesleyThe specific service for a SMC Function is selected based on the OEN and call
88640d553cfSPaul Beesleytype of the Function ID, and the framework uses that information in the service
88740d553cfSPaul Beesleydescriptor to identify the handler for the SMC Call.
88840d553cfSPaul Beesley
88940d553cfSPaul BeesleyThe service descriptors do not include information to identify the precise set
89040d553cfSPaul Beesleyof SMC function identifiers supported by this service implementation, the
89140d553cfSPaul Beesleysecurity state from which such calls are valid nor the capability to support
89240d553cfSPaul Beesley64-bit and/or 32-bit callers (using SMC32 or SMC64). Responding appropriately
89340d553cfSPaul Beesleyto these aspects of a SMC call is the responsibility of the service
89440d553cfSPaul Beesleyimplementation, the framework is focused on integration of services from
89540d553cfSPaul Beesleydifferent providers and minimizing the time taken by the framework before the
89640d553cfSPaul Beesleyservice handler is invoked.
89740d553cfSPaul Beesley
89840d553cfSPaul BeesleyDetails of the parameters, requirements and behavior of the initialization and
89940d553cfSPaul Beesleycall handling functions are provided in the following sections.
90040d553cfSPaul Beesley
90140d553cfSPaul BeesleyInitialization
90240d553cfSPaul Beesley~~~~~~~~~~~~~~
90340d553cfSPaul Beesley
90440d553cfSPaul Beesley``runtime_svc_init()`` in ``runtime_svc.c`` initializes the runtime services
90540d553cfSPaul Beesleyframework running on the primary CPU during cold boot as part of the BL31
90640d553cfSPaul Beesleyinitialization. This happens prior to initializing a Trusted OS and running
90740d553cfSPaul BeesleyNormal world boot firmware that might in turn use these services.
90840d553cfSPaul BeesleyInitialization involves validating each of the declared runtime service
90940d553cfSPaul Beesleydescriptors, calling the service initialization function and populating the
91040d553cfSPaul Beesleyindex used for runtime lookup of the service.
91140d553cfSPaul Beesley
91240d553cfSPaul BeesleyThe BL31 linker script collects all of the declared service descriptors into a
91340d553cfSPaul Beesleysingle array and defines symbols that allow the framework to locate and traverse
91440d553cfSPaul Beesleythe array, and determine its size.
91540d553cfSPaul Beesley
91640d553cfSPaul BeesleyThe framework does basic validation of each descriptor to halt firmware
91740d553cfSPaul Beesleyinitialization if service declaration errors are detected. The framework does
91840d553cfSPaul Beesleynot check descriptors for the following error conditions, and may behave in an
91940d553cfSPaul Beesleyunpredictable manner under such scenarios:
92040d553cfSPaul Beesley
92140d553cfSPaul Beesley#. Overlapping OEN ranges
92240d553cfSPaul Beesley#. Multiple descriptors for the same range of OENs and ``call_type``
92340d553cfSPaul Beesley#. Incorrect range of owning entity numbers for a given ``call_type``
92440d553cfSPaul Beesley
92540d553cfSPaul BeesleyOnce validated, the service ``init()`` callback is invoked. This function carries
92640d553cfSPaul Beesleyout any essential EL3 initialization before servicing requests. The ``init()``
92740d553cfSPaul Beesleyfunction is only invoked on the primary CPU during cold boot. If the service
92840d553cfSPaul Beesleyuses per-CPU data this must either be initialized for all CPUs during this call,
92940d553cfSPaul Beesleyor be done lazily when a CPU first issues an SMC call to that service. If
93040d553cfSPaul Beesley``init()`` returns anything other than ``0``, this is treated as an initialization
93140d553cfSPaul Beesleyerror and the service is ignored: this does not cause the firmware to halt.
93240d553cfSPaul Beesley
93340d553cfSPaul BeesleyThe OEN and call type fields present in the SMC Function ID cover a total of
93440d553cfSPaul Beesley128 distinct services, but in practice a single descriptor can cover a range of
93540d553cfSPaul BeesleyOENs, e.g. SMCs to call a Trusted OS function. To optimize the lookup of a
93640d553cfSPaul Beesleyservice handler, the framework uses an array of 128 indices that map every
93740d553cfSPaul Beesleydistinct OEN/call-type combination either to one of the declared services or to
93840d553cfSPaul Beesleyindicate the service is not handled. This ``rt_svc_descs_indices[]`` array is
93940d553cfSPaul Beesleypopulated for all of the OENs covered by a service after the service ``init()``
94040d553cfSPaul Beesleyfunction has reported success. So a service that fails to initialize will never
94140d553cfSPaul Beesleyhave it's ``handle()`` function invoked.
94240d553cfSPaul Beesley
94340d553cfSPaul BeesleyThe following figure shows how the ``rt_svc_descs_indices[]`` index maps the SMC
94440d553cfSPaul BeesleyFunction ID call type and OEN onto a specific service handler in the
94540d553cfSPaul Beesley``rt_svc_descs[]`` array.
94640d553cfSPaul Beesley
94740d553cfSPaul Beesley|Image 1|
94840d553cfSPaul Beesley
9496844c347SMadhukar Pappireddy.. _handling-an-smc:
9506844c347SMadhukar Pappireddy
95140d553cfSPaul BeesleyHandling an SMC
95240d553cfSPaul Beesley~~~~~~~~~~~~~~~
95340d553cfSPaul Beesley
95440d553cfSPaul BeesleyWhen the EL3 runtime services framework receives a Secure Monitor Call, the SMC
95540d553cfSPaul BeesleyFunction ID is passed in W0 from the lower exception level (as per the
95640d553cfSPaul Beesley`SMCCC`_). If the calling register width is AArch32, it is invalid to invoke an
95740d553cfSPaul BeesleySMC Function which indicates the SMC64 calling convention: such calls are
95840d553cfSPaul Beesleyignored and return the Unknown SMC Function Identifier result code ``0xFFFFFFFF``
95940d553cfSPaul Beesleyin R0/X0.
96040d553cfSPaul Beesley
96140d553cfSPaul BeesleyBit[31] (fast/yielding call) and bits[29:24] (owning entity number) of the SMC
96240d553cfSPaul BeesleyFunction ID are combined to index into the ``rt_svc_descs_indices[]`` array. The
96340d553cfSPaul Beesleyresulting value might indicate a service that has no handler, in this case the
96440d553cfSPaul Beesleyframework will also report an Unknown SMC Function ID. Otherwise, the value is
96540d553cfSPaul Beesleyused as a further index into the ``rt_svc_descs[]`` array to locate the required
96640d553cfSPaul Beesleyservice and handler.
96740d553cfSPaul Beesley
96840d553cfSPaul BeesleyThe service's ``handle()`` callback is provided with five of the SMC parameters
96940d553cfSPaul Beesleydirectly, the others are saved into memory for retrieval (if needed) by the
97040d553cfSPaul Beesleyhandler. The handler is also provided with an opaque ``handle`` for use with the
97140d553cfSPaul Beesleysupporting library for parameter retrieval, setting return values and context
9720fe7b9f2SOlivier Deprezmanipulation. The ``flags`` parameter indicates the security state of the caller
9730fe7b9f2SOlivier Deprezand the state of the SVE hint bit per the SMCCCv1.3. The framework finally sets
9740fe7b9f2SOlivier Deprezup the execution stack for the handler, and invokes the services ``handle()``
9750fe7b9f2SOlivier Deprezfunction.
97640d553cfSPaul Beesley
977e34cc0ceSMadhukar PappireddyOn return from the handler the result registers are populated in X0-X7 as needed
978e34cc0ceSMadhukar Pappireddybefore restoring the stack and CPU state and returning from the original SMC.
97940d553cfSPaul Beesley
98040d553cfSPaul BeesleyException Handling Framework
98140d553cfSPaul Beesley----------------------------
98240d553cfSPaul Beesley
983526f2bddSjohpow01Please refer to the :ref:`Exception Handling Framework` document.
98440d553cfSPaul Beesley
98540d553cfSPaul BeesleyPower State Coordination Interface
98640d553cfSPaul Beesley----------------------------------
98740d553cfSPaul Beesley
98840d553cfSPaul BeesleyTODO: Provide design walkthrough of PSCI implementation.
98940d553cfSPaul Beesley
99040d553cfSPaul BeesleyThe PSCI v1.1 specification categorizes APIs as optional and mandatory. All the
99140d553cfSPaul Beesleymandatory APIs in PSCI v1.1, PSCI v1.0 and in PSCI v0.2 draft specification
9923be6b4fbSManish V Badarkhe`PSCI`_ are implemented. The table lists the PSCI v1.1 APIs and their support
9933be6b4fbSManish V Badarkhein generic code.
99440d553cfSPaul Beesley
99540d553cfSPaul BeesleyAn API implementation might have a dependency on platform code e.g. CPU_SUSPEND
99640d553cfSPaul Beesleyrequires the platform to export a part of the implementation. Hence the level
99740d553cfSPaul Beesleyof support of the mandatory APIs depends upon the support exported by the
99840d553cfSPaul Beesleyplatform port as well. The Juno and FVP (all variants) platforms export all the
99940d553cfSPaul Beesleyrequired support.
100040d553cfSPaul Beesley
100140d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
100240d553cfSPaul Beesley| PSCI v1.1 API               | Supported   | Comments                      |
100340d553cfSPaul Beesley+=============================+=============+===============================+
100440d553cfSPaul Beesley| ``PSCI_VERSION``            | Yes         | The version returned is 1.1   |
100540d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
100640d553cfSPaul Beesley| ``CPU_SUSPEND``             | Yes\*       |                               |
100740d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
100840d553cfSPaul Beesley| ``CPU_OFF``                 | Yes\*       |                               |
100940d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
101040d553cfSPaul Beesley| ``CPU_ON``                  | Yes\*       |                               |
101140d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
101240d553cfSPaul Beesley| ``AFFINITY_INFO``           | Yes         |                               |
101340d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
101440d553cfSPaul Beesley| ``MIGRATE``                 | Yes\*\*     |                               |
101540d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
101640d553cfSPaul Beesley| ``MIGRATE_INFO_TYPE``       | Yes\*\*     |                               |
101740d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
101840d553cfSPaul Beesley| ``MIGRATE_INFO_CPU``        | Yes\*\*     |                               |
101940d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
102040d553cfSPaul Beesley| ``SYSTEM_OFF``              | Yes\*       |                               |
102140d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
102240d553cfSPaul Beesley| ``SYSTEM_RESET``            | Yes\*       |                               |
102340d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
102440d553cfSPaul Beesley| ``PSCI_FEATURES``           | Yes         |                               |
102540d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
102640d553cfSPaul Beesley| ``CPU_FREEZE``              | No          |                               |
102740d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
102840d553cfSPaul Beesley| ``CPU_DEFAULT_SUSPEND``     | No          |                               |
102940d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
103040d553cfSPaul Beesley| ``NODE_HW_STATE``           | Yes\*       |                               |
103140d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
103240d553cfSPaul Beesley| ``SYSTEM_SUSPEND``          | Yes\*       |                               |
103340d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
103440d553cfSPaul Beesley| ``PSCI_SET_SUSPEND_MODE``   | No          |                               |
103540d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
103640d553cfSPaul Beesley| ``PSCI_STAT_RESIDENCY``     | Yes\*       |                               |
103740d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
103840d553cfSPaul Beesley| ``PSCI_STAT_COUNT``         | Yes\*       |                               |
103940d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
104040d553cfSPaul Beesley| ``SYSTEM_RESET2``           | Yes\*       |                               |
104140d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
104240d553cfSPaul Beesley| ``MEM_PROTECT``             | Yes\*       |                               |
104340d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
104440d553cfSPaul Beesley| ``MEM_PROTECT_CHECK_RANGE`` | Yes\*       |                               |
104540d553cfSPaul Beesley+-----------------------------+-------------+-------------------------------+
104640d553cfSPaul Beesley
104740d553cfSPaul Beesley\*Note : These PSCI APIs require platform power management hooks to be
104840d553cfSPaul Beesleyregistered with the generic PSCI code to be supported.
104940d553cfSPaul Beesley
105040d553cfSPaul Beesley\*\*Note : These PSCI APIs require appropriate Secure Payload Dispatcher
105140d553cfSPaul Beesleyhooks to be registered with the generic PSCI code to be supported.
105240d553cfSPaul Beesley
105340d553cfSPaul BeesleyThe PSCI implementation in TF-A is a library which can be integrated with
105440d553cfSPaul BeesleyAArch64 or AArch32 EL3 Runtime Software for Armv8-A systems. A guide to
1055*b5f120b5SBoyan Karatotevintegrating the PSCI library for EL3 Runtime Software can be found
1056*b5f120b5SBoyan Karatotevat :ref:`Porting Guide`.
105734760951SPaul Beesley
1058d52ff2b3SArvind Ram PrakashDSU driver
1059d52ff2b3SArvind Ram Prakash----------
1060d52ff2b3SArvind Ram Prakash
1061d52ff2b3SArvind Ram PrakashPlatforms that include a DSU (DynamIQ Shared Unit) can define
1062d52ff2b3SArvind Ram Prakashthe ``USE_DSU_DRIVER`` build flag to enable the DSU driver.
1063d52ff2b3SArvind Ram PrakashThis driver is responsible for configuring DSU-related powerdown
10641f866fc9SAmr Mohamedand power feature settings, enabling access to PMU registers at EL1
10651f866fc9SAmr Mohamedusing ``dsu_driver_init()`` and for preserving the context of DSU
10661f866fc9SAmr MohamedPMU system registers.
1067d52ff2b3SArvind Ram Prakash
1068d52ff2b3SArvind Ram PrakashTo support the DSU driver, platforms must define the ``plat_dsu_data``
1069d52ff2b3SArvind Ram Prakashstructure.
1070d52ff2b3SArvind Ram Prakash
107134760951SPaul Beesley.. _firmware_design_sel1_spd:
107240d553cfSPaul Beesley
107340d553cfSPaul BeesleySecure-EL1 Payloads and Dispatchers
107440d553cfSPaul Beesley-----------------------------------
107540d553cfSPaul Beesley
107640d553cfSPaul BeesleyOn a production system that includes a Trusted OS running in Secure-EL1/EL0,
107740d553cfSPaul Beesleythe Trusted OS is coupled with a companion runtime service in the BL31
107840d553cfSPaul Beesleyfirmware. This service is responsible for the initialisation of the Trusted
107940d553cfSPaul BeesleyOS and all communications with it. The Trusted OS is the BL32 stage of the
108040d553cfSPaul Beesleyboot flow in TF-A. The firmware will attempt to locate, load and execute a
108140d553cfSPaul BeesleyBL32 image.
108240d553cfSPaul Beesley
108340d553cfSPaul BeesleyTF-A uses a more general term for the BL32 software that runs at Secure-EL1 -
108440d553cfSPaul Beesleythe *Secure-EL1 Payload* - as it is not always a Trusted OS.
108540d553cfSPaul Beesley
108640d553cfSPaul BeesleyTF-A provides a Test Secure-EL1 Payload (TSP) and a Test Secure-EL1 Payload
108740d553cfSPaul BeesleyDispatcher (TSPD) service as an example of how a Trusted OS is supported on a
108840d553cfSPaul Beesleyproduction system using the Runtime Services Framework. On such a system, the
108940d553cfSPaul BeesleyTest BL32 image and service are replaced by the Trusted OS and its dispatcher
109040d553cfSPaul Beesleyservice. The TF-A build system expects that the dispatcher will define the
109140d553cfSPaul Beesleybuild flag ``NEED_BL32`` to enable it to include the BL32 in the build either
109240d553cfSPaul Beesleyas a binary or to compile from source depending on whether the ``BL32`` build
109340d553cfSPaul Beesleyoption is specified or not.
109440d553cfSPaul Beesley
109540d553cfSPaul BeesleyThe TSP runs in Secure-EL1. It is designed to demonstrate synchronous
109640d553cfSPaul Beesleycommunication with the normal-world software running in EL1/EL2. Communication
109740d553cfSPaul Beesleyis initiated by the normal-world software
109840d553cfSPaul Beesley
109940d553cfSPaul Beesley-  either directly through a Fast SMC (as defined in the `SMCCC`_)
110040d553cfSPaul Beesley
110140d553cfSPaul Beesley-  or indirectly through a `PSCI`_ SMC. The `PSCI`_ implementation in turn
110240d553cfSPaul Beesley   informs the TSPD about the requested power management operation. This allows
110340d553cfSPaul Beesley   the TSP to prepare for or respond to the power state change
110440d553cfSPaul Beesley
110540d553cfSPaul BeesleyThe TSPD service is responsible for.
110640d553cfSPaul Beesley
110740d553cfSPaul Beesley-  Initializing the TSP
110840d553cfSPaul Beesley
110940d553cfSPaul Beesley-  Routing requests and responses between the secure and the non-secure
111040d553cfSPaul Beesley   states during the two types of communications just described
111140d553cfSPaul Beesley
111240d553cfSPaul BeesleyInitializing a BL32 Image
111340d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~
111440d553cfSPaul Beesley
111540d553cfSPaul BeesleyThe Secure-EL1 Payload Dispatcher (SPD) service is responsible for initializing
111640d553cfSPaul Beesleythe BL32 image. It needs access to the information passed by BL2 to BL31 to do
111740d553cfSPaul Beesleyso. This is provided by:
111840d553cfSPaul Beesley
111940d553cfSPaul Beesley.. code:: c
112040d553cfSPaul Beesley
112140d553cfSPaul Beesley    entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t);
112240d553cfSPaul Beesley
112340d553cfSPaul Beesleywhich returns a reference to the ``entry_point_info`` structure corresponding to
112440d553cfSPaul Beesleythe image which will be run in the specified security state. The SPD uses this
112540d553cfSPaul BeesleyAPI to get entry point information for the SECURE image, BL32.
112640d553cfSPaul Beesley
112740d553cfSPaul BeesleyIn the absence of a BL32 image, BL31 passes control to the normal world
112840d553cfSPaul Beesleybootloader image (BL33). When the BL32 image is present, it is typical
112940d553cfSPaul Beesleythat the SPD wants control to be passed to BL32 first and then later to BL33.
113040d553cfSPaul Beesley
113140d553cfSPaul BeesleyTo do this the SPD has to register a BL32 initialization function during
113240d553cfSPaul Beesleyinitialization of the SPD service. The BL32 initialization function has this
113340d553cfSPaul Beesleyprototype:
113440d553cfSPaul Beesley
113540d553cfSPaul Beesley.. code:: c
113640d553cfSPaul Beesley
113740d553cfSPaul Beesley    int32_t init(void);
113840d553cfSPaul Beesley
113940d553cfSPaul Beesleyand is registered using the ``bl31_register_bl32_init()`` function.
114040d553cfSPaul Beesley
114140d553cfSPaul BeesleyTF-A supports two approaches for the SPD to pass control to BL32 before
114240d553cfSPaul Beesleyreturning through EL3 and running the non-trusted firmware (BL33):
114340d553cfSPaul Beesley
114440d553cfSPaul Beesley#. In the BL32 setup function, use ``bl31_set_next_image_type()`` to
114540d553cfSPaul Beesley   request that the exit from ``bl31_main()`` is to the BL32 entrypoint in
114640d553cfSPaul Beesley   Secure-EL1. BL31 will exit to BL32 using the asynchronous method by
114740d553cfSPaul Beesley   calling ``bl31_prepare_next_image_entry()`` and ``el3_exit()``.
114840d553cfSPaul Beesley
114940d553cfSPaul Beesley   When the BL32 has completed initialization at Secure-EL1, it returns to
115040d553cfSPaul Beesley   BL31 by issuing an SMC, using a Function ID allocated to the SPD. On
115140d553cfSPaul Beesley   receipt of this SMC, the SPD service handler should switch the CPU context
115240d553cfSPaul Beesley   from trusted to normal world and use the ``bl31_set_next_image_type()`` and
115340d553cfSPaul Beesley   ``bl31_prepare_next_image_entry()`` functions to set up the initial return to
115440d553cfSPaul Beesley   the normal world firmware BL33. On return from the handler the framework
115540d553cfSPaul Beesley   will exit to EL2 and run BL33.
115640d553cfSPaul Beesley
115740d553cfSPaul Beesley#. The BL32 setup function registers an initialization function using
115840d553cfSPaul Beesley   ``bl31_register_bl32_init()`` which provides a SPD-defined mechanism to
115940d553cfSPaul Beesley   invoke a 'world-switch synchronous call' to Secure-EL1 to run the BL32
116040d553cfSPaul Beesley   entrypoint.
1161e1c5026aSPaul Beesley
1162e1c5026aSPaul Beesley   .. note::
1163e1c5026aSPaul Beesley      The Test SPD service included with TF-A provides one implementation
116440d553cfSPaul Beesley      of such a mechanism.
116540d553cfSPaul Beesley
116640d553cfSPaul Beesley   On completion BL32 returns control to BL31 via a SMC, and on receipt the
116740d553cfSPaul Beesley   SPD service handler invokes the synchronous call return mechanism to return
116840d553cfSPaul Beesley   to the BL32 initialization function. On return from this function,
116940d553cfSPaul Beesley   ``bl31_main()`` will set up the return to the normal world firmware BL33 and
117040d553cfSPaul Beesley   continue the boot process in the normal world.
117140d553cfSPaul Beesley
11729f9bfd7aSManish PandeyException handling in BL31
11739f9bfd7aSManish Pandey--------------------------
11749f9bfd7aSManish Pandey
11759f9bfd7aSManish PandeyWhen exception occurs, PE must execute handler corresponding to exception. The
11769f9bfd7aSManish Pandeylocation in memory where the handler is stored is called the exception vector.
11779f9bfd7aSManish PandeyFor ARM architecture, exception vectors are stored in a table, called the exception
11789f9bfd7aSManish Pandeyvector table.
11799f9bfd7aSManish Pandey
11809f9bfd7aSManish PandeyEach EL (except EL0) has its own vector table, VBAR_ELn register stores the base
11819f9bfd7aSManish Pandeyof vector table. Refer to `AArch64 exception vector table`_
11829f9bfd7aSManish Pandey
11839f9bfd7aSManish PandeyCurrent EL with SP_EL0
11849f9bfd7aSManish Pandey~~~~~~~~~~~~~~~~~~~~~~
11859f9bfd7aSManish Pandey
11869f9bfd7aSManish Pandey-  Sync exception : Not expected except for BRK instruction, its debugging tool which
11879f9bfd7aSManish Pandey   a programmer may place at specific points in a program, to check the state of
11889f9bfd7aSManish Pandey   processor flags at these points in the code.
11899f9bfd7aSManish Pandey
11909f9bfd7aSManish Pandey-  IRQ/FIQ : Unexpected exception, panic
11919f9bfd7aSManish Pandey
11929f9bfd7aSManish Pandey-  SError : "plat_handle_el3_ea", defaults to panic
11939f9bfd7aSManish Pandey
11949f9bfd7aSManish PandeyCurrent EL with SP_ELx
11959f9bfd7aSManish Pandey~~~~~~~~~~~~~~~~~~~~~~
11969f9bfd7aSManish Pandey
11979f9bfd7aSManish Pandey-  Sync exception : Unexpected exception, panic
11989f9bfd7aSManish Pandey
11999f9bfd7aSManish Pandey-  IRQ/FIQ : Unexpected exception, panic
12009f9bfd7aSManish Pandey
12019f9bfd7aSManish Pandey-  SError : "plat_handle_el3_ea" Except for special handling of lower EL's SError exception
12029f9bfd7aSManish Pandey   which gets triggered in EL3 when PSTATE.A is unmasked. Its only applicable when lower
12039f9bfd7aSManish Pandey   EL's EA is routed to EL3 (FFH_SUPPORT=1).
12049f9bfd7aSManish Pandey
12059f9bfd7aSManish PandeyLower EL Exceptions
12069f9bfd7aSManish Pandey~~~~~~~~~~~~~~~~~~~
12079f9bfd7aSManish Pandey
12089f9bfd7aSManish PandeyApplies to all the exceptions in both AArch64/AArch32 mode of lower EL.
12099f9bfd7aSManish Pandey
12109f9bfd7aSManish PandeyBefore handling any lower EL exception, we synchronize the errors at EL3 entry to ensure
12119f9bfd7aSManish Pandeythat any errors pertaining to lower EL is isolated/identified. If we continue without
12129f9bfd7aSManish Pandeyidentifying these errors early on then these errors will trigger in EL3 (as SError from
12139f9bfd7aSManish Pandeycurrent EL) any time after PSTATE.A is unmasked. This is wrong because the error originated
12149f9bfd7aSManish Pandeyin lower EL but exception happened in EL3.
12159f9bfd7aSManish Pandey
12169f9bfd7aSManish PandeyTo solve this problem, synchronize the errors at EL3 entry and check for any pending
12179f9bfd7aSManish Pandeyerrors (async EA). If there is no pending error then continue with original exception.
12189f9bfd7aSManish PandeyIf there is a pending error then, handle them based on routing model of EA's. Refer to
12199f9bfd7aSManish Pandey:ref:`Reliability, Availability, and Serviceability (RAS) Extensions` for details about
12209f9bfd7aSManish Pandeyrouting models.
12219f9bfd7aSManish Pandey
12229f9bfd7aSManish Pandey-  KFH : Reflect it back to lower EL using **reflect_pending_async_ea_to_lower_el()**
12239f9bfd7aSManish Pandey
12249f9bfd7aSManish Pandey-  FFH : Handle the synchronized error first using **handle_pending_async_ea()** after
12259f9bfd7aSManish Pandey   that continue with original exception. It is the only scenario where EL3 is capable
12269f9bfd7aSManish Pandey   of doing nested exception handling.
12279f9bfd7aSManish Pandey
12289f9bfd7aSManish PandeyAfter synchronizing and handling lower EL SErrors, unmask EA (PSTATE.A) to ensure
12299f9bfd7aSManish Pandeythat any further EA's caused by EL3 are caught.
12309f9bfd7aSManish Pandey
123140d553cfSPaul BeesleyCrash Reporting in BL31
123240d553cfSPaul Beesley-----------------------
123340d553cfSPaul Beesley
123440d553cfSPaul BeesleyBL31 implements a scheme for reporting the processor state when an unhandled
123540d553cfSPaul Beesleyexception is encountered. The reporting mechanism attempts to preserve all the
123640d553cfSPaul Beesleyregister contents and report it via a dedicated UART (PL011 console). BL31
123740d553cfSPaul Beesleyreports the general purpose, EL3, Secure EL1 and some EL2 state registers.
123840d553cfSPaul Beesley
123940d553cfSPaul BeesleyA dedicated per-CPU crash stack is maintained by BL31 and this is retrieved via
124040d553cfSPaul Beesleythe per-CPU pointer cache. The implementation attempts to minimise the memory
124140d553cfSPaul Beesleyrequired for this feature. The file ``crash_reporting.S`` contains the
124240d553cfSPaul Beesleyimplementation for crash reporting.
124340d553cfSPaul Beesley
124440d553cfSPaul BeesleyThe sample crash output is shown below.
124540d553cfSPaul Beesley
124640d553cfSPaul Beesley::
124740d553cfSPaul Beesley
1248b4292bc6SAlexei Fedorov    x0             = 0x000000002a4a0000
1249b4292bc6SAlexei Fedorov    x1             = 0x0000000000000001
1250b4292bc6SAlexei Fedorov    x2             = 0x0000000000000002
1251b4292bc6SAlexei Fedorov    x3             = 0x0000000000000003
1252b4292bc6SAlexei Fedorov    x4             = 0x0000000000000004
1253b4292bc6SAlexei Fedorov    x5             = 0x0000000000000005
1254b4292bc6SAlexei Fedorov    x6             = 0x0000000000000006
1255b4292bc6SAlexei Fedorov    x7             = 0x0000000000000007
1256b4292bc6SAlexei Fedorov    x8             = 0x0000000000000008
1257b4292bc6SAlexei Fedorov    x9             = 0x0000000000000009
1258b4292bc6SAlexei Fedorov    x10            = 0x0000000000000010
1259b4292bc6SAlexei Fedorov    x11            = 0x0000000000000011
1260b4292bc6SAlexei Fedorov    x12            = 0x0000000000000012
1261b4292bc6SAlexei Fedorov    x13            = 0x0000000000000013
1262b4292bc6SAlexei Fedorov    x14            = 0x0000000000000014
1263b4292bc6SAlexei Fedorov    x15            = 0x0000000000000015
1264b4292bc6SAlexei Fedorov    x16            = 0x0000000000000016
1265b4292bc6SAlexei Fedorov    x17            = 0x0000000000000017
1266b4292bc6SAlexei Fedorov    x18            = 0x0000000000000018
1267b4292bc6SAlexei Fedorov    x19            = 0x0000000000000019
1268b4292bc6SAlexei Fedorov    x20            = 0x0000000000000020
1269b4292bc6SAlexei Fedorov    x21            = 0x0000000000000021
1270b4292bc6SAlexei Fedorov    x22            = 0x0000000000000022
1271b4292bc6SAlexei Fedorov    x23            = 0x0000000000000023
1272b4292bc6SAlexei Fedorov    x24            = 0x0000000000000024
1273b4292bc6SAlexei Fedorov    x25            = 0x0000000000000025
1274b4292bc6SAlexei Fedorov    x26            = 0x0000000000000026
1275b4292bc6SAlexei Fedorov    x27            = 0x0000000000000027
1276b4292bc6SAlexei Fedorov    x28            = 0x0000000000000028
1277b4292bc6SAlexei Fedorov    x29            = 0x0000000000000029
1278b4292bc6SAlexei Fedorov    x30            = 0x0000000088000b78
1279b4292bc6SAlexei Fedorov    scr_el3        = 0x000000000003073d
1280b4292bc6SAlexei Fedorov    sctlr_el3      = 0x00000000b0cd183f
1281b4292bc6SAlexei Fedorov    cptr_el3       = 0x0000000000000000
1282b4292bc6SAlexei Fedorov    tcr_el3        = 0x000000008080351c
1283b4292bc6SAlexei Fedorov    daif           = 0x00000000000002c0
1284b4292bc6SAlexei Fedorov    mair_el3       = 0x00000000004404ff
1285b4292bc6SAlexei Fedorov    spsr_el3       = 0x0000000060000349
1286b4292bc6SAlexei Fedorov    elr_el3        = 0x0000000088000114
1287b4292bc6SAlexei Fedorov    ttbr0_el3      = 0x0000000004018201
1288b4292bc6SAlexei Fedorov    esr_el3        = 0x00000000be000000
1289b4292bc6SAlexei Fedorov    far_el3        = 0x0000000000000000
1290b4292bc6SAlexei Fedorov    spsr_el1       = 0x0000000000000000
1291b4292bc6SAlexei Fedorov    elr_el1        = 0x0000000000000000
1292b4292bc6SAlexei Fedorov    spsr_abt       = 0x0000000000000000
1293b4292bc6SAlexei Fedorov    spsr_und       = 0x0000000000000000
1294b4292bc6SAlexei Fedorov    spsr_irq       = 0x0000000000000000
1295b4292bc6SAlexei Fedorov    spsr_fiq       = 0x0000000000000000
1296b4292bc6SAlexei Fedorov    sctlr_el1      = 0x0000000030d00800
1297b4292bc6SAlexei Fedorov    actlr_el1      = 0x0000000000000000
1298b4292bc6SAlexei Fedorov    cpacr_el1      = 0x0000000000000000
1299b4292bc6SAlexei Fedorov    csselr_el1     = 0x0000000000000000
1300b4292bc6SAlexei Fedorov    sp_el1         = 0x0000000000000000
1301b4292bc6SAlexei Fedorov    esr_el1        = 0x0000000000000000
1302b4292bc6SAlexei Fedorov    ttbr0_el1      = 0x0000000000000000
1303b4292bc6SAlexei Fedorov    ttbr1_el1      = 0x0000000000000000
1304b4292bc6SAlexei Fedorov    mair_el1       = 0x0000000000000000
1305b4292bc6SAlexei Fedorov    amair_el1      = 0x0000000000000000
1306b4292bc6SAlexei Fedorov    tcr_el1        = 0x0000000000000000
1307b4292bc6SAlexei Fedorov    tpidr_el1      = 0x0000000000000000
1308b4292bc6SAlexei Fedorov    tpidr_el0      = 0x0000000000000000
1309b4292bc6SAlexei Fedorov    tpidrro_el0    = 0x0000000000000000
1310b4292bc6SAlexei Fedorov    par_el1        = 0x0000000000000000
1311b4292bc6SAlexei Fedorov    mpidr_el1      = 0x0000000080000000
1312b4292bc6SAlexei Fedorov    afsr0_el1      = 0x0000000000000000
1313b4292bc6SAlexei Fedorov    afsr1_el1      = 0x0000000000000000
1314b4292bc6SAlexei Fedorov    contextidr_el1 = 0x0000000000000000
1315b4292bc6SAlexei Fedorov    vbar_el1       = 0x0000000000000000
1316b4292bc6SAlexei Fedorov    cntp_ctl_el0   = 0x0000000000000000
1317b4292bc6SAlexei Fedorov    cntp_cval_el0  = 0x0000000000000000
1318b4292bc6SAlexei Fedorov    cntv_ctl_el0   = 0x0000000000000000
1319b4292bc6SAlexei Fedorov    cntv_cval_el0  = 0x0000000000000000
1320b4292bc6SAlexei Fedorov    cntkctl_el1    = 0x0000000000000000
1321b4292bc6SAlexei Fedorov    sp_el0         = 0x0000000004014940
1322b4292bc6SAlexei Fedorov    isr_el1        = 0x0000000000000000
1323b4292bc6SAlexei Fedorov    dacr32_el2     = 0x0000000000000000
1324b4292bc6SAlexei Fedorov    ifsr32_el2     = 0x0000000000000000
1325b4292bc6SAlexei Fedorov    icc_hppir0_el1 = 0x00000000000003ff
1326b4292bc6SAlexei Fedorov    icc_hppir1_el1 = 0x00000000000003ff
1327b4292bc6SAlexei Fedorov    icc_ctlr_el3   = 0x0000000000080400
1328b4292bc6SAlexei Fedorov    gicd_ispendr regs (Offsets 0x200-0x278)
1329b4292bc6SAlexei Fedorov    Offset		    Value
1330b4292bc6SAlexei Fedorov    0x200:	     0x0000000000000000
1331b4292bc6SAlexei Fedorov    0x208:	     0x0000000000000000
1332b4292bc6SAlexei Fedorov    0x210:	     0x0000000000000000
1333b4292bc6SAlexei Fedorov    0x218:	     0x0000000000000000
1334b4292bc6SAlexei Fedorov    0x220:	     0x0000000000000000
1335b4292bc6SAlexei Fedorov    0x228:	     0x0000000000000000
1336b4292bc6SAlexei Fedorov    0x230:	     0x0000000000000000
1337b4292bc6SAlexei Fedorov    0x238:	     0x0000000000000000
1338b4292bc6SAlexei Fedorov    0x240:	     0x0000000000000000
1339b4292bc6SAlexei Fedorov    0x248:	     0x0000000000000000
1340b4292bc6SAlexei Fedorov    0x250:	     0x0000000000000000
1341b4292bc6SAlexei Fedorov    0x258:	     0x0000000000000000
1342b4292bc6SAlexei Fedorov    0x260:	     0x0000000000000000
1343b4292bc6SAlexei Fedorov    0x268:	     0x0000000000000000
1344b4292bc6SAlexei Fedorov    0x270:	     0x0000000000000000
1345b4292bc6SAlexei Fedorov    0x278:	     0x0000000000000000
134640d553cfSPaul Beesley
134740d553cfSPaul BeesleyGuidelines for Reset Handlers
134840d553cfSPaul Beesley-----------------------------
134940d553cfSPaul Beesley
135040d553cfSPaul BeesleyTF-A implements a framework that allows CPU and platform ports to perform
135140d553cfSPaul Beesleyactions very early after a CPU is released from reset in both the cold and warm
13520d020822SBoyan Karatotevboot paths. This is done by calling the ``reset_handler`` macro/function in both
135340d553cfSPaul Beesleythe BL1 and BL31 images. It in turn calls the platform and CPU specific reset
135440d553cfSPaul Beesleyhandling functions.
135540d553cfSPaul Beesley
135640d553cfSPaul BeesleyDetails for implementing a CPU specific reset handler can be found in
13576a0e8e80SBoyan Karatotev:ref:`firmware_design_cpu_specific_reset_handling`. Details for implementing a
13586a0e8e80SBoyan Karatotevplatform specific reset handler can be found in the :ref:`Porting Guide` (see
13596a0e8e80SBoyan Karatotevthe``plat_reset_handler()`` function).
136040d553cfSPaul Beesley
136140d553cfSPaul BeesleyWhen adding functionality to a reset handler, keep in mind that if a different
136240d553cfSPaul Beesleyreset handling behavior is required between the first and the subsequent
136340d553cfSPaul Beesleyinvocations of the reset handling code, this should be detected at runtime.
136440d553cfSPaul BeesleyIn other words, the reset handler should be able to detect whether an action has
136540d553cfSPaul Beesleyalready been performed and act as appropriate. Possible courses of actions are,
136640d553cfSPaul Beesleye.g. skip the action the second time, or undo/redo it.
136740d553cfSPaul Beesley
13686844c347SMadhukar Pappireddy.. _configuring-secure-interrupts:
13696844c347SMadhukar Pappireddy
137040d553cfSPaul BeesleyConfiguring secure interrupts
137140d553cfSPaul Beesley-----------------------------
137240d553cfSPaul Beesley
137340d553cfSPaul BeesleyThe GIC driver is responsible for performing initial configuration of secure
137440d553cfSPaul Beesleyinterrupts on the platform. To this end, the platform is expected to provide the
137540d553cfSPaul BeesleyGIC driver (either GICv2 or GICv3, as selected by the platform) with the
137640d553cfSPaul Beesleyinterrupt configuration during the driver initialisation.
137740d553cfSPaul Beesley
137840d553cfSPaul BeesleySecure interrupt configuration are specified in an array of secure interrupt
137940d553cfSPaul Beesleyproperties. In this scheme, in both GICv2 and GICv3 driver data structures, the
138040d553cfSPaul Beesley``interrupt_props`` member points to an array of interrupt properties. Each
138140d553cfSPaul Beesleyelement of the array specifies the interrupt number and its attributes
138240d553cfSPaul Beesley(priority, group, configuration). Each element of the array shall be populated
138340d553cfSPaul Beesleyby the macro ``INTR_PROP_DESC()``. The macro takes the following arguments:
138440d553cfSPaul Beesley
1385d5eee8f3SMing Huang- 13-bit interrupt number,
138640d553cfSPaul Beesley
138740d553cfSPaul Beesley- 8-bit interrupt priority,
138840d553cfSPaul Beesley
138940d553cfSPaul Beesley- Interrupt type (one of ``INTR_TYPE_EL3``, ``INTR_TYPE_S_EL1``,
139040d553cfSPaul Beesley  ``INTR_TYPE_NS``),
139140d553cfSPaul Beesley
139240d553cfSPaul Beesley- Interrupt configuration (either ``GIC_INTR_CFG_LEVEL`` or
139340d553cfSPaul Beesley  ``GIC_INTR_CFG_EDGE``).
139440d553cfSPaul Beesley
139534760951SPaul Beesley.. _firmware_design_cpu_ops_fwk:
139634760951SPaul Beesley
139740d553cfSPaul BeesleyCPU specific operations framework
139840d553cfSPaul Beesley---------------------------------
139940d553cfSPaul Beesley
140040d553cfSPaul BeesleyCertain aspects of the Armv8-A architecture are implementation defined,
140140d553cfSPaul Beesleythat is, certain behaviours are not architecturally defined, but must be
140240d553cfSPaul Beesleydefined and documented by individual processor implementations. TF-A
140340d553cfSPaul Beesleyimplements a framework which categorises the common implementation defined
140440d553cfSPaul Beesleybehaviours and allows a processor to export its implementation of that
140540d553cfSPaul Beesleybehaviour. The categories are:
140640d553cfSPaul Beesley
140740d553cfSPaul Beesley#. Processor specific reset sequence.
140840d553cfSPaul Beesley
140940d553cfSPaul Beesley#. Processor specific power down sequences.
141040d553cfSPaul Beesley
141140d553cfSPaul Beesley#. Processor specific register dumping as a part of crash reporting.
141240d553cfSPaul Beesley
141340d553cfSPaul Beesley#. Errata status reporting.
141440d553cfSPaul Beesley
141540d553cfSPaul BeesleyEach of the above categories fulfils a different requirement.
141640d553cfSPaul Beesley
141740d553cfSPaul Beesley#. allows any processor specific initialization before the caches and MMU
141840d553cfSPaul Beesley   are turned on, like implementation of errata workarounds, entry into
141940d553cfSPaul Beesley   the intra-cluster coherency domain etc.
142040d553cfSPaul Beesley
142140d553cfSPaul Beesley#. allows each processor to implement the power down sequence mandated in
142240d553cfSPaul Beesley   its Technical Reference Manual (TRM).
142340d553cfSPaul Beesley
142440d553cfSPaul Beesley#. allows a processor to provide additional information to the developer
142540d553cfSPaul Beesley   in the event of a crash, for example Cortex-A53 has registers which
142640d553cfSPaul Beesley   can expose the data cache contents.
142740d553cfSPaul Beesley
142840d553cfSPaul Beesley#. allows a processor to define a function that inspects and reports the status
142940d553cfSPaul Beesley   of all errata workarounds on that processor.
143040d553cfSPaul Beesley
143140d553cfSPaul BeesleyPlease note that only 2. is mandated by the TRM.
143240d553cfSPaul Beesley
143340d553cfSPaul BeesleyThe CPU specific operations framework scales to accommodate a large number of
143440d553cfSPaul Beesleydifferent CPUs during power down and reset handling. The platform can specify
143540d553cfSPaul Beesleyany CPU optimization it wants to enable for each CPU. It can also specify
143640d553cfSPaul Beesleythe CPU errata workarounds to be applied for each CPU type during reset
143740d553cfSPaul Beesleyhandling by defining CPU errata compile time macros. Details on these macros
143834760951SPaul Beesleycan be found in the :ref:`Arm CPU Specific Build Macros` document.
143940d553cfSPaul Beesley
144040d553cfSPaul BeesleyThe CPU specific operations framework depends on the ``cpu_ops`` structure which
144140d553cfSPaul Beesleyneeds to be exported for each type of CPU in the platform. It is defined in
144240d553cfSPaul Beesley``include/lib/cpus/aarch64/cpu_macros.S`` and has the following fields : ``midr``,
144340d553cfSPaul Beesley``reset_func()``, ``cpu_pwr_down_ops`` (array of power down functions) and
144440d553cfSPaul Beesley``cpu_reg_dump()``.
144540d553cfSPaul Beesley
144640d553cfSPaul BeesleyThe CPU specific files in ``lib/cpus`` export a ``cpu_ops`` data structure with
144740d553cfSPaul Beesleysuitable handlers for that CPU. For example, ``lib/cpus/aarch64/cortex_a53.S``
144840d553cfSPaul Beesleyexports the ``cpu_ops`` for Cortex-A53 CPU. According to the platform
144940d553cfSPaul Beesleyconfiguration, these CPU specific files must be included in the build by
145040d553cfSPaul Beesleythe platform makefile. The generic CPU specific operations framework code exists
145140d553cfSPaul Beesleyin ``lib/cpus/aarch64/cpu_helpers.S``.
145240d553cfSPaul Beesley
14536a0e8e80SBoyan KaratotevCPU PCS
14546a0e8e80SBoyan Karatotev~~~~~~~
14556a0e8e80SBoyan Karatotev
14566a0e8e80SBoyan KaratotevAll assembly functions in CPU files are asked to follow a modified version of
14576a0e8e80SBoyan Karatotevthe Procedure Call Standard (PCS) in their internals. This is done to ensure
14586a0e8e80SBoyan Karatotevcalling these functions from outside the file doesn't unexpectedly corrupt
14596a0e8e80SBoyan Karatotevregisters in the very early environment and to help the internals to be easier
14606a0e8e80SBoyan Karatotevto understand. Please see the :ref:`firmware_design_cpu_errata_implementation`
14616a0e8e80SBoyan Karatotevfor any function specific restrictions.
14626a0e8e80SBoyan Karatotev
14636a0e8e80SBoyan Karatotev+--------------+---------------------------------+
14646a0e8e80SBoyan Karatotev|   register   | use                             |
14656a0e8e80SBoyan Karatotev+==============+=================================+
14666a0e8e80SBoyan Karatotev|   x0 - x15   | scratch                         |
14676a0e8e80SBoyan Karatotev+--------------+---------------------------------+
14686a0e8e80SBoyan Karatotev|   x16, x17   | do not use (used by the linker) |
14696a0e8e80SBoyan Karatotev+--------------+---------------------------------+
14706a0e8e80SBoyan Karatotev|     x18      | do not use (platform register)  |
14716a0e8e80SBoyan Karatotev+--------------+---------------------------------+
14726a0e8e80SBoyan Karatotev|   x19 - x28  | callee saved                    |
14736a0e8e80SBoyan Karatotev+--------------+---------------------------------+
14746a0e8e80SBoyan Karatotev|   x29, x30   | FP, LR                          |
14756a0e8e80SBoyan Karatotev+--------------+---------------------------------+
14766a0e8e80SBoyan Karatotev
14776a0e8e80SBoyan Karatotev.. _firmware_design_cpu_specific_reset_handling:
14786a0e8e80SBoyan Karatotev
147940d553cfSPaul BeesleyCPU specific Reset Handling
148040d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~
148140d553cfSPaul Beesley
148240d553cfSPaul BeesleyAfter a reset, the state of the CPU when it calls generic reset handler is:
14836a0e8e80SBoyan KaratotevMMU turned off, both instruction and data caches turned off, not part
14846a0e8e80SBoyan Karatotevof any coherency domain and no stack.
148540d553cfSPaul Beesley
148640d553cfSPaul BeesleyThe BL entrypoint code first invokes the ``plat_reset_handler()`` to allow
148740d553cfSPaul Beesleythe platform to perform any system initialization required and any system
148840d553cfSPaul Beesleyerrata workarounds that needs to be applied. The ``get_cpu_ops_ptr()`` reads
148940d553cfSPaul Beesleythe current CPU midr, finds the matching ``cpu_ops`` entry in the ``cpu_ops``
149040d553cfSPaul Beesleyarray and returns it. Note that only the part number and implementer fields
149140d553cfSPaul Beesleyin midr are used to find the matching ``cpu_ops`` entry. The ``reset_func()`` in
149240d553cfSPaul Beesleythe returned ``cpu_ops`` is then invoked which executes the required reset
149340d553cfSPaul Beesleyhandling for that CPU and also any errata workarounds enabled by the platform.
149440d553cfSPaul Beesley
14956a0e8e80SBoyan KaratotevIt should be defined using the ``cpu_reset_func_{start,end}`` macros and its
149689dba82dSBoyan Karatotevbody may only clobber x0 to x14 with x14 being the cpu_rev parameter. The cpu
149789dba82dSBoyan Karatotevfile should also include a call to ``cpu_reset_prologue`` at the start of the
149889dba82dSBoyan Karatotevfile for errata to work correctly.
149940d553cfSPaul Beesley
150040d553cfSPaul BeesleyCPU specific power down sequence
150140d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150240d553cfSPaul Beesley
150340d553cfSPaul BeesleyDuring the BL31 initialization sequence, the pointer to the matching ``cpu_ops``
1504022fcb48SBoyan Karatoteventry is stored in per-CPU data by ``cpu_data_init_cpu_ops()`` so that it can be quickly
150540d553cfSPaul Beesleyretrieved during power down sequences.
150640d553cfSPaul Beesley
150740d553cfSPaul BeesleyVarious CPU drivers register handlers to perform power down at certain power
150840d553cfSPaul Beesleylevels for that specific CPU. The PSCI service, upon receiving a power down
150940d553cfSPaul Beesleyrequest, determines the highest power level at which to execute power down
151040d553cfSPaul Beesleysequence for a particular CPU. It uses the ``prepare_cpu_pwr_dwn()`` function to
151140d553cfSPaul Beesleypick the right power down handler for the requested level. The function
151240d553cfSPaul Beesleyretrieves ``cpu_ops`` pointer member of per-CPU data, and from that, further
151340d553cfSPaul Beesleyretrieves ``cpu_pwr_down_ops`` array, and indexes into the required level. If the
151440d553cfSPaul Beesleyrequested power level is higher than what a CPU driver supports, the handler
151540d553cfSPaul Beesleyregistered for highest level is invoked.
151640d553cfSPaul Beesley
151740d553cfSPaul BeesleyAt runtime the platform hooks for power down are invoked by the PSCI service to
151840d553cfSPaul Beesleyperform platform specific operations during a power down sequence, for example
151940d553cfSPaul Beesleyturning off CCI coherency during a cluster power down.
152040d553cfSPaul Beesley
15212b5e00d4SBoyan KaratotevNewer CPUs include a feature called "powerdown abandon". The feature is based on
15222b5e00d4SBoyan Karatotevthe observation that events like GIC wakeups have a high likelihood of happening
15232b5e00d4SBoyan Karatotevwhile the core is in the middle of its powerdown sequence (at ``wfi``). Older
15242b5e00d4SBoyan Karatotevcores will powerdown and immediately power back up when this happens. To save on
15252b5e00d4SBoyan Karatotevthe work and latency involved, the newer cores will "give up" mid way through if
15262b5e00d4SBoyan Karatotevno context has been lost yet. This is possible as the powerdown operation is
15272b5e00d4SBoyan Karatotevlengthy and a large part of it does not lose context.
15282b5e00d4SBoyan Karatotev
15292b5e00d4SBoyan KaratotevTo cater for this possibility, the powerdown hook will be called a second time
15302b5e00d4SBoyan Karatotevafter a wakeup. The expectation is that the first call will operate as before,
15312b5e00d4SBoyan Karatotevwhile the second call will undo anything the first call did. This should be done
15322b5e00d4SBoyan Karatotevstatelessly, for example by toggling the relevant bits.
15332b5e00d4SBoyan Karatotev
153440d553cfSPaul BeesleyCPU specific register reporting during crash
153540d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153640d553cfSPaul Beesley
153740d553cfSPaul BeesleyIf the crash reporting is enabled in BL31, when a crash occurs, the crash
153840d553cfSPaul Beesleyreporting framework calls ``do_cpu_reg_dump`` which retrieves the matching
153940d553cfSPaul Beesley``cpu_ops`` using ``get_cpu_ops_ptr()`` function. The ``cpu_reg_dump()`` in
154040d553cfSPaul Beesley``cpu_ops`` is invoked, which then returns the CPU specific register values to
154140d553cfSPaul Beesleybe reported and a pointer to the ASCII list of register names in a format
154240d553cfSPaul Beesleyexpected by the crash reporting framework.
154340d553cfSPaul Beesley
15446a0e8e80SBoyan Karatotev.. _firmware_design_cpu_errata_implementation:
154534760951SPaul Beesley
15466a0e8e80SBoyan KaratotevCPU errata implementation
15476a0e8e80SBoyan Karatotev~~~~~~~~~~~~~~~~~~~~~~~~~
154840d553cfSPaul Beesley
154940d553cfSPaul BeesleyErrata workarounds for CPUs supported in TF-A are applied during both cold and
155040d553cfSPaul Beesleywarm boots, shortly after reset. Individual Errata workarounds are enabled as
155140d553cfSPaul Beesleybuild options. Some errata workarounds have potential run-time implications;
155240d553cfSPaul Beesleytherefore some are enabled by default, others not. Platform ports shall
155340d553cfSPaul Beesleyoverride build options to enable or disable errata as appropriate. The CPU
155440d553cfSPaul Beesleydrivers take care of applying errata workarounds that are enabled and applicable
15556a0e8e80SBoyan Karatotevto a given CPU.
155640d553cfSPaul Beesley
15576a0e8e80SBoyan KaratotevEach erratum has a build flag in ``lib/cpus/cpu-ops.mk`` of the form:
15586a0e8e80SBoyan Karatotev``ERRATA_<cpu_num>_<erratum_id>``. It also has a short description in
15596a0e8e80SBoyan Karatotev:ref:`arm_cpu_macros_errata_workarounds` on when it should apply.
156040d553cfSPaul Beesley
15616a0e8e80SBoyan KaratotevErrata framework
15626a0e8e80SBoyan Karatotev^^^^^^^^^^^^^^^^
156340d553cfSPaul Beesley
15646a0e8e80SBoyan KaratotevThe errata framework is a convention and a small library to allow errata to be
15656a0e8e80SBoyan Karatotevautomatically discovered. It enables compliant errata to be automatically
15666a0e8e80SBoyan Karatotevapplied and reported at runtime (either by status reporting or the errata ABI).
156740d553cfSPaul Beesley
15686a0e8e80SBoyan KaratotevTo write a compliant mitigation for erratum number ``erratum_id`` on a cpu that
15696a0e8e80SBoyan Karatotevdeclared itself (with ``declare_cpu_ops``) as ``cpu_name`` one needs 3 things:
157040d553cfSPaul Beesley
15716a0e8e80SBoyan Karatotev#. A CPU revision checker function: ``check_erratum_<cpu_name>_<erratum_id>``
157240d553cfSPaul Beesley
15736a0e8e80SBoyan Karatotev   It should check whether this erratum applies on this revision of this CPU.
15746a0e8e80SBoyan Karatotev   It will be called with the CPU revision as its first parameter (x0) and
15756a0e8e80SBoyan Karatotev   should return one of ``ERRATA_APPLIES`` or ``ERRATA_NOT_APPLIES``.
157640d553cfSPaul Beesley
15776a0e8e80SBoyan Karatotev   It may only clobber x0 to x4. The rest should be treated as callee-saved.
15786a0e8e80SBoyan Karatotev
15796a0e8e80SBoyan Karatotev#. A workaround function: ``erratum_<cpu_name>_<erratum_id>_wa``
15806a0e8e80SBoyan Karatotev
15816a0e8e80SBoyan Karatotev   It should obtain the cpu revision (with ``cpu_get_rev_var``), call its
15826a0e8e80SBoyan Karatotev   revision checker, and perform the mitigation, should the erratum apply.
15836a0e8e80SBoyan Karatotev
15846a0e8e80SBoyan Karatotev   It may only clobber x0 to x8. The rest should be treated as callee-saved.
15856a0e8e80SBoyan Karatotev
15866a0e8e80SBoyan Karatotev#. Register itself to the framework
15876a0e8e80SBoyan Karatotev
15886a0e8e80SBoyan Karatotev   Do this with
15896a0e8e80SBoyan Karatotev   ``add_erratum_entry <cpu_name>, ERRATUM(<erratum_id>), <errata_flag>``
15906a0e8e80SBoyan Karatotev   where the ``errata_flag`` is the enable flag in ``cpu-ops.mk`` described
15916a0e8e80SBoyan Karatotev   above.
15926a0e8e80SBoyan Karatotev
15936a0e8e80SBoyan KaratotevSee the next section on how to do this easily.
15946a0e8e80SBoyan Karatotev
15956a0e8e80SBoyan Karatotev.. note::
15966a0e8e80SBoyan Karatotev
15976a0e8e80SBoyan Karatotev CVEs have the format ``CVE_<year>_<number>``. To fit them in the framework, the
15986a0e8e80SBoyan Karatotev ``erratum_id`` for the checker and the workaround functions become the
15996a0e8e80SBoyan Karatotev ``number`` part of its name and the ``ERRATUM(<number>)`` part of the
16006a0e8e80SBoyan Karatotev registration should instead be ``CVE(<year>, <number>)``. In the extremely
16016a0e8e80SBoyan Karatotev unlikely scenario where a CVE and an erratum numbers clash, the CVE number
16026a0e8e80SBoyan Karatotev should be prefixed with a zero.
16036a0e8e80SBoyan Karatotev
16046a0e8e80SBoyan Karatotev Also, their build flag should be ``WORKAROUND_CVE_<year>_<number>``.
16056a0e8e80SBoyan Karatotev
16066a0e8e80SBoyan Karatotev.. note::
16076a0e8e80SBoyan Karatotev
16086a0e8e80SBoyan Karatotev AArch32 uses the legacy convention. The checker function has the format
16096a0e8e80SBoyan Karatotev ``check_errata_<erratum_id>`` and the workaround has the format
16106a0e8e80SBoyan Karatotev ``errata_<cpu_number>_<erratum_id>_wa`` where ``cpu_number`` is the shortform
16116a0e8e80SBoyan Karatotev letter and number name of the CPU.
16126a0e8e80SBoyan Karatotev
16136a0e8e80SBoyan Karatotev For CVEs the ``erratum_id`` also becomes ``cve_<year>_<number>``.
16146a0e8e80SBoyan Karatotev
16156a0e8e80SBoyan KaratotevErrata framework helpers
16166a0e8e80SBoyan Karatotev^^^^^^^^^^^^^^^^^^^^^^^^
16176a0e8e80SBoyan Karatotev
16186a0e8e80SBoyan KaratotevWriting these errata involves lots of boilerplate and repetitive code. On
16196a0e8e80SBoyan KaratotevAArch64 there are helpers to omit most of this. They are located in
16206a0e8e80SBoyan Karatotev``include/lib/cpus/aarch64/cpu_macros.S`` and the preferred way to implement
16216a0e8e80SBoyan Karatoteverrata. Please see their comments on how to use them.
16226a0e8e80SBoyan Karatotev
16236a0e8e80SBoyan KaratotevThe most common type of erratum workaround, one that just sets a "chicken" bit
16246a0e8e80SBoyan Karatotevin some arbitrary register, would have an implementation for the Cortex-A77,
16256a0e8e80SBoyan Karatoteverratum #1925769 like::
16266a0e8e80SBoyan Karatotev
16276a0e8e80SBoyan Karatotev    workaround_reset_start cortex_a77, ERRATUM(1925769), ERRATA_A77_1925769
16286a0e8e80SBoyan Karatotev        sysreg_bit_set CORTEX_A77_CPUECTLR_EL1, CORTEX_A77_CPUECTLR_EL1_BIT_8
16296a0e8e80SBoyan Karatotev    workaround_reset_end cortex_a77, ERRATUM(1925769)
16306a0e8e80SBoyan Karatotev
16316a0e8e80SBoyan Karatotev    check_erratum_ls cortex_a77, ERRATUM(1925769), CPU_REV(1, 1)
16326a0e8e80SBoyan Karatotev
16336a0e8e80SBoyan KaratotevStatus reporting
16346a0e8e80SBoyan Karatotev^^^^^^^^^^^^^^^^
163540d553cfSPaul Beesley
163640d553cfSPaul BeesleyIn a debug build of TF-A, on a CPU that comes out of reset, both BL1 and the
16376a0e8e80SBoyan Karatotevruntime firmware (BL31 in AArch64, and BL32 in AArch32) will invoke a generic
16386a0e8e80SBoyan Karatoteverrata status reporting function. It will read the ``errata_entries`` list of
16396a0e8e80SBoyan Karatotevthat cpu and will report whether each known erratum was applied and, if not,
16406a0e8e80SBoyan Karatotevwhether it should have been.
164140d553cfSPaul Beesley
164240d553cfSPaul BeesleyReporting the status of errata workaround is for informational purpose only; it
164340d553cfSPaul Beesleyhas no functional significance.
164440d553cfSPaul Beesley
164540d553cfSPaul BeesleyMemory layout of BL images
164640d553cfSPaul Beesley--------------------------
164740d553cfSPaul Beesley
164840d553cfSPaul BeesleyEach bootloader image can be divided in 2 parts:
164940d553cfSPaul Beesley
165040d553cfSPaul Beesley-  the static contents of the image. These are data actually stored in the
165140d553cfSPaul Beesley   binary on the disk. In the ELF terminology, they are called ``PROGBITS``
165240d553cfSPaul Beesley   sections;
165340d553cfSPaul Beesley
165440d553cfSPaul Beesley-  the run-time contents of the image. These are data that don't occupy any
165540d553cfSPaul Beesley   space in the binary on the disk. The ELF binary just contains some
165640d553cfSPaul Beesley   metadata indicating where these data will be stored at run-time and the
165740d553cfSPaul Beesley   corresponding sections need to be allocated and initialized at run-time.
165840d553cfSPaul Beesley   In the ELF terminology, they are called ``NOBITS`` sections.
165940d553cfSPaul Beesley
166040d553cfSPaul BeesleyAll PROGBITS sections are grouped together at the beginning of the image,
166140d553cfSPaul Beesleyfollowed by all NOBITS sections. This is true for all TF-A images and it is
166240d553cfSPaul Beesleygoverned by the linker scripts. This ensures that the raw binary images are
166340d553cfSPaul Beesleyas small as possible. If a NOBITS section was inserted in between PROGBITS
166440d553cfSPaul Beesleysections then the resulting binary file would contain zero bytes in place of
166540d553cfSPaul Beesleythis NOBITS section, making the image unnecessarily bigger. Smaller images
166640d553cfSPaul Beesleyallow faster loading from the FIP to the main memory.
166740d553cfSPaul Beesley
1668f8578e64SSamuel HollandFor BL31, a platform can specify an alternate location for NOBITS sections
1669f8578e64SSamuel Holland(other than immediately following PROGBITS sections) by setting
1670f8578e64SSamuel Holland``SEPARATE_NOBITS_REGION`` to 1 and defining ``BL31_NOBITS_BASE`` and
1671f8578e64SSamuel Holland``BL31_NOBITS_LIMIT``.
1672f8578e64SSamuel Holland
167340d553cfSPaul BeesleyLinker scripts and symbols
167440d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~
167540d553cfSPaul Beesley
167640d553cfSPaul BeesleyEach bootloader stage image layout is described by its own linker script. The
167740d553cfSPaul Beesleylinker scripts export some symbols into the program symbol table. Their values
167840d553cfSPaul Beesleycorrespond to particular addresses. TF-A code can refer to these symbols to
167940d553cfSPaul Beesleyfigure out the image memory layout.
168040d553cfSPaul Beesley
168140d553cfSPaul BeesleyLinker symbols follow the following naming convention in TF-A.
168240d553cfSPaul Beesley
168340d553cfSPaul Beesley-  ``__<SECTION>_START__``
168440d553cfSPaul Beesley
168540d553cfSPaul Beesley   Start address of a given section named ``<SECTION>``.
168640d553cfSPaul Beesley
168740d553cfSPaul Beesley-  ``__<SECTION>_END__``
168840d553cfSPaul Beesley
168940d553cfSPaul Beesley   End address of a given section named ``<SECTION>``. If there is an alignment
169040d553cfSPaul Beesley   constraint on the section's end address then ``__<SECTION>_END__`` corresponds
169140d553cfSPaul Beesley   to the end address of the section's actual contents, rounded up to the right
169240d553cfSPaul Beesley   boundary. Refer to the value of ``__<SECTION>_UNALIGNED_END__`` to know the
169340d553cfSPaul Beesley   actual end address of the section's contents.
169440d553cfSPaul Beesley
169540d553cfSPaul Beesley-  ``__<SECTION>_UNALIGNED_END__``
169640d553cfSPaul Beesley
169740d553cfSPaul Beesley   End address of a given section named ``<SECTION>`` without any padding or
169840d553cfSPaul Beesley   rounding up due to some alignment constraint.
169940d553cfSPaul Beesley
170040d553cfSPaul Beesley-  ``__<SECTION>_SIZE__``
170140d553cfSPaul Beesley
170240d553cfSPaul Beesley   Size (in bytes) of a given section named ``<SECTION>``. If there is an
170340d553cfSPaul Beesley   alignment constraint on the section's end address then ``__<SECTION>_SIZE__``
170440d553cfSPaul Beesley   corresponds to the size of the section's actual contents, rounded up to the
170540d553cfSPaul Beesley   right boundary. In other words, ``__<SECTION>_SIZE__ = __<SECTION>_END__ - _<SECTION>_START__``. Refer to the value of ``__<SECTION>_UNALIGNED_SIZE__``
170640d553cfSPaul Beesley   to know the actual size of the section's contents.
170740d553cfSPaul Beesley
170840d553cfSPaul Beesley-  ``__<SECTION>_UNALIGNED_SIZE__``
170940d553cfSPaul Beesley
171040d553cfSPaul Beesley   Size (in bytes) of a given section named ``<SECTION>`` without any padding or
171140d553cfSPaul Beesley   rounding up due to some alignment constraint. In other words,
171240d553cfSPaul Beesley   ``__<SECTION>_UNALIGNED_SIZE__ = __<SECTION>_UNALIGNED_END__ - __<SECTION>_START__``.
171340d553cfSPaul Beesley
171440d553cfSPaul BeesleySome of the linker symbols are mandatory as TF-A code relies on them to be
171540d553cfSPaul Beesleydefined. They are listed in the following subsections. Some of them must be
171640d553cfSPaul Beesleyprovided for each bootloader stage and some are specific to a given bootloader
171740d553cfSPaul Beesleystage.
171840d553cfSPaul Beesley
171940d553cfSPaul BeesleyThe linker scripts define some extra, optional symbols. They are not actually
172040d553cfSPaul Beesleyused by any code but they help in understanding the bootloader images' memory
172140d553cfSPaul Beesleylayout as they are easy to spot in the link map files.
172240d553cfSPaul Beesley
172340d553cfSPaul BeesleyCommon linker symbols
172440d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^
172540d553cfSPaul Beesley
172640d553cfSPaul BeesleyAll BL images share the following requirements:
172740d553cfSPaul Beesley
172840d553cfSPaul Beesley-  The BSS section must be zero-initialised before executing any C code.
172940d553cfSPaul Beesley-  The coherent memory section (if enabled) must be zero-initialised as well.
173040d553cfSPaul Beesley-  The MMU setup code needs to know the extents of the coherent and read-only
173140d553cfSPaul Beesley   memory regions to set the right memory attributes. When
173240d553cfSPaul Beesley   ``SEPARATE_CODE_AND_RODATA=1``, it needs to know more specifically how the
173340d553cfSPaul Beesley   read-only memory region is divided between code and data.
173440d553cfSPaul Beesley
173540d553cfSPaul BeesleyThe following linker symbols are defined for this purpose:
173640d553cfSPaul Beesley
173740d553cfSPaul Beesley-  ``__BSS_START__``
173840d553cfSPaul Beesley-  ``__BSS_SIZE__``
173940d553cfSPaul Beesley-  ``__COHERENT_RAM_START__`` Must be aligned on a page-size boundary.
174040d553cfSPaul Beesley-  ``__COHERENT_RAM_END__`` Must be aligned on a page-size boundary.
174140d553cfSPaul Beesley-  ``__COHERENT_RAM_UNALIGNED_SIZE__``
174240d553cfSPaul Beesley-  ``__RO_START__``
174340d553cfSPaul Beesley-  ``__RO_END__``
174440d553cfSPaul Beesley-  ``__TEXT_START__``
1745f7d445fcSMichal Simek-  ``__TEXT_END_UNALIGNED__``
174640d553cfSPaul Beesley-  ``__TEXT_END__``
174740d553cfSPaul Beesley-  ``__RODATA_START__``
1748f7d445fcSMichal Simek-  ``__RODATA_END_UNALIGNED__``
174940d553cfSPaul Beesley-  ``__RODATA_END__``
175040d553cfSPaul Beesley
175140d553cfSPaul BeesleyBL1's linker symbols
175240d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^
175340d553cfSPaul Beesley
175440d553cfSPaul BeesleyBL1 being the ROM image, it has additional requirements. BL1 resides in ROM and
175540d553cfSPaul Beesleyit is entirely executed in place but it needs some read-write memory for its
175640d553cfSPaul Beesleymutable data. Its ``.data`` section (i.e. its allocated read-write data) must be
175740d553cfSPaul Beesleyrelocated from ROM to RAM before executing any C code.
175840d553cfSPaul Beesley
175940d553cfSPaul BeesleyThe following additional linker symbols are defined for BL1:
176040d553cfSPaul Beesley
176140d553cfSPaul Beesley-  ``__BL1_ROM_END__`` End address of BL1's ROM contents, covering its code
176240d553cfSPaul Beesley   and ``.data`` section in ROM.
176340d553cfSPaul Beesley-  ``__DATA_ROM_START__`` Start address of the ``.data`` section in ROM. Must be
176440d553cfSPaul Beesley   aligned on a 16-byte boundary.
176540d553cfSPaul Beesley-  ``__DATA_RAM_START__`` Address in RAM where the ``.data`` section should be
176640d553cfSPaul Beesley   copied over. Must be aligned on a 16-byte boundary.
176740d553cfSPaul Beesley-  ``__DATA_SIZE__`` Size of the ``.data`` section (in ROM or RAM).
176840d553cfSPaul Beesley-  ``__BL1_RAM_START__`` Start address of BL1 read-write data.
176940d553cfSPaul Beesley-  ``__BL1_RAM_END__`` End address of BL1 read-write data.
177040d553cfSPaul Beesley
177140d553cfSPaul BeesleyHow to choose the right base addresses for each bootloader stage image
177240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177340d553cfSPaul Beesley
177440d553cfSPaul BeesleyThere is currently no support for dynamic image loading in TF-A. This means
177540d553cfSPaul Beesleythat all bootloader images need to be linked against their ultimate runtime
177640d553cfSPaul Beesleylocations and the base addresses of each image must be chosen carefully such
177740d553cfSPaul Beesleythat images don't overlap each other in an undesired way. As the code grows,
177840d553cfSPaul Beesleythe base addresses might need adjustments to cope with the new memory layout.
177940d553cfSPaul Beesley
178040d553cfSPaul BeesleyThe memory layout is completely specific to the platform and so there is no
178140d553cfSPaul Beesleygeneral recipe for choosing the right base addresses for each bootloader image.
178240d553cfSPaul BeesleyHowever, there are tools to aid in understanding the memory layout. These are
178340d553cfSPaul Beesleythe link map files: ``build/<platform>/<build-type>/bl<x>/bl<x>.map``, with ``<x>``
178440d553cfSPaul Beesleybeing the stage bootloader. They provide a detailed view of the memory usage of
178540d553cfSPaul Beesleyeach image. Among other useful information, they provide the end address of
178640d553cfSPaul Beesleyeach image.
178740d553cfSPaul Beesley
178840d553cfSPaul Beesley-  ``bl1.map`` link map file provides ``__BL1_RAM_END__`` address.
178940d553cfSPaul Beesley-  ``bl2.map`` link map file provides ``__BL2_END__`` address.
179040d553cfSPaul Beesley-  ``bl31.map`` link map file provides ``__BL31_END__`` address.
179140d553cfSPaul Beesley-  ``bl32.map`` link map file provides ``__BL32_END__`` address.
179240d553cfSPaul Beesley
179340d553cfSPaul BeesleyFor each bootloader image, the platform code must provide its start address
179440d553cfSPaul Beesleyas well as a limit address that it must not overstep. The latter is used in the
179540d553cfSPaul Beesleylinker scripts to check that the image doesn't grow past that address. If that
179640d553cfSPaul Beesleyhappens, the linker will issue a message similar to the following:
179740d553cfSPaul Beesley
179840d553cfSPaul Beesley::
179940d553cfSPaul Beesley
180040d553cfSPaul Beesley    aarch64-none-elf-ld: BLx has exceeded its limit.
180140d553cfSPaul Beesley
180240d553cfSPaul BeesleyAdditionally, if the platform memory layout implies some image overlaying like
180340d553cfSPaul Beesleyon FVP, BL31 and TSP need to know the limit address that their PROGBITS
180440d553cfSPaul Beesleysections must not overstep. The platform code must provide those.
180540d553cfSPaul Beesley
180640d553cfSPaul BeesleyTF-A does not provide any mechanism to verify at boot time that the memory
180740d553cfSPaul Beesleyto load a new image is free to prevent overwriting a previously loaded image.
180840d553cfSPaul BeesleyThe platform must specify the memory available in the system for all the
180940d553cfSPaul Beesleyrelevant BL images to be loaded.
181040d553cfSPaul Beesley
181140d553cfSPaul BeesleyFor example, in the case of BL1 loading BL2, ``bl1_plat_sec_mem_layout()`` will
181240d553cfSPaul Beesleyreturn the region defined by the platform where BL1 intends to load BL2. The
181340d553cfSPaul Beesley``load_image()`` function performs bounds check for the image size based on the
181440d553cfSPaul Beesleybase and maximum image size provided by the platforms. Platforms must take
181540d553cfSPaul Beesleythis behaviour into account when defining the base/size for each of the images.
181640d553cfSPaul Beesley
181740d553cfSPaul BeesleyMemory layout on Arm development platforms
181840d553cfSPaul Beesley^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181940d553cfSPaul Beesley
182040d553cfSPaul BeesleyThe following list describes the memory layout on the Arm development platforms:
182140d553cfSPaul Beesley
182240d553cfSPaul Beesley-  A 4KB page of shared memory is used for communication between Trusted
182340d553cfSPaul Beesley   Firmware and the platform's power controller. This is located at the base of
182440d553cfSPaul Beesley   Trusted SRAM. The amount of Trusted SRAM available to load the bootloader
182540d553cfSPaul Beesley   images is reduced by the size of the shared memory.
182640d553cfSPaul Beesley
182740d553cfSPaul Beesley   The shared memory is used to store the CPUs' entrypoint mailbox. On Juno,
182840d553cfSPaul Beesley   this is also used for the MHU payload when passing messages to and from the
182940d553cfSPaul Beesley   SCP.
183040d553cfSPaul Beesley
183140d553cfSPaul Beesley-  Another 4 KB page is reserved for passing memory layout between BL1 and BL2
183240d553cfSPaul Beesley   and also the dynamic firmware configurations.
183340d553cfSPaul Beesley
183440d553cfSPaul Beesley-  On FVP, BL1 is originally sitting in the Trusted ROM at address ``0x0``. On
183540d553cfSPaul Beesley   Juno, BL1 resides in flash memory at address ``0x0BEC0000``. BL1 read-write
183640d553cfSPaul Beesley   data are relocated to the top of Trusted SRAM at runtime.
183740d553cfSPaul Beesley
183840d553cfSPaul Beesley-  BL2 is loaded below BL1 RW
183940d553cfSPaul Beesley
184040d553cfSPaul Beesley-  EL3 Runtime Software, BL31 for AArch64 and BL32 for AArch32 (e.g. SP_MIN),
184140d553cfSPaul Beesley   is loaded at the top of the Trusted SRAM, such that its NOBITS sections will
184240d553cfSPaul Beesley   overwrite BL1 R/W data and BL2. This implies that BL1 global variables
184340d553cfSPaul Beesley   remain valid only until execution reaches the EL3 Runtime Software entry
184440d553cfSPaul Beesley   point during a cold boot.
184540d553cfSPaul Beesley
184640d553cfSPaul Beesley-  On Juno, SCP_BL2 is loaded temporarily into the EL3 Runtime Software memory
1847be653a69SPaul Beesley   region and transferred to the SCP before being overwritten by EL3 Runtime
184840d553cfSPaul Beesley   Software.
184940d553cfSPaul Beesley
185040d553cfSPaul Beesley-  BL32 (for AArch64) can be loaded in one of the following locations:
185140d553cfSPaul Beesley
185240d553cfSPaul Beesley   -  Trusted SRAM
185340d553cfSPaul Beesley   -  Trusted DRAM (FVP only)
185440d553cfSPaul Beesley   -  Secure region of DRAM (top 16MB of DRAM configured by the TrustZone
185540d553cfSPaul Beesley      controller)
185640d553cfSPaul Beesley
185740d553cfSPaul Beesley   When BL32 (for AArch64) is loaded into Trusted SRAM, it is loaded below
185840d553cfSPaul Beesley   BL31.
185940d553cfSPaul Beesley
186040d553cfSPaul BeesleyThe location of the BL32 image will result in different memory maps. This is
186140d553cfSPaul Beesleyillustrated for both FVP and Juno in the following diagrams, using the TSP as
186240d553cfSPaul Beesleyan example.
186340d553cfSPaul Beesley
1864e1c5026aSPaul Beesley.. note::
1865e1c5026aSPaul Beesley   Loading the BL32 image in TZC secured DRAM doesn't change the memory
186640d553cfSPaul Beesley   layout of the other images in Trusted SRAM.
186740d553cfSPaul Beesley
186840d553cfSPaul BeesleyCONFIG section in memory layouts shown below contains:
186940d553cfSPaul Beesley
187040d553cfSPaul Beesley::
187140d553cfSPaul Beesley
187240d553cfSPaul Beesley    +--------------------+
187340d553cfSPaul Beesley    |bl2_mem_params_descs|
187440d553cfSPaul Beesley    |--------------------|
187540d553cfSPaul Beesley    |     fw_configs     |
187640d553cfSPaul Beesley    +--------------------+
187740d553cfSPaul Beesley
187840d553cfSPaul Beesley``bl2_mem_params_descs`` contains parameters passed from BL2 to next the
187940d553cfSPaul BeesleyBL image during boot.
188040d553cfSPaul Beesley
1881089fc624SManish V Badarkhe``fw_configs`` includes soc_fw_config, tos_fw_config, tb_fw_config and fw_config.
188240d553cfSPaul Beesley
188340d553cfSPaul Beesley**FVP with TSP in Trusted SRAM with firmware configs :**
188440d553cfSPaul Beesley(These diagrams only cover the AArch64 case)
188540d553cfSPaul Beesley
188640d553cfSPaul Beesley::
188740d553cfSPaul Beesley
188840d553cfSPaul Beesley                   DRAM
188940d553cfSPaul Beesley    0xffffffff +----------+
1890a52c5251SManish V Badarkhe               | EL3 TZC  |
1891a52c5251SManish V Badarkhe    0xffe00000 |----------| (secure)
1892a52c5251SManish V Badarkhe               | AP TZC   |
1893a52c5251SManish V Badarkhe    0xff000000 +----------+
189440d553cfSPaul Beesley               :          :
1895b4a87836SManish V Badarkhe    0x82100000 |----------|
189640d553cfSPaul Beesley               |HW_CONFIG |
1897b4a87836SManish V Badarkhe    0x82000000 |----------|  (non-secure)
189840d553cfSPaul Beesley               |          |
189940d553cfSPaul Beesley    0x80000000 +----------+
190040d553cfSPaul Beesley
1901b4a87836SManish V Badarkhe               Trusted DRAM
1902b4a87836SManish V Badarkhe    0x08000000 +----------+
1903b4a87836SManish V Badarkhe               |HW_CONFIG |
1904b4a87836SManish V Badarkhe    0x07f00000 |----------|
1905b4a87836SManish V Badarkhe               :          :
1906b4a87836SManish V Badarkhe               |          |
1907b4a87836SManish V Badarkhe    0x06000000 +----------+
1908b4a87836SManish V Badarkhe
190940d553cfSPaul Beesley               Trusted SRAM
191040d553cfSPaul Beesley    0x04040000 +----------+  loaded by BL2  +----------------+
191140d553cfSPaul Beesley               | BL1 (rw) |  <<<<<<<<<<<<<  |                |
191240d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |  BL31 NOBITS   |
191340d553cfSPaul Beesley               |   BL2    |  <<<<<<<<<<<<<  |                |
191440d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |----------------|
191540d553cfSPaul Beesley               |          |  <<<<<<<<<<<<<  | BL31 PROGBITS  |
191640d553cfSPaul Beesley               |          |  <<<<<<<<<<<<<  |----------------|
191740d553cfSPaul Beesley               |          |  <<<<<<<<<<<<<  |     BL32       |
1918089fc624SManish V Badarkhe    0x04003000 +----------+                 +----------------+
191940d553cfSPaul Beesley               |  CONFIG  |
192040d553cfSPaul Beesley    0x04001000 +----------+
192140d553cfSPaul Beesley               |  Shared  |
192240d553cfSPaul Beesley    0x04000000 +----------+
192340d553cfSPaul Beesley
192440d553cfSPaul Beesley               Trusted ROM
192540d553cfSPaul Beesley    0x04000000 +----------+
192640d553cfSPaul Beesley               | BL1 (ro) |
192740d553cfSPaul Beesley    0x00000000 +----------+
192840d553cfSPaul Beesley
192940d553cfSPaul Beesley**FVP with TSP in Trusted DRAM with firmware configs (default option):**
193040d553cfSPaul Beesley
193140d553cfSPaul Beesley::
193240d553cfSPaul Beesley
193340d553cfSPaul Beesley                     DRAM
193440d553cfSPaul Beesley    0xffffffff +--------------+
1935a52c5251SManish V Badarkhe               |   EL3 TZC    |
1936a52c5251SManish V Badarkhe    0xffe00000 |--------------|  (secure)
1937a52c5251SManish V Badarkhe               |   AP TZC     |
1938a52c5251SManish V Badarkhe    0xff000000 +--------------+
193940d553cfSPaul Beesley               :              :
1940b4a87836SManish V Badarkhe    0x82100000 |--------------|
194140d553cfSPaul Beesley               |  HW_CONFIG   |
1942b4a87836SManish V Badarkhe    0x82000000 |--------------|  (non-secure)
194340d553cfSPaul Beesley               |              |
194440d553cfSPaul Beesley    0x80000000 +--------------+
194540d553cfSPaul Beesley
194640d553cfSPaul Beesley                 Trusted DRAM
194740d553cfSPaul Beesley    0x08000000 +--------------+
1948b4a87836SManish V Badarkhe               |  HW_CONFIG   |
1949b4a87836SManish V Badarkhe    0x07f00000 |--------------|
1950b4a87836SManish V Badarkhe               :              :
195140d553cfSPaul Beesley               |    BL32      |
195240d553cfSPaul Beesley    0x06000000 +--------------+
195340d553cfSPaul Beesley
195440d553cfSPaul Beesley                 Trusted SRAM
195540d553cfSPaul Beesley    0x04040000 +--------------+  loaded by BL2  +----------------+
195640d553cfSPaul Beesley               |   BL1 (rw)   |  <<<<<<<<<<<<<  |                |
195740d553cfSPaul Beesley               |--------------|  <<<<<<<<<<<<<  |  BL31 NOBITS   |
195840d553cfSPaul Beesley               |     BL2      |  <<<<<<<<<<<<<  |                |
195940d553cfSPaul Beesley               |--------------|  <<<<<<<<<<<<<  |----------------|
196040d553cfSPaul Beesley               |              |  <<<<<<<<<<<<<  | BL31 PROGBITS  |
196140d553cfSPaul Beesley               |              |                 +----------------+
1962089fc624SManish V Badarkhe    0x04003000 +--------------+
196340d553cfSPaul Beesley               |    CONFIG    |
196440d553cfSPaul Beesley    0x04001000 +--------------+
196540d553cfSPaul Beesley               |    Shared    |
196640d553cfSPaul Beesley    0x04000000 +--------------+
196740d553cfSPaul Beesley
196840d553cfSPaul Beesley                 Trusted ROM
196940d553cfSPaul Beesley    0x04000000 +--------------+
197040d553cfSPaul Beesley               |   BL1 (ro)   |
197140d553cfSPaul Beesley    0x00000000 +--------------+
197240d553cfSPaul Beesley
197340d553cfSPaul Beesley**FVP with TSP in TZC-Secured DRAM with firmware configs :**
197440d553cfSPaul Beesley
197540d553cfSPaul Beesley::
197640d553cfSPaul Beesley
197740d553cfSPaul Beesley                   DRAM
197840d553cfSPaul Beesley    0xffffffff +----------+
1979a52c5251SManish V Badarkhe               |  EL3 TZC |
1980a52c5251SManish V Badarkhe    0xffe00000 |----------|  (secure)
1981a52c5251SManish V Badarkhe               |  AP TZC  |
1982a52c5251SManish V Badarkhe               |  (BL32)  |
198340d553cfSPaul Beesley    0xff000000 +----------+
198440d553cfSPaul Beesley               |          |
1985b4a87836SManish V Badarkhe    0x82100000 |----------|
198640d553cfSPaul Beesley               |HW_CONFIG |
1987b4a87836SManish V Badarkhe    0x82000000 |----------|  (non-secure)
198840d553cfSPaul Beesley               |          |
198940d553cfSPaul Beesley    0x80000000 +----------+
199040d553cfSPaul Beesley
1991b4a87836SManish V Badarkhe               Trusted DRAM
1992b4a87836SManish V Badarkhe    0x08000000 +----------+
1993b4a87836SManish V Badarkhe               |HW_CONFIG |
1994b4a87836SManish V Badarkhe    0x7f000000 |----------|
1995b4a87836SManish V Badarkhe               :          :
1996b4a87836SManish V Badarkhe               |          |
1997b4a87836SManish V Badarkhe    0x06000000 +----------+
1998b4a87836SManish V Badarkhe
199940d553cfSPaul Beesley               Trusted SRAM
200040d553cfSPaul Beesley    0x04040000 +----------+  loaded by BL2  +----------------+
200140d553cfSPaul Beesley               | BL1 (rw) |  <<<<<<<<<<<<<  |                |
200240d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |  BL31 NOBITS   |
200340d553cfSPaul Beesley               |   BL2    |  <<<<<<<<<<<<<  |                |
200440d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |----------------|
200540d553cfSPaul Beesley               |          |  <<<<<<<<<<<<<  | BL31 PROGBITS  |
200640d553cfSPaul Beesley               |          |                 +----------------+
2007089fc624SManish V Badarkhe    0x04003000 +----------+
200840d553cfSPaul Beesley               |  CONFIG  |
200940d553cfSPaul Beesley    0x04001000 +----------+
201040d553cfSPaul Beesley               |  Shared  |
201140d553cfSPaul Beesley    0x04000000 +----------+
201240d553cfSPaul Beesley
201340d553cfSPaul Beesley               Trusted ROM
201440d553cfSPaul Beesley    0x04000000 +----------+
201540d553cfSPaul Beesley               | BL1 (ro) |
201640d553cfSPaul Beesley    0x00000000 +----------+
201740d553cfSPaul Beesley
201840d553cfSPaul Beesley**Juno with BL32 in Trusted SRAM :**
201940d553cfSPaul Beesley
202040d553cfSPaul Beesley::
202140d553cfSPaul Beesley
2022a52c5251SManish V Badarkhe                  DRAM
2023a52c5251SManish V Badarkhe    0xFFFFFFFF +----------+
2024a52c5251SManish V Badarkhe               |  SCP TZC |
2025a52c5251SManish V Badarkhe    0xFFE00000 |----------|
2026a52c5251SManish V Badarkhe               |  EL3 TZC |
2027a52c5251SManish V Badarkhe    0xFFC00000 |----------|  (secure)
2028a52c5251SManish V Badarkhe               |  AP TZC  |
2029a52c5251SManish V Badarkhe    0xFF000000 +----------+
2030a52c5251SManish V Badarkhe               |          |
2031a52c5251SManish V Badarkhe               :          :  (non-secure)
2032a52c5251SManish V Badarkhe               |          |
2033a52c5251SManish V Badarkhe    0x80000000 +----------+
2034a52c5251SManish V Badarkhe
2035a52c5251SManish V Badarkhe
203640d553cfSPaul Beesley                  Flash0
203740d553cfSPaul Beesley    0x0C000000 +----------+
203840d553cfSPaul Beesley               :          :
203940d553cfSPaul Beesley    0x0BED0000 |----------|
204040d553cfSPaul Beesley               | BL1 (ro) |
204140d553cfSPaul Beesley    0x0BEC0000 |----------|
204240d553cfSPaul Beesley               :          :
204340d553cfSPaul Beesley    0x08000000 +----------+                  BL31 is loaded
204440d553cfSPaul Beesley                                             after SCP_BL2 has
204540d553cfSPaul Beesley               Trusted SRAM                  been sent to SCP
204640d553cfSPaul Beesley    0x04040000 +----------+  loaded by BL2  +----------------+
204740d553cfSPaul Beesley               | BL1 (rw) |  <<<<<<<<<<<<<  |                |
204840d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |  BL31 NOBITS   |
204940d553cfSPaul Beesley               |   BL2    |  <<<<<<<<<<<<<  |                |
205040d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |----------------|
205140d553cfSPaul Beesley               | SCP_BL2  |  <<<<<<<<<<<<<  | BL31 PROGBITS  |
2052ddc93cbaSChris Kay               |          |  <<<<<<<<<<<<<  |----------------|
205340d553cfSPaul Beesley               |          |  <<<<<<<<<<<<<  |     BL32       |
205440d553cfSPaul Beesley               |          |                 +----------------+
205540d553cfSPaul Beesley               |          |
205640d553cfSPaul Beesley    0x04001000 +----------+
205740d553cfSPaul Beesley               |   MHU    |
205840d553cfSPaul Beesley    0x04000000 +----------+
205940d553cfSPaul Beesley
206040d553cfSPaul Beesley**Juno with BL32 in TZC-secured DRAM :**
206140d553cfSPaul Beesley
206240d553cfSPaul Beesley::
206340d553cfSPaul Beesley
206440d553cfSPaul Beesley                   DRAM
2065a52c5251SManish V Badarkhe    0xFFFFFFFF +----------+
2066a52c5251SManish V Badarkhe               |  SCP TZC |
2067a52c5251SManish V Badarkhe    0xFFE00000 |----------|
2068a52c5251SManish V Badarkhe               |  EL3 TZC |
2069a52c5251SManish V Badarkhe    0xFFC00000 |----------|  (secure)
2070a52c5251SManish V Badarkhe               |  AP TZC  |
2071a52c5251SManish V Badarkhe               |  (BL32)  |
2072a52c5251SManish V Badarkhe    0xFF000000 +----------+
207340d553cfSPaul Beesley               |          |
207440d553cfSPaul Beesley               :          :  (non-secure)
207540d553cfSPaul Beesley               |          |
207640d553cfSPaul Beesley    0x80000000 +----------+
207740d553cfSPaul Beesley
207840d553cfSPaul Beesley                  Flash0
207940d553cfSPaul Beesley    0x0C000000 +----------+
208040d553cfSPaul Beesley               :          :
208140d553cfSPaul Beesley    0x0BED0000 |----------|
208240d553cfSPaul Beesley               | BL1 (ro) |
208340d553cfSPaul Beesley    0x0BEC0000 |----------|
208440d553cfSPaul Beesley               :          :
208540d553cfSPaul Beesley    0x08000000 +----------+                  BL31 is loaded
208640d553cfSPaul Beesley                                             after SCP_BL2 has
208740d553cfSPaul Beesley               Trusted SRAM                  been sent to SCP
208840d553cfSPaul Beesley    0x04040000 +----------+  loaded by BL2  +----------------+
208940d553cfSPaul Beesley               | BL1 (rw) |  <<<<<<<<<<<<<  |                |
209040d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |  BL31 NOBITS   |
209140d553cfSPaul Beesley               |   BL2    |  <<<<<<<<<<<<<  |                |
209240d553cfSPaul Beesley               |----------|  <<<<<<<<<<<<<  |----------------|
209340d553cfSPaul Beesley               | SCP_BL2  |  <<<<<<<<<<<<<  | BL31 PROGBITS  |
2094ddc93cbaSChris Kay               |          |                 +----------------+
209540d553cfSPaul Beesley    0x04001000 +----------+
209640d553cfSPaul Beesley               |   MHU    |
209740d553cfSPaul Beesley    0x04000000 +----------+
209840d553cfSPaul Beesley
209943f35ef5SPaul Beesley.. _firmware_design_fip:
210040d553cfSPaul Beesley
210140d553cfSPaul BeesleyFirmware Image Package (FIP)
210240d553cfSPaul Beesley----------------------------
210340d553cfSPaul Beesley
210440d553cfSPaul BeesleyUsing a Firmware Image Package (FIP) allows for packing bootloader images (and
210540d553cfSPaul Beesleypotentially other payloads) into a single archive that can be loaded by TF-A
210640d553cfSPaul Beesleyfrom non-volatile platform storage. A driver to load images from a FIP has
210740d553cfSPaul Beesleybeen added to the storage layer and allows a package to be read from supported
210840d553cfSPaul Beesleyplatform storage. A tool to create Firmware Image Packages is also provided
210940d553cfSPaul Beesleyand described below.
211040d553cfSPaul Beesley
211140d553cfSPaul BeesleyFirmware Image Package layout
211240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
211340d553cfSPaul Beesley
211440d553cfSPaul BeesleyThe FIP layout consists of a table of contents (ToC) followed by payload data.
211540d553cfSPaul BeesleyThe ToC itself has a header followed by one or more table entries. The ToC is
211640d553cfSPaul Beesleyterminated by an end marker entry, and since the size of the ToC is 0 bytes,
211740d553cfSPaul Beesleythe offset equals the total size of the FIP file. All ToC entries describe some
211840d553cfSPaul Beesleypayload data that has been appended to the end of the binary package. With the
211940d553cfSPaul Beesleyinformation provided in the ToC entry the corresponding payload data can be
212040d553cfSPaul Beesleyretrieved.
212140d553cfSPaul Beesley
212240d553cfSPaul Beesley::
212340d553cfSPaul Beesley
212440d553cfSPaul Beesley    ------------------
212540d553cfSPaul Beesley    | ToC Header     |
212640d553cfSPaul Beesley    |----------------|
212740d553cfSPaul Beesley    | ToC Entry 0    |
212840d553cfSPaul Beesley    |----------------|
212940d553cfSPaul Beesley    | ToC Entry 1    |
213040d553cfSPaul Beesley    |----------------|
213140d553cfSPaul Beesley    | ToC End Marker |
213240d553cfSPaul Beesley    |----------------|
213340d553cfSPaul Beesley    |                |
213440d553cfSPaul Beesley    |     Data 0     |
213540d553cfSPaul Beesley    |                |
213640d553cfSPaul Beesley    |----------------|
213740d553cfSPaul Beesley    |                |
213840d553cfSPaul Beesley    |     Data 1     |
213940d553cfSPaul Beesley    |                |
214040d553cfSPaul Beesley    ------------------
214140d553cfSPaul Beesley
214240d553cfSPaul BeesleyThe ToC header and entry formats are described in the header file
214340d553cfSPaul Beesley``include/tools_share/firmware_image_package.h``. This file is used by both the
214440d553cfSPaul Beesleytool and TF-A.
214540d553cfSPaul Beesley
214640d553cfSPaul BeesleyThe ToC header has the following fields:
214740d553cfSPaul Beesley
214840d553cfSPaul Beesley::
214940d553cfSPaul Beesley
215040d553cfSPaul Beesley    `name`: The name of the ToC. This is currently used to validate the header.
215140d553cfSPaul Beesley    `serial_number`: A non-zero number provided by the creation tool
215240d553cfSPaul Beesley    `flags`: Flags associated with this data.
215340d553cfSPaul Beesley        Bits 0-31: Reserved
215440d553cfSPaul Beesley        Bits 32-47: Platform defined
215540d553cfSPaul Beesley        Bits 48-63: Reserved
215640d553cfSPaul Beesley
215740d553cfSPaul BeesleyA ToC entry has the following fields:
215840d553cfSPaul Beesley
215940d553cfSPaul Beesley::
216040d553cfSPaul Beesley
216140d553cfSPaul Beesley    `uuid`: All files are referred to by a pre-defined Universally Unique
216240d553cfSPaul Beesley        IDentifier [UUID] . The UUIDs are defined in
216340d553cfSPaul Beesley        `include/tools_share/firmware_image_package.h`. The platform translates
216440d553cfSPaul Beesley        the requested image name into the corresponding UUID when accessing the
216540d553cfSPaul Beesley        package.
216640d553cfSPaul Beesley    `offset_address`: The offset address at which the corresponding payload data
216740d553cfSPaul Beesley        can be found. The offset is calculated from the ToC base address.
216840d553cfSPaul Beesley    `size`: The size of the corresponding payload data in bytes.
216940d553cfSPaul Beesley    `flags`: Flags associated with this entry. None are yet defined.
217040d553cfSPaul Beesley
217140d553cfSPaul BeesleyFirmware Image Package creation tool
217240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
217340d553cfSPaul Beesley
217440d553cfSPaul BeesleyThe FIP creation tool can be used to pack specified images into a binary
217540d553cfSPaul Beesleypackage that can be loaded by TF-A from platform storage. The tool currently
217640d553cfSPaul Beesleyonly supports packing bootloader images. Additional image definitions can be
217740d553cfSPaul Beesleyadded to the tool as required.
217840d553cfSPaul Beesley
217940d553cfSPaul BeesleyThe tool can be found in ``tools/fiptool``.
218040d553cfSPaul Beesley
218140d553cfSPaul BeesleyLoading from a Firmware Image Package (FIP)
218240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
218340d553cfSPaul Beesley
218440d553cfSPaul BeesleyThe Firmware Image Package (FIP) driver can load images from a binary package on
218540d553cfSPaul Beesleynon-volatile platform storage. For the Arm development platforms, this is
218640d553cfSPaul Beesleycurrently NOR FLASH.
218740d553cfSPaul Beesley
218840d553cfSPaul BeesleyBootloader images are loaded according to the platform policy as specified by
218940d553cfSPaul Beesleythe function ``plat_get_image_source()``. For the Arm development platforms, this
219040d553cfSPaul Beesleymeans the platform will attempt to load images from a Firmware Image Package
219140d553cfSPaul Beesleylocated at the start of NOR FLASH0.
219240d553cfSPaul Beesley
219340d553cfSPaul BeesleyThe Arm development platforms' policy is to only allow loading of a known set of
219440d553cfSPaul Beesleyimages. The platform policy can be modified to allow additional images.
219540d553cfSPaul Beesley
219640d553cfSPaul BeesleyUse of coherent memory in TF-A
219740d553cfSPaul Beesley------------------------------
219840d553cfSPaul Beesley
219940d553cfSPaul BeesleyThere might be loss of coherency when physical memory with mismatched
220040d553cfSPaul Beesleyshareability, cacheability and memory attributes is accessed by multiple CPUs
220140d553cfSPaul Beesley(refer to section B2.9 of `Arm ARM`_ for more details). This possibility occurs
220240d553cfSPaul Beesleyin TF-A during power up/down sequences when coherency, MMU and caches are
220340d553cfSPaul Beesleyturned on/off incrementally.
220440d553cfSPaul Beesley
220540d553cfSPaul BeesleyTF-A defines coherent memory as a region of memory with Device nGnRE attributes
220640d553cfSPaul Beesleyin the translation tables. The translation granule size in TF-A is 4KB. This
220740d553cfSPaul Beesleyis the smallest possible size of the coherent memory region.
220840d553cfSPaul Beesley
220940d553cfSPaul BeesleyBy default, all data structures which are susceptible to accesses with
221040d553cfSPaul Beesleymismatched attributes from various CPUs are allocated in a coherent memory
221134760951SPaul Beesleyregion (refer to section 2.1 of :ref:`Porting Guide`). The coherent memory
221234760951SPaul Beesleyregion accesses are Outer Shareable, non-cacheable and they can be accessed with
221334760951SPaul Beesleythe Device nGnRE attributes when the MMU is turned on. Hence, at the expense of
221434760951SPaul Beesleyat least an extra page of memory, TF-A is able to work around coherency issues
221534760951SPaul Beesleydue to mismatched memory attributes.
221640d553cfSPaul Beesley
221740d553cfSPaul BeesleyThe alternative to the above approach is to allocate the susceptible data
221840d553cfSPaul Beesleystructures in Normal WriteBack WriteAllocate Inner shareable memory. This
221940d553cfSPaul Beesleyapproach requires the data structures to be designed so that it is possible to
222040d553cfSPaul Beesleywork around the issue of mismatched memory attributes by performing software
222140d553cfSPaul Beesleycache maintenance on them.
222240d553cfSPaul Beesley
222340d553cfSPaul BeesleyDisabling the use of coherent memory in TF-A
222440d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
222540d553cfSPaul Beesley
222640d553cfSPaul BeesleyIt might be desirable to avoid the cost of allocating coherent memory on
222740d553cfSPaul Beesleyplatforms which are memory constrained. TF-A enables inclusion of coherent
222840d553cfSPaul Beesleymemory in firmware images through the build flag ``USE_COHERENT_MEM``.
222940d553cfSPaul BeesleyThis flag is enabled by default. It can be disabled to choose the second
223040d553cfSPaul Beesleyapproach described above.
223140d553cfSPaul Beesley
223240d553cfSPaul BeesleyThe below sections analyze the data structures allocated in the coherent memory
223340d553cfSPaul Beesleyregion and the changes required to allocate them in normal memory.
223440d553cfSPaul Beesley
223540d553cfSPaul BeesleyCoherent memory usage in PSCI implementation
223640d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223740d553cfSPaul Beesley
223840d553cfSPaul BeesleyThe ``psci_non_cpu_pd_nodes`` data structure stores the platform's power domain
223940d553cfSPaul Beesleytree information for state management of power domains. By default, this data
224040d553cfSPaul Beesleystructure is allocated in the coherent memory region in TF-A because it can be
224140d553cfSPaul Beesleyaccessed by multiple CPUs, either with caches enabled or disabled.
224240d553cfSPaul Beesley
224340d553cfSPaul Beesley.. code:: c
224440d553cfSPaul Beesley
224540d553cfSPaul Beesley    typedef struct non_cpu_pwr_domain_node {
224640d553cfSPaul Beesley        /*
224740d553cfSPaul Beesley         * Index of the first CPU power domain node level 0 which has this node
224840d553cfSPaul Beesley         * as its parent.
224940d553cfSPaul Beesley         */
225040d553cfSPaul Beesley        unsigned int cpu_start_idx;
225140d553cfSPaul Beesley
225240d553cfSPaul Beesley        /*
225340d553cfSPaul Beesley         * Number of CPU power domains which are siblings of the domain indexed
225440d553cfSPaul Beesley         * by 'cpu_start_idx' i.e. all the domains in the range 'cpu_start_idx
225540d553cfSPaul Beesley         * -> cpu_start_idx + ncpus' have this node as their parent.
225640d553cfSPaul Beesley         */
225740d553cfSPaul Beesley        unsigned int ncpus;
225840d553cfSPaul Beesley
225940d553cfSPaul Beesley        /*
226040d553cfSPaul Beesley         * Index of the parent power domain node.
226140d553cfSPaul Beesley         */
226240d553cfSPaul Beesley        unsigned int parent_node;
226340d553cfSPaul Beesley
226440d553cfSPaul Beesley        plat_local_state_t local_state;
226540d553cfSPaul Beesley
226640d553cfSPaul Beesley        unsigned char level;
226740d553cfSPaul Beesley
226840d553cfSPaul Beesley        /* For indexing the psci_lock array*/
226940d553cfSPaul Beesley        unsigned char lock_index;
227040d553cfSPaul Beesley    } non_cpu_pd_node_t;
227140d553cfSPaul Beesley
227240d553cfSPaul BeesleyIn order to move this data structure to normal memory, the use of each of its
227340d553cfSPaul Beesleyfields must be analyzed. Fields like ``cpu_start_idx``, ``ncpus``, ``parent_node``
227440d553cfSPaul Beesley``level`` and ``lock_index`` are only written once during cold boot. Hence removing
227540d553cfSPaul Beesleythem from coherent memory involves only doing a clean and invalidate of the
227640d553cfSPaul Beesleycache lines after these fields are written.
227740d553cfSPaul Beesley
227840d553cfSPaul BeesleyThe field ``local_state`` can be concurrently accessed by multiple CPUs in
227940d553cfSPaul Beesleydifferent cache states. A Lamport's Bakery lock ``psci_locks`` is used to ensure
228040d553cfSPaul Beesleymutual exclusion to this field and a clean and invalidate is needed after it
228140d553cfSPaul Beesleyis written.
228240d553cfSPaul Beesley
228340d553cfSPaul BeesleyBakery lock data
228440d553cfSPaul Beesley~~~~~~~~~~~~~~~~
228540d553cfSPaul Beesley
228640d553cfSPaul BeesleyThe bakery lock data structure ``bakery_lock_t`` is allocated in coherent memory
228740d553cfSPaul Beesleyand is accessed by multiple CPUs with mismatched attributes. ``bakery_lock_t`` is
228840d553cfSPaul Beesleydefined as follows:
228940d553cfSPaul Beesley
229040d553cfSPaul Beesley.. code:: c
229140d553cfSPaul Beesley
229240d553cfSPaul Beesley    typedef struct bakery_lock {
229340d553cfSPaul Beesley        /*
229440d553cfSPaul Beesley         * The lock_data is a bit-field of 2 members:
229540d553cfSPaul Beesley         * Bit[0]       : choosing. This field is set when the CPU is
229640d553cfSPaul Beesley         *                choosing its bakery number.
229740d553cfSPaul Beesley         * Bits[1 - 15] : number. This is the bakery number allocated.
229840d553cfSPaul Beesley         */
229940d553cfSPaul Beesley        volatile uint16_t lock_data[BAKERY_LOCK_MAX_CPUS];
230040d553cfSPaul Beesley    } bakery_lock_t;
230140d553cfSPaul Beesley
230240d553cfSPaul BeesleyIt is a characteristic of Lamport's Bakery algorithm that the volatile per-CPU
230340d553cfSPaul Beesleyfields can be read by all CPUs but only written to by the owning CPU.
230440d553cfSPaul Beesley
230540d553cfSPaul BeesleyDepending upon the data cache line size, the per-CPU fields of the
230640d553cfSPaul Beesley``bakery_lock_t`` structure for multiple CPUs may exist on a single cache line.
230740d553cfSPaul BeesleyThese per-CPU fields can be read and written during lock contention by multiple
230840d553cfSPaul BeesleyCPUs with mismatched memory attributes. Since these fields are a part of the
230940d553cfSPaul Beesleylock implementation, they do not have access to any other locking primitive to
231040d553cfSPaul Beesleysafeguard against the resulting coherency issues. As a result, simple software
231140d553cfSPaul Beesleycache maintenance is not enough to allocate them in coherent memory. Consider
231240d553cfSPaul Beesleythe following example.
231340d553cfSPaul Beesley
231440d553cfSPaul BeesleyCPU0 updates its per-CPU field with data cache enabled. This write updates a
231540d553cfSPaul Beesleylocal cache line which contains a copy of the fields for other CPUs as well. Now
231640d553cfSPaul BeesleyCPU1 updates its per-CPU field of the ``bakery_lock_t`` structure with data cache
231740d553cfSPaul Beesleydisabled. CPU1 then issues a DCIVAC operation to invalidate any stale copies of
231840d553cfSPaul Beesleyits field in any other cache line in the system. This operation will invalidate
231940d553cfSPaul Beesleythe update made by CPU0 as well.
232040d553cfSPaul Beesley
232140d553cfSPaul BeesleyTo use bakery locks when ``USE_COHERENT_MEM`` is disabled, the lock data structure
232240d553cfSPaul Beesleyhas been redesigned. The changes utilise the characteristic of Lamport's Bakery
232340d553cfSPaul Beesleyalgorithm mentioned earlier. The bakery_lock structure only allocates the memory
232440d553cfSPaul Beesleyfor a single CPU. The macro ``DEFINE_BAKERY_LOCK`` allocates all the bakery locks
2325da04341eSChris Kayneeded for a CPU into a section ``.bakery_lock``. The linker allocates the memory
232640d553cfSPaul Beesleyfor other cores by using the total size allocated for the bakery_lock section
232740d553cfSPaul Beesleyand multiplying it with (PLATFORM_CORE_COUNT - 1). This enables software to
232840d553cfSPaul Beesleyperform software cache maintenance on the lock data structure without running
232940d553cfSPaul Beesleyinto coherency issues associated with mismatched attributes.
233040d553cfSPaul Beesley
233140d553cfSPaul BeesleyThe bakery lock data structure ``bakery_info_t`` is defined for use when
233240d553cfSPaul Beesley``USE_COHERENT_MEM`` is disabled as follows:
233340d553cfSPaul Beesley
233440d553cfSPaul Beesley.. code:: c
233540d553cfSPaul Beesley
233640d553cfSPaul Beesley    typedef struct bakery_info {
233740d553cfSPaul Beesley        /*
233840d553cfSPaul Beesley         * The lock_data is a bit-field of 2 members:
233940d553cfSPaul Beesley         * Bit[0]       : choosing. This field is set when the CPU is
234040d553cfSPaul Beesley         *                choosing its bakery number.
234140d553cfSPaul Beesley         * Bits[1 - 15] : number. This is the bakery number allocated.
234240d553cfSPaul Beesley         */
234340d553cfSPaul Beesley         volatile uint16_t lock_data;
234440d553cfSPaul Beesley    } bakery_info_t;
234540d553cfSPaul Beesley
234640d553cfSPaul BeesleyThe ``bakery_info_t`` represents a single per-CPU field of one lock and
234740d553cfSPaul Beesleythe combination of corresponding ``bakery_info_t`` structures for all CPUs in the
234840d553cfSPaul Beesleysystem represents the complete bakery lock. The view in memory for a system
234940d553cfSPaul Beesleywith n bakery locks are:
235040d553cfSPaul Beesley
235140d553cfSPaul Beesley::
235240d553cfSPaul Beesley
2353da04341eSChris Kay    .bakery_lock section start
235440d553cfSPaul Beesley    |----------------|
235540d553cfSPaul Beesley    | `bakery_info_t`| <-- Lock_0 per-CPU field
235640d553cfSPaul Beesley    |    Lock_0      |     for CPU0
235740d553cfSPaul Beesley    |----------------|
235840d553cfSPaul Beesley    | `bakery_info_t`| <-- Lock_1 per-CPU field
235940d553cfSPaul Beesley    |    Lock_1      |     for CPU0
236040d553cfSPaul Beesley    |----------------|
236140d553cfSPaul Beesley    | ....           |
236240d553cfSPaul Beesley    |----------------|
236340d553cfSPaul Beesley    | `bakery_info_t`| <-- Lock_N per-CPU field
236440d553cfSPaul Beesley    |    Lock_N      |     for CPU0
236540d553cfSPaul Beesley    ------------------
236640d553cfSPaul Beesley    |    XXXXX       |
236740d553cfSPaul Beesley    | Padding to     |
236840d553cfSPaul Beesley    | next Cache WB  | <--- Calculate PERCPU_BAKERY_LOCK_SIZE, allocate
236940d553cfSPaul Beesley    |  Granule       |       continuous memory for remaining CPUs.
237040d553cfSPaul Beesley    ------------------
237140d553cfSPaul Beesley    | `bakery_info_t`| <-- Lock_0 per-CPU field
237240d553cfSPaul Beesley    |    Lock_0      |     for CPU1
237340d553cfSPaul Beesley    |----------------|
237440d553cfSPaul Beesley    | `bakery_info_t`| <-- Lock_1 per-CPU field
237540d553cfSPaul Beesley    |    Lock_1      |     for CPU1
237640d553cfSPaul Beesley    |----------------|
237740d553cfSPaul Beesley    | ....           |
237840d553cfSPaul Beesley    |----------------|
237940d553cfSPaul Beesley    | `bakery_info_t`| <-- Lock_N per-CPU field
238040d553cfSPaul Beesley    |    Lock_N      |     for CPU1
238140d553cfSPaul Beesley    ------------------
238240d553cfSPaul Beesley    |    XXXXX       |
238340d553cfSPaul Beesley    | Padding to     |
238440d553cfSPaul Beesley    | next Cache WB  |
238540d553cfSPaul Beesley    |  Granule       |
238640d553cfSPaul Beesley    ------------------
238740d553cfSPaul Beesley
238840d553cfSPaul BeesleyConsider a system of 2 CPUs with 'N' bakery locks as shown above. For an
238940d553cfSPaul Beesleyoperation on Lock_N, the corresponding ``bakery_info_t`` in both CPU0 and CPU1
2390da04341eSChris Kay``.bakery_lock`` section need to be fetched and appropriate cache operations need
239140d553cfSPaul Beesleyto be performed for each access.
239240d553cfSPaul Beesley
239340d553cfSPaul BeesleyOn Arm Platforms, bakery locks are used in psci (``psci_locks``) and power controller
239440d553cfSPaul Beesleydriver (``arm_lock``).
239540d553cfSPaul Beesley
239640d553cfSPaul BeesleyNon Functional Impact of removing coherent memory
239740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239840d553cfSPaul Beesley
239940d553cfSPaul BeesleyRemoval of the coherent memory region leads to the additional software overhead
240040d553cfSPaul Beesleyof performing cache maintenance for the affected data structures. However, since
240140d553cfSPaul Beesleythe memory where the data structures are allocated is cacheable, the overhead is
240240d553cfSPaul Beesleymostly mitigated by an increase in performance.
240340d553cfSPaul Beesley
240440d553cfSPaul BeesleyThere is however a performance impact for bakery locks, due to:
240540d553cfSPaul Beesley
240640d553cfSPaul Beesley-  Additional cache maintenance operations, and
240740d553cfSPaul Beesley-  Multiple cache line reads for each lock operation, since the bakery locks
240840d553cfSPaul Beesley   for each CPU are distributed across different cache lines.
240940d553cfSPaul Beesley
241040d553cfSPaul BeesleyThe implementation has been optimized to minimize this additional overhead.
241140d553cfSPaul BeesleyMeasurements indicate that when bakery locks are allocated in Normal memory, the
241240d553cfSPaul Beesleyminimum latency of acquiring a lock is on an average 3-4 micro seconds whereas
241340d553cfSPaul Beesleyin Device memory the same is 2 micro seconds. The measurements were done on the
241440d553cfSPaul BeesleyJuno Arm development platform.
241540d553cfSPaul Beesley
241640d553cfSPaul BeesleyAs mentioned earlier, almost a page of memory can be saved by disabling
241740d553cfSPaul Beesley``USE_COHERENT_MEM``. Each platform needs to consider these trade-offs to decide
241840d553cfSPaul Beesleywhether coherent memory should be used. If a platform disables
241940d553cfSPaul Beesley``USE_COHERENT_MEM`` and needs to use bakery locks in the porting layer, it can
242040d553cfSPaul Beesleyoptionally define macro ``PLAT_PERCPU_BAKERY_LOCK_SIZE`` (see the
242134760951SPaul Beesley:ref:`Porting Guide`). Refer to the reference platform code for examples.
242240d553cfSPaul Beesley
242340d553cfSPaul BeesleyIsolating code and read-only data on separate memory pages
242440d553cfSPaul Beesley----------------------------------------------------------
242540d553cfSPaul Beesley
242640d553cfSPaul BeesleyIn the Armv8-A VMSA, translation table entries include fields that define the
242740d553cfSPaul Beesleyproperties of the target memory region, such as its access permissions. The
242840d553cfSPaul Beesleysmallest unit of memory that can be addressed by a translation table entry is
242940d553cfSPaul Beesleya memory page. Therefore, if software needs to set different permissions on two
243040d553cfSPaul Beesleymemory regions then it needs to map them using different memory pages.
243140d553cfSPaul Beesley
243240d553cfSPaul BeesleyThe default memory layout for each BL image is as follows:
243340d553cfSPaul Beesley
243440d553cfSPaul Beesley::
243540d553cfSPaul Beesley
243640d553cfSPaul Beesley       |        ...        |
243740d553cfSPaul Beesley       +-------------------+
243840d553cfSPaul Beesley       |  Read-write data  |
243940d553cfSPaul Beesley       +-------------------+ Page boundary
244040d553cfSPaul Beesley       |     <Padding>     |
244140d553cfSPaul Beesley       +-------------------+
244240d553cfSPaul Beesley       | Exception vectors |
244340d553cfSPaul Beesley       +-------------------+ 2 KB boundary
244440d553cfSPaul Beesley       |     <Padding>     |
244540d553cfSPaul Beesley       +-------------------+
244640d553cfSPaul Beesley       |  Read-only data   |
244740d553cfSPaul Beesley       +-------------------+
244840d553cfSPaul Beesley       |       Code        |
244940d553cfSPaul Beesley       +-------------------+ BLx_BASE
245040d553cfSPaul Beesley
2451e1c5026aSPaul Beesley.. note::
2452e1c5026aSPaul Beesley   The 2KB alignment for the exception vectors is an architectural
245340d553cfSPaul Beesley   requirement.
245440d553cfSPaul Beesley
245540d553cfSPaul BeesleyThe read-write data start on a new memory page so that they can be mapped with
245640d553cfSPaul Beesleyread-write permissions, whereas the code and read-only data below are configured
245740d553cfSPaul Beesleyas read-only.
245840d553cfSPaul Beesley
245940d553cfSPaul BeesleyHowever, the read-only data are not aligned on a page boundary. They are
246040d553cfSPaul Beesleycontiguous to the code. Therefore, the end of the code section and the beginning
246140d553cfSPaul Beesleyof the read-only data one might share a memory page. This forces both to be
246240d553cfSPaul Beesleymapped with the same memory attributes. As the code needs to be executable, this
246340d553cfSPaul Beesleymeans that the read-only data stored on the same memory page as the code are
246440d553cfSPaul Beesleyexecutable as well. This could potentially be exploited as part of a security
246540d553cfSPaul Beesleyattack.
246640d553cfSPaul Beesley
246740d553cfSPaul BeesleyTF provides the build flag ``SEPARATE_CODE_AND_RODATA`` to isolate the code and
246840d553cfSPaul Beesleyread-only data on separate memory pages. This in turn allows independent control
246940d553cfSPaul Beesleyof the access permissions for the code and read-only data. In this case,
247040d553cfSPaul Beesleyplatform code gets a finer-grained view of the image layout and can
247140d553cfSPaul Beesleyappropriately map the code region as executable and the read-only data as
247240d553cfSPaul Beesleyexecute-never.
247340d553cfSPaul Beesley
247440d553cfSPaul BeesleyThis has an impact on memory footprint, as padding bytes need to be introduced
247540d553cfSPaul Beesleybetween the code and read-only data to ensure the segregation of the two. To
247640d553cfSPaul Beesleylimit the memory cost, this flag also changes the memory layout such that the
247740d553cfSPaul Beesleycode and exception vectors are now contiguous, like so:
247840d553cfSPaul Beesley
247940d553cfSPaul Beesley::
248040d553cfSPaul Beesley
248140d553cfSPaul Beesley       |        ...        |
248240d553cfSPaul Beesley       +-------------------+
248340d553cfSPaul Beesley       |  Read-write data  |
248440d553cfSPaul Beesley       +-------------------+ Page boundary
248540d553cfSPaul Beesley       |     <Padding>     |
248640d553cfSPaul Beesley       +-------------------+
248740d553cfSPaul Beesley       |  Read-only data   |
248840d553cfSPaul Beesley       +-------------------+ Page boundary
248940d553cfSPaul Beesley       |     <Padding>     |
249040d553cfSPaul Beesley       +-------------------+
249140d553cfSPaul Beesley       | Exception vectors |
249240d553cfSPaul Beesley       +-------------------+ 2 KB boundary
249340d553cfSPaul Beesley       |     <Padding>     |
249440d553cfSPaul Beesley       +-------------------+
249540d553cfSPaul Beesley       |       Code        |
249640d553cfSPaul Beesley       +-------------------+ BLx_BASE
249740d553cfSPaul Beesley
249840d553cfSPaul BeesleyWith this more condensed memory layout, the separation of read-only data will
249940d553cfSPaul Beesleyadd zero or one page to the memory footprint of each BL image. Each platform
250040d553cfSPaul Beesleyshould consider the trade-off between memory footprint and security.
250140d553cfSPaul Beesley
250240d553cfSPaul BeesleyThis build flag is disabled by default, minimising memory footprint. On Arm
250340d553cfSPaul Beesleyplatforms, it is enabled.
250440d553cfSPaul Beesley
250540d553cfSPaul BeesleyPublish and Subscribe Framework
250640d553cfSPaul Beesley-------------------------------
250740d553cfSPaul Beesley
250840d553cfSPaul BeesleyThe Publish and Subscribe Framework allows EL3 components to define and publish
250940d553cfSPaul Beesleyevents, to which other EL3 components can subscribe.
251040d553cfSPaul Beesley
251140d553cfSPaul BeesleyThe following macros are provided by the framework:
251240d553cfSPaul Beesley
251340d553cfSPaul Beesley-  ``REGISTER_PUBSUB_EVENT(event)``: Defines an event, and takes one argument,
251440d553cfSPaul Beesley   the event name, which must be a valid C identifier. All calls to
251540d553cfSPaul Beesley   ``REGISTER_PUBSUB_EVENT`` macro must be placed in the file
251640d553cfSPaul Beesley   ``pubsub_events.h``.
251740d553cfSPaul Beesley
251840d553cfSPaul Beesley-  ``PUBLISH_EVENT_ARG(event, arg)``: Publishes a defined event, by iterating
251940d553cfSPaul Beesley   subscribed handlers and calling them in turn. The handlers will be passed the
252040d553cfSPaul Beesley   parameter ``arg``. The expected use-case is to broadcast an event.
252140d553cfSPaul Beesley
252240d553cfSPaul Beesley-  ``PUBLISH_EVENT(event)``: Like ``PUBLISH_EVENT_ARG``, except that the value
252340d553cfSPaul Beesley   ``NULL`` is passed to subscribed handlers.
252440d553cfSPaul Beesley
252540d553cfSPaul Beesley-  ``SUBSCRIBE_TO_EVENT(event, handler)``: Registers the ``handler`` to
252640d553cfSPaul Beesley   subscribe to ``event``. The handler will be executed whenever the ``event``
252740d553cfSPaul Beesley   is published.
252840d553cfSPaul Beesley
252940d553cfSPaul Beesley-  ``for_each_subscriber(event, subscriber)``: Iterates through all handlers
253040d553cfSPaul Beesley   subscribed for ``event``. ``subscriber`` must be a local variable of type
253140d553cfSPaul Beesley   ``pubsub_cb_t *``, and will point to each subscribed handler in turn during
253240d553cfSPaul Beesley   iteration. This macro can be used for those patterns that none of the
253340d553cfSPaul Beesley   ``PUBLISH_EVENT_*()`` macros cover.
253440d553cfSPaul Beesley
253540d553cfSPaul BeesleyPublishing an event that wasn't defined using ``REGISTER_PUBSUB_EVENT`` will
253640d553cfSPaul Beesleyresult in build error. Subscribing to an undefined event however won't.
253740d553cfSPaul Beesley
253840d553cfSPaul BeesleySubscribed handlers must be of type ``pubsub_cb_t``, with following function
253940d553cfSPaul Beesleysignature:
254040d553cfSPaul Beesley
254129c02529SPaul Beesley.. code:: c
254240d553cfSPaul Beesley
254340d553cfSPaul Beesley   typedef void* (*pubsub_cb_t)(const void *arg);
254440d553cfSPaul Beesley
254540d553cfSPaul BeesleyThere may be arbitrary number of handlers registered to the same event. The
254640d553cfSPaul Beesleyorder in which subscribed handlers are notified when that event is published is
254740d553cfSPaul Beesleynot defined. Subscribed handlers may be executed in any order; handlers should
254840d553cfSPaul Beesleynot assume any relative ordering amongst them.
254940d553cfSPaul Beesley
255040d553cfSPaul BeesleyPublishing an event on a PE will result in subscribed handlers executing on that
255140d553cfSPaul BeesleyPE only; it won't cause handlers to execute on a different PE.
255240d553cfSPaul Beesley
255340d553cfSPaul BeesleyNote that publishing an event on a PE blocks until all the subscribed handlers
255440d553cfSPaul Beesleyfinish executing on the PE.
255540d553cfSPaul Beesley
255640d553cfSPaul BeesleyTF-A generic code publishes and subscribes to some events within. Platform
255740d553cfSPaul Beesleyports are discouraged from subscribing to them. These events may be withdrawn,
255840d553cfSPaul Beesleyrenamed, or have their semantics altered in the future. Platforms may however
255940d553cfSPaul Beesleyregister, publish, and subscribe to platform-specific events.
256040d553cfSPaul Beesley
256140d553cfSPaul BeesleyPublish and Subscribe Example
256240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
256340d553cfSPaul Beesley
256440d553cfSPaul BeesleyA publisher that wants to publish event ``foo`` would:
256540d553cfSPaul Beesley
256640d553cfSPaul Beesley-  Define the event ``foo`` in the ``pubsub_events.h``.
256740d553cfSPaul Beesley
256829c02529SPaul Beesley   .. code:: c
256940d553cfSPaul Beesley
257040d553cfSPaul Beesley      REGISTER_PUBSUB_EVENT(foo);
257140d553cfSPaul Beesley
257240d553cfSPaul Beesley-  Depending on the nature of event, use one of ``PUBLISH_EVENT_*()`` macros to
257340d553cfSPaul Beesley   publish the event at the appropriate path and time of execution.
257440d553cfSPaul Beesley
257540d553cfSPaul BeesleyA subscriber that wants to subscribe to event ``foo`` published above would
257640d553cfSPaul Beesleyimplement:
257740d553cfSPaul Beesley
257840d553cfSPaul Beesley.. code:: c
257940d553cfSPaul Beesley
258040d553cfSPaul Beesley    void *foo_handler(const void *arg)
258140d553cfSPaul Beesley    {
258240d553cfSPaul Beesley         void *result;
258340d553cfSPaul Beesley
258440d553cfSPaul Beesley         /* Do handling ... */
258540d553cfSPaul Beesley
258640d553cfSPaul Beesley         return result;
258740d553cfSPaul Beesley    }
258840d553cfSPaul Beesley
258940d553cfSPaul Beesley    SUBSCRIBE_TO_EVENT(foo, foo_handler);
259040d553cfSPaul Beesley
259140d553cfSPaul Beesley
259240d553cfSPaul BeesleyReclaiming the BL31 initialization code
259340d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259440d553cfSPaul Beesley
259540d553cfSPaul BeesleyA significant amount of the code used for the initialization of BL31 is never
259640d553cfSPaul Beesleyneeded again after boot time. In order to reduce the runtime memory
259740d553cfSPaul Beesleyfootprint, the memory used for this code can be reclaimed after initialization
259840d553cfSPaul Beesleyhas finished and be used for runtime data.
259940d553cfSPaul Beesley
260040d553cfSPaul BeesleyThe build option ``RECLAIM_INIT_CODE`` can be set to mark this boot time code
260140d553cfSPaul Beesleywith a ``.text.init.*`` attribute which can be filtered and placed suitably
260240d553cfSPaul Beesleywithin the BL image for later reclamation by the platform. The platform can
260340d553cfSPaul Beesleyspecify the filter and the memory region for this init section in BL31 via the
260440d553cfSPaul Beesleyplat.ld.S linker script. For example, on the FVP, this section is placed
260540d553cfSPaul Beesleyoverlapping the secondary CPU stacks so that after the cold boot is done, this
260640d553cfSPaul Beesleymemory can be reclaimed for the stacks. The init memory section is initially
260740d553cfSPaul Beesleymapped with ``RO``, ``EXECUTE`` attributes. After BL31 initialization has
260840d553cfSPaul Beesleycompleted, the FVP changes the attributes of this section to ``RW``,
260940d553cfSPaul Beesley``EXECUTE_NEVER`` allowing it to be used for runtime data. The memory attributes
261040d553cfSPaul Beesleyare changed within the ``bl31_plat_runtime_setup`` platform hook. The init
261140d553cfSPaul Beesleysection section can be reclaimed for any data which is accessed after cold
261240d553cfSPaul Beesleyboot initialization and it is upto the platform to make the decision.
261340d553cfSPaul Beesley
261453644fa8SBoyan KaratotevPlease note that this will disable inlining for any functions with the __init
261553644fa8SBoyan Karatotevattribute.
261653644fa8SBoyan Karatotev
261734760951SPaul Beesley.. _firmware_design_pmf:
261834760951SPaul Beesley
261940d553cfSPaul BeesleyPerformance Measurement Framework
262040d553cfSPaul Beesley---------------------------------
262140d553cfSPaul Beesley
262240d553cfSPaul BeesleyThe Performance Measurement Framework (PMF) facilitates collection of
262340d553cfSPaul Beesleytimestamps by registered services and provides interfaces to retrieve them
262440d553cfSPaul Beesleyfrom within TF-A. A platform can choose to expose appropriate SMCs to
262540d553cfSPaul Beesleyretrieve these collected timestamps.
262640d553cfSPaul Beesley
262740d553cfSPaul BeesleyBy default, the global physical counter is used for the timestamp
262840d553cfSPaul Beesleyvalue and is read via ``CNTPCT_EL0``. The framework allows to retrieve
262940d553cfSPaul Beesleytimestamps captured by other CPUs.
263040d553cfSPaul Beesley
263140d553cfSPaul BeesleyTimestamp identifier format
263240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~~~
263340d553cfSPaul Beesley
263440d553cfSPaul BeesleyA PMF timestamp is uniquely identified across the system via the
263540d553cfSPaul Beesleytimestamp ID or ``tid``. The ``tid`` is composed as follows:
263640d553cfSPaul Beesley
263740d553cfSPaul Beesley::
263840d553cfSPaul Beesley
263940d553cfSPaul Beesley    Bits 0-7: The local timestamp identifier.
264040d553cfSPaul Beesley    Bits 8-9: Reserved.
264140d553cfSPaul Beesley    Bits 10-15: The service identifier.
264240d553cfSPaul Beesley    Bits 16-31: Reserved.
264340d553cfSPaul Beesley
264440d553cfSPaul Beesley#. The service identifier. Each PMF service is identified by a
264540d553cfSPaul Beesley   service name and a service identifier. Both the service name and
264640d553cfSPaul Beesley   identifier are unique within the system as a whole.
264740d553cfSPaul Beesley
264840d553cfSPaul Beesley#. The local timestamp identifier. This identifier is unique within a given
264940d553cfSPaul Beesley   service.
265040d553cfSPaul Beesley
265140d553cfSPaul BeesleyRegistering a PMF service
265240d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~~~~
265340d553cfSPaul Beesley
265440d553cfSPaul BeesleyTo register a PMF service, the ``PMF_REGISTER_SERVICE()`` macro from ``pmf.h``
265540d553cfSPaul Beesleyis used. The arguments required are the service name, the service ID,
265640d553cfSPaul Beesleythe total number of local timestamps to be captured and a set of flags.
265740d553cfSPaul Beesley
265840d553cfSPaul BeesleyThe ``flags`` field can be specified as a bitwise-OR of the following values:
265940d553cfSPaul Beesley
266040d553cfSPaul Beesley::
266140d553cfSPaul Beesley
266240d553cfSPaul Beesley    PMF_STORE_ENABLE: The timestamp is stored in memory for later retrieval.
266340d553cfSPaul Beesley    PMF_DUMP_ENABLE: The timestamp is dumped on the serial console.
266440d553cfSPaul Beesley
266540d553cfSPaul BeesleyThe ``PMF_REGISTER_SERVICE()`` reserves memory to store captured
266640d553cfSPaul Beesleytimestamps in a PMF specific linker section at build time.
266740d553cfSPaul BeesleyAdditionally, it defines necessary functions to capture and
266840d553cfSPaul Beesleyretrieve a particular timestamp for the given service at runtime.
266940d553cfSPaul Beesley
267040d553cfSPaul BeesleyThe macro ``PMF_REGISTER_SERVICE()`` only enables capturing PMF timestamps
267140d553cfSPaul Beesleyfrom within TF-A. In order to retrieve timestamps from outside of TF-A, the
267240d553cfSPaul Beesley``PMF_REGISTER_SERVICE_SMC()`` macro must be used instead. This macro
267340d553cfSPaul Beesleyaccepts the same set of arguments as the ``PMF_REGISTER_SERVICE()``
267440d553cfSPaul Beesleymacro but additionally supports retrieving timestamps using SMCs.
267540d553cfSPaul Beesley
267640d553cfSPaul BeesleyCapturing a timestamp
267740d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~
267840d553cfSPaul Beesley
267940d553cfSPaul BeesleyPMF timestamps are stored in a per-service timestamp region. On a
268040d553cfSPaul Beesleysystem with multiple CPUs, each timestamp is captured and stored
268140d553cfSPaul Beesleyin a per-CPU cache line aligned memory region.
268240d553cfSPaul Beesley
268340d553cfSPaul BeesleyHaving registered the service, the ``PMF_CAPTURE_TIMESTAMP()`` macro can be
268440d553cfSPaul Beesleyused to capture a timestamp at the location where it is used. The macro
268540d553cfSPaul Beesleytakes the service name, a local timestamp identifier and a flag as arguments.
268640d553cfSPaul Beesley
268740d553cfSPaul BeesleyThe ``flags`` field argument can be zero, or ``PMF_CACHE_MAINT`` which
268840d553cfSPaul Beesleyinstructs PMF to do cache maintenance following the capture. Cache
268940d553cfSPaul Beesleymaintenance is required if any of the service's timestamps are captured
269040d553cfSPaul Beesleywith data cache disabled.
269140d553cfSPaul Beesley
269240d553cfSPaul BeesleyTo capture a timestamp in assembly code, the caller should use
269340d553cfSPaul Beesley``pmf_calc_timestamp_addr`` macro (defined in ``pmf_asm_macros.S``) to
269440d553cfSPaul Beesleycalculate the address of where the timestamp would be stored. The
269540d553cfSPaul Beesleycaller should then read ``CNTPCT_EL0`` register to obtain the timestamp
269640d553cfSPaul Beesleyand store it at the determined address for later retrieval.
269740d553cfSPaul Beesley
269840d553cfSPaul BeesleyRetrieving a timestamp
269940d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~~~~~
270040d553cfSPaul Beesley
270140d553cfSPaul BeesleyFrom within TF-A, timestamps for individual CPUs can be retrieved using either
270240d553cfSPaul Beesley``PMF_GET_TIMESTAMP_BY_MPIDR()`` or ``PMF_GET_TIMESTAMP_BY_INDEX()`` macros.
270340d553cfSPaul BeesleyThese macros accept the CPU's MPIDR value, or its ordinal position
270440d553cfSPaul Beesleyrespectively.
270540d553cfSPaul Beesley
270640d553cfSPaul BeesleyFrom outside TF-A, timestamps for individual CPUs can be retrieved by calling
270740d553cfSPaul Beesleyinto ``pmf_smc_handler()``.
270840d553cfSPaul Beesley
270929c02529SPaul Beesley::
271040d553cfSPaul Beesley
271140d553cfSPaul Beesley    Interface : pmf_smc_handler()
271240d553cfSPaul Beesley    Argument  : unsigned int smc_fid, u_register_t x1,
271340d553cfSPaul Beesley                u_register_t x2, u_register_t x3,
271440d553cfSPaul Beesley                u_register_t x4, void *cookie,
271540d553cfSPaul Beesley                void *handle, u_register_t flags
271640d553cfSPaul Beesley    Return    : uintptr_t
271740d553cfSPaul Beesley
271840d553cfSPaul Beesley    smc_fid: Holds the SMC identifier which is either `PMF_SMC_GET_TIMESTAMP_32`
271940d553cfSPaul Beesley        when the caller of the SMC is running in AArch32 mode
272040d553cfSPaul Beesley        or `PMF_SMC_GET_TIMESTAMP_64` when the caller is running in AArch64 mode.
272140d553cfSPaul Beesley    x1: Timestamp identifier.
272240d553cfSPaul Beesley    x2: The `mpidr` of the CPU for which the timestamp has to be retrieved.
272340d553cfSPaul Beesley        This can be the `mpidr` of a different core to the one initiating
272440d553cfSPaul Beesley        the SMC.  In that case, service specific cache maintenance may be
272540d553cfSPaul Beesley        required to ensure the updated copy of the timestamp is returned.
272640d553cfSPaul Beesley    x3: A flags value that is either 0 or `PMF_CACHE_MAINT`.  If
272740d553cfSPaul Beesley        `PMF_CACHE_MAINT` is passed, then the PMF code will perform a
272840d553cfSPaul Beesley        cache invalidate before reading the timestamp.  This ensures
272940d553cfSPaul Beesley        an updated copy is returned.
273040d553cfSPaul Beesley
273140d553cfSPaul BeesleyThe remaining arguments, ``x4``, ``cookie``, ``handle`` and ``flags`` are unused
273240d553cfSPaul Beesleyin this implementation.
273340d553cfSPaul Beesley
273440d553cfSPaul BeesleyPMF code structure
273540d553cfSPaul Beesley~~~~~~~~~~~~~~~~~~
273640d553cfSPaul Beesley
273740d553cfSPaul Beesley#. ``pmf_main.c`` consists of core functions that implement service registration,
273840d553cfSPaul Beesley   initialization, storing, dumping and retrieving timestamps.
273940d553cfSPaul Beesley
274040d553cfSPaul Beesley#. ``pmf_smc.c`` contains the SMC handling for registered PMF services.
274140d553cfSPaul Beesley
274240d553cfSPaul Beesley#. ``pmf.h`` contains the public interface to Performance Measurement Framework.
274340d553cfSPaul Beesley
274440d553cfSPaul Beesley#. ``pmf_asm_macros.S`` consists of macros to facilitate capturing timestamps in
274540d553cfSPaul Beesley   assembly code.
274640d553cfSPaul Beesley
274740d553cfSPaul Beesley#. ``pmf_helpers.h`` is an internal header used by ``pmf.h``.
274840d553cfSPaul Beesley
274940d553cfSPaul BeesleyArmv8-A Architecture Extensions
275040d553cfSPaul Beesley-------------------------------
275140d553cfSPaul Beesley
275240d553cfSPaul BeesleyTF-A makes use of Armv8-A Architecture Extensions where applicable. This
275340d553cfSPaul Beesleysection lists the usage of Architecture Extensions, and build flags
275440d553cfSPaul Beesleycontrolling them.
275540d553cfSPaul Beesley
2756be6484cbSManish PandeyBuild options
2757be6484cbSManish Pandey~~~~~~~~~~~~~
275840d553cfSPaul Beesley
2759be6484cbSManish Pandey``ARM_ARCH_MAJOR`` and ``ARM_ARCH_MINOR``
2760be6484cbSManish Pandey
2761be6484cbSManish PandeyThese build options serve dual purpose
2762be6484cbSManish Pandey
2763be6484cbSManish Pandey- Determine the architecture extension support in TF-A build: All the mandatory
2764be6484cbSManish Pandey  architectural features up to ``ARM_ARCH_MAJOR.ARM_ARCH_MINOR`` are included
2765be6484cbSManish Pandey  and unconditionally enabled by TF-A build system.
2766be6484cbSManish Pandey
2767019311e7SGovindraj Raja- ``ARM_ARCH_MAJOR`` and ``ARM_ARCH_MINOR`` are passed to a march.mk build utility
2768019311e7SGovindraj Raja  this will try to come up with an appropriate -march value to be passed to compiler
2769019311e7SGovindraj Raja  by probing the compiler and checking what's supported by the compiler and what's best
2770019311e7SGovindraj Raja  that can be used. But if platform provides a ``MARCH_DIRECTIVE`` then it will used
2771019311e7SGovindraj Raja  directly and compiler probing will be skipped.
2772be6484cbSManish Pandey
2773be6484cbSManish PandeyThe build system requires that the platform provides a valid numeric value based on
2774be6484cbSManish PandeyCPU architecture extension, otherwise it defaults to base Armv8.0-A architecture.
2775be6484cbSManish PandeySubsequent Arm Architecture versions also support extensions which were introduced
2776be6484cbSManish Pandeyin previous versions.
2777be6484cbSManish Pandey
277843f35ef5SPaul Beesley.. seealso:: :ref:`Build Options`
277940d553cfSPaul Beesley
278040d553cfSPaul BeesleyFor details on the Architecture Extension and available features, please refer
278140d553cfSPaul Beesleyto the respective Architecture Extension Supplement.
278240d553cfSPaul Beesley
278340d553cfSPaul BeesleyArmv8.1-A
278440d553cfSPaul Beesley~~~~~~~~~
278540d553cfSPaul Beesley
278640d553cfSPaul BeesleyThis Architecture Extension is targeted when ``ARM_ARCH_MAJOR`` >= 8, or when
278740d553cfSPaul Beesley``ARM_ARCH_MAJOR`` == 8 and ``ARM_ARCH_MINOR`` >= 1.
278840d553cfSPaul Beesley
2789c97cba4eSSoby Mathew-  By default, a load-/store-exclusive instruction pair is used to implement
2790c97cba4eSSoby Mathew   spinlocks. The ``USE_SPINLOCK_CAS`` build option when set to 1 selects the
2791c97cba4eSSoby Mathew   spinlock implementation using the ARMv8.1-LSE Compare and Swap instruction.
2792c97cba4eSSoby Mathew   Notice this instruction is only available in AArch64 execution state, so
2793c97cba4eSSoby Mathew   the option is only available to AArch64 builds.
279440d553cfSPaul Beesley
279540d553cfSPaul BeesleyArmv8.2-A
279640d553cfSPaul Beesley~~~~~~~~~
279740d553cfSPaul Beesley
279840d553cfSPaul Beesley-  The presence of ARMv8.2-TTCNP is detected at runtime. When it is present, the
279940d553cfSPaul Beesley   Common not Private (TTBRn_ELx.CnP) bit is enabled to indicate that multiple
280040d553cfSPaul Beesley   Processing Elements in the same Inner Shareable domain use the same
280140d553cfSPaul Beesley   translation table entries for a given stage of translation for a particular
280240d553cfSPaul Beesley   translation regime.
280340d553cfSPaul Beesley
280440d553cfSPaul BeesleyArmv8.3-A
280540d553cfSPaul Beesley~~~~~~~~~
280640d553cfSPaul Beesley
280740d553cfSPaul Beesley-  Pointer authentication features of Armv8.3-A are unconditionally enabled in
280840d553cfSPaul Beesley   the Non-secure world so that lower ELs are allowed to use them without
280940d553cfSPaul Beesley   causing a trap to EL3.
281040d553cfSPaul Beesley
281140d553cfSPaul Beesley   In order to enable the Secure world to use it, ``CTX_INCLUDE_PAUTH_REGS``
281240d553cfSPaul Beesley   must be set to 1. This will add all pointer authentication system registers
281340d553cfSPaul Beesley   to the context that is saved when doing a world switch.
281440d553cfSPaul Beesley
281540d553cfSPaul Beesley   The TF-A itself has support for pointer authentication at runtime
28169fc59639SAlexei Fedorov   that can be enabled by setting ``BRANCH_PROTECTION`` option to non-zero and
281740d553cfSPaul Beesley   ``CTX_INCLUDE_PAUTH_REGS`` to 1. This enables pointer authentication in BL1,
281840d553cfSPaul Beesley   BL2, BL31, and the TSP if it is used.
281940d553cfSPaul Beesley
282040d553cfSPaul Beesley   Note that Pointer Authentication is enabled for Non-secure world irrespective
282140d553cfSPaul Beesley   of the value of these build flags if the CPU supports it.
282240d553cfSPaul Beesley
282340d553cfSPaul Beesley   If ``ARM_ARCH_MAJOR == 8`` and ``ARM_ARCH_MINOR >= 3`` the code footprint of
282440d553cfSPaul Beesley   enabling PAuth is lower because the compiler will use the optimized
282540d553cfSPaul Beesley   PAuth instructions rather than the backwards-compatible ones.
282640d553cfSPaul Beesley
28279fc59639SAlexei FedorovArmv8.5-A
28289fc59639SAlexei Fedorov~~~~~~~~~
28299fc59639SAlexei Fedorov
28309fc59639SAlexei Fedorov-  Branch Target Identification feature is selected by ``BRANCH_PROTECTION``
2831700e7685SManish Pandey   option set to 1. This option defaults to 0.
283288d493fbSJustin Chadwell
2833c282384dSGovindraj Raja-  Memory Tagging Extension feature has few variants but not all of them require
2834c282384dSGovindraj Raja   enablement from EL3 to be used at lower EL. e.g. Memory tagging only at
2835c282384dSGovindraj Raja   EL0(MTE) does not require EL3 configuration however memory tagging at
2836c282384dSGovindraj Raja   EL2/EL1 (MTE2) does require EL3 enablement and we need to set this option
2837c282384dSGovindraj Raja   ``ENABLE_FEAT_MTE2`` to 1. This option defaults to 0.
28389fc59639SAlexei Fedorov
283940d553cfSPaul BeesleyArmv7-A
284040d553cfSPaul Beesley~~~~~~~
284140d553cfSPaul Beesley
284240d553cfSPaul BeesleyThis Architecture Extension is targeted when ``ARM_ARCH_MAJOR`` == 7.
284340d553cfSPaul Beesley
284440d553cfSPaul BeesleyThere are several Armv7-A extensions available. Obviously the TrustZone
284540d553cfSPaul Beesleyextension is mandatory to support the TF-A bootloader and runtime services.
284640d553cfSPaul Beesley
284740d553cfSPaul BeesleyPlatform implementing an Armv7-A system can to define from its target
284840d553cfSPaul BeesleyCortex-A architecture through ``ARM_CORTEX_A<X> = yes`` in their
284940d553cfSPaul Beesley``platform.mk`` script. For example ``ARM_CORTEX_A15=yes`` for a
285040d553cfSPaul BeesleyCortex-A15 target.
285140d553cfSPaul Beesley
285240d553cfSPaul BeesleyPlatform can also set ``ARM_WITH_NEON=yes`` to enable neon support.
2853be653a69SPaul BeesleyNote that using neon at runtime has constraints on non secure world context.
285440d553cfSPaul BeesleyTF-A does not yet provide VFP context management.
285540d553cfSPaul Beesley
285640d553cfSPaul BeesleyDirective ``ARM_CORTEX_A<x>`` and ``ARM_WITH_NEON`` are used to set
285740d553cfSPaul Beesleythe toolchain  target architecture directive.
285840d553cfSPaul Beesley
285940d553cfSPaul BeesleyPlatform may choose to not define straight the toolchain target architecture
2860d4089fb8SGovindraj Rajadirective by defining ``MARCH_DIRECTIVE``.
286140d553cfSPaul BeesleyI.e:
286240d553cfSPaul Beesley
286329c02529SPaul Beesley.. code:: make
286440d553cfSPaul Beesley
2865019311e7SGovindraj Raja   MARCH_DIRECTIVE := -march=armv7-a
286640d553cfSPaul Beesley
286740d553cfSPaul BeesleyCode Structure
286840d553cfSPaul Beesley--------------
286940d553cfSPaul Beesley
287040d553cfSPaul BeesleyTF-A code is logically divided between the three boot loader stages mentioned
287140d553cfSPaul Beesleyin the previous sections. The code is also divided into the following
287240d553cfSPaul Beesleycategories (present as directories in the source code):
287340d553cfSPaul Beesley
287440d553cfSPaul Beesley-  **Platform specific.** Choice of architecture specific code depends upon
287540d553cfSPaul Beesley   the platform.
287640d553cfSPaul Beesley-  **Common code.** This is platform and architecture agnostic code.
287740d553cfSPaul Beesley-  **Library code.** This code comprises of functionality commonly used by all
287840d553cfSPaul Beesley   other code. The PSCI implementation and other EL3 runtime frameworks reside
287940d553cfSPaul Beesley   as Library components.
288040d553cfSPaul Beesley-  **Stage specific.** Code specific to a boot stage.
288140d553cfSPaul Beesley-  **Drivers.**
288240d553cfSPaul Beesley-  **Services.** EL3 runtime services (eg: SPD). Specific SPD services
288340d553cfSPaul Beesley   reside in the ``services/spd`` directory (e.g. ``services/spd/tspd``).
288440d553cfSPaul Beesley
288540d553cfSPaul BeesleyEach boot loader stage uses code from one or more of the above mentioned
288640d553cfSPaul Beesleycategories. Based upon the above, the code layout looks like this:
288740d553cfSPaul Beesley
288840d553cfSPaul Beesley::
288940d553cfSPaul Beesley
289040d553cfSPaul Beesley    Directory    Used by BL1?    Used by BL2?    Used by BL31?
289140d553cfSPaul Beesley    bl1          Yes             No              No
289240d553cfSPaul Beesley    bl2          No              Yes             No
289340d553cfSPaul Beesley    bl31         No              No              Yes
289440d553cfSPaul Beesley    plat         Yes             Yes             Yes
289540d553cfSPaul Beesley    drivers      Yes             No              Yes
289640d553cfSPaul Beesley    common       Yes             Yes             Yes
289740d553cfSPaul Beesley    lib          Yes             Yes             Yes
289840d553cfSPaul Beesley    services     No              No              Yes
289940d553cfSPaul Beesley
290040d553cfSPaul BeesleyThe build system provides a non configurable build option IMAGE_BLx for each
290140d553cfSPaul Beesleyboot loader stage (where x = BL stage). e.g. for BL1 , IMAGE_BL1 will be
290240d553cfSPaul Beesleydefined by the build system. This enables TF-A to compile certain code only
290340d553cfSPaul Beesleyfor specific boot loader stages
290440d553cfSPaul Beesley
290540d553cfSPaul BeesleyAll assembler files have the ``.S`` extension. The linker source files for each
290640d553cfSPaul Beesleyboot stage have the extension ``.ld.S``. These are processed by GCC to create the
290740d553cfSPaul Beesleylinker scripts which have the extension ``.ld``.
290840d553cfSPaul Beesley
290940d553cfSPaul BeesleyFDTs provide a description of the hardware platform and are used by the Linux
291040d553cfSPaul Beesleykernel at boot time. These can be found in the ``fdts`` directory.
291140d553cfSPaul Beesley
291234760951SPaul Beesley.. rubric:: References
291340d553cfSPaul Beesley
291434760951SPaul Beesley-  `Trusted Board Boot Requirements CLIENT (TBBR-CLIENT) Armv8-A (ARM DEN0006D)`_
291534760951SPaul Beesley
29163be6b4fbSManish V Badarkhe-  `PSCI`_
291734760951SPaul Beesley
291871ac931fSSandrine Bailleux-  `SMC Calling Convention`_
291934760951SPaul Beesley
292034760951SPaul Beesley-  :ref:`Interrupt Management Framework`
292140d553cfSPaul Beesley
292240d553cfSPaul Beesley--------------
292340d553cfSPaul Beesley
29240d020822SBoyan Karatotev*Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.*
292540d553cfSPaul Beesley
29263ba55a3cSlaurenw-arm.. _SMCCC: https://developer.arm.com/docs/den0028/latest
29273be6b4fbSManish V Badarkhe.. _PSCI: https://developer.arm.com/documentation/den0022/latest/
292862c9be71SPetre-Ionut Tudor.. _Arm ARM: https://developer.arm.com/docs/ddi0487/latest
29293ba55a3cSlaurenw-arm.. _SMC Calling Convention: https://developer.arm.com/docs/den0028/latest
29304290d343SSandrine Bailleux.. _Trusted Board Boot Requirements CLIENT (TBBR-CLIENT) Armv8-A (ARM DEN0006D): https://developer.arm.com/docs/den0006/latest
29317446c266SZelalem Aweke.. _Arm Confidential Compute Architecture (Arm CCA): https://www.arm.com/why-arm/architecture/security-features/arm-confidential-compute-architecture
29329f9bfd7aSManish Pandey.. _AArch64 exception vector table: https://developer.arm.com/documentation/100933/0100/AArch64-exception-vector-table
293340d553cfSPaul Beesley
2934a2c320a8SPaul Beesley.. |Image 1| image:: ../resources/diagrams/rt-svc-descs-layout.png
2935