board.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-3-08 GuEe-GUI the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <mmu.h>
  13. #include <psci.h>
  14. #include <gicv3.h>
  15. #include <gtimer.h>
  16. #include <cpuport.h>
  17. #include <interrupt.h>
  18. #include <board.h>
  19. #include <drv_uart.h>
  20. struct mem_desc platform_mem_desc[] =
  21. {
  22. {0x200000, 0x80000000, 0x200000, NORMAL_MEM},
  23. {UART0_MMIO_BASE, UART0_MMIO_BASE + 0x10000, UART0_MMIO_BASE, DEVICE_MEM},
  24. {UART1_MMIO_BASE, UART1_MMIO_BASE + 0x90000, UART1_MMIO_BASE, DEVICE_MEM},
  25. {GIC_PL600_DISTRIBUTOR_PPTR, GIC_PL600_DISTRIBUTOR_PPTR + 0x10000, GIC_PL600_DISTRIBUTOR_PPTR, DEVICE_MEM},
  26. {GIC_PL600_REDISTRIBUTOR_PPTR, GIC_PL600_REDISTRIBUTOR_PPTR + 0xc0000, GIC_PL600_REDISTRIBUTOR_PPTR, DEVICE_MEM},
  27. };
  28. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
  29. void idle_wfi(void)
  30. {
  31. __asm__ volatile ("wfi");
  32. }
  33. void rt_hw_board_init(void)
  34. {
  35. extern void *MMUTable;
  36. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x80000000, 0x10000000, MMUTable, 0);
  37. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
  38. /* initialize hardware interrupt */
  39. rt_hw_interrupt_init();
  40. /* initialize uart */
  41. rt_hw_uart_init();
  42. /* initialize timer for os tick */
  43. rt_hw_gtimer_init();
  44. rt_thread_idle_sethook(idle_wfi);
  45. // TODO porting to FDT-driven PSCI: arm_psci_init(PSCI_METHOD_SMC, RT_NULL, RT_NULL);
  46. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  47. /* set console device */
  48. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  49. #endif
  50. #ifdef RT_USING_HEAP
  51. /* initialize memory system */
  52. rt_kprintf("heap: [0x%08x - 0x%08x]\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  53. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  54. #endif
  55. #ifdef RT_USING_COMPONENTS_INIT
  56. rt_components_board_init();
  57. #endif
  58. #ifdef RT_USING_SMP
  59. /* install IPI handle */
  60. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  61. arm_gic_umask(0, IRQ_ARM_IPI_KICK);
  62. #endif
  63. }
  64. void reboot(void)
  65. {
  66. // TODO poring to FDT to use new PSCI: arm_psci_system_reboot();
  67. }
  68. MSH_CMD_EXPORT(reboot, reboot...);
  69. #ifdef RT_USING_SMP
  70. rt_uint64_t rt_cpu_mpidr_early[] =
  71. {
  72. [0] = 0x81000000,
  73. [1] = 0x81000100,
  74. [2] = 0x81000200,
  75. [3] = 0x81000300,
  76. };
  77. void rt_hw_secondary_cpu_up(void)
  78. {
  79. int i;
  80. extern void secondary_cpu_start(void);
  81. for (i = 1; i < RT_CPUS_NR; ++i)
  82. {
  83. arm_psci_cpu_on(rt_cpu_mpidr_early[i], (rt_uint64_t)secondary_cpu_start);
  84. }
  85. }
  86. void secondary_cpu_c_start(void)
  87. {
  88. rt_hw_mmu_init();
  89. rt_hw_spin_lock(&_cpus_lock);
  90. arm_gic_cpu_init(0, platform_get_gic_cpu_base());
  91. arm_gic_redist_init(0, platform_get_gic_redist_base());
  92. rt_hw_vector_init();
  93. rt_hw_gtimer_local_enable();
  94. arm_gic_umask(0, IRQ_ARM_IPI_KICK);
  95. rt_kprintf("\rcall cpu %d on success\n", rt_hw_cpu_id());
  96. rt_system_scheduler_start();
  97. }
  98. void rt_hw_secondary_cpu_idle_exec(void)
  99. {
  100. __WFE();
  101. }
  102. #endif