arm_topology.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2015-2019, 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 <plat/arm/common/plat_arm.h>
  9. /*******************************************************************************
  10. * This function validates an MPIDR by checking whether it falls within the
  11. * acceptable bounds. An error code (-1) is returned if an incorrect mpidr
  12. * is passed.
  13. ******************************************************************************/
  14. int arm_check_mpidr(u_register_t mpidr)
  15. {
  16. unsigned int cluster_id, cpu_id;
  17. uint64_t valid_mask;
  18. #if ARM_PLAT_MT
  19. unsigned int pe_id;
  20. valid_mask = ~(MPIDR_AFFLVL_MASK |
  21. (MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT) |
  22. (MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT) |
  23. (MPIDR_AFFLVL_MASK << MPIDR_AFF3_SHIFT));
  24. cluster_id = (mpidr >> MPIDR_AFF2_SHIFT) & MPIDR_AFFLVL_MASK;
  25. cpu_id = (mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;
  26. pe_id = (mpidr >> MPIDR_AFF0_SHIFT) & MPIDR_AFFLVL_MASK;
  27. #else
  28. valid_mask = ~(MPIDR_CLUSTER_MASK | MPIDR_CPU_MASK);
  29. cluster_id = (unsigned int) ((mpidr >> MPIDR_AFF1_SHIFT) &
  30. MPIDR_AFFLVL_MASK);
  31. cpu_id = (unsigned int) ((mpidr >> MPIDR_AFF0_SHIFT) &
  32. MPIDR_AFFLVL_MASK);
  33. #endif /* ARM_PLAT_MT */
  34. mpidr &= MPIDR_AFFINITY_MASK;
  35. if ((mpidr & valid_mask) != 0U)
  36. return -1;
  37. if (cluster_id >= PLAT_ARM_CLUSTER_COUNT)
  38. return -1;
  39. /* Validate cpu_id by checking whether it represents a CPU in
  40. one of the two clusters present on the platform. */
  41. if (cpu_id >= plat_arm_get_cluster_core_count(mpidr))
  42. return -1;
  43. #if ARM_PLAT_MT
  44. if (pe_id >= plat_arm_get_cpu_pe_count(mpidr))
  45. return -1;
  46. #endif /* ARM_PLAT_MT */
  47. return 0;
  48. }