blob: 56ddbb1c1521fefa19fe03e24ff5ced37b040558 [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
Harry Liebeld265bd72014-01-31 19:04:10 +0000233* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100234
Juan Castillod1786372015-12-14 09:35:25 +0000235 Defines the base address in non-secure DRAM where BL2 loads the BL33 binary
Harry Liebeld265bd72014-01-31 19:04:10 +0000236 image. Must be aligned on a page-size boundary.
237
Juan Castillo16948ae2015-04-13 17:36:19 +0100238For every image, the platform must define individual identifiers that will be
239used by BL1 or BL2 to load the corresponding image into memory from non-volatile
240storage. For the sake of performance, integer numbers will be used as
241identifiers. The platform will use those identifiers to return the relevant
242information about the image to be loaded (file handler, load address,
243authentication information, etc.). The following image identifiers are
244mandatory:
245
246* **#define : BL2_IMAGE_ID**
247
248 BL2 image identifier, used by BL1 to load BL2.
249
250* **#define : BL31_IMAGE_ID**
251
Juan Castillod1786372015-12-14 09:35:25 +0000252 BL31 image identifier, used by BL2 to load BL31.
Juan Castillo16948ae2015-04-13 17:36:19 +0100253
254* **#define : BL33_IMAGE_ID**
255
Juan Castillod1786372015-12-14 09:35:25 +0000256 BL33 image identifier, used by BL2 to load BL33.
Juan Castillo16948ae2015-04-13 17:36:19 +0100257
258If Trusted Board Boot is enabled, the following certificate identifiers must
259also be defined:
260
Juan Castillo516beb52015-12-03 10:19:21 +0000261* **#define : TRUSTED_BOOT_FW_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100262
263 BL2 content certificate identifier, used by BL1 to load the BL2 content
264 certificate.
265
266* **#define : TRUSTED_KEY_CERT_ID**
267
268 Trusted key certificate identifier, used by BL2 to load the trusted key
269 certificate.
270
Juan Castillo516beb52015-12-03 10:19:21 +0000271* **#define : SOC_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100272
Juan Castillod1786372015-12-14 09:35:25 +0000273 BL31 key certificate identifier, used by BL2 to load the BL31 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100274 certificate.
275
Juan Castillo516beb52015-12-03 10:19:21 +0000276* **#define : SOC_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100277
Juan Castillod1786372015-12-14 09:35:25 +0000278 BL31 content certificate identifier, used by BL2 to load the BL31 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100279 certificate.
280
Juan Castillo516beb52015-12-03 10:19:21 +0000281* **#define : NON_TRUSTED_FW_KEY_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100282
Juan Castillod1786372015-12-14 09:35:25 +0000283 BL33 key certificate identifier, used by BL2 to load the BL33 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100284 certificate.
285
Juan Castillo516beb52015-12-03 10:19:21 +0000286* **#define : NON_TRUSTED_FW_CONTENT_CERT_ID**
Juan Castillo16948ae2015-04-13 17:36:19 +0100287
Juan Castillod1786372015-12-14 09:35:25 +0000288 BL33 content certificate identifier, used by BL2 to load the BL33 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100289 certificate.
290
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000291* **#define : FWU_CERT_ID**
292
293 Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the
294 FWU content certificate.
295
296
297If the AP Firmware Updater Configuration image, BL2U is used, the following
298must also be defined:
299
300* **#define : BL2U_BASE**
301
302 Defines the base address in secure memory where BL1 copies the BL2U binary
303 image. Must be aligned on a page-size boundary.
304
305* **#define : BL2U_LIMIT**
306
307 Defines the maximum address in secure memory that the BL2U image can occupy.
308
309* **#define : BL2U_IMAGE_ID**
310
311 BL2U image identifier, used by BL1 to fetch an image descriptor
312 corresponding to BL2U.
313
314If the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following
315must also be defined:
316
317* **#define : SCP_BL2U_IMAGE_ID**
318
319 SCP_BL2U image identifier, used by BL1 to fetch an image descriptor
320 corresponding to SCP_BL2U.
321 NOTE: TF does not provide source code for this image.
322
323If the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must
324also be defined:
325
326* **#define : NS_BL1U_BASE**
327
328 Defines the base address in non-secure ROM where NS_BL1U executes.
329 Must be aligned on a page-size boundary.
330 NOTE: TF does not provide source code for this image.
331
332* **#define : NS_BL1U_IMAGE_ID**
333
334 NS_BL1U image identifier, used by BL1 to fetch an image descriptor
335 corresponding to NS_BL1U.
336
337If the Non-Secure Firmware Updater, NS_BL2U is used, the following must also
338be defined:
339
340* **#define : NS_BL2U_BASE**
341
342 Defines the base address in non-secure memory where NS_BL2U executes.
343 Must be aligned on a page-size boundary.
344 NOTE: TF does not provide source code for this image.
345
346* **#define : NS_BL2U_IMAGE_ID**
347
348 NS_BL2U image identifier, used by BL1 to fetch an image descriptor
349 corresponding to NS_BL2U.
350
351
Juan Castillof59821d2015-12-10 15:49:17 +0000352If a SCP_BL2 image is supported by the platform, the following constants must
Achin Gupta8d35f612015-01-25 22:44:23 +0000353also be defined:
354
Juan Castillof59821d2015-12-10 15:49:17 +0000355* **#define : SCP_BL2_IMAGE_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000356
Juan Castillof59821d2015-12-10 15:49:17 +0000357 SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory
358 from platform storage before being transfered to the SCP.
Achin Gupta8d35f612015-01-25 22:44:23 +0000359
Juan Castillo516beb52015-12-03 10:19:21 +0000360* **#define : SCP_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000361
Juan Castillof59821d2015-12-10 15:49:17 +0000362 SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100363 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000364
Juan Castillo516beb52015-12-03 10:19:21 +0000365* **#define : SCP_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000366
Juan Castillof59821d2015-12-10 15:49:17 +0000367 SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2
368 content certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000369
Juan Castillod1786372015-12-14 09:35:25 +0000370If a BL32 image is supported by the platform, the following constants must
Dan Handley5a06bb72014-08-04 11:41:20 +0100371also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100372
Juan Castillo16948ae2015-04-13 17:36:19 +0100373* **#define : BL32_IMAGE_ID**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100374
Juan Castillod1786372015-12-14 09:35:25 +0000375 BL32 image identifier, used by BL2 to load BL32.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100376
Juan Castillo516beb52015-12-03 10:19:21 +0000377* **#define : TRUSTED_OS_FW_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000378
Juan Castillod1786372015-12-14 09:35:25 +0000379 BL32 key certificate identifier, used by BL2 to load the BL32 key
Juan Castillo16948ae2015-04-13 17:36:19 +0100380 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000381
Juan Castillo516beb52015-12-03 10:19:21 +0000382* **#define : TRUSTED_OS_FW_CONTENT_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000383
Juan Castillod1786372015-12-14 09:35:25 +0000384 BL32 content certificate identifier, used by BL2 to load the BL32 content
Juan Castillo16948ae2015-04-13 17:36:19 +0100385 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000386
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100387* **#define : BL32_BASE**
388
Juan Castillod1786372015-12-14 09:35:25 +0000389 Defines the base address in secure memory where BL2 loads the BL32 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100390 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100391
392* **#define : BL32_LIMIT**
393
Juan Castillod1786372015-12-14 09:35:25 +0000394 Defines the maximum address that the BL32 image can occupy.
Dan Handley5a06bb72014-08-04 11:41:20 +0100395
Juan Castillod1786372015-12-14 09:35:25 +0000396If the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the
Dan Handley5a06bb72014-08-04 11:41:20 +0100397platform, the following constants must also be defined:
398
399* **#define : TSP_SEC_MEM_BASE**
400
401 Defines the base address of the secure memory used by the TSP image on the
402 platform. This must be at the same address or below `BL32_BASE`.
403
404* **#define : TSP_SEC_MEM_SIZE**
405
Juan Castillod1786372015-12-14 09:35:25 +0000406 Defines the size of the secure memory used by the BL32 image on the
Dan Handley5a06bb72014-08-04 11:41:20 +0100407 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
Juan Castillod1786372015-12-14 09:35:25 +0000408 the memory required by the BL32 image, defined by `BL32_BASE` and
Dan Handley5a06bb72014-08-04 11:41:20 +0100409 `BL32_LIMIT`.
410
411* **#define : TSP_IRQ_SEC_PHY_TIMER**
412
413 Defines the ID of the secure physical generic timer interrupt used by the
414 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100415
Dan Handley4a75b842015-03-19 19:24:43 +0000416If the platform port uses the translation table library code, the following
417constant must also be defined:
418
419* **#define : MAX_XLAT_TABLES**
420
421 Defines the maximum number of translation tables that are allocated by the
422 translation table library code. To minimize the amount of runtime memory
423 used, choose the smallest value needed to map the required virtual addresses
424 for each BL stage.
425
Juan Castillo359b60d2016-01-07 11:29:15 +0000426* **#define : MAX_MMAP_REGIONS**
427
428 Defines the maximum number of regions that are allocated by the translation
429 table library code. A region consists of physical base address, virtual base
430 address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as
431 defined in the `mmap_region_t` structure. The platform defines the regions
432 that should be mapped. Then, the translation table library will create the
433 corresponding tables and descriptors at runtime. To minimize the amount of
434 runtime memory used, choose the smallest value needed to register the
435 required regions for each BL stage.
436
437* **#define : ADDR_SPACE_SIZE**
438
439 Defines the total size of the address space in bytes. For example, for a 32
440 bit address space, this value should be `(1ull << 32)`.
441
Dan Handley6d16ce02014-08-04 18:31:43 +0100442If the platform port uses the IO storage framework, the following constants
443must also be defined:
444
445* **#define : MAX_IO_DEVICES**
446
447 Defines the maximum number of registered IO devices. Attempting to register
448 more devices than this value using `io_register_device()` will fail with
Juan Castillo7e26fe12015-10-01 17:55:11 +0100449 -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100450
451* **#define : MAX_IO_HANDLES**
452
453 Defines the maximum number of open IO handles. Attempting to open more IO
Juan Castillo7e26fe12015-10-01 17:55:11 +0100454 entities than this value using `io_open()` will fail with -ENOMEM.
Dan Handley6d16ce02014-08-04 18:31:43 +0100455
Soby Mathewab8707e2015-01-08 18:02:44 +0000456If the platform needs to allocate data within the per-cpu data framework in
Juan Castillod1786372015-12-14 09:35:25 +0000457BL31, it should define the following macro. Currently this is only required if
Soby Mathewab8707e2015-01-08 18:02:44 +0000458the platform decides not to use the coherent memory section by undefining the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000459`USE_COHERENT_MEM` build flag. In this case, the framework allocates the
460required memory within the the per-cpu data to minimize wastage.
Soby Mathewab8707e2015-01-08 18:02:44 +0000461
462* **#define : PLAT_PCPU_DATA_SIZE**
463
464 Defines the memory (in bytes) to be reserved within the per-cpu data
465 structure for use by the platform layer.
466
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100467The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000468memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100469
470* **#define : BL31_PROGBITS_LIMIT**
471
Juan Castillod1786372015-12-14 09:35:25 +0000472 Defines the maximum address in secure RAM that the BL31's progbits sections
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100473 can occupy.
474
Dan Handley5a06bb72014-08-04 11:41:20 +0100475* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100476
477 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100478
Dan Handleyb68954c2014-05-29 12:30:24 +0100479### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100480
Dan Handleyb68954c2014-05-29 12:30:24 +0100481Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000482the following macro defined. In the ARM development platforms, this file is
483found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100484
485* **Macro : plat_print_gic_regs**
486
487 This macro allows the crash reporting routine to print GIC registers
Juan Castillod1786372015-12-14 09:35:25 +0000488 in case of an unhandled exception in BL31. This aids in debugging and
Soby Mathewa43d4312014-04-07 15:28:55 +0100489 this macro can be defined to be empty in case GIC register reporting is
490 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100491
Soby Mathew8c106902014-07-16 09:23:52 +0100492* **Macro : plat_print_interconnect_regs**
493
Dan Handley4a75b842015-03-19 19:24:43 +0000494 This macro allows the crash reporting routine to print interconnect
Juan Castillod1786372015-12-14 09:35:25 +0000495 registers in case of an unhandled exception in BL31. This aids in debugging
Dan Handley4a75b842015-03-19 19:24:43 +0000496 and this macro can be defined to be empty in case interconnect register
497 reporting is not desired. In ARM standard platforms, the CCI snoop
498 control registers are reported.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100499
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000500
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005012.2 Handling Reset
502------------------
503
504BL1 by default implements the reset vector where execution starts from a cold
Juan Castillod1786372015-12-14 09:35:25 +0000505or warm boot. BL31 can be optionally set as a reset vector using the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +0000506`RESET_TO_BL31` make variable.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100507
508For each CPU, the reset vector code is responsible for the following tasks:
509
5101. Distinguishing between a cold boot and a warm boot.
511
5122. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
513 the CPU is placed in a platform-specific state until the primary CPU
514 performs the necessary steps to remove it from this state.
515
5163. In the case of a warm boot, ensuring that the CPU jumps to a platform-
Juan Castillod1786372015-12-14 09:35:25 +0000517 specific address in the BL31 image in the same processor mode as it was
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100518 when released from reset.
519
520The following functions need to be implemented by the platform port to enable
521reset vector code to perform the above tasks.
522
523
Soby Mathew58523c02015-06-08 12:32:50 +0100524### Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100525
Soby Mathew58523c02015-06-08 12:32:50 +0100526 Argument : void
527 Return : unsigned long
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100528
Soby Mathew58523c02015-06-08 12:32:50 +0100529This function is called with the called with the MMU and caches disabled
530(`SCTLR_EL3.M` = 0 and `SCTLR_EL3.C` = 0). The function is responsible for
531distinguishing between a warm and cold reset for the current CPU using
532platform-specific means. If it's a warm reset, then it returns the warm
533reset entrypoint point provided to `plat_setup_psci_ops()` during
Juan Castillod1786372015-12-14 09:35:25 +0000534BL31 initialization. If it's a cold reset then this function must return zero.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100535
536This function does not follow the Procedure Call Standard used by the
537Application Binary Interface for the ARM 64-bit architecture. The caller should
538not assume that callee saved registers are preserved across a call to this
539function.
540
541This function fulfills requirement 1 and 3 listed above.
542
Soby Mathew58523c02015-06-08 12:32:50 +0100543Note that for platforms that support programming the reset address, it is
544expected that a CPU will start executing code directly at the right address,
545both on a cold and warm reset. In this case, there is no need to identify the
546type of reset nor to query the warm reset entrypoint. Therefore, implementing
547this function is not required on such platforms.
548
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100549
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000550### Function : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100551
552 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100553
554This function is called with the MMU and data caches disabled. It is responsible
555for placing the executing secondary CPU in a platform-specific state until the
556primary CPU performs the necessary actions to bring it out of that state and
Sandrine Bailleux52010cc2015-05-19 11:54:45 +0100557allow entry into the OS. This function must not return.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100558
Sandrine Bailleuxcdf14082015-10-02 14:35:25 +0100559In the ARM FVP port, when using the normal boot flow, each secondary CPU powers
560itself off. The primary CPU is responsible for powering up the secondary CPUs
561when normal world software requires them. When booting an EL3 payload instead,
562they stay powered on and are put in a holding pen until their mailbox gets
563populated.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100564
565This function fulfills requirement 2 above.
566
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000567Note that for platforms that can't release secondary CPUs out of reset, only the
568primary CPU will execute the cold boot code. Therefore, implementing this
569function is not required on such platforms.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100570
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000571
572### Function : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
Juan Castillo53fdceb2014-07-16 15:53:43 +0100573
Soby Mathew58523c02015-06-08 12:32:50 +0100574 Argument : void
Juan Castillo53fdceb2014-07-16 15:53:43 +0100575 Return : unsigned int
576
Soby Mathew58523c02015-06-08 12:32:50 +0100577This function identifies whether the current CPU is the primary CPU or a
578secondary CPU. A return value of zero indicates that the CPU is not the
579primary CPU, while a non-zero return value indicates that the CPU is the
580primary CPU.
Juan Castillo53fdceb2014-07-16 15:53:43 +0100581
Sandrine Bailleuxa9bec672015-10-30 15:05:17 +0000582Note that for platforms that can't release secondary CPUs out of reset, only the
583primary CPU will execute the cold boot code. Therefore, there is no need to
584distinguish between primary and secondary CPUs and implementing this function is
585not required.
586
Juan Castillo53fdceb2014-07-16 15:53:43 +0100587
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100588### Function : platform_mem_init() [mandatory]
589
590 Argument : void
591 Return : void
592
593This function is called before any access to data is made by the firmware, in
594order to carry out any essential memory initialization.
595
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100596
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100597### Function: plat_get_rotpk_info()
598
599 Argument : void *, void **, unsigned int *, unsigned int *
600 Return : int
601
602This function is mandatory when Trusted Board Boot is enabled. It returns a
603pointer to the ROTPK stored in the platform (or a hash of it) and its length.
604The ROTPK must be encoded in DER format according to the following ASN.1
605structure:
606
607 AlgorithmIdentifier ::= SEQUENCE {
608 algorithm OBJECT IDENTIFIER,
609 parameters ANY DEFINED BY algorithm OPTIONAL
610 }
611
612 SubjectPublicKeyInfo ::= SEQUENCE {
613 algorithm AlgorithmIdentifier,
614 subjectPublicKey BIT STRING
615 }
616
617In case the function returns a hash of the key:
618
619 DigestInfo ::= SEQUENCE {
620 digestAlgorithm AlgorithmIdentifier,
621 digest OCTET STRING
622 }
623
624The function returns 0 on success. Any other value means the ROTPK could not be
625retrieved from the platform. The function also reports extra information related
626to the ROTPK in the flags parameter.
627
628
Soby Mathew58523c02015-06-08 12:32:50 +01006292.3 Common mandatory modifications
630---------------------------------
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100631
Soby Mathew58523c02015-06-08 12:32:50 +0100632The following functions are mandatory functions which need to be implemented
633by the platform port.
634
635### Function : plat_my_core_pos()
636
637 Argument : void
638 Return : unsigned int
639
640This funtion returns the index of the calling CPU which is used as a
641CPU-specific linear index into blocks of memory (for example while allocating
642per-CPU stacks). This function will be invoked very early in the
643initialization sequence which mandates that this function should be
644implemented in assembly and should not rely on the avalability of a C
645runtime environment.
646
647This function plays a crucial role in the power domain topology framework in
648PSCI and details of this can be found in [Power Domain Topology Design].
649
650### Function : plat_core_pos_by_mpidr()
651
652 Argument : u_register_t
653 Return : int
654
655This function validates the `MPIDR` of a CPU and converts it to an index,
656which can be used as a CPU-specific linear index into blocks of memory. In
657case the `MPIDR` is invalid, this function returns -1. This function will only
Juan Castillod1786372015-12-14 09:35:25 +0000658be invoked by BL31 after the power domain topology is initialized and can
Soby Mathew58523c02015-06-08 12:32:50 +0100659utilize the C runtime environment. For further details about how ARM Trusted
660Firmware represents the power domain topology and how this relates to the
661linear CPU index, please refer [Power Domain Topology Design].
662
663
664
6652.4 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100666---------------------------------
667
668The following are helper functions implemented by the firmware that perform
669common platform-specific tasks. A platform may choose to override these
670definitions.
671
Soby Mathew58523c02015-06-08 12:32:50 +0100672### Function : plat_set_my_stack()
Achin Gupta4f6ad662013-10-25 09:08:21 +0100673
Soby Mathew58523c02015-06-08 12:32:50 +0100674 Argument : void
Achin Gupta4f6ad662013-10-25 09:08:21 +0100675 Return : void
676
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000677This function sets the current stack pointer to the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100678has been allocated for the current CPU. For BL images that only require a
679stack for the primary CPU, the UP version of the function is used. The size
680of the stack allocated to each CPU is specified by the platform defined
681constant `PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100682
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000683Common implementations of this function for the UP and MP BL images are
684provided in [plat/common/aarch64/platform_up_stack.S] and
685[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100686
687
Soby Mathew58523c02015-06-08 12:32:50 +0100688### Function : plat_get_my_stack()
Achin Guptac8afc782013-11-25 18:45:02 +0000689
Soby Mathew58523c02015-06-08 12:32:50 +0100690 Argument : void
Achin Guptac8afc782013-11-25 18:45:02 +0000691 Return : unsigned long
692
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000693This function returns the base address of the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100694has been allocated for the current CPU. For BL images that only require a
695stack for the primary CPU, the UP version of the function is used. The size
696of the stack allocated to each CPU is specified by the platform defined
697constant `PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000698
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000699Common implementations of this function for the UP and MP BL images are
700provided in [plat/common/aarch64/platform_up_stack.S] and
701[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000702
703
Achin Gupta4f6ad662013-10-25 09:08:21 +0100704### Function : plat_report_exception()
705
706 Argument : unsigned int
707 Return : void
708
709A platform may need to report various information about its status when an
710exception is taken, for example the current exception level, the CPU security
711state (secure/non-secure), the exception type, and so on. This function is
712called in the following circumstances:
713
714* In BL1, whenever an exception is taken.
715* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100716
717The default implementation doesn't do anything, to avoid making assumptions
718about the way the platform displays its status information.
719
720This function receives the exception type as its argument. Possible values for
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000721exceptions types are listed in the [include/common/bl_common.h] header file.
722Note that these constants are not related to any architectural exception code;
723they are just an ARM Trusted Firmware convention.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100724
725
Soby Mathew24fb8382014-08-14 12:22:32 +0100726### Function : plat_reset_handler()
727
728 Argument : void
729 Return : void
730
731A platform may need to do additional initialization after reset. This function
732allows the platform to do the platform specific intializations. Platform
733specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000734preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100735
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000736The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000737the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100738guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100739
Soby Mathewadd40352014-08-14 12:49:05 +0100740### Function : plat_disable_acp()
741
742 Argument : void
743 Return : void
744
745This api allows a platform to disable the Accelerator Coherency Port (if
746present) during a cluster power down sequence. The default weak implementation
747doesn't do anything. Since this api is called during the power down sequence,
748it has restrictions for stack usage and it can use the registers x0 - x17 as
749scratch registers. It should preserve the value in x18 register as it is used
750by the caller to store the return address.
751
Juan Castillo40fc6cd2015-09-25 15:41:14 +0100752### Function : plat_error_handler()
753
754 Argument : int
755 Return : void
756
757This API is called when the generic code encounters an error situation from
758which it cannot continue. It allows the platform to perform error reporting or
759recovery actions (for example, reset the system). This function must not return.
760
761The parameter indicates the type of error using standard codes from `errno.h`.
762Possible errors reported by the generic code are:
763
764* `-EAUTH`: a certificate or image could not be authenticated (when Trusted
765 Board Boot is enabled)
766* `-ENOENT`: the requested image or certificate could not be found or an IO
767 error was detected
768* `-ENOMEM`: resources exhausted. Trusted Firmware does not use dynamic
769 memory, so this error is usually an indication of an incorrect array size
770
771The default implementation simply spins.
772
Soby Mathew24fb8382014-08-14 12:22:32 +0100773
Achin Gupta4f6ad662013-10-25 09:08:21 +01007743. Modifications specific to a Boot Loader stage
775-------------------------------------------------
776
7773.1 Boot Loader Stage 1 (BL1)
778-----------------------------
779
780BL1 implements the reset vector where execution starts from after a cold or
781warm boot. For each CPU, BL1 is responsible for the following tasks:
782
Vikram Kanigirie452cd82014-05-23 15:56:12 +01007831. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100784
7852. In the case of a cold boot and the CPU being the primary CPU, ensuring that
786 only this CPU executes the remaining BL1 code, including loading and passing
787 control to the BL2 stage.
788
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00007893. Identifying and starting the Firmware Update process (if required).
790
7914. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100792 address specified by the platform defined constant `BL2_BASE`.
793
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00007945. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100795 accessible by BL2 immediately upon entry.
796
797 meminfo.total_base = Base address of secure RAM visible to BL2
798 meminfo.total_size = Size of secure RAM visible to BL2
799 meminfo.free_base = Base address of secure RAM available for
800 allocation to BL2
801 meminfo.free_size = Size of secure RAM available for allocation to BL2
802
803 BL1 places this `meminfo` structure at the beginning of the free memory
804 available for its use. Since BL1 cannot allocate memory dynamically at the
805 moment, its free memory will be available for BL2's use as-is. However, this
806 means that BL2 must read the `meminfo` structure before it starts using its
807 free memory (this is discussed in Section 3.2).
808
809 In future releases of the ARM Trusted Firmware it will be possible for
810 the platform to decide where it wants to place the `meminfo` structure for
811 BL2.
812
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100813 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100814 BL2 `meminfo` structure. The platform may override this implementation, for
815 example if the platform wants to restrict the amount of memory visible to
816 BL2. Details of how to do this are given below.
817
818The following functions need to be implemented by the platform port to enable
819BL1 to perform the above tasks.
820
821
Dan Handley4a75b842015-03-19 19:24:43 +0000822### Function : bl1_early_platform_setup() [mandatory]
823
824 Argument : void
825 Return : void
826
827This function executes with the MMU and data caches disabled. It is only called
828by the primary CPU.
829
830In ARM standard platforms, this function initializes the console and enables
831snoop requests into the primary CPU's cluster.
832
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100833### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100834
835 Argument : void
836 Return : void
837
Achin Gupta4f6ad662013-10-25 09:08:21 +0100838This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000839platform requires. Platform-specific setup might include configuration of
840memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100841
Dan Handley4a75b842015-03-19 19:24:43 +0000842In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100843
844This function helps fulfill requirement 2 above.
845
846
847### Function : bl1_platform_setup() [mandatory]
848
849 Argument : void
850 Return : void
851
852This function executes with the MMU and data caches enabled. It is responsible
853for performing any remaining platform-specific setup that can occur after the
854MMU and data cache have been enabled.
855
Dan Handley4a75b842015-03-19 19:24:43 +0000856In ARM standard platforms, this function initializes the storage abstraction
857layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000858
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000859This function helps fulfill requirement 4 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100860
861
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000862### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100863
864 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000865 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100866
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000867This function should only be called on the cold boot path. It executes with the
868MMU and data caches enabled. The pointer returned by this function must point to
869a `meminfo` structure containing the extents and availability of secure RAM for
870the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100871
872 meminfo.total_base = Base address of secure RAM visible to BL1
873 meminfo.total_size = Size of secure RAM visible to BL1
874 meminfo.free_base = Base address of secure RAM available for allocation
875 to BL1
876 meminfo.free_size = Size of secure RAM available for allocation to BL1
877
878This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
879populates a similar structure to tell BL2 the extents of memory available for
880its own use.
881
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000882This function helps fulfill requirements 4 and 5 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100883
884
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100885### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100886
887 Argument : meminfo *, meminfo *, unsigned int, unsigned long
888 Return : void
889
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100890BL1 needs to tell the next stage the amount of secure RAM available
891for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100892structure.
893
894Depending upon where BL2 has been loaded in secure RAM (determined by
895`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
896BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000897to BL2. An illustration of how this is done in ARM standard platforms is given
898in the **Memory layout on ARM development platforms** section in the
899[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100900
901
Juan Castilloe3f67122015-10-05 16:59:38 +0100902### Function : bl1_plat_prepare_exit() [optional]
903
Sandrine Bailleux862b5dc2015-11-10 15:01:57 +0000904 Argument : entry_point_info_t *
Juan Castilloe3f67122015-10-05 16:59:38 +0100905 Return : void
906
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +0000907This function is called prior to exiting BL1 in response to the
908`BL1_SMC_RUN_IMAGE` SMC request raised by BL2. It should be used to perform
909platform specific clean up or bookkeeping operations before transferring
910control to the next image. It receives the address of the `entry_point_info_t`
911structure passed from BL2. This function runs with MMU disabled.
912
913### Function : bl1_plat_set_ep_info() [optional]
914
915 Argument : unsigned int image_id, entry_point_info_t *ep_info
916 Return : void
917
918This function allows platforms to override `ep_info` for the given `image_id`.
919
920The default implementation just returns.
921
922### Function : bl1_plat_get_next_image_id() [optional]
923
924 Argument : void
925 Return : unsigned int
926
927This and the following function must be overridden to enable the FWU feature.
928
929BL1 calls this function after platform setup to identify the next image to be
930loaded and executed. If the platform returns `BL2_IMAGE_ID` then BL1 proceeds
931with the normal boot sequence, which loads and executes BL2. If the platform
932returns a different image id, BL1 assumes that Firmware Update is required.
933
934The default implementation always returns `BL2_IMAGE_ID`. The ARM development
935platforms override this function to detect if firmware update is required, and
936if so, return the first image in the firmware update process.
937
938### Function : bl1_plat_get_image_desc() [optional]
939
940 Argument : unsigned int image_id
941 Return : image_desc_t *
942
943BL1 calls this function to get the image descriptor information `image_desc_t`
944for the provided `image_id` from the platform.
945
946The default implementation always returns a common BL2 image descriptor. ARM
947standard platforms return an image descriptor corresponding to BL2 or one of
948the firmware update images defined in the Trusted Board Boot Requirements
949specification.
950
951### Function : bl1_plat_fwu_done() [optional]
952
953 Argument : unsigned int image_id, uintptr_t image_src,
954 unsigned int image_size
955 Return : void
956
957BL1 calls this function when the FWU process is complete. It must not return.
958The platform may override this function to take platform specific action, for
959example to initiate the normal boot flow.
960
961The default implementation spins forever.
962
963### Function : bl1_plat_mem_check() [mandatory]
964
965 Argument : uintptr_t mem_base, unsigned int mem_size,
966 unsigned int flags
967 Return : void
968
969BL1 calls this function while handling FWU copy and authenticate SMCs. The
970platform must ensure that the provided `mem_base` and `mem_size` are mapped into
971BL1, and that this memory corresponds to either a secure or non-secure memory
972region as indicated by the security state of the `flags` argument.
973
974The default implementation of this function asserts therefore platforms must
975override it when using the FWU feature.
Juan Castilloe3f67122015-10-05 16:59:38 +0100976
977
Achin Gupta4f6ad662013-10-25 09:08:21 +01009783.2 Boot Loader Stage 2 (BL2)
979-----------------------------
980
981The BL2 stage is executed only by the primary CPU, which is determined in BL1
982using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
983`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
984
Juan Castillof59821d2015-12-10 15:49:17 +00009851. (Optional) Loading the SCP_BL2 binary image (if present) from platform
986 provided non-volatile storage. To load the SCP_BL2 image, BL2 makes use of
987 the `meminfo` returned by the `bl2_plat_get_scp_bl2_meminfo()` function.
988 The platform also defines the address in memory where SCP_BL2 is loaded
989 through the optional constant `SCP_BL2_BASE`. BL2 uses this information
990 to determine if there is enough memory to load the SCP_BL2 image.
991 Subsequent handling of the SCP_BL2 image is platform-specific and is
992 implemented in the `bl2_plat_handle_scp_bl2()` function.
993 If `SCP_BL2_BASE` is not defined then this step is not performed.
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100994
Juan Castillod1786372015-12-14 09:35:25 +00009952. Loading the BL31 binary image into secure RAM from non-volatile storage. To
996 load the BL31 image, BL2 makes use of the `meminfo` structure passed to it
Harry Liebeld265bd72014-01-31 19:04:10 +0000997 by BL1. This structure allows BL2 to calculate how much secure RAM is
998 available for its use. The platform also defines the address in secure RAM
Juan Castillod1786372015-12-14 09:35:25 +0000999 where BL31 is loaded through the constant `BL31_BASE`. BL2 uses this
1000 information to determine if there is enough memory to load the BL31 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001001
Juan Castillod1786372015-12-14 09:35:25 +000010023. (Optional) Loading the BL32 binary image (if present) from platform
1003 provided non-volatile storage. To load the BL32 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001004 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
Juan Castillod1786372015-12-14 09:35:25 +00001005 The platform also defines the address in memory where BL32 is loaded
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001006 through the optional constant `BL32_BASE`. BL2 uses this information
Juan Castillod1786372015-12-14 09:35:25 +00001007 to determine if there is enough memory to load the BL32 image.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001008 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001009
Juan Castillod1786372015-12-14 09:35:25 +000010104. (Optional) Arranging to pass control to the BL32 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001011 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +01001012 structure in memory provided by the platform with information about how
Juan Castillod1786372015-12-14 09:35:25 +00001013 BL31 should pass control to the BL32 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +00001014
Juan Castillod1786372015-12-14 09:35:25 +000010155. Loading the normal world BL33 binary image into non-secure DRAM from
1016 platform storage and arranging for BL31 to pass control to this image. This
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001017 address is determined using the `plat_get_ns_image_entrypoint()` function
1018 described below.
1019
10206. BL2 populates an `entry_point_info` structure in memory provided by the
Juan Castillod1786372015-12-14 09:35:25 +00001021 platform with information about how BL31 should pass control to the
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001022 other BL images.
1023
Achin Gupta4f6ad662013-10-25 09:08:21 +01001024The following functions must be implemented by the platform port to enable BL2
1025to perform the above tasks.
1026
1027
1028### Function : bl2_early_platform_setup() [mandatory]
1029
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001030 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001031 Return : void
1032
1033This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001034by the primary CPU. The arguments to this function is the address of the
1035`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001036
1037The platform must copy the contents of the `meminfo` structure into a private
1038variable as the original memory may be subsequently overwritten by BL2. The
1039copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +00001040`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001041
Dan Handley4a75b842015-03-19 19:24:43 +00001042In ARM standard platforms, this function also initializes the storage
1043abstraction layer used to load further bootloader images. It is necessary to do
Juan Castillof59821d2015-12-10 15:49:17 +00001044this early on platforms with a SCP_BL2 image, since the later
1045`bl2_platform_setup` must be done after SCP_BL2 is loaded.
Dan Handley4a75b842015-03-19 19:24:43 +00001046
Achin Gupta4f6ad662013-10-25 09:08:21 +01001047
1048### Function : bl2_plat_arch_setup() [mandatory]
1049
1050 Argument : void
1051 Return : void
1052
1053This function executes with the MMU and data caches disabled. It is only called
1054by the primary CPU.
1055
1056The purpose of this function is to perform any architectural initialization
1057that varies across platforms, for example enabling the MMU (since the memory
1058map differs across platforms).
1059
1060
1061### Function : bl2_platform_setup() [mandatory]
1062
1063 Argument : void
1064 Return : void
1065
1066This function may execute with the MMU and data caches enabled if the platform
1067port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
1068called by the primary CPU.
1069
Achin Guptae4d084e2014-02-19 17:18:23 +00001070The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +00001071specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +01001072
Dan Handley4a75b842015-03-19 19:24:43 +00001073In ARM standard platforms, this function performs security setup, including
1074configuration of the TrustZone controller to allow non-secure masters access
1075to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +00001076
Achin Gupta4f6ad662013-10-25 09:08:21 +01001077
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001078### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001079
1080 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001081 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001082
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001083This function should only be called on the cold boot path. It may execute with
1084the MMU and data caches enabled if the platform port does the necessary
1085initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001086
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +00001087The purpose of this function is to return a pointer to a `meminfo` structure
1088populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +01001089`bl2_early_platform_setup()` above.
1090
1091
Juan Castillof59821d2015-12-10 15:49:17 +00001092### Function : bl2_plat_get_scp_bl2_meminfo() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001093
1094 Argument : meminfo *
1095 Return : void
1096
1097This function is used to get the memory limits where BL2 can load the
Juan Castillof59821d2015-12-10 15:49:17 +00001098SCP_BL2 image. The meminfo provided by this is used by load_image() to
1099validate whether the SCP_BL2 image can be loaded within the given
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001100memory from the given base.
1101
1102
Juan Castillof59821d2015-12-10 15:49:17 +00001103### Function : bl2_plat_handle_scp_bl2() [mandatory]
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001104
1105 Argument : image_info *
1106 Return : int
1107
Juan Castillof59821d2015-12-10 15:49:17 +00001108This function is called after loading SCP_BL2 image and it is used to perform
1109any platform-specific actions required to handle the SCP firmware. Typically it
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01001110transfers the image into SCP memory using a platform-specific protocol and waits
1111until SCP executes it and signals to the Application Processor (AP) for BL2
1112execution to continue.
1113
1114This function returns 0 on success, a negative error code otherwise.
1115
1116
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001117### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +00001118
1119 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001120 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +00001121
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001122BL2 platform code needs to return a pointer to a `bl31_params` structure it
Juan Castillod1786372015-12-14 09:35:25 +00001123will use for passing information to BL31. The `bl31_params` structure carries
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001124the following information.
1125 - Header describing the version information for interpreting the bl31_param
1126 structure
Juan Castillod1786372015-12-14 09:35:25 +00001127 - Information about executing the BL33 image in the `bl33_ep_info` field
1128 - Information about executing the BL32 image in the `bl32_ep_info` field
1129 - Information about the type and extents of BL31 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001130 `bl31_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001131 - Information about the type and extents of BL32 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001132 `bl32_image_info` field
Juan Castillod1786372015-12-14 09:35:25 +00001133 - Information about the type and extents of BL33 image in the
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001134 `bl33_image_info` field
1135
1136The memory pointed by this structure and its sub-structures should be
Juan Castillod1786372015-12-14 09:35:25 +00001137accessible from BL31 initialisation code. BL31 might choose to copy the
1138necessary content, or maintain the structures until BL33 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +00001139
1140
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001141### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001142
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001143 Argument : void
1144 Return : entry_point_info *
1145
1146BL2 platform code returns a pointer which is used to populate the entry point
Juan Castillod1786372015-12-14 09:35:25 +00001147information for BL31 entry point. The location pointed by it should be
1148accessible from BL1 while processing the synchronous exception to run to BL31.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001149
Dan Handley4a75b842015-03-19 19:24:43 +00001150In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
1151structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001152
1153
1154### Function : bl2_plat_set_bl31_ep_info() [mandatory]
1155
1156 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001157 Return : void
1158
Juan Castillod1786372015-12-14 09:35:25 +00001159In the normal boot flow, this function is called after loading BL31 image and
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001160it can be used to overwrite the entry point set by loader and also set the
Juan Castillod1786372015-12-14 09:35:25 +00001161security state and SPSR which represents the entry point system state for BL31.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001162
Sandrine Bailleux4c117f62015-11-26 16:31:34 +00001163When booting an EL3 payload instead, this function is called after populating
1164its entry point address and can be used for the same purpose for the payload
1165image. It receives a null pointer as its first argument in this case.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001166
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001167### Function : bl2_plat_set_bl32_ep_info() [mandatory]
1168
1169 Argument : image_info *, entry_point_info *
1170 Return : void
1171
Juan Castillod1786372015-12-14 09:35:25 +00001172This function is called after loading BL32 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001173overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001174and SPSR which represents the entry point system state for BL32.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001175
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001176
1177### Function : bl2_plat_set_bl33_ep_info() [mandatory]
1178
1179 Argument : image_info *, entry_point_info *
1180 Return : void
1181
Juan Castillod1786372015-12-14 09:35:25 +00001182This function is called after loading BL33 image and it can be used to
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001183overwrite the entry point set by loader and also set the security state
Juan Castillod1786372015-12-14 09:35:25 +00001184and SPSR which represents the entry point system state for BL33.
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001185
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001186
1187### Function : bl2_plat_get_bl32_meminfo() [mandatory]
1188
1189 Argument : meminfo *
1190 Return : void
1191
1192This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001193BL32 image. The meminfo provided by this is used by load_image() to
1194validate whether the BL32 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001195memory from the given base.
1196
1197### Function : bl2_plat_get_bl33_meminfo() [mandatory]
1198
1199 Argument : meminfo *
1200 Return : void
1201
1202This function is used to get the memory limits where BL2 can load the
Juan Castillod1786372015-12-14 09:35:25 +00001203BL33 image. The meminfo provided by this is used by load_image() to
1204validate whether the BL33 image can be loaded with in the given
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001205memory from the given base.
1206
1207### Function : bl2_plat_flush_bl31_params() [mandatory]
1208
1209 Argument : void
1210 Return : void
1211
1212Once BL2 has populated all the structures that needs to be read by BL1
Juan Castillod1786372015-12-14 09:35:25 +00001213and BL31 including the bl31_params structures and its sub-structures,
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001214the bl31_ep_info structure and any platform specific data. It flushes
1215all these data to the main memory so that it is available when we jump to
1216later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +01001217
1218### Function : plat_get_ns_image_entrypoint() [mandatory]
1219
1220 Argument : void
1221 Return : unsigned long
1222
1223As previously described, BL2 is responsible for arranging for control to be
Juan Castillod1786372015-12-14 09:35:25 +00001224passed to a normal world BL image through BL31. This function returns the
1225entrypoint of that image, which BL31 uses to jump to it.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001226
Juan Castillod1786372015-12-14 09:35:25 +00001227BL2 is responsible for loading the normal world BL33 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001228
1229
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000012303.3 FWU Boot Loader Stage 2 (BL2U)
1231----------------------------------
1232
1233The AP Firmware Updater Configuration, BL2U, is an optional part of the FWU
1234process and is executed only by the primary CPU. BL1 passes control to BL2U at
1235`BL2U_BASE`. BL2U executes in Secure-EL1 and is responsible for:
1236
12371. (Optional) Transfering the optional SCP_BL2U binary image from AP secure
1238 memory to SCP RAM. BL2U uses the SCP_BL2U `image_info` passed by BL1.
1239 `SCP_BL2U_BASE` defines the address in AP secure memory where SCP_BL2U
1240 should be copied from. Subsequent handling of the SCP_BL2U image is
1241 implemented by the platform specific `bl2u_plat_handle_scp_bl2u()` function.
1242 If `SCP_BL2U_BASE` is not defined then this step is not performed.
1243
12442. Any platform specific setup required to perform the FWU process. For
1245 example, ARM standard platforms initialize the TZC controller so that the
1246 normal world can access DDR memory.
1247
1248The following functions must be implemented by the platform port to enable
1249BL2U to perform the tasks mentioned above.
1250
1251### Function : bl2u_early_platform_setup() [mandatory]
1252
1253 Argument : meminfo *mem_info, void *plat_info
1254 Return : void
1255
1256This function executes with the MMU and data caches disabled. It is only
1257called by the primary CPU. The arguments to this function is the address
1258of the `meminfo` structure and platform specific info provided by BL1.
1259
1260The platform must copy the contents of the `mem_info` and `plat_info` into
1261private storage as the original memory may be subsequently overwritten by BL2U.
1262
1263On ARM CSS platforms `plat_info` is interpreted as an `image_info_t` structure,
1264to extract SCP_BL2U image information, which is then copied into a private
1265variable.
1266
1267### Function : bl2u_plat_arch_setup() [mandatory]
1268
1269 Argument : void
1270 Return : void
1271
1272This function executes with the MMU and data caches disabled. It is only
1273called by the primary CPU.
1274
1275The purpose of this function is to perform any architectural initialization
1276that varies across platforms, for example enabling the MMU (since the memory
1277map differs across platforms).
1278
1279### Function : bl2u_platform_setup() [mandatory]
1280
1281 Argument : void
1282 Return : void
1283
1284This function may execute with the MMU and data caches enabled if the platform
1285port does the necessary initialization in `bl2u_plat_arch_setup()`. It is only
1286called by the primary CPU.
1287
1288The purpose of this function is to perform any platform initialization
1289specific to BL2U.
1290
1291In ARM standard platforms, this function performs security setup, including
1292configuration of the TrustZone controller to allow non-secure masters access
1293to most of DRAM. Part of DRAM is reserved for secure world use.
1294
1295### Function : bl2u_plat_handle_scp_bl2u() [optional]
1296
1297 Argument : void
1298 Return : int
1299
1300This function is used to perform any platform-specific actions required to
1301handle the SCP firmware. Typically it transfers the image into SCP memory using
1302a platform-specific protocol and waits until SCP executes it and signals to the
1303Application Processor (AP) for BL2U execution to continue.
1304
1305This function returns 0 on success, a negative error code otherwise.
1306This function is included if SCP_BL2U_BASE is defined.
1307
1308
13093.4 Boot Loader Stage 3-1 (BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001310---------------------------------
1311
Juan Castillod1786372015-12-14 09:35:25 +00001312During cold boot, the BL31 stage is executed only by the primary CPU. This is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001313determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
Juan Castillod1786372015-12-14 09:35:25 +00001314control to BL31 at `BL31_BASE`. During warm boot, BL31 is executed by all
1315CPUs. BL31 executes at EL3 and is responsible for:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001316
13171. Re-initializing all architectural and platform state. Although BL1 performs
Juan Castillod1786372015-12-14 09:35:25 +00001318 some of this initialization, BL31 remains resident in EL3 and must ensure
Achin Gupta4f6ad662013-10-25 09:08:21 +01001319 that EL3 architectural and platform state is completely initialized. It
1320 should make no assumptions about the system state when it receives control.
1321
13222. Passing control to a normal world BL image, pre-loaded at a platform-
Juan Castillod1786372015-12-14 09:35:25 +00001323 specific address by BL2. BL31 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001324 populated in memory to do this.
1325
Juan Castillod1786372015-12-14 09:35:25 +000013263. Providing runtime firmware services. Currently, BL31 only implements a
Achin Gupta4f6ad662013-10-25 09:08:21 +01001327 subset of the Power State Coordination Interface (PSCI) API as a runtime
1328 service. See Section 3.3 below for details of porting the PSCI
1329 implementation.
1330
Juan Castillod1786372015-12-14 09:35:25 +000013314. Optionally passing control to the BL32 image, pre-loaded at a platform-
1332 specific address by BL2. BL31 exports a set of apis that allow runtime
Achin Gupta35ca3512014-02-19 17:58:33 +00001333 services to specify the security state in which the next image should be
Juan Castillod1786372015-12-14 09:35:25 +00001334 executed and run the corresponding image. BL31 uses the `entry_point_info`
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001335 structure populated by BL2 to do this.
1336
Juan Castillod1786372015-12-14 09:35:25 +00001337If BL31 is a reset vector, It also needs to handle the reset as specified in
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001338section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001339
Juan Castillod1786372015-12-14 09:35:25 +00001340The following functions must be implemented by the platform port to enable BL31
Achin Gupta4f6ad662013-10-25 09:08:21 +01001341to perform the above tasks.
1342
1343
1344### Function : bl31_early_platform_setup() [mandatory]
1345
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001346 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001347 Return : void
1348
1349This function executes with the MMU and data caches disabled. It is only called
1350by the primary CPU. The arguments to this function are:
1351
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001352* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001353* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001354
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001355The platform can copy the contents of the `bl31_params` structure and its
1356sub-structures into private variables if the original memory may be
Juan Castillod1786372015-12-14 09:35:25 +00001357subsequently overwritten by BL31 and similarly the `void *` pointing
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001358to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001359
Dan Handley4a75b842015-03-19 19:24:43 +00001360In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
Juan Castillod1786372015-12-14 09:35:25 +00001361in BL2 memory. BL31 copies the information in this pointer to internal data
Dan Handley4a75b842015-03-19 19:24:43 +00001362structures.
1363
Achin Gupta4f6ad662013-10-25 09:08:21 +01001364
1365### Function : bl31_plat_arch_setup() [mandatory]
1366
1367 Argument : void
1368 Return : void
1369
1370This function executes with the MMU and data caches disabled. It is only called
1371by the primary CPU.
1372
1373The purpose of this function is to perform any architectural initialization
1374that varies across platforms, for example enabling the MMU (since the memory
1375map differs across platforms).
1376
1377
1378### Function : bl31_platform_setup() [mandatory]
1379
1380 Argument : void
1381 Return : void
1382
1383This function may execute with the MMU and data caches enabled if the platform
1384port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1385called by the primary CPU.
1386
1387The purpose of this function is to complete platform initialization so that both
Juan Castillod1786372015-12-14 09:35:25 +00001388BL31 runtime services and normal world software can function correctly.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001389
Dan Handley4a75b842015-03-19 19:24:43 +00001390In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001391* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001392* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001393* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001394* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001395* Detects the system topology.
1396
1397
Soby Mathew78e61612015-12-09 11:28:43 +00001398### Function : bl31_plat_runtime_setup() [optional]
1399
1400 Argument : void
1401 Return : void
1402
1403The purpose of this function is allow the platform to perform any BL31 runtime
1404setup just prior to BL31 exit during cold boot. The default weak
1405implementation of this function will invoke `console_uninit()` which will
1406suppress any BL31 runtime logs.
1407
Soby Mathew080225d2015-12-09 11:38:43 +00001408In ARM Standard platforms, this function will initialize the BL31 runtime
1409console which will cause all further BL31 logs to be output to the
1410runtime console.
1411
Soby Mathew78e61612015-12-09 11:28:43 +00001412
Achin Gupta4f6ad662013-10-25 09:08:21 +01001413### Function : bl31_get_next_image_info() [mandatory]
1414
Achin Gupta35ca3512014-02-19 17:58:33 +00001415 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001416 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001417
1418This function may execute with the MMU and data caches enabled if the platform
1419port does the necessary initializations in `bl31_plat_arch_setup()`.
1420
1421This function is called by `bl31_main()` to retrieve information provided by
Juan Castillod1786372015-12-14 09:35:25 +00001422BL2 for the next image in the security state specified by the argument. BL31
Achin Gupta35ca3512014-02-19 17:58:33 +00001423uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001424state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001425(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1426should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001427
Dan Handley4a75b842015-03-19 19:24:43 +00001428### Function : plat_get_syscnt_freq() [mandatory]
1429
1430 Argument : void
1431 Return : uint64_t
1432
1433This function is used by the architecture setup code to retrieve the counter
1434frequency for the CPU's generic timer. This value will be programmed into the
1435`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1436of the system counter, which is retrieved from the first entry in the frequency
1437modes table.
1438
Achin Gupta4f6ad662013-10-25 09:08:21 +01001439
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001440### #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001441
Vikram Kanigiri7173f5f2015-09-24 15:45:43 +01001442 When `USE_COHERENT_MEM = 0`, this constant defines the total memory (in
1443 bytes) aligned to the cache line boundary that should be allocated per-cpu to
1444 accommodate all the bakery locks.
1445
1446 If this constant is not defined when `USE_COHERENT_MEM = 0`, the linker
1447 calculates the size of the `bakery_lock` input section, aligns it to the
1448 nearest `CACHE_WRITEBACK_GRANULE`, multiplies it with `PLATFORM_CORE_COUNT`
1449 and stores the result in a linker symbol. This constant prevents a platform
1450 from relying on the linker and provide a more efficient mechanism for
1451 accessing per-cpu bakery lock information.
1452
1453 If this constant is defined and its value is not equal to the value
1454 calculated by the linker then a link time assertion is raised. A compile time
1455 assertion is raised if the value of the constant is not aligned to the cache
1456 line boundary.
Andrew Thoelkeee7b35c2015-09-10 11:39:36 +01001457
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000014583.5 Power State Coordination Interface (in BL31)
Achin Gupta4f6ad662013-10-25 09:08:21 +01001459------------------------------------------------
1460
1461The ARM Trusted Firmware's implementation of the PSCI API is based around the
Soby Mathew58523c02015-06-08 12:32:50 +01001462concept of a _power domain_. A _power domain_ is a CPU or a logical group of
1463CPUs which share some state on which power management operations can be
1464performed as specified by [PSCI]. Each CPU in the system is assigned a cpu
1465index which is a unique number between `0` and `PLATFORM_CORE_COUNT - 1`.
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001466The _power domains_ are arranged in a hierarchical tree structure and
Soby Mathew58523c02015-06-08 12:32:50 +01001467each _power domain_ can be identified in a system by the cpu index of any CPU
1468that is part of that domain and a _power domain level_. A processing element
1469(for example, a CPU) is at level 0. If the _power domain_ node above a CPU is
1470a logical grouping of CPUs that share some state, then level 1 is that group
1471of CPUs (for example, a cluster), and level 2 is a group of clusters
1472(for example, the system). More details on the power domain topology and its
1473organization can be found in [Power Domain Topology Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001474
Juan Castillod1786372015-12-14 09:35:25 +00001475BL31's platform initialization code exports a pointer to the platform-specific
Achin Gupta4f6ad662013-10-25 09:08:21 +01001476power management operations required for the PSCI implementation to function
Soby Mathew58523c02015-06-08 12:32:50 +01001477correctly. This information is populated in the `plat_psci_ops` structure. The
1478PSCI implementation calls members of the `plat_psci_ops` structure for performing
1479power management operations on the power domains. For example, the target
1480CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `pwr_domain_on()`
1481handler (if present) is called for the CPU power domain.
1482
1483The `power-state` parameter of a PSCI `CPU_SUSPEND` call can be used to
1484describe composite power states specific to a platform. The PSCI implementation
1485defines a generic representation of the power-state parameter viz which is an
1486array of local power states where each index corresponds to a power domain
1487level. Each entry contains the local power state the power domain at that power
1488level could enter. It depends on the `validate_power_state()` handler to
1489convert the power-state parameter (possibly encoding a composite power state)
1490passed in a PSCI `CPU_SUSPEND` call to this representation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001491
1492The following functions must be implemented to initialize PSCI functionality in
1493the ARM Trusted Firmware.
1494
1495
Soby Mathew58523c02015-06-08 12:32:50 +01001496### Function : plat_get_target_pwr_state() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001497
Soby Mathew58523c02015-06-08 12:32:50 +01001498 Argument : unsigned int, const plat_local_state_t *, unsigned int
1499 Return : plat_local_state_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001500
Soby Mathew58523c02015-06-08 12:32:50 +01001501The PSCI generic code uses this function to let the platform participate in
1502state coordination during a power management operation. The function is passed
1503a pointer to an array of platform specific local power state `states` (second
1504argument) which contains the requested power state for each CPU at a particular
1505power domain level `lvl` (first argument) within the power domain. The function
1506is expected to traverse this array of upto `ncpus` (third argument) and return
1507a coordinated target power state by the comparing all the requested power
1508states. The target power state should not be deeper than any of the requested
1509power states.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001510
Soby Mathew58523c02015-06-08 12:32:50 +01001511A weak definition of this API is provided by default wherein it assumes
1512that the platform assigns a local state value in order of increasing depth
1513of the power state i.e. for two power states X & Y, if X < Y
1514then X represents a shallower power state than Y. As a result, the
1515coordinated target local power state for a power domain will be the minimum
1516of the requested local power state values.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001517
1518
Soby Mathew58523c02015-06-08 12:32:50 +01001519### Function : plat_get_power_domain_tree_desc() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001520
Soby Mathew58523c02015-06-08 12:32:50 +01001521 Argument : void
1522 Return : const unsigned char *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001523
Soby Mathew58523c02015-06-08 12:32:50 +01001524This function returns a pointer to the byte array containing the power domain
1525topology tree description. The format and method to construct this array are
Juan Castillod1786372015-12-14 09:35:25 +00001526described in [Power Domain Topology Design]. The BL31 PSCI initilization code
Soby Mathew58523c02015-06-08 12:32:50 +01001527requires this array to be described by the platform, either statically or
1528dynamically, to initialize the power domain topology tree. In case the array
1529is populated dynamically, then plat_core_pos_by_mpidr() and
1530plat_my_core_pos() should also be implemented suitably so that the topology
1531tree description matches the CPU indices returned by these APIs. These APIs
1532together form the platform interface for the PSCI topology framework.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001533
1534
Soby Mathew58523c02015-06-08 12:32:50 +01001535## Function : plat_setup_psci_ops() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001536
Soby Mathew58523c02015-06-08 12:32:50 +01001537 Argument : uintptr_t, const plat_psci_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001538 Return : int
1539
1540This function may execute with the MMU and data caches enabled if the platform
1541port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1542called by the primary CPU.
1543
Soby Mathew58523c02015-06-08 12:32:50 +01001544This function is called by PSCI initialization code. Its purpose is to let
1545the platform layer know about the warm boot entrypoint through the
1546`sec_entrypoint` (first argument) and to export handler routines for
1547platform-specific psci power management actions by populating the passed
Juan Castillod1786372015-12-14 09:35:25 +00001548pointer with a pointer to BL31's private `plat_psci_ops` structure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001549
1550A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001551the ARM FVP specific implementation of these handlers in
Soby Mathew58523c02015-06-08 12:32:50 +01001552[plat/arm/board/fvp/fvp_pm.c] as an example. For each PSCI function that the
1553platform wants to support, the associated operation or operations in this
1554structure must be provided and implemented (Refer section 4 of
1555[Firmware Design] for the PSCI API supported in Trusted Firmware). To disable
1556a PSCI function in a platform port, the operation should be removed from this
1557structure instead of providing an empty implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001558
Soby Mathew58523c02015-06-08 12:32:50 +01001559#### plat_psci_ops.cpu_standby()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001560
Soby Mathew58523c02015-06-08 12:32:50 +01001561Perform the platform-specific actions to enter the standby state for a cpu
1562indicated by the passed argument. This provides a fast path for CPU standby
1563wherein overheads of PSCI state management and lock acquistion is avoided.
1564For this handler to be invoked by the PSCI `CPU_SUSPEND` API implementation,
1565the suspend state type specified in the `power-state` parameter should be
1566STANDBY and the target power domain level specified should be the CPU. The
1567handler should put the CPU into a low power retention state (usually by
1568issuing a wfi instruction) and ensure that it can be woken up from that
1569state by a normal interrupt. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001570
Soby Mathew58523c02015-06-08 12:32:50 +01001571#### plat_psci_ops.pwr_domain_on()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001572
Soby Mathew58523c02015-06-08 12:32:50 +01001573Perform the platform specific actions to power on a CPU, specified
1574by the `MPIDR` (first argument). The generic code expects the platform to
1575return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001576
Soby Mathew58523c02015-06-08 12:32:50 +01001577#### plat_psci_ops.pwr_domain_off()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001578
Soby Mathew58523c02015-06-08 12:32:50 +01001579Perform the platform specific actions to prepare to power off the calling CPU
1580and its higher parent power domain levels as indicated by the `target_state`
1581(first argument). It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001582
Soby Mathew58523c02015-06-08 12:32:50 +01001583The `target_state` encodes the platform coordinated target local power states
1584for the CPU power domain and its parent power domain levels. The handler
1585needs to perform power management operation corresponding to the local state
1586at each power level.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001587
Soby Mathew58523c02015-06-08 12:32:50 +01001588For this handler, the local power state for the CPU power domain will be a
1589power down state where as it could be either power down, retention or run state
1590for the higher power domain levels depending on the result of state
1591coordination. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001592
Soby Mathew58523c02015-06-08 12:32:50 +01001593#### plat_psci_ops.pwr_domain_suspend()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001594
Soby Mathew58523c02015-06-08 12:32:50 +01001595Perform the platform specific actions to prepare to suspend the calling
1596CPU and its higher parent power domain levels as indicated by the
1597`target_state` (first argument). It is called by the PSCI `CPU_SUSPEND`
1598API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001599
Soby Mathew58523c02015-06-08 12:32:50 +01001600The `target_state` has a similar meaning as described in
1601the `pwr_domain_off()` operation. It encodes the platform coordinated
1602target local power states for the CPU power domain and its parent
1603power domain levels. The handler needs to perform power management operation
1604corresponding to the local state at each power level. The generic code
1605expects the handler to succeed.
1606
1607The difference between turning a power domain off versus suspending it
1608is that in the former case, the power domain is expected to re-initialize
1609its state when it is next powered on (see `pwr_domain_on_finish()`). In the
1610latter case, the power domain is expected to save enough state so that it can
Achin Gupta4f6ad662013-10-25 09:08:21 +01001611resume execution by restoring this state when its powered on (see
Soby Mathew58523c02015-06-08 12:32:50 +01001612`pwr_domain_suspend_finish()`).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001613
Soby Mathew58523c02015-06-08 12:32:50 +01001614#### plat_psci_ops.pwr_domain_on_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001615
1616This function is called by the PSCI implementation after the calling CPU is
1617powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1618It performs the platform-specific setup required to initialize enough state for
1619this CPU to enter the normal world and also provide secure runtime firmware
1620services.
1621
Soby Mathew58523c02015-06-08 12:32:50 +01001622The `target_state` (first argument) is the prior state of the power domains
1623immediately before the CPU was turned on. It indicates which power domains
1624above the CPU might require initialization due to having previously been in
1625low power states. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001626
Soby Mathew58523c02015-06-08 12:32:50 +01001627#### plat_psci_ops.pwr_domain_suspend_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001628
1629This function is called by the PSCI implementation after the calling CPU is
1630powered on and released from reset in response to an asynchronous wakeup
1631event, for example a timer interrupt that was programmed by the CPU during the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001632`CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific
1633setup required to restore the saved state for this CPU to resume execution
1634in the normal world and also provide secure runtime firmware services.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001635
Soby Mathew58523c02015-06-08 12:32:50 +01001636The `target_state` (first argument) has a similar meaning as described in
1637the `pwr_domain_on_finish()` operation. The generic code expects the platform
1638to succeed.
Soby Mathew539dced2014-10-02 16:56:51 +01001639
Soby Mathew58523c02015-06-08 12:32:50 +01001640#### plat_psci_ops.validate_power_state()
Soby Mathew539dced2014-10-02 16:56:51 +01001641
1642This function is called by the PSCI implementation during the `CPU_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001643call to validate the `power_state` parameter of the PSCI API and if valid,
1644populate it in `req_state` (second argument) array as power domain level
1645specific local states. If the `power_state` is invalid, the platform must
1646return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1647normal world PSCI client.
Soby Mathew539dced2014-10-02 16:56:51 +01001648
Soby Mathew58523c02015-06-08 12:32:50 +01001649#### plat_psci_ops.validate_ns_entrypoint()
Soby Mathew539dced2014-10-02 16:56:51 +01001650
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001651This function is called by the PSCI implementation during the `CPU_SUSPEND`,
1652`SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point`
Soby Mathew58523c02015-06-08 12:32:50 +01001653parameter passed by the normal world. If the `entry_point` is invalid,
1654the platform must return PSCI_E_INVALID_ADDRESS as error, which is
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001655propagated back to the normal world PSCI client.
1656
Soby Mathew58523c02015-06-08 12:32:50 +01001657#### plat_psci_ops.get_sys_suspend_power_state()
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001658
1659This function is called by the PSCI implementation during the `SYSTEM_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001660call to get the `req_state` parameter from platform which encodes the power
1661domain level specific local states to suspend to system affinity level. The
1662`req_state` will be utilized to do the PSCI state coordination and
1663`pwr_domain_suspend()` will be invoked with the coordinated target state to
1664enter system suspend.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001665
Achin Gupta4f6ad662013-10-25 09:08:21 +01001666
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000016673.6 Interrupt Management framework (in BL31)
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001668----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001669BL31 implements an Interrupt Management Framework (IMF) to manage interrupts
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001670generated in either security state and targeted to EL1 or EL2 in the non-secure
1671state or EL3/S-EL1 in the secure state. The design of this framework is
1672described in the [IMF Design Guide]
1673
1674A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001675text briefly describes each api and its implementation in ARM standard
1676platforms. The API implementation depends upon the type of interrupt controller
Soby Mathew81123e82015-11-23 14:01:21 +00001677present in the platform. ARM standard platform layer supports both [ARM Generic
1678Interrupt Controller version 2.0 (GICv2)][ARM GIC Architecture Specification 2.0]
1679and [3.0 (GICv3)][ARM GIC Architecture Specification 3.0]. Juno builds the ARM
1680Standard layer to use GICv2 and the FVP can be configured to use either GICv2 or
1681GICv3 depending on the build flag `FVP_USE_GIC_DRIVER` (See FVP platform
1682specific build options in [User Guide] for more details).
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001683
1684### Function : plat_interrupt_type_to_line() [mandatory]
1685
1686 Argument : uint32_t, uint32_t
1687 Return : uint32_t
1688
1689The ARM processor signals an interrupt exception either through the IRQ or FIQ
1690interrupt line. The specific line that is signaled depends on how the interrupt
1691controller (IC) reports different interrupt types from an execution context in
1692either security state. The IMF uses this API to determine which interrupt line
1693the platform IC uses to signal each type of interrupt supported by the framework
Soby Mathew81123e82015-11-23 14:01:21 +00001694from a given security state. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001695
1696The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1697Guide]) indicating the target type of the interrupt, the second parameter is the
1698security state of the originating execution context. The return result is the
1699bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1700FIQ=2.
1701
Soby Mathew81123e82015-11-23 14:01:21 +00001702In the case of ARM standard platforms using GICv2, S-EL1 interrupts are
1703configured as FIQs and Non-secure interrupts as IRQs from either security
1704state.
1705
1706In the case of ARM standard platforms using GICv3, the interrupt line to be
1707configured depends on the security state of the execution context when the
1708interrupt is signalled and are as follows:
1709* The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in
1710 NS-EL0/1/2 context.
1711* The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ
1712 in the NS-EL0/1/2 context.
1713* The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2
1714 context.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001715
1716
1717### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1718
1719 Argument : void
1720 Return : uint32_t
1721
1722This API returns the type of the highest priority pending interrupt at the
1723platform IC. The IMF uses the interrupt type to retrieve the corresponding
1724handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1725pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
Soby Mathew81123e82015-11-23 14:01:21 +00001726`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001727
Soby Mathew81123e82015-11-23 14:01:21 +00001728In the case of ARM standard platforms using GICv2, the _Highest Priority
1729Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of
1730the pending interrupt. The type of interrupt depends upon the id value as
1731follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001732
17331. id < 1022 is reported as a S-EL1 interrupt
17342. id = 1022 is reported as a Non-secure interrupt.
17353. id = 1023 is reported as an invalid interrupt type.
1736
Soby Mathew81123e82015-11-23 14:01:21 +00001737In the case of ARM standard platforms using GICv3, the system register
1738`ICC_HPPIR0_EL1`, _Highest Priority Pending group 0 Interrupt Register_,
1739is read to determine the id of the pending interrupt. The type of interrupt
1740depends upon the id value as follows.
1741
17421. id = `PENDING_G1S_INTID` (1020) is reported as a S-EL1 interrupt
17432. id = `PENDING_G1NS_INTID` (1021) is reported as a Non-secure interrupt.
17443. id = `GIC_SPURIOUS_INTERRUPT` (1023) is reported as an invalid interrupt type.
17454. All other interrupt id's are reported as EL3 interrupt.
1746
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001747
1748### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1749
1750 Argument : void
1751 Return : uint32_t
1752
1753This API returns the id of the highest priority pending interrupt at the
Sandrine Bailleux1645d3e2015-12-17 13:58:58 +00001754platform IC. `INTR_ID_UNAVAILABLE` is returned when there is no interrupt
Soby Mathew54718412015-10-27 10:01:06 +00001755pending.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001756
Soby Mathew81123e82015-11-23 14:01:21 +00001757In the case of ARM standard platforms using GICv2, the _Highest Priority
1758Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of the
1759pending interrupt. The id that is returned by API depends upon the value of
1760the id read from the interrupt controller as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001761
17621. id < 1022. id is returned as is.
17632. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001764 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt.
1765 This id is returned by the API.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010017663. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1767
Soby Mathew81123e82015-11-23 14:01:21 +00001768In the case of ARM standard platforms using GICv3, if the API is invoked from
1769EL3, the system register `ICC_HPPIR0_EL1`, _Highest Priority Pending Interrupt
1770group 0 Register_, is read to determine the id of the pending interrupt. The id
1771that is returned by API depends upon the value of the id read from the
1772interrupt controller as follows.
1773
17741. id < `PENDING_G1S_INTID` (1020). id is returned as is.
17752. id = `PENDING_G1S_INTID` (1020) or `PENDING_G1NS_INTID` (1021). The system
1776 register `ICC_HPPIR1_EL1`, _Highest Priority Pending Interrupt group 1
1777 Register_ is read to determine the id of the group 1 interrupt. This id
1778 is returned by the API as long as it is a valid interrupt id
17793. If the id is any of the special interrupt identifiers,
1780 `INTR_ID_UNAVAILABLE` is returned.
1781
1782When the API invoked from S-EL1 for GICv3 systems, the id read from system
1783register `ICC_HPPIR1_EL1`, _Highest Priority Pending group 1 Interrupt
1784Register_, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else
1785`INTR_ID_UNAVAILABLE` is returned.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001786
1787### Function : plat_ic_acknowledge_interrupt() [mandatory]
1788
1789 Argument : void
1790 Return : uint32_t
1791
1792This API is used by the CPU to indicate to the platform IC that processing of
1793the highest pending interrupt has begun. It should return the id of the
1794interrupt which is being processed.
1795
Soby Mathew81123e82015-11-23 14:01:21 +00001796This function in ARM standard platforms using GICv2, reads the _Interrupt
1797Acknowledge Register_ (`GICC_IAR`). This changes the state of the highest
1798priority pending interrupt from pending to active in the interrupt controller.
1799It returns the value read from the `GICC_IAR`. This value is the id of the
1800interrupt whose state has been changed.
1801
1802In the case of ARM standard platforms using GICv3, if the API is invoked
1803from EL3, the function reads the system register `ICC_IAR0_EL1`, _Interrupt
1804Acknowledge Register group 0_. If the API is invoked from S-EL1, the function
1805reads the system register `ICC_IAR1_EL1`, _Interrupt Acknowledge Register
1806group 1_. The read changes the state of the highest pending interrupt from
1807pending to active in the interrupt controller. The value read is returned
1808and is the id of the interrupt whose state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001809
1810The TSP uses this API to start processing of the secure physical timer
1811interrupt.
1812
1813
1814### Function : plat_ic_end_of_interrupt() [mandatory]
1815
1816 Argument : uint32_t
1817 Return : void
1818
1819This API is used by the CPU to indicate to the platform IC that processing of
1820the interrupt corresponding to the id (passed as the parameter) has
1821finished. The id should be the same as the id returned by the
1822`plat_ic_acknowledge_interrupt()` API.
1823
Dan Handley4a75b842015-03-19 19:24:43 +00001824ARM standard platforms write the id to the _End of Interrupt Register_
Soby Mathew81123e82015-11-23 14:01:21 +00001825(`GICC_EOIR`) in case of GICv2, and to `ICC_EOIR0_EL1` or `ICC_EOIR1_EL1`
1826system register in case of GICv3 depending on where the API is invoked from,
1827EL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001828controller.
1829
1830The TSP uses this API to finish processing of the secure physical timer
1831interrupt.
1832
1833
1834### Function : plat_ic_get_interrupt_type() [mandatory]
1835
1836 Argument : uint32_t
1837 Return : uint32_t
1838
1839This API returns the type of the interrupt id passed as the parameter.
1840`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1841interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1842returned depending upon how the interrupt has been configured by the platform
Soby Mathew81123e82015-11-23 14:01:21 +00001843IC. This API must be invoked at EL3.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001844
Soby Mathew81123e82015-11-23 14:01:21 +00001845ARM standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts
1846and Non-secure interrupts as Group1 interrupts. It reads the group value
1847corresponding to the interrupt id from the relevant _Interrupt Group Register_
1848(`GICD_IGROUPRn`). It uses the group value to determine the type of interrupt.
1849
1850In the case of ARM standard platforms using GICv3, both the _Interrupt Group
1851Register_ (`GICD_IGROUPRn`) and _Interrupt Group Modifier Register_
1852(`GICD_IGRPMODRn`) is read to figure out whether the interrupt is configured
1853as Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt.
Dan Handley4a75b842015-03-19 19:24:43 +00001854
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001855
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +000018563.7 Crash Reporting mechanism (in BL31)
Soby Mathewc67b09b2014-07-14 16:57:23 +01001857----------------------------------------------
Juan Castillod1786372015-12-14 09:35:25 +00001858BL31 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001859of the CPU to enable quick crash analysis and debugging. It requires that a
1860console is designated as the crash console by the platform which will be used to
1861print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001862
Sandrine Bailleux44804252014-08-06 11:27:23 +01001863The following functions must be implemented by the platform if it wants crash
Juan Castillod1786372015-12-14 09:35:25 +00001864reporting mechanism in BL31. The functions are implemented in assembly so that
Sandrine Bailleux44804252014-08-06 11:27:23 +01001865they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001866
1867### Function : plat_crash_console_init
1868
1869 Argument : void
1870 Return : int
1871
Sandrine Bailleux44804252014-08-06 11:27:23 +01001872This API is used by the crash reporting mechanism to initialize the crash
Juan Castillo9400b402015-11-26 14:52:15 +00001873console. It must only use the general purpose registers x0 to x4 to do the
Sandrine Bailleux44804252014-08-06 11:27:23 +01001874initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001875
Soby Mathewc67b09b2014-07-14 16:57:23 +01001876### Function : plat_crash_console_putc
1877
1878 Argument : int
1879 Return : int
1880
1881This API is used by the crash reporting mechanism to print a character on the
Juan Castillo9400b402015-11-26 14:52:15 +00001882designated crash console. It must only use general purpose registers x1 and
Soby Mathewc67b09b2014-07-14 16:57:23 +01001883x2 to do its work. The parameter and the return value are in general purpose
1884register x0.
1885
Soby Mathew27713fb2014-09-08 17:51:01 +010018864. Build flags
1887---------------
1888
Soby Mathew58523c02015-06-08 12:32:50 +01001889* **ENABLE_PLAT_COMPAT**
1890 All the platforms ports conforming to this API specification should define
1891 the build flag `ENABLE_PLAT_COMPAT` to 0 as the compatibility layer should
1892 be disabled. For more details on compatibility layer, refer
1893 [Migration Guide].
1894
Soby Mathew27713fb2014-09-08 17:51:01 +01001895There are some build flags which can be defined by the platform to control
1896inclusion or exclusion of certain BL stages from the FIP image. These flags
1897need to be defined in the platform makefile which will get included by the
1898build system.
1899
Soby Mathew27713fb2014-09-08 17:51:01 +01001900* **NEED_BL33**
1901 By default, this flag is defined `yes` by the build system and `BL33`
1902 build option should be supplied as a build option. The platform has the option
Juan Castillod1786372015-12-14 09:35:25 +00001903 of excluding the BL33 image in the `fip` image by defining this flag to
Soby Mathew27713fb2014-09-08 17:51:01 +01001904 `no`.
1905
19065. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001907-------------
1908
1909To avoid subtle toolchain behavioral dependencies, the header files provided
1910by the compiler are not used. The software is built with the `-nostdinc` flag
1911to ensure no headers are included from the toolchain inadvertently. Instead the
1912required headers are included in the ARM Trusted Firmware source tree. The
1913library only contains those C library definitions required by the local
1914implementation. If more functionality is required, the needed library functions
1915will need to be added to the local implementation.
1916
1917Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1918headers have been cut down in order to simplify the implementation. In order to
1919minimize changes to the header files, the [FreeBSD] layout has been maintained.
1920The generic C library definitions can be found in `include/stdlib` with more
1921system and machine specific declarations in `include/stdlib/sys` and
1922`include/stdlib/machine`.
1923
1924The local C library implementations can be found in `lib/stdlib`. In order to
1925extend the C library these files may need to be modified. It is recommended to
1926use a release version of [FreeBSD] as a starting point.
1927
1928The C library header files in the [FreeBSD] source tree are located in the
1929`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1930can be found in the `sys/<machine-type>` directories. These files define things
1931like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1932port for [FreeBSD] does not yet exist, the machine specific definitions are
1933based on existing machine types with similar properties (for example SPARC64).
1934
1935Where possible, C library function implementations were taken from [FreeBSD]
1936as found in the `lib/libc` directory.
1937
1938A copy of the [FreeBSD] sources can be downloaded with `git`.
1939
1940 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1941
1942
Soby Mathew27713fb2014-09-08 17:51:01 +010019436. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001944-----------------------------
1945
1946In order to improve platform independence and portability an storage abstraction
1947layer is used to load data from non-volatile platform storage.
1948
1949Each platform should register devices and their drivers via the Storage layer.
1950These drivers then need to be initialized by bootloader phases as
1951required in their respective `blx_platform_setup()` functions. Currently
1952storage access is only required by BL1 and BL2 phases. The `load_image()`
1953function uses the storage layer to access non-volatile platform storage.
1954
Dan Handley4a75b842015-03-19 19:24:43 +00001955It is mandatory to implement at least one storage driver. For the ARM
1956development platforms the Firmware Image Package (FIP) driver is provided as
1957the default means to load data from storage (see the "Firmware Image Package"
1958section in the [User Guide]). The storage layer is described in the header file
1959`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001960is in `drivers/io/io_storage.c` and the driver files are located in
1961`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001962
1963Each IO driver must provide `io_dev_*` structures, as described in
1964`drivers/io/io_driver.h`. These are returned via a mandatory registration
1965function that is called on platform initialization. The semi-hosting driver
1966implementation in `io_semihosting.c` can be used as an example.
1967
1968The Storage layer provides mechanisms to initialize storage devices before
1969IO operations are called. The basic operations supported by the layer
1970include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1971Drivers do not have to implement all operations, but each platform must
1972provide at least one driver for a device capable of supporting generic
1973operations such as loading a bootloader image.
1974
1975The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01001976firmware. These images are specified by using their identifiers, as defined in
1977[include/plat/common/platform_def.h] (or a separate header file included from
1978there). The platform layer (`plat_get_image_source()`) then returns a reference
1979to a device and a driver-specific `spec` which will be understood by the driver
1980to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001981
1982The layer is designed in such a way that is it possible to chain drivers with
1983other drivers. For example, file-system drivers may be implemented on top of
1984physical block devices, both represented by IO devices with corresponding
1985drivers. In such a case, the file-system "binding" with the block device may
1986be deferred until the file-system device is initialised.
1987
1988The abstraction currently depends on structures being statically allocated
1989by the drivers and callers, as the system does not yet provide a means of
1990dynamically allocating memory. This may also have the affect of limiting the
1991amount of open resources per driver.
1992
1993
Achin Gupta4f6ad662013-10-25 09:08:21 +01001994- - - - - - - - - - - - - - - - - - - - - - - - - -
1995
Dan Handley4a75b842015-03-19 19:24:43 +00001996_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001997
1998
Yuping Luo6b140412016-01-15 11:17:27 +08001999[ARM GIC Architecture Specification 2.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
2000[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 +00002001[IMF Design Guide]: interrupt-framework-design.md
2002[User Guide]: user-guide.md
2003[FreeBSD]: http://www.freebsd.org
2004[Firmware Design]: firmware-design.md
2005[Power Domain Topology Design]: psci-pd-tree.md
2006[PSCI]: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
2007[Migration Guide]: platform-migration-guide.md
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002008[Firmware Update]: firmware-update.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01002009
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00002010[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
2011[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00002012[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Yatharth Kochar84a5d6d2015-10-27 15:55:18 +00002013[include/common/bl_common.h]: ../include/common/bl_common.h
Dan Handley4a75b842015-03-19 19:24:43 +00002014[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
2015[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01002016[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00002017[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]