blob: 4a007f4f526c041f1a2161b5f78fffe5dc4a9957 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Jeenu Viswambharan528d21b2016-11-15 13:53:57 +00002 * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01005 */
6
Dan Handley2b6b5742015-03-19 19:17:53 +00007#include <arch.h>
Jeenu Viswambharan528d21b2016-11-15 13:53:57 +00008#include <arm_config.h>
Soby Mathew47e43f22016-02-01 14:04:34 +00009#include <cassert.h>
Soby Mathewfec4eb72015-07-01 16:16:20 +010010#include <plat_arm.h>
Dan Handleyed6ff952014-05-14 17:44:19 +010011#include <platform_def.h>
Dan Handley4d2e49d2014-04-11 11:52:12 +010012#include "drivers/pwrc/fvp_pwrc.h"
Achin Gupta4f6ad662013-10-25 09:08:21 +010013
Soby Mathewfec4eb72015-07-01 16:16:20 +010014/* The FVP power domain tree descriptor */
Soby Mathew9ca28062017-10-11 16:08:58 +010015unsigned char fvp_power_domain_tree_desc[FVP_CLUSTER_COUNT + 2];
Soby Mathew47e43f22016-02-01 14:04:34 +000016
17
18CASSERT(FVP_CLUSTER_COUNT && FVP_CLUSTER_COUNT <= 256, assert_invalid_fvp_cluster_count);
19
20/*******************************************************************************
21 * This function dynamically constructs the topology according to
22 * FVP_CLUSTER_COUNT and returns it.
23 ******************************************************************************/
24const unsigned char *plat_get_power_domain_tree_desc(void)
25{
Soby Mathew9ca28062017-10-11 16:08:58 +010026 unsigned int i;
Soby Mathew47e43f22016-02-01 14:04:34 +000027
28 /*
Soby Mathew9ca28062017-10-11 16:08:58 +010029 * The highest level is the system level. The next level is constituted
30 * by clusters and then cores in clusters.
Soby Mathew47e43f22016-02-01 14:04:34 +000031 */
Soby Mathew9ca28062017-10-11 16:08:58 +010032 fvp_power_domain_tree_desc[0] = 1;
33 fvp_power_domain_tree_desc[1] = FVP_CLUSTER_COUNT;
Soby Mathew47e43f22016-02-01 14:04:34 +000034
35 for (i = 0; i < FVP_CLUSTER_COUNT; i++)
Soby Mathew9ca28062017-10-11 16:08:58 +010036 fvp_power_domain_tree_desc[i + 2] = FVP_MAX_CPUS_PER_CLUSTER;
37
Soby Mathew47e43f22016-02-01 14:04:34 +000038
39 return fvp_power_domain_tree_desc;
40}
41
42/*******************************************************************************
43 * This function returns the core count within the cluster corresponding to
44 * `mpidr`.
45 ******************************************************************************/
46unsigned int plat_arm_get_cluster_core_count(u_register_t mpidr)
47{
48 return FVP_MAX_CPUS_PER_CLUSTER;
49}
Achin Gupta4f6ad662013-10-25 09:08:21 +010050
51/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010052 * This function implements a part of the critical interface between the psci
Soby Mathewfec4eb72015-07-01 16:16:20 +010053 * generic layer and the platform that allows the former to query the platform
54 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
55 * in case the MPIDR is invalid.
Achin Gupta4f6ad662013-10-25 09:08:21 +010056 ******************************************************************************/
Soby Mathewfec4eb72015-07-01 16:16:20 +010057int plat_core_pos_by_mpidr(u_register_t mpidr)
Achin Gupta4f6ad662013-10-25 09:08:21 +010058{
Jeenu Viswambharan9e78b922017-07-18 15:42:50 +010059 unsigned int clus_id, cpu_id, thread_id;
60
61 /* Validate affinity fields */
62 if (arm_config.flags & ARM_CONFIG_FVP_SHIFTED_AFF) {
63 thread_id = MPIDR_AFFLVL0_VAL(mpidr);
64 cpu_id = MPIDR_AFFLVL1_VAL(mpidr);
65 clus_id = MPIDR_AFFLVL2_VAL(mpidr);
66 } else {
67 thread_id = 0;
68 cpu_id = MPIDR_AFFLVL0_VAL(mpidr);
69 clus_id = MPIDR_AFFLVL1_VAL(mpidr);
70 }
71
72 if (clus_id >= FVP_CLUSTER_COUNT)
73 return -1;
74 if (cpu_id >= FVP_MAX_CPUS_PER_CLUSTER)
75 return -1;
76 if (thread_id >= FVP_MAX_PE_PER_CPU)
77 return -1;
78
Soby Mathewfec4eb72015-07-01 16:16:20 +010079 if (fvp_pwrc_read_psysr(mpidr) == PSYSR_INVALID)
80 return -1;
Achin Gupta4f6ad662013-10-25 09:08:21 +010081
Jeenu Viswambharan528d21b2016-11-15 13:53:57 +000082 /*
83 * Core position calculation for FVP platform depends on the MT bit in
84 * MPIDR. This function cannot assume that the supplied MPIDR has the MT
85 * bit set even if the implementation has. For example, PSCI clients
86 * might supply MPIDR values without the MT bit set. Therefore, we
87 * inject the current PE's MT bit so as to get the calculation correct.
88 * This of course assumes that none or all CPUs on the platform has MT
89 * bit set.
90 */
91 mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
Soby Mathewfec4eb72015-07-01 16:16:20 +010092 return plat_arm_calc_core_pos(mpidr);
Achin Gupta4f6ad662013-10-25 09:08:21 +010093}