1 /* 2 * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch.h> 8 #include <arch_helpers.h> 9 #include <lib/psci/psci.h> 10 11 #include <plat_helpers.h> 12 #include <platform_def.h> 13 14 const unsigned char mtk_power_domain_tree_desc[] = { 15 /* Number of root nodes */ 16 PLATFORM_SYSTEM_COUNT, 17 /* Number of children for the root node */ 18 PLATFORM_MCUSYS_COUNT, 19 /* Number of children for the mcusys node */ 20 PLATFORM_CLUSTER_COUNT, 21 /* Number of children for the first cluster node */ 22 PLATFORM_CLUSTER0_CORE_COUNT, 23 }; 24 plat_get_power_domain_tree_desc(void)25const unsigned char *plat_get_power_domain_tree_desc(void) 26 { 27 return mtk_power_domain_tree_desc; 28 } 29 30 /******************************************************************************* 31 * This function implements a part of the critical interface between the psci 32 * generic layer and the platform that allows the former to query the platform 33 * to convert an MPIDR to a unique linear index. An error code (-1) is returned 34 * in case the MPIDR is invalid. 35 ******************************************************************************/ plat_core_pos_by_mpidr(u_register_t mpidr)36int plat_core_pos_by_mpidr(u_register_t mpidr) 37 { 38 unsigned int cluster_id, cpu_id; 39 40 if ((read_mpidr() & MPIDR_MT_MASK) != 0) { 41 /* ARMv8.2 arch */ 42 if ((mpidr & (MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT)) != 0) { 43 return -1; 44 } 45 return plat_mediatek_calc_core_pos(mpidr); 46 } 47 48 mpidr &= MPIDR_AFFINITY_MASK; 49 50 if ((mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) != 0) { 51 return -1; 52 } 53 54 cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK; 55 cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK; 56 57 if (cluster_id >= PLATFORM_CLUSTER_COUNT) { 58 return -1; 59 } 60 61 /* 62 * Validate cpu_id by checking whether it represents a CPU in 63 * one of the two clusters present on the platform. 64 */ 65 if (cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER) { 66 return -1; 67 } 68 69 return (cpu_id + (cluster_id * 8)); 70 } 71