plat_topology.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <arch_helpers.h>
  8. #include <lib/psci/psci.h>
  9. #include <plat_helpers.h>
  10. #include <platform_def.h>
  11. const unsigned char mtk_power_domain_tree_desc[] = {
  12. /* Number of root nodes */
  13. PLATFORM_SYSTEM_COUNT,
  14. /* Number of children for the root node */
  15. PLATFORM_MCUSYS_COUNT,
  16. /* Number of children for the mcusys node */
  17. PLATFORM_CLUSTER_COUNT,
  18. /* Number of children for the first cluster node */
  19. PLATFORM_CLUSTER0_CORE_COUNT,
  20. };
  21. const unsigned char *plat_get_power_domain_tree_desc(void)
  22. {
  23. return mtk_power_domain_tree_desc;
  24. }
  25. /*******************************************************************************
  26. * This function implements a part of the critical interface between the psci
  27. * generic layer and the platform that allows the former to query the platform
  28. * to convert an MPIDR to a unique linear index. An error code (-1) is returned
  29. * in case the MPIDR is invalid.
  30. ******************************************************************************/
  31. int plat_core_pos_by_mpidr(u_register_t mpidr)
  32. {
  33. unsigned int cluster_id, cpu_id;
  34. if ((read_mpidr() & MPIDR_MT_MASK) != 0) {
  35. /* ARMv8.2 arch */
  36. if ((mpidr & (MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT)) != 0) {
  37. return -1;
  38. }
  39. return plat_mediatek_calc_core_pos(mpidr);
  40. }
  41. mpidr &= MPIDR_AFFINITY_MASK;
  42. if ((mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK)) != 0) {
  43. return -1;
  44. }
  45. cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
  46. cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
  47. if (cluster_id >= PLATFORM_CLUSTER_COUNT) {
  48. return -1;
  49. }
  50. /*
  51. * Validate cpu_id by checking whether it represents a CPU in
  52. * one of the two clusters present on the platform.
  53. */
  54. if (cpu_id >= PLATFORM_MAX_CPUS_PER_CLUSTER) {
  55. return -1;
  56. }
  57. return (cpu_id + (cluster_id * 8));
  58. }