secondary_cpu.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2006-2021, 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. * 2022-10-26 zhugengyu support aarch64
  12. *
  13. */
  14. #include <rtthread.h>
  15. #include "board.h"
  16. #include <gicv3.h>
  17. #include "rtconfig.h"
  18. #include "phytium_cpu.h"
  19. #if defined(TARGET_ARMV8_AARCH64)
  20. #include "cpuport.h"
  21. #include "gtimer.h"
  22. #include "mmu.h"
  23. #endif
  24. #ifdef RT_USING_SMP
  25. #include <interrupt.h>
  26. #if defined(TARGET_ARMV8_AARCH64)
  27. #include "psci.h"
  28. #endif
  29. #include "fpsci.h"
  30. rt_uint64_t rt_cpu_mpidr_early[] =
  31. {
  32. #if defined(TARGET_E2000D)
  33. [0] = 0x80000200,
  34. [1] = 0x80000201,
  35. #elif defined(TARGET_E2000Q)
  36. [0] = 0x80000200,
  37. [1] = 0x80000201,
  38. [2] = 0x80000000,
  39. [3] = 0x80000100,
  40. #elif defined(TARGET_F2000_4) || defined(TARGET_D2000)
  41. [0] = 0x80000000,
  42. [1] = 0x80000001,
  43. [2] = 0x80000100,
  44. [3] = 0x80000101,
  45. #if defined(TARGET_D2000)
  46. [4] = 0x80000200,
  47. [5] = 0x80000201,
  48. [6] = 0x80000300,
  49. [7] = 0x80000301,
  50. #endif
  51. #endif
  52. };
  53. extern int rt_hw_timer_init(void);
  54. extern void secondary_cpu_start(void);
  55. void rt_hw_secondary_cpu_up(void)
  56. {
  57. rt_uint32_t i;
  58. rt_uint32_t cpu_mask = 0;
  59. rt_kprintf("rt_hw_secondary_cpu_up is processing \r\n");
  60. for (i = 1; i < RT_CPUS_NR; i++)
  61. {
  62. cpu_mask = 1 << phytium_cpu_id_mapping(i);
  63. /* code */
  64. PsciCpuOn(cpu_mask, (uintptr)secondary_cpu_start);
  65. #if defined(TARGET_ARMV8_AARCH64)
  66. __DSB();
  67. #else
  68. __asm__ volatile("dsb" ::: "memory");
  69. #endif
  70. }
  71. }
  72. void secondary_cpu_c_start(void)
  73. {
  74. /* mmu init */
  75. #if defined(TARGET_ARMV8_AARCH64)
  76. rt_hw_mmu_init();
  77. #endif
  78. /* spin lock init */
  79. rt_hw_spin_lock(&_cpus_lock);
  80. /* interrupt init */
  81. #if defined(TARGET_ARMV8_AARCH64)
  82. arm_gic_cpu_init(0, platform_get_gic_cpu_base());
  83. arm_gic_redist_init(0, platform_get_gic_redist_base());
  84. #else
  85. arm_gic_cpu_init(0);
  86. arm_gic_redist_init(0);
  87. #endif
  88. /* vector init */
  89. rt_hw_vector_init();
  90. /* gtimer init */
  91. #if defined(TARGET_ARMV8_AARCH64)
  92. rt_hw_gtimer_local_enable();
  93. #else
  94. rt_hw_timer_init();
  95. #endif
  96. rt_hw_interrupt_umask(RT_SCHEDULE_IPI);
  97. /* start scheduler */
  98. rt_kprintf("\rcall cpu %d on success\n", rt_hw_cpu_id());
  99. rt_hw_secondary_cpu_idle_exec();
  100. rt_system_scheduler_start();
  101. }
  102. void rt_hw_secondary_cpu_idle_exec(void)
  103. {
  104. #if defined(TARGET_ARMV8_AARCH64)
  105. __WFE();
  106. #else
  107. asm volatile("wfe" ::
  108. : "memory", "cc");
  109. #endif
  110. }
  111. #endif