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