board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. rt_uint64_t rt_hw_get_clock_timer_freq(void)
  39. {
  40. return 10000000ULL;
  41. }
  42. void primary_cpu_entry(void)
  43. {
  44. /* disable global interrupt */
  45. rt_hw_interrupt_disable();
  46. entry();
  47. }
  48. #define IOREMAP_SIZE (1ul << 30)
  49. #ifndef ARCH_REMAP_KERNEL
  50. #define IOREMAP_VEND USER_VADDR_START
  51. #else
  52. #define IOREMAP_VEND 0ul
  53. #endif /* ARCH_REMAP_KERNEL */
  54. void rt_hw_board_init(void)
  55. {
  56. #ifdef RT_USING_SMART
  57. /* init data structure */
  58. rt_hw_mmu_map_init(&rt_kernel_space, (void *)(IOREMAP_VEND - IOREMAP_SIZE), IOREMAP_SIZE, (rt_size_t *)MMUTable, PV_OFFSET);
  59. /* init page allocator */
  60. rt_page_init(init_page_region);
  61. /* setup region, and enable MMU */
  62. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, NUM_MEM_DESC);
  63. #endif
  64. #ifdef RT_USING_HEAP
  65. /* initialize memory system */
  66. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  67. #endif
  68. plic_init();
  69. rt_hw_interrupt_init();
  70. rt_hw_uart_init();
  71. #ifdef RT_USING_CONSOLE
  72. /* set console device */
  73. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  74. #endif /* RT_USING_CONSOLE */
  75. rt_hw_tick_init();
  76. #ifdef RT_USING_SMP
  77. /* ipi init */
  78. rt_hw_ipi_init();
  79. #endif /* RT_USING_SMP */
  80. #ifdef RT_USING_COMPONENTS_INIT
  81. rt_components_board_init();
  82. #endif
  83. #ifdef RT_USING_HEAP
  84. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t)RT_HW_HEAP_BEGIN, (rt_ubase_t)RT_HW_HEAP_END);
  85. #endif /* RT_USING_HEAP */
  86. }
  87. void rt_hw_cpu_reset(void)
  88. {
  89. sbi_shutdown();
  90. while (1)
  91. ;
  92. }
  93. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);