2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
9 #include <arch_helpers.h>
10 #include <common/bl_common.h>
11 #include <common/debug.h>
12 #include <lib/el3_runtime/context_mgmt.h>
13 #include <lib/psci/psci.h>
16 #include "tlkd_private.h"
18 extern tlk_context_t tlk_ctx
;
20 #define MPIDR_CPU0 0x80000000
22 /*******************************************************************************
23 * Return the type of payload TLKD is dealing with. Report the current
24 * resident cpu (mpidr format) if it is a UP/UP migratable payload.
25 ******************************************************************************/
26 static int32_t cpu_migrate_info(u_register_t
*resident_cpu
)
28 /* the payload runs only on CPU0 */
29 *resident_cpu
= MPIDR_CPU0
;
31 /* Uniprocessor, not migrate capable payload */
32 return PSCI_TOS_NOT_UP_MIG_CAP
;
35 /*******************************************************************************
36 * This cpu is being suspended. Inform TLK of the SYSTEM_SUSPEND event, so
37 * that it can pass this information to its Trusted Apps.
38 ******************************************************************************/
39 static void cpu_suspend_handler(u_register_t suspend_level
)
42 int cpu
= read_mpidr() & MPIDR_CPU_MASK
;
46 * TLK runs only on CPU0 and suspends its Trusted Apps during
47 * SYSTEM_SUSPEND. It has no role to play during CPU_SUSPEND.
49 if ((cpu
!= 0) || (suspend_level
!= PLAT_MAX_PWR_LVL
))
52 /* pass system suspend event to TLK */
53 gp_regs
= get_gpregs_ctx(&tlk_ctx
.cpu_ctx
);
54 write_ctx_reg(gp_regs
, CTX_GPREG_X0
, TLK_SYSTEM_SUSPEND
);
56 /* Program the entry point and enter TLK */
57 rc
= tlkd_synchronous_sp_entry(&tlk_ctx
);
60 * Read the response from TLK. A non-zero return means that
61 * something went wrong while communicating with it.
67 /*******************************************************************************
68 * This cpu is being resumed. Inform TLK of the SYSTEM_SUSPEND exit, so
69 * that it can pass this information to its Trusted Apps.
70 ******************************************************************************/
71 static void cpu_resume_handler(u_register_t suspend_level
)
74 int cpu
= read_mpidr() & MPIDR_CPU_MASK
;
78 * TLK runs only on CPU0 and resumes its Trusted Apps during
79 * SYSTEM_SUSPEND exit. It has no role to play during CPU_SUSPEND
82 if ((cpu
!= 0) || (suspend_level
!= PLAT_MAX_PWR_LVL
))
85 /* pass system resume event to TLK */
86 gp_regs
= get_gpregs_ctx(&tlk_ctx
.cpu_ctx
);
87 write_ctx_reg(gp_regs
, CTX_GPREG_X0
, TLK_SYSTEM_RESUME
);
89 /* Program the entry point and enter TLK */
90 rc
= tlkd_synchronous_sp_entry(&tlk_ctx
);
93 * Read the response from TLK. A non-zero return means that
94 * something went wrong while communicating with it.
100 /*******************************************************************************
101 * System is about to be reset. Inform the SP to allow any book-keeping
102 ******************************************************************************/
103 static void system_off_handler(void)
105 int cpu
= read_mpidr() & MPIDR_CPU_MASK
;
108 /* TLK runs only on CPU0 */
112 /* pass system off/reset events to TLK */
113 gp_regs
= get_gpregs_ctx(&tlk_ctx
.cpu_ctx
);
114 write_ctx_reg(gp_regs
, CTX_GPREG_X0
, TLK_SYSTEM_OFF
);
117 * Enter the SP. We do not care about the return value because we
118 * must continue with the shutdown anyway.
120 (void)tlkd_synchronous_sp_entry(&tlk_ctx
);
123 /*******************************************************************************
124 * Structure populated by the Dispatcher to be given a chance to perform any
125 * bookkeeping before PSCI executes a power mgmt. operation.
126 ******************************************************************************/
127 const spd_pm_ops_t tlkd_pm_ops
= {
128 .svc_migrate_info
= cpu_migrate_info
,
129 .svc_suspend
= cpu_suspend_handler
,
130 .svc_suspend_finish
= cpu_resume_handler
,
131 .svc_system_off
= system_off_handler
,
132 .svc_system_reset
= system_off_handler