blob: 3b96dfc400f3a71f0644f5db0b21f7d7f92a7c85 [file] [log] [blame]
Hadi Asyrafi616da772019-06-27 11:34:03 +08001/*
Jit Loon Lim86f6fb32023-05-17 12:26:11 +08002 * Copyright (c) 2019-2023, ARM Limited and Contributors. All rights reserved.
Hadi Asyrafi616da772019-06-27 11:34:03 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <common/debug.h>
Jit Loon Lim86f6fb32023-05-17 12:26:11 +08009#ifndef SOCFPGA_GIC_V3
Hadi Asyrafi616da772019-06-27 11:34:03 +080010#include <drivers/arm/gicv2.h>
Jit Loon Lim86f6fb32023-05-17 12:26:11 +080011#else
12#include <drivers/arm/gicv3.h>
13#endif
Hadi Asyrafi616da772019-06-27 11:34:03 +080014#include <lib/mmio.h>
15#include <lib/psci/psci.h>
16#include <plat/common/platform.h>
17
Hadi Asyrafi6f8a2b22019-10-23 18:34:14 +080018#include "socfpga_mailbox.h"
Hadi Asyrafi4d9f3952019-10-23 17:35:32 +080019#include "socfpga_plat_def.h"
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +080020#include "socfpga_reset_manager.h"
Sieu Mun Tangdbcc2cf2022-03-07 12:13:04 +080021#include "socfpga_sip_svc.h"
Jit Loon Lim86f6fb32023-05-17 12:26:11 +080022#include "socfpga_system_manager.h"
Hadi Asyrafi616da772019-06-27 11:34:03 +080023
Hadi Asyrafi616da772019-06-27 11:34:03 +080024
Hadi Asyrafi616da772019-06-27 11:34:03 +080025/*******************************************************************************
26 * plat handler called when a CPU is about to enter standby.
27 ******************************************************************************/
28void socfpga_cpu_standby(plat_local_state_t cpu_state)
29{
30 /*
31 * Enter standby state
32 * dsb is good practice before using wfi to enter low power states
33 */
34 VERBOSE("%s: cpu_state: 0x%x\n", __func__, cpu_state);
35 dsb();
36 wfi();
37}
38
39/*******************************************************************************
40 * plat handler called when a power domain is about to be turned on. The
41 * mpidr determines the CPU to be turned on.
42 ******************************************************************************/
43int socfpga_pwr_domain_on(u_register_t mpidr)
44{
45 unsigned int cpu_id = plat_core_pos_by_mpidr(mpidr);
Jit Loon Lim44c61fc2023-03-02 13:38:53 +080046 uint32_t psci_boot = 0x00;
Hadi Asyrafi616da772019-06-27 11:34:03 +080047
48 VERBOSE("%s: mpidr: 0x%lx\n", __func__, mpidr);
49
50 if (cpu_id == -1)
51 return PSCI_E_INTERN_FAIL;
52
Jit Loon Lim44c61fc2023-03-02 13:38:53 +080053 if (cpu_id == 0x00) {
54 psci_boot = mmio_read_32(SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_8));
55 psci_boot |= 0x20000; /* bit 17 */
56 mmio_write_32(SOCFPGA_SYSMGR(BOOT_SCRATCH_COLD_8), psci_boot);
57 }
58
Hadi Asyrafia2edf0e2019-10-22 13:39:14 +080059 mmio_write_64(PLAT_CPUID_RELEASE, cpu_id);
Hadi Asyrafi616da772019-06-27 11:34:03 +080060
61 /* release core reset */
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +080062 mmio_setbits_32(SOCFPGA_RSTMGR(MPUMODRST), 1 << cpu_id);
Hadi Asyrafi616da772019-06-27 11:34:03 +080063 return PSCI_E_SUCCESS;
64}
65
66/*******************************************************************************
67 * plat handler called when a power domain is about to be turned off. The
68 * target_state encodes the power state that each level should transition to.
69 ******************************************************************************/
70void socfpga_pwr_domain_off(const psci_power_state_t *target_state)
71{
Hadi Asyrafi616da772019-06-27 11:34:03 +080072 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
73 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
74 __func__, i, target_state->pwr_domain_state[i]);
75
Hadi Asyrafi91071fc2019-09-12 15:14:01 +080076 /* Prevent interrupts from spuriously waking up this cpu */
77 gicv2_cpuif_disable();
Hadi Asyrafi616da772019-06-27 11:34:03 +080078}
79
80/*******************************************************************************
81 * plat handler called when a power domain is about to be suspended. The
82 * target_state encodes the power state that each level should transition to.
83 ******************************************************************************/
84void socfpga_pwr_domain_suspend(const psci_power_state_t *target_state)
85{
86 unsigned int cpu_id = plat_my_core_pos();
87
88 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
89 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
90 __func__, i, target_state->pwr_domain_state[i]);
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +080091
Hadi Asyrafi616da772019-06-27 11:34:03 +080092 /* assert core reset */
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +080093 mmio_setbits_32(SOCFPGA_RSTMGR(MPUMODRST), 1 << cpu_id);
Hadi Asyrafi616da772019-06-27 11:34:03 +080094
95}
96
97/*******************************************************************************
98 * plat handler called when a power domain has just been powered on after
99 * being turned off earlier. The target_state encodes the low power state that
100 * each level has woken up from.
101 ******************************************************************************/
102void socfpga_pwr_domain_on_finish(const psci_power_state_t *target_state)
103{
104 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
105 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
106 __func__, i, target_state->pwr_domain_state[i]);
107
108 /* Program the gic per-cpu distributor or re-distributor interface */
109 gicv2_pcpu_distif_init();
110 gicv2_set_pe_target_mask(plat_my_core_pos());
111
112 /* Enable the gic cpu interface */
113 gicv2_cpuif_enable();
114}
115
116/*******************************************************************************
117 * plat handler called when a power domain has just been powered on after
118 * having been suspended earlier. The target_state encodes the low power state
119 * that each level has woken up from.
120 * TODO: At the moment we reuse the on finisher and reinitialize the secure
121 * context. Need to implement a separate suspend finisher.
122 ******************************************************************************/
123void socfpga_pwr_domain_suspend_finish(const psci_power_state_t *target_state)
124{
125 unsigned int cpu_id = plat_my_core_pos();
126
127 for (size_t i = 0; i <= PLAT_MAX_PWR_LVL; i++)
128 VERBOSE("%s: target_state->pwr_domain_state[%lu]=%x\n",
129 __func__, i, target_state->pwr_domain_state[i]);
130
131 /* release core reset */
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +0800132 mmio_clrbits_32(SOCFPGA_RSTMGR(MPUMODRST), 1 << cpu_id);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800133}
134
135/*******************************************************************************
136 * plat handlers to shutdown/reboot the system
137 ******************************************************************************/
138static void __dead2 socfpga_system_off(void)
139{
140 wfi();
141 ERROR("System Off: operation not handled.\n");
142 panic();
143}
144
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800145extern uint64_t intel_rsu_update_address;
146
Hadi Asyrafi616da772019-06-27 11:34:03 +0800147static void __dead2 socfpga_system_reset(void)
148{
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +0800149 uint32_t addr_buf[2];
150
151 memcpy(addr_buf, &intel_rsu_update_address,
152 sizeof(intel_rsu_update_address));
Jit Loon Lim86f6fb32023-05-17 12:26:11 +0800153 if (intel_rsu_update_address) {
Abdul Halim, Muhammad Hadi Asyrafid84bfef2020-02-25 16:28:10 +0800154 mailbox_rsu_update(addr_buf);
Jit Loon Lim86f6fb32023-05-17 12:26:11 +0800155 } else {
Hadi Asyrafi593c4c52019-12-17 19:22:17 +0800156 mailbox_reset_cold();
Jit Loon Lim86f6fb32023-05-17 12:26:11 +0800157 }
Hadi Asyrafi616da772019-06-27 11:34:03 +0800158
159 while (1)
160 wfi();
161}
162
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800163static int socfpga_system_reset2(int is_vendor, int reset_type,
164 u_register_t cookie)
165{
Sieu Mun Tangdbcc2cf2022-03-07 12:13:04 +0800166 if (cold_reset_for_ecc_dbe()) {
167 mailbox_reset_cold();
168 }
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800169 /* disable cpuif */
170 gicv2_cpuif_disable();
171
172 /* Store magic number */
173 mmio_write_32(L2_RESET_DONE_REG, L2_RESET_DONE_STATUS);
174
175 /* Increase timeout */
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +0800176 mmio_write_32(SOCFPGA_RSTMGR(HDSKTIMEOUT), 0xffffff);
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800177
178 /* Enable handshakes */
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +0800179 mmio_setbits_32(SOCFPGA_RSTMGR(HDSKEN), RSTMGR_HDSKEN_SET);
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800180
181 /* Reset L2 module */
Hadi Asyrafi67cb0ea2019-12-23 13:25:33 +0800182 mmio_setbits_32(SOCFPGA_RSTMGR(COLDMODRST), 0x100);
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800183
184 while (1)
185 wfi();
186
187 /* Should not reach here */
188 return 0;
189}
190
Hadi Asyrafi616da772019-06-27 11:34:03 +0800191int socfpga_validate_power_state(unsigned int power_state,
192 psci_power_state_t *req_state)
193{
194 VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
195
196 return PSCI_E_SUCCESS;
197}
198
199int socfpga_validate_ns_entrypoint(unsigned long ns_entrypoint)
200{
201 VERBOSE("%s: ns_entrypoint: 0x%lx\n", __func__, ns_entrypoint);
202 return PSCI_E_SUCCESS;
203}
204
205void socfpga_get_sys_suspend_power_state(psci_power_state_t *req_state)
206{
207 req_state->pwr_domain_state[PSCI_CPU_PWR_LVL] = PLAT_MAX_OFF_STATE;
208 req_state->pwr_domain_state[1] = PLAT_MAX_OFF_STATE;
209}
210
211/*******************************************************************************
212 * Export the platform handlers via plat_arm_psci_pm_ops. The ARM Standard
213 * platform layer will take care of registering the handlers with PSCI.
214 ******************************************************************************/
215const plat_psci_ops_t socfpga_psci_pm_ops = {
216 .cpu_standby = socfpga_cpu_standby,
217 .pwr_domain_on = socfpga_pwr_domain_on,
218 .pwr_domain_off = socfpga_pwr_domain_off,
219 .pwr_domain_suspend = socfpga_pwr_domain_suspend,
220 .pwr_domain_on_finish = socfpga_pwr_domain_on_finish,
221 .pwr_domain_suspend_finish = socfpga_pwr_domain_suspend_finish,
222 .system_off = socfpga_system_off,
223 .system_reset = socfpga_system_reset,
Hadi Asyrafi5fae68f2019-10-22 14:23:57 +0800224 .system_reset2 = socfpga_system_reset2,
Hadi Asyrafi616da772019-06-27 11:34:03 +0800225 .validate_power_state = socfpga_validate_power_state,
226 .validate_ns_entrypoint = socfpga_validate_ns_entrypoint,
227 .get_sys_suspend_power_state = socfpga_get_sys_suspend_power_state
228};
229
230/*******************************************************************************
231 * Export the platform specific power ops.
232 ******************************************************************************/
233int plat_setup_psci_ops(uintptr_t sec_entrypoint,
234 const struct plat_psci_ops **psci_ops)
235{
236 /* Save warm boot entrypoint.*/
Hadi Asyrafia2edf0e2019-10-22 13:39:14 +0800237 mmio_write_64(PLAT_SEC_ENTRY, sec_entrypoint);
Hadi Asyrafi616da772019-06-27 11:34:03 +0800238 *psci_ops = &socfpga_psci_pm_ops;
Hadi Asyrafia2edf0e2019-10-22 13:39:14 +0800239
Hadi Asyrafi616da772019-06-27 11:34:03 +0800240 return 0;
241}