blob: 7c9f404b04383cb8cffa1c5755ff7217d09cc04c [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
79across platforms. A memory translation library (see `lib/aarch64/xlat_helpers.c`
80and `lib/aarch64/xlat_tables.c`) is provided to help in this setup. Note that
81although this library supports non-identity mappings, this is intended only for
82re-mapping peripheral physical addresses and allows platforms with high I/O
83addresses to reduce their virtual address space. All other addresses
84corresponding to code and data must currently use an identity mapping.
85
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
192 PSCI implementation to distuiguish between retention and power down local
193 power states within PSCI_CPU_SUSPEND call.
Soby Mathew8c32bc22015-02-12 14:45:02 +0000194
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100195* **#define : BL1_RO_BASE**
196
197 Defines the base address in secure ROM where BL1 originally lives. Must be
198 aligned on a page-size boundary.
199
200* **#define : BL1_RO_LIMIT**
201
202 Defines the maximum address in secure ROM that BL1's actual content (i.e.
203 excluding any data section allocated at runtime) can occupy.
204
205* **#define : BL1_RW_BASE**
206
207 Defines the base address in secure RAM where BL1's read-write data will live
208 at runtime. Must be aligned on a page-size boundary.
209
210* **#define : BL1_RW_LIMIT**
211
212 Defines the maximum address in secure RAM that BL1's read-write data can
213 occupy at runtime.
214
James Morrisseyba3155b2013-10-29 10:56:46 +0000215* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100216
217 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000218 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100219
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100220* **#define : BL2_LIMIT**
221
222 Defines the maximum address in secure RAM that the BL2 image can occupy.
223
James Morrisseyba3155b2013-10-29 10:56:46 +0000224* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100225
Juan Castillod1786372015-12-14 09:35:25 +0000226 Defines the base address in secure RAM where BL2 loads the BL31 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000227 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100228
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100229* **#define : BL31_LIMIT**
230
Juan Castillod1786372015-12-14 09:35:25 +0000231 Defines the maximum address in secure RAM that the BL31 image can occupy.
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100232
Juan Castillo16948ae2015-04-13 17:36:19 +0100233For every image, the platform must define individual identifiers that will be
234used by BL1 or BL2 to load the corresponding image into memory from non-volatile
235storage. For the sake of performance, integer numbers will be used as
236identifiers. The platform will use those identifiers to return the relevant
237information about the image to be loaded (file handler, load address,
238authentication information, etc.). The following image identifiers are
239mandatory:
240
241* **#define : BL2_IMAGE_ID**
242
243 BL2 image identifier, used by BL1 to load BL2.
244
245* **#define : BL31_IMAGE_ID**
246
Juan Castillod1786372015-12-14 09:35:25 +0000247 BL31 image identifier, used by BL2 to load BL31.
Juan Castillo16948ae2015-04-13 17:36:19 +0100248
249* **#define : BL33_IMAGE_ID**
250
Juan Castillod1786372015-12-14 09:35:25 +0000251 BL33 image identifier, used by BL2 to load BL33.
Juan Castillo16948ae2015-04-13 17:36:19 +0100252
253If Trusted Board Boot is enabled, the following certificate identifiers must
254also be defined:
255
Juan Castillo516beb52015-12-03 10:19:21 +0000256* **#define : TRUSTED_BOOT_FW_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100257
258 BL2 content certificate identifier, used by BL1 to load the BL2 content
259 certificate.
260
261* **#define : TRUSTED_KEY_CERT_ID**
262
263 Trusted key certificate identifier, used by BL2 to load the trusted key
264 certificate.
265
Juan Castillo516beb52015-12-03 10:19:21 +0000266* **#define : SOC_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100267
Juan Castillod1786372015-12-14 09:35:25 +0000268 BL31 key certificate identifier, used by BL2 to load the BL31 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100269 certificate.
270
Juan Castillo516beb52015-12-03 10:19:21 +0000271* **#define : SOC_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100272
Juan Castillod1786372015-12-14 09:35:25 +0000273 BL31 content certificate identifier, used by BL2 to load the BL31 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100274 certificate.
275
Juan Castillo516beb52015-12-03 10:19:21 +0000276* **#define : NON_TRUSTED_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100277
Juan Castillod1786372015-12-14 09:35:25 +0000278 BL33 key certificate identifier, used by BL2 to load the BL33 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100279 certificate.
280
Juan Castillo516beb52015-12-03 10:19:21 +0000281* **#define : NON_TRUSTED_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100282
Juan Castillod1786372015-12-14 09:35:25 +0000283 BL33 content certificate identifier, used by BL2 to load the BL33 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100284 certificate.
285
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000286* **#define : FWU_CERT_ID**
287
288 Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the
289 FWU content certificate.
290
291
292If the AP Firmware Updater Configuration image, BL2U is used, the following
293must also be defined:
294
295* **#define : BL2U_BASE**
296
297 Defines the base address in secure memory where BL1 copies the BL2U binary
298 image. Must be aligned on a page-size boundary.
299
300* **#define : BL2U_LIMIT**
301
302 Defines the maximum address in secure memory that the BL2U image can occupy.
303
304* **#define : BL2U_IMAGE_ID**
305
306 BL2U image identifier, used by BL1 to fetch an image descriptor
307 corresponding to BL2U.
308
309If the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following
310must also be defined:
311
312* **#define : SCP_BL2U_IMAGE_ID**
313
314 SCP_BL2U image identifier, used by BL1 to fetch an image descriptor
315 corresponding to SCP_BL2U.
316 NOTE: TF does not provide source code for this image.
317
318If the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must
319also be defined:
320
321* **#define : NS_BL1U_BASE**
322
323 Defines the base address in non-secure ROM where NS_BL1U executes.
324 Must be aligned on a page-size boundary.
325 NOTE: TF does not provide source code for this image.
326
327* **#define : NS_BL1U_IMAGE_ID**
328
329 NS_BL1U image identifier, used by BL1 to fetch an image descriptor
330 corresponding to NS_BL1U.
331
332If the Non-Secure Firmware Updater, NS_BL2U is used, the following must also
333be defined:
334
335* **#define : NS_BL2U_BASE**
336
337 Defines the base address in non-secure memory where NS_BL2U executes.
338 Must be aligned on a page-size boundary.
339 NOTE: TF does not provide source code for this image.
340
341* **#define : NS_BL2U_IMAGE_ID**
342
343 NS_BL2U image identifier, used by BL1 to fetch an image descriptor
344 corresponding to NS_BL2U.
345
346
Juan Castillof59821d2015-12-10 15:49:17 +0000347If a SCP_BL2 image is supported by the platform, the following constants must
Achin Gupta8d35f612015-01-25 22:44:23 +0000348also be defined:
349
Juan Castillof59821d2015-12-10 15:49:17 +0000350* **#define : SCP_BL2_IMAGE_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000351
Juan Castillof59821d2015-12-10 15:49:17 +0000352 SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory
353 from platform storage before being transfered to the SCP.
Achin Gupta8d35f612015-01-25 22:44:23 +0000354
Juan Castillo516beb52015-12-03 10:19:21 +0000355* **#define : SCP_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000356
Juan Castillof59821d2015-12-10 15:49:17 +0000357 SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100358 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000359
Juan Castillo516beb52015-12-03 10:19:21 +0000360* **#define : SCP_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000361
Juan Castillof59821d2015-12-10 15:49:17 +0000362 SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2
363 content certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000364
Juan Castillod1786372015-12-14 09:35:25 +0000365If a BL32 image is supported by the platform, the following constants must
Dan Handley5a06bb72014-08-04 11:41:20 +0100366also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100367
Juan Castillo16948ae2015-04-13 17:36:19 +0100368* **#define : BL32_IMAGE_ID**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100369
Juan Castillod1786372015-12-14 09:35:25 +0000370 BL32 image identifier, used by BL2 to load BL32.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100371
Juan Castillo516beb52015-12-03 10:19:21 +0000372* **#define : TRUSTED_OS_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000373
Juan Castillod1786372015-12-14 09:35:25 +0000374 BL32 key certificate identifier, used by BL2 to load the BL32 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100375 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000376
Juan Castillo516beb52015-12-03 10:19:21 +0000377* **#define : TRUSTED_OS_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000378
Juan Castillod1786372015-12-14 09:35:25 +0000379 BL32 content certificate identifier, used by BL2 to load the BL32 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100380 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000381
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100382* **#define : BL32_BASE**
383
Juan Castillod1786372015-12-14 09:35:25 +0000384 Defines the base address in secure memory where BL2 loads the BL32 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100385 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100386
387* **#define : BL32_LIMIT**
388
Juan Castillod1786372015-12-14 09:35:25 +0000389 Defines the maximum address that the BL32 image can occupy.
Dan Handley5a06bb72014-08-04 11:41:20 +0100390
Juan Castillod1786372015-12-14 09:35:25 +0000391If the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the
Dan Handley5a06bb72014-08-04 11:41:20 +0100392platform, the following constants must also be defined:
393
394* **#define : TSP_SEC_MEM_BASE**
395
396 Defines the base address of the secure memory used by the TSP image on the
397 platform. This must be at the same address or below `BL32_BASE`.
398
399* **#define : TSP_SEC_MEM_SIZE**
400
Juan Castillod1786372015-12-14 09:35:25 +0000401 Defines the size of the secure memory used by the BL32 image on the
Dan Handley5a06bb72014-08-04 11:41:20 +0100402 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
Juan Castillod1786372015-12-14 09:35:25 +0000403 the memory required by the BL32 image, defined by `BL32_BASE` and
Dan Handley5a06bb72014-08-04 11:41:20 +0100404 `BL32_LIMIT`.
405
406* **#define : TSP_IRQ_SEC_PHY_TIMER**
407
408 Defines the ID of the secure physical generic timer interrupt used by the
409 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100410
Dan Handley4a75b842015-03-19 19:24:43 +0000411If the platform port uses the translation table library code, the following
412constant must also be defined:
413
414* **#define : MAX_XLAT_TABLES**
415
416 Defines the maximum number of translation tables that are allocated by the
417 translation table library code. To minimize the amount of runtime memory
418 used, choose the smallest value needed to map the required virtual addresses
419 for each BL stage.
420
Juan Castillo359b60d2016-01-07 11:29:15 +0000421* **#define : MAX_MMAP_REGIONS**
422
423 Defines the maximum number of regions that are allocated by the translation
424 table library code. A region consists of physical base address, virtual base
425 address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as
426 defined in the `mmap_region_t` structure. The platform defines the regions
427 that should be mapped. Then, the translation table library will create the
428 corresponding tables and descriptors at runtime. To minimize the amount of
429 runtime memory used, choose the smallest value needed to register the
430 required regions for each BL stage.
431
432* **#define : ADDR_SPACE_SIZE**
433
434 Defines the total size of the address space in bytes. For example, for a 32
435 bit address space, this value should be `(1ull << 32)`.
436
Dan Handley6d16ce02014-08-04 18:31:43 +0100437If the platform port uses the IO storage framework, the following constants
438must also be defined:
439
440* **#define : MAX_IO_DEVICES**
441
442 Defines the maximum number of registered IO devices. Attempting to register
443 more devices than this value using `io_register_device()` will fail with
Juan Castillo7e26fe12015-10-01 17:55:11 +0100444 -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100445
446* **#define : MAX_IO_HANDLES**
447
448 Defines the maximum number of open IO handles. Attempting to open more IO
Juan Castillo7e26fe12015-10-01 17:55:11 +0100449 entities than this value using `io_open()` will fail with -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100450
Soby Mathewab8707e2015-01-08 18:02:44 +0000451If the platform needs to allocate data within the per-cpu data framework in
Juan Castillod1786372015-12-14 09:35:25 +0000452BL31, it should define the following macro. Currently this is only required if
Soby Mathewab8707e2015-01-08 18:02:44 +0000453the platform decides not to use the coherent memory section by undefining the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000454`USE_COHERENT_MEM` build flag. In this case, the framework allocates the
455required memory within the the per-cpu data to minimize wastage.
Soby Mathewab8707e2015-01-08 18:02:44 +0000456
457* **#define : PLAT_PCPU_DATA_SIZE**
458
459 Defines the memory (in bytes) to be reserved within the per-cpu data
460 structure for use by the platform layer.
461
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100462The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000463memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100464
465* **#define : BL31_PROGBITS_LIMIT**
466
Juan Castillod1786372015-12-14 09:35:25 +0000467 Defines the maximum address in secure RAM that the BL31's progbits sections
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100468 can occupy.
469
Dan Handley5a06bb72014-08-04 11:41:20 +0100470* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100471
472 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100473
Dan Handleyb68954c2014-05-29 12:30:24 +0100474### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100475
Dan Handleyb68954c2014-05-29 12:30:24 +0100476Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000477the following macro defined. In the ARM development platforms, this file is
478found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100479
480* **Macro : plat_print_gic_regs**
481
482 This macro allows the crash reporting routine to print GIC registers
Juan Castillod1786372015-12-14 09:35:25 +0000483 in case of an unhandled exception in BL31. This aids in debugging and
Soby Mathewa43d4312014-04-07 15:28:55 +0100484 this macro can be defined to be empty in case GIC register reporting is
485 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100486
Soby Mathew8c106902014-07-16 09:23:52 +0100487* **Macro : plat_print_interconnect_regs**
488
Dan Handley4a75b842015-03-19 19:24:43 +0000489 This macro allows the crash reporting routine to print interconnect
Juan Castillod1786372015-12-14 09:35:25 +0000490 registers in case of an unhandled exception in BL31. This aids in debugging
Dan Handley4a75b842015-03-19 19:24:43 +0000491 and this macro can be defined to be empty in case interconnect register
492 reporting is not desired. In ARM standard platforms, the CCI snoop
493 control registers are reported.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100494
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000495
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004962.2 Handling Reset
497------------------
498
499BL1 by default implements the reset vector where execution starts from a cold
Juan Castillod1786372015-12-14 09:35:25 +0000500or warm boot. BL31 can be optionally set as a reset vector using the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000501`RESET_TO_BL31` make variable.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100502
503For each CPU, the reset vector code is responsible for the following tasks:
504
5051. Distinguishing between a cold boot and a warm boot.
506
5072. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
508 the CPU is placed in a platform-specific state until the primary CPU
509 performs the necessary steps to remove it from this state.
510
5113. In the case of a warm boot, ensuring that the CPU jumps to a platform-
Juan Castillod1786372015-12-14 09:35:25 +0000512 specific address in the BL31 image in the same processor mode as it was
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100513 when released from reset.
514
515The following functions need to be implemented by the platform port to enable
516reset vector code to perform the above tasks.
517
518
Soby Mathew58523c02015-06-08 12:32:50 +0100519### Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100520
Soby Mathew58523c02015-06-08 12:32:50 +0100521 Argument : void
522 Return : unsigned long
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100523
Soby Mathew58523c02015-06-08 12:32:50 +0100524This function is called with the called with the MMU and caches disabled
525(`SCTLR_EL3.M` = 0 and `SCTLR_EL3.C` = 0). The function is responsible for
526distinguishing between a warm and cold reset for the current CPU using
527platform-specific means. If it's a warm reset, then it returns the warm
528reset entrypoint point provided to `plat_setup_psci_ops()` during
Juan Castillod1786372015-12-14 09:35:25 +0000529BL31 initialization. If it's a cold reset then this function must return zero.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100530
531This function does not follow the Procedure Call Standard used by the
532Application Binary Interface for the ARM 64-bit architecture. The caller should
533not assume that callee saved registers are preserved across a call to this
534function.
535
536This function fulfills requirement 1 and 3 listed above.
537
Soby Mathew58523c02015-06-08 12:32:50 +0100538Note that for platforms that support programming the reset address, it is
539expected that a CPU will start executing code directly at the right address,
540both on a cold and warm reset. In this case, there is no need to identify the
541type of reset nor to query the warm reset entrypoint. Therefore, implementing
542this function is not required on such platforms.
543
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100544
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000545### Function : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100546
547 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100548
549This function is called with the MMU and data caches disabled. It is responsible
550for placing the executing secondary CPU in a platform-specific state until the
551primary CPU performs the necessary actions to bring it out of that state and
Sandrine Bailleux52010cc2015-05-19 11:54:45 +0100552allow entry into the OS. This function must not return.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100553
Sandrine Bailleuxcdf14082015-10-02 14:35:25 +0100554In the ARM FVP port, when using the normal boot flow, each secondary CPU powers
555itself off. The primary CPU is responsible for powering up the secondary CPUs
556when normal world software requires them. When booting an EL3 payload instead,
557they stay powered on and are put in a holding pen until their mailbox gets
558populated.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100559
560This function fulfills requirement 2 above.
561
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000562Note that for platforms that can't release secondary CPUs out of reset, only the
563primary CPU will execute the cold boot code. Therefore, implementing this
564function is not required on such platforms.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100565
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000566
567### Function : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Juan Castillo53fdceb2014-07-16 15:53:43 +0100568
Soby Mathew58523c02015-06-08 12:32:50 +0100569 Argument : void
Juan Castillo53fdceb2014-07-16 15:53:43 +0100570 Return : unsigned int
571
Soby Mathew58523c02015-06-08 12:32:50 +0100572This function identifies whether the current CPU is the primary CPU or a
573secondary CPU. A return value of zero indicates that the CPU is not the
574primary CPU, while a non-zero return value indicates that the CPU is the
575primary CPU.
Juan Castillo53fdceb2014-07-16 15:53:43 +0100576
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000577Note that for platforms that can't release secondary CPUs out of reset, only the
578primary CPU will execute the cold boot code. Therefore, there is no need to
579distinguish between primary and secondary CPUs and implementing this function is
580not required.
581
Juan Castillo53fdceb2014-07-16 15:53:43 +0100582
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100583### Function : platform_mem_init() [mandatory]
584
585 Argument : void
586 Return : void
587
588This function is called before any access to data is made by the firmware, in
589order to carry out any essential memory initialization.
590
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100591
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100592### Function: plat_get_rotpk_info()
593
594 Argument : void *, void **, unsigned int *, unsigned int *
595 Return : int
596
597This function is mandatory when Trusted Board Boot is enabled. It returns a
598pointer to the ROTPK stored in the platform (or a hash of it) and its length.
599The ROTPK must be encoded in DER format according to the following ASN.1
600structure:
601
602 AlgorithmIdentifier ::= SEQUENCE {
603 algorithm OBJECT IDENTIFIER,
604 parameters ANY DEFINED BY algorithm OPTIONAL
605 }
606
607 SubjectPublicKeyInfo ::= SEQUENCE {
608 algorithm AlgorithmIdentifier,
609 subjectPublicKey BIT STRING
610 }
611
612In case the function returns a hash of the key:
613
614 DigestInfo ::= SEQUENCE {
615 digestAlgorithm AlgorithmIdentifier,
616 digest OCTET STRING
617 }
618
619The function returns 0 on success. Any other value means the ROTPK could not be
620retrieved from the platform. The function also reports extra information related
621to the ROTPK in the flags parameter.
622
623
Soby Mathew58523c02015-06-08 12:32:50 +01006242.3 Common mandatory modifications
625---------------------------------
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100626
Soby Mathew58523c02015-06-08 12:32:50 +0100627The following functions are mandatory functions which need to be implemented
628by the platform port.
629
630### Function : plat_my_core_pos()
631
632 Argument : void
633 Return : unsigned int
634
635This funtion returns the index of the calling CPU which is used as a
636CPU-specific linear index into blocks of memory (for example while allocating
637per-CPU stacks). This function will be invoked very early in the
638initialization sequence which mandates that this function should be
639implemented in assembly and should not rely on the avalability of a C
640runtime environment.
641
642This function plays a crucial role in the power domain topology framework in
643PSCI and details of this can be found in [Power Domain Topology Design].
644
645### Function : plat_core_pos_by_mpidr()
646
647 Argument : u_register_t
648 Return : int
649
650This function validates the `MPIDR` of a CPU and converts it to an index,
651which can be used as a CPU-specific linear index into blocks of memory. In
652case the `MPIDR` is invalid, this function returns -1. This function will only
Juan Castillod1786372015-12-14 09:35:25 +0000653be invoked by BL31 after the power domain topology is initialized and can
Soby Mathew58523c02015-06-08 12:32:50 +0100654utilize the C runtime environment. For further details about how ARM Trusted
655Firmware represents the power domain topology and how this relates to the
656linear CPU index, please refer [Power Domain Topology Design].
657
658
659
6602.4 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100661---------------------------------
662
663The following are helper functions implemented by the firmware that perform
664common platform-specific tasks. A platform may choose to override these
665definitions.
666
Soby Mathew58523c02015-06-08 12:32:50 +0100667### Function : plat_set_my_stack()
Achin Gupta4f6ad662013-10-25 09:08:21 +0100668
Soby Mathew58523c02015-06-08 12:32:50 +0100669 Argument : void
Achin Gupta4f6ad662013-10-25 09:08:21 +0100670 Return : void
671
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000672This function sets the current stack pointer to the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100673has been allocated for the current CPU. For BL images that only require a
674stack for the primary CPU, the UP version of the function is used. The size
675of the stack allocated to each CPU is specified by the platform defined
676constant `PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100677
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000678Common implementations of this function for the UP and MP BL images are
679provided in [plat/common/aarch64/platform_up_stack.S] and
680[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100681
682
Soby Mathew58523c02015-06-08 12:32:50 +0100683### Function : plat_get_my_stack()
Achin Guptac8afc782013-11-25 18:45:02 +0000684
Soby Mathew58523c02015-06-08 12:32:50 +0100685 Argument : void
Achin Guptac8afc782013-11-25 18:45:02 +0000686 Return : unsigned long
687
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000688This function returns the base address of the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100689has been allocated for the current CPU. For BL images that only require a
690stack for the primary CPU, the UP version of the function is used. The size
691of the stack allocated to each CPU is specified by the platform defined
692constant `PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000693
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000694Common implementations of this function for the UP and MP BL images are
695provided in [plat/common/aarch64/platform_up_stack.S] and
696[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000697
698
Achin Gupta4f6ad662013-10-25 09:08:21 +0100699### Function : plat_report_exception()
700
701 Argument : unsigned int
702 Return : void
703
704A platform may need to report various information about its status when an
705exception is taken, for example the current exception level, the CPU security
706state (secure/non-secure), the exception type, and so on. This function is
707called in the following circumstances:
708
709* In BL1, whenever an exception is taken.
710* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100711
712The default implementation doesn't do anything, to avoid making assumptions
713about the way the platform displays its status information.
714
715This function receives the exception type as its argument. Possible values for
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000716exceptions types are listed in the [include/common/bl_common.h] header file.
717Note that these constants are not related to any architectural exception code;
718they are just an ARM Trusted Firmware convention.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100719
720
Soby Mathew24fb8382014-08-14 12:22:32 +0100721### Function : plat_reset_handler()
722
723 Argument : void
724 Return : void
725
726A platform may need to do additional initialization after reset. This function
727allows the platform to do the platform specific intializations. Platform
728specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000729preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100730
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000731The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000732the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100733guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100734
Soby Mathewadd40352014-08-14 12:49:05 +0100735### Function : plat_disable_acp()
736
737 Argument : void
738 Return : void
739
740This api allows a platform to disable the Accelerator Coherency Port (if
741present) during a cluster power down sequence. The default weak implementation
742doesn't do anything. Since this api is called during the power down sequence,
743it has restrictions for stack usage and it can use the registers x0 - x17 as
744scratch registers. It should preserve the value in x18 register as it is used
745by the caller to store the return address.
746
Juan Castillo40fc6cd2015-09-25 15:41:14 +0100747### Function : plat_error_handler()
748
749 Argument : int
750 Return : void
751
752This API is called when the generic code encounters an error situation from
753which it cannot continue. It allows the platform to perform error reporting or
754recovery actions (for example, reset the system). This function must not return.
755
756The parameter indicates the type of error using standard codes from `errno.h`.
757Possible errors reported by the generic code are:
758
759* `-EAUTH`: a certificate or image could not be authenticated (when Trusted
760 Board Boot is enabled)
761* `-ENOENT`: the requested image or certificate could not be found or an IO
762 error was detected
763* `-ENOMEM`: resources exhausted. Trusted Firmware does not use dynamic
764 memory, so this error is usually an indication of an incorrect array size
765
766The default implementation simply spins.
767
Soby Mathew24fb8382014-08-14 12:22:32 +0100768
Achin Gupta4f6ad662013-10-25 09:08:21 +01007693. Modifications specific to a Boot Loader stage
770-------------------------------------------------
771
7723.1 Boot Loader Stage 1 (BL1)
773-----------------------------
774
775BL1 implements the reset vector where execution starts from after a cold or
776warm boot. For each CPU, BL1 is responsible for the following tasks:
777
Vikram Kanigirie452cd82014-05-23 15:56:12 +01007781. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100779
7802. In the case of a cold boot and the CPU being the primary CPU, ensuring that
781 only this CPU executes the remaining BL1 code, including loading and passing
782 control to the BL2 stage.
783
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00007843. Identifying and starting the Firmware Update process (if required).
785
7864. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100787 address specified by the platform defined constant `BL2_BASE`.
788
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00007895. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100790 accessible by BL2 immediately upon entry.
791
792 meminfo.total_base = Base address of secure RAM visible to BL2
793 meminfo.total_size = Size of secure RAM visible to BL2
794 meminfo.free_base = Base address of secure RAM available for
795 allocation to BL2
796 meminfo.free_size = Size of secure RAM available for allocation to BL2
797
798 BL1 places this `meminfo` structure at the beginning of the free memory
799 available for its use. Since BL1 cannot allocate memory dynamically at the
800 moment, its free memory will be available for BL2's use as-is. However, this
801 means that BL2 must read the `meminfo` structure before it starts using its
802 free memory (this is discussed in Section 3.2).
803
804 In future releases of the ARM Trusted Firmware it will be possible for
805 the platform to decide where it wants to place the `meminfo` structure for
806 BL2.
807
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100808 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100809 BL2 `meminfo` structure. The platform may override this implementation, for
810 example if the platform wants to restrict the amount of memory visible to
811 BL2. Details of how to do this are given below.
812
813The following functions need to be implemented by the platform port to enable
814BL1 to perform the above tasks.
815
816
Dan Handley4a75b842015-03-19 19:24:43 +0000817### Function : bl1_early_platform_setup() [mandatory]
818
819 Argument : void
820 Return : void
821
822This function executes with the MMU and data caches disabled. It is only called
823by the primary CPU.
824
825In ARM standard platforms, this function initializes the console and enables
826snoop requests into the primary CPU's cluster.
827
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100828### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100829
830 Argument : void
831 Return : void
832
Achin Gupta4f6ad662013-10-25 09:08:21 +0100833This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000834platform requires. Platform-specific setup might include configuration of
835memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100836
Dan Handley4a75b842015-03-19 19:24:43 +0000837In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100838
839This function helps fulfill requirement 2 above.
840
841
842### Function : bl1_platform_setup() [mandatory]
843
844 Argument : void
845 Return : void
846
847This function executes with the MMU and data caches enabled. It is responsible
848for performing any remaining platform-specific setup that can occur after the
849MMU and data cache have been enabled.
850
Dan Handley4a75b842015-03-19 19:24:43 +0000851In ARM standard platforms, this function initializes the storage abstraction
852layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000853
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000854This function helps fulfill requirement 4 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100855
856
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000857### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100858
859 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000860 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100861
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000862This function should only be called on the cold boot path. It executes with the
863MMU and data caches enabled. The pointer returned by this function must point to
864a `meminfo` structure containing the extents and availability of secure RAM for
865the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100866
867 meminfo.total_base = Base address of secure RAM visible to BL1
868 meminfo.total_size = Size of secure RAM visible to BL1
869 meminfo.free_base = Base address of secure RAM available for allocation
870 to BL1
871 meminfo.free_size = Size of secure RAM available for allocation to BL1
872
873This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
874populates a similar structure to tell BL2 the extents of memory available for
875its own use.
876
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000877This function helps fulfill requirements 4 and 5 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100878
879
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100880### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100881
882 Argument : meminfo *, meminfo *, unsigned int, unsigned long
883 Return : void
884
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100885BL1 needs to tell the next stage the amount of secure RAM available
886for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100887structure.
888
889Depending upon where BL2 has been loaded in secure RAM (determined by
890`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
891BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000892to BL2. An illustration of how this is done in ARM standard platforms is given
893in the **Memory layout on ARM development platforms** section in the
894[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100895
896
Juan Castilloe3f67122015-10-05 16:59:38 +0100897### Function : bl1_plat_prepare_exit() [optional]
898
Sandrine Bailleux862b5dc2015-11-10 15:01:57 +0000899 Argument : entry_point_info_t *
Juan Castilloe3f67122015-10-05 16:59:38 +0100900 Return : void
901
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000902This function is called prior to exiting BL1 in response to the
903`BL1_SMC_RUN_IMAGE` SMC request raised by BL2. It should be used to perform
904platform specific clean up or bookkeeping operations before transferring
905control to the next image. It receives the address of the `entry_point_info_t`
906structure passed from BL2. This function runs with MMU disabled.
907
908### Function : bl1_plat_set_ep_info() [optional]
909
910 Argument : unsigned int image_id, entry_point_info_t *ep_info
911 Return : void
912
913This function allows platforms to override `ep_info` for the given `image_id`.
914
915The default implementation just returns.
916
917### Function : bl1_plat_get_next_image_id() [optional]
918
919 Argument : void
920 Return : unsigned int
921
922This and the following function must be overridden to enable the FWU feature.
923
924BL1 calls this function after platform setup to identify the next image to be
925loaded and executed. If the platform returns `BL2_IMAGE_ID` then BL1 proceeds
926with the normal boot sequence, which loads and executes BL2. If the platform
927returns a different image id, BL1 assumes that Firmware Update is required.
928
929The default implementation always returns `BL2_IMAGE_ID`. The ARM development
930platforms override this function to detect if firmware update is required, and
931if so, return the first image in the firmware update process.
932
933### Function : bl1_plat_get_image_desc() [optional]
934
935 Argument : unsigned int image_id
936 Return : image_desc_t *
937
938BL1 calls this function to get the image descriptor information `image_desc_t`
939for the provided `image_id` from the platform.
940
941The default implementation always returns a common BL2 image descriptor. ARM
942standard platforms return an image descriptor corresponding to BL2 or one of
943the firmware update images defined in the Trusted Board Boot Requirements
944specification.
945
946### Function : bl1_plat_fwu_done() [optional]
947
948 Argument : unsigned int image_id, uintptr_t image_src,
949 unsigned int image_size
950 Return : void
951
952BL1 calls this function when the FWU process is complete. It must not return.
953The platform may override this function to take platform specific action, for
954example to initiate the normal boot flow.
955
956The default implementation spins forever.
957
958### Function : bl1_plat_mem_check() [mandatory]
959
960 Argument : uintptr_t mem_base, unsigned int mem_size,
961 unsigned int flags
962 Return : void
963
964BL1 calls this function while handling FWU copy and authenticate SMCs. The
965platform must ensure that the provided `mem_base` and `mem_size` are mapped into
966BL1, and that this memory corresponds to either a secure or non-secure memory
967region as indicated by the security state of the `flags` argument.
968
969The default implementation of this function asserts therefore platforms must
970override it when using the FWU feature.
Juan Castilloe3f67122015-10-05 16:59:38 +0100971
972
Achin Gupta4f6ad662013-10-25 09:08:21 +01009733.2 Boot Loader Stage 2 (BL2)
974-----------------------------
975
976The BL2 stage is executed only by the primary CPU, which is determined in BL1
977using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
978`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
979
Juan Castillof59821d2015-12-10 15:49:17 +00009801. (Optional) Loading the SCP_BL2 binary image (if present) from platform
981 provided non-volatile storage. To load the SCP_BL2 image, BL2 makes use of
982 the `meminfo` returned by the `bl2_plat_get_scp_bl2_meminfo()` function.
983 The platform also defines the address in memory where SCP_BL2 is loaded
984 through the optional constant `SCP_BL2_BASE`. BL2 uses this information
985 to determine if there is enough memory to load the SCP_BL2 image.
986 Subsequent handling of the SCP_BL2 image is platform-specific and is
987 implemented in the `bl2_plat_handle_scp_bl2()` function.
988 If `SCP_BL2_BASE` is not defined then this step is not performed.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100989
Juan Castillod1786372015-12-14 09:35:25 +00009902. Loading the BL31 binary image into secure RAM from non-volatile storage. To
991 load the BL31 image, BL2 makes use of the `meminfo` structure passed to it
Harry Liebeld265bd72014-01-31 19:04:10 +0000992 by BL1. This structure allows BL2 to calculate how much secure RAM is
993 available for its use. The platform also defines the address in secure RAM
Juan Castillod1786372015-12-14 09:35:25 +0000994 where BL31 is loaded through the constant `BL31_BASE`. BL2 uses this
995 information to determine if there is enough memory to load the BL31 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100996
Juan Castillod1786372015-12-14 09:35:25 +00009973. (Optional) Loading the BL32 binary image (if present) from platform
998 provided non-volatile storage. To load the BL32 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100999 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
Juan Castillod1786372015-12-14 09:35:25 +00001000 The platform also defines the address in memory where BL32 is loaded
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001001 through the optional constant `BL32_BASE`. BL2 uses this information
Juan Castillod1786372015-12-14 09:35:25 +00001002 to determine if there is enough memory to load the BL32 image.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001003 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001004
Juan Castillod1786372015-12-14 09:35:25 +000010054. (Optional) Arranging to pass control to the BL32 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001006 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +01001007 structure in memory provided by the platform with information about how
Juan Castillod1786372015-12-14 09:35:25 +00001008 BL31 should pass control to the BL32 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001009
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +000010105. (Optional) Loading the normal world BL33 binary image (if not loaded by
1011 other means) into non-secure DRAM from platform storage and arranging for
1012 BL31 to pass control to this image. This address is determined using the
1013 `plat_get_ns_image_entrypoint()` function described below.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001014
10156. BL2 populates an `entry_point_info` structure in memory provided by the
Juan Castillod1786372015-12-14 09:35:25 +00001016 platform with information about how BL31 should pass control to the
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001017 other BL images.
1018
Achin Gupta4f6ad662013-10-25 09:08:21 +01001019The following functions must be implemented by the platform port to enable BL2
1020to perform the above tasks.
1021
1022
1023### Function : bl2_early_platform_setup() [mandatory]
1024
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001025 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001026 Return : void
1027
1028This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001029by the primary CPU. The arguments to this function is the address of the
1030`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001031
1032The platform must copy the contents of the `meminfo` structure into a private
1033variable as the original memory may be subsequently overwritten by BL2. The
1034copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +00001035`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001036
Dan Handley4a75b842015-03-19 19:24:43 +00001037In ARM standard platforms, this function also initializes the storage
1038abstraction layer used to load further bootloader images. It is necessary to do
Juan Castillof59821d2015-12-10 15:49:17 +00001039this early on platforms with a SCP_BL2 image, since the later
1040`bl2_platform_setup` must be done after SCP_BL2 is loaded.
Dan Handley4a75b842015-03-19 19:24:43 +00001041
Achin Gupta4f6ad662013-10-25 09:08:21 +01001042
1043### Function : bl2_plat_arch_setup() [mandatory]
1044
1045 Argument : void
1046 Return : void
1047
1048This function executes with the MMU and data caches disabled. It is only called
1049by the primary CPU.
1050
1051The purpose of this function is to perform any architectural initialization
1052that varies across platforms, for example enabling the MMU (since the memory
1053map differs across platforms).
1054
1055
1056### Function : bl2_platform_setup() [mandatory]
1057
1058 Argument : void
1059 Return : void
1060
1061This function may execute with the MMU and data caches enabled if the platform
1062port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
1063called by the primary CPU.
1064
Achin Guptae4d084e2014-02-19 17:18:23 +00001065The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +00001066specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +01001067
Dan Handley4a75b842015-03-19 19:24:43 +00001068In ARM standard platforms, this function performs security setup, including
1069configuration of the TrustZone controller to allow non-secure masters access
1070to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +00001071
Achin Gupta4f6ad662013-10-25 09:08:21 +01001072
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001073### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001074
1075 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001076 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001077
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001078This function should only be called on the cold boot path. It may execute with
1079the MMU and data caches enabled if the platform port does the necessary
1080initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001081
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001082The purpose of this function is to return a pointer to a `meminfo` structure
1083populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +01001084`bl2_early_platform_setup()` above.
1085
1086
Juan Castillof59821d2015-12-10 15:49:17 +00001087### Function : bl2_plat_get_scp_bl2_meminfo() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001088
1089 Argument : meminfo *
1090 Return : void
1091
1092This function is used to get the memory limits where BL2 can load the
Juan Castillof59821d2015-12-10 15:49:17 +00001093SCP_BL2 image. The meminfo provided by this is used by load_image() to
1094validate whether the SCP_BL2 image can be loaded within the given
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001095memory from the given base.
1096
1097
Juan Castillof59821d2015-12-10 15:49:17 +00001098### Function : bl2_plat_handle_scp_bl2() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001099
1100 Argument : image_info *
1101 Return : int
1102
Juan Castillof59821d2015-12-10 15:49:17 +00001103This function is called after loading SCP_BL2 image and it is used to perform
1104any platform-specific actions required to handle the SCP firmware. Typically it
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001105transfers the image into SCP memory using a platform-specific protocol and waits
1106until SCP executes it and signals to the Application Processor (AP) for BL2
1107execution to continue.
1108
1109This function returns 0 on success, a negative error code otherwise.
1110
1111
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001112### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +00001113
1114 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001115 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +00001116
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001117BL2 platform code needs to return a pointer to a `bl31_params` structure it
Juan Castillod1786372015-12-14 09:35:25 +00001118will use for passing information to BL31. The `bl31_params` structure carries
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001119the following information.
1120 - Header describing the version information for interpreting the bl31_param
1121 structure
Juan Castillod1786372015-12-14 09:35:25 +00001122 - Information about executing the BL33 image in the `bl33_ep_info` field
1123 - Information about executing the BL32 image in the `bl32_ep_info` field
1124 - Information about the type and extents of BL31 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001125 `bl31_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001126 - Information about the type and extents of BL32 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001127 `bl32_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001128 - Information about the type and extents of BL33 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001129 `bl33_image_info` field
1130
1131The memory pointed by this structure and its sub-structures should be
Juan Castillod1786372015-12-14 09:35:25 +00001132accessible from BL31 initialisation code. BL31 might choose to copy the
1133necessary content, or maintain the structures until BL33 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +00001134
1135
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001136### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001137
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001138 Argument : void
1139 Return : entry_point_info *
1140
1141BL2 platform code returns a pointer which is used to populate the entry point
Juan Castillod1786372015-12-14 09:35:25 +00001142information for BL31 entry point. The location pointed by it should be
1143accessible from BL1 while processing the synchronous exception to run to BL31.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001144
Dan Handley4a75b842015-03-19 19:24:43 +00001145In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
1146structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001147
1148
1149### Function : bl2_plat_set_bl31_ep_info() [mandatory]
1150
1151 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001152 Return : void
1153
Juan Castillod1786372015-12-14 09:35:25 +00001154In the normal boot flow, this function is called after loading BL31 image and
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001155it can be used to overwrite the entry point set by loader and also set the
Juan Castillod1786372015-12-14 09:35:25 +00001156security state and SPSR which represents the entry point system state for BL31.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001157
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001158When booting an EL3 payload instead, this function is called after populating
1159its entry point address and can be used for the same purpose for the payload
1160image. It receives a null pointer as its first argument in this case.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001161
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001162### Function : bl2_plat_set_bl32_ep_info() [mandatory]
1163
1164 Argument : image_info *, entry_point_info *
1165 Return : void
1166
Juan Castillod1786372015-12-14 09:35:25 +00001167This function is called after loading BL32 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001168overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001169and SPSR which represents the entry point system state for BL32.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001170
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001171
1172### Function : bl2_plat_set_bl33_ep_info() [mandatory]
1173
1174 Argument : image_info *, entry_point_info *
1175 Return : void
1176
Juan Castillod1786372015-12-14 09:35:25 +00001177This function is called after loading BL33 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001178overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001179and SPSR which represents the entry point system state for BL33.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001180
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001181In the preloaded BL33 alternative boot flow, this function is called after
1182populating its entry point address. It is passed a null pointer as its first
1183argument in this case.
1184
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001185
1186### Function : bl2_plat_get_bl32_meminfo() [mandatory]
1187
1188 Argument : meminfo *
1189 Return : void
1190
1191This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001192BL32 image. The meminfo provided by this is used by load_image() to
1193validate whether the BL32 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001194memory from the given base.
1195
1196### Function : bl2_plat_get_bl33_meminfo() [mandatory]
1197
1198 Argument : meminfo *
1199 Return : void
1200
1201This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001202BL33 image. The meminfo provided by this is used by load_image() to
1203validate whether the BL33 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001204memory from the given base.
1205
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001206This function isn't needed if either `BL33_BASE` or `EL3_PAYLOAD_BASE` build
1207options are used.
1208
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001209### Function : bl2_plat_flush_bl31_params() [mandatory]
1210
1211 Argument : void
1212 Return : void
1213
1214Once BL2 has populated all the structures that needs to be read by BL1
Juan Castillod1786372015-12-14 09:35:25 +00001215and BL31 including the bl31_params structures and its sub-structures,
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001216the bl31_ep_info structure and any platform specific data. It flushes
1217all these data to the main memory so that it is available when we jump to
1218later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +01001219
1220### Function : plat_get_ns_image_entrypoint() [mandatory]
1221
1222 Argument : void
1223 Return : unsigned long
1224
1225As previously described, BL2 is responsible for arranging for control to be
Juan Castillod1786372015-12-14 09:35:25 +00001226passed to a normal world BL image through BL31. This function returns the
1227entrypoint of that image, which BL31 uses to jump to it.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001228
Juan Castillod1786372015-12-14 09:35:25 +00001229BL2 is responsible for loading the normal world BL33 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001230
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001231This function isn't needed if either `BL33_BASE` or `EL3_PAYLOAD_BASE` build
1232options are used.
1233
Achin Gupta4f6ad662013-10-25 09:08:21 +01001234
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000012353.3 FWU Boot Loader Stage 2 (BL2U)
1236----------------------------------
1237
1238The AP Firmware Updater Configuration, BL2U, is an optional part of the FWU
1239process and is executed only by the primary CPU. BL1 passes control to BL2U at
1240`BL2U_BASE`. BL2U executes in Secure-EL1 and is responsible for:
1241
12421. (Optional) Transfering the optional SCP_BL2U binary image from AP secure
1243 memory to SCP RAM. BL2U uses the SCP_BL2U `image_info` passed by BL1.
1244 `SCP_BL2U_BASE` defines the address in AP secure memory where SCP_BL2U
1245 should be copied from. Subsequent handling of the SCP_BL2U image is
1246 implemented by the platform specific `bl2u_plat_handle_scp_bl2u()` function.
1247 If `SCP_BL2U_BASE` is not defined then this step is not performed.
1248
12492. Any platform specific setup required to perform the FWU process. For
1250 example, ARM standard platforms initialize the TZC controller so that the
1251 normal world can access DDR memory.
1252
1253The following functions must be implemented by the platform port to enable
1254BL2U to perform the tasks mentioned above.
1255
1256### Function : bl2u_early_platform_setup() [mandatory]
1257
1258 Argument : meminfo *mem_info, void *plat_info
1259 Return : void
1260
1261This function executes with the MMU and data caches disabled. It is only
1262called by the primary CPU. The arguments to this function is the address
1263of the `meminfo` structure and platform specific info provided by BL1.
1264
1265The platform must copy the contents of the `mem_info` and `plat_info` into
1266private storage as the original memory may be subsequently overwritten by BL2U.
1267
1268On ARM CSS platforms `plat_info` is interpreted as an `image_info_t` structure,
1269to extract SCP_BL2U image information, which is then copied into a private
1270variable.
1271
1272### Function : bl2u_plat_arch_setup() [mandatory]
1273
1274 Argument : void
1275 Return : void
1276
1277This function executes with the MMU and data caches disabled. It is only
1278called by the primary CPU.
1279
1280The purpose of this function is to perform any architectural initialization
1281that varies across platforms, for example enabling the MMU (since the memory
1282map differs across platforms).
1283
1284### Function : bl2u_platform_setup() [mandatory]
1285
1286 Argument : void
1287 Return : void
1288
1289This function may execute with the MMU and data caches enabled if the platform
1290port does the necessary initialization in `bl2u_plat_arch_setup()`. It is only
1291called by the primary CPU.
1292
1293The purpose of this function is to perform any platform initialization
1294specific to BL2U.
1295
1296In ARM standard platforms, this function performs security setup, including
1297configuration of the TrustZone controller to allow non-secure masters access
1298to most of DRAM. Part of DRAM is reserved for secure world use.
1299
1300### Function : bl2u_plat_handle_scp_bl2u() [optional]
1301
1302 Argument : void
1303 Return : int
1304
1305This function is used to perform any platform-specific actions required to
1306handle the SCP firmware. Typically it transfers the image into SCP memory using
1307a platform-specific protocol and waits until SCP executes it and signals to the
1308Application Processor (AP) for BL2U execution to continue.
1309
1310This function returns 0 on success, a negative error code otherwise.
1311This function is included if SCP_BL2U_BASE is defined.
1312
1313
13143.4 Boot Loader Stage 3-1 (BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001315---------------------------------
1316
Juan Castillod1786372015-12-14 09:35:25 +00001317During cold boot, the BL31 stage is executed only by the primary CPU. This is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001318determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
Juan Castillod1786372015-12-14 09:35:25 +00001319control to BL31 at `BL31_BASE`. During warm boot, BL31 is executed by all
1320CPUs. BL31 executes at EL3 and is responsible for:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001321
13221. Re-initializing all architectural and platform state. Although BL1 performs
Juan Castillod1786372015-12-14 09:35:25 +00001323 some of this initialization, BL31 remains resident in EL3 and must ensure
Achin Gupta4f6ad662013-10-25 09:08:21 +01001324 that EL3 architectural and platform state is completely initialized. It
1325 should make no assumptions about the system state when it receives control.
1326
13272. Passing control to a normal world BL image, pre-loaded at a platform-
Juan Castillod1786372015-12-14 09:35:25 +00001328 specific address by BL2. BL31 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001329 populated in memory to do this.
1330
Juan Castillod1786372015-12-14 09:35:25 +000013313. Providing runtime firmware services. Currently, BL31 only implements a
Achin Gupta4f6ad662013-10-25 09:08:21 +01001332 subset of the Power State Coordination Interface (PSCI) API as a runtime
1333 service. See Section 3.3 below for details of porting the PSCI
1334 implementation.
1335
Juan Castillod1786372015-12-14 09:35:25 +000013364. Optionally passing control to the BL32 image, pre-loaded at a platform-
1337 specific address by BL2. BL31 exports a set of apis that allow runtime
Achin Gupta35ca3512014-02-19 17:58:33 +00001338 services to specify the security state in which the next image should be
Juan Castillod1786372015-12-14 09:35:25 +00001339 executed and run the corresponding image. BL31 uses the `entry_point_info`
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001340 structure populated by BL2 to do this.
1341
Juan Castillod1786372015-12-14 09:35:25 +00001342If BL31 is a reset vector, It also needs to handle the reset as specified in
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001343section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001344
Juan Castillod1786372015-12-14 09:35:25 +00001345The following functions must be implemented by the platform port to enable BL31
Achin Gupta4f6ad662013-10-25 09:08:21 +01001346to perform the above tasks.
1347
1348
1349### Function : bl31_early_platform_setup() [mandatory]
1350
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001351 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001352 Return : void
1353
1354This function executes with the MMU and data caches disabled. It is only called
1355by the primary CPU. The arguments to this function are:
1356
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001357* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001358* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001359
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001360The platform can copy the contents of the `bl31_params` structure and its
1361sub-structures into private variables if the original memory may be
Juan Castillod1786372015-12-14 09:35:25 +00001362subsequently overwritten by BL31 and similarly the `void *` pointing
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001363to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001364
Dan Handley4a75b842015-03-19 19:24:43 +00001365In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
Juan Castillod1786372015-12-14 09:35:25 +00001366in BL2 memory. BL31 copies the information in this pointer to internal data
Dan Handley4a75b842015-03-19 19:24:43 +00001367structures.
1368
Achin Gupta4f6ad662013-10-25 09:08:21 +01001369
1370### Function : bl31_plat_arch_setup() [mandatory]
1371
1372 Argument : void
1373 Return : void
1374
1375This function executes with the MMU and data caches disabled. It is only called
1376by the primary CPU.
1377
1378The purpose of this function is to perform any architectural initialization
1379that varies across platforms, for example enabling the MMU (since the memory
1380map differs across platforms).
1381
1382
1383### Function : bl31_platform_setup() [mandatory]
1384
1385 Argument : void
1386 Return : void
1387
1388This function may execute with the MMU and data caches enabled if the platform
1389port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1390called by the primary CPU.
1391
1392The purpose of this function is to complete platform initialization so that both
Juan Castillod1786372015-12-14 09:35:25 +00001393BL31 runtime services and normal world software can function correctly.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001394
Dan Handley4a75b842015-03-19 19:24:43 +00001395In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001396* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001397* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001398* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001399* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001400* Detects the system topology.
1401
1402
Soby Mathew78e61612015-12-09 11:28:43 +00001403### Function : bl31_plat_runtime_setup() [optional]
1404
1405 Argument : void
1406 Return : void
1407
1408The purpose of this function is allow the platform to perform any BL31 runtime
1409setup just prior to BL31 exit during cold boot. The default weak
1410implementation of this function will invoke `console_uninit()` which will
1411suppress any BL31 runtime logs.
1412
Soby Mathew080225d2015-12-09 11:38:43 +00001413In ARM Standard platforms, this function will initialize the BL31 runtime
1414console which will cause all further BL31 logs to be output to the
1415runtime console.
1416
Soby Mathew78e61612015-12-09 11:28:43 +00001417
Achin Gupta4f6ad662013-10-25 09:08:21 +01001418### Function : bl31_get_next_image_info() [mandatory]
1419
Achin Gupta35ca3512014-02-19 17:58:33 +00001420 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001421 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001422
1423This function may execute with the MMU and data caches enabled if the platform
1424port does the necessary initializations in `bl31_plat_arch_setup()`.
1425
1426This function is called by `bl31_main()` to retrieve information provided by
Juan Castillod1786372015-12-14 09:35:25 +00001427BL2 for the next image in the security state specified by the argument. BL31
Achin Gupta35ca3512014-02-19 17:58:33 +00001428uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001429state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001430(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1431should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001432
Dan Handley4a75b842015-03-19 19:24:43 +00001433### Function : plat_get_syscnt_freq() [mandatory]
1434
1435 Argument : void
1436 Return : uint64_t
1437
1438This function is used by the architecture setup code to retrieve the counter
1439frequency for the CPU's generic timer. This value will be programmed into the
1440`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1441of the system counter, which is retrieved from the first entry in the frequency
1442modes table.
1443
Achin Gupta4f6ad662013-10-25 09:08:21 +01001444
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001445### #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001446
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001447 When `USE_COHERENT_MEM = 0`, this constant defines the total memory (in
1448 bytes) aligned to the cache line boundary that should be allocated per-cpu to
1449 accommodate all the bakery locks.
1450
1451 If this constant is not defined when `USE_COHERENT_MEM = 0`, the linker
1452 calculates the size of the `bakery_lock` input section, aligns it to the
1453 nearest `CACHE_WRITEBACK_GRANULE`, multiplies it with `PLATFORM_CORE_COUNT`
1454 and stores the result in a linker symbol. This constant prevents a platform
1455 from relying on the linker and provide a more efficient mechanism for
1456 accessing per-cpu bakery lock information.
1457
1458 If this constant is defined and its value is not equal to the value
1459 calculated by the linker then a link time assertion is raised. A compile time
1460 assertion is raised if the value of the constant is not aligned to the cache
1461 line boundary.
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001462
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000014633.5 Power State Coordination Interface (in BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001464------------------------------------------------
1465
1466The ARM Trusted Firmware's implementation of the PSCI API is based around the
Soby Mathew58523c02015-06-08 12:32:50 +01001467concept of a _power domain_. A _power domain_ is a CPU or a logical group of
1468CPUs which share some state on which power management operations can be
1469performed as specified by [PSCI]. Each CPU in the system is assigned a cpu
1470index which is a unique number between `0` and `PLATFORM_CORE_COUNT - 1`.
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001471The _power domains_ are arranged in a hierarchical tree structure and
Soby Mathew58523c02015-06-08 12:32:50 +01001472each _power domain_ can be identified in a system by the cpu index of any CPU
1473that is part of that domain and a _power domain level_. A processing element
1474(for example, a CPU) is at level 0. If the _power domain_ node above a CPU is
1475a logical grouping of CPUs that share some state, then level 1 is that group
1476of CPUs (for example, a cluster), and level 2 is a group of clusters
1477(for example, the system). More details on the power domain topology and its
1478organization can be found in [Power Domain Topology Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001479
Juan Castillod1786372015-12-14 09:35:25 +00001480BL31's platform initialization code exports a pointer to the platform-specific
Achin Gupta4f6ad662013-10-25 09:08:21 +01001481power management operations required for the PSCI implementation to function
Soby Mathew58523c02015-06-08 12:32:50 +01001482correctly. This information is populated in the `plat_psci_ops` structure. The
1483PSCI implementation calls members of the `plat_psci_ops` structure for performing
1484power management operations on the power domains. For example, the target
1485CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `pwr_domain_on()`
1486handler (if present) is called for the CPU power domain.
1487
1488The `power-state` parameter of a PSCI `CPU_SUSPEND` call can be used to
1489describe composite power states specific to a platform. The PSCI implementation
1490defines a generic representation of the power-state parameter viz which is an
1491array of local power states where each index corresponds to a power domain
1492level. Each entry contains the local power state the power domain at that power
1493level could enter. It depends on the `validate_power_state()` handler to
1494convert the power-state parameter (possibly encoding a composite power state)
1495passed in a PSCI `CPU_SUSPEND` call to this representation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001496
1497The following functions must be implemented to initialize PSCI functionality in
1498the ARM Trusted Firmware.
1499
1500
Soby Mathew58523c02015-06-08 12:32:50 +01001501### Function : plat_get_target_pwr_state() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001502
Soby Mathew58523c02015-06-08 12:32:50 +01001503 Argument : unsigned int, const plat_local_state_t *, unsigned int
1504 Return : plat_local_state_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001505
Soby Mathew58523c02015-06-08 12:32:50 +01001506The PSCI generic code uses this function to let the platform participate in
1507state coordination during a power management operation. The function is passed
1508a pointer to an array of platform specific local power state `states` (second
1509argument) which contains the requested power state for each CPU at a particular
1510power domain level `lvl` (first argument) within the power domain. The function
1511is expected to traverse this array of upto `ncpus` (third argument) and return
1512a coordinated target power state by the comparing all the requested power
1513states. The target power state should not be deeper than any of the requested
1514power states.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001515
Soby Mathew58523c02015-06-08 12:32:50 +01001516A weak definition of this API is provided by default wherein it assumes
1517that the platform assigns a local state value in order of increasing depth
1518of the power state i.e. for two power states X & Y, if X < Y
1519then X represents a shallower power state than Y. As a result, the
1520coordinated target local power state for a power domain will be the minimum
1521of the requested local power state values.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001522
1523
Soby Mathew58523c02015-06-08 12:32:50 +01001524### Function : plat_get_power_domain_tree_desc() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001525
Soby Mathew58523c02015-06-08 12:32:50 +01001526 Argument : void
1527 Return : const unsigned char *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001528
Soby Mathew58523c02015-06-08 12:32:50 +01001529This function returns a pointer to the byte array containing the power domain
1530topology tree description. The format and method to construct this array are
Juan Castillod1786372015-12-14 09:35:25 +00001531described in [Power Domain Topology Design]. The BL31 PSCI initilization code
Soby Mathew58523c02015-06-08 12:32:50 +01001532requires this array to be described by the platform, either statically or
1533dynamically, to initialize the power domain topology tree. In case the array
1534is populated dynamically, then plat_core_pos_by_mpidr() and
1535plat_my_core_pos() should also be implemented suitably so that the topology
1536tree description matches the CPU indices returned by these APIs. These APIs
1537together form the platform interface for the PSCI topology framework.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001538
1539
Soby Mathew58523c02015-06-08 12:32:50 +01001540## Function : plat_setup_psci_ops() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001541
Soby Mathew58523c02015-06-08 12:32:50 +01001542 Argument : uintptr_t, const plat_psci_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001543 Return : int
1544
1545This function may execute with the MMU and data caches enabled if the platform
1546port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1547called by the primary CPU.
1548
Soby Mathew58523c02015-06-08 12:32:50 +01001549This function is called by PSCI initialization code. Its purpose is to let
1550the platform layer know about the warm boot entrypoint through the
1551`sec_entrypoint` (first argument) and to export handler routines for
1552platform-specific psci power management actions by populating the passed
Juan Castillod1786372015-12-14 09:35:25 +00001553pointer with a pointer to BL31's private `plat_psci_ops` structure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001554
1555A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001556the ARM FVP specific implementation of these handlers in
Soby Mathew58523c02015-06-08 12:32:50 +01001557[plat/arm/board/fvp/fvp_pm.c] as an example. For each PSCI function that the
1558platform wants to support, the associated operation or operations in this
1559structure must be provided and implemented (Refer section 4 of
1560[Firmware Design] for the PSCI API supported in Trusted Firmware). To disable
1561a PSCI function in a platform port, the operation should be removed from this
1562structure instead of providing an empty implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001563
Soby Mathew58523c02015-06-08 12:32:50 +01001564#### plat_psci_ops.cpu_standby()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001565
Soby Mathew58523c02015-06-08 12:32:50 +01001566Perform the platform-specific actions to enter the standby state for a cpu
1567indicated by the passed argument. This provides a fast path for CPU standby
1568wherein overheads of PSCI state management and lock acquistion is avoided.
1569For this handler to be invoked by the PSCI `CPU_SUSPEND` API implementation,
1570the suspend state type specified in the `power-state` parameter should be
1571STANDBY and the target power domain level specified should be the CPU. The
1572handler should put the CPU into a low power retention state (usually by
1573issuing a wfi instruction) and ensure that it can be woken up from that
1574state by a normal interrupt. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001575
Soby Mathew58523c02015-06-08 12:32:50 +01001576#### plat_psci_ops.pwr_domain_on()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001577
Soby Mathew58523c02015-06-08 12:32:50 +01001578Perform the platform specific actions to power on a CPU, specified
1579by the `MPIDR` (first argument). The generic code expects the platform to
1580return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001581
Soby Mathew58523c02015-06-08 12:32:50 +01001582#### plat_psci_ops.pwr_domain_off()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001583
Soby Mathew58523c02015-06-08 12:32:50 +01001584Perform the platform specific actions to prepare to power off the calling CPU
1585and its higher parent power domain levels as indicated by the `target_state`
1586(first argument). It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001587
Soby Mathew58523c02015-06-08 12:32:50 +01001588The `target_state` encodes the platform coordinated target local power states
1589for the CPU power domain and its parent power domain levels. The handler
1590needs to perform power management operation corresponding to the local state
1591at each power level.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001592
Soby Mathew58523c02015-06-08 12:32:50 +01001593For this handler, the local power state for the CPU power domain will be a
1594power down state where as it could be either power down, retention or run state
1595for the higher power domain levels depending on the result of state
1596coordination. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001597
Soby Mathew58523c02015-06-08 12:32:50 +01001598#### plat_psci_ops.pwr_domain_suspend()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001599
Soby Mathew58523c02015-06-08 12:32:50 +01001600Perform the platform specific actions to prepare to suspend the calling
1601CPU and its higher parent power domain levels as indicated by the
1602`target_state` (first argument). It is called by the PSCI `CPU_SUSPEND`
1603API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001604
Soby Mathew58523c02015-06-08 12:32:50 +01001605The `target_state` has a similar meaning as described in
1606the `pwr_domain_off()` operation. It encodes the platform coordinated
1607target local power states for the CPU power domain and its parent
1608power domain levels. The handler needs to perform power management operation
1609corresponding to the local state at each power level. The generic code
1610expects the handler to succeed.
1611
1612The difference between turning a power domain off versus suspending it
1613is that in the former case, the power domain is expected to re-initialize
1614its state when it is next powered on (see `pwr_domain_on_finish()`). In the
1615latter case, the power domain is expected to save enough state so that it can
Achin Gupta4f6ad662013-10-25 09:08:21 +01001616resume execution by restoring this state when its powered on (see
Soby Mathew58523c02015-06-08 12:32:50 +01001617`pwr_domain_suspend_finish()`).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001618
Soby Mathew58523c02015-06-08 12:32:50 +01001619#### plat_psci_ops.pwr_domain_on_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001620
1621This function is called by the PSCI implementation after the calling CPU is
1622powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1623It performs the platform-specific setup required to initialize enough state for
1624this CPU to enter the normal world and also provide secure runtime firmware
1625services.
1626
Soby Mathew58523c02015-06-08 12:32:50 +01001627The `target_state` (first argument) is the prior state of the power domains
1628immediately before the CPU was turned on. It indicates which power domains
1629above the CPU might require initialization due to having previously been in
1630low power states. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001631
Soby Mathew58523c02015-06-08 12:32:50 +01001632#### plat_psci_ops.pwr_domain_suspend_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001633
1634This function is called by the PSCI implementation after the calling CPU is
1635powered on and released from reset in response to an asynchronous wakeup
1636event, for example a timer interrupt that was programmed by the CPU during the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001637`CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific
1638setup required to restore the saved state for this CPU to resume execution
1639in the normal world and also provide secure runtime firmware services.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001640
Soby Mathew58523c02015-06-08 12:32:50 +01001641The `target_state` (first argument) has a similar meaning as described in
1642the `pwr_domain_on_finish()` operation. The generic code expects the platform
1643to succeed.
Soby Mathew539dced2014-10-02 16:56:51 +01001644
Soby Mathew58523c02015-06-08 12:32:50 +01001645#### plat_psci_ops.validate_power_state()
Soby Mathew539dced2014-10-02 16:56:51 +01001646
1647This function is called by the PSCI implementation during the `CPU_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001648call to validate the `power_state` parameter of the PSCI API and if valid,
1649populate it in `req_state` (second argument) array as power domain level
1650specific local states. If the `power_state` is invalid, the platform must
1651return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1652normal world PSCI client.
Soby Mathew539dced2014-10-02 16:56:51 +01001653
Soby Mathew58523c02015-06-08 12:32:50 +01001654#### plat_psci_ops.validate_ns_entrypoint()
Soby Mathew539dced2014-10-02 16:56:51 +01001655
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001656This function is called by the PSCI implementation during the `CPU_SUSPEND`,
1657`SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point`
Soby Mathew58523c02015-06-08 12:32:50 +01001658parameter passed by the normal world. If the `entry_point` is invalid,
1659the platform must return PSCI_E_INVALID_ADDRESS as error, which is
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001660propagated back to the normal world PSCI client.
1661
Soby Mathew58523c02015-06-08 12:32:50 +01001662#### plat_psci_ops.get_sys_suspend_power_state()
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001663
1664This function is called by the PSCI implementation during the `SYSTEM_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001665call to get the `req_state` parameter from platform which encodes the power
1666domain level specific local states to suspend to system affinity level. The
1667`req_state` will be utilized to do the PSCI state coordination and
1668`pwr_domain_suspend()` will be invoked with the coordinated target state to
1669enter system suspend.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001670
Achin Gupta4f6ad662013-10-25 09:08:21 +01001671
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000016723.6 Interrupt Management framework (in BL31)
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001673----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001674BL31 implements an Interrupt Management Framework (IMF) to manage interrupts
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001675generated in either security state and targeted to EL1 or EL2 in the non-secure
1676state or EL3/S-EL1 in the secure state. The design of this framework is
1677described in the [IMF Design Guide]
1678
1679A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001680text briefly describes each api and its implementation in ARM standard
1681platforms. The API implementation depends upon the type of interrupt controller
Soby Mathew81123e82015-11-23 14:01:21 +00001682present in the platform. ARM standard platform layer supports both [ARM Generic
1683Interrupt Controller version 2.0 (GICv2)][ARM GIC Architecture Specification 2.0]
1684and [3.0 (GICv3)][ARM GIC Architecture Specification 3.0]. Juno builds the ARM
1685Standard layer to use GICv2 and the FVP can be configured to use either GICv2 or
1686GICv3 depending on the build flag `FVP_USE_GIC_DRIVER` (See FVP platform
1687specific build options in [User Guide] for more details).
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001688
1689### Function : plat_interrupt_type_to_line() [mandatory]
1690
1691 Argument : uint32_t, uint32_t
1692 Return : uint32_t
1693
1694The ARM processor signals an interrupt exception either through the IRQ or FIQ
1695interrupt line. The specific line that is signaled depends on how the interrupt
1696controller (IC) reports different interrupt types from an execution context in
1697either security state. The IMF uses this API to determine which interrupt line
1698the platform IC uses to signal each type of interrupt supported by the framework
Soby Mathew81123e82015-11-23 14:01:21 +00001699from a given security state. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001700
1701The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1702Guide]) indicating the target type of the interrupt, the second parameter is the
1703security state of the originating execution context. The return result is the
1704bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1705FIQ=2.
1706
Soby Mathew81123e82015-11-23 14:01:21 +00001707In the case of ARM standard platforms using GICv2, S-EL1 interrupts are
1708configured as FIQs and Non-secure interrupts as IRQs from either security
1709state.
1710
1711In the case of ARM standard platforms using GICv3, the interrupt line to be
1712configured depends on the security state of the execution context when the
1713interrupt is signalled and are as follows:
1714* The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in
1715 NS-EL0/1/2 context.
1716* The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ
1717 in the NS-EL0/1/2 context.
1718* The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2
1719 context.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001720
1721
1722### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1723
1724 Argument : void
1725 Return : uint32_t
1726
1727This API returns the type of the highest priority pending interrupt at the
1728platform IC. The IMF uses the interrupt type to retrieve the corresponding
1729handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1730pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
Soby Mathew81123e82015-11-23 14:01:21 +00001731`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001732
Soby Mathew81123e82015-11-23 14:01:21 +00001733In the case of ARM standard platforms using GICv2, the _Highest Priority
1734Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of
1735the pending interrupt. The type of interrupt depends upon the id value as
1736follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001737
17381. id < 1022 is reported as a S-EL1 interrupt
17392. id = 1022 is reported as a Non-secure interrupt.
17403. id = 1023 is reported as an invalid interrupt type.
1741
Soby Mathew81123e82015-11-23 14:01:21 +00001742In the case of ARM standard platforms using GICv3, the system register
1743`ICC_HPPIR0_EL1`, _Highest Priority Pending group 0 Interrupt Register_,
1744is read to determine the id of the pending interrupt. The type of interrupt
1745depends upon the id value as follows.
1746
17471. id = `PENDING_G1S_INTID` (1020) is reported as a S-EL1 interrupt
17482. id = `PENDING_G1NS_INTID` (1021) is reported as a Non-secure interrupt.
17493. id = `GIC_SPURIOUS_INTERRUPT` (1023) is reported as an invalid interrupt type.
17504. All other interrupt id's are reported as EL3 interrupt.
1751
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001752
1753### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1754
1755 Argument : void
1756 Return : uint32_t
1757
1758This API returns the id of the highest priority pending interrupt at the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001759platform IC. `INTR_ID_UNAVAILABLE` is returned when there is no interrupt
Soby Mathew54718412015-10-27 10:01:06 +00001760pending.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001761
Soby Mathew81123e82015-11-23 14:01:21 +00001762In the case of ARM standard platforms using GICv2, the _Highest Priority
1763Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of the
1764pending interrupt. The id that is returned by API depends upon the value of
1765the id read from the interrupt controller as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001766
17671. id < 1022. id is returned as is.
17682. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001769 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt.
1770 This id is returned by the API.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010017713. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1772
Soby Mathew81123e82015-11-23 14:01:21 +00001773In the case of ARM standard platforms using GICv3, if the API is invoked from
1774EL3, the system register `ICC_HPPIR0_EL1`, _Highest Priority Pending Interrupt
1775group 0 Register_, is read to determine the id of the pending interrupt. The id
1776that is returned by API depends upon the value of the id read from the
1777interrupt controller as follows.
1778
17791. id < `PENDING_G1S_INTID` (1020). id is returned as is.
17802. id = `PENDING_G1S_INTID` (1020) or `PENDING_G1NS_INTID` (1021). The system
1781 register `ICC_HPPIR1_EL1`, _Highest Priority Pending Interrupt group 1
1782 Register_ is read to determine the id of the group 1 interrupt. This id
1783 is returned by the API as long as it is a valid interrupt id
17843. If the id is any of the special interrupt identifiers,
1785 `INTR_ID_UNAVAILABLE` is returned.
1786
1787When the API invoked from S-EL1 for GICv3 systems, the id read from system
1788register `ICC_HPPIR1_EL1`, _Highest Priority Pending group 1 Interrupt
1789Register_, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else
1790`INTR_ID_UNAVAILABLE` is returned.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001791
1792### Function : plat_ic_acknowledge_interrupt() [mandatory]
1793
1794 Argument : void
1795 Return : uint32_t
1796
1797This API is used by the CPU to indicate to the platform IC that processing of
1798the highest pending interrupt has begun. It should return the id of the
1799interrupt which is being processed.
1800
Soby Mathew81123e82015-11-23 14:01:21 +00001801This function in ARM standard platforms using GICv2, reads the _Interrupt
1802Acknowledge Register_ (`GICC_IAR`). This changes the state of the highest
1803priority pending interrupt from pending to active in the interrupt controller.
1804It returns the value read from the `GICC_IAR`. This value is the id of the
1805interrupt whose state has been changed.
1806
1807In the case of ARM standard platforms using GICv3, if the API is invoked
1808from EL3, the function reads the system register `ICC_IAR0_EL1`, _Interrupt
1809Acknowledge Register group 0_. If the API is invoked from S-EL1, the function
1810reads the system register `ICC_IAR1_EL1`, _Interrupt Acknowledge Register
1811group 1_. The read changes the state of the highest pending interrupt from
1812pending to active in the interrupt controller. The value read is returned
1813and is the id of the interrupt whose state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001814
1815The TSP uses this API to start processing of the secure physical timer
1816interrupt.
1817
1818
1819### Function : plat_ic_end_of_interrupt() [mandatory]
1820
1821 Argument : uint32_t
1822 Return : void
1823
1824This API is used by the CPU to indicate to the platform IC that processing of
1825the interrupt corresponding to the id (passed as the parameter) has
1826finished. The id should be the same as the id returned by the
1827`plat_ic_acknowledge_interrupt()` API.
1828
Dan Handley4a75b842015-03-19 19:24:43 +00001829ARM standard platforms write the id to the _End of Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001830(`GICC_EOIR`) in case of GICv2, and to `ICC_EOIR0_EL1` or `ICC_EOIR1_EL1`
1831system register in case of GICv3 depending on where the API is invoked from,
1832EL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001833controller.
1834
1835The TSP uses this API to finish processing of the secure physical timer
1836interrupt.
1837
1838
1839### Function : plat_ic_get_interrupt_type() [mandatory]
1840
1841 Argument : uint32_t
1842 Return : uint32_t
1843
1844This API returns the type of the interrupt id passed as the parameter.
1845`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1846interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1847returned depending upon how the interrupt has been configured by the platform
Soby Mathew81123e82015-11-23 14:01:21 +00001848IC. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001849
Soby Mathew81123e82015-11-23 14:01:21 +00001850ARM standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts
1851and Non-secure interrupts as Group1 interrupts. It reads the group value
1852corresponding to the interrupt id from the relevant _Interrupt Group Register_
1853(`GICD_IGROUPRn`). It uses the group value to determine the type of interrupt.
1854
1855In the case of ARM standard platforms using GICv3, both the _Interrupt Group
1856Register_ (`GICD_IGROUPRn`) and _Interrupt Group Modifier Register_
1857(`GICD_IGRPMODRn`) is read to figure out whether the interrupt is configured
1858as Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt.
Dan Handley4a75b842015-03-19 19:24:43 +00001859
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001860
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000018613.7 Crash Reporting mechanism (in BL31)
Soby Mathewc67b09b2014-07-14 16:57:23 +01001862----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001863BL31 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001864of the CPU to enable quick crash analysis and debugging. It requires that a
1865console is designated as the crash console by the platform which will be used to
1866print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001867
Sandrine Bailleux44804252014-08-06 11:27:23 +01001868The following functions must be implemented by the platform if it wants crash
Juan Castillod1786372015-12-14 09:35:25 +00001869reporting mechanism in BL31. The functions are implemented in assembly so that
Sandrine Bailleux44804252014-08-06 11:27:23 +01001870they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001871
1872### Function : plat_crash_console_init
1873
1874 Argument : void
1875 Return : int
1876
Sandrine Bailleux44804252014-08-06 11:27:23 +01001877This API is used by the crash reporting mechanism to initialize the crash
Juan Castillo9400b402015-11-26 14:52:15 +00001878console. It must only use the general purpose registers x0 to x4 to do the
Sandrine Bailleux44804252014-08-06 11:27:23 +01001879initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001880
Soby Mathewc67b09b2014-07-14 16:57:23 +01001881### Function : plat_crash_console_putc
1882
1883 Argument : int
1884 Return : int
1885
1886This API is used by the crash reporting mechanism to print a character on the
Juan Castillo9400b402015-11-26 14:52:15 +00001887designated crash console. It must only use general purpose registers x1 and
Soby Mathewc67b09b2014-07-14 16:57:23 +01001888x2 to do its work. The parameter and the return value are in general purpose
1889register x0.
1890
Soby Mathew27713fb2014-09-08 17:51:01 +010018914. Build flags
1892---------------
1893
Soby Mathew58523c02015-06-08 12:32:50 +01001894* **ENABLE_PLAT_COMPAT**
1895 All the platforms ports conforming to this API specification should define
1896 the build flag `ENABLE_PLAT_COMPAT` to 0 as the compatibility layer should
1897 be disabled. For more details on compatibility layer, refer
1898 [Migration Guide].
1899
Soby Mathew27713fb2014-09-08 17:51:01 +01001900There are some build flags which can be defined by the platform to control
1901inclusion or exclusion of certain BL stages from the FIP image. These flags
1902need to be defined in the platform makefile which will get included by the
1903build system.
1904
Soby Mathew27713fb2014-09-08 17:51:01 +01001905* **NEED_BL33**
1906 By default, this flag is defined `yes` by the build system and `BL33`
Antonio Nino Diazcf2c8a32016-02-15 14:53:10 +00001907 build option should be supplied as a build option. The platform has the
1908 option of excluding the BL33 image in the `fip` image by defining this flag
1909 to `no`. If any of the options `EL3_PAYLOAD_BASE` or `BL33_BASE` are used,
1910 this flag will be set to `no` automatically.
Soby Mathew27713fb2014-09-08 17:51:01 +01001911
19125. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001913-------------
1914
1915To avoid subtle toolchain behavioral dependencies, the header files provided
1916by the compiler are not used. The software is built with the `-nostdinc` flag
1917to ensure no headers are included from the toolchain inadvertently. Instead the
1918required headers are included in the ARM Trusted Firmware source tree. The
1919library only contains those C library definitions required by the local
1920implementation. If more functionality is required, the needed library functions
1921will need to be added to the local implementation.
1922
1923Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1924headers have been cut down in order to simplify the implementation. In order to
1925minimize changes to the header files, the [FreeBSD] layout has been maintained.
1926The generic C library definitions can be found in `include/stdlib` with more
1927system and machine specific declarations in `include/stdlib/sys` and
1928`include/stdlib/machine`.
1929
1930The local C library implementations can be found in `lib/stdlib`. In order to
1931extend the C library these files may need to be modified. It is recommended to
1932use a release version of [FreeBSD] as a starting point.
1933
1934The C library header files in the [FreeBSD] source tree are located in the
1935`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1936can be found in the `sys/<machine-type>` directories. These files define things
1937like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1938port for [FreeBSD] does not yet exist, the machine specific definitions are
1939based on existing machine types with similar properties (for example SPARC64).
1940
1941Where possible, C library function implementations were taken from [FreeBSD]
1942as found in the `lib/libc` directory.
1943
1944A copy of the [FreeBSD] sources can be downloaded with `git`.
1945
1946 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1947
1948
Soby Mathew27713fb2014-09-08 17:51:01 +010019496. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001950-----------------------------
1951
1952In order to improve platform independence and portability an storage abstraction
1953layer is used to load data from non-volatile platform storage.
1954
1955Each platform should register devices and their drivers via the Storage layer.
1956These drivers then need to be initialized by bootloader phases as
1957required in their respective `blx_platform_setup()` functions. Currently
1958storage access is only required by BL1 and BL2 phases. The `load_image()`
1959function uses the storage layer to access non-volatile platform storage.
1960
Dan Handley4a75b842015-03-19 19:24:43 +00001961It is mandatory to implement at least one storage driver. For the ARM
1962development platforms the Firmware Image Package (FIP) driver is provided as
1963the default means to load data from storage (see the "Firmware Image Package"
1964section in the [User Guide]). The storage layer is described in the header file
1965`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001966is in `drivers/io/io_storage.c` and the driver files are located in
1967`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001968
1969Each IO driver must provide `io_dev_*` structures, as described in
1970`drivers/io/io_driver.h`. These are returned via a mandatory registration
1971function that is called on platform initialization. The semi-hosting driver
1972implementation in `io_semihosting.c` can be used as an example.
1973
1974The Storage layer provides mechanisms to initialize storage devices before
1975IO operations are called. The basic operations supported by the layer
1976include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1977Drivers do not have to implement all operations, but each platform must
1978provide at least one driver for a device capable of supporting generic
1979operations such as loading a bootloader image.
1980
1981The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01001982firmware. These images are specified by using their identifiers, as defined in
1983[include/plat/common/platform_def.h] (or a separate header file included from
1984there). The platform layer (`plat_get_image_source()`) then returns a reference
1985to a device and a driver-specific `spec` which will be understood by the driver
1986to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001987
1988The layer is designed in such a way that is it possible to chain drivers with
1989other drivers. For example, file-system drivers may be implemented on top of
1990physical block devices, both represented by IO devices with corresponding
1991drivers. In such a case, the file-system "binding" with the block device may
1992be deferred until the file-system device is initialised.
1993
1994The abstraction currently depends on structures being statically allocated
1995by the drivers and callers, as the system does not yet provide a means of
1996dynamically allocating memory. This may also have the affect of limiting the
1997amount of open resources per driver.
1998
1999
Achin Gupta4f6ad662013-10-25 09:08:21 +01002000- - - - - - - - - - - - - - - - - - - - - - - - - -
2001
Dan Handley4a75b842015-03-19 19:24:43 +00002002_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01002003
2004
Yuping Luo6b140412016-01-15 11:17:27 +08002005[ARM GIC Architecture Specification 2.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
2006[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 +00002007[IMF Design Guide]: interrupt-framework-design.md
2008[User Guide]: user-guide.md
2009[FreeBSD]: http://www.freebsd.org
2010[Firmware Design]: firmware-design.md
2011[Power Domain Topology Design]: psci-pd-tree.md
2012[PSCI]: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
2013[Migration Guide]: platform-migration-guide.md
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002014[Firmware Update]: firmware-update.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01002015
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00002016[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
2017[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00002018[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002019[include/common/bl_common.h]: ../include/common/bl_common.h
Dan Handley4a75b842015-03-19 19:24:43 +00002020[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
2021[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01002022[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00002023[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]