blob: 81cbe1be0677b7cd7881e75e93e1f9dd8bb74f3b [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
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100471
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100472### Function: plat_get_rotpk_info()
473
474 Argument : void *, void **, unsigned int *, unsigned int *
475 Return : int
476
477This function is mandatory when Trusted Board Boot is enabled. It returns a
478pointer to the ROTPK stored in the platform (or a hash of it) and its length.
479The ROTPK must be encoded in DER format according to the following ASN.1
480structure:
481
482 AlgorithmIdentifier ::= SEQUENCE {
483 algorithm OBJECT IDENTIFIER,
484 parameters ANY DEFINED BY algorithm OPTIONAL
485 }
486
487 SubjectPublicKeyInfo ::= SEQUENCE {
488 algorithm AlgorithmIdentifier,
489 subjectPublicKey BIT STRING
490 }
491
492In case the function returns a hash of the key:
493
494 DigestInfo ::= SEQUENCE {
495 digestAlgorithm AlgorithmIdentifier,
496 digest OCTET STRING
497 }
498
499The function returns 0 on success. Any other value means the ROTPK could not be
500retrieved from the platform. The function also reports extra information related
501to the ROTPK in the flags parameter.
502
503
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100504
5052.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100506---------------------------------
507
508The following are helper functions implemented by the firmware that perform
509common platform-specific tasks. A platform may choose to override these
510definitions.
511
512
513### Function : platform_get_core_pos()
514
515 Argument : unsigned long
516 Return : int
517
518A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
519can be used as a CPU-specific linear index into blocks of memory (for example
520while allocating per-CPU stacks). This routine contains a simple mechanism
521to perform this conversion, using the assumption that each cluster contains a
522maximum of 4 CPUs:
523
524 linear index = cpu_id + (cluster_id * 4)
525
526 cpu_id = 8-bit value in MPIDR at affinity level 0
527 cluster_id = 8-bit value in MPIDR at affinity level 1
528
529
Achin Gupta4f6ad662013-10-25 09:08:21 +0100530### Function : platform_set_stack()
531
532 Argument : unsigned long
533 Return : void
534
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000535This function sets the current stack pointer to the normal memory stack that
536has been allocated for the CPU specificed by MPIDR. For BL images that only
537require a stack for the primary CPU the parameter is ignored. The size of
538the stack allocated to each CPU is specified by the platform defined constant
539`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100540
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000541Common implementations of this function for the UP and MP BL images are
542provided in [plat/common/aarch64/platform_up_stack.S] and
543[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100544
545
Achin Guptac8afc782013-11-25 18:45:02 +0000546### Function : platform_get_stack()
547
548 Argument : unsigned long
549 Return : unsigned long
550
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000551This function returns the base address of the normal memory stack that
552has been allocated for the CPU specificed by MPIDR. For BL images that only
553require a stack for the primary CPU the parameter is ignored. The size of
554the stack allocated to each CPU is specified by the platform defined constant
555`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000556
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000557Common implementations of this function for the UP and MP BL images are
558provided in [plat/common/aarch64/platform_up_stack.S] and
559[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000560
561
Achin Gupta4f6ad662013-10-25 09:08:21 +0100562### Function : plat_report_exception()
563
564 Argument : unsigned int
565 Return : void
566
567A platform may need to report various information about its status when an
568exception is taken, for example the current exception level, the CPU security
569state (secure/non-secure), the exception type, and so on. This function is
570called in the following circumstances:
571
572* In BL1, whenever an exception is taken.
573* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100574
575The default implementation doesn't do anything, to avoid making assumptions
576about the way the platform displays its status information.
577
578This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000579exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100580that these constants are not related to any architectural exception code; they
581are just an ARM Trusted Firmware convention.
582
583
Soby Mathew24fb8382014-08-14 12:22:32 +0100584### Function : plat_reset_handler()
585
586 Argument : void
587 Return : void
588
589A platform may need to do additional initialization after reset. This function
590allows the platform to do the platform specific intializations. Platform
591specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000592preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100593
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000594The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000595the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100596guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100597
Soby Mathewadd40352014-08-14 12:49:05 +0100598### Function : plat_disable_acp()
599
600 Argument : void
601 Return : void
602
603This api allows a platform to disable the Accelerator Coherency Port (if
604present) during a cluster power down sequence. The default weak implementation
605doesn't do anything. Since this api is called during the power down sequence,
606it has restrictions for stack usage and it can use the registers x0 - x17 as
607scratch registers. It should preserve the value in x18 register as it is used
608by the caller to store the return address.
609
Soby Mathew24fb8382014-08-14 12:22:32 +0100610
Achin Gupta4f6ad662013-10-25 09:08:21 +01006113. Modifications specific to a Boot Loader stage
612-------------------------------------------------
613
6143.1 Boot Loader Stage 1 (BL1)
615-----------------------------
616
617BL1 implements the reset vector where execution starts from after a cold or
618warm boot. For each CPU, BL1 is responsible for the following tasks:
619
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006201. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100621
6222. In the case of a cold boot and the CPU being the primary CPU, ensuring that
623 only this CPU executes the remaining BL1 code, including loading and passing
624 control to the BL2 stage.
625
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006263. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100627 address specified by the platform defined constant `BL2_BASE`.
628
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006294. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100630 accessible by BL2 immediately upon entry.
631
632 meminfo.total_base = Base address of secure RAM visible to BL2
633 meminfo.total_size = Size of secure RAM visible to BL2
634 meminfo.free_base = Base address of secure RAM available for
635 allocation to BL2
636 meminfo.free_size = Size of secure RAM available for allocation to BL2
637
638 BL1 places this `meminfo` structure at the beginning of the free memory
639 available for its use. Since BL1 cannot allocate memory dynamically at the
640 moment, its free memory will be available for BL2's use as-is. However, this
641 means that BL2 must read the `meminfo` structure before it starts using its
642 free memory (this is discussed in Section 3.2).
643
644 In future releases of the ARM Trusted Firmware it will be possible for
645 the platform to decide where it wants to place the `meminfo` structure for
646 BL2.
647
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100648 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100649 BL2 `meminfo` structure. The platform may override this implementation, for
650 example if the platform wants to restrict the amount of memory visible to
651 BL2. Details of how to do this are given below.
652
653The following functions need to be implemented by the platform port to enable
654BL1 to perform the above tasks.
655
656
Dan Handley4a75b842015-03-19 19:24:43 +0000657### Function : bl1_early_platform_setup() [mandatory]
658
659 Argument : void
660 Return : void
661
662This function executes with the MMU and data caches disabled. It is only called
663by the primary CPU.
664
665In ARM standard platforms, this function initializes the console and enables
666snoop requests into the primary CPU's cluster.
667
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100668### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100669
670 Argument : void
671 Return : void
672
Achin Gupta4f6ad662013-10-25 09:08:21 +0100673This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000674platform requires. Platform-specific setup might include configuration of
675memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100676
Dan Handley4a75b842015-03-19 19:24:43 +0000677In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100678
679This function helps fulfill requirement 2 above.
680
681
682### Function : bl1_platform_setup() [mandatory]
683
684 Argument : void
685 Return : void
686
687This function executes with the MMU and data caches enabled. It is responsible
688for performing any remaining platform-specific setup that can occur after the
689MMU and data cache have been enabled.
690
Dan Handley4a75b842015-03-19 19:24:43 +0000691In ARM standard platforms, this function initializes the storage abstraction
692layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000693
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100694This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100695
696
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000697### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100698
699 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000700 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100701
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000702This function should only be called on the cold boot path. It executes with the
703MMU and data caches enabled. The pointer returned by this function must point to
704a `meminfo` structure containing the extents and availability of secure RAM for
705the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100706
707 meminfo.total_base = Base address of secure RAM visible to BL1
708 meminfo.total_size = Size of secure RAM visible to BL1
709 meminfo.free_base = Base address of secure RAM available for allocation
710 to BL1
711 meminfo.free_size = Size of secure RAM available for allocation to BL1
712
713This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
714populates a similar structure to tell BL2 the extents of memory available for
715its own use.
716
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100717This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100718
719
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100720### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100721
722 Argument : meminfo *, meminfo *, unsigned int, unsigned long
723 Return : void
724
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100725BL1 needs to tell the next stage the amount of secure RAM available
726for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100727structure.
728
729Depending upon where BL2 has been loaded in secure RAM (determined by
730`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
731BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000732to BL2. An illustration of how this is done in ARM standard platforms is given
733in the **Memory layout on ARM development platforms** section in the
734[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100735
736
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100737### Function : bl1_plat_set_bl2_ep_info() [mandatory]
738
739 Argument : image_info *, entry_point_info *
740 Return : void
741
742This function is called after loading BL2 image and it can be used to overwrite
743the entry point set by loader and also set the security state and SPSR which
744represents the entry point system state for BL2.
745
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100746
Achin Gupta4f6ad662013-10-25 09:08:21 +01007473.2 Boot Loader Stage 2 (BL2)
748-----------------------------
749
750The BL2 stage is executed only by the primary CPU, which is determined in BL1
751using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
752`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
753
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007541. (Optional) Loading the BL3-0 binary image (if present) from platform
755 provided non-volatile storage. To load the BL3-0 image, BL2 makes use of
756 the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function.
757 The platform also defines the address in memory where BL3-0 is loaded
758 through the optional constant `BL30_BASE`. BL2 uses this information
759 to determine if there is enough memory to load the BL3-0 image.
760 Subsequent handling of the BL3-0 image is platform-specific and is
761 implemented in the `bl2_plat_handle_bl30()` function.
762 If `BL30_BASE` is not defined then this step is not performed.
763
7642. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
Harry Liebeld265bd72014-01-31 19:04:10 +0000765 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
766 by BL1. This structure allows BL2 to calculate how much secure RAM is
767 available for its use. The platform also defines the address in secure RAM
768 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
769 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100770
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007713. (Optional) Loading the BL3-2 binary image (if present) from platform
Dan Handley1151c822014-04-15 11:38:38 +0100772 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100773 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
774 The platform also defines the address in memory where BL3-2 is loaded
775 through the optional constant `BL32_BASE`. BL2 uses this information
776 to determine if there is enough memory to load the BL3-2 image.
777 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000778
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007794. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100780 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100781 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100782 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000783
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007845. Loading the normal world BL3-3 binary image into non-secure DRAM from
785 platform storage and arranging for BL3-1 to pass control to this image. This
786 address is determined using the `plat_get_ns_image_entrypoint()` function
787 described below.
788
7896. BL2 populates an `entry_point_info` structure in memory provided by the
790 platform with information about how BL3-1 should pass control to the
791 other BL images.
792
Achin Gupta4f6ad662013-10-25 09:08:21 +0100793The following functions must be implemented by the platform port to enable BL2
794to perform the above tasks.
795
796
797### Function : bl2_early_platform_setup() [mandatory]
798
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100799 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100800 Return : void
801
802This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100803by the primary CPU. The arguments to this function is the address of the
804`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100805
806The platform must copy the contents of the `meminfo` structure into a private
807variable as the original memory may be subsequently overwritten by BL2. The
808copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000809`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100810
Dan Handley4a75b842015-03-19 19:24:43 +0000811In ARM standard platforms, this function also initializes the storage
812abstraction layer used to load further bootloader images. It is necessary to do
813this early on platforms with a BL3-0 image, since the later `bl2_platform_setup`
814must be done after BL3-0 is loaded.
815
Achin Gupta4f6ad662013-10-25 09:08:21 +0100816
817### Function : bl2_plat_arch_setup() [mandatory]
818
819 Argument : void
820 Return : void
821
822This function executes with the MMU and data caches disabled. It is only called
823by the primary CPU.
824
825The purpose of this function is to perform any architectural initialization
826that varies across platforms, for example enabling the MMU (since the memory
827map differs across platforms).
828
829
830### Function : bl2_platform_setup() [mandatory]
831
832 Argument : void
833 Return : void
834
835This function may execute with the MMU and data caches enabled if the platform
836port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
837called by the primary CPU.
838
Achin Guptae4d084e2014-02-19 17:18:23 +0000839The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +0000840specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +0100841
Dan Handley4a75b842015-03-19 19:24:43 +0000842In ARM standard platforms, this function performs security setup, including
843configuration of the TrustZone controller to allow non-secure masters access
844to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +0000845
Achin Gupta4f6ad662013-10-25 09:08:21 +0100846
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000847### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100848
849 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000850 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100851
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000852This function should only be called on the cold boot path. It may execute with
853the MMU and data caches enabled if the platform port does the necessary
854initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100855
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000856The purpose of this function is to return a pointer to a `meminfo` structure
857populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100858`bl2_early_platform_setup()` above.
859
860
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100861### Function : bl2_plat_get_bl30_meminfo() [mandatory]
862
863 Argument : meminfo *
864 Return : void
865
866This function is used to get the memory limits where BL2 can load the
867BL3-0 image. The meminfo provided by this is used by load_image() to
868validate whether the BL3-0 image can be loaded within the given
869memory from the given base.
870
871
872### Function : bl2_plat_handle_bl30() [mandatory]
873
874 Argument : image_info *
875 Return : int
876
877This function is called after loading BL3-0 image and it is used to perform any
878platform-specific actions required to handle the SCP firmware. Typically it
879transfers the image into SCP memory using a platform-specific protocol and waits
880until SCP executes it and signals to the Application Processor (AP) for BL2
881execution to continue.
882
883This function returns 0 on success, a negative error code otherwise.
884
885
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100886### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000887
888 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100889 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000890
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100891BL2 platform code needs to return a pointer to a `bl31_params` structure it
892will use for passing information to BL3-1. The `bl31_params` structure carries
893the following information.
894 - Header describing the version information for interpreting the bl31_param
895 structure
896 - Information about executing the BL3-3 image in the `bl33_ep_info` field
897 - Information about executing the BL3-2 image in the `bl32_ep_info` field
898 - Information about the type and extents of BL3-1 image in the
899 `bl31_image_info` field
900 - Information about the type and extents of BL3-2 image in the
901 `bl32_image_info` field
902 - Information about the type and extents of BL3-3 image in the
903 `bl33_image_info` field
904
905The memory pointed by this structure and its sub-structures should be
906accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
907necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000908
909
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100910### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100911
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100912 Argument : void
913 Return : entry_point_info *
914
915BL2 platform code returns a pointer which is used to populate the entry point
916information for BL3-1 entry point. The location pointed by it should be
917accessible from BL1 while processing the synchronous exception to run to BL3-1.
918
Dan Handley4a75b842015-03-19 19:24:43 +0000919In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
920structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100921
922
923### Function : bl2_plat_set_bl31_ep_info() [mandatory]
924
925 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100926 Return : void
927
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100928This function is called after loading BL3-1 image and it can be used to
929overwrite the entry point set by loader and also set the security state
930and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100931
Achin Gupta4f6ad662013-10-25 09:08:21 +0100932
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100933### Function : bl2_plat_set_bl32_ep_info() [mandatory]
934
935 Argument : image_info *, entry_point_info *
936 Return : void
937
938This function is called after loading BL3-2 image and it can be used to
939overwrite the entry point set by loader and also set the security state
940and SPSR which represents the entry point system state for BL3-2.
941
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100942
943### Function : bl2_plat_set_bl33_ep_info() [mandatory]
944
945 Argument : image_info *, entry_point_info *
946 Return : void
947
948This function is called after loading BL3-3 image and it can be used to
949overwrite the entry point set by loader and also set the security state
950and SPSR which represents the entry point system state for BL3-3.
951
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100952
953### Function : bl2_plat_get_bl32_meminfo() [mandatory]
954
955 Argument : meminfo *
956 Return : void
957
958This function is used to get the memory limits where BL2 can load the
959BL3-2 image. The meminfo provided by this is used by load_image() to
960validate whether the BL3-2 image can be loaded with in the given
961memory from the given base.
962
963### Function : bl2_plat_get_bl33_meminfo() [mandatory]
964
965 Argument : meminfo *
966 Return : void
967
968This function is used to get the memory limits where BL2 can load the
969BL3-3 image. The meminfo provided by this is used by load_image() to
970validate whether the BL3-3 image can be loaded with in the given
971memory from the given base.
972
973### Function : bl2_plat_flush_bl31_params() [mandatory]
974
975 Argument : void
976 Return : void
977
978Once BL2 has populated all the structures that needs to be read by BL1
979and BL3-1 including the bl31_params structures and its sub-structures,
980the bl31_ep_info structure and any platform specific data. It flushes
981all these data to the main memory so that it is available when we jump to
982later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100983
984### Function : plat_get_ns_image_entrypoint() [mandatory]
985
986 Argument : void
987 Return : unsigned long
988
989As previously described, BL2 is responsible for arranging for control to be
990passed to a normal world BL image through BL3-1. This function returns the
991entrypoint of that image, which BL3-1 uses to jump to it.
992
Harry Liebeld265bd72014-01-31 19:04:10 +0000993BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100994
995
9963.2 Boot Loader Stage 3-1 (BL3-1)
997---------------------------------
998
999During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
1000determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
1001control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
1002CPUs. BL3-1 executes at EL3 and is responsible for:
1003
10041. Re-initializing all architectural and platform state. Although BL1 performs
1005 some of this initialization, BL3-1 remains resident in EL3 and must ensure
1006 that EL3 architectural and platform state is completely initialized. It
1007 should make no assumptions about the system state when it receives control.
1008
10092. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001010 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001011 populated in memory to do this.
1012
10133. Providing runtime firmware services. Currently, BL3-1 only implements a
1014 subset of the Power State Coordination Interface (PSCI) API as a runtime
1015 service. See Section 3.3 below for details of porting the PSCI
1016 implementation.
1017
Achin Gupta35ca3512014-02-19 17:58:33 +000010184. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
1019 specific address by BL2. BL3-1 exports a set of apis that allow runtime
1020 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001021 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
1022 structure populated by BL2 to do this.
1023
1024If BL3-1 is a reset vector, It also needs to handle the reset as specified in
1025section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001026
Achin Gupta4f6ad662013-10-25 09:08:21 +01001027The following functions must be implemented by the platform port to enable BL3-1
1028to perform the above tasks.
1029
1030
1031### Function : bl31_early_platform_setup() [mandatory]
1032
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001033 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001034 Return : void
1035
1036This function executes with the MMU and data caches disabled. It is only called
1037by the primary CPU. The arguments to this function are:
1038
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001039* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001040* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001041
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001042The platform can copy the contents of the `bl31_params` structure and its
1043sub-structures into private variables if the original memory may be
1044subsequently overwritten by BL3-1 and similarly the `void *` pointing
1045to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001046
Dan Handley4a75b842015-03-19 19:24:43 +00001047In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
1048in BL2 memory. BL3-1 copies the information in this pointer to internal data
1049structures.
1050
Achin Gupta4f6ad662013-10-25 09:08:21 +01001051
1052### Function : bl31_plat_arch_setup() [mandatory]
1053
1054 Argument : void
1055 Return : void
1056
1057This function executes with the MMU and data caches disabled. It is only called
1058by the primary CPU.
1059
1060The purpose of this function is to perform any architectural initialization
1061that varies across platforms, for example enabling the MMU (since the memory
1062map differs across platforms).
1063
1064
1065### Function : bl31_platform_setup() [mandatory]
1066
1067 Argument : void
1068 Return : void
1069
1070This function may execute with the MMU and data caches enabled if the platform
1071port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1072called by the primary CPU.
1073
1074The purpose of this function is to complete platform initialization so that both
1075BL3-1 runtime services and normal world software can function correctly.
1076
Dan Handley4a75b842015-03-19 19:24:43 +00001077In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001078* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001079* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001080* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001081* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001082* Detects the system topology.
1083
1084
1085### Function : bl31_get_next_image_info() [mandatory]
1086
Achin Gupta35ca3512014-02-19 17:58:33 +00001087 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001088 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001089
1090This function may execute with the MMU and data caches enabled if the platform
1091port does the necessary initializations in `bl31_plat_arch_setup()`.
1092
1093This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +00001094BL2 for the next image in the security state specified by the argument. BL3-1
1095uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001096state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001097(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1098should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001099
Dan Handley4a75b842015-03-19 19:24:43 +00001100### Function : plat_get_syscnt_freq() [mandatory]
1101
1102 Argument : void
1103 Return : uint64_t
1104
1105This function is used by the architecture setup code to retrieve the counter
1106frequency for the CPU's generic timer. This value will be programmed into the
1107`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1108of the system counter, which is retrieved from the first entry in the frequency
1109modes table.
1110
Achin Gupta4f6ad662013-10-25 09:08:21 +01001111
Achin Gupta4f6ad662013-10-25 09:08:21 +010011123.3 Power State Coordination Interface (in BL3-1)
1113------------------------------------------------
1114
1115The ARM Trusted Firmware's implementation of the PSCI API is based around the
1116concept of an _affinity instance_. Each _affinity instance_ can be uniquely
1117identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
1118interface) and an _affinity level_. A processing element (for example, a
1119CPU) is at level 0. If the CPUs in the system are described in a tree where the
1120node above a CPU is a logical grouping of CPUs that share some state, then
1121affinity level 1 is that group of CPUs (for example, a cluster), and affinity
1122level 2 is a group of clusters (for example, the system). The implementation
1123assumes that the affinity level 1 ID can be computed from the affinity level 0
1124ID (for example, a unique cluster ID can be computed from the CPU ID). The
1125current implementation computes this on the basis of the recommended use of
1126`MPIDR` affinity fields in the ARM Architecture Reference Manual.
1127
1128BL3-1's platform initialization code exports a pointer to the platform-specific
1129power management operations required for the PSCI implementation to function
1130correctly. This information is populated in the `plat_pm_ops` structure. The
1131PSCI implementation calls members of the `plat_pm_ops` structure for performing
1132power management operations for each affinity instance. For example, the target
1133CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
1134handler (if present) is called for each affinity instance as the PSCI
1135implementation powers up each affinity level implemented in the `MPIDR` (for
1136example, CPU, cluster and system).
1137
1138The following functions must be implemented to initialize PSCI functionality in
1139the ARM Trusted Firmware.
1140
1141
1142### Function : plat_get_aff_count() [mandatory]
1143
1144 Argument : unsigned int, unsigned long
1145 Return : unsigned int
1146
1147This function may execute with the MMU and data caches enabled if the platform
1148port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1149called by the primary CPU.
1150
1151This function is called by the PSCI initialization code to detect the system
1152topology. Its purpose is to return the number of affinity instances implemented
1153at a given `affinity level` (specified by the first argument) and a given
1154`MPIDR` (specified by the second argument). For example, on a dual-cluster
1155system where first cluster implements 2 CPUs and the second cluster implements 4
1156CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
1157(`0x0`) and affinity level 0, would return 2. A call to this function with an
1158`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
1159would return 4.
1160
1161
1162### Function : plat_get_aff_state() [mandatory]
1163
1164 Argument : unsigned int, unsigned long
1165 Return : unsigned int
1166
1167This function may execute with the MMU and data caches enabled if the platform
1168port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1169called by the primary CPU.
1170
1171This function is called by the PSCI initialization code. Its purpose is to
1172return the state of an affinity instance. The affinity instance is determined by
1173the affinity ID at a given `affinity level` (specified by the first argument)
1174and an `MPIDR` (specified by the second argument). The state can be one of
1175`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
1176system topologies where certain affinity instances are unimplemented. For
1177example, consider a platform that implements a single cluster with 4 CPUs and
1178another CPU implemented directly on the interconnect with the cluster. The
1179`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
1180CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
1181is missing but needs to be accounted for to reach this single CPU in the
1182topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
1183
1184
Achin Gupta4f6ad662013-10-25 09:08:21 +01001185### Function : platform_setup_pm() [mandatory]
1186
Sandrine Bailleux44804252014-08-06 11:27:23 +01001187 Argument : const plat_pm_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001188 Return : int
1189
1190This function may execute with the MMU and data caches enabled if the platform
1191port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1192called by the primary CPU.
1193
1194This function is called by PSCI initialization code. Its purpose is to export
1195handler routines for platform-specific power management actions by populating
1196the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1197
1198A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001199the ARM FVP specific implementation of these handlers in
1200[plat/arm/board/fvp/fvp_pm.c] as an example. A platform port is expected to
1201implement these handlers if the corresponding PSCI operation is to be supported
1202and these handlers are expected to succeed if the return type is `void`.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001203
1204#### plat_pm_ops.affinst_standby()
1205
1206Perform the platform-specific setup to enter the standby state indicated by the
Soby Mathew539dced2014-10-02 16:56:51 +01001207passed argument. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001208
1209#### plat_pm_ops.affinst_on()
1210
1211Perform the platform specific setup to power on an affinity instance, specified
Soby Mathewe146f4c2014-09-26 15:08:52 +01001212by the `MPIDR` (first argument) and `affinity level` (third argument). The
1213`state` (fourth argument) contains the current state of that affinity instance
Achin Gupta4f6ad662013-10-25 09:08:21 +01001214(ON or OFF). This is useful to determine whether any action must be taken. For
1215example, while powering on a CPU, the cluster that contains this CPU might
1216already be in the ON state. The platform decides what actions must be taken to
1217transition from the current state to the target state (indicated by the power
Soby Mathew539dced2014-10-02 16:56:51 +01001218management operation). The generic code expects the platform to return
1219E_SUCCESS on success or E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001220
1221#### plat_pm_ops.affinst_off()
1222
Soby Mathewe146f4c2014-09-26 15:08:52 +01001223Perform the platform specific setup to power off an affinity instance of the
1224calling CPU. It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001225
Soby Mathewe146f4c2014-09-26 15:08:52 +01001226The `affinity level` (first argument) and `state` (second argument) have
1227a similar meaning as described in the `affinst_on()` operation. They are
1228used to identify the affinity instance on which the call is made and its
1229current state. This gives the platform port an indication of the
Achin Gupta4f6ad662013-10-25 09:08:21 +01001230state transition it must make to perform the requested action. For example, if
1231the calling CPU is the last powered on CPU in the cluster, after powering down
1232affinity level 0 (CPU), the platform port should power down affinity level 1
Soby Mathew539dced2014-10-02 16:56:51 +01001233(the cluster) as well. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001234
Achin Gupta4f6ad662013-10-25 09:08:21 +01001235#### plat_pm_ops.affinst_suspend()
1236
Soby Mathewe146f4c2014-09-26 15:08:52 +01001237Perform the platform specific setup to power off an affinity instance of the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001238calling CPU. It is called by the PSCI `CPU_SUSPEND` API and `SYSTEM_SUSPEND`
1239API implementation
Achin Gupta4f6ad662013-10-25 09:08:21 +01001240
Soby Mathewe146f4c2014-09-26 15:08:52 +01001241The `affinity level` (second argument) and `state` (third argument) have a
1242similar meaning as described in the `affinst_on()` operation. They are used to
1243identify the affinity instance on which the call is made and its current state.
1244This gives the platform port an indication of the state transition it must
1245make to perform the requested action. For example, if the calling CPU is the
1246last powered on CPU in the cluster, after powering down affinity level 0 (CPU),
1247the platform port should power down affinity level 1 (the cluster) as well.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001248
1249The difference between turning an affinity instance off versus suspending it
1250is that in the former case, the affinity instance is expected to re-initialize
1251its state when its next powered on (see `affinst_on_finish()`). In the latter
1252case, the affinity instance is expected to save enough state so that it can
1253resume execution by restoring this state when its powered on (see
Soby Mathew539dced2014-10-02 16:56:51 +01001254`affinst_suspend_finish()`).The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001255
Achin Gupta4f6ad662013-10-25 09:08:21 +01001256#### plat_pm_ops.affinst_on_finish()
1257
1258This function is called by the PSCI implementation after the calling CPU is
1259powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1260It performs the platform-specific setup required to initialize enough state for
1261this CPU to enter the normal world and also provide secure runtime firmware
1262services.
1263
Soby Mathewe146f4c2014-09-26 15:08:52 +01001264The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001265similar meaning as described in the previous operations. The generic code
1266expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001267
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001268#### plat_pm_ops.affinst_suspend_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001269
1270This function is called by the PSCI implementation after the calling CPU is
1271powered on and released from reset in response to an asynchronous wakeup
1272event, for example a timer interrupt that was programmed by the CPU during the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001273`CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific
1274setup required to restore the saved state for this CPU to resume execution
1275in the normal world and also provide secure runtime firmware services.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001276
Soby Mathewe146f4c2014-09-26 15:08:52 +01001277The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001278similar meaning as described in the previous operations. The generic code
1279expects the platform to succeed.
1280
1281#### plat_pm_ops.validate_power_state()
1282
1283This function is called by the PSCI implementation during the `CPU_SUSPEND`
1284call to validate the `power_state` parameter of the PSCI API. If the
1285`power_state` is known to be invalid, the platform must return
1286PSCI_E_INVALID_PARAMS as error, which is propagated back to the normal
1287world PSCI client.
1288
1289#### plat_pm_ops.validate_ns_entrypoint()
1290
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001291This function is called by the PSCI implementation during the `CPU_SUSPEND`,
1292`SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point`
1293parameter passed by the normal world. If the `entry_point` is known to be
1294invalid, the platform must return PSCI_E_INVALID_PARAMS as error, which is
1295propagated back to the normal world PSCI client.
1296
1297#### plat_pm_ops.get_sys_suspend_power_state()
1298
1299This function is called by the PSCI implementation during the `SYSTEM_SUSPEND`
1300call to return the `power_state` parameter. This allows the platform to encode
1301the appropriate State-ID field within the `power_state` parameter which can be
1302utilized in `affinst_suspend()` to suspend to system affinity level. The
1303`power_state` parameter should be in the same format as specified by the
1304PSCI specification for the CPU_SUSPEND API.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001305
Achin Gupta4f6ad662013-10-25 09:08:21 +01001306BL3-1 platform initialization code must also detect the system topology and
1307the state of each affinity instance in the topology. This information is
1308critical for the PSCI runtime service to function correctly. More details are
1309provided in the description of the `plat_get_aff_count()` and
1310`plat_get_aff_state()` functions above.
1311
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010013123.4 Interrupt Management framework (in BL3-1)
1313----------------------------------------------
1314BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1315generated in either security state and targeted to EL1 or EL2 in the non-secure
1316state or EL3/S-EL1 in the secure state. The design of this framework is
1317described in the [IMF Design Guide]
1318
1319A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001320text briefly describes each api and its implementation in ARM standard
1321platforms. The API implementation depends upon the type of interrupt controller
1322present in the platform. ARM standard platforms implements an ARM Generic
1323Interrupt Controller (ARM GIC) as per the version 2.0 of the
1324[ARM GIC Architecture Specification].
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001325
1326### Function : plat_interrupt_type_to_line() [mandatory]
1327
1328 Argument : uint32_t, uint32_t
1329 Return : uint32_t
1330
1331The ARM processor signals an interrupt exception either through the IRQ or FIQ
1332interrupt line. The specific line that is signaled depends on how the interrupt
1333controller (IC) reports different interrupt types from an execution context in
1334either security state. The IMF uses this API to determine which interrupt line
1335the platform IC uses to signal each type of interrupt supported by the framework
1336from a given security state.
1337
1338The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1339Guide]) indicating the target type of the interrupt, the second parameter is the
1340security state of the originating execution context. The return result is the
1341bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1342FIQ=2.
1343
Dan Handley4a75b842015-03-19 19:24:43 +00001344ARM standard platforms configure the ARM GIC to signal S-EL1 interrupts
1345as FIQs and Non-secure interrupts as IRQs from either security state.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001346
1347
1348### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1349
1350 Argument : void
1351 Return : uint32_t
1352
1353This API returns the type of the highest priority pending interrupt at the
1354platform IC. The IMF uses the interrupt type to retrieve the corresponding
1355handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1356pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1357`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1358
Dan Handley4a75b842015-03-19 19:24:43 +00001359ARM standard platforms read the _Highest Priority Pending Interrupt
1360Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The type
1361of interrupt depends upon the id value as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001362
13631. id < 1022 is reported as a S-EL1 interrupt
13642. id = 1022 is reported as a Non-secure interrupt.
13653. id = 1023 is reported as an invalid interrupt type.
1366
1367
1368### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1369
1370 Argument : void
1371 Return : uint32_t
1372
1373This API returns the id of the highest priority pending interrupt at the
1374platform IC. The IMF passes the id returned by this API to the registered
1375handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1376is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1377
Dan Handley4a75b842015-03-19 19:24:43 +00001378ARM standard platforms read the _Highest Priority Pending Interrupt
1379Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The id
1380that is returned by API depends upon the value of the id read from the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001381controller as follows.
1382
13831. id < 1022. id is returned as is.
13842. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1385 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1386 id is returned by the API.
13873. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1388
1389
1390### Function : plat_ic_acknowledge_interrupt() [mandatory]
1391
1392 Argument : void
1393 Return : uint32_t
1394
1395This API is used by the CPU to indicate to the platform IC that processing of
1396the highest pending interrupt has begun. It should return the id of the
1397interrupt which is being processed.
1398
Dan Handley4a75b842015-03-19 19:24:43 +00001399This function in ARM standard platforms reads the _Interrupt Acknowledge
1400Register_ (`GICC_IAR`). This changes the state of the highest priority pending
1401interrupt from pending to active in the interrupt controller. It returns the
1402value read from the `GICC_IAR`. This value is the id of the interrupt whose
1403state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001404
1405The TSP uses this API to start processing of the secure physical timer
1406interrupt.
1407
1408
1409### Function : plat_ic_end_of_interrupt() [mandatory]
1410
1411 Argument : uint32_t
1412 Return : void
1413
1414This API is used by the CPU to indicate to the platform IC that processing of
1415the interrupt corresponding to the id (passed as the parameter) has
1416finished. The id should be the same as the id returned by the
1417`plat_ic_acknowledge_interrupt()` API.
1418
Dan Handley4a75b842015-03-19 19:24:43 +00001419ARM standard platforms write the id to the _End of Interrupt Register_
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001420(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1421controller.
1422
1423The TSP uses this API to finish processing of the secure physical timer
1424interrupt.
1425
1426
1427### Function : plat_ic_get_interrupt_type() [mandatory]
1428
1429 Argument : uint32_t
1430 Return : uint32_t
1431
1432This API returns the type of the interrupt id passed as the parameter.
1433`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1434interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1435returned depending upon how the interrupt has been configured by the platform
1436IC.
1437
Dan Handley4a75b842015-03-19 19:24:43 +00001438This function in ARM standard platforms configures S-EL1 interrupts
1439as Group0 interrupts and Non-secure interrupts as Group1 interrupts. It reads
1440the group value corresponding to the interrupt id from the relevant _Interrupt
1441Group Register_ (`GICD_IGROUPRn`). It uses the group value to determine the
1442type of interrupt.
1443
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001444
Soby Mathewc67b09b2014-07-14 16:57:23 +010014453.5 Crash Reporting mechanism (in BL3-1)
1446----------------------------------------------
1447BL3-1 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001448of the CPU to enable quick crash analysis and debugging. It requires that a
1449console is designated as the crash console by the platform which will be used to
1450print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001451
Sandrine Bailleux44804252014-08-06 11:27:23 +01001452The following functions must be implemented by the platform if it wants crash
1453reporting mechanism in BL3-1. The functions are implemented in assembly so that
1454they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001455
1456### Function : plat_crash_console_init
1457
1458 Argument : void
1459 Return : int
1460
Sandrine Bailleux44804252014-08-06 11:27:23 +01001461This API is used by the crash reporting mechanism to initialize the crash
1462console. It should only use the general purpose registers x0 to x2 to do the
1463initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001464
Soby Mathewc67b09b2014-07-14 16:57:23 +01001465### Function : plat_crash_console_putc
1466
1467 Argument : int
1468 Return : int
1469
1470This API is used by the crash reporting mechanism to print a character on the
1471designated crash console. It should only use general purpose registers x1 and
1472x2 to do its work. The parameter and the return value are in general purpose
1473register x0.
1474
Soby Mathew27713fb2014-09-08 17:51:01 +010014754. Build flags
1476---------------
1477
1478There are some build flags which can be defined by the platform to control
1479inclusion or exclusion of certain BL stages from the FIP image. These flags
1480need to be defined in the platform makefile which will get included by the
1481build system.
1482
1483* **NEED_BL30**
1484 This flag if defined by the platform mandates that a BL3-0 binary should
1485 be included in the FIP image. The path to the BL3-0 binary can be specified
1486 by the `BL30` build option (see build options in the [User Guide]).
1487
1488* **NEED_BL33**
1489 By default, this flag is defined `yes` by the build system and `BL33`
1490 build option should be supplied as a build option. The platform has the option
1491 of excluding the BL3-3 image in the `fip` image by defining this flag to
1492 `no`.
1493
14945. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001495-------------
1496
1497To avoid subtle toolchain behavioral dependencies, the header files provided
1498by the compiler are not used. The software is built with the `-nostdinc` flag
1499to ensure no headers are included from the toolchain inadvertently. Instead the
1500required headers are included in the ARM Trusted Firmware source tree. The
1501library only contains those C library definitions required by the local
1502implementation. If more functionality is required, the needed library functions
1503will need to be added to the local implementation.
1504
1505Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1506headers have been cut down in order to simplify the implementation. In order to
1507minimize changes to the header files, the [FreeBSD] layout has been maintained.
1508The generic C library definitions can be found in `include/stdlib` with more
1509system and machine specific declarations in `include/stdlib/sys` and
1510`include/stdlib/machine`.
1511
1512The local C library implementations can be found in `lib/stdlib`. In order to
1513extend the C library these files may need to be modified. It is recommended to
1514use a release version of [FreeBSD] as a starting point.
1515
1516The C library header files in the [FreeBSD] source tree are located in the
1517`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1518can be found in the `sys/<machine-type>` directories. These files define things
1519like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1520port for [FreeBSD] does not yet exist, the machine specific definitions are
1521based on existing machine types with similar properties (for example SPARC64).
1522
1523Where possible, C library function implementations were taken from [FreeBSD]
1524as found in the `lib/libc` directory.
1525
1526A copy of the [FreeBSD] sources can be downloaded with `git`.
1527
1528 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1529
1530
Soby Mathew27713fb2014-09-08 17:51:01 +010015316. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001532-----------------------------
1533
1534In order to improve platform independence and portability an storage abstraction
1535layer is used to load data from non-volatile platform storage.
1536
1537Each platform should register devices and their drivers via the Storage layer.
1538These drivers then need to be initialized by bootloader phases as
1539required in their respective `blx_platform_setup()` functions. Currently
1540storage access is only required by BL1 and BL2 phases. The `load_image()`
1541function uses the storage layer to access non-volatile platform storage.
1542
Dan Handley4a75b842015-03-19 19:24:43 +00001543It is mandatory to implement at least one storage driver. For the ARM
1544development platforms the Firmware Image Package (FIP) driver is provided as
1545the default means to load data from storage (see the "Firmware Image Package"
1546section in the [User Guide]). The storage layer is described in the header file
1547`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001548is in `drivers/io/io_storage.c` and the driver files are located in
1549`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001550
1551Each IO driver must provide `io_dev_*` structures, as described in
1552`drivers/io/io_driver.h`. These are returned via a mandatory registration
1553function that is called on platform initialization. The semi-hosting driver
1554implementation in `io_semihosting.c` can be used as an example.
1555
1556The Storage layer provides mechanisms to initialize storage devices before
1557IO operations are called. The basic operations supported by the layer
1558include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1559Drivers do not have to implement all operations, but each platform must
1560provide at least one driver for a device capable of supporting generic
1561operations such as loading a bootloader image.
1562
1563The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01001564firmware. These images are specified by using their identifiers, as defined in
1565[include/plat/common/platform_def.h] (or a separate header file included from
1566there). The platform layer (`plat_get_image_source()`) then returns a reference
1567to a device and a driver-specific `spec` which will be understood by the driver
1568to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001569
1570The layer is designed in such a way that is it possible to chain drivers with
1571other drivers. For example, file-system drivers may be implemented on top of
1572physical block devices, both represented by IO devices with corresponding
1573drivers. In such a case, the file-system "binding" with the block device may
1574be deferred until the file-system device is initialised.
1575
1576The abstraction currently depends on structures being statically allocated
1577by the drivers and callers, as the system does not yet provide a means of
1578dynamically allocating memory. This may also have the affect of limiting the
1579amount of open resources per driver.
1580
1581
Achin Gupta4f6ad662013-10-25 09:08:21 +01001582- - - - - - - - - - - - - - - - - - - - - - - - - -
1583
Dan Handley4a75b842015-03-19 19:24:43 +00001584_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001585
1586
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001587[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1588[IMF Design Guide]: interrupt-framework-design.md
1589[User Guide]: user-guide.md
1590[FreeBSD]: http://www.freebsd.org
Dan Handley4a75b842015-03-19 19:24:43 +00001591[Firmware Design]: firmware-design.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01001592
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001593[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1594[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00001595[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001596[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handley4a75b842015-03-19 19:24:43 +00001597[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
1598[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001599[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00001600[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]