fpga_topology.c 1.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
/*
 * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <arch_helpers.h>

#include "fpga_private.h"
#include <platform_def.h>

12
13
static unsigned char fpga_power_domain_tree_desc[FPGA_MAX_CLUSTER_COUNT + 2];

14
15
const unsigned char *plat_get_power_domain_tree_desc(void)
{
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
	int i;
	/*
	* The highest level is the system level. The next level is constituted
	* by clusters and then cores in clusters.
	*
	* This description of the power domain topology is aligned with the CPU
	* indices returned by the plat_core_pos_by_mpidr() and plat_my_core_pos()
	* APIs.
	*/
	fpga_power_domain_tree_desc[0] = 1;
	fpga_power_domain_tree_desc[1] = FPGA_MAX_CLUSTER_COUNT;

	for (i = 0; i < FPGA_MAX_CLUSTER_COUNT; i++) {
		fpga_power_domain_tree_desc[i + 2] = FPGA_MAX_CPUS_PER_CLUSTER;
	}

	return fpga_power_domain_tree_desc;
33
34
35
36
}

int plat_core_pos_by_mpidr(u_register_t mpidr)
{
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	unsigned int cluster_id, cpu_id, thread_id;

	mpidr &= MPIDR_AFFINITY_MASK;
	if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) {
		return -1;
	}

	if (mpidr & MPIDR_MT_MASK) {
		thread_id = MPIDR_AFFLVL0_VAL(mpidr);
	} else {
		thread_id = 0;
	}

	cpu_id = MPIDR_AFFLVL1_VAL(mpidr);
	cluster_id = MPIDR_AFFLVL2_VAL(mpidr);

	if (cluster_id >= FPGA_MAX_CLUSTER_COUNT) {
		return -1;
	} else if (cpu_id >= FPGA_MAX_CPUS_PER_CLUSTER) {
		return -1;
	} else if (thread_id >= FPGA_MAX_PE_PER_CPU) {
		return -1;
	}

61
	/*
62
63
64
65
	 * The image running on the FPGA may or may not implement multithreading,
	 * and it shouldn't be assumed this is consistent across all CPUs.
	 * This ensures that any passed mpidr values reflect the status of the
	 * primary CPU's MT bit.
66
	 */
67
68
69
	mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);

	/* Calculate the correct core, catering for multi-threaded images */
70
71
	return (int) plat_fpga_calc_core_pos(mpidr);
}