board.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-01-30 lizhirui first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include "board.h"
  14. #include "mm_aspace.h"
  15. #include "tick.h"
  16. #include "drv_uart.h"
  17. #include "encoding.h"
  18. #include "stack.h"
  19. #include "sbi.h"
  20. #include "riscv.h"
  21. #include "plic.h"
  22. #include "stack.h"
  23. #ifdef RT_USING_SMP
  24. #include "interrupt.h"
  25. #endif /* RT_USING_SMP */
  26. #ifdef RT_USING_SMART
  27. #include "riscv_mmu.h"
  28. #include "mmu.h"
  29. #include "page.h"
  30. #include "lwp_arch.h"
  31. rt_region_t init_page_region = {(rt_size_t)RT_HW_PAGE_START, (rt_size_t)RT_HW_PAGE_END};
  32. extern size_t MMUTable[];
  33. struct mem_desc platform_mem_desc[] = {
  34. {KERNEL_VADDR_START, (rt_size_t)RT_HW_PAGE_END - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
  35. };
  36. #define NUM_MEM_DESC (sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]))
  37. #endif
  38. void primary_cpu_entry(void)
  39. {
  40. /* disable global interrupt */
  41. rt_hw_interrupt_disable();
  42. entry();
  43. }
  44. #define IOREMAP_SIZE (1ul << 30)
  45. #ifndef ARCH_REMAP_KERNEL
  46. #define IOREMAP_VEND USER_VADDR_START
  47. #else
  48. #define IOREMAP_VEND 0ul
  49. #endif /* ARCH_REMAP_KERNEL */
  50. void rt_hw_board_init(void)
  51. {
  52. #ifdef RT_USING_SMART
  53. /* init data structure */
  54. rt_hw_mmu_map_init(&rt_kernel_space, (void *)(IOREMAP_VEND - IOREMAP_SIZE), IOREMAP_SIZE, (rt_size_t *)MMUTable, PV_OFFSET);
  55. /* init page allocator */
  56. rt_page_init(init_page_region);
  57. /* setup region, and enable MMU */
  58. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, NUM_MEM_DESC);
  59. #endif
  60. #ifdef RT_USING_HEAP
  61. /* initialize memory system */
  62. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  63. #endif
  64. plic_init();
  65. rt_hw_interrupt_init();
  66. rt_hw_uart_init();
  67. #ifdef RT_USING_CONSOLE
  68. /* set console device */
  69. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  70. #endif /* RT_USING_CONSOLE */
  71. rt_hw_tick_init();
  72. #ifdef RT_USING_SMP
  73. /* ipi init */
  74. rt_hw_ipi_init();
  75. #endif /* RT_USING_SMP */
  76. #ifdef RT_USING_COMPONENTS_INIT
  77. rt_components_board_init();
  78. #endif
  79. #ifdef RT_USING_HEAP
  80. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t)RT_HW_HEAP_BEGIN, (rt_ubase_t)RT_HW_HEAP_END);
  81. #endif /* RT_USING_HEAP */
  82. }
  83. void rt_hw_cpu_reset(void)
  84. {
  85. sbi_shutdown();
  86. while (1)
  87. ;
  88. }
  89. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);