blob: ed5bf7761a3a7c12d06d4124e7c943ace00ab600 [file] [log] [blame]
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05301/*
2 * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved.
Varun Wadekarf09264a2018-11-05 15:12:55 -08003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05306 */
7
Varun Wadekara70dec32015-08-26 12:49:03 +05308#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
Antonio Nino Diaz31a157f2019-02-11 11:57:57 +000011#include <bl32/payloads/tlk.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <common/bl_common.h>
13#include <common/debug.h>
14#include <lib/el3_runtime/context_mgmt.h>
15#include <lib/psci/psci.h>
Varun Wadekara70dec32015-08-26 12:49:03 +053016
17#include "tlkd_private.h"
18
19extern tlk_context_t tlk_ctx;
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053020
21#define MPIDR_CPU0 0x80000000
22
23/*******************************************************************************
24 * Return the type of payload TLKD is dealing with. Report the current
25 * resident cpu (mpidr format) if it is a UP/UP migratable payload.
26 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090027static int32_t cpu_migrate_info(u_register_t *resident_cpu)
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053028{
29 /* the payload runs only on CPU0 */
30 *resident_cpu = MPIDR_CPU0;
31
32 /* Uniprocessor, not migrate capable payload */
33 return PSCI_TOS_NOT_UP_MIG_CAP;
34}
35
36/*******************************************************************************
Varun Wadekara70dec32015-08-26 12:49:03 +053037 * This cpu is being suspended. Inform TLK of the SYSTEM_SUSPEND event, so
38 * that it can pass this information to its Trusted Apps.
39 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090040static void cpu_suspend_handler(u_register_t suspend_level)
Varun Wadekara70dec32015-08-26 12:49:03 +053041{
42 gp_regs_t *gp_regs;
43 int cpu = read_mpidr() & MPIDR_CPU_MASK;
44 int32_t rc = 0;
45
46 /*
47 * TLK runs only on CPU0 and suspends its Trusted Apps during
48 * SYSTEM_SUSPEND. It has no role to play during CPU_SUSPEND.
49 */
50 if ((cpu != 0) || (suspend_level != PLAT_MAX_PWR_LVL))
51 return;
52
53 /* pass system suspend event to TLK */
54 gp_regs = get_gpregs_ctx(&tlk_ctx.cpu_ctx);
55 write_ctx_reg(gp_regs, CTX_GPREG_X0, TLK_SYSTEM_SUSPEND);
56
57 /* Program the entry point and enter TLK */
58 rc = tlkd_synchronous_sp_entry(&tlk_ctx);
59
60 /*
61 * Read the response from TLK. A non-zero return means that
62 * something went wrong while communicating with it.
63 */
64 if (rc != 0)
65 panic();
66}
67
68/*******************************************************************************
69 * This cpu is being resumed. Inform TLK of the SYSTEM_SUSPEND exit, so
70 * that it can pass this information to its Trusted Apps.
71 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +090072static void cpu_resume_handler(u_register_t suspend_level)
Varun Wadekara70dec32015-08-26 12:49:03 +053073{
74 gp_regs_t *gp_regs;
75 int cpu = read_mpidr() & MPIDR_CPU_MASK;
76 int32_t rc = 0;
77
78 /*
79 * TLK runs only on CPU0 and resumes its Trusted Apps during
80 * SYSTEM_SUSPEND exit. It has no role to play during CPU_SUSPEND
81 * exit.
82 */
83 if ((cpu != 0) || (suspend_level != PLAT_MAX_PWR_LVL))
84 return;
85
86 /* pass system resume event to TLK */
87 gp_regs = get_gpregs_ctx(&tlk_ctx.cpu_ctx);
88 write_ctx_reg(gp_regs, CTX_GPREG_X0, TLK_SYSTEM_RESUME);
89
90 /* Program the entry point and enter TLK */
91 rc = tlkd_synchronous_sp_entry(&tlk_ctx);
92
93 /*
94 * Read the response from TLK. A non-zero return means that
95 * something went wrong while communicating with it.
96 */
97 if (rc != 0)
98 panic();
99}
100
101/*******************************************************************************
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530102 * Structure populated by the Dispatcher to be given a chance to perform any
103 * bookkeeping before PSCI executes a power mgmt. operation.
104 ******************************************************************************/
105const spd_pm_ops_t tlkd_pm_ops = {
106 .svc_migrate_info = cpu_migrate_info,
Varun Wadekara70dec32015-08-26 12:49:03 +0530107 .svc_suspend = cpu_suspend_handler,
108 .svc_suspend_finish = cpu_resume_handler,
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530109};