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 |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 10 | * Handling reset |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 11 | * Common optional modifications |
| 12 | 3. Boot Loader stage specific modifications |
| 13 | * Boot Loader stage 1 (BL1) |
| 14 | * Boot Loader stage 2 (BL2) |
| 15 | * Boot Loader stage 3-1 (BL3-1) |
| 16 | * PSCI implementation (in BL3-1) |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 17 | * Interrupt Management framework (in BL3-1) |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame^] | 18 | * Crash Reporting mechanism (in BL3-1) |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 19 | 4. C Library |
| 20 | 5. Storage abstraction layer |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 21 | |
| 22 | - - - - - - - - - - - - - - - - - - |
| 23 | |
| 24 | 1. Introduction |
| 25 | ---------------- |
| 26 | |
| 27 | Porting the ARM Trusted Firmware to a new platform involves making some |
| 28 | mandatory and optional modifications for both the cold and warm boot paths. |
| 29 | Modifications consist of: |
| 30 | |
| 31 | * Implementing a platform-specific function or variable, |
| 32 | * Setting up the execution context in a certain way, or |
| 33 | * Defining certain constants (for example #defines). |
| 34 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 35 | The platform-specific functions and variables are all declared in |
| 36 | [include/plat/common/platform.h]. The firmware provides a default implementation |
| 37 | of variables and functions to fulfill the optional requirements. These |
| 38 | implementations are all weakly defined; they are provided to ease the porting |
| 39 | effort. Each platform port can override them with its own implementation if the |
| 40 | default implementation is inadequate. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | |
| 42 | Some modifications are common to all Boot Loader (BL) stages. Section 2 |
| 43 | discusses these in detail. The subsequent sections discuss the remaining |
| 44 | modifications for each BL stage in detail. |
| 45 | |
| 46 | This document should be read in conjunction with the ARM Trusted Firmware |
| 47 | [User Guide]. |
| 48 | |
| 49 | |
| 50 | 2. Common modifications |
| 51 | ------------------------ |
| 52 | |
| 53 | This section covers the modifications that should be made by the platform for |
| 54 | each BL stage to correctly port the firmware stack. They are categorized as |
| 55 | either mandatory or optional. |
| 56 | |
| 57 | |
| 58 | 2.1 Common mandatory modifications |
| 59 | ---------------------------------- |
| 60 | A platform port must enable the Memory Management Unit (MMU) with identity |
| 61 | mapped page tables, and enable both the instruction and data caches for each BL |
| 62 | stage. In the ARM FVP port, each BL stage configures the MMU in its platform- |
| 63 | specific architecture setup function, for example `blX_plat_arch_setup()`. |
| 64 | |
| 65 | Each platform must allocate a block of identity mapped secure memory with |
| 66 | Device-nGnRE attributes aligned to page boundary (4K) for each BL stage. This |
| 67 | memory is identified by the section name `tzfw_coherent_mem` so that its |
| 68 | possible for the firmware to place variables in it using the following C code |
| 69 | directive: |
| 70 | |
| 71 | __attribute__ ((section("tzfw_coherent_mem"))) |
| 72 | |
| 73 | Or alternatively the following assembler code directive: |
| 74 | |
| 75 | .section tzfw_coherent_mem |
| 76 | |
| 77 | The `tzfw_coherent_mem` section is used to allocate any data structures that are |
| 78 | accessed both when a CPU is executing with its MMU and caches enabled, and when |
| 79 | it's running with its MMU and caches disabled. Examples are given below. |
| 80 | |
| 81 | The following variables, functions and constants must be defined by the platform |
| 82 | for the firmware to work correctly. |
| 83 | |
| 84 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 85 | ### File : platform_def.h [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 86 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 87 | Each platform must ensure that a header file of this name is in the system |
| 88 | include path with the following constants defined. This may require updating the |
| 89 | list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM FVP port, this |
| 90 | file is found in [plat/fvp/include/platform_def.h]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 91 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 92 | * **#define : PLATFORM_LINKER_FORMAT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 93 | |
| 94 | Defines the linker format used by the platform, for example |
| 95 | `elf64-littleaarch64` used by the FVP. |
| 96 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 97 | * **#define : PLATFORM_LINKER_ARCH** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 98 | |
| 99 | Defines the processor architecture for the linker by the platform, for |
| 100 | example `aarch64` used by the FVP. |
| 101 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 102 | * **#define : PLATFORM_STACK_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | |
| 104 | Defines the normal stack memory available to each CPU. This constant is used |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 105 | by [plat/common/aarch64/platform_mp_stack.S] and |
| 106 | [plat/common/aarch64/platform_up_stack.S]. |
| 107 | |
| 108 | * **#define : PCPU_DV_MEM_STACK_SIZE** |
| 109 | |
| 110 | Defines the coherent stack memory available to each CPU. This constant is used |
| 111 | by [plat/common/aarch64/platform_mp_stack.S] and |
| 112 | [plat/common/aarch64/platform_up_stack.S]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 113 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 114 | * **#define : FIRMWARE_WELCOME_STR** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 115 | |
| 116 | Defines the character string printed by BL1 upon entry into the `bl1_main()` |
| 117 | function. |
| 118 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 119 | * **#define : BL2_IMAGE_NAME** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 120 | |
| 121 | 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] | 122 | BL1 to load BL2 into secure memory from non-volatile storage. |
| 123 | |
| 124 | * **#define : BL31_IMAGE_NAME** |
| 125 | |
| 126 | Name of the BL3-1 binary image on the host file-system. This name is used by |
| 127 | BL2 to load BL3-1 into secure memory from platform storage. |
| 128 | |
| 129 | * **#define : BL33_IMAGE_NAME** |
| 130 | |
| 131 | Name of the BL3-3 binary image on the host file-system. This name is used by |
| 132 | BL2 to load BL3-3 into non-secure memory from platform storage. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 133 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 134 | * **#define : PLATFORM_CACHE_LINE_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 135 | |
| 136 | Defines the size (in bytes) of the largest cache line across all the cache |
| 137 | levels in the platform. |
| 138 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 139 | * **#define : PLATFORM_CLUSTER_COUNT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 140 | |
| 141 | Defines the total number of clusters implemented by the platform in the |
| 142 | system. |
| 143 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 144 | * **#define : PLATFORM_CORE_COUNT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 145 | |
| 146 | Defines the total number of CPUs implemented by the platform across all |
| 147 | clusters in the system. |
| 148 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 149 | * **#define : PLATFORM_MAX_CPUS_PER_CLUSTER** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 150 | |
| 151 | Defines the maximum number of CPUs that can be implemented within a cluster |
| 152 | on the platform. |
| 153 | |
Andrew Thoelke | 6c0b45d | 2014-06-20 00:36:14 +0100 | [diff] [blame] | 154 | * **#define : PLATFORM_NUM_AFFS** |
| 155 | |
| 156 | Defines the total number of nodes in the affinity heirarchy at all affinity |
| 157 | levels used by the platform. |
| 158 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 159 | * **#define : PRIMARY_CPU** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 160 | |
| 161 | Defines the `MPIDR` of the primary CPU on the platform. This value is used |
| 162 | after a cold boot to distinguish between primary and secondary CPUs. |
| 163 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 164 | * **#define : TZROM_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 165 | |
| 166 | Defines the base address of secure ROM on the platform, where the BL1 binary |
| 167 | is loaded. This constant is used by the linker scripts to ensure that the |
| 168 | BL1 image fits into the available memory. |
| 169 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 170 | * **#define : TZROM_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 171 | |
| 172 | Defines the size of secure ROM on the platform. This constant is used by the |
| 173 | linker scripts to ensure that the BL1 image fits into the available memory. |
| 174 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 175 | * **#define : TZRAM_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 176 | |
| 177 | Defines the base address of the secure RAM on platform, where the data |
| 178 | section of the BL1 binary is loaded. The BL2 and BL3-1 images are also |
| 179 | loaded in this secure RAM region. This constant is used by the linker |
| 180 | scripts to ensure that the BL1 data section and BL2/BL3-1 binary images fit |
| 181 | into the available memory. |
| 182 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 183 | * **#define : TZRAM_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 184 | |
| 185 | Defines the size of the secure RAM on the platform. This constant is used by |
| 186 | the linker scripts to ensure that the BL1 data section and BL2/BL3-1 binary |
| 187 | images fit into the available memory. |
| 188 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 189 | * **#define : BL1_RO_BASE** |
| 190 | |
| 191 | Defines the base address in secure ROM where BL1 originally lives. Must be |
| 192 | aligned on a page-size boundary. |
| 193 | |
| 194 | * **#define : BL1_RO_LIMIT** |
| 195 | |
| 196 | Defines the maximum address in secure ROM that BL1's actual content (i.e. |
| 197 | excluding any data section allocated at runtime) can occupy. |
| 198 | |
| 199 | * **#define : BL1_RW_BASE** |
| 200 | |
| 201 | Defines the base address in secure RAM where BL1's read-write data will live |
| 202 | at runtime. Must be aligned on a page-size boundary. |
| 203 | |
| 204 | * **#define : BL1_RW_LIMIT** |
| 205 | |
| 206 | Defines the maximum address in secure RAM that BL1's read-write data can |
| 207 | occupy at runtime. |
| 208 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 209 | * **#define : BL2_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 210 | |
| 211 | 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] | 212 | Must be aligned on a page-size boundary. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 213 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 214 | * **#define : BL2_LIMIT** |
| 215 | |
| 216 | Defines the maximum address in secure RAM that the BL2 image can occupy. |
| 217 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 218 | * **#define : BL31_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 219 | |
| 220 | 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] | 221 | image. Must be aligned on a page-size boundary. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 222 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 223 | * **#define : BL31_LIMIT** |
| 224 | |
| 225 | Defines the maximum address in secure RAM that the BL3-1 image can occupy. |
| 226 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 227 | * **#define : NS_IMAGE_OFFSET** |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 228 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 229 | Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary |
| 230 | image. Must be aligned on a page-size boundary. |
| 231 | |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 232 | If the BL3-2 image is supported by the platform, the following constants must |
| 233 | be defined as well: |
| 234 | |
| 235 | * **#define : TSP_SEC_MEM_BASE** |
| 236 | |
| 237 | Defines the base address of the secure memory used by the BL3-2 image on the |
| 238 | platform. |
| 239 | |
| 240 | * **#define : TSP_SEC_MEM_SIZE** |
| 241 | |
| 242 | Defines the size of the secure memory used by the BL3-2 image on the |
| 243 | platform. |
| 244 | |
| 245 | * **#define : BL32_BASE** |
| 246 | |
| 247 | Defines the base address in secure memory where BL2 loads the BL3-2 binary |
| 248 | image. Must be inside the secure memory identified by `TSP_SEC_MEM_BASE` and |
| 249 | `TSP_SEC_MEM_SIZE` constants. Must also be aligned on a page-size boundary. |
| 250 | |
| 251 | * **#define : BL32_LIMIT** |
| 252 | |
| 253 | Defines the maximum address that the BL3-2 image can occupy. Must be inside |
| 254 | the secure memory identified by `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` |
| 255 | constants. |
| 256 | |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 257 | The following constants are optional. They should be defined when the platform |
| 258 | memory layout implies some image overlaying like on FVP. |
| 259 | |
| 260 | * **#define : BL31_PROGBITS_LIMIT** |
| 261 | |
| 262 | Defines the maximum address in secure RAM that the BL3-1's progbits sections |
| 263 | can occupy. |
| 264 | |
| 265 | * **#define : BL32_PROGBITS_LIMIT** |
| 266 | |
| 267 | Defines the maximum address that the TSP's progbits sections can occupy. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 268 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 269 | ### File : plat_macros.S [mandatory] |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 270 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 271 | Each platform must ensure a file of this name is in the system include path with |
| 272 | the following macro defined. In the ARM FVP port, this file is found in |
| 273 | [plat/fvp/include/plat_macros.S]. |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 274 | |
| 275 | * **Macro : plat_print_gic_regs** |
| 276 | |
| 277 | This macro allows the crash reporting routine to print GIC registers |
| 278 | in case of an unhandled IRQ or FIQ in BL3-1. This aids in debugging and |
| 279 | this macro can be defined to be empty in case GIC register reporting is |
| 280 | not desired. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 281 | |
| 282 | ### Other mandatory modifications |
| 283 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 284 | The following mandatory modifications may be implemented in any file |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 285 | the implementer chooses. In the ARM FVP port, they are implemented in |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 286 | [plat/fvp/aarch64/plat_common.c]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 287 | |
Sandrine Bailleux | 9e86490 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 288 | * **Function : uint64_t plat_get_syscnt_freq(void)** |
| 289 | |
| 290 | This function is used by the architecture setup code to retrieve the |
| 291 | counter frequency for the CPU's generic timer. This value will be |
| 292 | programmed into the `CNTFRQ_EL0` register. |
| 293 | In the ARM FVP port, it returns the base frequency of the system counter, |
| 294 | which is retrieved from the first entry in the frequency modes table. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 295 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 296 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 297 | 2.2 Handling Reset |
| 298 | ------------------ |
| 299 | |
| 300 | BL1 by default implements the reset vector where execution starts from a cold |
| 301 | or warm boot. BL3-1 can be optionally set as a reset vector using the |
| 302 | RESET_TO_BL31 make variable. |
| 303 | |
| 304 | For each CPU, the reset vector code is responsible for the following tasks: |
| 305 | |
| 306 | 1. Distinguishing between a cold boot and a warm boot. |
| 307 | |
| 308 | 2. In the case of a cold boot and the CPU being a secondary CPU, ensuring that |
| 309 | the CPU is placed in a platform-specific state until the primary CPU |
| 310 | performs the necessary steps to remove it from this state. |
| 311 | |
| 312 | 3. In the case of a warm boot, ensuring that the CPU jumps to a platform- |
| 313 | specific address in the BL3-1 image in the same processor mode as it was |
| 314 | when released from reset. |
| 315 | |
| 316 | The following functions need to be implemented by the platform port to enable |
| 317 | reset vector code to perform the above tasks. |
| 318 | |
| 319 | |
| 320 | ### Function : platform_get_entrypoint() [mandatory] |
| 321 | |
| 322 | Argument : unsigned long |
| 323 | Return : unsigned int |
| 324 | |
| 325 | This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU |
| 326 | is identified by its `MPIDR`, which is passed as the argument. The function is |
| 327 | responsible for distinguishing between a warm and cold reset using platform- |
| 328 | specific means. If it's a warm reset then it returns the entrypoint into the |
| 329 | BL3-1 image that the CPU must jump to. If it's a cold reset then this function |
| 330 | must return zero. |
| 331 | |
| 332 | This function is also responsible for implementing a platform-specific mechanism |
| 333 | to handle the condition where the CPU has been warm reset but there is no |
| 334 | entrypoint to jump to. |
| 335 | |
| 336 | This function does not follow the Procedure Call Standard used by the |
| 337 | Application Binary Interface for the ARM 64-bit architecture. The caller should |
| 338 | not assume that callee saved registers are preserved across a call to this |
| 339 | function. |
| 340 | |
| 341 | This function fulfills requirement 1 and 3 listed above. |
| 342 | |
| 343 | |
| 344 | ### Function : plat_secondary_cold_boot_setup() [mandatory] |
| 345 | |
| 346 | Argument : void |
| 347 | Return : void |
| 348 | |
| 349 | This function is called with the MMU and data caches disabled. It is responsible |
| 350 | for placing the executing secondary CPU in a platform-specific state until the |
| 351 | primary CPU performs the necessary actions to bring it out of that state and |
| 352 | allow entry into the OS. |
| 353 | |
| 354 | In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is |
| 355 | responsible for powering up the secondary CPU when normal world software |
| 356 | requires them. |
| 357 | |
| 358 | This function fulfills requirement 2 above. |
| 359 | |
| 360 | |
| 361 | ### Function : platform_mem_init() [mandatory] |
| 362 | |
| 363 | Argument : void |
| 364 | Return : void |
| 365 | |
| 366 | This function is called before any access to data is made by the firmware, in |
| 367 | order to carry out any essential memory initialization. |
| 368 | |
| 369 | The ARM FVP port uses this function to initialize the mailbox memory used for |
| 370 | providing the warm-boot entry-point addresses. |
| 371 | |
| 372 | |
| 373 | |
| 374 | 2.3 Common optional modifications |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 375 | --------------------------------- |
| 376 | |
| 377 | The following are helper functions implemented by the firmware that perform |
| 378 | common platform-specific tasks. A platform may choose to override these |
| 379 | definitions. |
| 380 | |
| 381 | |
| 382 | ### Function : platform_get_core_pos() |
| 383 | |
| 384 | Argument : unsigned long |
| 385 | Return : int |
| 386 | |
| 387 | A platform may need to convert the `MPIDR` of a CPU to an absolute number, which |
| 388 | can be used as a CPU-specific linear index into blocks of memory (for example |
| 389 | while allocating per-CPU stacks). This routine contains a simple mechanism |
| 390 | to perform this conversion, using the assumption that each cluster contains a |
| 391 | maximum of 4 CPUs: |
| 392 | |
| 393 | linear index = cpu_id + (cluster_id * 4) |
| 394 | |
| 395 | cpu_id = 8-bit value in MPIDR at affinity level 0 |
| 396 | cluster_id = 8-bit value in MPIDR at affinity level 1 |
| 397 | |
| 398 | |
| 399 | ### Function : platform_set_coherent_stack() |
| 400 | |
| 401 | Argument : unsigned long |
| 402 | Return : void |
| 403 | |
| 404 | A platform may need stack memory that is coherent with main memory to perform |
| 405 | certain operations like: |
| 406 | |
| 407 | * Turning the MMU on, or |
| 408 | * Flushing caches prior to powering down a CPU or cluster. |
| 409 | |
| 410 | Each BL stage allocates this coherent stack memory for each CPU in the |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 411 | `tzfw_coherent_mem` section. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 412 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 413 | This function sets the current stack pointer to the coherent stack that |
| 414 | has been allocated for the CPU specified by MPIDR. For BL images that only |
| 415 | require a stack for the primary CPU the parameter is ignored. The size of |
| 416 | the stack allocated to each CPU is specified by the platform defined constant |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 417 | `PCPU_DV_MEM_STACK_SIZE`. |
| 418 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 419 | Common implementations of this function for the UP and MP BL images are |
| 420 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 421 | [plat/common/aarch64/platform_mp_stack.S] |
| 422 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 423 | |
| 424 | ### Function : platform_is_primary_cpu() |
| 425 | |
| 426 | Argument : unsigned long |
| 427 | Return : unsigned int |
| 428 | |
| 429 | This function identifies a CPU by its `MPIDR`, which is passed as the argument, |
| 430 | to determine whether this CPU is the primary CPU or a secondary CPU. A return |
| 431 | value of zero indicates that the CPU is not the primary CPU, while a non-zero |
| 432 | return value indicates that the CPU is the primary CPU. |
| 433 | |
| 434 | |
| 435 | ### Function : platform_set_stack() |
| 436 | |
| 437 | Argument : unsigned long |
| 438 | Return : void |
| 439 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 440 | This function sets the current stack pointer to the normal memory stack that |
| 441 | has been allocated for the CPU specificed by MPIDR. For BL images that only |
| 442 | require a stack for the primary CPU the parameter is ignored. The size of |
| 443 | the stack allocated to each CPU is specified by the platform defined constant |
| 444 | `PLATFORM_STACK_SIZE`. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 445 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 446 | Common implementations of this function for the UP and MP BL images are |
| 447 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 448 | [plat/common/aarch64/platform_mp_stack.S] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 449 | |
| 450 | |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 451 | ### Function : platform_get_stack() |
| 452 | |
| 453 | Argument : unsigned long |
| 454 | Return : unsigned long |
| 455 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 456 | This function returns the base address of the normal memory stack that |
| 457 | has been allocated for the CPU specificed by MPIDR. For BL images that only |
| 458 | require a stack for the primary CPU the parameter is ignored. The size of |
| 459 | the stack allocated to each CPU is specified by the platform defined constant |
| 460 | `PLATFORM_STACK_SIZE`. |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 461 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 462 | Common implementations of this function for the UP and MP BL images are |
| 463 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 464 | [plat/common/aarch64/platform_mp_stack.S] |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 465 | |
| 466 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 467 | ### Function : plat_report_exception() |
| 468 | |
| 469 | Argument : unsigned int |
| 470 | Return : void |
| 471 | |
| 472 | A platform may need to report various information about its status when an |
| 473 | exception is taken, for example the current exception level, the CPU security |
| 474 | state (secure/non-secure), the exception type, and so on. This function is |
| 475 | called in the following circumstances: |
| 476 | |
| 477 | * In BL1, whenever an exception is taken. |
| 478 | * In BL2, whenever an exception is taken. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 479 | |
| 480 | The default implementation doesn't do anything, to avoid making assumptions |
| 481 | about the way the platform displays its status information. |
| 482 | |
| 483 | This function receives the exception type as its argument. Possible values for |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 484 | exceptions types are listed in the [include/runtime_svc.h] header file. Note |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 485 | that these constants are not related to any architectural exception code; they |
| 486 | are just an ARM Trusted Firmware convention. |
| 487 | |
| 488 | |
| 489 | 3. Modifications specific to a Boot Loader stage |
| 490 | ------------------------------------------------- |
| 491 | |
| 492 | 3.1 Boot Loader Stage 1 (BL1) |
| 493 | ----------------------------- |
| 494 | |
| 495 | BL1 implements the reset vector where execution starts from after a cold or |
| 496 | warm boot. For each CPU, BL1 is responsible for the following tasks: |
| 497 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 498 | 1. Handling the reset as described in section 2.2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 499 | |
| 500 | 2. In the case of a cold boot and the CPU being the primary CPU, ensuring that |
| 501 | only this CPU executes the remaining BL1 code, including loading and passing |
| 502 | control to the BL2 stage. |
| 503 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 504 | 3. 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] | 505 | address specified by the platform defined constant `BL2_BASE`. |
| 506 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 507 | 4. Populating a `meminfo` structure with the following information in memory, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 508 | accessible by BL2 immediately upon entry. |
| 509 | |
| 510 | meminfo.total_base = Base address of secure RAM visible to BL2 |
| 511 | meminfo.total_size = Size of secure RAM visible to BL2 |
| 512 | meminfo.free_base = Base address of secure RAM available for |
| 513 | allocation to BL2 |
| 514 | meminfo.free_size = Size of secure RAM available for allocation to BL2 |
| 515 | |
| 516 | BL1 places this `meminfo` structure at the beginning of the free memory |
| 517 | available for its use. Since BL1 cannot allocate memory dynamically at the |
| 518 | moment, its free memory will be available for BL2's use as-is. However, this |
| 519 | means that BL2 must read the `meminfo` structure before it starts using its |
| 520 | free memory (this is discussed in Section 3.2). |
| 521 | |
| 522 | In future releases of the ARM Trusted Firmware it will be possible for |
| 523 | the platform to decide where it wants to place the `meminfo` structure for |
| 524 | BL2. |
| 525 | |
Sandrine Bailleux | 8f55dfb | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 526 | BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 527 | BL2 `meminfo` structure. The platform may override this implementation, for |
| 528 | example if the platform wants to restrict the amount of memory visible to |
| 529 | BL2. Details of how to do this are given below. |
| 530 | |
| 531 | The following functions need to be implemented by the platform port to enable |
| 532 | BL1 to perform the above tasks. |
| 533 | |
| 534 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 535 | ### Function : bl1_plat_arch_setup() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 536 | |
| 537 | Argument : void |
| 538 | Return : void |
| 539 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 540 | This function performs any platform-specific and architectural setup that the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 541 | platform requires. Platform-specific setup might include configuration of |
| 542 | memory controllers, configuration of the interconnect to allow the cluster |
| 543 | to service cache snoop requests from another cluster, and so on. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 544 | |
| 545 | In the ARM FVP port, this function enables CCI snoops into the cluster that the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 546 | primary CPU is part of. It also enables the MMU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 547 | |
| 548 | This function helps fulfill requirement 2 above. |
| 549 | |
| 550 | |
| 551 | ### Function : bl1_platform_setup() [mandatory] |
| 552 | |
| 553 | Argument : void |
| 554 | Return : void |
| 555 | |
| 556 | This function executes with the MMU and data caches enabled. It is responsible |
| 557 | for performing any remaining platform-specific setup that can occur after the |
| 558 | MMU and data cache have been enabled. |
| 559 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 560 | This function is also responsible for initializing the storage abstraction layer |
| 561 | which is used to load further bootloader images. |
| 562 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 563 | This function helps fulfill requirement 3 above. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 564 | |
| 565 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 566 | ### Function : bl1_plat_sec_mem_layout() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 567 | |
| 568 | Argument : void |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 569 | Return : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 570 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 571 | This function should only be called on the cold boot path. It executes with the |
| 572 | MMU and data caches enabled. The pointer returned by this function must point to |
| 573 | a `meminfo` structure containing the extents and availability of secure RAM for |
| 574 | the BL1 stage. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 575 | |
| 576 | meminfo.total_base = Base address of secure RAM visible to BL1 |
| 577 | meminfo.total_size = Size of secure RAM visible to BL1 |
| 578 | meminfo.free_base = Base address of secure RAM available for allocation |
| 579 | to BL1 |
| 580 | meminfo.free_size = Size of secure RAM available for allocation to BL1 |
| 581 | |
| 582 | This information is used by BL1 to load the BL2 image in secure RAM. BL1 also |
| 583 | populates a similar structure to tell BL2 the extents of memory available for |
| 584 | its own use. |
| 585 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 586 | This function helps fulfill requirement 3 above. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 587 | |
| 588 | |
Sandrine Bailleux | 8f55dfb | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 589 | ### Function : bl1_init_bl2_mem_layout() [optional] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 590 | |
| 591 | Argument : meminfo *, meminfo *, unsigned int, unsigned long |
| 592 | Return : void |
| 593 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 594 | BL1 needs to tell the next stage the amount of secure RAM available |
| 595 | for it to use. This information is populated in a `meminfo` |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 596 | structure. |
| 597 | |
| 598 | Depending upon where BL2 has been loaded in secure RAM (determined by |
| 599 | `BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use. |
| 600 | BL1 also ensures that its data sections resident in secure RAM are not visible |
| 601 | to BL2. An illustration of how this is done in the ARM FVP port is given in the |
| 602 | [User Guide], in the Section "Memory layout on Base FVP". |
| 603 | |
| 604 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 605 | ### Function : bl1_plat_set_bl2_ep_info() [mandatory] |
| 606 | |
| 607 | Argument : image_info *, entry_point_info * |
| 608 | Return : void |
| 609 | |
| 610 | This function is called after loading BL2 image and it can be used to overwrite |
| 611 | the entry point set by loader and also set the security state and SPSR which |
| 612 | represents the entry point system state for BL2. |
| 613 | |
| 614 | On FVP, we are setting the security state and the SPSR for the BL2 entrypoint |
| 615 | |
| 616 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 617 | 3.2 Boot Loader Stage 2 (BL2) |
| 618 | ----------------------------- |
| 619 | |
| 620 | The BL2 stage is executed only by the primary CPU, which is determined in BL1 |
| 621 | using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at |
| 622 | `BL2_BASE`. BL2 executes in Secure EL1 and is responsible for: |
| 623 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 624 | 1. (Optional) Loading the BL3-0 binary image (if present) from platform |
| 625 | provided non-volatile storage. To load the BL3-0 image, BL2 makes use of |
| 626 | the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function. |
| 627 | The platform also defines the address in memory where BL3-0 is loaded |
| 628 | through the optional constant `BL30_BASE`. BL2 uses this information |
| 629 | to determine if there is enough memory to load the BL3-0 image. |
| 630 | Subsequent handling of the BL3-0 image is platform-specific and is |
| 631 | implemented in the `bl2_plat_handle_bl30()` function. |
| 632 | If `BL30_BASE` is not defined then this step is not performed. |
| 633 | |
| 634 | 2. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 635 | load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it |
| 636 | by BL1. This structure allows BL2 to calculate how much secure RAM is |
| 637 | available for its use. The platform also defines the address in secure RAM |
| 638 | where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this |
| 639 | 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] | 640 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 641 | 3. (Optional) Loading the BL3-2 binary image (if present) from platform |
Dan Handley | 1151c82 | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 642 | provided non-volatile storage. To load the BL3-2 image, BL2 makes use of |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 643 | the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function. |
| 644 | The platform also defines the address in memory where BL3-2 is loaded |
| 645 | through the optional constant `BL32_BASE`. BL2 uses this information |
| 646 | to determine if there is enough memory to load the BL3-2 image. |
| 647 | If `BL32_BASE` is not defined then this and the next step is not performed. |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 648 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 649 | 4. (Optional) Arranging to pass control to the BL3-2 image (if present) that |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 650 | has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info` |
Dan Handley | 1151c82 | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 651 | structure in memory provided by the platform with information about how |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 652 | BL3-1 should pass control to the BL3-2 image. |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 653 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 654 | 5. Loading the normal world BL3-3 binary image into non-secure DRAM from |
| 655 | platform storage and arranging for BL3-1 to pass control to this image. This |
| 656 | address is determined using the `plat_get_ns_image_entrypoint()` function |
| 657 | described below. |
| 658 | |
| 659 | 6. BL2 populates an `entry_point_info` structure in memory provided by the |
| 660 | platform with information about how BL3-1 should pass control to the |
| 661 | other BL images. |
| 662 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 663 | The following functions must be implemented by the platform port to enable BL2 |
| 664 | to perform the above tasks. |
| 665 | |
| 666 | |
| 667 | ### Function : bl2_early_platform_setup() [mandatory] |
| 668 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 669 | Argument : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 670 | Return : void |
| 671 | |
| 672 | This function executes with the MMU and data caches disabled. It is only called |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 673 | by the primary CPU. The arguments to this function is the address of the |
| 674 | `meminfo` structure populated by BL1. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 675 | |
| 676 | The platform must copy the contents of the `meminfo` structure into a private |
| 677 | variable as the original memory may be subsequently overwritten by BL2. The |
| 678 | copied structure is made available to all BL2 code through the |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 679 | `bl2_plat_sec_mem_layout()` function. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 680 | |
| 681 | |
| 682 | ### Function : bl2_plat_arch_setup() [mandatory] |
| 683 | |
| 684 | Argument : void |
| 685 | Return : void |
| 686 | |
| 687 | This function executes with the MMU and data caches disabled. It is only called |
| 688 | by the primary CPU. |
| 689 | |
| 690 | The purpose of this function is to perform any architectural initialization |
| 691 | that varies across platforms, for example enabling the MMU (since the memory |
| 692 | map differs across platforms). |
| 693 | |
| 694 | |
| 695 | ### Function : bl2_platform_setup() [mandatory] |
| 696 | |
| 697 | Argument : void |
| 698 | Return : void |
| 699 | |
| 700 | This function may execute with the MMU and data caches enabled if the platform |
| 701 | port does the necessary initialization in `bl2_plat_arch_setup()`. It is only |
| 702 | called by the primary CPU. |
| 703 | |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 704 | The purpose of this function is to perform any platform initialization |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 705 | specific to BL2. Platform security components are configured if required. |
| 706 | For the Base FVP the TZC-400 TrustZone controller is configured to only |
| 707 | grant non-secure access to DRAM. This avoids aliasing between secure and |
| 708 | non-secure accesses in the TLB and cache - secure execution states can use |
| 709 | the NS attributes in the MMU translation tables to access the DRAM. |
Harry Liebel | ce19cf1 | 2014-04-01 19:28:07 +0100 | [diff] [blame] | 710 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 711 | This function is also responsible for initializing the storage abstraction layer |
| 712 | which is used to load further bootloader images. |
| 713 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 714 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 715 | ### Function : bl2_plat_sec_mem_layout() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 716 | |
| 717 | Argument : void |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 718 | Return : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 719 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 720 | This function should only be called on the cold boot path. It may execute with |
| 721 | the MMU and data caches enabled if the platform port does the necessary |
| 722 | 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] | 723 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 724 | The purpose of this function is to return a pointer to a `meminfo` structure |
| 725 | 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] | 726 | `bl2_early_platform_setup()` above. |
| 727 | |
| 728 | |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 729 | ### Function : bl2_plat_get_bl30_meminfo() [mandatory] |
| 730 | |
| 731 | Argument : meminfo * |
| 732 | Return : void |
| 733 | |
| 734 | This function is used to get the memory limits where BL2 can load the |
| 735 | BL3-0 image. The meminfo provided by this is used by load_image() to |
| 736 | validate whether the BL3-0 image can be loaded within the given |
| 737 | memory from the given base. |
| 738 | |
| 739 | |
| 740 | ### Function : bl2_plat_handle_bl30() [mandatory] |
| 741 | |
| 742 | Argument : image_info * |
| 743 | Return : int |
| 744 | |
| 745 | This function is called after loading BL3-0 image and it is used to perform any |
| 746 | platform-specific actions required to handle the SCP firmware. Typically it |
| 747 | transfers the image into SCP memory using a platform-specific protocol and waits |
| 748 | until SCP executes it and signals to the Application Processor (AP) for BL2 |
| 749 | execution to continue. |
| 750 | |
| 751 | This function returns 0 on success, a negative error code otherwise. |
| 752 | |
| 753 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 754 | ### Function : bl2_plat_get_bl31_params() [mandatory] |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 755 | |
| 756 | Argument : void |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 757 | Return : bl31_params * |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 758 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 759 | BL2 platform code needs to return a pointer to a `bl31_params` structure it |
| 760 | will use for passing information to BL3-1. The `bl31_params` structure carries |
| 761 | the following information. |
| 762 | - Header describing the version information for interpreting the bl31_param |
| 763 | structure |
| 764 | - Information about executing the BL3-3 image in the `bl33_ep_info` field |
| 765 | - Information about executing the BL3-2 image in the `bl32_ep_info` field |
| 766 | - Information about the type and extents of BL3-1 image in the |
| 767 | `bl31_image_info` field |
| 768 | - Information about the type and extents of BL3-2 image in the |
| 769 | `bl32_image_info` field |
| 770 | - Information about the type and extents of BL3-3 image in the |
| 771 | `bl33_image_info` field |
| 772 | |
| 773 | The memory pointed by this structure and its sub-structures should be |
| 774 | accessible from BL3-1 initialisation code. BL3-1 might choose to copy the |
| 775 | necessary content, or maintain the structures until BL3-3 is initialised. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 776 | |
| 777 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 778 | ### Funtion : bl2_plat_get_bl31_ep_info() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 779 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 780 | Argument : void |
| 781 | Return : entry_point_info * |
| 782 | |
| 783 | BL2 platform code returns a pointer which is used to populate the entry point |
| 784 | information for BL3-1 entry point. The location pointed by it should be |
| 785 | accessible from BL1 while processing the synchronous exception to run to BL3-1. |
| 786 | |
| 787 | On FVP this is allocated inside an bl2_to_bl31_params_mem structure which |
| 788 | is allocated at an address pointed by PARAMS_BASE. |
| 789 | |
| 790 | |
| 791 | ### Function : bl2_plat_set_bl31_ep_info() [mandatory] |
| 792 | |
| 793 | Argument : image_info *, entry_point_info * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 794 | Return : void |
| 795 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 796 | This function is called after loading BL3-1 image and it can be used to |
| 797 | overwrite the entry point set by loader and also set the security state |
| 798 | and SPSR which represents the entry point system state for BL3-1. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 799 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 800 | On FVP, we are setting the security state and the SPSR for the BL3-1 |
| 801 | entrypoint. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 802 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 803 | ### Function : bl2_plat_set_bl32_ep_info() [mandatory] |
| 804 | |
| 805 | Argument : image_info *, entry_point_info * |
| 806 | Return : void |
| 807 | |
| 808 | This function is called after loading BL3-2 image and it can be used to |
| 809 | overwrite the entry point set by loader and also set the security state |
| 810 | and SPSR which represents the entry point system state for BL3-2. |
| 811 | |
| 812 | On FVP, we are setting the security state and the SPSR for the BL3-2 |
| 813 | entrypoint |
| 814 | |
| 815 | ### Function : bl2_plat_set_bl33_ep_info() [mandatory] |
| 816 | |
| 817 | Argument : image_info *, entry_point_info * |
| 818 | Return : void |
| 819 | |
| 820 | This function is called after loading BL3-3 image and it can be used to |
| 821 | overwrite the entry point set by loader and also set the security state |
| 822 | and SPSR which represents the entry point system state for BL3-3. |
| 823 | |
| 824 | On FVP, we are setting the security state and the SPSR for the BL3-3 |
| 825 | entrypoint |
| 826 | |
| 827 | ### Function : bl2_plat_get_bl32_meminfo() [mandatory] |
| 828 | |
| 829 | Argument : meminfo * |
| 830 | Return : void |
| 831 | |
| 832 | This function is used to get the memory limits where BL2 can load the |
| 833 | BL3-2 image. The meminfo provided by this is used by load_image() to |
| 834 | validate whether the BL3-2 image can be loaded with in the given |
| 835 | memory from the given base. |
| 836 | |
| 837 | ### Function : bl2_plat_get_bl33_meminfo() [mandatory] |
| 838 | |
| 839 | Argument : meminfo * |
| 840 | Return : void |
| 841 | |
| 842 | This function is used to get the memory limits where BL2 can load the |
| 843 | BL3-3 image. The meminfo provided by this is used by load_image() to |
| 844 | validate whether the BL3-3 image can be loaded with in the given |
| 845 | memory from the given base. |
| 846 | |
| 847 | ### Function : bl2_plat_flush_bl31_params() [mandatory] |
| 848 | |
| 849 | Argument : void |
| 850 | Return : void |
| 851 | |
| 852 | Once BL2 has populated all the structures that needs to be read by BL1 |
| 853 | and BL3-1 including the bl31_params structures and its sub-structures, |
| 854 | the bl31_ep_info structure and any platform specific data. It flushes |
| 855 | all these data to the main memory so that it is available when we jump to |
| 856 | later Bootloader stages with MMU off |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 857 | |
| 858 | ### Function : plat_get_ns_image_entrypoint() [mandatory] |
| 859 | |
| 860 | Argument : void |
| 861 | Return : unsigned long |
| 862 | |
| 863 | As previously described, BL2 is responsible for arranging for control to be |
| 864 | passed to a normal world BL image through BL3-1. This function returns the |
| 865 | entrypoint of that image, which BL3-1 uses to jump to it. |
| 866 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 867 | 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] | 868 | |
| 869 | |
| 870 | 3.2 Boot Loader Stage 3-1 (BL3-1) |
| 871 | --------------------------------- |
| 872 | |
| 873 | During cold boot, the BL3-1 stage is executed only by the primary CPU. This is |
| 874 | determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes |
| 875 | control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all |
| 876 | CPUs. BL3-1 executes at EL3 and is responsible for: |
| 877 | |
| 878 | 1. Re-initializing all architectural and platform state. Although BL1 performs |
| 879 | some of this initialization, BL3-1 remains resident in EL3 and must ensure |
| 880 | that EL3 architectural and platform state is completely initialized. It |
| 881 | should make no assumptions about the system state when it receives control. |
| 882 | |
| 883 | 2. Passing control to a normal world BL image, pre-loaded at a platform- |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 884 | specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 885 | populated in memory to do this. |
| 886 | |
| 887 | 3. Providing runtime firmware services. Currently, BL3-1 only implements a |
| 888 | subset of the Power State Coordination Interface (PSCI) API as a runtime |
| 889 | service. See Section 3.3 below for details of porting the PSCI |
| 890 | implementation. |
| 891 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 892 | 4. Optionally passing control to the BL3-2 image, pre-loaded at a platform- |
| 893 | specific address by BL2. BL3-1 exports a set of apis that allow runtime |
| 894 | services to specify the security state in which the next image should be |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 895 | executed and run the corresponding image. BL3-1 uses the `entry_point_info` |
| 896 | structure populated by BL2 to do this. |
| 897 | |
| 898 | If BL3-1 is a reset vector, It also needs to handle the reset as specified in |
| 899 | section 2.2 before the tasks described above. |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 900 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 901 | The following functions must be implemented by the platform port to enable BL3-1 |
| 902 | to perform the above tasks. |
| 903 | |
| 904 | |
| 905 | ### Function : bl31_early_platform_setup() [mandatory] |
| 906 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 907 | Argument : bl31_params *, void * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 908 | Return : void |
| 909 | |
| 910 | This function executes with the MMU and data caches disabled. It is only called |
| 911 | by the primary CPU. The arguments to this function are: |
| 912 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 913 | * The address of the `bl31_params` structure populated by BL2. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 914 | * An opaque pointer that the platform may use as needed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 915 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 916 | The platform can copy the contents of the `bl31_params` structure and its |
| 917 | sub-structures into private variables if the original memory may be |
| 918 | subsequently overwritten by BL3-1 and similarly the `void *` pointing |
| 919 | to the platform data also needs to be saved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 920 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 921 | On the ARM FVP port, BL2 passes a pointer to a `bl31_params` structure populated |
| 922 | in the secure DRAM at address `0x6000000` in the bl31_params * argument and it |
| 923 | does not use opaque pointer mentioned earlier. BL3-1 does not copy this |
| 924 | information to internal data structures as it guarantees that the secure |
| 925 | DRAM memory will not be overwritten. It maintains an internal reference to this |
| 926 | information in the `bl2_to_bl31_params` variable. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 927 | |
| 928 | ### Function : bl31_plat_arch_setup() [mandatory] |
| 929 | |
| 930 | Argument : void |
| 931 | Return : void |
| 932 | |
| 933 | This function executes with the MMU and data caches disabled. It is only called |
| 934 | by the primary CPU. |
| 935 | |
| 936 | The purpose of this function is to perform any architectural initialization |
| 937 | that varies across platforms, for example enabling the MMU (since the memory |
| 938 | map differs across platforms). |
| 939 | |
| 940 | |
| 941 | ### Function : bl31_platform_setup() [mandatory] |
| 942 | |
| 943 | Argument : void |
| 944 | Return : void |
| 945 | |
| 946 | This function may execute with the MMU and data caches enabled if the platform |
| 947 | port does the necessary initialization in `bl31_plat_arch_setup()`. It is only |
| 948 | called by the primary CPU. |
| 949 | |
| 950 | The purpose of this function is to complete platform initialization so that both |
| 951 | BL3-1 runtime services and normal world software can function correctly. |
| 952 | |
| 953 | The ARM FVP port does the following: |
| 954 | * Initializes the generic interrupt controller. |
| 955 | * Configures the CLCD controller. |
Sandrine Bailleux | 9e86490 | 2014-03-31 11:25:18 +0100 | [diff] [blame] | 956 | * Enables system-level implementation of the generic timer counter. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 957 | * Grants access to the system counter timer module |
| 958 | * Initializes the FVP power controller device |
| 959 | * Detects the system topology. |
| 960 | |
| 961 | |
| 962 | ### Function : bl31_get_next_image_info() [mandatory] |
| 963 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 964 | Argument : unsigned int |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 965 | Return : entry_point_info * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 966 | |
| 967 | This function may execute with the MMU and data caches enabled if the platform |
| 968 | port does the necessary initializations in `bl31_plat_arch_setup()`. |
| 969 | |
| 970 | This function is called by `bl31_main()` to retrieve information provided by |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 971 | BL2 for the next image in the security state specified by the argument. BL3-1 |
| 972 | uses this information to pass control to that image in the specified security |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 973 | state. This function must return a pointer to the `entry_point_info` structure |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 974 | (that was copied during `bl31_early_platform_setup()`) if the image exists. It |
| 975 | should return NULL otherwise. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 976 | |
| 977 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 978 | 3.3 Power State Coordination Interface (in BL3-1) |
| 979 | ------------------------------------------------ |
| 980 | |
| 981 | The ARM Trusted Firmware's implementation of the PSCI API is based around the |
| 982 | concept of an _affinity instance_. Each _affinity instance_ can be uniquely |
| 983 | identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI |
| 984 | interface) and an _affinity level_. A processing element (for example, a |
| 985 | CPU) is at level 0. If the CPUs in the system are described in a tree where the |
| 986 | node above a CPU is a logical grouping of CPUs that share some state, then |
| 987 | affinity level 1 is that group of CPUs (for example, a cluster), and affinity |
| 988 | level 2 is a group of clusters (for example, the system). The implementation |
| 989 | assumes that the affinity level 1 ID can be computed from the affinity level 0 |
| 990 | ID (for example, a unique cluster ID can be computed from the CPU ID). The |
| 991 | current implementation computes this on the basis of the recommended use of |
| 992 | `MPIDR` affinity fields in the ARM Architecture Reference Manual. |
| 993 | |
| 994 | BL3-1's platform initialization code exports a pointer to the platform-specific |
| 995 | power management operations required for the PSCI implementation to function |
| 996 | correctly. This information is populated in the `plat_pm_ops` structure. The |
| 997 | PSCI implementation calls members of the `plat_pm_ops` structure for performing |
| 998 | power management operations for each affinity instance. For example, the target |
| 999 | CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()` |
| 1000 | handler (if present) is called for each affinity instance as the PSCI |
| 1001 | implementation powers up each affinity level implemented in the `MPIDR` (for |
| 1002 | example, CPU, cluster and system). |
| 1003 | |
| 1004 | The following functions must be implemented to initialize PSCI functionality in |
| 1005 | the ARM Trusted Firmware. |
| 1006 | |
| 1007 | |
| 1008 | ### Function : plat_get_aff_count() [mandatory] |
| 1009 | |
| 1010 | Argument : unsigned int, unsigned long |
| 1011 | Return : unsigned int |
| 1012 | |
| 1013 | This function may execute with the MMU and data caches enabled if the platform |
| 1014 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1015 | called by the primary CPU. |
| 1016 | |
| 1017 | This function is called by the PSCI initialization code to detect the system |
| 1018 | topology. Its purpose is to return the number of affinity instances implemented |
| 1019 | at a given `affinity level` (specified by the first argument) and a given |
| 1020 | `MPIDR` (specified by the second argument). For example, on a dual-cluster |
| 1021 | system where first cluster implements 2 CPUs and the second cluster implements 4 |
| 1022 | CPUs, a call to this function with an `MPIDR` corresponding to the first cluster |
| 1023 | (`0x0`) and affinity level 0, would return 2. A call to this function with an |
| 1024 | `MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0, |
| 1025 | would return 4. |
| 1026 | |
| 1027 | |
| 1028 | ### Function : plat_get_aff_state() [mandatory] |
| 1029 | |
| 1030 | Argument : unsigned int, unsigned long |
| 1031 | Return : unsigned int |
| 1032 | |
| 1033 | This function may execute with the MMU and data caches enabled if the platform |
| 1034 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1035 | called by the primary CPU. |
| 1036 | |
| 1037 | This function is called by the PSCI initialization code. Its purpose is to |
| 1038 | return the state of an affinity instance. The affinity instance is determined by |
| 1039 | the affinity ID at a given `affinity level` (specified by the first argument) |
| 1040 | and an `MPIDR` (specified by the second argument). The state can be one of |
| 1041 | `PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for |
| 1042 | system topologies where certain affinity instances are unimplemented. For |
| 1043 | example, consider a platform that implements a single cluster with 4 CPUs and |
| 1044 | another CPU implemented directly on the interconnect with the cluster. The |
| 1045 | `MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single |
| 1046 | CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1 |
| 1047 | is missing but needs to be accounted for to reach this single CPU in the |
| 1048 | topology tree. Hence it is marked as `PSCI_AFF_ABSENT`. |
| 1049 | |
| 1050 | |
| 1051 | ### Function : plat_get_max_afflvl() [mandatory] |
| 1052 | |
| 1053 | Argument : void |
| 1054 | Return : int |
| 1055 | |
| 1056 | This function may execute with the MMU and data caches enabled if the platform |
| 1057 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1058 | called by the primary CPU. |
| 1059 | |
| 1060 | This function is called by the PSCI implementation both during cold and warm |
| 1061 | boot, to determine the maximum affinity level that the power management |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 1062 | 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] | 1063 | likely that hardware will implement fewer affinity levels. This function allows |
| 1064 | the PSCI implementation to consider only those affinity levels in the system |
| 1065 | that the platform implements. For example, the Base AEM FVP implements two |
| 1066 | clusters with a configurable number of CPUs. It reports the maximum affinity |
| 1067 | level as 1, resulting in PSCI power control up to the cluster level. |
| 1068 | |
| 1069 | |
| 1070 | ### Function : platform_setup_pm() [mandatory] |
| 1071 | |
| 1072 | Argument : plat_pm_ops ** |
| 1073 | Return : int |
| 1074 | |
| 1075 | This function may execute with the MMU and data caches enabled if the platform |
| 1076 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1077 | called by the primary CPU. |
| 1078 | |
| 1079 | This function is called by PSCI initialization code. Its purpose is to export |
| 1080 | handler routines for platform-specific power management actions by populating |
| 1081 | the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure. |
| 1082 | |
| 1083 | A description of each member of this structure is given below. Please refer to |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1084 | 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] | 1085 | as an example. A platform port may choose not implement some of the power |
| 1086 | management operations. For example, the ARM FVP port does not implement the |
| 1087 | `affinst_standby()` function. |
| 1088 | |
| 1089 | #### plat_pm_ops.affinst_standby() |
| 1090 | |
| 1091 | Perform the platform-specific setup to enter the standby state indicated by the |
| 1092 | passed argument. |
| 1093 | |
| 1094 | #### plat_pm_ops.affinst_on() |
| 1095 | |
| 1096 | Perform the platform specific setup to power on an affinity instance, specified |
| 1097 | by the `MPIDR` (first argument) and `affinity level` (fourth argument). The |
| 1098 | `state` (fifth argument) contains the current state of that affinity instance |
| 1099 | (ON or OFF). This is useful to determine whether any action must be taken. For |
| 1100 | example, while powering on a CPU, the cluster that contains this CPU might |
| 1101 | already be in the ON state. The platform decides what actions must be taken to |
| 1102 | transition from the current state to the target state (indicated by the power |
| 1103 | management operation). |
| 1104 | |
| 1105 | #### plat_pm_ops.affinst_off() |
| 1106 | |
| 1107 | Perform the platform specific setup to power off an affinity instance in the |
| 1108 | `MPIDR` of the calling CPU. It is called by the PSCI `CPU_OFF` API |
| 1109 | implementation. |
| 1110 | |
| 1111 | The `MPIDR` (first argument), `affinity level` (second argument) and `state` |
| 1112 | (third argument) have a similar meaning as described in the `affinst_on()` |
| 1113 | operation. They are used to identify the affinity instance on which the call |
| 1114 | is made and its current state. This gives the platform port an indication of the |
| 1115 | state transition it must make to perform the requested action. For example, if |
| 1116 | the calling CPU is the last powered on CPU in the cluster, after powering down |
| 1117 | affinity level 0 (CPU), the platform port should power down affinity level 1 |
| 1118 | (the cluster) as well. |
| 1119 | |
| 1120 | This function is called with coherent stacks. This allows the PSCI |
| 1121 | implementation to flush caches at a given affinity level without running into |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 1122 | stale stack state after turning off the caches. On ARMv8-A cache hits do not |
| 1123 | occur after the cache has been turned off. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1124 | |
| 1125 | #### plat_pm_ops.affinst_suspend() |
| 1126 | |
| 1127 | Perform the platform specific setup to power off an affinity instance in the |
| 1128 | `MPIDR` of the calling CPU. It is called by the PSCI `CPU_SUSPEND` API |
| 1129 | implementation. |
| 1130 | |
| 1131 | The `MPIDR` (first argument), `affinity level` (third argument) and `state` |
| 1132 | (fifth argument) have a similar meaning as described in the `affinst_on()` |
| 1133 | operation. They are used to identify the affinity instance on which the call |
| 1134 | is made and its current state. This gives the platform port an indication of the |
| 1135 | state transition it must make to perform the requested action. For example, if |
| 1136 | the calling CPU is the last powered on CPU in the cluster, after powering down |
| 1137 | affinity level 0 (CPU), the platform port should power down affinity level 1 |
| 1138 | (the cluster) as well. |
| 1139 | |
| 1140 | The difference between turning an affinity instance off versus suspending it |
| 1141 | is that in the former case, the affinity instance is expected to re-initialize |
| 1142 | its state when its next powered on (see `affinst_on_finish()`). In the latter |
| 1143 | case, the affinity instance is expected to save enough state so that it can |
| 1144 | resume execution by restoring this state when its powered on (see |
| 1145 | `affinst_suspend_finish()`). |
| 1146 | |
| 1147 | This function is called with coherent stacks. This allows the PSCI |
| 1148 | implementation to flush caches at a given affinity level without running into |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 1149 | stale stack state after turning off the caches. On ARMv8-A cache hits do not |
| 1150 | occur after the cache has been turned off. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1151 | |
| 1152 | #### plat_pm_ops.affinst_on_finish() |
| 1153 | |
| 1154 | This function is called by the PSCI implementation after the calling CPU is |
| 1155 | powered on and released from reset in response to an earlier PSCI `CPU_ON` call. |
| 1156 | It performs the platform-specific setup required to initialize enough state for |
| 1157 | this CPU to enter the normal world and also provide secure runtime firmware |
| 1158 | services. |
| 1159 | |
| 1160 | The `MPIDR` (first argument), `affinity level` (second argument) and `state` |
| 1161 | (third argument) have a similar meaning as described in the previous operations. |
| 1162 | |
| 1163 | This function is called with coherent stacks. This allows the PSCI |
| 1164 | implementation to flush caches at a given affinity level without running into |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 1165 | stale stack state after turning off the caches. On ARMv8-A cache hits do not |
| 1166 | occur after the cache has been turned off. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1167 | |
| 1168 | #### plat_pm_ops.affinst_on_suspend() |
| 1169 | |
| 1170 | This function is called by the PSCI implementation after the calling CPU is |
| 1171 | powered on and released from reset in response to an asynchronous wakeup |
| 1172 | event, for example a timer interrupt that was programmed by the CPU during the |
| 1173 | `CPU_SUSPEND` call. It performs the platform-specific setup required to |
| 1174 | restore the saved state for this CPU to resume execution in the normal world |
| 1175 | and also provide secure runtime firmware services. |
| 1176 | |
| 1177 | The `MPIDR` (first argument), `affinity level` (second argument) and `state` |
| 1178 | (third argument) have a similar meaning as described in the previous operations. |
| 1179 | |
| 1180 | This function is called with coherent stacks. This allows the PSCI |
| 1181 | implementation to flush caches at a given affinity level without running into |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 1182 | stale stack state after turning off the caches. On ARMv8-A cache hits do not |
| 1183 | occur after the cache has been turned off. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1184 | |
| 1185 | BL3-1 platform initialization code must also detect the system topology and |
| 1186 | the state of each affinity instance in the topology. This information is |
| 1187 | critical for the PSCI runtime service to function correctly. More details are |
| 1188 | provided in the description of the `plat_get_aff_count()` and |
| 1189 | `plat_get_aff_state()` functions above. |
| 1190 | |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 1191 | 3.4 Interrupt Management framework (in BL3-1) |
| 1192 | ---------------------------------------------- |
| 1193 | BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts |
| 1194 | generated in either security state and targeted to EL1 or EL2 in the non-secure |
| 1195 | state or EL3/S-EL1 in the secure state. The design of this framework is |
| 1196 | described in the [IMF Design Guide] |
| 1197 | |
| 1198 | A platform should export the following APIs to support the IMF. The following |
| 1199 | text briefly describes each api and its implementation on the FVP port. The API |
| 1200 | implementation depends upon the type of interrupt controller present in the |
| 1201 | platform. The FVP implements an ARM Generic Interrupt Controller (ARM GIC) as |
| 1202 | per the version 2.0 of the [ARM GIC Architecture Specification] |
| 1203 | |
| 1204 | ### Function : plat_interrupt_type_to_line() [mandatory] |
| 1205 | |
| 1206 | Argument : uint32_t, uint32_t |
| 1207 | Return : uint32_t |
| 1208 | |
| 1209 | The ARM processor signals an interrupt exception either through the IRQ or FIQ |
| 1210 | interrupt line. The specific line that is signaled depends on how the interrupt |
| 1211 | controller (IC) reports different interrupt types from an execution context in |
| 1212 | either security state. The IMF uses this API to determine which interrupt line |
| 1213 | the platform IC uses to signal each type of interrupt supported by the framework |
| 1214 | from a given security state. |
| 1215 | |
| 1216 | The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design |
| 1217 | Guide]) indicating the target type of the interrupt, the second parameter is the |
| 1218 | security state of the originating execution context. The return result is the |
| 1219 | bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1, |
| 1220 | FIQ=2. |
| 1221 | |
| 1222 | The FVP port configures the ARM GIC to signal S-EL1 interrupts as FIQs and |
| 1223 | Non-secure interrupts as IRQs from either security state. |
| 1224 | |
| 1225 | |
| 1226 | ### Function : plat_ic_get_pending_interrupt_type() [mandatory] |
| 1227 | |
| 1228 | Argument : void |
| 1229 | Return : uint32_t |
| 1230 | |
| 1231 | This API returns the type of the highest priority pending interrupt at the |
| 1232 | platform IC. The IMF uses the interrupt type to retrieve the corresponding |
| 1233 | handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt |
| 1234 | pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`, |
| 1235 | `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. |
| 1236 | |
| 1237 | The FVP port reads the _Highest Priority Pending Interrupt Register_ |
| 1238 | (`GICC_HPPIR`) to determine the id of the pending interrupt. The type of interrupt |
| 1239 | depends upon the id value as follows. |
| 1240 | |
| 1241 | 1. id < 1022 is reported as a S-EL1 interrupt |
| 1242 | 2. id = 1022 is reported as a Non-secure interrupt. |
| 1243 | 3. id = 1023 is reported as an invalid interrupt type. |
| 1244 | |
| 1245 | |
| 1246 | ### Function : plat_ic_get_pending_interrupt_id() [mandatory] |
| 1247 | |
| 1248 | Argument : void |
| 1249 | Return : uint32_t |
| 1250 | |
| 1251 | This API returns the id of the highest priority pending interrupt at the |
| 1252 | platform IC. The IMF passes the id returned by this API to the registered |
| 1253 | handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag |
| 1254 | is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending. |
| 1255 | |
| 1256 | The FVP port reads the _Highest Priority Pending Interrupt Register_ |
| 1257 | (`GICC_HPPIR`) to determine the id of the pending interrupt. The id that is |
| 1258 | returned by API depends upon the value of the id read from the interrupt |
| 1259 | controller as follows. |
| 1260 | |
| 1261 | 1. id < 1022. id is returned as is. |
| 1262 | 2. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_ |
| 1263 | (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This |
| 1264 | id is returned by the API. |
| 1265 | 3. id = 1023. `INTR_ID_UNAVAILABLE` is returned. |
| 1266 | |
| 1267 | |
| 1268 | ### Function : plat_ic_acknowledge_interrupt() [mandatory] |
| 1269 | |
| 1270 | Argument : void |
| 1271 | Return : uint32_t |
| 1272 | |
| 1273 | This API is used by the CPU to indicate to the platform IC that processing of |
| 1274 | the highest pending interrupt has begun. It should return the id of the |
| 1275 | interrupt which is being processed. |
| 1276 | |
| 1277 | The FVP port reads the _Interrupt Acknowledge Register_ (`GICC_IAR`). This |
| 1278 | changes the state of the highest priority pending interrupt from pending to |
| 1279 | active in the interrupt controller. It returns the value read from the |
| 1280 | `GICC_IAR`. This value is the id of the interrupt whose state has been changed. |
| 1281 | |
| 1282 | The TSP uses this API to start processing of the secure physical timer |
| 1283 | interrupt. |
| 1284 | |
| 1285 | |
| 1286 | ### Function : plat_ic_end_of_interrupt() [mandatory] |
| 1287 | |
| 1288 | Argument : uint32_t |
| 1289 | Return : void |
| 1290 | |
| 1291 | This API is used by the CPU to indicate to the platform IC that processing of |
| 1292 | the interrupt corresponding to the id (passed as the parameter) has |
| 1293 | finished. The id should be the same as the id returned by the |
| 1294 | `plat_ic_acknowledge_interrupt()` API. |
| 1295 | |
| 1296 | The FVP port writes the id to the _End of Interrupt Register_ |
| 1297 | (`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt |
| 1298 | controller. |
| 1299 | |
| 1300 | The TSP uses this API to finish processing of the secure physical timer |
| 1301 | interrupt. |
| 1302 | |
| 1303 | |
| 1304 | ### Function : plat_ic_get_interrupt_type() [mandatory] |
| 1305 | |
| 1306 | Argument : uint32_t |
| 1307 | Return : uint32_t |
| 1308 | |
| 1309 | This API returns the type of the interrupt id passed as the parameter. |
| 1310 | `INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid |
| 1311 | interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is |
| 1312 | returned depending upon how the interrupt has been configured by the platform |
| 1313 | IC. |
| 1314 | |
| 1315 | The FVP port configures S-EL1 interrupts as Group0 interrupts and Non-secure |
| 1316 | interrupts as Group1 interrupts. It reads the group value corresponding to the |
| 1317 | interrupt id from the relevant _Interrupt Group Register_ (`GICD_IGROUPRn`). It |
| 1318 | uses the group value to determine the type of interrupt. |
| 1319 | |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame^] | 1320 | 3.5 Crash Reporting mechanism (in BL3-1) |
| 1321 | ---------------------------------------------- |
| 1322 | BL3-1 implements a crash reporting mechanism which prints the various registers |
| 1323 | of the CPU to enable quick crash analysis and debugging. It requires that a console |
| 1324 | is designated as the crash console by the platform which will used to print the |
| 1325 | register dump. |
| 1326 | |
| 1327 | The following functions must be implemented by the platform if it wants crash reporting |
| 1328 | mechanism in BL3-1. The functions are implemented in assembly so that they can be |
| 1329 | invoked without a C Runtime stack. |
| 1330 | |
| 1331 | ### Function : plat_crash_console_init |
| 1332 | |
| 1333 | Argument : void |
| 1334 | Return : int |
| 1335 | |
| 1336 | This API is used by the crash reporting mechanism to intialize the crash console. |
| 1337 | It should only use the general purpose registers x0 to x2 to do the initiaization |
| 1338 | and returns 1 on success. |
| 1339 | |
| 1340 | The FVP port designates the PL011_UART0 as the crash console and calls the |
| 1341 | console_core_init() to initialize the console. |
| 1342 | |
| 1343 | ### Function : plat_crash_console_putc |
| 1344 | |
| 1345 | Argument : int |
| 1346 | Return : int |
| 1347 | |
| 1348 | This API is used by the crash reporting mechanism to print a character on the |
| 1349 | designated crash console. It should only use general purpose registers x1 and |
| 1350 | x2 to do its work. The parameter and the return value are in general purpose |
| 1351 | register x0. |
| 1352 | |
| 1353 | The FVP port designates the PL011_UART0 as the crash console and calls the |
| 1354 | console_core_putc() to print the character on the console. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1355 | |
Harry Liebel | a960f28 | 2013-12-12 16:03:44 +0000 | [diff] [blame] | 1356 | 4. C Library |
| 1357 | ------------- |
| 1358 | |
| 1359 | To avoid subtle toolchain behavioral dependencies, the header files provided |
| 1360 | by the compiler are not used. The software is built with the `-nostdinc` flag |
| 1361 | to ensure no headers are included from the toolchain inadvertently. Instead the |
| 1362 | required headers are included in the ARM Trusted Firmware source tree. The |
| 1363 | library only contains those C library definitions required by the local |
| 1364 | implementation. If more functionality is required, the needed library functions |
| 1365 | will need to be added to the local implementation. |
| 1366 | |
| 1367 | Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these |
| 1368 | headers have been cut down in order to simplify the implementation. In order to |
| 1369 | minimize changes to the header files, the [FreeBSD] layout has been maintained. |
| 1370 | The generic C library definitions can be found in `include/stdlib` with more |
| 1371 | system and machine specific declarations in `include/stdlib/sys` and |
| 1372 | `include/stdlib/machine`. |
| 1373 | |
| 1374 | The local C library implementations can be found in `lib/stdlib`. In order to |
| 1375 | extend the C library these files may need to be modified. It is recommended to |
| 1376 | use a release version of [FreeBSD] as a starting point. |
| 1377 | |
| 1378 | The C library header files in the [FreeBSD] source tree are located in the |
| 1379 | `include` and `sys/sys` directories. [FreeBSD] machine specific definitions |
| 1380 | can be found in the `sys/<machine-type>` directories. These files define things |
| 1381 | like 'the size of a pointer' and 'the range of an integer'. Since an AArch64 |
| 1382 | port for [FreeBSD] does not yet exist, the machine specific definitions are |
| 1383 | based on existing machine types with similar properties (for example SPARC64). |
| 1384 | |
| 1385 | Where possible, C library function implementations were taken from [FreeBSD] |
| 1386 | as found in the `lib/libc` directory. |
| 1387 | |
| 1388 | A copy of the [FreeBSD] sources can be downloaded with `git`. |
| 1389 | |
| 1390 | git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0 |
| 1391 | |
| 1392 | |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1393 | 5. Storage abstraction layer |
| 1394 | ----------------------------- |
| 1395 | |
| 1396 | In order to improve platform independence and portability an storage abstraction |
| 1397 | layer is used to load data from non-volatile platform storage. |
| 1398 | |
| 1399 | Each platform should register devices and their drivers via the Storage layer. |
| 1400 | These drivers then need to be initialized by bootloader phases as |
| 1401 | required in their respective `blx_platform_setup()` functions. Currently |
| 1402 | storage access is only required by BL1 and BL2 phases. The `load_image()` |
| 1403 | function uses the storage layer to access non-volatile platform storage. |
| 1404 | |
| 1405 | It is mandatory to implement at least one storage driver. For the FVP the |
| 1406 | Firmware Image Package(FIP) driver is provided as the default means to load data |
| 1407 | from storage (see the "Firmware Image Package" section in the [User Guide]). |
| 1408 | The storage layer is described in the header file `include/io_storage.h`. The |
| 1409 | implementation of the common library is in `lib/io_storage.c` and the driver |
| 1410 | files are located in `drivers/io/`. |
| 1411 | |
| 1412 | Each IO driver must provide `io_dev_*` structures, as described in |
| 1413 | `drivers/io/io_driver.h`. These are returned via a mandatory registration |
| 1414 | function that is called on platform initialization. The semi-hosting driver |
| 1415 | implementation in `io_semihosting.c` can be used as an example. |
| 1416 | |
| 1417 | The Storage layer provides mechanisms to initialize storage devices before |
| 1418 | IO operations are called. The basic operations supported by the layer |
| 1419 | include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`. |
| 1420 | Drivers do not have to implement all operations, but each platform must |
| 1421 | provide at least one driver for a device capable of supporting generic |
| 1422 | operations such as loading a bootloader image. |
| 1423 | |
| 1424 | The current implementation only allows for known images to be loaded by the |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 1425 | firmware. These images are specified by using their names, as defined in |
| 1426 | [include/plat/common/platform.h]. The platform layer (`plat_get_image_source()`) |
| 1427 | then returns a reference to a device and a driver-specific `spec` which will be |
| 1428 | understood by the driver to allow access to the image data. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1429 | |
| 1430 | The layer is designed in such a way that is it possible to chain drivers with |
| 1431 | other drivers. For example, file-system drivers may be implemented on top of |
| 1432 | physical block devices, both represented by IO devices with corresponding |
| 1433 | drivers. In such a case, the file-system "binding" with the block device may |
| 1434 | be deferred until the file-system device is initialised. |
| 1435 | |
| 1436 | The abstraction currently depends on structures being statically allocated |
| 1437 | by the drivers and callers, as the system does not yet provide a means of |
| 1438 | dynamically allocating memory. This may also have the affect of limiting the |
| 1439 | amount of open resources per driver. |
| 1440 | |
| 1441 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1442 | - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 1443 | |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 1444 | _Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1445 | |
| 1446 | |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 1447 | [ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf |
| 1448 | [IMF Design Guide]: interrupt-framework-design.md |
| 1449 | [User Guide]: user-guide.md |
| 1450 | [FreeBSD]: http://www.freebsd.org |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1451 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1452 | [plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S |
| 1453 | [plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 1454 | [plat/fvp/include/platform_def.h]: ../plat/fvp/include/platform_def.h |
| 1455 | [plat/fvp/include/plat_macros.S]: ../plat/fvp/include/plat_macros.S |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 1456 | [plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c |
| 1457 | [plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c |
| 1458 | [include/runtime_svc.h]: ../include/runtime_svc.h |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 1459 | [include/plat/common/platform.h]: ../include/plat/common/platform.h |