blob: f42ff6498e44b03e343c5b344edacf7b99feb864 [file] [log] [blame] [view]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001ARM Trusted Firmware Porting Guide
2==================================
3
4Contents
5--------
6
Joakim Bech14a5b342014-11-25 10:55:26 +010071. [Introduction](#1--introduction)
82. [Common Modifications](#2--common-modifications)
9 * [Common mandatory modifications](#21-common-mandatory-modifications)
10 * [Handling reset](#22-handling-reset)
Soby Mathew58523c02015-06-08 12:32:50 +010011 * [Common mandatory modifications](#23-common-mandatory-modifications)
12 * [Common optional modifications](#24-common-optional-modifications)
Joakim Bech14a5b342014-11-25 10:55:26 +0100133. [Boot Loader stage specific modifications](#3--modifications-specific-to-a-boot-loader-stage)
14 * [Boot Loader stage 1 (BL1)](#31-boot-loader-stage-1-bl1)
15 * [Boot Loader stage 2 (BL2)](#32-boot-loader-stage-2-bl2)
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000016 * [FWU Boot Loader stage 2 (BL2U)](#33-fwu-boot-loader-stage-2-bl2u)
17 * [Boot Loader stage 3-1 (BL31)](#34-boot-loader-stage-3-1-bl31)
18 * [PSCI implementation (in BL31)](#35-power-state-coordination-interface-in-bl31)
19 * [Interrupt Management framework (in BL31)](#36--interrupt-management-framework-in-bl31)
20 * [Crash Reporting mechanism (in BL31)](#37--crash-reporting-mechanism-in-bl31)
Joakim Bech14a5b342014-11-25 10:55:26 +0100214. [Build flags](#4--build-flags)
225. [C Library](#5--c-library)
236. [Storage abstraction layer](#6--storage-abstraction-layer)
Achin Gupta4f6ad662013-10-25 09:08:21 +010024
25- - - - - - - - - - - - - - - - - -
26
271. Introduction
28----------------
29
Soby Mathew58523c02015-06-08 12:32:50 +010030Please note that this document has been updated for the new platform API
31as required by the PSCI v1.0 implementation. Please refer to the
32[Migration Guide] for the previous platform API.
33
Achin Gupta4f6ad662013-10-25 09:08:21 +010034Porting the ARM Trusted Firmware to a new platform involves making some
35mandatory and optional modifications for both the cold and warm boot paths.
36Modifications consist of:
37
38* Implementing a platform-specific function or variable,
39* Setting up the execution context in a certain way, or
40* Defining certain constants (for example #defines).
41
Dan Handley4a75b842015-03-19 19:24:43 +000042The platform-specific functions and variables are declared in
Dan Handleyb68954c2014-05-29 12:30:24 +010043[include/plat/common/platform.h]. The firmware provides a default implementation
44of variables and functions to fulfill the optional requirements. These
45implementations are all weakly defined; they are provided to ease the porting
46effort. Each platform port can override them with its own implementation if the
47default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010048
Dan Handley4a75b842015-03-19 19:24:43 +000049Platform ports that want to be aligned with standard ARM platforms (for example
50FVP and Juno) may also use [include/plat/arm/common/plat_arm.h] and the
51corresponding source files in `plat/arm/common/`. These provide standard
52implementations for some of the required platform porting functions. However,
53using these functions requires the platform port to implement additional
54ARM standard platform porting functions. These additional functions are not
55documented here.
56
Achin Gupta4f6ad662013-10-25 09:08:21 +010057Some modifications are common to all Boot Loader (BL) stages. Section 2
58discusses these in detail. The subsequent sections discuss the remaining
59modifications for each BL stage in detail.
60
61This document should be read in conjunction with the ARM Trusted Firmware
62[User Guide].
63
64
652. Common modifications
66------------------------
67
68This section covers the modifications that should be made by the platform for
69each BL stage to correctly port the firmware stack. They are categorized as
70either mandatory or optional.
71
72
732.1 Common mandatory modifications
74----------------------------------
Sandrine Bailleuxef7fb9e2015-12-02 10:19:06 +000075
76A platform port must enable the Memory Management Unit (MMU) as well as the
77instruction and data caches for each BL stage. Setting up the translation
78tables is the responsibility of the platform port because memory maps differ
Sandrine Bailleux3c2c72f2016-04-26 14:49:57 +010079across platforms. A memory translation library (see `lib/xlat_tables/`) is
80provided to help in this setup. Note that although this library supports
Antonio Nino Diazf33fbb22016-03-31 09:08:56 +010081non-identity mappings, this is intended only for re-mapping peripheral physical
82addresses and allows platforms with high I/O addresses to reduce their virtual
83address space. All other addresses corresponding to code and data must currently
84use an identity mapping.
Sandrine Bailleuxef7fb9e2015-12-02 10:19:06 +000085
86In ARM standard platforms, each BL stage configures the MMU in the
87platform-specific architecture setup function, `blX_plat_arch_setup()`, and uses
88an identity mapping for all addresses.
Achin Gupta4f6ad662013-10-25 09:08:21 +010089
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +010090If the build option `USE_COHERENT_MEM` is enabled, each platform can allocate a
Soby Mathewab8707e2015-01-08 18:02:44 +000091block of identity mapped secure memory with Device-nGnRE attributes aligned to
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +010092page boundary (4K) for each BL stage. All sections which allocate coherent
93memory are grouped under `coherent_ram`. For ex: Bakery locks are placed in a
94section identified by name `bakery_lock` inside `coherent_ram` so that its
95possible for the firmware to place variables in it using the following C code
96directive:
Achin Gupta4f6ad662013-10-25 09:08:21 +010097
Soren Brinkmann65cd2992016-01-14 10:11:05 -080098 __section("bakery_lock")
Achin Gupta4f6ad662013-10-25 09:08:21 +010099
100Or alternatively the following assembler code directive:
101
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +0100102 .section bakery_lock
Achin Gupta4f6ad662013-10-25 09:08:21 +0100103
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +0100104The `coherent_ram` section is a sum of all sections like `bakery_lock` which are
105used to allocate any data structures that are accessed both when a CPU is
106executing with its MMU and caches enabled, and when it's running with its MMU
107and caches disabled. Examples are given below.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108
109The following variables, functions and constants must be defined by the platform
110for the firmware to work correctly.
111
112
Dan Handleyb68954c2014-05-29 12:30:24 +0100113### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100114
Dan Handleyb68954c2014-05-29 12:30:24 +0100115Each platform must ensure that a header file of this name is in the system
116include path with the following constants defined. This may require updating the
Dan Handley4a75b842015-03-19 19:24:43 +0000117list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM development
118platforms, this file is found in `plat/arm/board/<plat_name>/include/`.
119
120Platform ports may optionally use the file [include/plat/common/common_def.h],
121which provides typical values for some of the constants below. These values are
122likely to be suitable for all platform ports.
123
124Platform ports that want to be aligned with standard ARM platforms (for example
125FVP and Juno) may also use [include/plat/arm/common/arm_def.h], which provides
126standard values for some of the constants below. However, this requires the
127platform port to define additional platform porting constants in
128`platform_def.h`. These additional constants are not documented here.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129
James Morrisseyba3155b2013-10-29 10:56:46 +0000130* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131
132 Defines the linker format used by the platform, for example
Dan Handley4a75b842015-03-19 19:24:43 +0000133 `elf64-littleaarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134
James Morrisseyba3155b2013-10-29 10:56:46 +0000135* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100136
137 Defines the processor architecture for the linker by the platform, for
Dan Handley4a75b842015-03-19 19:24:43 +0000138 example `aarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139
James Morrisseyba3155b2013-10-29 10:56:46 +0000140* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100141
142 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000143 by [plat/common/aarch64/platform_mp_stack.S] and
144 [plat/common/aarch64/platform_up_stack.S].
145
Dan Handley4a75b842015-03-19 19:24:43 +0000146* **define : CACHE_WRITEBACK_GRANULE**
147
148 Defines the size in bits of the largest cache line across all the cache
149 levels in the platform.
150
James Morrisseyba3155b2013-10-29 10:56:46 +0000151* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100152
153 Defines the character string printed by BL1 upon entry into the `bl1_main()`
154 function.
155
James Morrisseyba3155b2013-10-29 10:56:46 +0000156* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100157
158 Defines the total number of CPUs implemented by the platform across all
159 clusters in the system.
160
Soby Mathew58523c02015-06-08 12:32:50 +0100161* **#define : PLAT_NUM_PWR_DOMAINS**
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100162
Soby Mathew58523c02015-06-08 12:32:50 +0100163 Defines the total number of nodes in the power domain topology
164 tree at all the power domain levels used by the platform.
165 This macro is used by the PSCI implementation to allocate
166 data structures to represent power domain topology.
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100167
Soby Mathew58523c02015-06-08 12:32:50 +0100168* **#define : PLAT_MAX_PWR_LVL**
Soby Mathew8c32bc22015-02-12 14:45:02 +0000169
Soby Mathew58523c02015-06-08 12:32:50 +0100170 Defines the maximum power domain level that the power management operations
171 should apply to. More often, but not always, the power domain level
172 corresponds to affinity level. This macro allows the PSCI implementation
173 to know the highest power domain level that it should consider for power
174 management operations in the system that the platform implements. For
175 example, the Base AEM FVP implements two clusters with a configurable
176 number of CPUs and it reports the maximum power domain level as 1.
177
178* **#define : PLAT_MAX_OFF_STATE**
179
180 Defines the local power state corresponding to the deepest power down
181 possible at every power domain level in the platform. The local power
182 states for each level may be sparsely allocated between 0 and this value
183 with 0 being reserved for the RUN state. The PSCI implementation uses this
184 value to initialize the local power states of the power domain nodes and
185 to specify the requested power state for a PSCI_CPU_OFF call.
186
187* **#define : PLAT_MAX_RET_STATE**
188
189 Defines the local power state corresponding to the deepest retention state
190 possible at every power domain level in the platform. This macro should be
191 a value less than PLAT_MAX_OFF_STATE and greater than 0. It is used by the
Yatharth Kochar170fb932016-05-09 18:26:35 +0100192 PSCI implementation to distinguish between retention and power down local
Soby Mathew58523c02015-06-08 12:32:50 +0100193 power states within PSCI_CPU_SUSPEND call.
Soby Mathew8c32bc22015-02-12 14:45:02 +0000194
Yatharth Kochar170fb932016-05-09 18:26:35 +0100195* **#define : PLAT_MAX_PWR_LVL_STATES**
196
197 Defines the maximum number of local power states per power domain level
198 that the platform supports. The default value of this macro is 2 since
199 most platforms just support a maximum of two local power states at each
200 power domain level (power-down and retention). If the platform needs to
201 account for more local power states, then it must redefine this macro.
202
203 Currently, this macro is used by the Generic PSCI implementation to size
204 the array used for PSCI_STAT_COUNT/RESIDENCY accounting.
205
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100206* **#define : BL1_RO_BASE**
207
208 Defines the base address in secure ROM where BL1 originally lives. Must be
209 aligned on a page-size boundary.
210
211* **#define : BL1_RO_LIMIT**
212
213 Defines the maximum address in secure ROM that BL1's actual content (i.e.
214 excluding any data section allocated at runtime) can occupy.
215
216* **#define : BL1_RW_BASE**
217
218 Defines the base address in secure RAM where BL1's read-write data will live
219 at runtime. Must be aligned on a page-size boundary.
220
221* **#define : BL1_RW_LIMIT**
222
223 Defines the maximum address in secure RAM that BL1's read-write data can
224 occupy at runtime.
225
James Morrisseyba3155b2013-10-29 10:56:46 +0000226* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100227
228 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000229 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100230
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100231* **#define : BL2_LIMIT**
232
233 Defines the maximum address in secure RAM that the BL2 image can occupy.
234
James Morrisseyba3155b2013-10-29 10:56:46 +0000235* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100236
Juan Castillod1786372015-12-14 09:35:25 +0000237 Defines the base address in secure RAM where BL2 loads the BL31 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000238 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100239
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100240* **#define : BL31_LIMIT**
241
Juan Castillod1786372015-12-14 09:35:25 +0000242 Defines the maximum address in secure RAM that the BL31 image can occupy.
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100243
Juan Castillo16948ae2015-04-13 17:36:19 +0100244For every image, the platform must define individual identifiers that will be
245used by BL1 or BL2 to load the corresponding image into memory from non-volatile
246storage. For the sake of performance, integer numbers will be used as
247identifiers. The platform will use those identifiers to return the relevant
248information about the image to be loaded (file handler, load address,
249authentication information, etc.). The following image identifiers are
250mandatory:
251
252* **#define : BL2_IMAGE_ID**
253
254 BL2 image identifier, used by BL1 to load BL2.
255
256* **#define : BL31_IMAGE_ID**
257
Juan Castillod1786372015-12-14 09:35:25 +0000258 BL31 image identifier, used by BL2 to load BL31.
Juan Castillo16948ae2015-04-13 17:36:19 +0100259
260* **#define : BL33_IMAGE_ID**
261
Juan Castillod1786372015-12-14 09:35:25 +0000262 BL33 image identifier, used by BL2 to load BL33.
Juan Castillo16948ae2015-04-13 17:36:19 +0100263
264If Trusted Board Boot is enabled, the following certificate identifiers must
265also be defined:
266
Juan Castillo516beb52015-12-03 10:19:21 +0000267* **#define : TRUSTED_BOOT_FW_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100268
269 BL2 content certificate identifier, used by BL1 to load the BL2 content
270 certificate.
271
272* **#define : TRUSTED_KEY_CERT_ID**
273
274 Trusted key certificate identifier, used by BL2 to load the trusted key
275 certificate.
276
Juan Castillo516beb52015-12-03 10:19:21 +0000277* **#define : SOC_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100278
Juan Castillod1786372015-12-14 09:35:25 +0000279 BL31 key certificate identifier, used by BL2 to load the BL31 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100280 certificate.
281
Juan Castillo516beb52015-12-03 10:19:21 +0000282* **#define : SOC_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100283
Juan Castillod1786372015-12-14 09:35:25 +0000284 BL31 content certificate identifier, used by BL2 to load the BL31 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100285 certificate.
286
Juan Castillo516beb52015-12-03 10:19:21 +0000287* **#define : NON_TRUSTED_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100288
Juan Castillod1786372015-12-14 09:35:25 +0000289 BL33 key certificate identifier, used by BL2 to load the BL33 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100290 certificate.
291
Juan Castillo516beb52015-12-03 10:19:21 +0000292* **#define : NON_TRUSTED_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100293
Juan Castillod1786372015-12-14 09:35:25 +0000294 BL33 content certificate identifier, used by BL2 to load the BL33 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100295 certificate.
296
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000297* **#define : FWU_CERT_ID**
298
299 Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the
300 FWU content certificate.
301
302
303If the AP Firmware Updater Configuration image, BL2U is used, the following
304must also be defined:
305
306* **#define : BL2U_BASE**
307
308 Defines the base address in secure memory where BL1 copies the BL2U binary
309 image. Must be aligned on a page-size boundary.
310
311* **#define : BL2U_LIMIT**
312
313 Defines the maximum address in secure memory that the BL2U image can occupy.
314
315* **#define : BL2U_IMAGE_ID**
316
317 BL2U image identifier, used by BL1 to fetch an image descriptor
318 corresponding to BL2U.
319
320If the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following
321must also be defined:
322
323* **#define : SCP_BL2U_IMAGE_ID**
324
325 SCP_BL2U image identifier, used by BL1 to fetch an image descriptor
326 corresponding to SCP_BL2U.
327 NOTE: TF does not provide source code for this image.
328
329If the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must
330also be defined:
331
332* **#define : NS_BL1U_BASE**
333
334 Defines the base address in non-secure ROM where NS_BL1U executes.
335 Must be aligned on a page-size boundary.
336 NOTE: TF does not provide source code for this image.
337
338* **#define : NS_BL1U_IMAGE_ID**
339
340 NS_BL1U image identifier, used by BL1 to fetch an image descriptor
341 corresponding to NS_BL1U.
342
343If the Non-Secure Firmware Updater, NS_BL2U is used, the following must also
344be defined:
345
346* **#define : NS_BL2U_BASE**
347
348 Defines the base address in non-secure memory where NS_BL2U executes.
349 Must be aligned on a page-size boundary.
350 NOTE: TF does not provide source code for this image.
351
352* **#define : NS_BL2U_IMAGE_ID**
353
354 NS_BL2U image identifier, used by BL1 to fetch an image descriptor
355 corresponding to NS_BL2U.
356
357
Juan Castillof59821d2015-12-10 15:49:17 +0000358If a SCP_BL2 image is supported by the platform, the following constants must
Achin Gupta8d35f612015-01-25 22:44:23 +0000359also be defined:
360
Juan Castillof59821d2015-12-10 15:49:17 +0000361* **#define : SCP_BL2_IMAGE_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000362
Juan Castillof59821d2015-12-10 15:49:17 +0000363 SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory
364 from platform storage before being transfered to the SCP.
Achin Gupta8d35f612015-01-25 22:44:23 +0000365
Juan Castillo516beb52015-12-03 10:19:21 +0000366* **#define : SCP_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000367
Juan Castillof59821d2015-12-10 15:49:17 +0000368 SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100369 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000370
Juan Castillo516beb52015-12-03 10:19:21 +0000371* **#define : SCP_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000372
Juan Castillof59821d2015-12-10 15:49:17 +0000373 SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2
374 content certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000375
Juan Castillod1786372015-12-14 09:35:25 +0000376If a BL32 image is supported by the platform, the following constants must
Dan Handley5a06bb72014-08-04 11:41:20 +0100377also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100378
Juan Castillo16948ae2015-04-13 17:36:19 +0100379* **#define : BL32_IMAGE_ID**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100380
Juan Castillod1786372015-12-14 09:35:25 +0000381 BL32 image identifier, used by BL2 to load BL32.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100382
Juan Castillo516beb52015-12-03 10:19:21 +0000383* **#define : TRUSTED_OS_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000384
Juan Castillod1786372015-12-14 09:35:25 +0000385 BL32 key certificate identifier, used by BL2 to load the BL32 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100386 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000387
Juan Castillo516beb52015-12-03 10:19:21 +0000388* **#define : TRUSTED_OS_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000389
Juan Castillod1786372015-12-14 09:35:25 +0000390 BL32 content certificate identifier, used by BL2 to load the BL32 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100391 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000392
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100393* **#define : BL32_BASE**
394
Juan Castillod1786372015-12-14 09:35:25 +0000395 Defines the base address in secure memory where BL2 loads the BL32 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100396 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100397
398* **#define : BL32_LIMIT**
399
Juan Castillod1786372015-12-14 09:35:25 +0000400 Defines the maximum address that the BL32 image can occupy.
Dan Handley5a06bb72014-08-04 11:41:20 +0100401
Juan Castillod1786372015-12-14 09:35:25 +0000402If the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the
Dan Handley5a06bb72014-08-04 11:41:20 +0100403platform, the following constants must also be defined:
404
405* **#define : TSP_SEC_MEM_BASE**
406
407 Defines the base address of the secure memory used by the TSP image on the
408 platform. This must be at the same address or below `BL32_BASE`.
409
410* **#define : TSP_SEC_MEM_SIZE**
411
Juan Castillod1786372015-12-14 09:35:25 +0000412 Defines the size of the secure memory used by the BL32 image on the
Dan Handley5a06bb72014-08-04 11:41:20 +0100413 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
Juan Castillod1786372015-12-14 09:35:25 +0000414 the memory required by the BL32 image, defined by `BL32_BASE` and
Dan Handley5a06bb72014-08-04 11:41:20 +0100415 `BL32_LIMIT`.
416
417* **#define : TSP_IRQ_SEC_PHY_TIMER**
418
419 Defines the ID of the secure physical generic timer interrupt used by the
420 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100421
Dan Handley4a75b842015-03-19 19:24:43 +0000422If the platform port uses the translation table library code, the following
423constant must also be defined:
424
425* **#define : MAX_XLAT_TABLES**
426
427 Defines the maximum number of translation tables that are allocated by the
428 translation table library code. To minimize the amount of runtime memory
429 used, choose the smallest value needed to map the required virtual addresses
430 for each BL stage.
431
Juan Castillo359b60d2016-01-07 11:29:15 +0000432* **#define : MAX_MMAP_REGIONS**
433
434 Defines the maximum number of regions that are allocated by the translation
435 table library code. A region consists of physical base address, virtual base
436 address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as
437 defined in the `mmap_region_t` structure. The platform defines the regions
438 that should be mapped. Then, the translation table library will create the
439 corresponding tables and descriptors at runtime. To minimize the amount of
440 runtime memory used, choose the smallest value needed to register the
441 required regions for each BL stage.
442
443* **#define : ADDR_SPACE_SIZE**
444
445 Defines the total size of the address space in bytes. For example, for a 32
446 bit address space, this value should be `(1ull << 32)`.
447
Dan Handley6d16ce02014-08-04 18:31:43 +0100448If the platform port uses the IO storage framework, the following constants
449must also be defined:
450
451* **#define : MAX_IO_DEVICES**
452
453 Defines the maximum number of registered IO devices. Attempting to register
454 more devices than this value using `io_register_device()` will fail with
Juan Castillo7e26fe12015-10-01 17:55:11 +0100455 -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100456
457* **#define : MAX_IO_HANDLES**
458
459 Defines the maximum number of open IO handles. Attempting to open more IO
Juan Castillo7e26fe12015-10-01 17:55:11 +0100460 entities than this value using `io_open()` will fail with -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100461
Haojian Zhuang08b375b2016-04-21 10:52:52 +0800462* **#define : MAX_IO_BLOCK_DEVICES**
463
464 Defines the maximum number of registered IO block devices. Attempting to
465 register more devices this value using `io_dev_open()` will fail
466 with -ENOMEM. MAX_IO_BLOCK_DEVICES should be less than MAX_IO_DEVICES.
467 With this macro, multiple block devices could be supported at the same
468 time.
469
Soby Mathewab8707e2015-01-08 18:02:44 +0000470If the platform needs to allocate data within the per-cpu data framework in
Juan Castillod1786372015-12-14 09:35:25 +0000471BL31, it should define the following macro. Currently this is only required if
Soby Mathewab8707e2015-01-08 18:02:44 +0000472the platform decides not to use the coherent memory section by undefining the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000473`USE_COHERENT_MEM` build flag. In this case, the framework allocates the
474required memory within the the per-cpu data to minimize wastage.
Soby Mathewab8707e2015-01-08 18:02:44 +0000475
476* **#define : PLAT_PCPU_DATA_SIZE**
477
478 Defines the memory (in bytes) to be reserved within the per-cpu data
479 structure for use by the platform layer.
480
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100481The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000482memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100483
484* **#define : BL31_PROGBITS_LIMIT**
485
Juan Castillod1786372015-12-14 09:35:25 +0000486 Defines the maximum address in secure RAM that the BL31's progbits sections
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100487 can occupy.
488
Dan Handley5a06bb72014-08-04 11:41:20 +0100489* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100490
491 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100492
Haojian Zhuang7dc4b222016-02-03 22:35:04 +0800493If the platform port uses the PL061 GPIO driver, the following constant may
494optionally be defined:
495
496* **PLAT_PL061_MAX_GPIOS**
497 Maximum number of GPIOs required by the platform. This allows control how
498 much memory is allocated for PL061 GPIO controllers. The default value is
499 32.
500 [For example, define the build flag in platform.mk]:
501 PLAT_PL061_MAX_GPIOS := 160
502 $(eval $(call add_define,PLAT_PL061_MAX_GPIOS))
503
504
Dan Handleyb68954c2014-05-29 12:30:24 +0100505### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100506
Dan Handleyb68954c2014-05-29 12:30:24 +0100507Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000508the following macro defined. In the ARM development platforms, this file is
509found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100510
Gerald Lejeune9ff67fa2015-11-26 15:47:53 +0100511* **Macro : plat_crash_print_regs**
Soby Mathewa43d4312014-04-07 15:28:55 +0100512
Gerald Lejeune9ff67fa2015-11-26 15:47:53 +0100513 This macro allows the crash reporting routine to print relevant platform
Juan Castillod1786372015-12-14 09:35:25 +0000514 registers in case of an unhandled exception in BL31. This aids in debugging
Gerald Lejeune9ff67fa2015-11-26 15:47:53 +0100515 and this macro can be defined to be empty in case register reporting is not
516 desired.
517
518 For instance, GIC or interconnect registers may be helpful for
519 troubleshooting.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100520
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000521
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005222.2 Handling Reset
523------------------
524
525BL1 by default implements the reset vector where execution starts from a cold
Juan Castillod1786372015-12-14 09:35:25 +0000526or warm boot. BL31 can be optionally set as a reset vector using the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000527`RESET_TO_BL31` make variable.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100528
529For each CPU, the reset vector code is responsible for the following tasks:
530
5311. Distinguishing between a cold boot and a warm boot.
532
5332. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
534 the CPU is placed in a platform-specific state until the primary CPU
535 performs the necessary steps to remove it from this state.
536
5373. In the case of a warm boot, ensuring that the CPU jumps to a platform-
Juan Castillod1786372015-12-14 09:35:25 +0000538 specific address in the BL31 image in the same processor mode as it was
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100539 when released from reset.
540
541The following functions need to be implemented by the platform port to enable
542reset vector code to perform the above tasks.
543
544
Soby Mathew58523c02015-06-08 12:32:50 +0100545### Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100546
Soby Mathew58523c02015-06-08 12:32:50 +0100547 Argument : void
Soby Mathew4c0d0392016-06-16 14:52:04 +0100548 Return : uintptr_t
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100549
Soby Mathew58523c02015-06-08 12:32:50 +0100550This function is called with the called with the MMU and caches disabled
551(`SCTLR_EL3.M` = 0 and `SCTLR_EL3.C` = 0). The function is responsible for
552distinguishing between a warm and cold reset for the current CPU using
553platform-specific means. If it's a warm reset, then it returns the warm
554reset entrypoint point provided to `plat_setup_psci_ops()` during
Juan Castillod1786372015-12-14 09:35:25 +0000555BL31 initialization. If it's a cold reset then this function must return zero.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100556
557This function does not follow the Procedure Call Standard used by the
558Application Binary Interface for the ARM 64-bit architecture. The caller should
559not assume that callee saved registers are preserved across a call to this
560function.
561
562This function fulfills requirement 1 and 3 listed above.
563
Soby Mathew58523c02015-06-08 12:32:50 +0100564Note that for platforms that support programming the reset address, it is
565expected that a CPU will start executing code directly at the right address,
566both on a cold and warm reset. In this case, there is no need to identify the
567type of reset nor to query the warm reset entrypoint. Therefore, implementing
568this function is not required on such platforms.
569
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100570
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000571### Function : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100572
573 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100574
575This function is called with the MMU and data caches disabled. It is responsible
576for placing the executing secondary CPU in a platform-specific state until the
577primary CPU performs the necessary actions to bring it out of that state and
Sandrine Bailleux52010cc2015-05-19 11:54:45 +0100578allow entry into the OS. This function must not return.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100579
Sandrine Bailleuxcdf14082015-10-02 14:35:25 +0100580In the ARM FVP port, when using the normal boot flow, each secondary CPU powers
581itself off. The primary CPU is responsible for powering up the secondary CPUs
582when normal world software requires them. When booting an EL3 payload instead,
583they stay powered on and are put in a holding pen until their mailbox gets
584populated.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100585
586This function fulfills requirement 2 above.
587
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000588Note that for platforms that can't release secondary CPUs out of reset, only the
589primary CPU will execute the cold boot code. Therefore, implementing this
590function is not required on such platforms.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100591
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000592
593### Function : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Juan Castillo53fdceb2014-07-16 15:53:43 +0100594
Soby Mathew58523c02015-06-08 12:32:50 +0100595 Argument : void
Juan Castillo53fdceb2014-07-16 15:53:43 +0100596 Return : unsigned int
597
Soby Mathew58523c02015-06-08 12:32:50 +0100598This function identifies whether the current CPU is the primary CPU or a
599secondary CPU. A return value of zero indicates that the CPU is not the
600primary CPU, while a non-zero return value indicates that the CPU is the
601primary CPU.
Juan Castillo53fdceb2014-07-16 15:53:43 +0100602
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000603Note that for platforms that can't release secondary CPUs out of reset, only the
604primary CPU will execute the cold boot code. Therefore, there is no need to
605distinguish between primary and secondary CPUs and implementing this function is
606not required.
607
Juan Castillo53fdceb2014-07-16 15:53:43 +0100608
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100609### Function : platform_mem_init() [mandatory]
610
611 Argument : void
612 Return : void
613
614This function is called before any access to data is made by the firmware, in
615order to carry out any essential memory initialization.
616
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100617
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100618### Function: plat_get_rotpk_info()
619
620 Argument : void *, void **, unsigned int *, unsigned int *
621 Return : int
622
623This function is mandatory when Trusted Board Boot is enabled. It returns a
624pointer to the ROTPK stored in the platform (or a hash of it) and its length.
625The ROTPK must be encoded in DER format according to the following ASN.1
626structure:
627
628 AlgorithmIdentifier ::= SEQUENCE {
629 algorithm OBJECT IDENTIFIER,
630 parameters ANY DEFINED BY algorithm OPTIONAL
631 }
632
633 SubjectPublicKeyInfo ::= SEQUENCE {
634 algorithm AlgorithmIdentifier,
635 subjectPublicKey BIT STRING
636 }
637
638In case the function returns a hash of the key:
639
640 DigestInfo ::= SEQUENCE {
641 digestAlgorithm AlgorithmIdentifier,
642 digest OCTET STRING
643 }
644
Soby Mathew04943d32016-05-24 15:05:15 +0100645The function returns 0 on success. Any other value is treated as error by the
646Trusted Board Boot. The function also reports extra information related
647to the ROTPK in the flags parameter:
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100648
Soby Mathew04943d32016-05-24 15:05:15 +0100649 ROTPK_IS_HASH : Indicates that the ROTPK returned by the platform is a
650 hash.
651 ROTPK_NOT_DEPLOYED : This allows the platform to skip certificate ROTPK
652 verification while the platform ROTPK is not deployed.
653 When this flag is set, the function does not need to
654 return a platform ROTPK, and the authentication
655 framework uses the ROTPK in the certificate without
656 verifying it against the platform value. This flag
657 must not be used in a deployed production environment.
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100658
Juan Castillo48279d52016-01-22 11:05:57 +0000659### Function: plat_get_nv_ctr()
660
661 Argument : void *, unsigned int *
662 Return : int
663
664This function is mandatory when Trusted Board Boot is enabled. It returns the
665non-volatile counter value stored in the platform in the second argument. The
666cookie in the first argument may be used to select the counter in case the
667platform provides more than one (for example, on platforms that use the default
668TBBR CoT, the cookie will correspond to the OID values defined in
669TRUSTED_FW_NVCOUNTER_OID or NON_TRUSTED_FW_NVCOUNTER_OID).
670
671The function returns 0 on success. Any other value means the counter value could
672not be retrieved from the platform.
673
674
675### Function: plat_set_nv_ctr()
676
677 Argument : void *, unsigned int
678 Return : int
679
680This function is mandatory when Trusted Board Boot is enabled. It sets a new
681counter value in the platform. The cookie in the first argument may be used to
682select the counter (as explained in plat_get_nv_ctr()).
683
684The function returns 0 on success. Any other value means the counter value could
685not be updated.
686
687
Soby Mathew58523c02015-06-08 12:32:50 +01006882.3 Common mandatory modifications
689---------------------------------
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100690
Soby Mathew58523c02015-06-08 12:32:50 +0100691The following functions are mandatory functions which need to be implemented
692by the platform port.
693
694### Function : plat_my_core_pos()
695
696 Argument : void
697 Return : unsigned int
698
699This funtion returns the index of the calling CPU which is used as a
700CPU-specific linear index into blocks of memory (for example while allocating
701per-CPU stacks). This function will be invoked very early in the
702initialization sequence which mandates that this function should be
703implemented in assembly and should not rely on the avalability of a C
Antonio Nino Diaze5846732016-02-08 10:39:42 +0000704runtime environment. This function can clobber x0 - x8 and must preserve
705x9 - x29.
Soby Mathew58523c02015-06-08 12:32:50 +0100706
707This function plays a crucial role in the power domain topology framework in
708PSCI and details of this can be found in [Power Domain Topology Design].
709
710### Function : plat_core_pos_by_mpidr()
711
712 Argument : u_register_t
713 Return : int
714
715This function validates the `MPIDR` of a CPU and converts it to an index,
716which can be used as a CPU-specific linear index into blocks of memory. In
717case the `MPIDR` is invalid, this function returns -1. This function will only
Juan Castillod1786372015-12-14 09:35:25 +0000718be invoked by BL31 after the power domain topology is initialized and can
Soby Mathew58523c02015-06-08 12:32:50 +0100719utilize the C runtime environment. For further details about how ARM Trusted
720Firmware represents the power domain topology and how this relates to the
721linear CPU index, please refer [Power Domain Topology Design].
722
723
Soby Mathew58523c02015-06-08 12:32:50 +01007242.4 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100725---------------------------------
726
727The following are helper functions implemented by the firmware that perform
728common platform-specific tasks. A platform may choose to override these
729definitions.
730
Soby Mathew58523c02015-06-08 12:32:50 +0100731### Function : plat_set_my_stack()
Achin Gupta4f6ad662013-10-25 09:08:21 +0100732
Soby Mathew58523c02015-06-08 12:32:50 +0100733 Argument : void
Achin Gupta4f6ad662013-10-25 09:08:21 +0100734 Return : void
735
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000736This function sets the current stack pointer to the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100737has been allocated for the current CPU. For BL images that only require a
738stack for the primary CPU, the UP version of the function is used. The size
739of the stack allocated to each CPU is specified by the platform defined
740constant `PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100741
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000742Common implementations of this function for the UP and MP BL images are
743provided in [plat/common/aarch64/platform_up_stack.S] and
744[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100745
746
Soby Mathew58523c02015-06-08 12:32:50 +0100747### Function : plat_get_my_stack()
Achin Guptac8afc782013-11-25 18:45:02 +0000748
Soby Mathew58523c02015-06-08 12:32:50 +0100749 Argument : void
Soby Mathew4c0d0392016-06-16 14:52:04 +0100750 Return : uintptr_t
Achin Guptac8afc782013-11-25 18:45:02 +0000751
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000752This function returns the base address of the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100753has been allocated for the current CPU. For BL images that only require a
754stack for the primary CPU, the UP version of the function is used. The size
755of the stack allocated to each CPU is specified by the platform defined
756constant `PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000757
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000758Common implementations of this function for the UP and MP BL images are
759provided in [plat/common/aarch64/platform_up_stack.S] and
760[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000761
762
Achin Gupta4f6ad662013-10-25 09:08:21 +0100763### Function : plat_report_exception()
764
765 Argument : unsigned int
766 Return : void
767
768A platform may need to report various information about its status when an
769exception is taken, for example the current exception level, the CPU security
770state (secure/non-secure), the exception type, and so on. This function is
771called in the following circumstances:
772
773* In BL1, whenever an exception is taken.
774* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100775
776The default implementation doesn't do anything, to avoid making assumptions
777about the way the platform displays its status information.
778
779This function receives the exception type as its argument. Possible values for
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000780exceptions types are listed in the [include/common/bl_common.h] header file.
781Note that these constants are not related to any architectural exception code;
782they are just an ARM Trusted Firmware convention.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100783
784
Soby Mathew24fb8382014-08-14 12:22:32 +0100785### Function : plat_reset_handler()
786
787 Argument : void
788 Return : void
789
790A platform may need to do additional initialization after reset. This function
791allows the platform to do the platform specific intializations. Platform
792specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000793preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100794
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000795The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000796the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100797guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100798
Soby Mathewadd40352014-08-14 12:49:05 +0100799### Function : plat_disable_acp()
800
801 Argument : void
802 Return : void
803
804This api allows a platform to disable the Accelerator Coherency Port (if
805present) during a cluster power down sequence. The default weak implementation
806doesn't do anything. Since this api is called during the power down sequence,
807it has restrictions for stack usage and it can use the registers x0 - x17 as
808scratch registers. It should preserve the value in x18 register as it is used
809by the caller to store the return address.
810
Juan Castillo40fc6cd2015-09-25 15:41:14 +0100811### Function : plat_error_handler()
812
813 Argument : int
814 Return : void
815
816This API is called when the generic code encounters an error situation from
817which it cannot continue. It allows the platform to perform error reporting or
818recovery actions (for example, reset the system). This function must not return.
819
820The parameter indicates the type of error using standard codes from `errno.h`.
821Possible errors reported by the generic code are:
822
823* `-EAUTH`: a certificate or image could not be authenticated (when Trusted
824 Board Boot is enabled)
825* `-ENOENT`: the requested image or certificate could not be found or an IO
826 error was detected
827* `-ENOMEM`: resources exhausted. Trusted Firmware does not use dynamic
828 memory, so this error is usually an indication of an incorrect array size
829
830The default implementation simply spins.
831
Antonio Nino Diaz1c3ea102016-02-01 13:57:25 +0000832### Function : plat_panic_handler()
833
834 Argument : void
835 Return : void
836
837This API is called when the generic code encounters an unexpected error
838situation from which it cannot recover. This function must not return,
839and must be implemented in assembly because it may be called before the C
840environment is initialized.
841
842Note: The address from where it was called is stored in x30 (Link Register).
Antonio Nino Diaz1c3ea102016-02-01 13:57:25 +0000843The default implementation simply spins.
844
Soby Mathew24fb8382014-08-14 12:22:32 +0100845
Yatharth Kochar72600222016-09-12 16:08:41 +0100846### Function : plat_get_bl_image_load_info()
847
848 Argument : void
849 Return : bl_load_info_t *
850
851This function returns pointer to the list of images that the platform has
852populated to load. This function is currently invoked in BL2 to load the
853BL3xx images, when LOAD_IMAGE_V2 is enabled.
854
855### Function : plat_get_next_bl_params()
856
857 Argument : void
858 Return : bl_params_t *
859
860This function returns a pointer to the shared memory that the platform has
861kept aside to pass trusted firmware related information that next BL image
862needs. This function is currently invoked in BL2 to pass this information to
863the next BL image, when LOAD_IMAGE_V2 is enabled.
864
865### Function : plat_flush_next_bl_params()
866
867 Argument : void
868 Return : void
869
870This function flushes to main memory all the image params that are passed to
871next image. This function is currently invoked in BL2 to flush this information
872to the next BL image, when LOAD_IMAGE_V2 is enabled.
873
Achin Gupta4f6ad662013-10-25 09:08:21 +01008743. Modifications specific to a Boot Loader stage
875-------------------------------------------------
876
8773.1 Boot Loader Stage 1 (BL1)
878-----------------------------
879
880BL1 implements the reset vector where execution starts from after a cold or
881warm boot. For each CPU, BL1 is responsible for the following tasks:
882
Vikram Kanigirie452cd82014-05-23 15:56:12 +01008831. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100884
8852. In the case of a cold boot and the CPU being the primary CPU, ensuring that
886 only this CPU executes the remaining BL1 code, including loading and passing
887 control to the BL2 stage.
888
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00008893. Identifying and starting the Firmware Update process (if required).
890
8914. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100892 address specified by the platform defined constant `BL2_BASE`.
893
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00008945. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100895 accessible by BL2 immediately upon entry.
896
897 meminfo.total_base = Base address of secure RAM visible to BL2
898 meminfo.total_size = Size of secure RAM visible to BL2
899 meminfo.free_base = Base address of secure RAM available for
900 allocation to BL2
901 meminfo.free_size = Size of secure RAM available for allocation to BL2
902
903 BL1 places this `meminfo` structure at the beginning of the free memory
904 available for its use. Since BL1 cannot allocate memory dynamically at the
905 moment, its free memory will be available for BL2's use as-is. However, this
906 means that BL2 must read the `meminfo` structure before it starts using its
907 free memory (this is discussed in Section 3.2).
908
909 In future releases of the ARM Trusted Firmware it will be possible for
910 the platform to decide where it wants to place the `meminfo` structure for
911 BL2.
912
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100913 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100914 BL2 `meminfo` structure. The platform may override this implementation, for
915 example if the platform wants to restrict the amount of memory visible to
916 BL2. Details of how to do this are given below.
917
918The following functions need to be implemented by the platform port to enable
919BL1 to perform the above tasks.
920
921
Dan Handley4a75b842015-03-19 19:24:43 +0000922### Function : bl1_early_platform_setup() [mandatory]
923
924 Argument : void
925 Return : void
926
927This function executes with the MMU and data caches disabled. It is only called
928by the primary CPU.
929
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +0000930On ARM standard platforms, this function:
931
932* Enables a secure instance of SP805 to act as the Trusted Watchdog.
933
934* Initializes a UART (PL011 console), which enables access to the `printf`
935 family of functions in BL1.
936
937* Enables issuing of snoop and DVM (Distributed Virtual Memory) requests to
938 the CCI slave interface corresponding to the cluster that includes the
939 primary CPU.
Dan Handley4a75b842015-03-19 19:24:43 +0000940
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100941### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100942
943 Argument : void
944 Return : void
945
Achin Gupta4f6ad662013-10-25 09:08:21 +0100946This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000947platform requires. Platform-specific setup might include configuration of
948memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100949
Dan Handley4a75b842015-03-19 19:24:43 +0000950In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100951
952This function helps fulfill requirement 2 above.
953
954
955### Function : bl1_platform_setup() [mandatory]
956
957 Argument : void
958 Return : void
959
960This function executes with the MMU and data caches enabled. It is responsible
961for performing any remaining platform-specific setup that can occur after the
962MMU and data cache have been enabled.
963
Dan Handley4a75b842015-03-19 19:24:43 +0000964In ARM standard platforms, this function initializes the storage abstraction
965layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000966
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000967This function helps fulfill requirement 4 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100968
969
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000970### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100971
972 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000973 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100974
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000975This function should only be called on the cold boot path. It executes with the
976MMU and data caches enabled. The pointer returned by this function must point to
977a `meminfo` structure containing the extents and availability of secure RAM for
978the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100979
980 meminfo.total_base = Base address of secure RAM visible to BL1
981 meminfo.total_size = Size of secure RAM visible to BL1
982 meminfo.free_base = Base address of secure RAM available for allocation
983 to BL1
984 meminfo.free_size = Size of secure RAM available for allocation to BL1
985
986This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
987populates a similar structure to tell BL2 the extents of memory available for
988its own use.
989
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000990This function helps fulfill requirements 4 and 5 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100991
992
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100993### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100994
Soby Mathew4c0d0392016-06-16 14:52:04 +0100995 Argument : meminfo *, meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100996 Return : void
997
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100998BL1 needs to tell the next stage the amount of secure RAM available
999for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +01001000structure.
1001
1002Depending upon where BL2 has been loaded in secure RAM (determined by
1003`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
1004BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +00001005to BL2. An illustration of how this is done in ARM standard platforms is given
1006in the **Memory layout on ARM development platforms** section in the
1007[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001008
1009
Juan Castilloe3f67122015-10-05 16:59:38 +01001010### Function : bl1_plat_prepare_exit() [optional]
1011
Sandrine Bailleux862b5dc2015-11-10 15:01:57 +00001012 Argument : entry_point_info_t *
Juan Castilloe3f67122015-10-05 16:59:38 +01001013 Return : void
1014
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00001015This function is called prior to exiting BL1 in response to the
1016`BL1_SMC_RUN_IMAGE` SMC request raised by BL2. It should be used to perform
1017platform specific clean up or bookkeeping operations before transferring
1018control to the next image. It receives the address of the `entry_point_info_t`
1019structure passed from BL2. This function runs with MMU disabled.
1020
1021### Function : bl1_plat_set_ep_info() [optional]
1022
1023 Argument : unsigned int image_id, entry_point_info_t *ep_info
1024 Return : void
1025
1026This function allows platforms to override `ep_info` for the given `image_id`.
1027
1028The default implementation just returns.
1029
1030### Function : bl1_plat_get_next_image_id() [optional]
1031
1032 Argument : void
1033 Return : unsigned int
1034
1035This and the following function must be overridden to enable the FWU feature.
1036
1037BL1 calls this function after platform setup to identify the next image to be
1038loaded and executed. If the platform returns `BL2_IMAGE_ID` then BL1 proceeds
1039with the normal boot sequence, which loads and executes BL2. If the platform
1040returns a different image id, BL1 assumes that Firmware Update is required.
1041
1042The default implementation always returns `BL2_IMAGE_ID`. The ARM development
1043platforms override this function to detect if firmware update is required, and
1044if so, return the first image in the firmware update process.
1045
1046### Function : bl1_plat_get_image_desc() [optional]
1047
1048 Argument : unsigned int image_id
1049 Return : image_desc_t *
1050
1051BL1 calls this function to get the image descriptor information `image_desc_t`
1052for the provided `image_id` from the platform.
1053
1054The default implementation always returns a common BL2 image descriptor. ARM
1055standard platforms return an image descriptor corresponding to BL2 or one of
1056the firmware update images defined in the Trusted Board Boot Requirements
1057specification.
1058
1059### Function : bl1_plat_fwu_done() [optional]
1060
1061 Argument : unsigned int image_id, uintptr_t image_src,
1062 unsigned int image_size
1063 Return : void
1064
1065BL1 calls this function when the FWU process is complete. It must not return.
1066The platform may override this function to take platform specific action, for
1067example to initiate the normal boot flow.
1068
1069The default implementation spins forever.
1070
1071### Function : bl1_plat_mem_check() [mandatory]
1072
1073 Argument : uintptr_t mem_base, unsigned int mem_size,
1074 unsigned int flags
1075 Return : void
1076
1077BL1 calls this function while handling FWU copy and authenticate SMCs. The
1078platform must ensure that the provided `mem_base` and `mem_size` are mapped into
1079BL1, and that this memory corresponds to either a secure or non-secure memory
1080region as indicated by the security state of the `flags` argument.
1081
1082The default implementation of this function asserts therefore platforms must
1083override it when using the FWU feature.
Juan Castilloe3f67122015-10-05 16:59:38 +01001084
1085
Achin Gupta4f6ad662013-10-25 09:08:21 +010010863.2 Boot Loader Stage 2 (BL2)
1087-----------------------------
1088
1089The BL2 stage is executed only by the primary CPU, which is determined in BL1
1090using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
1091`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
1092
Juan Castillof59821d2015-12-10 15:49:17 +000010931. (Optional) Loading the SCP_BL2 binary image (if present) from platform
1094 provided non-volatile storage. To load the SCP_BL2 image, BL2 makes use of
1095 the `meminfo` returned by the `bl2_plat_get_scp_bl2_meminfo()` function.
1096 The platform also defines the address in memory where SCP_BL2 is loaded
1097 through the optional constant `SCP_BL2_BASE`. BL2 uses this information
1098 to determine if there is enough memory to load the SCP_BL2 image.
1099 Subsequent handling of the SCP_BL2 image is platform-specific and is
1100 implemented in the `bl2_plat_handle_scp_bl2()` function.
1101 If `SCP_BL2_BASE` is not defined then this step is not performed.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001102
Juan Castillod1786372015-12-14 09:35:25 +000011032. Loading the BL31 binary image into secure RAM from non-volatile storage. To
1104 load the BL31 image, BL2 makes use of the `meminfo` structure passed to it
Harry Liebeld265bd72014-01-31 19:04:10 +00001105 by BL1. This structure allows BL2 to calculate how much secure RAM is
1106 available for its use. The platform also defines the address in secure RAM
Juan Castillod1786372015-12-14 09:35:25 +00001107 where BL31 is loaded through the constant `BL31_BASE`. BL2 uses this
1108 information to determine if there is enough memory to load the BL31 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001109
Juan Castillod1786372015-12-14 09:35:25 +000011103. (Optional) Loading the BL32 binary image (if present) from platform
1111 provided non-volatile storage. To load the BL32 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001112 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
Juan Castillod1786372015-12-14 09:35:25 +00001113 The platform also defines the address in memory where BL32 is loaded
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001114 through the optional constant `BL32_BASE`. BL2 uses this information
Juan Castillod1786372015-12-14 09:35:25 +00001115 to determine if there is enough memory to load the BL32 image.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001116 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001117
Juan Castillod1786372015-12-14 09:35:25 +000011184. (Optional) Arranging to pass control to the BL32 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001119 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +01001120 structure in memory provided by the platform with information about how
Juan Castillod1786372015-12-14 09:35:25 +00001121 BL31 should pass control to the BL32 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001122
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +000011235. (Optional) Loading the normal world BL33 binary image (if not loaded by
1124 other means) into non-secure DRAM from platform storage and arranging for
1125 BL31 to pass control to this image. This address is determined using the
1126 `plat_get_ns_image_entrypoint()` function described below.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001127
11286. BL2 populates an `entry_point_info` structure in memory provided by the
Juan Castillod1786372015-12-14 09:35:25 +00001129 platform with information about how BL31 should pass control to the
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001130 other BL images.
1131
Achin Gupta4f6ad662013-10-25 09:08:21 +01001132The following functions must be implemented by the platform port to enable BL2
1133to perform the above tasks.
1134
1135
1136### Function : bl2_early_platform_setup() [mandatory]
1137
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001138 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001139 Return : void
1140
1141This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001142by the primary CPU. The arguments to this function is the address of the
1143`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001144
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001145The platform may copy the contents of the `meminfo` structure into a private
Achin Gupta4f6ad662013-10-25 09:08:21 +01001146variable as the original memory may be subsequently overwritten by BL2. The
1147copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +00001148`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001149
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001150On ARM standard platforms, this function also:
1151
1152* Initializes a UART (PL011 console), which enables access to the `printf`
1153 family of functions in BL2.
1154
1155* Initializes the storage abstraction layer used to load further bootloader
1156 images. It is necessary to do this early on platforms with a SCP_BL2 image,
1157 since the later `bl2_platform_setup` must be done after SCP_BL2 is loaded.
Dan Handley4a75b842015-03-19 19:24:43 +00001158
Achin Gupta4f6ad662013-10-25 09:08:21 +01001159
1160### Function : bl2_plat_arch_setup() [mandatory]
1161
1162 Argument : void
1163 Return : void
1164
1165This function executes with the MMU and data caches disabled. It is only called
1166by the primary CPU.
1167
1168The purpose of this function is to perform any architectural initialization
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001169that varies across platforms.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001170
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001171On ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001172
1173### Function : bl2_platform_setup() [mandatory]
1174
1175 Argument : void
1176 Return : void
1177
1178This function may execute with the MMU and data caches enabled if the platform
1179port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
1180called by the primary CPU.
1181
Achin Guptae4d084e2014-02-19 17:18:23 +00001182The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +00001183specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +01001184
Dan Handley4a75b842015-03-19 19:24:43 +00001185In ARM standard platforms, this function performs security setup, including
1186configuration of the TrustZone controller to allow non-secure masters access
1187to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +00001188
Achin Gupta4f6ad662013-10-25 09:08:21 +01001189
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001190### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001191
1192 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001193 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001194
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001195This function should only be called on the cold boot path. It may execute with
1196the MMU and data caches enabled if the platform port does the necessary
1197initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001198
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001199The purpose of this function is to return a pointer to a `meminfo` structure
1200populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +01001201`bl2_early_platform_setup()` above.
1202
1203
Yatharth Kochar72600222016-09-12 16:08:41 +01001204Following function is required only when LOAD_IMAGE_V2 is enabled.
1205
1206### Function : bl2_plat_handle_post_image_load() [mandatory]
1207
1208 Argument : unsigned int
1209 Return : int
1210
1211This function can be used by the platforms to update/use image information
1212for given `image_id`. This function is currently invoked in BL2 to handle
1213BL image specific information based on the `image_id` passed, when
1214LOAD_IMAGE_V2 is enabled.
1215
1216Following functions are required only when LOAD_IMAGE_V2 is disabled.
1217
Juan Castillof59821d2015-12-10 15:49:17 +00001218### Function : bl2_plat_get_scp_bl2_meminfo() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001219
1220 Argument : meminfo *
1221 Return : void
1222
1223This function is used to get the memory limits where BL2 can load the
Juan Castillof59821d2015-12-10 15:49:17 +00001224SCP_BL2 image. The meminfo provided by this is used by load_image() to
1225validate whether the SCP_BL2 image can be loaded within the given
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001226memory from the given base.
1227
1228
Juan Castillof59821d2015-12-10 15:49:17 +00001229### Function : bl2_plat_handle_scp_bl2() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001230
1231 Argument : image_info *
1232 Return : int
1233
Juan Castillof59821d2015-12-10 15:49:17 +00001234This function is called after loading SCP_BL2 image and it is used to perform
1235any platform-specific actions required to handle the SCP firmware. Typically it
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001236transfers the image into SCP memory using a platform-specific protocol and waits
1237until SCP executes it and signals to the Application Processor (AP) for BL2
1238execution to continue.
1239
1240This function returns 0 on success, a negative error code otherwise.
1241
1242
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001243### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +00001244
1245 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001246 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +00001247
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001248BL2 platform code needs to return a pointer to a `bl31_params` structure it
Juan Castillod1786372015-12-14 09:35:25 +00001249will use for passing information to BL31. The `bl31_params` structure carries
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001250the following information.
1251 - Header describing the version information for interpreting the bl31_param
1252 structure
Juan Castillod1786372015-12-14 09:35:25 +00001253 - Information about executing the BL33 image in the `bl33_ep_info` field
1254 - Information about executing the BL32 image in the `bl32_ep_info` field
1255 - Information about the type and extents of BL31 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001256 `bl31_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001257 - Information about the type and extents of BL32 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001258 `bl32_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001259 - Information about the type and extents of BL33 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001260 `bl33_image_info` field
1261
1262The memory pointed by this structure and its sub-structures should be
Juan Castillod1786372015-12-14 09:35:25 +00001263accessible from BL31 initialisation code. BL31 might choose to copy the
1264necessary content, or maintain the structures until BL33 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +00001265
1266
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001267### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001268
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001269 Argument : void
1270 Return : entry_point_info *
1271
1272BL2 platform code returns a pointer which is used to populate the entry point
Juan Castillod1786372015-12-14 09:35:25 +00001273information for BL31 entry point. The location pointed by it should be
1274accessible from BL1 while processing the synchronous exception to run to BL31.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001275
Dan Handley4a75b842015-03-19 19:24:43 +00001276In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
1277structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001278
1279
1280### Function : bl2_plat_set_bl31_ep_info() [mandatory]
1281
1282 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001283 Return : void
1284
Juan Castillod1786372015-12-14 09:35:25 +00001285In the normal boot flow, this function is called after loading BL31 image and
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001286it can be used to overwrite the entry point set by loader and also set the
Juan Castillod1786372015-12-14 09:35:25 +00001287security state and SPSR which represents the entry point system state for BL31.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001288
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001289When booting an EL3 payload instead, this function is called after populating
1290its entry point address and can be used for the same purpose for the payload
1291image. It receives a null pointer as its first argument in this case.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001292
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001293### Function : bl2_plat_set_bl32_ep_info() [mandatory]
1294
1295 Argument : image_info *, entry_point_info *
1296 Return : void
1297
Juan Castillod1786372015-12-14 09:35:25 +00001298This function is called after loading BL32 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001299overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001300and SPSR which represents the entry point system state for BL32.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001301
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001302
1303### Function : bl2_plat_set_bl33_ep_info() [mandatory]
1304
1305 Argument : image_info *, entry_point_info *
1306 Return : void
1307
Juan Castillod1786372015-12-14 09:35:25 +00001308This function is called after loading BL33 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001309overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001310and SPSR which represents the entry point system state for BL33.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001311
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001312In the preloaded BL33 alternative boot flow, this function is called after
1313populating its entry point address. It is passed a null pointer as its first
1314argument in this case.
1315
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001316
1317### Function : bl2_plat_get_bl32_meminfo() [mandatory]
1318
1319 Argument : meminfo *
1320 Return : void
1321
1322This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001323BL32 image. The meminfo provided by this is used by load_image() to
1324validate whether the BL32 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001325memory from the given base.
1326
1327### Function : bl2_plat_get_bl33_meminfo() [mandatory]
1328
1329 Argument : meminfo *
1330 Return : void
1331
1332This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001333BL33 image. The meminfo provided by this is used by load_image() to
1334validate whether the BL33 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001335memory from the given base.
1336
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001337This function isn't needed if either `PRELOADED_BL33_BASE` or `EL3_PAYLOAD_BASE`
1338build options are used.
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001339
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001340### Function : bl2_plat_flush_bl31_params() [mandatory]
1341
1342 Argument : void
1343 Return : void
1344
1345Once BL2 has populated all the structures that needs to be read by BL1
Juan Castillod1786372015-12-14 09:35:25 +00001346and BL31 including the bl31_params structures and its sub-structures,
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001347the bl31_ep_info structure and any platform specific data. It flushes
1348all these data to the main memory so that it is available when we jump to
1349later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +01001350
1351### Function : plat_get_ns_image_entrypoint() [mandatory]
1352
1353 Argument : void
Soby Mathewa0ad6012016-03-23 10:11:10 +00001354 Return : uintptr_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001355
1356As previously described, BL2 is responsible for arranging for control to be
Juan Castillod1786372015-12-14 09:35:25 +00001357passed to a normal world BL image through BL31. This function returns the
1358entrypoint of that image, which BL31 uses to jump to it.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001359
Juan Castillod1786372015-12-14 09:35:25 +00001360BL2 is responsible for loading the normal world BL33 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001361
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01001362This function isn't needed if either `PRELOADED_BL33_BASE` or `EL3_PAYLOAD_BASE`
1363build options are used.
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001364
Achin Gupta4f6ad662013-10-25 09:08:21 +01001365
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000013663.3 FWU Boot Loader Stage 2 (BL2U)
1367----------------------------------
1368
1369The AP Firmware Updater Configuration, BL2U, is an optional part of the FWU
1370process and is executed only by the primary CPU. BL1 passes control to BL2U at
1371`BL2U_BASE`. BL2U executes in Secure-EL1 and is responsible for:
1372
13731. (Optional) Transfering the optional SCP_BL2U binary image from AP secure
1374 memory to SCP RAM. BL2U uses the SCP_BL2U `image_info` passed by BL1.
1375 `SCP_BL2U_BASE` defines the address in AP secure memory where SCP_BL2U
1376 should be copied from. Subsequent handling of the SCP_BL2U image is
1377 implemented by the platform specific `bl2u_plat_handle_scp_bl2u()` function.
1378 If `SCP_BL2U_BASE` is not defined then this step is not performed.
1379
13802. Any platform specific setup required to perform the FWU process. For
1381 example, ARM standard platforms initialize the TZC controller so that the
1382 normal world can access DDR memory.
1383
1384The following functions must be implemented by the platform port to enable
1385BL2U to perform the tasks mentioned above.
1386
1387### Function : bl2u_early_platform_setup() [mandatory]
1388
1389 Argument : meminfo *mem_info, void *plat_info
1390 Return : void
1391
1392This function executes with the MMU and data caches disabled. It is only
1393called by the primary CPU. The arguments to this function is the address
1394of the `meminfo` structure and platform specific info provided by BL1.
1395
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001396The platform may copy the contents of the `mem_info` and `plat_info` into
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00001397private storage as the original memory may be subsequently overwritten by BL2U.
1398
1399On ARM CSS platforms `plat_info` is interpreted as an `image_info_t` structure,
1400to extract SCP_BL2U image information, which is then copied into a private
1401variable.
1402
1403### Function : bl2u_plat_arch_setup() [mandatory]
1404
1405 Argument : void
1406 Return : void
1407
1408This function executes with the MMU and data caches disabled. It is only
1409called by the primary CPU.
1410
1411The purpose of this function is to perform any architectural initialization
1412that varies across platforms, for example enabling the MMU (since the memory
1413map differs across platforms).
1414
1415### Function : bl2u_platform_setup() [mandatory]
1416
1417 Argument : void
1418 Return : void
1419
1420This function may execute with the MMU and data caches enabled if the platform
1421port does the necessary initialization in `bl2u_plat_arch_setup()`. It is only
1422called by the primary CPU.
1423
1424The purpose of this function is to perform any platform initialization
1425specific to BL2U.
1426
1427In ARM standard platforms, this function performs security setup, including
1428configuration of the TrustZone controller to allow non-secure masters access
1429to most of DRAM. Part of DRAM is reserved for secure world use.
1430
1431### Function : bl2u_plat_handle_scp_bl2u() [optional]
1432
1433 Argument : void
1434 Return : int
1435
1436This function is used to perform any platform-specific actions required to
1437handle the SCP firmware. Typically it transfers the image into SCP memory using
1438a platform-specific protocol and waits until SCP executes it and signals to the
1439Application Processor (AP) for BL2U execution to continue.
1440
1441This function returns 0 on success, a negative error code otherwise.
1442This function is included if SCP_BL2U_BASE is defined.
1443
1444
14453.4 Boot Loader Stage 3-1 (BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001446---------------------------------
1447
Juan Castillod1786372015-12-14 09:35:25 +00001448During cold boot, the BL31 stage is executed only by the primary CPU. This is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001449determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
Juan Castillod1786372015-12-14 09:35:25 +00001450control to BL31 at `BL31_BASE`. During warm boot, BL31 is executed by all
1451CPUs. BL31 executes at EL3 and is responsible for:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001452
14531. Re-initializing all architectural and platform state. Although BL1 performs
Juan Castillod1786372015-12-14 09:35:25 +00001454 some of this initialization, BL31 remains resident in EL3 and must ensure
Achin Gupta4f6ad662013-10-25 09:08:21 +01001455 that EL3 architectural and platform state is completely initialized. It
1456 should make no assumptions about the system state when it receives control.
1457
14582. Passing control to a normal world BL image, pre-loaded at a platform-
Juan Castillod1786372015-12-14 09:35:25 +00001459 specific address by BL2. BL31 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001460 populated in memory to do this.
1461
Juan Castillod1786372015-12-14 09:35:25 +000014623. Providing runtime firmware services. Currently, BL31 only implements a
Achin Gupta4f6ad662013-10-25 09:08:21 +01001463 subset of the Power State Coordination Interface (PSCI) API as a runtime
1464 service. See Section 3.3 below for details of porting the PSCI
1465 implementation.
1466
Juan Castillod1786372015-12-14 09:35:25 +000014674. Optionally passing control to the BL32 image, pre-loaded at a platform-
1468 specific address by BL2. BL31 exports a set of apis that allow runtime
Achin Gupta35ca3512014-02-19 17:58:33 +00001469 services to specify the security state in which the next image should be
Juan Castillod1786372015-12-14 09:35:25 +00001470 executed and run the corresponding image. BL31 uses the `entry_point_info`
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001471 structure populated by BL2 to do this.
1472
Juan Castillod1786372015-12-14 09:35:25 +00001473If BL31 is a reset vector, It also needs to handle the reset as specified in
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001474section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001475
Juan Castillod1786372015-12-14 09:35:25 +00001476The following functions must be implemented by the platform port to enable BL31
Achin Gupta4f6ad662013-10-25 09:08:21 +01001477to perform the above tasks.
1478
1479
1480### Function : bl31_early_platform_setup() [mandatory]
1481
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001482 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001483 Return : void
1484
1485This function executes with the MMU and data caches disabled. It is only called
1486by the primary CPU. The arguments to this function are:
1487
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001488* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001489* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001490
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001491The platform can copy the contents of the `bl31_params` structure and its
1492sub-structures into private variables if the original memory may be
Juan Castillod1786372015-12-14 09:35:25 +00001493subsequently overwritten by BL31 and similarly the `void *` pointing
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001494to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001495
Dan Handley4a75b842015-03-19 19:24:43 +00001496In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
Juan Castillod1786372015-12-14 09:35:25 +00001497in BL2 memory. BL31 copies the information in this pointer to internal data
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001498structures. It also performs the following:
1499
1500* Initialize a UART (PL011 console), which enables access to the `printf`
1501 family of functions in BL31.
1502
1503* Enable issuing of snoop and DVM (Distributed Virtual Memory) requests to the
1504 CCI slave interface corresponding to the cluster that includes the primary
1505 CPU.
Dan Handley4a75b842015-03-19 19:24:43 +00001506
Achin Gupta4f6ad662013-10-25 09:08:21 +01001507
1508### Function : bl31_plat_arch_setup() [mandatory]
1509
1510 Argument : void
1511 Return : void
1512
1513This function executes with the MMU and data caches disabled. It is only called
1514by the primary CPU.
1515
1516The purpose of this function is to perform any architectural initialization
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001517that varies across platforms.
1518
1519On ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001520
1521
1522### Function : bl31_platform_setup() [mandatory]
1523
1524 Argument : void
1525 Return : void
1526
1527This function may execute with the MMU and data caches enabled if the platform
1528port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1529called by the primary CPU.
1530
1531The purpose of this function is to complete platform initialization so that both
Juan Castillod1786372015-12-14 09:35:25 +00001532BL31 runtime services and normal world software can function correctly.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001533
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00001534On ARM standard platforms, this function does the following:
1535
1536* Initialize the generic interrupt controller.
1537
1538 Depending on the GIC driver selected by the platform, the appropriate GICv2
1539 or GICv3 initialization will be done, which mainly consists of:
1540
1541 - Enable secure interrupts in the GIC CPU interface.
1542 - Disable the legacy interrupt bypass mechanism.
1543 - Configure the priority mask register to allow interrupts of all priorities
1544 to be signaled to the CPU interface.
1545 - Mark SGIs 8-15 and the other secure interrupts on the platform as secure.
1546 - Target all secure SPIs to CPU0.
1547 - Enable these secure interrupts in the GIC distributor.
1548 - Configure all other interrupts as non-secure.
1549 - Enable signaling of secure interrupts in the GIC distributor.
1550
1551* Enable system-level implementation of the generic timer counter through the
1552 memory mapped interface.
1553
1554* Grant access to the system counter timer module
1555
1556* Initialize the power controller device.
1557
1558 In particular, initialise the locks that prevent concurrent accesses to the
1559 power controller device.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001560
1561
Soby Mathew78e61612015-12-09 11:28:43 +00001562### Function : bl31_plat_runtime_setup() [optional]
1563
1564 Argument : void
1565 Return : void
1566
1567The purpose of this function is allow the platform to perform any BL31 runtime
1568setup just prior to BL31 exit during cold boot. The default weak
1569implementation of this function will invoke `console_uninit()` which will
1570suppress any BL31 runtime logs.
1571
Soby Mathew080225d2015-12-09 11:38:43 +00001572In ARM Standard platforms, this function will initialize the BL31 runtime
1573console which will cause all further BL31 logs to be output to the
1574runtime console.
1575
Soby Mathew78e61612015-12-09 11:28:43 +00001576
Achin Gupta4f6ad662013-10-25 09:08:21 +01001577### Function : bl31_get_next_image_info() [mandatory]
1578
Achin Gupta35ca3512014-02-19 17:58:33 +00001579 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001580 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001581
1582This function may execute with the MMU and data caches enabled if the platform
1583port does the necessary initializations in `bl31_plat_arch_setup()`.
1584
1585This function is called by `bl31_main()` to retrieve information provided by
Juan Castillod1786372015-12-14 09:35:25 +00001586BL2 for the next image in the security state specified by the argument. BL31
Achin Gupta35ca3512014-02-19 17:58:33 +00001587uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001588state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001589(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1590should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001591
Antonio Nino Diazd4486392016-05-18 16:53:31 +01001592### Function : plat_get_syscnt_freq2() [mandatory]
Dan Handley4a75b842015-03-19 19:24:43 +00001593
1594 Argument : void
Antonio Nino Diazd4486392016-05-18 16:53:31 +01001595 Return : unsigned int
Dan Handley4a75b842015-03-19 19:24:43 +00001596
1597This function is used by the architecture setup code to retrieve the counter
1598frequency for the CPU's generic timer. This value will be programmed into the
1599`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1600of the system counter, which is retrieved from the first entry in the frequency
1601modes table.
1602
Achin Gupta4f6ad662013-10-25 09:08:21 +01001603
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001604### #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001605
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001606 When `USE_COHERENT_MEM = 0`, this constant defines the total memory (in
1607 bytes) aligned to the cache line boundary that should be allocated per-cpu to
1608 accommodate all the bakery locks.
1609
1610 If this constant is not defined when `USE_COHERENT_MEM = 0`, the linker
1611 calculates the size of the `bakery_lock` input section, aligns it to the
1612 nearest `CACHE_WRITEBACK_GRANULE`, multiplies it with `PLATFORM_CORE_COUNT`
1613 and stores the result in a linker symbol. This constant prevents a platform
1614 from relying on the linker and provide a more efficient mechanism for
1615 accessing per-cpu bakery lock information.
1616
1617 If this constant is defined and its value is not equal to the value
1618 calculated by the linker then a link time assertion is raised. A compile time
1619 assertion is raised if the value of the constant is not aligned to the cache
1620 line boundary.
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001621
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000016223.5 Power State Coordination Interface (in BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001623------------------------------------------------
1624
1625The ARM Trusted Firmware's implementation of the PSCI API is based around the
Soby Mathew58523c02015-06-08 12:32:50 +01001626concept of a _power domain_. A _power domain_ is a CPU or a logical group of
1627CPUs which share some state on which power management operations can be
1628performed as specified by [PSCI]. Each CPU in the system is assigned a cpu
1629index which is a unique number between `0` and `PLATFORM_CORE_COUNT - 1`.
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001630The _power domains_ are arranged in a hierarchical tree structure and
Soby Mathew58523c02015-06-08 12:32:50 +01001631each _power domain_ can be identified in a system by the cpu index of any CPU
1632that is part of that domain and a _power domain level_. A processing element
1633(for example, a CPU) is at level 0. If the _power domain_ node above a CPU is
1634a logical grouping of CPUs that share some state, then level 1 is that group
1635of CPUs (for example, a cluster), and level 2 is a group of clusters
1636(for example, the system). More details on the power domain topology and its
1637organization can be found in [Power Domain Topology Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001638
Juan Castillod1786372015-12-14 09:35:25 +00001639BL31's platform initialization code exports a pointer to the platform-specific
Achin Gupta4f6ad662013-10-25 09:08:21 +01001640power management operations required for the PSCI implementation to function
Soby Mathew58523c02015-06-08 12:32:50 +01001641correctly. This information is populated in the `plat_psci_ops` structure. The
1642PSCI implementation calls members of the `plat_psci_ops` structure for performing
1643power management operations on the power domains. For example, the target
1644CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `pwr_domain_on()`
1645handler (if present) is called for the CPU power domain.
1646
1647The `power-state` parameter of a PSCI `CPU_SUSPEND` call can be used to
1648describe composite power states specific to a platform. The PSCI implementation
1649defines a generic representation of the power-state parameter viz which is an
1650array of local power states where each index corresponds to a power domain
1651level. Each entry contains the local power state the power domain at that power
1652level could enter. It depends on the `validate_power_state()` handler to
1653convert the power-state parameter (possibly encoding a composite power state)
1654passed in a PSCI `CPU_SUSPEND` call to this representation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001655
1656The following functions must be implemented to initialize PSCI functionality in
1657the ARM Trusted Firmware.
1658
1659
Soby Mathew58523c02015-06-08 12:32:50 +01001660### Function : plat_get_target_pwr_state() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001661
Soby Mathew58523c02015-06-08 12:32:50 +01001662 Argument : unsigned int, const plat_local_state_t *, unsigned int
1663 Return : plat_local_state_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001664
Soby Mathew58523c02015-06-08 12:32:50 +01001665The PSCI generic code uses this function to let the platform participate in
1666state coordination during a power management operation. The function is passed
1667a pointer to an array of platform specific local power state `states` (second
1668argument) which contains the requested power state for each CPU at a particular
1669power domain level `lvl` (first argument) within the power domain. The function
1670is expected to traverse this array of upto `ncpus` (third argument) and return
1671a coordinated target power state by the comparing all the requested power
1672states. The target power state should not be deeper than any of the requested
1673power states.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001674
Soby Mathew58523c02015-06-08 12:32:50 +01001675A weak definition of this API is provided by default wherein it assumes
1676that the platform assigns a local state value in order of increasing depth
1677of the power state i.e. for two power states X & Y, if X < Y
1678then X represents a shallower power state than Y. As a result, the
1679coordinated target local power state for a power domain will be the minimum
1680of the requested local power state values.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001681
1682
Soby Mathew58523c02015-06-08 12:32:50 +01001683### Function : plat_get_power_domain_tree_desc() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001684
Soby Mathew58523c02015-06-08 12:32:50 +01001685 Argument : void
1686 Return : const unsigned char *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001687
Soby Mathew58523c02015-06-08 12:32:50 +01001688This function returns a pointer to the byte array containing the power domain
1689topology tree description. The format and method to construct this array are
Juan Castillod1786372015-12-14 09:35:25 +00001690described in [Power Domain Topology Design]. The BL31 PSCI initilization code
Soby Mathew58523c02015-06-08 12:32:50 +01001691requires this array to be described by the platform, either statically or
1692dynamically, to initialize the power domain topology tree. In case the array
1693is populated dynamically, then plat_core_pos_by_mpidr() and
1694plat_my_core_pos() should also be implemented suitably so that the topology
1695tree description matches the CPU indices returned by these APIs. These APIs
1696together form the platform interface for the PSCI topology framework.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001697
1698
Soby Mathew58523c02015-06-08 12:32:50 +01001699## Function : plat_setup_psci_ops() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001700
Soby Mathew58523c02015-06-08 12:32:50 +01001701 Argument : uintptr_t, const plat_psci_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001702 Return : int
1703
1704This function may execute with the MMU and data caches enabled if the platform
1705port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1706called by the primary CPU.
1707
Soby Mathew58523c02015-06-08 12:32:50 +01001708This function is called by PSCI initialization code. Its purpose is to let
1709the platform layer know about the warm boot entrypoint through the
1710`sec_entrypoint` (first argument) and to export handler routines for
1711platform-specific psci power management actions by populating the passed
Juan Castillod1786372015-12-14 09:35:25 +00001712pointer with a pointer to BL31's private `plat_psci_ops` structure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001713
1714A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001715the ARM FVP specific implementation of these handlers in
Soby Mathew58523c02015-06-08 12:32:50 +01001716[plat/arm/board/fvp/fvp_pm.c] as an example. For each PSCI function that the
1717platform wants to support, the associated operation or operations in this
1718structure must be provided and implemented (Refer section 4 of
1719[Firmware Design] for the PSCI API supported in Trusted Firmware). To disable
1720a PSCI function in a platform port, the operation should be removed from this
1721structure instead of providing an empty implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001722
Soby Mathew58523c02015-06-08 12:32:50 +01001723#### plat_psci_ops.cpu_standby()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001724
Soby Mathew58523c02015-06-08 12:32:50 +01001725Perform the platform-specific actions to enter the standby state for a cpu
1726indicated by the passed argument. This provides a fast path for CPU standby
1727wherein overheads of PSCI state management and lock acquistion is avoided.
1728For this handler to be invoked by the PSCI `CPU_SUSPEND` API implementation,
1729the suspend state type specified in the `power-state` parameter should be
1730STANDBY and the target power domain level specified should be the CPU. The
1731handler should put the CPU into a low power retention state (usually by
1732issuing a wfi instruction) and ensure that it can be woken up from that
1733state by a normal interrupt. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001734
Soby Mathew58523c02015-06-08 12:32:50 +01001735#### plat_psci_ops.pwr_domain_on()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001736
Soby Mathew58523c02015-06-08 12:32:50 +01001737Perform the platform specific actions to power on a CPU, specified
1738by the `MPIDR` (first argument). The generic code expects the platform to
1739return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001740
Soby Mathew58523c02015-06-08 12:32:50 +01001741#### plat_psci_ops.pwr_domain_off()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001742
Soby Mathew58523c02015-06-08 12:32:50 +01001743Perform the platform specific actions to prepare to power off the calling CPU
1744and its higher parent power domain levels as indicated by the `target_state`
1745(first argument). It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001746
Soby Mathew58523c02015-06-08 12:32:50 +01001747The `target_state` encodes the platform coordinated target local power states
1748for the CPU power domain and its parent power domain levels. The handler
1749needs to perform power management operation corresponding to the local state
1750at each power level.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001751
Soby Mathew58523c02015-06-08 12:32:50 +01001752For this handler, the local power state for the CPU power domain will be a
1753power down state where as it could be either power down, retention or run state
1754for the higher power domain levels depending on the result of state
1755coordination. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001756
Soby Mathew58523c02015-06-08 12:32:50 +01001757#### plat_psci_ops.pwr_domain_suspend()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001758
Soby Mathew58523c02015-06-08 12:32:50 +01001759Perform the platform specific actions to prepare to suspend the calling
1760CPU and its higher parent power domain levels as indicated by the
1761`target_state` (first argument). It is called by the PSCI `CPU_SUSPEND`
1762API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001763
Soby Mathew58523c02015-06-08 12:32:50 +01001764The `target_state` has a similar meaning as described in
1765the `pwr_domain_off()` operation. It encodes the platform coordinated
1766target local power states for the CPU power domain and its parent
1767power domain levels. The handler needs to perform power management operation
1768corresponding to the local state at each power level. The generic code
1769expects the handler to succeed.
1770
1771The difference between turning a power domain off versus suspending it
1772is that in the former case, the power domain is expected to re-initialize
1773its state when it is next powered on (see `pwr_domain_on_finish()`). In the
1774latter case, the power domain is expected to save enough state so that it can
Achin Gupta4f6ad662013-10-25 09:08:21 +01001775resume execution by restoring this state when its powered on (see
Soby Mathew58523c02015-06-08 12:32:50 +01001776`pwr_domain_suspend_finish()`).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001777
Soby Mathewac1cc8e2016-04-27 14:46:28 +01001778#### plat_psci_ops.pwr_domain_pwr_down_wfi()
1779
1780This is an optional function and, if implemented, is expected to perform
1781platform specific actions including the `wfi` invocation which allows the
1782CPU to powerdown. Since this function is invoked outside the PSCI locks,
1783the actions performed in this hook must be local to the CPU or the platform
1784must ensure that races between multiple CPUs cannot occur.
1785
1786The `target_state` has a similar meaning as described in the `pwr_domain_off()`
1787operation and it encodes the platform coordinated target local power states for
1788the CPU power domain and its parent power domain levels. This function must
1789not return back to the caller.
1790
1791If this function is not implemented by the platform, PSCI generic
1792implementation invokes `psci_power_down_wfi()` for power down.
1793
Soby Mathew58523c02015-06-08 12:32:50 +01001794#### plat_psci_ops.pwr_domain_on_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001795
1796This function is called by the PSCI implementation after the calling CPU is
1797powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1798It performs the platform-specific setup required to initialize enough state for
1799this CPU to enter the normal world and also provide secure runtime firmware
1800services.
1801
Soby Mathew58523c02015-06-08 12:32:50 +01001802The `target_state` (first argument) is the prior state of the power domains
1803immediately before the CPU was turned on. It indicates which power domains
1804above the CPU might require initialization due to having previously been in
1805low power states. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001806
Soby Mathew58523c02015-06-08 12:32:50 +01001807#### plat_psci_ops.pwr_domain_suspend_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001808
1809This function is called by the PSCI implementation after the calling CPU is
1810powered on and released from reset in response to an asynchronous wakeup
1811event, for example a timer interrupt that was programmed by the CPU during the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001812`CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific
1813setup required to restore the saved state for this CPU to resume execution
1814in the normal world and also provide secure runtime firmware services.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001815
Soby Mathew58523c02015-06-08 12:32:50 +01001816The `target_state` (first argument) has a similar meaning as described in
1817the `pwr_domain_on_finish()` operation. The generic code expects the platform
1818to succeed.
Soby Mathew539dced2014-10-02 16:56:51 +01001819
Soby Mathew58523c02015-06-08 12:32:50 +01001820#### plat_psci_ops.validate_power_state()
Soby Mathew539dced2014-10-02 16:56:51 +01001821
1822This function is called by the PSCI implementation during the `CPU_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001823call to validate the `power_state` parameter of the PSCI API and if valid,
1824populate it in `req_state` (second argument) array as power domain level
1825specific local states. If the `power_state` is invalid, the platform must
1826return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1827normal world PSCI client.
Soby Mathew539dced2014-10-02 16:56:51 +01001828
Soby Mathew58523c02015-06-08 12:32:50 +01001829#### plat_psci_ops.validate_ns_entrypoint()
Soby Mathew539dced2014-10-02 16:56:51 +01001830
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001831This function is called by the PSCI implementation during the `CPU_SUSPEND`,
1832`SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point`
Soby Mathew58523c02015-06-08 12:32:50 +01001833parameter passed by the normal world. If the `entry_point` is invalid,
1834the platform must return PSCI_E_INVALID_ADDRESS as error, which is
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001835propagated back to the normal world PSCI client.
1836
Soby Mathew58523c02015-06-08 12:32:50 +01001837#### plat_psci_ops.get_sys_suspend_power_state()
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001838
1839This function is called by the PSCI implementation during the `SYSTEM_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001840call to get the `req_state` parameter from platform which encodes the power
1841domain level specific local states to suspend to system affinity level. The
1842`req_state` will be utilized to do the PSCI state coordination and
1843`pwr_domain_suspend()` will be invoked with the coordinated target state to
1844enter system suspend.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001845
Yatharth Kochar170fb932016-05-09 18:26:35 +01001846#### plat_psci_ops.get_pwr_lvl_state_idx()
1847
1848This is an optional function and, if implemented, is invoked by the PSCI
1849implementation to convert the `local_state` (first argument) at a specified
1850`pwr_lvl` (second argument) to an index between 0 and
1851`PLAT_MAX_PWR_LVL_STATES` - 1. This function is only needed if the platform
1852supports more than two local power states at each power domain level, that is
1853`PLAT_MAX_PWR_LVL_STATES` is greater than 2, and needs to account for these
1854local power states.
1855
1856#### plat_psci_ops.translate_power_state_by_mpidr()
1857
1858This is an optional function and, if implemented, verifies the `power_state`
1859(second argument) parameter of the PSCI API corresponding to a target power
1860domain. The target power domain is identified by using both `MPIDR` (first
1861argument) and the power domain level encoded in `power_state`. The power domain
1862level specific local states are to be extracted from `power_state` and be
1863populated in the `output_state` (third argument) array. The functionality
1864is similar to the `validate_power_state` function described above and is
1865envisaged to be used in case the validity of `power_state` depend on the
1866targeted power domain. If the `power_state` is invalid for the targeted power
1867domain, the platform must return PSCI_E_INVALID_PARAMS as error. If this
1868function is not implemented, then the generic implementation relies on
1869`validate_power_state` function to translate the `power_state`.
1870
1871This function can also be used in case the platform wants to support local
1872power state encoding for `power_state` parameter of PSCI_STAT_COUNT/RESIDENCY
1873APIs as described in Section 5.18 of [PSCI].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001874
Jeenu Viswambharan28d3d612016-08-03 15:54:50 +01001875#### plat_psci_ops.get_node_hw_state()
1876
1877This is an optional function. If implemented this function is intended to return
1878the power state of a node (identified by the first parameter, the `MPIDR`) in
1879the power domain topology (identified by the second parameter, `power_level`),
1880as retrieved from a power controller or equivalent component on the platform.
1881Upon successful completion, the implementation must map and return the final
1882status among `HW_ON`, `HW_OFF` or `HW_STANDBY`. Upon encountering failures, it
1883must return either `PSCI_E_INVALID_PARAMS` or `PSCI_E_NOT_SUPPORTED` as
1884appropriate.
1885
1886Implementations are not expected to handle `power_levels` greater than
1887`PLAT_MAX_PWR_LVL`.
1888
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000018893.6 Interrupt Management framework (in BL31)
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001890----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001891BL31 implements an Interrupt Management Framework (IMF) to manage interrupts
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001892generated in either security state and targeted to EL1 or EL2 in the non-secure
1893state or EL3/S-EL1 in the secure state. The design of this framework is
1894described in the [IMF Design Guide]
1895
1896A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001897text briefly describes each api and its implementation in ARM standard
1898platforms. The API implementation depends upon the type of interrupt controller
Soby Mathew81123e82015-11-23 14:01:21 +00001899present in the platform. ARM standard platform layer supports both [ARM Generic
1900Interrupt Controller version 2.0 (GICv2)][ARM GIC Architecture Specification 2.0]
1901and [3.0 (GICv3)][ARM GIC Architecture Specification 3.0]. Juno builds the ARM
1902Standard layer to use GICv2 and the FVP can be configured to use either GICv2 or
1903GICv3 depending on the build flag `FVP_USE_GIC_DRIVER` (See FVP platform
1904specific build options in [User Guide] for more details).
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001905
1906### Function : plat_interrupt_type_to_line() [mandatory]
1907
1908 Argument : uint32_t, uint32_t
1909 Return : uint32_t
1910
1911The ARM processor signals an interrupt exception either through the IRQ or FIQ
1912interrupt line. The specific line that is signaled depends on how the interrupt
1913controller (IC) reports different interrupt types from an execution context in
1914either security state. The IMF uses this API to determine which interrupt line
1915the platform IC uses to signal each type of interrupt supported by the framework
Soby Mathew81123e82015-11-23 14:01:21 +00001916from a given security state. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001917
1918The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1919Guide]) indicating the target type of the interrupt, the second parameter is the
1920security state of the originating execution context. The return result is the
1921bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1922FIQ=2.
1923
Soby Mathew81123e82015-11-23 14:01:21 +00001924In the case of ARM standard platforms using GICv2, S-EL1 interrupts are
1925configured as FIQs and Non-secure interrupts as IRQs from either security
1926state.
1927
1928In the case of ARM standard platforms using GICv3, the interrupt line to be
1929configured depends on the security state of the execution context when the
1930interrupt is signalled and are as follows:
1931* The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in
1932 NS-EL0/1/2 context.
1933* The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ
1934 in the NS-EL0/1/2 context.
1935* The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2
1936 context.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001937
1938
1939### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1940
1941 Argument : void
1942 Return : uint32_t
1943
1944This API returns the type of the highest priority pending interrupt at the
1945platform IC. The IMF uses the interrupt type to retrieve the corresponding
1946handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1947pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
Soby Mathew81123e82015-11-23 14:01:21 +00001948`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001949
Soby Mathew81123e82015-11-23 14:01:21 +00001950In the case of ARM standard platforms using GICv2, the _Highest Priority
1951Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of
1952the pending interrupt. The type of interrupt depends upon the id value as
1953follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001954
19551. id < 1022 is reported as a S-EL1 interrupt
19562. id = 1022 is reported as a Non-secure interrupt.
19573. id = 1023 is reported as an invalid interrupt type.
1958
Soby Mathew81123e82015-11-23 14:01:21 +00001959In the case of ARM standard platforms using GICv3, the system register
1960`ICC_HPPIR0_EL1`, _Highest Priority Pending group 0 Interrupt Register_,
1961is read to determine the id of the pending interrupt. The type of interrupt
1962depends upon the id value as follows.
1963
19641. id = `PENDING_G1S_INTID` (1020) is reported as a S-EL1 interrupt
19652. id = `PENDING_G1NS_INTID` (1021) is reported as a Non-secure interrupt.
19663. id = `GIC_SPURIOUS_INTERRUPT` (1023) is reported as an invalid interrupt type.
19674. All other interrupt id's are reported as EL3 interrupt.
1968
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001969
1970### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1971
1972 Argument : void
1973 Return : uint32_t
1974
1975This API returns the id of the highest priority pending interrupt at the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001976platform IC. `INTR_ID_UNAVAILABLE` is returned when there is no interrupt
Soby Mathew54718412015-10-27 10:01:06 +00001977pending.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001978
Soby Mathew81123e82015-11-23 14:01:21 +00001979In the case of ARM standard platforms using GICv2, the _Highest Priority
1980Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of the
1981pending interrupt. The id that is returned by API depends upon the value of
1982the id read from the interrupt controller as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001983
19841. id < 1022. id is returned as is.
19852. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001986 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt.
1987 This id is returned by the API.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010019883. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1989
Soby Mathew81123e82015-11-23 14:01:21 +00001990In the case of ARM standard platforms using GICv3, if the API is invoked from
1991EL3, the system register `ICC_HPPIR0_EL1`, _Highest Priority Pending Interrupt
1992group 0 Register_, is read to determine the id of the pending interrupt. The id
1993that is returned by API depends upon the value of the id read from the
1994interrupt controller as follows.
1995
19961. id < `PENDING_G1S_INTID` (1020). id is returned as is.
19972. id = `PENDING_G1S_INTID` (1020) or `PENDING_G1NS_INTID` (1021). The system
1998 register `ICC_HPPIR1_EL1`, _Highest Priority Pending Interrupt group 1
1999 Register_ is read to determine the id of the group 1 interrupt. This id
2000 is returned by the API as long as it is a valid interrupt id
20013. If the id is any of the special interrupt identifiers,
2002 `INTR_ID_UNAVAILABLE` is returned.
2003
2004When the API invoked from S-EL1 for GICv3 systems, the id read from system
2005register `ICC_HPPIR1_EL1`, _Highest Priority Pending group 1 Interrupt
2006Register_, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else
2007`INTR_ID_UNAVAILABLE` is returned.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01002008
2009### Function : plat_ic_acknowledge_interrupt() [mandatory]
2010
2011 Argument : void
2012 Return : uint32_t
2013
2014This API is used by the CPU to indicate to the platform IC that processing of
2015the highest pending interrupt has begun. It should return the id of the
2016interrupt which is being processed.
2017
Soby Mathew81123e82015-11-23 14:01:21 +00002018This function in ARM standard platforms using GICv2, reads the _Interrupt
2019Acknowledge Register_ (`GICC_IAR`). This changes the state of the highest
2020priority pending interrupt from pending to active in the interrupt controller.
2021It returns the value read from the `GICC_IAR`. This value is the id of the
2022interrupt whose state has been changed.
2023
2024In the case of ARM standard platforms using GICv3, if the API is invoked
2025from EL3, the function reads the system register `ICC_IAR0_EL1`, _Interrupt
2026Acknowledge Register group 0_. If the API is invoked from S-EL1, the function
2027reads the system register `ICC_IAR1_EL1`, _Interrupt Acknowledge Register
2028group 1_. The read changes the state of the highest pending interrupt from
2029pending to active in the interrupt controller. The value read is returned
2030and is the id of the interrupt whose state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01002031
2032The TSP uses this API to start processing of the secure physical timer
2033interrupt.
2034
2035
2036### Function : plat_ic_end_of_interrupt() [mandatory]
2037
2038 Argument : uint32_t
2039 Return : void
2040
2041This API is used by the CPU to indicate to the platform IC that processing of
2042the interrupt corresponding to the id (passed as the parameter) has
2043finished. The id should be the same as the id returned by the
2044`plat_ic_acknowledge_interrupt()` API.
2045
Dan Handley4a75b842015-03-19 19:24:43 +00002046ARM standard platforms write the id to the _End of Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00002047(`GICC_EOIR`) in case of GICv2, and to `ICC_EOIR0_EL1` or `ICC_EOIR1_EL1`
2048system register in case of GICv3 depending on where the API is invoked from,
2049EL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01002050controller.
2051
2052The TSP uses this API to finish processing of the secure physical timer
2053interrupt.
2054
2055
2056### Function : plat_ic_get_interrupt_type() [mandatory]
2057
2058 Argument : uint32_t
2059 Return : uint32_t
2060
2061This API returns the type of the interrupt id passed as the parameter.
2062`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
2063interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
2064returned depending upon how the interrupt has been configured by the platform
Soby Mathew81123e82015-11-23 14:01:21 +00002065IC. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01002066
Soby Mathew81123e82015-11-23 14:01:21 +00002067ARM standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts
2068and Non-secure interrupts as Group1 interrupts. It reads the group value
2069corresponding to the interrupt id from the relevant _Interrupt Group Register_
2070(`GICD_IGROUPRn`). It uses the group value to determine the type of interrupt.
2071
2072In the case of ARM standard platforms using GICv3, both the _Interrupt Group
2073Register_ (`GICD_IGROUPRn`) and _Interrupt Group Modifier Register_
2074(`GICD_IGRPMODRn`) is read to figure out whether the interrupt is configured
2075as Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt.
Dan Handley4a75b842015-03-19 19:24:43 +00002076
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01002077
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000020783.7 Crash Reporting mechanism (in BL31)
Soby Mathewc67b09b2014-07-14 16:57:23 +01002079----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00002080BL31 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01002081of the CPU to enable quick crash analysis and debugging. It requires that a
2082console is designated as the crash console by the platform which will be used to
2083print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01002084
Sandrine Bailleux44804252014-08-06 11:27:23 +01002085The following functions must be implemented by the platform if it wants crash
Juan Castillod1786372015-12-14 09:35:25 +00002086reporting mechanism in BL31. The functions are implemented in assembly so that
Sandrine Bailleux44804252014-08-06 11:27:23 +01002087they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01002088
2089### Function : plat_crash_console_init
2090
2091 Argument : void
2092 Return : int
2093
Sandrine Bailleux44804252014-08-06 11:27:23 +01002094This API is used by the crash reporting mechanism to initialize the crash
Juan Castillo9400b402015-11-26 14:52:15 +00002095console. It must only use the general purpose registers x0 to x4 to do the
Sandrine Bailleux44804252014-08-06 11:27:23 +01002096initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01002097
Soby Mathewc67b09b2014-07-14 16:57:23 +01002098### Function : plat_crash_console_putc
2099
2100 Argument : int
2101 Return : int
2102
2103This API is used by the crash reporting mechanism to print a character on the
Juan Castillo9400b402015-11-26 14:52:15 +00002104designated crash console. It must only use general purpose registers x1 and
Soby Mathewc67b09b2014-07-14 16:57:23 +01002105x2 to do its work. The parameter and the return value are in general purpose
2106register x0.
2107
Soby Mathew27713fb2014-09-08 17:51:01 +010021084. Build flags
2109---------------
2110
Soby Mathew58523c02015-06-08 12:32:50 +01002111* **ENABLE_PLAT_COMPAT**
2112 All the platforms ports conforming to this API specification should define
2113 the build flag `ENABLE_PLAT_COMPAT` to 0 as the compatibility layer should
2114 be disabled. For more details on compatibility layer, refer
2115 [Migration Guide].
2116
Soby Mathew27713fb2014-09-08 17:51:01 +01002117There are some build flags which can be defined by the platform to control
2118inclusion or exclusion of certain BL stages from the FIP image. These flags
2119need to be defined in the platform makefile which will get included by the
2120build system.
2121
Soby Mathew27713fb2014-09-08 17:51:01 +01002122* **NEED_BL33**
2123 By default, this flag is defined `yes` by the build system and `BL33`
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00002124 build option should be supplied as a build option. The platform has the
2125 option of excluding the BL33 image in the `fip` image by defining this flag
Antonio Nino Diaz68450a62016-04-06 17:31:57 +01002126 to `no`. If any of the options `EL3_PAYLOAD_BASE` or `PRELOADED_BL33_BASE`
2127 are used, this flag will be set to `no` automatically.
Soby Mathew27713fb2014-09-08 17:51:01 +01002128
21295. C Library
Harry Liebela960f282013-12-12 16:03:44 +00002130-------------
2131
2132To avoid subtle toolchain behavioral dependencies, the header files provided
2133by the compiler are not used. The software is built with the `-nostdinc` flag
2134to ensure no headers are included from the toolchain inadvertently. Instead the
2135required headers are included in the ARM Trusted Firmware source tree. The
2136library only contains those C library definitions required by the local
2137implementation. If more functionality is required, the needed library functions
2138will need to be added to the local implementation.
2139
Dan Handleyf0b489c2016-06-02 17:15:13 +01002140Versions of [FreeBSD] headers can be found in `include/lib/stdlib`. Some of
2141these headers have been cut down in order to simplify the implementation. In
2142order to minimize changes to the header files, the [FreeBSD] layout has been
2143maintained. The generic C library definitions can be found in
2144`include/lib/stdlib` with more system and machine specific declarations in
2145`include/lib/stdlib/sys` and `include/lib/stdlib/machine`.
Harry Liebela960f282013-12-12 16:03:44 +00002146
2147The local C library implementations can be found in `lib/stdlib`. In order to
2148extend the C library these files may need to be modified. It is recommended to
2149use a release version of [FreeBSD] as a starting point.
2150
2151The C library header files in the [FreeBSD] source tree are located in the
2152`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
2153can be found in the `sys/<machine-type>` directories. These files define things
2154like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
2155port for [FreeBSD] does not yet exist, the machine specific definitions are
2156based on existing machine types with similar properties (for example SPARC64).
2157
2158Where possible, C library function implementations were taken from [FreeBSD]
2159as found in the `lib/libc` directory.
2160
2161A copy of the [FreeBSD] sources can be downloaded with `git`.
2162
2163 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
2164
2165
Soby Mathew27713fb2014-09-08 17:51:01 +010021666. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00002167-----------------------------
2168
2169In order to improve platform independence and portability an storage abstraction
2170layer is used to load data from non-volatile platform storage.
2171
2172Each platform should register devices and their drivers via the Storage layer.
2173These drivers then need to be initialized by bootloader phases as
2174required in their respective `blx_platform_setup()` functions. Currently
2175storage access is only required by BL1 and BL2 phases. The `load_image()`
2176function uses the storage layer to access non-volatile platform storage.
2177
Dan Handley4a75b842015-03-19 19:24:43 +00002178It is mandatory to implement at least one storage driver. For the ARM
2179development platforms the Firmware Image Package (FIP) driver is provided as
2180the default means to load data from storage (see the "Firmware Image Package"
2181section in the [User Guide]). The storage layer is described in the header file
2182`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00002183is in `drivers/io/io_storage.c` and the driver files are located in
2184`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00002185
2186Each IO driver must provide `io_dev_*` structures, as described in
2187`drivers/io/io_driver.h`. These are returned via a mandatory registration
2188function that is called on platform initialization. The semi-hosting driver
2189implementation in `io_semihosting.c` can be used as an example.
2190
2191The Storage layer provides mechanisms to initialize storage devices before
2192IO operations are called. The basic operations supported by the layer
2193include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
2194Drivers do not have to implement all operations, but each platform must
2195provide at least one driver for a device capable of supporting generic
2196operations such as loading a bootloader image.
2197
2198The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01002199firmware. These images are specified by using their identifiers, as defined in
2200[include/plat/common/platform_def.h] (or a separate header file included from
2201there). The platform layer (`plat_get_image_source()`) then returns a reference
2202to a device and a driver-specific `spec` which will be understood by the driver
2203to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00002204
2205The layer is designed in such a way that is it possible to chain drivers with
2206other drivers. For example, file-system drivers may be implemented on top of
2207physical block devices, both represented by IO devices with corresponding
2208drivers. In such a case, the file-system "binding" with the block device may
2209be deferred until the file-system device is initialised.
2210
2211The abstraction currently depends on structures being statically allocated
2212by the drivers and callers, as the system does not yet provide a means of
2213dynamically allocating memory. This may also have the affect of limiting the
2214amount of open resources per driver.
2215
2216
Achin Gupta4f6ad662013-10-25 09:08:21 +01002217- - - - - - - - - - - - - - - - - - - - - - - - - -
2218
Sandrine Bailleuxeaefdec2016-01-26 15:00:40 +00002219_Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01002220
2221
Yuping Luo6b140412016-01-15 11:17:27 +08002222[ARM GIC Architecture Specification 2.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
2223[ARM GIC Architecture Specification 3.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0069b/index.html
Soby Mathew81123e82015-11-23 14:01:21 +00002224[IMF Design Guide]: interrupt-framework-design.md
2225[User Guide]: user-guide.md
2226[FreeBSD]: http://www.freebsd.org
2227[Firmware Design]: firmware-design.md
2228[Power Domain Topology Design]: psci-pd-tree.md
2229[PSCI]: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
2230[Migration Guide]: platform-migration-guide.md
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002231[Firmware Update]: firmware-update.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01002232
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00002233[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
2234[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00002235[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002236[include/common/bl_common.h]: ../include/common/bl_common.h
Dan Handley4a75b842015-03-19 19:24:43 +00002237[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
2238[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01002239[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00002240[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]