1 /*
2  * Copyright (c) 2006-2024, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2024-04-11     liYony       the first version
9  */
10 
11 #include <mmu.h>
12 #include <board.h>
13 #include <mm_aspace.h>
14 #include <mm_page.h>
15 #include <drv_uart.h>
16 #include <gtimer.h>
17 
18 extern size_t MMUTable[];
19 
20 #ifdef RT_USING_SMART
21 struct mem_desc platform_mem_desc[] = {
22     {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x7FF00000 - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM}
23 };
24 #else
25 struct mem_desc platform_mem_desc[] =
26 {
27     {0x00200000, 0x7FF00000 - 1, 0x00200000, NORMAL_MEM},
28     {GIC400_DISTRIBUTOR_PPTR, GIC400_DISTRIBUTOR_PPTR + GIC400_SIZE - 1, GIC400_DISTRIBUTOR_PPTR, DEVICE_MEM},
29     {GIC400_CONTROLLER_PPTR, GIC400_CONTROLLER_PPTR + GIC400_SIZE - 1, GIC400_CONTROLLER_PPTR, DEVICE_MEM},
30 };
31 #endif
32 
33 const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
34 
idle_wfi(void)35 void idle_wfi(void)
36 {
37     asm volatile("wfi");
38 }
39 
rt_hw_board_init(void)40 void rt_hw_board_init(void)
41 {
42 #ifdef RT_USING_SMART
43     rt_hw_mmu_map_init(&rt_kernel_space, (void *)0xfffffffff0000000, 0x10000000, MMUTable, PV_OFFSET);
44 #else
45     rt_hw_mmu_map_init(&rt_kernel_space, (void *)0xffffd0000000, 0x10000000, MMUTable, 0);
46 #endif
47     rt_region_t init_page_region;
48     init_page_region.start = PAGE_START;
49     init_page_region.end = PAGE_END;
50     rt_page_init(init_page_region);
51 
52     rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);
53 
54 #ifdef RT_USING_HEAP
55     /* initialize system heap */
56     rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
57 #endif
58     /* initialize hardware interrupt */
59     rt_hw_interrupt_init();
60 
61     /* initialize uart */
62     rt_hw_uart_init();
63 
64     /* initialize timer for os tick */
65     rt_hw_gtimer_init();
66 
67     rt_thread_idle_sethook(idle_wfi);
68 #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
69     /* set console device */
70     rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
71 #endif
72     rt_kprintf("heap: [0x%08x - 0x%08x]\n", HEAP_BEGIN, HEAP_END);
73 
74 #ifdef RT_USING_COMPONENTS_INIT
75     rt_components_board_init();
76 #endif
77 }
78