blob: 7fead869b5916a6b3b4cfc481d6efbc29e76c0e2 [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>
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +01008#include <common/debug.h>
9#include <lib/spinlock.h>
Oliver Swede8fed2fe2019-11-11 11:11:06 +000010
11#include "fpga_private.h"
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010012#include <plat/common/platform.h>
Oliver Swede8fed2fe2019-11-11 11:11:06 +000013#include <platform_def.h>
14
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010015unsigned char fpga_power_domain_tree_desc[FPGA_MAX_CLUSTER_COUNT + 2];
16unsigned char fpga_valid_mpids[PLATFORM_CORE_COUNT];
Oliver Swede6e86c5a2019-12-02 13:21:52 +000017
Oliver Swede8fed2fe2019-11-11 11:11:06 +000018const unsigned char *plat_get_power_domain_tree_desc(void)
19{
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010020 unsigned int i;
21
Oliver Swede6e86c5a2019-12-02 13:21:52 +000022 /*
23 * The highest level is the system level. The next level is constituted
24 * by clusters and then cores in clusters.
25 *
26 * This description of the power domain topology is aligned with the CPU
27 * indices returned by the plat_core_pos_by_mpidr() and plat_my_core_pos()
28 * APIs.
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010029 *
30 * A description of the topology tree can be found at
31 * https://trustedfirmware-a.readthedocs.io/en/latest/design/psci-pd-tree.html#design
Oliver Swede6e86c5a2019-12-02 13:21:52 +000032 */
Oliver Swede6e86c5a2019-12-02 13:21:52 +000033
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010034 if (fpga_power_domain_tree_desc[0] == 0U) {
35 /*
36 * As fpga_power_domain_tree_desc[0] == 0, assume that the
37 * Power Domain Topology Tree has not been initialized, so
38 * perform the initialization here.
39 */
40
41 fpga_power_domain_tree_desc[0] = 1U;
42 fpga_power_domain_tree_desc[1] = FPGA_MAX_CLUSTER_COUNT;
43
44 for (i = 0U; i < FPGA_MAX_CLUSTER_COUNT; i++) {
45 fpga_power_domain_tree_desc[2 + i] =
46 (FPGA_MAX_CPUS_PER_CLUSTER *
47 FPGA_MAX_PE_PER_CPU);
48 }
Oliver Swede6e86c5a2019-12-02 13:21:52 +000049 }
50
51 return fpga_power_domain_tree_desc;
Oliver Swede8fed2fe2019-11-11 11:11:06 +000052}
53
54int plat_core_pos_by_mpidr(u_register_t mpidr)
55{
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010056 unsigned int core_pos;
Oliver Swede6e86c5a2019-12-02 13:21:52 +000057
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010058 mpidr &= (MPID_MASK & ~(MPIDR_AFFLVL_MASK << MPIDR_AFF3_SHIFT));
Andre Przywara43318de2020-06-25 13:10:13 +010059 mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
Oliver Swede6e86c5a2019-12-02 13:21:52 +000060
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010061 if ((MPIDR_AFFLVL2_VAL(mpidr) >= FPGA_MAX_CLUSTER_COUNT) ||
62 (MPIDR_AFFLVL1_VAL(mpidr) >= FPGA_MAX_CPUS_PER_CLUSTER) ||
63 (MPIDR_AFFLVL0_VAL(mpidr) >= FPGA_MAX_PE_PER_CPU)) {
64 ERROR ("Invalid mpidr: 0x%08x\n", (uint32_t)mpidr);
65 panic();
Oliver Swede6e86c5a2019-12-02 13:21:52 +000066 }
67
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010068 /* Calculate the core position, based on the maximum topology. */
69 core_pos = plat_fpga_calc_core_pos(mpidr);
Oliver Swede6e86c5a2019-12-02 13:21:52 +000070
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010071 /* Check whether this core is actually present. */
72 if (fpga_valid_mpids[core_pos] != VALID_MPID) {
Andre Przywara43318de2020-06-25 13:10:13 +010073 return -1;
74 }
Oliver Swede6e86c5a2019-12-02 13:21:52 +000075
Javier Almansa Sobrinofc78c3c2020-05-13 14:09:58 +010076 return core_pos;
Oliver Swede8fed2fe2019-11-11 11:11:06 +000077}