blob: 55842cc7bb3f809dd9e94f5d0ee278f34274510e [file] [log] [blame]
Amit Nagal055796f2024-06-05 12:32:38 +05301/*
2 * Copyright (c) 2018-2020, Arm Limited and Contributors. All rights reserved.
3 * Copyright (c) 2021-2022, Xilinx, Inc. All rights reserved.
4 * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#include <assert.h>
10
11#include <common/debug.h>
12#include <common/runtime_svc.h>
13#include <lib/mmio.h>
14#include <lib/psci/psci.h>
15#include <plat/arm/common/plat_arm.h>
16#include <plat/common/platform.h>
17#include <plat_arm.h>
18
19#include <plat_private.h>
20#include <pm_defs.h>
21
22#define PM_RET_ERROR_NOFEATURE U(19)
23#define ALWAYSTRUE true
Maheedhar Bollapallicf1fd332024-10-29 05:55:18 +000024#define LINEAR_MODE BIT(1)
Amit Nagal055796f2024-06-05 12:32:38 +053025
26static uintptr_t _sec_entry;
27
28static void zynqmp_cpu_standby(plat_local_state_t cpu_state)
29{
30 dsb();
31 wfi();
32}
33
34#define MPIDR_MT_BIT (24)
35
36static int32_t zynqmp_nopmu_pwr_domain_on(u_register_t mpidr)
37{
Maheedhar Bollapalli8af09db2024-10-21 05:57:58 +000038 int32_t cpu_id = plat_core_pos_by_mpidr(mpidr) & ~BIT(MPIDR_MT_BIT);
39 int32_t cpu = cpu_id % PLATFORM_CORE_COUNT_PER_CLUSTER;
40 int32_t cluster = cpu_id / PLATFORM_CORE_COUNT_PER_CLUSTER;
Amit Nagal055796f2024-06-05 12:32:38 +053041 uintptr_t apu_cluster_base = 0, apu_pcli_base, apu_pcli_cluster = 0;
42 uintptr_t rst_apu_cluster = PSX_CRF + RST_APU0_OFFSET + ((uint64_t)cluster * 0x4U);
Maheedhar Bollapalli120bdd52024-10-29 03:53:19 +000043 int32_t ret = PSCI_E_SUCCESS;
Amit Nagal055796f2024-06-05 12:32:38 +053044
45 VERBOSE("%s: mpidr: 0x%lx, cpuid: %x, cpu: %x, cluster: %x\n",
46 __func__, mpidr, cpu_id, cpu, cluster);
47
48 if (cpu_id == -1) {
Maheedhar Bollapalli120bdd52024-10-29 03:53:19 +000049 ret = PSCI_E_INTERN_FAIL;
50 goto exit_label;
Amit Nagal055796f2024-06-05 12:32:38 +053051 }
52
Maheedhar Bollapalli8af09db2024-10-21 05:57:58 +000053 if (cluster > 3U) {
Amit Nagal055796f2024-06-05 12:32:38 +053054 panic();
55 }
56
57 apu_pcli_cluster = APU_PCLI + APU_PCLI_CLUSTER_OFFSET + ((uint64_t)cluster * APU_PCLI_CLUSTER_STEP);
58 apu_cluster_base = APU_CLUSTER0 + ((uint64_t)cluster * APU_CLUSTER_STEP);
59
60 /* Enable clock */
61 mmio_setbits_32(PSX_CRF + ACPU0_CLK_CTRL + ((uint64_t)cluster * 0x4U), ACPU_CLK_CTRL_CLKACT);
62
63 /* Enable cluster states */
64 mmio_setbits_32(apu_pcli_cluster + PCLI_PSTATE_OFFSET, PCLI_PSTATE_VAL_SET);
65 mmio_setbits_32(apu_pcli_cluster + PCLI_PREQ_OFFSET, PREQ_CHANGE_REQUEST);
66
67 /* assert core reset */
68 mmio_setbits_32(rst_apu_cluster, ((RST_APU_COLD_RESET|RST_APU_WARN_RESET) << cpu));
69
70 /* program RVBAR */
71 mmio_write_32(apu_cluster_base + APU_RVBAR_L_0 + (cpu << 3),
72 (uint32_t)_sec_entry);
73 mmio_write_32(apu_cluster_base + APU_RVBAR_H_0 + (cpu << 3),
Maheedhar Bollapalli9cadba32024-10-24 04:40:04 +000074 (uint32_t)(_sec_entry >> 32));
Amit Nagal055796f2024-06-05 12:32:38 +053075
76 /* de-assert core reset */
77 mmio_clrbits_32(rst_apu_cluster, ((RST_APU_COLD_RESET|RST_APU_WARN_RESET) << cpu));
78
79 /* clear cluster resets */
80 mmio_clrbits_32(rst_apu_cluster, RST_APU_CLUSTER_WARM_RESET);
81 mmio_clrbits_32(rst_apu_cluster, RST_APU_CLUSTER_COLD_RESET);
82
83 apu_pcli_base = APU_PCLI + (APU_PCLI_CPU_STEP * cpu) +
84 (APU_PCLI_CLUSTER_CPU_STEP * cluster);
85
86 mmio_write_32(apu_pcli_base + PCLI_PSTATE_OFFSET, PCLI_PSTATE_VAL_CLEAR);
87 mmio_write_32(apu_pcli_base + PCLI_PREQ_OFFSET, PREQ_CHANGE_REQUEST);
88
Maheedhar Bollapalli120bdd52024-10-29 03:53:19 +000089exit_label:
90 return ret;
Amit Nagal055796f2024-06-05 12:32:38 +053091}
92
93static void zynqmp_nopmu_pwr_domain_off(const psci_power_state_t *target_state)
94{
95 plat_gic_cpuif_disable();
96}
97
98static void __dead2 zynqmp_nopmu_system_reset(void)
99{
100 while (ALWAYSTRUE) {
101 wfi();
102 }
103}
104
105static int32_t zynqmp_validate_ns_entrypoint(uint64_t ns_entrypoint)
106{
Maheedhar Bollapalli120bdd52024-10-29 03:53:19 +0000107 int32_t ret = PSCI_E_INVALID_ADDRESS;
108
Amit Nagal055796f2024-06-05 12:32:38 +0530109 VERBOSE("Validate ns_entry point %lx\n", ns_entrypoint);
110
111 if ((ns_entrypoint) != 0U) {
Maheedhar Bollapalli120bdd52024-10-29 03:53:19 +0000112 ret = PSCI_E_SUCCESS;
Amit Nagal055796f2024-06-05 12:32:38 +0530113 }
Maheedhar Bollapalli120bdd52024-10-29 03:53:19 +0000114
115 return ret;
Amit Nagal055796f2024-06-05 12:32:38 +0530116}
117
118static void zynqmp_pwr_domain_on_finish(const psci_power_state_t *target_state)
119{
120 plat_gic_pcpu_init();
121 plat_gic_cpuif_enable();
122}
123
124static void __dead2 zynqmp_system_off(void)
125{
126 while (ALWAYSTRUE) {
127 wfi();
128 }
129}
130
131static int32_t zynqmp_validate_power_state(uint32_t power_state, psci_power_state_t *req_state)
132{
133 return PSCI_E_SUCCESS;
134}
135
136static const struct plat_psci_ops _nopmc_psci_ops = {
137 .cpu_standby = zynqmp_cpu_standby,
138 .pwr_domain_on = zynqmp_nopmu_pwr_domain_on,
139 .pwr_domain_off = zynqmp_nopmu_pwr_domain_off,
140 .system_reset = zynqmp_nopmu_system_reset,
141 .validate_ns_entrypoint = zynqmp_validate_ns_entrypoint,
142 .pwr_domain_on_finish = zynqmp_pwr_domain_on_finish,
143 .system_off = zynqmp_system_off,
144 .validate_power_state = zynqmp_validate_power_state,
145};
146
147/*******************************************************************************
148 * Export the platform specific power ops.
149 ******************************************************************************/
150int32_t plat_setup_psci_ops(uintptr_t sec_entrypoint,
151 const struct plat_psci_ops **psci_ops)
152{
153 _sec_entry = sec_entrypoint;
154
155 VERBOSE("Setting up entry point %lx\n", _sec_entry);
156
157 *psci_ops = &_nopmc_psci_ops;
158
159 return 0;
160}
161
162int sip_svc_setup_init(void)
163{
164 return 0;
165}
166
167static int32_t no_pm_ioctl(uint32_t device_id, uint32_t ioctl_id,
168 uint32_t arg1, uint32_t arg2)
169{
Amit Nagalacb6b922024-07-28 20:32:58 -1200170 int32_t ret = 0;
Amit Nagal055796f2024-06-05 12:32:38 +0530171 VERBOSE("%s: ioctl_id: %x, arg1: %x\n", __func__, ioctl_id, arg1);
Amit Nagalacb6b922024-07-28 20:32:58 -1200172
173 switch (ioctl_id) {
174 case IOCTL_OSPI_MUX_SELECT:
Maheedhar Bollapallicf1fd332024-10-29 05:55:18 +0000175 if ((arg1 == 0) || (arg1 == 1)) {
176 mmio_clrsetbits_32(SLCR_OSPI_QSPI_IOU_AXI_MUX_SEL, LINEAR_MODE,
177 (arg1 ? LINEAR_MODE : 0));
178 } else {
179 ret = PM_RET_ERROR_ARGS;
180 }
Amit Nagalacb6b922024-07-28 20:32:58 -1200181 break;
182 case IOCTL_UFS_TXRX_CFGRDY_GET:
183 ret = (int32_t) mmio_read_32(PMXC_IOU_SLCR_TX_RX_CONFIG_RDY);
184 break;
185 case IOCTL_UFS_SRAM_CSR_SEL:
Maheedhar Bollapalli8af09db2024-10-21 05:57:58 +0000186 if (arg1 == 1U) {
Amit Nagalacb6b922024-07-28 20:32:58 -1200187 ret = (int32_t) mmio_read_32(PMXC_IOU_SLCR_SRAM_CSR);
Maheedhar Bollapalli8af09db2024-10-21 05:57:58 +0000188 } else if (arg1 == 0U) {
Amit Nagalacb6b922024-07-28 20:32:58 -1200189 mmio_write_32(PMXC_IOU_SLCR_SRAM_CSR, arg2);
190 }
191 break;
Maheedhar Bollapalliebe40e22024-09-04 18:29:38 -1200192 case IOCTL_USB_SET_STATE:
193 break;
Amit Nagalacb6b922024-07-28 20:32:58 -1200194 default:
195 ret = PM_RET_ERROR_NOFEATURE;
196 break;
Amit Nagal055796f2024-06-05 12:32:38 +0530197 }
Amit Nagalacb6b922024-07-28 20:32:58 -1200198
199 return ret;
Amit Nagal055796f2024-06-05 12:32:38 +0530200}
201
202static uint64_t no_pm_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3,
203 uint64_t x4, void *cookie, void *handle, uint64_t flags)
204{
205 int32_t ret;
206 uint32_t arg[4], api_id;
207
208 arg[0] = (uint32_t)x1;
209 arg[1] = (uint32_t)(x1 >> 32);
210 arg[2] = (uint32_t)x2;
211 arg[3] = (uint32_t)(x2 >> 32);
212
213 api_id = smc_fid & FUNCID_NUM_MASK;
214 VERBOSE("%s: smc_fid: %x, api_id=0x%x\n", __func__, smc_fid, api_id);
215
216 switch (api_id) {
217 case PM_IOCTL:
218 {
219 ret = no_pm_ioctl(arg[0], arg[1], arg[2], arg[3]);
Amit Nagalacb6b922024-07-28 20:32:58 -1200220 /* Firmware driver expects return code in upper 32 bits and
221 * status in lower 32 bits.
222 * status is always SUCCESS(0) for mmio low level register
223 * r/w calls and return value is the value returned from
224 * no_pm_ioctl
225 */
226 SMC_RET1(handle, ((uint64_t)ret << 32));
Amit Nagal055796f2024-06-05 12:32:38 +0530227 }
228 case PM_GET_CHIPID:
229 {
Maheedhar Bollapalli51d3e6c2024-10-08 06:09:19 +0000230 uint32_t idcode, version_type;
Amit Nagal055796f2024-06-05 12:32:38 +0530231
232 idcode = mmio_read_32(PMC_TAP);
Maheedhar Bollapalli51d3e6c2024-10-08 06:09:19 +0000233 version_type = mmio_read_32(PMC_TAP_VERSION);
234 SMC_RET2(handle, ((uint64_t)idcode << 32), version_type);
Amit Nagal055796f2024-06-05 12:32:38 +0530235 }
236 default:
237 WARN("Unimplemented PM Service Call: 0x%x\n", smc_fid);
238 SMC_RET1(handle, SMC_UNK);
239 }
240}
241
242uint64_t smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, uint64_t x3, uint64_t x4,
243 void *cookie, void *handle, uint64_t flags)
244{
245 return no_pm_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
246}