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