board.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * 2021-07-14 JasonHu first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include <rtconfig.h>
  14. #include <rtdbg.h>
  15. #include <cpuport.h>
  16. #include <board.h>
  17. #include <dma.h>
  18. #include "drv_uart.h"
  19. #include "direct_uart.h"
  20. #include "drv_timer.h"
  21. #include "pci.h"
  22. #ifdef RT_USING_USERSPACE
  23. #include <mmu.h>
  24. #include <page.h>
  25. #include "lwp_arch.h"
  26. rt_mmu_info mmu_info;
  27. /* kernel mmu table */
  28. volatile rt_size_t g_mmu_table[ARCH_PAGE_SIZE / sizeof(rt_size_t)] __attribute__((aligned(ARCH_PAGE_SIZE)));
  29. static size_t page_region_init()
  30. {
  31. unsigned int memory_size = *((unsigned int *)0x000001000);
  32. rt_kprintf("physic memory size: %x bytes, %d MB\n", memory_size, memory_size / (1024 * 1024));
  33. if (memory_size < HW_PHY_MEM_SIZE_MIN)
  34. {
  35. dbg_log(DBG_ERROR, "phyisc memory too small! only %d MB, must >= %d MB\n",
  36. memory_size / (1024 * 1024), HW_PHY_MEM_SIZE_MIN / (1024 * 1024));
  37. for (;;)
  38. {
  39. }
  40. }
  41. if (memory_size > HW_PAGE_SIZE_MAX)
  42. {
  43. memory_size = HW_PAGE_SIZE_MAX;
  44. }
  45. return memory_size;
  46. }
  47. #endif
  48. void rt_hw_board_init(void)
  49. {
  50. #ifdef BSP_USING_DIRECT_UART
  51. /* init direct serial hardware */
  52. rt_hw_direct_uart_init();
  53. #endif /* RT_USING_DIRECT_UART */
  54. #ifdef RT_USING_USERSPACE
  55. /* init page and mmu */
  56. rt_region_t init_page_region;
  57. init_page_region.start = (size_t)HW_PAGE_START;
  58. init_page_region.end = page_region_init();
  59. /* init no mapped area in kernel table, must in kernel space */
  60. RT_ASSERT(!rt_hw_mmu_map_init(&mmu_info, (void *)HW_KERNEL_DELAY_MAP_START,
  61. HW_KERNEL_DELAY_MAP_SIZE, (rt_size_t *)g_mmu_table, 0));
  62. rt_page_init(init_page_region);
  63. /* map kernel space, then can read/write this area directly. */
  64. rt_hw_mmu_kernel_map_init(&mmu_info, HW_KERNEL_START, HW_KERNEL_END);
  65. rt_hw_mmu_switch((void *)g_mmu_table);
  66. mmu_enable();
  67. #endif
  68. /* init cpu special */
  69. rt_hw_cpu_init();
  70. /* initalize interrupt */
  71. rt_hw_interrupt_init();
  72. #ifdef BSP_DRV_UART
  73. /* init serial driver */
  74. rt_hw_uart_init();
  75. #endif /* BSP_DRV_UART */
  76. /* init timer driver */
  77. rt_hw_timer_init();
  78. #ifdef RT_USING_HEAP
  79. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t) HW_HEAP_BEGIN, (rt_ubase_t) HW_HEAP_END);
  80. /* initialize memory system */
  81. rt_system_heap_init((void *)HW_HEAP_BEGIN, (void *)HW_HEAP_END);
  82. #endif
  83. /* init dma allocator */
  84. rt_hw_dma_init(HW_DMA_BEGIN, HW_DMA_BEGIN + HW_DMA_SIZE);
  85. /* init pci bus */
  86. rt_pci_init();
  87. #ifdef RT_USING_COMPONENTS_INIT
  88. rt_components_board_init();
  89. #endif
  90. #ifdef RT_USING_CONSOLE
  91. /* set console device */
  92. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  93. #endif /* RT_USING_CONSOLE */
  94. }
  95. void primary_cpu_entry(void)
  96. {
  97. extern void entry(void);
  98. rt_hw_interrupt_disable();
  99. entry();
  100. }