board.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * 2012-11-20 Bernard the first version
  9. * 2018-11-22 Jesven add rt_hw_spin_lock
  10. * add rt_hw_spin_unlock
  11. * add smp ipi init
  12. */
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include <mmu.h>
  16. #include <gtimer.h>
  17. #ifdef RT_USING_SMART
  18. #include <lwp_arch.h>
  19. #endif
  20. #include "board.h"
  21. #include <mm_aspace.h>
  22. #include <mm_page.h>
  23. #include <interrupt.h>
  24. #ifdef RT_USING_FDT
  25. #include "interrupt.h"
  26. #include "dtb_node.h"
  27. #include <psci_api.h>
  28. #include <cpu.h>
  29. #endif
  30. #ifdef RT_USING_SMART
  31. struct mem_desc platform_mem_desc[] = {
  32. {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x0fffffff, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM}
  33. };
  34. #else
  35. #define PAGE_POOL_SIZE (2ul << 20)
  36. #define PHYMEM_END (0x48000000ul)
  37. struct mem_desc platform_mem_desc[] =
  38. {
  39. {0x40000000, PHYMEM_END - 1, 0x40000000, NORMAL_MEM},
  40. // {PL031_RTC_BASE, PL031_RTC_BASE + 0x1000 - 1, PL031_RTC_BASE, DEVICE_MEM},
  41. // {PL061_GPIO_BASE, PL061_GPIO_BASE + 0x1000 - 1, PL061_GPIO_BASE, DEVICE_MEM},
  42. {PL011_UART0_BASE, PL011_UART0_BASE + ARCH_SECTION_SIZE - 1, PL011_UART0_BASE, DEVICE_MEM},
  43. {VIRTIO_MMIO_BASE, RT_ALIGN(VIRTIO_MMIO_BASE + VIRTIO_MAX_NR * VIRTIO_MMIO_SIZE, ARCH_SECTION_SIZE) - 1, VIRTIO_MMIO_BASE, DEVICE_MEM},
  44. #ifdef BSP_USING_GICV2
  45. {GIC_PL390_DISTRIBUTOR_PPTR, GIC_PL390_DISTRIBUTOR_PPTR + ARCH_SECTION_SIZE - 1, GIC_PL390_DISTRIBUTOR_PPTR, DEVICE_MEM},
  46. #endif
  47. #ifdef BSP_USING_GICV3
  48. {GIC_PL500_DISTRIBUTOR_PPTR, GIC_PL500_DISTRIBUTOR_PPTR + 0x1000 - 1, GIC_PL500_DISTRIBUTOR_PPTR, DEVICE_MEM},
  49. {GIC_PL500_REDISTRIBUTOR_PPTR, GIC_PL500_REDISTRIBUTOR_PPTR + 0xf60000 - 1, GIC_PL500_REDISTRIBUTOR_PPTR, DEVICE_MEM},
  50. #endif
  51. };
  52. #endif
  53. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  54. void idle_wfi(void)
  55. {
  56. asm volatile ("wfi");
  57. }
  58. /**
  59. * This function will initialize board
  60. */
  61. extern size_t MMUTable[];
  62. #ifdef RT_USING_SMART
  63. rt_region_t init_page_region = {
  64. PAGE_START,
  65. PAGE_END,
  66. };
  67. #else
  68. rt_region_t init_page_region = {
  69. PHYMEM_END - PAGE_POOL_SIZE,
  70. PHYMEM_END,
  71. };
  72. #endif
  73. void rt_hw_board_init(void)
  74. {
  75. #ifdef RT_USING_SMART
  76. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xfffffffff0000000, 0x10000000, MMUTable, PV_OFFSET);
  77. #else
  78. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x80000000, 0x10000000, MMUTable, 0);
  79. #endif
  80. rt_page_init(init_page_region);
  81. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
  82. /* initialize system heap */
  83. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  84. /* initialize hardware interrupt */
  85. rt_hw_interrupt_init();
  86. rt_hw_gtimer_init();
  87. /* support debug feature before components init */
  88. rt_hw_uart_init();
  89. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  90. #ifdef RT_USING_FDT
  91. // TODO 0x44000000 should be replace by a variable
  92. void * fdt_start = (void *)0x44000000 - PV_OFFSET;
  93. device_tree_setup(fdt_start);
  94. #ifdef RT_USING_SMP
  95. rt_hw_cpu_init();
  96. #else
  97. psci_init();
  98. #endif /* RT_USING_SMP */
  99. #endif
  100. rt_components_board_init();
  101. rt_thread_idle_sethook(idle_wfi);
  102. #ifdef RT_USING_SMP
  103. /* install IPI handle */
  104. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  105. #endif
  106. }