blob: 7578528875726877a174f0a28cba6cd0193224f1 [file] [log] [blame]
Tien Hock, Lohab34f742019-02-26 09:25:14 +08001/*
2 * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <assert.h>
9#include <common/debug.h>
10#include <errno.h>
11#include <lib/mmio.h>
12#include <drivers/arm/gic_common.h>
13#include <drivers/arm/gicv2.h>
14#include <plat/common/platform.h>
15#include <lib/psci/psci.h>
16
17#include "platform_def.h"
18#include "platform_private.h"
19#include "s10_reset_manager.h"
20#include "s10_mailbox.h"
21
22#define S10_RSTMGR_OFST 0xffd11000
23#define S10_RSTMGR_MPUMODRST_OFST 0x20
24
25uintptr_t *stratix10_sec_entry = (uintptr_t *) PLAT_S10_SEC_ENTRY;
26uintptr_t *cpuid_release = (uintptr_t *) PLAT_CPUID_RELEASE;
27
28/*******************************************************************************
29 * plat handler called when a CPU is about to enter standby.
30 ******************************************************************************/
31void plat_cpu_standby(plat_local_state_t cpu_state)
32{
33 /*
34 * Enter standby state
35 * dsb is good practice before using wfi to enter low power states
36 */
37 VERBOSE("%s: cpu_state: 0x%x\n", __func__, cpu_state);
38 dsb();
39 wfi();
40}
41
42/*******************************************************************************
43 * plat handler called when a power domain is about to be turned on. The
44 * mpidr determines the CPU to be turned on.
45 ******************************************************************************/
46int plat_pwr_domain_on(u_register_t mpidr)
47{
48 unsigned int cpu_id = plat_core_pos_by_mpidr(mpidr);
49
50 VERBOSE("%s: mpidr: 0x%lx\n", __func__, mpidr);
51
52 if (cpu_id == -1)
53 return PSCI_E_INTERN_FAIL;
54
55 *cpuid_release = cpu_id;
56
57 /* release core reset */
58 mmio_setbits_32(S10_RSTMGR_OFST + S10_RSTMGR_MPUMODRST_OFST,
59 1 << cpu_id);
60 return PSCI_E_SUCCESS;
61}
62
63/*******************************************************************************
64 * plat handler called when a power domain is about to be turned off. The
65 * target_state encodes the power state that each level should transition to.
66 ******************************************************************************/
67void plat_pwr_domain_off(const psci_power_state_t *target_state)
68{
69 unsigned int cpu_id = plat_my_core_pos();
70
71 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
72 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
73 __func__, i, target_state->pwr_domain_state[i]);
74
75 /* TODO: Prevent interrupts from spuriously waking up this cpu */
76 /* gicv2_cpuif_disable(); */
77
78 /* assert core reset */
79 mmio_setbits_32(S10_RSTMGR_OFST + S10_RSTMGR_MPUMODRST_OFST,
80 1 << cpu_id);
81}
82
83/*******************************************************************************
84 * plat handler called when a power domain is about to be suspended. The
85 * target_state encodes the power state that each level should transition to.
86 ******************************************************************************/
87void plat_pwr_domain_suspend(const psci_power_state_t *target_state)
88{
89 unsigned int cpu_id = plat_my_core_pos();
90
91 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
92 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
93 __func__, i, target_state->pwr_domain_state[i]);
94 /* assert core reset */
95 mmio_setbits_32(S10_RSTMGR_OFST + S10_RSTMGR_MPUMODRST_OFST,
96 1 << cpu_id);
97
98}
99
100/*******************************************************************************
101 * plat handler called when a power domain has just been powered on after
102 * being turned off earlier. The target_state encodes the low power state that
103 * each level has woken up from.
104 ******************************************************************************/
105void plat_pwr_domain_on_finish(const psci_power_state_t *target_state)
106{
107 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
108 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
109 __func__, i, target_state->pwr_domain_state[i]);
110
111 /* Program the gic per-cpu distributor or re-distributor interface */
112 gicv2_pcpu_distif_init();
113 gicv2_set_pe_target_mask(plat_my_core_pos());
114
115 /* Enable the gic cpu interface */
116 gicv2_cpuif_enable();
117}
118
119/*******************************************************************************
120 * plat handler called when a power domain has just been powered on after
121 * having been suspended earlier. The target_state encodes the low power state
122 * that each level has woken up from.
123 * TODO: At the moment we reuse the on finisher and reinitialize the secure
124 * context. Need to implement a separate suspend finisher.
125 ******************************************************************************/
126void plat_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
127{
128 unsigned int cpu_id = plat_my_core_pos();
129
130 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
131 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
132 __func__, i, target_state->pwr_domain_state[i]);
133
134 /* release core reset */
135 mmio_clrbits_32(S10_RSTMGR_OFST + S10_RSTMGR_MPUMODRST_OFST,
136 1 << cpu_id);
137}
138
139/*******************************************************************************
140 * plat handlers to shutdown/reboot the system
141 ******************************************************************************/
142static void __dead2 plat_system_off(void)
143{
144 wfi();
145 ERROR("System Off: operation not handled.\n");
146 panic();
147}
148
149static void __dead2 plat_system_reset(void)
150{
151 INFO("assert Peripheral from Reset\r\n");
152
153 deassert_peripheral_reset();
154 mailbox_reset_cold();
155
156 while (1)
157 wfi();
158}
159
160int plat_validate_power_state(unsigned int power_state,
161 psci_power_state_t *req_state)
162{
163 VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
164
165 return PSCI_E_SUCCESS;
166}
167
168int plat_validate_ns_entrypoint(unsigned long ns_entrypoint)
169{
170 VERBOSE("%s: ns_entrypoint: 0x%lx\n", __func__, ns_entrypoint);
171 return PSCI_E_SUCCESS;
172}
173
174void plat_get_sys_suspend_power_state(psci_power_state_t *req_state)
175{
176 req_state->pwr_domain_state[PSCI_CPU_PWR_LVL] = PLAT_MAX_OFF_STATE;
177 req_state->pwr_domain_state[1] = PLAT_MAX_OFF_STATE;
178}
179
180/*******************************************************************************
181 * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard
182 * platform layer will take care of registering the handlers with PSCI.
183 ******************************************************************************/
184const plat_psci_ops_t plat_psci_pm_ops = {
185 .cpu_standby = plat_cpu_standby,
186 .pwr_domain_on = plat_pwr_domain_on,
187 .pwr_domain_off = plat_pwr_domain_off,
188 .pwr_domain_suspend = plat_pwr_domain_suspend,
189 .pwr_domain_on_finish = plat_pwr_domain_on_finish,
190 .pwr_domain_suspend_finish = plat_pwr_domain_suspend_finish,
191 .system_off = plat_system_off,
192 .system_reset = plat_system_reset,
193 .validate_power_state = plat_validate_power_state,
194 .validate_ns_entrypoint = plat_validate_ns_entrypoint,
195 .get_sys_suspend_power_state = plat_get_sys_suspend_power_state
196};
197
198/*******************************************************************************
199 * Export the platform specific power ops.
200 ******************************************************************************/
201int plat_setup_psci_ops(uintptr_t sec_entrypoint,
202 const struct plat_psci_ops **psci_ops)
203{
204 /* Save warm boot entrypoint.*/
205 *stratix10_sec_entry = sec_entrypoint;
206
207 *psci_ops = &plat_psci_pm_ops;
208 return 0;
209}