secondary_cpu.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-22 Jesven first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdint.h>
  13. #include "board.h"
  14. #include "gic.h"
  15. #include "drv_timer.h"
  16. #ifdef RT_USING_SMP
  17. #include <interrupt.h>
  18. #ifdef RT_USING_SMART
  19. #include <mmu.h>
  20. #endif
  21. static void rt_hw_timer2_isr(int vector, void *param)
  22. {
  23. rt_tick_increase();
  24. /* clear interrupt */
  25. timer_clear_pending(0);
  26. }
  27. void rt_hw_secondary_cpu_up(void)
  28. {
  29. volatile void **plat_boot_reg = (volatile void **)0x10000034;
  30. char *entry = (char *)rt_secondary_cpu_entry;
  31. #ifdef RT_USING_SMART
  32. plat_boot_reg = (volatile void **)rt_ioremap_nocache((void *)plat_boot_reg, 0x1000);
  33. if (!plat_boot_reg)
  34. {
  35. /* failed */
  36. return;
  37. }
  38. entry += PV_OFFSET;
  39. #endif
  40. *plat_boot_reg-- = (void *)(size_t)-1;
  41. *plat_boot_reg = (void *)entry;
  42. rt_hw_dsb();
  43. rt_hw_ipi_send(0, RT_CPU_MASK ^ (1 << rt_hw_cpu_id()));
  44. }
  45. extern size_t MMUTable[];
  46. /* Interface */
  47. void rt_hw_secondary_cpu_bsp_start(void)
  48. {
  49. rt_hw_vector_init();
  50. rt_hw_spin_lock(&_cpus_lock);
  51. rt_uint32_t mmutable_p;
  52. mmutable_p = (rt_uint32_t)MMUTable + (rt_uint32_t)PV_OFFSET ;
  53. rt_hw_mmu_switch((void*)mmutable_p) ;
  54. arm_gic_cpu_init(0, 0);
  55. arm_gic_set_cpu(0, IRQ_PBA8_TIMER0_1, 0x2);
  56. timer_init(0, 10000);
  57. rt_hw_interrupt_install(IRQ_PBA8_TIMER0_1, rt_hw_timer2_isr, RT_NULL, "tick");
  58. rt_hw_interrupt_umask(IRQ_PBA8_TIMER0_1);
  59. rt_system_scheduler_start();
  60. }
  61. void rt_hw_secondary_cpu_idle_exec(void)
  62. {
  63. asm volatile ("wfe":::"memory", "cc");
  64. }
  65. #endif