blob: 721ba1b6359bd7a44d1acd7c7c9d97263f1342c7 [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
10 * Common optional modifications
113. Boot Loader stage specific modifications
12 * Boot Loader stage 1 (BL1)
13 * Boot Loader stage 2 (BL2)
14 * Boot Loader stage 3-1 (BL3-1)
15 * PSCI implementation (in BL3-1)
Harry Liebeld265bd72014-01-31 19:04:10 +0000164. C Library
175. Storage abstraction layer
Achin Gupta4f6ad662013-10-25 09:08:21 +010018
19- - - - - - - - - - - - - - - - - -
20
211. Introduction
22----------------
23
24Porting the ARM Trusted Firmware to a new platform involves making some
25mandatory and optional modifications for both the cold and warm boot paths.
26Modifications consist of:
27
28* Implementing a platform-specific function or variable,
29* Setting up the execution context in a certain way, or
30* Defining certain constants (for example #defines).
31
32The firmware provides a default implementation of variables and functions to
33fulfill the optional requirements. These implementations are all weakly defined;
34they are provided to ease the porting effort. Each platform port can override
35them with its own implementation if the default implementation is inadequate.
36
37Some modifications are common to all Boot Loader (BL) stages. Section 2
38discusses these in detail. The subsequent sections discuss the remaining
39modifications for each BL stage in detail.
40
41This document should be read in conjunction with the ARM Trusted Firmware
42[User Guide].
43
44
452. Common modifications
46------------------------
47
48This section covers the modifications that should be made by the platform for
49each BL stage to correctly port the firmware stack. They are categorized as
50either mandatory or optional.
51
52
532.1 Common mandatory modifications
54----------------------------------
55A platform port must enable the Memory Management Unit (MMU) with identity
56mapped page tables, and enable both the instruction and data caches for each BL
57stage. In the ARM FVP port, each BL stage configures the MMU in its platform-
58specific architecture setup function, for example `blX_plat_arch_setup()`.
59
60Each platform must allocate a block of identity mapped secure memory with
61Device-nGnRE attributes aligned to page boundary (4K) for each BL stage. This
62memory is identified by the section name `tzfw_coherent_mem` so that its
63possible for the firmware to place variables in it using the following C code
64directive:
65
66 __attribute__ ((section("tzfw_coherent_mem")))
67
68Or alternatively the following assembler code directive:
69
70 .section tzfw_coherent_mem
71
72The `tzfw_coherent_mem` section is used to allocate any data structures that are
73accessed both when a CPU is executing with its MMU and caches enabled, and when
74it's running with its MMU and caches disabled. Examples are given below.
75
76The following variables, functions and constants must be defined by the platform
77for the firmware to work correctly.
78
79
80### File : platform.h [mandatory]
81
82Each platform must export a header file of this name with the following
83constants defined. In the ARM FVP port, this file is found in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +000084[plat/fvp/platform.h].
Achin Gupta4f6ad662013-10-25 09:08:21 +010085
James Morrisseyba3155b2013-10-29 10:56:46 +000086* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +010087
88 Defines the linker format used by the platform, for example
89 `elf64-littleaarch64` used by the FVP.
90
James Morrisseyba3155b2013-10-29 10:56:46 +000091* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +010092
93 Defines the processor architecture for the linker by the platform, for
94 example `aarch64` used by the FVP.
95
James Morrisseyba3155b2013-10-29 10:56:46 +000096* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +010097
98 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +000099 by [plat/common/aarch64/platform_mp_stack.S] and
100 [plat/common/aarch64/platform_up_stack.S].
101
102* **#define : PCPU_DV_MEM_STACK_SIZE**
103
104 Defines the coherent stack memory available to each CPU. This constant is used
105 by [plat/common/aarch64/platform_mp_stack.S] and
106 [plat/common/aarch64/platform_up_stack.S].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100107
James Morrisseyba3155b2013-10-29 10:56:46 +0000108* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100109
110 Defines the character string printed by BL1 upon entry into the `bl1_main()`
111 function.
112
James Morrisseyba3155b2013-10-29 10:56:46 +0000113* **#define : BL2_IMAGE_NAME**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100114
115 Name of the BL2 binary image on the host file-system. This name is used by
Harry Liebeld265bd72014-01-31 19:04:10 +0000116 BL1 to load BL2 into secure memory from non-volatile storage.
117
118* **#define : BL31_IMAGE_NAME**
119
120 Name of the BL3-1 binary image on the host file-system. This name is used by
121 BL2 to load BL3-1 into secure memory from platform storage.
122
123* **#define : BL33_IMAGE_NAME**
124
125 Name of the BL3-3 binary image on the host file-system. This name is used by
126 BL2 to load BL3-3 into non-secure memory from platform storage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100127
James Morrisseyba3155b2013-10-29 10:56:46 +0000128* **#define : PLATFORM_CACHE_LINE_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100129
130 Defines the size (in bytes) of the largest cache line across all the cache
131 levels in the platform.
132
James Morrisseyba3155b2013-10-29 10:56:46 +0000133* **#define : PLATFORM_CLUSTER_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100134
135 Defines the total number of clusters implemented by the platform in the
136 system.
137
James Morrisseyba3155b2013-10-29 10:56:46 +0000138* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100139
140 Defines the total number of CPUs implemented by the platform across all
141 clusters in the system.
142
James Morrisseyba3155b2013-10-29 10:56:46 +0000143* **#define : PLATFORM_MAX_CPUS_PER_CLUSTER**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100144
145 Defines the maximum number of CPUs that can be implemented within a cluster
146 on the platform.
147
James Morrisseyba3155b2013-10-29 10:56:46 +0000148* **#define : PRIMARY_CPU**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100149
150 Defines the `MPIDR` of the primary CPU on the platform. This value is used
151 after a cold boot to distinguish between primary and secondary CPUs.
152
James Morrisseyba3155b2013-10-29 10:56:46 +0000153* **#define : TZROM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100154
155 Defines the base address of secure ROM on the platform, where the BL1 binary
156 is loaded. This constant is used by the linker scripts to ensure that the
157 BL1 image fits into the available memory.
158
James Morrisseyba3155b2013-10-29 10:56:46 +0000159* **#define : TZROM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100160
161 Defines the size of secure ROM on the platform. This constant is used by the
162 linker scripts to ensure that the BL1 image fits into the available memory.
163
James Morrisseyba3155b2013-10-29 10:56:46 +0000164* **#define : TZRAM_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100165
166 Defines the base address of the secure RAM on platform, where the data
167 section of the BL1 binary is loaded. The BL2 and BL3-1 images are also
168 loaded in this secure RAM region. This constant is used by the linker
169 scripts to ensure that the BL1 data section and BL2/BL3-1 binary images fit
170 into the available memory.
171
James Morrisseyba3155b2013-10-29 10:56:46 +0000172* **#define : TZRAM_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100173
174 Defines the size of the secure RAM on the platform. This constant is used by
175 the linker scripts to ensure that the BL1 data section and BL2/BL3-1 binary
176 images fit into the available memory.
177
James Morrisseyba3155b2013-10-29 10:56:46 +0000178* **#define : SYS_CNTCTL_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100179
180 Defines the base address of the `CNTCTLBase` frame of the memory mapped
181 counter and timer in the system level implementation of the generic timer.
182
James Morrisseyba3155b2013-10-29 10:56:46 +0000183* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100184
185 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000186 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100187
James Morrisseyba3155b2013-10-29 10:56:46 +0000188* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100189
190 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000191 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100192
Harry Liebeld265bd72014-01-31 19:04:10 +0000193* **#define : NS_IMAGE_OFFSET**
194 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
195 image. Must be aligned on a page-size boundary.
196
Soby Mathewa43d4312014-04-07 15:28:55 +0100197### File : platform_macros.S [mandatory]
198
199Each platform must export a file of this name with the following
200macro defined. In the ARM FVP port, this file is found in
201[plat/fvp/include/platform_macros.S].
202
203* **Macro : plat_print_gic_regs**
204
205 This macro allows the crash reporting routine to print GIC registers
206 in case of an unhandled IRQ or FIQ in BL3-1. This aids in debugging and
207 this macro can be defined to be empty in case GIC register reporting is
208 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100209
210### Other mandatory modifications
211
James Morrisseyba3155b2013-10-29 10:56:46 +0000212The following mandatory modifications may be implemented in any file
Achin Gupta4f6ad662013-10-25 09:08:21 +0100213the implementer chooses. In the ARM FVP port, they are implemented in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000214[plat/fvp/aarch64/plat_common.c].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100215
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100216* **Function : uint64_t plat_get_syscnt_freq(void)**
217
218 This function is used by the architecture setup code to retrieve the
219 counter frequency for the CPU's generic timer. This value will be
220 programmed into the `CNTFRQ_EL0` register.
221 In the ARM FVP port, it returns the base frequency of the system counter,
222 which is retrieved from the first entry in the frequency modes table.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100223
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000224
Achin Gupta4f6ad662013-10-25 09:08:21 +01002252.2 Common optional modifications
226---------------------------------
227
228The following are helper functions implemented by the firmware that perform
229common platform-specific tasks. A platform may choose to override these
230definitions.
231
232
233### Function : platform_get_core_pos()
234
235 Argument : unsigned long
236 Return : int
237
238A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
239can be used as a CPU-specific linear index into blocks of memory (for example
240while allocating per-CPU stacks). This routine contains a simple mechanism
241to perform this conversion, using the assumption that each cluster contains a
242maximum of 4 CPUs:
243
244 linear index = cpu_id + (cluster_id * 4)
245
246 cpu_id = 8-bit value in MPIDR at affinity level 0
247 cluster_id = 8-bit value in MPIDR at affinity level 1
248
249
250### Function : platform_set_coherent_stack()
251
252 Argument : unsigned long
253 Return : void
254
255A platform may need stack memory that is coherent with main memory to perform
256certain operations like:
257
258* Turning the MMU on, or
259* Flushing caches prior to powering down a CPU or cluster.
260
261Each BL stage allocates this coherent stack memory for each CPU in the
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000262`tzfw_coherent_mem` section.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100263
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000264This function sets the current stack pointer to the coherent stack that
265has been allocated for the CPU specified by MPIDR. For BL images that only
266require a stack for the primary CPU the parameter is ignored. The size of
267the stack allocated to each CPU is specified by the platform defined constant
Achin Gupta4f6ad662013-10-25 09:08:21 +0100268`PCPU_DV_MEM_STACK_SIZE`.
269
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000270Common implementations of this function for the UP and MP BL images are
271provided in [plat/common/aarch64/platform_up_stack.S] and
272[plat/common/aarch64/platform_mp_stack.S]
273
Achin Gupta4f6ad662013-10-25 09:08:21 +0100274
275### Function : platform_is_primary_cpu()
276
277 Argument : unsigned long
278 Return : unsigned int
279
280This function identifies a CPU by its `MPIDR`, which is passed as the argument,
281to determine whether this CPU is the primary CPU or a secondary CPU. A return
282value of zero indicates that the CPU is not the primary CPU, while a non-zero
283return value indicates that the CPU is the primary CPU.
284
285
286### Function : platform_set_stack()
287
288 Argument : unsigned long
289 Return : void
290
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000291This function sets the current stack pointer to the normal memory stack that
292has been allocated for the CPU specificed by MPIDR. For BL images that only
293require a stack for the primary CPU the parameter is ignored. The size of
294the stack allocated to each CPU is specified by the platform defined constant
295`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100296
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000297Common implementations of this function for the UP and MP BL images are
298provided in [plat/common/aarch64/platform_up_stack.S] and
299[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100300
301
Achin Guptac8afc782013-11-25 18:45:02 +0000302### Function : platform_get_stack()
303
304 Argument : unsigned long
305 Return : unsigned long
306
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000307This function returns the base address of the normal memory stack that
308has been allocated for the CPU specificed by MPIDR. For BL images that only
309require a stack for the primary CPU the parameter is ignored. The size of
310the stack allocated to each CPU is specified by the platform defined constant
311`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000312
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000313Common implementations of this function for the UP and MP BL images are
314provided in [plat/common/aarch64/platform_up_stack.S] and
315[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000316
317
Achin Gupta4f6ad662013-10-25 09:08:21 +0100318### Function : plat_report_exception()
319
320 Argument : unsigned int
321 Return : void
322
323A platform may need to report various information about its status when an
324exception is taken, for example the current exception level, the CPU security
325state (secure/non-secure), the exception type, and so on. This function is
326called in the following circumstances:
327
328* In BL1, whenever an exception is taken.
329* In BL2, whenever an exception is taken.
330* In BL3-1, whenever an asynchronous exception or a synchronous exception
331 other than an SMC32/SMC64 exception is taken.
332
333The default implementation doesn't do anything, to avoid making assumptions
334about the way the platform displays its status information.
335
336This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000337exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100338that these constants are not related to any architectural exception code; they
339are just an ARM Trusted Firmware convention.
340
341
3423. Modifications specific to a Boot Loader stage
343-------------------------------------------------
344
3453.1 Boot Loader Stage 1 (BL1)
346-----------------------------
347
348BL1 implements the reset vector where execution starts from after a cold or
349warm boot. For each CPU, BL1 is responsible for the following tasks:
350
3511. Distinguishing between a cold boot and a warm boot.
352
3532. In the case of a cold boot and the CPU being the primary CPU, ensuring that
354 only this CPU executes the remaining BL1 code, including loading and passing
355 control to the BL2 stage.
356
3573. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
358 the CPU is placed in a platform-specific state until the primary CPU
359 performs the necessary steps to remove it from this state.
360
3614. In the case of a warm boot, ensuring that the CPU jumps to a platform-
362 specific address in the BL3-1 image in the same processor mode as it was
363 when released from reset.
364
Harry Liebeld265bd72014-01-31 19:04:10 +00003655. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100366 address specified by the platform defined constant `BL2_BASE`.
367
3686. Populating a `meminfo` structure with the following information in memory,
369 accessible by BL2 immediately upon entry.
370
371 meminfo.total_base = Base address of secure RAM visible to BL2
372 meminfo.total_size = Size of secure RAM visible to BL2
373 meminfo.free_base = Base address of secure RAM available for
374 allocation to BL2
375 meminfo.free_size = Size of secure RAM available for allocation to BL2
376
377 BL1 places this `meminfo` structure at the beginning of the free memory
378 available for its use. Since BL1 cannot allocate memory dynamically at the
379 moment, its free memory will be available for BL2's use as-is. However, this
380 means that BL2 must read the `meminfo` structure before it starts using its
381 free memory (this is discussed in Section 3.2).
382
383 In future releases of the ARM Trusted Firmware it will be possible for
384 the platform to decide where it wants to place the `meminfo` structure for
385 BL2.
386
387 BL1 implements the `init_bl2_mem_layout()` function to populate the
388 BL2 `meminfo` structure. The platform may override this implementation, for
389 example if the platform wants to restrict the amount of memory visible to
390 BL2. Details of how to do this are given below.
391
392The following functions need to be implemented by the platform port to enable
393BL1 to perform the above tasks.
394
395
396### Function : platform_get_entrypoint() [mandatory]
397
398 Argument : unsigned long
399 Return : unsigned int
400
401This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
402is identified by its `MPIDR`, which is passed as the argument. The function is
403responsible for distinguishing between a warm and cold reset using platform-
404specific means. If it's a warm reset then it returns the entrypoint into the
405BL3-1 image that the CPU must jump to. If it's a cold reset then this function
406must return zero.
407
408This function is also responsible for implementing a platform-specific mechanism
409to handle the condition where the CPU has been warm reset but there is no
410entrypoint to jump to.
411
412This function does not follow the Procedure Call Standard used by the
413Application Binary Interface for the ARM 64-bit architecture. The caller should
414not assume that callee saved registers are preserved across a call to this
415function.
416
417This function fulfills requirement 1 listed above.
418
419
420### Function : plat_secondary_cold_boot_setup() [mandatory]
421
422 Argument : void
423 Return : void
424
425This function is called with the MMU and data caches disabled. It is responsible
426for placing the executing secondary CPU in a platform-specific state until the
427primary CPU performs the necessary actions to bring it out of that state and
428allow entry into the OS.
429
430In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
431responsible for powering up the secondary CPU when normal world software
432requires them.
433
434This function fulfills requirement 3 above.
435
436
437### Function : platform_cold_boot_init() [mandatory]
438
439 Argument : unsigned long
440 Return : unsigned int
441
442This function executes with the MMU and data caches disabled. It is only called
443by the primary CPU. The argument to this function is the address of the
444`bl1_main()` routine where the generic BL1-specific actions are performed.
445This function performs any platform-specific and architectural setup that the
446platform requires to make execution of `bl1_main()` possible.
447
448The platform must enable the MMU with identity mapped page tables and enable
449caches by setting the `SCTLR.I` and `SCTLR.C` bits.
450
451Platform-specific setup might include configuration of memory controllers,
452configuration of the interconnect to allow the cluster to service cache snoop
453requests from another cluster, zeroing of the ZI section, and so on.
454
455In the ARM FVP port, this function enables CCI snoops into the cluster that the
456primary CPU is part of. It also enables the MMU and initializes the ZI section
457in the BL1 image through the use of linker defined symbols.
458
459This function helps fulfill requirement 2 above.
460
461
462### Function : bl1_platform_setup() [mandatory]
463
464 Argument : void
465 Return : void
466
467This function executes with the MMU and data caches enabled. It is responsible
468for performing any remaining platform-specific setup that can occur after the
469MMU and data cache have been enabled.
470
Harry Liebeld265bd72014-01-31 19:04:10 +0000471This function is also responsible for initializing the storage abstraction layer
472which is used to load further bootloader images.
473
Achin Gupta4f6ad662013-10-25 09:08:21 +0100474This function helps fulfill requirement 5 above.
475
476
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000477### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100478
479 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000480 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100481
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000482This function should only be called on the cold boot path. It executes with the
483MMU and data caches enabled. The pointer returned by this function must point to
484a `meminfo` structure containing the extents and availability of secure RAM for
485the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100486
487 meminfo.total_base = Base address of secure RAM visible to BL1
488 meminfo.total_size = Size of secure RAM visible to BL1
489 meminfo.free_base = Base address of secure RAM available for allocation
490 to BL1
491 meminfo.free_size = Size of secure RAM available for allocation to BL1
492
493This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
494populates a similar structure to tell BL2 the extents of memory available for
495its own use.
496
497This function helps fulfill requirement 5 above.
498
499
500### Function : init_bl2_mem_layout() [optional]
501
502 Argument : meminfo *, meminfo *, unsigned int, unsigned long
503 Return : void
504
505Each BL stage needs to tell the next stage the amount of secure RAM available
506for it to use. For example, as part of handing control to BL2, BL1 informs BL2
507of the extents of secure RAM available for BL2 to use. BL2 must do the same when
508passing control to BL3-1. This information is populated in a `meminfo`
509structure.
510
511Depending upon where BL2 has been loaded in secure RAM (determined by
512`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
513BL1 also ensures that its data sections resident in secure RAM are not visible
514to BL2. An illustration of how this is done in the ARM FVP port is given in the
515[User Guide], in the Section "Memory layout on Base FVP".
516
517
5183.2 Boot Loader Stage 2 (BL2)
519-----------------------------
520
521The BL2 stage is executed only by the primary CPU, which is determined in BL1
522using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
523`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
524
Harry Liebeld265bd72014-01-31 19:04:10 +00005251. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
526 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
527 by BL1. This structure allows BL2 to calculate how much secure RAM is
528 available for its use. The platform also defines the address in secure RAM
529 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
530 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100531
Harry Liebeld265bd72014-01-31 19:04:10 +00005322. Loading the normal world BL3-3 binary image into non-secure DRAM from
533 platform storage and arranging for BL3-1 to pass control to this image. This
534 address is determined using the `plat_get_ns_image_entrypoint()` function
535 described below.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100536
537 BL2 populates an `el_change_info` structure in memory provided by the
538 platform with information about how BL3-1 should pass control to the normal
539 world BL image.
540
5413. Populating a `meminfo` structure with the following information in
542 memory that is accessible by BL3-1 immediately upon entry.
543
544 meminfo.total_base = Base address of secure RAM visible to BL3-1
545 meminfo.total_size = Size of secure RAM visible to BL3-1
546 meminfo.free_base = Base address of secure RAM available for allocation
547 to BL3-1
548 meminfo.free_size = Size of secure RAM available for allocation to
549 BL3-1
550
Achin Guptae4d084e2014-02-19 17:18:23 +0000551 BL2 populates this information in the `bl31_meminfo` field of the pointer
552 returned by the `bl2_get_bl31_args_ptr() function. BL2 implements the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100553 `init_bl31_mem_layout()` function to populate the BL3-1 meminfo structure
554 described above. The platform may override this implementation, for example
555 if the platform wants to restrict the amount of memory visible to BL3-1.
556 Details of this function are given below.
557
Achin Guptaa3050ed2014-02-19 17:52:35 +00005584. Loading the BL3-2 binary image (if present) in platform provided memory
559 using semi-hosting. To load the BL3-2 image, BL2 makes use of the
560 `bl32_meminfo` field in the `bl31_args` structure to which a pointer is
561 returned by the `bl2_get_bl31_args_ptr()` function. The platform also
562 defines the address in memory where BL3-2 is loaded through the constant
563 `BL32_BASE`. BL2 uses this information to determine if there is enough
564 memory to load the BL3-2 image.
565
5665. Arranging to pass control to the BL3-2 image (if present) that has been
567 pre-loaded at `BL32_BASE`. BL2 populates an `el_change_info` structure
568 in memory provided by the platform with information about how BL3-1 should
569 pass control to the BL3-2 image. This structure follows the
570 `el_change_info` structure populated for the normal world BL image in 2.
571 above.
572
5736. Populating a `meminfo` structure with the following information in
574 memory that is accessible by BL3-1 immediately upon entry.
575
576 meminfo.total_base = Base address of memory visible to BL3-2
577 meminfo.total_size = Size of memory visible to BL3-2
578 meminfo.free_base = Base address of memory available for allocation
579 to BL3-2
580 meminfo.free_size = Size of memory available for allocation to
581 BL3-2
582
583 BL2 populates this information in the `bl32_meminfo` field of the pointer
584 returned by the `bl2_get_bl31_args_ptr() function.
585
Achin Gupta4f6ad662013-10-25 09:08:21 +0100586The following functions must be implemented by the platform port to enable BL2
587to perform the above tasks.
588
589
590### Function : bl2_early_platform_setup() [mandatory]
591
592 Argument : meminfo *, void *
593 Return : void
594
595This function executes with the MMU and data caches disabled. It is only called
596by the primary CPU. The arguments to this function are:
597
598* The address of the `meminfo` structure populated by BL1
599* An opaque pointer that the platform may use as needed.
600
601The platform must copy the contents of the `meminfo` structure into a private
602variable as the original memory may be subsequently overwritten by BL2. The
603copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000604`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100605
606
607### Function : bl2_plat_arch_setup() [mandatory]
608
609 Argument : void
610 Return : void
611
612This function executes with the MMU and data caches disabled. It is only called
613by the primary CPU.
614
615The purpose of this function is to perform any architectural initialization
616that varies across platforms, for example enabling the MMU (since the memory
617map differs across platforms).
618
619
620### Function : bl2_platform_setup() [mandatory]
621
622 Argument : void
623 Return : void
624
625This function may execute with the MMU and data caches enabled if the platform
626port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
627called by the primary CPU.
628
Achin Guptae4d084e2014-02-19 17:18:23 +0000629The purpose of this function is to perform any platform initialization
630specific to BL2. For example on the ARM FVP port this function initialises a
631internal pointer (`bl2_to_bl31_args`) to a `bl31_args` which will be used by
632BL2 to pass information to BL3_1. The pointer is initialized to the base
633address of Secure DRAM (`0x06000000`).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100634
Achin Guptaa3050ed2014-02-19 17:52:35 +0000635The ARM FVP port also populates the `bl32_meminfo` field in the `bl31_args`
636structure pointed to by `bl2_to_bl31_args` with the extents of memory available
637for use by the BL3-2 image. The memory is allocated in the Secure DRAM from the
Dan Handley57de6d72014-02-27 19:46:37 +0000638address defined by the constant `BL32_BASE`. The ARM FVP port currently loads
639the BL3-2 image at the Secure DRAM address `0x6002000`.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000640
Achin Guptae4d084e2014-02-19 17:18:23 +0000641The non-secure memory extents used for loading BL3-3 are also initialized in
642this function. This information is accessible in the `bl33_meminfo` field in
643the `bl31_args` structure pointed to by `bl2_to_bl31_args`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100644
Harry Liebelce19cf12014-04-01 19:28:07 +0100645Platform security components are configured if required. For the Base FVP the
Andrew Thoelke84dbf6f2014-05-09 15:36:13 +0100646TZC-400 TrustZone controller is configured to only grant non-secure access
647to DRAM. This avoids aliasing between secure and non-secure accesses in the
648TLB and cache - secure execution states can use the NS attributes in the
649MMU translation tables to access the DRAM.
Harry Liebelce19cf12014-04-01 19:28:07 +0100650
Harry Liebeld265bd72014-01-31 19:04:10 +0000651This function is also responsible for initializing the storage abstraction layer
652which is used to load further bootloader images.
653
Achin Gupta4f6ad662013-10-25 09:08:21 +0100654
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000655### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100656
657 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000658 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100659
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000660This function should only be called on the cold boot path. It may execute with
661the MMU and data caches enabled if the platform port does the necessary
662initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100663
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000664The purpose of this function is to return a pointer to a `meminfo` structure
665populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100666`bl2_early_platform_setup()` above.
667
668
Achin Guptae4d084e2014-02-19 17:18:23 +0000669### Function : bl2_get_bl31_args_ptr() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000670
671 Argument : void
Achin Guptae4d084e2014-02-19 17:18:23 +0000672 Return : bl31_args *
Harry Liebeld265bd72014-01-31 19:04:10 +0000673
Achin Guptae4d084e2014-02-19 17:18:23 +0000674BL2 platform code needs to return a pointer to a `bl31_args` structure it will
675use for passing information to BL3-1. The `bl31_args` structure carries the
676following information. This information is used by the `bl2_main()` function to
677load the BL3-2 (if present) and BL3-3 images.
678 - Extents of memory available to the BL3-1 image in the `bl31_meminfo` field
679 - Extents of memory available to the BL3-2 image in the `bl32_meminfo` field
680 - Extents of memory available to the BL3-3 image in the `bl33_meminfo` field
681 - Information about executing the BL3-3 image in the `bl33_image_info` field
682 - Information about executing the BL3-2 image in the `bl32_image_info` field
Harry Liebeld265bd72014-01-31 19:04:10 +0000683
684
Achin Gupta4f6ad662013-10-25 09:08:21 +0100685### Function : init_bl31_mem_layout() [optional]
686
687 Argument : meminfo *, meminfo *, unsigned int
688 Return : void
689
690Each BL stage needs to tell the next stage the amount of secure RAM that is
691available for it to use. For example, as part of handing control to BL2, BL1
692must inform BL2 about the extents of secure RAM that is available for BL2 to
693use. BL2 must do the same when passing control to BL3-1. This information is
694populated in a `meminfo` structure.
695
696Depending upon where BL3-1 has been loaded in secure RAM (determined by
697`BL31_BASE`), BL2 calculates the amount of free memory available for BL3-1 to
698use. BL2 also ensures that BL3-1 is able reclaim memory occupied by BL2. This
699is done because BL2 never executes again after passing control to BL3-1.
700An illustration of how this is done in the ARM FVP port is given in the
701[User Guide], in the section "Memory layout on Base FVP".
702
703
704### Function : plat_get_ns_image_entrypoint() [mandatory]
705
706 Argument : void
707 Return : unsigned long
708
709As previously described, BL2 is responsible for arranging for control to be
710passed to a normal world BL image through BL3-1. This function returns the
711entrypoint of that image, which BL3-1 uses to jump to it.
712
Harry Liebeld265bd72014-01-31 19:04:10 +0000713BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100714
715
7163.2 Boot Loader Stage 3-1 (BL3-1)
717---------------------------------
718
719During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
720determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
721control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
722CPUs. BL3-1 executes at EL3 and is responsible for:
723
7241. Re-initializing all architectural and platform state. Although BL1 performs
725 some of this initialization, BL3-1 remains resident in EL3 and must ensure
726 that EL3 architectural and platform state is completely initialized. It
727 should make no assumptions about the system state when it receives control.
728
7292. Passing control to a normal world BL image, pre-loaded at a platform-
730 specific address by BL2. BL3-1 uses the `el_change_info` structure that BL2
731 populated in memory to do this.
732
7333. Providing runtime firmware services. Currently, BL3-1 only implements a
734 subset of the Power State Coordination Interface (PSCI) API as a runtime
735 service. See Section 3.3 below for details of porting the PSCI
736 implementation.
737
Achin Gupta35ca3512014-02-19 17:58:33 +00007384. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
739 specific address by BL2. BL3-1 exports a set of apis that allow runtime
740 services to specify the security state in which the next image should be
741 executed and run the corresponding image. BL3-1 uses the `el_change_info`
742 and `meminfo` structure populated by BL2 to do this.
743
Achin Gupta4f6ad662013-10-25 09:08:21 +0100744The following functions must be implemented by the platform port to enable BL3-1
745to perform the above tasks.
746
747
748### Function : bl31_early_platform_setup() [mandatory]
749
750 Argument : meminfo *, void *, unsigned long
751 Return : void
752
753This function executes with the MMU and data caches disabled. It is only called
754by the primary CPU. The arguments to this function are:
755
756* The address of the `meminfo` structure populated by BL2.
757* An opaque pointer that the platform may use as needed.
758* The `MPIDR` of the primary CPU.
759
Achin Guptae4d084e2014-02-19 17:18:23 +0000760The platform can copy the contents of the `meminfo` structure into a private
761variable if the original memory may be subsequently overwritten by BL3-1. The
762reference to this structure is made available to all BL3-1 code through the
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000763`bl31_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100764
Achin Guptae4d084e2014-02-19 17:18:23 +0000765On the ARM FVP port, BL2 passes a pointer to a `bl31_args` structure populated
766in the secure DRAM at address `0x6000000` in the opaque pointer mentioned
767earlier. BL3-1 does not copy this information to internal data structures as it
768guarantees that the secure DRAM memory will not be overwritten. It maintains an
769internal reference to this information in the `bl2_to_bl31_args` variable.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100770
771### Function : bl31_plat_arch_setup() [mandatory]
772
773 Argument : void
774 Return : void
775
776This function executes with the MMU and data caches disabled. It is only called
777by the primary CPU.
778
779The purpose of this function is to perform any architectural initialization
780that varies across platforms, for example enabling the MMU (since the memory
781map differs across platforms).
782
783
784### Function : bl31_platform_setup() [mandatory]
785
786 Argument : void
787 Return : void
788
789This function may execute with the MMU and data caches enabled if the platform
790port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
791called by the primary CPU.
792
793The purpose of this function is to complete platform initialization so that both
794BL3-1 runtime services and normal world software can function correctly.
795
796The ARM FVP port does the following:
797* Initializes the generic interrupt controller.
798* Configures the CLCD controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100799* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100800* Grants access to the system counter timer module
801* Initializes the FVP power controller device
802* Detects the system topology.
803
804
805### Function : bl31_get_next_image_info() [mandatory]
806
Achin Gupta35ca3512014-02-19 17:58:33 +0000807 Argument : unsigned int
Achin Gupta4f6ad662013-10-25 09:08:21 +0100808 Return : el_change_info *
809
810This function may execute with the MMU and data caches enabled if the platform
811port does the necessary initializations in `bl31_plat_arch_setup()`.
812
813This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +0000814BL2 for the next image in the security state specified by the argument. BL3-1
815uses this information to pass control to that image in the specified security
816state. This function must return a pointer to the `el_change_info` structure
817(that was copied during `bl31_early_platform_setup()`) if the image exists. It
818should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100819
820
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000821### Function : bl31_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100822
823 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000824 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100825
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000826This function should only be called on the cold boot path. This function may
827execute with the MMU and data caches enabled if the platform port does the
828necessary initializations in `bl31_plat_arch_setup()`. It is only called by the
829primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100830
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000831The purpose of this function is to return a pointer to a `meminfo` structure
832populated with the extents of secure RAM available for BL3-1 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100833`bl31_early_platform_setup()` above.
834
835
Achin Gupta35ca3512014-02-19 17:58:33 +0000836### Function : bl31_plat_get_bl32_mem_layout() [mandatory]
837
838 Argument : void
839 Return : meminfo *
840
841This function should only be called on the cold boot path. This function may
842execute with the MMU and data caches enabled if the platform port does the
843necessary initializations in `bl31_plat_arch_setup()`. It is only called by the
844primary CPU.
845
846The purpose of this function is to return a pointer to a `meminfo` structure
847populated with the extents of memory available for BL3-2 to use. See
848`bl31_early_platform_setup()` above.
849
850
Achin Gupta4f6ad662013-10-25 09:08:21 +01008513.3 Power State Coordination Interface (in BL3-1)
852------------------------------------------------
853
854The ARM Trusted Firmware's implementation of the PSCI API is based around the
855concept of an _affinity instance_. Each _affinity instance_ can be uniquely
856identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
857interface) and an _affinity level_. A processing element (for example, a
858CPU) is at level 0. If the CPUs in the system are described in a tree where the
859node above a CPU is a logical grouping of CPUs that share some state, then
860affinity level 1 is that group of CPUs (for example, a cluster), and affinity
861level 2 is a group of clusters (for example, the system). The implementation
862assumes that the affinity level 1 ID can be computed from the affinity level 0
863ID (for example, a unique cluster ID can be computed from the CPU ID). The
864current implementation computes this on the basis of the recommended use of
865`MPIDR` affinity fields in the ARM Architecture Reference Manual.
866
867BL3-1's platform initialization code exports a pointer to the platform-specific
868power management operations required for the PSCI implementation to function
869correctly. This information is populated in the `plat_pm_ops` structure. The
870PSCI implementation calls members of the `plat_pm_ops` structure for performing
871power management operations for each affinity instance. For example, the target
872CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
873handler (if present) is called for each affinity instance as the PSCI
874implementation powers up each affinity level implemented in the `MPIDR` (for
875example, CPU, cluster and system).
876
877The following functions must be implemented to initialize PSCI functionality in
878the ARM Trusted Firmware.
879
880
881### Function : plat_get_aff_count() [mandatory]
882
883 Argument : unsigned int, unsigned long
884 Return : unsigned int
885
886This function may execute with the MMU and data caches enabled if the platform
887port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
888called by the primary CPU.
889
890This function is called by the PSCI initialization code to detect the system
891topology. Its purpose is to return the number of affinity instances implemented
892at a given `affinity level` (specified by the first argument) and a given
893`MPIDR` (specified by the second argument). For example, on a dual-cluster
894system where first cluster implements 2 CPUs and the second cluster implements 4
895CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
896(`0x0`) and affinity level 0, would return 2. A call to this function with an
897`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
898would return 4.
899
900
901### Function : plat_get_aff_state() [mandatory]
902
903 Argument : unsigned int, unsigned long
904 Return : unsigned int
905
906This function may execute with the MMU and data caches enabled if the platform
907port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
908called by the primary CPU.
909
910This function is called by the PSCI initialization code. Its purpose is to
911return the state of an affinity instance. The affinity instance is determined by
912the affinity ID at a given `affinity level` (specified by the first argument)
913and an `MPIDR` (specified by the second argument). The state can be one of
914`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
915system topologies where certain affinity instances are unimplemented. For
916example, consider a platform that implements a single cluster with 4 CPUs and
917another CPU implemented directly on the interconnect with the cluster. The
918`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
919CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
920is missing but needs to be accounted for to reach this single CPU in the
921topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
922
923
924### Function : plat_get_max_afflvl() [mandatory]
925
926 Argument : void
927 Return : int
928
929This function may execute with the MMU and data caches enabled if the platform
930port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
931called by the primary CPU.
932
933This function is called by the PSCI implementation both during cold and warm
934boot, to determine the maximum affinity level that the power management
James Morrisseyba3155b2013-10-29 10:56:46 +0000935operations should apply to. ARMv8-A has support for 4 affinity levels. It is
Achin Gupta4f6ad662013-10-25 09:08:21 +0100936likely that hardware will implement fewer affinity levels. This function allows
937the PSCI implementation to consider only those affinity levels in the system
938that the platform implements. For example, the Base AEM FVP implements two
939clusters with a configurable number of CPUs. It reports the maximum affinity
940level as 1, resulting in PSCI power control up to the cluster level.
941
942
943### Function : platform_setup_pm() [mandatory]
944
945 Argument : plat_pm_ops **
946 Return : int
947
948This function may execute with the MMU and data caches enabled if the platform
949port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
950called by the primary CPU.
951
952This function is called by PSCI initialization code. Its purpose is to export
953handler routines for platform-specific power management actions by populating
954the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
955
956A description of each member of this structure is given below. Please refer to
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000957the ARM FVP specific implementation of these handlers in [plat/fvp/plat_pm.c]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100958as an example. A platform port may choose not implement some of the power
959management operations. For example, the ARM FVP port does not implement the
960`affinst_standby()` function.
961
962#### plat_pm_ops.affinst_standby()
963
964Perform the platform-specific setup to enter the standby state indicated by the
965passed argument.
966
967#### plat_pm_ops.affinst_on()
968
969Perform the platform specific setup to power on an affinity instance, specified
970by the `MPIDR` (first argument) and `affinity level` (fourth argument). The
971`state` (fifth argument) contains the current state of that affinity instance
972(ON or OFF). This is useful to determine whether any action must be taken. For
973example, while powering on a CPU, the cluster that contains this CPU might
974already be in the ON state. The platform decides what actions must be taken to
975transition from the current state to the target state (indicated by the power
976management operation).
977
978#### plat_pm_ops.affinst_off()
979
980Perform the platform specific setup to power off an affinity instance in the
981`MPIDR` of the calling CPU. It is called by the PSCI `CPU_OFF` API
982implementation.
983
984The `MPIDR` (first argument), `affinity level` (second argument) and `state`
985(third argument) have a similar meaning as described in the `affinst_on()`
986operation. They are used to identify the affinity instance on which the call
987is made and its current state. This gives the platform port an indication of the
988state transition it must make to perform the requested action. For example, if
989the calling CPU is the last powered on CPU in the cluster, after powering down
990affinity level 0 (CPU), the platform port should power down affinity level 1
991(the cluster) as well.
992
993This function is called with coherent stacks. This allows the PSCI
994implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +0000995stale stack state after turning off the caches. On ARMv8-A cache hits do not
996occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100997
998#### plat_pm_ops.affinst_suspend()
999
1000Perform the platform specific setup to power off an affinity instance in the
1001`MPIDR` of the calling CPU. It is called by the PSCI `CPU_SUSPEND` API
1002implementation.
1003
1004The `MPIDR` (first argument), `affinity level` (third argument) and `state`
1005(fifth argument) have a similar meaning as described in the `affinst_on()`
1006operation. They are used to identify the affinity instance on which the call
1007is made and its current state. This gives the platform port an indication of the
1008state transition it must make to perform the requested action. For example, if
1009the calling CPU is the last powered on CPU in the cluster, after powering down
1010affinity level 0 (CPU), the platform port should power down affinity level 1
1011(the cluster) as well.
1012
1013The difference between turning an affinity instance off versus suspending it
1014is that in the former case, the affinity instance is expected to re-initialize
1015its state when its next powered on (see `affinst_on_finish()`). In the latter
1016case, the affinity instance is expected to save enough state so that it can
1017resume execution by restoring this state when its powered on (see
1018`affinst_suspend_finish()`).
1019
1020This function is called with coherent stacks. This allows the PSCI
1021implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001022stale stack state after turning off the caches. On ARMv8-A cache hits do not
1023occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001024
1025#### plat_pm_ops.affinst_on_finish()
1026
1027This function is called by the PSCI implementation after the calling CPU is
1028powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1029It performs the platform-specific setup required to initialize enough state for
1030this CPU to enter the normal world and also provide secure runtime firmware
1031services.
1032
1033The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1034(third argument) have a similar meaning as described in the previous operations.
1035
1036This function is called with coherent stacks. This allows the PSCI
1037implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001038stale stack state after turning off the caches. On ARMv8-A cache hits do not
1039occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001040
1041#### plat_pm_ops.affinst_on_suspend()
1042
1043This function is called by the PSCI implementation after the calling CPU is
1044powered on and released from reset in response to an asynchronous wakeup
1045event, for example a timer interrupt that was programmed by the CPU during the
1046`CPU_SUSPEND` call. It performs the platform-specific setup required to
1047restore the saved state for this CPU to resume execution in the normal world
1048and also provide secure runtime firmware services.
1049
1050The `MPIDR` (first argument), `affinity level` (second argument) and `state`
1051(third argument) have a similar meaning as described in the previous operations.
1052
1053This function is called with coherent stacks. This allows the PSCI
1054implementation to flush caches at a given affinity level without running into
James Morrisseyba3155b2013-10-29 10:56:46 +00001055stale stack state after turning off the caches. On ARMv8-A cache hits do not
1056occur after the cache has been turned off.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001057
1058BL3-1 platform initialization code must also detect the system topology and
1059the state of each affinity instance in the topology. This information is
1060critical for the PSCI runtime service to function correctly. More details are
1061provided in the description of the `plat_get_aff_count()` and
1062`plat_get_aff_state()` functions above.
1063
1064
Harry Liebela960f282013-12-12 16:03:44 +000010654. C Library
1066-------------
1067
1068To avoid subtle toolchain behavioral dependencies, the header files provided
1069by the compiler are not used. The software is built with the `-nostdinc` flag
1070to ensure no headers are included from the toolchain inadvertently. Instead the
1071required headers are included in the ARM Trusted Firmware source tree. The
1072library only contains those C library definitions required by the local
1073implementation. If more functionality is required, the needed library functions
1074will need to be added to the local implementation.
1075
1076Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1077headers have been cut down in order to simplify the implementation. In order to
1078minimize changes to the header files, the [FreeBSD] layout has been maintained.
1079The generic C library definitions can be found in `include/stdlib` with more
1080system and machine specific declarations in `include/stdlib/sys` and
1081`include/stdlib/machine`.
1082
1083The local C library implementations can be found in `lib/stdlib`. In order to
1084extend the C library these files may need to be modified. It is recommended to
1085use a release version of [FreeBSD] as a starting point.
1086
1087The C library header files in the [FreeBSD] source tree are located in the
1088`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1089can be found in the `sys/<machine-type>` directories. These files define things
1090like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1091port for [FreeBSD] does not yet exist, the machine specific definitions are
1092based on existing machine types with similar properties (for example SPARC64).
1093
1094Where possible, C library function implementations were taken from [FreeBSD]
1095as found in the `lib/libc` directory.
1096
1097A copy of the [FreeBSD] sources can be downloaded with `git`.
1098
1099 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1100
1101
Harry Liebeld265bd72014-01-31 19:04:10 +000011025. Storage abstraction layer
1103-----------------------------
1104
1105In order to improve platform independence and portability an storage abstraction
1106layer is used to load data from non-volatile platform storage.
1107
1108Each platform should register devices and their drivers via the Storage layer.
1109These drivers then need to be initialized by bootloader phases as
1110required in their respective `blx_platform_setup()` functions. Currently
1111storage access is only required by BL1 and BL2 phases. The `load_image()`
1112function uses the storage layer to access non-volatile platform storage.
1113
1114It is mandatory to implement at least one storage driver. For the FVP the
1115Firmware Image Package(FIP) driver is provided as the default means to load data
1116from storage (see the "Firmware Image Package" section in the [User Guide]).
1117The storage layer is described in the header file `include/io_storage.h`. The
1118implementation of the common library is in `lib/io_storage.c` and the driver
1119files are located in `drivers/io/`.
1120
1121Each IO driver must provide `io_dev_*` structures, as described in
1122`drivers/io/io_driver.h`. These are returned via a mandatory registration
1123function that is called on platform initialization. The semi-hosting driver
1124implementation in `io_semihosting.c` can be used as an example.
1125
1126The Storage layer provides mechanisms to initialize storage devices before
1127IO operations are called. The basic operations supported by the layer
1128include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1129Drivers do not have to implement all operations, but each platform must
1130provide at least one driver for a device capable of supporting generic
1131operations such as loading a bootloader image.
1132
1133The current implementation only allows for known images to be loaded by the
1134firmware. These images are specified by using their names, as defined in the
1135`platform.h` file. The platform layer (`plat_get_image_source()`) then returns
1136a reference to a device and a driver-specific `spec` which will be understood
1137by the driver to allow access to the image data.
1138
1139The layer is designed in such a way that is it possible to chain drivers with
1140other drivers. For example, file-system drivers may be implemented on top of
1141physical block devices, both represented by IO devices with corresponding
1142drivers. In such a case, the file-system "binding" with the block device may
1143be deferred until the file-system device is initialised.
1144
1145The abstraction currently depends on structures being statically allocated
1146by the drivers and callers, as the system does not yet provide a means of
1147dynamically allocating memory. This may also have the affect of limiting the
1148amount of open resources per driver.
1149
1150
Achin Gupta4f6ad662013-10-25 09:08:21 +01001151- - - - - - - - - - - - - - - - - - - - - - - - - -
1152
Dan Handleye83b0ca2014-01-14 18:17:09 +00001153_Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001154
1155
1156[User Guide]: user-guide.md
Harry Liebela960f282013-12-12 16:03:44 +00001157[FreeBSD]: http://www.freebsd.org
Achin Gupta4f6ad662013-10-25 09:08:21 +01001158
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001159[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1160[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
1161[plat/fvp/platform.h]: ../plat/fvp/platform.h
Soby Mathewa43d4312014-04-07 15:28:55 +01001162[plat/fvp/include/platform_macros.S]: ../plat/fvp/include/platform_macros.S
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001163[plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c
1164[plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c
1165[include/runtime_svc.h]: ../include/runtime_svc.h