blob: 09cd7d5ed47dd453c6b805bf1c56397adae333ba [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)
11 * [Common optional modifications](#23-common-optional-modifications)
123. [Boot Loader stage specific modifications](#3--modifications-specific-to-a-boot-loader-stage)
13 * [Boot Loader stage 1 (BL1)](#31-boot-loader-stage-1-bl1)
14 * [Boot Loader stage 2 (BL2)](#32-boot-loader-stage-2-bl2)
15 * [Boot Loader stage 3-1 (BL3-1)](#32-boot-loader-stage-3-1-bl3-1)
16 * [PSCI implementation (in BL3-1)](#33-power-state-coordination-interface-in-bl3-1)
17 * [Interrupt Management framework (in BL3-1)](#34--interrupt-management-framework-in-bl3-1)
18 * [Crash Reporting mechanism (in BL3-1)](#35--crash-reporting-mechanism-in-bl3-1)
194. [Build flags](#4--build-flags)
205. [C Library](#5--c-library)
216. [Storage abstraction layer](#6--storage-abstraction-layer)
Achin Gupta4f6ad662013-10-25 09:08:21 +010022
23- - - - - - - - - - - - - - - - - -
24
251. Introduction
26----------------
27
28Porting the ARM Trusted Firmware to a new platform involves making some
29mandatory and optional modifications for both the cold and warm boot paths.
30Modifications consist of:
31
32* Implementing a platform-specific function or variable,
33* Setting up the execution context in a certain way, or
34* Defining certain constants (for example #defines).
35
Dan Handleyb68954c2014-05-29 12:30:24 +010036The platform-specific functions and variables are all declared in
37[include/plat/common/platform.h]. The firmware provides a default implementation
38of variables and functions to fulfill the optional requirements. These
39implementations are all weakly defined; they are provided to ease the porting
40effort. Each platform port can override them with its own implementation if the
41default implementation is inadequate.
Achin Gupta4f6ad662013-10-25 09:08:21 +010042
43Some modifications are common to all Boot Loader (BL) stages. Section 2
44discusses these in detail. The subsequent sections discuss the remaining
45modifications for each BL stage in detail.
46
47This document should be read in conjunction with the ARM Trusted Firmware
48[User Guide].
49
50
512. Common modifications
52------------------------
53
54This section covers the modifications that should be made by the platform for
55each BL stage to correctly port the firmware stack. They are categorized as
56either mandatory or optional.
57
58
592.1 Common mandatory modifications
60----------------------------------
61A platform port must enable the Memory Management Unit (MMU) with identity
62mapped page tables, and enable both the instruction and data caches for each BL
63stage. In the ARM FVP port, each BL stage configures the MMU in its platform-
64specific architecture setup function, for example `blX_plat_arch_setup()`.
65
Soby Mathewab8707e2015-01-08 18:02:44 +000066If the build option `USE_COHERENT_MEM` is enabled, each platform must allocate a
67block of identity mapped secure memory with Device-nGnRE attributes aligned to
68page boundary (4K) for each BL stage. This memory is identified by the section
69name `tzfw_coherent_mem` so that its possible for the firmware to place
70variables in it using the following C code directive:
Achin Gupta4f6ad662013-10-25 09:08:21 +010071
72 __attribute__ ((section("tzfw_coherent_mem")))
73
74Or alternatively the following assembler code directive:
75
76 .section tzfw_coherent_mem
77
78The `tzfw_coherent_mem` section is used to allocate any data structures that are
79accessed both when a CPU is executing with its MMU and caches enabled, and when
80it's running with its MMU and caches disabled. Examples are given below.
81
82The following variables, functions and constants must be defined by the platform
83for the firmware to work correctly.
84
85
Dan Handleyb68954c2014-05-29 12:30:24 +010086### File : platform_def.h [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +010087
Dan Handleyb68954c2014-05-29 12:30:24 +010088Each platform must ensure that a header file of this name is in the system
89include path with the following constants defined. This may require updating the
90list of `PLAT_INCLUDES` in the `platform.mk` file. In the ARM FVP port, this
91file is found in [plat/fvp/include/platform_def.h].
Achin Gupta4f6ad662013-10-25 09:08:21 +010092
James Morrisseyba3155b2013-10-29 10:56:46 +000093* **#define : PLATFORM_LINKER_FORMAT**
Achin Gupta4f6ad662013-10-25 09:08:21 +010094
95 Defines the linker format used by the platform, for example
96 `elf64-littleaarch64` used by the FVP.
97
James Morrisseyba3155b2013-10-29 10:56:46 +000098* **#define : PLATFORM_LINKER_ARCH**
Achin Gupta4f6ad662013-10-25 09:08:21 +010099
100 Defines the processor architecture for the linker by the platform, for
101 example `aarch64` used by the FVP.
102
James Morrisseyba3155b2013-10-29 10:56:46 +0000103* **#define : PLATFORM_STACK_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100104
105 Defines the normal stack memory available to each CPU. This constant is used
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000106 by [plat/common/aarch64/platform_mp_stack.S] and
107 [plat/common/aarch64/platform_up_stack.S].
108
James Morrisseyba3155b2013-10-29 10:56:46 +0000109* **#define : FIRMWARE_WELCOME_STR**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100110
111 Defines the character string printed by BL1 upon entry into the `bl1_main()`
112 function.
113
James Morrisseyba3155b2013-10-29 10:56:46 +0000114* **#define : BL2_IMAGE_NAME**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100115
116 Name of the BL2 binary image on the host file-system. This name is used by
Harry Liebeld265bd72014-01-31 19:04:10 +0000117 BL1 to load BL2 into secure memory from non-volatile storage.
118
119* **#define : BL31_IMAGE_NAME**
120
121 Name of the BL3-1 binary image on the host file-system. This name is used by
122 BL2 to load BL3-1 into secure memory from platform storage.
123
124* **#define : BL33_IMAGE_NAME**
125
126 Name of the BL3-3 binary image on the host file-system. This name is used by
127 BL2 to load BL3-3 into non-secure memory from platform storage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100128
James Morrisseyba3155b2013-10-29 10:56:46 +0000129* **#define : PLATFORM_CACHE_LINE_SIZE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100130
131 Defines the size (in bytes) of the largest cache line across all the cache
132 levels in the platform.
133
James Morrisseyba3155b2013-10-29 10:56:46 +0000134* **#define : PLATFORM_CLUSTER_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100135
136 Defines the total number of clusters implemented by the platform in the
137 system.
138
James Morrisseyba3155b2013-10-29 10:56:46 +0000139* **#define : PLATFORM_CORE_COUNT**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100140
141 Defines the total number of CPUs implemented by the platform across all
142 clusters in the system.
143
James Morrisseyba3155b2013-10-29 10:56:46 +0000144* **#define : PLATFORM_MAX_CPUS_PER_CLUSTER**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100145
146 Defines the maximum number of CPUs that can be implemented within a cluster
147 on the platform.
148
Andrew Thoelke6c0b45d2014-06-20 00:36:14 +0100149* **#define : PLATFORM_NUM_AFFS**
150
151 Defines the total number of nodes in the affinity heirarchy at all affinity
152 levels used by the platform.
153
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100154* **#define : BL1_RO_BASE**
155
156 Defines the base address in secure ROM where BL1 originally lives. Must be
157 aligned on a page-size boundary.
158
159* **#define : BL1_RO_LIMIT**
160
161 Defines the maximum address in secure ROM that BL1's actual content (i.e.
162 excluding any data section allocated at runtime) can occupy.
163
164* **#define : BL1_RW_BASE**
165
166 Defines the base address in secure RAM where BL1's read-write data will live
167 at runtime. Must be aligned on a page-size boundary.
168
169* **#define : BL1_RW_LIMIT**
170
171 Defines the maximum address in secure RAM that BL1's read-write data can
172 occupy at runtime.
173
James Morrisseyba3155b2013-10-29 10:56:46 +0000174* **#define : BL2_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100175
176 Defines the base address in secure RAM where BL1 loads the BL2 binary image.
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000177 Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100178
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100179* **#define : BL2_LIMIT**
180
181 Defines the maximum address in secure RAM that the BL2 image can occupy.
182
James Morrisseyba3155b2013-10-29 10:56:46 +0000183* **#define : BL31_BASE**
Achin Gupta4f6ad662013-10-25 09:08:21 +0100184
185 Defines the base address in secure RAM where BL2 loads the BL3-1 binary
Sandrine Bailleuxcd29b0a2013-11-27 10:32:17 +0000186 image. Must be aligned on a page-size boundary.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100187
Sandrine Bailleux638363e2014-05-21 17:08:26 +0100188* **#define : BL31_LIMIT**
189
190 Defines the maximum address in secure RAM that the BL3-1 image can occupy.
191
Harry Liebeld265bd72014-01-31 19:04:10 +0000192* **#define : NS_IMAGE_OFFSET**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100193
Harry Liebeld265bd72014-01-31 19:04:10 +0000194 Defines the base address in non-secure DRAM where BL2 loads the BL3-3 binary
195 image. Must be aligned on a page-size boundary.
196
Dan Handley5a06bb72014-08-04 11:41:20 +0100197If a BL3-2 image is supported by the platform, the following constants must
198also be defined:
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100199
Dan Handley5a06bb72014-08-04 11:41:20 +0100200* **#define : BL32_IMAGE_NAME**
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100201
Dan Handley5a06bb72014-08-04 11:41:20 +0100202 Name of the BL3-2 binary image on the host file-system. This name is used by
203 BL2 to load BL3-2 into secure memory from platform storage.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100204
205* **#define : BL32_BASE**
206
207 Defines the base address in secure memory where BL2 loads the BL3-2 binary
Dan Handley5a06bb72014-08-04 11:41:20 +0100208 image. Must be aligned on a page-size boundary.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100209
210* **#define : BL32_LIMIT**
211
Dan Handley5a06bb72014-08-04 11:41:20 +0100212 Defines the maximum address that the BL3-2 image can occupy.
213
214If the Test Secure-EL1 Payload (TSP) instantiation of BL3-2 is supported by the
215platform, the following constants must also be defined:
216
217* **#define : TSP_SEC_MEM_BASE**
218
219 Defines the base address of the secure memory used by the TSP image on the
220 platform. This must be at the same address or below `BL32_BASE`.
221
222* **#define : TSP_SEC_MEM_SIZE**
223
224 Defines the size of the secure memory used by the BL3-2 image on the
225 platform. `TSP_SEC_MEM_BASE` and `TSP_SEC_MEM_SIZE` must fully accomodate
226 the memory required by the BL3-2 image, defined by `BL32_BASE` and
227 `BL32_LIMIT`.
228
229* **#define : TSP_IRQ_SEC_PHY_TIMER**
230
231 Defines the ID of the secure physical generic timer interrupt used by the
232 TSP's interrupt handling code.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100233
Dan Handley6d16ce02014-08-04 18:31:43 +0100234If the platform port uses the IO storage framework, the following constants
235must also be defined:
236
237* **#define : MAX_IO_DEVICES**
238
239 Defines the maximum number of registered IO devices. Attempting to register
240 more devices than this value using `io_register_device()` will fail with
241 IO_RESOURCES_EXHAUSTED.
242
243* **#define : MAX_IO_HANDLES**
244
245 Defines the maximum number of open IO handles. Attempting to open more IO
246 entities than this value using `io_open()` will fail with
247 IO_RESOURCES_EXHAUSTED.
248
Soby Mathewab8707e2015-01-08 18:02:44 +0000249If the platform needs to allocate data within the per-cpu data framework in
250BL3-1, it should define the following macro. Currently this is only required if
251the platform decides not to use the coherent memory section by undefining the
252USE_COHERENT_MEM build flag. In this case, the framework allocates the required
253memory within the the per-cpu data to minimize wastage.
254
255* **#define : PLAT_PCPU_DATA_SIZE**
256
257 Defines the memory (in bytes) to be reserved within the per-cpu data
258 structure for use by the platform layer.
259
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100260The following constants are optional. They should be defined when the platform
261memory layout implies some image overlaying like on FVP.
262
263* **#define : BL31_PROGBITS_LIMIT**
264
265 Defines the maximum address in secure RAM that the BL3-1's progbits sections
266 can occupy.
267
Dan Handley5a06bb72014-08-04 11:41:20 +0100268* **#define : TSP_PROGBITS_LIMIT**
Sandrine Bailleux46d49f632014-06-23 17:00:23 +0100269
270 Defines the maximum address that the TSP's progbits sections can occupy.
Sandrine Bailleux2467f702014-05-20 17:22:24 +0100271
Dan Handleyb68954c2014-05-29 12:30:24 +0100272### File : plat_macros.S [mandatory]
Soby Mathewa43d4312014-04-07 15:28:55 +0100273
Dan Handleyb68954c2014-05-29 12:30:24 +0100274Each platform must ensure a file of this name is in the system include path with
275the following macro defined. In the ARM FVP port, this file is found in
276[plat/fvp/include/plat_macros.S].
Soby Mathewa43d4312014-04-07 15:28:55 +0100277
278* **Macro : plat_print_gic_regs**
279
280 This macro allows the crash reporting routine to print GIC registers
Soby Mathew8c106902014-07-16 09:23:52 +0100281 in case of an unhandled exception in BL3-1. This aids in debugging and
Soby Mathewa43d4312014-04-07 15:28:55 +0100282 this macro can be defined to be empty in case GIC register reporting is
283 not desired.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100284
Soby Mathew8c106902014-07-16 09:23:52 +0100285* **Macro : plat_print_interconnect_regs**
286
287 This macro allows the crash reporting routine to print interconnect registers
288 in case of an unhandled exception in BL3-1. This aids in debugging and
289 this macro can be defined to be empty in case interconnect register reporting
290 is not desired. In the ARM FVP port, the CCI snoop control registers are
291 reported.
292
Achin Gupta4f6ad662013-10-25 09:08:21 +0100293### Other mandatory modifications
294
James Morrisseyba3155b2013-10-29 10:56:46 +0000295The following mandatory modifications may be implemented in any file
Achin Gupta4f6ad662013-10-25 09:08:21 +0100296the implementer chooses. In the ARM FVP port, they are implemented in
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000297[plat/fvp/aarch64/plat_common.c].
Achin Gupta4f6ad662013-10-25 09:08:21 +0100298
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100299* **Function : uint64_t plat_get_syscnt_freq(void)**
300
301 This function is used by the architecture setup code to retrieve the
302 counter frequency for the CPU's generic timer. This value will be
303 programmed into the `CNTFRQ_EL0` register.
304 In the ARM FVP port, it returns the base frequency of the system counter,
305 which is retrieved from the first entry in the frequency modes table.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100306
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000307
Vikram Kanigirie452cd82014-05-23 15:56:12 +01003082.2 Handling Reset
309------------------
310
311BL1 by default implements the reset vector where execution starts from a cold
312or warm boot. BL3-1 can be optionally set as a reset vector using the
313RESET_TO_BL31 make variable.
314
315For each CPU, the reset vector code is responsible for the following tasks:
316
3171. Distinguishing between a cold boot and a warm boot.
318
3192. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
320 the CPU is placed in a platform-specific state until the primary CPU
321 performs the necessary steps to remove it from this state.
322
3233. In the case of a warm boot, ensuring that the CPU jumps to a platform-
324 specific address in the BL3-1 image in the same processor mode as it was
325 when released from reset.
326
327The following functions need to be implemented by the platform port to enable
328reset vector code to perform the above tasks.
329
330
331### Function : platform_get_entrypoint() [mandatory]
332
333 Argument : unsigned long
334 Return : unsigned int
335
336This function is called with the `SCTLR.M` and `SCTLR.C` bits disabled. The CPU
337is identified by its `MPIDR`, which is passed as the argument. The function is
338responsible for distinguishing between a warm and cold reset using platform-
339specific means. If it's a warm reset then it returns the entrypoint into the
340BL3-1 image that the CPU must jump to. If it's a cold reset then this function
341must return zero.
342
343This function is also responsible for implementing a platform-specific mechanism
344to handle the condition where the CPU has been warm reset but there is no
345entrypoint to jump to.
346
347This function does not follow the Procedure Call Standard used by the
348Application Binary Interface for the ARM 64-bit architecture. The caller should
349not assume that callee saved registers are preserved across a call to this
350function.
351
352This function fulfills requirement 1 and 3 listed above.
353
354
355### Function : plat_secondary_cold_boot_setup() [mandatory]
356
357 Argument : void
358 Return : void
359
360This function is called with the MMU and data caches disabled. It is responsible
361for placing the executing secondary CPU in a platform-specific state until the
362primary CPU performs the necessary actions to bring it out of that state and
363allow entry into the OS.
364
365In the ARM FVP port, each secondary CPU powers itself off. The primary CPU is
366responsible for powering up the secondary CPU when normal world software
367requires them.
368
369This function fulfills requirement 2 above.
370
371
Juan Castillo53fdceb2014-07-16 15:53:43 +0100372### Function : platform_is_primary_cpu() [mandatory]
373
374 Argument : unsigned long
375 Return : unsigned int
376
377This function identifies a CPU by its `MPIDR`, which is passed as the argument,
378to determine whether this CPU is the primary CPU or a secondary CPU. A return
379value of zero indicates that the CPU is not the primary CPU, while a non-zero
380return value indicates that the CPU is the primary CPU.
381
382
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100383### Function : platform_mem_init() [mandatory]
384
385 Argument : void
386 Return : void
387
388This function is called before any access to data is made by the firmware, in
389order to carry out any essential memory initialization.
390
391The ARM FVP port uses this function to initialize the mailbox memory used for
392providing the warm-boot entry-point addresses.
393
394
Juan Castillo6eadf762015-01-07 10:39:25 +0000395### Function: plat_match_rotpk()
396
397 Argument : const unsigned char *, unsigned int
398 Return : int
399
400This function is mandatory when Trusted Board Boot is enabled. It receives a
401pointer to a buffer containing a signing key and its size as parameters and
402returns 0 (success) if that key matches the ROT (Root Of Trust) key stored in
403the platform. Any other return value means a mismatch.
404
405
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100406
4072.3 Common optional modifications
Achin Gupta4f6ad662013-10-25 09:08:21 +0100408---------------------------------
409
410The following are helper functions implemented by the firmware that perform
411common platform-specific tasks. A platform may choose to override these
412definitions.
413
414
415### Function : platform_get_core_pos()
416
417 Argument : unsigned long
418 Return : int
419
420A platform may need to convert the `MPIDR` of a CPU to an absolute number, which
421can be used as a CPU-specific linear index into blocks of memory (for example
422while allocating per-CPU stacks). This routine contains a simple mechanism
423to perform this conversion, using the assumption that each cluster contains a
424maximum of 4 CPUs:
425
426 linear index = cpu_id + (cluster_id * 4)
427
428 cpu_id = 8-bit value in MPIDR at affinity level 0
429 cluster_id = 8-bit value in MPIDR at affinity level 1
430
431
Achin Gupta4f6ad662013-10-25 09:08:21 +0100432### Function : platform_set_stack()
433
434 Argument : unsigned long
435 Return : void
436
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000437This function sets the current stack pointer to the normal memory stack that
438has been allocated for the CPU specificed by MPIDR. For BL images that only
439require a stack for the primary CPU the parameter is ignored. The size of
440the stack allocated to each CPU is specified by the platform defined constant
441`PLATFORM_STACK_SIZE`.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100442
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000443Common implementations of this function for the UP and MP BL images are
444provided in [plat/common/aarch64/platform_up_stack.S] and
445[plat/common/aarch64/platform_mp_stack.S]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100446
447
Achin Guptac8afc782013-11-25 18:45:02 +0000448### Function : platform_get_stack()
449
450 Argument : unsigned long
451 Return : unsigned long
452
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000453This function returns the base address of the normal memory stack that
454has been allocated for the CPU specificed by MPIDR. For BL images that only
455require a stack for the primary CPU the parameter is ignored. The size of
456the stack allocated to each CPU is specified by the platform defined constant
457`PLATFORM_STACK_SIZE`.
Achin Guptac8afc782013-11-25 18:45:02 +0000458
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000459Common implementations of this function for the UP and MP BL images are
460provided in [plat/common/aarch64/platform_up_stack.S] and
461[plat/common/aarch64/platform_mp_stack.S]
Achin Guptac8afc782013-11-25 18:45:02 +0000462
463
Achin Gupta4f6ad662013-10-25 09:08:21 +0100464### Function : plat_report_exception()
465
466 Argument : unsigned int
467 Return : void
468
469A platform may need to report various information about its status when an
470exception is taken, for example the current exception level, the CPU security
471state (secure/non-secure), the exception type, and so on. This function is
472called in the following circumstances:
473
474* In BL1, whenever an exception is taken.
475* In BL2, whenever an exception is taken.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100476
477The default implementation doesn't do anything, to avoid making assumptions
478about the way the platform displays its status information.
479
480This function receives the exception type as its argument. Possible values for
Andrew Thoelke2bf28e62014-03-20 10:48:23 +0000481exceptions types are listed in the [include/runtime_svc.h] header file. Note
Achin Gupta4f6ad662013-10-25 09:08:21 +0100482that these constants are not related to any architectural exception code; they
483are just an ARM Trusted Firmware convention.
484
485
Soby Mathew24fb8382014-08-14 12:22:32 +0100486### Function : plat_reset_handler()
487
488 Argument : void
489 Return : void
490
491A platform may need to do additional initialization after reset. This function
492allows the platform to do the platform specific intializations. Platform
493specific errata workarounds could also be implemented here. The api should
Soby Mathew683f7882015-01-29 12:00:58 +0000494preserve the values of callee saved registers x19 to x29.
Soby Mathew24fb8382014-08-14 12:22:32 +0100495
Yatharth Kochar79a97b22014-11-20 18:09:41 +0000496The default implementation doesn't do anything. If a platform needs to override
497the default implementation, refer to the [Firmware Design Guide] for general
498guidelines regarding placement of code in a reset handler.
Soby Mathew24fb8382014-08-14 12:22:32 +0100499
Soby Mathewadd40352014-08-14 12:49:05 +0100500### Function : plat_disable_acp()
501
502 Argument : void
503 Return : void
504
505This api allows a platform to disable the Accelerator Coherency Port (if
506present) during a cluster power down sequence. The default weak implementation
507doesn't do anything. Since this api is called during the power down sequence,
508it has restrictions for stack usage and it can use the registers x0 - x17 as
509scratch registers. It should preserve the value in x18 register as it is used
510by the caller to store the return address.
511
Soby Mathew24fb8382014-08-14 12:22:32 +0100512
Achin Gupta4f6ad662013-10-25 09:08:21 +01005133. Modifications specific to a Boot Loader stage
514-------------------------------------------------
515
5163.1 Boot Loader Stage 1 (BL1)
517-----------------------------
518
519BL1 implements the reset vector where execution starts from after a cold or
520warm boot. For each CPU, BL1 is responsible for the following tasks:
521
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005221. Handling the reset as described in section 2.2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100523
5242. In the case of a cold boot and the CPU being the primary CPU, ensuring that
525 only this CPU executes the remaining BL1 code, including loading and passing
526 control to the BL2 stage.
527
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005283. Loading the BL2 image from non-volatile storage into secure memory at the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100529 address specified by the platform defined constant `BL2_BASE`.
530
Vikram Kanigirie452cd82014-05-23 15:56:12 +01005314. Populating a `meminfo` structure with the following information in memory,
Achin Gupta4f6ad662013-10-25 09:08:21 +0100532 accessible by BL2 immediately upon entry.
533
534 meminfo.total_base = Base address of secure RAM visible to BL2
535 meminfo.total_size = Size of secure RAM visible to BL2
536 meminfo.free_base = Base address of secure RAM available for
537 allocation to BL2
538 meminfo.free_size = Size of secure RAM available for allocation to BL2
539
540 BL1 places this `meminfo` structure at the beginning of the free memory
541 available for its use. Since BL1 cannot allocate memory dynamically at the
542 moment, its free memory will be available for BL2's use as-is. However, this
543 means that BL2 must read the `meminfo` structure before it starts using its
544 free memory (this is discussed in Section 3.2).
545
546 In future releases of the ARM Trusted Firmware it will be possible for
547 the platform to decide where it wants to place the `meminfo` structure for
548 BL2.
549
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100550 BL1 implements the `bl1_init_bl2_mem_layout()` function to populate the
Achin Gupta4f6ad662013-10-25 09:08:21 +0100551 BL2 `meminfo` structure. The platform may override this implementation, for
552 example if the platform wants to restrict the amount of memory visible to
553 BL2. Details of how to do this are given below.
554
555The following functions need to be implemented by the platform port to enable
556BL1 to perform the above tasks.
557
558
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100559### Function : bl1_plat_arch_setup() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100560
561 Argument : void
562 Return : void
563
Achin Gupta4f6ad662013-10-25 09:08:21 +0100564This function performs any platform-specific and architectural setup that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100565platform requires. Platform-specific setup might include configuration of
566memory controllers, configuration of the interconnect to allow the cluster
567to service cache snoop requests from another cluster, and so on.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100568
569In the ARM FVP port, this function enables CCI snoops into the cluster that the
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100570primary CPU is part of. It also enables the MMU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100571
572This function helps fulfill requirement 2 above.
573
574
575### Function : bl1_platform_setup() [mandatory]
576
577 Argument : void
578 Return : void
579
580This function executes with the MMU and data caches enabled. It is responsible
581for performing any remaining platform-specific setup that can occur after the
582MMU and data cache have been enabled.
583
Harry Liebeld265bd72014-01-31 19:04:10 +0000584This function is also responsible for initializing the storage abstraction layer
585which is used to load further bootloader images.
586
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100587This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100588
589
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000590### Function : bl1_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100591
592 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000593 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100594
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000595This function should only be called on the cold boot path. It executes with the
596MMU and data caches enabled. The pointer returned by this function must point to
597a `meminfo` structure containing the extents and availability of secure RAM for
598the BL1 stage.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100599
600 meminfo.total_base = Base address of secure RAM visible to BL1
601 meminfo.total_size = Size of secure RAM visible to BL1
602 meminfo.free_base = Base address of secure RAM available for allocation
603 to BL1
604 meminfo.free_size = Size of secure RAM available for allocation to BL1
605
606This information is used by BL1 to load the BL2 image in secure RAM. BL1 also
607populates a similar structure to tell BL2 the extents of memory available for
608its own use.
609
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100610This function helps fulfill requirement 3 above.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100611
612
Sandrine Bailleux8f55dfb2014-06-24 14:02:34 +0100613### Function : bl1_init_bl2_mem_layout() [optional]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100614
615 Argument : meminfo *, meminfo *, unsigned int, unsigned long
616 Return : void
617
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100618BL1 needs to tell the next stage the amount of secure RAM available
619for it to use. This information is populated in a `meminfo`
Achin Gupta4f6ad662013-10-25 09:08:21 +0100620structure.
621
622Depending upon where BL2 has been loaded in secure RAM (determined by
623`BL2_BASE`), BL1 calculates the amount of free memory available for BL2 to use.
624BL1 also ensures that its data sections resident in secure RAM are not visible
625to BL2. An illustration of how this is done in the ARM FVP port is given in the
626[User Guide], in the Section "Memory layout on Base FVP".
627
628
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100629### Function : bl1_plat_set_bl2_ep_info() [mandatory]
630
631 Argument : image_info *, entry_point_info *
632 Return : void
633
634This function is called after loading BL2 image and it can be used to overwrite
635the entry point set by loader and also set the security state and SPSR which
636represents the entry point system state for BL2.
637
638On FVP, we are setting the security state and the SPSR for the BL2 entrypoint
639
640
Achin Gupta4f6ad662013-10-25 09:08:21 +01006413.2 Boot Loader Stage 2 (BL2)
642-----------------------------
643
644The BL2 stage is executed only by the primary CPU, which is determined in BL1
645using the `platform_is_primary_cpu()` function. BL1 passed control to BL2 at
646`BL2_BASE`. BL2 executes in Secure EL1 and is responsible for:
647
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01006481. (Optional) Loading the BL3-0 binary image (if present) from platform
649 provided non-volatile storage. To load the BL3-0 image, BL2 makes use of
650 the `meminfo` returned by the `bl2_plat_get_bl30_meminfo()` function.
651 The platform also defines the address in memory where BL3-0 is loaded
652 through the optional constant `BL30_BASE`. BL2 uses this information
653 to determine if there is enough memory to load the BL3-0 image.
654 Subsequent handling of the BL3-0 image is platform-specific and is
655 implemented in the `bl2_plat_handle_bl30()` function.
656 If `BL30_BASE` is not defined then this step is not performed.
657
6582. Loading the BL3-1 binary image into secure RAM from non-volatile storage. To
Harry Liebeld265bd72014-01-31 19:04:10 +0000659 load the BL3-1 image, BL2 makes use of the `meminfo` structure passed to it
660 by BL1. This structure allows BL2 to calculate how much secure RAM is
661 available for its use. The platform also defines the address in secure RAM
662 where BL3-1 is loaded through the constant `BL31_BASE`. BL2 uses this
663 information to determine if there is enough memory to load the BL3-1 image.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100664
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01006653. (Optional) Loading the BL3-2 binary image (if present) from platform
Dan Handley1151c822014-04-15 11:38:38 +0100666 provided non-volatile storage. To load the BL3-2 image, BL2 makes use of
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100667 the `meminfo` returned by the `bl2_plat_get_bl32_meminfo()` function.
668 The platform also defines the address in memory where BL3-2 is loaded
669 through the optional constant `BL32_BASE`. BL2 uses this information
670 to determine if there is enough memory to load the BL3-2 image.
671 If `BL32_BASE` is not defined then this and the next step is not performed.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000672
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01006734. (Optional) Arranging to pass control to the BL3-2 image (if present) that
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100674 has been pre-loaded at `BL32_BASE`. BL2 populates an `entry_point_info`
Dan Handley1151c822014-04-15 11:38:38 +0100675 structure in memory provided by the platform with information about how
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100676 BL3-1 should pass control to the BL3-2 image.
Achin Guptaa3050ed2014-02-19 17:52:35 +0000677
Sandrine Bailleux93d81d62014-06-24 14:19:36 +01006785. Loading the normal world BL3-3 binary image into non-secure DRAM from
679 platform storage and arranging for BL3-1 to pass control to this image. This
680 address is determined using the `plat_get_ns_image_entrypoint()` function
681 described below.
682
6836. BL2 populates an `entry_point_info` structure in memory provided by the
684 platform with information about how BL3-1 should pass control to the
685 other BL images.
686
Achin Gupta4f6ad662013-10-25 09:08:21 +0100687The following functions must be implemented by the platform port to enable BL2
688to perform the above tasks.
689
690
691### Function : bl2_early_platform_setup() [mandatory]
692
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100693 Argument : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100694 Return : void
695
696This function executes with the MMU and data caches disabled. It is only called
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100697by the primary CPU. The arguments to this function is the address of the
698`meminfo` structure populated by BL1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100699
700The platform must copy the contents of the `meminfo` structure into a private
701variable as the original memory may be subsequently overwritten by BL2. The
702copied structure is made available to all BL2 code through the
Achin Guptae4d084e2014-02-19 17:18:23 +0000703`bl2_plat_sec_mem_layout()` function.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100704
705
706### Function : bl2_plat_arch_setup() [mandatory]
707
708 Argument : void
709 Return : void
710
711This function executes with the MMU and data caches disabled. It is only called
712by the primary CPU.
713
714The purpose of this function is to perform any architectural initialization
715that varies across platforms, for example enabling the MMU (since the memory
716map differs across platforms).
717
718
719### Function : bl2_platform_setup() [mandatory]
720
721 Argument : void
722 Return : void
723
724This function may execute with the MMU and data caches enabled if the platform
725port does the necessary initialization in `bl2_plat_arch_setup()`. It is only
726called by the primary CPU.
727
Achin Guptae4d084e2014-02-19 17:18:23 +0000728The purpose of this function is to perform any platform initialization
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100729specific to BL2. Platform security components are configured if required.
730For the Base FVP the TZC-400 TrustZone controller is configured to only
731grant non-secure access to DRAM. This avoids aliasing between secure and
732non-secure accesses in the TLB and cache - secure execution states can use
733the NS attributes in the MMU translation tables to access the DRAM.
Harry Liebelce19cf12014-04-01 19:28:07 +0100734
Harry Liebeld265bd72014-01-31 19:04:10 +0000735This function is also responsible for initializing the storage abstraction layer
736which is used to load further bootloader images.
737
Achin Gupta4f6ad662013-10-25 09:08:21 +0100738
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000739### Function : bl2_plat_sec_mem_layout() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100740
741 Argument : void
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000742 Return : meminfo *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100743
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000744This function should only be called on the cold boot path. It may execute with
745the MMU and data caches enabled if the platform port does the necessary
746initialization in `bl2_plat_arch_setup()`. It is only called by the primary CPU.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100747
Sandrine Bailleuxee12f6f2013-11-28 14:55:58 +0000748The purpose of this function is to return a pointer to a `meminfo` structure
749populated with the extents of secure RAM available for BL2 to use. See
Achin Gupta4f6ad662013-10-25 09:08:21 +0100750`bl2_early_platform_setup()` above.
751
752
Sandrine Bailleux93d81d62014-06-24 14:19:36 +0100753### Function : bl2_plat_get_bl30_meminfo() [mandatory]
754
755 Argument : meminfo *
756 Return : void
757
758This function is used to get the memory limits where BL2 can load the
759BL3-0 image. The meminfo provided by this is used by load_image() to
760validate whether the BL3-0 image can be loaded within the given
761memory from the given base.
762
763
764### Function : bl2_plat_handle_bl30() [mandatory]
765
766 Argument : image_info *
767 Return : int
768
769This function is called after loading BL3-0 image and it is used to perform any
770platform-specific actions required to handle the SCP firmware. Typically it
771transfers the image into SCP memory using a platform-specific protocol and waits
772until SCP executes it and signals to the Application Processor (AP) for BL2
773execution to continue.
774
775This function returns 0 on success, a negative error code otherwise.
776
777
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100778### Function : bl2_plat_get_bl31_params() [mandatory]
Harry Liebeld265bd72014-01-31 19:04:10 +0000779
780 Argument : void
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100781 Return : bl31_params *
Harry Liebeld265bd72014-01-31 19:04:10 +0000782
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100783BL2 platform code needs to return a pointer to a `bl31_params` structure it
784will use for passing information to BL3-1. The `bl31_params` structure carries
785the following information.
786 - Header describing the version information for interpreting the bl31_param
787 structure
788 - Information about executing the BL3-3 image in the `bl33_ep_info` field
789 - Information about executing the BL3-2 image in the `bl32_ep_info` field
790 - Information about the type and extents of BL3-1 image in the
791 `bl31_image_info` field
792 - Information about the type and extents of BL3-2 image in the
793 `bl32_image_info` field
794 - Information about the type and extents of BL3-3 image in the
795 `bl33_image_info` field
796
797The memory pointed by this structure and its sub-structures should be
798accessible from BL3-1 initialisation code. BL3-1 might choose to copy the
799necessary content, or maintain the structures until BL3-3 is initialised.
Harry Liebeld265bd72014-01-31 19:04:10 +0000800
801
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100802### Funtion : bl2_plat_get_bl31_ep_info() [mandatory]
Achin Gupta4f6ad662013-10-25 09:08:21 +0100803
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100804 Argument : void
805 Return : entry_point_info *
806
807BL2 platform code returns a pointer which is used to populate the entry point
808information for BL3-1 entry point. The location pointed by it should be
809accessible from BL1 while processing the synchronous exception to run to BL3-1.
810
811On FVP this is allocated inside an bl2_to_bl31_params_mem structure which
812is allocated at an address pointed by PARAMS_BASE.
813
814
815### Function : bl2_plat_set_bl31_ep_info() [mandatory]
816
817 Argument : image_info *, entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100818 Return : void
819
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100820This function is called after loading BL3-1 image and it can be used to
821overwrite the entry point set by loader and also set the security state
822and SPSR which represents the entry point system state for BL3-1.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100823
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100824On FVP, we are setting the security state and the SPSR for the BL3-1
825entrypoint.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100826
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100827### Function : bl2_plat_set_bl32_ep_info() [mandatory]
828
829 Argument : image_info *, entry_point_info *
830 Return : void
831
832This function is called after loading BL3-2 image and it can be used to
833overwrite the entry point set by loader and also set the security state
834and SPSR which represents the entry point system state for BL3-2.
835
836On FVP, we are setting the security state and the SPSR for the BL3-2
837entrypoint
838
839### Function : bl2_plat_set_bl33_ep_info() [mandatory]
840
841 Argument : image_info *, entry_point_info *
842 Return : void
843
844This function is called after loading BL3-3 image and it can be used to
845overwrite the entry point set by loader and also set the security state
846and SPSR which represents the entry point system state for BL3-3.
847
848On FVP, we are setting the security state and the SPSR for the BL3-3
849entrypoint
850
851### Function : bl2_plat_get_bl32_meminfo() [mandatory]
852
853 Argument : meminfo *
854 Return : void
855
856This function is used to get the memory limits where BL2 can load the
857BL3-2 image. The meminfo provided by this is used by load_image() to
858validate whether the BL3-2 image can be loaded with in the given
859memory from the given base.
860
861### Function : bl2_plat_get_bl33_meminfo() [mandatory]
862
863 Argument : meminfo *
864 Return : void
865
866This function is used to get the memory limits where BL2 can load the
867BL3-3 image. The meminfo provided by this is used by load_image() to
868validate whether the BL3-3 image can be loaded with in the given
869memory from the given base.
870
871### Function : bl2_plat_flush_bl31_params() [mandatory]
872
873 Argument : void
874 Return : void
875
876Once BL2 has populated all the structures that needs to be read by BL1
877and BL3-1 including the bl31_params structures and its sub-structures,
878the bl31_ep_info structure and any platform specific data. It flushes
879all these data to the main memory so that it is available when we jump to
880later Bootloader stages with MMU off
Achin Gupta4f6ad662013-10-25 09:08:21 +0100881
882### Function : plat_get_ns_image_entrypoint() [mandatory]
883
884 Argument : void
885 Return : unsigned long
886
887As previously described, BL2 is responsible for arranging for control to be
888passed to a normal world BL image through BL3-1. This function returns the
889entrypoint of that image, which BL3-1 uses to jump to it.
890
Harry Liebeld265bd72014-01-31 19:04:10 +0000891BL2 is responsible for loading the normal world BL3-3 image (e.g. UEFI).
Achin Gupta4f6ad662013-10-25 09:08:21 +0100892
893
8943.2 Boot Loader Stage 3-1 (BL3-1)
895---------------------------------
896
897During cold boot, the BL3-1 stage is executed only by the primary CPU. This is
898determined in BL1 using the `platform_is_primary_cpu()` function. BL1 passes
899control to BL3-1 at `BL31_BASE`. During warm boot, BL3-1 is executed by all
900CPUs. BL3-1 executes at EL3 and is responsible for:
901
9021. Re-initializing all architectural and platform state. Although BL1 performs
903 some of this initialization, BL3-1 remains resident in EL3 and must ensure
904 that EL3 architectural and platform state is completely initialized. It
905 should make no assumptions about the system state when it receives control.
906
9072. Passing control to a normal world BL image, pre-loaded at a platform-
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100908 specific address by BL2. BL3-1 uses the `entry_point_info` structure that BL2
Achin Gupta4f6ad662013-10-25 09:08:21 +0100909 populated in memory to do this.
910
9113. Providing runtime firmware services. Currently, BL3-1 only implements a
912 subset of the Power State Coordination Interface (PSCI) API as a runtime
913 service. See Section 3.3 below for details of porting the PSCI
914 implementation.
915
Achin Gupta35ca3512014-02-19 17:58:33 +00009164. Optionally passing control to the BL3-2 image, pre-loaded at a platform-
917 specific address by BL2. BL3-1 exports a set of apis that allow runtime
918 services to specify the security state in which the next image should be
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100919 executed and run the corresponding image. BL3-1 uses the `entry_point_info`
920 structure populated by BL2 to do this.
921
922If BL3-1 is a reset vector, It also needs to handle the reset as specified in
923section 2.2 before the tasks described above.
Achin Gupta35ca3512014-02-19 17:58:33 +0000924
Achin Gupta4f6ad662013-10-25 09:08:21 +0100925The following functions must be implemented by the platform port to enable BL3-1
926to perform the above tasks.
927
928
929### Function : bl31_early_platform_setup() [mandatory]
930
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100931 Argument : bl31_params *, void *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100932 Return : void
933
934This function executes with the MMU and data caches disabled. It is only called
935by the primary CPU. The arguments to this function are:
936
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100937* The address of the `bl31_params` structure populated by BL2.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100938* An opaque pointer that the platform may use as needed.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100939
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100940The platform can copy the contents of the `bl31_params` structure and its
941sub-structures into private variables if the original memory may be
942subsequently overwritten by BL3-1 and similarly the `void *` pointing
943to the platform data also needs to be saved.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100944
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100945On the ARM FVP port, BL2 passes a pointer to a `bl31_params` structure populated
946in the secure DRAM at address `0x6000000` in the bl31_params * argument and it
947does not use opaque pointer mentioned earlier. BL3-1 does not copy this
948information to internal data structures as it guarantees that the secure
949DRAM memory will not be overwritten. It maintains an internal reference to this
950information in the `bl2_to_bl31_params` variable.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100951
952### Function : bl31_plat_arch_setup() [mandatory]
953
954 Argument : void
955 Return : void
956
957This function executes with the MMU and data caches disabled. It is only called
958by the primary CPU.
959
960The purpose of this function is to perform any architectural initialization
961that varies across platforms, for example enabling the MMU (since the memory
962map differs across platforms).
963
964
965### Function : bl31_platform_setup() [mandatory]
966
967 Argument : void
968 Return : void
969
970This function may execute with the MMU and data caches enabled if the platform
971port does the necessary initialization in `bl31_plat_arch_setup()`. It is only
972called by the primary CPU.
973
974The purpose of this function is to complete platform initialization so that both
975BL3-1 runtime services and normal world software can function correctly.
976
977The ARM FVP port does the following:
978* Initializes the generic interrupt controller.
979* Configures the CLCD controller.
Sandrine Bailleux9e864902014-03-31 11:25:18 +0100980* Enables system-level implementation of the generic timer counter.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100981* Grants access to the system counter timer module
982* Initializes the FVP power controller device
983* Detects the system topology.
984
985
986### Function : bl31_get_next_image_info() [mandatory]
987
Achin Gupta35ca3512014-02-19 17:58:33 +0000988 Argument : unsigned int
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100989 Return : entry_point_info *
Achin Gupta4f6ad662013-10-25 09:08:21 +0100990
991This function may execute with the MMU and data caches enabled if the platform
992port does the necessary initializations in `bl31_plat_arch_setup()`.
993
994This function is called by `bl31_main()` to retrieve information provided by
Achin Gupta35ca3512014-02-19 17:58:33 +0000995BL2 for the next image in the security state specified by the argument. BL3-1
996uses this information to pass control to that image in the specified security
Vikram Kanigirie452cd82014-05-23 15:56:12 +0100997state. This function must return a pointer to the `entry_point_info` structure
Achin Gupta35ca3512014-02-19 17:58:33 +0000998(that was copied during `bl31_early_platform_setup()`) if the image exists. It
999should return NULL otherwise.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001000
1001
Achin Gupta4f6ad662013-10-25 09:08:21 +010010023.3 Power State Coordination Interface (in BL3-1)
1003------------------------------------------------
1004
1005The ARM Trusted Firmware's implementation of the PSCI API is based around the
1006concept of an _affinity instance_. Each _affinity instance_ can be uniquely
1007identified in a system by a CPU ID (the processor `MPIDR` is used in the PSCI
1008interface) and an _affinity level_. A processing element (for example, a
1009CPU) is at level 0. If the CPUs in the system are described in a tree where the
1010node above a CPU is a logical grouping of CPUs that share some state, then
1011affinity level 1 is that group of CPUs (for example, a cluster), and affinity
1012level 2 is a group of clusters (for example, the system). The implementation
1013assumes that the affinity level 1 ID can be computed from the affinity level 0
1014ID (for example, a unique cluster ID can be computed from the CPU ID). The
1015current implementation computes this on the basis of the recommended use of
1016`MPIDR` affinity fields in the ARM Architecture Reference Manual.
1017
1018BL3-1's platform initialization code exports a pointer to the platform-specific
1019power management operations required for the PSCI implementation to function
1020correctly. This information is populated in the `plat_pm_ops` structure. The
1021PSCI implementation calls members of the `plat_pm_ops` structure for performing
1022power management operations for each affinity instance. For example, the target
1023CPU is specified by its `MPIDR` in a PSCI `CPU_ON` call. The `affinst_on()`
1024handler (if present) is called for each affinity instance as the PSCI
1025implementation powers up each affinity level implemented in the `MPIDR` (for
1026example, CPU, cluster and system).
1027
1028The following functions must be implemented to initialize PSCI functionality in
1029the ARM Trusted Firmware.
1030
1031
1032### Function : plat_get_aff_count() [mandatory]
1033
1034 Argument : unsigned int, unsigned long
1035 Return : unsigned int
1036
1037This function may execute with the MMU and data caches enabled if the platform
1038port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1039called by the primary CPU.
1040
1041This function is called by the PSCI initialization code to detect the system
1042topology. Its purpose is to return the number of affinity instances implemented
1043at a given `affinity level` (specified by the first argument) and a given
1044`MPIDR` (specified by the second argument). For example, on a dual-cluster
1045system where first cluster implements 2 CPUs and the second cluster implements 4
1046CPUs, a call to this function with an `MPIDR` corresponding to the first cluster
1047(`0x0`) and affinity level 0, would return 2. A call to this function with an
1048`MPIDR` corresponding to the second cluster (`0x100`) and affinity level 0,
1049would return 4.
1050
1051
1052### Function : plat_get_aff_state() [mandatory]
1053
1054 Argument : unsigned int, unsigned long
1055 Return : unsigned int
1056
1057This function may execute with the MMU and data caches enabled if the platform
1058port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1059called by the primary CPU.
1060
1061This function is called by the PSCI initialization code. Its purpose is to
1062return the state of an affinity instance. The affinity instance is determined by
1063the affinity ID at a given `affinity level` (specified by the first argument)
1064and an `MPIDR` (specified by the second argument). The state can be one of
1065`PSCI_AFF_PRESENT` or `PSCI_AFF_ABSENT`. The latter state is used to cater for
1066system topologies where certain affinity instances are unimplemented. For
1067example, consider a platform that implements a single cluster with 4 CPUs and
1068another CPU implemented directly on the interconnect with the cluster. The
1069`MPIDR`s of the cluster would range from `0x0-0x3`. The `MPIDR` of the single
1070CPU would be 0x100 to indicate that it does not belong to cluster 0. Cluster 1
1071is missing but needs to be accounted for to reach this single CPU in the
1072topology tree. Hence it is marked as `PSCI_AFF_ABSENT`.
1073
1074
1075### Function : plat_get_max_afflvl() [mandatory]
1076
1077 Argument : void
1078 Return : int
1079
1080This function may execute with the MMU and data caches enabled if the platform
1081port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1082called by the primary CPU.
1083
1084This function is called by the PSCI implementation both during cold and warm
1085boot, to determine the maximum affinity level that the power management
James Morrisseyba3155b2013-10-29 10:56:46 +00001086operations should apply to. ARMv8-A has support for 4 affinity levels. It is
Achin Gupta4f6ad662013-10-25 09:08:21 +01001087likely that hardware will implement fewer affinity levels. This function allows
1088the PSCI implementation to consider only those affinity levels in the system
1089that the platform implements. For example, the Base AEM FVP implements two
1090clusters with a configurable number of CPUs. It reports the maximum affinity
1091level as 1, resulting in PSCI power control up to the cluster level.
1092
1093
1094### Function : platform_setup_pm() [mandatory]
1095
Sandrine Bailleux44804252014-08-06 11:27:23 +01001096 Argument : const plat_pm_ops **
Achin Gupta4f6ad662013-10-25 09:08:21 +01001097 Return : int
1098
1099This function may execute with the MMU and data caches enabled if the platform
1100port does the necessary initializations in `bl31_plat_arch_setup()`. It is only
1101called by the primary CPU.
1102
1103This function is called by PSCI initialization code. Its purpose is to export
1104handler routines for platform-specific power management actions by populating
1105the passed pointer with a pointer to BL3-1's private `plat_pm_ops` structure.
1106
1107A description of each member of this structure is given below. Please refer to
Sandrine Bailleux44804252014-08-06 11:27:23 +01001108the ARM FVP specific implementation of these handlers in [plat/fvp/fvp_pm.c]
Soby Mathew539dced2014-10-02 16:56:51 +01001109as an example. A platform port is expected to implement these handlers if the
1110corresponding PSCI operation is to be supported and these handlers are expected
1111to succeed if the return type is `void`.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001112
1113#### plat_pm_ops.affinst_standby()
1114
1115Perform the platform-specific setup to enter the standby state indicated by the
Soby Mathew539dced2014-10-02 16:56:51 +01001116passed argument. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001117
1118#### plat_pm_ops.affinst_on()
1119
1120Perform the platform specific setup to power on an affinity instance, specified
Soby Mathewe146f4c2014-09-26 15:08:52 +01001121by the `MPIDR` (first argument) and `affinity level` (third argument). The
1122`state` (fourth argument) contains the current state of that affinity instance
Achin Gupta4f6ad662013-10-25 09:08:21 +01001123(ON or OFF). This is useful to determine whether any action must be taken. For
1124example, while powering on a CPU, the cluster that contains this CPU might
1125already be in the ON state. The platform decides what actions must be taken to
1126transition from the current state to the target state (indicated by the power
Soby Mathew539dced2014-10-02 16:56:51 +01001127management operation). The generic code expects the platform to return
1128E_SUCCESS on success or E_INTERN_FAIL for any failure.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001129
1130#### plat_pm_ops.affinst_off()
1131
Soby Mathewe146f4c2014-09-26 15:08:52 +01001132Perform the platform specific setup to power off an affinity instance of the
1133calling CPU. It is called by the PSCI `CPU_OFF` API implementation.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001134
Soby Mathewe146f4c2014-09-26 15:08:52 +01001135The `affinity level` (first argument) and `state` (second argument) have
1136a similar meaning as described in the `affinst_on()` operation. They are
1137used to identify the affinity instance on which the call is made and its
1138current state. This gives the platform port an indication of the
Achin Gupta4f6ad662013-10-25 09:08:21 +01001139state transition it must make to perform the requested action. For example, if
1140the calling CPU is the last powered on CPU in the cluster, after powering down
1141affinity level 0 (CPU), the platform port should power down affinity level 1
Soby Mathew539dced2014-10-02 16:56:51 +01001142(the cluster) as well. The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001143
Achin Gupta4f6ad662013-10-25 09:08:21 +01001144#### plat_pm_ops.affinst_suspend()
1145
Soby Mathewe146f4c2014-09-26 15:08:52 +01001146Perform the platform specific setup to power off an affinity instance of the
1147calling CPU. It is called by the PSCI `CPU_SUSPEND` API
Achin Gupta4f6ad662013-10-25 09:08:21 +01001148implementation.
1149
Soby Mathewe146f4c2014-09-26 15:08:52 +01001150The `affinity level` (second argument) and `state` (third argument) have a
1151similar meaning as described in the `affinst_on()` operation. They are used to
1152identify the affinity instance on which the call is made and its current state.
1153This gives the platform port an indication of the state transition it must
1154make to perform the requested action. For example, if the calling CPU is the
1155last powered on CPU in the cluster, after powering down affinity level 0 (CPU),
1156the platform port should power down affinity level 1 (the cluster) as well.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001157
1158The difference between turning an affinity instance off versus suspending it
1159is that in the former case, the affinity instance is expected to re-initialize
1160its state when its next powered on (see `affinst_on_finish()`). In the latter
1161case, the affinity instance is expected to save enough state so that it can
1162resume execution by restoring this state when its powered on (see
Soby Mathew539dced2014-10-02 16:56:51 +01001163`affinst_suspend_finish()`).The generic code expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001164
Achin Gupta4f6ad662013-10-25 09:08:21 +01001165#### plat_pm_ops.affinst_on_finish()
1166
1167This function is called by the PSCI implementation after the calling CPU is
1168powered on and released from reset in response to an earlier PSCI `CPU_ON` call.
1169It performs the platform-specific setup required to initialize enough state for
1170this CPU to enter the normal world and also provide secure runtime firmware
1171services.
1172
Soby Mathewe146f4c2014-09-26 15:08:52 +01001173The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001174similar meaning as described in the previous operations. The generic code
1175expects the handler to succeed.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001176
Achin Gupta4f6ad662013-10-25 09:08:21 +01001177#### plat_pm_ops.affinst_on_suspend()
1178
1179This function is called by the PSCI implementation after the calling CPU is
1180powered on and released from reset in response to an asynchronous wakeup
1181event, for example a timer interrupt that was programmed by the CPU during the
1182`CPU_SUSPEND` call. It performs the platform-specific setup required to
1183restore the saved state for this CPU to resume execution in the normal world
1184and also provide secure runtime firmware services.
1185
Soby Mathewe146f4c2014-09-26 15:08:52 +01001186The `affinity level` (first argument) and `state` (second argument) have a
Soby Mathew539dced2014-10-02 16:56:51 +01001187similar meaning as described in the previous operations. The generic code
1188expects the platform to succeed.
1189
1190#### plat_pm_ops.validate_power_state()
1191
1192This function is called by the PSCI implementation during the `CPU_SUSPEND`
1193call to validate the `power_state` parameter of the PSCI API. If the
1194`power_state` is known to be invalid, the platform must return
1195PSCI_E_INVALID_PARAMS as error, which is propagated back to the normal
1196world PSCI client.
1197
1198#### plat_pm_ops.validate_ns_entrypoint()
1199
1200This function is called by the PSCI implementation during the `CPU_SUSPEND`
1201and `CPU_ON` calls to validate the non-secure `entry_point` parameter passed
1202by the normal world. If the `entry_point` is known to be invalid, the platform
1203must return PSCI_E_INVALID_PARAMS as error, which is propagated back to the
1204normal world PSCI client.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001205
Achin Gupta4f6ad662013-10-25 09:08:21 +01001206BL3-1 platform initialization code must also detect the system topology and
1207the state of each affinity instance in the topology. This information is
1208critical for the PSCI runtime service to function correctly. More details are
1209provided in the description of the `plat_get_aff_count()` and
1210`plat_get_aff_state()` functions above.
1211
Achin Guptaa4fa3cb2014-06-02 22:27:36 +010012123.4 Interrupt Management framework (in BL3-1)
1213----------------------------------------------
1214BL3-1 implements an Interrupt Management Framework (IMF) to manage interrupts
1215generated in either security state and targeted to EL1 or EL2 in the non-secure
1216state or EL3/S-EL1 in the secure state. The design of this framework is
1217described in the [IMF Design Guide]
1218
1219A platform should export the following APIs to support the IMF. The following
1220text briefly describes each api and its implementation on the FVP port. The API
1221implementation depends upon the type of interrupt controller present in the
1222platform. The FVP implements an ARM Generic Interrupt Controller (ARM GIC) as
1223per the version 2.0 of the [ARM GIC Architecture Specification]
1224
1225### Function : plat_interrupt_type_to_line() [mandatory]
1226
1227 Argument : uint32_t, uint32_t
1228 Return : uint32_t
1229
1230The ARM processor signals an interrupt exception either through the IRQ or FIQ
1231interrupt line. The specific line that is signaled depends on how the interrupt
1232controller (IC) reports different interrupt types from an execution context in
1233either security state. The IMF uses this API to determine which interrupt line
1234the platform IC uses to signal each type of interrupt supported by the framework
1235from a given security state.
1236
1237The first parameter will be one of the `INTR_TYPE_*` values (see [IMF Design
1238Guide]) indicating the target type of the interrupt, the second parameter is the
1239security state of the originating execution context. The return result is the
1240bit position in the `SCR_EL3` register of the respective interrupt trap: IRQ=1,
1241FIQ=2.
1242
1243The FVP port configures the ARM GIC to signal S-EL1 interrupts as FIQs and
1244Non-secure interrupts as IRQs from either security state.
1245
1246
1247### Function : plat_ic_get_pending_interrupt_type() [mandatory]
1248
1249 Argument : void
1250 Return : uint32_t
1251
1252This API returns the type of the highest priority pending interrupt at the
1253platform IC. The IMF uses the interrupt type to retrieve the corresponding
1254handler function. `INTR_TYPE_INVAL` is returned when there is no interrupt
1255pending. The valid interrupt types that can be returned are `INTR_TYPE_EL3`,
1256`INTR_TYPE_S_EL1` and `INTR_TYPE_NS`.
1257
1258The FVP port reads the _Highest Priority Pending Interrupt Register_
1259(`GICC_HPPIR`) to determine the id of the pending interrupt. The type of interrupt
1260depends upon the id value as follows.
1261
12621. id < 1022 is reported as a S-EL1 interrupt
12632. id = 1022 is reported as a Non-secure interrupt.
12643. id = 1023 is reported as an invalid interrupt type.
1265
1266
1267### Function : plat_ic_get_pending_interrupt_id() [mandatory]
1268
1269 Argument : void
1270 Return : uint32_t
1271
1272This API returns the id of the highest priority pending interrupt at the
1273platform IC. The IMF passes the id returned by this API to the registered
1274handler for the pending interrupt if the `IMF_READ_INTERRUPT_ID` build time flag
1275is set. INTR_ID_UNAVAILABLE is returned when there is no interrupt pending.
1276
1277The FVP port reads the _Highest Priority Pending Interrupt Register_
1278(`GICC_HPPIR`) to determine the id of the pending interrupt. The id that is
1279returned by API depends upon the value of the id read from the interrupt
1280controller as follows.
1281
12821. id < 1022. id is returned as is.
12832. id = 1022. The _Aliased Highest Priority Pending Interrupt Register_
1284 (`GICC_AHPPIR`) is read to determine the id of the non-secure interrupt. This
1285 id is returned by the API.
12863. id = 1023. `INTR_ID_UNAVAILABLE` is returned.
1287
1288
1289### Function : plat_ic_acknowledge_interrupt() [mandatory]
1290
1291 Argument : void
1292 Return : uint32_t
1293
1294This API is used by the CPU to indicate to the platform IC that processing of
1295the highest pending interrupt has begun. It should return the id of the
1296interrupt which is being processed.
1297
1298The FVP port reads the _Interrupt Acknowledge Register_ (`GICC_IAR`). This
1299changes the state of the highest priority pending interrupt from pending to
1300active in the interrupt controller. It returns the value read from the
1301`GICC_IAR`. This value is the id of the interrupt whose state has been changed.
1302
1303The TSP uses this API to start processing of the secure physical timer
1304interrupt.
1305
1306
1307### Function : plat_ic_end_of_interrupt() [mandatory]
1308
1309 Argument : uint32_t
1310 Return : void
1311
1312This API is used by the CPU to indicate to the platform IC that processing of
1313the interrupt corresponding to the id (passed as the parameter) has
1314finished. The id should be the same as the id returned by the
1315`plat_ic_acknowledge_interrupt()` API.
1316
1317The FVP port writes the id to the _End of Interrupt Register_
1318(`GICC_EOIR`). This deactivates the corresponding interrupt in the interrupt
1319controller.
1320
1321The TSP uses this API to finish processing of the secure physical timer
1322interrupt.
1323
1324
1325### Function : plat_ic_get_interrupt_type() [mandatory]
1326
1327 Argument : uint32_t
1328 Return : uint32_t
1329
1330This API returns the type of the interrupt id passed as the parameter.
1331`INTR_TYPE_INVAL` is returned if the id is invalid. If the id is valid, a valid
1332interrupt type (one of `INTR_TYPE_EL3`, `INTR_TYPE_S_EL1` and `INTR_TYPE_NS`) is
1333returned depending upon how the interrupt has been configured by the platform
1334IC.
1335
1336The FVP port configures S-EL1 interrupts as Group0 interrupts and Non-secure
1337interrupts as Group1 interrupts. It reads the group value corresponding to the
1338interrupt id from the relevant _Interrupt Group Register_ (`GICD_IGROUPRn`). It
1339uses the group value to determine the type of interrupt.
1340
Soby Mathewc67b09b2014-07-14 16:57:23 +010013413.5 Crash Reporting mechanism (in BL3-1)
1342----------------------------------------------
1343BL3-1 implements a crash reporting mechanism which prints the various registers
Sandrine Bailleux44804252014-08-06 11:27:23 +01001344of the CPU to enable quick crash analysis and debugging. It requires that a
1345console is designated as the crash console by the platform which will be used to
1346print the register dump.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001347
Sandrine Bailleux44804252014-08-06 11:27:23 +01001348The following functions must be implemented by the platform if it wants crash
1349reporting mechanism in BL3-1. The functions are implemented in assembly so that
1350they can be invoked without a C Runtime stack.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001351
1352### Function : plat_crash_console_init
1353
1354 Argument : void
1355 Return : int
1356
Sandrine Bailleux44804252014-08-06 11:27:23 +01001357This API is used by the crash reporting mechanism to initialize the crash
1358console. It should only use the general purpose registers x0 to x2 to do the
1359initialization and returns 1 on success.
Soby Mathewc67b09b2014-07-14 16:57:23 +01001360
Sandrine Bailleux44804252014-08-06 11:27:23 +01001361The FVP port designates the `PL011_UART0` as the crash console and calls the
Soby Mathewc67b09b2014-07-14 16:57:23 +01001362console_core_init() to initialize the console.
1363
1364### Function : plat_crash_console_putc
1365
1366 Argument : int
1367 Return : int
1368
1369This API is used by the crash reporting mechanism to print a character on the
1370designated crash console. It should only use general purpose registers x1 and
1371x2 to do its work. The parameter and the return value are in general purpose
1372register x0.
1373
Sandrine Bailleux44804252014-08-06 11:27:23 +01001374The FVP port designates the `PL011_UART0` as the crash console and calls the
Soby Mathewc67b09b2014-07-14 16:57:23 +01001375console_core_putc() to print the character on the console.
Achin Gupta4f6ad662013-10-25 09:08:21 +01001376
Soby Mathew27713fb2014-09-08 17:51:01 +010013774. Build flags
1378---------------
1379
1380There are some build flags which can be defined by the platform to control
1381inclusion or exclusion of certain BL stages from the FIP image. These flags
1382need to be defined in the platform makefile which will get included by the
1383build system.
1384
1385* **NEED_BL30**
1386 This flag if defined by the platform mandates that a BL3-0 binary should
1387 be included in the FIP image. The path to the BL3-0 binary can be specified
1388 by the `BL30` build option (see build options in the [User Guide]).
1389
1390* **NEED_BL33**
1391 By default, this flag is defined `yes` by the build system and `BL33`
1392 build option should be supplied as a build option. The platform has the option
1393 of excluding the BL3-3 image in the `fip` image by defining this flag to
1394 `no`.
1395
13965. C Library
Harry Liebela960f282013-12-12 16:03:44 +00001397-------------
1398
1399To avoid subtle toolchain behavioral dependencies, the header files provided
1400by the compiler are not used. The software is built with the `-nostdinc` flag
1401to ensure no headers are included from the toolchain inadvertently. Instead the
1402required headers are included in the ARM Trusted Firmware source tree. The
1403library only contains those C library definitions required by the local
1404implementation. If more functionality is required, the needed library functions
1405will need to be added to the local implementation.
1406
1407Versions of [FreeBSD] headers can be found in `include/stdlib`. Some of these
1408headers have been cut down in order to simplify the implementation. In order to
1409minimize changes to the header files, the [FreeBSD] layout has been maintained.
1410The generic C library definitions can be found in `include/stdlib` with more
1411system and machine specific declarations in `include/stdlib/sys` and
1412`include/stdlib/machine`.
1413
1414The local C library implementations can be found in `lib/stdlib`. In order to
1415extend the C library these files may need to be modified. It is recommended to
1416use a release version of [FreeBSD] as a starting point.
1417
1418The C library header files in the [FreeBSD] source tree are located in the
1419`include` and `sys/sys` directories. [FreeBSD] machine specific definitions
1420can be found in the `sys/<machine-type>` directories. These files define things
1421like 'the size of a pointer' and 'the range of an integer'. Since an AArch64
1422port for [FreeBSD] does not yet exist, the machine specific definitions are
1423based on existing machine types with similar properties (for example SPARC64).
1424
1425Where possible, C library function implementations were taken from [FreeBSD]
1426as found in the `lib/libc` directory.
1427
1428A copy of the [FreeBSD] sources can be downloaded with `git`.
1429
1430 git clone git://github.com/freebsd/freebsd.git -b origin/release/9.2.0
1431
1432
Soby Mathew27713fb2014-09-08 17:51:01 +010014336. Storage abstraction layer
Harry Liebeld265bd72014-01-31 19:04:10 +00001434-----------------------------
1435
1436In order to improve platform independence and portability an storage abstraction
1437layer is used to load data from non-volatile platform storage.
1438
1439Each platform should register devices and their drivers via the Storage layer.
1440These drivers then need to be initialized by bootloader phases as
1441required in their respective `blx_platform_setup()` functions. Currently
1442storage access is only required by BL1 and BL2 phases. The `load_image()`
1443function uses the storage layer to access non-volatile platform storage.
1444
1445It is mandatory to implement at least one storage driver. For the FVP the
1446Firmware Image Package(FIP) driver is provided as the default means to load data
1447from storage (see the "Firmware Image Package" section in the [User Guide]).
1448The storage layer is described in the header file `include/io_storage.h`. The
1449implementation of the common library is in `lib/io_storage.c` and the driver
1450files are located in `drivers/io/`.
1451
1452Each IO driver must provide `io_dev_*` structures, as described in
1453`drivers/io/io_driver.h`. These are returned via a mandatory registration
1454function that is called on platform initialization. The semi-hosting driver
1455implementation in `io_semihosting.c` can be used as an example.
1456
1457The Storage layer provides mechanisms to initialize storage devices before
1458IO operations are called. The basic operations supported by the layer
1459include `open()`, `close()`, `read()`, `write()`, `size()` and `seek()`.
1460Drivers do not have to implement all operations, but each platform must
1461provide at least one driver for a device capable of supporting generic
1462operations such as loading a bootloader image.
1463
1464The current implementation only allows for known images to be loaded by the
Dan Handleyb68954c2014-05-29 12:30:24 +01001465firmware. These images are specified by using their names, as defined in
1466[include/plat/common/platform.h]. The platform layer (`plat_get_image_source()`)
1467then returns a reference to a device and a driver-specific `spec` which will be
1468understood by the driver to allow access to the image data.
Harry Liebeld265bd72014-01-31 19:04:10 +00001469
1470The layer is designed in such a way that is it possible to chain drivers with
1471other drivers. For example, file-system drivers may be implemented on top of
1472physical block devices, both represented by IO devices with corresponding
1473drivers. In such a case, the file-system "binding" with the block device may
1474be deferred until the file-system device is initialised.
1475
1476The abstraction currently depends on structures being statically allocated
1477by the drivers and callers, as the system does not yet provide a means of
1478dynamically allocating memory. This may also have the affect of limiting the
1479amount of open resources per driver.
1480
1481
Achin Gupta4f6ad662013-10-25 09:08:21 +01001482- - - - - - - - - - - - - - - - - - - - - - - - - -
1483
Dan Handleye83b0ca2014-01-14 18:17:09 +00001484_Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved._
Achin Gupta4f6ad662013-10-25 09:08:21 +01001485
1486
Achin Guptaa4fa3cb2014-06-02 22:27:36 +01001487[ARM GIC Architecture Specification]: http://arminfo.emea.arm.com/help/topic/com.arm.doc.ihi0048b/IHI0048B_gic_architecture_specification.pdf
1488[IMF Design Guide]: interrupt-framework-design.md
1489[User Guide]: user-guide.md
1490[FreeBSD]: http://www.freebsd.org
Yatharth Kochar79a97b22014-11-20 18:09:41 +00001491[Firmware Design Guide]: firmware-design.md
Achin Gupta4f6ad662013-10-25 09:08:21 +01001492
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001493[plat/common/aarch64/platform_mp_stack.S]: ../plat/common/aarch64/platform_mp_stack.S
1494[plat/common/aarch64/platform_up_stack.S]: ../plat/common/aarch64/platform_up_stack.S
Dan Handleyb68954c2014-05-29 12:30:24 +01001495[plat/fvp/include/platform_def.h]: ../plat/fvp/include/platform_def.h
1496[plat/fvp/include/plat_macros.S]: ../plat/fvp/include/plat_macros.S
Andrew Thoelke2bf28e62014-03-20 10:48:23 +00001497[plat/fvp/aarch64/plat_common.c]: ../plat/fvp/aarch64/plat_common.c
1498[plat/fvp/plat_pm.c]: ../plat/fvp/plat_pm.c
1499[include/runtime_svc.h]: ../include/runtime_svc.h
Dan Handleyb68954c2014-05-29 12:30:24 +01001500[include/plat/common/platform.h]: ../include/plat/common/platform.h