summaryrefslogtreecommitdiff
path: root/bsp/cvitek/cv18xx_aarch64/board/board.c
blob: bed90f8ddaf2c7c865768a34164c55c83c6997f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (c) 2006-2024, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2024-04-15     liYony       the first version
 */

#include <mmu.h>
#include <board.h>
#include <mm_aspace.h>
#include <mm_page.h>
#include <drv_uart.h>
#include <gtimer.h>
#include <setup.h>

extern size_t MMUTable[];

#ifndef RT_USING_OFW
void idle_wfi(void)
{
    asm volatile("wfi");
}

#ifdef RT_USING_SMART
struct mem_desc platform_mem_desc[] = {
    {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x0FFFFFFF, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
};
#else
struct mem_desc platform_mem_desc[] =
{
    {0x80200000, 0x90200000 - 1, 0x80200000, NORMAL_MEM}, /* memory size 256M */
    {0x01000000, 0x80000000 - 1, 0x01000000, DEVICE_MEM},
};
#endif

const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);

rt_uint64_t rt_hw_get_clock_timer_freq(void)
{
    return 25000000ULL;
}

void rt_hw_board_init(void)
{
#ifdef RT_USING_SMART
    rt_hw_mmu_map_init(&rt_kernel_space, (void *)0xfffffffff0000000, 0x10000000, MMUTable, PV_OFFSET);
#else
    rt_hw_mmu_map_init(&rt_kernel_space, (void *)0xffffd0000000, 0x10000000, MMUTable, 0);
#endif
    rt_region_t init_page_region;
    init_page_region.start = PAGE_START;
    init_page_region.end = PAGE_END;
    rt_page_init(init_page_region);

    rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, platform_mem_desc_size);

#ifdef RT_USING_HEAP
    /* initialize system heap */
    rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
    /* initialize hardware interrupt */
    rt_hw_interrupt_init();

    /* initialize uart */
    rt_hw_uart_init();

    /* initialize timer for os tick */
    rt_hw_gtimer_init();

    rt_thread_idle_sethook(idle_wfi);
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
    /* set console device */
    rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif
    rt_kprintf("heap: [0x%08x - 0x%08x]\n", HEAP_BEGIN, HEAP_END);

#ifdef RT_USING_COMPONENTS_INIT
    rt_components_board_init();
#endif
}
#else
void rt_hw_board_init(void)
{
    rt_hw_common_setup();
}

/*
 * FIXME: This is a temporary workaround.
 * When aarch bsp enables the device tree, the current u-boot will
 * pass in bootargs, which contains "root=/dev/mmcblk0p2 rootwait rw",
 * which means that the kernel is required to wait until the rootfs
 * in /dev/mmcblk0p2 loaded successfully. However, the current aarch64 bsp
 * default does not implement sdmmc device mounting, causing the kernel file
 * system mounting module (rootfs_mnt_init() of components/drivers/core/mnt.c)
 * to enter an infinite loop waiting.
 * Solution: At present, we do not plan to modify the startup parameters
 * of u-boot. The temporary solution adopted is to create a pseudo
 * /dev/mmcblk0p2 device during the board initialization process, and
 * then cancel the pseudo device after mnt is completed. This allows the
 * kernel boot to be completed successfully.
 */
static struct rt_device *pseudo_mmcblk;

static int pseudo_mmcblk_setup(void)
{
    pseudo_mmcblk = rt_calloc(1, sizeof(*pseudo_mmcblk));

    RT_ASSERT(pseudo_mmcblk != RT_NULL);

    pseudo_mmcblk->type = RT_Device_Class_Graphic;

    return (int)rt_device_register(pseudo_mmcblk, "/dev/mmcblk0p2", RT_DEVICE_FLAG_DEACTIVATE);
}
INIT_BOARD_EXPORT(pseudo_mmcblk_setup);

static int pseudo_mmcblk_remove(void)
{
    if (pseudo_mmcblk)
    {
        return (int)rt_device_unregister(pseudo_mmcblk);
    }

    return 0;
}
INIT_FS_EXPORT(pseudo_mmcblk_remove);
#endif /* RT_USING_OFW */

static rt_ubase_t pinmux_base = RT_NULL;

rt_ubase_t pinmux_base_ioremap(void)
{
    if (pinmux_base == RT_NULL)
    {
        pinmux_base = (rt_size_t)rt_ioremap((void*)0x03001000, 0x1000);
    }

    return pinmux_base;
}