phytium_cpu.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 rt_hw_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. #else
  65. int phytium_cpu_id_mapping(int cpu_id)
  66. {
  67. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  68. switch (cpu_id)
  69. {
  70. case 0:
  71. return 2;
  72. case 1:
  73. return 3;
  74. case 2:
  75. return 0;
  76. case 3:
  77. return 1;
  78. default:
  79. RT_ASSERT(0);
  80. return 0;
  81. break;
  82. }
  83. #else
  84. return (int)cpu_id;
  85. #endif
  86. }
  87. int rt_hw_cpu_id(void)
  88. {
  89. FError ret;
  90. u32 cpu_id;
  91. ret = GetCpuId(&cpu_id);
  92. if (ret != ERR_SUCCESS)
  93. {
  94. RT_ASSERT(0);
  95. }
  96. return phytium_cpu_id_mapping(cpu_id);
  97. }
  98. rt_uint64_t get_main_cpu_affval(void)
  99. {
  100. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  101. return CORE2_AFF;
  102. #else
  103. return CORE0_AFF;
  104. #endif
  105. }
  106. extern u32 GetCpuMaskToAffval(u32 *cpu_mask, u32 *cluster_id, u32 *target_list);
  107. rt_uint32_t arm_gic_cpumask_to_affval(rt_uint32_t *cpu_mask, rt_uint32_t *cluster_id, rt_uint32_t *target_list)
  108. {
  109. return GetCpuMaskToAffval(cpu_mask, cluster_id, target_list);
  110. }
  111. #ifdef RT_USING_SMP
  112. void send_core_isg(void)
  113. {
  114. for (rt_size_t i = 0; i <= 0xf; i++)
  115. {
  116. /* code */
  117. rt_kprintf("i %x \r\n", i);
  118. arm_gic_send_affinity_sgi(0, 0, i, 0);
  119. rt_thread_mdelay(100);
  120. }
  121. }
  122. MSH_CMD_EXPORT(send_core_isg, send_core_isg);
  123. #endif
  124. #endif