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