14f2b9848SAndre Przywara /* 2*6744d07dSMario Bălănică * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. 34f2b9848SAndre Przywara * 44f2b9848SAndre Przywara * SPDX-License-Identifier: BSD-3-Clause 54f2b9848SAndre Przywara */ 64f2b9848SAndre Przywara 74f2b9848SAndre Przywara #include <stdint.h> 84f2b9848SAndre Przywara 94f2b9848SAndre Przywara #include <platform_def.h> 104f2b9848SAndre Przywara 114f2b9848SAndre Przywara #include <arch.h> 124f2b9848SAndre Przywara 134f2b9848SAndre Przywara #include <rpi_shared.h> 144f2b9848SAndre Przywara 154f2b9848SAndre Przywara /* The power domain tree descriptor */ 164f2b9848SAndre Przywara static unsigned char power_domain_tree_desc[] = { 174f2b9848SAndre Przywara /* Number of root nodes */ 184f2b9848SAndre Przywara PLATFORM_CLUSTER_COUNT, 194f2b9848SAndre Przywara /* Number of children for the first node */ 204f2b9848SAndre Przywara PLATFORM_CLUSTER0_CORE_COUNT, 214f2b9848SAndre Przywara }; 224f2b9848SAndre Przywara 234f2b9848SAndre Przywara /******************************************************************************* 244f2b9848SAndre Przywara * This function returns the ARM default topology tree information. 254f2b9848SAndre Przywara ******************************************************************************/ 264f2b9848SAndre Przywara const unsigned char *plat_get_power_domain_tree_desc(void) 274f2b9848SAndre Przywara { 284f2b9848SAndre Przywara return power_domain_tree_desc; 294f2b9848SAndre Przywara } 304f2b9848SAndre Przywara 314f2b9848SAndre Przywara /******************************************************************************* 324f2b9848SAndre Przywara * This function implements a part of the critical interface between the psci 334f2b9848SAndre Przywara * generic layer and the platform that allows the former to query the platform 344f2b9848SAndre Przywara * to convert an MPIDR to a unique linear index. An error code (-1) is returned 354f2b9848SAndre Przywara * in case the MPIDR is invalid. 364f2b9848SAndre Przywara ******************************************************************************/ 374f2b9848SAndre Przywara int plat_core_pos_by_mpidr(u_register_t mpidr) 384f2b9848SAndre Przywara { 394f2b9848SAndre Przywara unsigned int cluster_id, cpu_id; 404f2b9848SAndre Przywara 414f2b9848SAndre Przywara mpidr &= MPIDR_AFFINITY_MASK; 42*6744d07dSMario Bălănică 43*6744d07dSMario Bălănică /* 44*6744d07dSMario Bălănică * When MT is set, lowest affinity represents the thread ID. 45*6744d07dSMario Bălănică * Since we only support one thread per core, discard this field 46*6744d07dSMario Bălănică * so cluster and core IDs go back into Aff1 and Aff0 respectively. 47*6744d07dSMario Bălănică * The upper bits are also affected, but plat_rpi3_calc_core_pos() 48*6744d07dSMario Bălănică * does not use them. 49*6744d07dSMario Bălănică */ 50*6744d07dSMario Bălănică if ((read_mpidr() & MPIDR_MT_MASK) != 0) { 51*6744d07dSMario Bălănică if (MPIDR_AFFLVL0_VAL(mpidr) != 0) { 52*6744d07dSMario Bălănică return -1; 53*6744d07dSMario Bălănică } 54*6744d07dSMario Bălănică mpidr >>= MPIDR_AFFINITY_BITS; 55*6744d07dSMario Bălănică } 56*6744d07dSMario Bălănică 574f2b9848SAndre Przywara if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) { 584f2b9848SAndre Przywara return -1; 594f2b9848SAndre Przywara } 604f2b9848SAndre Przywara 61*6744d07dSMario Bălănică cluster_id = MPIDR_AFFLVL1_VAL(mpidr); 62*6744d07dSMario Bălănică cpu_id = MPIDR_AFFLVL0_VAL(mpidr); 634f2b9848SAndre Przywara 644f2b9848SAndre Przywara if (cluster_id >= PLATFORM_CLUSTER_COUNT) { 654f2b9848SAndre Przywara return -1; 664f2b9848SAndre Przywara } 674f2b9848SAndre Przywara 684f2b9848SAndre Przywara if (cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER) { 694f2b9848SAndre Przywara return -1; 704f2b9848SAndre Przywara } 714f2b9848SAndre Przywara 724f2b9848SAndre Przywara return plat_rpi3_calc_core_pos(mpidr); 734f2b9848SAndre Przywara } 74