Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 1 | /* |
Samuel Holland | cd12044 | 2021-01-16 01:21:38 -0600 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved. |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 9 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <common/debug.h> |
Samuel Holland | 365966c | 2022-01-22 23:37:12 -0600 | [diff] [blame] | 12 | #include <common/fdt_fixup.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <lib/mmio.h> |
| 14 | #include <lib/psci/psci.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 16 | #include <sunxi_cpucfg.h> |
Andre Przywara | 456208a | 2018-10-14 12:02:02 +0100 | [diff] [blame] | 17 | #include <sunxi_private.h> |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 18 | |
Samuel Holland | 365966c | 2022-01-22 23:37:12 -0600 | [diff] [blame] | 19 | static bool psci_is_scpi; |
| 20 | |
| 21 | #if SUNXI_PSCI_USE_SCPI |
| 22 | bool sunxi_psci_is_scpi(void) |
| 23 | { |
| 24 | return psci_is_scpi; |
| 25 | } |
| 26 | #endif |
| 27 | |
Samuel Holland | ad6f6ca | 2021-01-16 00:56:48 -0600 | [diff] [blame] | 28 | int sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint) |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 29 | { |
| 30 | /* The non-secure entry point must be in DRAM */ |
Samuel Holland | cd12044 | 2021-01-16 01:21:38 -0600 | [diff] [blame] | 31 | if (ns_entrypoint < SUNXI_DRAM_BASE) { |
| 32 | return PSCI_E_INVALID_ADDRESS; |
| 33 | } |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 34 | |
Samuel Holland | cd12044 | 2021-01-16 01:21:38 -0600 | [diff] [blame] | 35 | return PSCI_E_SUCCESS; |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 36 | } |
| 37 | |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 38 | int plat_setup_psci_ops(uintptr_t sec_entrypoint, |
| 39 | const plat_psci_ops_t **psci_ops) |
| 40 | { |
| 41 | assert(psci_ops); |
| 42 | |
Samuel Holland | 103ee9b | 2018-10-21 12:41:03 -0500 | [diff] [blame] | 43 | /* Program all CPU entry points. */ |
| 44 | for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; ++cpu) { |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 45 | 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 Holland | ad6f6ca | 2021-01-16 00:56:48 -0600 | [diff] [blame] | 51 | if (sunxi_set_scpi_psci_ops(psci_ops) == 0) { |
| 52 | INFO("PSCI: Suspend is available via SCPI\n"); |
Samuel Holland | 365966c | 2022-01-22 23:37:12 -0600 | [diff] [blame] | 53 | psci_is_scpi = true; |
Samuel Holland | ad6f6ca | 2021-01-16 00:56:48 -0600 | [diff] [blame] | 54 | } else { |
| 55 | INFO("PSCI: Suspend is unavailable\n"); |
| 56 | sunxi_set_native_psci_ops(psci_ops); |
Samuel Holland | 103ee9b | 2018-10-21 12:41:03 -0500 | [diff] [blame] | 57 | } |
| 58 | |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 59 | return 0; |
| 60 | } |