board.c 3.3 KB

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