blob: d97019063dd805349c212810a579253a1278b0d8 [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)
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010017 * Interrupt Management framework (in BL3-1)
Harry Liebeld265bd72014-01-31 19:04:10 +0000184. C Library
195. Storage abstraction layer
Achin Gupta4f6ad662013-10-25 09:08:21 +010020
21- - - - - - - - - - - - - - - - - -
22
231. Introduction
24----------------
25
26Porting the ARM Trusted Firmware to a new platform involves making some
27mandatory and optional modifications for both the cold and warm boot paths.
28Modifications consist of:
29
30* Implementing a platform-specific function or variable,
31* Setting up the execution context in a certain way, or
32* Defining certain constants (for example #defines).
33
Dan Handleyb68954c2014-05-29 12:30:24 +010034The platform-specific functions and variables are all declared in
35[include/plat/common/platform.h]. The firmware provides a default implementation
36of variables and functions to fulfill the optional requirements. These
37implementations are all weakly defined; they are provided to ease the porting
38effort. Each platform port can override them with its own implementation if the
39default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010040
41Some modifications are common to all Boot Loader (BL) stages. Section 2
42discusses these in detail. The subsequent sections discuss the remaining
43modifications for each BL stage in detail.
44
45This document should be read in conjunction with the ARM Trusted Firmware
46[User Guide].
47
48
492. Common modifications
50------------------------
51
52This section covers the modifications that should be made by the platform for
53each BL stage to correctly port the firmware stack. They are categorized as
54either mandatory or optional.
55
56
572.1 Common mandatory modifications
58----------------------------------
59A platform port must enable the Memory Management Unit (MMU) with identity
60mapped page tables, and enable both the instruction and data caches for each BL
61stage. In the ARM FVP port, each BL stage configures the MMU in its platform-
62specific architecture setup function, for example `blX_plat_arch_setup()`.
63
64Each platform must allocate a block of identity mapped secure memory with
65Device-nGnRE attributes aligned to page boundary (4K) for each BL stage. This
66memory is identified by the section name `tzfw_coherent_mem` so that its
67possible for the firmware to place variables in it using the following C code
68directive:
69
70 __attribute__ ((section("tzfw_coherent_mem")))
71
72Or alternatively the following assembler code directive:
73
74 .section tzfw_coherent_mem
75
76The `tzfw_coherent_mem` section is used to allocate any data structures that are
77accessed both when a CPU is executing with its MMU and caches enabled, and when
78it's running with its MMU and caches disabled. Examples are given below.
79
80The following variables, functions and constants must be defined by the platform
81for the firmware to work correctly.
82
83
Dan Handleyb68954c2014-05-29 12:30:24 +010084### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +010085
Dan Handleyb68954c2014-05-29 12:30:24 +010086Each platform must ensure that a header file of this name is in the system
87include path with the following constants defined. This may require updating the
88list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM FVP port, this
89file is found in [plat/fvp/include/platform_def.h].
Achin Gupta4f6ad662013-10-25 09:08:21 +010090
James Morrisseyba3155b2013-10-29 10:56:46 +000091* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +010092
93 Defines the linker format used by the platform, for example
94 `elf64-littleaarch64` used by the FVP.
95
James Morrisseyba3155b2013-10-29 10:56:46 +000096* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +010097
98 Defines the processor architecture for the linker by the platform, for
99 example `aarch64` used by the FVP.
100
James Morrisseyba3155b2013-10-29 10:56:46 +0000101* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100102
103 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000104 by [plat/common/aarch64/platform_mp_stack.S] and
105 [plat/common/aarch64/platform_up_stack.S].
106
107* **#define : PCPU_DV_MEM_STACK_SIZE**
108
109 Defines the coherent stack memory available to each CPU. This constant is used
110 by [plat/common/aarch64/platform_mp_stack.S] and
111 [plat/common/aarch64/platform_up_stack.S].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100112
James Morrisseyba3155b2013-10-29 10:56:46 +0000113* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100114
115 Defines the character string printed by BL1 upon entry into the `bl1_main()`
116 function.
117
James Morrisseyba3155b2013-10-29 10:56:46 +0000118* **#define : BL2_IMAGE_NAME**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100119
120 Name of the BL2 binary image on the host file-system. This name is used by
Harry Liebeld265bd72014-01-31 19:04:10 +0000121 BL1 to load BL2 into secure memory from non-volatile storage.
122
123* **#define : BL31_IMAGE_NAME**
124
125 Name of the BL3-1 binary image on the host file-system. This name is used by
126 BL2 to load BL3-1 into secure memory from platform storage.
127
128* **#define : BL33_IMAGE_NAME**
129
130 Name of the BL3-3 binary image on the host file-system. This name is used by
131 BL2 to load BL3-3 into non-secure memory from platform storage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100132
James Morrisseyba3155b2013-10-29 10:56:46 +0000133* **#define : PLATFORM_CACHE_LINE_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134
135 Defines the size (in bytes) of the largest cache line across all the cache
136 levels in the platform.
137
James Morrisseyba3155b2013-10-29 10:56:46 +0000138* **#define : PLATFORM_CLUSTER_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139
140 Defines the total number of clusters implemented by the platform in the
141 system.
142
James Morrisseyba3155b2013-10-29 10:56:46 +0000143* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100144
145 Defines the total number of CPUs implemented by the platform across all
146 clusters in the system.
147
James Morrisseyba3155b2013-10-29 10:56:46 +0000148* **#define : PLATFORM_MAX_CPUS_PER_CLUSTER**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100149
150 Defines the maximum number of CPUs that can be implemented within a cluster
151 on the platform.
152
James Morrisseyba3155b2013-10-29 10:56:46 +0000153* **#define : PRIMARY_CPU**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100154
155 Defines the `MPIDR` of the primary CPU on the platform. This value is used
156 after a cold boot to distinguish between primary and secondary CPUs.
157
James Morrisseyba3155b2013-10-29 10:56:46 +0000158* **#define : TZROM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100159
160 Defines the base address of secure ROM on the platform, where the BL1 binary
161 is loaded. This constant is used by the linker scripts to ensure that the
162 BL1 image fits into the available memory.
163
James Morrisseyba3155b2013-10-29 10:56:46 +0000164* **#define : TZROM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100165
166 Defines the size of secure ROM on the platform. This constant is used by the
167 linker scripts to ensure that the BL1 image fits into the available memory.
168
James Morrisseyba3155b2013-10-29 10:56:46 +0000169* **#define : TZRAM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100170
171 Defines the base address of the secure RAM on platform, where the data
172 section of the BL1 binary is loaded. The BL2 and BL3-1 images are also
173 loaded in this secure RAM region. This constant is used by the linker
174 scripts to ensure that the BL1 data section and BL2/BL3-1 binary images fit
175 into the available memory.
176
James Morrisseyba3155b2013-10-29 10:56:46 +0000177* **#define : TZRAM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100178
179 Defines the size of the secure RAM on the platform. This constant is used by
180 the linker scripts to ensure that the BL1 data section and BL2/BL3-1 binary
181 images fit into the available memory.
182
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100183* **#define : BL1_RO_BASE**
184
185 Defines the base address in secure ROM where BL1 originally lives. Must be
186 aligned on a page-size boundary.
187
188* **#define : BL1_RO_LIMIT**
189
190 Defines the maximum address in secure ROM that BL1's actual content (i.e.
191 excluding any data section allocated at runtime) can occupy.
192
193* **#define : BL1_RW_BASE**
194
195 Defines the base address in secure RAM where BL1's read-write data will live
196 at runtime. Must be aligned on a page-size boundary.
197
198* **#define : BL1_RW_LIMIT**
199
200 Defines the maximum address in secure RAM that BL1's read-write data can
201 occupy at runtime.
202
James Morrisseyba3155b2013-10-29 10:56:46 +0000203* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100204
205 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000206 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100207
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100208* **#define : BL2_LIMIT**
209
210 Defines the maximum address in secure RAM that the BL2 image can occupy.
211
James Morrisseyba3155b2013-10-29 10:56:46 +0000212* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100213
214 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000215 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100216
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100217* **#define : BL31_LIMIT**
218
219 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
220
Harry Liebeld265bd72014-01-31 19:04:10 +0000221* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100222
Harry Liebeld265bd72014-01-31 19:04:10 +0000223 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
224 image. Must be aligned on a page-size boundary.
225
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100226If the BL3-2 image is supported by the platform, the following constants must
227be defined as well:
228
229* **#define : TSP_SEC_MEM_BASE**
230
231 Defines the base address of the secure memory used by the BL3-2 image on the
232 platform.
233
234* **#define : TSP_SEC_MEM_SIZE**
235
236 Defines the size of the secure memory used by the BL3-2 image on the
237 platform.
238
239* **#define : BL32_BASE**
240
241 Defines the base address in secure memory where BL2 loads the BL3-2 binary
242 image. Must be inside the secure memory identified by `TSP_SEC_MEM_BASE` and
243 `TSP_SEC_MEM_SIZE` constants. Must also be aligned on a page-size boundary.
244
245* **#define : BL32_LIMIT**
246
247 Defines the maximum address that the BL3-2 image can occupy. Must be inside
248 the secure memory identified by `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE`
249 constants.
250
251
Dan Handleyb68954c2014-05-29 12:30:24 +0100252### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100253
Dan Handleyb68954c2014-05-29 12:30:24 +0100254Each platform must ensure a file of this name is in the system include path with
255the following macro defined. In the ARM FVP port, this file is found in
256[plat/fvp/include/plat_macros.S].
Soby Mathewa43d4312014-04-07 15:28:55 +0100257
258* **Macro : plat_print_gic_regs**
259
260 This macro allows the crash reporting routine to print GIC registers
261 in case of an unhandled IRQ or FIQ in BL3-1. This aids in debugging and
262 this macro can be defined to be empty in case GIC register reporting is
263 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100264
265### Other mandatory modifications
266
James Morrisseyba3155b2013-10-29 10:56:46 +0000267The following mandatory modifications may be implemented in any file
Achin Gupta4f6ad662013-10-25 09:08:21 +0100268the implementer chooses. In the ARM FVP port, they are implemented in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000269[plat/fvp/aarch64/plat_common.c].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100270
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100271* **Function : uint64_t plat_get_syscnt_freq(void)**
272
273 This function is used by the architecture setup code to retrieve the
274 counter frequency for the CPU's generic timer. This value will be
275 programmed into the `CNTFRQ_EL0` register.
276 In the ARM FVP port, it returns the base frequency of the system counter,
277 which is retrieved from the first entry in the frequency modes table.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100278
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000279
Vikram Kanigirie452cd82014-05-23 15:56:12 +01002802.2 Handling Reset
281------------------
282
283BL1 by default implements the reset vector where execution starts from a cold
284or warm boot. BL3-1 can be optionally set as a reset vector using the
285RESET_TO_BL31 make variable.
286
287For each CPU, the reset vector code is responsible for the following tasks:
288
2891. Distinguishing between a cold boot and a warm boot.
290
2912. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
292 the CPU is placed in a platform-specific state until the primary CPU
293 performs the necessary steps to remove it from this state.
294
2953. In the case of a warm boot, ensuring that the CPU jumps to a platform-
296 specific address in the BL3-1 image in the same processor mode as it was
297 when released from reset.
298
299The following functions need to be implemented by the platform port to enable
300reset vector code to perform the above tasks.
301
302
303### Function : platform_get_entrypoint() [mandatory]
304
305 Argument : unsigned long
306 Return : unsigned int
307
308This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
309is identified by its `MPIDR`, which is passed as the argument. The function is
310responsible for distinguishing between a warm and cold reset using platform-
311specific means. If it's a warm reset then it returns the entrypoint into the
312BL3-1 image that the CPU must jump to. If it's a cold reset then this function
313must return zero.
314
315This function is also responsible for implementing a platform-specific mechanism
316to handle the condition where the CPU has been warm reset but there is no
317entrypoint to jump to.
318
319This function does not follow the Procedure Call Standard used by the
320Application Binary Interface for the ARM 64-bit architecture. The caller should
321not assume that callee saved registers are preserved across a call to this
322function.
323
324This function fulfills requirement 1 and 3 listed above.
325
326
327### Function : plat_secondary_cold_boot_setup() [mandatory]
328
329 Argument : void
330 Return : void
331
332This function is called with the MMU and data caches disabled. It is responsible
333for placing the executing secondary CPU in a platform-specific state until the
334primary CPU performs the necessary actions to bring it out of that state and
335allow entry into the OS.
336
337In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
338responsible for powering up the secondary CPU when normal world software
339requires them.
340
341This function fulfills requirement 2 above.
342
343
344### Function : platform_mem_init() [mandatory]
345
346 Argument : void
347 Return : void
348
349This function is called before any access to data is made by the firmware, in
350order to carry out any essential memory initialization.
351
352The ARM FVP port uses this function to initialize the mailbox memory used for
353providing the warm-boot entry-point addresses.
354
355
356
3572.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100358---------------------------------
359
360The following are helper functions implemented by the firmware that perform
361common platform-specific tasks. A platform may choose to override these
362definitions.
363
364
365### Function : platform_get_core_pos()
366
367 Argument : unsigned long
368 Return : int
369
370A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
371can be used as a CPU-specific linear index into blocks of memory (for example
372while allocating per-CPU stacks). This routine contains a simple mechanism
373to perform this conversion, using the assumption that each cluster contains a
374maximum of 4 CPUs:
375
376 linear index = cpu_id + (cluster_id * 4)
377
378 cpu_id = 8-bit value in MPIDR at affinity level 0
379 cluster_id = 8-bit value in MPIDR at affinity level 1
380
381
382### Function : platform_set_coherent_stack()
383
384 Argument : unsigned long
385 Return : void
386
387A platform may need stack memory that is coherent with main memory to perform
388certain operations like:
389
390* Turning the MMU on, or
391* Flushing caches prior to powering down a CPU or cluster.
392
393Each BL stage allocates this coherent stack memory for each CPU in the
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000394`tzfw_coherent_mem` section.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100395
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000396This function sets the current stack pointer to the coherent stack that
397has been allocated for the CPU specified by MPIDR. For BL images that only
398require a stack for the primary CPU the parameter is ignored. The size of
399the stack allocated to each CPU is specified by the platform defined constant
Achin Gupta4f6ad662013-10-25 09:08:21 +0100400`PCPU_DV_MEM_STACK_SIZE`.
401
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000402Common implementations of this function for the UP and MP BL images are
403provided in [plat/common/aarch64/platform_up_stack.S] and
404[plat/common/aarch64/platform_mp_stack.S]
405
Achin Gupta4f6ad662013-10-25 09:08:21 +0100406
407### Function : platform_is_primary_cpu()
408
409 Argument : unsigned long
410 Return : unsigned int
411
412This function identifies a CPU by its `MPIDR`, which is passed as the argument,
413to determine whether this CPU is the primary CPU or a secondary CPU. A return
414value of zero indicates that the CPU is not the primary CPU, while a non-zero
415return value indicates that the CPU is the primary CPU.
416
417
418### Function : platform_set_stack()
419
420 Argument : unsigned long
421 Return : void
422
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000423This function sets the current stack pointer to the normal memory stack that
424has been allocated for the CPU specificed by MPIDR. For BL images that only
425require a stack for the primary CPU the parameter is ignored. The size of
426the stack allocated to each CPU is specified by the platform defined constant
427`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100428
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000429Common implementations of this function for the UP and MP BL images are
430provided in [plat/common/aarch64/platform_up_stack.S] and
431[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100432
433
Achin Guptac8afc782013-11-25 18:45:02 +0000434### Function : platform_get_stack()
435
436 Argument : unsigned long
437 Return : unsigned long
438
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000439This function returns the base address of the normal memory stack that
440has been allocated for the CPU specificed by MPIDR. For BL images that only
441require a stack for the primary CPU the parameter is ignored. The size of
442the stack allocated to each CPU is specified by the platform defined constant
443`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000444
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000445Common implementations of this function for the UP and MP BL images are
446provided in [plat/common/aarch64/platform_up_stack.S] and
447[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000448
449
Achin Gupta4f6ad662013-10-25 09:08:21 +0100450### Function : plat_report_exception()
451
452 Argument : unsigned int
453 Return : void
454
455A platform may need to report various information about its status when an
456exception is taken, for example the current exception level, the CPU security
457state (secure/non-secure), the exception type, and so on. This function is
458called in the following circumstances:
459
460* In BL1, whenever an exception is taken.
461* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100462
463The default implementation doesn't do anything, to avoid making assumptions
464about the way the platform displays its status information.
465
466This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000467exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100468that these constants are not related to any architectural exception code; they
469are just an ARM Trusted Firmware convention.
470
471
4723. Modifications specific to a Boot Loader stage
473-------------------------------------------------
474
4753.1 Boot Loader Stage 1 (BL1)
476-----------------------------
477
478BL1 implements the reset vector where execution starts from after a cold or
479warm boot. For each CPU, BL1 is responsible for the following tasks:
480
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004811. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100482
4832. In the case of a cold boot and the CPU being the primary CPU, ensuring that
484 only this CPU executes the remaining BL1 code, including loading and passing
485 control to the BL2 stage.
486
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004873. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100488 address specified by the platform defined constant `BL2_BASE`.
489
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004904. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100491 accessible by BL2 immediately upon entry.
492
493 meminfo.total_base = Base address of secure RAM visible to BL2
494 meminfo.total_size = Size of secure RAM visible to BL2
495 meminfo.free_base = Base address of secure RAM available for
496 allocation to BL2
497 meminfo.free_size = Size of secure RAM available for allocation to BL2
498
499 BL1 places this `meminfo` structure at the beginning of the free memory
500 available for its use. Since BL1 cannot allocate memory dynamically at the
501 moment, its free memory will be available for BL2's use as-is. However, this
502 means that BL2 must read the `meminfo` structure before it starts using its
503 free memory (this is discussed in Section 3.2).
504
505 In future releases of the ARM Trusted Firmware it will be possible for
506 the platform to decide where it wants to place the `meminfo` structure for
507 BL2.
508
509 BL1 implements the `init_bl2_mem_layout()` function to populate the
510 BL2 `meminfo` structure. The platform may override this implementation, for
511 example if the platform wants to restrict the amount of memory visible to
512 BL2. Details of how to do this are given below.
513
514The following functions need to be implemented by the platform port to enable
515BL1 to perform the above tasks.
516
517
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100518### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100519
520 Argument : void
521 Return : void
522
Achin Gupta4f6ad662013-10-25 09:08:21 +0100523This function performs any platform-specific and architectural setup that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100524platform requires. Platform-specific setup might include configuration of
525memory controllers, configuration of the interconnect to allow the cluster
526to service cache snoop requests from another cluster, and so on.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100527
528In the ARM FVP port, this function enables CCI snoops into the cluster that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100529primary CPU is part of. It also enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100530
531This function helps fulfill requirement 2 above.
532
533
534### Function : bl1_platform_setup() [mandatory]
535
536 Argument : void
537 Return : void
538
539This function executes with the MMU and data caches enabled. It is responsible
540for performing any remaining platform-specific setup that can occur after the
541MMU and data cache have been enabled.
542
Harry Liebeld265bd72014-01-31 19:04:10 +0000543This function is also responsible for initializing the storage abstraction layer
544which is used to load further bootloader images.
545
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100546This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100547
548
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000549### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100550
551 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000552 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100553
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000554This function should only be called on the cold boot path. It executes with the
555MMU and data caches enabled. The pointer returned by this function must point to
556a `meminfo` structure containing the extents and availability of secure RAM for
557the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100558
559 meminfo.total_base = Base address of secure RAM visible to BL1
560 meminfo.total_size = Size of secure RAM visible to BL1
561 meminfo.free_base = Base address of secure RAM available for allocation
562 to BL1
563 meminfo.free_size = Size of secure RAM available for allocation to BL1
564
565This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
566populates a similar structure to tell BL2 the extents of memory available for
567its own use.
568
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100569This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100570
571
572### Function : init_bl2_mem_layout() [optional]
573
574 Argument : meminfo *, meminfo *, unsigned int, unsigned long
575 Return : void
576
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100577BL1 needs to tell the next stage the amount of secure RAM available
578for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100579structure.
580
581Depending upon where BL2 has been loaded in secure RAM (determined by
582`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
583BL1 also ensures that its data sections resident in secure RAM are not visible
584to BL2. An illustration of how this is done in the ARM FVP port is given in the
585[User Guide], in the Section "Memory layout on Base FVP".
586
587
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100588### Function : bl1_plat_set_bl2_ep_info() [mandatory]
589
590 Argument : image_info *, entry_point_info *
591 Return : void
592
593This function is called after loading BL2 image and it can be used to overwrite
594the entry point set by loader and also set the security state and SPSR which
595represents the entry point system state for BL2.
596
597On FVP, we are setting the security state and the SPSR for the BL2 entrypoint
598
599
Achin Gupta4f6ad662013-10-25 09:08:21 +01006003.2 Boot Loader Stage 2 (BL2)
601-----------------------------
602
603The BL2 stage is executed only by the primary CPU, which is determined in BL1
604using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
605`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
606
Harry Liebeld265bd72014-01-31 19:04:10 +00006071. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
608 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
609 by BL1. This structure allows BL2 to calculate how much secure RAM is
610 available for its use. The platform also defines the address in secure RAM
611 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
612 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100613
Harry Liebeld265bd72014-01-31 19:04:10 +00006142. Loading the normal world BL3-3 binary image into non-secure DRAM from
615 platform storage and arranging for BL3-1 to pass control to this image. This
616 address is determined using the `plat_get_ns_image_entrypoint()` function
617 described below.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100618
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006193. BL2 populates an `entry_point_info` structure in memory provided by the
620 platform with information about how BL3-1 should pass control to the
621 other BL images.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100622
Dan Handley1151c822014-04-15 11:38:38 +01006234. (Optional) Loading the BL3-2 binary image (if present) from platform
624 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100625 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
626 The platform also defines the address in memory where BL3-2 is loaded
627 through the optional constant `BL32_BASE`. BL2 uses this information
628 to determine if there is enough memory to load the BL3-2 image.
629 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000630
Dan Handley1151c822014-04-15 11:38:38 +01006315. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100632 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100633 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100634 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000635
Achin Gupta4f6ad662013-10-25 09:08:21 +0100636The following functions must be implemented by the platform port to enable BL2
637to perform the above tasks.
638
639
640### Function : bl2_early_platform_setup() [mandatory]
641
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100642 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100643 Return : void
644
645This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100646by the primary CPU. The arguments to this function is the address of the
647`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100648
649The platform must copy the contents of the `meminfo` structure into a private
650variable as the original memory may be subsequently overwritten by BL2. The
651copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000652`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100653
654
655### Function : bl2_plat_arch_setup() [mandatory]
656
657 Argument : void
658 Return : void
659
660This function executes with the MMU and data caches disabled. It is only called
661by the primary CPU.
662
663The purpose of this function is to perform any architectural initialization
664that varies across platforms, for example enabling the MMU (since the memory
665map differs across platforms).
666
667
668### Function : bl2_platform_setup() [mandatory]
669
670 Argument : void
671 Return : void
672
673This function may execute with the MMU and data caches enabled if the platform
674port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
675called by the primary CPU.
676
Achin Guptae4d084e2014-02-19 17:18:23 +0000677The purpose of this function is to perform any platform initialization
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100678specific to BL2. Platform security components are configured if required.
679For the Base FVP the TZC-400 TrustZone controller is configured to only
680grant non-secure access to DRAM. This avoids aliasing between secure and
681non-secure accesses in the TLB and cache - secure execution states can use
682the NS attributes in the MMU translation tables to access the DRAM.
Harry Liebelce19cf12014-04-01 19:28:07 +0100683
Harry Liebeld265bd72014-01-31 19:04:10 +0000684This function is also responsible for initializing the storage abstraction layer
685which is used to load further bootloader images.
686
Achin Gupta4f6ad662013-10-25 09:08:21 +0100687
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000688### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100689
690 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000691 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100692
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000693This function should only be called on the cold boot path. It may execute with
694the MMU and data caches enabled if the platform port does the necessary
695initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100696
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000697The purpose of this function is to return a pointer to a `meminfo` structure
698populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100699`bl2_early_platform_setup()` above.
700
701
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100702### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000703
704 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100705 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000706
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100707BL2 platform code needs to return a pointer to a `bl31_params` structure it
708will use for passing information to BL3-1. The `bl31_params` structure carries
709the following information.
710 - Header describing the version information for interpreting the bl31_param
711 structure
712 - Information about executing the BL3-3 image in the `bl33_ep_info` field
713 - Information about executing the BL3-2 image in the `bl32_ep_info` field
714 - Information about the type and extents of BL3-1 image in the
715 `bl31_image_info` field
716 - Information about the type and extents of BL3-2 image in the
717 `bl32_image_info` field
718 - Information about the type and extents of BL3-3 image in the
719 `bl33_image_info` field
720
721The memory pointed by this structure and its sub-structures should be
722accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
723necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000724
725
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100726### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100727
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100728 Argument : void
729 Return : entry_point_info *
730
731BL2 platform code returns a pointer which is used to populate the entry point
732information for BL3-1 entry point. The location pointed by it should be
733accessible from BL1 while processing the synchronous exception to run to BL3-1.
734
735On FVP this is allocated inside an bl2_to_bl31_params_mem structure which
736is allocated at an address pointed by PARAMS_BASE.
737
738
739### Function : bl2_plat_set_bl31_ep_info() [mandatory]
740
741 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100742 Return : void
743
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100744This function is called after loading BL3-1 image and it can be used to
745overwrite the entry point set by loader and also set the security state
746and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100747
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100748On FVP, we are setting the security state and the SPSR for the BL3-1
749entrypoint.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100750
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100751### Function : bl2_plat_set_bl32_ep_info() [mandatory]
752
753 Argument : image_info *, entry_point_info *
754 Return : void
755
756This function is called after loading BL3-2 image and it can be used to
757overwrite the entry point set by loader and also set the security state
758and SPSR which represents the entry point system state for BL3-2.
759
760On FVP, we are setting the security state and the SPSR for the BL3-2
761entrypoint
762
763### Function : bl2_plat_set_bl33_ep_info() [mandatory]
764
765 Argument : image_info *, entry_point_info *
766 Return : void
767
768This function is called after loading BL3-3 image and it can be used to
769overwrite the entry point set by loader and also set the security state
770and SPSR which represents the entry point system state for BL3-3.
771
772On FVP, we are setting the security state and the SPSR for the BL3-3
773entrypoint
774
775### Function : bl2_plat_get_bl32_meminfo() [mandatory]
776
777 Argument : meminfo *
778 Return : void
779
780This function is used to get the memory limits where BL2 can load the
781BL3-2 image. The meminfo provided by this is used by load_image() to
782validate whether the BL3-2 image can be loaded with in the given
783memory from the given base.
784
785### Function : bl2_plat_get_bl33_meminfo() [mandatory]
786
787 Argument : meminfo *
788 Return : void
789
790This function is used to get the memory limits where BL2 can load the
791BL3-3 image. The meminfo provided by this is used by load_image() to
792validate whether the BL3-3 image can be loaded with in the given
793memory from the given base.
794
795### Function : bl2_plat_flush_bl31_params() [mandatory]
796
797 Argument : void
798 Return : void
799
800Once BL2 has populated all the structures that needs to be read by BL1
801and BL3-1 including the bl31_params structures and its sub-structures,
802the bl31_ep_info structure and any platform specific data. It flushes
803all these data to the main memory so that it is available when we jump to
804later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100805
806### Function : plat_get_ns_image_entrypoint() [mandatory]
807
808 Argument : void
809 Return : unsigned long
810
811As previously described, BL2 is responsible for arranging for control to be
812passed to a normal world BL image through BL3-1. This function returns the
813entrypoint of that image, which BL3-1 uses to jump to it.
814
Harry Liebeld265bd72014-01-31 19:04:10 +0000815BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100816
817
8183.2 Boot Loader Stage 3-1 (BL3-1)
819---------------------------------
820
821During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
822determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
823control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
824CPUs. BL3-1 executes at EL3 and is responsible for:
825
8261. Re-initializing all architectural and platform state. Although BL1 performs
827 some of this initialization, BL3-1 remains resident in EL3 and must ensure
828 that EL3 architectural and platform state is completely initialized. It
829 should make no assumptions about the system state when it receives control.
830
8312. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100832 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100833 populated in memory to do this.
834
8353. Providing runtime firmware services. Currently, BL3-1 only implements a
836 subset of the Power State Coordination Interface (PSCI) API as a runtime
837 service. See Section 3.3 below for details of porting the PSCI
838 implementation.
839
Achin Gupta35ca3512014-02-19 17:58:33 +00008404. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
841 specific address by BL2. BL3-1 exports a set of apis that allow runtime
842 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100843 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
844 structure populated by BL2 to do this.
845
846If BL3-1 is a reset vector, It also needs to handle the reset as specified in
847section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +0000848
Achin Gupta4f6ad662013-10-25 09:08:21 +0100849The following functions must be implemented by the platform port to enable BL3-1
850to perform the above tasks.
851
852
853### Function : bl31_early_platform_setup() [mandatory]
854
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100855 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100856 Return : void
857
858This function executes with the MMU and data caches disabled. It is only called
859by the primary CPU. The arguments to this function are:
860
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100861* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100862* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100863
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100864The platform can copy the contents of the `bl31_params` structure and its
865sub-structures into private variables if the original memory may be
866subsequently overwritten by BL3-1 and similarly the `void *` pointing
867to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100868
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100869On the ARM FVP port, BL2 passes a pointer to a `bl31_params` structure populated
870in the secure DRAM at address `0x6000000` in the bl31_params * argument and it
871does not use opaque pointer mentioned earlier. BL3-1 does not copy this
872information to internal data structures as it guarantees that the secure
873DRAM memory will not be overwritten. It maintains an internal reference to this
874information in the `bl2_to_bl31_params` variable.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100875
876### Function : bl31_plat_arch_setup() [mandatory]
877
878 Argument : void
879 Return : void
880
881This function executes with the MMU and data caches disabled. It is only called
882by the primary CPU.
883
884The purpose of this function is to perform any architectural initialization
885that varies across platforms, for example enabling the MMU (since the memory
886map differs across platforms).
887
888
889### Function : bl31_platform_setup() [mandatory]
890
891 Argument : void
892 Return : void
893
894This function may execute with the MMU and data caches enabled if the platform
895port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
896called by the primary CPU.
897
898The purpose of this function is to complete platform initialization so that both
899BL3-1 runtime services and normal world software can function correctly.
900
901The ARM FVP port does the following:
902* Initializes the generic interrupt controller.
903* Configures the CLCD controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100904* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100905* Grants access to the system counter timer module
906* Initializes the FVP power controller device
907* Detects the system topology.
908
909
910### Function : bl31_get_next_image_info() [mandatory]
911
Achin Gupta35ca3512014-02-19 17:58:33 +0000912 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100913 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100914
915This function may execute with the MMU and data caches enabled if the platform
916port does the necessary initializations in `bl31_plat_arch_setup()`.
917
918This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +0000919BL2 for the next image in the security state specified by the argument. BL3-1
920uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100921state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +0000922(that was copied during `bl31_early_platform_setup()`) if the image exists. It
923should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100924
925
Achin Gupta4f6ad662013-10-25 09:08:21 +01009263.3 Power State Coordination Interface (in BL3-1)
927------------------------------------------------
928
929The ARM Trusted Firmware's implementation of the PSCI API is based around the
930concept of an _affinity instance_. Each _affinity instance_ can be uniquely
931identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
932interface) and an _affinity level_. A processing element (for example, a
933CPU) is at level 0. If the CPUs in the system are described in a tree where the
934node above a CPU is a logical grouping of CPUs that share some state, then
935affinity level 1 is that group of CPUs (for example, a cluster), and affinity
936level 2 is a group of clusters (for example, the system). The implementation
937assumes that the affinity level 1 ID can be computed from the affinity level 0
938ID (for example, a unique cluster ID can be computed from the CPU ID). The
939current implementation computes this on the basis of the recommended use of
940`MPIDR` affinity fields in the ARM Architecture Reference Manual.
941
942BL3-1's platform initialization code exports a pointer to the platform-specific
943power management operations required for the PSCI implementation to function
944correctly. This information is populated in the `plat_pm_ops` structure. The
945PSCI implementation calls members of the `plat_pm_ops` structure for performing
946power management operations for each affinity instance. For example, the target
947CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
948handler (if present) is called for each affinity instance as the PSCI
949implementation powers up each affinity level implemented in the `MPIDR` (for
950example, CPU, cluster and system).
951
952The following functions must be implemented to initialize PSCI functionality in
953the ARM Trusted Firmware.
954
955
956### Function : plat_get_aff_count() [mandatory]
957
958 Argument : unsigned int, unsigned long
959 Return : unsigned int
960
961This function may execute with the MMU and data caches enabled if the platform
962port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
963called by the primary CPU.
964
965This function is called by the PSCI initialization code to detect the system
966topology. Its purpose is to return the number of affinity instances implemented
967at a given `affinity level` (specified by the first argument) and a given
968`MPIDR` (specified by the second argument). For example, on a dual-cluster
969system where first cluster implements 2 CPUs and the second cluster implements 4
970CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
971(`0x0`) and affinity level 0, would return 2. A call to this function with an
972`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
973would return 4.
974
975
976### Function : plat_get_aff_state() [mandatory]
977
978 Argument : unsigned int, unsigned long
979 Return : unsigned int
980
981This function may execute with the MMU and data caches enabled if the platform
982port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
983called by the primary CPU.
984
985This function is called by the PSCI initialization code. Its purpose is to
986return the state of an affinity instance. The affinity instance is determined by
987the affinity ID at a given `affinity level` (specified by the first argument)
988and an `MPIDR` (specified by the second argument). The state can be one of
989`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
990system topologies where certain affinity instances are unimplemented. For
991example, consider a platform that implements a single cluster with 4 CPUs and
992another CPU implemented directly on the interconnect with the cluster. The
993`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
994CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
995is missing but needs to be accounted for to reach this single CPU in the
996topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
997
998
999### Function : plat_get_max_afflvl() [mandatory]
1000
1001 Argument : void
1002 Return : int
1003
1004This function may execute with the MMU and data caches enabled if the platform
1005port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1006called by the primary CPU.
1007
1008This function is called by the PSCI implementation both during cold and warm
1009boot, to determine the maximum affinity level that the power management
James Morrisseyba3155b2013-10-29 10:56:46 +00001010operations should apply to. ARMv8-A has support for 4 affinity levels. It is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001011likely that hardware will implement fewer affinity levels. This function allows
1012the PSCI implementation to consider only those affinity levels in the system
1013that the platform implements. For example, the Base AEM FVP implements two
1014clusters with a configurable number of CPUs. It reports the maximum affinity
1015level as 1, resulting in PSCI power control up to the cluster level.
1016
1017
1018### Function : platform_setup_pm() [mandatory]
1019
1020 Argument : plat_pm_ops **
1021 Return : int
1022
1023This function may execute with the MMU and data caches enabled if the platform
1024port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1025called by the primary CPU.
1026
1027This function is called by PSCI initialization code. Its purpose is to export
1028handler routines for platform-specific power management actions by populating
1029the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1030
1031A description of each member of this structure is given below. Please refer to
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001032the ARM FVP specific implementation of these handlers in [plat/fvp/plat_pm.c]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001033as an example. A platform port may choose not implement some of the power
1034management operations. For example, the ARM FVP port does not implement the
1035`affinst_standby()` function.
1036
1037#### plat_pm_ops.affinst_standby()
1038
1039Perform the platform-specific setup to enter the standby state indicated by the
1040passed argument.
1041
1042#### plat_pm_ops.affinst_on()
1043
1044Perform the platform specific setup to power on an affinity instance, specified
1045by the `MPIDR` (first argument) and `affinity level` (fourth argument). The
1046`state` (fifth argument) contains the current state of that affinity instance
1047(ON or OFF). This is useful to determine whether any action must be taken. For
1048example, while powering on a CPU, the cluster that contains this CPU might
1049already be in the ON state. The platform decides what actions must be taken to
1050transition from the current state to the target state (indicated by the power
1051management operation).
1052
1053#### plat_pm_ops.affinst_off()
1054
1055Perform the platform specific setup to power off an affinity instance in the
1056`MPIDR` of the calling CPU. It is called by the PSCI `CPU_OFF` API
1057implementation.
1058
1059The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1060(third argument) have a similar meaning as described in the `affinst_on()`
1061operation. They are used to identify the affinity instance on which the call
1062is made and its current state. This gives the platform port an indication of the
1063state transition it must make to perform the requested action. For example, if
1064the calling CPU is the last powered on CPU in the cluster, after powering down
1065affinity level 0 (CPU), the platform port should power down affinity level 1
1066(the cluster) as well.
1067
1068This function is called with coherent stacks. This allows the PSCI
1069implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001070stale stack state after turning off the caches. On ARMv8-A cache hits do not
1071occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001072
1073#### plat_pm_ops.affinst_suspend()
1074
1075Perform the platform specific setup to power off an affinity instance in the
1076`MPIDR` of the calling CPU. It is called by the PSCI `CPU_SUSPEND` API
1077implementation.
1078
1079The `MPIDR` (first argument), `affinity level` (third argument) and `state`
1080(fifth argument) have a similar meaning as described in the `affinst_on()`
1081operation. They are used to identify the affinity instance on which the call
1082is made and its current state. This gives the platform port an indication of the
1083state transition it must make to perform the requested action. For example, if
1084the calling CPU is the last powered on CPU in the cluster, after powering down
1085affinity level 0 (CPU), the platform port should power down affinity level 1
1086(the cluster) as well.
1087
1088The difference between turning an affinity instance off versus suspending it
1089is that in the former case, the affinity instance is expected to re-initialize
1090its state when its next powered on (see `affinst_on_finish()`). In the latter
1091case, the affinity instance is expected to save enough state so that it can
1092resume execution by restoring this state when its powered on (see
1093`affinst_suspend_finish()`).
1094
1095This function is called with coherent stacks. This allows the PSCI
1096implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001097stale stack state after turning off the caches. On ARMv8-A cache hits do not
1098occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001099
1100#### plat_pm_ops.affinst_on_finish()
1101
1102This function is called by the PSCI implementation after the calling CPU is
1103powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1104It performs the platform-specific setup required to initialize enough state for
1105this CPU to enter the normal world and also provide secure runtime firmware
1106services.
1107
1108The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1109(third argument) have a similar meaning as described in the previous operations.
1110
1111This function is called with coherent stacks. This allows the PSCI
1112implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001113stale stack state after turning off the caches. On ARMv8-A cache hits do not
1114occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001115
1116#### plat_pm_ops.affinst_on_suspend()
1117
1118This function is called by the PSCI implementation after the calling CPU is
1119powered on and released from reset in response to an asynchronous wakeup
1120event, for example a timer interrupt that was programmed by the CPU during the
1121`CPU_SUSPEND` call. It performs the platform-specific setup required to
1122restore the saved state for this CPU to resume execution in the normal world
1123and also provide secure runtime firmware services.
1124
1125The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1126(third argument) have a similar meaning as described in the previous operations.
1127
1128This function is called with coherent stacks. This allows the PSCI
1129implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001130stale stack state after turning off the caches. On ARMv8-A cache hits do not
1131occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001132
1133BL3-1 platform initialization code must also detect the system topology and
1134the state of each affinity instance in the topology. This information is
1135critical for the PSCI runtime service to function correctly. More details are
1136provided in the description of the `plat_get_aff_count()` and
1137`plat_get_aff_state()` functions above.
1138
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010011393.4 Interrupt Management framework (in BL3-1)
1140----------------------------------------------
1141BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1142generated in either security state and targeted to EL1 or EL2 in the non-secure
1143state or EL3/S-EL1 in the secure state. The design of this framework is
1144described in the [IMF Design Guide]
1145
1146A platform should export the following APIs to support the IMF. The following
1147text briefly describes each api and its implementation on the FVP port. The API
1148implementation depends upon the type of interrupt controller present in the
1149platform. The FVP implements an ARM Generic Interrupt Controller (ARM GIC) as
1150per the version 2.0 of the [ARM GIC Architecture Specification]
1151
1152### Function : plat_interrupt_type_to_line() [mandatory]
1153
1154 Argument : uint32_t, uint32_t
1155 Return : uint32_t
1156
1157The ARM processor signals an interrupt exception either through the IRQ or FIQ
1158interrupt line. The specific line that is signaled depends on how the interrupt
1159controller (IC) reports different interrupt types from an execution context in
1160either security state. The IMF uses this API to determine which interrupt line
1161the platform IC uses to signal each type of interrupt supported by the framework
1162from a given security state.
1163
1164The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1165Guide]) indicating the target type of the interrupt, the second parameter is the
1166security state of the originating execution context. The return result is the
1167bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1168FIQ=2.
1169
1170The FVP port configures the ARM GIC to signal S-EL1 interrupts as FIQs and
1171Non-secure interrupts as IRQs from either security state.
1172
1173
1174### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1175
1176 Argument : void
1177 Return : uint32_t
1178
1179This API returns the type of the highest priority pending interrupt at the
1180platform IC. The IMF uses the interrupt type to retrieve the corresponding
1181handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1182pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1183`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1184
1185The FVP port reads the _Highest Priority Pending Interrupt Register_
1186(`GICC_HPPIR`) to determine the id of the pending interrupt. The type of interrupt
1187depends upon the id value as follows.
1188
11891. id < 1022 is reported as a S-EL1 interrupt
11902. id = 1022 is reported as a Non-secure interrupt.
11913. id = 1023 is reported as an invalid interrupt type.
1192
1193
1194### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1195
1196 Argument : void
1197 Return : uint32_t
1198
1199This API returns the id of the highest priority pending interrupt at the
1200platform IC. The IMF passes the id returned by this API to the registered
1201handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1202is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1203
1204The FVP port reads the _Highest Priority Pending Interrupt Register_
1205(`GICC_HPPIR`) to determine the id of the pending interrupt. The id that is
1206returned by API depends upon the value of the id read from the interrupt
1207controller as follows.
1208
12091. id < 1022. id is returned as is.
12102. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1211 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1212 id is returned by the API.
12133. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1214
1215
1216### Function : plat_ic_acknowledge_interrupt() [mandatory]
1217
1218 Argument : void
1219 Return : uint32_t
1220
1221This API is used by the CPU to indicate to the platform IC that processing of
1222the highest pending interrupt has begun. It should return the id of the
1223interrupt which is being processed.
1224
1225The FVP port reads the _Interrupt Acknowledge Register_ (`GICC_IAR`). This
1226changes the state of the highest priority pending interrupt from pending to
1227active in the interrupt controller. It returns the value read from the
1228`GICC_IAR`. This value is the id of the interrupt whose state has been changed.
1229
1230The TSP uses this API to start processing of the secure physical timer
1231interrupt.
1232
1233
1234### Function : plat_ic_end_of_interrupt() [mandatory]
1235
1236 Argument : uint32_t
1237 Return : void
1238
1239This API is used by the CPU to indicate to the platform IC that processing of
1240the interrupt corresponding to the id (passed as the parameter) has
1241finished. The id should be the same as the id returned by the
1242`plat_ic_acknowledge_interrupt()` API.
1243
1244The FVP port writes the id to the _End of Interrupt Register_
1245(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1246controller.
1247
1248The TSP uses this API to finish processing of the secure physical timer
1249interrupt.
1250
1251
1252### Function : plat_ic_get_interrupt_type() [mandatory]
1253
1254 Argument : uint32_t
1255 Return : uint32_t
1256
1257This API returns the type of the interrupt id passed as the parameter.
1258`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1259interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1260returned depending upon how the interrupt has been configured by the platform
1261IC.
1262
1263The FVP port configures S-EL1 interrupts as Group0 interrupts and Non-secure
1264interrupts as Group1 interrupts. It reads the group value corresponding to the
1265interrupt id from the relevant _Interrupt Group Register_ (`GICD_IGROUPRn`). It
1266uses the group value to determine the type of interrupt.
1267
Achin Gupta4f6ad662013-10-25 09:08:21 +01001268
Harry Liebela960f282013-12-12 16:03:44 +000012694. C Library
1270-------------
1271
1272To avoid subtle toolchain behavioral dependencies, the header files provided
1273by the compiler are not used. The software is built with the `-nostdinc` flag
1274to ensure no headers are included from the toolchain inadvertently. Instead the
1275required headers are included in the ARM Trusted Firmware source tree. The
1276library only contains those C library definitions required by the local
1277implementation. If more functionality is required, the needed library functions
1278will need to be added to the local implementation.
1279
1280Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1281headers have been cut down in order to simplify the implementation. In order to
1282minimize changes to the header files, the [FreeBSD] layout has been maintained.
1283The generic C library definitions can be found in `include/stdlib` with more
1284system and machine specific declarations in `include/stdlib/sys` and
1285`include/stdlib/machine`.
1286
1287The local C library implementations can be found in `lib/stdlib`. In order to
1288extend the C library these files may need to be modified. It is recommended to
1289use a release version of [FreeBSD] as a starting point.
1290
1291The C library header files in the [FreeBSD] source tree are located in the
1292`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1293can be found in the `sys/<machine-type>` directories. These files define things
1294like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1295port for [FreeBSD] does not yet exist, the machine specific definitions are
1296based on existing machine types with similar properties (for example SPARC64).
1297
1298Where possible, C library function implementations were taken from [FreeBSD]
1299as found in the `lib/libc` directory.
1300
1301A copy of the [FreeBSD] sources can be downloaded with `git`.
1302
1303 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1304
1305
Harry Liebeld265bd72014-01-31 19:04:10 +000013065. Storage abstraction layer
1307-----------------------------
1308
1309In order to improve platform independence and portability an storage abstraction
1310layer is used to load data from non-volatile platform storage.
1311
1312Each platform should register devices and their drivers via the Storage layer.
1313These drivers then need to be initialized by bootloader phases as
1314required in their respective `blx_platform_setup()` functions. Currently
1315storage access is only required by BL1 and BL2 phases. The `load_image()`
1316function uses the storage layer to access non-volatile platform storage.
1317
1318It is mandatory to implement at least one storage driver. For the FVP the
1319Firmware Image Package(FIP) driver is provided as the default means to load data
1320from storage (see the "Firmware Image Package" section in the [User Guide]).
1321The storage layer is described in the header file `include/io_storage.h`. The
1322implementation of the common library is in `lib/io_storage.c` and the driver
1323files are located in `drivers/io/`.
1324
1325Each IO driver must provide `io_dev_*` structures, as described in
1326`drivers/io/io_driver.h`. These are returned via a mandatory registration
1327function that is called on platform initialization. The semi-hosting driver
1328implementation in `io_semihosting.c` can be used as an example.
1329
1330The Storage layer provides mechanisms to initialize storage devices before
1331IO operations are called. The basic operations supported by the layer
1332include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1333Drivers do not have to implement all operations, but each platform must
1334provide at least one driver for a device capable of supporting generic
1335operations such as loading a bootloader image.
1336
1337The current implementation only allows for known images to be loaded by the
Dan Handleyb68954c2014-05-29 12:30:24 +01001338firmware. These images are specified by using their names, as defined in
1339[include/plat/common/platform.h]. The platform layer (`plat_get_image_source()`)
1340then returns a reference to a device and a driver-specific `spec` which will be
1341understood by the driver to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001342
1343The layer is designed in such a way that is it possible to chain drivers with
1344other drivers. For example, file-system drivers may be implemented on top of
1345physical block devices, both represented by IO devices with corresponding
1346drivers. In such a case, the file-system "binding" with the block device may
1347be deferred until the file-system device is initialised.
1348
1349The abstraction currently depends on structures being statically allocated
1350by the drivers and callers, as the system does not yet provide a means of
1351dynamically allocating memory. This may also have the affect of limiting the
1352amount of open resources per driver.
1353
1354
Achin Gupta4f6ad662013-10-25 09:08:21 +01001355- - - - - - - - - - - - - - - - - - - - - - - - - -
1356
Dan Handleye83b0ca2014-01-14 18:17:09 +00001357_Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001358
1359
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001360[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1361[IMF Design Guide]: interrupt-framework-design.md
1362[User Guide]: user-guide.md
1363[FreeBSD]: http://www.freebsd.org
Achin Gupta4f6ad662013-10-25 09:08:21 +01001364
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001365[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1366[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handleyb68954c2014-05-29 12:30:24 +01001367[plat/fvp/include/platform_def.h]: ../plat/fvp/include/platform_def.h
1368[plat/fvp/include/plat_macros.S]: ../plat/fvp/include/plat_macros.S
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001369[plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c
1370[plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c
1371[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001372[include/plat/common/platform.h]: ../include/plat/common/platform.h