Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Manish Pandey | ef738d1 | 2024-06-22 00:00:18 +0100 | [diff] [blame] | 2 | * Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <assert.h> |
| 8 | #include <stddef.h> |
| 9 | |
Dan Handley | 97043ac | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 10 | #include <arch.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 11 | #include <arch_helpers.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <common/bl_common.h> |
Dan Handley | 97043ac | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 13 | #include <context.h> |
Boyan Karatotev | 6bb96fa | 2023-01-27 09:37:07 +0000 | [diff] [blame] | 14 | #include <lib/cpus/errata.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <lib/el3_runtime/context_mgmt.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
| 17 | |
Dan Handley | 35e98e5 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 18 | #include "psci_private.h" |
Achin Gupta | ef7a28c | 2014-02-01 08:59:56 +0000 | [diff] [blame] | 19 | |
Graeme Gregory | a86865a | 2020-12-02 16:24:32 +0000 | [diff] [blame] | 20 | /* |
| 21 | * Check that PLATFORM_CORE_COUNT fits into the number of cores |
| 22 | * that can be represented by PSCI_MAX_CPUS_INDEX. |
| 23 | */ |
| 24 | CASSERT(PLATFORM_CORE_COUNT <= (PSCI_MAX_CPUS_INDEX + 1U), assert_psci_cores_overflow); |
| 25 | |
Achin Gupta | ef7a28c | 2014-02-01 08:59:56 +0000 | [diff] [blame] | 26 | /******************************************************************************* |
| 27 | * Per cpu non-secure contexts used to program the architectural state prior |
| 28 | * return to the normal world. |
| 29 | * TODO: Use the memory allocator to set aside memory for the contexts instead |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 30 | * of relying on platform defined constants. |
Achin Gupta | ef7a28c | 2014-02-01 08:59:56 +0000 | [diff] [blame] | 31 | ******************************************************************************/ |
Dan Handley | fb037bf | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 32 | static cpu_context_t psci_ns_context[PLATFORM_CORE_COUNT]; |
Manish Pandey | ef738d1 | 2024-06-22 00:00:18 +0100 | [diff] [blame] | 33 | static entry_point_info_t warmboot_ep_info[PLATFORM_CORE_COUNT]; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 34 | |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 35 | /****************************************************************************** |
| 36 | * Define the psci capability variable. |
| 37 | *****************************************************************************/ |
Soby Mathew | 9d070b9 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 38 | unsigned int psci_caps; |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 39 | |
Dan Handley | 7a9a5f2 | 2014-05-14 15:13:16 +0100 | [diff] [blame] | 40 | /******************************************************************************* |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 41 | * Function which initializes the 'psci_non_cpu_pd_nodes' or the |
| 42 | * 'psci_cpu_pd_nodes' corresponding to the power level. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 43 | ******************************************************************************/ |
Graeme Gregory | a86865a | 2020-12-02 16:24:32 +0000 | [diff] [blame] | 44 | static void __init psci_init_pwr_domain_node(uint16_t node_idx, |
Soby Mathew | 9d070b9 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 45 | unsigned int parent_idx, |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 46 | unsigned char level) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 47 | { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 48 | if (level > PSCI_CPU_PWR_LVL) { |
Graeme Gregory | a86865a | 2020-12-02 16:24:32 +0000 | [diff] [blame] | 49 | assert(node_idx < PSCI_NUM_NON_CPU_PWR_DOMAINS); |
| 50 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 51 | psci_non_cpu_pd_nodes[node_idx].level = level; |
| 52 | psci_lock_init(psci_non_cpu_pd_nodes, node_idx); |
| 53 | psci_non_cpu_pd_nodes[node_idx].parent_node = parent_idx; |
| 54 | psci_non_cpu_pd_nodes[node_idx].local_state = |
| 55 | PLAT_MAX_OFF_STATE; |
| 56 | } else { |
| 57 | psci_cpu_data_t *svc_cpu_data; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 58 | |
Graeme Gregory | a86865a | 2020-12-02 16:24:32 +0000 | [diff] [blame] | 59 | assert(node_idx < PLATFORM_CORE_COUNT); |
| 60 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 61 | psci_cpu_pd_nodes[node_idx].parent_node = parent_idx; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 62 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 63 | /* Initialize with an invalid mpidr */ |
| 64 | psci_cpu_pd_nodes[node_idx].mpidr = PSCI_INVALID_MPIDR; |
Soby Mathew | 264999f | 2014-10-02 17:24:19 +0100 | [diff] [blame] | 65 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 66 | svc_cpu_data = |
| 67 | &(_cpu_data_by_index(node_idx)->psci_svc_cpu_data); |
Soby Mathew | 264999f | 2014-10-02 17:24:19 +0100 | [diff] [blame] | 68 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 69 | /* Set the Affinity Info for the cores as OFF */ |
| 70 | svc_cpu_data->aff_info_state = AFF_STATE_OFF; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 71 | |
Boyan Karatotev | 0c83655 | 2024-09-30 11:31:55 +0100 | [diff] [blame] | 72 | /* Default to the highest power level when the cpu is not suspending */ |
| 73 | svc_cpu_data->target_pwrlvl = PLAT_MAX_PWR_LVL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 74 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 75 | /* Set the power state to OFF state */ |
| 76 | svc_cpu_data->local_state = PLAT_MAX_OFF_STATE; |
Soby Mathew | 264999f | 2014-10-02 17:24:19 +0100 | [diff] [blame] | 77 | |
Jeenu Viswambharan | a10d363 | 2017-01-06 14:58:11 +0000 | [diff] [blame] | 78 | psci_flush_dcache_range((uintptr_t)svc_cpu_data, |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 79 | sizeof(*svc_cpu_data)); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 80 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 81 | cm_set_context_by_index(node_idx, |
| 82 | (void *) &psci_ns_context[node_idx], |
Andrew Thoelke | 08ab89d | 2014-05-14 17:09:32 +0100 | [diff] [blame] | 83 | NON_SECURE); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 84 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /******************************************************************************* |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 88 | * This functions updates cpu_start_idx and ncpus field for each of the node in |
| 89 | * psci_non_cpu_pd_nodes[]. It does so by comparing the parent nodes of each of |
| 90 | * the CPUs and check whether they match with the parent of the previous |
| 91 | * CPU. The basic assumption for this work is that children of the same parent |
| 92 | * are allocated adjacent indices. The platform should ensure this though proper |
| 93 | * mapping of the CPUs to indices via plat_core_pos_by_mpidr() and |
| 94 | * plat_my_core_pos() APIs. |
| 95 | *******************************************************************************/ |
Daniel Boulby | 87c8513 | 2018-09-20 14:12:46 +0100 | [diff] [blame] | 96 | static void __init psci_update_pwrlvl_limits(void) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 97 | { |
Pankaj Gupta | ab4df50 | 2019-10-15 15:44:45 +0530 | [diff] [blame] | 98 | unsigned int cpu_idx; |
| 99 | int j; |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 100 | unsigned int nodes_idx[PLAT_MAX_PWR_LVL] = {0}; |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 101 | unsigned int temp_index[PLAT_MAX_PWR_LVL]; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 102 | |
Pankaj Gupta | ab4df50 | 2019-10-15 15:44:45 +0530 | [diff] [blame] | 103 | for (cpu_idx = 0; cpu_idx < psci_plat_core_count; cpu_idx++) { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 104 | psci_get_parent_pwr_domain_nodes(cpu_idx, |
Deepika Bhavnani | 5b33ad1 | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 105 | PLAT_MAX_PWR_LVL, |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 106 | temp_index); |
Deepika Bhavnani | 5b33ad1 | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 107 | for (j = (int)PLAT_MAX_PWR_LVL - 1; j >= 0; j--) { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 108 | if (temp_index[j] != nodes_idx[j]) { |
| 109 | nodes_idx[j] = temp_index[j]; |
| 110 | psci_non_cpu_pd_nodes[nodes_idx[j]].cpu_start_idx |
| 111 | = cpu_idx; |
| 112 | } |
| 113 | psci_non_cpu_pd_nodes[nodes_idx[j]].ncpus++; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
Manish Pandey | ef738d1 | 2024-06-22 00:00:18 +0100 | [diff] [blame] | 118 | static void __init populate_cpu_data(void) |
| 119 | { |
| 120 | for (unsigned int idx = 0; idx < psci_plat_core_count; idx++) { |
| 121 | set_cpu_data_by_index(idx, warmboot_ep_info, &warmboot_ep_info[idx]); |
| 122 | } |
| 123 | } |
| 124 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 125 | /******************************************************************************* |
| 126 | * Core routine to populate the power domain tree. The tree descriptor passed by |
| 127 | * the platform is populated breadth-first and the first entry in the map |
| 128 | * informs the number of root power domains. The parent nodes of the root nodes |
| 129 | * will point to an invalid entry(-1). |
| 130 | ******************************************************************************/ |
Pankaj Gupta | ab4df50 | 2019-10-15 15:44:45 +0530 | [diff] [blame] | 131 | static unsigned int __init populate_power_domain_tree(const unsigned char |
| 132 | *topology) |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 133 | { |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 134 | unsigned int i, j = 0U, num_nodes_at_lvl = 1U, num_nodes_at_next_lvl; |
| 135 | unsigned int node_index = 0U, num_children; |
Deepika Bhavnani | 5b33ad1 | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 136 | unsigned int parent_node_index = 0U; |
| 137 | int level = (int)PLAT_MAX_PWR_LVL; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 138 | |
| 139 | /* |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 140 | * For each level the inputs are: |
| 141 | * - number of nodes at this level in plat_array i.e. num_nodes_at_level |
| 142 | * This is the sum of values of nodes at the parent level. |
| 143 | * - Index of first entry at this level in the plat_array i.e. |
| 144 | * parent_node_index. |
| 145 | * - Index of first free entry in psci_non_cpu_pd_nodes[] or |
| 146 | * psci_cpu_pd_nodes[] i.e. node_index depending upon the level. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 147 | */ |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 148 | while (level >= (int) PSCI_CPU_PWR_LVL) { |
| 149 | num_nodes_at_next_lvl = 0U; |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 150 | /* |
| 151 | * For each entry (parent node) at this level in the plat_array: |
| 152 | * - Find the number of children |
| 153 | * - Allocate a node in a power domain array for each child |
| 154 | * - Set the parent of the child to the parent_node_index - 1 |
| 155 | * - Increment parent_node_index to point to the next parent |
| 156 | * - Accumulate the number of children at next level. |
| 157 | */ |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 158 | for (i = 0U; i < num_nodes_at_lvl; i++) { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 159 | assert(parent_node_index <= |
| 160 | PSCI_NUM_NON_CPU_PWR_DOMAINS); |
| 161 | num_children = topology[parent_node_index]; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 162 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 163 | for (j = node_index; |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 164 | j < (node_index + num_children); j++) |
Graeme Gregory | a86865a | 2020-12-02 16:24:32 +0000 | [diff] [blame] | 165 | psci_init_pwr_domain_node((uint16_t)j, |
Deepika Bhavnani | 5b33ad1 | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 166 | parent_node_index - 1U, |
| 167 | (unsigned char)level); |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 168 | |
| 169 | node_index = j; |
| 170 | num_nodes_at_next_lvl += num_children; |
| 171 | parent_node_index++; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 174 | num_nodes_at_lvl = num_nodes_at_next_lvl; |
| 175 | level--; |
| 176 | |
| 177 | /* Reset the index for the cpu power domain array */ |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 178 | if (level == (int) PSCI_CPU_PWR_LVL) |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 179 | node_index = 0; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 182 | /* Validate the sanity of array exported by the platform */ |
Deepika Bhavnani | 5b33ad1 | 2019-12-13 10:23:18 -0600 | [diff] [blame] | 183 | assert(j <= PLATFORM_CORE_COUNT); |
Pankaj Gupta | ab4df50 | 2019-10-15 15:44:45 +0530 | [diff] [blame] | 184 | return j; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /******************************************************************************* |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 188 | * This function does the architectural setup and takes the warm boot |
| 189 | * entry-point `mailbox_ep` as an argument. The function also initializes the |
| 190 | * power domain topology tree by querying the platform. The power domain nodes |
| 191 | * higher than the CPU are populated in the array psci_non_cpu_pd_nodes[] and |
| 192 | * the CPU power domains are populated in psci_cpu_pd_nodes[]. The platform |
| 193 | * exports its static topology map through the |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 194 | * populate_power_domain_topology_tree() API. The algorithm populates the |
| 195 | * psci_non_cpu_pd_nodes and psci_cpu_pd_nodes iteratively by using this |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 196 | * topology map. On a platform that implements two clusters of 2 cpus each, |
| 197 | * and supporting 3 domain levels, the populated psci_non_cpu_pd_nodes would |
| 198 | * look like this: |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 199 | * |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 200 | * --------------------------------------------------- |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 201 | * | system node | cluster 0 node | cluster 1 node | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 202 | * --------------------------------------------------- |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 203 | * |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 204 | * And populated psci_cpu_pd_nodes would look like this : |
| 205 | * <- cpus cluster0 -><- cpus cluster1 -> |
| 206 | * ------------------------------------------------ |
| 207 | * | CPU 0 | CPU 1 | CPU 2 | CPU 3 | |
| 208 | * ------------------------------------------------ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 209 | ******************************************************************************/ |
Daniel Boulby | 87c8513 | 2018-09-20 14:12:46 +0100 | [diff] [blame] | 210 | int __init psci_setup(const psci_lib_args_t *lib_args) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 211 | { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 212 | const unsigned char *topology_tree; |
Boyan Karatotev | 3b80210 | 2024-11-06 16:26:15 +0000 | [diff] [blame] | 213 | unsigned int cpu_idx = plat_my_core_pos(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 214 | |
Soby Mathew | f426fc0 | 2016-09-13 14:19:08 +0100 | [diff] [blame] | 215 | assert(VERIFY_PSCI_LIB_ARGS_V1(lib_args)); |
| 216 | |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 217 | /* Do the Architectural initialization */ |
| 218 | psci_arch_setup(); |
| 219 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 220 | /* Query the topology map from the platform */ |
| 221 | topology_tree = plat_get_power_domain_tree_desc(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 222 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 223 | /* Populate the power domain arrays using the platform topology map */ |
Pankaj Gupta | ab4df50 | 2019-10-15 15:44:45 +0530 | [diff] [blame] | 224 | psci_plat_core_count = populate_power_domain_tree(topology_tree); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 225 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 226 | /* Update the CPU limits for each node in psci_non_cpu_pd_nodes */ |
| 227 | psci_update_pwrlvl_limits(); |
| 228 | |
Manish Pandey | ef738d1 | 2024-06-22 00:00:18 +0100 | [diff] [blame] | 229 | /* Initialise the warmboot entrypoints */ |
| 230 | populate_cpu_data(); |
| 231 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 232 | /* Populate the mpidr field of cpu node for this CPU */ |
Boyan Karatotev | 3b80210 | 2024-11-06 16:26:15 +0000 | [diff] [blame] | 233 | psci_cpu_pd_nodes[cpu_idx].mpidr = |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 234 | read_mpidr() & MPIDR_AFFINITY_MASK; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 235 | |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 236 | psci_init_req_local_pwr_states(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 237 | |
| 238 | /* |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 239 | * Set the requested and target state of this CPU and all the higher |
| 240 | * power domain levels for this CPU to run. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 241 | */ |
Boyan Karatotev | 3b80210 | 2024-11-06 16:26:15 +0000 | [diff] [blame] | 242 | psci_set_pwr_domains_to_run(cpu_idx, PLAT_MAX_PWR_LVL); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 243 | |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 244 | (void) plat_setup_psci_ops((uintptr_t)lib_args->mailbox_ep, |
| 245 | &psci_plat_pm_ops); |
| 246 | assert(psci_plat_pm_ops != NULL); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 247 | |
Soby Mathew | 7a3d4bd | 2016-09-09 11:33:58 +0100 | [diff] [blame] | 248 | /* |
| 249 | * Flush `psci_plat_pm_ops` as it will be accessed by secondary CPUs |
Jeenu Viswambharan | a10d363 | 2017-01-06 14:58:11 +0000 | [diff] [blame] | 250 | * during warm boot, possibly before data cache is enabled. |
Soby Mathew | 7a3d4bd | 2016-09-09 11:33:58 +0100 | [diff] [blame] | 251 | */ |
Jeenu Viswambharan | a10d363 | 2017-01-06 14:58:11 +0000 | [diff] [blame] | 252 | psci_flush_dcache_range((uintptr_t)&psci_plat_pm_ops, |
Soby Mathew | 7a3d4bd | 2016-09-09 11:33:58 +0100 | [diff] [blame] | 253 | sizeof(psci_plat_pm_ops)); |
| 254 | |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 255 | /* Initialize the psci capability */ |
| 256 | psci_caps = PSCI_GENERIC_CAP; |
| 257 | |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 258 | if (psci_plat_pm_ops->pwr_domain_off != NULL) { |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 259 | psci_caps |= define_psci_cap(PSCI_CPU_OFF); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 260 | } |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 261 | if ((psci_plat_pm_ops->pwr_domain_on != NULL) && |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 262 | (psci_plat_pm_ops->pwr_domain_on_finish != NULL)) { |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 263 | psci_caps |= define_psci_cap(PSCI_CPU_ON_AARCH64); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 264 | } |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 265 | if ((psci_plat_pm_ops->pwr_domain_suspend != NULL) && |
| 266 | (psci_plat_pm_ops->pwr_domain_suspend_finish != NULL)) { |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 267 | if (psci_plat_pm_ops->validate_power_state != NULL) { |
Samuel Holland | a1d5ac6 | 2021-04-28 17:52:02 -0500 | [diff] [blame] | 268 | psci_caps |= define_psci_cap(PSCI_CPU_SUSPEND_AARCH64); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 269 | } |
| 270 | if (psci_plat_pm_ops->get_sys_suspend_power_state != NULL) { |
Soby Mathew | c0aff0e | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 271 | psci_caps |= define_psci_cap(PSCI_SYSTEM_SUSPEND_AARCH64); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 272 | } |
Wing Li | b88a441 | 2022-09-14 13:18:15 -0700 | [diff] [blame] | 273 | #if PSCI_OS_INIT_MODE |
| 274 | psci_caps |= define_psci_cap(PSCI_SET_SUSPEND_MODE); |
| 275 | #endif |
Soby Mathew | c0aff0e | 2014-12-17 14:47:57 +0000 | [diff] [blame] | 276 | } |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 277 | if (psci_plat_pm_ops->system_off != NULL) { |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 278 | psci_caps |= define_psci_cap(PSCI_SYSTEM_OFF); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 279 | } |
| 280 | if (psci_plat_pm_ops->system_reset != NULL) { |
Soby Mathew | 90e8258 | 2015-01-07 11:10:22 +0000 | [diff] [blame] | 281 | psci_caps |= define_psci_cap(PSCI_SYSTEM_RESET); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 282 | } |
| 283 | if (psci_plat_pm_ops->get_node_hw_state != NULL) { |
Jeenu Viswambharan | 28d3d61 | 2016-08-03 15:54:50 +0100 | [diff] [blame] | 284 | psci_caps |= define_psci_cap(PSCI_NODE_HW_STATE_AARCH64); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 285 | } |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 286 | if ((psci_plat_pm_ops->read_mem_protect != NULL) && |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 287 | (psci_plat_pm_ops->write_mem_protect != NULL)) { |
Roberto Vargas | d4c596b | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 288 | psci_caps |= define_psci_cap(PSCI_MEM_PROTECT); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 289 | } |
| 290 | if (psci_plat_pm_ops->mem_protect_chk != NULL) { |
Roberto Vargas | d4c596b | 2017-08-03 08:16:16 +0100 | [diff] [blame] | 291 | psci_caps |= define_psci_cap(PSCI_MEM_CHK_RANGE_AARCH64); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 292 | } |
| 293 | if (psci_plat_pm_ops->system_reset2 != NULL) { |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 294 | psci_caps |= define_psci_cap(PSCI_SYSTEM_RESET2_AARCH64); |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 295 | } |
Yatharth Kochar | 170fb93 | 2016-05-09 18:26:35 +0100 | [diff] [blame] | 296 | #if ENABLE_PSCI_STAT |
| 297 | psci_caps |= define_psci_cap(PSCI_STAT_RESIDENCY_AARCH64); |
| 298 | psci_caps |= define_psci_cap(PSCI_STAT_COUNT_AARCH64); |
| 299 | #endif |
| 300 | |
Achin Gupta | 7421b46 | 2014-02-01 18:53:26 +0000 | [diff] [blame] | 301 | return 0; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 302 | } |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 303 | |
| 304 | /******************************************************************************* |
| 305 | * This duplicates what the primary cpu did after a cold boot in BL1. The same |
| 306 | * needs to be done when a cpu is hotplugged in. This function could also over- |
| 307 | * ride any EL3 setup done by BL1 as this code resides in rw memory. |
| 308 | ******************************************************************************/ |
| 309 | void psci_arch_setup(void) |
| 310 | { |
Antonio Nino Diaz | 6b7b0f3 | 2018-07-17 15:10:08 +0100 | [diff] [blame] | 311 | #if (ARM_ARCH_MAJOR > 7) || defined(ARMV7_SUPPORTS_GENERIC_TIMER) |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 312 | /* Program the counter frequency */ |
| 313 | write_cntfrq_el0(plat_get_syscnt_freq2()); |
Etienne Carriere | 86e2683 | 2017-11-08 14:41:47 +0100 | [diff] [blame] | 314 | #endif |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 315 | |
| 316 | /* Initialize the cpu_ops pointer. */ |
| 317 | init_cpu_ops(); |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 318 | |
| 319 | /* Having initialized cpu_ops, we can now print errata status */ |
| 320 | print_errata_status(); |
Alexei Fedorov | ed108b5 | 2019-09-13 14:11:59 +0100 | [diff] [blame] | 321 | |
Soby Mathew | cf0b149 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 322 | } |
Soby Mathew | 727e523 | 2016-05-05 14:11:23 +0100 | [diff] [blame] | 323 | |
| 324 | /****************************************************************************** |
| 325 | * PSCI Library interface to initialize the cpu context for the next non |
| 326 | * secure image during cold boot. The relevant registers in the cpu context |
| 327 | * need to be retrieved and programmed on return from this interface. |
| 328 | *****************************************************************************/ |
| 329 | void psci_prepare_next_non_secure_ctx(entry_point_info_t *next_image_info) |
| 330 | { |
| 331 | assert(GET_SECURITY_STATE(next_image_info->h.attr) == NON_SECURE); |
| 332 | cm_init_my_context(next_image_info); |
| 333 | cm_prepare_el3_exit(NON_SECURE); |
| 334 | } |