phytium_cpu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 "fparameters.h"
  17. #include "fcpu_info.h"
  18. #include "phytium_cpu.h"
  19. #if defined(TARGET_ARMV8_AARCH64)
  20. /**
  21. @name: phytium_cpu_id_mapping
  22. @msg: Map Phytium CPU ID
  23. @brief: Map the input CPU ID to a new CPU ID based on the type and quantity of CPUs on the target board.
  24. @param {int} cpu_id Input CPU ID
  25. @return {int} Mapped CPU ID
  26. */
  27. int phytium_cpu_id_mapping(int cpu_id)
  28. {
  29. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  30. #if RT_CPUS_NR <= 2
  31. switch (cpu_id)
  32. {
  33. case 0:
  34. return 2;
  35. case 1:
  36. return 3;
  37. case 2:
  38. return 0;
  39. case 3:
  40. return 1;
  41. default:
  42. RT_ASSERT(0);
  43. return 0;
  44. break;
  45. }
  46. #else
  47. return (int)cpu_id;
  48. #endif
  49. #else
  50. return (int)cpu_id;
  51. #endif
  52. }
  53. int phytium_cpu_id(void)
  54. {
  55. FError ret;
  56. u32 cpu_id;
  57. ret = GetCpuId(&cpu_id);
  58. if (ret != ERR_SUCCESS)
  59. {
  60. RT_ASSERT(0);
  61. }
  62. return phytium_cpu_id_mapping(cpu_id);
  63. }
  64. int rt_hw_cpu_id(void)
  65. {
  66. FError ret;
  67. u32 cpu_id;
  68. ret = GetCpuId(&cpu_id);
  69. if (ret != ERR_SUCCESS)
  70. {
  71. RT_ASSERT(0);
  72. }
  73. return phytium_cpu_id_mapping(cpu_id);
  74. }
  75. #else
  76. int phytium_cpu_id_mapping(int cpu_id)
  77. {
  78. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  79. switch (cpu_id)
  80. {
  81. case 0:
  82. return 2;
  83. case 1:
  84. return 3;
  85. case 2:
  86. return 0;
  87. case 3:
  88. return 1;
  89. default:
  90. RT_ASSERT(0);
  91. return 0;
  92. break;
  93. }
  94. #else
  95. return (int)cpu_id;
  96. #endif
  97. }
  98. int rt_hw_cpu_id(void)
  99. {
  100. FError ret;
  101. u32 cpu_id;
  102. ret = GetCpuId(&cpu_id);
  103. if (ret != ERR_SUCCESS)
  104. {
  105. RT_ASSERT(0);
  106. }
  107. return phytium_cpu_id_mapping(cpu_id);
  108. }
  109. rt_uint64_t get_main_cpu_affval(void)
  110. {
  111. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  112. return CORE2_AFF;
  113. #else
  114. return CORE0_AFF;
  115. #endif
  116. }
  117. extern u32 GetCpuMaskToAffval(u32 *cpu_mask, u32 *cluster_id, u32 *target_list);
  118. rt_uint32_t arm_gic_cpumask_to_affval(rt_uint32_t *cpu_mask, rt_uint32_t *cluster_id, rt_uint32_t *target_list)
  119. {
  120. return GetCpuMaskToAffval(cpu_mask, cluster_id, target_list);
  121. }
  122. #ifdef RT_USING_SMP
  123. void send_core_isg(void)
  124. {
  125. for (rt_size_t i = 0; i <= 0xf; i++)
  126. {
  127. /* code */
  128. rt_kprintf("i %x \r\n", i);
  129. arm_gic_send_affinity_sgi(0, 0, i, 0);
  130. rt_thread_mdelay(100);
  131. }
  132. }
  133. MSH_CMD_EXPORT(send_core_isg, send_core_isg);
  134. #endif
  135. #endif