blob: bd8d16b9ab2d9cd432cfd29fa2ab74a2e120902f [file] [log] [blame]
Graeme Gregory10e92232020-08-28 16:37:02 +01001/*
2 * Copyright (c) 2020, Nuvia Inc
3 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include <arch.h>
9#include <common/debug.h>
10
11#include <platform_def.h>
12#include "sbsa_private.h"
13
14/* The power domain tree descriptor */
15static unsigned char power_domain_tree_desc[PLATFORM_CLUSTER_COUNT + 1];
16
17/*******************************************************************************
18 * This function returns the sbsa-ref default topology tree information.
19 ******************************************************************************/
20const unsigned char *plat_get_power_domain_tree_desc(void)
21{
22 unsigned int i;
23
24 power_domain_tree_desc[0] = PLATFORM_CLUSTER_COUNT;
25
26 for (i = 0U; i < PLATFORM_CLUSTER_COUNT; i++) {
27 power_domain_tree_desc[i + 1] = PLATFORM_MAX_CPUS_PER_CLUSTER;
28 }
29
30 return power_domain_tree_desc;
31}
32
33/*******************************************************************************
34 * This function implements a part of the critical interface between the psci
35 * generic layer and the platform that allows the former to query the platform
36 * to convert an MPIDR to a unique linear index. An error code (-1) is returned
37 * in case the MPIDR is invalid.
38 ******************************************************************************/
39int plat_core_pos_by_mpidr(u_register_t mpidr)
40{
41 unsigned int cluster_id, cpu_id;
42
43 mpidr &= MPIDR_AFFINITY_MASK;
44 if ((mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) != 0U) {
45 ERROR("Invalid MPIDR\n");
46 return -1;
47 }
48
49 cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
50 cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
51
52 if (cluster_id >= PLATFORM_CLUSTER_COUNT) {
53 ERROR("cluster_id >= PLATFORM_CLUSTER_COUNT define\n");
54 return -1;
55 }
56
57 if (cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER) {
58 ERROR("cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER define\n");
59 return -1;
60 }
61
62 return plat_qemu_calc_core_pos(mpidr);
63}