blob: d0096054b0d8935923e8e5ae94f4d6fd2c22f1e6 [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
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100486### Function: plat_get_rotpk_info()
487
488 Argument : void *, void **, unsigned int *, unsigned int *
489 Return : int
490
491This function is mandatory when Trusted Board Boot is enabled. It returns a
492pointer to the ROTPK stored in the platform (or a hash of it) and its length.
493The ROTPK must be encoded in DER format according to the following ASN.1
494structure:
495
496 AlgorithmIdentifier ::= SEQUENCE {
497 algorithm OBJECT IDENTIFIER,
498 parameters ANY DEFINED BY algorithm OPTIONAL
499 }
500
501 SubjectPublicKeyInfo ::= SEQUENCE {
502 algorithm AlgorithmIdentifier,
503 subjectPublicKey BIT STRING
504 }
505
506In case the function returns a hash of the key:
507
508 DigestInfo ::= SEQUENCE {
509 digestAlgorithm AlgorithmIdentifier,
510 digest OCTET STRING
511 }
512
513The function returns 0 on success. Any other value means the ROTPK could not be
514retrieved from the platform. The function also reports extra information related
515to the ROTPK in the flags parameter.
516
517
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100518
5192.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100520---------------------------------
521
522The following are helper functions implemented by the firmware that perform
523common platform-specific tasks. A platform may choose to override these
524definitions.
525
526
527### Function : platform_get_core_pos()
528
529 Argument : unsigned long
530 Return : int
531
532A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
533can be used as a CPU-specific linear index into blocks of memory (for example
534while allocating per-CPU stacks). This routine contains a simple mechanism
535to perform this conversion, using the assumption that each cluster contains a
536maximum of 4 CPUs:
537
538 linear index = cpu_id + (cluster_id * 4)
539
540 cpu_id = 8-bit value in MPIDR at affinity level 0
541 cluster_id = 8-bit value in MPIDR at affinity level 1
542
543
Achin Gupta4f6ad662013-10-25 09:08:21 +0100544### Function : platform_set_stack()
545
546 Argument : unsigned long
547 Return : void
548
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000549This function sets the current stack pointer to the normal memory stack that
550has been allocated for the CPU specificed by MPIDR. For BL images that only
551require a stack for the primary CPU the parameter is ignored. The size of
552the stack allocated to each CPU is specified by the platform defined constant
553`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100554
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000555Common implementations of this function for the UP and MP BL images are
556provided in [plat/common/aarch64/platform_up_stack.S] and
557[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100558
559
Achin Guptac8afc782013-11-25 18:45:02 +0000560### Function : platform_get_stack()
561
562 Argument : unsigned long
563 Return : unsigned long
564
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000565This function returns the base address of the normal memory stack that
566has been allocated for the CPU specificed by MPIDR. For BL images that only
567require a stack for the primary CPU the parameter is ignored. The size of
568the stack allocated to each CPU is specified by the platform defined constant
569`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000570
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000571Common implementations of this function for the UP and MP BL images are
572provided in [plat/common/aarch64/platform_up_stack.S] and
573[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000574
575
Achin Gupta4f6ad662013-10-25 09:08:21 +0100576### Function : plat_report_exception()
577
578 Argument : unsigned int
579 Return : void
580
581A platform may need to report various information about its status when an
582exception is taken, for example the current exception level, the CPU security
583state (secure/non-secure), the exception type, and so on. This function is
584called in the following circumstances:
585
586* In BL1, whenever an exception is taken.
587* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100588
589The default implementation doesn't do anything, to avoid making assumptions
590about the way the platform displays its status information.
591
592This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000593exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100594that these constants are not related to any architectural exception code; they
595are just an ARM Trusted Firmware convention.
596
597
Soby Mathew24fb8382014-08-14 12:22:32 +0100598### Function : plat_reset_handler()
599
600 Argument : void
601 Return : void
602
603A platform may need to do additional initialization after reset. This function
604allows the platform to do the platform specific intializations. Platform
605specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000606preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100607
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000608The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000609the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100610guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100611
Soby Mathewadd40352014-08-14 12:49:05 +0100612### Function : plat_disable_acp()
613
614 Argument : void
615 Return : void
616
617This api allows a platform to disable the Accelerator Coherency Port (if
618present) during a cluster power down sequence. The default weak implementation
619doesn't do anything. Since this api is called during the power down sequence,
620it has restrictions for stack usage and it can use the registers x0 - x17 as
621scratch registers. It should preserve the value in x18 register as it is used
622by the caller to store the return address.
623
Soby Mathew24fb8382014-08-14 12:22:32 +0100624
Achin Gupta4f6ad662013-10-25 09:08:21 +01006253. Modifications specific to a Boot Loader stage
626-------------------------------------------------
627
6283.1 Boot Loader Stage 1 (BL1)
629-----------------------------
630
631BL1 implements the reset vector where execution starts from after a cold or
632warm boot. For each CPU, BL1 is responsible for the following tasks:
633
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006341. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100635
6362. In the case of a cold boot and the CPU being the primary CPU, ensuring that
637 only this CPU executes the remaining BL1 code, including loading and passing
638 control to the BL2 stage.
639
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006403. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100641 address specified by the platform defined constant `BL2_BASE`.
642
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006434. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100644 accessible by BL2 immediately upon entry.
645
646 meminfo.total_base = Base address of secure RAM visible to BL2
647 meminfo.total_size = Size of secure RAM visible to BL2
648 meminfo.free_base = Base address of secure RAM available for
649 allocation to BL2
650 meminfo.free_size = Size of secure RAM available for allocation to BL2
651
652 BL1 places this `meminfo` structure at the beginning of the free memory
653 available for its use. Since BL1 cannot allocate memory dynamically at the
654 moment, its free memory will be available for BL2's use as-is. However, this
655 means that BL2 must read the `meminfo` structure before it starts using its
656 free memory (this is discussed in Section 3.2).
657
658 In future releases of the ARM Trusted Firmware it will be possible for
659 the platform to decide where it wants to place the `meminfo` structure for
660 BL2.
661
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100662 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100663 BL2 `meminfo` structure. The platform may override this implementation, for
664 example if the platform wants to restrict the amount of memory visible to
665 BL2. Details of how to do this are given below.
666
667The following functions need to be implemented by the platform port to enable
668BL1 to perform the above tasks.
669
670
Dan Handley4a75b842015-03-19 19:24:43 +0000671### Function : bl1_early_platform_setup() [mandatory]
672
673 Argument : void
674 Return : void
675
676This function executes with the MMU and data caches disabled. It is only called
677by the primary CPU.
678
679In ARM standard platforms, this function initializes the console and enables
680snoop requests into the primary CPU's cluster.
681
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100682### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100683
684 Argument : void
685 Return : void
686
Achin Gupta4f6ad662013-10-25 09:08:21 +0100687This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000688platform requires. Platform-specific setup might include configuration of
689memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100690
Dan Handley4a75b842015-03-19 19:24:43 +0000691In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100692
693This function helps fulfill requirement 2 above.
694
695
696### Function : bl1_platform_setup() [mandatory]
697
698 Argument : void
699 Return : void
700
701This function executes with the MMU and data caches enabled. It is responsible
702for performing any remaining platform-specific setup that can occur after the
703MMU and data cache have been enabled.
704
Dan Handley4a75b842015-03-19 19:24:43 +0000705In ARM standard platforms, this function initializes the storage abstraction
706layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000707
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100708This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100709
710
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000711### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100712
713 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000714 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100715
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000716This function should only be called on the cold boot path. It executes with the
717MMU and data caches enabled. The pointer returned by this function must point to
718a `meminfo` structure containing the extents and availability of secure RAM for
719the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100720
721 meminfo.total_base = Base address of secure RAM visible to BL1
722 meminfo.total_size = Size of secure RAM visible to BL1
723 meminfo.free_base = Base address of secure RAM available for allocation
724 to BL1
725 meminfo.free_size = Size of secure RAM available for allocation to BL1
726
727This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
728populates a similar structure to tell BL2 the extents of memory available for
729its own use.
730
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100731This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100732
733
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100734### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100735
736 Argument : meminfo *, meminfo *, unsigned int, unsigned long
737 Return : void
738
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100739BL1 needs to tell the next stage the amount of secure RAM available
740for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100741structure.
742
743Depending upon where BL2 has been loaded in secure RAM (determined by
744`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
745BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000746to BL2. An illustration of how this is done in ARM standard platforms is given
747in the **Memory layout on ARM development platforms** section in the
748[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100749
750
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100751### Function : bl1_plat_set_bl2_ep_info() [mandatory]
752
753 Argument : image_info *, entry_point_info *
754 Return : void
755
756This function is called after loading BL2 image and it can be used to overwrite
757the entry point set by loader and also set the security state and SPSR which
758represents the entry point system state for BL2.
759
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100760
Achin Gupta4f6ad662013-10-25 09:08:21 +01007613.2 Boot Loader Stage 2 (BL2)
762-----------------------------
763
764The BL2 stage is executed only by the primary CPU, which is determined in BL1
765using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
766`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
767
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007681. (Optional) Loading the BL3-0 binary image (if present) from platform
769 provided non-volatile storage. To load the BL3-0 image, BL2 makes use of
770 the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function.
771 The platform also defines the address in memory where BL3-0 is loaded
772 through the optional constant `BL30_BASE`. BL2 uses this information
773 to determine if there is enough memory to load the BL3-0 image.
774 Subsequent handling of the BL3-0 image is platform-specific and is
775 implemented in the `bl2_plat_handle_bl30()` function.
776 If `BL30_BASE` is not defined then this step is not performed.
777
7782. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
Harry Liebeld265bd72014-01-31 19:04:10 +0000779 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
780 by BL1. This structure allows BL2 to calculate how much secure RAM is
781 available for its use. The platform also defines the address in secure RAM
782 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
783 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100784
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007853. (Optional) Loading the BL3-2 binary image (if present) from platform
Dan Handley1151c822014-04-15 11:38:38 +0100786 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100787 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
788 The platform also defines the address in memory where BL3-2 is loaded
789 through the optional constant `BL32_BASE`. BL2 uses this information
790 to determine if there is enough memory to load the BL3-2 image.
791 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000792
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007934. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100794 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100795 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100796 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000797
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007985. Loading the normal world BL3-3 binary image into non-secure DRAM from
799 platform storage and arranging for BL3-1 to pass control to this image. This
800 address is determined using the `plat_get_ns_image_entrypoint()` function
801 described below.
802
8036. BL2 populates an `entry_point_info` structure in memory provided by the
804 platform with information about how BL3-1 should pass control to the
805 other BL images.
806
Achin Gupta4f6ad662013-10-25 09:08:21 +0100807The following functions must be implemented by the platform port to enable BL2
808to perform the above tasks.
809
810
811### Function : bl2_early_platform_setup() [mandatory]
812
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100813 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100814 Return : void
815
816This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100817by the primary CPU. The arguments to this function is the address of the
818`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100819
820The platform must copy the contents of the `meminfo` structure into a private
821variable as the original memory may be subsequently overwritten by BL2. The
822copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000823`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100824
Dan Handley4a75b842015-03-19 19:24:43 +0000825In ARM standard platforms, this function also initializes the storage
826abstraction layer used to load further bootloader images. It is necessary to do
827this early on platforms with a BL3-0 image, since the later `bl2_platform_setup`
828must be done after BL3-0 is loaded.
829
Achin Gupta4f6ad662013-10-25 09:08:21 +0100830
831### Function : bl2_plat_arch_setup() [mandatory]
832
833 Argument : void
834 Return : void
835
836This function executes with the MMU and data caches disabled. It is only called
837by the primary CPU.
838
839The purpose of this function is to perform any architectural initialization
840that varies across platforms, for example enabling the MMU (since the memory
841map differs across platforms).
842
843
844### Function : bl2_platform_setup() [mandatory]
845
846 Argument : void
847 Return : void
848
849This function may execute with the MMU and data caches enabled if the platform
850port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
851called by the primary CPU.
852
Achin Guptae4d084e2014-02-19 17:18:23 +0000853The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +0000854specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +0100855
Dan Handley4a75b842015-03-19 19:24:43 +0000856In ARM standard platforms, this function performs security setup, including
857configuration of the TrustZone controller to allow non-secure masters access
858to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +0000859
Achin Gupta4f6ad662013-10-25 09:08:21 +0100860
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000861### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100862
863 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000864 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100865
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000866This function should only be called on the cold boot path. It may execute with
867the MMU and data caches enabled if the platform port does the necessary
868initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100869
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000870The purpose of this function is to return a pointer to a `meminfo` structure
871populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100872`bl2_early_platform_setup()` above.
873
874
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100875### Function : bl2_plat_get_bl30_meminfo() [mandatory]
876
877 Argument : meminfo *
878 Return : void
879
880This function is used to get the memory limits where BL2 can load the
881BL3-0 image. The meminfo provided by this is used by load_image() to
882validate whether the BL3-0 image can be loaded within the given
883memory from the given base.
884
885
886### Function : bl2_plat_handle_bl30() [mandatory]
887
888 Argument : image_info *
889 Return : int
890
891This function is called after loading BL3-0 image and it is used to perform any
892platform-specific actions required to handle the SCP firmware. Typically it
893transfers the image into SCP memory using a platform-specific protocol and waits
894until SCP executes it and signals to the Application Processor (AP) for BL2
895execution to continue.
896
897This function returns 0 on success, a negative error code otherwise.
898
899
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100900### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000901
902 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100903 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000904
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100905BL2 platform code needs to return a pointer to a `bl31_params` structure it
906will use for passing information to BL3-1. The `bl31_params` structure carries
907the following information.
908 - Header describing the version information for interpreting the bl31_param
909 structure
910 - Information about executing the BL3-3 image in the `bl33_ep_info` field
911 - Information about executing the BL3-2 image in the `bl32_ep_info` field
912 - Information about the type and extents of BL3-1 image in the
913 `bl31_image_info` field
914 - Information about the type and extents of BL3-2 image in the
915 `bl32_image_info` field
916 - Information about the type and extents of BL3-3 image in the
917 `bl33_image_info` field
918
919The memory pointed by this structure and its sub-structures should be
920accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
921necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000922
923
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100924### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100925
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100926 Argument : void
927 Return : entry_point_info *
928
929BL2 platform code returns a pointer which is used to populate the entry point
930information for BL3-1 entry point. The location pointed by it should be
931accessible from BL1 while processing the synchronous exception to run to BL3-1.
932
Dan Handley4a75b842015-03-19 19:24:43 +0000933In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
934structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100935
936
937### Function : bl2_plat_set_bl31_ep_info() [mandatory]
938
939 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100940 Return : void
941
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100942This function is called after loading BL3-1 image and it can be used to
943overwrite the entry point set by loader and also set the security state
944and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100945
Achin Gupta4f6ad662013-10-25 09:08:21 +0100946
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100947### Function : bl2_plat_set_bl32_ep_info() [mandatory]
948
949 Argument : image_info *, entry_point_info *
950 Return : void
951
952This function is called after loading BL3-2 image and it can be used to
953overwrite the entry point set by loader and also set the security state
954and SPSR which represents the entry point system state for BL3-2.
955
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100956
957### Function : bl2_plat_set_bl33_ep_info() [mandatory]
958
959 Argument : image_info *, entry_point_info *
960 Return : void
961
962This function is called after loading BL3-3 image and it can be used to
963overwrite the entry point set by loader and also set the security state
964and SPSR which represents the entry point system state for BL3-3.
965
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100966
967### Function : bl2_plat_get_bl32_meminfo() [mandatory]
968
969 Argument : meminfo *
970 Return : void
971
972This function is used to get the memory limits where BL2 can load the
973BL3-2 image. The meminfo provided by this is used by load_image() to
974validate whether the BL3-2 image can be loaded with in the given
975memory from the given base.
976
977### Function : bl2_plat_get_bl33_meminfo() [mandatory]
978
979 Argument : meminfo *
980 Return : void
981
982This function is used to get the memory limits where BL2 can load the
983BL3-3 image. The meminfo provided by this is used by load_image() to
984validate whether the BL3-3 image can be loaded with in the given
985memory from the given base.
986
987### Function : bl2_plat_flush_bl31_params() [mandatory]
988
989 Argument : void
990 Return : void
991
992Once BL2 has populated all the structures that needs to be read by BL1
993and BL3-1 including the bl31_params structures and its sub-structures,
994the bl31_ep_info structure and any platform specific data. It flushes
995all these data to the main memory so that it is available when we jump to
996later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100997
998### Function : plat_get_ns_image_entrypoint() [mandatory]
999
1000 Argument : void
1001 Return : unsigned long
1002
1003As previously described, BL2 is responsible for arranging for control to be
1004passed to a normal world BL image through BL3-1. This function returns the
1005entrypoint of that image, which BL3-1 uses to jump to it.
1006
Harry Liebeld265bd72014-01-31 19:04:10 +00001007BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001008
1009
10103.2 Boot Loader Stage 3-1 (BL3-1)
1011---------------------------------
1012
1013During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
1014determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
1015control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
1016CPUs. BL3-1 executes at EL3 and is responsible for:
1017
10181. Re-initializing all architectural and platform state. Although BL1 performs
1019 some of this initialization, BL3-1 remains resident in EL3 and must ensure
1020 that EL3 architectural and platform state is completely initialized. It
1021 should make no assumptions about the system state when it receives control.
1022
10232. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001024 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001025 populated in memory to do this.
1026
10273. Providing runtime firmware services. Currently, BL3-1 only implements a
1028 subset of the Power State Coordination Interface (PSCI) API as a runtime
1029 service. See Section 3.3 below for details of porting the PSCI
1030 implementation.
1031
Achin Gupta35ca3512014-02-19 17:58:33 +000010324. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
1033 specific address by BL2. BL3-1 exports a set of apis that allow runtime
1034 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001035 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
1036 structure populated by BL2 to do this.
1037
1038If BL3-1 is a reset vector, It also needs to handle the reset as specified in
1039section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001040
Achin Gupta4f6ad662013-10-25 09:08:21 +01001041The following functions must be implemented by the platform port to enable BL3-1
1042to perform the above tasks.
1043
1044
1045### Function : bl31_early_platform_setup() [mandatory]
1046
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001047 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001048 Return : void
1049
1050This function executes with the MMU and data caches disabled. It is only called
1051by the primary CPU. The arguments to this function are:
1052
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001053* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001054* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001055
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001056The platform can copy the contents of the `bl31_params` structure and its
1057sub-structures into private variables if the original memory may be
1058subsequently overwritten by BL3-1 and similarly the `void *` pointing
1059to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001060
Dan Handley4a75b842015-03-19 19:24:43 +00001061In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
1062in BL2 memory. BL3-1 copies the information in this pointer to internal data
1063structures.
1064
Achin Gupta4f6ad662013-10-25 09:08:21 +01001065
1066### Function : bl31_plat_arch_setup() [mandatory]
1067
1068 Argument : void
1069 Return : void
1070
1071This function executes with the MMU and data caches disabled. It is only called
1072by the primary CPU.
1073
1074The purpose of this function is to perform any architectural initialization
1075that varies across platforms, for example enabling the MMU (since the memory
1076map differs across platforms).
1077
1078
1079### Function : bl31_platform_setup() [mandatory]
1080
1081 Argument : void
1082 Return : void
1083
1084This function may execute with the MMU and data caches enabled if the platform
1085port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1086called by the primary CPU.
1087
1088The purpose of this function is to complete platform initialization so that both
1089BL3-1 runtime services and normal world software can function correctly.
1090
Dan Handley4a75b842015-03-19 19:24:43 +00001091In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001092* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001093* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001094* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001095* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001096* Detects the system topology.
1097
1098
1099### Function : bl31_get_next_image_info() [mandatory]
1100
Achin Gupta35ca3512014-02-19 17:58:33 +00001101 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001102 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001103
1104This function may execute with the MMU and data caches enabled if the platform
1105port does the necessary initializations in `bl31_plat_arch_setup()`.
1106
1107This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +00001108BL2 for the next image in the security state specified by the argument. BL3-1
1109uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001110state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001111(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1112should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001113
Dan Handley4a75b842015-03-19 19:24:43 +00001114### Function : plat_get_syscnt_freq() [mandatory]
1115
1116 Argument : void
1117 Return : uint64_t
1118
1119This function is used by the architecture setup code to retrieve the counter
1120frequency for the CPU's generic timer. This value will be programmed into the
1121`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1122of the system counter, which is retrieved from the first entry in the frequency
1123modes table.
1124
Achin Gupta4f6ad662013-10-25 09:08:21 +01001125
Achin Gupta4f6ad662013-10-25 09:08:21 +010011263.3 Power State Coordination Interface (in BL3-1)
1127------------------------------------------------
1128
1129The ARM Trusted Firmware's implementation of the PSCI API is based around the
1130concept of an _affinity instance_. Each _affinity instance_ can be uniquely
1131identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
1132interface) and an _affinity level_. A processing element (for example, a
1133CPU) is at level 0. If the CPUs in the system are described in a tree where the
1134node above a CPU is a logical grouping of CPUs that share some state, then
1135affinity level 1 is that group of CPUs (for example, a cluster), and affinity
1136level 2 is a group of clusters (for example, the system). The implementation
1137assumes that the affinity level 1 ID can be computed from the affinity level 0
1138ID (for example, a unique cluster ID can be computed from the CPU ID). The
1139current implementation computes this on the basis of the recommended use of
1140`MPIDR` affinity fields in the ARM Architecture Reference Manual.
1141
1142BL3-1's platform initialization code exports a pointer to the platform-specific
1143power management operations required for the PSCI implementation to function
1144correctly. This information is populated in the `plat_pm_ops` structure. The
1145PSCI implementation calls members of the `plat_pm_ops` structure for performing
1146power management operations for each affinity instance. For example, the target
1147CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
1148handler (if present) is called for each affinity instance as the PSCI
1149implementation powers up each affinity level implemented in the `MPIDR` (for
1150example, CPU, cluster and system).
1151
1152The following functions must be implemented to initialize PSCI functionality in
1153the ARM Trusted Firmware.
1154
1155
1156### Function : plat_get_aff_count() [mandatory]
1157
1158 Argument : unsigned int, unsigned long
1159 Return : unsigned int
1160
1161This function may execute with the MMU and data caches enabled if the platform
1162port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1163called by the primary CPU.
1164
1165This function is called by the PSCI initialization code to detect the system
1166topology. Its purpose is to return the number of affinity instances implemented
1167at a given `affinity level` (specified by the first argument) and a given
1168`MPIDR` (specified by the second argument). For example, on a dual-cluster
1169system where first cluster implements 2 CPUs and the second cluster implements 4
1170CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
1171(`0x0`) and affinity level 0, would return 2. A call to this function with an
1172`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
1173would return 4.
1174
1175
1176### Function : plat_get_aff_state() [mandatory]
1177
1178 Argument : unsigned int, unsigned long
1179 Return : unsigned int
1180
1181This function may execute with the MMU and data caches enabled if the platform
1182port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1183called by the primary CPU.
1184
1185This function is called by the PSCI initialization code. Its purpose is to
1186return the state of an affinity instance. The affinity instance is determined by
1187the affinity ID at a given `affinity level` (specified by the first argument)
1188and an `MPIDR` (specified by the second argument). The state can be one of
1189`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
1190system topologies where certain affinity instances are unimplemented. For
1191example, consider a platform that implements a single cluster with 4 CPUs and
1192another CPU implemented directly on the interconnect with the cluster. The
1193`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
1194CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
1195is missing but needs to be accounted for to reach this single CPU in the
1196topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
1197
1198
Achin Gupta4f6ad662013-10-25 09:08:21 +01001199### Function : platform_setup_pm() [mandatory]
1200
Sandrine Bailleux44804252014-08-06 11:27:23 +01001201 Argument : const plat_pm_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001202 Return : int
1203
1204This function may execute with the MMU and data caches enabled if the platform
1205port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1206called by the primary CPU.
1207
1208This function is called by PSCI initialization code. Its purpose is to export
1209handler routines for platform-specific power management actions by populating
1210the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1211
1212A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001213the ARM FVP specific implementation of these handlers in
1214[plat/arm/board/fvp/fvp_pm.c] as an example. A platform port is expected to
1215implement these handlers if the corresponding PSCI operation is to be supported
1216and these handlers are expected to succeed if the return type is `void`.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001217
1218#### plat_pm_ops.affinst_standby()
1219
1220Perform the platform-specific setup to enter the standby state indicated by the
Soby Mathew539dced2014-10-02 16:56:51 +01001221passed argument. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001222
1223#### plat_pm_ops.affinst_on()
1224
1225Perform the platform specific setup to power on an affinity instance, specified
Soby Mathewe146f4c2014-09-26 15:08:52 +01001226by the `MPIDR` (first argument) and `affinity level` (third argument). The
1227`state` (fourth argument) contains the current state of that affinity instance
Achin Gupta4f6ad662013-10-25 09:08:21 +01001228(ON or OFF). This is useful to determine whether any action must be taken. For
1229example, while powering on a CPU, the cluster that contains this CPU might
1230already be in the ON state. The platform decides what actions must be taken to
1231transition from the current state to the target state (indicated by the power
Soby Mathew539dced2014-10-02 16:56:51 +01001232management operation). The generic code expects the platform to return
1233E_SUCCESS on success or E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001234
1235#### plat_pm_ops.affinst_off()
1236
Soby Mathewe146f4c2014-09-26 15:08:52 +01001237Perform the platform specific setup to power off an affinity instance of the
1238calling CPU. It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001239
Soby Mathewe146f4c2014-09-26 15:08:52 +01001240The `affinity level` (first argument) and `state` (second argument) have
1241a similar meaning as described in the `affinst_on()` operation. They are
1242used to identify the affinity instance on which the call is made and its
1243current state. This gives the platform port an indication of the
Achin Gupta4f6ad662013-10-25 09:08:21 +01001244state transition it must make to perform the requested action. For example, if
1245the calling CPU is the last powered on CPU in the cluster, after powering down
1246affinity level 0 (CPU), the platform port should power down affinity level 1
Soby Mathew539dced2014-10-02 16:56:51 +01001247(the cluster) as well. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001248
Achin Gupta4f6ad662013-10-25 09:08:21 +01001249#### plat_pm_ops.affinst_suspend()
1250
Soby Mathewe146f4c2014-09-26 15:08:52 +01001251Perform the platform specific setup to power off an affinity instance of the
1252calling CPU. It is called by the PSCI `CPU_SUSPEND` API
Achin Gupta4f6ad662013-10-25 09:08:21 +01001253implementation.
1254
Soby Mathewe146f4c2014-09-26 15:08:52 +01001255The `affinity level` (second argument) and `state` (third argument) have a
1256similar meaning as described in the `affinst_on()` operation. They are used to
1257identify the affinity instance on which the call is made and its current state.
1258This gives the platform port an indication of the state transition it must
1259make to perform the requested action. For example, if the calling CPU is the
1260last powered on CPU in the cluster, after powering down affinity level 0 (CPU),
1261the platform port should power down affinity level 1 (the cluster) as well.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001262
1263The difference between turning an affinity instance off versus suspending it
1264is that in the former case, the affinity instance is expected to re-initialize
1265its state when its next powered on (see `affinst_on_finish()`). In the latter
1266case, the affinity instance is expected to save enough state so that it can
1267resume execution by restoring this state when its powered on (see
Soby Mathew539dced2014-10-02 16:56:51 +01001268`affinst_suspend_finish()`).The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001269
Achin Gupta4f6ad662013-10-25 09:08:21 +01001270#### plat_pm_ops.affinst_on_finish()
1271
1272This function is called by the PSCI implementation after the calling CPU is
1273powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1274It performs the platform-specific setup required to initialize enough state for
1275this CPU to enter the normal world and also provide secure runtime firmware
1276services.
1277
Soby Mathewe146f4c2014-09-26 15:08:52 +01001278The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001279similar meaning as described in the previous operations. The generic code
1280expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001281
Achin Gupta4f6ad662013-10-25 09:08:21 +01001282#### plat_pm_ops.affinst_on_suspend()
1283
1284This function is called by the PSCI implementation after the calling CPU is
1285powered on and released from reset in response to an asynchronous wakeup
1286event, for example a timer interrupt that was programmed by the CPU during the
1287`CPU_SUSPEND` call. It performs the platform-specific setup required to
1288restore the saved state for this CPU to resume execution in the normal world
1289and also provide secure runtime firmware services.
1290
Soby Mathewe146f4c2014-09-26 15:08:52 +01001291The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001292similar meaning as described in the previous operations. The generic code
1293expects the platform to succeed.
1294
1295#### plat_pm_ops.validate_power_state()
1296
1297This function is called by the PSCI implementation during the `CPU_SUSPEND`
1298call to validate the `power_state` parameter of the PSCI API. If the
1299`power_state` is known to be invalid, the platform must return
1300PSCI_E_INVALID_PARAMS as error, which is propagated back to the normal
1301world PSCI client.
1302
1303#### plat_pm_ops.validate_ns_entrypoint()
1304
1305This function is called by the PSCI implementation during the `CPU_SUSPEND`
1306and `CPU_ON` calls to validate the non-secure `entry_point` parameter passed
1307by the normal world. If the `entry_point` is known to be invalid, the platform
1308must return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1309normal world PSCI client.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001310
Achin Gupta4f6ad662013-10-25 09:08:21 +01001311BL3-1 platform initialization code must also detect the system topology and
1312the state of each affinity instance in the topology. This information is
1313critical for the PSCI runtime service to function correctly. More details are
1314provided in the description of the `plat_get_aff_count()` and
1315`plat_get_aff_state()` functions above.
1316
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010013173.4 Interrupt Management framework (in BL3-1)
1318----------------------------------------------
1319BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1320generated in either security state and targeted to EL1 or EL2 in the non-secure
1321state or EL3/S-EL1 in the secure state. The design of this framework is
1322described in the [IMF Design Guide]
1323
1324A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001325text briefly describes each api and its implementation in ARM standard
1326platforms. The API implementation depends upon the type of interrupt controller
1327present in the platform. ARM standard platforms implements an ARM Generic
1328Interrupt Controller (ARM GIC) as per the version 2.0 of the
1329[ARM GIC Architecture Specification].
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001330
1331### Function : plat_interrupt_type_to_line() [mandatory]
1332
1333 Argument : uint32_t, uint32_t
1334 Return : uint32_t
1335
1336The ARM processor signals an interrupt exception either through the IRQ or FIQ
1337interrupt line. The specific line that is signaled depends on how the interrupt
1338controller (IC) reports different interrupt types from an execution context in
1339either security state. The IMF uses this API to determine which interrupt line
1340the platform IC uses to signal each type of interrupt supported by the framework
1341from a given security state.
1342
1343The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1344Guide]) indicating the target type of the interrupt, the second parameter is the
1345security state of the originating execution context. The return result is the
1346bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1347FIQ=2.
1348
Dan Handley4a75b842015-03-19 19:24:43 +00001349ARM standard platforms configure the ARM GIC to signal S-EL1 interrupts
1350as FIQs and Non-secure interrupts as IRQs from either security state.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001351
1352
1353### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1354
1355 Argument : void
1356 Return : uint32_t
1357
1358This API returns the type of the highest priority pending interrupt at the
1359platform IC. The IMF uses the interrupt type to retrieve the corresponding
1360handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1361pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1362`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1363
Dan Handley4a75b842015-03-19 19:24:43 +00001364ARM standard platforms read the _Highest Priority Pending Interrupt
1365Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The type
1366of interrupt depends upon the id value as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001367
13681. id < 1022 is reported as a S-EL1 interrupt
13692. id = 1022 is reported as a Non-secure interrupt.
13703. id = 1023 is reported as an invalid interrupt type.
1371
1372
1373### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1374
1375 Argument : void
1376 Return : uint32_t
1377
1378This API returns the id of the highest priority pending interrupt at the
1379platform IC. The IMF passes the id returned by this API to the registered
1380handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1381is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1382
Dan Handley4a75b842015-03-19 19:24:43 +00001383ARM standard platforms read the _Highest Priority Pending Interrupt
1384Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The id
1385that is returned by API depends upon the value of the id read from the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001386controller as follows.
1387
13881. id < 1022. id is returned as is.
13892. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1390 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1391 id is returned by the API.
13923. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1393
1394
1395### Function : plat_ic_acknowledge_interrupt() [mandatory]
1396
1397 Argument : void
1398 Return : uint32_t
1399
1400This API is used by the CPU to indicate to the platform IC that processing of
1401the highest pending interrupt has begun. It should return the id of the
1402interrupt which is being processed.
1403
Dan Handley4a75b842015-03-19 19:24:43 +00001404This function in ARM standard platforms reads the _Interrupt Acknowledge
1405Register_ (`GICC_IAR`). This changes the state of the highest priority pending
1406interrupt from pending to active in the interrupt controller. It returns the
1407value read from the `GICC_IAR`. This value is the id of the interrupt whose
1408state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001409
1410The TSP uses this API to start processing of the secure physical timer
1411interrupt.
1412
1413
1414### Function : plat_ic_end_of_interrupt() [mandatory]
1415
1416 Argument : uint32_t
1417 Return : void
1418
1419This API is used by the CPU to indicate to the platform IC that processing of
1420the interrupt corresponding to the id (passed as the parameter) has
1421finished. The id should be the same as the id returned by the
1422`plat_ic_acknowledge_interrupt()` API.
1423
Dan Handley4a75b842015-03-19 19:24:43 +00001424ARM standard platforms write the id to the _End of Interrupt Register_
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001425(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1426controller.
1427
1428The TSP uses this API to finish processing of the secure physical timer
1429interrupt.
1430
1431
1432### Function : plat_ic_get_interrupt_type() [mandatory]
1433
1434 Argument : uint32_t
1435 Return : uint32_t
1436
1437This API returns the type of the interrupt id passed as the parameter.
1438`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1439interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1440returned depending upon how the interrupt has been configured by the platform
1441IC.
1442
Dan Handley4a75b842015-03-19 19:24:43 +00001443This function in ARM standard platforms configures S-EL1 interrupts
1444as Group0 interrupts and Non-secure interrupts as Group1 interrupts. It reads
1445the group value corresponding to the interrupt id from the relevant _Interrupt
1446Group Register_ (`GICD_IGROUPRn`). It uses the group value to determine the
1447type of interrupt.
1448
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001449
Soby Mathewc67b09b2014-07-14 16:57:23 +010014503.5 Crash Reporting mechanism (in BL3-1)
1451----------------------------------------------
1452BL3-1 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001453of the CPU to enable quick crash analysis and debugging. It requires that a
1454console is designated as the crash console by the platform which will be used to
1455print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001456
Sandrine Bailleux44804252014-08-06 11:27:23 +01001457The following functions must be implemented by the platform if it wants crash
1458reporting mechanism in BL3-1. The functions are implemented in assembly so that
1459they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001460
1461### Function : plat_crash_console_init
1462
1463 Argument : void
1464 Return : int
1465
Sandrine Bailleux44804252014-08-06 11:27:23 +01001466This API is used by the crash reporting mechanism to initialize the crash
1467console. It should only use the general purpose registers x0 to x2 to do the
1468initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001469
Soby Mathewc67b09b2014-07-14 16:57:23 +01001470### Function : plat_crash_console_putc
1471
1472 Argument : int
1473 Return : int
1474
1475This API is used by the crash reporting mechanism to print a character on the
1476designated crash console. It should only use general purpose registers x1 and
1477x2 to do its work. The parameter and the return value are in general purpose
1478register x0.
1479
Soby Mathew27713fb2014-09-08 17:51:01 +010014804. Build flags
1481---------------
1482
1483There are some build flags which can be defined by the platform to control
1484inclusion or exclusion of certain BL stages from the FIP image. These flags
1485need to be defined in the platform makefile which will get included by the
1486build system.
1487
1488* **NEED_BL30**
1489 This flag if defined by the platform mandates that a BL3-0 binary should
1490 be included in the FIP image. The path to the BL3-0 binary can be specified
1491 by the `BL30` build option (see build options in the [User Guide]).
1492
1493* **NEED_BL33**
1494 By default, this flag is defined `yes` by the build system and `BL33`
1495 build option should be supplied as a build option. The platform has the option
1496 of excluding the BL3-3 image in the `fip` image by defining this flag to
1497 `no`.
1498
14995. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001500-------------
1501
1502To avoid subtle toolchain behavioral dependencies, the header files provided
1503by the compiler are not used. The software is built with the `-nostdinc` flag
1504to ensure no headers are included from the toolchain inadvertently. Instead the
1505required headers are included in the ARM Trusted Firmware source tree. The
1506library only contains those C library definitions required by the local
1507implementation. If more functionality is required, the needed library functions
1508will need to be added to the local implementation.
1509
1510Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1511headers have been cut down in order to simplify the implementation. In order to
1512minimize changes to the header files, the [FreeBSD] layout has been maintained.
1513The generic C library definitions can be found in `include/stdlib` with more
1514system and machine specific declarations in `include/stdlib/sys` and
1515`include/stdlib/machine`.
1516
1517The local C library implementations can be found in `lib/stdlib`. In order to
1518extend the C library these files may need to be modified. It is recommended to
1519use a release version of [FreeBSD] as a starting point.
1520
1521The C library header files in the [FreeBSD] source tree are located in the
1522`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1523can be found in the `sys/<machine-type>` directories. These files define things
1524like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1525port for [FreeBSD] does not yet exist, the machine specific definitions are
1526based on existing machine types with similar properties (for example SPARC64).
1527
1528Where possible, C library function implementations were taken from [FreeBSD]
1529as found in the `lib/libc` directory.
1530
1531A copy of the [FreeBSD] sources can be downloaded with `git`.
1532
1533 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1534
1535
Soby Mathew27713fb2014-09-08 17:51:01 +010015366. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001537-----------------------------
1538
1539In order to improve platform independence and portability an storage abstraction
1540layer is used to load data from non-volatile platform storage.
1541
1542Each platform should register devices and their drivers via the Storage layer.
1543These drivers then need to be initialized by bootloader phases as
1544required in their respective `blx_platform_setup()` functions. Currently
1545storage access is only required by BL1 and BL2 phases. The `load_image()`
1546function uses the storage layer to access non-volatile platform storage.
1547
Dan Handley4a75b842015-03-19 19:24:43 +00001548It is mandatory to implement at least one storage driver. For the ARM
1549development platforms the Firmware Image Package (FIP) driver is provided as
1550the default means to load data from storage (see the "Firmware Image Package"
1551section in the [User Guide]). The storage layer is described in the header file
1552`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001553is in `drivers/io/io_storage.c` and the driver files are located in
1554`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001555
1556Each IO driver must provide `io_dev_*` structures, as described in
1557`drivers/io/io_driver.h`. These are returned via a mandatory registration
1558function that is called on platform initialization. The semi-hosting driver
1559implementation in `io_semihosting.c` can be used as an example.
1560
1561The Storage layer provides mechanisms to initialize storage devices before
1562IO operations are called. The basic operations supported by the layer
1563include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1564Drivers do not have to implement all operations, but each platform must
1565provide at least one driver for a device capable of supporting generic
1566operations such as loading a bootloader image.
1567
1568The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01001569firmware. These images are specified by using their identifiers, as defined in
1570[include/plat/common/platform_def.h] (or a separate header file included from
1571there). The platform layer (`plat_get_image_source()`) then returns a reference
1572to a device and a driver-specific `spec` which will be understood by the driver
1573to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001574
1575The layer is designed in such a way that is it possible to chain drivers with
1576other drivers. For example, file-system drivers may be implemented on top of
1577physical block devices, both represented by IO devices with corresponding
1578drivers. In such a case, the file-system "binding" with the block device may
1579be deferred until the file-system device is initialised.
1580
1581The abstraction currently depends on structures being statically allocated
1582by the drivers and callers, as the system does not yet provide a means of
1583dynamically allocating memory. This may also have the affect of limiting the
1584amount of open resources per driver.
1585
1586
Achin Gupta4f6ad662013-10-25 09:08:21 +01001587- - - - - - - - - - - - - - - - - - - - - - - - - -
1588
Dan Handley4a75b842015-03-19 19:24:43 +00001589_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001590
1591
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001592[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1593[IMF Design Guide]: interrupt-framework-design.md
1594[User Guide]: user-guide.md
1595[FreeBSD]: http://www.freebsd.org
Dan Handley4a75b842015-03-19 19:24:43 +00001596[Firmware Design]: firmware-design.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01001597
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001598[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1599[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00001600[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001601[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handley4a75b842015-03-19 19:24:43 +00001602[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
1603[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001604[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00001605[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]