Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Chris Kay | e2ae162 | 2024-02-06 17:44:31 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2024, 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 | |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
Dan Handley | 2b6b574 | 2015-03-19 19:17:53 +0000 | [diff] [blame] | 9 | #include <arch.h> |
Antonio Nino Diaz | f13d09a | 2019-01-23 21:50:09 +0000 | [diff] [blame] | 10 | #include <drivers/arm/fvp/fvp_pwrc.h> |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 11 | #include <fconf_hw_config_getter.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <lib/cassert.h> |
Antonio Nino Diaz | bd7b740 | 2019-01-25 14:30:04 +0000 | [diff] [blame] | 13 | #include <plat/arm/common/arm_config.h> |
| 14 | #include <plat/arm/common/plat_arm.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <plat/common/platform.h> |
| 16 | |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 17 | #include <platform_def.h> |
| 18 | |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 19 | /* The FVP power domain tree descriptor */ |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 20 | static unsigned char fvp_power_domain_tree_desc[FVP_CLUSTER_COUNT + 2]; |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 21 | |
| 22 | |
Sathees Balya | 30952cc | 2018-09-27 14:41:02 +0100 | [diff] [blame] | 23 | CASSERT(((FVP_CLUSTER_COUNT > 0) && (FVP_CLUSTER_COUNT <= 256)), |
| 24 | assert_invalid_fvp_cluster_count); |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 25 | |
| 26 | /******************************************************************************* |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 27 | * This function dynamically constructs the topology according to cpu-map node |
| 28 | * in HW_CONFIG dtb and returns it. |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 29 | ******************************************************************************/ |
| 30 | const unsigned char *plat_get_power_domain_tree_desc(void) |
| 31 | { |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 32 | unsigned int i; |
| 33 | uint32_t cluster_count, cpus_per_cluster; |
| 34 | |
| 35 | /* |
| 36 | * fconf APIs are not supported for RESET_TO_SP_MIN, RESET_TO_BL31 and |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 37 | * RESET_TO_BL2 systems. |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 38 | */ |
Chris Kay | e2ae162 | 2024-02-06 17:44:31 +0000 | [diff] [blame] | 39 | #if RESET_TO_SP_MIN || RESET_TO_BL31 || RESET_TO_BL2 || IMAGE_BL1 |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 40 | cluster_count = FVP_CLUSTER_COUNT; |
| 41 | cpus_per_cluster = FVP_MAX_CPUS_PER_CLUSTER * FVP_MAX_PE_PER_CPU; |
| 42 | #else |
| 43 | cluster_count = FCONF_GET_PROPERTY(hw_config, topology, plat_cluster_count); |
| 44 | cpus_per_cluster = FCONF_GET_PROPERTY(hw_config, topology, cluster_cpu_count); |
| 45 | /* Several FVP Models use the same blanket dts. Ex: FVP_Base_Cortex-A65x4 |
| 46 | * and FVP_Base_Cortex-A65AEx8 both use same dts but have different number of |
| 47 | * CPUs in the cluster, as reflected by build flags FVP_MAX_CPUS_PER_CLUSTER. |
| 48 | * Take the minimum of two to ensure PSCI functions do not exceed the size of |
| 49 | * the PSCI data structures allocated at build time. |
| 50 | */ |
| 51 | cpus_per_cluster = MIN(cpus_per_cluster, |
| 52 | (uint32_t)(FVP_MAX_CPUS_PER_CLUSTER * FVP_MAX_PE_PER_CPU)); |
| 53 | |
| 54 | #endif |
| 55 | |
| 56 | assert(cluster_count > 0U); |
| 57 | assert(cpus_per_cluster > 0U); |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 60 | * The highest level is the system level. The next level is constituted |
| 61 | * by clusters and then cores in clusters. |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 62 | */ |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 63 | fvp_power_domain_tree_desc[0] = 1; |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 64 | fvp_power_domain_tree_desc[1] = (unsigned char)cluster_count; |
Soby Mathew | 9ca2806 | 2017-10-11 16:08:58 +0100 | [diff] [blame] | 65 | |
Madhukar Pappireddy | 7b834ad | 2020-02-21 14:01:44 -0600 | [diff] [blame] | 66 | for (i = 0; i < cluster_count; i++) |
| 67 | fvp_power_domain_tree_desc[i + 2] = (unsigned char)cpus_per_cluster; |
Soby Mathew | 47e43f2 | 2016-02-01 14:04:34 +0000 | [diff] [blame] | 68 | |
| 69 | return fvp_power_domain_tree_desc; |
| 70 | } |
| 71 | |
| 72 | /******************************************************************************* |
| 73 | * This function returns the core count within the cluster corresponding to |
| 74 | * `mpidr`. |
| 75 | ******************************************************************************/ |
| 76 | unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr) |
| 77 | { |
| 78 | return FVP_MAX_CPUS_PER_CLUSTER; |
| 79 | } |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 80 | |
| 81 | /******************************************************************************* |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 82 | * This function implements a part of the critical interface between the psci |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 83 | * generic layer and the platform that allows the former to query the platform |
| 84 | * to convert an MPIDR to a unique linear index. An error code (-1) is returned |
| 85 | * in case the MPIDR is invalid. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 86 | ******************************************************************************/ |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 87 | int plat_core_pos_by_mpidr(u_register_t mpidr) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 88 | { |
Jeenu Viswambharan | 9e78b92 | 2017-07-18 15:42:50 +0100 | [diff] [blame] | 89 | unsigned int clus_id, cpu_id, thread_id; |
| 90 | |
| 91 | /* Validate affinity fields */ |
Sathees Balya | 30952cc | 2018-09-27 14:41:02 +0100 | [diff] [blame] | 92 | if ((arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) != 0U) { |
Jeenu Viswambharan | 9e78b92 | 2017-07-18 15:42:50 +0100 | [diff] [blame] | 93 | thread_id = MPIDR_AFFLVL0_VAL(mpidr); |
| 94 | cpu_id = MPIDR_AFFLVL1_VAL(mpidr); |
| 95 | clus_id = MPIDR_AFFLVL2_VAL(mpidr); |
| 96 | } else { |
| 97 | thread_id = 0; |
| 98 | cpu_id = MPIDR_AFFLVL0_VAL(mpidr); |
| 99 | clus_id = MPIDR_AFFLVL1_VAL(mpidr); |
| 100 | } |
| 101 | |
| 102 | if (clus_id >= FVP_CLUSTER_COUNT) |
| 103 | return -1; |
| 104 | if (cpu_id >= FVP_MAX_CPUS_PER_CLUSTER) |
| 105 | return -1; |
| 106 | if (thread_id >= FVP_MAX_PE_PER_CPU) |
| 107 | return -1; |
| 108 | |
Chris Kay | e2ae162 | 2024-02-06 17:44:31 +0000 | [diff] [blame] | 109 | #if !IMAGE_BL1 |
Soby Mathew | fec4eb7 | 2015-07-01 16:16:20 +0100 | [diff] [blame] | 110 | if (fvp_pwrc_read_psysr(mpidr) == PSYSR_INVALID) |
| 111 | return -1; |
Chris Kay | e2ae162 | 2024-02-06 17:44:31 +0000 | [diff] [blame] | 112 | #endif /* IMAGE_BL1 */ |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 113 | |
Jeenu Viswambharan | 528d21b | 2016-11-15 13:53:57 +0000 | [diff] [blame] | 114 | /* |
| 115 | * Core position calculation for FVP platform depends on the MT bit in |
| 116 | * MPIDR. This function cannot assume that the supplied MPIDR has the MT |
| 117 | * bit set even if the implementation has. For example, PSCI clients |
| 118 | * might supply MPIDR values without the MT bit set. Therefore, we |
| 119 | * inject the current PE's MT bit so as to get the calculation correct. |
| 120 | * This of course assumes that none or all CPUs on the platform has MT |
| 121 | * bit set. |
| 122 | */ |
| 123 | mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK); |
Sathees Balya | 30952cc | 2018-09-27 14:41:02 +0100 | [diff] [blame] | 124 | return (int) plat_arm_calc_core_pos(mpidr); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 125 | } |