blob: 8b0b4b5ae6830a5d474649d6a3323cd26408fcc0 [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
33The firmware provides a default implementation of variables and functions to
34fulfill the optional requirements. These implementations are all weakly defined;
35they are provided to ease the porting effort. Each platform port can override
36them with its own implementation if the default implementation is inadequate.
37
38Some modifications are common to all Boot Loader (BL) stages. Section 2
39discusses these in detail. The subsequent sections discuss the remaining
40modifications for each BL stage in detail.
41
42This document should be read in conjunction with the ARM Trusted Firmware
43[User Guide].
44
45
462. Common modifications
47------------------------
48
49This section covers the modifications that should be made by the platform for
50each BL stage to correctly port the firmware stack. They are categorized as
51either mandatory or optional.
52
53
542.1 Common mandatory modifications
55----------------------------------
56A platform port must enable the Memory Management Unit (MMU) with identity
57mapped page tables, and enable both the instruction and data caches for each BL
58stage. In the ARM FVP port, each BL stage configures the MMU in its platform-
59specific architecture setup function, for example `blX_plat_arch_setup()`.
60
61Each platform must allocate a block of identity mapped secure memory with
62Device-nGnRE attributes aligned to page boundary (4K) for each BL stage. This
63memory is identified by the section name `tzfw_coherent_mem` so that its
64possible for the firmware to place variables in it using the following C code
65directive:
66
67 __attribute__ ((section("tzfw_coherent_mem")))
68
69Or alternatively the following assembler code directive:
70
71 .section tzfw_coherent_mem
72
73The `tzfw_coherent_mem` section is used to allocate any data structures that are
74accessed both when a CPU is executing with its MMU and caches enabled, and when
75it's running with its MMU and caches disabled. Examples are given below.
76
77The following variables, functions and constants must be defined by the platform
78for the firmware to work correctly.
79
80
81### File : platform.h [mandatory]
82
83Each platform must export a header file of this name with the following
84constants defined. In the ARM FVP port, this file is found in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +000085[plat/fvp/platform.h].
Achin Gupta4f6ad662013-10-25 09:08:21 +010086
James Morrisseyba3155b2013-10-29 10:56:46 +000087* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +010088
89 Defines the linker format used by the platform, for example
90 `elf64-littleaarch64` used by the FVP.
91
James Morrisseyba3155b2013-10-29 10:56:46 +000092* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +010093
94 Defines the processor architecture for the linker by the platform, for
95 example `aarch64` used by the FVP.
96
James Morrisseyba3155b2013-10-29 10:56:46 +000097* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +010098
99 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000100 by [plat/common/aarch64/platform_mp_stack.S] and
101 [plat/common/aarch64/platform_up_stack.S].
102
103* **#define : PCPU_DV_MEM_STACK_SIZE**
104
105 Defines the coherent stack memory available to each CPU. This constant is used
106 by [plat/common/aarch64/platform_mp_stack.S] and
107 [plat/common/aarch64/platform_up_stack.S].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100108
James Morrisseyba3155b2013-10-29 10:56:46 +0000109* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110
111 Defines the character string printed by BL1 upon entry into the `bl1_main()`
112 function.
113
James Morrisseyba3155b2013-10-29 10:56:46 +0000114* **#define : BL2_IMAGE_NAME**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115
116 Name of the BL2 binary image on the host file-system. This name is used by
Harry Liebeld265bd72014-01-31 19:04:10 +0000117 BL1 to load BL2 into secure memory from non-volatile storage.
118
119* **#define : BL31_IMAGE_NAME**
120
121 Name of the BL3-1 binary image on the host file-system. This name is used by
122 BL2 to load BL3-1 into secure memory from platform storage.
123
124* **#define : BL33_IMAGE_NAME**
125
126 Name of the BL3-3 binary image on the host file-system. This name is used by
127 BL2 to load BL3-3 into non-secure memory from platform storage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100128
James Morrisseyba3155b2013-10-29 10:56:46 +0000129* **#define : PLATFORM_CACHE_LINE_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100130
131 Defines the size (in bytes) of the largest cache line across all the cache
132 levels in the platform.
133
James Morrisseyba3155b2013-10-29 10:56:46 +0000134* **#define : PLATFORM_CLUSTER_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100135
136 Defines the total number of clusters implemented by the platform in the
137 system.
138
James Morrisseyba3155b2013-10-29 10:56:46 +0000139* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100140
141 Defines the total number of CPUs implemented by the platform across all
142 clusters in the system.
143
James Morrisseyba3155b2013-10-29 10:56:46 +0000144* **#define : PLATFORM_MAX_CPUS_PER_CLUSTER**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100145
146 Defines the maximum number of CPUs that can be implemented within a cluster
147 on the platform.
148
James Morrisseyba3155b2013-10-29 10:56:46 +0000149* **#define : PRIMARY_CPU**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100150
151 Defines the `MPIDR` of the primary CPU on the platform. This value is used
152 after a cold boot to distinguish between primary and secondary CPUs.
153
James Morrisseyba3155b2013-10-29 10:56:46 +0000154* **#define : TZROM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100155
156 Defines the base address of secure ROM on the platform, where the BL1 binary
157 is loaded. This constant is used by the linker scripts to ensure that the
158 BL1 image fits into the available memory.
159
James Morrisseyba3155b2013-10-29 10:56:46 +0000160* **#define : TZROM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100161
162 Defines the size of secure ROM on the platform. This constant is used by the
163 linker scripts to ensure that the BL1 image fits into the available memory.
164
James Morrisseyba3155b2013-10-29 10:56:46 +0000165* **#define : TZRAM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100166
167 Defines the base address of the secure RAM on platform, where the data
168 section of the BL1 binary is loaded. The BL2 and BL3-1 images are also
169 loaded in this secure RAM region. This constant is used by the linker
170 scripts to ensure that the BL1 data section and BL2/BL3-1 binary images fit
171 into the available memory.
172
James Morrisseyba3155b2013-10-29 10:56:46 +0000173* **#define : TZRAM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100174
175 Defines the size of the secure RAM on the platform. This constant is used by
176 the linker scripts to ensure that the BL1 data section and BL2/BL3-1 binary
177 images fit into the available memory.
178
James Morrisseyba3155b2013-10-29 10:56:46 +0000179* **#define : SYS_CNTCTL_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100180
181 Defines the base address of the `CNTCTLBase` frame of the memory mapped
182 counter and timer in the system level implementation of the generic timer.
183
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100184* **#define : BL1_RO_BASE**
185
186 Defines the base address in secure ROM where BL1 originally lives. Must be
187 aligned on a page-size boundary.
188
189* **#define : BL1_RO_LIMIT**
190
191 Defines the maximum address in secure ROM that BL1's actual content (i.e.
192 excluding any data section allocated at runtime) can occupy.
193
194* **#define : BL1_RW_BASE**
195
196 Defines the base address in secure RAM where BL1's read-write data will live
197 at runtime. Must be aligned on a page-size boundary.
198
199* **#define : BL1_RW_LIMIT**
200
201 Defines the maximum address in secure RAM that BL1's read-write data can
202 occupy at runtime.
203
James Morrisseyba3155b2013-10-29 10:56:46 +0000204* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100205
206 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000207 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100208
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100209* **#define : BL2_LIMIT**
210
211 Defines the maximum address in secure RAM that the BL2 image can occupy.
212
James Morrisseyba3155b2013-10-29 10:56:46 +0000213* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100214
215 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000216 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100217
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100218* **#define : BL31_LIMIT**
219
220 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
221
Harry Liebeld265bd72014-01-31 19:04:10 +0000222* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100223
Harry Liebeld265bd72014-01-31 19:04:10 +0000224 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
225 image. Must be aligned on a page-size boundary.
226
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100227If the BL3-2 image is supported by the platform, the following constants must
228be defined as well:
229
230* **#define : TSP_SEC_MEM_BASE**
231
232 Defines the base address of the secure memory used by the BL3-2 image on the
233 platform.
234
235* **#define : TSP_SEC_MEM_SIZE**
236
237 Defines the size of the secure memory used by the BL3-2 image on the
238 platform.
239
240* **#define : BL32_BASE**
241
242 Defines the base address in secure memory where BL2 loads the BL3-2 binary
243 image. Must be inside the secure memory identified by `TSP_SEC_MEM_BASE` and
244 `TSP_SEC_MEM_SIZE` constants. Must also be aligned on a page-size boundary.
245
246* **#define : BL32_LIMIT**
247
248 Defines the maximum address that the BL3-2 image can occupy. Must be inside
249 the secure memory identified by `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE`
250 constants.
251
252
Soby Mathewa43d4312014-04-07 15:28:55 +0100253### File : platform_macros.S [mandatory]
254
255Each platform must export a file of this name with the following
256macro defined. In the ARM FVP port, this file is found in
257[plat/fvp/include/platform_macros.S].
258
259* **Macro : plat_print_gic_regs**
260
261 This macro allows the crash reporting routine to print GIC registers
262 in case of an unhandled IRQ or FIQ in BL3-1. This aids in debugging and
263 this macro can be defined to be empty in case GIC register reporting is
264 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100265
266### Other mandatory modifications
267
James Morrisseyba3155b2013-10-29 10:56:46 +0000268The following mandatory modifications may be implemented in any file
Achin Gupta4f6ad662013-10-25 09:08:21 +0100269the implementer chooses. In the ARM FVP port, they are implemented in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000270[plat/fvp/aarch64/plat_common.c].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100271
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100272* **Function : uint64_t plat_get_syscnt_freq(void)**
273
274 This function is used by the architecture setup code to retrieve the
275 counter frequency for the CPU's generic timer. This value will be
276 programmed into the `CNTFRQ_EL0` register.
277 In the ARM FVP port, it returns the base frequency of the system counter,
278 which is retrieved from the first entry in the frequency modes table.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100279
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000280
Vikram Kanigirie452cd82014-05-23 15:56:12 +01002812.2 Handling Reset
282------------------
283
284BL1 by default implements the reset vector where execution starts from a cold
285or warm boot. BL3-1 can be optionally set as a reset vector using the
286RESET_TO_BL31 make variable.
287
288For each CPU, the reset vector code is responsible for the following tasks:
289
2901. Distinguishing between a cold boot and a warm boot.
291
2922. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
293 the CPU is placed in a platform-specific state until the primary CPU
294 performs the necessary steps to remove it from this state.
295
2963. In the case of a warm boot, ensuring that the CPU jumps to a platform-
297 specific address in the BL3-1 image in the same processor mode as it was
298 when released from reset.
299
300The following functions need to be implemented by the platform port to enable
301reset vector code to perform the above tasks.
302
303
304### Function : platform_get_entrypoint() [mandatory]
305
306 Argument : unsigned long
307 Return : unsigned int
308
309This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
310is identified by its `MPIDR`, which is passed as the argument. The function is
311responsible for distinguishing between a warm and cold reset using platform-
312specific means. If it's a warm reset then it returns the entrypoint into the
313BL3-1 image that the CPU must jump to. If it's a cold reset then this function
314must return zero.
315
316This function is also responsible for implementing a platform-specific mechanism
317to handle the condition where the CPU has been warm reset but there is no
318entrypoint to jump to.
319
320This function does not follow the Procedure Call Standard used by the
321Application Binary Interface for the ARM 64-bit architecture. The caller should
322not assume that callee saved registers are preserved across a call to this
323function.
324
325This function fulfills requirement 1 and 3 listed above.
326
327
328### Function : plat_secondary_cold_boot_setup() [mandatory]
329
330 Argument : void
331 Return : void
332
333This function is called with the MMU and data caches disabled. It is responsible
334for placing the executing secondary CPU in a platform-specific state until the
335primary CPU performs the necessary actions to bring it out of that state and
336allow entry into the OS.
337
338In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
339responsible for powering up the secondary CPU when normal world software
340requires them.
341
342This function fulfills requirement 2 above.
343
344
345### Function : platform_mem_init() [mandatory]
346
347 Argument : void
348 Return : void
349
350This function is called before any access to data is made by the firmware, in
351order to carry out any essential memory initialization.
352
353The ARM FVP port uses this function to initialize the mailbox memory used for
354providing the warm-boot entry-point addresses.
355
356
357
3582.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100359---------------------------------
360
361The following are helper functions implemented by the firmware that perform
362common platform-specific tasks. A platform may choose to override these
363definitions.
364
365
366### Function : platform_get_core_pos()
367
368 Argument : unsigned long
369 Return : int
370
371A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
372can be used as a CPU-specific linear index into blocks of memory (for example
373while allocating per-CPU stacks). This routine contains a simple mechanism
374to perform this conversion, using the assumption that each cluster contains a
375maximum of 4 CPUs:
376
377 linear index = cpu_id + (cluster_id * 4)
378
379 cpu_id = 8-bit value in MPIDR at affinity level 0
380 cluster_id = 8-bit value in MPIDR at affinity level 1
381
382
383### Function : platform_set_coherent_stack()
384
385 Argument : unsigned long
386 Return : void
387
388A platform may need stack memory that is coherent with main memory to perform
389certain operations like:
390
391* Turning the MMU on, or
392* Flushing caches prior to powering down a CPU or cluster.
393
394Each BL stage allocates this coherent stack memory for each CPU in the
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000395`tzfw_coherent_mem` section.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100396
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000397This function sets the current stack pointer to the coherent stack that
398has been allocated for the CPU specified by MPIDR. For BL images that only
399require a stack for the primary CPU the parameter is ignored. The size of
400the stack allocated to each CPU is specified by the platform defined constant
Achin Gupta4f6ad662013-10-25 09:08:21 +0100401`PCPU_DV_MEM_STACK_SIZE`.
402
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000403Common implementations of this function for the UP and MP BL images are
404provided in [plat/common/aarch64/platform_up_stack.S] and
405[plat/common/aarch64/platform_mp_stack.S]
406
Achin Gupta4f6ad662013-10-25 09:08:21 +0100407
408### Function : platform_is_primary_cpu()
409
410 Argument : unsigned long
411 Return : unsigned int
412
413This function identifies a CPU by its `MPIDR`, which is passed as the argument,
414to determine whether this CPU is the primary CPU or a secondary CPU. A return
415value of zero indicates that the CPU is not the primary CPU, while a non-zero
416return value indicates that the CPU is the primary CPU.
417
418
419### Function : platform_set_stack()
420
421 Argument : unsigned long
422 Return : void
423
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000424This function sets the current stack pointer to the normal memory stack that
425has been allocated for the CPU specificed by MPIDR. For BL images that only
426require a stack for the primary CPU the parameter is ignored. The size of
427the stack allocated to each CPU is specified by the platform defined constant
428`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100429
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000430Common implementations of this function for the UP and MP BL images are
431provided in [plat/common/aarch64/platform_up_stack.S] and
432[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100433
434
Achin Guptac8afc782013-11-25 18:45:02 +0000435### Function : platform_get_stack()
436
437 Argument : unsigned long
438 Return : unsigned long
439
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000440This function returns the base address of the normal memory stack that
441has been allocated for the CPU specificed by MPIDR. For BL images that only
442require a stack for the primary CPU the parameter is ignored. The size of
443the stack allocated to each CPU is specified by the platform defined constant
444`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000445
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000446Common implementations of this function for the UP and MP BL images are
447provided in [plat/common/aarch64/platform_up_stack.S] and
448[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000449
450
Achin Gupta4f6ad662013-10-25 09:08:21 +0100451### Function : plat_report_exception()
452
453 Argument : unsigned int
454 Return : void
455
456A platform may need to report various information about its status when an
457exception is taken, for example the current exception level, the CPU security
458state (secure/non-secure), the exception type, and so on. This function is
459called in the following circumstances:
460
461* In BL1, whenever an exception is taken.
462* In BL2, whenever an exception is taken.
463* In BL3-1, whenever an asynchronous exception or a synchronous exception
464 other than an SMC32/SMC64 exception is taken.
465
466The default implementation doesn't do anything, to avoid making assumptions
467about the way the platform displays its status information.
468
469This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000470exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100471that these constants are not related to any architectural exception code; they
472are just an ARM Trusted Firmware convention.
473
474
4753. Modifications specific to a Boot Loader stage
476-------------------------------------------------
477
4783.1 Boot Loader Stage 1 (BL1)
479-----------------------------
480
481BL1 implements the reset vector where execution starts from after a cold or
482warm boot. For each CPU, BL1 is responsible for the following tasks:
483
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004841. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100485
4862. In the case of a cold boot and the CPU being the primary CPU, ensuring that
487 only this CPU executes the remaining BL1 code, including loading and passing
488 control to the BL2 stage.
489
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004903. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100491 address specified by the platform defined constant `BL2_BASE`.
492
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004934. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100494 accessible by BL2 immediately upon entry.
495
496 meminfo.total_base = Base address of secure RAM visible to BL2
497 meminfo.total_size = Size of secure RAM visible to BL2
498 meminfo.free_base = Base address of secure RAM available for
499 allocation to BL2
500 meminfo.free_size = Size of secure RAM available for allocation to BL2
501
502 BL1 places this `meminfo` structure at the beginning of the free memory
503 available for its use. Since BL1 cannot allocate memory dynamically at the
504 moment, its free memory will be available for BL2's use as-is. However, this
505 means that BL2 must read the `meminfo` structure before it starts using its
506 free memory (this is discussed in Section 3.2).
507
508 In future releases of the ARM Trusted Firmware it will be possible for
509 the platform to decide where it wants to place the `meminfo` structure for
510 BL2.
511
512 BL1 implements the `init_bl2_mem_layout()` function to populate the
513 BL2 `meminfo` structure. The platform may override this implementation, for
514 example if the platform wants to restrict the amount of memory visible to
515 BL2. Details of how to do this are given below.
516
517The following functions need to be implemented by the platform port to enable
518BL1 to perform the above tasks.
519
520
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100521### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100522
523 Argument : void
524 Return : void
525
Achin Gupta4f6ad662013-10-25 09:08:21 +0100526This function performs any platform-specific and architectural setup that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100527platform requires. Platform-specific setup might include configuration of
528memory controllers, configuration of the interconnect to allow the cluster
529to service cache snoop requests from another cluster, and so on.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100530
531In the ARM FVP port, this function enables CCI snoops into the cluster that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100532primary CPU is part of. It also enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100533
534This function helps fulfill requirement 2 above.
535
536
537### Function : bl1_platform_setup() [mandatory]
538
539 Argument : void
540 Return : void
541
542This function executes with the MMU and data caches enabled. It is responsible
543for performing any remaining platform-specific setup that can occur after the
544MMU and data cache have been enabled.
545
Harry Liebeld265bd72014-01-31 19:04:10 +0000546This function is also responsible for initializing the storage abstraction layer
547which is used to load further bootloader images.
548
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100549This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100550
551
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000552### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100553
554 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000555 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100556
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000557This function should only be called on the cold boot path. It executes with the
558MMU and data caches enabled. The pointer returned by this function must point to
559a `meminfo` structure containing the extents and availability of secure RAM for
560the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100561
562 meminfo.total_base = Base address of secure RAM visible to BL1
563 meminfo.total_size = Size of secure RAM visible to BL1
564 meminfo.free_base = Base address of secure RAM available for allocation
565 to BL1
566 meminfo.free_size = Size of secure RAM available for allocation to BL1
567
568This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
569populates a similar structure to tell BL2 the extents of memory available for
570its own use.
571
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100572This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100573
574
575### Function : init_bl2_mem_layout() [optional]
576
577 Argument : meminfo *, meminfo *, unsigned int, unsigned long
578 Return : void
579
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100580BL1 needs to tell the next stage the amount of secure RAM available
581for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100582structure.
583
584Depending upon where BL2 has been loaded in secure RAM (determined by
585`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
586BL1 also ensures that its data sections resident in secure RAM are not visible
587to BL2. An illustration of how this is done in the ARM FVP port is given in the
588[User Guide], in the Section "Memory layout on Base FVP".
589
590
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100591### Function : bl1_plat_set_bl2_ep_info() [mandatory]
592
593 Argument : image_info *, entry_point_info *
594 Return : void
595
596This function is called after loading BL2 image and it can be used to overwrite
597the entry point set by loader and also set the security state and SPSR which
598represents the entry point system state for BL2.
599
600On FVP, we are setting the security state and the SPSR for the BL2 entrypoint
601
602
Achin Gupta4f6ad662013-10-25 09:08:21 +01006033.2 Boot Loader Stage 2 (BL2)
604-----------------------------
605
606The BL2 stage is executed only by the primary CPU, which is determined in BL1
607using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
608`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
609
Harry Liebeld265bd72014-01-31 19:04:10 +00006101. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
611 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
612 by BL1. This structure allows BL2 to calculate how much secure RAM is
613 available for its use. The platform also defines the address in secure RAM
614 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
615 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100616
Harry Liebeld265bd72014-01-31 19:04:10 +00006172. Loading the normal world BL3-3 binary image into non-secure DRAM from
618 platform storage and arranging for BL3-1 to pass control to this image. This
619 address is determined using the `plat_get_ns_image_entrypoint()` function
620 described below.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100621
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006223. BL2 populates an `entry_point_info` structure in memory provided by the
623 platform with information about how BL3-1 should pass control to the
624 other BL images.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100625
Dan Handley1151c822014-04-15 11:38:38 +01006264. (Optional) Loading the BL3-2 binary image (if present) from platform
627 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100628 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
629 The platform also defines the address in memory where BL3-2 is loaded
630 through the optional constant `BL32_BASE`. BL2 uses this information
631 to determine if there is enough memory to load the BL3-2 image.
632 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000633
Dan Handley1151c822014-04-15 11:38:38 +01006345. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100635 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100636 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100637 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000638
Achin Gupta4f6ad662013-10-25 09:08:21 +0100639The following functions must be implemented by the platform port to enable BL2
640to perform the above tasks.
641
642
643### Function : bl2_early_platform_setup() [mandatory]
644
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100645 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100646 Return : void
647
648This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100649by the primary CPU. The arguments to this function is the address of the
650`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100651
652The platform must copy the contents of the `meminfo` structure into a private
653variable as the original memory may be subsequently overwritten by BL2. The
654copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000655`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100656
657
658### Function : bl2_plat_arch_setup() [mandatory]
659
660 Argument : void
661 Return : void
662
663This function executes with the MMU and data caches disabled. It is only called
664by the primary CPU.
665
666The purpose of this function is to perform any architectural initialization
667that varies across platforms, for example enabling the MMU (since the memory
668map differs across platforms).
669
670
671### Function : bl2_platform_setup() [mandatory]
672
673 Argument : void
674 Return : void
675
676This function may execute with the MMU and data caches enabled if the platform
677port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
678called by the primary CPU.
679
Achin Guptae4d084e2014-02-19 17:18:23 +0000680The purpose of this function is to perform any platform initialization
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100681specific to BL2. Platform security components are configured if required.
682For the Base FVP the TZC-400 TrustZone controller is configured to only
683grant non-secure access to DRAM. This avoids aliasing between secure and
684non-secure accesses in the TLB and cache - secure execution states can use
685the NS attributes in the MMU translation tables to access the DRAM.
Harry Liebelce19cf12014-04-01 19:28:07 +0100686
Harry Liebeld265bd72014-01-31 19:04:10 +0000687This function is also responsible for initializing the storage abstraction layer
688which is used to load further bootloader images.
689
Achin Gupta4f6ad662013-10-25 09:08:21 +0100690
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000691### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100692
693 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000694 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100695
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000696This function should only be called on the cold boot path. It may execute with
697the MMU and data caches enabled if the platform port does the necessary
698initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100699
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000700The purpose of this function is to return a pointer to a `meminfo` structure
701populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100702`bl2_early_platform_setup()` above.
703
704
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100705### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000706
707 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100708 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000709
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100710BL2 platform code needs to return a pointer to a `bl31_params` structure it
711will use for passing information to BL3-1. The `bl31_params` structure carries
712the following information.
713 - Header describing the version information for interpreting the bl31_param
714 structure
715 - Information about executing the BL3-3 image in the `bl33_ep_info` field
716 - Information about executing the BL3-2 image in the `bl32_ep_info` field
717 - Information about the type and extents of BL3-1 image in the
718 `bl31_image_info` field
719 - Information about the type and extents of BL3-2 image in the
720 `bl32_image_info` field
721 - Information about the type and extents of BL3-3 image in the
722 `bl33_image_info` field
723
724The memory pointed by this structure and its sub-structures should be
725accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
726necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000727
728
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100729### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100730
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100731 Argument : void
732 Return : entry_point_info *
733
734BL2 platform code returns a pointer which is used to populate the entry point
735information for BL3-1 entry point. The location pointed by it should be
736accessible from BL1 while processing the synchronous exception to run to BL3-1.
737
738On FVP this is allocated inside an bl2_to_bl31_params_mem structure which
739is allocated at an address pointed by PARAMS_BASE.
740
741
742### Function : bl2_plat_set_bl31_ep_info() [mandatory]
743
744 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100745 Return : void
746
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100747This function is called after loading BL3-1 image and it can be used to
748overwrite the entry point set by loader and also set the security state
749and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100750
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100751On FVP, we are setting the security state and the SPSR for the BL3-1
752entrypoint.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100753
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100754### Function : bl2_plat_set_bl32_ep_info() [mandatory]
755
756 Argument : image_info *, entry_point_info *
757 Return : void
758
759This function is called after loading BL3-2 image and it can be used to
760overwrite the entry point set by loader and also set the security state
761and SPSR which represents the entry point system state for BL3-2.
762
763On FVP, we are setting the security state and the SPSR for the BL3-2
764entrypoint
765
766### Function : bl2_plat_set_bl33_ep_info() [mandatory]
767
768 Argument : image_info *, entry_point_info *
769 Return : void
770
771This function is called after loading BL3-3 image and it can be used to
772overwrite the entry point set by loader and also set the security state
773and SPSR which represents the entry point system state for BL3-3.
774
775On FVP, we are setting the security state and the SPSR for the BL3-3
776entrypoint
777
778### Function : bl2_plat_get_bl32_meminfo() [mandatory]
779
780 Argument : meminfo *
781 Return : void
782
783This function is used to get the memory limits where BL2 can load the
784BL3-2 image. The meminfo provided by this is used by load_image() to
785validate whether the BL3-2 image can be loaded with in the given
786memory from the given base.
787
788### Function : bl2_plat_get_bl33_meminfo() [mandatory]
789
790 Argument : meminfo *
791 Return : void
792
793This function is used to get the memory limits where BL2 can load the
794BL3-3 image. The meminfo provided by this is used by load_image() to
795validate whether the BL3-3 image can be loaded with in the given
796memory from the given base.
797
798### Function : bl2_plat_flush_bl31_params() [mandatory]
799
800 Argument : void
801 Return : void
802
803Once BL2 has populated all the structures that needs to be read by BL1
804and BL3-1 including the bl31_params structures and its sub-structures,
805the bl31_ep_info structure and any platform specific data. It flushes
806all these data to the main memory so that it is available when we jump to
807later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100808
809### Function : plat_get_ns_image_entrypoint() [mandatory]
810
811 Argument : void
812 Return : unsigned long
813
814As previously described, BL2 is responsible for arranging for control to be
815passed to a normal world BL image through BL3-1. This function returns the
816entrypoint of that image, which BL3-1 uses to jump to it.
817
Harry Liebeld265bd72014-01-31 19:04:10 +0000818BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100819
820
8213.2 Boot Loader Stage 3-1 (BL3-1)
822---------------------------------
823
824During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
825determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
826control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
827CPUs. BL3-1 executes at EL3 and is responsible for:
828
8291. Re-initializing all architectural and platform state. Although BL1 performs
830 some of this initialization, BL3-1 remains resident in EL3 and must ensure
831 that EL3 architectural and platform state is completely initialized. It
832 should make no assumptions about the system state when it receives control.
833
8342. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100835 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100836 populated in memory to do this.
837
8383. Providing runtime firmware services. Currently, BL3-1 only implements a
839 subset of the Power State Coordination Interface (PSCI) API as a runtime
840 service. See Section 3.3 below for details of porting the PSCI
841 implementation.
842
Achin Gupta35ca3512014-02-19 17:58:33 +00008434. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
844 specific address by BL2. BL3-1 exports a set of apis that allow runtime
845 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100846 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
847 structure populated by BL2 to do this.
848
849If BL3-1 is a reset vector, It also needs to handle the reset as specified in
850section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +0000851
Achin Gupta4f6ad662013-10-25 09:08:21 +0100852The following functions must be implemented by the platform port to enable BL3-1
853to perform the above tasks.
854
855
856### Function : bl31_early_platform_setup() [mandatory]
857
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100858 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100859 Return : void
860
861This function executes with the MMU and data caches disabled. It is only called
862by the primary CPU. The arguments to this function are:
863
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100864* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100865* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100866
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100867The platform can copy the contents of the `bl31_params` structure and its
868sub-structures into private variables if the original memory may be
869subsequently overwritten by BL3-1 and similarly the `void *` pointing
870to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100871
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100872On the ARM FVP port, BL2 passes a pointer to a `bl31_params` structure populated
873in the secure DRAM at address `0x6000000` in the bl31_params * argument and it
874does not use opaque pointer mentioned earlier. BL3-1 does not copy this
875information to internal data structures as it guarantees that the secure
876DRAM memory will not be overwritten. It maintains an internal reference to this
877information in the `bl2_to_bl31_params` variable.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100878
879### Function : bl31_plat_arch_setup() [mandatory]
880
881 Argument : void
882 Return : void
883
884This function executes with the MMU and data caches disabled. It is only called
885by the primary CPU.
886
887The purpose of this function is to perform any architectural initialization
888that varies across platforms, for example enabling the MMU (since the memory
889map differs across platforms).
890
891
892### Function : bl31_platform_setup() [mandatory]
893
894 Argument : void
895 Return : void
896
897This function may execute with the MMU and data caches enabled if the platform
898port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
899called by the primary CPU.
900
901The purpose of this function is to complete platform initialization so that both
902BL3-1 runtime services and normal world software can function correctly.
903
904The ARM FVP port does the following:
905* Initializes the generic interrupt controller.
906* Configures the CLCD controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100907* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100908* Grants access to the system counter timer module
909* Initializes the FVP power controller device
910* Detects the system topology.
911
912
913### Function : bl31_get_next_image_info() [mandatory]
914
Achin Gupta35ca3512014-02-19 17:58:33 +0000915 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100916 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100917
918This function may execute with the MMU and data caches enabled if the platform
919port does the necessary initializations in `bl31_plat_arch_setup()`.
920
921This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +0000922BL2 for the next image in the security state specified by the argument. BL3-1
923uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100924state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +0000925(that was copied during `bl31_early_platform_setup()`) if the image exists. It
926should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100927
928
Achin Gupta4f6ad662013-10-25 09:08:21 +01009293.3 Power State Coordination Interface (in BL3-1)
930------------------------------------------------
931
932The ARM Trusted Firmware's implementation of the PSCI API is based around the
933concept of an _affinity instance_. Each _affinity instance_ can be uniquely
934identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
935interface) and an _affinity level_. A processing element (for example, a
936CPU) is at level 0. If the CPUs in the system are described in a tree where the
937node above a CPU is a logical grouping of CPUs that share some state, then
938affinity level 1 is that group of CPUs (for example, a cluster), and affinity
939level 2 is a group of clusters (for example, the system). The implementation
940assumes that the affinity level 1 ID can be computed from the affinity level 0
941ID (for example, a unique cluster ID can be computed from the CPU ID). The
942current implementation computes this on the basis of the recommended use of
943`MPIDR` affinity fields in the ARM Architecture Reference Manual.
944
945BL3-1's platform initialization code exports a pointer to the platform-specific
946power management operations required for the PSCI implementation to function
947correctly. This information is populated in the `plat_pm_ops` structure. The
948PSCI implementation calls members of the `plat_pm_ops` structure for performing
949power management operations for each affinity instance. For example, the target
950CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
951handler (if present) is called for each affinity instance as the PSCI
952implementation powers up each affinity level implemented in the `MPIDR` (for
953example, CPU, cluster and system).
954
955The following functions must be implemented to initialize PSCI functionality in
956the ARM Trusted Firmware.
957
958
959### Function : plat_get_aff_count() [mandatory]
960
961 Argument : unsigned int, unsigned long
962 Return : unsigned int
963
964This function may execute with the MMU and data caches enabled if the platform
965port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
966called by the primary CPU.
967
968This function is called by the PSCI initialization code to detect the system
969topology. Its purpose is to return the number of affinity instances implemented
970at a given `affinity level` (specified by the first argument) and a given
971`MPIDR` (specified by the second argument). For example, on a dual-cluster
972system where first cluster implements 2 CPUs and the second cluster implements 4
973CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
974(`0x0`) and affinity level 0, would return 2. A call to this function with an
975`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
976would return 4.
977
978
979### Function : plat_get_aff_state() [mandatory]
980
981 Argument : unsigned int, unsigned long
982 Return : unsigned int
983
984This function may execute with the MMU and data caches enabled if the platform
985port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
986called by the primary CPU.
987
988This function is called by the PSCI initialization code. Its purpose is to
989return the state of an affinity instance. The affinity instance is determined by
990the affinity ID at a given `affinity level` (specified by the first argument)
991and an `MPIDR` (specified by the second argument). The state can be one of
992`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
993system topologies where certain affinity instances are unimplemented. For
994example, consider a platform that implements a single cluster with 4 CPUs and
995another CPU implemented directly on the interconnect with the cluster. The
996`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
997CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
998is missing but needs to be accounted for to reach this single CPU in the
999topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
1000
1001
1002### Function : plat_get_max_afflvl() [mandatory]
1003
1004 Argument : void
1005 Return : int
1006
1007This function may execute with the MMU and data caches enabled if the platform
1008port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1009called by the primary CPU.
1010
1011This function is called by the PSCI implementation both during cold and warm
1012boot, to determine the maximum affinity level that the power management
James Morrisseyba3155b2013-10-29 10:56:46 +00001013operations should apply to. ARMv8-A has support for 4 affinity levels. It is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001014likely that hardware will implement fewer affinity levels. This function allows
1015the PSCI implementation to consider only those affinity levels in the system
1016that the platform implements. For example, the Base AEM FVP implements two
1017clusters with a configurable number of CPUs. It reports the maximum affinity
1018level as 1, resulting in PSCI power control up to the cluster level.
1019
1020
1021### Function : platform_setup_pm() [mandatory]
1022
1023 Argument : plat_pm_ops **
1024 Return : int
1025
1026This function may execute with the MMU and data caches enabled if the platform
1027port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1028called by the primary CPU.
1029
1030This function is called by PSCI initialization code. Its purpose is to export
1031handler routines for platform-specific power management actions by populating
1032the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1033
1034A description of each member of this structure is given below. Please refer to
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001035the ARM FVP specific implementation of these handlers in [plat/fvp/plat_pm.c]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001036as an example. A platform port may choose not implement some of the power
1037management operations. For example, the ARM FVP port does not implement the
1038`affinst_standby()` function.
1039
1040#### plat_pm_ops.affinst_standby()
1041
1042Perform the platform-specific setup to enter the standby state indicated by the
1043passed argument.
1044
1045#### plat_pm_ops.affinst_on()
1046
1047Perform the platform specific setup to power on an affinity instance, specified
1048by the `MPIDR` (first argument) and `affinity level` (fourth argument). The
1049`state` (fifth argument) contains the current state of that affinity instance
1050(ON or OFF). This is useful to determine whether any action must be taken. For
1051example, while powering on a CPU, the cluster that contains this CPU might
1052already be in the ON state. The platform decides what actions must be taken to
1053transition from the current state to the target state (indicated by the power
1054management operation).
1055
1056#### plat_pm_ops.affinst_off()
1057
1058Perform the platform specific setup to power off an affinity instance in the
1059`MPIDR` of the calling CPU. It is called by the PSCI `CPU_OFF` API
1060implementation.
1061
1062The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1063(third argument) have a similar meaning as described in the `affinst_on()`
1064operation. They are used to identify the affinity instance on which the call
1065is made and its current state. This gives the platform port an indication of the
1066state transition it must make to perform the requested action. For example, if
1067the calling CPU is the last powered on CPU in the cluster, after powering down
1068affinity level 0 (CPU), the platform port should power down affinity level 1
1069(the cluster) as well.
1070
1071This function is called with coherent stacks. This allows the PSCI
1072implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001073stale stack state after turning off the caches. On ARMv8-A cache hits do not
1074occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001075
1076#### plat_pm_ops.affinst_suspend()
1077
1078Perform the platform specific setup to power off an affinity instance in the
1079`MPIDR` of the calling CPU. It is called by the PSCI `CPU_SUSPEND` API
1080implementation.
1081
1082The `MPIDR` (first argument), `affinity level` (third argument) and `state`
1083(fifth argument) have a similar meaning as described in the `affinst_on()`
1084operation. They are used to identify the affinity instance on which the call
1085is made and its current state. This gives the platform port an indication of the
1086state transition it must make to perform the requested action. For example, if
1087the calling CPU is the last powered on CPU in the cluster, after powering down
1088affinity level 0 (CPU), the platform port should power down affinity level 1
1089(the cluster) as well.
1090
1091The difference between turning an affinity instance off versus suspending it
1092is that in the former case, the affinity instance is expected to re-initialize
1093its state when its next powered on (see `affinst_on_finish()`). In the latter
1094case, the affinity instance is expected to save enough state so that it can
1095resume execution by restoring this state when its powered on (see
1096`affinst_suspend_finish()`).
1097
1098This function is called with coherent stacks. This allows the PSCI
1099implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001100stale stack state after turning off the caches. On ARMv8-A cache hits do not
1101occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001102
1103#### plat_pm_ops.affinst_on_finish()
1104
1105This function is called by the PSCI implementation after the calling CPU is
1106powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1107It performs the platform-specific setup required to initialize enough state for
1108this CPU to enter the normal world and also provide secure runtime firmware
1109services.
1110
1111The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1112(third argument) have a similar meaning as described in the previous operations.
1113
1114This function is called with coherent stacks. This allows the PSCI
1115implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001116stale stack state after turning off the caches. On ARMv8-A cache hits do not
1117occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001118
1119#### plat_pm_ops.affinst_on_suspend()
1120
1121This function is called by the PSCI implementation after the calling CPU is
1122powered on and released from reset in response to an asynchronous wakeup
1123event, for example a timer interrupt that was programmed by the CPU during the
1124`CPU_SUSPEND` call. It performs the platform-specific setup required to
1125restore the saved state for this CPU to resume execution in the normal world
1126and also provide secure runtime firmware services.
1127
1128The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1129(third argument) have a similar meaning as described in the previous operations.
1130
1131This function is called with coherent stacks. This allows the PSCI
1132implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001133stale stack state after turning off the caches. On ARMv8-A cache hits do not
1134occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001135
1136BL3-1 platform initialization code must also detect the system topology and
1137the state of each affinity instance in the topology. This information is
1138critical for the PSCI runtime service to function correctly. More details are
1139provided in the description of the `plat_get_aff_count()` and
1140`plat_get_aff_state()` functions above.
1141
1142
Harry Liebela960f282013-12-12 16:03:44 +000011434. C Library
1144-------------
1145
1146To avoid subtle toolchain behavioral dependencies, the header files provided
1147by the compiler are not used. The software is built with the `-nostdinc` flag
1148to ensure no headers are included from the toolchain inadvertently. Instead the
1149required headers are included in the ARM Trusted Firmware source tree. The
1150library only contains those C library definitions required by the local
1151implementation. If more functionality is required, the needed library functions
1152will need to be added to the local implementation.
1153
1154Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1155headers have been cut down in order to simplify the implementation. In order to
1156minimize changes to the header files, the [FreeBSD] layout has been maintained.
1157The generic C library definitions can be found in `include/stdlib` with more
1158system and machine specific declarations in `include/stdlib/sys` and
1159`include/stdlib/machine`.
1160
1161The local C library implementations can be found in `lib/stdlib`. In order to
1162extend the C library these files may need to be modified. It is recommended to
1163use a release version of [FreeBSD] as a starting point.
1164
1165The C library header files in the [FreeBSD] source tree are located in the
1166`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1167can be found in the `sys/<machine-type>` directories. These files define things
1168like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1169port for [FreeBSD] does not yet exist, the machine specific definitions are
1170based on existing machine types with similar properties (for example SPARC64).
1171
1172Where possible, C library function implementations were taken from [FreeBSD]
1173as found in the `lib/libc` directory.
1174
1175A copy of the [FreeBSD] sources can be downloaded with `git`.
1176
1177 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1178
1179
Harry Liebeld265bd72014-01-31 19:04:10 +000011805. Storage abstraction layer
1181-----------------------------
1182
1183In order to improve platform independence and portability an storage abstraction
1184layer is used to load data from non-volatile platform storage.
1185
1186Each platform should register devices and their drivers via the Storage layer.
1187These drivers then need to be initialized by bootloader phases as
1188required in their respective `blx_platform_setup()` functions. Currently
1189storage access is only required by BL1 and BL2 phases. The `load_image()`
1190function uses the storage layer to access non-volatile platform storage.
1191
1192It is mandatory to implement at least one storage driver. For the FVP the
1193Firmware Image Package(FIP) driver is provided as the default means to load data
1194from storage (see the "Firmware Image Package" section in the [User Guide]).
1195The storage layer is described in the header file `include/io_storage.h`. The
1196implementation of the common library is in `lib/io_storage.c` and the driver
1197files are located in `drivers/io/`.
1198
1199Each IO driver must provide `io_dev_*` structures, as described in
1200`drivers/io/io_driver.h`. These are returned via a mandatory registration
1201function that is called on platform initialization. The semi-hosting driver
1202implementation in `io_semihosting.c` can be used as an example.
1203
1204The Storage layer provides mechanisms to initialize storage devices before
1205IO operations are called. The basic operations supported by the layer
1206include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1207Drivers do not have to implement all operations, but each platform must
1208provide at least one driver for a device capable of supporting generic
1209operations such as loading a bootloader image.
1210
1211The current implementation only allows for known images to be loaded by the
1212firmware. These images are specified by using their names, as defined in the
1213`platform.h` file. The platform layer (`plat_get_image_source()`) then returns
1214a reference to a device and a driver-specific `spec` which will be understood
1215by the driver to allow access to the image data.
1216
1217The layer is designed in such a way that is it possible to chain drivers with
1218other drivers. For example, file-system drivers may be implemented on top of
1219physical block devices, both represented by IO devices with corresponding
1220drivers. In such a case, the file-system "binding" with the block device may
1221be deferred until the file-system device is initialised.
1222
1223The abstraction currently depends on structures being statically allocated
1224by the drivers and callers, as the system does not yet provide a means of
1225dynamically allocating memory. This may also have the affect of limiting the
1226amount of open resources per driver.
1227
1228
Achin Gupta4f6ad662013-10-25 09:08:21 +01001229- - - - - - - - - - - - - - - - - - - - - - - - - -
1230
Dan Handleye83b0ca2014-01-14 18:17:09 +00001231_Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001232
1233
1234[User Guide]: user-guide.md
Harry Liebela960f282013-12-12 16:03:44 +00001235[FreeBSD]: http://www.freebsd.org
Achin Gupta4f6ad662013-10-25 09:08:21 +01001236
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001237[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1238[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
1239[plat/fvp/platform.h]: ../plat/fvp/platform.h
Soby Mathewa43d4312014-04-07 15:28:55 +01001240[plat/fvp/include/platform_macros.S]: ../plat/fvp/include/platform_macros.S
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001241[plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c
1242[plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c
1243[include/runtime_svc.h]: ../include/runtime_svc.h