fpga_topology.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <lib/spinlock.h>
  9. #include "fpga_private.h"
  10. #include <plat/common/platform.h>
  11. #include <platform_def.h>
  12. unsigned char fpga_power_domain_tree_desc[FPGA_MAX_CLUSTER_COUNT + 2];
  13. unsigned char fpga_valid_mpids[PLATFORM_CORE_COUNT];
  14. const unsigned char *plat_get_power_domain_tree_desc(void)
  15. {
  16. unsigned 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. * A description of the topology tree can be found at
  26. * https://trustedfirmware-a.readthedocs.io/en/latest/design/psci-pd-tree.html#design
  27. */
  28. if (fpga_power_domain_tree_desc[0] == 0U) {
  29. /*
  30. * As fpga_power_domain_tree_desc[0] == 0, assume that the
  31. * Power Domain Topology Tree has not been initialized, so
  32. * perform the initialization here.
  33. */
  34. fpga_power_domain_tree_desc[0] = 1U;
  35. fpga_power_domain_tree_desc[1] = FPGA_MAX_CLUSTER_COUNT;
  36. for (i = 0U; i < FPGA_MAX_CLUSTER_COUNT; i++) {
  37. fpga_power_domain_tree_desc[2 + i] =
  38. (FPGA_MAX_CPUS_PER_CLUSTER *
  39. FPGA_MAX_PE_PER_CPU);
  40. }
  41. }
  42. return fpga_power_domain_tree_desc;
  43. }
  44. int plat_core_pos_by_mpidr(u_register_t mpidr)
  45. {
  46. unsigned int core_pos;
  47. mpidr &= (MPID_MASK & ~(MPIDR_AFFLVL_MASK << MPIDR_AFF3_SHIFT));
  48. mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
  49. if ((MPIDR_AFFLVL2_VAL(mpidr) >= FPGA_MAX_CLUSTER_COUNT) ||
  50. (MPIDR_AFFLVL1_VAL(mpidr) >= FPGA_MAX_CPUS_PER_CLUSTER) ||
  51. (MPIDR_AFFLVL0_VAL(mpidr) >= FPGA_MAX_PE_PER_CPU)) {
  52. ERROR ("Invalid mpidr: 0x%08x\n", (uint32_t)mpidr);
  53. panic();
  54. }
  55. /* Calculate the core position, based on the maximum topology. */
  56. core_pos = plat_fpga_calc_core_pos(mpidr);
  57. /* Check whether this core is actually present. */
  58. if (fpga_valid_mpids[core_pos] != VALID_MPID) {
  59. return -1;
  60. }
  61. return core_pos;
  62. }