From 824852fd717491d3a1ed979e8763603648a1ad2d Mon Sep 17 00:00:00 2001 From: wangguokun Date: Thu, 24 Oct 2024 10:08:37 +0800 Subject: [PATCH] plat/rk3568: refactor the static page table Signed-off-by: wangguokun --- Linker.uk | 19 +++++- Makefile.uk | 4 +- rk3568_bpt64.S | 118 -------------------------------- rk3568_mrds.c | 151 +++++++++++++++++++++++++++++++++++++++++ start.S | 1 - static_memregion.lds.S | 12 ++++ 6 files changed, 183 insertions(+), 122 deletions(-) delete mode 100644 rk3568_bpt64.S create mode 100644 rk3568_mrds.c create mode 100644 static_memregion.lds.S diff --git a/Linker.uk b/Linker.uk index 619d75c..9be0768 100644 --- a/Linker.uk +++ b/Linker.uk @@ -15,15 +15,29 @@ RK3568_LD_SCRIPT_FLAGS := $(addprefix -Wl$(comma)-dT$(comma),\ RK3568_LD_SCRIPT_FLAGS += $(addprefix -Wl$(comma)-T$(comma),\ $(RK3568_LD_SCRIPT-y) $(EXTRA_LD_SCRIPT-y)) +RK3568_STATIC_PT := $(BUILD_DIR)/tn_static_pgtable +ifeq ($(CONFIG_STATIC_PGTABLE),y) +RK3568_STATIC_PT_OBLIB := $(RK3568_STATIC_PT).o +else +RK3568_STATIC_PT_OBLIB := +endif + +ifeq ($(CONFIG_STATIC_PGTABLE),y) +$(RK3568_STATIC_PT_OBLIB): $(RK3568_OLIBS-y) $(STATIC_PAGE_TOOLS) + $(call build_static_pgtable,$(word 1, $<),$(RK3568_STATIC_PT)) +endif + $(RK3568_DEBUG_IMAGE): $(RK3568_ALIBS) $(RK3568_ALIBS-y) $(RK3568_OLIBS) $(RK3568_OLIBS-y) \ $(UK_ALIBS) $(UK_ALIBS-y) $(UK_OLIBS) $(UK_OLIBS-y) \ $(RK3568_LD_SCRIPT-y) $(EXTRA_LD_SCRIPT-y) \ - $(UK_PLAT_RK3568_DEF_LDS) $(UK_LDEPS) + $(UK_PLAT_RK3568_DEF_LDS) $(UK_LDEPS) \ + $(RK3568_STATIC_PT_OBLIB) $(call build_cmd,LD,,$@,\ $(LD) \ $(RK3568_LDFLAGS) $(RK3568_LDFLAGS-y) \ $(RK3568_OLIBS) $(RK3568_OLIBS-y) \ $(UK_OLIBS) $(UK_OLIBS-y) \ + $(RK3568_STATIC_PT_OBLIB) \ -Wl$(comma)--start-group \ $(RK3568_ALIBS) $(RK3568_ALIBS-y) \ $(UK_ALIBS) $(UK_ALIBS-y) \ @@ -35,6 +49,9 @@ $(RK3568_DEBUG_IMAGE): $(RK3568_ALIBS) $(RK3568_ALIBS-y) $(RK3568_OLIBS) $(RK356 ifeq ($(CONFIG_OPTIMIZE_PIE),y) $(call build_uk_reloc,$@) endif +ifeq ($(CONFIG_STATIC_PGTABLE),y) + $(call update_static_pgtable,$@,$(RK3568_STATIC_PT)) +endif $(RK3568_IMAGE): $(RK3568_IMAGE).dbg diff --git a/Makefile.uk b/Makefile.uk index 5b7437f..8280db5 100644 --- a/Makefile.uk +++ b/Makefile.uk @@ -64,6 +64,6 @@ LIBRK3568PLAT_SRCS-y += $(LIBRK3568PLAT_BASE)/memory.c LIBRK3568PLAT_SRCS-y += $(LIBRK3568PLAT_BASE)/setup.c LIBRK3568PLAT_SRCS-y += $(LIBRK3568PLAT_BASE)/shutdown.c LIBRK3568PLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBRK3568PLAT_BASE)/mmu.S|isr -LIBRK3568PLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBRK3568PLAT_BASE)/rk3568_bpt64.S|arm +LIBRK3568PLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBRK3568PLAT_BASE)/rk3568_mrds.c|arm +LIBRK3568PLAT_SRCS-$(CONFIG_STATIC_PGTABLE) += $(LIBRK3568PLAT_BASE)/static_memregion.lds.S|arm LIBRK3568PLAT_SRCS-y += $(UK_PLAT_RK3568_DEF_LDS) - diff --git a/rk3568_bpt64.S b/rk3568_bpt64.S deleted file mode 100644 index 380a3cb..0000000 --- a/rk3568_bpt64.S +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2024 Hangzhou Yingyi Technology Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include -#include -/* ------------------------- Memory Map of rk3568 ----------------------- - * - * 0x0000,0000,0000 - 0x0000,3FFF,FFFF NormalMem: 0-1GiB attr:normal - * 0x0000,F000,0000 - 0x0000,FE8D,FFFF Device: attr:device - * 0x0003,0000,0000 - 0x0003,BFFF,FFFF PCIe: attr:device - * 0x0003,C000,0000 - 0x0003,C0BF,FFFF PCIe_DBI attr:device - * Notice: The page tables below use the Unikraft indexing convention. - */ - -.section .data -.align 4 -.global bpt_unmap_mrd -bpt_unmap_mrd: - .quad 0x000000000200000 /* 4K */ - .quad 0x000000000200000 /* 4k */ - /* Used for struct ukplat_memregion_desc - * Unmapping starts at 4K and ends at 1G - */ - .quad 0x000000003FE00000 - .short 0x0000000000000000 - .short 0x0000000000000010 /* UKPLAT_MEMRF_UNMAP */ - .space 36 - -.global arm64_bpt_l3_pt0 -.align 12 -arm64_bpt_l3_pt0: - ur_pte arm64_bpt_l2_pt0, PTE_TYPE_TABLE - pte_zero , 510 -#if CONFIG_PAGING - ur_pte arm64_bpt_l2_pt511, PTE_TYPE_TABLE -#else /* !CONFIG_PAGING */ - pte_zero , 1 -#endif /* !CONFIG_PAGING */ - - -/* l2_pt0: 1GiB / entry - * 0x0000,0000,0000 - 0x0000,3FFF,FFFF RAM - * 0x0000,4000,0000 - 0x0000,BFFF,FFFF hole - * 0x0000,C000,0000 - 0x0000,FFFF,FFFF Device - * 0x0001,0000,0000 - 0x0002,FFFF,FFFF hole - * 0x0003,0000,0000 - 0x0003,BFFF,FFFF PCIe (PCIe2x1_S PCIe3x1_S PCIe3x2_S) - * 0x0003,C000,0000 - 0x0003,FFFF,FFFF Device (PCIE_DBI) -*/ -.align 12 -arm64_bpt_l2_pt0: - ur_pte arm64_bpt_l1_pt0, PTE_TYPE_TABLE - pte_zero ,2 - ur_pte arm64_bpt_l1_pt3, PTE_TYPE_TABLE - pte_zero ,8 - pte_fill 0x300000000, 3, 2, PTE_BLOCK_DEVICE_nGnRnE - ur_pte arm64_bpt_l1_pt15, PTE_TYPE_TABLE - pte_zero ,496 - -#if CONFIG_PAGING -/* l2_pt511: 1GiB / entry - * - * 0x0000ff8000000000 - 0x0000ffffffffffff Direct-mapped - */ -.align 12 -arm64_bpt_l2_pt511: - pte_fill 0x0000000000000000, 1, 2, PTE_BLOCK_NORMAL_RW - pte_zero , 511 -#endif /* CONFIG_PAGING */ - - -/* l1_pt0: 2MiB / entry - * 0x0000,0000 - 0x001F,FFFF hole - * 0x0020,0000 - 0x083F,FFFF RAM - * 0x0840,0000 - 0x093F,FFFF hole - * 0x0940,0000 - 0x3FFF,FFFF RAM -*/ -.align 12 -arm64_bpt_l1_pt0: - pte_zero , 1 - pte_fill 0x200000, 65, 1, PTE_BLOCK_NORMAL_RWX - pte_zero , 8 - pte_fill 0x9400000, 438, 1, PTE_BLOCK_NORMAL_RWX - -/* l1_pt3: 2MiB / entry - * 0xC000,0000 - 0xEFFF,FFFF hole - * 0xF000,0000 - 0xFE8D,FFFF device - * 0xFE8E,0000 - 0xFFFF,FFFF hole -*/ -.align 12 -arm64_bpt_l1_pt3: - pte_zero ,384 - pte_fill 0x000000F0000000, 116, 1, PTE_BLOCK_DEVICE_nGnRnE - pte_zero ,12 - - -/* l1_pt15: 2MiB / entry - * 0x3,C000,0000 - 0x3,C0BF,FFFF - * PCIe (PCIe2x1_DBI PCIe3x1_DBI PCIe3x2_DBI) -*/ -.align 12 -arm64_bpt_l1_pt15: - pte_fill 0x3C0000000, 6, 1, PTE_BLOCK_DEVICE_nGnRnE - pte_zero ,506 diff --git a/rk3568_mrds.c b/rk3568_mrds.c new file mode 100644 index 0000000..0cd4d42 --- /dev/null +++ b/rk3568_mrds.c @@ -0,0 +1,151 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2024 The TenonOS Authors + */ + +#include +#include + +/* ------------------------- Memory Map of rk3568 ----------------------- + * + * 0x0000,0020,0000 - 0x0000,083F,FFFF NormalMem: attr:normal + * 0x0000,0940,0000 - 0x0000,3FFF,FFFF NormalMem: attr:normal + * 0x0000,F000,0000 - 0x0000,FFFF,FFFF Device: attr:device + * 0x0003,0000,0000 - 0x0003,BFFF,FFFF PCIe: attr:device + * 0x0003,C000,0000 - 0x0003,C0BF,FFFF PCIe_DBI attr:device + */ +struct ukplat_memregion_desc bpt_unmap_mrd __section(".data") = { + .pbase = ALIGN_DOWN(0x200000UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0x200000UL, __PAGE_SIZE), + .pg_off = 0x0UL, + .len = 0x3FE00000UL, + .pg_count = PAGE_COUNT(0x3FE00000UL), + .type = UKPLAT_MEMRT_RESERVED, + .flags = UKPLAT_MEMRF_UNMAP +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif +}; + +#ifdef CONFIG_STATIC_PGTABLE +struct ukplat_memregion_desc + bpt_memregion[] __section(".tn_static_memregion") = { + /* RAM + * Virtual address: 0x0000000000200000 - 0x00000000083FFFFF + * Physical address: 0x0000000000200000 - 0x00000000083FFFFF + */ + { .pbase = ALIGN_DOWN(0x200000UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0x200000UL, __PAGE_SIZE), + .pg_off = 0x0, + .len = 0x8200000UL, + .pg_count = PAGE_COUNT(0x8200000UL), + .type = UKPLAT_MEMRT_FREE, + .flags = UKPLAT_MEMRF_VALUE_IS_WR | UKPLAT_MEMRF_UXN | + UKPLAT_MEMRF_MAIR(UKPLAT_MEMRF_MAIR_NORMAL_WB) | + UKPLAT_MEMRF_LEVEL(UKPLAT_MEMRF_LEVEL_PMD) +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif /* CONFIG_UKPLAT_MEMRNAME */ + }, + /* RAM + * Virtual address: 0x0000000009400000 - 0x000000003FFFFFFF + * Physical address: 0x0000000009400000 - 0x000000003FFFFFFF + */ + { .pbase = ALIGN_DOWN(0x9400000UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0x9400000UL, __PAGE_SIZE), + .pg_off = 0x0, + .len = 0x36C00000UL, + .pg_count = PAGE_COUNT(0x36C00000UL), + .type = UKPLAT_MEMRT_FREE, + .flags = UKPLAT_MEMRF_VALUE_IS_WR | UKPLAT_MEMRF_UXN | + UKPLAT_MEMRF_MAIR(UKPLAT_MEMRF_MAIR_NORMAL_WB) | + UKPLAT_MEMRF_LEVEL(UKPLAT_MEMRF_LEVEL_PMD) +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif /* CONFIG_UKPLAT_MEMRNAME */ + }, + /* DEVICE + * Virtual address: 0x00000000F0000000 - 0x00000000FFFFFFFF + * Physical address: 0x00000000F0000000 - 0x00000000FFFFFFFF + */ + { .pbase = ALIGN_DOWN(0xF0000000UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0xF0000000UL, __PAGE_SIZE), + .pg_off = 0x0, + .len = 0x10000000UL, + .pg_count = PAGE_COUNT(0x10000000UL), + .type = UKPLAT_MEMRT_RESERVED, + .flags = UKPLAT_MEMRF_VALUE_IS_WR | + UKPLAT_MEMRF_MAIR(UKPLAT_MEMRF_MAIR_DEVICE_nGnRnE) | + UKPLAT_MEMRF_LEVEL(UKPLAT_MEMRF_LEVEL_PMD) +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif /* CONFIG_UKPLAT_MEMRNAME */ + }, + /* DEVICE + * Virtual address: 0x0000000300000000 - 0x00000003BFFFFFFF + * Physical address: 0x0000000300000000 - 0x00000003BFFFFFFF + */ + { .pbase = ALIGN_DOWN(0x300000000UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0x300000000UL, __PAGE_SIZE), + .pg_off = 0x0, + .len = 0xC0000000UL, + .pg_count = PAGE_COUNT(0xC0000000UL), + .type = UKPLAT_MEMRT_RESERVED, + .flags = UKPLAT_MEMRF_VALUE_IS_WR | + UKPLAT_MEMRF_MAIR(UKPLAT_MEMRF_MAIR_DEVICE_nGnRnE) | + UKPLAT_MEMRF_LEVEL(UKPLAT_MEMRF_LEVEL_PMD) +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif /* CONFIG_UKPLAT_MEMRNAME */ + }, + /* DEVICE + * Virtual address: 0x00000003C0000000 - 0x00000003C0BFFFFF + * Physical address: 0x00000003C0000000 - 0x00000003C0BFFFFF + */ + { .pbase = ALIGN_DOWN(0x3C0000000UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0x3C0000000UL, __PAGE_SIZE), + .pg_off = 0x0, + .len = 0xC00000UL, + .pg_count = PAGE_COUNT(0xC00000UL), + .type = UKPLAT_MEMRT_RESERVED, + .flags = UKPLAT_MEMRF_VALUE_IS_WR | + UKPLAT_MEMRF_MAIR(UKPLAT_MEMRF_MAIR_DEVICE_nGnRnE) | + UKPLAT_MEMRF_LEVEL(UKPLAT_MEMRF_LEVEL_PMD) +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif /* CONFIG_UKPLAT_MEMRNAME */ + } +}; + +#ifdef CONFIG_PAGING +struct ukplat_memregion_desc + direct_map_mrd __section(".tn_direct_memregion") = { + /* Direct-mapped + * Virtual address: 0x0000ff8000000000 - 0x0000ffffffffffff + * Physical address: 0x0000000000000000 - 0x0000008000000000 + */ + .pbase = ALIGN_DOWN(0x0UL, __PAGE_SIZE), + .vbase = ALIGN_DOWN(0xff8000000000UL, __PAGE_SIZE), + .pg_off = 0x0, + .len = 0x8000000000UL, + .pg_count = PAGE_COUNT(0x8000000000UL), + .type = UKPLAT_MEMRT_RESERVED, + .flags = UKPLAT_MEMRF_VALUE_IS_WR | + UKPLAT_MEMRF_MAIR(UKPLAT_MEMRF_MAIR_NORMAL_WB) | + UKPLAT_MEMRF_LEVEL(UKPLAT_MEMRF_LEVEL_PUD) +#ifdef CONFIG_UKPLAT_MEMRNAME + , + .name = { 0 } +#endif /* CONFIG_UKPLAT_MEMRNAME */ +}; +#endif + +__u32 bpt_memregion_count = + sizeof(bpt_memregion) / sizeof(struct ukplat_memregion_desc); + +#endif diff --git a/start.S b/start.S index 433b61b..a9a28bd 100644 --- a/start.S +++ b/start.S @@ -17,7 +17,6 @@ #include #include #include -#include #define BOOTSTACK_SIZE 4096 diff --git a/static_memregion.lds.S b/static_memregion.lds.S new file mode 100644 index 0000000..bed1af2 --- /dev/null +++ b/static_memregion.lds.S @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: Apache-2.0 + * Copyright 2024 The TenonOS Authors + */ + +SECTIONS { + . = ALIGN(8); + .tn_static_memregion : + { + KEEP(*(.tn_static_memregion)) + } +} +INSERT AFTER .data -- Gitee