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