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 | |
Mikhail Kalashnikov | 5cafd16 | 2023-03-27 18:36:14 +0300 | [diff] [blame] | 28 | #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 Holland | ad6f6ca | 2021-01-16 00:56:48 -0600 | [diff] [blame] | 33 | int sunxi_validate_ns_entrypoint(uintptr_t ns_entrypoint) |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 34 | { |
| 35 | /* The non-secure entry point must be in DRAM */ |
Samuel Holland | cd12044 | 2021-01-16 01:21:38 -0600 | [diff] [blame] | 36 | if (ns_entrypoint < SUNXI_DRAM_BASE) { |
| 37 | return PSCI_E_INVALID_ADDRESS; |
| 38 | } |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 39 | |
Samuel Holland | cd12044 | 2021-01-16 01:21:38 -0600 | [diff] [blame] | 40 | return PSCI_E_SUCCESS; |
Samuel Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 43 | int plat_setup_psci_ops(uintptr_t sec_entrypoint, |
| 44 | const plat_psci_ops_t **psci_ops) |
| 45 | { |
| 46 | assert(psci_ops); |
| 47 | |
Samuel Holland | 103ee9b | 2018-10-21 12:41:03 -0500 | [diff] [blame] | 48 | /* Program all CPU entry points. */ |
| 49 | for (unsigned int cpu = 0; cpu < PLATFORM_CORE_COUNT; ++cpu) { |
Mikhail Kalashnikov | 5cafd16 | 2023-03-27 18:36:14 +0300 | [diff] [blame] | 50 | 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 Holland | 0a9018c | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 61 | } |
| 62 | |
Samuel Holland | ad6f6ca | 2021-01-16 00:56:48 -0600 | [diff] [blame] | 63 | if (sunxi_set_scpi_psci_ops(psci_ops) == 0) { |
| 64 | INFO("PSCI: Suspend is available via SCPI\n"); |
Samuel Holland | 365966c | 2022-01-22 23:37:12 -0600 | [diff] [blame] | 65 | psci_is_scpi = true; |
Samuel Holland | ad6f6ca | 2021-01-16 00:56:48 -0600 | [diff] [blame] | 66 | } else { |
| 67 | INFO("PSCI: Suspend is unavailable\n"); |
| 68 | sunxi_set_native_psci_ops(psci_ops); |
Samuel Holland | 103ee9b | 2018-10-21 12:41:03 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Samuel Holland | b856664 | 2017-08-12 04:07:39 -0500 | [diff] [blame] | 71 | return 0; |
| 72 | } |