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