xref: /aosp_15_r20/external/arm-trusted-firmware/docs/getting_started/porting-guide.rst (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong ParkPorting Guide
2*54fd6939SJiyong Park=============
3*54fd6939SJiyong Park
4*54fd6939SJiyong ParkIntroduction
5*54fd6939SJiyong Park------------
6*54fd6939SJiyong Park
7*54fd6939SJiyong ParkPorting Trusted Firmware-A (TF-A) to a new platform involves making some
8*54fd6939SJiyong Parkmandatory and optional modifications for both the cold and warm boot paths.
9*54fd6939SJiyong ParkModifications consist of:
10*54fd6939SJiyong Park
11*54fd6939SJiyong Park-  Implementing a platform-specific function or variable,
12*54fd6939SJiyong Park-  Setting up the execution context in a certain way, or
13*54fd6939SJiyong Park-  Defining certain constants (for example #defines).
14*54fd6939SJiyong Park
15*54fd6939SJiyong ParkThe platform-specific functions and variables are declared in
16*54fd6939SJiyong Park``include/plat/common/platform.h``. The firmware provides a default
17*54fd6939SJiyong Parkimplementation of variables and functions to fulfill the optional requirements.
18*54fd6939SJiyong ParkThese implementations are all weakly defined; they are provided to ease the
19*54fd6939SJiyong Parkporting effort. Each platform port can override them with its own implementation
20*54fd6939SJiyong Parkif the default implementation is inadequate.
21*54fd6939SJiyong Park
22*54fd6939SJiyong ParkSome modifications are common to all Boot Loader (BL) stages. Section 2
23*54fd6939SJiyong Parkdiscusses these in detail. The subsequent sections discuss the remaining
24*54fd6939SJiyong Parkmodifications for each BL stage in detail.
25*54fd6939SJiyong Park
26*54fd6939SJiyong ParkPlease refer to the :ref:`Platform Compatibility Policy` for the policy
27*54fd6939SJiyong Parkregarding compatibility and deprecation of these porting interfaces.
28*54fd6939SJiyong Park
29*54fd6939SJiyong ParkOnly Arm development platforms (such as FVP and Juno) may use the
30*54fd6939SJiyong Parkfunctions/definitions in ``include/plat/arm/common/`` and the corresponding
31*54fd6939SJiyong Parksource files in ``plat/arm/common/``. This is done so that there are no
32*54fd6939SJiyong Parkdependencies between platforms maintained by different people/companies. If you
33*54fd6939SJiyong Parkwant to use any of the functionality present in ``plat/arm`` files, please
34*54fd6939SJiyong Parkcreate a pull request that moves the code to ``plat/common`` so that it can be
35*54fd6939SJiyong Parkdiscussed.
36*54fd6939SJiyong Park
37*54fd6939SJiyong ParkCommon modifications
38*54fd6939SJiyong Park--------------------
39*54fd6939SJiyong Park
40*54fd6939SJiyong ParkThis section covers the modifications that should be made by the platform for
41*54fd6939SJiyong Parkeach BL stage to correctly port the firmware stack. They are categorized as
42*54fd6939SJiyong Parkeither mandatory or optional.
43*54fd6939SJiyong Park
44*54fd6939SJiyong ParkCommon mandatory modifications
45*54fd6939SJiyong Park------------------------------
46*54fd6939SJiyong Park
47*54fd6939SJiyong ParkA platform port must enable the Memory Management Unit (MMU) as well as the
48*54fd6939SJiyong Parkinstruction and data caches for each BL stage. Setting up the translation
49*54fd6939SJiyong Parktables is the responsibility of the platform port because memory maps differ
50*54fd6939SJiyong Parkacross platforms. A memory translation library (see ``lib/xlat_tables/``) is
51*54fd6939SJiyong Parkprovided to help in this setup.
52*54fd6939SJiyong Park
53*54fd6939SJiyong ParkNote that although this library supports non-identity mappings, this is intended
54*54fd6939SJiyong Parkonly for re-mapping peripheral physical addresses and allows platforms with high
55*54fd6939SJiyong ParkI/O addresses to reduce their virtual address space. All other addresses
56*54fd6939SJiyong Parkcorresponding to code and data must currently use an identity mapping.
57*54fd6939SJiyong Park
58*54fd6939SJiyong ParkAlso, the only translation granule size supported in TF-A is 4KB, as various
59*54fd6939SJiyong Parkparts of the code assume that is the case. It is not possible to switch to
60*54fd6939SJiyong Park16 KB or 64 KB granule sizes at the moment.
61*54fd6939SJiyong Park
62*54fd6939SJiyong ParkIn Arm standard platforms, each BL stage configures the MMU in the
63*54fd6939SJiyong Parkplatform-specific architecture setup function, ``blX_plat_arch_setup()``, and uses
64*54fd6939SJiyong Parkan identity mapping for all addresses.
65*54fd6939SJiyong Park
66*54fd6939SJiyong ParkIf the build option ``USE_COHERENT_MEM`` is enabled, each platform can allocate a
67*54fd6939SJiyong Parkblock of identity mapped secure memory with Device-nGnRE attributes aligned to
68*54fd6939SJiyong Parkpage boundary (4K) for each BL stage. All sections which allocate coherent
69*54fd6939SJiyong Parkmemory are grouped under ``coherent_ram``. For ex: Bakery locks are placed in a
70*54fd6939SJiyong Parksection identified by name ``bakery_lock`` inside ``coherent_ram`` so that its
71*54fd6939SJiyong Parkpossible for the firmware to place variables in it using the following C code
72*54fd6939SJiyong Parkdirective:
73*54fd6939SJiyong Park
74*54fd6939SJiyong Park::
75*54fd6939SJiyong Park
76*54fd6939SJiyong Park    __section("bakery_lock")
77*54fd6939SJiyong Park
78*54fd6939SJiyong ParkOr alternatively the following assembler code directive:
79*54fd6939SJiyong Park
80*54fd6939SJiyong Park::
81*54fd6939SJiyong Park
82*54fd6939SJiyong Park    .section bakery_lock
83*54fd6939SJiyong Park
84*54fd6939SJiyong ParkThe ``coherent_ram`` section is a sum of all sections like ``bakery_lock`` which are
85*54fd6939SJiyong Parkused to allocate any data structures that are accessed both when a CPU is
86*54fd6939SJiyong Parkexecuting with its MMU and caches enabled, and when it's running with its MMU
87*54fd6939SJiyong Parkand caches disabled. Examples are given below.
88*54fd6939SJiyong Park
89*54fd6939SJiyong ParkThe following variables, functions and constants must be defined by the platform
90*54fd6939SJiyong Parkfor the firmware to work correctly.
91*54fd6939SJiyong Park
92*54fd6939SJiyong ParkFile : platform_def.h [mandatory]
93*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94*54fd6939SJiyong Park
95*54fd6939SJiyong ParkEach platform must ensure that a header file of this name is in the system
96*54fd6939SJiyong Parkinclude path with the following constants defined. This will require updating
97*54fd6939SJiyong Parkthe list of ``PLAT_INCLUDES`` in the ``platform.mk`` file.
98*54fd6939SJiyong Park
99*54fd6939SJiyong ParkPlatform ports may optionally use the file ``include/plat/common/common_def.h``,
100*54fd6939SJiyong Parkwhich provides typical values for some of the constants below. These values are
101*54fd6939SJiyong Parklikely to be suitable for all platform ports.
102*54fd6939SJiyong Park
103*54fd6939SJiyong Park-  **#define : PLATFORM_LINKER_FORMAT**
104*54fd6939SJiyong Park
105*54fd6939SJiyong Park   Defines the linker format used by the platform, for example
106*54fd6939SJiyong Park   ``elf64-littleaarch64``.
107*54fd6939SJiyong Park
108*54fd6939SJiyong Park-  **#define : PLATFORM_LINKER_ARCH**
109*54fd6939SJiyong Park
110*54fd6939SJiyong Park   Defines the processor architecture for the linker by the platform, for
111*54fd6939SJiyong Park   example ``aarch64``.
112*54fd6939SJiyong Park
113*54fd6939SJiyong Park-  **#define : PLATFORM_STACK_SIZE**
114*54fd6939SJiyong Park
115*54fd6939SJiyong Park   Defines the normal stack memory available to each CPU. This constant is used
116*54fd6939SJiyong Park   by ``plat/common/aarch64/platform_mp_stack.S`` and
117*54fd6939SJiyong Park   ``plat/common/aarch64/platform_up_stack.S``.
118*54fd6939SJiyong Park
119*54fd6939SJiyong Park-  **#define : CACHE_WRITEBACK_GRANULE**
120*54fd6939SJiyong Park
121*54fd6939SJiyong Park   Defines the size in bits of the largest cache line across all the cache
122*54fd6939SJiyong Park   levels in the platform.
123*54fd6939SJiyong Park
124*54fd6939SJiyong Park-  **#define : FIRMWARE_WELCOME_STR**
125*54fd6939SJiyong Park
126*54fd6939SJiyong Park   Defines the character string printed by BL1 upon entry into the ``bl1_main()``
127*54fd6939SJiyong Park   function.
128*54fd6939SJiyong Park
129*54fd6939SJiyong Park-  **#define : PLATFORM_CORE_COUNT**
130*54fd6939SJiyong Park
131*54fd6939SJiyong Park   Defines the total number of CPUs implemented by the platform across all
132*54fd6939SJiyong Park   clusters in the system.
133*54fd6939SJiyong Park
134*54fd6939SJiyong Park-  **#define : PLAT_NUM_PWR_DOMAINS**
135*54fd6939SJiyong Park
136*54fd6939SJiyong Park   Defines the total number of nodes in the power domain topology
137*54fd6939SJiyong Park   tree at all the power domain levels used by the platform.
138*54fd6939SJiyong Park   This macro is used by the PSCI implementation to allocate
139*54fd6939SJiyong Park   data structures to represent power domain topology.
140*54fd6939SJiyong Park
141*54fd6939SJiyong Park-  **#define : PLAT_MAX_PWR_LVL**
142*54fd6939SJiyong Park
143*54fd6939SJiyong Park   Defines the maximum power domain level that the power management operations
144*54fd6939SJiyong Park   should apply to. More often, but not always, the power domain level
145*54fd6939SJiyong Park   corresponds to affinity level. This macro allows the PSCI implementation
146*54fd6939SJiyong Park   to know the highest power domain level that it should consider for power
147*54fd6939SJiyong Park   management operations in the system that the platform implements. For
148*54fd6939SJiyong Park   example, the Base AEM FVP implements two clusters with a configurable
149*54fd6939SJiyong Park   number of CPUs and it reports the maximum power domain level as 1.
150*54fd6939SJiyong Park
151*54fd6939SJiyong Park-  **#define : PLAT_MAX_OFF_STATE**
152*54fd6939SJiyong Park
153*54fd6939SJiyong Park   Defines the local power state corresponding to the deepest power down
154*54fd6939SJiyong Park   possible at every power domain level in the platform. The local power
155*54fd6939SJiyong Park   states for each level may be sparsely allocated between 0 and this value
156*54fd6939SJiyong Park   with 0 being reserved for the RUN state. The PSCI implementation uses this
157*54fd6939SJiyong Park   value to initialize the local power states of the power domain nodes and
158*54fd6939SJiyong Park   to specify the requested power state for a PSCI_CPU_OFF call.
159*54fd6939SJiyong Park
160*54fd6939SJiyong Park-  **#define : PLAT_MAX_RET_STATE**
161*54fd6939SJiyong Park
162*54fd6939SJiyong Park   Defines the local power state corresponding to the deepest retention state
163*54fd6939SJiyong Park   possible at every power domain level in the platform. This macro should be
164*54fd6939SJiyong Park   a value less than PLAT_MAX_OFF_STATE and greater than 0. It is used by the
165*54fd6939SJiyong Park   PSCI implementation to distinguish between retention and power down local
166*54fd6939SJiyong Park   power states within PSCI_CPU_SUSPEND call.
167*54fd6939SJiyong Park
168*54fd6939SJiyong Park-  **#define : PLAT_MAX_PWR_LVL_STATES**
169*54fd6939SJiyong Park
170*54fd6939SJiyong Park   Defines the maximum number of local power states per power domain level
171*54fd6939SJiyong Park   that the platform supports. The default value of this macro is 2 since
172*54fd6939SJiyong Park   most platforms just support a maximum of two local power states at each
173*54fd6939SJiyong Park   power domain level (power-down and retention). If the platform needs to
174*54fd6939SJiyong Park   account for more local power states, then it must redefine this macro.
175*54fd6939SJiyong Park
176*54fd6939SJiyong Park   Currently, this macro is used by the Generic PSCI implementation to size
177*54fd6939SJiyong Park   the array used for PSCI_STAT_COUNT/RESIDENCY accounting.
178*54fd6939SJiyong Park
179*54fd6939SJiyong Park-  **#define : BL1_RO_BASE**
180*54fd6939SJiyong Park
181*54fd6939SJiyong Park   Defines the base address in secure ROM where BL1 originally lives. Must be
182*54fd6939SJiyong Park   aligned on a page-size boundary.
183*54fd6939SJiyong Park
184*54fd6939SJiyong Park-  **#define : BL1_RO_LIMIT**
185*54fd6939SJiyong Park
186*54fd6939SJiyong Park   Defines the maximum address in secure ROM that BL1's actual content (i.e.
187*54fd6939SJiyong Park   excluding any data section allocated at runtime) can occupy.
188*54fd6939SJiyong Park
189*54fd6939SJiyong Park-  **#define : BL1_RW_BASE**
190*54fd6939SJiyong Park
191*54fd6939SJiyong Park   Defines the base address in secure RAM where BL1's read-write data will live
192*54fd6939SJiyong Park   at runtime. Must be aligned on a page-size boundary.
193*54fd6939SJiyong Park
194*54fd6939SJiyong Park-  **#define : BL1_RW_LIMIT**
195*54fd6939SJiyong Park
196*54fd6939SJiyong Park   Defines the maximum address in secure RAM that BL1's read-write data can
197*54fd6939SJiyong Park   occupy at runtime.
198*54fd6939SJiyong Park
199*54fd6939SJiyong Park-  **#define : BL2_BASE**
200*54fd6939SJiyong Park
201*54fd6939SJiyong Park   Defines the base address in secure RAM where BL1 loads the BL2 binary image.
202*54fd6939SJiyong Park   Must be aligned on a page-size boundary. This constant is not applicable
203*54fd6939SJiyong Park   when BL2_IN_XIP_MEM is set to '1'.
204*54fd6939SJiyong Park
205*54fd6939SJiyong Park-  **#define : BL2_LIMIT**
206*54fd6939SJiyong Park
207*54fd6939SJiyong Park   Defines the maximum address in secure RAM that the BL2 image can occupy.
208*54fd6939SJiyong Park   This constant is not applicable when BL2_IN_XIP_MEM is set to '1'.
209*54fd6939SJiyong Park
210*54fd6939SJiyong Park-  **#define : BL2_RO_BASE**
211*54fd6939SJiyong Park
212*54fd6939SJiyong Park   Defines the base address in secure XIP memory where BL2 RO section originally
213*54fd6939SJiyong Park   lives. Must be aligned on a page-size boundary. This constant is only needed
214*54fd6939SJiyong Park   when BL2_IN_XIP_MEM is set to '1'.
215*54fd6939SJiyong Park
216*54fd6939SJiyong Park-  **#define : BL2_RO_LIMIT**
217*54fd6939SJiyong Park
218*54fd6939SJiyong Park   Defines the maximum address in secure XIP memory that BL2's actual content
219*54fd6939SJiyong Park   (i.e. excluding any data section allocated at runtime) can occupy. This
220*54fd6939SJiyong Park   constant is only needed when BL2_IN_XIP_MEM is set to '1'.
221*54fd6939SJiyong Park
222*54fd6939SJiyong Park-  **#define : BL2_RW_BASE**
223*54fd6939SJiyong Park
224*54fd6939SJiyong Park   Defines the base address in secure RAM where BL2's read-write data will live
225*54fd6939SJiyong Park   at runtime. Must be aligned on a page-size boundary. This constant is only
226*54fd6939SJiyong Park   needed when BL2_IN_XIP_MEM is set to '1'.
227*54fd6939SJiyong Park
228*54fd6939SJiyong Park-  **#define : BL2_RW_LIMIT**
229*54fd6939SJiyong Park
230*54fd6939SJiyong Park   Defines the maximum address in secure RAM that BL2's read-write data can
231*54fd6939SJiyong Park   occupy at runtime. This constant is only needed when BL2_IN_XIP_MEM is set
232*54fd6939SJiyong Park   to '1'.
233*54fd6939SJiyong Park
234*54fd6939SJiyong Park-  **#define : BL31_BASE**
235*54fd6939SJiyong Park
236*54fd6939SJiyong Park   Defines the base address in secure RAM where BL2 loads the BL31 binary
237*54fd6939SJiyong Park   image. Must be aligned on a page-size boundary.
238*54fd6939SJiyong Park
239*54fd6939SJiyong Park-  **#define : BL31_LIMIT**
240*54fd6939SJiyong Park
241*54fd6939SJiyong Park   Defines the maximum address in secure RAM that the BL31 image can occupy.
242*54fd6939SJiyong Park
243*54fd6939SJiyong ParkFor every image, the platform must define individual identifiers that will be
244*54fd6939SJiyong Parkused by BL1 or BL2 to load the corresponding image into memory from non-volatile
245*54fd6939SJiyong Parkstorage. For the sake of performance, integer numbers will be used as
246*54fd6939SJiyong Parkidentifiers. The platform will use those identifiers to return the relevant
247*54fd6939SJiyong Parkinformation about the image to be loaded (file handler, load address,
248*54fd6939SJiyong Parkauthentication information, etc.). The following image identifiers are
249*54fd6939SJiyong Parkmandatory:
250*54fd6939SJiyong Park
251*54fd6939SJiyong Park-  **#define : BL2_IMAGE_ID**
252*54fd6939SJiyong Park
253*54fd6939SJiyong Park   BL2 image identifier, used by BL1 to load BL2.
254*54fd6939SJiyong Park
255*54fd6939SJiyong Park-  **#define : BL31_IMAGE_ID**
256*54fd6939SJiyong Park
257*54fd6939SJiyong Park   BL31 image identifier, used by BL2 to load BL31.
258*54fd6939SJiyong Park
259*54fd6939SJiyong Park-  **#define : BL33_IMAGE_ID**
260*54fd6939SJiyong Park
261*54fd6939SJiyong Park   BL33 image identifier, used by BL2 to load BL33.
262*54fd6939SJiyong Park
263*54fd6939SJiyong ParkIf Trusted Board Boot is enabled, the following certificate identifiers must
264*54fd6939SJiyong Parkalso be defined:
265*54fd6939SJiyong Park
266*54fd6939SJiyong Park-  **#define : TRUSTED_BOOT_FW_CERT_ID**
267*54fd6939SJiyong Park
268*54fd6939SJiyong Park   BL2 content certificate identifier, used by BL1 to load the BL2 content
269*54fd6939SJiyong Park   certificate.
270*54fd6939SJiyong Park
271*54fd6939SJiyong Park-  **#define : TRUSTED_KEY_CERT_ID**
272*54fd6939SJiyong Park
273*54fd6939SJiyong Park   Trusted key certificate identifier, used by BL2 to load the trusted key
274*54fd6939SJiyong Park   certificate.
275*54fd6939SJiyong Park
276*54fd6939SJiyong Park-  **#define : SOC_FW_KEY_CERT_ID**
277*54fd6939SJiyong Park
278*54fd6939SJiyong Park   BL31 key certificate identifier, used by BL2 to load the BL31 key
279*54fd6939SJiyong Park   certificate.
280*54fd6939SJiyong Park
281*54fd6939SJiyong Park-  **#define : SOC_FW_CONTENT_CERT_ID**
282*54fd6939SJiyong Park
283*54fd6939SJiyong Park   BL31 content certificate identifier, used by BL2 to load the BL31 content
284*54fd6939SJiyong Park   certificate.
285*54fd6939SJiyong Park
286*54fd6939SJiyong Park-  **#define : NON_TRUSTED_FW_KEY_CERT_ID**
287*54fd6939SJiyong Park
288*54fd6939SJiyong Park   BL33 key certificate identifier, used by BL2 to load the BL33 key
289*54fd6939SJiyong Park   certificate.
290*54fd6939SJiyong Park
291*54fd6939SJiyong Park-  **#define : NON_TRUSTED_FW_CONTENT_CERT_ID**
292*54fd6939SJiyong Park
293*54fd6939SJiyong Park   BL33 content certificate identifier, used by BL2 to load the BL33 content
294*54fd6939SJiyong Park   certificate.
295*54fd6939SJiyong Park
296*54fd6939SJiyong Park-  **#define : FWU_CERT_ID**
297*54fd6939SJiyong Park
298*54fd6939SJiyong Park   Firmware Update (FWU) certificate identifier, used by NS_BL1U to load the
299*54fd6939SJiyong Park   FWU content certificate.
300*54fd6939SJiyong Park
301*54fd6939SJiyong Park-  **#define : PLAT_CRYPTOCELL_BASE**
302*54fd6939SJiyong Park
303*54fd6939SJiyong Park   This defines the base address of Arm® TrustZone® CryptoCell and must be
304*54fd6939SJiyong Park   defined if CryptoCell crypto driver is used for Trusted Board Boot. For
305*54fd6939SJiyong Park   capable Arm platforms, this driver is used if ``ARM_CRYPTOCELL_INTEG`` is
306*54fd6939SJiyong Park   set.
307*54fd6939SJiyong Park
308*54fd6939SJiyong ParkIf the AP Firmware Updater Configuration image, BL2U is used, the following
309*54fd6939SJiyong Parkmust also be defined:
310*54fd6939SJiyong Park
311*54fd6939SJiyong Park-  **#define : BL2U_BASE**
312*54fd6939SJiyong Park
313*54fd6939SJiyong Park   Defines the base address in secure memory where BL1 copies the BL2U binary
314*54fd6939SJiyong Park   image. Must be aligned on a page-size boundary.
315*54fd6939SJiyong Park
316*54fd6939SJiyong Park-  **#define : BL2U_LIMIT**
317*54fd6939SJiyong Park
318*54fd6939SJiyong Park   Defines the maximum address in secure memory that the BL2U image can occupy.
319*54fd6939SJiyong Park
320*54fd6939SJiyong Park-  **#define : BL2U_IMAGE_ID**
321*54fd6939SJiyong Park
322*54fd6939SJiyong Park   BL2U image identifier, used by BL1 to fetch an image descriptor
323*54fd6939SJiyong Park   corresponding to BL2U.
324*54fd6939SJiyong Park
325*54fd6939SJiyong ParkIf the SCP Firmware Update Configuration Image, SCP_BL2U is used, the following
326*54fd6939SJiyong Parkmust also be defined:
327*54fd6939SJiyong Park
328*54fd6939SJiyong Park-  **#define : SCP_BL2U_IMAGE_ID**
329*54fd6939SJiyong Park
330*54fd6939SJiyong Park   SCP_BL2U image identifier, used by BL1 to fetch an image descriptor
331*54fd6939SJiyong Park   corresponding to SCP_BL2U.
332*54fd6939SJiyong Park
333*54fd6939SJiyong Park   .. note::
334*54fd6939SJiyong Park      TF-A does not provide source code for this image.
335*54fd6939SJiyong Park
336*54fd6939SJiyong ParkIf the Non-Secure Firmware Updater ROM, NS_BL1U is used, the following must
337*54fd6939SJiyong Parkalso be defined:
338*54fd6939SJiyong Park
339*54fd6939SJiyong Park-  **#define : NS_BL1U_BASE**
340*54fd6939SJiyong Park
341*54fd6939SJiyong Park   Defines the base address in non-secure ROM where NS_BL1U executes.
342*54fd6939SJiyong Park   Must be aligned on a page-size boundary.
343*54fd6939SJiyong Park
344*54fd6939SJiyong Park   .. note::
345*54fd6939SJiyong Park      TF-A does not provide source code for this image.
346*54fd6939SJiyong Park
347*54fd6939SJiyong Park-  **#define : NS_BL1U_IMAGE_ID**
348*54fd6939SJiyong Park
349*54fd6939SJiyong Park   NS_BL1U image identifier, used by BL1 to fetch an image descriptor
350*54fd6939SJiyong Park   corresponding to NS_BL1U.
351*54fd6939SJiyong Park
352*54fd6939SJiyong ParkIf the Non-Secure Firmware Updater, NS_BL2U is used, the following must also
353*54fd6939SJiyong Parkbe defined:
354*54fd6939SJiyong Park
355*54fd6939SJiyong Park-  **#define : NS_BL2U_BASE**
356*54fd6939SJiyong Park
357*54fd6939SJiyong Park   Defines the base address in non-secure memory where NS_BL2U executes.
358*54fd6939SJiyong Park   Must be aligned on a page-size boundary.
359*54fd6939SJiyong Park
360*54fd6939SJiyong Park   .. note::
361*54fd6939SJiyong Park      TF-A does not provide source code for this image.
362*54fd6939SJiyong Park
363*54fd6939SJiyong Park-  **#define : NS_BL2U_IMAGE_ID**
364*54fd6939SJiyong Park
365*54fd6939SJiyong Park   NS_BL2U image identifier, used by BL1 to fetch an image descriptor
366*54fd6939SJiyong Park   corresponding to NS_BL2U.
367*54fd6939SJiyong Park
368*54fd6939SJiyong ParkFor the the Firmware update capability of TRUSTED BOARD BOOT, the following
369*54fd6939SJiyong Parkmacros may also be defined:
370*54fd6939SJiyong Park
371*54fd6939SJiyong Park-  **#define : PLAT_FWU_MAX_SIMULTANEOUS_IMAGES**
372*54fd6939SJiyong Park
373*54fd6939SJiyong Park   Total number of images that can be loaded simultaneously. If the platform
374*54fd6939SJiyong Park   doesn't specify any value, it defaults to 10.
375*54fd6939SJiyong Park
376*54fd6939SJiyong ParkIf a SCP_BL2 image is supported by the platform, the following constants must
377*54fd6939SJiyong Parkalso be defined:
378*54fd6939SJiyong Park
379*54fd6939SJiyong Park-  **#define : SCP_BL2_IMAGE_ID**
380*54fd6939SJiyong Park
381*54fd6939SJiyong Park   SCP_BL2 image identifier, used by BL2 to load SCP_BL2 into secure memory
382*54fd6939SJiyong Park   from platform storage before being transferred to the SCP.
383*54fd6939SJiyong Park
384*54fd6939SJiyong Park-  **#define : SCP_FW_KEY_CERT_ID**
385*54fd6939SJiyong Park
386*54fd6939SJiyong Park   SCP_BL2 key certificate identifier, used by BL2 to load the SCP_BL2 key
387*54fd6939SJiyong Park   certificate (mandatory when Trusted Board Boot is enabled).
388*54fd6939SJiyong Park
389*54fd6939SJiyong Park-  **#define : SCP_FW_CONTENT_CERT_ID**
390*54fd6939SJiyong Park
391*54fd6939SJiyong Park   SCP_BL2 content certificate identifier, used by BL2 to load the SCP_BL2
392*54fd6939SJiyong Park   content certificate (mandatory when Trusted Board Boot is enabled).
393*54fd6939SJiyong Park
394*54fd6939SJiyong ParkIf a BL32 image is supported by the platform, the following constants must
395*54fd6939SJiyong Parkalso be defined:
396*54fd6939SJiyong Park
397*54fd6939SJiyong Park-  **#define : BL32_IMAGE_ID**
398*54fd6939SJiyong Park
399*54fd6939SJiyong Park   BL32 image identifier, used by BL2 to load BL32.
400*54fd6939SJiyong Park
401*54fd6939SJiyong Park-  **#define : TRUSTED_OS_FW_KEY_CERT_ID**
402*54fd6939SJiyong Park
403*54fd6939SJiyong Park   BL32 key certificate identifier, used by BL2 to load the BL32 key
404*54fd6939SJiyong Park   certificate (mandatory when Trusted Board Boot is enabled).
405*54fd6939SJiyong Park
406*54fd6939SJiyong Park-  **#define : TRUSTED_OS_FW_CONTENT_CERT_ID**
407*54fd6939SJiyong Park
408*54fd6939SJiyong Park   BL32 content certificate identifier, used by BL2 to load the BL32 content
409*54fd6939SJiyong Park   certificate (mandatory when Trusted Board Boot is enabled).
410*54fd6939SJiyong Park
411*54fd6939SJiyong Park-  **#define : BL32_BASE**
412*54fd6939SJiyong Park
413*54fd6939SJiyong Park   Defines the base address in secure memory where BL2 loads the BL32 binary
414*54fd6939SJiyong Park   image. Must be aligned on a page-size boundary.
415*54fd6939SJiyong Park
416*54fd6939SJiyong Park-  **#define : BL32_LIMIT**
417*54fd6939SJiyong Park
418*54fd6939SJiyong Park   Defines the maximum address that the BL32 image can occupy.
419*54fd6939SJiyong Park
420*54fd6939SJiyong ParkIf the Test Secure-EL1 Payload (TSP) instantiation of BL32 is supported by the
421*54fd6939SJiyong Parkplatform, the following constants must also be defined:
422*54fd6939SJiyong Park
423*54fd6939SJiyong Park-  **#define : TSP_SEC_MEM_BASE**
424*54fd6939SJiyong Park
425*54fd6939SJiyong Park   Defines the base address of the secure memory used by the TSP image on the
426*54fd6939SJiyong Park   platform. This must be at the same address or below ``BL32_BASE``.
427*54fd6939SJiyong Park
428*54fd6939SJiyong Park-  **#define : TSP_SEC_MEM_SIZE**
429*54fd6939SJiyong Park
430*54fd6939SJiyong Park   Defines the size of the secure memory used by the BL32 image on the
431*54fd6939SJiyong Park   platform. ``TSP_SEC_MEM_BASE`` and ``TSP_SEC_MEM_SIZE`` must fully
432*54fd6939SJiyong Park   accommodate the memory required by the BL32 image, defined by ``BL32_BASE``
433*54fd6939SJiyong Park   and ``BL32_LIMIT``.
434*54fd6939SJiyong Park
435*54fd6939SJiyong Park-  **#define : TSP_IRQ_SEC_PHY_TIMER**
436*54fd6939SJiyong Park
437*54fd6939SJiyong Park   Defines the ID of the secure physical generic timer interrupt used by the
438*54fd6939SJiyong Park   TSP's interrupt handling code.
439*54fd6939SJiyong Park
440*54fd6939SJiyong ParkIf the platform port uses the translation table library code, the following
441*54fd6939SJiyong Parkconstants must also be defined:
442*54fd6939SJiyong Park
443*54fd6939SJiyong Park-  **#define : PLAT_XLAT_TABLES_DYNAMIC**
444*54fd6939SJiyong Park
445*54fd6939SJiyong Park   Optional flag that can be set per-image to enable the dynamic allocation of
446*54fd6939SJiyong Park   regions even when the MMU is enabled. If not defined, only static
447*54fd6939SJiyong Park   functionality will be available, if defined and set to 1 it will also
448*54fd6939SJiyong Park   include the dynamic functionality.
449*54fd6939SJiyong Park
450*54fd6939SJiyong Park-  **#define : MAX_XLAT_TABLES**
451*54fd6939SJiyong Park
452*54fd6939SJiyong Park   Defines the maximum number of translation tables that are allocated by the
453*54fd6939SJiyong Park   translation table library code. To minimize the amount of runtime memory
454*54fd6939SJiyong Park   used, choose the smallest value needed to map the required virtual addresses
455*54fd6939SJiyong Park   for each BL stage. If ``PLAT_XLAT_TABLES_DYNAMIC`` flag is enabled for a BL
456*54fd6939SJiyong Park   image, ``MAX_XLAT_TABLES`` must be defined to accommodate the dynamic regions
457*54fd6939SJiyong Park   as well.
458*54fd6939SJiyong Park
459*54fd6939SJiyong Park-  **#define : MAX_MMAP_REGIONS**
460*54fd6939SJiyong Park
461*54fd6939SJiyong Park   Defines the maximum number of regions that are allocated by the translation
462*54fd6939SJiyong Park   table library code. A region consists of physical base address, virtual base
463*54fd6939SJiyong Park   address, size and attributes (Device/Memory, RO/RW, Secure/Non-Secure), as
464*54fd6939SJiyong Park   defined in the ``mmap_region_t`` structure. The platform defines the regions
465*54fd6939SJiyong Park   that should be mapped. Then, the translation table library will create the
466*54fd6939SJiyong Park   corresponding tables and descriptors at runtime. To minimize the amount of
467*54fd6939SJiyong Park   runtime memory used, choose the smallest value needed to register the
468*54fd6939SJiyong Park   required regions for each BL stage. If ``PLAT_XLAT_TABLES_DYNAMIC`` flag is
469*54fd6939SJiyong Park   enabled for a BL image, ``MAX_MMAP_REGIONS`` must be defined to accommodate
470*54fd6939SJiyong Park   the dynamic regions as well.
471*54fd6939SJiyong Park
472*54fd6939SJiyong Park-  **#define : PLAT_VIRT_ADDR_SPACE_SIZE**
473*54fd6939SJiyong Park
474*54fd6939SJiyong Park   Defines the total size of the virtual address space in bytes. For example,
475*54fd6939SJiyong Park   for a 32 bit virtual address space, this value should be ``(1ULL << 32)``.
476*54fd6939SJiyong Park
477*54fd6939SJiyong Park-  **#define : PLAT_PHY_ADDR_SPACE_SIZE**
478*54fd6939SJiyong Park
479*54fd6939SJiyong Park   Defines the total size of the physical address space in bytes. For example,
480*54fd6939SJiyong Park   for a 32 bit physical address space, this value should be ``(1ULL << 32)``.
481*54fd6939SJiyong Park
482*54fd6939SJiyong ParkIf the platform port uses the IO storage framework, the following constants
483*54fd6939SJiyong Parkmust also be defined:
484*54fd6939SJiyong Park
485*54fd6939SJiyong Park-  **#define : MAX_IO_DEVICES**
486*54fd6939SJiyong Park
487*54fd6939SJiyong Park   Defines the maximum number of registered IO devices. Attempting to register
488*54fd6939SJiyong Park   more devices than this value using ``io_register_device()`` will fail with
489*54fd6939SJiyong Park   -ENOMEM.
490*54fd6939SJiyong Park
491*54fd6939SJiyong Park-  **#define : MAX_IO_HANDLES**
492*54fd6939SJiyong Park
493*54fd6939SJiyong Park   Defines the maximum number of open IO handles. Attempting to open more IO
494*54fd6939SJiyong Park   entities than this value using ``io_open()`` will fail with -ENOMEM.
495*54fd6939SJiyong Park
496*54fd6939SJiyong Park-  **#define : MAX_IO_BLOCK_DEVICES**
497*54fd6939SJiyong Park
498*54fd6939SJiyong Park   Defines the maximum number of registered IO block devices. Attempting to
499*54fd6939SJiyong Park   register more devices this value using ``io_dev_open()`` will fail
500*54fd6939SJiyong Park   with -ENOMEM. MAX_IO_BLOCK_DEVICES should be less than MAX_IO_DEVICES.
501*54fd6939SJiyong Park   With this macro, multiple block devices could be supported at the same
502*54fd6939SJiyong Park   time.
503*54fd6939SJiyong Park
504*54fd6939SJiyong ParkIf the platform needs to allocate data within the per-cpu data framework in
505*54fd6939SJiyong ParkBL31, it should define the following macro. Currently this is only required if
506*54fd6939SJiyong Parkthe platform decides not to use the coherent memory section by undefining the
507*54fd6939SJiyong Park``USE_COHERENT_MEM`` build flag. In this case, the framework allocates the
508*54fd6939SJiyong Parkrequired memory within the the per-cpu data to minimize wastage.
509*54fd6939SJiyong Park
510*54fd6939SJiyong Park-  **#define : PLAT_PCPU_DATA_SIZE**
511*54fd6939SJiyong Park
512*54fd6939SJiyong Park   Defines the memory (in bytes) to be reserved within the per-cpu data
513*54fd6939SJiyong Park   structure for use by the platform layer.
514*54fd6939SJiyong Park
515*54fd6939SJiyong ParkThe following constants are optional. They should be defined when the platform
516*54fd6939SJiyong Parkmemory layout implies some image overlaying like in Arm standard platforms.
517*54fd6939SJiyong Park
518*54fd6939SJiyong Park-  **#define : BL31_PROGBITS_LIMIT**
519*54fd6939SJiyong Park
520*54fd6939SJiyong Park   Defines the maximum address in secure RAM that the BL31's progbits sections
521*54fd6939SJiyong Park   can occupy.
522*54fd6939SJiyong Park
523*54fd6939SJiyong Park-  **#define : TSP_PROGBITS_LIMIT**
524*54fd6939SJiyong Park
525*54fd6939SJiyong Park   Defines the maximum address that the TSP's progbits sections can occupy.
526*54fd6939SJiyong Park
527*54fd6939SJiyong ParkIf the platform port uses the PL061 GPIO driver, the following constant may
528*54fd6939SJiyong Parkoptionally be defined:
529*54fd6939SJiyong Park
530*54fd6939SJiyong Park-  **PLAT_PL061_MAX_GPIOS**
531*54fd6939SJiyong Park   Maximum number of GPIOs required by the platform. This allows control how
532*54fd6939SJiyong Park   much memory is allocated for PL061 GPIO controllers. The default value is
533*54fd6939SJiyong Park
534*54fd6939SJiyong Park   #. $(eval $(call add_define,PLAT_PL061_MAX_GPIOS))
535*54fd6939SJiyong Park
536*54fd6939SJiyong ParkIf the platform port uses the partition driver, the following constant may
537*54fd6939SJiyong Parkoptionally be defined:
538*54fd6939SJiyong Park
539*54fd6939SJiyong Park-  **PLAT_PARTITION_MAX_ENTRIES**
540*54fd6939SJiyong Park   Maximum number of partition entries required by the platform. This allows
541*54fd6939SJiyong Park   control how much memory is allocated for partition entries. The default
542*54fd6939SJiyong Park   value is 128.
543*54fd6939SJiyong Park   For example, define the build flag in ``platform.mk``:
544*54fd6939SJiyong Park   PLAT_PARTITION_MAX_ENTRIES := 12
545*54fd6939SJiyong Park   $(eval $(call add_define,PLAT_PARTITION_MAX_ENTRIES))
546*54fd6939SJiyong Park
547*54fd6939SJiyong Park-  **PLAT_PARTITION_BLOCK_SIZE**
548*54fd6939SJiyong Park   The size of partition block. It could be either 512 bytes or 4096 bytes.
549*54fd6939SJiyong Park   The default value is 512.
550*54fd6939SJiyong Park   For example, define the build flag in ``platform.mk``:
551*54fd6939SJiyong Park   PLAT_PARTITION_BLOCK_SIZE := 4096
552*54fd6939SJiyong Park   $(eval $(call add_define,PLAT_PARTITION_BLOCK_SIZE))
553*54fd6939SJiyong Park
554*54fd6939SJiyong ParkThe following constant is optional. It should be defined to override the default
555*54fd6939SJiyong Parkbehaviour of the ``assert()`` function (for example, to save memory).
556*54fd6939SJiyong Park
557*54fd6939SJiyong Park-  **PLAT_LOG_LEVEL_ASSERT**
558*54fd6939SJiyong Park   If ``PLAT_LOG_LEVEL_ASSERT`` is higher or equal than ``LOG_LEVEL_VERBOSE``,
559*54fd6939SJiyong Park   ``assert()`` prints the name of the file, the line number and the asserted
560*54fd6939SJiyong Park   expression. Else if it is higher than ``LOG_LEVEL_INFO``, it prints the file
561*54fd6939SJiyong Park   name and the line number. Else if it is lower than ``LOG_LEVEL_INFO``, it
562*54fd6939SJiyong Park   doesn't print anything to the console. If ``PLAT_LOG_LEVEL_ASSERT`` isn't
563*54fd6939SJiyong Park   defined, it defaults to ``LOG_LEVEL``.
564*54fd6939SJiyong Park
565*54fd6939SJiyong ParkFile : plat_macros.S [mandatory]
566*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
567*54fd6939SJiyong Park
568*54fd6939SJiyong ParkEach platform must ensure a file of this name is in the system include path with
569*54fd6939SJiyong Parkthe following macro defined. In the Arm development platforms, this file is
570*54fd6939SJiyong Parkfound in ``plat/arm/board/<plat_name>/include/plat_macros.S``.
571*54fd6939SJiyong Park
572*54fd6939SJiyong Park-  **Macro : plat_crash_print_regs**
573*54fd6939SJiyong Park
574*54fd6939SJiyong Park   This macro allows the crash reporting routine to print relevant platform
575*54fd6939SJiyong Park   registers in case of an unhandled exception in BL31. This aids in debugging
576*54fd6939SJiyong Park   and this macro can be defined to be empty in case register reporting is not
577*54fd6939SJiyong Park   desired.
578*54fd6939SJiyong Park
579*54fd6939SJiyong Park   For instance, GIC or interconnect registers may be helpful for
580*54fd6939SJiyong Park   troubleshooting.
581*54fd6939SJiyong Park
582*54fd6939SJiyong ParkHandling Reset
583*54fd6939SJiyong Park--------------
584*54fd6939SJiyong Park
585*54fd6939SJiyong ParkBL1 by default implements the reset vector where execution starts from a cold
586*54fd6939SJiyong Parkor warm boot. BL31 can be optionally set as a reset vector using the
587*54fd6939SJiyong Park``RESET_TO_BL31`` make variable.
588*54fd6939SJiyong Park
589*54fd6939SJiyong ParkFor each CPU, the reset vector code is responsible for the following tasks:
590*54fd6939SJiyong Park
591*54fd6939SJiyong Park#. Distinguishing between a cold boot and a warm boot.
592*54fd6939SJiyong Park
593*54fd6939SJiyong Park#. In the case of a cold boot and the CPU being a secondary CPU, ensuring that
594*54fd6939SJiyong Park   the CPU is placed in a platform-specific state until the primary CPU
595*54fd6939SJiyong Park   performs the necessary steps to remove it from this state.
596*54fd6939SJiyong Park
597*54fd6939SJiyong Park#. In the case of a warm boot, ensuring that the CPU jumps to a platform-
598*54fd6939SJiyong Park   specific address in the BL31 image in the same processor mode as it was
599*54fd6939SJiyong Park   when released from reset.
600*54fd6939SJiyong Park
601*54fd6939SJiyong ParkThe following functions need to be implemented by the platform port to enable
602*54fd6939SJiyong Parkreset vector code to perform the above tasks.
603*54fd6939SJiyong Park
604*54fd6939SJiyong ParkFunction : plat_get_my_entrypoint() [mandatory when PROGRAMMABLE_RESET_ADDRESS == 0]
605*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
606*54fd6939SJiyong Park
607*54fd6939SJiyong Park::
608*54fd6939SJiyong Park
609*54fd6939SJiyong Park    Argument : void
610*54fd6939SJiyong Park    Return   : uintptr_t
611*54fd6939SJiyong Park
612*54fd6939SJiyong ParkThis function is called with the MMU and caches disabled
613*54fd6939SJiyong Park(``SCTLR_EL3.M`` = 0 and ``SCTLR_EL3.C`` = 0). The function is responsible for
614*54fd6939SJiyong Parkdistinguishing between a warm and cold reset for the current CPU using
615*54fd6939SJiyong Parkplatform-specific means. If it's a warm reset, then it returns the warm
616*54fd6939SJiyong Parkreset entrypoint point provided to ``plat_setup_psci_ops()`` during
617*54fd6939SJiyong ParkBL31 initialization. If it's a cold reset then this function must return zero.
618*54fd6939SJiyong Park
619*54fd6939SJiyong ParkThis function does not follow the Procedure Call Standard used by the
620*54fd6939SJiyong ParkApplication Binary Interface for the Arm 64-bit architecture. The caller should
621*54fd6939SJiyong Parknot assume that callee saved registers are preserved across a call to this
622*54fd6939SJiyong Parkfunction.
623*54fd6939SJiyong Park
624*54fd6939SJiyong ParkThis function fulfills requirement 1 and 3 listed above.
625*54fd6939SJiyong Park
626*54fd6939SJiyong ParkNote that for platforms that support programming the reset address, it is
627*54fd6939SJiyong Parkexpected that a CPU will start executing code directly at the right address,
628*54fd6939SJiyong Parkboth on a cold and warm reset. In this case, there is no need to identify the
629*54fd6939SJiyong Parktype of reset nor to query the warm reset entrypoint. Therefore, implementing
630*54fd6939SJiyong Parkthis function is not required on such platforms.
631*54fd6939SJiyong Park
632*54fd6939SJiyong ParkFunction : plat_secondary_cold_boot_setup() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
633*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
634*54fd6939SJiyong Park
635*54fd6939SJiyong Park::
636*54fd6939SJiyong Park
637*54fd6939SJiyong Park    Argument : void
638*54fd6939SJiyong Park
639*54fd6939SJiyong ParkThis function is called with the MMU and data caches disabled. It is responsible
640*54fd6939SJiyong Parkfor placing the executing secondary CPU in a platform-specific state until the
641*54fd6939SJiyong Parkprimary CPU performs the necessary actions to bring it out of that state and
642*54fd6939SJiyong Parkallow entry into the OS. This function must not return.
643*54fd6939SJiyong Park
644*54fd6939SJiyong ParkIn the Arm FVP port, when using the normal boot flow, each secondary CPU powers
645*54fd6939SJiyong Parkitself off. The primary CPU is responsible for powering up the secondary CPUs
646*54fd6939SJiyong Parkwhen normal world software requires them. When booting an EL3 payload instead,
647*54fd6939SJiyong Parkthey stay powered on and are put in a holding pen until their mailbox gets
648*54fd6939SJiyong Parkpopulated.
649*54fd6939SJiyong Park
650*54fd6939SJiyong ParkThis function fulfills requirement 2 above.
651*54fd6939SJiyong Park
652*54fd6939SJiyong ParkNote that for platforms that can't release secondary CPUs out of reset, only the
653*54fd6939SJiyong Parkprimary CPU will execute the cold boot code. Therefore, implementing this
654*54fd6939SJiyong Parkfunction is not required on such platforms.
655*54fd6939SJiyong Park
656*54fd6939SJiyong ParkFunction : plat_is_my_cpu_primary() [mandatory when COLD_BOOT_SINGLE_CPU == 0]
657*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
658*54fd6939SJiyong Park
659*54fd6939SJiyong Park::
660*54fd6939SJiyong Park
661*54fd6939SJiyong Park    Argument : void
662*54fd6939SJiyong Park    Return   : unsigned int
663*54fd6939SJiyong Park
664*54fd6939SJiyong ParkThis function identifies whether the current CPU is the primary CPU or a
665*54fd6939SJiyong Parksecondary CPU. A return value of zero indicates that the CPU is not the
666*54fd6939SJiyong Parkprimary CPU, while a non-zero return value indicates that the CPU is the
667*54fd6939SJiyong Parkprimary CPU.
668*54fd6939SJiyong Park
669*54fd6939SJiyong ParkNote that for platforms that can't release secondary CPUs out of reset, only the
670*54fd6939SJiyong Parkprimary CPU will execute the cold boot code. Therefore, there is no need to
671*54fd6939SJiyong Parkdistinguish between primary and secondary CPUs and implementing this function is
672*54fd6939SJiyong Parknot required.
673*54fd6939SJiyong Park
674*54fd6939SJiyong ParkFunction : platform_mem_init() [mandatory]
675*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
676*54fd6939SJiyong Park
677*54fd6939SJiyong Park::
678*54fd6939SJiyong Park
679*54fd6939SJiyong Park    Argument : void
680*54fd6939SJiyong Park    Return   : void
681*54fd6939SJiyong Park
682*54fd6939SJiyong ParkThis function is called before any access to data is made by the firmware, in
683*54fd6939SJiyong Parkorder to carry out any essential memory initialization.
684*54fd6939SJiyong Park
685*54fd6939SJiyong ParkFunction: plat_get_rotpk_info()
686*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
687*54fd6939SJiyong Park
688*54fd6939SJiyong Park::
689*54fd6939SJiyong Park
690*54fd6939SJiyong Park    Argument : void *, void **, unsigned int *, unsigned int *
691*54fd6939SJiyong Park    Return   : int
692*54fd6939SJiyong Park
693*54fd6939SJiyong ParkThis function is mandatory when Trusted Board Boot is enabled. It returns a
694*54fd6939SJiyong Parkpointer to the ROTPK stored in the platform (or a hash of it) and its length.
695*54fd6939SJiyong ParkThe ROTPK must be encoded in DER format according to the following ASN.1
696*54fd6939SJiyong Parkstructure:
697*54fd6939SJiyong Park
698*54fd6939SJiyong Park::
699*54fd6939SJiyong Park
700*54fd6939SJiyong Park    AlgorithmIdentifier  ::=  SEQUENCE  {
701*54fd6939SJiyong Park        algorithm         OBJECT IDENTIFIER,
702*54fd6939SJiyong Park        parameters        ANY DEFINED BY algorithm OPTIONAL
703*54fd6939SJiyong Park    }
704*54fd6939SJiyong Park
705*54fd6939SJiyong Park    SubjectPublicKeyInfo  ::=  SEQUENCE  {
706*54fd6939SJiyong Park        algorithm         AlgorithmIdentifier,
707*54fd6939SJiyong Park        subjectPublicKey  BIT STRING
708*54fd6939SJiyong Park    }
709*54fd6939SJiyong Park
710*54fd6939SJiyong ParkIn case the function returns a hash of the key:
711*54fd6939SJiyong Park
712*54fd6939SJiyong Park::
713*54fd6939SJiyong Park
714*54fd6939SJiyong Park    DigestInfo ::= SEQUENCE {
715*54fd6939SJiyong Park        digestAlgorithm   AlgorithmIdentifier,
716*54fd6939SJiyong Park        digest            OCTET STRING
717*54fd6939SJiyong Park    }
718*54fd6939SJiyong Park
719*54fd6939SJiyong ParkThe function returns 0 on success. Any other value is treated as error by the
720*54fd6939SJiyong ParkTrusted Board Boot. The function also reports extra information related
721*54fd6939SJiyong Parkto the ROTPK in the flags parameter:
722*54fd6939SJiyong Park
723*54fd6939SJiyong Park::
724*54fd6939SJiyong Park
725*54fd6939SJiyong Park    ROTPK_IS_HASH      : Indicates that the ROTPK returned by the platform is a
726*54fd6939SJiyong Park                         hash.
727*54fd6939SJiyong Park    ROTPK_NOT_DEPLOYED : This allows the platform to skip certificate ROTPK
728*54fd6939SJiyong Park                         verification while the platform ROTPK is not deployed.
729*54fd6939SJiyong Park                         When this flag is set, the function does not need to
730*54fd6939SJiyong Park                         return a platform ROTPK, and the authentication
731*54fd6939SJiyong Park                         framework uses the ROTPK in the certificate without
732*54fd6939SJiyong Park                         verifying it against the platform value. This flag
733*54fd6939SJiyong Park                         must not be used in a deployed production environment.
734*54fd6939SJiyong Park
735*54fd6939SJiyong ParkFunction: plat_get_nv_ctr()
736*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~
737*54fd6939SJiyong Park
738*54fd6939SJiyong Park::
739*54fd6939SJiyong Park
740*54fd6939SJiyong Park    Argument : void *, unsigned int *
741*54fd6939SJiyong Park    Return   : int
742*54fd6939SJiyong Park
743*54fd6939SJiyong ParkThis function is mandatory when Trusted Board Boot is enabled. It returns the
744*54fd6939SJiyong Parknon-volatile counter value stored in the platform in the second argument. The
745*54fd6939SJiyong Parkcookie in the first argument may be used to select the counter in case the
746*54fd6939SJiyong Parkplatform provides more than one (for example, on platforms that use the default
747*54fd6939SJiyong ParkTBBR CoT, the cookie will correspond to the OID values defined in
748*54fd6939SJiyong ParkTRUSTED_FW_NVCOUNTER_OID or NON_TRUSTED_FW_NVCOUNTER_OID).
749*54fd6939SJiyong Park
750*54fd6939SJiyong ParkThe function returns 0 on success. Any other value means the counter value could
751*54fd6939SJiyong Parknot be retrieved from the platform.
752*54fd6939SJiyong Park
753*54fd6939SJiyong ParkFunction: plat_set_nv_ctr()
754*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~
755*54fd6939SJiyong Park
756*54fd6939SJiyong Park::
757*54fd6939SJiyong Park
758*54fd6939SJiyong Park    Argument : void *, unsigned int
759*54fd6939SJiyong Park    Return   : int
760*54fd6939SJiyong Park
761*54fd6939SJiyong ParkThis function is mandatory when Trusted Board Boot is enabled. It sets a new
762*54fd6939SJiyong Parkcounter value in the platform. The cookie in the first argument may be used to
763*54fd6939SJiyong Parkselect the counter (as explained in plat_get_nv_ctr()). The second argument is
764*54fd6939SJiyong Parkthe updated counter value to be written to the NV counter.
765*54fd6939SJiyong Park
766*54fd6939SJiyong ParkThe function returns 0 on success. Any other value means the counter value could
767*54fd6939SJiyong Parknot be updated.
768*54fd6939SJiyong Park
769*54fd6939SJiyong ParkFunction: plat_set_nv_ctr2()
770*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~
771*54fd6939SJiyong Park
772*54fd6939SJiyong Park::
773*54fd6939SJiyong Park
774*54fd6939SJiyong Park    Argument : void *, const auth_img_desc_t *, unsigned int
775*54fd6939SJiyong Park    Return   : int
776*54fd6939SJiyong Park
777*54fd6939SJiyong ParkThis function is optional when Trusted Board Boot is enabled. If this
778*54fd6939SJiyong Parkinterface is defined, then ``plat_set_nv_ctr()`` need not be defined. The
779*54fd6939SJiyong Parkfirst argument passed is a cookie and is typically used to
780*54fd6939SJiyong Parkdifferentiate between a Non Trusted NV Counter and a Trusted NV
781*54fd6939SJiyong ParkCounter. The second argument is a pointer to an authentication image
782*54fd6939SJiyong Parkdescriptor and may be used to decide if the counter is allowed to be
783*54fd6939SJiyong Parkupdated or not. The third argument is the updated counter value to
784*54fd6939SJiyong Parkbe written to the NV counter.
785*54fd6939SJiyong Park
786*54fd6939SJiyong ParkThe function returns 0 on success. Any other value means the counter value
787*54fd6939SJiyong Parkeither could not be updated or the authentication image descriptor indicates
788*54fd6939SJiyong Parkthat it is not allowed to be updated.
789*54fd6939SJiyong Park
790*54fd6939SJiyong ParkCommon mandatory function modifications
791*54fd6939SJiyong Park---------------------------------------
792*54fd6939SJiyong Park
793*54fd6939SJiyong ParkThe following functions are mandatory functions which need to be implemented
794*54fd6939SJiyong Parkby the platform port.
795*54fd6939SJiyong Park
796*54fd6939SJiyong ParkFunction : plat_my_core_pos()
797*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
798*54fd6939SJiyong Park
799*54fd6939SJiyong Park::
800*54fd6939SJiyong Park
801*54fd6939SJiyong Park    Argument : void
802*54fd6939SJiyong Park    Return   : unsigned int
803*54fd6939SJiyong Park
804*54fd6939SJiyong ParkThis function returns the index of the calling CPU which is used as a
805*54fd6939SJiyong ParkCPU-specific linear index into blocks of memory (for example while allocating
806*54fd6939SJiyong Parkper-CPU stacks). This function will be invoked very early in the
807*54fd6939SJiyong Parkinitialization sequence which mandates that this function should be
808*54fd6939SJiyong Parkimplemented in assembly and should not rely on the availability of a C
809*54fd6939SJiyong Parkruntime environment. This function can clobber x0 - x8 and must preserve
810*54fd6939SJiyong Parkx9 - x29.
811*54fd6939SJiyong Park
812*54fd6939SJiyong ParkThis function plays a crucial role in the power domain topology framework in
813*54fd6939SJiyong ParkPSCI and details of this can be found in
814*54fd6939SJiyong Park:ref:`PSCI Power Domain Tree Structure`.
815*54fd6939SJiyong Park
816*54fd6939SJiyong ParkFunction : plat_core_pos_by_mpidr()
817*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
818*54fd6939SJiyong Park
819*54fd6939SJiyong Park::
820*54fd6939SJiyong Park
821*54fd6939SJiyong Park    Argument : u_register_t
822*54fd6939SJiyong Park    Return   : int
823*54fd6939SJiyong Park
824*54fd6939SJiyong ParkThis function validates the ``MPIDR`` of a CPU and converts it to an index,
825*54fd6939SJiyong Parkwhich can be used as a CPU-specific linear index into blocks of memory. In
826*54fd6939SJiyong Parkcase the ``MPIDR`` is invalid, this function returns -1. This function will only
827*54fd6939SJiyong Parkbe invoked by BL31 after the power domain topology is initialized and can
828*54fd6939SJiyong Parkutilize the C runtime environment. For further details about how TF-A
829*54fd6939SJiyong Parkrepresents the power domain topology and how this relates to the linear CPU
830*54fd6939SJiyong Parkindex, please refer :ref:`PSCI Power Domain Tree Structure`.
831*54fd6939SJiyong Park
832*54fd6939SJiyong ParkFunction : plat_get_mbedtls_heap() [when TRUSTED_BOARD_BOOT == 1]
833*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
834*54fd6939SJiyong Park
835*54fd6939SJiyong Park::
836*54fd6939SJiyong Park
837*54fd6939SJiyong Park    Arguments : void **heap_addr, size_t *heap_size
838*54fd6939SJiyong Park    Return    : int
839*54fd6939SJiyong Park
840*54fd6939SJiyong ParkThis function is invoked during Mbed TLS library initialisation to get a heap,
841*54fd6939SJiyong Parkby means of a starting address and a size. This heap will then be used
842*54fd6939SJiyong Parkinternally by the Mbed TLS library. Hence, each BL stage that utilises Mbed TLS
843*54fd6939SJiyong Parkmust be able to provide a heap to it.
844*54fd6939SJiyong Park
845*54fd6939SJiyong ParkA helper function can be found in `drivers/auth/mbedtls/mbedtls_common.c` in
846*54fd6939SJiyong Parkwhich a heap is statically reserved during compile time inside every image
847*54fd6939SJiyong Park(i.e. every BL stage) that utilises Mbed TLS. In this default implementation,
848*54fd6939SJiyong Parkthe function simply returns the address and size of this "pre-allocated" heap.
849*54fd6939SJiyong ParkFor a platform to use this default implementation, only a call to the helper
850*54fd6939SJiyong Parkfrom inside plat_get_mbedtls_heap() body is enough and nothing else is needed.
851*54fd6939SJiyong Park
852*54fd6939SJiyong ParkHowever, by writting their own implementation, platforms have the potential to
853*54fd6939SJiyong Parkoptimise memory usage. For example, on some Arm platforms, the Mbed TLS heap is
854*54fd6939SJiyong Parkshared between BL1 and BL2 stages and, thus, the necessary space is not reserved
855*54fd6939SJiyong Parktwice.
856*54fd6939SJiyong Park
857*54fd6939SJiyong ParkOn success the function should return 0 and a negative error code otherwise.
858*54fd6939SJiyong Park
859*54fd6939SJiyong ParkFunction : plat_get_enc_key_info() [when FW_ENC_STATUS == 0 or 1]
860*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
861*54fd6939SJiyong Park
862*54fd6939SJiyong Park::
863*54fd6939SJiyong Park
864*54fd6939SJiyong Park    Arguments : enum fw_enc_status_t fw_enc_status, uint8_t *key,
865*54fd6939SJiyong Park                size_t *key_len, unsigned int *flags, const uint8_t *img_id,
866*54fd6939SJiyong Park                size_t img_id_len
867*54fd6939SJiyong Park    Return    : int
868*54fd6939SJiyong Park
869*54fd6939SJiyong ParkThis function provides a symmetric key (either SSK or BSSK depending on
870*54fd6939SJiyong Parkfw_enc_status) which is invoked during runtime decryption of encrypted
871*54fd6939SJiyong Parkfirmware images. `plat/common/plat_bl_common.c` provides a dummy weak
872*54fd6939SJiyong Parkimplementation for testing purposes which must be overridden by the platform
873*54fd6939SJiyong Parktrying to implement a real world firmware encryption use-case.
874*54fd6939SJiyong Park
875*54fd6939SJiyong ParkIt also allows the platform to pass symmetric key identifier rather than
876*54fd6939SJiyong Parkactual symmetric key which is useful in cases where the crypto backend provides
877*54fd6939SJiyong Parksecure storage for the symmetric key. So in this case ``ENC_KEY_IS_IDENTIFIER``
878*54fd6939SJiyong Parkflag must be set in ``flags``.
879*54fd6939SJiyong Park
880*54fd6939SJiyong ParkIn addition to above a platform may also choose to provide an image specific
881*54fd6939SJiyong Parksymmetric key/identifier using img_id.
882*54fd6939SJiyong Park
883*54fd6939SJiyong ParkOn success the function should return 0 and a negative error code otherwise.
884*54fd6939SJiyong Park
885*54fd6939SJiyong ParkNote that this API depends on ``DECRYPTION_SUPPORT`` build flag.
886*54fd6939SJiyong Park
887*54fd6939SJiyong ParkFunction : plat_fwu_set_images_source() [when PSA_FWU_SUPPORT == 1]
888*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
889*54fd6939SJiyong Park
890*54fd6939SJiyong Park::
891*54fd6939SJiyong Park
892*54fd6939SJiyong Park    Argument : struct fwu_metadata *metadata
893*54fd6939SJiyong Park    Return   : void
894*54fd6939SJiyong Park
895*54fd6939SJiyong ParkThis function is mandatory when PSA_FWU_SUPPORT is enabled.
896*54fd6939SJiyong ParkIt provides a means to retrieve image specification (offset in
897*54fd6939SJiyong Parknon-volatile storage and length) of active/updated images using the passed
898*54fd6939SJiyong ParkFWU metadata, and update I/O policies of active/updated images using retrieved
899*54fd6939SJiyong Parkimage specification information.
900*54fd6939SJiyong ParkFurther I/O layer operations such as I/O open, I/O read, etc. on these
901*54fd6939SJiyong Parkimages rely on this function call.
902*54fd6939SJiyong Park
903*54fd6939SJiyong ParkIn Arm platforms, this function is used to set an I/O policy of the FIP image,
904*54fd6939SJiyong Parkcontainer of all active/updated secure and non-secure images.
905*54fd6939SJiyong Park
906*54fd6939SJiyong ParkFunction : plat_fwu_set_metadata_image_source() [when PSA_FWU_SUPPORT == 1]
907*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
908*54fd6939SJiyong Park
909*54fd6939SJiyong Park::
910*54fd6939SJiyong Park
911*54fd6939SJiyong Park    Argument : unsigned int image_id, uintptr_t *dev_handle,
912*54fd6939SJiyong Park               uintptr_t *image_spec
913*54fd6939SJiyong Park    Return   : int
914*54fd6939SJiyong Park
915*54fd6939SJiyong ParkThis function is mandatory when PSA_FWU_SUPPORT is enabled. It is
916*54fd6939SJiyong Parkresponsible for setting up the platform I/O policy of the requested metadata
917*54fd6939SJiyong Parkimage (either FWU_METADATA_IMAGE_ID or BKUP_FWU_METADATA_IMAGE_ID) that will
918*54fd6939SJiyong Parkbe used to load this image from the platform's non-volatile storage.
919*54fd6939SJiyong Park
920*54fd6939SJiyong ParkFWU metadata can not be always stored as a raw image in non-volatile storage
921*54fd6939SJiyong Parkto define its image specification (offset in non-volatile storage and length)
922*54fd6939SJiyong Parkstatically in I/O policy.
923*54fd6939SJiyong ParkFor example, the FWU metadata image is stored as a partition inside the GUID
924*54fd6939SJiyong Parkpartition table image. Its specification is defined in the partition table
925*54fd6939SJiyong Parkthat needs to be parsed dynamically.
926*54fd6939SJiyong ParkThis function provides a means to retrieve such dynamic information to set
927*54fd6939SJiyong Parkthe I/O policy of the FWU metadata image.
928*54fd6939SJiyong ParkFurther I/O layer operations such as I/O open, I/O read, etc. on FWU metadata
929*54fd6939SJiyong Parkimage relies on this function call.
930*54fd6939SJiyong Park
931*54fd6939SJiyong ParkIt returns '0' on success, otherwise a negative error value on error.
932*54fd6939SJiyong ParkAlongside, returns device handle and image specification from the I/O policy
933*54fd6939SJiyong Parkof the requested FWU metadata image.
934*54fd6939SJiyong Park
935*54fd6939SJiyong ParkCommon optional modifications
936*54fd6939SJiyong Park-----------------------------
937*54fd6939SJiyong Park
938*54fd6939SJiyong ParkThe following are helper functions implemented by the firmware that perform
939*54fd6939SJiyong Parkcommon platform-specific tasks. A platform may choose to override these
940*54fd6939SJiyong Parkdefinitions.
941*54fd6939SJiyong Park
942*54fd6939SJiyong ParkFunction : plat_set_my_stack()
943*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
944*54fd6939SJiyong Park
945*54fd6939SJiyong Park::
946*54fd6939SJiyong Park
947*54fd6939SJiyong Park    Argument : void
948*54fd6939SJiyong Park    Return   : void
949*54fd6939SJiyong Park
950*54fd6939SJiyong ParkThis function sets the current stack pointer to the normal memory stack that
951*54fd6939SJiyong Parkhas been allocated for the current CPU. For BL images that only require a
952*54fd6939SJiyong Parkstack for the primary CPU, the UP version of the function is used. The size
953*54fd6939SJiyong Parkof the stack allocated to each CPU is specified by the platform defined
954*54fd6939SJiyong Parkconstant ``PLATFORM_STACK_SIZE``.
955*54fd6939SJiyong Park
956*54fd6939SJiyong ParkCommon implementations of this function for the UP and MP BL images are
957*54fd6939SJiyong Parkprovided in ``plat/common/aarch64/platform_up_stack.S`` and
958*54fd6939SJiyong Park``plat/common/aarch64/platform_mp_stack.S``
959*54fd6939SJiyong Park
960*54fd6939SJiyong ParkFunction : plat_get_my_stack()
961*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
962*54fd6939SJiyong Park
963*54fd6939SJiyong Park::
964*54fd6939SJiyong Park
965*54fd6939SJiyong Park    Argument : void
966*54fd6939SJiyong Park    Return   : uintptr_t
967*54fd6939SJiyong Park
968*54fd6939SJiyong ParkThis function returns the base address of the normal memory stack that
969*54fd6939SJiyong Parkhas been allocated for the current CPU. For BL images that only require a
970*54fd6939SJiyong Parkstack for the primary CPU, the UP version of the function is used. The size
971*54fd6939SJiyong Parkof the stack allocated to each CPU is specified by the platform defined
972*54fd6939SJiyong Parkconstant ``PLATFORM_STACK_SIZE``.
973*54fd6939SJiyong Park
974*54fd6939SJiyong ParkCommon implementations of this function for the UP and MP BL images are
975*54fd6939SJiyong Parkprovided in ``plat/common/aarch64/platform_up_stack.S`` and
976*54fd6939SJiyong Park``plat/common/aarch64/platform_mp_stack.S``
977*54fd6939SJiyong Park
978*54fd6939SJiyong ParkFunction : plat_report_exception()
979*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
980*54fd6939SJiyong Park
981*54fd6939SJiyong Park::
982*54fd6939SJiyong Park
983*54fd6939SJiyong Park    Argument : unsigned int
984*54fd6939SJiyong Park    Return   : void
985*54fd6939SJiyong Park
986*54fd6939SJiyong ParkA platform may need to report various information about its status when an
987*54fd6939SJiyong Parkexception is taken, for example the current exception level, the CPU security
988*54fd6939SJiyong Parkstate (secure/non-secure), the exception type, and so on. This function is
989*54fd6939SJiyong Parkcalled in the following circumstances:
990*54fd6939SJiyong Park
991*54fd6939SJiyong Park-  In BL1, whenever an exception is taken.
992*54fd6939SJiyong Park-  In BL2, whenever an exception is taken.
993*54fd6939SJiyong Park
994*54fd6939SJiyong ParkThe default implementation doesn't do anything, to avoid making assumptions
995*54fd6939SJiyong Parkabout the way the platform displays its status information.
996*54fd6939SJiyong Park
997*54fd6939SJiyong ParkFor AArch64, this function receives the exception type as its argument.
998*54fd6939SJiyong ParkPossible values for exceptions types are listed in the
999*54fd6939SJiyong Park``include/common/bl_common.h`` header file. Note that these constants are not
1000*54fd6939SJiyong Parkrelated to any architectural exception code; they are just a TF-A convention.
1001*54fd6939SJiyong Park
1002*54fd6939SJiyong ParkFor AArch32, this function receives the exception mode as its argument.
1003*54fd6939SJiyong ParkPossible values for exception modes are listed in the
1004*54fd6939SJiyong Park``include/lib/aarch32/arch.h`` header file.
1005*54fd6939SJiyong Park
1006*54fd6939SJiyong ParkFunction : plat_reset_handler()
1007*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1008*54fd6939SJiyong Park
1009*54fd6939SJiyong Park::
1010*54fd6939SJiyong Park
1011*54fd6939SJiyong Park    Argument : void
1012*54fd6939SJiyong Park    Return   : void
1013*54fd6939SJiyong Park
1014*54fd6939SJiyong ParkA platform may need to do additional initialization after reset. This function
1015*54fd6939SJiyong Parkallows the platform to do the platform specific initializations. Platform
1016*54fd6939SJiyong Parkspecific errata workarounds could also be implemented here. The API should
1017*54fd6939SJiyong Parkpreserve the values of callee saved registers x19 to x29.
1018*54fd6939SJiyong Park
1019*54fd6939SJiyong ParkThe default implementation doesn't do anything. If a platform needs to override
1020*54fd6939SJiyong Parkthe default implementation, refer to the :ref:`Firmware Design` for general
1021*54fd6939SJiyong Parkguidelines.
1022*54fd6939SJiyong Park
1023*54fd6939SJiyong ParkFunction : plat_disable_acp()
1024*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1025*54fd6939SJiyong Park
1026*54fd6939SJiyong Park::
1027*54fd6939SJiyong Park
1028*54fd6939SJiyong Park    Argument : void
1029*54fd6939SJiyong Park    Return   : void
1030*54fd6939SJiyong Park
1031*54fd6939SJiyong ParkThis API allows a platform to disable the Accelerator Coherency Port (if
1032*54fd6939SJiyong Parkpresent) during a cluster power down sequence. The default weak implementation
1033*54fd6939SJiyong Parkdoesn't do anything. Since this API is called during the power down sequence,
1034*54fd6939SJiyong Parkit has restrictions for stack usage and it can use the registers x0 - x17 as
1035*54fd6939SJiyong Parkscratch registers. It should preserve the value in x18 register as it is used
1036*54fd6939SJiyong Parkby the caller to store the return address.
1037*54fd6939SJiyong Park
1038*54fd6939SJiyong ParkFunction : plat_error_handler()
1039*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1040*54fd6939SJiyong Park
1041*54fd6939SJiyong Park::
1042*54fd6939SJiyong Park
1043*54fd6939SJiyong Park    Argument : int
1044*54fd6939SJiyong Park    Return   : void
1045*54fd6939SJiyong Park
1046*54fd6939SJiyong ParkThis API is called when the generic code encounters an error situation from
1047*54fd6939SJiyong Parkwhich it cannot continue. It allows the platform to perform error reporting or
1048*54fd6939SJiyong Parkrecovery actions (for example, reset the system). This function must not return.
1049*54fd6939SJiyong Park
1050*54fd6939SJiyong ParkThe parameter indicates the type of error using standard codes from ``errno.h``.
1051*54fd6939SJiyong ParkPossible errors reported by the generic code are:
1052*54fd6939SJiyong Park
1053*54fd6939SJiyong Park-  ``-EAUTH``: a certificate or image could not be authenticated (when Trusted
1054*54fd6939SJiyong Park   Board Boot is enabled)
1055*54fd6939SJiyong Park-  ``-ENOENT``: the requested image or certificate could not be found or an IO
1056*54fd6939SJiyong Park   error was detected
1057*54fd6939SJiyong Park-  ``-ENOMEM``: resources exhausted. TF-A does not use dynamic memory, so this
1058*54fd6939SJiyong Park   error is usually an indication of an incorrect array size
1059*54fd6939SJiyong Park
1060*54fd6939SJiyong ParkThe default implementation simply spins.
1061*54fd6939SJiyong Park
1062*54fd6939SJiyong ParkFunction : plat_panic_handler()
1063*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1064*54fd6939SJiyong Park
1065*54fd6939SJiyong Park::
1066*54fd6939SJiyong Park
1067*54fd6939SJiyong Park    Argument : void
1068*54fd6939SJiyong Park    Return   : void
1069*54fd6939SJiyong Park
1070*54fd6939SJiyong ParkThis API is called when the generic code encounters an unexpected error
1071*54fd6939SJiyong Parksituation from which it cannot recover. This function must not return,
1072*54fd6939SJiyong Parkand must be implemented in assembly because it may be called before the C
1073*54fd6939SJiyong Parkenvironment is initialized.
1074*54fd6939SJiyong Park
1075*54fd6939SJiyong Park.. note::
1076*54fd6939SJiyong Park   The address from where it was called is stored in x30 (Link Register).
1077*54fd6939SJiyong Park   The default implementation simply spins.
1078*54fd6939SJiyong Park
1079*54fd6939SJiyong ParkFunction : plat_get_bl_image_load_info()
1080*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1081*54fd6939SJiyong Park
1082*54fd6939SJiyong Park::
1083*54fd6939SJiyong Park
1084*54fd6939SJiyong Park    Argument : void
1085*54fd6939SJiyong Park    Return   : bl_load_info_t *
1086*54fd6939SJiyong Park
1087*54fd6939SJiyong ParkThis function returns pointer to the list of images that the platform has
1088*54fd6939SJiyong Parkpopulated to load. This function is invoked in BL2 to load the
1089*54fd6939SJiyong ParkBL3xx images.
1090*54fd6939SJiyong Park
1091*54fd6939SJiyong ParkFunction : plat_get_next_bl_params()
1092*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1093*54fd6939SJiyong Park
1094*54fd6939SJiyong Park::
1095*54fd6939SJiyong Park
1096*54fd6939SJiyong Park    Argument : void
1097*54fd6939SJiyong Park    Return   : bl_params_t *
1098*54fd6939SJiyong Park
1099*54fd6939SJiyong ParkThis function returns a pointer to the shared memory that the platform has
1100*54fd6939SJiyong Parkkept aside to pass TF-A related information that next BL image needs. This
1101*54fd6939SJiyong Parkfunction is invoked in BL2 to pass this information to the next BL
1102*54fd6939SJiyong Parkimage.
1103*54fd6939SJiyong Park
1104*54fd6939SJiyong ParkFunction : plat_get_stack_protector_canary()
1105*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1106*54fd6939SJiyong Park
1107*54fd6939SJiyong Park::
1108*54fd6939SJiyong Park
1109*54fd6939SJiyong Park    Argument : void
1110*54fd6939SJiyong Park    Return   : u_register_t
1111*54fd6939SJiyong Park
1112*54fd6939SJiyong ParkThis function returns a random value that is used to initialize the canary used
1113*54fd6939SJiyong Parkwhen the stack protector is enabled with ENABLE_STACK_PROTECTOR. A predictable
1114*54fd6939SJiyong Parkvalue will weaken the protection as the attacker could easily write the right
1115*54fd6939SJiyong Parkvalue as part of the attack most of the time. Therefore, it should return a
1116*54fd6939SJiyong Parktrue random number.
1117*54fd6939SJiyong Park
1118*54fd6939SJiyong Park.. warning::
1119*54fd6939SJiyong Park   For the protection to be effective, the global data need to be placed at
1120*54fd6939SJiyong Park   a lower address than the stack bases. Failure to do so would allow an
1121*54fd6939SJiyong Park   attacker to overwrite the canary as part of the stack buffer overflow attack.
1122*54fd6939SJiyong Park
1123*54fd6939SJiyong ParkFunction : plat_flush_next_bl_params()
1124*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1125*54fd6939SJiyong Park
1126*54fd6939SJiyong Park::
1127*54fd6939SJiyong Park
1128*54fd6939SJiyong Park    Argument : void
1129*54fd6939SJiyong Park    Return   : void
1130*54fd6939SJiyong Park
1131*54fd6939SJiyong ParkThis function flushes to main memory all the image params that are passed to
1132*54fd6939SJiyong Parknext image. This function is invoked in BL2 to flush this information
1133*54fd6939SJiyong Parkto the next BL image.
1134*54fd6939SJiyong Park
1135*54fd6939SJiyong ParkFunction : plat_log_get_prefix()
1136*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1137*54fd6939SJiyong Park
1138*54fd6939SJiyong Park::
1139*54fd6939SJiyong Park
1140*54fd6939SJiyong Park    Argument : unsigned int
1141*54fd6939SJiyong Park    Return   : const char *
1142*54fd6939SJiyong Park
1143*54fd6939SJiyong ParkThis function defines the prefix string corresponding to the `log_level` to be
1144*54fd6939SJiyong Parkprepended to all the log output from TF-A. The `log_level` (argument) will
1145*54fd6939SJiyong Parkcorrespond to one of the standard log levels defined in debug.h. The platform
1146*54fd6939SJiyong Parkcan override the common implementation to define a different prefix string for
1147*54fd6939SJiyong Parkthe log output. The implementation should be robust to future changes that
1148*54fd6939SJiyong Parkincrease the number of log levels.
1149*54fd6939SJiyong Park
1150*54fd6939SJiyong ParkFunction : plat_get_soc_version()
1151*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1152*54fd6939SJiyong Park
1153*54fd6939SJiyong Park::
1154*54fd6939SJiyong Park
1155*54fd6939SJiyong Park    Argument : void
1156*54fd6939SJiyong Park    Return   : int32_t
1157*54fd6939SJiyong Park
1158*54fd6939SJiyong ParkThis function returns soc version which mainly consist of below fields
1159*54fd6939SJiyong Park
1160*54fd6939SJiyong Park::
1161*54fd6939SJiyong Park
1162*54fd6939SJiyong Park    soc_version[30:24] = JEP-106 continuation code for the SiP
1163*54fd6939SJiyong Park    soc_version[23:16] = JEP-106 identification code with parity bit for the SiP
1164*54fd6939SJiyong Park    soc_version[15:0]  = Implementation defined SoC ID
1165*54fd6939SJiyong Park
1166*54fd6939SJiyong ParkFunction : plat_get_soc_revision()
1167*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1168*54fd6939SJiyong Park
1169*54fd6939SJiyong Park::
1170*54fd6939SJiyong Park
1171*54fd6939SJiyong Park    Argument : void
1172*54fd6939SJiyong Park    Return   : int32_t
1173*54fd6939SJiyong Park
1174*54fd6939SJiyong ParkThis function returns soc revision in below format
1175*54fd6939SJiyong Park
1176*54fd6939SJiyong Park::
1177*54fd6939SJiyong Park
1178*54fd6939SJiyong Park    soc_revision[0:30] = SOC revision of specific SOC
1179*54fd6939SJiyong Park
1180*54fd6939SJiyong ParkFunction : plat_is_smccc_feature_available()
1181*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1182*54fd6939SJiyong Park
1183*54fd6939SJiyong Park::
1184*54fd6939SJiyong Park
1185*54fd6939SJiyong Park    Argument : u_register_t
1186*54fd6939SJiyong Park    Return   : int32_t
1187*54fd6939SJiyong Park
1188*54fd6939SJiyong ParkThis function returns SMC_ARCH_CALL_SUCCESS if the platform supports
1189*54fd6939SJiyong Parkthe SMCCC function specified in the argument; otherwise returns
1190*54fd6939SJiyong ParkSMC_ARCH_CALL_NOT_SUPPORTED.
1191*54fd6939SJiyong Park
1192*54fd6939SJiyong ParkFunction : plat_mboot_measure_image()
1193*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1194*54fd6939SJiyong Park
1195*54fd6939SJiyong Park::
1196*54fd6939SJiyong Park
1197*54fd6939SJiyong Park    Argument : unsigned int, image_info_t *
1198*54fd6939SJiyong Park    Return   : void
1199*54fd6939SJiyong Park
1200*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is enabled:
1201*54fd6939SJiyong Park
1202*54fd6939SJiyong Park-  This function measures the given image and records its measurement using
1203*54fd6939SJiyong Park   the measured boot backend driver.
1204*54fd6939SJiyong Park-  On the Arm FVP port, this function measures the given image using its
1205*54fd6939SJiyong Park   passed id and information and then records that measurement in the
1206*54fd6939SJiyong Park   Event Log buffer.
1207*54fd6939SJiyong Park-  This function must return 0 on success, a negative error code otherwise.
1208*54fd6939SJiyong Park
1209*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is disabled, this function doesn't do anything.
1210*54fd6939SJiyong Park
1211*54fd6939SJiyong ParkModifications specific to a Boot Loader stage
1212*54fd6939SJiyong Park---------------------------------------------
1213*54fd6939SJiyong Park
1214*54fd6939SJiyong ParkBoot Loader Stage 1 (BL1)
1215*54fd6939SJiyong Park-------------------------
1216*54fd6939SJiyong Park
1217*54fd6939SJiyong ParkBL1 implements the reset vector where execution starts from after a cold or
1218*54fd6939SJiyong Parkwarm boot. For each CPU, BL1 is responsible for the following tasks:
1219*54fd6939SJiyong Park
1220*54fd6939SJiyong Park#. Handling the reset as described in section 2.2
1221*54fd6939SJiyong Park
1222*54fd6939SJiyong Park#. In the case of a cold boot and the CPU being the primary CPU, ensuring that
1223*54fd6939SJiyong Park   only this CPU executes the remaining BL1 code, including loading and passing
1224*54fd6939SJiyong Park   control to the BL2 stage.
1225*54fd6939SJiyong Park
1226*54fd6939SJiyong Park#. Identifying and starting the Firmware Update process (if required).
1227*54fd6939SJiyong Park
1228*54fd6939SJiyong Park#. Loading the BL2 image from non-volatile storage into secure memory at the
1229*54fd6939SJiyong Park   address specified by the platform defined constant ``BL2_BASE``.
1230*54fd6939SJiyong Park
1231*54fd6939SJiyong Park#. Populating a ``meminfo`` structure with the following information in memory,
1232*54fd6939SJiyong Park   accessible by BL2 immediately upon entry.
1233*54fd6939SJiyong Park
1234*54fd6939SJiyong Park   ::
1235*54fd6939SJiyong Park
1236*54fd6939SJiyong Park       meminfo.total_base = Base address of secure RAM visible to BL2
1237*54fd6939SJiyong Park       meminfo.total_size = Size of secure RAM visible to BL2
1238*54fd6939SJiyong Park
1239*54fd6939SJiyong Park   By default, BL1 places this ``meminfo`` structure at the end of secure
1240*54fd6939SJiyong Park   memory visible to BL2.
1241*54fd6939SJiyong Park
1242*54fd6939SJiyong Park   It is possible for the platform to decide where it wants to place the
1243*54fd6939SJiyong Park   ``meminfo`` structure for BL2 or restrict the amount of memory visible to
1244*54fd6939SJiyong Park   BL2 by overriding the weak default implementation of
1245*54fd6939SJiyong Park   ``bl1_plat_handle_post_image_load`` API.
1246*54fd6939SJiyong Park
1247*54fd6939SJiyong ParkThe following functions need to be implemented by the platform port to enable
1248*54fd6939SJiyong ParkBL1 to perform the above tasks.
1249*54fd6939SJiyong Park
1250*54fd6939SJiyong ParkFunction : bl1_early_platform_setup() [mandatory]
1251*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1252*54fd6939SJiyong Park
1253*54fd6939SJiyong Park::
1254*54fd6939SJiyong Park
1255*54fd6939SJiyong Park    Argument : void
1256*54fd6939SJiyong Park    Return   : void
1257*54fd6939SJiyong Park
1258*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1259*54fd6939SJiyong Parkby the primary CPU.
1260*54fd6939SJiyong Park
1261*54fd6939SJiyong ParkOn Arm standard platforms, this function:
1262*54fd6939SJiyong Park
1263*54fd6939SJiyong Park-  Enables a secure instance of SP805 to act as the Trusted Watchdog.
1264*54fd6939SJiyong Park
1265*54fd6939SJiyong Park-  Initializes a UART (PL011 console), which enables access to the ``printf``
1266*54fd6939SJiyong Park   family of functions in BL1.
1267*54fd6939SJiyong Park
1268*54fd6939SJiyong Park-  Enables issuing of snoop and DVM (Distributed Virtual Memory) requests to
1269*54fd6939SJiyong Park   the CCI slave interface corresponding to the cluster that includes the
1270*54fd6939SJiyong Park   primary CPU.
1271*54fd6939SJiyong Park
1272*54fd6939SJiyong ParkFunction : bl1_plat_arch_setup() [mandatory]
1273*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1274*54fd6939SJiyong Park
1275*54fd6939SJiyong Park::
1276*54fd6939SJiyong Park
1277*54fd6939SJiyong Park    Argument : void
1278*54fd6939SJiyong Park    Return   : void
1279*54fd6939SJiyong Park
1280*54fd6939SJiyong ParkThis function performs any platform-specific and architectural setup that the
1281*54fd6939SJiyong Parkplatform requires. Platform-specific setup might include configuration of
1282*54fd6939SJiyong Parkmemory controllers and the interconnect.
1283*54fd6939SJiyong Park
1284*54fd6939SJiyong ParkIn Arm standard platforms, this function enables the MMU.
1285*54fd6939SJiyong Park
1286*54fd6939SJiyong ParkThis function helps fulfill requirement 2 above.
1287*54fd6939SJiyong Park
1288*54fd6939SJiyong ParkFunction : bl1_platform_setup() [mandatory]
1289*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1290*54fd6939SJiyong Park
1291*54fd6939SJiyong Park::
1292*54fd6939SJiyong Park
1293*54fd6939SJiyong Park    Argument : void
1294*54fd6939SJiyong Park    Return   : void
1295*54fd6939SJiyong Park
1296*54fd6939SJiyong ParkThis function executes with the MMU and data caches enabled. It is responsible
1297*54fd6939SJiyong Parkfor performing any remaining platform-specific setup that can occur after the
1298*54fd6939SJiyong ParkMMU and data cache have been enabled.
1299*54fd6939SJiyong Park
1300*54fd6939SJiyong Parkif support for multiple boot sources is required, it initializes the boot
1301*54fd6939SJiyong Parksequence used by plat_try_next_boot_source().
1302*54fd6939SJiyong Park
1303*54fd6939SJiyong ParkIn Arm standard platforms, this function initializes the storage abstraction
1304*54fd6939SJiyong Parklayer used to load the next bootloader image.
1305*54fd6939SJiyong Park
1306*54fd6939SJiyong ParkThis function helps fulfill requirement 4 above.
1307*54fd6939SJiyong Park
1308*54fd6939SJiyong ParkFunction : bl1_plat_sec_mem_layout() [mandatory]
1309*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1310*54fd6939SJiyong Park
1311*54fd6939SJiyong Park::
1312*54fd6939SJiyong Park
1313*54fd6939SJiyong Park    Argument : void
1314*54fd6939SJiyong Park    Return   : meminfo *
1315*54fd6939SJiyong Park
1316*54fd6939SJiyong ParkThis function should only be called on the cold boot path. It executes with the
1317*54fd6939SJiyong ParkMMU and data caches enabled. The pointer returned by this function must point to
1318*54fd6939SJiyong Parka ``meminfo`` structure containing the extents and availability of secure RAM for
1319*54fd6939SJiyong Parkthe BL1 stage.
1320*54fd6939SJiyong Park
1321*54fd6939SJiyong Park::
1322*54fd6939SJiyong Park
1323*54fd6939SJiyong Park    meminfo.total_base = Base address of secure RAM visible to BL1
1324*54fd6939SJiyong Park    meminfo.total_size = Size of secure RAM visible to BL1
1325*54fd6939SJiyong Park
1326*54fd6939SJiyong ParkThis information is used by BL1 to load the BL2 image in secure RAM. BL1 also
1327*54fd6939SJiyong Parkpopulates a similar structure to tell BL2 the extents of memory available for
1328*54fd6939SJiyong Parkits own use.
1329*54fd6939SJiyong Park
1330*54fd6939SJiyong ParkThis function helps fulfill requirements 4 and 5 above.
1331*54fd6939SJiyong Park
1332*54fd6939SJiyong ParkFunction : bl1_plat_prepare_exit() [optional]
1333*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1334*54fd6939SJiyong Park
1335*54fd6939SJiyong Park::
1336*54fd6939SJiyong Park
1337*54fd6939SJiyong Park    Argument : entry_point_info_t *
1338*54fd6939SJiyong Park    Return   : void
1339*54fd6939SJiyong Park
1340*54fd6939SJiyong ParkThis function is called prior to exiting BL1 in response to the
1341*54fd6939SJiyong Park``BL1_SMC_RUN_IMAGE`` SMC request raised by BL2. It should be used to perform
1342*54fd6939SJiyong Parkplatform specific clean up or bookkeeping operations before transferring
1343*54fd6939SJiyong Parkcontrol to the next image. It receives the address of the ``entry_point_info_t``
1344*54fd6939SJiyong Parkstructure passed from BL2. This function runs with MMU disabled.
1345*54fd6939SJiyong Park
1346*54fd6939SJiyong ParkFunction : bl1_plat_set_ep_info() [optional]
1347*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1348*54fd6939SJiyong Park
1349*54fd6939SJiyong Park::
1350*54fd6939SJiyong Park
1351*54fd6939SJiyong Park    Argument : unsigned int image_id, entry_point_info_t *ep_info
1352*54fd6939SJiyong Park    Return   : void
1353*54fd6939SJiyong Park
1354*54fd6939SJiyong ParkThis function allows platforms to override ``ep_info`` for the given ``image_id``.
1355*54fd6939SJiyong Park
1356*54fd6939SJiyong ParkThe default implementation just returns.
1357*54fd6939SJiyong Park
1358*54fd6939SJiyong ParkFunction : bl1_plat_get_next_image_id() [optional]
1359*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1360*54fd6939SJiyong Park
1361*54fd6939SJiyong Park::
1362*54fd6939SJiyong Park
1363*54fd6939SJiyong Park    Argument : void
1364*54fd6939SJiyong Park    Return   : unsigned int
1365*54fd6939SJiyong Park
1366*54fd6939SJiyong ParkThis and the following function must be overridden to enable the FWU feature.
1367*54fd6939SJiyong Park
1368*54fd6939SJiyong ParkBL1 calls this function after platform setup to identify the next image to be
1369*54fd6939SJiyong Parkloaded and executed. If the platform returns ``BL2_IMAGE_ID`` then BL1 proceeds
1370*54fd6939SJiyong Parkwith the normal boot sequence, which loads and executes BL2. If the platform
1371*54fd6939SJiyong Parkreturns a different image id, BL1 assumes that Firmware Update is required.
1372*54fd6939SJiyong Park
1373*54fd6939SJiyong ParkThe default implementation always returns ``BL2_IMAGE_ID``. The Arm development
1374*54fd6939SJiyong Parkplatforms override this function to detect if firmware update is required, and
1375*54fd6939SJiyong Parkif so, return the first image in the firmware update process.
1376*54fd6939SJiyong Park
1377*54fd6939SJiyong ParkFunction : bl1_plat_get_image_desc() [optional]
1378*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1379*54fd6939SJiyong Park
1380*54fd6939SJiyong Park::
1381*54fd6939SJiyong Park
1382*54fd6939SJiyong Park    Argument : unsigned int image_id
1383*54fd6939SJiyong Park    Return   : image_desc_t *
1384*54fd6939SJiyong Park
1385*54fd6939SJiyong ParkBL1 calls this function to get the image descriptor information ``image_desc_t``
1386*54fd6939SJiyong Parkfor the provided ``image_id`` from the platform.
1387*54fd6939SJiyong Park
1388*54fd6939SJiyong ParkThe default implementation always returns a common BL2 image descriptor. Arm
1389*54fd6939SJiyong Parkstandard platforms return an image descriptor corresponding to BL2 or one of
1390*54fd6939SJiyong Parkthe firmware update images defined in the Trusted Board Boot Requirements
1391*54fd6939SJiyong Parkspecification.
1392*54fd6939SJiyong Park
1393*54fd6939SJiyong ParkFunction : bl1_plat_handle_pre_image_load() [optional]
1394*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1395*54fd6939SJiyong Park
1396*54fd6939SJiyong Park::
1397*54fd6939SJiyong Park
1398*54fd6939SJiyong Park    Argument : unsigned int image_id
1399*54fd6939SJiyong Park    Return   : int
1400*54fd6939SJiyong Park
1401*54fd6939SJiyong ParkThis function can be used by the platforms to update/use image information
1402*54fd6939SJiyong Parkcorresponding to ``image_id``. This function is invoked in BL1, both in cold
1403*54fd6939SJiyong Parkboot and FWU code path, before loading the image.
1404*54fd6939SJiyong Park
1405*54fd6939SJiyong ParkFunction : bl1_plat_handle_post_image_load() [optional]
1406*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1407*54fd6939SJiyong Park
1408*54fd6939SJiyong Park::
1409*54fd6939SJiyong Park
1410*54fd6939SJiyong Park    Argument : unsigned int image_id
1411*54fd6939SJiyong Park    Return   : int
1412*54fd6939SJiyong Park
1413*54fd6939SJiyong ParkThis function can be used by the platforms to update/use image information
1414*54fd6939SJiyong Parkcorresponding to ``image_id``. This function is invoked in BL1, both in cold
1415*54fd6939SJiyong Parkboot and FWU code path, after loading and authenticating the image.
1416*54fd6939SJiyong Park
1417*54fd6939SJiyong ParkThe default weak implementation of this function calculates the amount of
1418*54fd6939SJiyong ParkTrusted SRAM that can be used by BL2 and allocates a ``meminfo_t``
1419*54fd6939SJiyong Parkstructure at the beginning of this free memory and populates it. The address
1420*54fd6939SJiyong Parkof ``meminfo_t`` structure is updated in ``arg1`` of the entrypoint
1421*54fd6939SJiyong Parkinformation to BL2.
1422*54fd6939SJiyong Park
1423*54fd6939SJiyong ParkFunction : bl1_plat_fwu_done() [optional]
1424*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1425*54fd6939SJiyong Park
1426*54fd6939SJiyong Park::
1427*54fd6939SJiyong Park
1428*54fd6939SJiyong Park    Argument : unsigned int image_id, uintptr_t image_src,
1429*54fd6939SJiyong Park               unsigned int image_size
1430*54fd6939SJiyong Park    Return   : void
1431*54fd6939SJiyong Park
1432*54fd6939SJiyong ParkBL1 calls this function when the FWU process is complete. It must not return.
1433*54fd6939SJiyong ParkThe platform may override this function to take platform specific action, for
1434*54fd6939SJiyong Parkexample to initiate the normal boot flow.
1435*54fd6939SJiyong Park
1436*54fd6939SJiyong ParkThe default implementation spins forever.
1437*54fd6939SJiyong Park
1438*54fd6939SJiyong ParkFunction : bl1_plat_mem_check() [mandatory]
1439*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1440*54fd6939SJiyong Park
1441*54fd6939SJiyong Park::
1442*54fd6939SJiyong Park
1443*54fd6939SJiyong Park    Argument : uintptr_t mem_base, unsigned int mem_size,
1444*54fd6939SJiyong Park               unsigned int flags
1445*54fd6939SJiyong Park    Return   : int
1446*54fd6939SJiyong Park
1447*54fd6939SJiyong ParkBL1 calls this function while handling FWU related SMCs, more specifically when
1448*54fd6939SJiyong Parkcopying or authenticating an image. Its responsibility is to ensure that the
1449*54fd6939SJiyong Parkregion of memory identified by ``mem_base`` and ``mem_size`` is mapped in BL1, and
1450*54fd6939SJiyong Parkthat this memory corresponds to either a secure or non-secure memory region as
1451*54fd6939SJiyong Parkindicated by the security state of the ``flags`` argument.
1452*54fd6939SJiyong Park
1453*54fd6939SJiyong ParkThis function can safely assume that the value resulting from the addition of
1454*54fd6939SJiyong Park``mem_base`` and ``mem_size`` fits into a ``uintptr_t`` type variable and does not
1455*54fd6939SJiyong Parkoverflow.
1456*54fd6939SJiyong Park
1457*54fd6939SJiyong ParkThis function must return 0 on success, a non-null error code otherwise.
1458*54fd6939SJiyong Park
1459*54fd6939SJiyong ParkThe default implementation of this function asserts therefore platforms must
1460*54fd6939SJiyong Parkoverride it when using the FWU feature.
1461*54fd6939SJiyong Park
1462*54fd6939SJiyong ParkFunction : bl1_plat_mboot_init() [optional]
1463*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1464*54fd6939SJiyong Park
1465*54fd6939SJiyong Park::
1466*54fd6939SJiyong Park
1467*54fd6939SJiyong Park    Argument : void
1468*54fd6939SJiyong Park    Return   : void
1469*54fd6939SJiyong Park
1470*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is enabled:
1471*54fd6939SJiyong Park
1472*54fd6939SJiyong Park-  This function is used to initialize the backend driver(s) of measured boot.
1473*54fd6939SJiyong Park-  On the Arm FVP port, this function is used to initialize the Event Log
1474*54fd6939SJiyong Park   backend driver, and also to write header information in the Event Log buffer.
1475*54fd6939SJiyong Park
1476*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is disabled, this function doesn't do anything.
1477*54fd6939SJiyong Park
1478*54fd6939SJiyong ParkFunction : bl1_plat_mboot_finish() [optional]
1479*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1480*54fd6939SJiyong Park
1481*54fd6939SJiyong Park::
1482*54fd6939SJiyong Park
1483*54fd6939SJiyong Park    Argument : void
1484*54fd6939SJiyong Park    Return   : void
1485*54fd6939SJiyong Park
1486*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is enabled:
1487*54fd6939SJiyong Park
1488*54fd6939SJiyong Park-  This function is used to finalize the measured boot backend driver(s),
1489*54fd6939SJiyong Park   and also, set the information for the next bootloader component to
1490*54fd6939SJiyong Park   extend the measurement if needed.
1491*54fd6939SJiyong Park-  On the Arm FVP port, this function is used to pass the base address of
1492*54fd6939SJiyong Park   the Event Log buffer and its size to BL2 via tb_fw_config to extend the
1493*54fd6939SJiyong Park   Event Log buffer with the measurement of various images loaded by BL2.
1494*54fd6939SJiyong Park   It results in panic on error.
1495*54fd6939SJiyong Park
1496*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is disabled, this function doesn't do anything.
1497*54fd6939SJiyong Park
1498*54fd6939SJiyong ParkBoot Loader Stage 2 (BL2)
1499*54fd6939SJiyong Park-------------------------
1500*54fd6939SJiyong Park
1501*54fd6939SJiyong ParkThe BL2 stage is executed only by the primary CPU, which is determined in BL1
1502*54fd6939SJiyong Parkusing the ``platform_is_primary_cpu()`` function. BL1 passed control to BL2 at
1503*54fd6939SJiyong Park``BL2_BASE``. BL2 executes in Secure EL1 and and invokes
1504*54fd6939SJiyong Park``plat_get_bl_image_load_info()`` to retrieve the list of images to load from
1505*54fd6939SJiyong Parknon-volatile storage to secure/non-secure RAM. After all the images are loaded
1506*54fd6939SJiyong Parkthen BL2 invokes ``plat_get_next_bl_params()`` to get the list of executable
1507*54fd6939SJiyong Parkimages to be passed to the next BL image.
1508*54fd6939SJiyong Park
1509*54fd6939SJiyong ParkThe following functions must be implemented by the platform port to enable BL2
1510*54fd6939SJiyong Parkto perform the above tasks.
1511*54fd6939SJiyong Park
1512*54fd6939SJiyong ParkFunction : bl2_early_platform_setup2() [mandatory]
1513*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1514*54fd6939SJiyong Park
1515*54fd6939SJiyong Park::
1516*54fd6939SJiyong Park
1517*54fd6939SJiyong Park    Argument : u_register_t, u_register_t, u_register_t, u_register_t
1518*54fd6939SJiyong Park    Return   : void
1519*54fd6939SJiyong Park
1520*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1521*54fd6939SJiyong Parkby the primary CPU. The 4 arguments are passed by BL1 to BL2 and these arguments
1522*54fd6939SJiyong Parkare platform specific.
1523*54fd6939SJiyong Park
1524*54fd6939SJiyong ParkOn Arm standard platforms, the arguments received are :
1525*54fd6939SJiyong Park
1526*54fd6939SJiyong Park    arg0 - Points to load address of FW_CONFIG
1527*54fd6939SJiyong Park
1528*54fd6939SJiyong Park    arg1 - ``meminfo`` structure populated by BL1. The platform copies
1529*54fd6939SJiyong Park    the contents of ``meminfo`` as it may be subsequently overwritten by BL2.
1530*54fd6939SJiyong Park
1531*54fd6939SJiyong ParkOn Arm standard platforms, this function also:
1532*54fd6939SJiyong Park
1533*54fd6939SJiyong Park-  Initializes a UART (PL011 console), which enables access to the ``printf``
1534*54fd6939SJiyong Park   family of functions in BL2.
1535*54fd6939SJiyong Park
1536*54fd6939SJiyong Park-  Initializes the storage abstraction layer used to load further bootloader
1537*54fd6939SJiyong Park   images. It is necessary to do this early on platforms with a SCP_BL2 image,
1538*54fd6939SJiyong Park   since the later ``bl2_platform_setup`` must be done after SCP_BL2 is loaded.
1539*54fd6939SJiyong Park
1540*54fd6939SJiyong ParkFunction : bl2_plat_arch_setup() [mandatory]
1541*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1542*54fd6939SJiyong Park
1543*54fd6939SJiyong Park::
1544*54fd6939SJiyong Park
1545*54fd6939SJiyong Park    Argument : void
1546*54fd6939SJiyong Park    Return   : void
1547*54fd6939SJiyong Park
1548*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1549*54fd6939SJiyong Parkby the primary CPU.
1550*54fd6939SJiyong Park
1551*54fd6939SJiyong ParkThe purpose of this function is to perform any architectural initialization
1552*54fd6939SJiyong Parkthat varies across platforms.
1553*54fd6939SJiyong Park
1554*54fd6939SJiyong ParkOn Arm standard platforms, this function enables the MMU.
1555*54fd6939SJiyong Park
1556*54fd6939SJiyong ParkFunction : bl2_platform_setup() [mandatory]
1557*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1558*54fd6939SJiyong Park
1559*54fd6939SJiyong Park::
1560*54fd6939SJiyong Park
1561*54fd6939SJiyong Park    Argument : void
1562*54fd6939SJiyong Park    Return   : void
1563*54fd6939SJiyong Park
1564*54fd6939SJiyong ParkThis function may execute with the MMU and data caches enabled if the platform
1565*54fd6939SJiyong Parkport does the necessary initialization in ``bl2_plat_arch_setup()``. It is only
1566*54fd6939SJiyong Parkcalled by the primary CPU.
1567*54fd6939SJiyong Park
1568*54fd6939SJiyong ParkThe purpose of this function is to perform any platform initialization
1569*54fd6939SJiyong Parkspecific to BL2.
1570*54fd6939SJiyong Park
1571*54fd6939SJiyong ParkIn Arm standard platforms, this function performs security setup, including
1572*54fd6939SJiyong Parkconfiguration of the TrustZone controller to allow non-secure masters access
1573*54fd6939SJiyong Parkto most of DRAM. Part of DRAM is reserved for secure world use.
1574*54fd6939SJiyong Park
1575*54fd6939SJiyong ParkFunction : bl2_plat_handle_pre_image_load() [optional]
1576*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1577*54fd6939SJiyong Park
1578*54fd6939SJiyong Park::
1579*54fd6939SJiyong Park
1580*54fd6939SJiyong Park    Argument : unsigned int
1581*54fd6939SJiyong Park    Return   : int
1582*54fd6939SJiyong Park
1583*54fd6939SJiyong ParkThis function can be used by the platforms to update/use image information
1584*54fd6939SJiyong Parkfor given ``image_id``. This function is currently invoked in BL2 before
1585*54fd6939SJiyong Parkloading each image.
1586*54fd6939SJiyong Park
1587*54fd6939SJiyong ParkFunction : bl2_plat_handle_post_image_load() [optional]
1588*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1589*54fd6939SJiyong Park
1590*54fd6939SJiyong Park::
1591*54fd6939SJiyong Park
1592*54fd6939SJiyong Park    Argument : unsigned int
1593*54fd6939SJiyong Park    Return   : int
1594*54fd6939SJiyong Park
1595*54fd6939SJiyong ParkThis function can be used by the platforms to update/use image information
1596*54fd6939SJiyong Parkfor given ``image_id``. This function is currently invoked in BL2 after
1597*54fd6939SJiyong Parkloading each image.
1598*54fd6939SJiyong Park
1599*54fd6939SJiyong ParkFunction : bl2_plat_preload_setup [optional]
1600*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1601*54fd6939SJiyong Park
1602*54fd6939SJiyong Park::
1603*54fd6939SJiyong Park
1604*54fd6939SJiyong Park    Argument : void
1605*54fd6939SJiyong Park    Return   : void
1606*54fd6939SJiyong Park
1607*54fd6939SJiyong ParkThis optional function performs any BL2 platform initialization
1608*54fd6939SJiyong Parkrequired before image loading, that is not done later in
1609*54fd6939SJiyong Parkbl2_platform_setup(). Specifically, if support for multiple
1610*54fd6939SJiyong Parkboot sources is required, it initializes the boot sequence used by
1611*54fd6939SJiyong Parkplat_try_next_boot_source().
1612*54fd6939SJiyong Park
1613*54fd6939SJiyong ParkFunction : plat_try_next_boot_source() [optional]
1614*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1615*54fd6939SJiyong Park
1616*54fd6939SJiyong Park::
1617*54fd6939SJiyong Park
1618*54fd6939SJiyong Park    Argument : void
1619*54fd6939SJiyong Park    Return   : int
1620*54fd6939SJiyong Park
1621*54fd6939SJiyong ParkThis optional function passes to the next boot source in the redundancy
1622*54fd6939SJiyong Parksequence.
1623*54fd6939SJiyong Park
1624*54fd6939SJiyong ParkThis function moves the current boot redundancy source to the next
1625*54fd6939SJiyong Parkelement in the boot sequence. If there are no more boot sources then it
1626*54fd6939SJiyong Parkmust return 0, otherwise it must return 1. The default implementation
1627*54fd6939SJiyong Parkof this always returns 0.
1628*54fd6939SJiyong Park
1629*54fd6939SJiyong ParkBoot Loader Stage 2 (BL2) at EL3
1630*54fd6939SJiyong Park--------------------------------
1631*54fd6939SJiyong Park
1632*54fd6939SJiyong ParkWhen the platform has a non-TF-A Boot ROM it is desirable to jump
1633*54fd6939SJiyong Parkdirectly to BL2 instead of TF-A BL1. In this case BL2 is expected to
1634*54fd6939SJiyong Parkexecute at EL3 instead of executing at EL1. Refer to the :ref:`Firmware Design`
1635*54fd6939SJiyong Parkdocument for more information.
1636*54fd6939SJiyong Park
1637*54fd6939SJiyong ParkAll mandatory functions of BL2 must be implemented, except the functions
1638*54fd6939SJiyong Parkbl2_early_platform_setup and bl2_el3_plat_arch_setup, because
1639*54fd6939SJiyong Parktheir work is done now by bl2_el3_early_platform_setup and
1640*54fd6939SJiyong Parkbl2_el3_plat_arch_setup. These functions should generally implement
1641*54fd6939SJiyong Parkthe bl1_plat_xxx() and bl2_plat_xxx() functionality combined.
1642*54fd6939SJiyong Park
1643*54fd6939SJiyong Park
1644*54fd6939SJiyong ParkFunction : bl2_el3_early_platform_setup() [mandatory]
1645*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1646*54fd6939SJiyong Park
1647*54fd6939SJiyong Park::
1648*54fd6939SJiyong Park
1649*54fd6939SJiyong Park	Argument : u_register_t, u_register_t, u_register_t, u_register_t
1650*54fd6939SJiyong Park	Return   : void
1651*54fd6939SJiyong Park
1652*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1653*54fd6939SJiyong Parkby the primary CPU. This function receives four parameters which can be used
1654*54fd6939SJiyong Parkby the platform to pass any needed information from the Boot ROM to BL2.
1655*54fd6939SJiyong Park
1656*54fd6939SJiyong ParkOn Arm standard platforms, this function does the following:
1657*54fd6939SJiyong Park
1658*54fd6939SJiyong Park-  Initializes a UART (PL011 console), which enables access to the ``printf``
1659*54fd6939SJiyong Park   family of functions in BL2.
1660*54fd6939SJiyong Park
1661*54fd6939SJiyong Park-  Initializes the storage abstraction layer used to load further bootloader
1662*54fd6939SJiyong Park   images. It is necessary to do this early on platforms with a SCP_BL2 image,
1663*54fd6939SJiyong Park   since the later ``bl2_platform_setup`` must be done after SCP_BL2 is loaded.
1664*54fd6939SJiyong Park
1665*54fd6939SJiyong Park- Initializes the private variables that define the memory layout used.
1666*54fd6939SJiyong Park
1667*54fd6939SJiyong ParkFunction : bl2_el3_plat_arch_setup() [mandatory]
1668*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1669*54fd6939SJiyong Park
1670*54fd6939SJiyong Park::
1671*54fd6939SJiyong Park
1672*54fd6939SJiyong Park	Argument : void
1673*54fd6939SJiyong Park	Return   : void
1674*54fd6939SJiyong Park
1675*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1676*54fd6939SJiyong Parkby the primary CPU.
1677*54fd6939SJiyong Park
1678*54fd6939SJiyong ParkThe purpose of this function is to perform any architectural initialization
1679*54fd6939SJiyong Parkthat varies across platforms.
1680*54fd6939SJiyong Park
1681*54fd6939SJiyong ParkOn Arm standard platforms, this function enables the MMU.
1682*54fd6939SJiyong Park
1683*54fd6939SJiyong ParkFunction : bl2_el3_plat_prepare_exit() [optional]
1684*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1685*54fd6939SJiyong Park
1686*54fd6939SJiyong Park::
1687*54fd6939SJiyong Park
1688*54fd6939SJiyong Park	Argument : void
1689*54fd6939SJiyong Park	Return   : void
1690*54fd6939SJiyong Park
1691*54fd6939SJiyong ParkThis function is called prior to exiting BL2 and run the next image.
1692*54fd6939SJiyong ParkIt should be used to perform platform specific clean up or bookkeeping
1693*54fd6939SJiyong Parkoperations before transferring control to the next image. This function
1694*54fd6939SJiyong Parkruns with MMU disabled.
1695*54fd6939SJiyong Park
1696*54fd6939SJiyong ParkFWU Boot Loader Stage 2 (BL2U)
1697*54fd6939SJiyong Park------------------------------
1698*54fd6939SJiyong Park
1699*54fd6939SJiyong ParkThe AP Firmware Updater Configuration, BL2U, is an optional part of the FWU
1700*54fd6939SJiyong Parkprocess and is executed only by the primary CPU. BL1 passes control to BL2U at
1701*54fd6939SJiyong Park``BL2U_BASE``. BL2U executes in Secure-EL1 and is responsible for:
1702*54fd6939SJiyong Park
1703*54fd6939SJiyong Park#. (Optional) Transferring the optional SCP_BL2U binary image from AP secure
1704*54fd6939SJiyong Park   memory to SCP RAM. BL2U uses the SCP_BL2U ``image_info`` passed by BL1.
1705*54fd6939SJiyong Park   ``SCP_BL2U_BASE`` defines the address in AP secure memory where SCP_BL2U
1706*54fd6939SJiyong Park   should be copied from. Subsequent handling of the SCP_BL2U image is
1707*54fd6939SJiyong Park   implemented by the platform specific ``bl2u_plat_handle_scp_bl2u()`` function.
1708*54fd6939SJiyong Park   If ``SCP_BL2U_BASE`` is not defined then this step is not performed.
1709*54fd6939SJiyong Park
1710*54fd6939SJiyong Park#. Any platform specific setup required to perform the FWU process. For
1711*54fd6939SJiyong Park   example, Arm standard platforms initialize the TZC controller so that the
1712*54fd6939SJiyong Park   normal world can access DDR memory.
1713*54fd6939SJiyong Park
1714*54fd6939SJiyong ParkThe following functions must be implemented by the platform port to enable
1715*54fd6939SJiyong ParkBL2U to perform the tasks mentioned above.
1716*54fd6939SJiyong Park
1717*54fd6939SJiyong ParkFunction : bl2u_early_platform_setup() [mandatory]
1718*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1719*54fd6939SJiyong Park
1720*54fd6939SJiyong Park::
1721*54fd6939SJiyong Park
1722*54fd6939SJiyong Park    Argument : meminfo *mem_info, void *plat_info
1723*54fd6939SJiyong Park    Return   : void
1724*54fd6939SJiyong Park
1725*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only
1726*54fd6939SJiyong Parkcalled by the primary CPU. The arguments to this function is the address
1727*54fd6939SJiyong Parkof the ``meminfo`` structure and platform specific info provided by BL1.
1728*54fd6939SJiyong Park
1729*54fd6939SJiyong ParkThe platform may copy the contents of the ``mem_info`` and ``plat_info`` into
1730*54fd6939SJiyong Parkprivate storage as the original memory may be subsequently overwritten by BL2U.
1731*54fd6939SJiyong Park
1732*54fd6939SJiyong ParkOn Arm CSS platforms ``plat_info`` is interpreted as an ``image_info_t`` structure,
1733*54fd6939SJiyong Parkto extract SCP_BL2U image information, which is then copied into a private
1734*54fd6939SJiyong Parkvariable.
1735*54fd6939SJiyong Park
1736*54fd6939SJiyong ParkFunction : bl2u_plat_arch_setup() [mandatory]
1737*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1738*54fd6939SJiyong Park
1739*54fd6939SJiyong Park::
1740*54fd6939SJiyong Park
1741*54fd6939SJiyong Park    Argument : void
1742*54fd6939SJiyong Park    Return   : void
1743*54fd6939SJiyong Park
1744*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only
1745*54fd6939SJiyong Parkcalled by the primary CPU.
1746*54fd6939SJiyong Park
1747*54fd6939SJiyong ParkThe purpose of this function is to perform any architectural initialization
1748*54fd6939SJiyong Parkthat varies across platforms, for example enabling the MMU (since the memory
1749*54fd6939SJiyong Parkmap differs across platforms).
1750*54fd6939SJiyong Park
1751*54fd6939SJiyong ParkFunction : bl2u_platform_setup() [mandatory]
1752*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1753*54fd6939SJiyong Park
1754*54fd6939SJiyong Park::
1755*54fd6939SJiyong Park
1756*54fd6939SJiyong Park    Argument : void
1757*54fd6939SJiyong Park    Return   : void
1758*54fd6939SJiyong Park
1759*54fd6939SJiyong ParkThis function may execute with the MMU and data caches enabled if the platform
1760*54fd6939SJiyong Parkport does the necessary initialization in ``bl2u_plat_arch_setup()``. It is only
1761*54fd6939SJiyong Parkcalled by the primary CPU.
1762*54fd6939SJiyong Park
1763*54fd6939SJiyong ParkThe purpose of this function is to perform any platform initialization
1764*54fd6939SJiyong Parkspecific to BL2U.
1765*54fd6939SJiyong Park
1766*54fd6939SJiyong ParkIn Arm standard platforms, this function performs security setup, including
1767*54fd6939SJiyong Parkconfiguration of the TrustZone controller to allow non-secure masters access
1768*54fd6939SJiyong Parkto most of DRAM. Part of DRAM is reserved for secure world use.
1769*54fd6939SJiyong Park
1770*54fd6939SJiyong ParkFunction : bl2u_plat_handle_scp_bl2u() [optional]
1771*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1772*54fd6939SJiyong Park
1773*54fd6939SJiyong Park::
1774*54fd6939SJiyong Park
1775*54fd6939SJiyong Park    Argument : void
1776*54fd6939SJiyong Park    Return   : int
1777*54fd6939SJiyong Park
1778*54fd6939SJiyong ParkThis function is used to perform any platform-specific actions required to
1779*54fd6939SJiyong Parkhandle the SCP firmware. Typically it transfers the image into SCP memory using
1780*54fd6939SJiyong Parka platform-specific protocol and waits until SCP executes it and signals to the
1781*54fd6939SJiyong ParkApplication Processor (AP) for BL2U execution to continue.
1782*54fd6939SJiyong Park
1783*54fd6939SJiyong ParkThis function returns 0 on success, a negative error code otherwise.
1784*54fd6939SJiyong ParkThis function is included if SCP_BL2U_BASE is defined.
1785*54fd6939SJiyong Park
1786*54fd6939SJiyong ParkFunction : bl2_plat_mboot_init() [optional]
1787*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1788*54fd6939SJiyong Park
1789*54fd6939SJiyong Park::
1790*54fd6939SJiyong Park
1791*54fd6939SJiyong Park    Argument : void
1792*54fd6939SJiyong Park    Return   : void
1793*54fd6939SJiyong Park
1794*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is enabled:
1795*54fd6939SJiyong Park
1796*54fd6939SJiyong Park-  This function is used to initialize the backend driver(s) of measured boot.
1797*54fd6939SJiyong Park-  On the Arm FVP port, this function is used to initialize the Event Log
1798*54fd6939SJiyong Park   backend driver with the Event Log buffer information (base address and
1799*54fd6939SJiyong Park   size) received from BL1. It results in panic on error.
1800*54fd6939SJiyong Park
1801*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is disabled, this function doesn't do anything.
1802*54fd6939SJiyong Park
1803*54fd6939SJiyong ParkFunction : bl2_plat_mboot_finish() [optional]
1804*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1805*54fd6939SJiyong Park
1806*54fd6939SJiyong Park::
1807*54fd6939SJiyong Park
1808*54fd6939SJiyong Park    Argument : void
1809*54fd6939SJiyong Park    Return   : void
1810*54fd6939SJiyong Park
1811*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is enabled:
1812*54fd6939SJiyong Park
1813*54fd6939SJiyong Park-  This function is used to finalize the measured boot backend driver(s),
1814*54fd6939SJiyong Park   and also, set the information for the next bootloader component to extend
1815*54fd6939SJiyong Park   the measurement if needed.
1816*54fd6939SJiyong Park-  On the Arm FVP port, this function is used to pass the Event Log buffer
1817*54fd6939SJiyong Park   information (base address and size) to non-secure(BL33) and trusted OS(BL32)
1818*54fd6939SJiyong Park   via nt_fw and tos_fw config respectively. It results in panic on error.
1819*54fd6939SJiyong Park
1820*54fd6939SJiyong ParkWhen the MEASURED_BOOT flag is disabled, this function doesn't do anything.
1821*54fd6939SJiyong Park
1822*54fd6939SJiyong ParkBoot Loader Stage 3-1 (BL31)
1823*54fd6939SJiyong Park----------------------------
1824*54fd6939SJiyong Park
1825*54fd6939SJiyong ParkDuring cold boot, the BL31 stage is executed only by the primary CPU. This is
1826*54fd6939SJiyong Parkdetermined in BL1 using the ``platform_is_primary_cpu()`` function. BL1 passes
1827*54fd6939SJiyong Parkcontrol to BL31 at ``BL31_BASE``. During warm boot, BL31 is executed by all
1828*54fd6939SJiyong ParkCPUs. BL31 executes at EL3 and is responsible for:
1829*54fd6939SJiyong Park
1830*54fd6939SJiyong Park#. Re-initializing all architectural and platform state. Although BL1 performs
1831*54fd6939SJiyong Park   some of this initialization, BL31 remains resident in EL3 and must ensure
1832*54fd6939SJiyong Park   that EL3 architectural and platform state is completely initialized. It
1833*54fd6939SJiyong Park   should make no assumptions about the system state when it receives control.
1834*54fd6939SJiyong Park
1835*54fd6939SJiyong Park#. Passing control to a normal world BL image, pre-loaded at a platform-
1836*54fd6939SJiyong Park   specific address by BL2. On ARM platforms, BL31 uses the ``bl_params`` list
1837*54fd6939SJiyong Park   populated by BL2 in memory to do this.
1838*54fd6939SJiyong Park
1839*54fd6939SJiyong Park#. Providing runtime firmware services. Currently, BL31 only implements a
1840*54fd6939SJiyong Park   subset of the Power State Coordination Interface (PSCI) API as a runtime
1841*54fd6939SJiyong Park   service. See Section 3.3 below for details of porting the PSCI
1842*54fd6939SJiyong Park   implementation.
1843*54fd6939SJiyong Park
1844*54fd6939SJiyong Park#. Optionally passing control to the BL32 image, pre-loaded at a platform-
1845*54fd6939SJiyong Park   specific address by BL2. BL31 exports a set of APIs that allow runtime
1846*54fd6939SJiyong Park   services to specify the security state in which the next image should be
1847*54fd6939SJiyong Park   executed and run the corresponding image. On ARM platforms, BL31 uses the
1848*54fd6939SJiyong Park   ``bl_params`` list populated by BL2 in memory to do this.
1849*54fd6939SJiyong Park
1850*54fd6939SJiyong ParkIf BL31 is a reset vector, It also needs to handle the reset as specified in
1851*54fd6939SJiyong Parksection 2.2 before the tasks described above.
1852*54fd6939SJiyong Park
1853*54fd6939SJiyong ParkThe following functions must be implemented by the platform port to enable BL31
1854*54fd6939SJiyong Parkto perform the above tasks.
1855*54fd6939SJiyong Park
1856*54fd6939SJiyong ParkFunction : bl31_early_platform_setup2() [mandatory]
1857*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1858*54fd6939SJiyong Park
1859*54fd6939SJiyong Park::
1860*54fd6939SJiyong Park
1861*54fd6939SJiyong Park    Argument : u_register_t, u_register_t, u_register_t, u_register_t
1862*54fd6939SJiyong Park    Return   : void
1863*54fd6939SJiyong Park
1864*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1865*54fd6939SJiyong Parkby the primary CPU. BL2 can pass 4 arguments to BL31 and these arguments are
1866*54fd6939SJiyong Parkplatform specific.
1867*54fd6939SJiyong Park
1868*54fd6939SJiyong ParkIn Arm standard platforms, the arguments received are :
1869*54fd6939SJiyong Park
1870*54fd6939SJiyong Park    arg0 - The pointer to the head of `bl_params_t` list
1871*54fd6939SJiyong Park    which is list of executable images following BL31,
1872*54fd6939SJiyong Park
1873*54fd6939SJiyong Park    arg1 - Points to load address of SOC_FW_CONFIG if present
1874*54fd6939SJiyong Park           except in case of Arm FVP and Juno platform.
1875*54fd6939SJiyong Park
1876*54fd6939SJiyong Park           In case of Arm FVP and Juno platform, points to load address
1877*54fd6939SJiyong Park           of FW_CONFIG.
1878*54fd6939SJiyong Park
1879*54fd6939SJiyong Park    arg2 - Points to load address of HW_CONFIG if present
1880*54fd6939SJiyong Park
1881*54fd6939SJiyong Park    arg3 - A special value to verify platform parameters from BL2 to BL31. Not
1882*54fd6939SJiyong Park    used in release builds.
1883*54fd6939SJiyong Park
1884*54fd6939SJiyong ParkThe function runs through the `bl_param_t` list and extracts the entry point
1885*54fd6939SJiyong Parkinformation for BL32 and BL33. It also performs the following:
1886*54fd6939SJiyong Park
1887*54fd6939SJiyong Park-  Initialize a UART (PL011 console), which enables access to the ``printf``
1888*54fd6939SJiyong Park   family of functions in BL31.
1889*54fd6939SJiyong Park
1890*54fd6939SJiyong Park-  Enable issuing of snoop and DVM (Distributed Virtual Memory) requests to the
1891*54fd6939SJiyong Park   CCI slave interface corresponding to the cluster that includes the primary
1892*54fd6939SJiyong Park   CPU.
1893*54fd6939SJiyong Park
1894*54fd6939SJiyong ParkFunction : bl31_plat_arch_setup() [mandatory]
1895*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1896*54fd6939SJiyong Park
1897*54fd6939SJiyong Park::
1898*54fd6939SJiyong Park
1899*54fd6939SJiyong Park    Argument : void
1900*54fd6939SJiyong Park    Return   : void
1901*54fd6939SJiyong Park
1902*54fd6939SJiyong ParkThis function executes with the MMU and data caches disabled. It is only called
1903*54fd6939SJiyong Parkby the primary CPU.
1904*54fd6939SJiyong Park
1905*54fd6939SJiyong ParkThe purpose of this function is to perform any architectural initialization
1906*54fd6939SJiyong Parkthat varies across platforms.
1907*54fd6939SJiyong Park
1908*54fd6939SJiyong ParkOn Arm standard platforms, this function enables the MMU.
1909*54fd6939SJiyong Park
1910*54fd6939SJiyong ParkFunction : bl31_platform_setup() [mandatory]
1911*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1912*54fd6939SJiyong Park
1913*54fd6939SJiyong Park::
1914*54fd6939SJiyong Park
1915*54fd6939SJiyong Park    Argument : void
1916*54fd6939SJiyong Park    Return   : void
1917*54fd6939SJiyong Park
1918*54fd6939SJiyong ParkThis function may execute with the MMU and data caches enabled if the platform
1919*54fd6939SJiyong Parkport does the necessary initialization in ``bl31_plat_arch_setup()``. It is only
1920*54fd6939SJiyong Parkcalled by the primary CPU.
1921*54fd6939SJiyong Park
1922*54fd6939SJiyong ParkThe purpose of this function is to complete platform initialization so that both
1923*54fd6939SJiyong ParkBL31 runtime services and normal world software can function correctly.
1924*54fd6939SJiyong Park
1925*54fd6939SJiyong ParkOn Arm standard platforms, this function does the following:
1926*54fd6939SJiyong Park
1927*54fd6939SJiyong Park-  Initialize the generic interrupt controller.
1928*54fd6939SJiyong Park
1929*54fd6939SJiyong Park   Depending on the GIC driver selected by the platform, the appropriate GICv2
1930*54fd6939SJiyong Park   or GICv3 initialization will be done, which mainly consists of:
1931*54fd6939SJiyong Park
1932*54fd6939SJiyong Park   -  Enable secure interrupts in the GIC CPU interface.
1933*54fd6939SJiyong Park   -  Disable the legacy interrupt bypass mechanism.
1934*54fd6939SJiyong Park   -  Configure the priority mask register to allow interrupts of all priorities
1935*54fd6939SJiyong Park      to be signaled to the CPU interface.
1936*54fd6939SJiyong Park   -  Mark SGIs 8-15 and the other secure interrupts on the platform as secure.
1937*54fd6939SJiyong Park   -  Target all secure SPIs to CPU0.
1938*54fd6939SJiyong Park   -  Enable these secure interrupts in the GIC distributor.
1939*54fd6939SJiyong Park   -  Configure all other interrupts as non-secure.
1940*54fd6939SJiyong Park   -  Enable signaling of secure interrupts in the GIC distributor.
1941*54fd6939SJiyong Park
1942*54fd6939SJiyong Park-  Enable system-level implementation of the generic timer counter through the
1943*54fd6939SJiyong Park   memory mapped interface.
1944*54fd6939SJiyong Park
1945*54fd6939SJiyong Park-  Grant access to the system counter timer module
1946*54fd6939SJiyong Park
1947*54fd6939SJiyong Park-  Initialize the power controller device.
1948*54fd6939SJiyong Park
1949*54fd6939SJiyong Park   In particular, initialise the locks that prevent concurrent accesses to the
1950*54fd6939SJiyong Park   power controller device.
1951*54fd6939SJiyong Park
1952*54fd6939SJiyong ParkFunction : bl31_plat_runtime_setup() [optional]
1953*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1954*54fd6939SJiyong Park
1955*54fd6939SJiyong Park::
1956*54fd6939SJiyong Park
1957*54fd6939SJiyong Park    Argument : void
1958*54fd6939SJiyong Park    Return   : void
1959*54fd6939SJiyong Park
1960*54fd6939SJiyong ParkThe purpose of this function is allow the platform to perform any BL31 runtime
1961*54fd6939SJiyong Parksetup just prior to BL31 exit during cold boot. The default weak
1962*54fd6939SJiyong Parkimplementation of this function will invoke ``console_switch_state()`` to switch
1963*54fd6939SJiyong Parkconsole output to consoles marked for use in the ``runtime`` state.
1964*54fd6939SJiyong Park
1965*54fd6939SJiyong ParkFunction : bl31_plat_get_next_image_ep_info() [mandatory]
1966*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1967*54fd6939SJiyong Park
1968*54fd6939SJiyong Park::
1969*54fd6939SJiyong Park
1970*54fd6939SJiyong Park    Argument : uint32_t
1971*54fd6939SJiyong Park    Return   : entry_point_info *
1972*54fd6939SJiyong Park
1973*54fd6939SJiyong ParkThis function may execute with the MMU and data caches enabled if the platform
1974*54fd6939SJiyong Parkport does the necessary initializations in ``bl31_plat_arch_setup()``.
1975*54fd6939SJiyong Park
1976*54fd6939SJiyong ParkThis function is called by ``bl31_main()`` to retrieve information provided by
1977*54fd6939SJiyong ParkBL2 for the next image in the security state specified by the argument. BL31
1978*54fd6939SJiyong Parkuses this information to pass control to that image in the specified security
1979*54fd6939SJiyong Parkstate. This function must return a pointer to the ``entry_point_info`` structure
1980*54fd6939SJiyong Park(that was copied during ``bl31_early_platform_setup()``) if the image exists. It
1981*54fd6939SJiyong Parkshould return NULL otherwise.
1982*54fd6939SJiyong Park
1983*54fd6939SJiyong ParkFunction : bl31_plat_enable_mmu [optional]
1984*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1985*54fd6939SJiyong Park
1986*54fd6939SJiyong Park::
1987*54fd6939SJiyong Park
1988*54fd6939SJiyong Park    Argument : uint32_t
1989*54fd6939SJiyong Park    Return   : void
1990*54fd6939SJiyong Park
1991*54fd6939SJiyong ParkThis function enables the MMU. The boot code calls this function with MMU and
1992*54fd6939SJiyong Parkcaches disabled. This function should program necessary registers to enable
1993*54fd6939SJiyong Parktranslation, and upon return, the MMU on the calling PE must be enabled.
1994*54fd6939SJiyong Park
1995*54fd6939SJiyong ParkThe function must honor flags passed in the first argument. These flags are
1996*54fd6939SJiyong Parkdefined by the translation library, and can be found in the file
1997*54fd6939SJiyong Park``include/lib/xlat_tables/xlat_mmu_helpers.h``.
1998*54fd6939SJiyong Park
1999*54fd6939SJiyong ParkOn DynamIQ systems, this function must not use stack while enabling MMU, which
2000*54fd6939SJiyong Parkis how the function in xlat table library version 2 is implemented.
2001*54fd6939SJiyong Park
2002*54fd6939SJiyong ParkFunction : plat_init_apkey [optional]
2003*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2004*54fd6939SJiyong Park
2005*54fd6939SJiyong Park::
2006*54fd6939SJiyong Park
2007*54fd6939SJiyong Park    Argument : void
2008*54fd6939SJiyong Park    Return   : uint128_t
2009*54fd6939SJiyong Park
2010*54fd6939SJiyong ParkThis function returns the 128-bit value which can be used to program ARMv8.3
2011*54fd6939SJiyong Parkpointer authentication keys.
2012*54fd6939SJiyong Park
2013*54fd6939SJiyong ParkThe value should be obtained from a reliable source of randomness.
2014*54fd6939SJiyong Park
2015*54fd6939SJiyong ParkThis function is only needed if ARMv8.3 pointer authentication is used in the
2016*54fd6939SJiyong ParkTrusted Firmware by building with ``BRANCH_PROTECTION`` option set to non-zero.
2017*54fd6939SJiyong Park
2018*54fd6939SJiyong ParkFunction : plat_get_syscnt_freq2() [mandatory]
2019*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020*54fd6939SJiyong Park
2021*54fd6939SJiyong Park::
2022*54fd6939SJiyong Park
2023*54fd6939SJiyong Park    Argument : void
2024*54fd6939SJiyong Park    Return   : unsigned int
2025*54fd6939SJiyong Park
2026*54fd6939SJiyong ParkThis function is used by the architecture setup code to retrieve the counter
2027*54fd6939SJiyong Parkfrequency for the CPU's generic timer. This value will be programmed into the
2028*54fd6939SJiyong Park``CNTFRQ_EL0`` register. In Arm standard platforms, it returns the base frequency
2029*54fd6939SJiyong Parkof the system counter, which is retrieved from the first entry in the frequency
2030*54fd6939SJiyong Parkmodes table.
2031*54fd6939SJiyong Park
2032*54fd6939SJiyong ParkFunction : plat_arm_set_twedel_scr_el3() [optional]
2033*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2034*54fd6939SJiyong Park
2035*54fd6939SJiyong Park::
2036*54fd6939SJiyong Park
2037*54fd6939SJiyong Park    Argument : void
2038*54fd6939SJiyong Park    Return   : uint32_t
2039*54fd6939SJiyong Park
2040*54fd6939SJiyong ParkThis function is used in v8.6+ systems to set the WFE trap delay value in
2041*54fd6939SJiyong ParkSCR_EL3. If this function returns TWED_DISABLED or is left unimplemented, this
2042*54fd6939SJiyong Parkfeature is not enabled.  The only hook provided is to set the TWED fields in
2043*54fd6939SJiyong ParkSCR_EL3, there are similar fields in HCR_EL2, SCTLR_EL2, and SCTLR_EL1 to adjust
2044*54fd6939SJiyong Parkthe WFE trap delays in lower ELs and these fields should be set by the
2045*54fd6939SJiyong Parkappropriate EL2 or EL1 code depending on the platform configuration.
2046*54fd6939SJiyong Park
2047*54fd6939SJiyong Park#define : PLAT_PERCPU_BAKERY_LOCK_SIZE [optional]
2048*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2049*54fd6939SJiyong Park
2050*54fd6939SJiyong ParkWhen ``USE_COHERENT_MEM = 0``, this constant defines the total memory (in
2051*54fd6939SJiyong Parkbytes) aligned to the cache line boundary that should be allocated per-cpu to
2052*54fd6939SJiyong Parkaccommodate all the bakery locks.
2053*54fd6939SJiyong Park
2054*54fd6939SJiyong ParkIf this constant is not defined when ``USE_COHERENT_MEM = 0``, the linker
2055*54fd6939SJiyong Parkcalculates the size of the ``bakery_lock`` input section, aligns it to the
2056*54fd6939SJiyong Parknearest ``CACHE_WRITEBACK_GRANULE``, multiplies it with ``PLATFORM_CORE_COUNT``
2057*54fd6939SJiyong Parkand stores the result in a linker symbol. This constant prevents a platform
2058*54fd6939SJiyong Parkfrom relying on the linker and provide a more efficient mechanism for
2059*54fd6939SJiyong Parkaccessing per-cpu bakery lock information.
2060*54fd6939SJiyong Park
2061*54fd6939SJiyong ParkIf this constant is defined and its value is not equal to the value
2062*54fd6939SJiyong Parkcalculated by the linker then a link time assertion is raised. A compile time
2063*54fd6939SJiyong Parkassertion is raised if the value of the constant is not aligned to the cache
2064*54fd6939SJiyong Parkline boundary.
2065*54fd6939SJiyong Park
2066*54fd6939SJiyong Park.. _porting_guide_sdei_requirements:
2067*54fd6939SJiyong Park
2068*54fd6939SJiyong ParkSDEI porting requirements
2069*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~
2070*54fd6939SJiyong Park
2071*54fd6939SJiyong ParkThe |SDEI| dispatcher requires the platform to provide the following macros
2072*54fd6939SJiyong Parkand functions, of which some are optional, and some others mandatory.
2073*54fd6939SJiyong Park
2074*54fd6939SJiyong ParkMacros
2075*54fd6939SJiyong Park......
2076*54fd6939SJiyong Park
2077*54fd6939SJiyong ParkMacro: PLAT_SDEI_NORMAL_PRI [mandatory]
2078*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2079*54fd6939SJiyong Park
2080*54fd6939SJiyong ParkThis macro must be defined to the EL3 exception priority level associated with
2081*54fd6939SJiyong ParkNormal |SDEI| events on the platform. This must have a higher value
2082*54fd6939SJiyong Park(therefore of lower priority) than ``PLAT_SDEI_CRITICAL_PRI``.
2083*54fd6939SJiyong Park
2084*54fd6939SJiyong ParkMacro: PLAT_SDEI_CRITICAL_PRI [mandatory]
2085*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2086*54fd6939SJiyong Park
2087*54fd6939SJiyong ParkThis macro must be defined to the EL3 exception priority level associated with
2088*54fd6939SJiyong ParkCritical |SDEI| events on the platform. This must have a lower value
2089*54fd6939SJiyong Park(therefore of higher priority) than ``PLAT_SDEI_NORMAL_PRI``.
2090*54fd6939SJiyong Park
2091*54fd6939SJiyong Park**Note**: |SDEI| exception priorities must be the lowest among Secure
2092*54fd6939SJiyong Parkpriorities. Among the |SDEI| exceptions, Critical |SDEI| priority must
2093*54fd6939SJiyong Parkbe higher than Normal |SDEI| priority.
2094*54fd6939SJiyong Park
2095*54fd6939SJiyong ParkFunctions
2096*54fd6939SJiyong Park.........
2097*54fd6939SJiyong Park
2098*54fd6939SJiyong ParkFunction: int plat_sdei_validate_entry_point() [optional]
2099*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2100*54fd6939SJiyong Park
2101*54fd6939SJiyong Park::
2102*54fd6939SJiyong Park
2103*54fd6939SJiyong Park  Argument: uintptr_t ep, unsigned int client_mode
2104*54fd6939SJiyong Park  Return: int
2105*54fd6939SJiyong Park
2106*54fd6939SJiyong ParkThis function validates the entry point address of the event handler provided by
2107*54fd6939SJiyong Parkthe client for both event registration and *Complete and Resume* |SDEI| calls.
2108*54fd6939SJiyong ParkThe function ensures that the address is valid in the client translation regime.
2109*54fd6939SJiyong Park
2110*54fd6939SJiyong ParkThe second argument is the exception level that the client is executing in. It
2111*54fd6939SJiyong Parkcan be Non-Secure EL1 or Non-Secure EL2.
2112*54fd6939SJiyong Park
2113*54fd6939SJiyong ParkThe function must return ``0`` for successful validation, or ``-1`` upon failure.
2114*54fd6939SJiyong Park
2115*54fd6939SJiyong ParkThe default implementation always returns ``0``. On Arm platforms, this function
2116*54fd6939SJiyong Parktranslates the entry point address within the client translation regime and
2117*54fd6939SJiyong Parkfurther ensures that the resulting physical address is located in Non-secure
2118*54fd6939SJiyong ParkDRAM.
2119*54fd6939SJiyong Park
2120*54fd6939SJiyong ParkFunction: void plat_sdei_handle_masked_trigger(uint64_t mpidr, unsigned int intr) [optional]
2121*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2122*54fd6939SJiyong Park
2123*54fd6939SJiyong Park::
2124*54fd6939SJiyong Park
2125*54fd6939SJiyong Park  Argument: uint64_t
2126*54fd6939SJiyong Park  Argument: unsigned int
2127*54fd6939SJiyong Park  Return: void
2128*54fd6939SJiyong Park
2129*54fd6939SJiyong Park|SDEI| specification requires that a PE comes out of reset with the events
2130*54fd6939SJiyong Parkmasked. The client therefore is expected to call ``PE_UNMASK`` to unmask
2131*54fd6939SJiyong Park|SDEI| events on the PE. No |SDEI| events can be dispatched until such
2132*54fd6939SJiyong Parktime.
2133*54fd6939SJiyong Park
2134*54fd6939SJiyong ParkShould a PE receive an interrupt that was bound to an |SDEI| event while the
2135*54fd6939SJiyong Parkevents are masked on the PE, the dispatcher implementation invokes the function
2136*54fd6939SJiyong Park``plat_sdei_handle_masked_trigger``. The MPIDR of the PE that received the
2137*54fd6939SJiyong Parkinterrupt and the interrupt ID are passed as parameters.
2138*54fd6939SJiyong Park
2139*54fd6939SJiyong ParkThe default implementation only prints out a warning message.
2140*54fd6939SJiyong Park
2141*54fd6939SJiyong Park.. _porting_guide_trng_requirements:
2142*54fd6939SJiyong Park
2143*54fd6939SJiyong ParkTRNG porting requirements
2144*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~
2145*54fd6939SJiyong Park
2146*54fd6939SJiyong ParkThe |TRNG| backend requires the platform to provide the following values
2147*54fd6939SJiyong Parkand mandatory functions.
2148*54fd6939SJiyong Park
2149*54fd6939SJiyong ParkValues
2150*54fd6939SJiyong Park......
2151*54fd6939SJiyong Park
2152*54fd6939SJiyong Parkvalue: uuid_t plat_trng_uuid [mandatory]
2153*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2154*54fd6939SJiyong Park
2155*54fd6939SJiyong ParkThis value must be defined to the UUID of the TRNG backend that is specific to
2156*54fd6939SJiyong Parkthe hardware after ``plat_trng_setup`` function is called. This value must
2157*54fd6939SJiyong Parkconform to the SMCCC calling convention; The most significant 32 bits of the
2158*54fd6939SJiyong ParkUUID must not equal ``0xffffffff`` or the signed integer ``-1`` as this value in
2159*54fd6939SJiyong Parkw0 indicates failure to get a TRNG source.
2160*54fd6939SJiyong Park
2161*54fd6939SJiyong ParkFunctions
2162*54fd6939SJiyong Park.........
2163*54fd6939SJiyong Park
2164*54fd6939SJiyong ParkFunction: void plat_entropy_setup(void) [mandatory]
2165*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2166*54fd6939SJiyong Park
2167*54fd6939SJiyong Park::
2168*54fd6939SJiyong Park
2169*54fd6939SJiyong Park  Argument: none
2170*54fd6939SJiyong Park  Return: none
2171*54fd6939SJiyong Park
2172*54fd6939SJiyong ParkThis function is expected to do platform-specific initialization of any TRNG
2173*54fd6939SJiyong Parkhardware. This may include generating a UUID from a hardware-specific seed.
2174*54fd6939SJiyong Park
2175*54fd6939SJiyong ParkFunction: bool plat_get_entropy(uint64_t \*out) [mandatory]
2176*54fd6939SJiyong Park^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2177*54fd6939SJiyong Park
2178*54fd6939SJiyong Park::
2179*54fd6939SJiyong Park
2180*54fd6939SJiyong Park  Argument: uint64_t *
2181*54fd6939SJiyong Park  Return: bool
2182*54fd6939SJiyong Park  Out : when the return value is true, the entropy has been written into the
2183*54fd6939SJiyong Park  storage pointed to
2184*54fd6939SJiyong Park
2185*54fd6939SJiyong ParkThis function writes entropy into storage provided by the caller. If no entropy
2186*54fd6939SJiyong Parkis available, it must return false and the storage must not be written.
2187*54fd6939SJiyong Park
2188*54fd6939SJiyong ParkPower State Coordination Interface (in BL31)
2189*54fd6939SJiyong Park--------------------------------------------
2190*54fd6939SJiyong Park
2191*54fd6939SJiyong ParkThe TF-A implementation of the PSCI API is based around the concept of a
2192*54fd6939SJiyong Park*power domain*. A *power domain* is a CPU or a logical group of CPUs which
2193*54fd6939SJiyong Parkshare some state on which power management operations can be performed as
2194*54fd6939SJiyong Parkspecified by `PSCI`_. Each CPU in the system is assigned a cpu index which is
2195*54fd6939SJiyong Parka unique number between ``0`` and ``PLATFORM_CORE_COUNT - 1``. The
2196*54fd6939SJiyong Park*power domains* are arranged in a hierarchical tree structure and each
2197*54fd6939SJiyong Park*power domain* can be identified in a system by the cpu index of any CPU that
2198*54fd6939SJiyong Parkis part of that domain and a *power domain level*. A processing element (for
2199*54fd6939SJiyong Parkexample, a CPU) is at level 0. If the *power domain* node above a CPU is a
2200*54fd6939SJiyong Parklogical grouping of CPUs that share some state, then level 1 is that group of
2201*54fd6939SJiyong ParkCPUs (for example, a cluster), and level 2 is a group of clusters (for
2202*54fd6939SJiyong Parkexample, the system). More details on the power domain topology and its
2203*54fd6939SJiyong Parkorganization can be found in :ref:`PSCI Power Domain Tree Structure`.
2204*54fd6939SJiyong Park
2205*54fd6939SJiyong ParkBL31's platform initialization code exports a pointer to the platform-specific
2206*54fd6939SJiyong Parkpower management operations required for the PSCI implementation to function
2207*54fd6939SJiyong Parkcorrectly. This information is populated in the ``plat_psci_ops`` structure. The
2208*54fd6939SJiyong ParkPSCI implementation calls members of the ``plat_psci_ops`` structure for performing
2209*54fd6939SJiyong Parkpower management operations on the power domains. For example, the target
2210*54fd6939SJiyong ParkCPU is specified by its ``MPIDR`` in a PSCI ``CPU_ON`` call. The ``pwr_domain_on()``
2211*54fd6939SJiyong Parkhandler (if present) is called for the CPU power domain.
2212*54fd6939SJiyong Park
2213*54fd6939SJiyong ParkThe ``power-state`` parameter of a PSCI ``CPU_SUSPEND`` call can be used to
2214*54fd6939SJiyong Parkdescribe composite power states specific to a platform. The PSCI implementation
2215*54fd6939SJiyong Parkdefines a generic representation of the power-state parameter, which is an
2216*54fd6939SJiyong Parkarray of local power states where each index corresponds to a power domain
2217*54fd6939SJiyong Parklevel. Each entry contains the local power state the power domain at that power
2218*54fd6939SJiyong Parklevel could enter. It depends on the ``validate_power_state()`` handler to
2219*54fd6939SJiyong Parkconvert the power-state parameter (possibly encoding a composite power state)
2220*54fd6939SJiyong Parkpassed in a PSCI ``CPU_SUSPEND`` call to this representation.
2221*54fd6939SJiyong Park
2222*54fd6939SJiyong ParkThe following functions form part of platform port of PSCI functionality.
2223*54fd6939SJiyong Park
2224*54fd6939SJiyong ParkFunction : plat_psci_stat_accounting_start() [optional]
2225*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2226*54fd6939SJiyong Park
2227*54fd6939SJiyong Park::
2228*54fd6939SJiyong Park
2229*54fd6939SJiyong Park    Argument : const psci_power_state_t *
2230*54fd6939SJiyong Park    Return   : void
2231*54fd6939SJiyong Park
2232*54fd6939SJiyong ParkThis is an optional hook that platforms can implement for residency statistics
2233*54fd6939SJiyong Parkaccounting before entering a low power state. The ``pwr_domain_state`` field of
2234*54fd6939SJiyong Park``state_info`` (first argument) can be inspected if stat accounting is done
2235*54fd6939SJiyong Parkdifferently at CPU level versus higher levels. As an example, if the element at
2236*54fd6939SJiyong Parkindex 0 (CPU power level) in the ``pwr_domain_state`` array indicates a power down
2237*54fd6939SJiyong Parkstate, special hardware logic may be programmed in order to keep track of the
2238*54fd6939SJiyong Parkresidency statistics. For higher levels (array indices > 0), the residency
2239*54fd6939SJiyong Parkstatistics could be tracked in software using PMF. If ``ENABLE_PMF`` is set, the
2240*54fd6939SJiyong Parkdefault implementation will use PMF to capture timestamps.
2241*54fd6939SJiyong Park
2242*54fd6939SJiyong ParkFunction : plat_psci_stat_accounting_stop() [optional]
2243*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2244*54fd6939SJiyong Park
2245*54fd6939SJiyong Park::
2246*54fd6939SJiyong Park
2247*54fd6939SJiyong Park    Argument : const psci_power_state_t *
2248*54fd6939SJiyong Park    Return   : void
2249*54fd6939SJiyong Park
2250*54fd6939SJiyong ParkThis is an optional hook that platforms can implement for residency statistics
2251*54fd6939SJiyong Parkaccounting after exiting from a low power state. The ``pwr_domain_state`` field
2252*54fd6939SJiyong Parkof ``state_info`` (first argument) can be inspected if stat accounting is done
2253*54fd6939SJiyong Parkdifferently at CPU level versus higher levels. As an example, if the element at
2254*54fd6939SJiyong Parkindex 0 (CPU power level) in the ``pwr_domain_state`` array indicates a power down
2255*54fd6939SJiyong Parkstate, special hardware logic may be programmed in order to keep track of the
2256*54fd6939SJiyong Parkresidency statistics. For higher levels (array indices > 0), the residency
2257*54fd6939SJiyong Parkstatistics could be tracked in software using PMF. If ``ENABLE_PMF`` is set, the
2258*54fd6939SJiyong Parkdefault implementation will use PMF to capture timestamps.
2259*54fd6939SJiyong Park
2260*54fd6939SJiyong ParkFunction : plat_psci_stat_get_residency() [optional]
2261*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2262*54fd6939SJiyong Park
2263*54fd6939SJiyong Park::
2264*54fd6939SJiyong Park
2265*54fd6939SJiyong Park    Argument : unsigned int, const psci_power_state_t *, unsigned int
2266*54fd6939SJiyong Park    Return   : u_register_t
2267*54fd6939SJiyong Park
2268*54fd6939SJiyong ParkThis is an optional interface that is is invoked after resuming from a low power
2269*54fd6939SJiyong Parkstate and provides the time spent resident in that low power state by the power
2270*54fd6939SJiyong Parkdomain at a particular power domain level. When a CPU wakes up from suspend,
2271*54fd6939SJiyong Parkall its parent power domain levels are also woken up. The generic PSCI code
2272*54fd6939SJiyong Parkinvokes this function for each parent power domain that is resumed and it
2273*54fd6939SJiyong Parkidentified by the ``lvl`` (first argument) parameter. The ``state_info`` (second
2274*54fd6939SJiyong Parkargument) describes the low power state that the power domain has resumed from.
2275*54fd6939SJiyong ParkThe current CPU is the first CPU in the power domain to resume from the low
2276*54fd6939SJiyong Parkpower state and the ``last_cpu_idx`` (third parameter) is the index of the last
2277*54fd6939SJiyong ParkCPU in the power domain to suspend and may be needed to calculate the residency
2278*54fd6939SJiyong Parkfor that power domain.
2279*54fd6939SJiyong Park
2280*54fd6939SJiyong ParkFunction : plat_get_target_pwr_state() [optional]
2281*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2282*54fd6939SJiyong Park
2283*54fd6939SJiyong Park::
2284*54fd6939SJiyong Park
2285*54fd6939SJiyong Park    Argument : unsigned int, const plat_local_state_t *, unsigned int
2286*54fd6939SJiyong Park    Return   : plat_local_state_t
2287*54fd6939SJiyong Park
2288*54fd6939SJiyong ParkThe PSCI generic code uses this function to let the platform participate in
2289*54fd6939SJiyong Parkstate coordination during a power management operation. The function is passed
2290*54fd6939SJiyong Parka pointer to an array of platform specific local power state ``states`` (second
2291*54fd6939SJiyong Parkargument) which contains the requested power state for each CPU at a particular
2292*54fd6939SJiyong Parkpower domain level ``lvl`` (first argument) within the power domain. The function
2293*54fd6939SJiyong Parkis expected to traverse this array of upto ``ncpus`` (third argument) and return
2294*54fd6939SJiyong Parka coordinated target power state by the comparing all the requested power
2295*54fd6939SJiyong Parkstates. The target power state should not be deeper than any of the requested
2296*54fd6939SJiyong Parkpower states.
2297*54fd6939SJiyong Park
2298*54fd6939SJiyong ParkA weak definition of this API is provided by default wherein it assumes
2299*54fd6939SJiyong Parkthat the platform assigns a local state value in order of increasing depth
2300*54fd6939SJiyong Parkof the power state i.e. for two power states X & Y, if X < Y
2301*54fd6939SJiyong Parkthen X represents a shallower power state than Y. As a result, the
2302*54fd6939SJiyong Parkcoordinated target local power state for a power domain will be the minimum
2303*54fd6939SJiyong Parkof the requested local power state values.
2304*54fd6939SJiyong Park
2305*54fd6939SJiyong ParkFunction : plat_get_power_domain_tree_desc() [mandatory]
2306*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2307*54fd6939SJiyong Park
2308*54fd6939SJiyong Park::
2309*54fd6939SJiyong Park
2310*54fd6939SJiyong Park    Argument : void
2311*54fd6939SJiyong Park    Return   : const unsigned char *
2312*54fd6939SJiyong Park
2313*54fd6939SJiyong ParkThis function returns a pointer to the byte array containing the power domain
2314*54fd6939SJiyong Parktopology tree description. The format and method to construct this array are
2315*54fd6939SJiyong Parkdescribed in :ref:`PSCI Power Domain Tree Structure`. The BL31 PSCI
2316*54fd6939SJiyong Parkinitialization code requires this array to be described by the platform, either
2317*54fd6939SJiyong Parkstatically or dynamically, to initialize the power domain topology tree. In case
2318*54fd6939SJiyong Parkthe array is populated dynamically, then plat_core_pos_by_mpidr() and
2319*54fd6939SJiyong Parkplat_my_core_pos() should also be implemented suitably so that the topology tree
2320*54fd6939SJiyong Parkdescription matches the CPU indices returned by these APIs. These APIs together
2321*54fd6939SJiyong Parkform the platform interface for the PSCI topology framework.
2322*54fd6939SJiyong Park
2323*54fd6939SJiyong ParkFunction : plat_setup_psci_ops() [mandatory]
2324*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2325*54fd6939SJiyong Park
2326*54fd6939SJiyong Park::
2327*54fd6939SJiyong Park
2328*54fd6939SJiyong Park    Argument : uintptr_t, const plat_psci_ops **
2329*54fd6939SJiyong Park    Return   : int
2330*54fd6939SJiyong Park
2331*54fd6939SJiyong ParkThis function may execute with the MMU and data caches enabled if the platform
2332*54fd6939SJiyong Parkport does the necessary initializations in ``bl31_plat_arch_setup()``. It is only
2333*54fd6939SJiyong Parkcalled by the primary CPU.
2334*54fd6939SJiyong Park
2335*54fd6939SJiyong ParkThis function is called by PSCI initialization code. Its purpose is to let
2336*54fd6939SJiyong Parkthe platform layer know about the warm boot entrypoint through the
2337*54fd6939SJiyong Park``sec_entrypoint`` (first argument) and to export handler routines for
2338*54fd6939SJiyong Parkplatform-specific psci power management actions by populating the passed
2339*54fd6939SJiyong Parkpointer with a pointer to BL31's private ``plat_psci_ops`` structure.
2340*54fd6939SJiyong Park
2341*54fd6939SJiyong ParkA description of each member of this structure is given below. Please refer to
2342*54fd6939SJiyong Parkthe Arm FVP specific implementation of these handlers in
2343*54fd6939SJiyong Park``plat/arm/board/fvp/fvp_pm.c`` as an example. For each PSCI function that the
2344*54fd6939SJiyong Parkplatform wants to support, the associated operation or operations in this
2345*54fd6939SJiyong Parkstructure must be provided and implemented (Refer section 4 of
2346*54fd6939SJiyong Park:ref:`Firmware Design` for the PSCI API supported in TF-A). To disable a PSCI
2347*54fd6939SJiyong Parkfunction in a platform port, the operation should be removed from this
2348*54fd6939SJiyong Parkstructure instead of providing an empty implementation.
2349*54fd6939SJiyong Park
2350*54fd6939SJiyong Parkplat_psci_ops.cpu_standby()
2351*54fd6939SJiyong Park...........................
2352*54fd6939SJiyong Park
2353*54fd6939SJiyong ParkPerform the platform-specific actions to enter the standby state for a cpu
2354*54fd6939SJiyong Parkindicated by the passed argument. This provides a fast path for CPU standby
2355*54fd6939SJiyong Parkwherein overheads of PSCI state management and lock acquisition is avoided.
2356*54fd6939SJiyong ParkFor this handler to be invoked by the PSCI ``CPU_SUSPEND`` API implementation,
2357*54fd6939SJiyong Parkthe suspend state type specified in the ``power-state`` parameter should be
2358*54fd6939SJiyong ParkSTANDBY and the target power domain level specified should be the CPU. The
2359*54fd6939SJiyong Parkhandler should put the CPU into a low power retention state (usually by
2360*54fd6939SJiyong Parkissuing a wfi instruction) and ensure that it can be woken up from that
2361*54fd6939SJiyong Parkstate by a normal interrupt. The generic code expects the handler to succeed.
2362*54fd6939SJiyong Park
2363*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_on()
2364*54fd6939SJiyong Park.............................
2365*54fd6939SJiyong Park
2366*54fd6939SJiyong ParkPerform the platform specific actions to power on a CPU, specified
2367*54fd6939SJiyong Parkby the ``MPIDR`` (first argument). The generic code expects the platform to
2368*54fd6939SJiyong Parkreturn PSCI_E_SUCCESS on success or PSCI_E_INTERN_FAIL for any failure.
2369*54fd6939SJiyong Park
2370*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_off()
2371*54fd6939SJiyong Park..............................
2372*54fd6939SJiyong Park
2373*54fd6939SJiyong ParkPerform the platform specific actions to prepare to power off the calling CPU
2374*54fd6939SJiyong Parkand its higher parent power domain levels as indicated by the ``target_state``
2375*54fd6939SJiyong Park(first argument). It is called by the PSCI ``CPU_OFF`` API implementation.
2376*54fd6939SJiyong Park
2377*54fd6939SJiyong ParkThe ``target_state`` encodes the platform coordinated target local power states
2378*54fd6939SJiyong Parkfor the CPU power domain and its parent power domain levels. The handler
2379*54fd6939SJiyong Parkneeds to perform power management operation corresponding to the local state
2380*54fd6939SJiyong Parkat each power level.
2381*54fd6939SJiyong Park
2382*54fd6939SJiyong ParkFor this handler, the local power state for the CPU power domain will be a
2383*54fd6939SJiyong Parkpower down state where as it could be either power down, retention or run state
2384*54fd6939SJiyong Parkfor the higher power domain levels depending on the result of state
2385*54fd6939SJiyong Parkcoordination. The generic code expects the handler to succeed.
2386*54fd6939SJiyong Park
2387*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_suspend_pwrdown_early() [optional]
2388*54fd6939SJiyong Park...........................................................
2389*54fd6939SJiyong Park
2390*54fd6939SJiyong ParkThis optional function may be used as a performance optimization to replace
2391*54fd6939SJiyong Parkor complement pwr_domain_suspend() on some platforms. Its calling semantics
2392*54fd6939SJiyong Parkare identical to pwr_domain_suspend(), except the PSCI implementation only
2393*54fd6939SJiyong Parkcalls this function when suspending to a power down state, and it guarantees
2394*54fd6939SJiyong Parkthat data caches are enabled.
2395*54fd6939SJiyong Park
2396*54fd6939SJiyong ParkWhen HW_ASSISTED_COHERENCY = 0, the PSCI implementation disables data caches
2397*54fd6939SJiyong Parkbefore calling pwr_domain_suspend(). If the target_state corresponds to a
2398*54fd6939SJiyong Parkpower down state and it is safe to perform some or all of the platform
2399*54fd6939SJiyong Parkspecific actions in that function with data caches enabled, it may be more
2400*54fd6939SJiyong Parkefficient to move those actions to this function. When HW_ASSISTED_COHERENCY
2401*54fd6939SJiyong Park= 1, data caches remain enabled throughout, and so there is no advantage to
2402*54fd6939SJiyong Parkmoving platform specific actions to this function.
2403*54fd6939SJiyong Park
2404*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_suspend()
2405*54fd6939SJiyong Park..................................
2406*54fd6939SJiyong Park
2407*54fd6939SJiyong ParkPerform the platform specific actions to prepare to suspend the calling
2408*54fd6939SJiyong ParkCPU and its higher parent power domain levels as indicated by the
2409*54fd6939SJiyong Park``target_state`` (first argument). It is called by the PSCI ``CPU_SUSPEND``
2410*54fd6939SJiyong ParkAPI implementation.
2411*54fd6939SJiyong Park
2412*54fd6939SJiyong ParkThe ``target_state`` has a similar meaning as described in
2413*54fd6939SJiyong Parkthe ``pwr_domain_off()`` operation. It encodes the platform coordinated
2414*54fd6939SJiyong Parktarget local power states for the CPU power domain and its parent
2415*54fd6939SJiyong Parkpower domain levels. The handler needs to perform power management operation
2416*54fd6939SJiyong Parkcorresponding to the local state at each power level. The generic code
2417*54fd6939SJiyong Parkexpects the handler to succeed.
2418*54fd6939SJiyong Park
2419*54fd6939SJiyong ParkThe difference between turning a power domain off versus suspending it is that
2420*54fd6939SJiyong Parkin the former case, the power domain is expected to re-initialize its state
2421*54fd6939SJiyong Parkwhen it is next powered on (see ``pwr_domain_on_finish()``). In the latter
2422*54fd6939SJiyong Parkcase, the power domain is expected to save enough state so that it can resume
2423*54fd6939SJiyong Parkexecution by restoring this state when its powered on (see
2424*54fd6939SJiyong Park``pwr_domain_suspend_finish()``).
2425*54fd6939SJiyong Park
2426*54fd6939SJiyong ParkWhen suspending a core, the platform can also choose to power off the GICv3
2427*54fd6939SJiyong ParkRedistributor and ITS through an implementation-defined sequence. To achieve
2428*54fd6939SJiyong Parkthis safely, the ITS context must be saved first. The architectural part is
2429*54fd6939SJiyong Parkimplemented by the ``gicv3_its_save_disable()`` helper, but most of the needed
2430*54fd6939SJiyong Parksequence is implementation defined and it is therefore the responsibility of
2431*54fd6939SJiyong Parkthe platform code to implement the necessary sequence. Then the GIC
2432*54fd6939SJiyong ParkRedistributor context can be saved using the ``gicv3_rdistif_save()`` helper.
2433*54fd6939SJiyong ParkPowering off the Redistributor requires the implementation to support it and it
2434*54fd6939SJiyong Parkis the responsibility of the platform code to execute the right implementation
2435*54fd6939SJiyong Parkdefined sequence.
2436*54fd6939SJiyong Park
2437*54fd6939SJiyong ParkWhen a system suspend is requested, the platform can also make use of the
2438*54fd6939SJiyong Park``gicv3_distif_save()`` helper to save the context of the GIC Distributor after
2439*54fd6939SJiyong Parkit has saved the context of the Redistributors and ITS of all the cores in the
2440*54fd6939SJiyong Parksystem. The context of the Distributor can be large and may require it to be
2441*54fd6939SJiyong Parkallocated in a special area if it cannot fit in the platform's global static
2442*54fd6939SJiyong Parkdata, for example in DRAM. The Distributor can then be powered down using an
2443*54fd6939SJiyong Parkimplementation-defined sequence.
2444*54fd6939SJiyong Park
2445*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_pwr_down_wfi()
2446*54fd6939SJiyong Park.......................................
2447*54fd6939SJiyong Park
2448*54fd6939SJiyong ParkThis is an optional function and, if implemented, is expected to perform
2449*54fd6939SJiyong Parkplatform specific actions including the ``wfi`` invocation which allows the
2450*54fd6939SJiyong ParkCPU to powerdown. Since this function is invoked outside the PSCI locks,
2451*54fd6939SJiyong Parkthe actions performed in this hook must be local to the CPU or the platform
2452*54fd6939SJiyong Parkmust ensure that races between multiple CPUs cannot occur.
2453*54fd6939SJiyong Park
2454*54fd6939SJiyong ParkThe ``target_state`` has a similar meaning as described in the ``pwr_domain_off()``
2455*54fd6939SJiyong Parkoperation and it encodes the platform coordinated target local power states for
2456*54fd6939SJiyong Parkthe CPU power domain and its parent power domain levels. This function must
2457*54fd6939SJiyong Parknot return back to the caller.
2458*54fd6939SJiyong Park
2459*54fd6939SJiyong ParkIf this function is not implemented by the platform, PSCI generic
2460*54fd6939SJiyong Parkimplementation invokes ``psci_power_down_wfi()`` for power down.
2461*54fd6939SJiyong Park
2462*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_on_finish()
2463*54fd6939SJiyong Park....................................
2464*54fd6939SJiyong Park
2465*54fd6939SJiyong ParkThis function is called by the PSCI implementation after the calling CPU is
2466*54fd6939SJiyong Parkpowered on and released from reset in response to an earlier PSCI ``CPU_ON`` call.
2467*54fd6939SJiyong ParkIt performs the platform-specific setup required to initialize enough state for
2468*54fd6939SJiyong Parkthis CPU to enter the normal world and also provide secure runtime firmware
2469*54fd6939SJiyong Parkservices.
2470*54fd6939SJiyong Park
2471*54fd6939SJiyong ParkThe ``target_state`` (first argument) is the prior state of the power domains
2472*54fd6939SJiyong Parkimmediately before the CPU was turned on. It indicates which power domains
2473*54fd6939SJiyong Parkabove the CPU might require initialization due to having previously been in
2474*54fd6939SJiyong Parklow power states. The generic code expects the handler to succeed.
2475*54fd6939SJiyong Park
2476*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_on_finish_late() [optional]
2477*54fd6939SJiyong Park...........................................................
2478*54fd6939SJiyong Park
2479*54fd6939SJiyong ParkThis optional function is called by the PSCI implementation after the calling
2480*54fd6939SJiyong ParkCPU is fully powered on with respective data caches enabled. The calling CPU and
2481*54fd6939SJiyong Parkthe associated cluster are guaranteed to be participating in coherency. This
2482*54fd6939SJiyong Parkfunction gives the flexibility to perform any platform-specific actions safely,
2483*54fd6939SJiyong Parksuch as initialization or modification of shared data structures, without the
2484*54fd6939SJiyong Parkoverhead of explicit cache maintainace operations.
2485*54fd6939SJiyong Park
2486*54fd6939SJiyong ParkThe ``target_state`` has a similar meaning as described in the ``pwr_domain_on_finish()``
2487*54fd6939SJiyong Parkoperation. The generic code expects the handler to succeed.
2488*54fd6939SJiyong Park
2489*54fd6939SJiyong Parkplat_psci_ops.pwr_domain_suspend_finish()
2490*54fd6939SJiyong Park.........................................
2491*54fd6939SJiyong Park
2492*54fd6939SJiyong ParkThis function is called by the PSCI implementation after the calling CPU is
2493*54fd6939SJiyong Parkpowered on and released from reset in response to an asynchronous wakeup
2494*54fd6939SJiyong Parkevent, for example a timer interrupt that was programmed by the CPU during the
2495*54fd6939SJiyong Park``CPU_SUSPEND`` call or ``SYSTEM_SUSPEND`` call. It performs the platform-specific
2496*54fd6939SJiyong Parksetup required to restore the saved state for this CPU to resume execution
2497*54fd6939SJiyong Parkin the normal world and also provide secure runtime firmware services.
2498*54fd6939SJiyong Park
2499*54fd6939SJiyong ParkThe ``target_state`` (first argument) has a similar meaning as described in
2500*54fd6939SJiyong Parkthe ``pwr_domain_on_finish()`` operation. The generic code expects the platform
2501*54fd6939SJiyong Parkto succeed.
2502*54fd6939SJiyong Park
2503*54fd6939SJiyong ParkIf the Distributor, Redistributors or ITS have been powered off as part of a
2504*54fd6939SJiyong Parksuspend, their context must be restored in this function in the reverse order
2505*54fd6939SJiyong Parkto how they were saved during suspend sequence.
2506*54fd6939SJiyong Park
2507*54fd6939SJiyong Parkplat_psci_ops.system_off()
2508*54fd6939SJiyong Park..........................
2509*54fd6939SJiyong Park
2510*54fd6939SJiyong ParkThis function is called by PSCI implementation in response to a ``SYSTEM_OFF``
2511*54fd6939SJiyong Parkcall. It performs the platform-specific system poweroff sequence after
2512*54fd6939SJiyong Parknotifying the Secure Payload Dispatcher.
2513*54fd6939SJiyong Park
2514*54fd6939SJiyong Parkplat_psci_ops.system_reset()
2515*54fd6939SJiyong Park............................
2516*54fd6939SJiyong Park
2517*54fd6939SJiyong ParkThis function is called by PSCI implementation in response to a ``SYSTEM_RESET``
2518*54fd6939SJiyong Parkcall. It performs the platform-specific system reset sequence after
2519*54fd6939SJiyong Parknotifying the Secure Payload Dispatcher.
2520*54fd6939SJiyong Park
2521*54fd6939SJiyong Parkplat_psci_ops.validate_power_state()
2522*54fd6939SJiyong Park....................................
2523*54fd6939SJiyong Park
2524*54fd6939SJiyong ParkThis function is called by the PSCI implementation during the ``CPU_SUSPEND``
2525*54fd6939SJiyong Parkcall to validate the ``power_state`` parameter of the PSCI API and if valid,
2526*54fd6939SJiyong Parkpopulate it in ``req_state`` (second argument) array as power domain level
2527*54fd6939SJiyong Parkspecific local states. If the ``power_state`` is invalid, the platform must
2528*54fd6939SJiyong Parkreturn PSCI_E_INVALID_PARAMS as error, which is propagated back to the
2529*54fd6939SJiyong Parknormal world PSCI client.
2530*54fd6939SJiyong Park
2531*54fd6939SJiyong Parkplat_psci_ops.validate_ns_entrypoint()
2532*54fd6939SJiyong Park......................................
2533*54fd6939SJiyong Park
2534*54fd6939SJiyong ParkThis function is called by the PSCI implementation during the ``CPU_SUSPEND``,
2535*54fd6939SJiyong Park``SYSTEM_SUSPEND`` and ``CPU_ON`` calls to validate the non-secure ``entry_point``
2536*54fd6939SJiyong Parkparameter passed by the normal world. If the ``entry_point`` is invalid,
2537*54fd6939SJiyong Parkthe platform must return PSCI_E_INVALID_ADDRESS as error, which is
2538*54fd6939SJiyong Parkpropagated back to the normal world PSCI client.
2539*54fd6939SJiyong Park
2540*54fd6939SJiyong Parkplat_psci_ops.get_sys_suspend_power_state()
2541*54fd6939SJiyong Park...........................................
2542*54fd6939SJiyong Park
2543*54fd6939SJiyong ParkThis function is called by the PSCI implementation during the ``SYSTEM_SUSPEND``
2544*54fd6939SJiyong Parkcall to get the ``req_state`` parameter from platform which encodes the power
2545*54fd6939SJiyong Parkdomain level specific local states to suspend to system affinity level. The
2546*54fd6939SJiyong Park``req_state`` will be utilized to do the PSCI state coordination and
2547*54fd6939SJiyong Park``pwr_domain_suspend()`` will be invoked with the coordinated target state to
2548*54fd6939SJiyong Parkenter system suspend.
2549*54fd6939SJiyong Park
2550*54fd6939SJiyong Parkplat_psci_ops.get_pwr_lvl_state_idx()
2551*54fd6939SJiyong Park.....................................
2552*54fd6939SJiyong Park
2553*54fd6939SJiyong ParkThis is an optional function and, if implemented, is invoked by the PSCI
2554*54fd6939SJiyong Parkimplementation to convert the ``local_state`` (first argument) at a specified
2555*54fd6939SJiyong Park``pwr_lvl`` (second argument) to an index between 0 and
2556*54fd6939SJiyong Park``PLAT_MAX_PWR_LVL_STATES`` - 1. This function is only needed if the platform
2557*54fd6939SJiyong Parksupports more than two local power states at each power domain level, that is
2558*54fd6939SJiyong Park``PLAT_MAX_PWR_LVL_STATES`` is greater than 2, and needs to account for these
2559*54fd6939SJiyong Parklocal power states.
2560*54fd6939SJiyong Park
2561*54fd6939SJiyong Parkplat_psci_ops.translate_power_state_by_mpidr()
2562*54fd6939SJiyong Park..............................................
2563*54fd6939SJiyong Park
2564*54fd6939SJiyong ParkThis is an optional function and, if implemented, verifies the ``power_state``
2565*54fd6939SJiyong Park(second argument) parameter of the PSCI API corresponding to a target power
2566*54fd6939SJiyong Parkdomain. The target power domain is identified by using both ``MPIDR`` (first
2567*54fd6939SJiyong Parkargument) and the power domain level encoded in ``power_state``. The power domain
2568*54fd6939SJiyong Parklevel specific local states are to be extracted from ``power_state`` and be
2569*54fd6939SJiyong Parkpopulated in the ``output_state`` (third argument) array. The functionality
2570*54fd6939SJiyong Parkis similar to the ``validate_power_state`` function described above and is
2571*54fd6939SJiyong Parkenvisaged to be used in case the validity of ``power_state`` depend on the
2572*54fd6939SJiyong Parktargeted power domain. If the ``power_state`` is invalid for the targeted power
2573*54fd6939SJiyong Parkdomain, the platform must return PSCI_E_INVALID_PARAMS as error. If this
2574*54fd6939SJiyong Parkfunction is not implemented, then the generic implementation relies on
2575*54fd6939SJiyong Park``validate_power_state`` function to translate the ``power_state``.
2576*54fd6939SJiyong Park
2577*54fd6939SJiyong ParkThis function can also be used in case the platform wants to support local
2578*54fd6939SJiyong Parkpower state encoding for ``power_state`` parameter of PSCI_STAT_COUNT/RESIDENCY
2579*54fd6939SJiyong ParkAPIs as described in Section 5.18 of `PSCI`_.
2580*54fd6939SJiyong Park
2581*54fd6939SJiyong Parkplat_psci_ops.get_node_hw_state()
2582*54fd6939SJiyong Park.................................
2583*54fd6939SJiyong Park
2584*54fd6939SJiyong ParkThis is an optional function. If implemented this function is intended to return
2585*54fd6939SJiyong Parkthe power state of a node (identified by the first parameter, the ``MPIDR``) in
2586*54fd6939SJiyong Parkthe power domain topology (identified by the second parameter, ``power_level``),
2587*54fd6939SJiyong Parkas retrieved from a power controller or equivalent component on the platform.
2588*54fd6939SJiyong ParkUpon successful completion, the implementation must map and return the final
2589*54fd6939SJiyong Parkstatus among ``HW_ON``, ``HW_OFF`` or ``HW_STANDBY``. Upon encountering failures, it
2590*54fd6939SJiyong Parkmust return either ``PSCI_E_INVALID_PARAMS`` or ``PSCI_E_NOT_SUPPORTED`` as
2591*54fd6939SJiyong Parkappropriate.
2592*54fd6939SJiyong Park
2593*54fd6939SJiyong ParkImplementations are not expected to handle ``power_levels`` greater than
2594*54fd6939SJiyong Park``PLAT_MAX_PWR_LVL``.
2595*54fd6939SJiyong Park
2596*54fd6939SJiyong Parkplat_psci_ops.system_reset2()
2597*54fd6939SJiyong Park.............................
2598*54fd6939SJiyong Park
2599*54fd6939SJiyong ParkThis is an optional function. If implemented this function is
2600*54fd6939SJiyong Parkcalled during the ``SYSTEM_RESET2`` call to perform a reset
2601*54fd6939SJiyong Parkbased on the first parameter ``reset_type`` as specified in
2602*54fd6939SJiyong Park`PSCI`_. The parameter ``cookie`` can be used to pass additional
2603*54fd6939SJiyong Parkreset information. If the ``reset_type`` is not supported, the
2604*54fd6939SJiyong Parkfunction must return ``PSCI_E_NOT_SUPPORTED``. For architectural
2605*54fd6939SJiyong Parkresets, all failures must return ``PSCI_E_INVALID_PARAMETERS``
2606*54fd6939SJiyong Parkand vendor reset can return other PSCI error codes as defined
2607*54fd6939SJiyong Parkin `PSCI`_. On success this function will not return.
2608*54fd6939SJiyong Park
2609*54fd6939SJiyong Parkplat_psci_ops.write_mem_protect()
2610*54fd6939SJiyong Park.................................
2611*54fd6939SJiyong Park
2612*54fd6939SJiyong ParkThis is an optional function. If implemented it enables or disables the
2613*54fd6939SJiyong Park``MEM_PROTECT`` functionality based on the value of ``val``.
2614*54fd6939SJiyong ParkA non-zero value enables ``MEM_PROTECT`` and a value of zero
2615*54fd6939SJiyong Parkdisables it. Upon encountering failures it must return a negative value
2616*54fd6939SJiyong Parkand on success it must return 0.
2617*54fd6939SJiyong Park
2618*54fd6939SJiyong Parkplat_psci_ops.read_mem_protect()
2619*54fd6939SJiyong Park................................
2620*54fd6939SJiyong Park
2621*54fd6939SJiyong ParkThis is an optional function. If implemented it returns the current
2622*54fd6939SJiyong Parkstate of ``MEM_PROTECT`` via the ``val`` parameter.  Upon encountering
2623*54fd6939SJiyong Parkfailures it must return a negative value and on success it must
2624*54fd6939SJiyong Parkreturn 0.
2625*54fd6939SJiyong Park
2626*54fd6939SJiyong Parkplat_psci_ops.mem_protect_chk()
2627*54fd6939SJiyong Park...............................
2628*54fd6939SJiyong Park
2629*54fd6939SJiyong ParkThis is an optional function. If implemented it checks if a memory
2630*54fd6939SJiyong Parkregion defined by a base address ``base`` and with a size of ``length``
2631*54fd6939SJiyong Parkbytes is protected by ``MEM_PROTECT``.  If the region is protected
2632*54fd6939SJiyong Parkthen it must return 0, otherwise it must return a negative number.
2633*54fd6939SJiyong Park
2634*54fd6939SJiyong Park.. _porting_guide_imf_in_bl31:
2635*54fd6939SJiyong Park
2636*54fd6939SJiyong ParkInterrupt Management framework (in BL31)
2637*54fd6939SJiyong Park----------------------------------------
2638*54fd6939SJiyong Park
2639*54fd6939SJiyong ParkBL31 implements an Interrupt Management Framework (IMF) to manage interrupts
2640*54fd6939SJiyong Parkgenerated in either security state and targeted to EL1 or EL2 in the non-secure
2641*54fd6939SJiyong Parkstate or EL3/S-EL1 in the secure state. The design of this framework is
2642*54fd6939SJiyong Parkdescribed in the :ref:`Interrupt Management Framework`
2643*54fd6939SJiyong Park
2644*54fd6939SJiyong ParkA platform should export the following APIs to support the IMF. The following
2645*54fd6939SJiyong Parktext briefly describes each API and its implementation in Arm standard
2646*54fd6939SJiyong Parkplatforms. The API implementation depends upon the type of interrupt controller
2647*54fd6939SJiyong Parkpresent in the platform. Arm standard platform layer supports both
2648*54fd6939SJiyong Park`Arm Generic Interrupt Controller version 2.0 (GICv2)`_
2649*54fd6939SJiyong Parkand `3.0 (GICv3)`_. Juno builds the Arm platform layer to use GICv2 and the
2650*54fd6939SJiyong ParkFVP can be configured to use either GICv2 or GICv3 depending on the build flag
2651*54fd6939SJiyong Park``FVP_USE_GIC_DRIVER`` (See :ref:`build_options_arm_fvp_platform` for more
2652*54fd6939SJiyong Parkdetails).
2653*54fd6939SJiyong Park
2654*54fd6939SJiyong ParkSee also: :ref:`Interrupt Controller Abstraction APIs<Platform Interrupt Controller API>`.
2655*54fd6939SJiyong Park
2656*54fd6939SJiyong ParkFunction : plat_interrupt_type_to_line() [mandatory]
2657*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2658*54fd6939SJiyong Park
2659*54fd6939SJiyong Park::
2660*54fd6939SJiyong Park
2661*54fd6939SJiyong Park    Argument : uint32_t, uint32_t
2662*54fd6939SJiyong Park    Return   : uint32_t
2663*54fd6939SJiyong Park
2664*54fd6939SJiyong ParkThe Arm processor signals an interrupt exception either through the IRQ or FIQ
2665*54fd6939SJiyong Parkinterrupt line. The specific line that is signaled depends on how the interrupt
2666*54fd6939SJiyong Parkcontroller (IC) reports different interrupt types from an execution context in
2667*54fd6939SJiyong Parkeither security state. The IMF uses this API to determine which interrupt line
2668*54fd6939SJiyong Parkthe platform IC uses to signal each type of interrupt supported by the framework
2669*54fd6939SJiyong Parkfrom a given security state. This API must be invoked at EL3.
2670*54fd6939SJiyong Park
2671*54fd6939SJiyong ParkThe first parameter will be one of the ``INTR_TYPE_*`` values (see
2672*54fd6939SJiyong Park:ref:`Interrupt Management Framework`) indicating the target type of the
2673*54fd6939SJiyong Parkinterrupt, the second parameter is the security state of the originating
2674*54fd6939SJiyong Parkexecution context. The return result is the bit position in the ``SCR_EL3``
2675*54fd6939SJiyong Parkregister of the respective interrupt trap: IRQ=1, FIQ=2.
2676*54fd6939SJiyong Park
2677*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv2, S-EL1 interrupts are
2678*54fd6939SJiyong Parkconfigured as FIQs and Non-secure interrupts as IRQs from either security
2679*54fd6939SJiyong Parkstate.
2680*54fd6939SJiyong Park
2681*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv3, the interrupt line to be
2682*54fd6939SJiyong Parkconfigured depends on the security state of the execution context when the
2683*54fd6939SJiyong Parkinterrupt is signalled and are as follows:
2684*54fd6939SJiyong Park
2685*54fd6939SJiyong Park-  The S-EL1 interrupts are signaled as IRQ in S-EL0/1 context and as FIQ in
2686*54fd6939SJiyong Park   NS-EL0/1/2 context.
2687*54fd6939SJiyong Park-  The Non secure interrupts are signaled as FIQ in S-EL0/1 context and as IRQ
2688*54fd6939SJiyong Park   in the NS-EL0/1/2 context.
2689*54fd6939SJiyong Park-  The EL3 interrupts are signaled as FIQ in both S-EL0/1 and NS-EL0/1/2
2690*54fd6939SJiyong Park   context.
2691*54fd6939SJiyong Park
2692*54fd6939SJiyong ParkFunction : plat_ic_get_pending_interrupt_type() [mandatory]
2693*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2694*54fd6939SJiyong Park
2695*54fd6939SJiyong Park::
2696*54fd6939SJiyong Park
2697*54fd6939SJiyong Park    Argument : void
2698*54fd6939SJiyong Park    Return   : uint32_t
2699*54fd6939SJiyong Park
2700*54fd6939SJiyong ParkThis API returns the type of the highest priority pending interrupt at the
2701*54fd6939SJiyong Parkplatform IC. The IMF uses the interrupt type to retrieve the corresponding
2702*54fd6939SJiyong Parkhandler function. ``INTR_TYPE_INVAL`` is returned when there is no interrupt
2703*54fd6939SJiyong Parkpending. The valid interrupt types that can be returned are ``INTR_TYPE_EL3``,
2704*54fd6939SJiyong Park``INTR_TYPE_S_EL1`` and ``INTR_TYPE_NS``. This API must be invoked at EL3.
2705*54fd6939SJiyong Park
2706*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv2, the *Highest Priority
2707*54fd6939SJiyong ParkPending Interrupt Register* (``GICC_HPPIR``) is read to determine the id of
2708*54fd6939SJiyong Parkthe pending interrupt. The type of interrupt depends upon the id value as
2709*54fd6939SJiyong Parkfollows.
2710*54fd6939SJiyong Park
2711*54fd6939SJiyong Park#. id < 1022 is reported as a S-EL1 interrupt
2712*54fd6939SJiyong Park#. id = 1022 is reported as a Non-secure interrupt.
2713*54fd6939SJiyong Park#. id = 1023 is reported as an invalid interrupt type.
2714*54fd6939SJiyong Park
2715*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv3, the system register
2716*54fd6939SJiyong Park``ICC_HPPIR0_EL1``, *Highest Priority Pending group 0 Interrupt Register*,
2717*54fd6939SJiyong Parkis read to determine the id of the pending interrupt. The type of interrupt
2718*54fd6939SJiyong Parkdepends upon the id value as follows.
2719*54fd6939SJiyong Park
2720*54fd6939SJiyong Park#. id = ``PENDING_G1S_INTID`` (1020) is reported as a S-EL1 interrupt
2721*54fd6939SJiyong Park#. id = ``PENDING_G1NS_INTID`` (1021) is reported as a Non-secure interrupt.
2722*54fd6939SJiyong Park#. id = ``GIC_SPURIOUS_INTERRUPT`` (1023) is reported as an invalid interrupt type.
2723*54fd6939SJiyong Park#. All other interrupt id's are reported as EL3 interrupt.
2724*54fd6939SJiyong Park
2725*54fd6939SJiyong ParkFunction : plat_ic_get_pending_interrupt_id() [mandatory]
2726*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2727*54fd6939SJiyong Park
2728*54fd6939SJiyong Park::
2729*54fd6939SJiyong Park
2730*54fd6939SJiyong Park    Argument : void
2731*54fd6939SJiyong Park    Return   : uint32_t
2732*54fd6939SJiyong Park
2733*54fd6939SJiyong ParkThis API returns the id of the highest priority pending interrupt at the
2734*54fd6939SJiyong Parkplatform IC. ``INTR_ID_UNAVAILABLE`` is returned when there is no interrupt
2735*54fd6939SJiyong Parkpending.
2736*54fd6939SJiyong Park
2737*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv2, the *Highest Priority
2738*54fd6939SJiyong ParkPending Interrupt Register* (``GICC_HPPIR``) is read to determine the id of the
2739*54fd6939SJiyong Parkpending interrupt. The id that is returned by API depends upon the value of
2740*54fd6939SJiyong Parkthe id read from the interrupt controller as follows.
2741*54fd6939SJiyong Park
2742*54fd6939SJiyong Park#. id < 1022. id is returned as is.
2743*54fd6939SJiyong Park#. id = 1022. The *Aliased Highest Priority Pending Interrupt Register*
2744*54fd6939SJiyong Park   (``GICC_AHPPIR``) is read to determine the id of the non-secure interrupt.
2745*54fd6939SJiyong Park   This id is returned by the API.
2746*54fd6939SJiyong Park#. id = 1023. ``INTR_ID_UNAVAILABLE`` is returned.
2747*54fd6939SJiyong Park
2748*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv3, if the API is invoked from
2749*54fd6939SJiyong ParkEL3, the system register ``ICC_HPPIR0_EL1``, *Highest Priority Pending Interrupt
2750*54fd6939SJiyong Parkgroup 0 Register*, is read to determine the id of the pending interrupt. The id
2751*54fd6939SJiyong Parkthat is returned by API depends upon the value of the id read from the
2752*54fd6939SJiyong Parkinterrupt controller as follows.
2753*54fd6939SJiyong Park
2754*54fd6939SJiyong Park#. id < ``PENDING_G1S_INTID`` (1020). id is returned as is.
2755*54fd6939SJiyong Park#. id = ``PENDING_G1S_INTID`` (1020) or ``PENDING_G1NS_INTID`` (1021). The system
2756*54fd6939SJiyong Park   register ``ICC_HPPIR1_EL1``, *Highest Priority Pending Interrupt group 1
2757*54fd6939SJiyong Park   Register* is read to determine the id of the group 1 interrupt. This id
2758*54fd6939SJiyong Park   is returned by the API as long as it is a valid interrupt id
2759*54fd6939SJiyong Park#. If the id is any of the special interrupt identifiers,
2760*54fd6939SJiyong Park   ``INTR_ID_UNAVAILABLE`` is returned.
2761*54fd6939SJiyong Park
2762*54fd6939SJiyong ParkWhen the API invoked from S-EL1 for GICv3 systems, the id read from system
2763*54fd6939SJiyong Parkregister ``ICC_HPPIR1_EL1``, *Highest Priority Pending group 1 Interrupt
2764*54fd6939SJiyong ParkRegister*, is returned if is not equal to GIC_SPURIOUS_INTERRUPT (1023) else
2765*54fd6939SJiyong Park``INTR_ID_UNAVAILABLE`` is returned.
2766*54fd6939SJiyong Park
2767*54fd6939SJiyong ParkFunction : plat_ic_acknowledge_interrupt() [mandatory]
2768*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2769*54fd6939SJiyong Park
2770*54fd6939SJiyong Park::
2771*54fd6939SJiyong Park
2772*54fd6939SJiyong Park    Argument : void
2773*54fd6939SJiyong Park    Return   : uint32_t
2774*54fd6939SJiyong Park
2775*54fd6939SJiyong ParkThis API is used by the CPU to indicate to the platform IC that processing of
2776*54fd6939SJiyong Parkthe highest pending interrupt has begun. It should return the raw, unmodified
2777*54fd6939SJiyong Parkvalue obtained from the interrupt controller when acknowledging an interrupt.
2778*54fd6939SJiyong ParkThe actual interrupt number shall be extracted from this raw value using the API
2779*54fd6939SJiyong Park`plat_ic_get_interrupt_id()<plat_ic_get_interrupt_id>`.
2780*54fd6939SJiyong Park
2781*54fd6939SJiyong ParkThis function in Arm standard platforms using GICv2, reads the *Interrupt
2782*54fd6939SJiyong ParkAcknowledge Register* (``GICC_IAR``). This changes the state of the highest
2783*54fd6939SJiyong Parkpriority pending interrupt from pending to active in the interrupt controller.
2784*54fd6939SJiyong ParkIt returns the value read from the ``GICC_IAR``, unmodified.
2785*54fd6939SJiyong Park
2786*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv3, if the API is invoked
2787*54fd6939SJiyong Parkfrom EL3, the function reads the system register ``ICC_IAR0_EL1``, *Interrupt
2788*54fd6939SJiyong ParkAcknowledge Register group 0*. If the API is invoked from S-EL1, the function
2789*54fd6939SJiyong Parkreads the system register ``ICC_IAR1_EL1``, *Interrupt Acknowledge Register
2790*54fd6939SJiyong Parkgroup 1*. The read changes the state of the highest pending interrupt from
2791*54fd6939SJiyong Parkpending to active in the interrupt controller. The value read is returned
2792*54fd6939SJiyong Parkunmodified.
2793*54fd6939SJiyong Park
2794*54fd6939SJiyong ParkThe TSP uses this API to start processing of the secure physical timer
2795*54fd6939SJiyong Parkinterrupt.
2796*54fd6939SJiyong Park
2797*54fd6939SJiyong ParkFunction : plat_ic_end_of_interrupt() [mandatory]
2798*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2799*54fd6939SJiyong Park
2800*54fd6939SJiyong Park::
2801*54fd6939SJiyong Park
2802*54fd6939SJiyong Park    Argument : uint32_t
2803*54fd6939SJiyong Park    Return   : void
2804*54fd6939SJiyong Park
2805*54fd6939SJiyong ParkThis API is used by the CPU to indicate to the platform IC that processing of
2806*54fd6939SJiyong Parkthe interrupt corresponding to the id (passed as the parameter) has
2807*54fd6939SJiyong Parkfinished. The id should be the same as the id returned by the
2808*54fd6939SJiyong Park``plat_ic_acknowledge_interrupt()`` API.
2809*54fd6939SJiyong Park
2810*54fd6939SJiyong ParkArm standard platforms write the id to the *End of Interrupt Register*
2811*54fd6939SJiyong Park(``GICC_EOIR``) in case of GICv2, and to ``ICC_EOIR0_EL1`` or ``ICC_EOIR1_EL1``
2812*54fd6939SJiyong Parksystem register in case of GICv3 depending on where the API is invoked from,
2813*54fd6939SJiyong ParkEL3 or S-EL1. This deactivates the corresponding interrupt in the interrupt
2814*54fd6939SJiyong Parkcontroller.
2815*54fd6939SJiyong Park
2816*54fd6939SJiyong ParkThe TSP uses this API to finish processing of the secure physical timer
2817*54fd6939SJiyong Parkinterrupt.
2818*54fd6939SJiyong Park
2819*54fd6939SJiyong ParkFunction : plat_ic_get_interrupt_type() [mandatory]
2820*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2821*54fd6939SJiyong Park
2822*54fd6939SJiyong Park::
2823*54fd6939SJiyong Park
2824*54fd6939SJiyong Park    Argument : uint32_t
2825*54fd6939SJiyong Park    Return   : uint32_t
2826*54fd6939SJiyong Park
2827*54fd6939SJiyong ParkThis API returns the type of the interrupt id passed as the parameter.
2828*54fd6939SJiyong Park``INTR_TYPE_INVAL`` is returned if the id is invalid. If the id is valid, a valid
2829*54fd6939SJiyong Parkinterrupt type (one of ``INTR_TYPE_EL3``, ``INTR_TYPE_S_EL1`` and ``INTR_TYPE_NS``) is
2830*54fd6939SJiyong Parkreturned depending upon how the interrupt has been configured by the platform
2831*54fd6939SJiyong ParkIC. This API must be invoked at EL3.
2832*54fd6939SJiyong Park
2833*54fd6939SJiyong ParkArm standard platforms using GICv2 configures S-EL1 interrupts as Group0 interrupts
2834*54fd6939SJiyong Parkand Non-secure interrupts as Group1 interrupts. It reads the group value
2835*54fd6939SJiyong Parkcorresponding to the interrupt id from the relevant *Interrupt Group Register*
2836*54fd6939SJiyong Park(``GICD_IGROUPRn``). It uses the group value to determine the type of interrupt.
2837*54fd6939SJiyong Park
2838*54fd6939SJiyong ParkIn the case of Arm standard platforms using GICv3, both the *Interrupt Group
2839*54fd6939SJiyong ParkRegister* (``GICD_IGROUPRn``) and *Interrupt Group Modifier Register*
2840*54fd6939SJiyong Park(``GICD_IGRPMODRn``) is read to figure out whether the interrupt is configured
2841*54fd6939SJiyong Parkas Group 0 secure interrupt, Group 1 secure interrupt or Group 1 NS interrupt.
2842*54fd6939SJiyong Park
2843*54fd6939SJiyong ParkCrash Reporting mechanism (in BL31)
2844*54fd6939SJiyong Park-----------------------------------
2845*54fd6939SJiyong Park
2846*54fd6939SJiyong ParkBL31 implements a crash reporting mechanism which prints the various registers
2847*54fd6939SJiyong Parkof the CPU to enable quick crash analysis and debugging. This mechanism relies
2848*54fd6939SJiyong Parkon the platform implementing ``plat_crash_console_init``,
2849*54fd6939SJiyong Park``plat_crash_console_putc`` and ``plat_crash_console_flush``.
2850*54fd6939SJiyong Park
2851*54fd6939SJiyong ParkThe file ``plat/common/aarch64/crash_console_helpers.S`` contains sample
2852*54fd6939SJiyong Parkimplementation of all of them. Platforms may include this file to their
2853*54fd6939SJiyong Parkmakefiles in order to benefit from them. By default, they will cause the crash
2854*54fd6939SJiyong Parkoutput to be routed over the normal console infrastructure and get printed on
2855*54fd6939SJiyong Parkconsoles configured to output in crash state. ``console_set_scope()`` can be
2856*54fd6939SJiyong Parkused to control whether a console is used for crash output.
2857*54fd6939SJiyong Park
2858*54fd6939SJiyong Park.. note::
2859*54fd6939SJiyong Park   Platforms are responsible for making sure that they only mark consoles for
2860*54fd6939SJiyong Park   use in the crash scope that are able to support this, i.e. that are written
2861*54fd6939SJiyong Park   in assembly and conform with the register clobber rules for putc()
2862*54fd6939SJiyong Park   (x0-x2, x16-x17) and flush() (x0-x3, x16-x17) crash callbacks.
2863*54fd6939SJiyong Park
2864*54fd6939SJiyong ParkIn some cases (such as debugging very early crashes that happen before the
2865*54fd6939SJiyong Parknormal boot console can be set up), platforms may want to control crash output
2866*54fd6939SJiyong Parkmore explicitly. These platforms may instead provide custom implementations for
2867*54fd6939SJiyong Parkthese. They are executed outside of a C environment and without a stack. Many
2868*54fd6939SJiyong Parkconsole drivers provide functions named ``console_xxx_core_init/putc/flush``
2869*54fd6939SJiyong Parkthat are designed to be used by these functions. See Arm platforms (like juno)
2870*54fd6939SJiyong Parkfor an example of this.
2871*54fd6939SJiyong Park
2872*54fd6939SJiyong ParkFunction : plat_crash_console_init [mandatory]
2873*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2874*54fd6939SJiyong Park
2875*54fd6939SJiyong Park::
2876*54fd6939SJiyong Park
2877*54fd6939SJiyong Park    Argument : void
2878*54fd6939SJiyong Park    Return   : int
2879*54fd6939SJiyong Park
2880*54fd6939SJiyong ParkThis API is used by the crash reporting mechanism to initialize the crash
2881*54fd6939SJiyong Parkconsole. It must only use the general purpose registers x0 through x7 to do the
2882*54fd6939SJiyong Parkinitialization and returns 1 on success.
2883*54fd6939SJiyong Park
2884*54fd6939SJiyong ParkFunction : plat_crash_console_putc [mandatory]
2885*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2886*54fd6939SJiyong Park
2887*54fd6939SJiyong Park::
2888*54fd6939SJiyong Park
2889*54fd6939SJiyong Park    Argument : int
2890*54fd6939SJiyong Park    Return   : int
2891*54fd6939SJiyong Park
2892*54fd6939SJiyong ParkThis API is used by the crash reporting mechanism to print a character on the
2893*54fd6939SJiyong Parkdesignated crash console. It must only use general purpose registers x1 and
2894*54fd6939SJiyong Parkx2 to do its work. The parameter and the return value are in general purpose
2895*54fd6939SJiyong Parkregister x0.
2896*54fd6939SJiyong Park
2897*54fd6939SJiyong ParkFunction : plat_crash_console_flush [mandatory]
2898*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2899*54fd6939SJiyong Park
2900*54fd6939SJiyong Park::
2901*54fd6939SJiyong Park
2902*54fd6939SJiyong Park    Argument : void
2903*54fd6939SJiyong Park    Return   : void
2904*54fd6939SJiyong Park
2905*54fd6939SJiyong ParkThis API is used by the crash reporting mechanism to force write of all buffered
2906*54fd6939SJiyong Parkdata on the designated crash console. It should only use general purpose
2907*54fd6939SJiyong Parkregisters x0 through x5 to do its work.
2908*54fd6939SJiyong Park
2909*54fd6939SJiyong Park.. _External Abort handling and RAS Support:
2910*54fd6939SJiyong Park
2911*54fd6939SJiyong ParkExternal Abort handling and RAS Support
2912*54fd6939SJiyong Park---------------------------------------
2913*54fd6939SJiyong Park
2914*54fd6939SJiyong ParkFunction : plat_ea_handler
2915*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~
2916*54fd6939SJiyong Park
2917*54fd6939SJiyong Park::
2918*54fd6939SJiyong Park
2919*54fd6939SJiyong Park    Argument : int
2920*54fd6939SJiyong Park    Argument : uint64_t
2921*54fd6939SJiyong Park    Argument : void *
2922*54fd6939SJiyong Park    Argument : void *
2923*54fd6939SJiyong Park    Argument : uint64_t
2924*54fd6939SJiyong Park    Return   : void
2925*54fd6939SJiyong Park
2926*54fd6939SJiyong ParkThis function is invoked by the RAS framework for the platform to handle an
2927*54fd6939SJiyong ParkExternal Abort received at EL3. The intention of the function is to attempt to
2928*54fd6939SJiyong Parkresolve the cause of External Abort and return; if that's not possible, to
2929*54fd6939SJiyong Parkinitiate orderly shutdown of the system.
2930*54fd6939SJiyong Park
2931*54fd6939SJiyong ParkThe first parameter (``int ea_reason``) indicates the reason for External Abort.
2932*54fd6939SJiyong ParkIts value is one of ``ERROR_EA_*`` constants defined in ``ea_handle.h``.
2933*54fd6939SJiyong Park
2934*54fd6939SJiyong ParkThe second parameter (``uint64_t syndrome``) is the respective syndrome
2935*54fd6939SJiyong Parkpresented to EL3 after having received the External Abort. Depending on the
2936*54fd6939SJiyong Parknature of the abort (as can be inferred from the ``ea_reason`` parameter), this
2937*54fd6939SJiyong Parkcan be the content of either ``ESR_EL3`` or ``DISR_EL1``.
2938*54fd6939SJiyong Park
2939*54fd6939SJiyong ParkThe third parameter (``void *cookie``) is unused for now. The fourth parameter
2940*54fd6939SJiyong Park(``void *handle``) is a pointer to the preempted context. The fifth parameter
2941*54fd6939SJiyong Park(``uint64_t flags``) indicates the preempted security state. These parameters
2942*54fd6939SJiyong Parkare received from the top-level exception handler.
2943*54fd6939SJiyong Park
2944*54fd6939SJiyong ParkIf ``RAS_EXTENSION`` is set to ``1``, the default implementation of this
2945*54fd6939SJiyong Parkfunction iterates through RAS handlers registered by the platform. If any of the
2946*54fd6939SJiyong ParkRAS handlers resolve the External Abort, no further action is taken.
2947*54fd6939SJiyong Park
2948*54fd6939SJiyong ParkIf ``RAS_EXTENSION`` is set to ``0``, or if none of the platform RAS handlers
2949*54fd6939SJiyong Parkcould resolve the External Abort, the default implementation prints an error
2950*54fd6939SJiyong Parkmessage, and panics.
2951*54fd6939SJiyong Park
2952*54fd6939SJiyong ParkFunction : plat_handle_uncontainable_ea
2953*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2954*54fd6939SJiyong Park
2955*54fd6939SJiyong Park::
2956*54fd6939SJiyong Park
2957*54fd6939SJiyong Park    Argument : int
2958*54fd6939SJiyong Park    Argument : uint64_t
2959*54fd6939SJiyong Park    Return   : void
2960*54fd6939SJiyong Park
2961*54fd6939SJiyong ParkThis function is invoked by the RAS framework when an External Abort of
2962*54fd6939SJiyong ParkUncontainable type is received at EL3. Due to the critical nature of
2963*54fd6939SJiyong ParkUncontainable errors, the intention of this function is to initiate orderly
2964*54fd6939SJiyong Parkshutdown of the system, and is not expected to return.
2965*54fd6939SJiyong Park
2966*54fd6939SJiyong ParkThis function must be implemented in assembly.
2967*54fd6939SJiyong Park
2968*54fd6939SJiyong ParkThe first and second parameters are the same as that of ``plat_ea_handler``.
2969*54fd6939SJiyong Park
2970*54fd6939SJiyong ParkThe default implementation of this function calls
2971*54fd6939SJiyong Park``report_unhandled_exception``.
2972*54fd6939SJiyong Park
2973*54fd6939SJiyong ParkFunction : plat_handle_double_fault
2974*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2975*54fd6939SJiyong Park
2976*54fd6939SJiyong Park::
2977*54fd6939SJiyong Park
2978*54fd6939SJiyong Park    Argument : int
2979*54fd6939SJiyong Park    Argument : uint64_t
2980*54fd6939SJiyong Park    Return   : void
2981*54fd6939SJiyong Park
2982*54fd6939SJiyong ParkThis function is invoked by the RAS framework when another External Abort is
2983*54fd6939SJiyong Parkreceived at EL3 while one is already being handled. I.e., a call to
2984*54fd6939SJiyong Park``plat_ea_handler`` is outstanding. Due to its critical nature, the intention of
2985*54fd6939SJiyong Parkthis function is to initiate orderly shutdown of the system, and is not expected
2986*54fd6939SJiyong Parkrecover or return.
2987*54fd6939SJiyong Park
2988*54fd6939SJiyong ParkThis function must be implemented in assembly.
2989*54fd6939SJiyong Park
2990*54fd6939SJiyong ParkThe first and second parameters are the same as that of ``plat_ea_handler``.
2991*54fd6939SJiyong Park
2992*54fd6939SJiyong ParkThe default implementation of this function calls
2993*54fd6939SJiyong Park``report_unhandled_exception``.
2994*54fd6939SJiyong Park
2995*54fd6939SJiyong ParkFunction : plat_handle_el3_ea
2996*54fd6939SJiyong Park~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2997*54fd6939SJiyong Park
2998*54fd6939SJiyong Park::
2999*54fd6939SJiyong Park
3000*54fd6939SJiyong Park    Return   : void
3001*54fd6939SJiyong Park
3002*54fd6939SJiyong ParkThis function is invoked when an External Abort is received while executing in
3003*54fd6939SJiyong ParkEL3. Due to its critical nature, the intention of this function is to initiate
3004*54fd6939SJiyong Parkorderly shutdown of the system, and is not expected recover or return.
3005*54fd6939SJiyong Park
3006*54fd6939SJiyong ParkThis function must be implemented in assembly.
3007*54fd6939SJiyong Park
3008*54fd6939SJiyong ParkThe default implementation of this function calls
3009*54fd6939SJiyong Park``report_unhandled_exception``.
3010*54fd6939SJiyong Park
3011*54fd6939SJiyong ParkBuild flags
3012*54fd6939SJiyong Park-----------
3013*54fd6939SJiyong Park
3014*54fd6939SJiyong ParkThere are some build flags which can be defined by the platform to control
3015*54fd6939SJiyong Parkinclusion or exclusion of certain BL stages from the FIP image. These flags
3016*54fd6939SJiyong Parkneed to be defined in the platform makefile which will get included by the
3017*54fd6939SJiyong Parkbuild system.
3018*54fd6939SJiyong Park
3019*54fd6939SJiyong Park-  **NEED_BL33**
3020*54fd6939SJiyong Park   By default, this flag is defined ``yes`` by the build system and ``BL33``
3021*54fd6939SJiyong Park   build option should be supplied as a build option. The platform has the
3022*54fd6939SJiyong Park   option of excluding the BL33 image in the ``fip`` image by defining this flag
3023*54fd6939SJiyong Park   to ``no``. If any of the options ``EL3_PAYLOAD_BASE`` or ``PRELOADED_BL33_BASE``
3024*54fd6939SJiyong Park   are used, this flag will be set to ``no`` automatically.
3025*54fd6939SJiyong Park
3026*54fd6939SJiyong ParkPlatform include paths
3027*54fd6939SJiyong Park----------------------
3028*54fd6939SJiyong Park
3029*54fd6939SJiyong ParkPlatforms are allowed to add more include paths to be passed to the compiler.
3030*54fd6939SJiyong ParkThe ``PLAT_INCLUDES`` variable is used for this purpose. This is needed in
3031*54fd6939SJiyong Parkparticular for the file ``platform_def.h``.
3032*54fd6939SJiyong Park
3033*54fd6939SJiyong ParkExample:
3034*54fd6939SJiyong Park
3035*54fd6939SJiyong Park.. code:: c
3036*54fd6939SJiyong Park
3037*54fd6939SJiyong Park  PLAT_INCLUDES  += -Iinclude/plat/myplat/include
3038*54fd6939SJiyong Park
3039*54fd6939SJiyong ParkC Library
3040*54fd6939SJiyong Park---------
3041*54fd6939SJiyong Park
3042*54fd6939SJiyong ParkTo avoid subtle toolchain behavioral dependencies, the header files provided
3043*54fd6939SJiyong Parkby the compiler are not used. The software is built with the ``-nostdinc`` flag
3044*54fd6939SJiyong Parkto ensure no headers are included from the toolchain inadvertently. Instead the
3045*54fd6939SJiyong Parkrequired headers are included in the TF-A source tree. The library only
3046*54fd6939SJiyong Parkcontains those C library definitions required by the local implementation. If
3047*54fd6939SJiyong Parkmore functionality is required, the needed library functions will need to be
3048*54fd6939SJiyong Parkadded to the local implementation.
3049*54fd6939SJiyong Park
3050*54fd6939SJiyong ParkSome C headers have been obtained from `FreeBSD`_ and `SCC`_, while others have
3051*54fd6939SJiyong Parkbeen written specifically for TF-A. Some implementation files have been obtained
3052*54fd6939SJiyong Parkfrom `FreeBSD`_, others have been written specifically for TF-A as well. The
3053*54fd6939SJiyong Parkfiles can be found in ``include/lib/libc`` and ``lib/libc``.
3054*54fd6939SJiyong Park
3055*54fd6939SJiyong ParkSCC can be found in http://www.simple-cc.org/. A copy of the `FreeBSD`_ sources
3056*54fd6939SJiyong Parkcan be obtained from http://github.com/freebsd/freebsd.
3057*54fd6939SJiyong Park
3058*54fd6939SJiyong ParkStorage abstraction layer
3059*54fd6939SJiyong Park-------------------------
3060*54fd6939SJiyong Park
3061*54fd6939SJiyong ParkIn order to improve platform independence and portability a storage abstraction
3062*54fd6939SJiyong Parklayer is used to load data from non-volatile platform storage. Currently
3063*54fd6939SJiyong Parkstorage access is only required by BL1 and BL2 phases and performed inside the
3064*54fd6939SJiyong Park``load_image()`` function in ``bl_common.c``.
3065*54fd6939SJiyong Park
3066*54fd6939SJiyong Park.. uml:: ../resources/diagrams/plantuml/io_framework_usage_overview.puml
3067*54fd6939SJiyong Park
3068*54fd6939SJiyong ParkIt is mandatory to implement at least one storage driver. For the Arm
3069*54fd6939SJiyong Parkdevelopment platforms the Firmware Image Package (FIP) driver is provided as
3070*54fd6939SJiyong Parkthe default means to load data from storage (see :ref:`firmware_design_fip`).
3071*54fd6939SJiyong ParkThe storage layer is described in the header file
3072*54fd6939SJiyong Park``include/drivers/io/io_storage.h``. The implementation of the common library is
3073*54fd6939SJiyong Parkin ``drivers/io/io_storage.c`` and the driver files are located in
3074*54fd6939SJiyong Park``drivers/io/``.
3075*54fd6939SJiyong Park
3076*54fd6939SJiyong Park.. uml:: ../resources/diagrams/plantuml/io_arm_class_diagram.puml
3077*54fd6939SJiyong Park
3078*54fd6939SJiyong ParkEach IO driver must provide ``io_dev_*`` structures, as described in
3079*54fd6939SJiyong Park``drivers/io/io_driver.h``. These are returned via a mandatory registration
3080*54fd6939SJiyong Parkfunction that is called on platform initialization. The semi-hosting driver
3081*54fd6939SJiyong Parkimplementation in ``io_semihosting.c`` can be used as an example.
3082*54fd6939SJiyong Park
3083*54fd6939SJiyong ParkEach platform should register devices and their drivers via the storage
3084*54fd6939SJiyong Parkabstraction layer. These drivers then need to be initialized by bootloader
3085*54fd6939SJiyong Parkphases as required in their respective ``blx_platform_setup()`` functions.
3086*54fd6939SJiyong Park
3087*54fd6939SJiyong Park.. uml:: ../resources/diagrams/plantuml/io_dev_registration.puml
3088*54fd6939SJiyong Park
3089*54fd6939SJiyong ParkThe storage abstraction layer provides mechanisms (``io_dev_init()``) to
3090*54fd6939SJiyong Parkinitialize storage devices before IO operations are called.
3091*54fd6939SJiyong Park
3092*54fd6939SJiyong Park.. uml:: ../resources/diagrams/plantuml/io_dev_init_and_check.puml
3093*54fd6939SJiyong Park
3094*54fd6939SJiyong ParkThe basic operations supported by the layer
3095*54fd6939SJiyong Parkinclude ``open()``, ``close()``, ``read()``, ``write()``, ``size()`` and ``seek()``.
3096*54fd6939SJiyong ParkDrivers do not have to implement all operations, but each platform must
3097*54fd6939SJiyong Parkprovide at least one driver for a device capable of supporting generic
3098*54fd6939SJiyong Parkoperations such as loading a bootloader image.
3099*54fd6939SJiyong Park
3100*54fd6939SJiyong ParkThe current implementation only allows for known images to be loaded by the
3101*54fd6939SJiyong Parkfirmware. These images are specified by using their identifiers, as defined in
3102*54fd6939SJiyong Park``include/plat/common/common_def.h`` (or a separate header file included from
3103*54fd6939SJiyong Parkthere). The platform layer (``plat_get_image_source()``) then returns a reference
3104*54fd6939SJiyong Parkto a device and a driver-specific ``spec`` which will be understood by the driver
3105*54fd6939SJiyong Parkto allow access to the image data.
3106*54fd6939SJiyong Park
3107*54fd6939SJiyong ParkThe layer is designed in such a way that is it possible to chain drivers with
3108*54fd6939SJiyong Parkother drivers. For example, file-system drivers may be implemented on top of
3109*54fd6939SJiyong Parkphysical block devices, both represented by IO devices with corresponding
3110*54fd6939SJiyong Parkdrivers. In such a case, the file-system "binding" with the block device may
3111*54fd6939SJiyong Parkbe deferred until the file-system device is initialised.
3112*54fd6939SJiyong Park
3113*54fd6939SJiyong ParkThe abstraction currently depends on structures being statically allocated
3114*54fd6939SJiyong Parkby the drivers and callers, as the system does not yet provide a means of
3115*54fd6939SJiyong Parkdynamically allocating memory. This may also have the affect of limiting the
3116*54fd6939SJiyong Parkamount of open resources per driver.
3117*54fd6939SJiyong Park
3118*54fd6939SJiyong Park--------------
3119*54fd6939SJiyong Park
3120*54fd6939SJiyong Park*Copyright (c) 2013-2021, Arm Limited and Contributors. All rights reserved.*
3121*54fd6939SJiyong Park
3122*54fd6939SJiyong Park.. _PSCI: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
3123*54fd6939SJiyong Park.. _Arm Generic Interrupt Controller version 2.0 (GICv2): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0048b/index.html
3124*54fd6939SJiyong Park.. _3.0 (GICv3): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0069b/index.html
3125*54fd6939SJiyong Park.. _FreeBSD: https://www.freebsd.org
3126*54fd6939SJiyong Park.. _SCC: http://www.simple-cc.org/
3127