blob: a2908d72787253f9192fe2dfd65b1b2b573df4e5 [file] [log] [blame]
Oliver Swede8fed2fe2019-11-11 11:11:06 +00001/*
2 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8
9#include "fpga_private.h"
10#include <platform_def.h>
11
Oliver Swede6e86c5a2019-12-02 13:21:52 +000012static unsigned char fpga_power_domain_tree_desc[FPGA_MAX_CLUSTER_COUNT + 2];
13
Oliver Swede8fed2fe2019-11-11 11:11:06 +000014const unsigned char *plat_get_power_domain_tree_desc(void)
15{
Oliver Swede6e86c5a2019-12-02 13:21:52 +000016 int i;
17 /*
18 * The highest level is the system level. The next level is constituted
19 * by clusters and then cores in clusters.
20 *
21 * This description of the power domain topology is aligned with the CPU
22 * indices returned by the plat_core_pos_by_mpidr() and plat_my_core_pos()
23 * APIs.
24 */
25 fpga_power_domain_tree_desc[0] = 1;
26 fpga_power_domain_tree_desc[1] = FPGA_MAX_CLUSTER_COUNT;
27
28 for (i = 0; i < FPGA_MAX_CLUSTER_COUNT; i++) {
Andre Przywara43318de2020-06-25 13:10:13 +010029 fpga_power_domain_tree_desc[i + 2] = FPGA_MAX_CPUS_PER_CLUSTER * FPGA_MAX_PE_PER_CPU;
Oliver Swede6e86c5a2019-12-02 13:21:52 +000030 }
31
32 return fpga_power_domain_tree_desc;
Oliver Swede8fed2fe2019-11-11 11:11:06 +000033}
34
35int plat_core_pos_by_mpidr(u_register_t mpidr)
36{
Oliver Swede6e86c5a2019-12-02 13:21:52 +000037 unsigned int cluster_id, cpu_id, thread_id;
38
Andre Przywara43318de2020-06-25 13:10:13 +010039 /*
40 * The image running on the FPGA may or may not implement
41 * multithreading, and it shouldn't be assumed this is consistent
42 * across all CPUs.
43 * This ensures that any passed mpidr values reflect the status of the
44 * primary CPU's MT bit.
45 */
46 mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
47 mpidr &= MPID_MASK;
Oliver Swede6e86c5a2019-12-02 13:21:52 +000048
49 if (mpidr & MPIDR_MT_MASK) {
50 thread_id = MPIDR_AFFLVL0_VAL(mpidr);
Andre Przywara43318de2020-06-25 13:10:13 +010051 cpu_id = MPIDR_AFFLVL1_VAL(mpidr);
52 cluster_id = MPIDR_AFFLVL2_VAL(mpidr);
Oliver Swede6e86c5a2019-12-02 13:21:52 +000053 } else {
54 thread_id = 0;
Andre Przywara43318de2020-06-25 13:10:13 +010055 cpu_id = MPIDR_AFFLVL0_VAL(mpidr);
56 cluster_id = MPIDR_AFFLVL1_VAL(mpidr);
Oliver Swede6e86c5a2019-12-02 13:21:52 +000057 }
58
Oliver Swede6e86c5a2019-12-02 13:21:52 +000059 if (cluster_id >= FPGA_MAX_CLUSTER_COUNT) {
60 return -1;
Andre Przywara43318de2020-06-25 13:10:13 +010061 }
62
63 if (cpu_id >= FPGA_MAX_CPUS_PER_CLUSTER) {
Oliver Swede6e86c5a2019-12-02 13:21:52 +000064 return -1;
65 }
66
Andre Przywara43318de2020-06-25 13:10:13 +010067 if (thread_id >= FPGA_MAX_PE_PER_CPU) {
68 return -1;
69 }
Oliver Swede6e86c5a2019-12-02 13:21:52 +000070
71 /* Calculate the correct core, catering for multi-threaded images */
Oliver Swede8fed2fe2019-11-11 11:11:06 +000072 return (int) plat_fpga_calc_core_pos(mpidr);
73}