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