board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "board.h"
  16. #include "drv_timer.h"
  17. #include "mm_aspace.h"
  18. #include <mmu.h>
  19. #ifdef RT_USING_SMART
  20. #include <page.h>
  21. #include <lwp_arch.h>
  22. #endif
  23. #ifdef RT_USING_SMART
  24. struct mem_desc platform_mem_desc[] = {
  25. {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x10000000, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM}
  26. };
  27. #else
  28. struct mem_desc platform_mem_desc[] = {
  29. {0x10000000, 0x50000000, 0x10000000, DEVICE_MEM},
  30. {0x60000000, 0x70000000, 0x60000000, NORMAL_MEM}
  31. };
  32. #endif
  33. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  34. #define SYS_CTRL __REG32(REALVIEW_SCTL_BASE)
  35. extern void rt_hw_ipi_handler_install(int ipi_vector, rt_isr_handler_t ipi_isr_handler);
  36. void idle_wfi(void)
  37. {
  38. asm volatile ("wfi");
  39. }
  40. /**
  41. * This function will initialize board
  42. */
  43. extern size_t MMUTable[];
  44. #ifdef RT_USING_SMART
  45. rt_region_t init_page_region = {
  46. (uint32_t)PAGE_START,
  47. (uint32_t)PAGE_END,
  48. };
  49. #endif
  50. void rt_hw_board_init(void)
  51. {
  52. #ifdef RT_USING_SMART
  53. rt_uint32_t mmutable_p = 0;
  54. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xf0000000, 0x10000000, MMUTable, PV_OFFSET);
  55. rt_hw_init_mmu_table(platform_mem_desc,platform_mem_desc_size);
  56. mmutable_p = (rt_uint32_t)MMUTable + (rt_uint32_t)PV_OFFSET ;
  57. rt_hw_mmu_switch((void*)mmutable_p);
  58. rt_page_init(init_page_region);
  59. rt_hw_mmu_ioremap_init(&rt_kernel_space, (void*)0xf0000000, 0x10000000);
  60. arch_kuser_init(&rt_kernel_space, (void*)0xffff0000);
  61. #else
  62. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x80000000, 0x10000000, MMUTable, 0);
  63. rt_hw_init_mmu_table(platform_mem_desc,platform_mem_desc_size);
  64. rt_hw_mmu_init();
  65. rt_hw_mmu_ioremap_init(&rt_kernel_space, (void*)0x80000000, 0x10000000);
  66. #endif
  67. /* initialize system heap */
  68. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  69. /* initialize hardware interrupt */
  70. rt_hw_interrupt_init();
  71. rt_components_board_init();
  72. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  73. rt_thread_idle_sethook(idle_wfi);
  74. #ifdef RT_USING_SMP
  75. /* install IPI handle */
  76. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  77. #endif
  78. }