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) |
Jeenu Viswambharan | ec2653a | 2016-10-11 11:43:04 +0100 | [diff] [blame] | 11 | * [Common mandatory function modifications](#23-common-mandatory-function-modifications) |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 12 | * [Common optional modifications](#24-common-optional-modifications) |
Joakim Bech | 14a5b34 | 2014-11-25 10:55:26 +0100 | [diff] [blame] | 13 | 3. [Boot Loader stage specific modifications](#3--modifications-specific-to-a-boot-loader-stage) |
| 14 | * [Boot Loader stage 1 (BL1)](#31-boot-loader-stage-1-bl1) |
| 15 | * [Boot Loader stage 2 (BL2)](#32-boot-loader-stage-2-bl2) |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 16 | * [FWU Boot Loader stage 2 (BL2U)](#33-fwu-boot-loader-stage-2-bl2u) |
| 17 | * [Boot Loader stage 3-1 (BL31)](#34-boot-loader-stage-3-1-bl31) |
| 18 | * [PSCI implementation (in BL31)](#35-power-state-coordination-interface-in-bl31) |
| 19 | * [Interrupt Management framework (in BL31)](#36--interrupt-management-framework-in-bl31) |
| 20 | * [Crash Reporting mechanism (in BL31)](#37--crash-reporting-mechanism-in-bl31) |
Joakim Bech | 14a5b34 | 2014-11-25 10:55:26 +0100 | [diff] [blame] | 21 | 4. [Build flags](#4--build-flags) |
| 22 | 5. [C Library](#5--c-library) |
| 23 | 6. [Storage abstraction layer](#6--storage-abstraction-layer) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 24 | |
| 25 | - - - - - - - - - - - - - - - - - - |
| 26 | |
| 27 | 1. Introduction |
| 28 | ---------------- |
| 29 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 30 | Please note that this document has been updated for the new platform API |
| 31 | as required by the PSCI v1.0 implementation. Please refer to the |
| 32 | [Migration Guide] for the previous platform API. |
| 33 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 34 | Porting the ARM Trusted Firmware to a new platform involves making some |
| 35 | mandatory and optional modifications for both the cold and warm boot paths. |
| 36 | Modifications consist of: |
| 37 | |
| 38 | * Implementing a platform-specific function or variable, |
| 39 | * Setting up the execution context in a certain way, or |
| 40 | * Defining certain constants (for example #defines). |
| 41 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 42 | The platform-specific functions and variables are declared in |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 43 | [include/plat/common/platform.h]. The firmware provides a default implementation |
| 44 | of variables and functions to fulfill the optional requirements. These |
| 45 | implementations are all weakly defined; they are provided to ease the porting |
| 46 | effort. Each platform port can override them with its own implementation if the |
| 47 | default implementation is inadequate. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 48 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 49 | Platform ports that want to be aligned with standard ARM platforms (for example |
| 50 | FVP and Juno) may also use [include/plat/arm/common/plat_arm.h] and the |
| 51 | corresponding source files in `plat/arm/common/`. These provide standard |
| 52 | implementations for some of the required platform porting functions. However, |
| 53 | using these functions requires the platform port to implement additional |
| 54 | ARM standard platform porting functions. These additional functions are not |
| 55 | documented here. |
| 56 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 57 | Some modifications are common to all Boot Loader (BL) stages. Section 2 |
| 58 | discusses these in detail. The subsequent sections discuss the remaining |
| 59 | modifications for each BL stage in detail. |
| 60 | |
| 61 | This document should be read in conjunction with the ARM Trusted Firmware |
| 62 | [User Guide]. |
| 63 | |
| 64 | |
| 65 | 2. Common modifications |
| 66 | ------------------------ |
| 67 | |
| 68 | This section covers the modifications that should be made by the platform for |
| 69 | each BL stage to correctly port the firmware stack. They are categorized as |
| 70 | either mandatory or optional. |
| 71 | |
| 72 | |
| 73 | 2.1 Common mandatory modifications |
| 74 | ---------------------------------- |
Sandrine Bailleux | ef7fb9e | 2015-12-02 10:19:06 +0000 | [diff] [blame] | 75 | |
| 76 | A platform port must enable the Memory Management Unit (MMU) as well as the |
| 77 | instruction and data caches for each BL stage. Setting up the translation |
| 78 | tables is the responsibility of the platform port because memory maps differ |
Sandrine Bailleux | 3c2c72f | 2016-04-26 14:49:57 +0100 | [diff] [blame] | 79 | across platforms. A memory translation library (see `lib/xlat_tables/`) is |
| 80 | provided to help in this setup. Note that although this library supports |
Antonio Nino Diaz | f33fbb2 | 2016-03-31 09:08:56 +0100 | [diff] [blame] | 81 | non-identity mappings, this is intended only for re-mapping peripheral physical |
| 82 | addresses and allows platforms with high I/O addresses to reduce their virtual |
| 83 | address space. All other addresses corresponding to code and data must currently |
| 84 | use an identity mapping. |
Sandrine Bailleux | ef7fb9e | 2015-12-02 10:19:06 +0000 | [diff] [blame] | 85 | |
| 86 | In ARM standard platforms, each BL stage configures the MMU in the |
| 87 | platform-specific architecture setup function, `blX_plat_arch_setup()`, and uses |
| 88 | an identity mapping for all addresses. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 89 | |
Andrew Thoelke | ee7b35c | 2015-09-10 11:39:36 +0100 | [diff] [blame] | 90 | If the build option `USE_COHERENT_MEM` is enabled, each platform can allocate a |
Soby Mathew | ab8707e | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 91 | block of identity mapped secure memory with Device-nGnRE attributes aligned to |
Andrew Thoelke | ee7b35c | 2015-09-10 11:39:36 +0100 | [diff] [blame] | 92 | page boundary (4K) for each BL stage. All sections which allocate coherent |
| 93 | memory are grouped under `coherent_ram`. For ex: Bakery locks are placed in a |
| 94 | section identified by name `bakery_lock` inside `coherent_ram` so that its |
| 95 | possible for the firmware to place variables in it using the following C code |
| 96 | directive: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 97 | |
Soren Brinkmann | 65cd299 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 98 | __section("bakery_lock") |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 99 | |
| 100 | Or alternatively the following assembler code directive: |
| 101 | |
Andrew Thoelke | ee7b35c | 2015-09-10 11:39:36 +0100 | [diff] [blame] | 102 | .section bakery_lock |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | |
Andrew Thoelke | ee7b35c | 2015-09-10 11:39:36 +0100 | [diff] [blame] | 104 | The `coherent_ram` section is a sum of all sections like `bakery_lock` which are |
| 105 | used to allocate any data structures that are accessed both when a CPU is |
| 106 | executing with its MMU and caches enabled, and when it's running with its MMU |
| 107 | and caches disabled. Examples are given below. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 108 | |
| 109 | The following variables, functions and constants must be defined by the platform |
| 110 | for the firmware to work correctly. |
| 111 | |
| 112 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 113 | ### File : platform_def.h [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 114 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 115 | Each platform must ensure that a header file of this name is in the system |
| 116 | include path with the following constants defined. This may require updating the |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 117 | list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM development |
| 118 | platforms, this file is found in `plat/arm/board/<plat_name>/include/`. |
| 119 | |
| 120 | Platform ports may optionally use the file [include/plat/common/common_def.h], |
| 121 | which provides typical values for some of the constants below. These values are |
| 122 | likely to be suitable for all platform ports. |
| 123 | |
| 124 | Platform ports that want to be aligned with standard ARM platforms (for example |
| 125 | FVP and Juno) may also use [include/plat/arm/common/arm_def.h], which provides |
| 126 | standard values for some of the constants below. However, this requires the |
| 127 | platform port to define additional platform porting constants in |
| 128 | `platform_def.h`. These additional constants are not documented here. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 129 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 130 | * **#define : PLATFORM_LINKER_FORMAT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 131 | |
| 132 | Defines the linker format used by the platform, for example |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 133 | `elf64-littleaarch64`. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 134 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 135 | * **#define : PLATFORM_LINKER_ARCH** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 136 | |
| 137 | Defines the processor architecture for the linker by the platform, for |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 138 | example `aarch64`. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 139 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 140 | * **#define : PLATFORM_STACK_SIZE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 141 | |
| 142 | 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] | 143 | by [plat/common/aarch64/platform_mp_stack.S] and |
| 144 | [plat/common/aarch64/platform_up_stack.S]. |
| 145 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 146 | * **define : CACHE_WRITEBACK_GRANULE** |
| 147 | |
| 148 | Defines the size in bits of the largest cache line across all the cache |
| 149 | levels in the platform. |
| 150 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 151 | * **#define : FIRMWARE_WELCOME_STR** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 152 | |
| 153 | Defines the character string printed by BL1 upon entry into the `bl1_main()` |
| 154 | function. |
| 155 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 156 | * **#define : PLATFORM_CORE_COUNT** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 157 | |
| 158 | Defines the total number of CPUs implemented by the platform across all |
| 159 | clusters in the system. |
| 160 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 161 | * **#define : PLAT_NUM_PWR_DOMAINS** |
Andrew Thoelke | 6c0b45d | 2014-06-20 00:36:14 +0100 | [diff] [blame] | 162 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 163 | Defines the total number of nodes in the power domain topology |
| 164 | tree at all the power domain levels used by the platform. |
| 165 | This macro is used by the PSCI implementation to allocate |
| 166 | data structures to represent power domain topology. |
Andrew Thoelke | 6c0b45d | 2014-06-20 00:36:14 +0100 | [diff] [blame] | 167 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 168 | * **#define : PLAT_MAX_PWR_LVL** |
Soby Mathew | 8c32bc2 | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 169 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 170 | Defines the maximum power domain level that the power management operations |
| 171 | should apply to. More often, but not always, the power domain level |
| 172 | corresponds to affinity level. This macro allows the PSCI implementation |
| 173 | to know the highest power domain level that it should consider for power |
| 174 | management operations in the system that the platform implements. For |
| 175 | example, the Base AEM FVP implements two clusters with a configurable |
| 176 | number of CPUs and it reports the maximum power domain level as 1. |
| 177 | |
| 178 | * **#define : PLAT_MAX_OFF_STATE** |
| 179 | |
| 180 | Defines the local power state corresponding to the deepest power down |
| 181 | possible at every power domain level in the platform. The local power |
| 182 | states for each level may be sparsely allocated between 0 and this value |
| 183 | with 0 being reserved for the RUN state. The PSCI implementation uses this |
| 184 | value to initialize the local power states of the power domain nodes and |
| 185 | to specify the requested power state for a PSCI_CPU_OFF call. |
| 186 | |
| 187 | * **#define : PLAT_MAX_RET_STATE** |
| 188 | |
| 189 | Defines the local power state corresponding to the deepest retention state |
| 190 | possible at every power domain level in the platform. This macro should be |
| 191 | a value less than PLAT_MAX_OFF_STATE and greater than 0. It is used by the |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 192 | PSCI implementation to distinguish between retention and power down local |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 193 | power states within PSCI_CPU_SUSPEND call. |
Soby Mathew | 8c32bc2 | 2015-02-12 14:45:02 +0000 | [diff] [blame] | 194 | |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 195 | * **#define : PLAT_MAX_PWR_LVL_STATES** |
| 196 | |
| 197 | Defines the maximum number of local power states per power domain level |
| 198 | that the platform supports. The default value of this macro is 2 since |
| 199 | most platforms just support a maximum of two local power states at each |
| 200 | power domain level (power-down and retention). If the platform needs to |
| 201 | account for more local power states, then it must redefine this macro. |
| 202 | |
| 203 | Currently, this macro is used by the Generic PSCI implementation to size |
| 204 | the array used for PSCI_STAT_COUNT/RESIDENCY accounting. |
| 205 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 206 | * **#define : BL1_RO_BASE** |
| 207 | |
| 208 | Defines the base address in secure ROM where BL1 originally lives. Must be |
| 209 | aligned on a page-size boundary. |
| 210 | |
| 211 | * **#define : BL1_RO_LIMIT** |
| 212 | |
| 213 | Defines the maximum address in secure ROM that BL1's actual content (i.e. |
| 214 | excluding any data section allocated at runtime) can occupy. |
| 215 | |
| 216 | * **#define : BL1_RW_BASE** |
| 217 | |
| 218 | Defines the base address in secure RAM where BL1's read-write data will live |
| 219 | at runtime. Must be aligned on a page-size boundary. |
| 220 | |
| 221 | * **#define : BL1_RW_LIMIT** |
| 222 | |
| 223 | Defines the maximum address in secure RAM that BL1's read-write data can |
| 224 | occupy at runtime. |
| 225 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 226 | * **#define : BL2_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 227 | |
| 228 | 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] | 229 | Must be aligned on a page-size boundary. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 230 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 231 | * **#define : BL2_LIMIT** |
| 232 | |
| 233 | Defines the maximum address in secure RAM that the BL2 image can occupy. |
| 234 | |
James Morrissey | ba3155b | 2013-10-29 10:56:46 +0000 | [diff] [blame] | 235 | * **#define : BL31_BASE** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 236 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 237 | Defines the base address in secure RAM where BL2 loads the BL31 binary |
Sandrine Bailleux | cd29b0a | 2013-11-27 10:32:17 +0000 | [diff] [blame] | 238 | image. Must be aligned on a page-size boundary. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 239 | |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 240 | * **#define : BL31_LIMIT** |
| 241 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 242 | Defines the maximum address in secure RAM that the BL31 image can occupy. |
Sandrine Bailleux | 638363e | 2014-05-21 17:08:26 +0100 | [diff] [blame] | 243 | |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 244 | For every image, the platform must define individual identifiers that will be |
| 245 | used by BL1 or BL2 to load the corresponding image into memory from non-volatile |
| 246 | storage. For the sake of performance, integer numbers will be used as |
| 247 | identifiers. The platform will use those identifiers to return the relevant |
| 248 | information about the image to be loaded (file handler, load address, |
| 249 | authentication information, etc.). The following image identifiers are |
| 250 | mandatory: |
| 251 | |
| 252 | * **#define : BL2_IMAGE_ID** |
| 253 | |
| 254 | BL2 image identifier, used by BL1 to load BL2. |
| 255 | |
| 256 | * **#define : BL31_IMAGE_ID** |
| 257 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 258 | BL31 image identifier, used by BL2 to load BL31. |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 259 | |
| 260 | * **#define : BL33_IMAGE_ID** |
| 261 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 262 | BL33 image identifier, used by BL2 to load BL33. |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 263 | |
| 264 | If Trusted Board Boot is enabled, the following certificate identifiers must |
| 265 | also be defined: |
| 266 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 267 | * **#define : TRUSTED_BOOT_FW_CERT_ID** |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 268 | |
| 269 | BL2 content certificate identifier, used by BL1 to load the BL2 content |
| 270 | certificate. |
| 271 | |
| 272 | * **#define : TRUSTED_KEY_CERT_ID** |
| 273 | |
| 274 | Trusted key certificate identifier, used by BL2 to load the trusted key |
| 275 | certificate. |
| 276 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 277 | * **#define : SOC_FW_KEY_CERT_ID** |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 278 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 279 | BL31 key certificate identifier, used by BL2 to load the BL31 key |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 280 | certificate. |
| 281 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 282 | * **#define : SOC_FW_CONTENT_CERT_ID** |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 283 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 284 | BL31 content certificate identifier, used by BL2 to load the BL31 content |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 285 | certificate. |
| 286 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 287 | * **#define : NON_TRUSTED_FW_KEY_CERT_ID** |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 288 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 289 | BL33 key certificate identifier, used by BL2 to load the BL33 key |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 290 | certificate. |
| 291 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 292 | * **#define : NON_TRUSTED_FW_CONTENT_CERT_ID** |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 293 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 294 | BL33 content certificate identifier, used by BL2 to load the BL33 content |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 295 | certificate. |
| 296 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 297 | * **#define : FWU_CERT_ID** |
| 298 | |
| 299 | Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the |
| 300 | FWU content certificate. |
| 301 | |
| 302 | |
| 303 | If the AP Firmware Updater Configuration image, BL2U is used, the following |
| 304 | must also be defined: |
| 305 | |
| 306 | * **#define : BL2U_BASE** |
| 307 | |
| 308 | Defines the base address in secure memory where BL1 copies the BL2U binary |
| 309 | image. Must be aligned on a page-size boundary. |
| 310 | |
| 311 | * **#define : BL2U_LIMIT** |
| 312 | |
| 313 | Defines the maximum address in secure memory that the BL2U image can occupy. |
| 314 | |
| 315 | * **#define : BL2U_IMAGE_ID** |
| 316 | |
| 317 | BL2U image identifier, used by BL1 to fetch an image descriptor |
| 318 | corresponding to BL2U. |
| 319 | |
| 320 | If the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following |
| 321 | must also be defined: |
| 322 | |
| 323 | * **#define : SCP_BL2U_IMAGE_ID** |
| 324 | |
| 325 | SCP_BL2U image identifier, used by BL1 to fetch an image descriptor |
| 326 | corresponding to SCP_BL2U. |
| 327 | NOTE: TF does not provide source code for this image. |
| 328 | |
| 329 | If the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must |
| 330 | also be defined: |
| 331 | |
| 332 | * **#define : NS_BL1U_BASE** |
| 333 | |
| 334 | Defines the base address in non-secure ROM where NS_BL1U executes. |
| 335 | Must be aligned on a page-size boundary. |
| 336 | NOTE: TF does not provide source code for this image. |
| 337 | |
| 338 | * **#define : NS_BL1U_IMAGE_ID** |
| 339 | |
| 340 | NS_BL1U image identifier, used by BL1 to fetch an image descriptor |
| 341 | corresponding to NS_BL1U. |
| 342 | |
| 343 | If the Non-Secure Firmware Updater, NS_BL2U is used, the following must also |
| 344 | be defined: |
| 345 | |
| 346 | * **#define : NS_BL2U_BASE** |
| 347 | |
| 348 | Defines the base address in non-secure memory where NS_BL2U executes. |
| 349 | Must be aligned on a page-size boundary. |
| 350 | NOTE: TF does not provide source code for this image. |
| 351 | |
| 352 | * **#define : NS_BL2U_IMAGE_ID** |
| 353 | |
| 354 | NS_BL2U image identifier, used by BL1 to fetch an image descriptor |
| 355 | corresponding to NS_BL2U. |
| 356 | |
| 357 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 358 | If a SCP_BL2 image is supported by the platform, the following constants must |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 359 | also be defined: |
| 360 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 361 | * **#define : SCP_BL2_IMAGE_ID** |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 362 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 363 | SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory |
| 364 | from platform storage before being transfered to the SCP. |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 365 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 366 | * **#define : SCP_FW_KEY_CERT_ID** |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 367 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 368 | SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 369 | certificate (mandatory when Trusted Board Boot is enabled). |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 370 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 371 | * **#define : SCP_FW_CONTENT_CERT_ID** |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 372 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 373 | SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2 |
| 374 | content certificate (mandatory when Trusted Board Boot is enabled). |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 375 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 376 | If a BL32 image is supported by the platform, the following constants must |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 377 | also be defined: |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 378 | |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 379 | * **#define : BL32_IMAGE_ID** |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 380 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 381 | BL32 image identifier, used by BL2 to load BL32. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 382 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 383 | * **#define : TRUSTED_OS_FW_KEY_CERT_ID** |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 384 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 385 | BL32 key certificate identifier, used by BL2 to load the BL32 key |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 386 | certificate (mandatory when Trusted Board Boot is enabled). |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 387 | |
Juan Castillo | 516beb5 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 388 | * **#define : TRUSTED_OS_FW_CONTENT_CERT_ID** |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 389 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 390 | BL32 content certificate identifier, used by BL2 to load the BL32 content |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 391 | certificate (mandatory when Trusted Board Boot is enabled). |
Achin Gupta | 8d35f61 | 2015-01-25 22:44:23 +0000 | [diff] [blame] | 392 | |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 393 | * **#define : BL32_BASE** |
| 394 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 395 | Defines the base address in secure memory where BL2 loads the BL32 binary |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 396 | image. Must be aligned on a page-size boundary. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 397 | |
| 398 | * **#define : BL32_LIMIT** |
| 399 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 400 | Defines the maximum address that the BL32 image can occupy. |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 401 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 402 | If the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 403 | platform, the following constants must also be defined: |
| 404 | |
| 405 | * **#define : TSP_SEC_MEM_BASE** |
| 406 | |
| 407 | Defines the base address of the secure memory used by the TSP image on the |
| 408 | platform. This must be at the same address or below `BL32_BASE`. |
| 409 | |
| 410 | * **#define : TSP_SEC_MEM_SIZE** |
| 411 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 412 | Defines the size of the secure memory used by the BL32 image on the |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 413 | platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 414 | the memory required by the BL32 image, defined by `BL32_BASE` and |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 415 | `BL32_LIMIT`. |
| 416 | |
| 417 | * **#define : TSP_IRQ_SEC_PHY_TIMER** |
| 418 | |
| 419 | Defines the ID of the secure physical generic timer interrupt used by the |
| 420 | TSP's interrupt handling code. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 421 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 422 | If the platform port uses the translation table library code, the following |
| 423 | constant must also be defined: |
| 424 | |
| 425 | * **#define : MAX_XLAT_TABLES** |
| 426 | |
| 427 | Defines the maximum number of translation tables that are allocated by the |
| 428 | translation table library code. To minimize the amount of runtime memory |
| 429 | used, choose the smallest value needed to map the required virtual addresses |
| 430 | for each BL stage. |
| 431 | |
Juan Castillo | 359b60d | 2016-01-07 11:29:15 +0000 | [diff] [blame] | 432 | * **#define : MAX_MMAP_REGIONS** |
| 433 | |
| 434 | Defines the maximum number of regions that are allocated by the translation |
| 435 | table library code. A region consists of physical base address, virtual base |
| 436 | address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as |
| 437 | defined in the `mmap_region_t` structure. The platform defines the regions |
| 438 | that should be mapped. Then, the translation table library will create the |
| 439 | corresponding tables and descriptors at runtime. To minimize the amount of |
| 440 | runtime memory used, choose the smallest value needed to register the |
| 441 | required regions for each BL stage. |
| 442 | |
| 443 | * **#define : ADDR_SPACE_SIZE** |
| 444 | |
| 445 | Defines the total size of the address space in bytes. For example, for a 32 |
Antonio Nino Diaz | 0029624 | 2016-12-13 15:28:54 +0000 | [diff] [blame] | 446 | bit address space, this value should be `(1ull << 32)`. This definition is |
| 447 | now deprecated, platforms should use `PLAT_PHY_ADDR_SPACE_SIZE` and |
| 448 | `PLAT_VIRT_ADDR_SPACE_SIZE` instead. |
| 449 | |
| 450 | * **#define : PLAT_VIRT_ADDR_SPACE_SIZE** |
| 451 | |
| 452 | Defines the total size of the virtual address space in bytes. For example, |
| 453 | for a 32 bit virtual address space, this value should be `(1ull << 32)`. |
| 454 | |
| 455 | * **#define : PLAT_PHY_ADDR_SPACE_SIZE** |
| 456 | |
| 457 | Defines the total size of the physical address space in bytes. For example, |
| 458 | for a 32 bit physical address space, this value should be `(1ull << 32)`. |
Juan Castillo | 359b60d | 2016-01-07 11:29:15 +0000 | [diff] [blame] | 459 | |
Dan Handley | 6d16ce0 | 2014-08-04 18:31:43 +0100 | [diff] [blame] | 460 | If the platform port uses the IO storage framework, the following constants |
| 461 | must also be defined: |
| 462 | |
| 463 | * **#define : MAX_IO_DEVICES** |
| 464 | |
| 465 | Defines the maximum number of registered IO devices. Attempting to register |
| 466 | more devices than this value using `io_register_device()` will fail with |
Juan Castillo | 7e26fe1 | 2015-10-01 17:55:11 +0100 | [diff] [blame] | 467 | -ENOMEM. |
Dan Handley | 6d16ce0 | 2014-08-04 18:31:43 +0100 | [diff] [blame] | 468 | |
| 469 | * **#define : MAX_IO_HANDLES** |
| 470 | |
| 471 | Defines the maximum number of open IO handles. Attempting to open more IO |
Juan Castillo | 7e26fe1 | 2015-10-01 17:55:11 +0100 | [diff] [blame] | 472 | entities than this value using `io_open()` will fail with -ENOMEM. |
Dan Handley | 6d16ce0 | 2014-08-04 18:31:43 +0100 | [diff] [blame] | 473 | |
Haojian Zhuang | 08b375b | 2016-04-21 10:52:52 +0800 | [diff] [blame] | 474 | * **#define : MAX_IO_BLOCK_DEVICES** |
| 475 | |
| 476 | Defines the maximum number of registered IO block devices. Attempting to |
| 477 | register more devices this value using `io_dev_open()` will fail |
| 478 | with -ENOMEM. MAX_IO_BLOCK_DEVICES should be less than MAX_IO_DEVICES. |
| 479 | With this macro, multiple block devices could be supported at the same |
| 480 | time. |
| 481 | |
Soby Mathew | ab8707e | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 482 | If the platform needs to allocate data within the per-cpu data framework in |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 483 | BL31, it should define the following macro. Currently this is only required if |
Soby Mathew | ab8707e | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 484 | the platform decides not to use the coherent memory section by undefining the |
Sandrine Bailleux | 1645d3e | 2015-12-17 13:58:58 +0000 | [diff] [blame] | 485 | `USE_COHERENT_MEM` build flag. In this case, the framework allocates the |
| 486 | required memory within the the per-cpu data to minimize wastage. |
Soby Mathew | ab8707e | 2015-01-08 18:02:44 +0000 | [diff] [blame] | 487 | |
| 488 | * **#define : PLAT_PCPU_DATA_SIZE** |
| 489 | |
| 490 | Defines the memory (in bytes) to be reserved within the per-cpu data |
| 491 | structure for use by the platform layer. |
| 492 | |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 493 | The following constants are optional. They should be defined when the platform |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 494 | memory layout implies some image overlaying like in ARM standard platforms. |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 495 | |
| 496 | * **#define : BL31_PROGBITS_LIMIT** |
| 497 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 498 | Defines the maximum address in secure RAM that the BL31's progbits sections |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 499 | can occupy. |
| 500 | |
Dan Handley | 5a06bb7 | 2014-08-04 11:41:20 +0100 | [diff] [blame] | 501 | * **#define : TSP_PROGBITS_LIMIT** |
Sandrine Bailleux | 46d49f63 | 2014-06-23 17:00:23 +0100 | [diff] [blame] | 502 | |
| 503 | Defines the maximum address that the TSP's progbits sections can occupy. |
Sandrine Bailleux | 2467f70 | 2014-05-20 17:22:24 +0100 | [diff] [blame] | 504 | |
Haojian Zhuang | 7dc4b22 | 2016-02-03 22:35:04 +0800 | [diff] [blame] | 505 | If the platform port uses the PL061 GPIO driver, the following constant may |
| 506 | optionally be defined: |
| 507 | |
| 508 | * **PLAT_PL061_MAX_GPIOS** |
| 509 | Maximum number of GPIOs required by the platform. This allows control how |
| 510 | much memory is allocated for PL061 GPIO controllers. The default value is |
| 511 | 32. |
| 512 | [For example, define the build flag in platform.mk]: |
| 513 | PLAT_PL061_MAX_GPIOS := 160 |
| 514 | $(eval $(call add_define,PLAT_PL061_MAX_GPIOS)) |
| 515 | |
Haojian Zhuang | 7813aae | 2016-08-17 21:05:07 +0800 | [diff] [blame] | 516 | If the platform port uses the partition driver, the following constant may |
| 517 | optionally be defined: |
| 518 | |
| 519 | * **PLAT_PARTITION_MAX_ENTRIES** |
| 520 | Maximum number of partition entries required by the platform. This allows |
| 521 | control how much memory is allocated for partition entries. The default |
| 522 | value is 128. |
| 523 | [For example, define the build flag in platform.mk]: |
| 524 | PLAT_PARTITION_MAX_ENTRIES := 12 |
| 525 | $(eval $(call add_define,PLAT_PARTITION_MAX_ENTRIES)) |
| 526 | |
Haojian Zhuang | 7dc4b22 | 2016-02-03 22:35:04 +0800 | [diff] [blame] | 527 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 528 | ### File : plat_macros.S [mandatory] |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 529 | |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 530 | 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] | 531 | the following macro defined. In the ARM development platforms, this file is |
| 532 | found in `plat/arm/board/<plat_name>/include/plat_macros.S`. |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 533 | |
Gerald Lejeune | 9ff67fa | 2015-11-26 15:47:53 +0100 | [diff] [blame] | 534 | * **Macro : plat_crash_print_regs** |
Soby Mathew | a43d431 | 2014-04-07 15:28:55 +0100 | [diff] [blame] | 535 | |
Gerald Lejeune | 9ff67fa | 2015-11-26 15:47:53 +0100 | [diff] [blame] | 536 | This macro allows the crash reporting routine to print relevant platform |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 537 | registers in case of an unhandled exception in BL31. This aids in debugging |
Gerald Lejeune | 9ff67fa | 2015-11-26 15:47:53 +0100 | [diff] [blame] | 538 | and this macro can be defined to be empty in case register reporting is not |
| 539 | desired. |
| 540 | |
| 541 | For instance, GIC or interconnect registers may be helpful for |
| 542 | troubleshooting. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 543 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 544 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 545 | 2.2 Handling Reset |
| 546 | ------------------ |
| 547 | |
| 548 | BL1 by default implements the reset vector where execution starts from a cold |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 549 | or warm boot. BL31 can be optionally set as a reset vector using the |
Sandrine Bailleux | 1645d3e | 2015-12-17 13:58:58 +0000 | [diff] [blame] | 550 | `RESET_TO_BL31` make variable. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 551 | |
| 552 | For each CPU, the reset vector code is responsible for the following tasks: |
| 553 | |
| 554 | 1. Distinguishing between a cold boot and a warm boot. |
| 555 | |
| 556 | 2. In the case of a cold boot and the CPU being a secondary CPU, ensuring that |
| 557 | the CPU is placed in a platform-specific state until the primary CPU |
| 558 | performs the necessary steps to remove it from this state. |
| 559 | |
| 560 | 3. In the case of a warm boot, ensuring that the CPU jumps to a platform- |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 561 | specific address in the BL31 image in the same processor mode as it was |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 562 | when released from reset. |
| 563 | |
| 564 | The following functions need to be implemented by the platform port to enable |
| 565 | reset vector code to perform the above tasks. |
| 566 | |
| 567 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 568 | ### Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0] |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 569 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 570 | Argument : void |
Soby Mathew | 4c0d039 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 571 | Return : uintptr_t |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 572 | |
Masahiro Yamada | ba21b75 | 2016-10-23 01:15:21 +0900 | [diff] [blame] | 573 | This function is called with the MMU and caches disabled |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 574 | (`SCTLR_EL3.M` = 0 and `SCTLR_EL3.C` = 0). The function is responsible for |
| 575 | distinguishing between a warm and cold reset for the current CPU using |
| 576 | platform-specific means. If it's a warm reset, then it returns the warm |
| 577 | reset entrypoint point provided to `plat_setup_psci_ops()` during |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 578 | BL31 initialization. If it's a cold reset then this function must return zero. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 579 | |
| 580 | This function does not follow the Procedure Call Standard used by the |
| 581 | Application Binary Interface for the ARM 64-bit architecture. The caller should |
| 582 | not assume that callee saved registers are preserved across a call to this |
| 583 | function. |
| 584 | |
| 585 | This function fulfills requirement 1 and 3 listed above. |
| 586 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 587 | Note that for platforms that support programming the reset address, it is |
| 588 | expected that a CPU will start executing code directly at the right address, |
| 589 | both on a cold and warm reset. In this case, there is no need to identify the |
| 590 | type of reset nor to query the warm reset entrypoint. Therefore, implementing |
| 591 | this function is not required on such platforms. |
| 592 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 593 | |
Sandrine Bailleux | a9bec67 | 2015-10-30 15:05:17 +0000 | [diff] [blame] | 594 | ### Function : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0] |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 595 | |
| 596 | Argument : void |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 597 | |
| 598 | This function is called with the MMU and data caches disabled. It is responsible |
| 599 | for placing the executing secondary CPU in a platform-specific state until the |
| 600 | primary CPU performs the necessary actions to bring it out of that state and |
Sandrine Bailleux | 52010cc | 2015-05-19 11:54:45 +0100 | [diff] [blame] | 601 | allow entry into the OS. This function must not return. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 602 | |
Sandrine Bailleux | cdf1408 | 2015-10-02 14:35:25 +0100 | [diff] [blame] | 603 | In the ARM FVP port, when using the normal boot flow, each secondary CPU powers |
| 604 | itself off. The primary CPU is responsible for powering up the secondary CPUs |
| 605 | when normal world software requires them. When booting an EL3 payload instead, |
| 606 | they stay powered on and are put in a holding pen until their mailbox gets |
| 607 | populated. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 608 | |
| 609 | This function fulfills requirement 2 above. |
| 610 | |
Sandrine Bailleux | a9bec67 | 2015-10-30 15:05:17 +0000 | [diff] [blame] | 611 | Note that for platforms that can't release secondary CPUs out of reset, only the |
| 612 | primary CPU will execute the cold boot code. Therefore, implementing this |
| 613 | function is not required on such platforms. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 614 | |
Sandrine Bailleux | a9bec67 | 2015-10-30 15:05:17 +0000 | [diff] [blame] | 615 | |
| 616 | ### Function : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0] |
Juan Castillo | 53fdceb | 2014-07-16 15:53:43 +0100 | [diff] [blame] | 617 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 618 | Argument : void |
Juan Castillo | 53fdceb | 2014-07-16 15:53:43 +0100 | [diff] [blame] | 619 | Return : unsigned int |
| 620 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 621 | This function identifies whether the current CPU is the primary CPU or a |
| 622 | secondary CPU. A return value of zero indicates that the CPU is not the |
| 623 | primary CPU, while a non-zero return value indicates that the CPU is the |
| 624 | primary CPU. |
Juan Castillo | 53fdceb | 2014-07-16 15:53:43 +0100 | [diff] [blame] | 625 | |
Sandrine Bailleux | a9bec67 | 2015-10-30 15:05:17 +0000 | [diff] [blame] | 626 | Note that for platforms that can't release secondary CPUs out of reset, only the |
| 627 | primary CPU will execute the cold boot code. Therefore, there is no need to |
| 628 | distinguish between primary and secondary CPUs and implementing this function is |
| 629 | not required. |
| 630 | |
Juan Castillo | 53fdceb | 2014-07-16 15:53:43 +0100 | [diff] [blame] | 631 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 632 | ### Function : platform_mem_init() [mandatory] |
| 633 | |
| 634 | Argument : void |
| 635 | Return : void |
| 636 | |
| 637 | This function is called before any access to data is made by the firmware, in |
| 638 | order to carry out any essential memory initialization. |
| 639 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 640 | |
Juan Castillo | 95cfd4a | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 641 | ### Function: plat_get_rotpk_info() |
| 642 | |
| 643 | Argument : void *, void **, unsigned int *, unsigned int * |
| 644 | Return : int |
| 645 | |
| 646 | This function is mandatory when Trusted Board Boot is enabled. It returns a |
| 647 | pointer to the ROTPK stored in the platform (or a hash of it) and its length. |
| 648 | The ROTPK must be encoded in DER format according to the following ASN.1 |
| 649 | structure: |
| 650 | |
| 651 | AlgorithmIdentifier ::= SEQUENCE { |
| 652 | algorithm OBJECT IDENTIFIER, |
| 653 | parameters ANY DEFINED BY algorithm OPTIONAL |
| 654 | } |
| 655 | |
| 656 | SubjectPublicKeyInfo ::= SEQUENCE { |
| 657 | algorithm AlgorithmIdentifier, |
| 658 | subjectPublicKey BIT STRING |
| 659 | } |
| 660 | |
| 661 | In case the function returns a hash of the key: |
| 662 | |
| 663 | DigestInfo ::= SEQUENCE { |
| 664 | digestAlgorithm AlgorithmIdentifier, |
| 665 | digest OCTET STRING |
| 666 | } |
| 667 | |
Soby Mathew | 04943d3 | 2016-05-24 15:05:15 +0100 | [diff] [blame] | 668 | The function returns 0 on success. Any other value is treated as error by the |
| 669 | Trusted Board Boot. The function also reports extra information related |
| 670 | to the ROTPK in the flags parameter: |
Juan Castillo | 95cfd4a | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 671 | |
Soby Mathew | 04943d3 | 2016-05-24 15:05:15 +0100 | [diff] [blame] | 672 | ROTPK_IS_HASH : Indicates that the ROTPK returned by the platform is a |
| 673 | hash. |
| 674 | ROTPK_NOT_DEPLOYED : This allows the platform to skip certificate ROTPK |
| 675 | verification while the platform ROTPK is not deployed. |
| 676 | When this flag is set, the function does not need to |
| 677 | return a platform ROTPK, and the authentication |
| 678 | framework uses the ROTPK in the certificate without |
| 679 | verifying it against the platform value. This flag |
| 680 | must not be used in a deployed production environment. |
Juan Castillo | 95cfd4a | 2015-04-14 12:49:03 +0100 | [diff] [blame] | 681 | |
Juan Castillo | 48279d5 | 2016-01-22 11:05:57 +0000 | [diff] [blame] | 682 | ### Function: plat_get_nv_ctr() |
| 683 | |
| 684 | Argument : void *, unsigned int * |
| 685 | Return : int |
| 686 | |
| 687 | This function is mandatory when Trusted Board Boot is enabled. It returns the |
| 688 | non-volatile counter value stored in the platform in the second argument. The |
| 689 | cookie in the first argument may be used to select the counter in case the |
| 690 | platform provides more than one (for example, on platforms that use the default |
| 691 | TBBR CoT, the cookie will correspond to the OID values defined in |
| 692 | TRUSTED_FW_NVCOUNTER_OID or NON_TRUSTED_FW_NVCOUNTER_OID). |
| 693 | |
| 694 | The function returns 0 on success. Any other value means the counter value could |
| 695 | not be retrieved from the platform. |
| 696 | |
| 697 | |
| 698 | ### Function: plat_set_nv_ctr() |
| 699 | |
| 700 | Argument : void *, unsigned int |
| 701 | Return : int |
| 702 | |
| 703 | This function is mandatory when Trusted Board Boot is enabled. It sets a new |
| 704 | counter value in the platform. The cookie in the first argument may be used to |
dp-arm | d35dee2 | 2016-12-12 14:48:13 +0000 | [diff] [blame] | 705 | select the counter (as explained in plat_get_nv_ctr()). The second argument is |
| 706 | the updated counter value to be written to the NV counter. |
Juan Castillo | 48279d5 | 2016-01-22 11:05:57 +0000 | [diff] [blame] | 707 | |
| 708 | The function returns 0 on success. Any other value means the counter value could |
| 709 | not be updated. |
| 710 | |
| 711 | |
dp-arm | d35dee2 | 2016-12-12 14:48:13 +0000 | [diff] [blame] | 712 | ### Function: plat_set_nv_ctr2() |
| 713 | |
| 714 | Argument : void *, const auth_img_desc_t *, unsigned int |
| 715 | Return : int |
| 716 | |
| 717 | This function is optional when Trusted Board Boot is enabled. If this |
| 718 | interface is defined, then `plat_set_nv_ctr()` need not be defined. The |
| 719 | first argument passed is a cookie and is typically used to |
| 720 | differentiate between a Non Trusted NV Counter and a Trusted NV |
| 721 | Counter. The second argument is a pointer to an authentication image |
| 722 | descriptor and may be used to decide if the counter is allowed to be |
| 723 | updated or not. The third argument is the updated counter value to |
| 724 | be written to the NV counter. |
| 725 | |
| 726 | The function returns 0 on success. Any other value means the counter value |
| 727 | either could not be updated or the authentication image descriptor indicates |
| 728 | that it is not allowed to be updated. |
| 729 | |
| 730 | |
Jeenu Viswambharan | ec2653a | 2016-10-11 11:43:04 +0100 | [diff] [blame] | 731 | 2.3 Common mandatory function modifications |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 732 | --------------------------------- |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 733 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 734 | The following functions are mandatory functions which need to be implemented |
| 735 | by the platform port. |
| 736 | |
| 737 | ### Function : plat_my_core_pos() |
| 738 | |
| 739 | Argument : void |
| 740 | Return : unsigned int |
| 741 | |
| 742 | This funtion returns the index of the calling CPU which is used as a |
| 743 | CPU-specific linear index into blocks of memory (for example while allocating |
| 744 | per-CPU stacks). This function will be invoked very early in the |
| 745 | initialization sequence which mandates that this function should be |
| 746 | implemented in assembly and should not rely on the avalability of a C |
Antonio Nino Diaz | e584673 | 2016-02-08 10:39:42 +0000 | [diff] [blame] | 747 | runtime environment. This function can clobber x0 - x8 and must preserve |
| 748 | x9 - x29. |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 749 | |
| 750 | This function plays a crucial role in the power domain topology framework in |
| 751 | PSCI and details of this can be found in [Power Domain Topology Design]. |
| 752 | |
| 753 | ### Function : plat_core_pos_by_mpidr() |
| 754 | |
| 755 | Argument : u_register_t |
| 756 | Return : int |
| 757 | |
| 758 | This function validates the `MPIDR` of a CPU and converts it to an index, |
| 759 | which can be used as a CPU-specific linear index into blocks of memory. In |
| 760 | case the `MPIDR` is invalid, this function returns -1. This function will only |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 761 | be invoked by BL31 after the power domain topology is initialized and can |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 762 | utilize the C runtime environment. For further details about how ARM Trusted |
| 763 | Firmware represents the power domain topology and how this relates to the |
| 764 | linear CPU index, please refer [Power Domain Topology Design]. |
| 765 | |
| 766 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 767 | 2.4 Common optional modifications |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 768 | --------------------------------- |
| 769 | |
| 770 | The following are helper functions implemented by the firmware that perform |
| 771 | common platform-specific tasks. A platform may choose to override these |
| 772 | definitions. |
| 773 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 774 | ### Function : plat_set_my_stack() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 775 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 776 | Argument : void |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 777 | Return : void |
| 778 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 779 | This function sets the current stack pointer to the normal memory stack that |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 780 | has been allocated for the current CPU. For BL images that only require a |
| 781 | stack for the primary CPU, the UP version of the function is used. The size |
| 782 | of the stack allocated to each CPU is specified by the platform defined |
| 783 | constant `PLATFORM_STACK_SIZE`. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 784 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 785 | Common implementations of this function for the UP and MP BL images are |
| 786 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 787 | [plat/common/aarch64/platform_mp_stack.S] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 788 | |
| 789 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 790 | ### Function : plat_get_my_stack() |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 791 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 792 | Argument : void |
Soby Mathew | 4c0d039 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 793 | Return : uintptr_t |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 794 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 795 | This function returns the base address of the normal memory stack that |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 796 | has been allocated for the current CPU. For BL images that only require a |
| 797 | stack for the primary CPU, the UP version of the function is used. The size |
| 798 | of the stack allocated to each CPU is specified by the platform defined |
| 799 | constant `PLATFORM_STACK_SIZE`. |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 800 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 801 | Common implementations of this function for the UP and MP BL images are |
| 802 | provided in [plat/common/aarch64/platform_up_stack.S] and |
| 803 | [plat/common/aarch64/platform_mp_stack.S] |
Achin Gupta | c8afc78 | 2013-11-25 18:45:02 +0000 | [diff] [blame] | 804 | |
| 805 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 806 | ### Function : plat_report_exception() |
| 807 | |
| 808 | Argument : unsigned int |
| 809 | Return : void |
| 810 | |
| 811 | A platform may need to report various information about its status when an |
| 812 | exception is taken, for example the current exception level, the CPU security |
| 813 | state (secure/non-secure), the exception type, and so on. This function is |
| 814 | called in the following circumstances: |
| 815 | |
| 816 | * In BL1, whenever an exception is taken. |
| 817 | * In BL2, whenever an exception is taken. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 818 | |
| 819 | The default implementation doesn't do anything, to avoid making assumptions |
| 820 | about the way the platform displays its status information. |
| 821 | |
Yatharth Kochar | 1a0a3f0 | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 822 | For AArch64, this function receives the exception type as its argument. |
| 823 | Possible values for exceptions types are listed in the |
| 824 | [include/common/bl_common.h] header file. Note that these constants are not |
| 825 | related to any architectural exception code; they are just an ARM Trusted |
| 826 | Firmware convention. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 827 | |
Yatharth Kochar | 1a0a3f0 | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 828 | For AArch32, this function receives the exception mode as its argument. |
| 829 | Possible values for exception modes are listed in the |
| 830 | [include/lib/aarch32/arch.h] header file. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 831 | |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 832 | ### Function : plat_reset_handler() |
| 833 | |
| 834 | Argument : void |
| 835 | Return : void |
| 836 | |
| 837 | A platform may need to do additional initialization after reset. This function |
| 838 | allows the platform to do the platform specific intializations. Platform |
| 839 | specific errata workarounds could also be implemented here. The api should |
Soby Mathew | 683f788 | 2015-01-29 12:00:58 +0000 | [diff] [blame] | 840 | preserve the values of callee saved registers x19 to x29. |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 841 | |
Yatharth Kochar | 79a97b2 | 2014-11-20 18:09:41 +0000 | [diff] [blame] | 842 | 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] | 843 | the default implementation, refer to the [Firmware Design] for general |
Sandrine Bailleux | 452b7fa | 2015-05-27 17:14:22 +0100 | [diff] [blame] | 844 | guidelines. |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 845 | |
Soby Mathew | add4035 | 2014-08-14 12:49:05 +0100 | [diff] [blame] | 846 | ### Function : plat_disable_acp() |
| 847 | |
| 848 | Argument : void |
| 849 | Return : void |
| 850 | |
| 851 | This api allows a platform to disable the Accelerator Coherency Port (if |
| 852 | present) during a cluster power down sequence. The default weak implementation |
| 853 | doesn't do anything. Since this api is called during the power down sequence, |
| 854 | it has restrictions for stack usage and it can use the registers x0 - x17 as |
| 855 | scratch registers. It should preserve the value in x18 register as it is used |
| 856 | by the caller to store the return address. |
| 857 | |
Juan Castillo | 40fc6cd | 2015-09-25 15:41:14 +0100 | [diff] [blame] | 858 | ### Function : plat_error_handler() |
| 859 | |
| 860 | Argument : int |
| 861 | Return : void |
| 862 | |
| 863 | This API is called when the generic code encounters an error situation from |
| 864 | which it cannot continue. It allows the platform to perform error reporting or |
| 865 | recovery actions (for example, reset the system). This function must not return. |
| 866 | |
| 867 | The parameter indicates the type of error using standard codes from `errno.h`. |
| 868 | Possible errors reported by the generic code are: |
| 869 | |
| 870 | * `-EAUTH`: a certificate or image could not be authenticated (when Trusted |
| 871 | Board Boot is enabled) |
| 872 | * `-ENOENT`: the requested image or certificate could not be found or an IO |
| 873 | error was detected |
| 874 | * `-ENOMEM`: resources exhausted. Trusted Firmware does not use dynamic |
| 875 | memory, so this error is usually an indication of an incorrect array size |
| 876 | |
| 877 | The default implementation simply spins. |
| 878 | |
Antonio Nino Diaz | 1c3ea10 | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 879 | ### Function : plat_panic_handler() |
| 880 | |
| 881 | Argument : void |
| 882 | Return : void |
| 883 | |
| 884 | This API is called when the generic code encounters an unexpected error |
| 885 | situation from which it cannot recover. This function must not return, |
| 886 | and must be implemented in assembly because it may be called before the C |
| 887 | environment is initialized. |
| 888 | |
| 889 | Note: The address from where it was called is stored in x30 (Link Register). |
Antonio Nino Diaz | 1c3ea10 | 2016-02-01 13:57:25 +0000 | [diff] [blame] | 890 | The default implementation simply spins. |
| 891 | |
Soby Mathew | 24fb838 | 2014-08-14 12:22:32 +0100 | [diff] [blame] | 892 | |
Yatharth Kochar | 7260022 | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 893 | ### Function : plat_get_bl_image_load_info() |
| 894 | |
| 895 | Argument : void |
| 896 | Return : bl_load_info_t * |
| 897 | |
| 898 | This function returns pointer to the list of images that the platform has |
| 899 | populated to load. This function is currently invoked in BL2 to load the |
| 900 | BL3xx images, when LOAD_IMAGE_V2 is enabled. |
| 901 | |
| 902 | ### Function : plat_get_next_bl_params() |
| 903 | |
| 904 | Argument : void |
| 905 | Return : bl_params_t * |
| 906 | |
| 907 | This function returns a pointer to the shared memory that the platform has |
| 908 | kept aside to pass trusted firmware related information that next BL image |
| 909 | needs. This function is currently invoked in BL2 to pass this information to |
| 910 | the next BL image, when LOAD_IMAGE_V2 is enabled. |
| 911 | |
| 912 | ### Function : plat_flush_next_bl_params() |
| 913 | |
| 914 | Argument : void |
| 915 | Return : void |
| 916 | |
| 917 | This function flushes to main memory all the image params that are passed to |
| 918 | next image. This function is currently invoked in BL2 to flush this information |
| 919 | to the next BL image, when LOAD_IMAGE_V2 is enabled. |
| 920 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 921 | 3. Modifications specific to a Boot Loader stage |
| 922 | ------------------------------------------------- |
| 923 | |
| 924 | 3.1 Boot Loader Stage 1 (BL1) |
| 925 | ----------------------------- |
| 926 | |
| 927 | BL1 implements the reset vector where execution starts from after a cold or |
| 928 | warm boot. For each CPU, BL1 is responsible for the following tasks: |
| 929 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 930 | 1. Handling the reset as described in section 2.2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 931 | |
| 932 | 2. In the case of a cold boot and the CPU being the primary CPU, ensuring that |
| 933 | only this CPU executes the remaining BL1 code, including loading and passing |
| 934 | control to the BL2 stage. |
| 935 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 936 | 3. Identifying and starting the Firmware Update process (if required). |
| 937 | |
| 938 | 4. 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] | 939 | address specified by the platform defined constant `BL2_BASE`. |
| 940 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 941 | 5. Populating a `meminfo` structure with the following information in memory, |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 942 | accessible by BL2 immediately upon entry. |
| 943 | |
| 944 | meminfo.total_base = Base address of secure RAM visible to BL2 |
| 945 | meminfo.total_size = Size of secure RAM visible to BL2 |
| 946 | meminfo.free_base = Base address of secure RAM available for |
| 947 | allocation to BL2 |
| 948 | meminfo.free_size = Size of secure RAM available for allocation to BL2 |
| 949 | |
| 950 | BL1 places this `meminfo` structure at the beginning of the free memory |
| 951 | available for its use. Since BL1 cannot allocate memory dynamically at the |
| 952 | moment, its free memory will be available for BL2's use as-is. However, this |
| 953 | means that BL2 must read the `meminfo` structure before it starts using its |
| 954 | free memory (this is discussed in Section 3.2). |
| 955 | |
| 956 | In future releases of the ARM Trusted Firmware it will be possible for |
| 957 | the platform to decide where it wants to place the `meminfo` structure for |
| 958 | BL2. |
| 959 | |
Sandrine Bailleux | 8f55dfb | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 960 | BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 961 | BL2 `meminfo` structure. The platform may override this implementation, for |
| 962 | example if the platform wants to restrict the amount of memory visible to |
| 963 | BL2. Details of how to do this are given below. |
| 964 | |
| 965 | The following functions need to be implemented by the platform port to enable |
| 966 | BL1 to perform the above tasks. |
| 967 | |
| 968 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 969 | ### Function : bl1_early_platform_setup() [mandatory] |
| 970 | |
| 971 | Argument : void |
| 972 | Return : void |
| 973 | |
| 974 | This function executes with the MMU and data caches disabled. It is only called |
| 975 | by the primary CPU. |
| 976 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 977 | On ARM standard platforms, this function: |
| 978 | |
| 979 | * Enables a secure instance of SP805 to act as the Trusted Watchdog. |
| 980 | |
| 981 | * Initializes a UART (PL011 console), which enables access to the `printf` |
| 982 | family of functions in BL1. |
| 983 | |
| 984 | * Enables issuing of snoop and DVM (Distributed Virtual Memory) requests to |
| 985 | the CCI slave interface corresponding to the cluster that includes the |
| 986 | primary CPU. |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 987 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 988 | ### Function : bl1_plat_arch_setup() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 989 | |
| 990 | Argument : void |
| 991 | Return : void |
| 992 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 993 | This function performs any platform-specific and architectural setup that the |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 994 | platform requires. Platform-specific setup might include configuration of |
| 995 | memory controllers and the interconnect. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 996 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 997 | In ARM standard platforms, this function enables the MMU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 998 | |
| 999 | This function helps fulfill requirement 2 above. |
| 1000 | |
| 1001 | |
| 1002 | ### Function : bl1_platform_setup() [mandatory] |
| 1003 | |
| 1004 | Argument : void |
| 1005 | Return : void |
| 1006 | |
| 1007 | This function executes with the MMU and data caches enabled. It is responsible |
| 1008 | for performing any remaining platform-specific setup that can occur after the |
| 1009 | MMU and data cache have been enabled. |
| 1010 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1011 | In ARM standard platforms, this function initializes the storage abstraction |
| 1012 | layer used to load the next bootloader image. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1013 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1014 | This function helps fulfill requirement 4 above. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1015 | |
| 1016 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1017 | ### Function : bl1_plat_sec_mem_layout() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1018 | |
| 1019 | Argument : void |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1020 | Return : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1021 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1022 | This function should only be called on the cold boot path. It executes with the |
| 1023 | MMU and data caches enabled. The pointer returned by this function must point to |
| 1024 | a `meminfo` structure containing the extents and availability of secure RAM for |
| 1025 | the BL1 stage. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1026 | |
| 1027 | meminfo.total_base = Base address of secure RAM visible to BL1 |
| 1028 | meminfo.total_size = Size of secure RAM visible to BL1 |
| 1029 | meminfo.free_base = Base address of secure RAM available for allocation |
| 1030 | to BL1 |
| 1031 | meminfo.free_size = Size of secure RAM available for allocation to BL1 |
| 1032 | |
| 1033 | This information is used by BL1 to load the BL2 image in secure RAM. BL1 also |
| 1034 | populates a similar structure to tell BL2 the extents of memory available for |
| 1035 | its own use. |
| 1036 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1037 | This function helps fulfill requirements 4 and 5 above. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1038 | |
| 1039 | |
Sandrine Bailleux | 8f55dfb | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 1040 | ### Function : bl1_init_bl2_mem_layout() [optional] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1041 | |
Soby Mathew | 4c0d039 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 1042 | Argument : meminfo *, meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1043 | Return : void |
| 1044 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1045 | BL1 needs to tell the next stage the amount of secure RAM available |
| 1046 | for it to use. This information is populated in a `meminfo` |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1047 | structure. |
| 1048 | |
| 1049 | Depending upon where BL2 has been loaded in secure RAM (determined by |
| 1050 | `BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use. |
| 1051 | 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] | 1052 | to BL2. An illustration of how this is done in ARM standard platforms is given |
| 1053 | in the **Memory layout on ARM development platforms** section in the |
| 1054 | [Firmware Design]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1055 | |
| 1056 | |
Juan Castillo | e3f6712 | 2015-10-05 16:59:38 +0100 | [diff] [blame] | 1057 | ### Function : bl1_plat_prepare_exit() [optional] |
| 1058 | |
Sandrine Bailleux | 862b5dc | 2015-11-10 15:01:57 +0000 | [diff] [blame] | 1059 | Argument : entry_point_info_t * |
Juan Castillo | e3f6712 | 2015-10-05 16:59:38 +0100 | [diff] [blame] | 1060 | Return : void |
| 1061 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1062 | This function is called prior to exiting BL1 in response to the |
| 1063 | `BL1_SMC_RUN_IMAGE` SMC request raised by BL2. It should be used to perform |
| 1064 | platform specific clean up or bookkeeping operations before transferring |
| 1065 | control to the next image. It receives the address of the `entry_point_info_t` |
| 1066 | structure passed from BL2. This function runs with MMU disabled. |
| 1067 | |
| 1068 | ### Function : bl1_plat_set_ep_info() [optional] |
| 1069 | |
| 1070 | Argument : unsigned int image_id, entry_point_info_t *ep_info |
| 1071 | Return : void |
| 1072 | |
| 1073 | This function allows platforms to override `ep_info` for the given `image_id`. |
| 1074 | |
| 1075 | The default implementation just returns. |
| 1076 | |
| 1077 | ### Function : bl1_plat_get_next_image_id() [optional] |
| 1078 | |
| 1079 | Argument : void |
| 1080 | Return : unsigned int |
| 1081 | |
| 1082 | This and the following function must be overridden to enable the FWU feature. |
| 1083 | |
| 1084 | BL1 calls this function after platform setup to identify the next image to be |
| 1085 | loaded and executed. If the platform returns `BL2_IMAGE_ID` then BL1 proceeds |
| 1086 | with the normal boot sequence, which loads and executes BL2. If the platform |
| 1087 | returns a different image id, BL1 assumes that Firmware Update is required. |
| 1088 | |
| 1089 | The default implementation always returns `BL2_IMAGE_ID`. The ARM development |
| 1090 | platforms override this function to detect if firmware update is required, and |
| 1091 | if so, return the first image in the firmware update process. |
| 1092 | |
| 1093 | ### Function : bl1_plat_get_image_desc() [optional] |
| 1094 | |
| 1095 | Argument : unsigned int image_id |
| 1096 | Return : image_desc_t * |
| 1097 | |
| 1098 | BL1 calls this function to get the image descriptor information `image_desc_t` |
| 1099 | for the provided `image_id` from the platform. |
| 1100 | |
| 1101 | The default implementation always returns a common BL2 image descriptor. ARM |
| 1102 | standard platforms return an image descriptor corresponding to BL2 or one of |
| 1103 | the firmware update images defined in the Trusted Board Boot Requirements |
| 1104 | specification. |
| 1105 | |
| 1106 | ### Function : bl1_plat_fwu_done() [optional] |
| 1107 | |
| 1108 | Argument : unsigned int image_id, uintptr_t image_src, |
| 1109 | unsigned int image_size |
| 1110 | Return : void |
| 1111 | |
| 1112 | BL1 calls this function when the FWU process is complete. It must not return. |
| 1113 | The platform may override this function to take platform specific action, for |
| 1114 | example to initiate the normal boot flow. |
| 1115 | |
| 1116 | The default implementation spins forever. |
| 1117 | |
| 1118 | ### Function : bl1_plat_mem_check() [mandatory] |
| 1119 | |
| 1120 | Argument : uintptr_t mem_base, unsigned int mem_size, |
| 1121 | unsigned int flags |
Sandrine Bailleux | ba78977 | 2016-11-03 14:26:37 +0000 | [diff] [blame] | 1122 | Return : int |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1123 | |
Sandrine Bailleux | 34ba298 | 2016-11-11 16:58:59 +0000 | [diff] [blame] | 1124 | BL1 calls this function while handling FWU related SMCs, more specifically when |
| 1125 | copying or authenticating an image. Its responsibility is to ensure that the |
| 1126 | region of memory identified by `mem_base` and `mem_size` is mapped in BL1, and |
| 1127 | that this memory corresponds to either a secure or non-secure memory region as |
| 1128 | indicated by the security state of the `flags` argument. |
| 1129 | |
| 1130 | This function can safely assume that the value resulting from the addition of |
| 1131 | `mem_base` and `mem_size` fits into a `uintptr_t` type variable and does not |
| 1132 | overflow. |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1133 | |
Sandrine Bailleux | ba78977 | 2016-11-03 14:26:37 +0000 | [diff] [blame] | 1134 | This function must return 0 on success, a non-null error code otherwise. |
| 1135 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1136 | The default implementation of this function asserts therefore platforms must |
| 1137 | override it when using the FWU feature. |
Juan Castillo | e3f6712 | 2015-10-05 16:59:38 +0100 | [diff] [blame] | 1138 | |
| 1139 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1140 | 3.2 Boot Loader Stage 2 (BL2) |
| 1141 | ----------------------------- |
| 1142 | |
| 1143 | The BL2 stage is executed only by the primary CPU, which is determined in BL1 |
| 1144 | using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at |
| 1145 | `BL2_BASE`. BL2 executes in Secure EL1 and is responsible for: |
| 1146 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 1147 | 1. (Optional) Loading the SCP_BL2 binary image (if present) from platform |
| 1148 | provided non-volatile storage. To load the SCP_BL2 image, BL2 makes use of |
| 1149 | the `meminfo` returned by the `bl2_plat_get_scp_bl2_meminfo()` function. |
| 1150 | The platform also defines the address in memory where SCP_BL2 is loaded |
| 1151 | through the optional constant `SCP_BL2_BASE`. BL2 uses this information |
| 1152 | to determine if there is enough memory to load the SCP_BL2 image. |
| 1153 | Subsequent handling of the SCP_BL2 image is platform-specific and is |
| 1154 | implemented in the `bl2_plat_handle_scp_bl2()` function. |
| 1155 | If `SCP_BL2_BASE` is not defined then this step is not performed. |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1156 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1157 | 2. Loading the BL31 binary image into secure RAM from non-volatile storage. To |
| 1158 | load the BL31 image, BL2 makes use of the `meminfo` structure passed to it |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1159 | by BL1. This structure allows BL2 to calculate how much secure RAM is |
| 1160 | available for its use. The platform also defines the address in secure RAM |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1161 | where BL31 is loaded through the constant `BL31_BASE`. BL2 uses this |
| 1162 | information to determine if there is enough memory to load the BL31 image. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1163 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1164 | 3. (Optional) Loading the BL32 binary image (if present) from platform |
| 1165 | provided non-volatile storage. To load the BL32 image, BL2 makes use of |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1166 | the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function. |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1167 | The platform also defines the address in memory where BL32 is loaded |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1168 | through the optional constant `BL32_BASE`. BL2 uses this information |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1169 | to determine if there is enough memory to load the BL32 image. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1170 | 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] | 1171 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1172 | 4. (Optional) Arranging to pass control to the BL32 image (if present) that |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1173 | 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] | 1174 | structure in memory provided by the platform with information about how |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1175 | BL31 should pass control to the BL32 image. |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 1176 | |
Antonio Nino Diaz | cf2c8a3 | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 1177 | 5. (Optional) Loading the normal world BL33 binary image (if not loaded by |
| 1178 | other means) into non-secure DRAM from platform storage and arranging for |
| 1179 | BL31 to pass control to this image. This address is determined using the |
| 1180 | `plat_get_ns_image_entrypoint()` function described below. |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1181 | |
| 1182 | 6. BL2 populates an `entry_point_info` structure in memory provided by the |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1183 | platform with information about how BL31 should pass control to the |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1184 | other BL images. |
| 1185 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1186 | The following functions must be implemented by the platform port to enable BL2 |
| 1187 | to perform the above tasks. |
| 1188 | |
| 1189 | |
| 1190 | ### Function : bl2_early_platform_setup() [mandatory] |
| 1191 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1192 | Argument : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1193 | Return : void |
| 1194 | |
| 1195 | 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] | 1196 | by the primary CPU. The arguments to this function is the address of the |
| 1197 | `meminfo` structure populated by BL1. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1198 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1199 | The platform may copy the contents of the `meminfo` structure into a private |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1200 | variable as the original memory may be subsequently overwritten by BL2. The |
| 1201 | copied structure is made available to all BL2 code through the |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 1202 | `bl2_plat_sec_mem_layout()` function. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1203 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1204 | On ARM standard platforms, this function also: |
| 1205 | |
| 1206 | * Initializes a UART (PL011 console), which enables access to the `printf` |
| 1207 | family of functions in BL2. |
| 1208 | |
| 1209 | * Initializes the storage abstraction layer used to load further bootloader |
| 1210 | images. It is necessary to do this early on platforms with a SCP_BL2 image, |
| 1211 | since the later `bl2_platform_setup` must be done after SCP_BL2 is loaded. |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1212 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1213 | |
| 1214 | ### Function : bl2_plat_arch_setup() [mandatory] |
| 1215 | |
| 1216 | Argument : void |
| 1217 | Return : void |
| 1218 | |
| 1219 | This function executes with the MMU and data caches disabled. It is only called |
| 1220 | by the primary CPU. |
| 1221 | |
| 1222 | The purpose of this function is to perform any architectural initialization |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1223 | that varies across platforms. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1224 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1225 | On ARM standard platforms, this function enables the MMU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1226 | |
| 1227 | ### Function : bl2_platform_setup() [mandatory] |
| 1228 | |
| 1229 | Argument : void |
| 1230 | Return : void |
| 1231 | |
| 1232 | This function may execute with the MMU and data caches enabled if the platform |
| 1233 | port does the necessary initialization in `bl2_plat_arch_setup()`. It is only |
| 1234 | called by the primary CPU. |
| 1235 | |
Achin Gupta | e4d084e | 2014-02-19 17:18:23 +0000 | [diff] [blame] | 1236 | The purpose of this function is to perform any platform initialization |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1237 | specific to BL2. |
Harry Liebel | ce19cf1 | 2014-04-01 19:28:07 +0100 | [diff] [blame] | 1238 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1239 | In ARM standard platforms, this function performs security setup, including |
| 1240 | configuration of the TrustZone controller to allow non-secure masters access |
| 1241 | 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] | 1242 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1243 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1244 | ### Function : bl2_plat_sec_mem_layout() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1245 | |
| 1246 | Argument : void |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1247 | Return : meminfo * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1248 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1249 | This function should only be called on the cold boot path. It may execute with |
| 1250 | the MMU and data caches enabled if the platform port does the necessary |
| 1251 | 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] | 1252 | |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 1253 | The purpose of this function is to return a pointer to a `meminfo` structure |
| 1254 | 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] | 1255 | `bl2_early_platform_setup()` above. |
| 1256 | |
| 1257 | |
Yatharth Kochar | 7260022 | 2016-09-12 16:08:41 +0100 | [diff] [blame] | 1258 | Following function is required only when LOAD_IMAGE_V2 is enabled. |
| 1259 | |
| 1260 | ### Function : bl2_plat_handle_post_image_load() [mandatory] |
| 1261 | |
| 1262 | Argument : unsigned int |
| 1263 | Return : int |
| 1264 | |
| 1265 | This function can be used by the platforms to update/use image information |
| 1266 | for given `image_id`. This function is currently invoked in BL2 to handle |
| 1267 | BL image specific information based on the `image_id` passed, when |
| 1268 | LOAD_IMAGE_V2 is enabled. |
| 1269 | |
| 1270 | Following functions are required only when LOAD_IMAGE_V2 is disabled. |
| 1271 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 1272 | ### Function : bl2_plat_get_scp_bl2_meminfo() [mandatory] |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1273 | |
| 1274 | Argument : meminfo * |
| 1275 | Return : void |
| 1276 | |
| 1277 | This function is used to get the memory limits where BL2 can load the |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 1278 | SCP_BL2 image. The meminfo provided by this is used by load_image() to |
| 1279 | validate whether the SCP_BL2 image can be loaded within the given |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1280 | memory from the given base. |
| 1281 | |
| 1282 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 1283 | ### Function : bl2_plat_handle_scp_bl2() [mandatory] |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1284 | |
| 1285 | Argument : image_info * |
| 1286 | Return : int |
| 1287 | |
Juan Castillo | f59821d | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 1288 | This function is called after loading SCP_BL2 image and it is used to perform |
| 1289 | any platform-specific actions required to handle the SCP firmware. Typically it |
Sandrine Bailleux | 93d81d6 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 1290 | transfers the image into SCP memory using a platform-specific protocol and waits |
| 1291 | until SCP executes it and signals to the Application Processor (AP) for BL2 |
| 1292 | execution to continue. |
| 1293 | |
| 1294 | This function returns 0 on success, a negative error code otherwise. |
| 1295 | |
| 1296 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1297 | ### Function : bl2_plat_get_bl31_params() [mandatory] |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1298 | |
| 1299 | Argument : void |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1300 | Return : bl31_params * |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1301 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1302 | BL2 platform code needs to return a pointer to a `bl31_params` structure it |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1303 | will use for passing information to BL31. The `bl31_params` structure carries |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1304 | the following information. |
| 1305 | - Header describing the version information for interpreting the bl31_param |
| 1306 | structure |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1307 | - Information about executing the BL33 image in the `bl33_ep_info` field |
| 1308 | - Information about executing the BL32 image in the `bl32_ep_info` field |
| 1309 | - Information about the type and extents of BL31 image in the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1310 | `bl31_image_info` field |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1311 | - Information about the type and extents of BL32 image in the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1312 | `bl32_image_info` field |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1313 | - Information about the type and extents of BL33 image in the |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1314 | `bl33_image_info` field |
| 1315 | |
| 1316 | The memory pointed by this structure and its sub-structures should be |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1317 | accessible from BL31 initialisation code. BL31 might choose to copy the |
| 1318 | necessary content, or maintain the structures until BL33 is initialised. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 1319 | |
| 1320 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1321 | ### Funtion : bl2_plat_get_bl31_ep_info() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1322 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1323 | Argument : void |
| 1324 | Return : entry_point_info * |
| 1325 | |
| 1326 | BL2 platform code returns a pointer which is used to populate the entry point |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1327 | information for BL31 entry point. The location pointed by it should be |
| 1328 | accessible from BL1 while processing the synchronous exception to run to BL31. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1329 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1330 | In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem |
| 1331 | structure in BL2 memory. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1332 | |
| 1333 | |
| 1334 | ### Function : bl2_plat_set_bl31_ep_info() [mandatory] |
| 1335 | |
| 1336 | Argument : image_info *, entry_point_info * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1337 | Return : void |
| 1338 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1339 | In the normal boot flow, this function is called after loading BL31 image and |
Sandrine Bailleux | 4c117f6 | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 1340 | it can be used to overwrite the entry point set by loader and also set the |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1341 | security state and SPSR which represents the entry point system state for BL31. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1342 | |
Sandrine Bailleux | 4c117f6 | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 1343 | When booting an EL3 payload instead, this function is called after populating |
| 1344 | its entry point address and can be used for the same purpose for the payload |
| 1345 | image. It receives a null pointer as its first argument in this case. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1346 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1347 | ### Function : bl2_plat_set_bl32_ep_info() [mandatory] |
| 1348 | |
| 1349 | Argument : image_info *, entry_point_info * |
| 1350 | Return : void |
| 1351 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1352 | This function is called after loading BL32 image and it can be used to |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1353 | overwrite the entry point set by loader and also set the security state |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1354 | and SPSR which represents the entry point system state for BL32. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1355 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1356 | |
| 1357 | ### Function : bl2_plat_set_bl33_ep_info() [mandatory] |
| 1358 | |
| 1359 | Argument : image_info *, entry_point_info * |
| 1360 | Return : void |
| 1361 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1362 | This function is called after loading BL33 image and it can be used to |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1363 | overwrite the entry point set by loader and also set the security state |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1364 | and SPSR which represents the entry point system state for BL33. |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1365 | |
Antonio Nino Diaz | cf2c8a3 | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 1366 | In the preloaded BL33 alternative boot flow, this function is called after |
| 1367 | populating its entry point address. It is passed a null pointer as its first |
| 1368 | argument in this case. |
| 1369 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1370 | |
| 1371 | ### Function : bl2_plat_get_bl32_meminfo() [mandatory] |
| 1372 | |
| 1373 | Argument : meminfo * |
| 1374 | Return : void |
| 1375 | |
| 1376 | This function is used to get the memory limits where BL2 can load the |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1377 | BL32 image. The meminfo provided by this is used by load_image() to |
| 1378 | validate whether the BL32 image can be loaded with in the given |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1379 | memory from the given base. |
| 1380 | |
| 1381 | ### Function : bl2_plat_get_bl33_meminfo() [mandatory] |
| 1382 | |
| 1383 | Argument : meminfo * |
| 1384 | Return : void |
| 1385 | |
| 1386 | This function is used to get the memory limits where BL2 can load the |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1387 | BL33 image. The meminfo provided by this is used by load_image() to |
| 1388 | validate whether the BL33 image can be loaded with in the given |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1389 | memory from the given base. |
| 1390 | |
Antonio Nino Diaz | 68450a6 | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 1391 | This function isn't needed if either `PRELOADED_BL33_BASE` or `EL3_PAYLOAD_BASE` |
| 1392 | build options are used. |
Antonio Nino Diaz | cf2c8a3 | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 1393 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1394 | ### Function : bl2_plat_flush_bl31_params() [mandatory] |
| 1395 | |
| 1396 | Argument : void |
| 1397 | Return : void |
| 1398 | |
| 1399 | Once BL2 has populated all the structures that needs to be read by BL1 |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1400 | and BL31 including the bl31_params structures and its sub-structures, |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1401 | the bl31_ep_info structure and any platform specific data. It flushes |
| 1402 | all these data to the main memory so that it is available when we jump to |
| 1403 | later Bootloader stages with MMU off |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1404 | |
| 1405 | ### Function : plat_get_ns_image_entrypoint() [mandatory] |
| 1406 | |
| 1407 | Argument : void |
Soby Mathew | a0ad601 | 2016-03-23 10:11:10 +0000 | [diff] [blame] | 1408 | Return : uintptr_t |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1409 | |
| 1410 | As previously described, BL2 is responsible for arranging for control to be |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1411 | passed to a normal world BL image through BL31. This function returns the |
| 1412 | entrypoint of that image, which BL31 uses to jump to it. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1413 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1414 | BL2 is responsible for loading the normal world BL33 image (e.g. UEFI). |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1415 | |
Antonio Nino Diaz | 68450a6 | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 1416 | This function isn't needed if either `PRELOADED_BL33_BASE` or `EL3_PAYLOAD_BASE` |
| 1417 | build options are used. |
Antonio Nino Diaz | cf2c8a3 | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 1418 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1419 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1420 | 3.3 FWU Boot Loader Stage 2 (BL2U) |
| 1421 | ---------------------------------- |
| 1422 | |
| 1423 | The AP Firmware Updater Configuration, BL2U, is an optional part of the FWU |
| 1424 | process and is executed only by the primary CPU. BL1 passes control to BL2U at |
| 1425 | `BL2U_BASE`. BL2U executes in Secure-EL1 and is responsible for: |
| 1426 | |
| 1427 | 1. (Optional) Transfering the optional SCP_BL2U binary image from AP secure |
| 1428 | memory to SCP RAM. BL2U uses the SCP_BL2U `image_info` passed by BL1. |
| 1429 | `SCP_BL2U_BASE` defines the address in AP secure memory where SCP_BL2U |
| 1430 | should be copied from. Subsequent handling of the SCP_BL2U image is |
| 1431 | implemented by the platform specific `bl2u_plat_handle_scp_bl2u()` function. |
| 1432 | If `SCP_BL2U_BASE` is not defined then this step is not performed. |
| 1433 | |
| 1434 | 2. Any platform specific setup required to perform the FWU process. For |
| 1435 | example, ARM standard platforms initialize the TZC controller so that the |
| 1436 | normal world can access DDR memory. |
| 1437 | |
| 1438 | The following functions must be implemented by the platform port to enable |
| 1439 | BL2U to perform the tasks mentioned above. |
| 1440 | |
| 1441 | ### Function : bl2u_early_platform_setup() [mandatory] |
| 1442 | |
| 1443 | Argument : meminfo *mem_info, void *plat_info |
| 1444 | Return : void |
| 1445 | |
| 1446 | This function executes with the MMU and data caches disabled. It is only |
| 1447 | called by the primary CPU. The arguments to this function is the address |
| 1448 | of the `meminfo` structure and platform specific info provided by BL1. |
| 1449 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1450 | The platform may copy the contents of the `mem_info` and `plat_info` into |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1451 | private storage as the original memory may be subsequently overwritten by BL2U. |
| 1452 | |
| 1453 | On ARM CSS platforms `plat_info` is interpreted as an `image_info_t` structure, |
| 1454 | to extract SCP_BL2U image information, which is then copied into a private |
| 1455 | variable. |
| 1456 | |
| 1457 | ### Function : bl2u_plat_arch_setup() [mandatory] |
| 1458 | |
| 1459 | Argument : void |
| 1460 | Return : void |
| 1461 | |
| 1462 | This function executes with the MMU and data caches disabled. It is only |
| 1463 | called by the primary CPU. |
| 1464 | |
| 1465 | The purpose of this function is to perform any architectural initialization |
| 1466 | that varies across platforms, for example enabling the MMU (since the memory |
| 1467 | map differs across platforms). |
| 1468 | |
| 1469 | ### Function : bl2u_platform_setup() [mandatory] |
| 1470 | |
| 1471 | Argument : void |
| 1472 | Return : void |
| 1473 | |
| 1474 | This function may execute with the MMU and data caches enabled if the platform |
| 1475 | port does the necessary initialization in `bl2u_plat_arch_setup()`. It is only |
| 1476 | called by the primary CPU. |
| 1477 | |
| 1478 | The purpose of this function is to perform any platform initialization |
| 1479 | specific to BL2U. |
| 1480 | |
| 1481 | In ARM standard platforms, this function performs security setup, including |
| 1482 | configuration of the TrustZone controller to allow non-secure masters access |
| 1483 | to most of DRAM. Part of DRAM is reserved for secure world use. |
| 1484 | |
| 1485 | ### Function : bl2u_plat_handle_scp_bl2u() [optional] |
| 1486 | |
| 1487 | Argument : void |
| 1488 | Return : int |
| 1489 | |
| 1490 | This function is used to perform any platform-specific actions required to |
| 1491 | handle the SCP firmware. Typically it transfers the image into SCP memory using |
| 1492 | a platform-specific protocol and waits until SCP executes it and signals to the |
| 1493 | Application Processor (AP) for BL2U execution to continue. |
| 1494 | |
| 1495 | This function returns 0 on success, a negative error code otherwise. |
| 1496 | This function is included if SCP_BL2U_BASE is defined. |
| 1497 | |
| 1498 | |
| 1499 | 3.4 Boot Loader Stage 3-1 (BL31) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1500 | --------------------------------- |
| 1501 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1502 | During cold boot, the BL31 stage is executed only by the primary CPU. This is |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1503 | determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1504 | control to BL31 at `BL31_BASE`. During warm boot, BL31 is executed by all |
| 1505 | CPUs. BL31 executes at EL3 and is responsible for: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1506 | |
| 1507 | 1. Re-initializing all architectural and platform state. Although BL1 performs |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1508 | some of this initialization, BL31 remains resident in EL3 and must ensure |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1509 | that EL3 architectural and platform state is completely initialized. It |
| 1510 | should make no assumptions about the system state when it receives control. |
| 1511 | |
| 1512 | 2. Passing control to a normal world BL image, pre-loaded at a platform- |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1513 | specific address by BL2. BL31 uses the `entry_point_info` structure that BL2 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1514 | populated in memory to do this. |
| 1515 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1516 | 3. Providing runtime firmware services. Currently, BL31 only implements a |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1517 | subset of the Power State Coordination Interface (PSCI) API as a runtime |
| 1518 | service. See Section 3.3 below for details of porting the PSCI |
| 1519 | implementation. |
| 1520 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1521 | 4. Optionally passing control to the BL32 image, pre-loaded at a platform- |
| 1522 | specific address by BL2. BL31 exports a set of apis that allow runtime |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1523 | services to specify the security state in which the next image should be |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1524 | executed and run the corresponding image. BL31 uses the `entry_point_info` |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1525 | structure populated by BL2 to do this. |
| 1526 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1527 | If BL31 is a reset vector, It also needs to handle the reset as specified in |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1528 | section 2.2 before the tasks described above. |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1529 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1530 | The following functions must be implemented by the platform port to enable BL31 |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1531 | to perform the above tasks. |
| 1532 | |
| 1533 | |
| 1534 | ### Function : bl31_early_platform_setup() [mandatory] |
| 1535 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1536 | Argument : bl31_params *, void * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1537 | Return : void |
| 1538 | |
| 1539 | This function executes with the MMU and data caches disabled. It is only called |
| 1540 | by the primary CPU. The arguments to this function are: |
| 1541 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1542 | * The address of the `bl31_params` structure populated by BL2. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1543 | * An opaque pointer that the platform may use as needed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1544 | |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1545 | The platform can copy the contents of the `bl31_params` structure and its |
| 1546 | sub-structures into private variables if the original memory may be |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1547 | subsequently overwritten by BL31 and similarly the `void *` pointing |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1548 | to the platform data also needs to be saved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1549 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1550 | In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1551 | in BL2 memory. BL31 copies the information in this pointer to internal data |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1552 | structures. It also performs the following: |
| 1553 | |
| 1554 | * Initialize a UART (PL011 console), which enables access to the `printf` |
| 1555 | family of functions in BL31. |
| 1556 | |
| 1557 | * Enable issuing of snoop and DVM (Distributed Virtual Memory) requests to the |
| 1558 | CCI slave interface corresponding to the cluster that includes the primary |
| 1559 | CPU. |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1560 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1561 | |
| 1562 | ### Function : bl31_plat_arch_setup() [mandatory] |
| 1563 | |
| 1564 | Argument : void |
| 1565 | Return : void |
| 1566 | |
| 1567 | This function executes with the MMU and data caches disabled. It is only called |
| 1568 | by the primary CPU. |
| 1569 | |
| 1570 | The purpose of this function is to perform any architectural initialization |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1571 | that varies across platforms. |
| 1572 | |
| 1573 | On ARM standard platforms, this function enables the MMU. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1574 | |
| 1575 | |
| 1576 | ### Function : bl31_platform_setup() [mandatory] |
| 1577 | |
| 1578 | Argument : void |
| 1579 | Return : void |
| 1580 | |
| 1581 | This function may execute with the MMU and data caches enabled if the platform |
| 1582 | port does the necessary initialization in `bl31_plat_arch_setup()`. It is only |
| 1583 | called by the primary CPU. |
| 1584 | |
| 1585 | The purpose of this function is to complete platform initialization so that both |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1586 | BL31 runtime services and normal world software can function correctly. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1587 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 1588 | On ARM standard platforms, this function does the following: |
| 1589 | |
| 1590 | * Initialize the generic interrupt controller. |
| 1591 | |
| 1592 | Depending on the GIC driver selected by the platform, the appropriate GICv2 |
| 1593 | or GICv3 initialization will be done, which mainly consists of: |
| 1594 | |
| 1595 | - Enable secure interrupts in the GIC CPU interface. |
| 1596 | - Disable the legacy interrupt bypass mechanism. |
| 1597 | - Configure the priority mask register to allow interrupts of all priorities |
| 1598 | to be signaled to the CPU interface. |
| 1599 | - Mark SGIs 8-15 and the other secure interrupts on the platform as secure. |
| 1600 | - Target all secure SPIs to CPU0. |
| 1601 | - Enable these secure interrupts in the GIC distributor. |
| 1602 | - Configure all other interrupts as non-secure. |
| 1603 | - Enable signaling of secure interrupts in the GIC distributor. |
| 1604 | |
| 1605 | * Enable system-level implementation of the generic timer counter through the |
| 1606 | memory mapped interface. |
| 1607 | |
| 1608 | * Grant access to the system counter timer module |
| 1609 | |
| 1610 | * Initialize the power controller device. |
| 1611 | |
| 1612 | In particular, initialise the locks that prevent concurrent accesses to the |
| 1613 | power controller device. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1614 | |
| 1615 | |
Soby Mathew | 78e6161 | 2015-12-09 11:28:43 +0000 | [diff] [blame] | 1616 | ### Function : bl31_plat_runtime_setup() [optional] |
| 1617 | |
| 1618 | Argument : void |
| 1619 | Return : void |
| 1620 | |
| 1621 | The purpose of this function is allow the platform to perform any BL31 runtime |
| 1622 | setup just prior to BL31 exit during cold boot. The default weak |
| 1623 | implementation of this function will invoke `console_uninit()` which will |
| 1624 | suppress any BL31 runtime logs. |
| 1625 | |
Soby Mathew | 080225d | 2015-12-09 11:38:43 +0000 | [diff] [blame] | 1626 | In ARM Standard platforms, this function will initialize the BL31 runtime |
| 1627 | console which will cause all further BL31 logs to be output to the |
| 1628 | runtime console. |
| 1629 | |
Soby Mathew | 78e6161 | 2015-12-09 11:28:43 +0000 | [diff] [blame] | 1630 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1631 | ### Function : bl31_get_next_image_info() [mandatory] |
| 1632 | |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1633 | Argument : unsigned int |
Vikram Kanigiri | e452cd8 | 2014-05-23 15:56:12 +0100 | [diff] [blame] | 1634 | Return : entry_point_info * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1635 | |
| 1636 | This function may execute with the MMU and data caches enabled if the platform |
| 1637 | port does the necessary initializations in `bl31_plat_arch_setup()`. |
| 1638 | |
| 1639 | This function is called by `bl31_main()` to retrieve information provided by |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1640 | BL2 for the next image in the security state specified by the argument. BL31 |
Achin Gupta | 35ca351 | 2014-02-19 17:58:33 +0000 | [diff] [blame] | 1641 | 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] | 1642 | 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] | 1643 | (that was copied during `bl31_early_platform_setup()`) if the image exists. It |
| 1644 | should return NULL otherwise. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1645 | |
Antonio Nino Diaz | d448639 | 2016-05-18 16:53:31 +0100 | [diff] [blame] | 1646 | ### Function : plat_get_syscnt_freq2() [mandatory] |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1647 | |
| 1648 | Argument : void |
Antonio Nino Diaz | d448639 | 2016-05-18 16:53:31 +0100 | [diff] [blame] | 1649 | Return : unsigned int |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 1650 | |
| 1651 | This function is used by the architecture setup code to retrieve the counter |
| 1652 | frequency for the CPU's generic timer. This value will be programmed into the |
| 1653 | `CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency |
| 1654 | of the system counter, which is retrieved from the first entry in the frequency |
| 1655 | modes table. |
| 1656 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1657 | |
Vikram Kanigiri | 7173f5f | 2015-09-24 15:45:43 +0100 | [diff] [blame] | 1658 | ### #define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional] |
Andrew Thoelke | ee7b35c | 2015-09-10 11:39:36 +0100 | [diff] [blame] | 1659 | |
Vikram Kanigiri | 7173f5f | 2015-09-24 15:45:43 +0100 | [diff] [blame] | 1660 | When `USE_COHERENT_MEM = 0`, this constant defines the total memory (in |
| 1661 | bytes) aligned to the cache line boundary that should be allocated per-cpu to |
| 1662 | accommodate all the bakery locks. |
| 1663 | |
| 1664 | If this constant is not defined when `USE_COHERENT_MEM = 0`, the linker |
| 1665 | calculates the size of the `bakery_lock` input section, aligns it to the |
| 1666 | nearest `CACHE_WRITEBACK_GRANULE`, multiplies it with `PLATFORM_CORE_COUNT` |
| 1667 | and stores the result in a linker symbol. This constant prevents a platform |
| 1668 | from relying on the linker and provide a more efficient mechanism for |
| 1669 | accessing per-cpu bakery lock information. |
| 1670 | |
| 1671 | If this constant is defined and its value is not equal to the value |
| 1672 | calculated by the linker then a link time assertion is raised. A compile time |
| 1673 | assertion is raised if the value of the constant is not aligned to the cache |
| 1674 | line boundary. |
Andrew Thoelke | ee7b35c | 2015-09-10 11:39:36 +0100 | [diff] [blame] | 1675 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 1676 | 3.5 Power State Coordination Interface (in BL31) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1677 | ------------------------------------------------ |
| 1678 | |
| 1679 | The ARM Trusted Firmware's implementation of the PSCI API is based around the |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1680 | concept of a _power domain_. A _power domain_ is a CPU or a logical group of |
| 1681 | CPUs which share some state on which power management operations can be |
| 1682 | performed as specified by [PSCI]. Each CPU in the system is assigned a cpu |
| 1683 | index which is a unique number between `0` and `PLATFORM_CORE_COUNT - 1`. |
Sandrine Bailleux | 1645d3e | 2015-12-17 13:58:58 +0000 | [diff] [blame] | 1684 | The _power domains_ are arranged in a hierarchical tree structure and |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1685 | each _power domain_ can be identified in a system by the cpu index of any CPU |
| 1686 | that is part of that domain and a _power domain level_. A processing element |
| 1687 | (for example, a CPU) is at level 0. If the _power domain_ node above a CPU is |
| 1688 | a logical grouping of CPUs that share some state, then level 1 is that group |
| 1689 | of CPUs (for example, a cluster), and level 2 is a group of clusters |
| 1690 | (for example, the system). More details on the power domain topology and its |
| 1691 | organization can be found in [Power Domain Topology Design]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1692 | |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1693 | BL31's platform initialization code exports a pointer to the platform-specific |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1694 | power management operations required for the PSCI implementation to function |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1695 | correctly. This information is populated in the `plat_psci_ops` structure. The |
| 1696 | PSCI implementation calls members of the `plat_psci_ops` structure for performing |
| 1697 | power management operations on the power domains. For example, the target |
| 1698 | CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `pwr_domain_on()` |
| 1699 | handler (if present) is called for the CPU power domain. |
| 1700 | |
| 1701 | The `power-state` parameter of a PSCI `CPU_SUSPEND` call can be used to |
| 1702 | describe composite power states specific to a platform. The PSCI implementation |
| 1703 | defines a generic representation of the power-state parameter viz which is an |
| 1704 | array of local power states where each index corresponds to a power domain |
| 1705 | level. Each entry contains the local power state the power domain at that power |
| 1706 | level could enter. It depends on the `validate_power_state()` handler to |
| 1707 | convert the power-state parameter (possibly encoding a composite power state) |
| 1708 | passed in a PSCI `CPU_SUSPEND` call to this representation. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1709 | |
dp-arm | 04c1db1 | 2017-01-31 13:01:04 +0000 | [diff] [blame] | 1710 | The following functions form part of platform port of PSCI functionality. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1711 | |
| 1712 | |
dp-arm | 04c1db1 | 2017-01-31 13:01:04 +0000 | [diff] [blame] | 1713 | ### Function : plat_psci_stat_accounting_start() [optional] |
| 1714 | |
| 1715 | Argument : const psci_power_state_t * |
| 1716 | Return : void |
| 1717 | |
| 1718 | This is an optional hook that platforms can implement for residency statistics |
| 1719 | accounting before entering a low power state. The `pwr_domain_state` field of |
| 1720 | `state_info` (first argument) can be inspected if stat accounting is done |
| 1721 | differently at CPU level versus higher levels. As an example, if the element at |
| 1722 | index 0 (CPU power level) in the `pwr_domain_state` array indicates a power down |
| 1723 | state, special hardware logic may be programmed in order to keep track of the |
| 1724 | residency statistics. For higher levels (array indices > 0), the residency |
| 1725 | statistics could be tracked in software using PMF. If `ENABLE_PMF` is set, the |
| 1726 | default implementation will use PMF to capture timestamps. |
| 1727 | |
| 1728 | ### Function : plat_psci_stat_accounting_stop() [optional] |
| 1729 | |
| 1730 | Argument : const psci_power_state_t * |
| 1731 | Return : void |
| 1732 | |
| 1733 | This is an optional hook that platforms can implement for residency statistics |
| 1734 | accounting after exiting from a low power state. The `pwr_domain_state` field |
| 1735 | of `state_info` (first argument) can be inspected if stat accounting is done |
| 1736 | differently at CPU level versus higher levels. As an example, if the element at |
| 1737 | index 0 (CPU power level) in the `pwr_domain_state` array indicates a power down |
| 1738 | state, special hardware logic may be programmed in order to keep track of the |
| 1739 | residency statistics. For higher levels (array indices > 0), the residency |
| 1740 | statistics could be tracked in software using PMF. If `ENABLE_PMF` is set, the |
| 1741 | default implementation will use PMF to capture timestamps. |
| 1742 | |
| 1743 | ### Function : plat_psci_stat_get_residency() [optional] |
| 1744 | |
| 1745 | Argument : unsigned int, const psci_power_state_t *, int |
| 1746 | Return : u_register_t |
| 1747 | |
| 1748 | This is an optional interface that is is invoked after resuming from a low power |
| 1749 | state and provides the time spent resident in that low power state by the power |
| 1750 | domain at a particular power domain level. When a CPU wakes up from suspend, |
| 1751 | all its parent power domain levels are also woken up. The generic PSCI code |
| 1752 | invokes this function for each parent power domain that is resumed and it |
| 1753 | identified by the `lvl` (first argument) parameter. The `state_info` (second |
| 1754 | argument) describes the low power state that the power domain has resumed from. |
| 1755 | The current CPU is the first CPU in the power domain to resume from the low |
| 1756 | power state and the `last_cpu_idx` (third parameter) is the index of the last |
| 1757 | CPU in the power domain to suspend and may be needed to calculate the residency |
| 1758 | for that power domain. |
| 1759 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1760 | ### Function : plat_get_target_pwr_state() [optional] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1761 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1762 | Argument : unsigned int, const plat_local_state_t *, unsigned int |
| 1763 | Return : plat_local_state_t |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1764 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1765 | The PSCI generic code uses this function to let the platform participate in |
| 1766 | state coordination during a power management operation. The function is passed |
| 1767 | a pointer to an array of platform specific local power state `states` (second |
| 1768 | argument) which contains the requested power state for each CPU at a particular |
| 1769 | power domain level `lvl` (first argument) within the power domain. The function |
| 1770 | is expected to traverse this array of upto `ncpus` (third argument) and return |
| 1771 | a coordinated target power state by the comparing all the requested power |
| 1772 | states. The target power state should not be deeper than any of the requested |
| 1773 | power states. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1774 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1775 | A weak definition of this API is provided by default wherein it assumes |
| 1776 | that the platform assigns a local state value in order of increasing depth |
| 1777 | of the power state i.e. for two power states X & Y, if X < Y |
| 1778 | then X represents a shallower power state than Y. As a result, the |
| 1779 | coordinated target local power state for a power domain will be the minimum |
| 1780 | of the requested local power state values. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1781 | |
| 1782 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1783 | ### Function : plat_get_power_domain_tree_desc() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1784 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1785 | Argument : void |
| 1786 | Return : const unsigned char * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1787 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1788 | This function returns a pointer to the byte array containing the power domain |
| 1789 | topology tree description. The format and method to construct this array are |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1790 | described in [Power Domain Topology Design]. The BL31 PSCI initilization code |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1791 | requires this array to be described by the platform, either statically or |
| 1792 | dynamically, to initialize the power domain topology tree. In case the array |
| 1793 | is populated dynamically, then plat_core_pos_by_mpidr() and |
| 1794 | plat_my_core_pos() should also be implemented suitably so that the topology |
| 1795 | tree description matches the CPU indices returned by these APIs. These APIs |
| 1796 | together form the platform interface for the PSCI topology framework. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1797 | |
| 1798 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1799 | ## Function : plat_setup_psci_ops() [mandatory] |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1800 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1801 | Argument : uintptr_t, const plat_psci_ops ** |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1802 | Return : int |
| 1803 | |
| 1804 | This function may execute with the MMU and data caches enabled if the platform |
| 1805 | port does the necessary initializations in `bl31_plat_arch_setup()`. It is only |
| 1806 | called by the primary CPU. |
| 1807 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1808 | This function is called by PSCI initialization code. Its purpose is to let |
| 1809 | the platform layer know about the warm boot entrypoint through the |
| 1810 | `sec_entrypoint` (first argument) and to export handler routines for |
| 1811 | platform-specific psci power management actions by populating the passed |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 1812 | pointer with a pointer to BL31's private `plat_psci_ops` structure. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1813 | |
| 1814 | 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] | 1815 | the ARM FVP specific implementation of these handlers in |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1816 | [plat/arm/board/fvp/fvp_pm.c] as an example. For each PSCI function that the |
| 1817 | platform wants to support, the associated operation or operations in this |
| 1818 | structure must be provided and implemented (Refer section 4 of |
| 1819 | [Firmware Design] for the PSCI API supported in Trusted Firmware). To disable |
| 1820 | a PSCI function in a platform port, the operation should be removed from this |
| 1821 | structure instead of providing an empty implementation. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1822 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1823 | #### plat_psci_ops.cpu_standby() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1824 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1825 | Perform the platform-specific actions to enter the standby state for a cpu |
| 1826 | indicated by the passed argument. This provides a fast path for CPU standby |
| 1827 | wherein overheads of PSCI state management and lock acquistion is avoided. |
| 1828 | For this handler to be invoked by the PSCI `CPU_SUSPEND` API implementation, |
| 1829 | the suspend state type specified in the `power-state` parameter should be |
| 1830 | STANDBY and the target power domain level specified should be the CPU. The |
| 1831 | handler should put the CPU into a low power retention state (usually by |
| 1832 | issuing a wfi instruction) and ensure that it can be woken up from that |
| 1833 | state by a normal interrupt. The generic code expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1834 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1835 | #### plat_psci_ops.pwr_domain_on() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1836 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1837 | Perform the platform specific actions to power on a CPU, specified |
| 1838 | by the `MPIDR` (first argument). The generic code expects the platform to |
| 1839 | return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1840 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1841 | #### plat_psci_ops.pwr_domain_off() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1842 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1843 | Perform the platform specific actions to prepare to power off the calling CPU |
| 1844 | and its higher parent power domain levels as indicated by the `target_state` |
| 1845 | (first argument). It is called by the PSCI `CPU_OFF` API implementation. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1846 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1847 | The `target_state` encodes the platform coordinated target local power states |
| 1848 | for the CPU power domain and its parent power domain levels. The handler |
| 1849 | needs to perform power management operation corresponding to the local state |
| 1850 | at each power level. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1851 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1852 | For this handler, the local power state for the CPU power domain will be a |
| 1853 | power down state where as it could be either power down, retention or run state |
| 1854 | for the higher power domain levels depending on the result of state |
| 1855 | coordination. The generic code expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1856 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1857 | #### plat_psci_ops.pwr_domain_suspend() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1858 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1859 | Perform the platform specific actions to prepare to suspend the calling |
| 1860 | CPU and its higher parent power domain levels as indicated by the |
| 1861 | `target_state` (first argument). It is called by the PSCI `CPU_SUSPEND` |
| 1862 | API implementation. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1863 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1864 | The `target_state` has a similar meaning as described in |
| 1865 | the `pwr_domain_off()` operation. It encodes the platform coordinated |
| 1866 | target local power states for the CPU power domain and its parent |
| 1867 | power domain levels. The handler needs to perform power management operation |
| 1868 | corresponding to the local state at each power level. The generic code |
| 1869 | expects the handler to succeed. |
| 1870 | |
| 1871 | The difference between turning a power domain off versus suspending it |
| 1872 | is that in the former case, the power domain is expected to re-initialize |
| 1873 | its state when it is next powered on (see `pwr_domain_on_finish()`). In the |
| 1874 | latter case, the power domain is expected to save enough state so that it can |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1875 | resume execution by restoring this state when its powered on (see |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1876 | `pwr_domain_suspend_finish()`). |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1877 | |
Soby Mathew | ac1cc8e | 2016-04-27 14:46:28 +0100 | [diff] [blame] | 1878 | #### plat_psci_ops.pwr_domain_pwr_down_wfi() |
| 1879 | |
| 1880 | This is an optional function and, if implemented, is expected to perform |
| 1881 | platform specific actions including the `wfi` invocation which allows the |
| 1882 | CPU to powerdown. Since this function is invoked outside the PSCI locks, |
| 1883 | the actions performed in this hook must be local to the CPU or the platform |
| 1884 | must ensure that races between multiple CPUs cannot occur. |
| 1885 | |
| 1886 | The `target_state` has a similar meaning as described in the `pwr_domain_off()` |
| 1887 | operation and it encodes the platform coordinated target local power states for |
| 1888 | the CPU power domain and its parent power domain levels. This function must |
| 1889 | not return back to the caller. |
| 1890 | |
| 1891 | If this function is not implemented by the platform, PSCI generic |
| 1892 | implementation invokes `psci_power_down_wfi()` for power down. |
| 1893 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1894 | #### plat_psci_ops.pwr_domain_on_finish() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1895 | |
| 1896 | This function is called by the PSCI implementation after the calling CPU is |
| 1897 | powered on and released from reset in response to an earlier PSCI `CPU_ON` call. |
| 1898 | It performs the platform-specific setup required to initialize enough state for |
| 1899 | this CPU to enter the normal world and also provide secure runtime firmware |
| 1900 | services. |
| 1901 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1902 | The `target_state` (first argument) is the prior state of the power domains |
| 1903 | immediately before the CPU was turned on. It indicates which power domains |
| 1904 | above the CPU might require initialization due to having previously been in |
| 1905 | low power states. The generic code expects the handler to succeed. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1906 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1907 | #### plat_psci_ops.pwr_domain_suspend_finish() |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1908 | |
| 1909 | This function is called by the PSCI implementation after the calling CPU is |
| 1910 | powered on and released from reset in response to an asynchronous wakeup |
| 1911 | event, for example a timer interrupt that was programmed by the CPU during the |
Soby Mathew | c0aff0e | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 1912 | `CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific |
| 1913 | setup required to restore the saved state for this CPU to resume execution |
| 1914 | in the normal world and also provide secure runtime firmware services. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1915 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1916 | The `target_state` (first argument) has a similar meaning as described in |
| 1917 | the `pwr_domain_on_finish()` operation. The generic code expects the platform |
| 1918 | to succeed. |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1919 | |
Douglas Raillard | 7dd570e | 2016-10-31 13:26:03 +0000 | [diff] [blame] | 1920 | #### plat_psci_ops.system_off() |
| 1921 | |
| 1922 | This function is called by PSCI implementation in response to a `SYSTEM_OFF` |
| 1923 | call. It performs the platform-specific system poweroff sequence after |
| 1924 | notifying the Secure Payload Dispatcher. |
| 1925 | |
| 1926 | #### plat_psci_ops.system_reset() |
| 1927 | |
| 1928 | This function is called by PSCI implementation in response to a `SYSTEM_RESET` |
| 1929 | call. It performs the platform-specific system reset sequence after |
| 1930 | notifying the Secure Payload Dispatcher. |
| 1931 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1932 | #### plat_psci_ops.validate_power_state() |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1933 | |
| 1934 | This function is called by the PSCI implementation during the `CPU_SUSPEND` |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1935 | call to validate the `power_state` parameter of the PSCI API and if valid, |
| 1936 | populate it in `req_state` (second argument) array as power domain level |
| 1937 | specific local states. If the `power_state` is invalid, the platform must |
| 1938 | return PSCI_E_INVALID_PARAMS as error, which is propagated back to the |
| 1939 | normal world PSCI client. |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1940 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1941 | #### plat_psci_ops.validate_ns_entrypoint() |
Soby Mathew | 539dced | 2014-10-02 16:56:51 +0100 | [diff] [blame] | 1942 | |
Soby Mathew | c0aff0e | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 1943 | This function is called by the PSCI implementation during the `CPU_SUSPEND`, |
| 1944 | `SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point` |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1945 | parameter passed by the normal world. If the `entry_point` is invalid, |
| 1946 | the platform must return PSCI_E_INVALID_ADDRESS as error, which is |
Soby Mathew | c0aff0e | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 1947 | propagated back to the normal world PSCI client. |
| 1948 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1949 | #### plat_psci_ops.get_sys_suspend_power_state() |
Soby Mathew | c0aff0e | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 1950 | |
| 1951 | This function is called by the PSCI implementation during the `SYSTEM_SUSPEND` |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 1952 | call to get the `req_state` parameter from platform which encodes the power |
| 1953 | domain level specific local states to suspend to system affinity level. The |
| 1954 | `req_state` will be utilized to do the PSCI state coordination and |
| 1955 | `pwr_domain_suspend()` will be invoked with the coordinated target state to |
| 1956 | enter system suspend. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1957 | |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 1958 | #### plat_psci_ops.get_pwr_lvl_state_idx() |
| 1959 | |
| 1960 | This is an optional function and, if implemented, is invoked by the PSCI |
| 1961 | implementation to convert the `local_state` (first argument) at a specified |
| 1962 | `pwr_lvl` (second argument) to an index between 0 and |
| 1963 | `PLAT_MAX_PWR_LVL_STATES` - 1. This function is only needed if the platform |
| 1964 | supports more than two local power states at each power domain level, that is |
| 1965 | `PLAT_MAX_PWR_LVL_STATES` is greater than 2, and needs to account for these |
| 1966 | local power states. |
| 1967 | |
| 1968 | #### plat_psci_ops.translate_power_state_by_mpidr() |
| 1969 | |
| 1970 | This is an optional function and, if implemented, verifies the `power_state` |
| 1971 | (second argument) parameter of the PSCI API corresponding to a target power |
| 1972 | domain. The target power domain is identified by using both `MPIDR` (first |
| 1973 | argument) and the power domain level encoded in `power_state`. The power domain |
| 1974 | level specific local states are to be extracted from `power_state` and be |
| 1975 | populated in the `output_state` (third argument) array. The functionality |
| 1976 | is similar to the `validate_power_state` function described above and is |
| 1977 | envisaged to be used in case the validity of `power_state` depend on the |
| 1978 | targeted power domain. If the `power_state` is invalid for the targeted power |
| 1979 | domain, the platform must return PSCI_E_INVALID_PARAMS as error. If this |
| 1980 | function is not implemented, then the generic implementation relies on |
| 1981 | `validate_power_state` function to translate the `power_state`. |
| 1982 | |
| 1983 | This function can also be used in case the platform wants to support local |
| 1984 | power state encoding for `power_state` parameter of PSCI_STAT_COUNT/RESIDENCY |
| 1985 | APIs as described in Section 5.18 of [PSCI]. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1986 | |
Jeenu Viswambharan | 28d3d61 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 1987 | #### plat_psci_ops.get_node_hw_state() |
| 1988 | |
| 1989 | This is an optional function. If implemented this function is intended to return |
| 1990 | the power state of a node (identified by the first parameter, the `MPIDR`) in |
| 1991 | the power domain topology (identified by the second parameter, `power_level`), |
| 1992 | as retrieved from a power controller or equivalent component on the platform. |
| 1993 | Upon successful completion, the implementation must map and return the final |
| 1994 | status among `HW_ON`, `HW_OFF` or `HW_STANDBY`. Upon encountering failures, it |
| 1995 | must return either `PSCI_E_INVALID_PARAMS` or `PSCI_E_NOT_SUPPORTED` as |
| 1996 | appropriate. |
| 1997 | |
| 1998 | Implementations are not expected to handle `power_levels` greater than |
| 1999 | `PLAT_MAX_PWR_LVL`. |
| 2000 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 2001 | 3.6 Interrupt Management framework (in BL31) |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2002 | ---------------------------------------------- |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 2003 | BL31 implements an Interrupt Management Framework (IMF) to manage interrupts |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2004 | generated in either security state and targeted to EL1 or EL2 in the non-secure |
| 2005 | state or EL3/S-EL1 in the secure state. The design of this framework is |
| 2006 | described in the [IMF Design Guide] |
| 2007 | |
| 2008 | 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] | 2009 | text briefly describes each api and its implementation in ARM standard |
| 2010 | platforms. The API implementation depends upon the type of interrupt controller |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2011 | present in the platform. ARM standard platform layer supports both [ARM Generic |
| 2012 | Interrupt Controller version 2.0 (GICv2)][ARM GIC Architecture Specification 2.0] |
| 2013 | and [3.0 (GICv3)][ARM GIC Architecture Specification 3.0]. Juno builds the ARM |
| 2014 | Standard layer to use GICv2 and the FVP can be configured to use either GICv2 or |
| 2015 | GICv3 depending on the build flag `FVP_USE_GIC_DRIVER` (See FVP platform |
| 2016 | specific build options in [User Guide] for more details). |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2017 | |
| 2018 | ### Function : plat_interrupt_type_to_line() [mandatory] |
| 2019 | |
| 2020 | Argument : uint32_t, uint32_t |
| 2021 | Return : uint32_t |
| 2022 | |
| 2023 | The ARM processor signals an interrupt exception either through the IRQ or FIQ |
| 2024 | interrupt line. The specific line that is signaled depends on how the interrupt |
| 2025 | controller (IC) reports different interrupt types from an execution context in |
| 2026 | either security state. The IMF uses this API to determine which interrupt line |
| 2027 | the platform IC uses to signal each type of interrupt supported by the framework |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2028 | from a given security state. This API must be invoked at EL3. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2029 | |
| 2030 | The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design |
| 2031 | Guide]) indicating the target type of the interrupt, the second parameter is the |
| 2032 | security state of the originating execution context. The return result is the |
| 2033 | bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1, |
| 2034 | FIQ=2. |
| 2035 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2036 | In the case of ARM standard platforms using GICv2, S-EL1 interrupts are |
| 2037 | configured as FIQs and Non-secure interrupts as IRQs from either security |
| 2038 | state. |
| 2039 | |
| 2040 | In the case of ARM standard platforms using GICv3, the interrupt line to be |
| 2041 | configured depends on the security state of the execution context when the |
| 2042 | interrupt is signalled and are as follows: |
| 2043 | * The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in |
| 2044 | NS-EL0/1/2 context. |
| 2045 | * The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ |
| 2046 | in the NS-EL0/1/2 context. |
| 2047 | * The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2 |
| 2048 | context. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2049 | |
| 2050 | |
| 2051 | ### Function : plat_ic_get_pending_interrupt_type() [mandatory] |
| 2052 | |
| 2053 | Argument : void |
| 2054 | Return : uint32_t |
| 2055 | |
| 2056 | This API returns the type of the highest priority pending interrupt at the |
| 2057 | platform IC. The IMF uses the interrupt type to retrieve the corresponding |
| 2058 | handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt |
| 2059 | pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`, |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2060 | `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`. This API must be invoked at EL3. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2061 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2062 | In the case of ARM standard platforms using GICv2, the _Highest Priority |
| 2063 | Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of |
| 2064 | the pending interrupt. The type of interrupt depends upon the id value as |
| 2065 | follows. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2066 | |
| 2067 | 1. id < 1022 is reported as a S-EL1 interrupt |
| 2068 | 2. id = 1022 is reported as a Non-secure interrupt. |
| 2069 | 3. id = 1023 is reported as an invalid interrupt type. |
| 2070 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2071 | In the case of ARM standard platforms using GICv3, the system register |
| 2072 | `ICC_HPPIR0_EL1`, _Highest Priority Pending group 0 Interrupt Register_, |
| 2073 | is read to determine the id of the pending interrupt. The type of interrupt |
| 2074 | depends upon the id value as follows. |
| 2075 | |
| 2076 | 1. id = `PENDING_G1S_INTID` (1020) is reported as a S-EL1 interrupt |
| 2077 | 2. id = `PENDING_G1NS_INTID` (1021) is reported as a Non-secure interrupt. |
| 2078 | 3. id = `GIC_SPURIOUS_INTERRUPT` (1023) is reported as an invalid interrupt type. |
| 2079 | 4. All other interrupt id's are reported as EL3 interrupt. |
| 2080 | |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2081 | |
| 2082 | ### Function : plat_ic_get_pending_interrupt_id() [mandatory] |
| 2083 | |
| 2084 | Argument : void |
| 2085 | Return : uint32_t |
| 2086 | |
| 2087 | This API returns the id of the highest priority pending interrupt at the |
Sandrine Bailleux | 1645d3e | 2015-12-17 13:58:58 +0000 | [diff] [blame] | 2088 | platform IC. `INTR_ID_UNAVAILABLE` is returned when there is no interrupt |
Soby Mathew | 5471841 | 2015-10-27 10:01:06 +0000 | [diff] [blame] | 2089 | pending. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2090 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2091 | In the case of ARM standard platforms using GICv2, the _Highest Priority |
| 2092 | Pending Interrupt Register_ (`GICC_HPPIR`) is read to determine the id of the |
| 2093 | pending interrupt. The id that is returned by API depends upon the value of |
| 2094 | the id read from the interrupt controller as follows. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2095 | |
| 2096 | 1. id < 1022. id is returned as is. |
| 2097 | 2. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_ |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2098 | (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. |
| 2099 | This id is returned by the API. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2100 | 3. id = 1023. `INTR_ID_UNAVAILABLE` is returned. |
| 2101 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2102 | In the case of ARM standard platforms using GICv3, if the API is invoked from |
| 2103 | EL3, the system register `ICC_HPPIR0_EL1`, _Highest Priority Pending Interrupt |
| 2104 | group 0 Register_, is read to determine the id of the pending interrupt. The id |
| 2105 | that is returned by API depends upon the value of the id read from the |
| 2106 | interrupt controller as follows. |
| 2107 | |
| 2108 | 1. id < `PENDING_G1S_INTID` (1020). id is returned as is. |
| 2109 | 2. id = `PENDING_G1S_INTID` (1020) or `PENDING_G1NS_INTID` (1021). The system |
| 2110 | register `ICC_HPPIR1_EL1`, _Highest Priority Pending Interrupt group 1 |
| 2111 | Register_ is read to determine the id of the group 1 interrupt. This id |
| 2112 | is returned by the API as long as it is a valid interrupt id |
| 2113 | 3. If the id is any of the special interrupt identifiers, |
| 2114 | `INTR_ID_UNAVAILABLE` is returned. |
| 2115 | |
| 2116 | When the API invoked from S-EL1 for GICv3 systems, the id read from system |
| 2117 | register `ICC_HPPIR1_EL1`, _Highest Priority Pending group 1 Interrupt |
| 2118 | Register_, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else |
| 2119 | `INTR_ID_UNAVAILABLE` is returned. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2120 | |
| 2121 | ### Function : plat_ic_acknowledge_interrupt() [mandatory] |
| 2122 | |
| 2123 | Argument : void |
| 2124 | Return : uint32_t |
| 2125 | |
| 2126 | This API is used by the CPU to indicate to the platform IC that processing of |
| 2127 | the highest pending interrupt has begun. It should return the id of the |
| 2128 | interrupt which is being processed. |
| 2129 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2130 | This function in ARM standard platforms using GICv2, reads the _Interrupt |
| 2131 | Acknowledge Register_ (`GICC_IAR`). This changes the state of the highest |
| 2132 | priority pending interrupt from pending to active in the interrupt controller. |
| 2133 | It returns the value read from the `GICC_IAR`. This value is the id of the |
| 2134 | interrupt whose state has been changed. |
| 2135 | |
| 2136 | In the case of ARM standard platforms using GICv3, if the API is invoked |
| 2137 | from EL3, the function reads the system register `ICC_IAR0_EL1`, _Interrupt |
| 2138 | Acknowledge Register group 0_. If the API is invoked from S-EL1, the function |
| 2139 | reads the system register `ICC_IAR1_EL1`, _Interrupt Acknowledge Register |
| 2140 | group 1_. The read changes the state of the highest pending interrupt from |
| 2141 | pending to active in the interrupt controller. The value read is returned |
| 2142 | and is the id of the interrupt whose state has been changed. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2143 | |
| 2144 | The TSP uses this API to start processing of the secure physical timer |
| 2145 | interrupt. |
| 2146 | |
| 2147 | |
| 2148 | ### Function : plat_ic_end_of_interrupt() [mandatory] |
| 2149 | |
| 2150 | Argument : uint32_t |
| 2151 | Return : void |
| 2152 | |
| 2153 | This API is used by the CPU to indicate to the platform IC that processing of |
| 2154 | the interrupt corresponding to the id (passed as the parameter) has |
| 2155 | finished. The id should be the same as the id returned by the |
| 2156 | `plat_ic_acknowledge_interrupt()` API. |
| 2157 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 2158 | ARM standard platforms write the id to the _End of Interrupt Register_ |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2159 | (`GICC_EOIR`) in case of GICv2, and to `ICC_EOIR0_EL1` or `ICC_EOIR1_EL1` |
| 2160 | system register in case of GICv3 depending on where the API is invoked from, |
| 2161 | EL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2162 | controller. |
| 2163 | |
| 2164 | The TSP uses this API to finish processing of the secure physical timer |
| 2165 | interrupt. |
| 2166 | |
| 2167 | |
| 2168 | ### Function : plat_ic_get_interrupt_type() [mandatory] |
| 2169 | |
| 2170 | Argument : uint32_t |
| 2171 | Return : uint32_t |
| 2172 | |
| 2173 | This API returns the type of the interrupt id passed as the parameter. |
| 2174 | `INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid |
| 2175 | interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is |
| 2176 | returned depending upon how the interrupt has been configured by the platform |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2177 | IC. This API must be invoked at EL3. |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2178 | |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2179 | ARM standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts |
| 2180 | and Non-secure interrupts as Group1 interrupts. It reads the group value |
| 2181 | corresponding to the interrupt id from the relevant _Interrupt Group Register_ |
| 2182 | (`GICD_IGROUPRn`). It uses the group value to determine the type of interrupt. |
| 2183 | |
| 2184 | In the case of ARM standard platforms using GICv3, both the _Interrupt Group |
| 2185 | Register_ (`GICD_IGROUPRn`) and _Interrupt Group Modifier Register_ |
| 2186 | (`GICD_IGRPMODRn`) is read to figure out whether the interrupt is configured |
| 2187 | as Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt. |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 2188 | |
Achin Gupta | a4fa3cb | 2014-06-02 22:27:36 +0100 | [diff] [blame] | 2189 | |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 2190 | 3.7 Crash Reporting mechanism (in BL31) |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 2191 | ---------------------------------------------- |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 2192 | BL31 implements a crash reporting mechanism which prints the various registers |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 2193 | of the CPU to enable quick crash analysis and debugging. It requires that a |
| 2194 | console is designated as the crash console by the platform which will be used to |
| 2195 | print the register dump. |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 2196 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 2197 | The following functions must be implemented by the platform if it wants crash |
Juan Castillo | d178637 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 2198 | reporting mechanism in BL31. The functions are implemented in assembly so that |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 2199 | they can be invoked without a C Runtime stack. |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 2200 | |
| 2201 | ### Function : plat_crash_console_init |
| 2202 | |
| 2203 | Argument : void |
| 2204 | Return : int |
| 2205 | |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 2206 | This API is used by the crash reporting mechanism to initialize the crash |
Juan Castillo | 9400b40 | 2015-11-26 14:52:15 +0000 | [diff] [blame] | 2207 | console. It must only use the general purpose registers x0 to x4 to do the |
Sandrine Bailleux | 4480425 | 2014-08-06 11:27:23 +0100 | [diff] [blame] | 2208 | initialization and returns 1 on success. |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 2209 | |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 2210 | ### Function : plat_crash_console_putc |
| 2211 | |
| 2212 | Argument : int |
| 2213 | Return : int |
| 2214 | |
| 2215 | This API is used by the crash reporting mechanism to print a character on the |
Juan Castillo | 9400b40 | 2015-11-26 14:52:15 +0000 | [diff] [blame] | 2216 | designated crash console. It must only use general purpose registers x1 and |
Soby Mathew | c67b09b | 2014-07-14 16:57:23 +0100 | [diff] [blame] | 2217 | x2 to do its work. The parameter and the return value are in general purpose |
| 2218 | register x0. |
| 2219 | |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 2220 | 4. Build flags |
| 2221 | --------------- |
| 2222 | |
Soby Mathew | 58523c0 | 2015-06-08 12:32:50 +0100 | [diff] [blame] | 2223 | * **ENABLE_PLAT_COMPAT** |
| 2224 | All the platforms ports conforming to this API specification should define |
| 2225 | the build flag `ENABLE_PLAT_COMPAT` to 0 as the compatibility layer should |
| 2226 | be disabled. For more details on compatibility layer, refer |
| 2227 | [Migration Guide]. |
| 2228 | |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 2229 | There are some build flags which can be defined by the platform to control |
| 2230 | inclusion or exclusion of certain BL stages from the FIP image. These flags |
| 2231 | need to be defined in the platform makefile which will get included by the |
| 2232 | build system. |
| 2233 | |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 2234 | * **NEED_BL33** |
| 2235 | By default, this flag is defined `yes` by the build system and `BL33` |
Antonio Nino Diaz | cf2c8a3 | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 2236 | build option should be supplied as a build option. The platform has the |
| 2237 | option of excluding the BL33 image in the `fip` image by defining this flag |
Antonio Nino Diaz | 68450a6 | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 2238 | to `no`. If any of the options `EL3_PAYLOAD_BASE` or `PRELOADED_BL33_BASE` |
| 2239 | are used, this flag will be set to `no` automatically. |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 2240 | |
| 2241 | 5. C Library |
Harry Liebel | a960f28 | 2013-12-12 16:03:44 +0000 | [diff] [blame] | 2242 | ------------- |
| 2243 | |
| 2244 | To avoid subtle toolchain behavioral dependencies, the header files provided |
| 2245 | by the compiler are not used. The software is built with the `-nostdinc` flag |
| 2246 | to ensure no headers are included from the toolchain inadvertently. Instead the |
| 2247 | required headers are included in the ARM Trusted Firmware source tree. The |
| 2248 | library only contains those C library definitions required by the local |
| 2249 | implementation. If more functionality is required, the needed library functions |
| 2250 | will need to be added to the local implementation. |
| 2251 | |
Dan Handley | f0b489c | 2016-06-02 17:15:13 +0100 | [diff] [blame] | 2252 | Versions of [FreeBSD] headers can be found in `include/lib/stdlib`. Some of |
| 2253 | these headers have been cut down in order to simplify the implementation. In |
| 2254 | order to minimize changes to the header files, the [FreeBSD] layout has been |
| 2255 | maintained. The generic C library definitions can be found in |
| 2256 | `include/lib/stdlib` with more system and machine specific declarations in |
| 2257 | `include/lib/stdlib/sys` and `include/lib/stdlib/machine`. |
Harry Liebel | a960f28 | 2013-12-12 16:03:44 +0000 | [diff] [blame] | 2258 | |
| 2259 | The local C library implementations can be found in `lib/stdlib`. In order to |
| 2260 | extend the C library these files may need to be modified. It is recommended to |
| 2261 | use a release version of [FreeBSD] as a starting point. |
| 2262 | |
| 2263 | The C library header files in the [FreeBSD] source tree are located in the |
| 2264 | `include` and `sys/sys` directories. [FreeBSD] machine specific definitions |
| 2265 | can be found in the `sys/<machine-type>` directories. These files define things |
| 2266 | like 'the size of a pointer' and 'the range of an integer'. Since an AArch64 |
| 2267 | port for [FreeBSD] does not yet exist, the machine specific definitions are |
| 2268 | based on existing machine types with similar properties (for example SPARC64). |
| 2269 | |
| 2270 | Where possible, C library function implementations were taken from [FreeBSD] |
| 2271 | as found in the `lib/libc` directory. |
| 2272 | |
| 2273 | A copy of the [FreeBSD] sources can be downloaded with `git`. |
| 2274 | |
| 2275 | git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0 |
| 2276 | |
| 2277 | |
Soby Mathew | 27713fb | 2014-09-08 17:51:01 +0100 | [diff] [blame] | 2278 | 6. Storage abstraction layer |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 2279 | ----------------------------- |
| 2280 | |
| 2281 | In order to improve platform independence and portability an storage abstraction |
| 2282 | layer is used to load data from non-volatile platform storage. |
| 2283 | |
| 2284 | Each platform should register devices and their drivers via the Storage layer. |
| 2285 | These drivers then need to be initialized by bootloader phases as |
| 2286 | required in their respective `blx_platform_setup()` functions. Currently |
| 2287 | storage access is only required by BL1 and BL2 phases. The `load_image()` |
| 2288 | function uses the storage layer to access non-volatile platform storage. |
| 2289 | |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 2290 | It is mandatory to implement at least one storage driver. For the ARM |
| 2291 | development platforms the Firmware Image Package (FIP) driver is provided as |
| 2292 | the default means to load data from storage (see the "Firmware Image Package" |
| 2293 | section in the [User Guide]). The storage layer is described in the header file |
| 2294 | `include/drivers/io/io_storage.h`. The implementation of the common library |
Sandrine Bailleux | 121f2ae | 2015-01-28 10:11:48 +0000 | [diff] [blame] | 2295 | is in `drivers/io/io_storage.c` and the driver files are located in |
| 2296 | `drivers/io/`. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 2297 | |
| 2298 | Each IO driver must provide `io_dev_*` structures, as described in |
| 2299 | `drivers/io/io_driver.h`. These are returned via a mandatory registration |
| 2300 | function that is called on platform initialization. The semi-hosting driver |
| 2301 | implementation in `io_semihosting.c` can be used as an example. |
| 2302 | |
| 2303 | The Storage layer provides mechanisms to initialize storage devices before |
| 2304 | IO operations are called. The basic operations supported by the layer |
| 2305 | include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`. |
| 2306 | Drivers do not have to implement all operations, but each platform must |
| 2307 | provide at least one driver for a device capable of supporting generic |
| 2308 | operations such as loading a bootloader image. |
| 2309 | |
| 2310 | The current implementation only allows for known images to be loaded by the |
Juan Castillo | 16948ae | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 2311 | firmware. These images are specified by using their identifiers, as defined in |
| 2312 | [include/plat/common/platform_def.h] (or a separate header file included from |
| 2313 | there). The platform layer (`plat_get_image_source()`) then returns a reference |
| 2314 | to a device and a driver-specific `spec` which will be understood by the driver |
| 2315 | to allow access to the image data. |
Harry Liebel | d265bd7 | 2014-01-31 19:04:10 +0000 | [diff] [blame] | 2316 | |
| 2317 | The layer is designed in such a way that is it possible to chain drivers with |
| 2318 | other drivers. For example, file-system drivers may be implemented on top of |
| 2319 | physical block devices, both represented by IO devices with corresponding |
| 2320 | drivers. In such a case, the file-system "binding" with the block device may |
| 2321 | be deferred until the file-system device is initialised. |
| 2322 | |
| 2323 | The abstraction currently depends on structures being statically allocated |
| 2324 | by the drivers and callers, as the system does not yet provide a means of |
| 2325 | dynamically allocating memory. This may also have the affect of limiting the |
| 2326 | amount of open resources per driver. |
| 2327 | |
| 2328 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 2329 | - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 2330 | |
Sandrine Bailleux | eaefdec | 2016-01-26 15:00:40 +0000 | [diff] [blame] | 2331 | _Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved._ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 2332 | |
| 2333 | |
Yuping Luo | 6b14041 | 2016-01-15 11:17:27 +0800 | [diff] [blame] | 2334 | [ARM GIC Architecture Specification 2.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html |
| 2335 | [ARM GIC Architecture Specification 3.0]: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0069b/index.html |
Soby Mathew | 81123e8 | 2015-11-23 14:01:21 +0000 | [diff] [blame] | 2336 | [IMF Design Guide]: interrupt-framework-design.md |
| 2337 | [User Guide]: user-guide.md |
| 2338 | [FreeBSD]: http://www.freebsd.org |
| 2339 | [Firmware Design]: firmware-design.md |
| 2340 | [Power Domain Topology Design]: psci-pd-tree.md |
| 2341 | [PSCI]: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf |
| 2342 | [Migration Guide]: platform-migration-guide.md |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 2343 | [Firmware Update]: firmware-update.md |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 2344 | |
Andrew Thoelke | 2bf28e6 | 2014-03-20 10:48:23 +0000 | [diff] [blame] | 2345 | [plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S |
| 2346 | [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] | 2347 | [plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c |
Yatharth Kochar | 84a5d6d | 2015-10-27 15:55:18 +0000 | [diff] [blame] | 2348 | [include/common/bl_common.h]: ../include/common/bl_common.h |
Yatharth Kochar | 1a0a3f0 | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 2349 | [include/lib/aarch32/arch.h]: ../include/lib/aarch32/arch.h |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 2350 | [include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h |
| 2351 | [include/plat/common/common_def.h]: ../include/plat/common/common_def.h |
Dan Handley | b68954c | 2014-05-29 12:30:24 +0100 | [diff] [blame] | 2352 | [include/plat/common/platform.h]: ../include/plat/common/platform.h |
Dan Handley | 4a75b84 | 2015-03-19 19:24:43 +0000 | [diff] [blame] | 2353 | [include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h] |