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