board.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * 2019-07-29 zdzn first version
  9. * 2021-07-31 GuEe-GUI config the memory/io address map
  10. * 2021-09-11 GuEe-GUI remove do-while in rt_hw_timer_isr
  11. * 2021-12-28 GuEe-GUI add smp support
  12. */
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include "board.h"
  16. #include <mmu.h>
  17. #include <gic.h>
  18. #include <psci.h>
  19. #include <gtimer.h>
  20. #include <cpuport.h>
  21. #include <interrupt.h>
  22. #include "drv_uart.h"
  23. struct mem_desc platform_mem_desc[] =
  24. {
  25. {0x40000000, 0x80000000, 0x40000000, NORMAL_MEM},
  26. {PL031_RTC_BASE, PL031_RTC_BASE + 0x1000, PL031_RTC_BASE, DEVICE_MEM},
  27. {PL011_UART0_BASE, PL011_UART0_BASE + 0x1000, PL011_UART0_BASE, DEVICE_MEM},
  28. {VIRTIO_MMIO_BLK0_BASE, VIRTIO_MMIO_BLK0_BASE + 0x1000, VIRTIO_MMIO_BLK0_BASE, DEVICE_MEM},
  29. {GIC_PL390_DISTRIBUTOR_PPTR, GIC_PL390_DISTRIBUTOR_PPTR + 0x1000, GIC_PL390_DISTRIBUTOR_PPTR, DEVICE_MEM},
  30. };
  31. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  32. void idle_wfi(void)
  33. {
  34. asm volatile ("wfi");
  35. }
  36. /**
  37. * Initialize the Hardware related stuffs. Called from rtthread_startup()
  38. * after interrupt disabled.
  39. */
  40. void rt_hw_board_init(void)
  41. {
  42. rt_hw_init_mmu_table(platform_mem_desc, platform_mem_desc_size);
  43. rt_hw_mmu_init();
  44. /* initialize hardware interrupt */
  45. rt_hw_interrupt_init();
  46. /* initialize uart */
  47. rt_hw_uart_init();
  48. /* initialize timer for os tick */
  49. rt_hw_gtimer_init();
  50. rt_thread_idle_sethook(idle_wfi);
  51. arm_psci_init(RT_NULL, RT_NULL);
  52. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  53. /* set console device */
  54. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  55. #endif
  56. #ifdef RT_USING_HEAP
  57. /* initialize memory system */
  58. rt_kprintf("heap: [0x%08x - 0x%08x]\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  59. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  60. #endif
  61. #ifdef RT_USING_COMPONENTS_INIT
  62. rt_components_board_init();
  63. #endif
  64. #ifdef RT_USING_SMP
  65. /* install IPI handle */
  66. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  67. arm_gic_umask(0, IRQ_ARM_IPI_KICK);
  68. #endif
  69. }
  70. void poweroff(void)
  71. {
  72. arm_psci_system_off();
  73. }
  74. MSH_CMD_EXPORT(poweroff, poweroff...);
  75. void reboot(void)
  76. {
  77. arm_psci_system_reboot();
  78. }
  79. MSH_CMD_EXPORT(reboot, reboot...);
  80. #ifdef RT_USING_SMP
  81. void rt_hw_secondary_cpu_up(void)
  82. {
  83. int i;
  84. extern void secondary_cpu_start(void);
  85. extern rt_uint64_t rt_cpu_mpidr_early[];
  86. for (i = 1; i < RT_CPUS_NR; ++i)
  87. {
  88. arm_psci_cpu_on(rt_cpu_mpidr_early[i], (uint64_t)(secondary_cpu_start));
  89. }
  90. }
  91. void secondary_cpu_c_start(void)
  92. {
  93. rt_hw_mmu_init();
  94. rt_hw_spin_lock(&_cpus_lock);
  95. arm_gic_cpu_init(0, platform_get_gic_cpu_base());
  96. rt_hw_vector_init();
  97. rt_hw_gtimer_local_enable();
  98. arm_gic_umask(0, IRQ_ARM_IPI_KICK);
  99. rt_kprintf("\rcall cpu %d on success\n", rt_hw_cpu_id());
  100. rt_system_scheduler_start();
  101. }
  102. void rt_hw_secondary_cpu_idle_exec(void)
  103. {
  104. __WFE();
  105. }
  106. #endif