blob: 7890eb7ede97afd437214dd24e482e0a532dd19f [file] [log] [blame]
Haojian Zhuang3846f142017-05-24 08:49:26 +08001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00006
Haojian Zhuang3846f142017-05-24 08:49:26 +08007#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
9#include <arch.h>
10#include <lib/psci/psci.h>
Haojian Zhuang3846f142017-05-24 08:49:26 +080011
12/*
13 * The HiKey power domain tree descriptor. The cluster power domains
14 * are arranged so that when the PSCI generic code creates the power
15 * domain tree, the indices of the CPU power domain nodes it allocates
16 * match the linear indices returned by plat_core_pos_by_mpidr().
17 */
18const unsigned char hikey_power_domain_tree_desc[] = {
19 /* Number of root nodes */
20 1,
21 /* Number of clusters */
22 PLATFORM_CLUSTER_COUNT,
Leo Yan3ba08222017-05-27 13:12:40 +080023 /* Number of children for the first cluster node */
24 PLATFORM_CORE_COUNT_PER_CLUSTER,
25 /* Number of children for the second cluster node */
26 PLATFORM_CORE_COUNT_PER_CLUSTER,
Haojian Zhuang3846f142017-05-24 08:49:26 +080027};
28
29/*******************************************************************************
30 * This function returns the HiKey topology tree information.
31 ******************************************************************************/
32const unsigned char *plat_get_power_domain_tree_desc(void)
33{
34 return hikey_power_domain_tree_desc;
35}
36
37/*******************************************************************************
38 * This function implements a part of the critical interface between the psci
39 * generic layer and the platform that allows the former to query the platform
40 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
41 * in case the MPIDR is invalid.
42 ******************************************************************************/
43int plat_core_pos_by_mpidr(u_register_t mpidr)
44{
45 unsigned int cluster_id, cpu_id;
46
47 mpidr &= MPIDR_AFFINITY_MASK;
48
49 if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK))
50 return -1;
51
52 cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
53 cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
54
55 if (cluster_id >= PLATFORM_CLUSTER_COUNT)
56 return -1;
57
58 /*
59 * Validate cpu_id by checking whether it represents a CPU in
60 * one of the two clusters present on the platform.
61 */
62 if (cpu_id >= PLATFORM_CORE_COUNT_PER_CLUSTER)
63 return -1;
64
65 return (cpu_id + (cluster_id * 4));
66}