board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifdef RT_USING_USERSPACE
  17. #include <page.h>
  18. #include <lwp_arch.h>
  19. #endif
  20. #include "board.h"
  21. #ifdef RT_USING_FDT
  22. #include "interrupt.h"
  23. #include "dtb_node.h"
  24. #include <psci_api.h>
  25. #include <cpu.h>
  26. #endif
  27. #ifdef RT_USING_USERSPACE
  28. struct mem_desc platform_mem_desc[] = {
  29. {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x0fffffff, KERNEL_VADDR_START + PV_OFFSET, NORMAL_MEM}
  30. };
  31. #else
  32. struct mem_desc platform_mem_desc[] = {
  33. {0x10000000, 0x50000000, 0x10000000, DEVICE_MEM},
  34. {0x40000000, 0x50000000, 0x40000000, NORMAL_MEM}
  35. };
  36. #endif
  37. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  38. void idle_wfi(void)
  39. {
  40. asm volatile ("wfi");
  41. }
  42. /**
  43. * This function will initialize board
  44. */
  45. rt_mmu_info mmu_info;
  46. extern size_t MMUTable[];
  47. #ifdef RT_USING_USERSPACE
  48. rt_region_t init_page_region = {
  49. PAGE_START,
  50. PAGE_END,
  51. };
  52. #endif
  53. void rt_hw_board_init(void)
  54. {
  55. #ifdef RT_USING_USERSPACE
  56. rt_page_init(init_page_region);
  57. rt_hw_mmu_setup(platform_mem_desc, platform_mem_desc_size);
  58. rt_hw_mmu_map_init(&mmu_info, (void*)0xfffffffff0000000, 0x10000000, MMUTable, PV_OFFSET);
  59. arch_kuser_init(&mmu_info, (void*)0xffffffffffff0000);
  60. #else
  61. rt_hw_mmu_map_init(&mmu_info, (void*)0x80000000, 0x10000000, MMUTable, 0);
  62. rt_hw_mmu_ioremap_init(&mmu_info, (void*)0x80000000, 0x10000000);
  63. #endif
  64. /* initialize hardware interrupt */
  65. rt_hw_interrupt_init();
  66. /* initialize system heap */
  67. rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
  68. /* support debug feature before components init */
  69. rt_hw_uart_init();
  70. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  71. #ifdef RT_USING_FDT
  72. // TODO 0x44000000 should be replace by a variable
  73. void * fdt_start = (void *)0x44000000 - PV_OFFSET;
  74. device_tree_setup(fdt_start);
  75. #ifdef RT_USING_SMP
  76. rt_hw_cpu_init();
  77. #else
  78. psci_init();
  79. #endif /* RT_USING_SMP */
  80. #endif
  81. rt_components_board_init();
  82. rt_thread_idle_sethook(idle_wfi);
  83. #ifdef RT_USING_SMP
  84. /* install IPI handle */
  85. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  86. #endif
  87. }