phytium_cpu.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /**
  20. @name: phytium_cpu_id_mapping
  21. @msg: Map Phytium CPU ID
  22. @brief: Map the input CPU ID to a new CPU ID based on the type and quantity of CPUs on the target board.
  23. @param {int} cpu_id Input CPU ID
  24. @return {int} Mapped CPU ID
  25. */
  26. int phytium_cpu_id_mapping(int cpu_id)
  27. {
  28. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  29. switch (cpu_id)
  30. {
  31. case 0:
  32. return 2;
  33. case 1:
  34. return 3;
  35. case 2:
  36. return 0;
  37. case 3:
  38. return 1;
  39. default:
  40. RT_ASSERT(0);
  41. return 0;
  42. break;
  43. }
  44. #else
  45. return (int)cpu_id;
  46. #endif
  47. }
  48. #if defined(TARGET_ARMV8_AARCH32)
  49. int rt_hw_cpu_id(void)
  50. {
  51. FError ret;
  52. u32 cpu_id;
  53. ret = GetCpuId(&cpu_id);
  54. if (ret != ERR_SUCCESS)
  55. {
  56. RT_ASSERT(0);
  57. }
  58. return phytium_cpu_id_mapping(cpu_id);
  59. }
  60. rt_uint64_t get_main_cpu_affval(void)
  61. {
  62. #if defined(TARGET_E2000Q) || defined(TARGET_PHYTIUMPI)
  63. return CORE2_AFF;
  64. #else
  65. return CORE0_AFF;
  66. #endif
  67. }
  68. extern u32 GetCpuMaskToAffval(u32 *cpu_mask, u32 *cluster_id, u32 *target_list);
  69. rt_uint32_t arm_gic_cpumask_to_affval(rt_uint32_t *cpu_mask, rt_uint32_t *cluster_id, rt_uint32_t *target_list)
  70. {
  71. return GetCpuMaskToAffval(cpu_mask, cluster_id, target_list);
  72. }
  73. #ifdef RT_USING_SMP
  74. void send_core_isg(void)
  75. {
  76. for (rt_size_t i = 0; i <= 0xf; i++)
  77. {
  78. /* code */
  79. rt_kprintf("i %x \r\n", i);
  80. arm_gic_send_affinity_sgi(0, 0, i, 0);
  81. rt_thread_mdelay(100);
  82. }
  83. }
  84. MSH_CMD_EXPORT(send_core_isg, send_core_isg);
  85. #endif
  86. #endif