Skip to content

Commit 96da7ab

Browse files
zhuzhuzhusmysterywolf
authored andcommitted
[libcpu] fix No memory higher than 1 GB is mapped
1 parent 09f47c5 commit 96da7ab

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

libcpu/aarch64/common/mmu.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,8 @@ unsigned long get_free_page(void)
556556
}
557557

558558
static int _map_single_page_2M(unsigned long *lv0_tbl, unsigned long va,
559-
unsigned long pa, unsigned long attr)
559+
unsigned long pa, unsigned long attr,
560+
rt_bool_t flush)
560561
{
561562
int level;
562563
unsigned long *cur_lv_tbl = lv0_tbl;
@@ -585,6 +586,10 @@ static int _map_single_page_2M(unsigned long *lv0_tbl, unsigned long va,
585586
}
586587
rt_memset((char *)page, 0, ARCH_PAGE_SIZE);
587588
cur_lv_tbl[off] = page | MMU_TYPE_TABLE;
589+
if (flush)
590+
{
591+
rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, cur_lv_tbl + off, sizeof(void *));
592+
}
588593
}
589594
page = cur_lv_tbl[off];
590595
if ((page & MMU_TYPE_MASK) == MMU_TYPE_BLOCK)
@@ -600,6 +605,10 @@ static int _map_single_page_2M(unsigned long *lv0_tbl, unsigned long va,
600605
off = (va >> ARCH_SECTION_SHIFT);
601606
off &= MMU_LEVEL_MASK;
602607
cur_lv_tbl[off] = pa;
608+
if (flush)
609+
{
610+
rt_hw_cpu_dcache_ops(RT_HW_CACHE_FLUSH, cur_lv_tbl + off, sizeof(void *));
611+
}
603612
return 0;
604613
}
605614

@@ -633,7 +642,7 @@ void *rt_ioremap_early(void *paddr, size_t size)
633642

634643
while (count --> 0)
635644
{
636-
if (_map_single_page_2M(tbl, base, base, MMU_MAP_K_DEVICE))
645+
if (_map_single_page_2M(tbl, base, base, MMU_MAP_K_DEVICE, RT_TRUE))
637646
{
638647
return RT_NULL;
639648
}
@@ -661,7 +670,7 @@ static int _init_map_2M(unsigned long *lv0_tbl, unsigned long va,
661670
}
662671
for (i = 0; i < count; i++)
663672
{
664-
ret = _map_single_page_2M(lv0_tbl, va, pa, attr);
673+
ret = _map_single_page_2M(lv0_tbl, va, pa, attr, RT_FALSE);
665674
va += ARCH_SECTION_SIZE;
666675
pa += ARCH_SECTION_SIZE;
667676
if (ret != 0)

libcpu/aarch64/common/setup.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,17 @@ void rt_hw_common_setup(void)
235235
rt_memblock_reserve_memory("init-page", init_page_start, init_page_end, MEMBLOCK_NONE);
236236
rt_memblock_reserve_memory("fdt", fdt_start, fdt_end, MEMBLOCK_NONE);
237237

238-
rt_memmove((void *)(fdt_start - pv_off), (void *)(fdt_ptr - pv_off), fdt_size);
238+
/* To virtual address */
239+
fdt_ptr = (void *)(fdt_ptr - pv_off);
240+
241+
if ((rt_ubase_t)fdt_ptr + fdt_size - KERNEL_VADDR_START > SIZE_GB)
242+
{
243+
fdt_ptr = rt_ioremap_early(fdt_ptr + pv_off, fdt_size);
244+
245+
RT_ASSERT(fdt_ptr != RT_NULL);
246+
}
247+
248+
rt_memmove((void *)(fdt_start - pv_off), fdt_ptr, fdt_size);
239249
fdt_ptr = (void *)fdt_start - pv_off;
240250

241251
rt_system_heap_init((void *)(heap_start - pv_off), (void *)(heap_end - pv_off));

0 commit comments

Comments
 (0)