Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
---
plat/kvm/arm/entry64.S | 33 +++++++++++++++++++++++++++--
plat/kvm/arm/pagetable64.S | 7 ++++--
plat/kvm/arm/setup.c | 2 +-
plat/kvm/include/kvm-arm/arm64/mm.h | 14 ++++++------
4 files changed, 45 insertions(+), 11 deletions(-)
diff --git a/plat/kvm/arm/entry64.S b/plat/kvm/arm/entry64.S
index c1af0a4..72e170f 100644
--- a/plat/kvm/arm/entry64.S
+++ b/plat/kvm/arm/entry64.S
@@ -36,6 +36,11 @@
#include <kvm-arm/mm.h>
#include <arm/cpu_defs.h>
+.global page_table_size
+.data
+page_table_size:
+ .dword 0x0
+
/*
* The registers used by _libkvmplat_start:
* x0 - FDT pointer
@@ -60,9 +65,29 @@ ENTRY(_libkvmplat_entry)
msr sctlr_el1, x2
isb
- /* Boot stack is placed after pagetable area temporarily */
+ /* Caculate the image size */
ldr x26, =_end
- add x26, x26, #PAGE_TABLE_SIZE
+ ldr x15, =_dtb
+ sub x15, x26, x15
+
+ /* Round up the size to 2MB */
+ mov x17, #0xfffff
+ add x15, x15, x17
+ and x15, x15, #0xfffffffffff00000
+
+ /*
+ * How many bytes would be used for L3_TABLE
+ * ((x15 >> 21) << 12)
+ */
+ lsr x17, x15, #9
+
+ /* Total bytes for pagetable */
+ add x17, x17, #L0_TABLE_SIZE
+ add x17, x17, #L1_TABLE_SIZE
+ add x17, x17, #L2_TABLE_SIZE
+
+ /* Boot stack is placed after pagetable area temporarily */
+ add x26, x26, x17
add x27, x26, #__STACK_SIZE
/*
@@ -84,6 +109,10 @@ ENTRY(_libkvmplat_entry)
/* Set the context id */
msr contextidr_el1, xzr
+ /* Save page table size for later usage */
+ ldr x26, =page_table_size
+ str x17, [x26]
+
/* Create a pagetable to do PA == VA mapping */
bl create_pagetables
diff --git a/plat/kvm/arm/pagetable64.S b/plat/kvm/arm/pagetable64.S
index cf30584..7d19f6b 100644
--- a/plat/kvm/arm/pagetable64.S
+++ b/plat/kvm/arm/pagetable64.S
@@ -72,7 +72,8 @@ ENTRY(create_pagetables)
/* Clean the page table */
mov x6, x14
- add x13, x14, #PAGE_TABLE_SIZE
+ ldr x13, =page_table_size
+ ldr x13, [x13]
1:
stp xzr, xzr, [x6], #16
stp xzr, xzr, [x6], #16
@@ -244,7 +245,9 @@ ENTRY(start_mmu)
*/
ldr x0, =_data
ldr x1, =_end
- add x1, x1, #PAGE_TABLE_SIZE
+ ldr x2, =page_table_size
+ ldr x2, [x2]
+ add x1, x2, x1
add x1, x1, #__STACK_SIZE
sub x1, x1, x0
bl clean_and_invalidate_dcache_range
diff --git a/plat/kvm/arm/setup.c b/plat/kvm/arm/setup.c
index 59faaa2..bfbb627 100644
--- a/plat/kvm/arm/setup.c
+++ b/plat/kvm/arm/setup.c
@@ -147,7 +147,7 @@ static void _init_dtb_mem(void)
max_addr = mem_base + mem_size;
_libkvmplat_pagetable =(void *) ALIGN_DOWN((size_t)&_end, __PAGE_SIZE);
- _libkvmplat_heap_start = _libkvmplat_pagetable + PAGE_TABLE_SIZE;
+ _libkvmplat_heap_start = _libkvmplat_pagetable + page_table_size;
_libkvmplat_mem_end = (void *) max_addr;
/* AArch64 require stack be 16-bytes alignment by default */
diff --git a/plat/kvm/include/kvm-arm/arm64/mm.h
b/plat/kvm/include/kvm-arm/arm64/mm.h
index 23bc658..9ec1273 100644
--- a/plat/kvm/include/kvm-arm/arm64/mm.h
+++ b/plat/kvm/include/kvm-arm/arm64/mm.h
@@ -69,15 +69,17 @@
#define L2_TABLE_SIZE __PAGE_SIZE
/*
- * As Unikraft image's size is very tiny, from tens to hundreds kilo
- * bytes. So one page for L3_TABLE is enough for us to manage section
- * attributes of image.
+ * We will use Unikraft image's size to caculate the L3_TABLE_SIZE.
+ * Because we allocate one page for L2 TABLE, fo the max image size
+ * would be 1GB. It would be enough for current stage.
*/
#define L3_TABLE_OFFSET (L2_TABLE_OFFSET + L2_TABLE_SIZE)
-#define L3_TABLE_SIZE __PAGE_SIZE
+
+#ifndef __ASSEMBLY__
/* Total memory size that will be used by pagetable */
-#define PAGE_TABLE_SIZE (L0_TABLE_SIZE + L1_TABLE_SIZE + \
- L2_TABLE_SIZE + L3_TABLE_SIZE)
+extern uint64_t page_table_size;
+
+#endif /*__ASSEMBLY__ */
#endif /* __KVM_ARM_64_MM_H__ */