blob: 6846ddfe2c52738920097a82f498c9e6f718980a [file] [log] [blame] [view]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001ARM Trusted Firmware Porting Guide
2==================================
3
4Contents
5--------
6
Joakim Bech14a5b342014-11-25 10:55:26 +010071. [Introduction](#1--introduction)
82. [Common Modifications](#2--common-modifications)
9 * [Common mandatory modifications](#21-common-mandatory-modifications)
10 * [Handling reset](#22-handling-reset)
Soby Mathew58523c02015-06-08 12:32:50 +010011 * [Common mandatory modifications](#23-common-mandatory-modifications)
12 * [Common optional modifications](#24-common-optional-modifications)
Joakim Bech14a5b342014-11-25 10:55:26 +0100133. [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)
204. [Build flags](#4--build-flags)
215. [C Library](#5--c-library)
226. [Storage abstraction layer](#6--storage-abstraction-layer)
Achin Gupta4f6ad662013-10-25 09:08:21 +010023
24- - - - - - - - - - - - - - - - - -
25
261. Introduction
27----------------
28
Soby Mathew58523c02015-06-08 12:32:50 +010029Please note that this document has been updated for the new platform API
30as required by the PSCI v1.0 implementation. Please refer to the
31[Migration Guide] for the previous platform API.
32
Achin Gupta4f6ad662013-10-25 09:08:21 +010033Porting the ARM Trusted Firmware to a new platform involves making some
34mandatory and optional modifications for both the cold and warm boot paths.
35Modifications 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 Handley4a75b842015-03-19 19:24:43 +000041The platform-specific functions and variables are declared in
Dan Handleyb68954c2014-05-29 12:30:24 +010042[include/plat/common/platform.h]. The firmware provides a default implementation
43of variables and functions to fulfill the optional requirements. These
44implementations are all weakly defined; they are provided to ease the porting
45effort. Each platform port can override them with its own implementation if the
46default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010047
Dan Handley4a75b842015-03-19 19:24:43 +000048Platform ports that want to be aligned with standard ARM platforms (for example
49FVP and Juno) may also use [include/plat/arm/common/plat_arm.h] and the
50corresponding source files in `plat/arm/common/`. These provide standard
51implementations for some of the required platform porting functions. However,
52using these functions requires the platform port to implement additional
53ARM standard platform porting functions. These additional functions are not
54documented here.
55
Achin Gupta4f6ad662013-10-25 09:08:21 +010056Some modifications are common to all Boot Loader (BL) stages. Section 2
57discusses these in detail. The subsequent sections discuss the remaining
58modifications for each BL stage in detail.
59
60This document should be read in conjunction with the ARM Trusted Firmware
61[User Guide].
62
63
642. Common modifications
65------------------------
66
67This section covers the modifications that should be made by the platform for
68each BL stage to correctly port the firmware stack. They are categorized as
69either mandatory or optional.
70
71
722.1 Common mandatory modifications
73----------------------------------
74A platform port must enable the Memory Management Unit (MMU) with identity
75mapped page tables, and enable both the instruction and data caches for each BL
Dan Handley4a75b842015-03-19 19:24:43 +000076stage. In ARM standard platforms, each BL stage configures the MMU in
77the platform-specific architecture setup function, `blX_plat_arch_setup()`.
Achin Gupta4f6ad662013-10-25 09:08:21 +010078
Soby Mathewab8707e2015-01-08 18:02:44 +000079If the build option `USE_COHERENT_MEM` is enabled, each platform must allocate a
80block of identity mapped secure memory with Device-nGnRE attributes aligned to
81page boundary (4K) for each BL stage. This memory is identified by the section
82name `tzfw_coherent_mem` so that its possible for the firmware to place
83variables in it using the following C code directive:
Achin Gupta4f6ad662013-10-25 09:08:21 +010084
85 __attribute__ ((section("tzfw_coherent_mem")))
86
87Or alternatively the following assembler code directive:
88
89 .section tzfw_coherent_mem
90
91The `tzfw_coherent_mem` section is used to allocate any data structures that are
92accessed both when a CPU is executing with its MMU and caches enabled, and when
93it's running with its MMU and caches disabled. Examples are given below.
94
95The following variables, functions and constants must be defined by the platform
96for the firmware to work correctly.
97
98
Dan Handleyb68954c2014-05-29 12:30:24 +010099### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100100
Dan Handleyb68954c2014-05-29 12:30:24 +0100101Each platform must ensure that a header file of this name is in the system
102include path with the following constants defined. This may require updating the
Dan Handley4a75b842015-03-19 19:24:43 +0000103list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM development
104platforms, this file is found in `plat/arm/board/<plat_name>/include/`.
105
106Platform ports may optionally use the file [include/plat/common/common_def.h],
107which provides typical values for some of the constants below. These values are
108likely to be suitable for all platform ports.
109
110Platform ports that want to be aligned with standard ARM platforms (for example
111FVP and Juno) may also use [include/plat/arm/common/arm_def.h], which provides
112standard values for some of the constants below. However, this requires the
113platform port to define additional platform porting constants in
114`platform_def.h`. These additional constants are not documented here.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115
James Morrisseyba3155b2013-10-29 10:56:46 +0000116* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100117
118 Defines the linker format used by the platform, for example
Dan Handley4a75b842015-03-19 19:24:43 +0000119 `elf64-littleaarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100120
James Morrisseyba3155b2013-10-29 10:56:46 +0000121* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100122
123 Defines the processor architecture for the linker by the platform, for
Dan Handley4a75b842015-03-19 19:24:43 +0000124 example `aarch64`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100125
James Morrisseyba3155b2013-10-29 10:56:46 +0000126* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100127
128 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000129 by [plat/common/aarch64/platform_mp_stack.S] and
130 [plat/common/aarch64/platform_up_stack.S].
131
Dan Handley4a75b842015-03-19 19:24:43 +0000132* **define : CACHE_WRITEBACK_GRANULE**
133
134 Defines the size in bits of the largest cache line across all the cache
135 levels in the platform.
136
James Morrisseyba3155b2013-10-29 10:56:46 +0000137* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100138
139 Defines the character string printed by BL1 upon entry into the `bl1_main()`
140 function.
141
James Morrisseyba3155b2013-10-29 10:56:46 +0000142* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100143
144 Defines the total number of CPUs implemented by the platform across all
145 clusters in the system.
146
Soby Mathew58523c02015-06-08 12:32:50 +0100147* **#define : PLAT_NUM_PWR_DOMAINS**
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100148
Soby Mathew58523c02015-06-08 12:32:50 +0100149 Defines the total number of nodes in the power domain topology
150 tree at all the power domain levels used by the platform.
151 This macro is used by the PSCI implementation to allocate
152 data structures to represent power domain topology.
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100153
Soby Mathew58523c02015-06-08 12:32:50 +0100154* **#define : PLAT_MAX_PWR_LVL**
Soby Mathew8c32bc22015-02-12 14:45:02 +0000155
Soby Mathew58523c02015-06-08 12:32:50 +0100156 Defines the maximum power domain level that the power management operations
157 should apply to. More often, but not always, the power domain level
158 corresponds to affinity level. This macro allows the PSCI implementation
159 to know the highest power domain level that it should consider for power
160 management operations in the system that the platform implements. For
161 example, the Base AEM FVP implements two clusters with a configurable
162 number of CPUs and it reports the maximum power domain level as 1.
163
164* **#define : PLAT_MAX_OFF_STATE**
165
166 Defines the local power state corresponding to the deepest power down
167 possible at every power domain level in the platform. The local power
168 states for each level may be sparsely allocated between 0 and this value
169 with 0 being reserved for the RUN state. The PSCI implementation uses this
170 value to initialize the local power states of the power domain nodes and
171 to specify the requested power state for a PSCI_CPU_OFF call.
172
173* **#define : PLAT_MAX_RET_STATE**
174
175 Defines the local power state corresponding to the deepest retention state
176 possible at every power domain level in the platform. This macro should be
177 a value less than PLAT_MAX_OFF_STATE and greater than 0. It is used by the
178 PSCI implementation to distuiguish between retention and power down local
179 power states within PSCI_CPU_SUSPEND call.
Soby Mathew8c32bc22015-02-12 14:45:02 +0000180
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100181* **#define : BL1_RO_BASE**
182
183 Defines the base address in secure ROM where BL1 originally lives. Must be
184 aligned on a page-size boundary.
185
186* **#define : BL1_RO_LIMIT**
187
188 Defines the maximum address in secure ROM that BL1's actual content (i.e.
189 excluding any data section allocated at runtime) can occupy.
190
191* **#define : BL1_RW_BASE**
192
193 Defines the base address in secure RAM where BL1's read-write data will live
194 at runtime. Must be aligned on a page-size boundary.
195
196* **#define : BL1_RW_LIMIT**
197
198 Defines the maximum address in secure RAM that BL1's read-write data can
199 occupy at runtime.
200
James Morrisseyba3155b2013-10-29 10:56:46 +0000201* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100202
203 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000204 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100205
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100206* **#define : BL2_LIMIT**
207
208 Defines the maximum address in secure RAM that the BL2 image can occupy.
209
James Morrisseyba3155b2013-10-29 10:56:46 +0000210* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100211
212 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000213 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100214
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100215* **#define : BL31_LIMIT**
216
217 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
218
Harry Liebeld265bd72014-01-31 19:04:10 +0000219* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100220
Harry Liebeld265bd72014-01-31 19:04:10 +0000221 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
222 image. Must be aligned on a page-size boundary.
223
Juan Castillo16948ae2015-04-13 17:36:19 +0100224For every image, the platform must define individual identifiers that will be
225used by BL1 or BL2 to load the corresponding image into memory from non-volatile
226storage. For the sake of performance, integer numbers will be used as
227identifiers. The platform will use those identifiers to return the relevant
228information about the image to be loaded (file handler, load address,
229authentication information, etc.). The following image identifiers are
230mandatory:
231
232* **#define : BL2_IMAGE_ID**
233
234 BL2 image identifier, used by BL1 to load BL2.
235
236* **#define : BL31_IMAGE_ID**
237
238 BL3-1 image identifier, used by BL2 to load BL3-1.
239
240* **#define : BL33_IMAGE_ID**
241
242 BL3-3 image identifier, used by BL2 to load BL3-3.
243
244If Trusted Board Boot is enabled, the following certificate identifiers must
245also be defined:
246
247* **#define : BL2_CERT_ID**
248
249 BL2 content certificate identifier, used by BL1 to load the BL2 content
250 certificate.
251
252* **#define : TRUSTED_KEY_CERT_ID**
253
254 Trusted key certificate identifier, used by BL2 to load the trusted key
255 certificate.
256
257* **#define : BL31_KEY_CERT_ID**
258
259 BL3-1 key certificate identifier, used by BL2 to load the BL3-1 key
260 certificate.
261
262* **#define : BL31_CERT_ID**
263
264 BL3-1 content certificate identifier, used by BL2 to load the BL3-1 content
265 certificate.
266
267* **#define : BL33_KEY_CERT_ID**
268
269 BL3-3 key certificate identifier, used by BL2 to load the BL3-3 key
270 certificate.
271
272* **#define : BL33_CERT_ID**
273
274 BL3-3 content certificate identifier, used by BL2 to load the BL3-3 content
275 certificate.
276
Achin Gupta8d35f612015-01-25 22:44:23 +0000277If a BL3-0 image is supported by the platform, the following constants must
278also be defined:
279
Juan Castillo16948ae2015-04-13 17:36:19 +0100280* **#define : BL30_IMAGE_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000281
Juan Castillo16948ae2015-04-13 17:36:19 +0100282 BL3-0 image identifier, used by BL2 to load BL3-0 into secure memory from
283 platform storage before being transfered to the SCP.
Achin Gupta8d35f612015-01-25 22:44:23 +0000284
Juan Castillo16948ae2015-04-13 17:36:19 +0100285* **#define : BL30_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000286
Juan Castillo16948ae2015-04-13 17:36:19 +0100287 BL3-0 key certificate identifier, used by BL2 to load the BL3-0 key
288 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000289
Juan Castillo16948ae2015-04-13 17:36:19 +0100290* **#define : BL30_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000291
Juan Castillo16948ae2015-04-13 17:36:19 +0100292 BL3-0 content certificate identifier, used by BL2 to load the BL3-0 content
293 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000294
Dan Handley5a06bb72014-08-04 11:41:20 +0100295If a BL3-2 image is supported by the platform, the following constants must
296also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100297
Juan Castillo16948ae2015-04-13 17:36:19 +0100298* **#define : BL32_IMAGE_ID**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100299
Juan Castillo16948ae2015-04-13 17:36:19 +0100300 BL3-2 image identifier, used by BL2 to load BL3-2.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100301
Juan Castillo16948ae2015-04-13 17:36:19 +0100302* **#define : BL32_KEY_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000303
Juan Castillo16948ae2015-04-13 17:36:19 +0100304 BL3-2 key certificate identifier, used by BL2 to load the BL3-2 key
305 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000306
Juan Castillo16948ae2015-04-13 17:36:19 +0100307* **#define : BL32_CERT_ID**
Achin Gupta8d35f612015-01-25 22:44:23 +0000308
Juan Castillo16948ae2015-04-13 17:36:19 +0100309 BL3-2 content certificate identifier, used by BL2 to load the BL3-2 content
310 certificate (mandatory when Trusted Board Boot is enabled).
Achin Gupta8d35f612015-01-25 22:44:23 +0000311
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100312* **#define : BL32_BASE**
313
314 Defines the base address in secure memory where BL2 loads the BL3-2 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100315 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100316
317* **#define : BL32_LIMIT**
318
Dan Handley5a06bb72014-08-04 11:41:20 +0100319 Defines the maximum address that the BL3-2 image can occupy.
320
321If the Test Secure-EL1 Payload (TSP) instantiation of BL3-2 is supported by the
322platform, the following constants must also be defined:
323
324* **#define : TSP_SEC_MEM_BASE**
325
326 Defines the base address of the secure memory used by the TSP image on the
327 platform. This must be at the same address or below `BL32_BASE`.
328
329* **#define : TSP_SEC_MEM_SIZE**
330
331 Defines the size of the secure memory used by the BL3-2 image on the
332 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
333 the memory required by the BL3-2 image, defined by `BL32_BASE` and
334 `BL32_LIMIT`.
335
336* **#define : TSP_IRQ_SEC_PHY_TIMER**
337
338 Defines the ID of the secure physical generic timer interrupt used by the
339 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100340
Dan Handley4a75b842015-03-19 19:24:43 +0000341If the platform port uses the translation table library code, the following
342constant must also be defined:
343
344* **#define : MAX_XLAT_TABLES**
345
346 Defines the maximum number of translation tables that are allocated by the
347 translation table library code. To minimize the amount of runtime memory
348 used, choose the smallest value needed to map the required virtual addresses
349 for each BL stage.
350
Dan Handley6d16ce02014-08-04 18:31:43 +0100351If the platform port uses the IO storage framework, the following constants
352must also be defined:
353
354* **#define : MAX_IO_DEVICES**
355
356 Defines the maximum number of registered IO devices. Attempting to register
357 more devices than this value using `io_register_device()` will fail with
358 IO_RESOURCES_EXHAUSTED.
359
360* **#define : MAX_IO_HANDLES**
361
362 Defines the maximum number of open IO handles. Attempting to open more IO
363 entities than this value using `io_open()` will fail with
364 IO_RESOURCES_EXHAUSTED.
365
Soby Mathewab8707e2015-01-08 18:02:44 +0000366If the platform needs to allocate data within the per-cpu data framework in
367BL3-1, it should define the following macro. Currently this is only required if
368the platform decides not to use the coherent memory section by undefining the
369USE_COHERENT_MEM build flag. In this case, the framework allocates the required
370memory within the the per-cpu data to minimize wastage.
371
372* **#define : PLAT_PCPU_DATA_SIZE**
373
374 Defines the memory (in bytes) to be reserved within the per-cpu data
375 structure for use by the platform layer.
376
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100377The following constants are optional. They should be defined when the platform
Dan Handley4a75b842015-03-19 19:24:43 +0000378memory layout implies some image overlaying like in ARM standard platforms.
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100379
380* **#define : BL31_PROGBITS_LIMIT**
381
382 Defines the maximum address in secure RAM that the BL3-1's progbits sections
383 can occupy.
384
Dan Handley5a06bb72014-08-04 11:41:20 +0100385* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100386
387 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100388
Dan Handleyb68954c2014-05-29 12:30:24 +0100389### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100390
Dan Handleyb68954c2014-05-29 12:30:24 +0100391Each platform must ensure a file of this name is in the system include path with
Dan Handley4a75b842015-03-19 19:24:43 +0000392the following macro defined. In the ARM development platforms, this file is
393found in `plat/arm/board/<plat_name>/include/plat_macros.S`.
Soby Mathewa43d4312014-04-07 15:28:55 +0100394
395* **Macro : plat_print_gic_regs**
396
397 This macro allows the crash reporting routine to print GIC registers
Soby Mathew8c106902014-07-16 09:23:52 +0100398 in case of an unhandled exception in BL3-1. This aids in debugging and
Soby Mathewa43d4312014-04-07 15:28:55 +0100399 this macro can be defined to be empty in case GIC register reporting is
400 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100401
Soby Mathew8c106902014-07-16 09:23:52 +0100402* **Macro : plat_print_interconnect_regs**
403
Dan Handley4a75b842015-03-19 19:24:43 +0000404 This macro allows the crash reporting routine to print interconnect
405 registers in case of an unhandled exception in BL3-1. This aids in debugging
406 and this macro can be defined to be empty in case interconnect register
407 reporting is not desired. In ARM standard platforms, the CCI snoop
408 control registers are reported.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100409
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000410
Vikram Kanigirie452cd82014-05-23 15:56:12 +01004112.2 Handling Reset
412------------------
413
414BL1 by default implements the reset vector where execution starts from a cold
415or warm boot. BL3-1 can be optionally set as a reset vector using the
416RESET_TO_BL31 make variable.
417
418For each CPU, the reset vector code is responsible for the following tasks:
419
4201. Distinguishing between a cold boot and a warm boot.
421
4222. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
423 the CPU is placed in a platform-specific state until the primary CPU
424 performs the necessary steps to remove it from this state.
425
4263. In the case of a warm boot, ensuring that the CPU jumps to a platform-
427 specific address in the BL3-1 image in the same processor mode as it was
428 when released from reset.
429
430The following functions need to be implemented by the platform port to enable
431reset vector code to perform the above tasks.
432
433
Soby Mathew58523c02015-06-08 12:32:50 +0100434### Function : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100435
Soby Mathew58523c02015-06-08 12:32:50 +0100436 Argument : void
437 Return : unsigned long
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100438
Soby Mathew58523c02015-06-08 12:32:50 +0100439This function is called with the called with the MMU and caches disabled
440(`SCTLR_EL3.M` = 0 and `SCTLR_EL3.C` = 0). The function is responsible for
441distinguishing between a warm and cold reset for the current CPU using
442platform-specific means. If it's a warm reset, then it returns the warm
443reset entrypoint point provided to `plat_setup_psci_ops()` during
444BL3-1 initialization. If it's a cold reset then this function must return zero.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100445
446This function does not follow the Procedure Call Standard used by the
447Application Binary Interface for the ARM 64-bit architecture. The caller should
448not assume that callee saved registers are preserved across a call to this
449function.
450
451This function fulfills requirement 1 and 3 listed above.
452
Soby Mathew58523c02015-06-08 12:32:50 +0100453Note that for platforms that support programming the reset address, it is
454expected that a CPU will start executing code directly at the right address,
455both on a cold and warm reset. In this case, there is no need to identify the
456type of reset nor to query the warm reset entrypoint. Therefore, implementing
457this function is not required on such platforms.
458
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100459
460### Function : plat_secondary_cold_boot_setup() [mandatory]
461
462 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100463
464This function is called with the MMU and data caches disabled. It is responsible
465for placing the executing secondary CPU in a platform-specific state until the
466primary CPU performs the necessary actions to bring it out of that state and
Sandrine Bailleux52010cc2015-05-19 11:54:45 +0100467allow entry into the OS. This function must not return.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100468
469In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
470responsible for powering up the secondary CPU when normal world software
471requires them.
472
473This function fulfills requirement 2 above.
474
475
Soby Mathew58523c02015-06-08 12:32:50 +0100476### Function : plat_is_my_cpu_primary() [mandatory]
Juan Castillo53fdceb2014-07-16 15:53:43 +0100477
Soby Mathew58523c02015-06-08 12:32:50 +0100478 Argument : void
Juan Castillo53fdceb2014-07-16 15:53:43 +0100479 Return : unsigned int
480
Soby Mathew58523c02015-06-08 12:32:50 +0100481This function identifies whether the current CPU is the primary CPU or a
482secondary CPU. A return value of zero indicates that the CPU is not the
483primary CPU, while a non-zero return value indicates that the CPU is the
484primary CPU.
Juan Castillo53fdceb2014-07-16 15:53:43 +0100485
486
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100487### Function : platform_mem_init() [mandatory]
488
489 Argument : void
490 Return : void
491
492This function is called before any access to data is made by the firmware, in
493order to carry out any essential memory initialization.
494
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100495
Juan Castillo95cfd4a2015-04-14 12:49:03 +0100496### Function: plat_get_rotpk_info()
497
498 Argument : void *, void **, unsigned int *, unsigned int *
499 Return : int
500
501This function is mandatory when Trusted Board Boot is enabled. It returns a
502pointer to the ROTPK stored in the platform (or a hash of it) and its length.
503The ROTPK must be encoded in DER format according to the following ASN.1
504structure:
505
506 AlgorithmIdentifier ::= SEQUENCE {
507 algorithm OBJECT IDENTIFIER,
508 parameters ANY DEFINED BY algorithm OPTIONAL
509 }
510
511 SubjectPublicKeyInfo ::= SEQUENCE {
512 algorithm AlgorithmIdentifier,
513 subjectPublicKey BIT STRING
514 }
515
516In case the function returns a hash of the key:
517
518 DigestInfo ::= SEQUENCE {
519 digestAlgorithm AlgorithmIdentifier,
520 digest OCTET STRING
521 }
522
523The function returns 0 on success. Any other value means the ROTPK could not be
524retrieved from the platform. The function also reports extra information related
525to the ROTPK in the flags parameter.
526
527
Soby Mathew58523c02015-06-08 12:32:50 +01005282.3 Common mandatory modifications
529---------------------------------
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100530
Soby Mathew58523c02015-06-08 12:32:50 +0100531The following functions are mandatory functions which need to be implemented
532by the platform port.
533
534### Function : plat_my_core_pos()
535
536 Argument : void
537 Return : unsigned int
538
539This funtion returns the index of the calling CPU which is used as a
540CPU-specific linear index into blocks of memory (for example while allocating
541per-CPU stacks). This function will be invoked very early in the
542initialization sequence which mandates that this function should be
543implemented in assembly and should not rely on the avalability of a C
544runtime environment.
545
546This function plays a crucial role in the power domain topology framework in
547PSCI and details of this can be found in [Power Domain Topology Design].
548
549### Function : plat_core_pos_by_mpidr()
550
551 Argument : u_register_t
552 Return : int
553
554This function validates the `MPIDR` of a CPU and converts it to an index,
555which can be used as a CPU-specific linear index into blocks of memory. In
556case the `MPIDR` is invalid, this function returns -1. This function will only
557be invoked by BL3-1 after the power domain topology is initialized and can
558utilize the C runtime environment. For further details about how ARM Trusted
559Firmware represents the power domain topology and how this relates to the
560linear CPU index, please refer [Power Domain Topology Design].
561
562
563
5642.4 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100565---------------------------------
566
567The following are helper functions implemented by the firmware that perform
568common platform-specific tasks. A platform may choose to override these
569definitions.
570
Soby Mathew58523c02015-06-08 12:32:50 +0100571### Function : plat_set_my_stack()
Achin Gupta4f6ad662013-10-25 09:08:21 +0100572
Soby Mathew58523c02015-06-08 12:32:50 +0100573 Argument : void
Achin Gupta4f6ad662013-10-25 09:08:21 +0100574 Return : void
575
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000576This function sets the current stack pointer to the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100577has been allocated for the current CPU. For BL images that only require a
578stack for the primary CPU, the UP version of the function is used. The size
579of the stack allocated to each CPU is specified by the platform defined
580constant `PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100581
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000582Common implementations of this function for the UP and MP BL images are
583provided in [plat/common/aarch64/platform_up_stack.S] and
584[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100585
586
Soby Mathew58523c02015-06-08 12:32:50 +0100587### Function : plat_get_my_stack()
Achin Guptac8afc782013-11-25 18:45:02 +0000588
Soby Mathew58523c02015-06-08 12:32:50 +0100589 Argument : void
Achin Guptac8afc782013-11-25 18:45:02 +0000590 Return : unsigned long
591
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000592This function returns the base address of the normal memory stack that
Soby Mathew58523c02015-06-08 12:32:50 +0100593has been allocated for the current CPU. For BL images that only require a
594stack for the primary CPU, the UP version of the function is used. The size
595of the stack allocated to each CPU is specified by the platform defined
596constant `PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000597
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000598Common implementations of this function for the UP and MP BL images are
599provided in [plat/common/aarch64/platform_up_stack.S] and
600[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000601
602
Achin Gupta4f6ad662013-10-25 09:08:21 +0100603### Function : plat_report_exception()
604
605 Argument : unsigned int
606 Return : void
607
608A platform may need to report various information about its status when an
609exception is taken, for example the current exception level, the CPU security
610state (secure/non-secure), the exception type, and so on. This function is
611called in the following circumstances:
612
613* In BL1, whenever an exception is taken.
614* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100615
616The default implementation doesn't do anything, to avoid making assumptions
617about the way the platform displays its status information.
618
619This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000620exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100621that these constants are not related to any architectural exception code; they
622are just an ARM Trusted Firmware convention.
623
624
Soby Mathew24fb8382014-08-14 12:22:32 +0100625### Function : plat_reset_handler()
626
627 Argument : void
628 Return : void
629
630A platform may need to do additional initialization after reset. This function
631allows the platform to do the platform specific intializations. Platform
632specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000633preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100634
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000635The default implementation doesn't do anything. If a platform needs to override
Dan Handley4a75b842015-03-19 19:24:43 +0000636the default implementation, refer to the [Firmware Design] for general
Sandrine Bailleux452b7fa2015-05-27 17:14:22 +0100637guidelines.
Soby Mathew24fb8382014-08-14 12:22:32 +0100638
Soby Mathewadd40352014-08-14 12:49:05 +0100639### Function : plat_disable_acp()
640
641 Argument : void
642 Return : void
643
644This api allows a platform to disable the Accelerator Coherency Port (if
645present) during a cluster power down sequence. The default weak implementation
646doesn't do anything. Since this api is called during the power down sequence,
647it has restrictions for stack usage and it can use the registers x0 - x17 as
648scratch registers. It should preserve the value in x18 register as it is used
649by the caller to store the return address.
650
Soby Mathew24fb8382014-08-14 12:22:32 +0100651
Achin Gupta4f6ad662013-10-25 09:08:21 +01006523. Modifications specific to a Boot Loader stage
653-------------------------------------------------
654
6553.1 Boot Loader Stage 1 (BL1)
656-----------------------------
657
658BL1 implements the reset vector where execution starts from after a cold or
659warm boot. For each CPU, BL1 is responsible for the following tasks:
660
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006611. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100662
6632. In the case of a cold boot and the CPU being the primary CPU, ensuring that
664 only this CPU executes the remaining BL1 code, including loading and passing
665 control to the BL2 stage.
666
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006673. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100668 address specified by the platform defined constant `BL2_BASE`.
669
Vikram Kanigirie452cd82014-05-23 15:56:12 +01006704. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100671 accessible by BL2 immediately upon entry.
672
673 meminfo.total_base = Base address of secure RAM visible to BL2
674 meminfo.total_size = Size of secure RAM visible to BL2
675 meminfo.free_base = Base address of secure RAM available for
676 allocation to BL2
677 meminfo.free_size = Size of secure RAM available for allocation to BL2
678
679 BL1 places this `meminfo` structure at the beginning of the free memory
680 available for its use. Since BL1 cannot allocate memory dynamically at the
681 moment, its free memory will be available for BL2's use as-is. However, this
682 means that BL2 must read the `meminfo` structure before it starts using its
683 free memory (this is discussed in Section 3.2).
684
685 In future releases of the ARM Trusted Firmware it will be possible for
686 the platform to decide where it wants to place the `meminfo` structure for
687 BL2.
688
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100689 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100690 BL2 `meminfo` structure. The platform may override this implementation, for
691 example if the platform wants to restrict the amount of memory visible to
692 BL2. Details of how to do this are given below.
693
694The following functions need to be implemented by the platform port to enable
695BL1 to perform the above tasks.
696
697
Dan Handley4a75b842015-03-19 19:24:43 +0000698### Function : bl1_early_platform_setup() [mandatory]
699
700 Argument : void
701 Return : void
702
703This function executes with the MMU and data caches disabled. It is only called
704by the primary CPU.
705
706In ARM standard platforms, this function initializes the console and enables
707snoop requests into the primary CPU's cluster.
708
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100709### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100710
711 Argument : void
712 Return : void
713
Achin Gupta4f6ad662013-10-25 09:08:21 +0100714This function performs any platform-specific and architectural setup that the
Dan Handley4a75b842015-03-19 19:24:43 +0000715platform requires. Platform-specific setup might include configuration of
716memory controllers and the interconnect.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100717
Dan Handley4a75b842015-03-19 19:24:43 +0000718In ARM standard platforms, this function enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100719
720This function helps fulfill requirement 2 above.
721
722
723### Function : bl1_platform_setup() [mandatory]
724
725 Argument : void
726 Return : void
727
728This function executes with the MMU and data caches enabled. It is responsible
729for performing any remaining platform-specific setup that can occur after the
730MMU and data cache have been enabled.
731
Dan Handley4a75b842015-03-19 19:24:43 +0000732In ARM standard platforms, this function initializes the storage abstraction
733layer used to load the next bootloader image.
Harry Liebeld265bd72014-01-31 19:04:10 +0000734
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100735This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100736
737
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000738### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100739
740 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000741 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100742
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000743This function should only be called on the cold boot path. It executes with the
744MMU and data caches enabled. The pointer returned by this function must point to
745a `meminfo` structure containing the extents and availability of secure RAM for
746the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100747
748 meminfo.total_base = Base address of secure RAM visible to BL1
749 meminfo.total_size = Size of secure RAM visible to BL1
750 meminfo.free_base = Base address of secure RAM available for allocation
751 to BL1
752 meminfo.free_size = Size of secure RAM available for allocation to BL1
753
754This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
755populates a similar structure to tell BL2 the extents of memory available for
756its own use.
757
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100758This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100759
760
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100761### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100762
763 Argument : meminfo *, meminfo *, unsigned int, unsigned long
764 Return : void
765
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100766BL1 needs to tell the next stage the amount of secure RAM available
767for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100768structure.
769
770Depending upon where BL2 has been loaded in secure RAM (determined by
771`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
772BL1 also ensures that its data sections resident in secure RAM are not visible
Dan Handley4a75b842015-03-19 19:24:43 +0000773to BL2. An illustration of how this is done in ARM standard platforms is given
774in the **Memory layout on ARM development platforms** section in the
775[Firmware Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100776
777
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100778### Function : bl1_plat_set_bl2_ep_info() [mandatory]
779
780 Argument : image_info *, entry_point_info *
781 Return : void
782
783This function is called after loading BL2 image and it can be used to overwrite
784the entry point set by loader and also set the security state and SPSR which
785represents the entry point system state for BL2.
786
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100787
Achin Gupta4f6ad662013-10-25 09:08:21 +01007883.2 Boot Loader Stage 2 (BL2)
789-----------------------------
790
791The BL2 stage is executed only by the primary CPU, which is determined in BL1
792using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
793`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
794
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01007951. (Optional) Loading the BL3-0 binary image (if present) from platform
796 provided non-volatile storage. To load the BL3-0 image, BL2 makes use of
797 the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function.
798 The platform also defines the address in memory where BL3-0 is loaded
799 through the optional constant `BL30_BASE`. BL2 uses this information
800 to determine if there is enough memory to load the BL3-0 image.
801 Subsequent handling of the BL3-0 image is platform-specific and is
802 implemented in the `bl2_plat_handle_bl30()` function.
803 If `BL30_BASE` is not defined then this step is not performed.
804
8052. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
Harry Liebeld265bd72014-01-31 19:04:10 +0000806 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
807 by BL1. This structure allows BL2 to calculate how much secure RAM is
808 available for its use. The platform also defines the address in secure RAM
809 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
810 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100811
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01008123. (Optional) Loading the BL3-2 binary image (if present) from platform
Dan Handley1151c822014-04-15 11:38:38 +0100813 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100814 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
815 The platform also defines the address in memory where BL3-2 is loaded
816 through the optional constant `BL32_BASE`. BL2 uses this information
817 to determine if there is enough memory to load the BL3-2 image.
818 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000819
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01008204. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100821 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100822 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100823 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000824
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01008255. Loading the normal world BL3-3 binary image into non-secure DRAM from
826 platform storage and arranging for BL3-1 to pass control to this image. This
827 address is determined using the `plat_get_ns_image_entrypoint()` function
828 described below.
829
8306. BL2 populates an `entry_point_info` structure in memory provided by the
831 platform with information about how BL3-1 should pass control to the
832 other BL images.
833
Achin Gupta4f6ad662013-10-25 09:08:21 +0100834The following functions must be implemented by the platform port to enable BL2
835to perform the above tasks.
836
837
838### Function : bl2_early_platform_setup() [mandatory]
839
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100840 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100841 Return : void
842
843This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100844by the primary CPU. The arguments to this function is the address of the
845`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100846
847The platform must copy the contents of the `meminfo` structure into a private
848variable as the original memory may be subsequently overwritten by BL2. The
849copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000850`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100851
Dan Handley4a75b842015-03-19 19:24:43 +0000852In ARM standard platforms, this function also initializes the storage
853abstraction layer used to load further bootloader images. It is necessary to do
854this early on platforms with a BL3-0 image, since the later `bl2_platform_setup`
855must be done after BL3-0 is loaded.
856
Achin Gupta4f6ad662013-10-25 09:08:21 +0100857
858### Function : bl2_plat_arch_setup() [mandatory]
859
860 Argument : void
861 Return : void
862
863This function executes with the MMU and data caches disabled. It is only called
864by the primary CPU.
865
866The purpose of this function is to perform any architectural initialization
867that varies across platforms, for example enabling the MMU (since the memory
868map differs across platforms).
869
870
871### Function : bl2_platform_setup() [mandatory]
872
873 Argument : void
874 Return : void
875
876This function may execute with the MMU and data caches enabled if the platform
877port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
878called by the primary CPU.
879
Achin Guptae4d084e2014-02-19 17:18:23 +0000880The purpose of this function is to perform any platform initialization
Dan Handley4a75b842015-03-19 19:24:43 +0000881specific to BL2.
Harry Liebelce19cf12014-04-01 19:28:07 +0100882
Dan Handley4a75b842015-03-19 19:24:43 +0000883In ARM standard platforms, this function performs security setup, including
884configuration of the TrustZone controller to allow non-secure masters access
885to most of DRAM. Part of DRAM is reserved for secure world use.
Harry Liebeld265bd72014-01-31 19:04:10 +0000886
Achin Gupta4f6ad662013-10-25 09:08:21 +0100887
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000888### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100889
890 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000891 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100892
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000893This function should only be called on the cold boot path. It may execute with
894the MMU and data caches enabled if the platform port does the necessary
895initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100896
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000897The purpose of this function is to return a pointer to a `meminfo` structure
898populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100899`bl2_early_platform_setup()` above.
900
901
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100902### Function : bl2_plat_get_bl30_meminfo() [mandatory]
903
904 Argument : meminfo *
905 Return : void
906
907This function is used to get the memory limits where BL2 can load the
908BL3-0 image. The meminfo provided by this is used by load_image() to
909validate whether the BL3-0 image can be loaded within the given
910memory from the given base.
911
912
913### Function : bl2_plat_handle_bl30() [mandatory]
914
915 Argument : image_info *
916 Return : int
917
918This function is called after loading BL3-0 image and it is used to perform any
919platform-specific actions required to handle the SCP firmware. Typically it
920transfers the image into SCP memory using a platform-specific protocol and waits
921until SCP executes it and signals to the Application Processor (AP) for BL2
922execution to continue.
923
924This function returns 0 on success, a negative error code otherwise.
925
926
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100927### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000928
929 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100930 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000931
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100932BL2 platform code needs to return a pointer to a `bl31_params` structure it
933will use for passing information to BL3-1. The `bl31_params` structure carries
934the following information.
935 - Header describing the version information for interpreting the bl31_param
936 structure
937 - Information about executing the BL3-3 image in the `bl33_ep_info` field
938 - Information about executing the BL3-2 image in the `bl32_ep_info` field
939 - Information about the type and extents of BL3-1 image in the
940 `bl31_image_info` field
941 - Information about the type and extents of BL3-2 image in the
942 `bl32_image_info` field
943 - Information about the type and extents of BL3-3 image in the
944 `bl33_image_info` field
945
946The memory pointed by this structure and its sub-structures should be
947accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
948necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000949
950
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100951### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100952
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100953 Argument : void
954 Return : entry_point_info *
955
956BL2 platform code returns a pointer which is used to populate the entry point
957information for BL3-1 entry point. The location pointed by it should be
958accessible from BL1 while processing the synchronous exception to run to BL3-1.
959
Dan Handley4a75b842015-03-19 19:24:43 +0000960In ARM standard platforms this is allocated inside a bl2_to_bl31_params_mem
961structure in BL2 memory.
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100962
963
964### Function : bl2_plat_set_bl31_ep_info() [mandatory]
965
966 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100967 Return : void
968
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100969This function is called after loading BL3-1 image and it can be used to
970overwrite the entry point set by loader and also set the security state
971and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100972
Achin Gupta4f6ad662013-10-25 09:08:21 +0100973
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100974### Function : bl2_plat_set_bl32_ep_info() [mandatory]
975
976 Argument : image_info *, entry_point_info *
977 Return : void
978
979This function is called after loading BL3-2 image and it can be used to
980overwrite the entry point set by loader and also set the security state
981and SPSR which represents the entry point system state for BL3-2.
982
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100983
984### Function : bl2_plat_set_bl33_ep_info() [mandatory]
985
986 Argument : image_info *, entry_point_info *
987 Return : void
988
989This function is called after loading BL3-3 image and it can be used to
990overwrite the entry point set by loader and also set the security state
991and SPSR which represents the entry point system state for BL3-3.
992
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100993
994### Function : bl2_plat_get_bl32_meminfo() [mandatory]
995
996 Argument : meminfo *
997 Return : void
998
999This function is used to get the memory limits where BL2 can load the
1000BL3-2 image. The meminfo provided by this is used by load_image() to
1001validate whether the BL3-2 image can be loaded with in the given
1002memory from the given base.
1003
1004### Function : bl2_plat_get_bl33_meminfo() [mandatory]
1005
1006 Argument : meminfo *
1007 Return : void
1008
1009This function is used to get the memory limits where BL2 can load the
1010BL3-3 image. The meminfo provided by this is used by load_image() to
1011validate whether the BL3-3 image can be loaded with in the given
1012memory from the given base.
1013
1014### Function : bl2_plat_flush_bl31_params() [mandatory]
1015
1016 Argument : void
1017 Return : void
1018
1019Once BL2 has populated all the structures that needs to be read by BL1
1020and BL3-1 including the bl31_params structures and its sub-structures,
1021the bl31_ep_info structure and any platform specific data. It flushes
1022all these data to the main memory so that it is available when we jump to
1023later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +01001024
1025### Function : plat_get_ns_image_entrypoint() [mandatory]
1026
1027 Argument : void
1028 Return : unsigned long
1029
1030As previously described, BL2 is responsible for arranging for control to be
1031passed to a normal world BL image through BL3-1. This function returns the
1032entrypoint of that image, which BL3-1 uses to jump to it.
1033
Harry Liebeld265bd72014-01-31 19:04:10 +00001034BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001035
1036
10373.2 Boot Loader Stage 3-1 (BL3-1)
1038---------------------------------
1039
1040During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
1041determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
1042control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
1043CPUs. BL3-1 executes at EL3 and is responsible for:
1044
10451. Re-initializing all architectural and platform state. Although BL1 performs
1046 some of this initialization, BL3-1 remains resident in EL3 and must ensure
1047 that EL3 architectural and platform state is completely initialized. It
1048 should make no assumptions about the system state when it receives control.
1049
10502. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001051 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +01001052 populated in memory to do this.
1053
10543. Providing runtime firmware services. Currently, BL3-1 only implements a
1055 subset of the Power State Coordination Interface (PSCI) API as a runtime
1056 service. See Section 3.3 below for details of porting the PSCI
1057 implementation.
1058
Achin Gupta35ca3512014-02-19 17:58:33 +000010594. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
1060 specific address by BL2. BL3-1 exports a set of apis that allow runtime
1061 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001062 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
1063 structure populated by BL2 to do this.
1064
1065If BL3-1 is a reset vector, It also needs to handle the reset as specified in
1066section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +00001067
Achin Gupta4f6ad662013-10-25 09:08:21 +01001068The following functions must be implemented by the platform port to enable BL3-1
1069to perform the above tasks.
1070
1071
1072### Function : bl31_early_platform_setup() [mandatory]
1073
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001074 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001075 Return : void
1076
1077This function executes with the MMU and data caches disabled. It is only called
1078by the primary CPU. The arguments to this function are:
1079
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001080* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001081* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001082
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001083The platform can copy the contents of the `bl31_params` structure and its
1084sub-structures into private variables if the original memory may be
1085subsequently overwritten by BL3-1 and similarly the `void *` pointing
1086to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001087
Dan Handley4a75b842015-03-19 19:24:43 +00001088In ARM standard platforms, BL2 passes a pointer to a `bl31_params` structure
1089in BL2 memory. BL3-1 copies the information in this pointer to internal data
1090structures.
1091
Achin Gupta4f6ad662013-10-25 09:08:21 +01001092
1093### Function : bl31_plat_arch_setup() [mandatory]
1094
1095 Argument : void
1096 Return : void
1097
1098This function executes with the MMU and data caches disabled. It is only called
1099by the primary CPU.
1100
1101The purpose of this function is to perform any architectural initialization
1102that varies across platforms, for example enabling the MMU (since the memory
1103map differs across platforms).
1104
1105
1106### Function : bl31_platform_setup() [mandatory]
1107
1108 Argument : void
1109 Return : void
1110
1111This function may execute with the MMU and data caches enabled if the platform
1112port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
1113called by the primary CPU.
1114
1115The purpose of this function is to complete platform initialization so that both
1116BL3-1 runtime services and normal world software can function correctly.
1117
Dan Handley4a75b842015-03-19 19:24:43 +00001118In ARM standard platforms, this function does the following:
Achin Gupta4f6ad662013-10-25 09:08:21 +01001119* Initializes the generic interrupt controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +01001120* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001121* Grants access to the system counter timer module
Dan Handley4a75b842015-03-19 19:24:43 +00001122* Initializes the power controller device
Achin Gupta4f6ad662013-10-25 09:08:21 +01001123* Detects the system topology.
1124
1125
1126### Function : bl31_get_next_image_info() [mandatory]
1127
Achin Gupta35ca3512014-02-19 17:58:33 +00001128 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001129 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001130
1131This function may execute with the MMU and data caches enabled if the platform
1132port does the necessary initializations in `bl31_plat_arch_setup()`.
1133
1134This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +00001135BL2 for the next image in the security state specified by the argument. BL3-1
1136uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +01001137state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +00001138(that was copied during `bl31_early_platform_setup()`) if the image exists. It
1139should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001140
Dan Handley4a75b842015-03-19 19:24:43 +00001141### Function : plat_get_syscnt_freq() [mandatory]
1142
1143 Argument : void
1144 Return : uint64_t
1145
1146This function is used by the architecture setup code to retrieve the counter
1147frequency for the CPU's generic timer. This value will be programmed into the
1148`CNTFRQ_EL0` register. In ARM standard platforms, it returns the base frequency
1149of the system counter, which is retrieved from the first entry in the frequency
1150modes table.
1151
Achin Gupta4f6ad662013-10-25 09:08:21 +01001152
Achin Gupta4f6ad662013-10-25 09:08:21 +010011533.3 Power State Coordination Interface (in BL3-1)
1154------------------------------------------------
1155
1156The ARM Trusted Firmware's implementation of the PSCI API is based around the
Soby Mathew58523c02015-06-08 12:32:50 +01001157concept of a _power domain_. A _power domain_ is a CPU or a logical group of
1158CPUs which share some state on which power management operations can be
1159performed as specified by [PSCI]. Each CPU in the system is assigned a cpu
1160index which is a unique number between `0` and `PLATFORM_CORE_COUNT - 1`.
1161The _power domains_ are arranged in a hierarchial tree structure and
1162each _power domain_ can be identified in a system by the cpu index of any CPU
1163that is part of that domain and a _power domain level_. A processing element
1164(for example, a CPU) is at level 0. If the _power domain_ node above a CPU is
1165a logical grouping of CPUs that share some state, then level 1 is that group
1166of CPUs (for example, a cluster), and level 2 is a group of clusters
1167(for example, the system). More details on the power domain topology and its
1168organization can be found in [Power Domain Topology Design].
Achin Gupta4f6ad662013-10-25 09:08:21 +01001169
1170BL3-1's platform initialization code exports a pointer to the platform-specific
1171power management operations required for the PSCI implementation to function
Soby Mathew58523c02015-06-08 12:32:50 +01001172correctly. This information is populated in the `plat_psci_ops` structure. The
1173PSCI implementation calls members of the `plat_psci_ops` structure for performing
1174power management operations on the power domains. For example, the target
1175CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `pwr_domain_on()`
1176handler (if present) is called for the CPU power domain.
1177
1178The `power-state` parameter of a PSCI `CPU_SUSPEND` call can be used to
1179describe composite power states specific to a platform. The PSCI implementation
1180defines a generic representation of the power-state parameter viz which is an
1181array of local power states where each index corresponds to a power domain
1182level. Each entry contains the local power state the power domain at that power
1183level could enter. It depends on the `validate_power_state()` handler to
1184convert the power-state parameter (possibly encoding a composite power state)
1185passed in a PSCI `CPU_SUSPEND` call to this representation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001186
1187The following functions must be implemented to initialize PSCI functionality in
1188the ARM Trusted Firmware.
1189
1190
Soby Mathew58523c02015-06-08 12:32:50 +01001191### Function : plat_get_target_pwr_state() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001192
Soby Mathew58523c02015-06-08 12:32:50 +01001193 Argument : unsigned int, const plat_local_state_t *, unsigned int
1194 Return : plat_local_state_t
Achin Gupta4f6ad662013-10-25 09:08:21 +01001195
Soby Mathew58523c02015-06-08 12:32:50 +01001196The PSCI generic code uses this function to let the platform participate in
1197state coordination during a power management operation. The function is passed
1198a pointer to an array of platform specific local power state `states` (second
1199argument) which contains the requested power state for each CPU at a particular
1200power domain level `lvl` (first argument) within the power domain. The function
1201is expected to traverse this array of upto `ncpus` (third argument) and return
1202a coordinated target power state by the comparing all the requested power
1203states. The target power state should not be deeper than any of the requested
1204power states.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001205
Soby Mathew58523c02015-06-08 12:32:50 +01001206A weak definition of this API is provided by default wherein it assumes
1207that the platform assigns a local state value in order of increasing depth
1208of the power state i.e. for two power states X & Y, if X < Y
1209then X represents a shallower power state than Y. As a result, the
1210coordinated target local power state for a power domain will be the minimum
1211of the requested local power state values.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001212
1213
Soby Mathew58523c02015-06-08 12:32:50 +01001214### Function : plat_get_power_domain_tree_desc() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001215
Soby Mathew58523c02015-06-08 12:32:50 +01001216 Argument : void
1217 Return : const unsigned char *
Achin Gupta4f6ad662013-10-25 09:08:21 +01001218
Soby Mathew58523c02015-06-08 12:32:50 +01001219This function returns a pointer to the byte array containing the power domain
1220topology tree description. The format and method to construct this array are
1221described in [Power Domain Topology Design]. The BL3-1 PSCI initilization code
1222requires this array to be described by the platform, either statically or
1223dynamically, to initialize the power domain topology tree. In case the array
1224is populated dynamically, then plat_core_pos_by_mpidr() and
1225plat_my_core_pos() should also be implemented suitably so that the topology
1226tree description matches the CPU indices returned by these APIs. These APIs
1227together form the platform interface for the PSCI topology framework.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001228
1229
Soby Mathew58523c02015-06-08 12:32:50 +01001230## Function : plat_setup_psci_ops() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001231
Soby Mathew58523c02015-06-08 12:32:50 +01001232 Argument : uintptr_t, const plat_psci_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001233 Return : int
1234
1235This function may execute with the MMU and data caches enabled if the platform
1236port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1237called by the primary CPU.
1238
Soby Mathew58523c02015-06-08 12:32:50 +01001239This function is called by PSCI initialization code. Its purpose is to let
1240the platform layer know about the warm boot entrypoint through the
1241`sec_entrypoint` (first argument) and to export handler routines for
1242platform-specific psci power management actions by populating the passed
1243pointer with a pointer to BL3-1's private `plat_psci_ops` structure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001244
1245A description of each member of this structure is given below. Please refer to
Dan Handley4a75b842015-03-19 19:24:43 +00001246the ARM FVP specific implementation of these handlers in
Soby Mathew58523c02015-06-08 12:32:50 +01001247[plat/arm/board/fvp/fvp_pm.c] as an example. For each PSCI function that the
1248platform wants to support, the associated operation or operations in this
1249structure must be provided and implemented (Refer section 4 of
1250[Firmware Design] for the PSCI API supported in Trusted Firmware). To disable
1251a PSCI function in a platform port, the operation should be removed from this
1252structure instead of providing an empty implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001253
Soby Mathew58523c02015-06-08 12:32:50 +01001254#### plat_psci_ops.cpu_standby()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001255
Soby Mathew58523c02015-06-08 12:32:50 +01001256Perform the platform-specific actions to enter the standby state for a cpu
1257indicated by the passed argument. This provides a fast path for CPU standby
1258wherein overheads of PSCI state management and lock acquistion is avoided.
1259For this handler to be invoked by the PSCI `CPU_SUSPEND` API implementation,
1260the suspend state type specified in the `power-state` parameter should be
1261STANDBY and the target power domain level specified should be the CPU. The
1262handler should put the CPU into a low power retention state (usually by
1263issuing a wfi instruction) and ensure that it can be woken up from that
1264state by a normal interrupt. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001265
Soby Mathew58523c02015-06-08 12:32:50 +01001266#### plat_psci_ops.pwr_domain_on()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001267
Soby Mathew58523c02015-06-08 12:32:50 +01001268Perform the platform specific actions to power on a CPU, specified
1269by the `MPIDR` (first argument). The generic code expects the platform to
1270return PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001271
Soby Mathew58523c02015-06-08 12:32:50 +01001272#### plat_psci_ops.pwr_domain_off()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001273
Soby Mathew58523c02015-06-08 12:32:50 +01001274Perform the platform specific actions to prepare to power off the calling CPU
1275and its higher parent power domain levels as indicated by the `target_state`
1276(first argument). It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001277
Soby Mathew58523c02015-06-08 12:32:50 +01001278The `target_state` encodes the platform coordinated target local power states
1279for the CPU power domain and its parent power domain levels. The handler
1280needs to perform power management operation corresponding to the local state
1281at each power level.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001282
Soby Mathew58523c02015-06-08 12:32:50 +01001283For this handler, the local power state for the CPU power domain will be a
1284power down state where as it could be either power down, retention or run state
1285for the higher power domain levels depending on the result of state
1286coordination. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001287
Soby Mathew58523c02015-06-08 12:32:50 +01001288#### plat_psci_ops.pwr_domain_suspend()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001289
Soby Mathew58523c02015-06-08 12:32:50 +01001290Perform the platform specific actions to prepare to suspend the calling
1291CPU and its higher parent power domain levels as indicated by the
1292`target_state` (first argument). It is called by the PSCI `CPU_SUSPEND`
1293API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001294
Soby Mathew58523c02015-06-08 12:32:50 +01001295The `target_state` has a similar meaning as described in
1296the `pwr_domain_off()` operation. It encodes the platform coordinated
1297target local power states for the CPU power domain and its parent
1298power domain levels. The handler needs to perform power management operation
1299corresponding to the local state at each power level. The generic code
1300expects the handler to succeed.
1301
1302The difference between turning a power domain off versus suspending it
1303is that in the former case, the power domain is expected to re-initialize
1304its state when it is next powered on (see `pwr_domain_on_finish()`). In the
1305latter case, the power domain is expected to save enough state so that it can
Achin Gupta4f6ad662013-10-25 09:08:21 +01001306resume execution by restoring this state when its powered on (see
Soby Mathew58523c02015-06-08 12:32:50 +01001307`pwr_domain_suspend_finish()`).
Achin Gupta4f6ad662013-10-25 09:08:21 +01001308
Soby Mathew58523c02015-06-08 12:32:50 +01001309#### plat_psci_ops.pwr_domain_on_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001310
1311This function is called by the PSCI implementation after the calling CPU is
1312powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1313It performs the platform-specific setup required to initialize enough state for
1314this CPU to enter the normal world and also provide secure runtime firmware
1315services.
1316
Soby Mathew58523c02015-06-08 12:32:50 +01001317The `target_state` (first argument) is the prior state of the power domains
1318immediately before the CPU was turned on. It indicates which power domains
1319above the CPU might require initialization due to having previously been in
1320low power states. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001321
Soby Mathew58523c02015-06-08 12:32:50 +01001322#### plat_psci_ops.pwr_domain_suspend_finish()
Achin Gupta4f6ad662013-10-25 09:08:21 +01001323
1324This function is called by the PSCI implementation after the calling CPU is
1325powered on and released from reset in response to an asynchronous wakeup
1326event, for example a timer interrupt that was programmed by the CPU during the
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001327`CPU_SUSPEND` call or `SYSTEM_SUSPEND` call. It performs the platform-specific
1328setup required to restore the saved state for this CPU to resume execution
1329in the normal world and also provide secure runtime firmware services.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001330
Soby Mathew58523c02015-06-08 12:32:50 +01001331The `target_state` (first argument) has a similar meaning as described in
1332the `pwr_domain_on_finish()` operation. The generic code expects the platform
1333to succeed.
Soby Mathew539dced2014-10-02 16:56:51 +01001334
Soby Mathew58523c02015-06-08 12:32:50 +01001335#### plat_psci_ops.validate_power_state()
Soby Mathew539dced2014-10-02 16:56:51 +01001336
1337This function is called by the PSCI implementation during the `CPU_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001338call to validate the `power_state` parameter of the PSCI API and if valid,
1339populate it in `req_state` (second argument) array as power domain level
1340specific local states. If the `power_state` is invalid, the platform must
1341return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1342normal world PSCI client.
Soby Mathew539dced2014-10-02 16:56:51 +01001343
Soby Mathew58523c02015-06-08 12:32:50 +01001344#### plat_psci_ops.validate_ns_entrypoint()
Soby Mathew539dced2014-10-02 16:56:51 +01001345
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001346This function is called by the PSCI implementation during the `CPU_SUSPEND`,
1347`SYSTEM_SUSPEND` and `CPU_ON` calls to validate the non-secure `entry_point`
Soby Mathew58523c02015-06-08 12:32:50 +01001348parameter passed by the normal world. If the `entry_point` is invalid,
1349the platform must return PSCI_E_INVALID_ADDRESS as error, which is
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001350propagated back to the normal world PSCI client.
1351
Soby Mathew58523c02015-06-08 12:32:50 +01001352#### plat_psci_ops.get_sys_suspend_power_state()
Soby Mathewc0aff0e2014-12-17 14:47:57 +00001353
1354This function is called by the PSCI implementation during the `SYSTEM_SUSPEND`
Soby Mathew58523c02015-06-08 12:32:50 +01001355call to get the `req_state` parameter from platform which encodes the power
1356domain level specific local states to suspend to system affinity level. The
1357`req_state` will be utilized to do the PSCI state coordination and
1358`pwr_domain_suspend()` will be invoked with the coordinated target state to
1359enter system suspend.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001360
Achin Gupta4f6ad662013-10-25 09:08:21 +01001361
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010013623.4 Interrupt Management framework (in BL3-1)
1363----------------------------------------------
1364BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1365generated in either security state and targeted to EL1 or EL2 in the non-secure
1366state or EL3/S-EL1 in the secure state. The design of this framework is
1367described in the [IMF Design Guide]
1368
1369A platform should export the following APIs to support the IMF. The following
Dan Handley4a75b842015-03-19 19:24:43 +00001370text briefly describes each api and its implementation in ARM standard
1371platforms. The API implementation depends upon the type of interrupt controller
1372present in the platform. ARM standard platforms implements an ARM Generic
1373Interrupt Controller (ARM GIC) as per the version 2.0 of the
1374[ARM GIC Architecture Specification].
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001375
1376### Function : plat_interrupt_type_to_line() [mandatory]
1377
1378 Argument : uint32_t, uint32_t
1379 Return : uint32_t
1380
1381The ARM processor signals an interrupt exception either through the IRQ or FIQ
1382interrupt line. The specific line that is signaled depends on how the interrupt
1383controller (IC) reports different interrupt types from an execution context in
1384either security state. The IMF uses this API to determine which interrupt line
1385the platform IC uses to signal each type of interrupt supported by the framework
1386from a given security state.
1387
1388The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1389Guide]) indicating the target type of the interrupt, the second parameter is the
1390security state of the originating execution context. The return result is the
1391bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1392FIQ=2.
1393
Dan Handley4a75b842015-03-19 19:24:43 +00001394ARM standard platforms configure the ARM GIC to signal S-EL1 interrupts
1395as FIQs and Non-secure interrupts as IRQs from either security state.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001396
1397
1398### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1399
1400 Argument : void
1401 Return : uint32_t
1402
1403This API returns the type of the highest priority pending interrupt at the
1404platform IC. The IMF uses the interrupt type to retrieve the corresponding
1405handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1406pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1407`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1408
Dan Handley4a75b842015-03-19 19:24:43 +00001409ARM standard platforms read the _Highest Priority Pending Interrupt
1410Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The type
1411of interrupt depends upon the id value as follows.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001412
14131. id < 1022 is reported as a S-EL1 interrupt
14142. id = 1022 is reported as a Non-secure interrupt.
14153. id = 1023 is reported as an invalid interrupt type.
1416
1417
1418### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1419
1420 Argument : void
1421 Return : uint32_t
1422
1423This API returns the id of the highest priority pending interrupt at the
1424platform IC. The IMF passes the id returned by this API to the registered
1425handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1426is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1427
Dan Handley4a75b842015-03-19 19:24:43 +00001428ARM standard platforms read the _Highest Priority Pending Interrupt
1429Register_ (`GICC_HPPIR`) to determine the id of the pending interrupt. The id
1430that is returned by API depends upon the value of the id read from the interrupt
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001431controller as follows.
1432
14331. id < 1022. id is returned as is.
14342. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1435 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1436 id is returned by the API.
14373. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1438
1439
1440### Function : plat_ic_acknowledge_interrupt() [mandatory]
1441
1442 Argument : void
1443 Return : uint32_t
1444
1445This API is used by the CPU to indicate to the platform IC that processing of
1446the highest pending interrupt has begun. It should return the id of the
1447interrupt which is being processed.
1448
Dan Handley4a75b842015-03-19 19:24:43 +00001449This function in ARM standard platforms reads the _Interrupt Acknowledge
1450Register_ (`GICC_IAR`). This changes the state of the highest priority pending
1451interrupt from pending to active in the interrupt controller. It returns the
1452value read from the `GICC_IAR`. This value is the id of the interrupt whose
1453state has been changed.
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001454
1455The TSP uses this API to start processing of the secure physical timer
1456interrupt.
1457
1458
1459### Function : plat_ic_end_of_interrupt() [mandatory]
1460
1461 Argument : uint32_t
1462 Return : void
1463
1464This API is used by the CPU to indicate to the platform IC that processing of
1465the interrupt corresponding to the id (passed as the parameter) has
1466finished. The id should be the same as the id returned by the
1467`plat_ic_acknowledge_interrupt()` API.
1468
Dan Handley4a75b842015-03-19 19:24:43 +00001469ARM standard platforms write the id to the _End of Interrupt Register_
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001470(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1471controller.
1472
1473The TSP uses this API to finish processing of the secure physical timer
1474interrupt.
1475
1476
1477### Function : plat_ic_get_interrupt_type() [mandatory]
1478
1479 Argument : uint32_t
1480 Return : uint32_t
1481
1482This API returns the type of the interrupt id passed as the parameter.
1483`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1484interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1485returned depending upon how the interrupt has been configured by the platform
1486IC.
1487
Dan Handley4a75b842015-03-19 19:24:43 +00001488This function in ARM standard platforms configures S-EL1 interrupts
1489as Group0 interrupts and Non-secure interrupts as Group1 interrupts. It reads
1490the group value corresponding to the interrupt id from the relevant _Interrupt
1491Group Register_ (`GICD_IGROUPRn`). It uses the group value to determine the
1492type of interrupt.
1493
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001494
Soby Mathewc67b09b2014-07-14 16:57:23 +010014953.5 Crash Reporting mechanism (in BL3-1)
1496----------------------------------------------
1497BL3-1 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001498of the CPU to enable quick crash analysis and debugging. It requires that a
1499console is designated as the crash console by the platform which will be used to
1500print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001501
Sandrine Bailleux44804252014-08-06 11:27:23 +01001502The following functions must be implemented by the platform if it wants crash
1503reporting mechanism in BL3-1. The functions are implemented in assembly so that
1504they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001505
1506### Function : plat_crash_console_init
1507
1508 Argument : void
1509 Return : int
1510
Sandrine Bailleux44804252014-08-06 11:27:23 +01001511This API is used by the crash reporting mechanism to initialize the crash
1512console. It should only use the general purpose registers x0 to x2 to do the
1513initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001514
Soby Mathewc67b09b2014-07-14 16:57:23 +01001515### Function : plat_crash_console_putc
1516
1517 Argument : int
1518 Return : int
1519
1520This API is used by the crash reporting mechanism to print a character on the
1521designated crash console. It should only use general purpose registers x1 and
1522x2 to do its work. The parameter and the return value are in general purpose
1523register x0.
1524
Soby Mathew27713fb2014-09-08 17:51:01 +010015254. Build flags
1526---------------
1527
Soby Mathew58523c02015-06-08 12:32:50 +01001528* **ENABLE_PLAT_COMPAT**
1529 All the platforms ports conforming to this API specification should define
1530 the build flag `ENABLE_PLAT_COMPAT` to 0 as the compatibility layer should
1531 be disabled. For more details on compatibility layer, refer
1532 [Migration Guide].
1533
Soby Mathew27713fb2014-09-08 17:51:01 +01001534There are some build flags which can be defined by the platform to control
1535inclusion or exclusion of certain BL stages from the FIP image. These flags
1536need to be defined in the platform makefile which will get included by the
1537build system.
1538
1539* **NEED_BL30**
1540 This flag if defined by the platform mandates that a BL3-0 binary should
1541 be included in the FIP image. The path to the BL3-0 binary can be specified
1542 by the `BL30` build option (see build options in the [User Guide]).
1543
1544* **NEED_BL33**
1545 By default, this flag is defined `yes` by the build system and `BL33`
1546 build option should be supplied as a build option. The platform has the option
1547 of excluding the BL3-3 image in the `fip` image by defining this flag to
1548 `no`.
1549
15505. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001551-------------
1552
1553To avoid subtle toolchain behavioral dependencies, the header files provided
1554by the compiler are not used. The software is built with the `-nostdinc` flag
1555to ensure no headers are included from the toolchain inadvertently. Instead the
1556required headers are included in the ARM Trusted Firmware source tree. The
1557library only contains those C library definitions required by the local
1558implementation. If more functionality is required, the needed library functions
1559will need to be added to the local implementation.
1560
1561Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1562headers have been cut down in order to simplify the implementation. In order to
1563minimize changes to the header files, the [FreeBSD] layout has been maintained.
1564The generic C library definitions can be found in `include/stdlib` with more
1565system and machine specific declarations in `include/stdlib/sys` and
1566`include/stdlib/machine`.
1567
1568The local C library implementations can be found in `lib/stdlib`. In order to
1569extend the C library these files may need to be modified. It is recommended to
1570use a release version of [FreeBSD] as a starting point.
1571
1572The C library header files in the [FreeBSD] source tree are located in the
1573`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1574can be found in the `sys/<machine-type>` directories. These files define things
1575like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1576port for [FreeBSD] does not yet exist, the machine specific definitions are
1577based on existing machine types with similar properties (for example SPARC64).
1578
1579Where possible, C library function implementations were taken from [FreeBSD]
1580as found in the `lib/libc` directory.
1581
1582A copy of the [FreeBSD] sources can be downloaded with `git`.
1583
1584 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1585
1586
Soby Mathew27713fb2014-09-08 17:51:01 +010015876. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001588-----------------------------
1589
1590In order to improve platform independence and portability an storage abstraction
1591layer is used to load data from non-volatile platform storage.
1592
1593Each platform should register devices and their drivers via the Storage layer.
1594These drivers then need to be initialized by bootloader phases as
1595required in their respective `blx_platform_setup()` functions. Currently
1596storage access is only required by BL1 and BL2 phases. The `load_image()`
1597function uses the storage layer to access non-volatile platform storage.
1598
Dan Handley4a75b842015-03-19 19:24:43 +00001599It is mandatory to implement at least one storage driver. For the ARM
1600development platforms the Firmware Image Package (FIP) driver is provided as
1601the default means to load data from storage (see the "Firmware Image Package"
1602section in the [User Guide]). The storage layer is described in the header file
1603`include/drivers/io/io_storage.h`. The implementation of the common library
Sandrine Bailleux121f2ae2015-01-28 10:11:48 +00001604is in `drivers/io/io_storage.c` and the driver files are located in
1605`drivers/io/`.
Harry Liebeld265bd72014-01-31 19:04:10 +00001606
1607Each IO driver must provide `io_dev_*` structures, as described in
1608`drivers/io/io_driver.h`. These are returned via a mandatory registration
1609function that is called on platform initialization. The semi-hosting driver
1610implementation in `io_semihosting.c` can be used as an example.
1611
1612The Storage layer provides mechanisms to initialize storage devices before
1613IO operations are called. The basic operations supported by the layer
1614include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1615Drivers do not have to implement all operations, but each platform must
1616provide at least one driver for a device capable of supporting generic
1617operations such as loading a bootloader image.
1618
1619The current implementation only allows for known images to be loaded by the
Juan Castillo16948ae2015-04-13 17:36:19 +01001620firmware. These images are specified by using their identifiers, as defined in
1621[include/plat/common/platform_def.h] (or a separate header file included from
1622there). The platform layer (`plat_get_image_source()`) then returns a reference
1623to a device and a driver-specific `spec` which will be understood by the driver
1624to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001625
1626The layer is designed in such a way that is it possible to chain drivers with
1627other drivers. For example, file-system drivers may be implemented on top of
1628physical block devices, both represented by IO devices with corresponding
1629drivers. In such a case, the file-system "binding" with the block device may
1630be deferred until the file-system device is initialised.
1631
1632The abstraction currently depends on structures being statically allocated
1633by the drivers and callers, as the system does not yet provide a means of
1634dynamically allocating memory. This may also have the affect of limiting the
1635amount of open resources per driver.
1636
1637
Achin Gupta4f6ad662013-10-25 09:08:21 +01001638- - - - - - - - - - - - - - - - - - - - - - - - - -
1639
Dan Handley4a75b842015-03-19 19:24:43 +00001640_Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001641
1642
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001643[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1644[IMF Design Guide]: interrupt-framework-design.md
1645[User Guide]: user-guide.md
1646[FreeBSD]: http://www.freebsd.org
Dan Handley4a75b842015-03-19 19:24:43 +00001647[Firmware Design]: firmware-design.md
Soby Mathew58523c02015-06-08 12:32:50 +01001648[Power Domain Topology Design]: psci-pd-tree.md
1649[PSCI]: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
1650[Migration Guide]: platform-migration-guide.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01001651
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001652[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1653[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handley4a75b842015-03-19 19:24:43 +00001654[plat/arm/board/fvp/fvp_pm.c]: ../plat/arm/board/fvp/fvp_pm.c
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001655[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handley4a75b842015-03-19 19:24:43 +00001656[include/plat/arm/common/arm_def.h]: ../include/plat/arm/common/arm_def.h
1657[include/plat/common/common_def.h]: ../include/plat/common/common_def.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001658[include/plat/common/platform.h]: ../include/plat/common/platform.h
Dan Handley4a75b842015-03-19 19:24:43 +00001659[include/plat/arm/common/plat_arm.h]: ../include/plat/arm/common/plat_arm.h]