phytium_cpu.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Email: opensource_embedded@phytium.com.cn
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2022-10-26 huanghe first commit
  11. *
  12. */
  13. #include "rtconfig.h"
  14. #include <rtthread.h>
  15. #include "gicv3.h"
  16. #include "fcpu_info.h"
  17. #include "phytium_cpu.h"
  18. rt_uint64_t rt_cpu_mpidr_table[] =
  19. {
  20. #if defined(TARGET_PE2202)
  21. [0] = RT_CORE_AFF(0),
  22. [1] = RT_CORE_AFF(1),
  23. #elif defined(TARGET_PE2204)
  24. [0] = RT_CORE_AFF(0),
  25. [1] = RT_CORE_AFF(1),
  26. [2] = RT_CORE_AFF(2),
  27. [3] = RT_CORE_AFF(3),
  28. #elif defined(TARGET_PD2408)
  29. [0] = RT_CORE_AFF(0),
  30. [1] = RT_CORE_AFF(1),
  31. [2] = RT_CORE_AFF(2),
  32. [3] = RT_CORE_AFF(3),
  33. [4] = RT_CORE_AFF(4),
  34. [5] = RT_CORE_AFF(5),
  35. [6] = RT_CORE_AFF(6),
  36. [7] = RT_CORE_AFF(7),
  37. #endif
  38. [RT_CPUS_NR] = 0
  39. };
  40. /**
  41. @name: phytium_cpu_id_mapping
  42. @msg: Map Phytium CPU ID
  43. @brief: Map the input CPU ID to a new CPU ID based on the type and quantity of CPUs on the target board.
  44. @param {int} cpu_id Input CPU ID
  45. @return {int} Mapped CPU ID
  46. */
  47. int phytium_cpu_id_mapping(int cpu_id)
  48. {
  49. #if defined(TARGET_PE2204)
  50. switch (cpu_id)
  51. {
  52. case 0:
  53. return 2;
  54. case 1:
  55. return 3;
  56. case 2:
  57. return 0;
  58. case 3:
  59. return 1;
  60. default:
  61. RT_ASSERT(0);
  62. return 0;
  63. break;
  64. }
  65. #else
  66. return (int)cpu_id;
  67. #endif
  68. }
  69. #if defined(TARGET_ARMV8_AARCH32)
  70. int rt_hw_cpu_id(void)
  71. {
  72. FError ret;
  73. u32 cpu_id;
  74. ret = GetCpuId(&cpu_id);
  75. if (ret != ERR_SUCCESS)
  76. {
  77. RT_ASSERT(0);
  78. }
  79. return phytium_cpu_id_mapping(cpu_id);
  80. }
  81. rt_uint64_t get_main_cpu_affval(void)
  82. {
  83. #if defined(TARGET_PE2204)
  84. return CORE2_AFF;
  85. #else
  86. return CORE0_AFF;
  87. #endif
  88. }
  89. extern u32 GetCpuMaskToAffval(u32 *cpu_mask, u32 *cluster_id, u32 *target_list);
  90. rt_uint32_t arm_gic_cpumask_to_affval(rt_uint32_t *cpu_mask, rt_uint32_t *cluster_id, rt_uint32_t *target_list)
  91. {
  92. return GetCpuMaskToAffval(cpu_mask, cluster_id, target_list);
  93. }
  94. #ifdef RT_USING_SMP
  95. void send_core_isg(void)
  96. {
  97. for (rt_size_t i = 0; i <= 0xf; i++)
  98. {
  99. /* code */
  100. rt_kprintf("i %x \r\n", i);
  101. arm_gic_send_affinity_sgi(0, 0, i, 0);
  102. rt_thread_mdelay(100);
  103. }
  104. }
  105. MSH_CMD_EXPORT(send_core_isg, send_core_isg);
  106. #endif
  107. #endif