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