blob: 3772b4a572d82883aecd9a3627ec46b319f52106 [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
Samuel Hollandad6f6ca2021-01-16 00:56:48 -060028int sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint)
Samuel Holland0a9018c2017-08-12 04:07:39 -050029{
30 /* The non-secure entry point must be in DRAM */
Samuel Hollandcd120442021-01-16 01:21:38 -060031 if (ns_entrypoint < SUNXI_DRAM_BASE) {
32 return PSCI_E_INVALID_ADDRESS;
33 }
Samuel Holland0a9018c2017-08-12 04:07:39 -050034
Samuel Hollandcd120442021-01-16 01:21:38 -060035 return PSCI_E_SUCCESS;
Samuel Holland0a9018c2017-08-12 04:07:39 -050036}
37
Samuel Hollandb8566642017-08-12 04:07:39 -050038int plat_setup_psci_ops(uintptr_t sec_entrypoint,
39 const plat_psci_ops_t **psci_ops)
40{
41 assert(psci_ops);
42
Samuel Holland103ee9b2018-10-21 12:41:03 -050043 /* Program all CPU entry points. */
44 for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; ++cpu) {
Samuel Holland0a9018c2017-08-12 04:07:39 -050045 mmio_write_32(SUNXI_CPUCFG_RVBAR_LO_REG(cpu),
46 sec_entrypoint & 0xffffffff);
47 mmio_write_32(SUNXI_CPUCFG_RVBAR_HI_REG(cpu),
48 sec_entrypoint >> 32);
49 }
50
Samuel Hollandad6f6ca2021-01-16 00:56:48 -060051 if (sunxi_set_scpi_psci_ops(psci_ops) == 0) {
52 INFO("PSCI: Suspend is available via SCPI\n");
Samuel Holland365966c2022-01-22 23:37:12 -060053 psci_is_scpi = true;
Samuel Hollandad6f6ca2021-01-16 00:56:48 -060054 } else {
55 INFO("PSCI: Suspend is unavailable\n");
56 sunxi_set_native_psci_ops(psci_ops);
Samuel Holland103ee9b2018-10-21 12:41:03 -050057 }
58
Samuel Hollandb8566642017-08-12 04:07:39 -050059 return 0;
60}