
Date: Thu, 2 Feb 2012 09:37:23 +0900
Subject: [PATCH 2/4] ppc: add page table size variables

Add PGD_TABLE_SIZE and PTE_TABLE_SIZE and fill pagetables with
corresponding order size.
Also make consideration of machdep->pgd, ptbl realloc().

Signed-off-by: Toshikazu Nakayama <nakayama.ts@ncos.nec.co.jp>
---
 defs.h |    4 ++++
 ppc.c  |   24 ++++++++++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/defs.h b/defs.h
index b64e886..68169b1 100755
--- a/defs.h
+++ b/defs.h
@@ -2606,10 +2606,14 @@ struct load_module {
 extern int PGDIR_SHIFT;
 extern int PTRS_PER_PTE;
 extern int PTRS_PER_PGD;
+extern int PGD_TABLE_SIZE;
+extern int PTE_TABLE_SIZE;
 /* ppc32's default page table format */
 #define PGDIR_SHIFT_DEFAULT	(22)
 #define PTRS_PER_PTE_DEFAULT	(1024)
 #define PTRS_PER_PGD_DEFAULT	(1024)
+#define PGD_TABLE_SIZE_DEFAULT	(1 << 12)
+#define PTE_TABLE_SIZE_DEFAULT	(1 << 12)
 
 #define _PAGE_PRESENT   0x001   /* software: pte contains a translation */
 #define _PAGE_USER      0x002   /* matches one of the PP bits */
diff --git a/ppc.c b/ppc.c
index 52d665d..f00092e 100755
--- a/ppc.c
+++ b/ppc.c
@@ -72,6 +72,8 @@ static struct line_number_hook ppc_line_number_hooks[];
 int PGDIR_SHIFT = PGDIR_SHIFT_DEFAULT;
 int PTRS_PER_PTE = PTRS_PER_PTE_DEFAULT;
 int PTRS_PER_PGD = PTRS_PER_PGD_DEFAULT;
+int PGD_TABLE_SIZE = PGD_TABLE_SIZE_DEFAULT;
+int PTE_TABLE_SIZE = PTE_TABLE_SIZE_DEFAULT;
 
 /*
  *  Do all necessary machine-specific setup here.  This is called twice,
@@ -94,10 +96,10 @@ ppc_init(int when)
                 machdep->pageoffset = machdep->pagesize - 1;
                 machdep->pagemask = ~((ulonglong)machdep->pageoffset);
 		machdep->stacksize = PPC_STACK_SIZE;
-                if ((machdep->pgd = (char *)malloc(PAGESIZE())) == NULL)
+		if ((machdep->pgd = (char *)malloc(PGD_TABLE_SIZE)) == NULL)
                         error(FATAL, "cannot malloc pgd space.");
                 machdep->pmd = machdep->pgd;
-                if ((machdep->ptbl = (char *)malloc(PAGESIZE())) == NULL)
+		if ((machdep->ptbl = (char *)malloc(PTE_TABLE_SIZE)) == NULL)
                         error(FATAL, "cannot malloc ptbl space.");
                 machdep->last_pgd_read = 0;
                 machdep->last_pmd_read = 0;
@@ -190,6 +192,16 @@ ppc_init(int when)
 		if ((THIS_KERNEL_VERSION >= LINUX(2,6,0)) &&
 			symbol_exists("hardirq_ctx"))
 			STRUCT_SIZE_INIT(irq_ctx, "hardirq_ctx");
+		/*
+		 * realloc page table buffers if size is changed.
+		 */
+		if ((PGD_TABLE_SIZE != PGD_TABLE_SIZE_DEFAULT) &&
+		    (machdep->pgd = (char *)realloc(PGD_TABLE_SIZE)) == NULL)
+			error(FATAL, "cannot realloc pgd space.");
+		machdep->pmd = machdep->pgd;
+		if ((PTE_TABLE_SIZE != PTE_TABLE_SIZE_DEFAULT) &&
+		    (machdep->ptbl = (char *)realloc(PTE_TABLE_SIZE)) == NULL)
+			error(FATAL, "cannot realloc ptbl space.");
 		break;
 
 	case POST_INIT:
@@ -322,7 +334,7 @@ ppc_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr, int verbose)
 
 	page_dir = pgd + (vaddr >> PGDIR_SHIFT);
 
-	FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE());
+	FILL_PGD(PAGEBASE(pgd), KVADDR, PGD_TABLE_SIZE);
 	pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir));
 
 	if (verbose)
@@ -344,7 +356,7 @@ ppc_uvtop(struct task_context *tc, ulong vaddr, physaddr_t *paddr, int verbose)
 		fprintf(fp, "  PMD: %lx => %lx\n",(ulong)page_middle, 
 			(ulong)page_table);
 	
-        FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE());
+        FILL_PTBL(PAGEBASE(page_table), KVADDR, PTE_TABLE_SIZE);
 	pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table));
 
         if (verbose) 
@@ -411,7 +423,7 @@ ppc_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
 
 	page_dir = pgd + (kvaddr >> PGDIR_SHIFT);
 
-        FILL_PGD(PAGEBASE(pgd), KVADDR, PAGESIZE());
+        FILL_PGD(PAGEBASE(pgd), KVADDR, PGD_TABLE_SIZE);
         pgd_pte = ULONG(machdep->pgd + PAGEOFFSET(page_dir));
 
 	if (verbose)
@@ -433,7 +445,7 @@ ppc_kvtop(struct task_context *tc, ulong kvaddr, physaddr_t *paddr, int verbose)
 		fprintf(fp, "  PMD: %lx => %lx\n", (ulong)page_middle, 
 			(ulong)page_table);
 
-        FILL_PTBL(PAGEBASE(page_table), KVADDR, PAGESIZE());
+        FILL_PTBL(PAGEBASE(page_table), KVADDR, PTE_TABLE_SIZE);
         pte = ULONG(machdep->ptbl + PAGEOFFSET(page_table));
 
 	if (verbose) 
-- 
1.7.8.163.g9859a


