secondary_cpu.c 1.5 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. /* Interface */
  46. void rt_hw_secondary_cpu_bsp_start(void)
  47. {
  48. rt_hw_vector_init();
  49. rt_hw_spin_lock(&_cpus_lock);
  50. arm_gic_cpu_init(0, 0);
  51. arm_gic_set_cpu(0, IRQ_PBA8_TIMER0_1, 0x2);
  52. timer_init(0, 10000);
  53. rt_hw_interrupt_install(IRQ_PBA8_TIMER0_1, rt_hw_timer2_isr, RT_NULL, "tick");
  54. rt_hw_interrupt_umask(IRQ_PBA8_TIMER0_1);
  55. rt_system_scheduler_start();
  56. }
  57. void rt_hw_secondary_cpu_idle_exec(void)
  58. {
  59. asm volatile ("wfe":::"memory", "cc");
  60. }
  61. #endif