blob: 4f842c48d886d5324d96e2ee0042832b0b287172 [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)
11 * [Common optional modifications](#23-common-optional-modifications)
123. [Boot Loader stage specific modifications](#3--modifications-specific-to-a-boot-loader-stage)
13 * [Boot Loader stage 1 (BL1)](#31-boot-loader-stage-1-bl1)
14 * [Boot Loader stage 2 (BL2)](#32-boot-loader-stage-2-bl2)
15 * [Boot Loader stage 3-1 (BL3-1)](#32-boot-loader-stage-3-1-bl3-1)
16 * [PSCI implementation (in BL3-1)](#33-power-state-coordination-interface-in-bl3-1)
17 * [Interrupt Management framework (in BL3-1)](#34--interrupt-management-framework-in-bl3-1)
18 * [Crash Reporting mechanism (in BL3-1)](#35--crash-reporting-mechanism-in-bl3-1)
194. [Build flags](#4--build-flags)
205. [C Library](#5--c-library)
216. [Storage abstraction layer](#6--storage-abstraction-layer)
Achin Gupta4f6ad662013-10-25 09:08:21 +010022
23- - - - - - - - - - - - - - - - - -
24
251. Introduction
26----------------
27
28Porting the ARM Trusted Firmware to a new platform involves making some
29mandatory and optional modifications for both the cold and warm boot paths.
30Modifications consist of:
31
32* Implementing a platform-specific function or variable,
33* Setting up the execution context in a certain way, or
34* Defining certain constants (for example #defines).
35
Dan Handley4a75b842015-03-19 19:24:43 +000036The platform-specific functions and variables are declared in
Dan Handleyb68954c2014-05-29 12:30:24 +010037[include/plat/common/platform.h]. The firmware provides a default implementation
38of variables and functions to fulfill the optional requirements. These
39implementations are all weakly defined; they are provided to ease the porting
40effort. Each platform port can override them with its own implementation if the
41default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010042
Dan Handley4a75b842015-03-19 19:24:43 +000043Platform ports that want to be aligned with standard ARM platforms (for example
44FVP and Juno) may also use [include/plat/arm/common/plat_arm.h] and the
45corresponding source files in `plat/arm/common/`. These provide standard
46implementations for some of the required platform porting functions. However,
47using these functions requires the platform port to implement additional
48ARM standard platform porting functions. These additional functions are not
49documented here.
50
Achin Gupta4f6ad662013-10-25 09:08:21 +010051Some modifications are common to all Boot Loader (BL) stages. Section 2
52discusses these in detail. The subsequent sections discuss the remaining
53modifications for each BL stage in detail.
54
55This document should be read in conjunction with the ARM Trusted Firmware
56[User Guide].
57
58
592. Common modifications
60------------------------
61
62This section covers the modifications that should be made by the platform for
63each BL stage to correctly port the firmware stack. They are categorized as
64either mandatory or optional.
65
66
672.1 Common mandatory modifications
68----------------------------------
69A platform port must enable the Memory Management Unit (MMU) with identity
70mapped page tables, and enable both the instruction and data caches for each BL
Dan Handley4a75b842015-03-19 19:24:43 +000071stage. In ARM standard platforms, each BL stage configures the MMU in
72the platform-specific architecture setup function, `blX_plat_arch_setup()`.
Achin Gupta4f6ad662013-10-25 09:08:21 +010073
Soby Mathewab8707e2015-01-08 18:02:44 +000074If the build option `USE_COHERENT_MEM` is enabled, each platform must allocate a
75block of identity mapped secure memory with Device-nGnRE attributes aligned to
76page boundary (4K) for each BL stage. This memory is identified by the section
77name `tzfw_coherent_mem` so that its possible for the firmware to place
78variables in it using the following C code directive:
Achin Gupta4f6ad662013-10-25 09:08:21 +010079
80 __attribute__ ((section("tzfw_coherent_mem")))
81
82Or alternatively the following assembler code directive:
83
84 .section tzfw_coherent_mem
85
86The `tzfw_coherent_mem` section is used to allocate any data structures that are
87accessed both when a CPU is executing with its MMU and caches enabled, and when
88it's running with its MMU and caches disabled. Examples are given below.
89
90The following variables, functions and constants must be defined by the platform
91for the firmware to work correctly.
92
93
Dan Handleyb68954c2014-05-29 12:30:24 +010094### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +010095
Dan Handleyb68954c2014-05-29 12:30:24 +010096Each platform must ensure that a header file of this name is in the system
97include path with the following constants defined. This may require updating the
Dan Handley4a75b842015-03-19 19:24:43 +000098list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM development
99platforms, this file is found in `plat/arm/board/<plat_name>/include/`.
100
101Platform ports may optionally use the file [include/plat/common/common_def.h],
102which provides typical values for some of the constants below. These values are
103likely to be suitable for all platform ports.
104
105Platform ports that want to be aligned with standard ARM platforms (for example
106FVP and Juno) may also use [include/plat/arm/common/arm_def.h], which provides
107standard values for some of the constants below. However, this requires the
108platform port to define additional platform porting constants in
109`platform_def.h`. These additional constants are not documented here.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110
James Morrisseyba3155b2013-10-29 10:56:46 +0000111* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112
113 Defines the linker format used by the platform, for example
Dan Handley4a75b842015-03-19 19:24:43 +0000114 `elf64-littleaarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115
James Morrisseyba3155b2013-10-29 10:56:46 +0000116* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100117
118 Defines the processor architecture for the linker by the platform, for
Dan Handley4a75b842015-03-19 19:24:43 +0000119 example `aarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100120
James Morrisseyba3155b2013-10-29 10:56:46 +0000121* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122
123 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000124 by [plat/common/aarch64/platform_mp_stack.S] and
125 [plat/common/aarch64/platform_up_stack.S].
126
Dan Handley4a75b842015-03-19 19:24:43 +0000127* **define : CACHE_WRITEBACK_GRANULE**
128
129 Defines the size in bits of the largest cache line across all the cache
130 levels in the platform.
131
James Morrisseyba3155b2013-10-29 10:56:46 +0000132* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100133
134 Defines the character string printed by BL1 upon entry into the `bl1_main()`
135 function.
136
James Morrisseyba3155b2013-10-29 10:56:46 +0000137* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
139 Defines the total number of CPUs implemented by the platform across all
140 clusters in the system.
141
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100142* **#define : PLATFORM_NUM_AFFS**
143
144 Defines the total number of nodes in the affinity heirarchy at all affinity
145 levels used by the platform.
146
Soby Mathew8c32bc22015-02-12 14:45:02 +0000147* **#define : PLATFORM_MAX_AFFLVL**
148
149 Defines the maximum affinity level that the power management operations
150 should apply to. ARMv8-A has support for 4 affinity levels. It is likely
151 that hardware will implement fewer affinity levels. This macro allows the
152 PSCI implementation to consider only those affinity levels in the system
153 that the platform implements. For example, the Base AEM FVP implements two
154 clusters with a configurable number of CPUs. It reports the maximum
155 affinity level as 1, resulting in PSCI power control up to the cluster
156 level.
157
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100158* **#define : BL1_RO_BASE**
159
160 Defines the base address in secure ROM where BL1 originally lives. Must be
161 aligned on a page-size boundary.
162
163* **#define : BL1_RO_LIMIT**
164
165 Defines the maximum address in secure ROM that BL1's actual content (i.e.
166 excluding any data section allocated at runtime) can occupy.
167
168* **#define : BL1_RW_BASE**
169
170 Defines the base address in secure RAM where BL1's read-write data will live
171 at runtime. Must be aligned on a page-size boundary.
172
173* **#define : BL1_RW_LIMIT**
174
175 Defines the maximum address in secure RAM that BL1's read-write data can
176 occupy at runtime.
177
James Morrisseyba3155b2013-10-29 10:56:46 +0000178* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100179
180 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000181 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100182
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100183* **#define : BL2_LIMIT**
184
185 Defines the maximum address in secure RAM that the BL2 image can occupy.
186
James Morrisseyba3155b2013-10-29 10:56:46 +0000187* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100188
189 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000190 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100191
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100192* **#define : BL31_LIMIT**
193
194 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
195
Harry Liebeld265bd72014-01-31 19:04:10 +0000196* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100197
Harry Liebeld265bd72014-01-31 19:04:10 +0000198 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
199 image. Must be aligned on a page-size boundary.
200
Juan Castillo16948ae2015-04-13 17:36:19 +0100201For every image, the platform must define individual identifiers that will be
202used by BL1 or BL2 to load the corresponding image into memory from non-volatile
203storage. For the sake of performance, integer numbers will be used as
204identifiers. The platform will use those identifiers to return the relevant
205information about the image to be loaded (file handler, load address,
206authentication information, etc.). The following image identifiers are
207mandatory:
208
209* **#define : BL2_IMAGE_ID**
210
211 BL2 image identifier, used by BL1 to load BL2.
212
213* **#define : BL31_IMAGE_ID**
214
215 BL3-1 image identifier, used by BL2 to load BL3-1.
216
217* **#define : BL33_IMAGE_ID**
218
219 BL3-3 image identifier, used by BL2 to load BL3-3.
220
221If Trusted Board Boot is enabled, the following certificate identifiers must
222also be defined:
223
224* **#define : BL2_CERT_ID**
225
226 BL2 content certificate identifier, used by BL1 to load the BL2 content
227 certificate.
228
229* **#define : TRUSTED_KEY_CERT_ID**
230
231 Trusted key certificate identifier, used by BL2 to load the trusted key
232 certificate.
233
234* **#define : BL31_KEY_CERT_ID**
235
236 BL3-1 key certificate identifier, used by BL2 to load the BL3-1 key
237 certificate.
238
239* **#define : BL31_CERT_ID**
240
241 BL3-1 content certificate identifier, used by BL2 to load the BL3-1 content
242 certificate.
243
244* **#define : BL33_KEY_CERT_ID**
245
246 BL3-3 key certificate identifier, used by BL2 to load the BL3-3 key
247 certificate.
248
249* **#define : BL33_CERT_ID**
250
251 BL3-3 content certificate identifier, used by BL2 to load the BL3-3 content
252 certificate.
253
Achin Gupta8d35f612015-01-25 22:44:23 +0000254If a BL3-0 image is supported by the platform, the following constants must
255also be defined:
256
Juan Castillo16948ae2015-04-13 17:36:19 +0100257* **#define : BL30_IMAGE_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000258
Juan Castillo16948ae2015-04-13 17:36:19 +0100259 BL3-0 image identifier, used by BL2 to load BL3-0 into secure memory from
260 platform storage before being transfered to the SCP.
Achin Gupta8d35f612015-01-25 22:44:23 +0000261
Juan Castillo16948ae2015-04-13 17:36:19 +0100262* **#define : BL30_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000263
Juan Castillo16948ae2015-04-13 17:36:19 +0100264 BL3-0 key certificate identifier, used by BL2 to load the BL3-0 key
265 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000266
Juan Castillo16948ae2015-04-13 17:36:19 +0100267* **#define : BL30_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000268
Juan Castillo16948ae2015-04-13 17:36:19 +0100269 BL3-0 content certificate identifier, used by BL2 to load the BL3-0 content
270 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000271
Dan Handley5a06bb72014-08-04 11:41:20 +0100272If a BL3-2 image is supported by the platform, the following constants must
273also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100274
Juan Castillo16948ae2015-04-13 17:36:19 +0100275* **#define : BL32_IMAGE_ID**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100276
Juan Castillo16948ae2015-04-13 17:36:19 +0100277 BL3-2 image identifier, used by BL2 to load BL3-2.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100278
Juan Castillo16948ae2015-04-13 17:36:19 +0100279* **#define : BL32_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000280
Juan Castillo16948ae2015-04-13 17:36:19 +0100281 BL3-2 key certificate identifier, used by BL2 to load the BL3-2 key
282 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000283
Juan Castillo16948ae2015-04-13 17:36:19 +0100284* **#define : BL32_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000285
Juan Castillo16948ae2015-04-13 17:36:19 +0100286 BL3-2 content certificate identifier, used by BL2 to load the BL3-2 content
287 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000288
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100289* **#define : BL32_BASE**
290
291 Defines the base address in secure memory where BL2 loads the BL3-2 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100292 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100293
294* **#define : BL32_LIMIT**
295
Dan Handley5a06bb72014-08-04 11:41:20 +0100296 Defines the maximum address that the BL3-2 image can occupy.
297
298If the Test Secure-EL1 Payload (TSP) instantiation of BL3-2 is supported by the
299platform, the following constants must also be defined:
300
301* **#define : TSP_SEC_MEM_BASE**
302
303 Defines the base address of the secure memory used by the TSP image on the
304 platform. This must be at the same address or below `BL32_BASE`.
305
306* **#define : TSP_SEC_MEM_SIZE**
307
308 Defines the size of the secure memory used by the BL3-2 image on the
309 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
310 the memory required by the BL3-2 image, defined by `BL32_BASE` and
311 `BL32_LIMIT`.
312
313* **#define : TSP_IRQ_SEC_PHY_TIMER**
314
315 Defines the ID of the secure physical generic timer interrupt used by the
316 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100317
Dan Handley4a75b842015-03-19 19:24:43 +0000318If the platform port uses the translation table library code, the following
319constant must also be defined:
320
321* **#define : MAX_XLAT_TABLES**
322
323 Defines the maximum number of translation tables that are allocated by the
324 translation table library code. To minimize the amount of runtime memory
325 used, choose the smallest value needed to map the required virtual addresses
326 for each BL stage.
327
Dan Handley6d16ce02014-08-04 18:31:43 +0100328If the platform port uses the IO storage framework, the following constants
329must also be defined:
330
331* **#define : MAX_IO_DEVICES**
332
333 Defines the maximum number of registered IO devices. Attempting to register
334 more devices than this value using `io_register_device()` will fail with
335 IO_RESOURCES_EXHAUSTED.
336
337* **#define : MAX_IO_HANDLES**
338
339 Defines the maximum number of open IO handles. Attempting to open more IO
340 entities than this value using `io_open()` will fail with
341 IO_RESOURCES_EXHAUSTED.
342
Soby Mathewab8707e2015-01-08 18:02:44 +0000343If the platform needs to allocate data within the per-cpu data framework in
344BL3-1, it should define the following macro. Currently this is only required if
345the platform decides not to use the coherent memory section by undefining the
346USE_COHERENT_MEM build flag. In this case, the framework allocates the required
347memory within the the per-cpu data to minimize wastage.
348
349* **#define : PLAT_PCPU_DATA_SIZE**
350
351 Defines the memory (in bytes) to be reserved within the per-cpu data
352 structure for use by the platform layer.
353
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100354The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000355memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100356
357* **#define : BL31_PROGBITS_LIMIT**
358
359 Defines the maximum address in secure RAM that the BL3-1's progbits sections
360 can occupy.
361
Dan Handley5a06bb72014-08-04 11:41:20 +0100362* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100363
364 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100365
Dan Handleyb68954c2014-05-29 12:30:24 +0100366### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100367
Dan Handleyb68954c2014-05-29 12:30:24 +0100368Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000369the following macro defined. In the ARM development platforms, this file is
370found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100371
372* **Macro : plat_print_gic_regs**
373
374 This macro allows the crash reporting routine to print GIC registers
Soby Mathew8c106902014-07-16 09:23:52 +0100375 in case of an unhandled exception in BL3-1. This aids in debugging and
Soby Mathewa43d4312014-04-07 15:28:55 +0100376 this macro can be defined to be empty in case GIC register reporting is
377 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100378
Soby Mathew8c106902014-07-16 09:23:52 +0100379* **Macro : plat_print_interconnect_regs**
380
Dan Handley4a75b842015-03-19 19:24:43 +0000381 This macro allows the crash reporting routine to print interconnect
382 registers in case of an unhandled exception in BL3-1. This aids in debugging
383 and this macro can be defined to be empty in case interconnect register
384 reporting is not desired. In ARM standard platforms, the CCI snoop
385 control registers are reported.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100386
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000387
Vikram Kanigirie452cd82014-05-23 15:56:12 +01003882.2 Handling Reset
389------------------
390
391BL1 by default implements the reset vector where execution starts from a cold
392or warm boot. BL3-1 can be optionally set as a reset vector using the
393RESET_TO_BL31 make variable.
394
395For each CPU, the reset vector code is responsible for the following tasks:
396
3971. Distinguishing between a cold boot and a warm boot.
398
3992. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
400 the CPU is placed in a platform-specific state until the primary CPU
401 performs the necessary steps to remove it from this state.
402
4033. In the case of a warm boot, ensuring that the CPU jumps to a platform-
404 specific address in the BL3-1 image in the same processor mode as it was
405 when released from reset.
406
407The following functions need to be implemented by the platform port to enable
408reset vector code to perform the above tasks.
409
410
411### Function : platform_get_entrypoint() [mandatory]
412
413 Argument : unsigned long
414 Return : unsigned int
415
416This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
417is identified by its `MPIDR`, which is passed as the argument. The function is
418responsible for distinguishing between a warm and cold reset using platform-
419specific means. If it's a warm reset then it returns the entrypoint into the
420BL3-1 image that the CPU must jump to. If it's a cold reset then this function
421must return zero.
422
423This function is also responsible for implementing a platform-specific mechanism
424to handle the condition where the CPU has been warm reset but there is no
425entrypoint to jump to.
426
427This function does not follow the Procedure Call Standard used by the
428Application Binary Interface for the ARM 64-bit architecture. The caller should
429not assume that callee saved registers are preserved across a call to this
430function.
431
432This function fulfills requirement 1 and 3 listed above.
433
434
435### Function : plat_secondary_cold_boot_setup() [mandatory]
436
437 Argument : void
438 Return : void
439
440This function is called with the MMU and data caches disabled. It is responsible
441for placing the executing secondary CPU in a platform-specific state until the
442primary CPU performs the necessary actions to bring it out of that state and
Sandrine Bailleux52010cc2015-05-19 11:54:45 +0100443allow entry into the OS. This function must not return.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100444
445In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
446responsible for powering up the secondary CPU when normal world software
447requires them.
448
449This function fulfills requirement 2 above.
450
451
Juan Castillo53fdceb2014-07-16 15:53:43 +0100452### Function : platform_is_primary_cpu() [mandatory]
453
454 Argument : unsigned long
455 Return : unsigned int
456
457This function identifies a CPU by its `MPIDR`, which is passed as the argument,
458to determine whether this CPU is the primary CPU or a secondary CPU. A return
459value of zero indicates that the CPU is not the primary CPU, while a non-zero
460return value indicates that the CPU is the primary CPU.
461
462
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100463### Function : platform_mem_init() [mandatory]
464
465 Argument : void
466 Return : void
467
468This function is called before any access to data is made by the firmware, in
469order to carry out any essential memory initialization.
470
471The ARM FVP port uses this function to initialize the mailbox memory used for
472providing the warm-boot entry-point addresses.
473
474
Juan Castillo6eadf762015-01-07 10:39:25 +0000475### Function: plat_match_rotpk()
476
477 Argument : const unsigned char *, unsigned int
478 Return : int
479
480This function is mandatory when Trusted Board Boot is enabled. It receives a
481pointer to a buffer containing a signing key and its size as parameters and
482returns 0 (success) if that key matches the ROT (Root Of Trust) key stored in
483the platform. Any other return value means a mismatch.
484
485
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100486
4872.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100488---------------------------------
489
490The following are helper functions implemented by the firmware that perform
491common platform-specific tasks. A platform may choose to override these
492definitions.
493
494
495### Function : platform_get_core_pos()
496
497 Argument : unsigned long
498 Return : int
499
500A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
501can be used as a CPU-specific linear index into blocks of memory (for example
502while allocating per-CPU stacks). This routine contains a simple mechanism
503to perform this conversion, using the assumption that each cluster contains a
504maximum of 4 CPUs:
505
506 linear index = cpu_id + (cluster_id * 4)
507
508 cpu_id = 8-bit value in MPIDR at affinity level 0
509 cluster_id = 8-bit value in MPIDR at affinity level 1
510
511
Achin Gupta4f6ad662013-10-25 09:08:21 +0100512### Function : platform_set_stack()
513
514 Argument : unsigned long
515 Return : void
516
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000517This function sets the current stack pointer to the normal memory stack that
518has been allocated for the CPU specificed by MPIDR. For BL images that only
519require a stack for the primary CPU the parameter is ignored. The size of
520the stack allocated to each CPU is specified by the platform defined constant
521`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100522
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000523Common implementations of this function for the UP and MP BL images are
524provided in [plat/common/aarch64/platform_up_stack.S] and
525[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100526
527
Achin Guptac8afc782013-11-25 18:45:02 +0000528### Function : platform_get_stack()
529
530 Argument : unsigned long
531 Return : unsigned long
532
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000533This function returns the base address of the normal memory stack that
534has been allocated for the CPU specificed by MPIDR. For BL images that only
535require a stack for the primary CPU the parameter is ignored. The size of
536the stack allocated to each CPU is specified by the platform defined constant
537`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000538
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000539Common implementations of this function for the UP and MP BL images are
540provided in [plat/common/aarch64/platform_up_stack.S] and
541[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000542
543
Achin Gupta4f6ad662013-10-25 09:08:21 +0100544### Function : plat_report_exception()
545
546 Argument : unsigned int
547 Return : void
548
549A platform may need to report various information about its status when an
550exception is taken, for example the current exception level, the CPU security
551state (secure/non-secure), the exception type, and so on. This function is
552called in the following circumstances:
553
554* In BL1, whenever an exception is taken.
555* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100556
557The default implementation doesn't do anything, to avoid making assumptions
558about the way the platform displays its status information.
559
560This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000561exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100562that these constants are not related to any architectural exception code; they
563are just an ARM Trusted Firmware convention.
564
565
Soby Mathew24fb8382014-08-14 12:22:32 +0100566### Function : plat_reset_handler()
567
568 Argument : void
569 Return : void
570
571A platform may need to do additional initialization after reset. This function
572allows the platform to do the platform specific intializations. Platform
573specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000574preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100575
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000576The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000577the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100578guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100579
Soby Mathewadd40352014-08-14 12:49:05 +0100580### Function : plat_disable_acp()
581
582 Argument : void
583 Return : void
584
585This api allows a platform to disable the Accelerator Coherency Port (if
586present) during a cluster power down sequence. The default weak implementation
587doesn't do anything. Since this api is called during the power down sequence,
588it has restrictions for stack usage and it can use the registers x0 - x17 as
589scratch registers. It should preserve the value in x18 register as it is used
590by the caller to store the return address.
591
Soby Mathew24fb8382014-08-14 12:22:32 +0100592
Achin Gupta4f6ad662013-10-25 09:08:21 +01005933. Modifications specific to a Boot Loader stage
594-------------------------------------------------
595
5963.1 Boot Loader Stage 1 (BL1)
597-----------------------------
598
599BL1 implements the reset vector where execution starts from after a cold or
600warm boot. For each CPU, BL1 is responsible for the following tasks:
601
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006021. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100603
6042. In the case of a cold boot and the CPU being the primary CPU, ensuring that
605 only this CPU executes the remaining BL1 code, including loading and passing
606 control to the BL2 stage.
607
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006083. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100609 address specified by the platform defined constant `BL2_BASE`.
610
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006114. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100612 accessible by BL2 immediately upon entry.
613
614 meminfo.total_base = Base address of secure RAM visible to BL2
615 meminfo.total_size = Size of secure RAM visible to BL2
616 meminfo.free_base = Base address of secure RAM available for
617 allocation to BL2
618 meminfo.free_size = Size of secure RAM available for allocation to BL2
619
620 BL1 places this `meminfo` structure at the beginning of the free memory
621 available for its use. Since BL1 cannot allocate memory dynamically at the
622 moment, its free memory will be available for BL2's use as-is. However, this
623 means that BL2 must read the `meminfo` structure before it starts using its
624 free memory (this is discussed in Section 3.2).
625
626 In future releases of the ARM Trusted Firmware it will be possible for
627 the platform to decide where it wants to place the `meminfo` structure for
628 BL2.
629
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100630 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100631 BL2 `meminfo` structure. The platform may override this implementation, for
632 example if the platform wants to restrict the amount of memory visible to
633 BL2. Details of how to do this are given below.
634
635The following functions need to be implemented by the platform port to enable
636BL1 to perform the above tasks.
637
638
Dan Handley4a75b842015-03-19 19:24:43 +0000639### Function : bl1_early_platform_setup() [mandatory]
640
641 Argument : void
642 Return : void
643
644This function executes with the MMU and data caches disabled. It is only called
645by the primary CPU.
646
647In ARM standard platforms, this function initializes the console and enables
648snoop requests into the primary CPU's cluster.
649
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100650### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100651
652 Argument : void
653 Return : void
654
Achin Gupta4f6ad662013-10-25 09:08:21 +0100655This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000656platform requires. Platform-specific setup might include configuration of
657memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100658
Dan Handley4a75b842015-03-19 19:24:43 +0000659In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100660
661This function helps fulfill requirement 2 above.
662
663
664### Function : bl1_platform_setup() [mandatory]
665
666 Argument : void
667 Return : void
668
669This function executes with the MMU and data caches enabled. It is responsible
670for performing any remaining platform-specific setup that can occur after the
671MMU and data cache have been enabled.
672
Dan Handley4a75b842015-03-19 19:24:43 +0000673In ARM standard platforms, this function initializes the storage abstraction
674layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000675
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100676This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100677
678
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000679### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100680
681 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000682 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100683
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000684This function should only be called on the cold boot path. It executes with the
685MMU and data caches enabled. The pointer returned by this function must point to
686a `meminfo` structure containing the extents and availability of secure RAM for
687the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100688
689 meminfo.total_base = Base address of secure RAM visible to BL1
690 meminfo.total_size = Size of secure RAM visible to BL1
691 meminfo.free_base = Base address of secure RAM available for allocation
692 to BL1
693 meminfo.free_size = Size of secure RAM available for allocation to BL1
694
695This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
696populates a similar structure to tell BL2 the extents of memory available for
697its own use.
698
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100699This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100700
701
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100702### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100703
704 Argument : meminfo *, meminfo *, unsigned int, unsigned long
705 Return : void
706
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100707BL1 needs to tell the next stage the amount of secure RAM available
708for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100709structure.
710
711Depending upon where BL2 has been loaded in secure RAM (determined by
712`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
713BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000714to BL2. An illustration of how this is done in ARM standard platforms is given
715in the **Memory layout on ARM development platforms** section in the
716[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100717
718
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100719### Function : bl1_plat_set_bl2_ep_info() [mandatory]
720
721 Argument : image_info *, entry_point_info *
722 Return : void
723
724This function is called after loading BL2 image and it can be used to overwrite
725the entry point set by loader and also set the security state and SPSR which
726represents the entry point system state for BL2.
727
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100728
Achin Gupta4f6ad662013-10-25 09:08:21 +01007293.2 Boot Loader Stage 2 (BL2)
730-----------------------------
731
732The BL2 stage is executed only by the primary CPU, which is determined in BL1
733using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
734`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
735
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007361. (Optional) Loading the BL3-0 binary image (if present) from platform
737 provided non-volatile storage. To load the BL3-0 image, BL2 makes use of
738 the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function.
739 The platform also defines the address in memory where BL3-0 is loaded
740 through the optional constant `BL30_BASE`. BL2 uses this information
741 to determine if there is enough memory to load the BL3-0 image.
742 Subsequent handling of the BL3-0 image is platform-specific and is
743 implemented in the `bl2_plat_handle_bl30()` function.
744 If `BL30_BASE` is not defined then this step is not performed.
745
7462. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
Harry Liebeld265bd72014-01-31 19:04:10 +0000747 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
748 by BL1. This structure allows BL2 to calculate how much secure RAM is
749 available for its use. The platform also defines the address in secure RAM
750 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
751 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100752
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007533. (Optional) Loading the BL3-2 binary image (if present) from platform
Dan Handley1151c822014-04-15 11:38:38 +0100754 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100755 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
756 The platform also defines the address in memory where BL3-2 is loaded
757 through the optional constant `BL32_BASE`. BL2 uses this information
758 to determine if there is enough memory to load the BL3-2 image.
759 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000760
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007614. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100762 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100763 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100764 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000765
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007665. Loading the normal world BL3-3 binary image into non-secure DRAM from
767 platform storage and arranging for BL3-1 to pass control to this image. This
768 address is determined using the `plat_get_ns_image_entrypoint()` function
769 described below.
770
7716. BL2 populates an `entry_point_info` structure in memory provided by the
772 platform with information about how BL3-1 should pass control to the
773 other BL images.
774
Achin Gupta4f6ad662013-10-25 09:08:21 +0100775The following functions must be implemented by the platform port to enable BL2
776to perform the above tasks.
777
778
779### Function : bl2_early_platform_setup() [mandatory]
780
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100781 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100782 Return : void
783
784This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100785by the primary CPU. The arguments to this function is the address of the
786`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100787
788The platform must copy the contents of the `meminfo` structure into a private
789variable as the original memory may be subsequently overwritten by BL2. The
790copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000791`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100792
Dan Handley4a75b842015-03-19 19:24:43 +0000793In ARM standard platforms, this function also initializes the storage
794abstraction layer used to load further bootloader images. It is necessary to do
795this early on platforms with a BL3-0 image, since the later `bl2_platform_setup`
796must be done after BL3-0 is loaded.
797
Achin Gupta4f6ad662013-10-25 09:08:21 +0100798
799### Function : bl2_plat_arch_setup() [mandatory]
800
801 Argument : void
802 Return : void
803
804This function executes with the MMU and data caches disabled. It is only called
805by the primary CPU.
806
807The purpose of this function is to perform any architectural initialization
808that varies across platforms, for example enabling the MMU (since the memory
809map differs across platforms).
810
811
812### Function : bl2_platform_setup() [mandatory]
813
814 Argument : void
815 Return : void
816
817This function may execute with the MMU and data caches enabled if the platform
818port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
819called by the primary CPU.
820
Achin Guptae4d084e2014-02-19 17:18:23 +0000821The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +0000822specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +0100823
Dan Handley4a75b842015-03-19 19:24:43 +0000824In ARM standard platforms, this function performs security setup, including
825configuration of the TrustZone controller to allow non-secure masters access
826to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +0000827
Achin Gupta4f6ad662013-10-25 09:08:21 +0100828
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000829### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100830
831 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000832 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100833
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000834This function should only be called on the cold boot path. It may execute with
835the MMU and data caches enabled if the platform port does the necessary
836initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100837
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000838The purpose of this function is to return a pointer to a `meminfo` structure
839populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100840`bl2_early_platform_setup()` above.
841
842
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100843### Function : bl2_plat_get_bl30_meminfo() [mandatory]
844
845 Argument : meminfo *
846 Return : void
847
848This function is used to get the memory limits where BL2 can load the
849BL3-0 image. The meminfo provided by this is used by load_image() to
850validate whether the BL3-0 image can be loaded within the given
851memory from the given base.
852
853
854### Function : bl2_plat_handle_bl30() [mandatory]
855
856 Argument : image_info *
857 Return : int
858
859This function is called after loading BL3-0 image and it is used to perform any
860platform-specific actions required to handle the SCP firmware. Typically it
861transfers the image into SCP memory using a platform-specific protocol and waits
862until SCP executes it and signals to the Application Processor (AP) for BL2
863execution to continue.
864
865This function returns 0 on success, a negative error code otherwise.
866
867
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100868### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000869
870 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100871 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000872
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100873BL2 platform code needs to return a pointer to a `bl31_params` structure it
874will use for passing information to BL3-1. The `bl31_params` structure carries
875the following information.
876 - Header describing the version information for interpreting the bl31_param
877 structure
878 - Information about executing the BL3-3 image in the `bl33_ep_info` field
879 - Information about executing the BL3-2 image in the `bl32_ep_info` field
880 - Information about the type and extents of BL3-1 image in the
881 `bl31_image_info` field
882 - Information about the type and extents of BL3-2 image in the
883 `bl32_image_info` field
884 - Information about the type and extents of BL3-3 image in the
885 `bl33_image_info` field
886
887The memory pointed by this structure and its sub-structures should be
888accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
889necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000890
891
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100892### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100893
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100894 Argument : void
895 Return : entry_point_info *
896
897BL2 platform code returns a pointer which is used to populate the entry point
898information for BL3-1 entry point. The location pointed by it should be
899accessible from BL1 while processing the synchronous exception to run to BL3-1.
900
Dan Handley4a75b842015-03-19 19:24:43 +0000901In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
902structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100903
904
905### Function : bl2_plat_set_bl31_ep_info() [mandatory]
906
907 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100908 Return : void
909
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100910This function is called after loading BL3-1 image and it can be used to
911overwrite the entry point set by loader and also set the security state
912and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100913
Achin Gupta4f6ad662013-10-25 09:08:21 +0100914
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100915### Function : bl2_plat_set_bl32_ep_info() [mandatory]
916
917 Argument : image_info *, entry_point_info *
918 Return : void
919
920This function is called after loading BL3-2 image and it can be used to
921overwrite the entry point set by loader and also set the security state
922and SPSR which represents the entry point system state for BL3-2.
923
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100924
925### Function : bl2_plat_set_bl33_ep_info() [mandatory]
926
927 Argument : image_info *, entry_point_info *
928 Return : void
929
930This function is called after loading BL3-3 image and it can be used to
931overwrite the entry point set by loader and also set the security state
932and SPSR which represents the entry point system state for BL3-3.
933
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100934
935### Function : bl2_plat_get_bl32_meminfo() [mandatory]
936
937 Argument : meminfo *
938 Return : void
939
940This function is used to get the memory limits where BL2 can load the
941BL3-2 image. The meminfo provided by this is used by load_image() to
942validate whether the BL3-2 image can be loaded with in the given
943memory from the given base.
944
945### Function : bl2_plat_get_bl33_meminfo() [mandatory]
946
947 Argument : meminfo *
948 Return : void
949
950This function is used to get the memory limits where BL2 can load the
951BL3-3 image. The meminfo provided by this is used by load_image() to
952validate whether the BL3-3 image can be loaded with in the given
953memory from the given base.
954
955### Function : bl2_plat_flush_bl31_params() [mandatory]
956
957 Argument : void
958 Return : void
959
960Once BL2 has populated all the structures that needs to be read by BL1
961and BL3-1 including the bl31_params structures and its sub-structures,
962the bl31_ep_info structure and any platform specific data. It flushes
963all these data to the main memory so that it is available when we jump to
964later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100965
966### Function : plat_get_ns_image_entrypoint() [mandatory]
967
968 Argument : void
969 Return : unsigned long
970
971As previously described, BL2 is responsible for arranging for control to be
972passed to a normal world BL image through BL3-1. This function returns the
973entrypoint of that image, which BL3-1 uses to jump to it.
974
Harry Liebeld265bd72014-01-31 19:04:10 +0000975BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100976
977
9783.2 Boot Loader Stage 3-1 (BL3-1)
979---------------------------------
980
981During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
982determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
983control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
984CPUs. BL3-1 executes at EL3 and is responsible for:
985
9861. Re-initializing all architectural and platform state. Although BL1 performs
987 some of this initialization, BL3-1 remains resident in EL3 and must ensure
988 that EL3 architectural and platform state is completely initialized. It
989 should make no assumptions about the system state when it receives control.
990
9912. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100992 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100993 populated in memory to do this.
994
9953. Providing runtime firmware services. Currently, BL3-1 only implements a
996 subset of the Power State Coordination Interface (PSCI) API as a runtime
997 service. See Section 3.3 below for details of porting the PSCI
998 implementation.
999
Achin Gupta35ca3512014-02-19 17:58:33 +000010004. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
1001 specific address by BL2. BL3-1 exports a set of apis that allow runtime
1002 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001003 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
1004 structure populated by BL2 to do this.
1005
1006If BL3-1 is a reset vector, It also needs to handle the reset as specified in
1007section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001008
Achin Gupta4f6ad662013-10-25 09:08:21 +01001009The following functions must be implemented by the platform port to enable BL3-1
1010to perform the above tasks.
1011
1012
1013### Function : bl31_early_platform_setup() [mandatory]
1014
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001015 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001016 Return : void
1017
1018This function executes with the MMU and data caches disabled. It is only called
1019by the primary CPU. The arguments to this function are:
1020
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001021* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001022* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001023
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001024The platform can copy the contents of the `bl31_params` structure and its
1025sub-structures into private variables if the original memory may be
1026subsequently overwritten by BL3-1 and similarly the `void *` pointing
1027to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001028
Dan Handley4a75b842015-03-19 19:24:43 +00001029In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
1030in BL2 memory. BL3-1 copies the information in this pointer to internal data
1031structures.
1032
Achin Gupta4f6ad662013-10-25 09:08:21 +01001033
1034### Function : bl31_plat_arch_setup() [mandatory]
1035
1036 Argument : void
1037 Return : void
1038
1039This function executes with the MMU and data caches disabled. It is only called
1040by the primary CPU.
1041
1042The purpose of this function is to perform any architectural initialization
1043that varies across platforms, for example enabling the MMU (since the memory
1044map differs across platforms).
1045
1046
1047### Function : bl31_platform_setup() [mandatory]
1048
1049 Argument : void
1050 Return : void
1051
1052This function may execute with the MMU and data caches enabled if the platform
1053port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1054called by the primary CPU.
1055
1056The purpose of this function is to complete platform initialization so that both
1057BL3-1 runtime services and normal world software can function correctly.
1058
Dan Handley4a75b842015-03-19 19:24:43 +00001059In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001060* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001061* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001062* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001063* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001064* Detects the system topology.
1065
1066
1067### Function : bl31_get_next_image_info() [mandatory]
1068
Achin Gupta35ca3512014-02-19 17:58:33 +00001069 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001070 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001071
1072This function may execute with the MMU and data caches enabled if the platform
1073port does the necessary initializations in `bl31_plat_arch_setup()`.
1074
1075This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +00001076BL2 for the next image in the security state specified by the argument. BL3-1
1077uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001078state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001079(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1080should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001081
Dan Handley4a75b842015-03-19 19:24:43 +00001082### Function : plat_get_syscnt_freq() [mandatory]
1083
1084 Argument : void
1085 Return : uint64_t
1086
1087This function is used by the architecture setup code to retrieve the counter
1088frequency for the CPU's generic timer. This value will be programmed into the
1089`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1090of the system counter, which is retrieved from the first entry in the frequency
1091modes table.
1092
Achin Gupta4f6ad662013-10-25 09:08:21 +01001093
Achin Gupta4f6ad662013-10-25 09:08:21 +010010943.3 Power State Coordination Interface (in BL3-1)
1095------------------------------------------------
1096
1097The ARM Trusted Firmware's implementation of the PSCI API is based around the
1098concept of an _affinity instance_. Each _affinity instance_ can be uniquely
1099identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
1100interface) and an _affinity level_. A processing element (for example, a
1101CPU) is at level 0. If the CPUs in the system are described in a tree where the
1102node above a CPU is a logical grouping of CPUs that share some state, then
1103affinity level 1 is that group of CPUs (for example, a cluster), and affinity
1104level 2 is a group of clusters (for example, the system). The implementation
1105assumes that the affinity level 1 ID can be computed from the affinity level 0
1106ID (for example, a unique cluster ID can be computed from the CPU ID). The
1107current implementation computes this on the basis of the recommended use of
1108`MPIDR` affinity fields in the ARM Architecture Reference Manual.
1109
1110BL3-1's platform initialization code exports a pointer to the platform-specific
1111power management operations required for the PSCI implementation to function
1112correctly. This information is populated in the `plat_pm_ops` structure. The
1113PSCI implementation calls members of the `plat_pm_ops` structure for performing
1114power management operations for each affinity instance. For example, the target
1115CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
1116handler (if present) is called for each affinity instance as the PSCI
1117implementation powers up each affinity level implemented in the `MPIDR` (for
1118example, CPU, cluster and system).
1119
1120The following functions must be implemented to initialize PSCI functionality in
1121the ARM Trusted Firmware.
1122
1123
1124### Function : plat_get_aff_count() [mandatory]
1125
1126 Argument : unsigned int, unsigned long
1127 Return : unsigned int
1128
1129This function may execute with the MMU and data caches enabled if the platform
1130port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1131called by the primary CPU.
1132
1133This function is called by the PSCI initialization code to detect the system
1134topology. Its purpose is to return the number of affinity instances implemented
1135at a given `affinity level` (specified by the first argument) and a given
1136`MPIDR` (specified by the second argument). For example, on a dual-cluster
1137system where first cluster implements 2 CPUs and the second cluster implements 4
1138CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
1139(`0x0`) and affinity level 0, would return 2. A call to this function with an
1140`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
1141would return 4.
1142
1143
1144### Function : plat_get_aff_state() [mandatory]
1145
1146 Argument : unsigned int, unsigned long
1147 Return : unsigned int
1148
1149This function may execute with the MMU and data caches enabled if the platform
1150port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1151called by the primary CPU.
1152
1153This function is called by the PSCI initialization code. Its purpose is to
1154return the state of an affinity instance. The affinity instance is determined by
1155the affinity ID at a given `affinity level` (specified by the first argument)
1156and an `MPIDR` (specified by the second argument). The state can be one of
1157`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
1158system topologies where certain affinity instances are unimplemented. For
1159example, consider a platform that implements a single cluster with 4 CPUs and
1160another CPU implemented directly on the interconnect with the cluster. The
1161`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
1162CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
1163is missing but needs to be accounted for to reach this single CPU in the
1164topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
1165
1166
Achin Gupta4f6ad662013-10-25 09:08:21 +01001167### Function : platform_setup_pm() [mandatory]
1168
Sandrine Bailleux44804252014-08-06 11:27:23 +01001169 Argument : const plat_pm_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001170 Return : int
1171
1172This function may execute with the MMU and data caches enabled if the platform
1173port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1174called by the primary CPU.
1175
1176This function is called by PSCI initialization code. Its purpose is to export
1177handler routines for platform-specific power management actions by populating
1178the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1179
1180A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001181the ARM FVP specific implementation of these handlers in
1182[plat/arm/board/fvp/fvp_pm.c] as an example. A platform port is expected to
1183implement these handlers if the corresponding PSCI operation is to be supported
1184and these handlers are expected to succeed if the return type is `void`.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001185
1186#### plat_pm_ops.affinst_standby()
1187
1188Perform the platform-specific setup to enter the standby state indicated by the
Soby Mathew539dced2014-10-02 16:56:51 +01001189passed argument. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001190
1191#### plat_pm_ops.affinst_on()
1192
1193Perform the platform specific setup to power on an affinity instance, specified
Soby Mathewe146f4c2014-09-26 15:08:52 +01001194by the `MPIDR` (first argument) and `affinity level` (third argument). The
1195`state` (fourth argument) contains the current state of that affinity instance
Achin Gupta4f6ad662013-10-25 09:08:21 +01001196(ON or OFF). This is useful to determine whether any action must be taken. For
1197example, while powering on a CPU, the cluster that contains this CPU might
1198already be in the ON state. The platform decides what actions must be taken to
1199transition from the current state to the target state (indicated by the power
Soby Mathew539dced2014-10-02 16:56:51 +01001200management operation). The generic code expects the platform to return
1201E_SUCCESS on success or E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001202
1203#### plat_pm_ops.affinst_off()
1204
Soby Mathewe146f4c2014-09-26 15:08:52 +01001205Perform the platform specific setup to power off an affinity instance of the
1206calling CPU. It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001207
Soby Mathewe146f4c2014-09-26 15:08:52 +01001208The `affinity level` (first argument) and `state` (second argument) have
1209a similar meaning as described in the `affinst_on()` operation. They are
1210used to identify the affinity instance on which the call is made and its
1211current state. This gives the platform port an indication of the
Achin Gupta4f6ad662013-10-25 09:08:21 +01001212state transition it must make to perform the requested action. For example, if
1213the calling CPU is the last powered on CPU in the cluster, after powering down
1214affinity level 0 (CPU), the platform port should power down affinity level 1
Soby Mathew539dced2014-10-02 16:56:51 +01001215(the cluster) as well. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001216
Achin Gupta4f6ad662013-10-25 09:08:21 +01001217#### plat_pm_ops.affinst_suspend()
1218
Soby Mathewe146f4c2014-09-26 15:08:52 +01001219Perform the platform specific setup to power off an affinity instance of the
1220calling CPU. It is called by the PSCI `CPU_SUSPEND` API
Achin Gupta4f6ad662013-10-25 09:08:21 +01001221implementation.
1222
Soby Mathewe146f4c2014-09-26 15:08:52 +01001223The `affinity level` (second argument) and `state` (third argument) have a
1224similar meaning as described in the `affinst_on()` operation. They are used to
1225identify the affinity instance on which the call is made and its current state.
1226This gives the platform port an indication of the state transition it must
1227make to perform the requested action. For example, if the calling CPU is the
1228last powered on CPU in the cluster, after powering down affinity level 0 (CPU),
1229the platform port should power down affinity level 1 (the cluster) as well.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001230
1231The difference between turning an affinity instance off versus suspending it
1232is that in the former case, the affinity instance is expected to re-initialize
1233its state when its next powered on (see `affinst_on_finish()`). In the latter
1234case, the affinity instance is expected to save enough state so that it can
1235resume execution by restoring this state when its powered on (see
Soby Mathew539dced2014-10-02 16:56:51 +01001236`affinst_suspend_finish()`).The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001237
Achin Gupta4f6ad662013-10-25 09:08:21 +01001238#### plat_pm_ops.affinst_on_finish()
1239
1240This function is called by the PSCI implementation after the calling CPU is
1241powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1242It performs the platform-specific setup required to initialize enough state for
1243this CPU to enter the normal world and also provide secure runtime firmware
1244services.
1245
Soby Mathewe146f4c2014-09-26 15:08:52 +01001246The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001247similar meaning as described in the previous operations. The generic code
1248expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001249
Achin Gupta4f6ad662013-10-25 09:08:21 +01001250#### plat_pm_ops.affinst_on_suspend()
1251
1252This function is called by the PSCI implementation after the calling CPU is
1253powered on and released from reset in response to an asynchronous wakeup
1254event, for example a timer interrupt that was programmed by the CPU during the
1255`CPU_SUSPEND` call. It performs the platform-specific setup required to
1256restore the saved state for this CPU to resume execution in the normal world
1257and also provide secure runtime firmware services.
1258
Soby Mathewe146f4c2014-09-26 15:08:52 +01001259The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001260similar meaning as described in the previous operations. The generic code
1261expects the platform to succeed.
1262
1263#### plat_pm_ops.validate_power_state()
1264
1265This function is called by the PSCI implementation during the `CPU_SUSPEND`
1266call to validate the `power_state` parameter of the PSCI API. If the
1267`power_state` is known to be invalid, the platform must return
1268PSCI_E_INVALID_PARAMS as error, which is propagated back to the normal
1269world PSCI client.
1270
1271#### plat_pm_ops.validate_ns_entrypoint()
1272
1273This function is called by the PSCI implementation during the `CPU_SUSPEND`
1274and `CPU_ON` calls to validate the non-secure `entry_point` parameter passed
1275by the normal world. If the `entry_point` is known to be invalid, the platform
1276must return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1277normal world PSCI client.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001278
Achin Gupta4f6ad662013-10-25 09:08:21 +01001279BL3-1 platform initialization code must also detect the system topology and
1280the state of each affinity instance in the topology. This information is
1281critical for the PSCI runtime service to function correctly. More details are
1282provided in the description of the `plat_get_aff_count()` and
1283`plat_get_aff_state()` functions above.
1284
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010012853.4 Interrupt Management framework (in BL3-1)
1286----------------------------------------------
1287BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1288generated in either security state and targeted to EL1 or EL2 in the non-secure
1289state or EL3/S-EL1 in the secure state. The design of this framework is
1290described in the [IMF Design Guide]
1291
1292A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001293text briefly describes each api and its implementation in ARM standard
1294platforms. The API implementation depends upon the type of interrupt controller
1295present in the platform. ARM standard platforms implements an ARM Generic
1296Interrupt Controller (ARM GIC) as per the version 2.0 of the
1297[ARM GIC Architecture Specification].
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001298
1299### Function : plat_interrupt_type_to_line() [mandatory]
1300
1301 Argument : uint32_t, uint32_t
1302 Return : uint32_t
1303
1304The ARM processor signals an interrupt exception either through the IRQ or FIQ
1305interrupt line. The specific line that is signaled depends on how the interrupt
1306controller (IC) reports different interrupt types from an execution context in
1307either security state. The IMF uses this API to determine which interrupt line
1308the platform IC uses to signal each type of interrupt supported by the framework
1309from a given security state.
1310
1311The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1312Guide]) indicating the target type of the interrupt, the second parameter is the
1313security state of the originating execution context. The return result is the
1314bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1315FIQ=2.
1316
Dan Handley4a75b842015-03-19 19:24:43 +00001317ARM standard platforms configure the ARM GIC to signal S-EL1 interrupts
1318as FIQs and Non-secure interrupts as IRQs from either security state.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001319
1320
1321### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1322
1323 Argument : void
1324 Return : uint32_t
1325
1326This API returns the type of the highest priority pending interrupt at the
1327platform IC. The IMF uses the interrupt type to retrieve the corresponding
1328handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1329pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1330`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1331
Dan Handley4a75b842015-03-19 19:24:43 +00001332ARM standard platforms read the _Highest Priority Pending Interrupt
1333Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The type
1334of interrupt depends upon the id value as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001335
13361. id < 1022 is reported as a S-EL1 interrupt
13372. id = 1022 is reported as a Non-secure interrupt.
13383. id = 1023 is reported as an invalid interrupt type.
1339
1340
1341### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1342
1343 Argument : void
1344 Return : uint32_t
1345
1346This API returns the id of the highest priority pending interrupt at the
1347platform IC. The IMF passes the id returned by this API to the registered
1348handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1349is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1350
Dan Handley4a75b842015-03-19 19:24:43 +00001351ARM standard platforms read the _Highest Priority Pending Interrupt
1352Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The id
1353that is returned by API depends upon the value of the id read from the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001354controller as follows.
1355
13561. id < 1022. id is returned as is.
13572. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1358 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1359 id is returned by the API.
13603. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1361
1362
1363### Function : plat_ic_acknowledge_interrupt() [mandatory]
1364
1365 Argument : void
1366 Return : uint32_t
1367
1368This API is used by the CPU to indicate to the platform IC that processing of
1369the highest pending interrupt has begun. It should return the id of the
1370interrupt which is being processed.
1371
Dan Handley4a75b842015-03-19 19:24:43 +00001372This function in ARM standard platforms reads the _Interrupt Acknowledge
1373Register_ (`GICC_IAR`). This changes the state of the highest priority pending
1374interrupt from pending to active in the interrupt controller. It returns the
1375value read from the `GICC_IAR`. This value is the id of the interrupt whose
1376state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001377
1378The TSP uses this API to start processing of the secure physical timer
1379interrupt.
1380
1381
1382### Function : plat_ic_end_of_interrupt() [mandatory]
1383
1384 Argument : uint32_t
1385 Return : void
1386
1387This API is used by the CPU to indicate to the platform IC that processing of
1388the interrupt corresponding to the id (passed as the parameter) has
1389finished. The id should be the same as the id returned by the
1390`plat_ic_acknowledge_interrupt()` API.
1391
Dan Handley4a75b842015-03-19 19:24:43 +00001392ARM standard platforms write the id to the _End of Interrupt Register_
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001393(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1394controller.
1395
1396The TSP uses this API to finish processing of the secure physical timer
1397interrupt.
1398
1399
1400### Function : plat_ic_get_interrupt_type() [mandatory]
1401
1402 Argument : uint32_t
1403 Return : uint32_t
1404
1405This API returns the type of the interrupt id passed as the parameter.
1406`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1407interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1408returned depending upon how the interrupt has been configured by the platform
1409IC.
1410
Dan Handley4a75b842015-03-19 19:24:43 +00001411This function in ARM standard platforms configures S-EL1 interrupts
1412as Group0 interrupts and Non-secure interrupts as Group1 interrupts. It reads
1413the group value corresponding to the interrupt id from the relevant _Interrupt
1414Group Register_ (`GICD_IGROUPRn`). It uses the group value to determine the
1415type of interrupt.
1416
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001417
Soby Mathewc67b09b2014-07-14 16:57:23 +010014183.5 Crash Reporting mechanism (in BL3-1)
1419----------------------------------------------
1420BL3-1 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001421of the CPU to enable quick crash analysis and debugging. It requires that a
1422console is designated as the crash console by the platform which will be used to
1423print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001424
Sandrine Bailleux44804252014-08-06 11:27:23 +01001425The following functions must be implemented by the platform if it wants crash
1426reporting mechanism in BL3-1. The functions are implemented in assembly so that
1427they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001428
1429### Function : plat_crash_console_init
1430
1431 Argument : void
1432 Return : int
1433
Sandrine Bailleux44804252014-08-06 11:27:23 +01001434This API is used by the crash reporting mechanism to initialize the crash
1435console. It should only use the general purpose registers x0 to x2 to do the
1436initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001437
Soby Mathewc67b09b2014-07-14 16:57:23 +01001438### Function : plat_crash_console_putc
1439
1440 Argument : int
1441 Return : int
1442
1443This API is used by the crash reporting mechanism to print a character on the
1444designated crash console. It should only use general purpose registers x1 and
1445x2 to do its work. The parameter and the return value are in general purpose
1446register x0.
1447
Soby Mathew27713fb2014-09-08 17:51:01 +010014484. Build flags
1449---------------
1450
1451There are some build flags which can be defined by the platform to control
1452inclusion or exclusion of certain BL stages from the FIP image. These flags
1453need to be defined in the platform makefile which will get included by the
1454build system.
1455
1456* **NEED_BL30**
1457 This flag if defined by the platform mandates that a BL3-0 binary should
1458 be included in the FIP image. The path to the BL3-0 binary can be specified
1459 by the `BL30` build option (see build options in the [User Guide]).
1460
1461* **NEED_BL33**
1462 By default, this flag is defined `yes` by the build system and `BL33`
1463 build option should be supplied as a build option. The platform has the option
1464 of excluding the BL3-3 image in the `fip` image by defining this flag to
1465 `no`.
1466
14675. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001468-------------
1469
1470To avoid subtle toolchain behavioral dependencies, the header files provided
1471by the compiler are not used. The software is built with the `-nostdinc` flag
1472to ensure no headers are included from the toolchain inadvertently. Instead the
1473required headers are included in the ARM Trusted Firmware source tree. The
1474library only contains those C library definitions required by the local
1475implementation. If more functionality is required, the needed library functions
1476will need to be added to the local implementation.
1477
1478Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1479headers have been cut down in order to simplify the implementation. In order to
1480minimize changes to the header files, the [FreeBSD] layout has been maintained.
1481The generic C library definitions can be found in `include/stdlib` with more
1482system and machine specific declarations in `include/stdlib/sys` and
1483`include/stdlib/machine`.
1484
1485The local C library implementations can be found in `lib/stdlib`. In order to
1486extend the C library these files may need to be modified. It is recommended to
1487use a release version of [FreeBSD] as a starting point.
1488
1489The C library header files in the [FreeBSD] source tree are located in the
1490`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1491can be found in the `sys/<machine-type>` directories. These files define things
1492like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1493port for [FreeBSD] does not yet exist, the machine specific definitions are
1494based on existing machine types with similar properties (for example SPARC64).
1495
1496Where possible, C library function implementations were taken from [FreeBSD]
1497as found in the `lib/libc` directory.
1498
1499A copy of the [FreeBSD] sources can be downloaded with `git`.
1500
1501 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1502
1503
Soby Mathew27713fb2014-09-08 17:51:01 +010015046. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001505-----------------------------
1506
1507In order to improve platform independence and portability an storage abstraction
1508layer is used to load data from non-volatile platform storage.
1509
1510Each platform should register devices and their drivers via the Storage layer.
1511These drivers then need to be initialized by bootloader phases as
1512required in their respective `blx_platform_setup()` functions. Currently
1513storage access is only required by BL1 and BL2 phases. The `load_image()`
1514function uses the storage layer to access non-volatile platform storage.
1515
Dan Handley4a75b842015-03-19 19:24:43 +00001516It is mandatory to implement at least one storage driver. For the ARM
1517development platforms the Firmware Image Package (FIP) driver is provided as
1518the default means to load data from storage (see the "Firmware Image Package"
1519section in the [User Guide]). The storage layer is described in the header file
1520`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001521is in `drivers/io/io_storage.c` and the driver files are located in
1522`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001523
1524Each IO driver must provide `io_dev_*` structures, as described in
1525`drivers/io/io_driver.h`. These are returned via a mandatory registration
1526function that is called on platform initialization. The semi-hosting driver
1527implementation in `io_semihosting.c` can be used as an example.
1528
1529The Storage layer provides mechanisms to initialize storage devices before
1530IO operations are called. The basic operations supported by the layer
1531include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1532Drivers do not have to implement all operations, but each platform must
1533provide at least one driver for a device capable of supporting generic
1534operations such as loading a bootloader image.
1535
1536The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01001537firmware. These images are specified by using their identifiers, as defined in
1538[include/plat/common/platform_def.h] (or a separate header file included from
1539there). The platform layer (`plat_get_image_source()`) then returns a reference
1540to a device and a driver-specific `spec` which will be understood by the driver
1541to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001542
1543The layer is designed in such a way that is it possible to chain drivers with
1544other drivers. For example, file-system drivers may be implemented on top of
1545physical block devices, both represented by IO devices with corresponding
1546drivers. In such a case, the file-system "binding" with the block device may
1547be deferred until the file-system device is initialised.
1548
1549The abstraction currently depends on structures being statically allocated
1550by the drivers and callers, as the system does not yet provide a means of
1551dynamically allocating memory. This may also have the affect of limiting the
1552amount of open resources per driver.
1553
1554
Achin Gupta4f6ad662013-10-25 09:08:21 +01001555- - - - - - - - - - - - - - - - - - - - - - - - - -
1556
Dan Handley4a75b842015-03-19 19:24:43 +00001557_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001558
1559
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001560[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1561[IMF Design Guide]: interrupt-framework-design.md
1562[User Guide]: user-guide.md
1563[FreeBSD]: http://www.freebsd.org
Dan Handley4a75b842015-03-19 19:24:43 +00001564[Firmware Design]: firmware-design.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01001565
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001566[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1567[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00001568[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001569[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handley4a75b842015-03-19 19:24:43 +00001570[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
1571[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001572[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00001573[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]