blob: 753b129485c7587786ebace4c66f1cc1bd5698fb [file] [log] [blame] [view]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001ARM Trusted Firmware Porting Guide
2==================================
3
4Contents
5--------
6
71. Introduction
82. Common Modifications
9 * Common mandatory modifications
Vikram Kanigirie452cd82014-05-23 15:56:12 +010010 * Handling reset
Achin Gupta4f6ad662013-10-25 09:08:21 +010011 * Common optional modifications
123. Boot Loader stage specific modifications
13 * Boot Loader stage 1 (BL1)
14 * Boot Loader stage 2 (BL2)
15 * Boot Loader stage 3-1 (BL3-1)
16 * PSCI implementation (in BL3-1)
Harry Liebeld265bd72014-01-31 19:04:10 +0000174. C Library
185. Storage abstraction layer
Achin Gupta4f6ad662013-10-25 09:08:21 +010019
20- - - - - - - - - - - - - - - - - -
21
221. Introduction
23----------------
24
25Porting the ARM Trusted Firmware to a new platform involves making some
26mandatory and optional modifications for both the cold and warm boot paths.
27Modifications consist of:
28
29* Implementing a platform-specific function or variable,
30* Setting up the execution context in a certain way, or
31* Defining certain constants (for example #defines).
32
Dan Handleyb68954c2014-05-29 12:30:24 +010033The platform-specific functions and variables are all declared in
34[include/plat/common/platform.h]. The firmware provides a default implementation
35of variables and functions to fulfill the optional requirements. These
36implementations are all weakly defined; they are provided to ease the porting
37effort. Each platform port can override them with its own implementation if the
38default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010039
40Some modifications are common to all Boot Loader (BL) stages. Section 2
41discusses these in detail. The subsequent sections discuss the remaining
42modifications for each BL stage in detail.
43
44This document should be read in conjunction with the ARM Trusted Firmware
45[User Guide].
46
47
482. Common modifications
49------------------------
50
51This section covers the modifications that should be made by the platform for
52each BL stage to correctly port the firmware stack. They are categorized as
53either mandatory or optional.
54
55
562.1 Common mandatory modifications
57----------------------------------
58A platform port must enable the Memory Management Unit (MMU) with identity
59mapped page tables, and enable both the instruction and data caches for each BL
60stage. In the ARM FVP port, each BL stage configures the MMU in its platform-
61specific architecture setup function, for example `blX_plat_arch_setup()`.
62
63Each platform must allocate a block of identity mapped secure memory with
64Device-nGnRE attributes aligned to page boundary (4K) for each BL stage. This
65memory is identified by the section name `tzfw_coherent_mem` so that its
66possible for the firmware to place variables in it using the following C code
67directive:
68
69 __attribute__ ((section("tzfw_coherent_mem")))
70
71Or alternatively the following assembler code directive:
72
73 .section tzfw_coherent_mem
74
75The `tzfw_coherent_mem` section is used to allocate any data structures that are
76accessed both when a CPU is executing with its MMU and caches enabled, and when
77it's running with its MMU and caches disabled. Examples are given below.
78
79The following variables, functions and constants must be defined by the platform
80for the firmware to work correctly.
81
82
Dan Handleyb68954c2014-05-29 12:30:24 +010083### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +010084
Dan Handleyb68954c2014-05-29 12:30:24 +010085Each platform must ensure that a header file of this name is in the system
86include path with the following constants defined. This may require updating the
87list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM FVP port, this
88file is found in [plat/fvp/include/platform_def.h].
Achin Gupta4f6ad662013-10-25 09:08:21 +010089
James Morrisseyba3155b2013-10-29 10:56:46 +000090* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +010091
92 Defines the linker format used by the platform, for example
93 `elf64-littleaarch64` used by the FVP.
94
James Morrisseyba3155b2013-10-29 10:56:46 +000095* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +010096
97 Defines the processor architecture for the linker by the platform, for
98 example `aarch64` used by the FVP.
99
James Morrisseyba3155b2013-10-29 10:56:46 +0000100* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100101
102 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000103 by [plat/common/aarch64/platform_mp_stack.S] and
104 [plat/common/aarch64/platform_up_stack.S].
105
106* **#define : PCPU_DV_MEM_STACK_SIZE**
107
108 Defines the coherent stack memory available to each CPU. This constant is used
109 by [plat/common/aarch64/platform_mp_stack.S] and
110 [plat/common/aarch64/platform_up_stack.S].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100111
James Morrisseyba3155b2013-10-29 10:56:46 +0000112* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100113
114 Defines the character string printed by BL1 upon entry into the `bl1_main()`
115 function.
116
James Morrisseyba3155b2013-10-29 10:56:46 +0000117* **#define : BL2_IMAGE_NAME**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100118
119 Name of the BL2 binary image on the host file-system. This name is used by
Harry Liebeld265bd72014-01-31 19:04:10 +0000120 BL1 to load BL2 into secure memory from non-volatile storage.
121
122* **#define : BL31_IMAGE_NAME**
123
124 Name of the BL3-1 binary image on the host file-system. This name is used by
125 BL2 to load BL3-1 into secure memory from platform storage.
126
127* **#define : BL33_IMAGE_NAME**
128
129 Name of the BL3-3 binary image on the host file-system. This name is used by
130 BL2 to load BL3-3 into non-secure memory from platform storage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100131
James Morrisseyba3155b2013-10-29 10:56:46 +0000132* **#define : PLATFORM_CACHE_LINE_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100133
134 Defines the size (in bytes) of the largest cache line across all the cache
135 levels in the platform.
136
James Morrisseyba3155b2013-10-29 10:56:46 +0000137* **#define : PLATFORM_CLUSTER_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
139 Defines the total number of clusters implemented by the platform in the
140 system.
141
James Morrisseyba3155b2013-10-29 10:56:46 +0000142* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100143
144 Defines the total number of CPUs implemented by the platform across all
145 clusters in the system.
146
James Morrisseyba3155b2013-10-29 10:56:46 +0000147* **#define : PLATFORM_MAX_CPUS_PER_CLUSTER**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100148
149 Defines the maximum number of CPUs that can be implemented within a cluster
150 on the platform.
151
James Morrisseyba3155b2013-10-29 10:56:46 +0000152* **#define : PRIMARY_CPU**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100153
154 Defines the `MPIDR` of the primary CPU on the platform. This value is used
155 after a cold boot to distinguish between primary and secondary CPUs.
156
James Morrisseyba3155b2013-10-29 10:56:46 +0000157* **#define : TZROM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100158
159 Defines the base address of secure ROM on the platform, where the BL1 binary
160 is loaded. This constant is used by the linker scripts to ensure that the
161 BL1 image fits into the available memory.
162
James Morrisseyba3155b2013-10-29 10:56:46 +0000163* **#define : TZROM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100164
165 Defines the size of secure ROM on the platform. This constant is used by the
166 linker scripts to ensure that the BL1 image fits into the available memory.
167
James Morrisseyba3155b2013-10-29 10:56:46 +0000168* **#define : TZRAM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100169
170 Defines the base address of the secure RAM on platform, where the data
171 section of the BL1 binary is loaded. The BL2 and BL3-1 images are also
172 loaded in this secure RAM region. This constant is used by the linker
173 scripts to ensure that the BL1 data section and BL2/BL3-1 binary images fit
174 into the available memory.
175
James Morrisseyba3155b2013-10-29 10:56:46 +0000176* **#define : TZRAM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100177
178 Defines the size of the secure RAM on the platform. This constant is used by
179 the linker scripts to ensure that the BL1 data section and BL2/BL3-1 binary
180 images fit into the available memory.
181
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100182* **#define : BL1_RO_BASE**
183
184 Defines the base address in secure ROM where BL1 originally lives. Must be
185 aligned on a page-size boundary.
186
187* **#define : BL1_RO_LIMIT**
188
189 Defines the maximum address in secure ROM that BL1's actual content (i.e.
190 excluding any data section allocated at runtime) can occupy.
191
192* **#define : BL1_RW_BASE**
193
194 Defines the base address in secure RAM where BL1's read-write data will live
195 at runtime. Must be aligned on a page-size boundary.
196
197* **#define : BL1_RW_LIMIT**
198
199 Defines the maximum address in secure RAM that BL1's read-write data can
200 occupy at runtime.
201
James Morrisseyba3155b2013-10-29 10:56:46 +0000202* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100203
204 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000205 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100206
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100207* **#define : BL2_LIMIT**
208
209 Defines the maximum address in secure RAM that the BL2 image can occupy.
210
James Morrisseyba3155b2013-10-29 10:56:46 +0000211* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100212
213 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000214 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100215
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100216* **#define : BL31_LIMIT**
217
218 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
219
Harry Liebeld265bd72014-01-31 19:04:10 +0000220* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100221
Harry Liebeld265bd72014-01-31 19:04:10 +0000222 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
223 image. Must be aligned on a page-size boundary.
224
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100225If the BL3-2 image is supported by the platform, the following constants must
226be defined as well:
227
228* **#define : TSP_SEC_MEM_BASE**
229
230 Defines the base address of the secure memory used by the BL3-2 image on the
231 platform.
232
233* **#define : TSP_SEC_MEM_SIZE**
234
235 Defines the size of the secure memory used by the BL3-2 image on the
236 platform.
237
238* **#define : BL32_BASE**
239
240 Defines the base address in secure memory where BL2 loads the BL3-2 binary
241 image. Must be inside the secure memory identified by `TSP_SEC_MEM_BASE` and
242 `TSP_SEC_MEM_SIZE` constants. Must also be aligned on a page-size boundary.
243
244* **#define : BL32_LIMIT**
245
246 Defines the maximum address that the BL3-2 image can occupy. Must be inside
247 the secure memory identified by `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE`
248 constants.
249
250
Dan Handleyb68954c2014-05-29 12:30:24 +0100251### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100252
Dan Handleyb68954c2014-05-29 12:30:24 +0100253Each platform must ensure a file of this name is in the system include path with
254the following macro defined. In the ARM FVP port, this file is found in
255[plat/fvp/include/plat_macros.S].
Soby Mathewa43d4312014-04-07 15:28:55 +0100256
257* **Macro : plat_print_gic_regs**
258
259 This macro allows the crash reporting routine to print GIC registers
260 in case of an unhandled IRQ or FIQ in BL3-1. This aids in debugging and
261 this macro can be defined to be empty in case GIC register reporting is
262 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100263
264### Other mandatory modifications
265
James Morrisseyba3155b2013-10-29 10:56:46 +0000266The following mandatory modifications may be implemented in any file
Achin Gupta4f6ad662013-10-25 09:08:21 +0100267the implementer chooses. In the ARM FVP port, they are implemented in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000268[plat/fvp/aarch64/plat_common.c].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100269
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100270* **Function : uint64_t plat_get_syscnt_freq(void)**
271
272 This function is used by the architecture setup code to retrieve the
273 counter frequency for the CPU's generic timer. This value will be
274 programmed into the `CNTFRQ_EL0` register.
275 In the ARM FVP port, it returns the base frequency of the system counter,
276 which is retrieved from the first entry in the frequency modes table.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100277
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000278
Vikram Kanigirie452cd82014-05-23 15:56:12 +01002792.2 Handling Reset
280------------------
281
282BL1 by default implements the reset vector where execution starts from a cold
283or warm boot. BL3-1 can be optionally set as a reset vector using the
284RESET_TO_BL31 make variable.
285
286For each CPU, the reset vector code is responsible for the following tasks:
287
2881. Distinguishing between a cold boot and a warm boot.
289
2902. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
291 the CPU is placed in a platform-specific state until the primary CPU
292 performs the necessary steps to remove it from this state.
293
2943. In the case of a warm boot, ensuring that the CPU jumps to a platform-
295 specific address in the BL3-1 image in the same processor mode as it was
296 when released from reset.
297
298The following functions need to be implemented by the platform port to enable
299reset vector code to perform the above tasks.
300
301
302### Function : platform_get_entrypoint() [mandatory]
303
304 Argument : unsigned long
305 Return : unsigned int
306
307This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
308is identified by its `MPIDR`, which is passed as the argument. The function is
309responsible for distinguishing between a warm and cold reset using platform-
310specific means. If it's a warm reset then it returns the entrypoint into the
311BL3-1 image that the CPU must jump to. If it's a cold reset then this function
312must return zero.
313
314This function is also responsible for implementing a platform-specific mechanism
315to handle the condition where the CPU has been warm reset but there is no
316entrypoint to jump to.
317
318This function does not follow the Procedure Call Standard used by the
319Application Binary Interface for the ARM 64-bit architecture. The caller should
320not assume that callee saved registers are preserved across a call to this
321function.
322
323This function fulfills requirement 1 and 3 listed above.
324
325
326### Function : plat_secondary_cold_boot_setup() [mandatory]
327
328 Argument : void
329 Return : void
330
331This function is called with the MMU and data caches disabled. It is responsible
332for placing the executing secondary CPU in a platform-specific state until the
333primary CPU performs the necessary actions to bring it out of that state and
334allow entry into the OS.
335
336In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
337responsible for powering up the secondary CPU when normal world software
338requires them.
339
340This function fulfills requirement 2 above.
341
342
343### Function : platform_mem_init() [mandatory]
344
345 Argument : void
346 Return : void
347
348This function is called before any access to data is made by the firmware, in
349order to carry out any essential memory initialization.
350
351The ARM FVP port uses this function to initialize the mailbox memory used for
352providing the warm-boot entry-point addresses.
353
354
355
3562.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100357---------------------------------
358
359The following are helper functions implemented by the firmware that perform
360common platform-specific tasks. A platform may choose to override these
361definitions.
362
363
364### Function : platform_get_core_pos()
365
366 Argument : unsigned long
367 Return : int
368
369A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
370can be used as a CPU-specific linear index into blocks of memory (for example
371while allocating per-CPU stacks). This routine contains a simple mechanism
372to perform this conversion, using the assumption that each cluster contains a
373maximum of 4 CPUs:
374
375 linear index = cpu_id + (cluster_id * 4)
376
377 cpu_id = 8-bit value in MPIDR at affinity level 0
378 cluster_id = 8-bit value in MPIDR at affinity level 1
379
380
381### Function : platform_set_coherent_stack()
382
383 Argument : unsigned long
384 Return : void
385
386A platform may need stack memory that is coherent with main memory to perform
387certain operations like:
388
389* Turning the MMU on, or
390* Flushing caches prior to powering down a CPU or cluster.
391
392Each BL stage allocates this coherent stack memory for each CPU in the
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000393`tzfw_coherent_mem` section.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100394
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000395This function sets the current stack pointer to the coherent stack that
396has been allocated for the CPU specified by MPIDR. For BL images that only
397require a stack for the primary CPU the parameter is ignored. The size of
398the stack allocated to each CPU is specified by the platform defined constant
Achin Gupta4f6ad662013-10-25 09:08:21 +0100399`PCPU_DV_MEM_STACK_SIZE`.
400
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000401Common implementations of this function for the UP and MP BL images are
402provided in [plat/common/aarch64/platform_up_stack.S] and
403[plat/common/aarch64/platform_mp_stack.S]
404
Achin Gupta4f6ad662013-10-25 09:08:21 +0100405
406### Function : platform_is_primary_cpu()
407
408 Argument : unsigned long
409 Return : unsigned int
410
411This function identifies a CPU by its `MPIDR`, which is passed as the argument,
412to determine whether this CPU is the primary CPU or a secondary CPU. A return
413value of zero indicates that the CPU is not the primary CPU, while a non-zero
414return value indicates that the CPU is the primary CPU.
415
416
417### Function : platform_set_stack()
418
419 Argument : unsigned long
420 Return : void
421
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000422This function sets the current stack pointer to the normal memory stack that
423has been allocated for the CPU specificed by MPIDR. For BL images that only
424require a stack for the primary CPU the parameter is ignored. The size of
425the stack allocated to each CPU is specified by the platform defined constant
426`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100427
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000428Common implementations of this function for the UP and MP BL images are
429provided in [plat/common/aarch64/platform_up_stack.S] and
430[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100431
432
Achin Guptac8afc782013-11-25 18:45:02 +0000433### Function : platform_get_stack()
434
435 Argument : unsigned long
436 Return : unsigned long
437
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000438This function returns the base address of the normal memory stack that
439has been allocated for the CPU specificed by MPIDR. For BL images that only
440require a stack for the primary CPU the parameter is ignored. The size of
441the stack allocated to each CPU is specified by the platform defined constant
442`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000443
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000444Common implementations of this function for the UP and MP BL images are
445provided in [plat/common/aarch64/platform_up_stack.S] and
446[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000447
448
Achin Gupta4f6ad662013-10-25 09:08:21 +0100449### Function : plat_report_exception()
450
451 Argument : unsigned int
452 Return : void
453
454A platform may need to report various information about its status when an
455exception is taken, for example the current exception level, the CPU security
456state (secure/non-secure), the exception type, and so on. This function is
457called in the following circumstances:
458
459* In BL1, whenever an exception is taken.
460* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100461
462The default implementation doesn't do anything, to avoid making assumptions
463about the way the platform displays its status information.
464
465This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000466exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100467that these constants are not related to any architectural exception code; they
468are just an ARM Trusted Firmware convention.
469
470
4713. Modifications specific to a Boot Loader stage
472-------------------------------------------------
473
4743.1 Boot Loader Stage 1 (BL1)
475-----------------------------
476
477BL1 implements the reset vector where execution starts from after a cold or
478warm boot. For each CPU, BL1 is responsible for the following tasks:
479
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004801. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100481
4822. In the case of a cold boot and the CPU being the primary CPU, ensuring that
483 only this CPU executes the remaining BL1 code, including loading and passing
484 control to the BL2 stage.
485
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004863. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100487 address specified by the platform defined constant `BL2_BASE`.
488
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004894. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100490 accessible by BL2 immediately upon entry.
491
492 meminfo.total_base = Base address of secure RAM visible to BL2
493 meminfo.total_size = Size of secure RAM visible to BL2
494 meminfo.free_base = Base address of secure RAM available for
495 allocation to BL2
496 meminfo.free_size = Size of secure RAM available for allocation to BL2
497
498 BL1 places this `meminfo` structure at the beginning of the free memory
499 available for its use. Since BL1 cannot allocate memory dynamically at the
500 moment, its free memory will be available for BL2's use as-is. However, this
501 means that BL2 must read the `meminfo` structure before it starts using its
502 free memory (this is discussed in Section 3.2).
503
504 In future releases of the ARM Trusted Firmware it will be possible for
505 the platform to decide where it wants to place the `meminfo` structure for
506 BL2.
507
508 BL1 implements the `init_bl2_mem_layout()` function to populate the
509 BL2 `meminfo` structure. The platform may override this implementation, for
510 example if the platform wants to restrict the amount of memory visible to
511 BL2. Details of how to do this are given below.
512
513The following functions need to be implemented by the platform port to enable
514BL1 to perform the above tasks.
515
516
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100517### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100518
519 Argument : void
520 Return : void
521
Achin Gupta4f6ad662013-10-25 09:08:21 +0100522This function performs any platform-specific and architectural setup that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100523platform requires. Platform-specific setup might include configuration of
524memory controllers, configuration of the interconnect to allow the cluster
525to service cache snoop requests from another cluster, and so on.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100526
527In the ARM FVP port, this function enables CCI snoops into the cluster that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100528primary CPU is part of. It also enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100529
530This function helps fulfill requirement 2 above.
531
532
533### Function : bl1_platform_setup() [mandatory]
534
535 Argument : void
536 Return : void
537
538This function executes with the MMU and data caches enabled. It is responsible
539for performing any remaining platform-specific setup that can occur after the
540MMU and data cache have been enabled.
541
Harry Liebeld265bd72014-01-31 19:04:10 +0000542This function is also responsible for initializing the storage abstraction layer
543which is used to load further bootloader images.
544
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100545This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100546
547
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000548### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100549
550 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000551 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100552
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000553This function should only be called on the cold boot path. It executes with the
554MMU and data caches enabled. The pointer returned by this function must point to
555a `meminfo` structure containing the extents and availability of secure RAM for
556the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100557
558 meminfo.total_base = Base address of secure RAM visible to BL1
559 meminfo.total_size = Size of secure RAM visible to BL1
560 meminfo.free_base = Base address of secure RAM available for allocation
561 to BL1
562 meminfo.free_size = Size of secure RAM available for allocation to BL1
563
564This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
565populates a similar structure to tell BL2 the extents of memory available for
566its own use.
567
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100568This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100569
570
571### Function : init_bl2_mem_layout() [optional]
572
573 Argument : meminfo *, meminfo *, unsigned int, unsigned long
574 Return : void
575
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100576BL1 needs to tell the next stage the amount of secure RAM available
577for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100578structure.
579
580Depending upon where BL2 has been loaded in secure RAM (determined by
581`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
582BL1 also ensures that its data sections resident in secure RAM are not visible
583to BL2. An illustration of how this is done in the ARM FVP port is given in the
584[User Guide], in the Section "Memory layout on Base FVP".
585
586
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100587### Function : bl1_plat_set_bl2_ep_info() [mandatory]
588
589 Argument : image_info *, entry_point_info *
590 Return : void
591
592This function is called after loading BL2 image and it can be used to overwrite
593the entry point set by loader and also set the security state and SPSR which
594represents the entry point system state for BL2.
595
596On FVP, we are setting the security state and the SPSR for the BL2 entrypoint
597
598
Achin Gupta4f6ad662013-10-25 09:08:21 +01005993.2 Boot Loader Stage 2 (BL2)
600-----------------------------
601
602The BL2 stage is executed only by the primary CPU, which is determined in BL1
603using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
604`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
605
Harry Liebeld265bd72014-01-31 19:04:10 +00006061. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
607 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
608 by BL1. This structure allows BL2 to calculate how much secure RAM is
609 available for its use. The platform also defines the address in secure RAM
610 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
611 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100612
Harry Liebeld265bd72014-01-31 19:04:10 +00006132. Loading the normal world BL3-3 binary image into non-secure DRAM from
614 platform storage and arranging for BL3-1 to pass control to this image. This
615 address is determined using the `plat_get_ns_image_entrypoint()` function
616 described below.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100617
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006183. BL2 populates an `entry_point_info` structure in memory provided by the
619 platform with information about how BL3-1 should pass control to the
620 other BL images.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100621
Dan Handley1151c822014-04-15 11:38:38 +01006224. (Optional) Loading the BL3-2 binary image (if present) from platform
623 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100624 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
625 The platform also defines the address in memory where BL3-2 is loaded
626 through the optional constant `BL32_BASE`. BL2 uses this information
627 to determine if there is enough memory to load the BL3-2 image.
628 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000629
Dan Handley1151c822014-04-15 11:38:38 +01006305. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100631 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100632 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100633 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000634
Achin Gupta4f6ad662013-10-25 09:08:21 +0100635The following functions must be implemented by the platform port to enable BL2
636to perform the above tasks.
637
638
639### Function : bl2_early_platform_setup() [mandatory]
640
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100641 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100642 Return : void
643
644This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100645by the primary CPU. The arguments to this function is the address of the
646`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100647
648The platform must copy the contents of the `meminfo` structure into a private
649variable as the original memory may be subsequently overwritten by BL2. The
650copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000651`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100652
653
654### Function : bl2_plat_arch_setup() [mandatory]
655
656 Argument : void
657 Return : void
658
659This function executes with the MMU and data caches disabled. It is only called
660by the primary CPU.
661
662The purpose of this function is to perform any architectural initialization
663that varies across platforms, for example enabling the MMU (since the memory
664map differs across platforms).
665
666
667### Function : bl2_platform_setup() [mandatory]
668
669 Argument : void
670 Return : void
671
672This function may execute with the MMU and data caches enabled if the platform
673port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
674called by the primary CPU.
675
Achin Guptae4d084e2014-02-19 17:18:23 +0000676The purpose of this function is to perform any platform initialization
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100677specific to BL2. Platform security components are configured if required.
678For the Base FVP the TZC-400 TrustZone controller is configured to only
679grant non-secure access to DRAM. This avoids aliasing between secure and
680non-secure accesses in the TLB and cache - secure execution states can use
681the NS attributes in the MMU translation tables to access the DRAM.
Harry Liebelce19cf12014-04-01 19:28:07 +0100682
Harry Liebeld265bd72014-01-31 19:04:10 +0000683This function is also responsible for initializing the storage abstraction layer
684which is used to load further bootloader images.
685
Achin Gupta4f6ad662013-10-25 09:08:21 +0100686
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000687### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100688
689 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000690 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100691
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000692This function should only be called on the cold boot path. It may execute with
693the MMU and data caches enabled if the platform port does the necessary
694initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100695
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000696The purpose of this function is to return a pointer to a `meminfo` structure
697populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100698`bl2_early_platform_setup()` above.
699
700
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100701### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000702
703 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100704 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000705
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100706BL2 platform code needs to return a pointer to a `bl31_params` structure it
707will use for passing information to BL3-1. The `bl31_params` structure carries
708the following information.
709 - Header describing the version information for interpreting the bl31_param
710 structure
711 - Information about executing the BL3-3 image in the `bl33_ep_info` field
712 - Information about executing the BL3-2 image in the `bl32_ep_info` field
713 - Information about the type and extents of BL3-1 image in the
714 `bl31_image_info` field
715 - Information about the type and extents of BL3-2 image in the
716 `bl32_image_info` field
717 - Information about the type and extents of BL3-3 image in the
718 `bl33_image_info` field
719
720The memory pointed by this structure and its sub-structures should be
721accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
722necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000723
724
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100725### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100726
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100727 Argument : void
728 Return : entry_point_info *
729
730BL2 platform code returns a pointer which is used to populate the entry point
731information for BL3-1 entry point. The location pointed by it should be
732accessible from BL1 while processing the synchronous exception to run to BL3-1.
733
734On FVP this is allocated inside an bl2_to_bl31_params_mem structure which
735is allocated at an address pointed by PARAMS_BASE.
736
737
738### Function : bl2_plat_set_bl31_ep_info() [mandatory]
739
740 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100741 Return : void
742
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100743This function is called after loading BL3-1 image and it can be used to
744overwrite the entry point set by loader and also set the security state
745and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100746
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100747On FVP, we are setting the security state and the SPSR for the BL3-1
748entrypoint.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100749
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100750### Function : bl2_plat_set_bl32_ep_info() [mandatory]
751
752 Argument : image_info *, entry_point_info *
753 Return : void
754
755This function is called after loading BL3-2 image and it can be used to
756overwrite the entry point set by loader and also set the security state
757and SPSR which represents the entry point system state for BL3-2.
758
759On FVP, we are setting the security state and the SPSR for the BL3-2
760entrypoint
761
762### Function : bl2_plat_set_bl33_ep_info() [mandatory]
763
764 Argument : image_info *, entry_point_info *
765 Return : void
766
767This function is called after loading BL3-3 image and it can be used to
768overwrite the entry point set by loader and also set the security state
769and SPSR which represents the entry point system state for BL3-3.
770
771On FVP, we are setting the security state and the SPSR for the BL3-3
772entrypoint
773
774### Function : bl2_plat_get_bl32_meminfo() [mandatory]
775
776 Argument : meminfo *
777 Return : void
778
779This function is used to get the memory limits where BL2 can load the
780BL3-2 image. The meminfo provided by this is used by load_image() to
781validate whether the BL3-2 image can be loaded with in the given
782memory from the given base.
783
784### Function : bl2_plat_get_bl33_meminfo() [mandatory]
785
786 Argument : meminfo *
787 Return : void
788
789This function is used to get the memory limits where BL2 can load the
790BL3-3 image. The meminfo provided by this is used by load_image() to
791validate whether the BL3-3 image can be loaded with in the given
792memory from the given base.
793
794### Function : bl2_plat_flush_bl31_params() [mandatory]
795
796 Argument : void
797 Return : void
798
799Once BL2 has populated all the structures that needs to be read by BL1
800and BL3-1 including the bl31_params structures and its sub-structures,
801the bl31_ep_info structure and any platform specific data. It flushes
802all these data to the main memory so that it is available when we jump to
803later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100804
805### Function : plat_get_ns_image_entrypoint() [mandatory]
806
807 Argument : void
808 Return : unsigned long
809
810As previously described, BL2 is responsible for arranging for control to be
811passed to a normal world BL image through BL3-1. This function returns the
812entrypoint of that image, which BL3-1 uses to jump to it.
813
Harry Liebeld265bd72014-01-31 19:04:10 +0000814BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100815
816
8173.2 Boot Loader Stage 3-1 (BL3-1)
818---------------------------------
819
820During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
821determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
822control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
823CPUs. BL3-1 executes at EL3 and is responsible for:
824
8251. Re-initializing all architectural and platform state. Although BL1 performs
826 some of this initialization, BL3-1 remains resident in EL3 and must ensure
827 that EL3 architectural and platform state is completely initialized. It
828 should make no assumptions about the system state when it receives control.
829
8302. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100831 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100832 populated in memory to do this.
833
8343. Providing runtime firmware services. Currently, BL3-1 only implements a
835 subset of the Power State Coordination Interface (PSCI) API as a runtime
836 service. See Section 3.3 below for details of porting the PSCI
837 implementation.
838
Achin Gupta35ca3512014-02-19 17:58:33 +00008394. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
840 specific address by BL2. BL3-1 exports a set of apis that allow runtime
841 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100842 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
843 structure populated by BL2 to do this.
844
845If BL3-1 is a reset vector, It also needs to handle the reset as specified in
846section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +0000847
Achin Gupta4f6ad662013-10-25 09:08:21 +0100848The following functions must be implemented by the platform port to enable BL3-1
849to perform the above tasks.
850
851
852### Function : bl31_early_platform_setup() [mandatory]
853
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100854 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100855 Return : void
856
857This function executes with the MMU and data caches disabled. It is only called
858by the primary CPU. The arguments to this function are:
859
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100860* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100861* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100862
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100863The platform can copy the contents of the `bl31_params` structure and its
864sub-structures into private variables if the original memory may be
865subsequently overwritten by BL3-1 and similarly the `void *` pointing
866to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100867
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100868On the ARM FVP port, BL2 passes a pointer to a `bl31_params` structure populated
869in the secure DRAM at address `0x6000000` in the bl31_params * argument and it
870does not use opaque pointer mentioned earlier. BL3-1 does not copy this
871information to internal data structures as it guarantees that the secure
872DRAM memory will not be overwritten. It maintains an internal reference to this
873information in the `bl2_to_bl31_params` variable.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100874
875### Function : bl31_plat_arch_setup() [mandatory]
876
877 Argument : void
878 Return : void
879
880This function executes with the MMU and data caches disabled. It is only called
881by the primary CPU.
882
883The purpose of this function is to perform any architectural initialization
884that varies across platforms, for example enabling the MMU (since the memory
885map differs across platforms).
886
887
888### Function : bl31_platform_setup() [mandatory]
889
890 Argument : void
891 Return : void
892
893This function may execute with the MMU and data caches enabled if the platform
894port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
895called by the primary CPU.
896
897The purpose of this function is to complete platform initialization so that both
898BL3-1 runtime services and normal world software can function correctly.
899
900The ARM FVP port does the following:
901* Initializes the generic interrupt controller.
902* Configures the CLCD controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100903* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100904* Grants access to the system counter timer module
905* Initializes the FVP power controller device
906* Detects the system topology.
907
908
909### Function : bl31_get_next_image_info() [mandatory]
910
Achin Gupta35ca3512014-02-19 17:58:33 +0000911 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100912 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100913
914This function may execute with the MMU and data caches enabled if the platform
915port does the necessary initializations in `bl31_plat_arch_setup()`.
916
917This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +0000918BL2 for the next image in the security state specified by the argument. BL3-1
919uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100920state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +0000921(that was copied during `bl31_early_platform_setup()`) if the image exists. It
922should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100923
924
Achin Gupta4f6ad662013-10-25 09:08:21 +01009253.3 Power State Coordination Interface (in BL3-1)
926------------------------------------------------
927
928The ARM Trusted Firmware's implementation of the PSCI API is based around the
929concept of an _affinity instance_. Each _affinity instance_ can be uniquely
930identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
931interface) and an _affinity level_. A processing element (for example, a
932CPU) is at level 0. If the CPUs in the system are described in a tree where the
933node above a CPU is a logical grouping of CPUs that share some state, then
934affinity level 1 is that group of CPUs (for example, a cluster), and affinity
935level 2 is a group of clusters (for example, the system). The implementation
936assumes that the affinity level 1 ID can be computed from the affinity level 0
937ID (for example, a unique cluster ID can be computed from the CPU ID). The
938current implementation computes this on the basis of the recommended use of
939`MPIDR` affinity fields in the ARM Architecture Reference Manual.
940
941BL3-1's platform initialization code exports a pointer to the platform-specific
942power management operations required for the PSCI implementation to function
943correctly. This information is populated in the `plat_pm_ops` structure. The
944PSCI implementation calls members of the `plat_pm_ops` structure for performing
945power management operations for each affinity instance. For example, the target
946CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
947handler (if present) is called for each affinity instance as the PSCI
948implementation powers up each affinity level implemented in the `MPIDR` (for
949example, CPU, cluster and system).
950
951The following functions must be implemented to initialize PSCI functionality in
952the ARM Trusted Firmware.
953
954
955### Function : plat_get_aff_count() [mandatory]
956
957 Argument : unsigned int, unsigned long
958 Return : unsigned int
959
960This function may execute with the MMU and data caches enabled if the platform
961port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
962called by the primary CPU.
963
964This function is called by the PSCI initialization code to detect the system
965topology. Its purpose is to return the number of affinity instances implemented
966at a given `affinity level` (specified by the first argument) and a given
967`MPIDR` (specified by the second argument). For example, on a dual-cluster
968system where first cluster implements 2 CPUs and the second cluster implements 4
969CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
970(`0x0`) and affinity level 0, would return 2. A call to this function with an
971`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
972would return 4.
973
974
975### Function : plat_get_aff_state() [mandatory]
976
977 Argument : unsigned int, unsigned long
978 Return : unsigned int
979
980This function may execute with the MMU and data caches enabled if the platform
981port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
982called by the primary CPU.
983
984This function is called by the PSCI initialization code. Its purpose is to
985return the state of an affinity instance. The affinity instance is determined by
986the affinity ID at a given `affinity level` (specified by the first argument)
987and an `MPIDR` (specified by the second argument). The state can be one of
988`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
989system topologies where certain affinity instances are unimplemented. For
990example, consider a platform that implements a single cluster with 4 CPUs and
991another CPU implemented directly on the interconnect with the cluster. The
992`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
993CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
994is missing but needs to be accounted for to reach this single CPU in the
995topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
996
997
998### Function : plat_get_max_afflvl() [mandatory]
999
1000 Argument : void
1001 Return : int
1002
1003This function may execute with the MMU and data caches enabled if the platform
1004port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1005called by the primary CPU.
1006
1007This function is called by the PSCI implementation both during cold and warm
1008boot, to determine the maximum affinity level that the power management
James Morrisseyba3155b2013-10-29 10:56:46 +00001009operations should apply to. ARMv8-A has support for 4 affinity levels. It is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001010likely that hardware will implement fewer affinity levels. This function allows
1011the PSCI implementation to consider only those affinity levels in the system
1012that the platform implements. For example, the Base AEM FVP implements two
1013clusters with a configurable number of CPUs. It reports the maximum affinity
1014level as 1, resulting in PSCI power control up to the cluster level.
1015
1016
1017### Function : platform_setup_pm() [mandatory]
1018
1019 Argument : plat_pm_ops **
1020 Return : int
1021
1022This function may execute with the MMU and data caches enabled if the platform
1023port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1024called by the primary CPU.
1025
1026This function is called by PSCI initialization code. Its purpose is to export
1027handler routines for platform-specific power management actions by populating
1028the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1029
1030A description of each member of this structure is given below. Please refer to
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001031the ARM FVP specific implementation of these handlers in [plat/fvp/plat_pm.c]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001032as an example. A platform port may choose not implement some of the power
1033management operations. For example, the ARM FVP port does not implement the
1034`affinst_standby()` function.
1035
1036#### plat_pm_ops.affinst_standby()
1037
1038Perform the platform-specific setup to enter the standby state indicated by the
1039passed argument.
1040
1041#### plat_pm_ops.affinst_on()
1042
1043Perform the platform specific setup to power on an affinity instance, specified
1044by the `MPIDR` (first argument) and `affinity level` (fourth argument). The
1045`state` (fifth argument) contains the current state of that affinity instance
1046(ON or OFF). This is useful to determine whether any action must be taken. For
1047example, while powering on a CPU, the cluster that contains this CPU might
1048already be in the ON state. The platform decides what actions must be taken to
1049transition from the current state to the target state (indicated by the power
1050management operation).
1051
1052#### plat_pm_ops.affinst_off()
1053
1054Perform the platform specific setup to power off an affinity instance in the
1055`MPIDR` of the calling CPU. It is called by the PSCI `CPU_OFF` API
1056implementation.
1057
1058The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1059(third argument) have a similar meaning as described in the `affinst_on()`
1060operation. They are used to identify the affinity instance on which the call
1061is made and its current state. This gives the platform port an indication of the
1062state transition it must make to perform the requested action. For example, if
1063the calling CPU is the last powered on CPU in the cluster, after powering down
1064affinity level 0 (CPU), the platform port should power down affinity level 1
1065(the cluster) as well.
1066
1067This function is called with coherent stacks. This allows the PSCI
1068implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001069stale stack state after turning off the caches. On ARMv8-A cache hits do not
1070occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001071
1072#### plat_pm_ops.affinst_suspend()
1073
1074Perform the platform specific setup to power off an affinity instance in the
1075`MPIDR` of the calling CPU. It is called by the PSCI `CPU_SUSPEND` API
1076implementation.
1077
1078The `MPIDR` (first argument), `affinity level` (third argument) and `state`
1079(fifth argument) have a similar meaning as described in the `affinst_on()`
1080operation. They are used to identify the affinity instance on which the call
1081is made and its current state. This gives the platform port an indication of the
1082state transition it must make to perform the requested action. For example, if
1083the calling CPU is the last powered on CPU in the cluster, after powering down
1084affinity level 0 (CPU), the platform port should power down affinity level 1
1085(the cluster) as well.
1086
1087The difference between turning an affinity instance off versus suspending it
1088is that in the former case, the affinity instance is expected to re-initialize
1089its state when its next powered on (see `affinst_on_finish()`). In the latter
1090case, the affinity instance is expected to save enough state so that it can
1091resume execution by restoring this state when its powered on (see
1092`affinst_suspend_finish()`).
1093
1094This function is called with coherent stacks. This allows the PSCI
1095implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001096stale stack state after turning off the caches. On ARMv8-A cache hits do not
1097occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001098
1099#### plat_pm_ops.affinst_on_finish()
1100
1101This function is called by the PSCI implementation after the calling CPU is
1102powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1103It performs the platform-specific setup required to initialize enough state for
1104this CPU to enter the normal world and also provide secure runtime firmware
1105services.
1106
1107The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1108(third argument) have a similar meaning as described in the previous operations.
1109
1110This function is called with coherent stacks. This allows the PSCI
1111implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001112stale stack state after turning off the caches. On ARMv8-A cache hits do not
1113occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001114
1115#### plat_pm_ops.affinst_on_suspend()
1116
1117This function is called by the PSCI implementation after the calling CPU is
1118powered on and released from reset in response to an asynchronous wakeup
1119event, for example a timer interrupt that was programmed by the CPU during the
1120`CPU_SUSPEND` call. It performs the platform-specific setup required to
1121restore the saved state for this CPU to resume execution in the normal world
1122and also provide secure runtime firmware services.
1123
1124The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1125(third argument) have a similar meaning as described in the previous operations.
1126
1127This function is called with coherent stacks. This allows the PSCI
1128implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001129stale stack state after turning off the caches. On ARMv8-A cache hits do not
1130occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001131
1132BL3-1 platform initialization code must also detect the system topology and
1133the state of each affinity instance in the topology. This information is
1134critical for the PSCI runtime service to function correctly. More details are
1135provided in the description of the `plat_get_aff_count()` and
1136`plat_get_aff_state()` functions above.
1137
1138
Harry Liebela960f282013-12-12 16:03:44 +000011394. C Library
1140-------------
1141
1142To avoid subtle toolchain behavioral dependencies, the header files provided
1143by the compiler are not used. The software is built with the `-nostdinc` flag
1144to ensure no headers are included from the toolchain inadvertently. Instead the
1145required headers are included in the ARM Trusted Firmware source tree. The
1146library only contains those C library definitions required by the local
1147implementation. If more functionality is required, the needed library functions
1148will need to be added to the local implementation.
1149
1150Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1151headers have been cut down in order to simplify the implementation. In order to
1152minimize changes to the header files, the [FreeBSD] layout has been maintained.
1153The generic C library definitions can be found in `include/stdlib` with more
1154system and machine specific declarations in `include/stdlib/sys` and
1155`include/stdlib/machine`.
1156
1157The local C library implementations can be found in `lib/stdlib`. In order to
1158extend the C library these files may need to be modified. It is recommended to
1159use a release version of [FreeBSD] as a starting point.
1160
1161The C library header files in the [FreeBSD] source tree are located in the
1162`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1163can be found in the `sys/<machine-type>` directories. These files define things
1164like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1165port for [FreeBSD] does not yet exist, the machine specific definitions are
1166based on existing machine types with similar properties (for example SPARC64).
1167
1168Where possible, C library function implementations were taken from [FreeBSD]
1169as found in the `lib/libc` directory.
1170
1171A copy of the [FreeBSD] sources can be downloaded with `git`.
1172
1173 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1174
1175
Harry Liebeld265bd72014-01-31 19:04:10 +000011765. Storage abstraction layer
1177-----------------------------
1178
1179In order to improve platform independence and portability an storage abstraction
1180layer is used to load data from non-volatile platform storage.
1181
1182Each platform should register devices and their drivers via the Storage layer.
1183These drivers then need to be initialized by bootloader phases as
1184required in their respective `blx_platform_setup()` functions. Currently
1185storage access is only required by BL1 and BL2 phases. The `load_image()`
1186function uses the storage layer to access non-volatile platform storage.
1187
1188It is mandatory to implement at least one storage driver. For the FVP the
1189Firmware Image Package(FIP) driver is provided as the default means to load data
1190from storage (see the "Firmware Image Package" section in the [User Guide]).
1191The storage layer is described in the header file `include/io_storage.h`. The
1192implementation of the common library is in `lib/io_storage.c` and the driver
1193files are located in `drivers/io/`.
1194
1195Each IO driver must provide `io_dev_*` structures, as described in
1196`drivers/io/io_driver.h`. These are returned via a mandatory registration
1197function that is called on platform initialization. The semi-hosting driver
1198implementation in `io_semihosting.c` can be used as an example.
1199
1200The Storage layer provides mechanisms to initialize storage devices before
1201IO operations are called. The basic operations supported by the layer
1202include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1203Drivers do not have to implement all operations, but each platform must
1204provide at least one driver for a device capable of supporting generic
1205operations such as loading a bootloader image.
1206
1207The current implementation only allows for known images to be loaded by the
Dan Handleyb68954c2014-05-29 12:30:24 +01001208firmware. These images are specified by using their names, as defined in
1209[include/plat/common/platform.h]. The platform layer (`plat_get_image_source()`)
1210then returns a reference to a device and a driver-specific `spec` which will be
1211understood by the driver to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001212
1213The layer is designed in such a way that is it possible to chain drivers with
1214other drivers. For example, file-system drivers may be implemented on top of
1215physical block devices, both represented by IO devices with corresponding
1216drivers. In such a case, the file-system "binding" with the block device may
1217be deferred until the file-system device is initialised.
1218
1219The abstraction currently depends on structures being statically allocated
1220by the drivers and callers, as the system does not yet provide a means of
1221dynamically allocating memory. This may also have the affect of limiting the
1222amount of open resources per driver.
1223
1224
Achin Gupta4f6ad662013-10-25 09:08:21 +01001225- - - - - - - - - - - - - - - - - - - - - - - - - -
1226
Dan Handleye83b0ca2014-01-14 18:17:09 +00001227_Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001228
1229
1230[User Guide]: user-guide.md
Harry Liebela960f282013-12-12 16:03:44 +00001231[FreeBSD]: http://www.freebsd.org
Achin Gupta4f6ad662013-10-25 09:08:21 +01001232
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001233[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1234[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handleyb68954c2014-05-29 12:30:24 +01001235[plat/fvp/include/platform_def.h]: ../plat/fvp/include/platform_def.h
1236[plat/fvp/include/plat_macros.S]: ../plat/fvp/include/plat_macros.S
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001237[plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c
1238[plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c
1239[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001240[include/plat/common/platform.h]: ../include/plat/common/platform.h