blob: c8cf3f3932fc9aa61163be8af820cebf70e19180 [file] [log] [blame]
Dan Handley610e7e12018-03-01 18:44:00 +00001PSCI Library Integration guide for Armv8-A AArch32 systems
Douglas Raillardd7c21b72017-06-28 15:23:03 +01002==========================================================
3
4
Douglas Raillardd7c21b72017-06-28 15:23:03 +01005
6.. contents::
7
8This document describes the PSCI library interface with a focus on how to
Dan Handley610e7e12018-03-01 18:44:00 +00009integrate with a suitable Trusted OS for an Armv8-A AArch32 system. The PSCI
Douglas Raillardd7c21b72017-06-28 15:23:03 +010010Library implements the PSCI Standard as described in `PSCI spec`_ and is meant
11to be integrated with EL3 Runtime Software which invokes the PSCI Library
12interface appropriately. **EL3 Runtime Software** refers to software executing
13at the highest secure privileged mode, which is EL3 in AArch64 or Secure SVC/
14Monitor mode in AArch32, and provides runtime services to the non-secure world.
15The runtime service request is made via SMC (Secure Monitor Call) and the call
16must adhere to `SMCCC`_. In AArch32, EL3 Runtime Software may additionally
17include Trusted OS functionality. A minimal AArch32 Secure Payload, SP-MIN, is
Dan Handley610e7e12018-03-01 18:44:00 +000018provided in Trusted Firmware-A (TF-A) to illustrate the usage and integration
19of the PSCI library. The description of PSCI library interface and its
20integration with EL3 Runtime Software in this document is targeted towards
21AArch32 systems.
Douglas Raillardd7c21b72017-06-28 15:23:03 +010022
23Generic call sequence for PSCI Library interface (AArch32)
24----------------------------------------------------------
25
26The generic call sequence of PSCI Library interfaces (see
Douglas Raillard30d7b362017-06-28 16:14:55 +010027`PSCI Library Interface`_) during cold boot in AArch32
Douglas Raillardd7c21b72017-06-28 15:23:03 +010028system is described below:
29
30#. After cold reset, the EL3 Runtime Software performs its cold boot
31 initialization including the PSCI library pre-requisites mentioned in
Douglas Raillard30d7b362017-06-28 16:14:55 +010032 `PSCI Library Interface`_, and also the necessary platform
Douglas Raillardd7c21b72017-06-28 15:23:03 +010033 setup.
34
35#. Call ``psci_setup()`` in Monitor mode.
36
37#. Optionally call ``psci_register_spd_pm_hook()`` to register callbacks to
38 do bookkeeping for the EL3 Runtime Software during power management.
39
40#. Call ``psci_prepare_next_non_secure_ctx()`` to initialize the non-secure CPU
41 context.
42
43#. Get the non-secure ``cpu_context_t`` for the current CPU by calling
44 ``cm_get_context()`` , then programming the registers in the non-secure
45 context and exiting to non-secure world. If the EL3 Runtime Software needs
46 additional configuration to be set for non-secure context, like routing
47 FIQs to the secure world, the values of the registers can be modified prior
Douglas Raillard30d7b362017-06-28 16:14:55 +010048 to programming. See `PSCI CPU context management`_ for more
Douglas Raillardd7c21b72017-06-28 15:23:03 +010049 details on CPU context management.
50
51The generic call sequence of PSCI library interfaces during warm boot in
52AArch32 systems is described below:
53
54#. After warm reset, the EL3 Runtime Software performs the necessary warm
55 boot initialization including the PSCI library pre-requisites mentioned in
Douglas Raillard30d7b362017-06-28 16:14:55 +010056 `PSCI Library Interface`_ (Note that the Data cache
Douglas Raillardd7c21b72017-06-28 15:23:03 +010057 **must not** be enabled).
58
59#. Call ``psci_warmboot_entrypoint()`` in Monitor mode. This interface
60 initializes/restores the non-secure CPU context as well.
61
62#. Do step 5 of the cold boot call sequence described above.
63
64The generic call sequence of PSCI library interfaces on receipt of a PSCI SMC
65on an AArch32 system is described below:
66
67#. On receipt of an SMC, save the register context as per `SMCCC`_.
68
69#. If the SMC function identifier corresponds to a SMC32 PSCI API, construct
70 the appropriate arguments and call the ``psci_smc_handler()`` interface.
71 The invocation may or may not return back to the caller depending on
72 whether the PSCI API resulted in power down of the CPU.
73
74#. If ``psci_smc_handler()`` returns, populate the return value in R0 (AArch32)/
75 X0 (AArch64) and restore other registers as per `SMCCC`_.
76
Douglas Raillard30d7b362017-06-28 16:14:55 +010077PSCI CPU context management
78---------------------------
Douglas Raillardd7c21b72017-06-28 15:23:03 +010079
80PSCI library is in charge of initializing/restoring the non-secure CPU system
81registers according to `PSCI specification`_ during cold/warm boot.
82This is referred to as ``PSCI CPU Context Management``. Registers that need to
83be preserved across CPU power down/power up cycles are maintained in
84``cpu_context_t`` data structure. The initialization of other non-secure CPU
85system registers which do not require coordination with the EL3 Runtime
86Software is done directly by the PSCI library (see ``cm_prepare_el3_exit()``).
87
88The EL3 Runtime Software is responsible for managing register context
89during switch between Normal and Secure worlds. The register context to be
90saved and restored depends on the mechanism used to trigger the world switch.
91For example, if the world switch was triggered by an SMC call, then the
92registers need to be saved and restored according to `SMCCC`_. In AArch64,
93due to the tight integration with BL31, both BL31 and PSCI library
94use the same ``cpu_context_t`` data structure for PSCI CPU context management
95and register context management during world switch. This cannot be assumed
96for AArch32 EL3 Runtime Software since most AArch32 Trusted OSes already implement
97a mechanism for register context management during world switch. Hence, when
98the PSCI library is integrated with a AArch32 EL3 Runtime Software, the
99``cpu_context_t`` is stripped down for just PSCI CPU context management.
100
101During cold/warm boot, after invoking appropriate PSCI library interfaces, it
102is expected that the EL3 Runtime Software will query the ``cpu_context_t`` and
103write appropriate values to the corresponding system registers. This mechanism
104resolves 2 additional problems for AArch32 EL3 Runtime Software:
105
106#. Values for certain system registers like SCR and SCTLR cannot be
107 unilaterally determined by PSCI library and need inputs from the EL3
108 Runtime Software. Using ``cpu_context_t`` as an intermediary data store
109 allows EL3 Runtime Software to modify the register values appropriately
110 before programming them.
111
112#. The PSCI library provides appropriate LR and SPSR values (entrypoint
113 information) for exit into non-secure world. Using ``cpu_context_t`` as an
114 intermediary data store allows the EL3 Runtime Software to store these
115 values safely until it is ready for exit to non-secure world.
116
117Currently the ``cpu_context_t`` data structure for AArch32 stores the following
118registers: R0 - R3, LR (R14), SCR, SPSR, SCTLR.
119
120The EL3 Runtime Software must implement accessors to get/set pointers
121to CPU context ``cpu_context_t`` data and these are described in
Douglas Raillard30d7b362017-06-28 16:14:55 +0100122`CPU Context management API`_.
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100123
124PSCI Library Interface
125----------------------
126
127The PSCI library implements the `PSCI Specification`_. The interfaces
John Tsichritzis2bcd5322019-05-13 11:20:05 +0100128to this library are declared in ``psci_lib.h`` and are as listed below:
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100129
130.. code:: c
131
132 u_register_t psci_smc_handler(uint32_t smc_fid, u_register_t x1,
133 u_register_t x2, u_register_t x3,
134 u_register_t x4, void *cookie,
135 void *handle, u_register_t flags);
136 int psci_setup(const psci_lib_args_t *lib_args);
137 void psci_warmboot_entrypoint(void);
138 void psci_register_spd_pm_hook(const spd_pm_ops_t *pm);
139 void psci_prepare_next_non_secure_ctx(entry_point_info_t *next_image_info);
140
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100141The CPU context data 'cpu_context_t' is programmed to the registers differently
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100142when PSCI is integrated with an AArch32 EL3 Runtime Software compared to
143when the PSCI is integrated with an AArch64 EL3 Runtime Software (BL31). For
144example, in the case of AArch64, there is no need to retrieve ``cpu_context_t``
145data and program the registers as it will done implicitly as part of
146``el3_exit``. The description below of the PSCI interfaces is targeted at
147integration with an AArch32 EL3 Runtime Software.
148
149The PSCI library is responsible for initializing/restoring the non-secure world
150to an appropriate state after boot and may choose to directly program the
151non-secure system registers. The PSCI generic code takes care not to directly
152modify any of the system registers affecting the secure world and instead
153returns the values to be programmed to these registers via ``cpu_context_t``.
154The EL3 Runtime Software is responsible for programming those registers and
155can use the proposed values provided in the ``cpu_context_t``, modifying the
156values if required.
157
158PSCI library needs the flexibility to access both secure and non-secure
159copies of banked registers. Hence it needs to be invoked in Monitor mode
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100160for AArch32 and in EL3 for AArch64. The NS bit in SCR (in AArch32) or SCR_EL3
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100161(in AArch64) must be set to 0. Additional requirements for the PSCI library
162interfaces are:
163
164- Instruction cache must be enabled
165- Both IRQ and FIQ must be masked for the current CPU
166- The page tables must be setup and the MMU enabled
167- The C runtime environment must be setup and stack initialized
168- The Data cache must be enabled prior to invoking any of the PSCI library
169 interfaces except for ``psci_warmboot_entrypoint()``. For
170 ``psci_warmboot_entrypoint()``, if the build option ``HW_ASSISTED_COHERENCY``
171 is enabled however, data caches are expected to be enabled.
172
173Further requirements for each interface can be found in the interface
174description.
175
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100176Interface : psci_setup()
177~~~~~~~~~~~~~~~~~~~~~~~~
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100178
179::
180
181 Argument : const psci_lib_args_t *lib_args
182 Return : void
183
184This function is to be called by the primary CPU during cold boot before
185any other interface to the PSCI library. It takes ``lib_args``, a const pointer
186to ``psci_lib_args_t``, as the argument. The ``psci_lib_args_t`` is a versioned
John Tsichritzis2bcd5322019-05-13 11:20:05 +0100187structure and is declared in ``psci_lib.h`` header as follows:
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100188
189.. code:: c
190
191 typedef struct psci_lib_args {
192 /* The version information of PSCI Library Interface */
193 param_header_t h;
194 /* The warm boot entrypoint function */
195 mailbox_entrypoint_t mailbox_ep;
196 } psci_lib_args_t;
197
198The first field ``h``, of ``param_header_t`` type, provides the version
199information. The second field ``mailbox_ep`` is the warm boot entrypoint address
200and is used to configure the platform mailbox. Helper macros are provided in
John Tsichritzis2bcd5322019-05-13 11:20:05 +0100201``psci_lib.h`` to construct the ``lib_args`` argument statically or during
202runtime. Prior to calling the ``psci_setup()`` interface, the platform setup for
203cold boot must have completed. Major actions performed by this interface are:
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100204
205- Initializes architecture.
206- Initializes PSCI power domain and state coordination data structures.
207- Calls ``plat_setup_psci_ops()`` with warm boot entrypoint ``mailbox_ep`` as
208 argument.
209- Calls ``cm_set_context_by_index()`` (see
Douglas Raillard30d7b362017-06-28 16:14:55 +0100210 `CPU Context management API`_) for all the CPUs in the
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100211 platform
212
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100213Interface : psci_prepare_next_non_secure_ctx()
214~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100215
216::
217
218 Argument : entry_point_info_t *next_image_info
219 Return : void
220
221After ``psci_setup()`` and prior to exit to the non-secure world, this function
222must be called by the EL3 Runtime Software to initialize the non-secure world
223context. The non-secure world entrypoint information ``next_image_info`` (first
224argument) will be used to determine the non-secure context. After this function
225returns, the EL3 Runtime Software must retrieve the ``cpu_context_t`` (using
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100226cm_get_context()) for the current CPU and program the registers prior to exit
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100227to the non-secure world.
228
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100229Interface : psci_register_spd_pm_hook()
230~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100231
232::
233
234 Argument : const spd_pm_ops_t *
235 Return : void
236
Douglas Raillard30d7b362017-06-28 16:14:55 +0100237As explained in `Secure payload power management callback`_,
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100238the EL3 Runtime Software may want to perform some bookkeeping during power
239management operations. This function is used to register the ``spd_pm_ops_t``
240(first argument) callbacks with the PSCI library which will be called
Paul Beesley1fbc97b2019-01-11 18:26:51 +0000241appropriately during power management. Calling this function is optional and
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100242need to be called by the primary CPU during the cold boot sequence after
243``psci_setup()`` has completed.
244
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100245Interface : psci_smc_handler()
246~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100247
248::
249
250 Argument : uint32_t smc_fid, u_register_t x1,
251 u_register_t x2, u_register_t x3,
252 u_register_t x4, void *cookie,
253 void *handle, u_register_t flags
254 Return : u_register_t
255
256This function is the top level handler for SMCs which fall within the
257PSCI service range specified in `SMCCC`_. The function ID ``smc_fid`` (first
258argument) determines the PSCI API to be called. The ``x1`` to ``x4`` (2nd to 5th
259arguments), are the values of the registers r1 - r4 (in AArch32) or x1 - x4
260(in AArch64) when the SMC is received. These are the arguments to PSCI API as
261described in `PSCI spec`_. The 'flags' (8th argument) is a bit field parameter
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +0000262and is detailed in 'smccc.h' header. It includes whether the call is from the
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100263secure or non-secure world. The ``cookie`` (6th argument) and the ``handle``
264(7th argument) are not used and are reserved for future use.
265
266The return value from this interface is the return value from the underlying
267PSCI API corresponding to ``smc_fid``. This function may not return back to the
268caller if PSCI API causes power down of the CPU. In this case, when the CPU
269wakes up, it will start execution from the warm reset address.
270
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100271Interface : psci_warmboot_entrypoint()
272~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100273
274::
275
276 Argument : void
277 Return : void
278
279This function performs the warm boot initialization/restoration as mandated by
280`PSCI spec`_. For AArch32, on wakeup from power down the CPU resets to secure SVC
281mode and the EL3 Runtime Software must perform the prerequisite initializations
282mentioned at top of this section. This function must be called with Data cache
283disabled (unless build option ``HW_ASSISTED_COHERENCY`` is enabled) but with MMU
284initialized and enabled. The major actions performed by this function are:
285
286- Invalidates the stack and enables the data cache.
287- Initializes architecture and PSCI state coordination.
288- Restores/Initializes the peripheral drivers to the required state via
289 appropriate ``plat_psci_ops_t`` hooks
290- Restores the EL3 Runtime Software context via appropriate ``spd_pm_ops_t``
291 callbacks.
292- Restores/Initializes the non-secure context and populates the
293 ``cpu_context_t`` for the current CPU.
294
295Upon the return of this function, the EL3 Runtime Software must retrieve the
296non-secure ``cpu_context_t`` using ``cm_get_context()`` and program the registers
297prior to exit to the non-secure world.
298
299EL3 Runtime Software dependencies
300---------------------------------
301
302The PSCI Library includes supporting frameworks like context management,
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100303cpu operations (cpu_ops) and per-cpu data framework. Other helper library
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100304functions like bakery locks and spin locks are also included in the library.
305The dependencies which must be fulfilled by the EL3 Runtime Software
306for integration with PSCI library are described below.
307
308General dependencies
309~~~~~~~~~~~~~~~~~~~~
310
311The PSCI library being a Multiprocessor (MP) implementation, EL3 Runtime
312Software must provide an SMC handling framework capable of MP adhering to
313`SMCCC`_ specification.
314
315The EL3 Runtime Software must also export cache maintenance primitives
316and some helper utilities for assert, print and memory operations as listed
Dan Handley610e7e12018-03-01 18:44:00 +0000317below. The TF-A source tree provides implementations for all
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100318these functions but the EL3 Runtime Software may use its own implementation.
319
Antonio Nino Diazc0c8eb62018-08-15 17:02:28 +0100320**Functions : assert(), memcpy(), memset(), printf()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100321
322These must be implemented as described in ISO C Standard.
323
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100324**Function : flush_dcache_range()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100325
326::
327
328 Argument : uintptr_t addr, size_t size
329 Return : void
330
331This function cleans and invalidates (flushes) the data cache for memory
332at address ``addr`` (first argument) address and of size ``size`` (second argument).
333
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100334**Function : inv_dcache_range()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100335
336::
337
338 Argument : uintptr_t addr, size_t size
339 Return : void
340
341This function invalidates (flushes) the data cache for memory at address
342``addr`` (first argument) address and of size ``size`` (second argument).
343
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100344**Function : do_panic()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100345
346::
347
348 Argument : void
349 Return : void
350
351This function will be called by the PSCI library on encountering a critical
352failure that cannot be recovered from. This function **must not** return.
353
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100354CPU Context management API
355~~~~~~~~~~~~~~~~~~~~~~~~~~
356
357The CPU context management data memory is statically allocated by PSCI library
358in BSS section. The PSCI library requires the EL3 Runtime Software to implement
359APIs to store and retrieve pointers to this CPU context data. SP-MIN
360demonstrates how these APIs can be implemented but the EL3 Runtime Software can
361choose a more optimal implementation (like dedicating the secure TPIDRPRW
362system register (in AArch32) for storing these pointers).
363
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100364**Function : cm_set_context_by_index()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100365
366::
367
368 Argument : unsigned int cpu_idx, void *context, unsigned int security_state
369 Return : void
370
371This function is called during cold boot when the ``psci_setup()`` PSCI library
372interface is called.
373
374This function must store the pointer to the CPU context data, ``context`` (2nd
375argument), for the specified ``security_state`` (3rd argument) and CPU identified
376by ``cpu_idx`` (first argument). The ``security_state`` will always be non-secure
377when called by PSCI library and this argument is retained for compatibility
378with BL31. The ``cpu_idx`` will correspond to the index returned by the
379``plat_core_pos_by_mpidr()`` for ``mpidr`` of the CPU.
380
381The actual method of storing the ``context`` pointers is implementation specific.
382For example, SP-MIN stores the pointers in the array ``sp_min_cpu_ctx_ptr``
383declared in ``sp_min_main.c``.
384
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100385**Function : cm_get_context()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100386
387::
388
389 Argument : uint32_t security_state
390 Return : void *
391
392This function must return the pointer to the ``cpu_context_t`` structure for
393the specified ``security_state`` (first argument) for the current CPU. The caller
394must ensure that ``cm_set_context_by_index`` is called first and the appropriate
395context pointers are stored prior to invoking this API. The ``security_state``
396will always be non-secure when called by PSCI library and this argument
397is retained for compatibility with BL31.
398
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100399**Function : cm_get_context_by_index()**
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100400
401::
402
403 Argument : unsigned int cpu_idx, unsigned int security_state
404 Return : void *
405
406This function must return the pointer to the ``cpu_context_t`` structure for
407the specified ``security_state`` (second argument) for the CPU identified by
408``cpu_idx`` (first argument). The caller must ensure that
409``cm_set_context_by_index`` is called first and the appropriate context
410pointers are stored prior to invoking this API. The ``security_state`` will
411always be non-secure when called by PSCI library and this argument is
412retained for compatibility with BL31. The ``cpu_idx`` will correspond to the
413index returned by the ``plat_core_pos_by_mpidr()`` for ``mpidr`` of the CPU.
414
415Platform API
416~~~~~~~~~~~~
417
418The platform layer abstracts the platform-specific details from the generic
419PSCI library. The following platform APIs/macros must be defined by the EL3
420Runtime Software for integration with the PSCI library.
421
422The mandatory platform APIs are:
423
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100424- plat_my_core_pos
425- plat_core_pos_by_mpidr
426- plat_get_syscnt_freq2
427- plat_get_power_domain_tree_desc
428- plat_setup_psci_ops
429- plat_reset_handler
430- plat_panic_handler
431- plat_get_my_stack
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100432
433The mandatory platform macros are:
434
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100435- PLATFORM_CORE_COUNT
436- PLAT_MAX_PWR_LVL
437- PLAT_NUM_PWR_DOMAINS
438- CACHE_WRITEBACK_GRANULE
439- PLAT_MAX_OFF_STATE
440- PLAT_MAX_RET_STATE
441- PLAT_MAX_PWR_LVL_STATES (optional)
442- PLAT_PCPU_DATA_SIZE (optional)
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100443
444The details of these APIs/macros can be found in `Porting Guide`_.
445
446All platform specific operations for power management are done via
447``plat_psci_ops_t`` callbacks registered by the platform when
448``plat_setup_psci_ops()`` API is called. The description of each of
449the callbacks in ``plat_psci_ops_t`` can be found in PSCI section of the
450`Porting Guide`_. If any these callbacks are not registered, then the
451PSCI API associated with that callback will not be supported by PSCI
452library.
453
454Secure payload power management callback
455~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
456
457During PSCI power management operations, the EL3 Runtime Software may
458need to perform some bookkeeping, and PSCI library provides
459``spd_pm_ops_t`` callbacks for this purpose. These hooks must be
460populated and registered by using ``psci_register_spd_pm_hook()`` PSCI
461library interface.
462
463Typical bookkeeping during PSCI power management calls include save/restore
464of the EL3 Runtime Software context. Also if the EL3 Runtime Software makes
465use of secure interrupts, then these interrupts must also be managed
466appropriately during CPU power down/power up. Any secure interrupt targeted
467to the current CPU must be disabled or re-targeted to other running CPU prior
468to power down of the current CPU. During power up, these interrupt can be
469enabled/re-targeted back to the current CPU.
470
471.. code:: c
472
473 typedef struct spd_pm_ops {
474 void (*svc_on)(u_register_t target_cpu);
475 int32_t (*svc_off)(u_register_t __unused);
476 void (*svc_suspend)(u_register_t max_off_pwrlvl);
477 void (*svc_on_finish)(u_register_t __unused);
478 void (*svc_suspend_finish)(u_register_t max_off_pwrlvl);
479 int32_t (*svc_migrate)(u_register_t from_cpu, u_register_t to_cpu);
480 int32_t (*svc_migrate_info)(u_register_t *resident_cpu);
481 void (*svc_system_off)(void);
482 void (*svc_system_reset)(void);
483 } spd_pm_ops_t;
484
485A brief description of each callback is given below:
486
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100487- svc_on, svc_off, svc_on_finish
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100488
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100489 The ``svc_on``, ``svc_off`` callbacks are called during PSCI_CPU_ON,
490 PSCI_CPU_OFF APIs respectively. The ``svc_on_finish`` is called when the
491 target CPU of PSCI_CPU_ON API powers up and executes the
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100492 ``psci_warmboot_entrypoint()`` PSCI library interface.
493
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100494- svc_suspend, svc_suspend_finish
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100495
496 The ``svc_suspend`` callback is called during power down bu either
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100497 PSCI_SUSPEND or PSCI_SYSTEM_SUSPEND APIs. The ``svc_suspend_finish`` is
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100498 called when the CPU wakes up from suspend and executes the
499 ``psci_warmboot_entrypoint()`` PSCI library interface. The ``max_off_pwrlvl``
500 (first parameter) denotes the highest power domain level being powered down
501 to or woken up from suspend.
502
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100503- svc_system_off, svc_system_reset
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100504
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100505 These callbacks are called during PSCI_SYSTEM_OFF and PSCI_SYSTEM_RESET
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100506 PSCI APIs respectively.
507
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100508- svc_migrate_info
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100509
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100510 This callback is called in response to PSCI_MIGRATE_INFO_TYPE or
511 PSCI_MIGRATE_INFO_UP_CPU APIs. The return value of this callback must
512 correspond to the return value of PSCI_MIGRATE_INFO_TYPE API as described
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100513 in `PSCI spec`_. If the secure payload is a Uniprocessor (UP)
514 implementation, then it must update the mpidr of the CPU it is resident in
515 via ``resident_cpu`` (first argument). The updates to ``resident_cpu`` is
516 ignored if the secure payload is a multiprocessor (MP) implementation.
517
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100518- svc_migrate
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100519
520 This callback is only relevant if the secure payload in EL3 Runtime
521 Software is a Uniprocessor (UP) implementation and supports migration from
522 the current CPU ``from_cpu`` (first argument) to another CPU ``to_cpu``
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100523 (second argument). This callback is called in response to PSCI_MIGRATE
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100524 API. This callback is never called if the secure payload is a
525 Multiprocessor (MP) implementation.
526
527CPU operations
528~~~~~~~~~~~~~~
529
Sandrine Bailleux15530dd2019-02-08 15:26:36 +0100530The CPU operations (cpu_ops) framework implement power down sequence specific
Dan Handley610e7e12018-03-01 18:44:00 +0000531to the CPU and the details of which can be found in the
532``CPU specific operations framework`` section of `Firmware Design`_. The TF-A
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100533tree implements the ``cpu_ops`` for various supported CPUs and the EL3 Runtime
534Software needs to include the required ``cpu_ops`` in its build. The start and
535end of the ``cpu_ops`` descriptors must be exported by the EL3 Runtime Software
536via the ``__CPU_OPS_START__`` and ``__CPU_OPS_END__`` linker symbols.
537
538The ``cpu_ops`` descriptors also include reset sequences and may include errata
539workarounds for the CPU. The EL3 Runtime Software can choose to call this
540during cold/warm reset if it does not implement its own reset sequence/errata
541workarounds.
542
543--------------
544
Dan Handley610e7e12018-03-01 18:44:00 +0000545*Copyright (c) 2016-2018, Arm Limited and Contributors. All rights reserved.*
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100546
547.. _PSCI spec: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
548.. _SMCCC: https://silver.arm.com/download/ARM_and_AMBA_Architecture/AR570-DA-80002-r0p0-00rel0/ARM_DEN0028A_SMC_Calling_Convention.pdf
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100549.. _PSCI specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
Douglas Raillardd7c21b72017-06-28 15:23:03 +0100550.. _PSCI Specification: http://infocenter.arm.com/help/topic/com.arm.doc.den0022c/DEN0022C_Power_State_Coordination_Interface.pdf
Paul Beesleyea225122019-02-11 17:54:45 +0000551.. _Porting Guide: ../getting_started/porting-guide.rst
552.. _Firmware Design: ../design/firmware-design.rst