blob: 3e1fb720c5697f60f4c3874c2246fa82fa73512b [file] [log] [blame]
Jimmy Brisson0862f012020-04-02 15:19:12 -05001Framework Design
2================
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +02003
4This document provides some details about the internals of the TF-A Tests
5design. It is incomplete at the moment.
6
Jimmy Brisson4844dc92020-04-02 15:19:34 -05007.. _design_high_level_behaviour:
8
Jimmy Brissonff08d3e2020-04-02 15:19:27 -05009High-Level Behaviour
10--------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020011
12The EL3 firmware is expected to hand over to the TF-A tests with all secondary
13cores powered down, i.e. only the primary core should enter the TF-A tests.
14
15The primary CPU initialises the platform and the TF-A tests internal data
16structures.
17
18Then the test session begins. The TF-A tests are executed one after the
19other. Tests results are saved in non-volatile memory as we go along.
20
Sandrine Bailleux68d76a22018-11-07 16:31:23 +010021Once all tests have completed, a report is printed over the serial console.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020022
23Global Code Structure
24---------------------
25
26The code is organised into the following categories (present as directories at
27the top level or under the ``tftf/`` directory):
28
29- **Drivers.**
30
31 Some examples follow, this list might not be exhaustive.
32
33 - Generic GIC driver.
34
35 ``arm_gic.h`` contains the public APIs that tests might use. Both GIC
36 architecture versions 2 and 3 are supported.
37
38 - PL011 UART driver.
39
40 - VExpress NOR flash driver.
41
42 Note that tests are not expected to use this driver in most
43 cases. Instead, they should use the ``tftf_nvm_read()`` and
44 ``tftf_nvm_write()`` wrapper APIs. See definitions in
45 ``tftf/framework/include/nvm.h``. See also the NVM validation test cases
46 (``tftf/tests/framework_validation_tests/test_validation_nvm.c``) for an
47 example of usage of these functions.
48
49 - SP805 watchdog.
50
51 Used solely to generate an interrupt that will reset the system on purpose
52 (used in ``tftf_plat_reset()``).
53
54 - SP804 timer.
55
56 This is used as the system timer on Juno. It is configured such that an
57 interrupt is generated when it reaches 0. It is programmed in one-shot
58 mode, i.e. it must be rearmed every time it reaches 0.
59
60- **Framework.**
61
62 Core features of the test framework.
63
64- **Library code.**
65
Ambroise Vincentd6e806d2019-02-11 14:34:26 +000066 Firstly, there is ``include/libc/`` which provides standard C library
John Tsichritzis4586e0d2018-10-18 10:00:28 +010067 functions like ``memcpy()``, ``printf()`` and so on.
68 Additionally, various other APIs are provided under ``include/lib/``. The
69 below list gives some examples but might not be exhaustive.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020070
71 - ``aarch64/``
72
73 Architecture helper functions for e.g. system registers access, cache
74 maintenance operations, MMU configuration, ...
75
76 - ``events.h``
77
78 Events API. Used to create synchronisation points between CPUs in tests.
79
80 - ``irq.h``
81
82 IRQ handling support. Used to configure IRQs and register/unregister
Boyan Karatotev794b0ac2025-06-20 13:13:29 +010083 handlers called upon reception of a specific IRQ. Also raises software
84 generated interrupts (SGI).
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020085
86 - ``power_management.h``
87
88 Power management operations (CPU ON/OFF, CPU suspend, etc.).
89
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +020090 - ``spinlock.h``
91
92 Lightweight implementation of synchronisation locks. Used to prevent
93 concurrent accesses to shared data structures.
94
95 - ``timer.h``
96
97 Support for programming the timer. Any timer which is in the `always-on`
98 power domain can be used to exit CPUs from suspend state.
99
100 - ``tftf_lib.h``
101
102 Miscellaneous helper functions/macros: MP-safe ``printf()``, low-level
103 PSCI wrappers, insertion of delays, raw SMC interface, support for writing
104 a string in the test report, macros to skip tests on platforms that do not
105 meet topology requirements, etc.
106
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200107 - ``io_storage.h``
108
109 Low-level IO operations. Tests are not expected to use these APIs
110 directly. They should use higher-level APIs like ``tftf_nvm_read()``
111 and ``tftf_nvm_write()``.
112
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200113- **Platform specific.**
114
115 Note that ``include/plat/common/plat_topology.h`` provides the interfaces
116 that a platform must implement to support topology discovery (i.e. how many
117 CPUs and clusters there are).
118
119- **Tests.**
120
John Tsichritzis88a956f2018-10-19 10:30:00 +0100121 The tests are divided into the following categories (present as directories in
122 the ``tftf/tests/`` directory):
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200123
John Tsichritzis88a956f2018-10-19 10:30:00 +0100124 - **Framework validation tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200125
John Tsichritzis88a956f2018-10-19 10:30:00 +0100126 Tests that exercise the core features of the framework. Verify that the test
127 framework itself works properly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200128
John Tsichritzis88a956f2018-10-19 10:30:00 +0100129 - **Runtime services tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200130
John Tsichritzis88a956f2018-10-19 10:30:00 +0100131 Tests that exercise the runtime services offered by the EL3 Firmware to the
132 Normal World software. For example, this includes tests for the Standard
133 Service (to which PSCI belongs to), the Trusted OS service or the SiP
134 service.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200135
John Tsichritzis88a956f2018-10-19 10:30:00 +0100136 - **CPU extensions tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200137
John Tsichritzis88a956f2018-10-19 10:30:00 +0100138 Tests some CPU extensions features. For example, the AMU tests ensure that
139 the counters provided by the Activity Monitor Unit are behaving correctly.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200140
John Tsichritzis88a956f2018-10-19 10:30:00 +0100141 - **Firmware Update tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200142
John Tsichritzis88a956f2018-10-19 10:30:00 +0100143 Tests that exercise the `Firmware Update`_ feature of TF-A.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200144
John Tsichritzis88a956f2018-10-19 10:30:00 +0100145 - **Template tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200146
John Tsichritzis88a956f2018-10-19 10:30:00 +0100147 Sample test code showing how to write tests in practice. Serves as
148 documentation.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200149
John Tsichritzis88a956f2018-10-19 10:30:00 +0100150 - **Performance tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200151
John Tsichritzis88a956f2018-10-19 10:30:00 +0100152 Simple tests measuring the latency of an SMC call.
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200153
John Tsichritzis88a956f2018-10-19 10:30:00 +0100154 - **Miscellaneous tests.**
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200155
John Tsichritzis88a956f2018-10-19 10:30:00 +0100156 Tests for RAS support, correct system setup, ...
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200157
158All assembler files have the ``.S`` extension. The linker source file has the
159extension ``.ld.S``. This is processed by GCC to create the linker script which
160has the extension ``.ld``.
161
162Detailed Code Structure
163-----------------------
164
165The cold boot entry point is ``tftf_entrypoint`` (see
Jimmy Brisson4844dc92020-04-02 15:19:34 -0500166``tftf/framework/aarch64/entrypoint.S``). As explained in
167:ref:`design_high_level_behaviour`, only the primary CPU is expected to
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200168execute this code.
169
170Tests can power on other CPUs using the function ``tftf_cpu_on()``. This uses
171the PSCI ``CPU_ON`` API of the EL3 Firmware. When entering the Normal World,
172execution starts at the warm boot entry point, which is ``tftf_hotplug_entry()``
173(see ``tftf/framework/aarch64/entrypoint.S``).
174
175Information about the progression of the test session and tests results are
176written into Non-Volatile Memory as we go along. This consists of the following
177data (see struct ``tftf_state_t`` typedef in ``tftf/framework/include/nvm.h``):
178
179- ``test_to_run``
180
181 Reference to the test to run.
182
183- ``test_progress``
184
185 Progress in the execution of ``test_to_run``. This is used to implement the
186 following state machine:
187
188::
189
190 +-> TEST_READY (initial state of the test) <--------------+
191 | | |
192 | | Test framework prepares the test environment. |
193 | | |
194 | v |
195 | TEST_IN_PROGRESS |
196 | | |
197 | | Hand over to the test function. |
198 | | If the test wants to reboot the platform ---> TEST_REBOOTING |
199 | | | |
200 | | Test function returns into framework. | Reboot |
201 | | | |
202 | | +---------+
203 | v
204 | TEST_COMPLETE
205 | |
206 | | Do some framework management.
207 | | Move to next test.
208 +--------+
209
210- ``testcase_buffer``
211
212 A buffer that the test can use as a scratch area for whatever it is doing.
213
214- ``testcase_results``
215
216- ``result_buffer_size``
217
218- ``result_buffer``
219
220 Buffer holding the tests output. Tests output are concatenated.
221
Jimmy Brissonff08d3e2020-04-02 15:19:27 -0500222Interrupt Management
223--------------------
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200224
225The TF-A tests expect SGIs #0 to #7 to be available for their own usage. In
226particular, this means that Trusted World software must configure them as
227non-secure interrupts.
228
229SGI #7 has a special status. It is the SGI that the timer management framework
230sends to all CPUs when the system timer fires off (see the definition of the
231constant ``IRQ_WAKE_SGI`` in the header file ``include/lib/irq.h``). Although
232test cases can use this specific SGI - e.g. they can register an IRQ handler for
233it and use it as an inter-CPU communication mechanism - they have to be aware of
234the underlying consequences. Some tests, like the PSCI ``CPU_SUSPEND`` tests,
235rely on this SGI to be enabled in order to wake up CPUs from their suspend
236state. If it is disabled, these tests will leave the system in an unresponsive
237state.
238
239--------------
240
Boyan Karatotev794b0ac2025-06-20 13:13:29 +0100241*Copyright (c) 2018-2025, Arm Limited. All rights reserved.*
Sandrine Bailleux3cd87d72018-10-09 11:12:55 +0200242
Jimmy Brisson4844dc92020-04-02 15:19:34 -0500243.. _Firmware update: https://trustedfirmware-a.readthedocs.io/en/latest/components/firmware-update.html