blob: ae77c553481d98178173509067041048e612799d [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)
16
17- - - - - - - - - - - - - - - - - -
18
191. Introduction
20----------------
21
22Porting the ARM Trusted Firmware to a new platform involves making some
23mandatory and optional modifications for both the cold and warm boot paths.
24Modifications consist of:
25
26* Implementing a platform-specific function or variable,
27* Setting up the execution context in a certain way, or
28* Defining certain constants (for example #defines).
29
30The firmware provides a default implementation of variables and functions to
31fulfill the optional requirements. These implementations are all weakly defined;
32they are provided to ease the porting effort. Each platform port can override
33them with its own implementation if the default implementation is inadequate.
34
35Some modifications are common to all Boot Loader (BL) stages. Section 2
36discusses these in detail. The subsequent sections discuss the remaining
37modifications for each BL stage in detail.
38
39This document should be read in conjunction with the ARM Trusted Firmware
40[User Guide].
41
42
432. Common modifications
44------------------------
45
46This section covers the modifications that should be made by the platform for
47each BL stage to correctly port the firmware stack. They are categorized as
48either mandatory or optional.
49
50
512.1 Common mandatory modifications
52----------------------------------
53A platform port must enable the Memory Management Unit (MMU) with identity
54mapped page tables, and enable both the instruction and data caches for each BL
55stage. In the ARM FVP port, each BL stage configures the MMU in its platform-
56specific architecture setup function, for example `blX_plat_arch_setup()`.
57
58Each platform must allocate a block of identity mapped secure memory with
59Device-nGnRE attributes aligned to page boundary (4K) for each BL stage. This
60memory is identified by the section name `tzfw_coherent_mem` so that its
61possible for the firmware to place variables in it using the following C code
62directive:
63
64 __attribute__ ((section("tzfw_coherent_mem")))
65
66Or alternatively the following assembler code directive:
67
68 .section tzfw_coherent_mem
69
70The `tzfw_coherent_mem` section is used to allocate any data structures that are
71accessed both when a CPU is executing with its MMU and caches enabled, and when
72it's running with its MMU and caches disabled. Examples are given below.
73
74The following variables, functions and constants must be defined by the platform
75for the firmware to work correctly.
76
77
78### File : platform.h [mandatory]
79
80Each platform must export a header file of this name with the following
81constants defined. In the ARM FVP port, this file is found in
82[../plat/fvp/platform.h].
83
84* ** #define : PLATFORM_LINKER_FORMAT **
85
86 Defines the linker format used by the platform, for example
87 `elf64-littleaarch64` used by the FVP.
88
89* ** #define : PLATFORM_LINKER_ARCH **
90
91 Defines the processor architecture for the linker by the platform, for
92 example `aarch64` used by the FVP.
93
94* ** #define : PLATFORM_STACK_SIZE **
95
96 Defines the normal stack memory available to each CPU. This constant is used
97 by `platform_set_stack()`.
98
99* ** #define : FIRMWARE_WELCOME_STR **
100
101 Defines the character string printed by BL1 upon entry into the `bl1_main()`
102 function.
103
104* ** #define : BL2_IMAGE_NAME **
105
106 Name of the BL2 binary image on the host file-system. This name is used by
107 BL1 to load BL2 into secure memory using semi-hosting.
108
109* ** #define : PLATFORM_CACHE_LINE_SIZE **
110
111 Defines the size (in bytes) of the largest cache line across all the cache
112 levels in the platform.
113
114* ** #define : PLATFORM_CLUSTER_COUNT **
115
116 Defines the total number of clusters implemented by the platform in the
117 system.
118
119* ** #define : PLATFORM_CORE_COUNT **
120
121 Defines the total number of CPUs implemented by the platform across all
122 clusters in the system.
123
124* ** #define : PLATFORM_MAX_CPUS_PER_CLUSTER **
125
126 Defines the maximum number of CPUs that can be implemented within a cluster
127 on the platform.
128
129* ** #define : PRIMARY_CPU **
130
131 Defines the `MPIDR` of the primary CPU on the platform. This value is used
132 after a cold boot to distinguish between primary and secondary CPUs.
133
134* ** #define : TZROM_BASE **
135
136 Defines the base address of secure ROM on the platform, where the BL1 binary
137 is loaded. This constant is used by the linker scripts to ensure that the
138 BL1 image fits into the available memory.
139
140* ** #define : TZROM_SIZE **
141
142 Defines the size of secure ROM on the platform. This constant is used by the
143 linker scripts to ensure that the BL1 image fits into the available memory.
144
145* ** #define : TZRAM_BASE **
146
147 Defines the base address of the secure RAM on platform, where the data
148 section of the BL1 binary is loaded. The BL2 and BL3-1 images are also
149 loaded in this secure RAM region. This constant is used by the linker
150 scripts to ensure that the BL1 data section and BL2/BL3-1 binary images fit
151 into the available memory.
152
153* ** #define : TZRAM_SIZE **
154
155 Defines the size of the secure RAM on the platform. This constant is used by
156 the linker scripts to ensure that the BL1 data section and BL2/BL3-1 binary
157 images fit into the available memory.
158
159* ** #define : SYS_CNTCTL_BASE **
160
161 Defines the base address of the `CNTCTLBase` frame of the memory mapped
162 counter and timer in the system level implementation of the generic timer.
163
164* ** #define : BL2_BASE **
165
166 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
167
168* ** #define : BL31_BASE **
169
170 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
171 image.
172
173
174### Other mandatory modifications
175
176The following following mandatory modifications may be implemented in any file
177the implementer chooses. In the ARM FVP port, they are implemented in
178[../plat/fvp/aarch64/fvp_common.c].
179
180* ** Variable : unsigned char platform_normal_stacks[X][Y] **
181
182 where X = PLATFORM_STACK_SIZE
183 and Y = PLATFORM_CORE_COUNT
184
185 Each platform must allocate a block of memory with Normal Cacheable, Write
186 back, Write allocate and Inner Shareable attributes aligned to the size (in
187 bytes) of the largest cache line amongst all caches implemented in the
188 system. A pointer to this memory should be exported with the name
189 `platform_normal_stacks`. This pointer is used by the common platform helper
190 function `platform_set_stack()` to allocate a stack to each CPU in the
191 platform (see [../plat/common/aarch64/platform_helpers.S]).
192
193
1942.2 Common optional modifications
195---------------------------------
196
197The following are helper functions implemented by the firmware that perform
198common platform-specific tasks. A platform may choose to override these
199definitions.
200
201
202### Function : platform_get_core_pos()
203
204 Argument : unsigned long
205 Return : int
206
207A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
208can be used as a CPU-specific linear index into blocks of memory (for example
209while allocating per-CPU stacks). This routine contains a simple mechanism
210to perform this conversion, using the assumption that each cluster contains a
211maximum of 4 CPUs:
212
213 linear index = cpu_id + (cluster_id * 4)
214
215 cpu_id = 8-bit value in MPIDR at affinity level 0
216 cluster_id = 8-bit value in MPIDR at affinity level 1
217
218
219### Function : platform_set_coherent_stack()
220
221 Argument : unsigned long
222 Return : void
223
224A platform may need stack memory that is coherent with main memory to perform
225certain operations like:
226
227* Turning the MMU on, or
228* Flushing caches prior to powering down a CPU or cluster.
229
230Each BL stage allocates this coherent stack memory for each CPU in the
231`tzfw_coherent_mem` section. A pointer to this memory (`pcpu_dv_mem_stack`) is
232used by this function to allocate a coherent stack for each CPU. A CPU is
233identified by its `MPIDR`, which is passed as an argument to this function.
234
235The size of the stack allocated to each CPU is specified by the constant
236`PCPU_DV_MEM_STACK_SIZE`.
237
238
239### Function : platform_is_primary_cpu()
240
241 Argument : unsigned long
242 Return : unsigned int
243
244This function identifies a CPU by its `MPIDR`, which is passed as the argument,
245to determine whether this CPU is the primary CPU or a secondary CPU. A return
246value of zero indicates that the CPU is not the primary CPU, while a non-zero
247return value indicates that the CPU is the primary CPU.
248
249
250### Function : platform_set_stack()
251
252 Argument : unsigned long
253 Return : void
254
255This function uses the `platform_normal_stacks` pointer variable to allocate
256stacks to each CPU. Further details are given in the description of the
257`platform_normal_stacks` variable below. A CPU is identified by its `MPIDR`,
258which is passed as the argument.
259
260The size of the stack allocated to each CPU is specified by the platform defined
261constant `PLATFORM_STACK_SIZE`.
262
263
264### Function : plat_report_exception()
265
266 Argument : unsigned int
267 Return : void
268
269A platform may need to report various information about its status when an
270exception is taken, for example the current exception level, the CPU security
271state (secure/non-secure), the exception type, and so on. This function is
272called in the following circumstances:
273
274* In BL1, whenever an exception is taken.
275* In BL2, whenever an exception is taken.
276* In BL3-1, whenever an asynchronous exception or a synchronous exception
277 other than an SMC32/SMC64 exception is taken.
278
279The default implementation doesn't do anything, to avoid making assumptions
280about the way the platform displays its status information.
281
282This function receives the exception type as its argument. Possible values for
283exceptions types are listed in the [../include/runtime_svc.h] header file. Note
284that these constants are not related to any architectural exception code; they
285are just an ARM Trusted Firmware convention.
286
287
2883. Modifications specific to a Boot Loader stage
289-------------------------------------------------
290
2913.1 Boot Loader Stage 1 (BL1)
292-----------------------------
293
294BL1 implements the reset vector where execution starts from after a cold or
295warm boot. For each CPU, BL1 is responsible for the following tasks:
296
2971. Distinguishing between a cold boot and a warm boot.
298
2992. In the case of a cold boot and the CPU being the primary CPU, ensuring that
300 only this CPU executes the remaining BL1 code, including loading and passing
301 control to the BL2 stage.
302
3033. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
304 the CPU is placed in a platform-specific state until the primary CPU
305 performs the necessary steps to remove it from this state.
306
3074. In the case of a warm boot, ensuring that the CPU jumps to a platform-
308 specific address in the BL3-1 image in the same processor mode as it was
309 when released from reset.
310
3115. Loading the BL2 image in secure memory using semi-hosting at the
312 address specified by the platform defined constant `BL2_BASE`.
313
3146. Populating a `meminfo` structure with the following information in memory,
315 accessible by BL2 immediately upon entry.
316
317 meminfo.total_base = Base address of secure RAM visible to BL2
318 meminfo.total_size = Size of secure RAM visible to BL2
319 meminfo.free_base = Base address of secure RAM available for
320 allocation to BL2
321 meminfo.free_size = Size of secure RAM available for allocation to BL2
322
323 BL1 places this `meminfo` structure at the beginning of the free memory
324 available for its use. Since BL1 cannot allocate memory dynamically at the
325 moment, its free memory will be available for BL2's use as-is. However, this
326 means that BL2 must read the `meminfo` structure before it starts using its
327 free memory (this is discussed in Section 3.2).
328
329 In future releases of the ARM Trusted Firmware it will be possible for
330 the platform to decide where it wants to place the `meminfo` structure for
331 BL2.
332
333 BL1 implements the `init_bl2_mem_layout()` function to populate the
334 BL2 `meminfo` structure. The platform may override this implementation, for
335 example if the platform wants to restrict the amount of memory visible to
336 BL2. Details of how to do this are given below.
337
338The following functions need to be implemented by the platform port to enable
339BL1 to perform the above tasks.
340
341
342### Function : platform_get_entrypoint() [mandatory]
343
344 Argument : unsigned long
345 Return : unsigned int
346
347This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
348is identified by its `MPIDR`, which is passed as the argument. The function is
349responsible for distinguishing between a warm and cold reset using platform-
350specific means. If it's a warm reset then it returns the entrypoint into the
351BL3-1 image that the CPU must jump to. If it's a cold reset then this function
352must return zero.
353
354This function is also responsible for implementing a platform-specific mechanism
355to handle the condition where the CPU has been warm reset but there is no
356entrypoint to jump to.
357
358This function does not follow the Procedure Call Standard used by the
359Application Binary Interface for the ARM 64-bit architecture. The caller should
360not assume that callee saved registers are preserved across a call to this
361function.
362
363This function fulfills requirement 1 listed above.
364
365
366### Function : plat_secondary_cold_boot_setup() [mandatory]
367
368 Argument : void
369 Return : void
370
371This function is called with the MMU and data caches disabled. It is responsible
372for placing the executing secondary CPU in a platform-specific state until the
373primary CPU performs the necessary actions to bring it out of that state and
374allow entry into the OS.
375
376In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
377responsible for powering up the secondary CPU when normal world software
378requires them.
379
380This function fulfills requirement 3 above.
381
382
383### Function : platform_cold_boot_init() [mandatory]
384
385 Argument : unsigned long
386 Return : unsigned int
387
388This function executes with the MMU and data caches disabled. It is only called
389by the primary CPU. The argument to this function is the address of the
390`bl1_main()` routine where the generic BL1-specific actions are performed.
391This function performs any platform-specific and architectural setup that the
392platform requires to make execution of `bl1_main()` possible.
393
394The platform must enable the MMU with identity mapped page tables and enable
395caches by setting the `SCTLR.I` and `SCTLR.C` bits.
396
397Platform-specific setup might include configuration of memory controllers,
398configuration of the interconnect to allow the cluster to service cache snoop
399requests from another cluster, zeroing of the ZI section, and so on.
400
401In the ARM FVP port, this function enables CCI snoops into the cluster that the
402primary CPU is part of. It also enables the MMU and initializes the ZI section
403in the BL1 image through the use of linker defined symbols.
404
405This function helps fulfill requirement 2 above.
406
407
408### Function : bl1_platform_setup() [mandatory]
409
410 Argument : void
411 Return : void
412
413This function executes with the MMU and data caches enabled. It is responsible
414for performing any remaining platform-specific setup that can occur after the
415MMU and data cache have been enabled.
416
417In the ARM FVP port, it zeros out the ZI section, enables the system level
418implementation of the generic timer counter and initializes the console.
419
420This function helps fulfill requirement 5 above.
421
422
423### Function : bl1_get_sec_mem_layout() [mandatory]
424
425 Argument : void
426 Return : meminfo
427
428This function executes with the MMU and data caches enabled. The `meminfo`
429structure returned by this function must contain the extents and availability of
430secure RAM for the BL1 stage.
431
432 meminfo.total_base = Base address of secure RAM visible to BL1
433 meminfo.total_size = Size of secure RAM visible to BL1
434 meminfo.free_base = Base address of secure RAM available for allocation
435 to BL1
436 meminfo.free_size = Size of secure RAM available for allocation to BL1
437
438This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
439populates a similar structure to tell BL2 the extents of memory available for
440its own use.
441
442This function helps fulfill requirement 5 above.
443
444
445### Function : init_bl2_mem_layout() [optional]
446
447 Argument : meminfo *, meminfo *, unsigned int, unsigned long
448 Return : void
449
450Each BL stage needs to tell the next stage the amount of secure RAM available
451for it to use. For example, as part of handing control to BL2, BL1 informs BL2
452of the extents of secure RAM available for BL2 to use. BL2 must do the same when
453passing control to BL3-1. This information is populated in a `meminfo`
454structure.
455
456Depending upon where BL2 has been loaded in secure RAM (determined by
457`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
458BL1 also ensures that its data sections resident in secure RAM are not visible
459to BL2. An illustration of how this is done in the ARM FVP port is given in the
460[User Guide], in the Section "Memory layout on Base FVP".
461
462
4633.2 Boot Loader Stage 2 (BL2)
464-----------------------------
465
466The BL2 stage is executed only by the primary CPU, which is determined in BL1
467using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
468`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
469
4701. Loading the BL3-1 binary image in secure RAM using semi-hosting. To load the
471 BL3-1 image, BL2 makes use of the `meminfo` structure passed to it by BL1.
472 This structure allows BL2 to calculate how much secure RAM is available for
473 its use. The platform also defines the address in secure RAM where BL3-1 is
474 loaded through the constant `BL31_BASE`. BL2 uses this information to
475 determine if there is enough memory to load the BL3-1 image.
476
4772. Arranging to pass control to a normal world BL image that has been
478 pre-loaded at a platform-specific address. This address is determined using
479 the `plat_get_ns_image_entrypoint()` function described below.
480
481 BL2 populates an `el_change_info` structure in memory provided by the
482 platform with information about how BL3-1 should pass control to the normal
483 world BL image.
484
4853. Populating a `meminfo` structure with the following information in
486 memory that is accessible by BL3-1 immediately upon entry.
487
488 meminfo.total_base = Base address of secure RAM visible to BL3-1
489 meminfo.total_size = Size of secure RAM visible to BL3-1
490 meminfo.free_base = Base address of secure RAM available for allocation
491 to BL3-1
492 meminfo.free_size = Size of secure RAM available for allocation to
493 BL3-1
494
495 BL2 places this `meminfo` structure in memory provided by the
496 platform (`bl2_el_change_mem_ptr`). BL2 implements the
497 `init_bl31_mem_layout()` function to populate the BL3-1 meminfo structure
498 described above. The platform may override this implementation, for example
499 if the platform wants to restrict the amount of memory visible to BL3-1.
500 Details of this function are given below.
501
502The following functions must be implemented by the platform port to enable BL2
503to perform the above tasks.
504
505
506### Function : bl2_early_platform_setup() [mandatory]
507
508 Argument : meminfo *, void *
509 Return : void
510
511This function executes with the MMU and data caches disabled. It is only called
512by the primary CPU. The arguments to this function are:
513
514* The address of the `meminfo` structure populated by BL1
515* An opaque pointer that the platform may use as needed.
516
517The platform must copy the contents of the `meminfo` structure into a private
518variable as the original memory may be subsequently overwritten by BL2. The
519copied structure is made available to all BL2 code through the
520`bl2_get_sec_mem_layout()` function.
521
522
523### Function : bl2_plat_arch_setup() [mandatory]
524
525 Argument : void
526 Return : void
527
528This function executes with the MMU and data caches disabled. It is only called
529by the primary CPU.
530
531The purpose of this function is to perform any architectural initialization
532that varies across platforms, for example enabling the MMU (since the memory
533map differs across platforms).
534
535
536### Function : bl2_platform_setup() [mandatory]
537
538 Argument : void
539 Return : void
540
541This function may execute with the MMU and data caches enabled if the platform
542port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
543called by the primary CPU.
544
545The purpose of this function is to perform any platform initialization specific
546to BL2. This function must initialize a pointer to memory
547(`bl2_el_change_mem_ptr`), which can then be used to populate an
548`el_change_info` structure. The underlying requirement is that the platform must
549initialize this pointer before the `get_el_change_mem_ptr()` function
550accesses it in `bl2_main()`.
551
552The ARM FVP port initializes this pointer to the base address of Secure DRAM
553(`0x06000000`).
554
555
556### Variable : unsigned char bl2_el_change_mem_ptr[EL_CHANGE_MEM_SIZE] [mandatory]
557
558As mentioned in the description of `bl2_platform_setup()`, this pointer is
559initialized by the platform to point to memory where an `el_change_info`
560structure can be populated.
561
562
563### Function : bl2_get_sec_mem_layout() [mandatory]
564
565 Argument : void
566 Return : meminfo
567
568This function may execute with the MMU and data caches enabled if the platform
569port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
570called by the primary CPU.
571
572The purpose of this function is to return a `meminfo` structure populated with
573the extents of secure RAM available for BL2 to use. See
574`bl2_early_platform_setup()` above.
575
576
577### Function : init_bl31_mem_layout() [optional]
578
579 Argument : meminfo *, meminfo *, unsigned int
580 Return : void
581
582Each BL stage needs to tell the next stage the amount of secure RAM that is
583available for it to use. For example, as part of handing control to BL2, BL1
584must inform BL2 about the extents of secure RAM that is available for BL2 to
585use. BL2 must do the same when passing control to BL3-1. This information is
586populated in a `meminfo` structure.
587
588Depending upon where BL3-1 has been loaded in secure RAM (determined by
589`BL31_BASE`), BL2 calculates the amount of free memory available for BL3-1 to
590use. BL2 also ensures that BL3-1 is able reclaim memory occupied by BL2. This
591is done because BL2 never executes again after passing control to BL3-1.
592An illustration of how this is done in the ARM FVP port is given in the
593[User Guide], in the section "Memory layout on Base FVP".
594
595
596### Function : plat_get_ns_image_entrypoint() [mandatory]
597
598 Argument : void
599 Return : unsigned long
600
601As previously described, BL2 is responsible for arranging for control to be
602passed to a normal world BL image through BL3-1. This function returns the
603entrypoint of that image, which BL3-1 uses to jump to it.
604
605The ARM FVP port assumes that flash memory has been pre-loaded with the UEFI
606image, and so returns the base address of flash memory.
607
608
6093.2 Boot Loader Stage 3-1 (BL3-1)
610---------------------------------
611
612During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
613determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
614control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
615CPUs. BL3-1 executes at EL3 and is responsible for:
616
6171. Re-initializing all architectural and platform state. Although BL1 performs
618 some of this initialization, BL3-1 remains resident in EL3 and must ensure
619 that EL3 architectural and platform state is completely initialized. It
620 should make no assumptions about the system state when it receives control.
621
6222. Passing control to a normal world BL image, pre-loaded at a platform-
623 specific address by BL2. BL3-1 uses the `el_change_info` structure that BL2
624 populated in memory to do this.
625
6263. Providing runtime firmware services. Currently, BL3-1 only implements a
627 subset of the Power State Coordination Interface (PSCI) API as a runtime
628 service. See Section 3.3 below for details of porting the PSCI
629 implementation.
630
631The following functions must be implemented by the platform port to enable BL3-1
632to perform the above tasks.
633
634
635### Function : bl31_early_platform_setup() [mandatory]
636
637 Argument : meminfo *, void *, unsigned long
638 Return : void
639
640This function executes with the MMU and data caches disabled. It is only called
641by the primary CPU. The arguments to this function are:
642
643* The address of the `meminfo` structure populated by BL2.
644* An opaque pointer that the platform may use as needed.
645* The `MPIDR` of the primary CPU.
646
647The platform must copy the contents of the `meminfo` structure into a private
648variable as the original memory may be subsequently overwritten by BL3-1. The
649copied structure is made available to all BL3-1 code through the
650`bl31_get_sec_mem_layout()` function.
651
652
653### Function : bl31_plat_arch_setup() [mandatory]
654
655 Argument : void
656 Return : void
657
658This function executes with the MMU and data caches disabled. It is only called
659by the primary CPU.
660
661The purpose of this function is to perform any architectural initialization
662that varies across platforms, for example enabling the MMU (since the memory
663map differs across platforms).
664
665
666### Function : bl31_platform_setup() [mandatory]
667
668 Argument : void
669 Return : void
670
671This function may execute with the MMU and data caches enabled if the platform
672port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
673called by the primary CPU.
674
675The purpose of this function is to complete platform initialization so that both
676BL3-1 runtime services and normal world software can function correctly.
677
678The ARM FVP port does the following:
679* Initializes the generic interrupt controller.
680* Configures the CLCD controller.
681* Grants access to the system counter timer module
682* Initializes the FVP power controller device
683* Detects the system topology.
684
685
686### Function : bl31_get_next_image_info() [mandatory]
687
688 Argument : unsigned long
689 Return : el_change_info *
690
691This function may execute with the MMU and data caches enabled if the platform
692port does the necessary initializations in `bl31_plat_arch_setup()`.
693
694This function is called by `bl31_main()` to retrieve information provided by
695BL2, so that BL3-1 can pass control to the normal world software image. This
696function must return a pointer to the `el_change_info` structure (that was
697copied during `bl31_early_platform_setup()`).
698
699
700### Function : bl31_get_sec_mem_layout() [mandatory]
701
702 Argument : void
703 Return : meminfo
704
705This function may execute with the MMU and data caches enabled if the platform
706port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
707called by the primary CPU.
708
709The purpose of this function is to return a `meminfo` structure populated with
710the extents of secure RAM available for BL3-1 to use. See
711`bl31_early_platform_setup()` above.
712
713
7143.3 Power State Coordination Interface (in BL3-1)
715------------------------------------------------
716
717The ARM Trusted Firmware's implementation of the PSCI API is based around the
718concept of an _affinity instance_. Each _affinity instance_ can be uniquely
719identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
720interface) and an _affinity level_. A processing element (for example, a
721CPU) is at level 0. If the CPUs in the system are described in a tree where the
722node above a CPU is a logical grouping of CPUs that share some state, then
723affinity level 1 is that group of CPUs (for example, a cluster), and affinity
724level 2 is a group of clusters (for example, the system). The implementation
725assumes that the affinity level 1 ID can be computed from the affinity level 0
726ID (for example, a unique cluster ID can be computed from the CPU ID). The
727current implementation computes this on the basis of the recommended use of
728`MPIDR` affinity fields in the ARM Architecture Reference Manual.
729
730BL3-1's platform initialization code exports a pointer to the platform-specific
731power management operations required for the PSCI implementation to function
732correctly. This information is populated in the `plat_pm_ops` structure. The
733PSCI implementation calls members of the `plat_pm_ops` structure for performing
734power management operations for each affinity instance. For example, the target
735CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
736handler (if present) is called for each affinity instance as the PSCI
737implementation powers up each affinity level implemented in the `MPIDR` (for
738example, CPU, cluster and system).
739
740The following functions must be implemented to initialize PSCI functionality in
741the ARM Trusted Firmware.
742
743
744### Function : plat_get_aff_count() [mandatory]
745
746 Argument : unsigned int, unsigned long
747 Return : unsigned int
748
749This function may execute with the MMU and data caches enabled if the platform
750port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
751called by the primary CPU.
752
753This function is called by the PSCI initialization code to detect the system
754topology. Its purpose is to return the number of affinity instances implemented
755at a given `affinity level` (specified by the first argument) and a given
756`MPIDR` (specified by the second argument). For example, on a dual-cluster
757system where first cluster implements 2 CPUs and the second cluster implements 4
758CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
759(`0x0`) and affinity level 0, would return 2. A call to this function with an
760`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
761would return 4.
762
763
764### Function : plat_get_aff_state() [mandatory]
765
766 Argument : unsigned int, unsigned long
767 Return : unsigned int
768
769This function may execute with the MMU and data caches enabled if the platform
770port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
771called by the primary CPU.
772
773This function is called by the PSCI initialization code. Its purpose is to
774return the state of an affinity instance. The affinity instance is determined by
775the affinity ID at a given `affinity level` (specified by the first argument)
776and an `MPIDR` (specified by the second argument). The state can be one of
777`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
778system topologies where certain affinity instances are unimplemented. For
779example, consider a platform that implements a single cluster with 4 CPUs and
780another CPU implemented directly on the interconnect with the cluster. The
781`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
782CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
783is missing but needs to be accounted for to reach this single CPU in the
784topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
785
786
787### Function : plat_get_max_afflvl() [mandatory]
788
789 Argument : void
790 Return : int
791
792This function may execute with the MMU and data caches enabled if the platform
793port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
794called by the primary CPU.
795
796This function is called by the PSCI implementation both during cold and warm
797boot, to determine the maximum affinity level that the power management
798operations should apply to. ARMv8 has support for 4 affinity levels. It is
799likely that hardware will implement fewer affinity levels. This function allows
800the PSCI implementation to consider only those affinity levels in the system
801that the platform implements. For example, the Base AEM FVP implements two
802clusters with a configurable number of CPUs. It reports the maximum affinity
803level as 1, resulting in PSCI power control up to the cluster level.
804
805
806### Function : platform_setup_pm() [mandatory]
807
808 Argument : plat_pm_ops **
809 Return : int
810
811This function may execute with the MMU and data caches enabled if the platform
812port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
813called by the primary CPU.
814
815This function is called by PSCI initialization code. Its purpose is to export
816handler routines for platform-specific power management actions by populating
817the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
818
819A description of each member of this structure is given below. Please refer to
820the ARM FVP specific implementation of these handlers in [../plat/fvp/fvp_pm.c]
821as an example. A platform port may choose not implement some of the power
822management operations. For example, the ARM FVP port does not implement the
823`affinst_standby()` function.
824
825#### plat_pm_ops.affinst_standby()
826
827Perform the platform-specific setup to enter the standby state indicated by the
828passed argument.
829
830#### plat_pm_ops.affinst_on()
831
832Perform the platform specific setup to power on an affinity instance, specified
833by the `MPIDR` (first argument) and `affinity level` (fourth argument). The
834`state` (fifth argument) contains the current state of that affinity instance
835(ON or OFF). This is useful to determine whether any action must be taken. For
836example, while powering on a CPU, the cluster that contains this CPU might
837already be in the ON state. The platform decides what actions must be taken to
838transition from the current state to the target state (indicated by the power
839management operation).
840
841#### plat_pm_ops.affinst_off()
842
843Perform the platform specific setup to power off an affinity instance in the
844`MPIDR` of the calling CPU. It is called by the PSCI `CPU_OFF` API
845implementation.
846
847The `MPIDR` (first argument), `affinity level` (second argument) and `state`
848(third argument) have a similar meaning as described in the `affinst_on()`
849operation. They are used to identify the affinity instance on which the call
850is made and its current state. This gives the platform port an indication of the
851state transition it must make to perform the requested action. For example, if
852the calling CPU is the last powered on CPU in the cluster, after powering down
853affinity level 0 (CPU), the platform port should power down affinity level 1
854(the cluster) as well.
855
856This function is called with coherent stacks. This allows the PSCI
857implementation to flush caches at a given affinity level without running into
858stale stack state after turning off the caches. On ARMv8 cache hits do not occur
859after the cache has been turned off.
860
861#### plat_pm_ops.affinst_suspend()
862
863Perform the platform specific setup to power off an affinity instance in the
864`MPIDR` of the calling CPU. It is called by the PSCI `CPU_SUSPEND` API
865implementation.
866
867The `MPIDR` (first argument), `affinity level` (third argument) and `state`
868(fifth argument) have a similar meaning as described in the `affinst_on()`
869operation. They are used to identify the affinity instance on which the call
870is made and its current state. This gives the platform port an indication of the
871state transition it must make to perform the requested action. For example, if
872the calling CPU is the last powered on CPU in the cluster, after powering down
873affinity level 0 (CPU), the platform port should power down affinity level 1
874(the cluster) as well.
875
876The difference between turning an affinity instance off versus suspending it
877is that in the former case, the affinity instance is expected to re-initialize
878its state when its next powered on (see `affinst_on_finish()`). In the latter
879case, the affinity instance is expected to save enough state so that it can
880resume execution by restoring this state when its powered on (see
881`affinst_suspend_finish()`).
882
883This function is called with coherent stacks. This allows the PSCI
884implementation to flush caches at a given affinity level without running into
885stale stack state after turning off the caches. On ARMv8 cache hits do not occur
886after the cache has been turned off.
887
888#### plat_pm_ops.affinst_on_finish()
889
890This function is called by the PSCI implementation after the calling CPU is
891powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
892It performs the platform-specific setup required to initialize enough state for
893this CPU to enter the normal world and also provide secure runtime firmware
894services.
895
896The `MPIDR` (first argument), `affinity level` (second argument) and `state`
897(third argument) have a similar meaning as described in the previous operations.
898
899This function is called with coherent stacks. This allows the PSCI
900implementation to flush caches at a given affinity level without running into
901stale stack state after turning off the caches. On ARMv8 cache hits do not occur
902after the cache has been turned off.
903
904#### plat_pm_ops.affinst_on_suspend()
905
906This function is called by the PSCI implementation after the calling CPU is
907powered on and released from reset in response to an asynchronous wakeup
908event, for example a timer interrupt that was programmed by the CPU during the
909`CPU_SUSPEND` call. It performs the platform-specific setup required to
910restore the saved state for this CPU to resume execution in the normal world
911and also provide secure runtime firmware services.
912
913The `MPIDR` (first argument), `affinity level` (second argument) and `state`
914(third argument) have a similar meaning as described in the previous operations.
915
916This function is called with coherent stacks. This allows the PSCI
917implementation to flush caches at a given affinity level without running into
918stale stack state after turning off the caches. On ARMv8 cache hits do not occur
919after the cache has been turned off.
920
921BL3-1 platform initialization code must also detect the system topology and
922the state of each affinity instance in the topology. This information is
923critical for the PSCI runtime service to function correctly. More details are
924provided in the description of the `plat_get_aff_count()` and
925`plat_get_aff_state()` functions above.
926
927
928- - - - - - - - - - - - - - - - - - - - - - - - - -
929
930_Copyright (c) 2013 ARM Ltd. All rights reserved._
931
932
933[User Guide]: user-guide.md
934
935[../plat/common/aarch64/platform_helpers.S]: ../plat/common/aarch64/platform_helpers.S
936[../plat/fvp/platform.h]: ../plat/fvp/platform.h
937[../plat/fvp/aarch64/fvp_common.c]: ../plat/fvp/aarch64/fvp_common.c
938[../plat/fvp/fvp_pm.c]: ../plat/fvp/fvp_pm.c
939[../include/runtime_svc.h]: ../include/runtime_svc.h