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