hikey960_topology.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <platform_def.h>
  7. #include <arch.h>
  8. #include <lib/psci/psci.h>
  9. /*
  10. * The HiKey power domain tree descriptor. The cluster power domains
  11. * are arranged so that when the PSCI generic code creates the power
  12. * domain tree, the indices of the CPU power domain nodes it allocates
  13. * match the linear indices returned by plat_core_pos_by_mpidr().
  14. */
  15. const unsigned char hikey960_power_domain_tree_desc[] = {
  16. /* Number of root nodes */
  17. 1,
  18. /* Number of clusters */
  19. PLATFORM_CLUSTER_COUNT,
  20. /* Number of children for the first cluster node */
  21. PLATFORM_CORE_COUNT_PER_CLUSTER,
  22. /* Number of children for the second cluster node */
  23. PLATFORM_CORE_COUNT_PER_CLUSTER,
  24. };
  25. /*******************************************************************************
  26. * This function returns the HiKey topology tree information.
  27. ******************************************************************************/
  28. const unsigned char *plat_get_power_domain_tree_desc(void)
  29. {
  30. return hikey960_power_domain_tree_desc;
  31. }
  32. /*******************************************************************************
  33. * This function implements a part of the critical interface between the psci
  34. * generic layer and the platform that allows the former to query the platform
  35. * to convert an MPIDR to a unique linear index. An error code (-1) is returned
  36. * in case the MPIDR is invalid.
  37. ******************************************************************************/
  38. int plat_core_pos_by_mpidr(u_register_t mpidr)
  39. {
  40. unsigned int cluster_id, cpu_id;
  41. mpidr &= MPIDR_AFFINITY_MASK;
  42. if (mpidr & ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK))
  43. return -1;
  44. cluster_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
  45. cpu_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
  46. if (cluster_id >= PLATFORM_CLUSTER_COUNT)
  47. return -1;
  48. /*
  49. * Validate cpu_id by checking whether it represents a CPU in
  50. * one of the two clusters present on the platform.
  51. */
  52. if (cpu_id >= PLATFORM_CORE_COUNT_PER_CLUSTER)
  53. return -1;
  54. return (cpu_id + (cluster_id * 4));
  55. }