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