blob: ebc406b91ad4db8d73c0afce21a9ff2a05dd23e7 [file] [log] [blame]
Samuel Hollandb8566642017-08-12 04:07:39 -05001/*
Samuel Hollandcd120442021-01-16 01:21:38 -06002 * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
Samuel Hollandb8566642017-08-12 04:07:39 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Samuel Hollandb8566642017-08-12 04:07:39 -05007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Samuel Hollandb8566642017-08-12 04:07:39 -05009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <common/debug.h>
Samuel Holland365966c2022-01-22 23:37:12 -060012#include <common/fdt_fixup.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/mmio.h>
14#include <lib/psci/psci.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015
Samuel Holland0a9018c2017-08-12 04:07:39 -050016#include <sunxi_cpucfg.h>
Andre Przywara456208a2018-10-14 12:02:02 +010017#include <sunxi_private.h>
Samuel Hollandb8566642017-08-12 04:07:39 -050018
Samuel Holland365966c2022-01-22 23:37:12 -060019static bool psci_is_scpi;
20
21#if SUNXI_PSCI_USE_SCPI
22bool sunxi_psci_is_scpi(void)
23{
24 return psci_is_scpi;
25}
26#endif
27
Mikhail Kalashnikov5cafd162023-03-27 18:36:14 +030028#ifndef SUNXI_ALT_RVBAR_LO_REG
29#define SUNXI_ALT_RVBAR_LO_REG(n) 0
30#define SUNXI_ALT_RVBAR_HI_REG(n) 0
31#endif
32
Samuel Hollandad6f6ca2021-01-16 00:56:48 -060033int sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint)
Samuel Holland0a9018c2017-08-12 04:07:39 -050034{
35 /* The non-secure entry point must be in DRAM */
Samuel Hollandcd120442021-01-16 01:21:38 -060036 if (ns_entrypoint < SUNXI_DRAM_BASE) {
37 return PSCI_E_INVALID_ADDRESS;
38 }
Samuel Holland0a9018c2017-08-12 04:07:39 -050039
Samuel Hollandcd120442021-01-16 01:21:38 -060040 return PSCI_E_SUCCESS;
Samuel Holland0a9018c2017-08-12 04:07:39 -050041}
42
Samuel Hollandb8566642017-08-12 04:07:39 -050043int plat_setup_psci_ops(uintptr_t sec_entrypoint,
44 const plat_psci_ops_t **psci_ops)
45{
46 assert(psci_ops);
47
Samuel Holland103ee9b2018-10-21 12:41:03 -050048 /* Program all CPU entry points. */
49 for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; ++cpu) {
Mikhail Kalashnikov5cafd162023-03-27 18:36:14 +030050 if (sunxi_cpucfg_has_per_cluster_regs()) {
51 mmio_write_32(SUNXI_CPUCFG_RVBAR_LO_REG(cpu),
52 sec_entrypoint & 0xffffffff);
53 mmio_write_32(SUNXI_CPUCFG_RVBAR_HI_REG(cpu),
54 sec_entrypoint >> 32);
55 } else {
56 mmio_write_32(SUNXI_ALT_RVBAR_LO_REG(cpu),
57 sec_entrypoint & 0xffffffff);
58 mmio_write_32(SUNXI_ALT_RVBAR_HI_REG(cpu),
59 sec_entrypoint >> 32);
60 }
Samuel Holland0a9018c2017-08-12 04:07:39 -050061 }
62
Samuel Hollandad6f6ca2021-01-16 00:56:48 -060063 if (sunxi_set_scpi_psci_ops(psci_ops) == 0) {
64 INFO("PSCI: Suspend is available via SCPI\n");
Samuel Holland365966c2022-01-22 23:37:12 -060065 psci_is_scpi = true;
Samuel Hollandad6f6ca2021-01-16 00:56:48 -060066 } else {
67 INFO("PSCI: Suspend is unavailable\n");
68 sunxi_set_native_psci_ops(psci_ops);
Samuel Holland103ee9b2018-10-21 12:41:03 -050069 }
70
Samuel Hollandb8566642017-08-12 04:07:39 -050071 return 0;
72}