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