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