xref: /aosp_15_r20/external/arm-trusted-firmware/plat/allwinner/common/sunxi_pm.c (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #include <assert.h>
8*54fd6939SJiyong Park 
9*54fd6939SJiyong Park #include <platform_def.h>
10*54fd6939SJiyong Park 
11*54fd6939SJiyong Park #include <common/debug.h>
12*54fd6939SJiyong Park #include <lib/mmio.h>
13*54fd6939SJiyong Park #include <lib/psci/psci.h>
14*54fd6939SJiyong Park 
15*54fd6939SJiyong Park #include <sunxi_cpucfg.h>
16*54fd6939SJiyong Park #include <sunxi_private.h>
17*54fd6939SJiyong Park 
sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint)18*54fd6939SJiyong Park int sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint)
19*54fd6939SJiyong Park {
20*54fd6939SJiyong Park 	/* The non-secure entry point must be in DRAM */
21*54fd6939SJiyong Park 	if (ns_entrypoint < SUNXI_DRAM_BASE) {
22*54fd6939SJiyong Park 		return PSCI_E_INVALID_ADDRESS;
23*54fd6939SJiyong Park 	}
24*54fd6939SJiyong Park 
25*54fd6939SJiyong Park 	return PSCI_E_SUCCESS;
26*54fd6939SJiyong Park }
27*54fd6939SJiyong Park 
plat_setup_psci_ops(uintptr_t sec_entrypoint,const plat_psci_ops_t ** psci_ops)28*54fd6939SJiyong Park int plat_setup_psci_ops(uintptr_t sec_entrypoint,
29*54fd6939SJiyong Park 			const plat_psci_ops_t **psci_ops)
30*54fd6939SJiyong Park {
31*54fd6939SJiyong Park 	assert(psci_ops);
32*54fd6939SJiyong Park 
33*54fd6939SJiyong Park 	/* Program all CPU entry points. */
34*54fd6939SJiyong Park 	for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; ++cpu) {
35*54fd6939SJiyong Park 		mmio_write_32(SUNXI_CPUCFG_RVBAR_LO_REG(cpu),
36*54fd6939SJiyong Park 			      sec_entrypoint & 0xffffffff);
37*54fd6939SJiyong Park 		mmio_write_32(SUNXI_CPUCFG_RVBAR_HI_REG(cpu),
38*54fd6939SJiyong Park 			      sec_entrypoint >> 32);
39*54fd6939SJiyong Park 	}
40*54fd6939SJiyong Park 
41*54fd6939SJiyong Park 	if (sunxi_set_scpi_psci_ops(psci_ops) == 0) {
42*54fd6939SJiyong Park 		INFO("PSCI: Suspend is available via SCPI\n");
43*54fd6939SJiyong Park 	} else {
44*54fd6939SJiyong Park 		INFO("PSCI: Suspend is unavailable\n");
45*54fd6939SJiyong Park 		sunxi_set_native_psci_ops(psci_ops);
46*54fd6939SJiyong Park 	}
47*54fd6939SJiyong Park 
48*54fd6939SJiyong Park 	return 0;
49*54fd6939SJiyong Park }
50