
Date: Mon, 19 Mar 2012 18:20:27 +0900
Subject: [PATCH 5/5] ppc32: cleanup page table code

Use use macro accessor insted of machdep->machspec->xxx as possible.
Shrink page flags setup code by using macro.
Comparing sizeof(ulonglong) is only once, use PAE flag.

Signed-off-by: Toshikazu Nakayama <nakayama.ts@ncos.nec.co.jp>
---
 ppc.c |   95 ++++++++++++++++++++--------------------------------------------
 1 files changed, 30 insertions(+), 65 deletions(-)

diff --git a/ppc.c b/ppc.c
index d74957f..3e11664 100755
--- a/ppc.c
+++ b/ppc.c
@@ -86,27 +86,26 @@ probe_func_t probe_platforms[] = {
 	NULL
 };
 
+/* Don't forget page flags definitions for each platform */
+#define PLATFORM_PAGE_FLAGS_SETUP(PLT)		\
+	_PAGE_PRESENT = PLT##_PAGE_PRESENT;	\
+	_PAGE_USER = PLT##_PAGE_USER;		\
+	_PAGE_RW = PLT##_PAGE_RW;		\
+	_PAGE_GUARDED = PLT##_PAGE_GUARDED;	\
+	_PAGE_COHERENT = PLT##_PAGE_COHERENT;	\
+	_PAGE_NO_CACHE = PLT##_PAGE_NO_CACHE;	\
+	_PAGE_WRITETHRU = PLT##_PAGE_WRITETHRU;	\
+	_PAGE_DIRTY = PLT##_PAGE_DIRTY;		\
+	_PAGE_ACCESSED = PLT##_PAGE_ACCESSED;	\
+	_PAGE_HWWRITE = PLT##_PAGE_HWWRITE;	\
+	_PAGE_SHARED = PLT##_PAGE_SHARED;
 static int
 probe_ppc44x_platform(char *name)
 {
-	struct machine_specific *machspec = machdep->machspec;
-
 	/* 44x include ppc440* and ppc470 */
 	if (STRNEQ(name, "ppc440") || STREQ(name, "ppc470")) {
-
-		machspec->platform 		= strdup(name);
-
-		machspec->_page_present		= PPC44x_PAGE_PRESENT;
-		machspec->_page_user 		= PPC44x_PAGE_USER;
-		machspec->_page_rw 		= PPC44x_PAGE_RW;
-		machspec->_page_guarded		= PPC44x_PAGE_GUARDED;
-		machspec->_page_coherent 	= PPC44x_PAGE_COHERENT;
-		machspec->_page_no_cache 	= PPC44x_PAGE_NO_CACHE;
-		machspec->_page_writethru 	= PPC44x_PAGE_WRITETHRU;
-		machspec->_page_dirty 		= PPC44x_PAGE_DIRTY;
-		machspec->_page_accessed 	= PPC44x_PAGE_ACCESSED;
-		machspec->_page_hwwrite 	= PPC44x_PAGE_HWWRITE;
-		machspec->_page_shared 		= PPC44x_PAGE_SHARED;
+		PPC_PLATFORM = strdup(name);
+		PLATFORM_PAGE_FLAGS_SETUP(PPC44x);
 
 		return TRUE;
 	}
@@ -117,35 +116,13 @@ probe_ppc44x_platform(char *name)
 static int
 probe_ppce500_platform(char *name)
 {
-	struct machine_specific *machspec = machdep->machspec;
-
 	if (STRNEQ(name, "ppce500mc")) {
-		machspec->platform = strdup(name);
+		PPC_PLATFORM = strdup(name);
 		if (machdep->flags & PAE) {
-			machspec->pte_rpn_shift = BOOKE3E_PTE_RPN_SHIFT;
-
-			machspec->_page_present = BOOK3E_PAGE_PRESENT;
-			machspec->_page_user = BOOK3E_PAGE_USER;
-			machspec->_page_rw = BOOK3E_PAGE_RW;
-			machspec->_page_dirty = BOOK3E_PAGE_DIRTY;
-			machspec->_page_accessed = BOOK3E_PAGE_ACCESSED;
-			machspec->_page_guarded = BOOK3E_PAGE_GUARDED;
-			machspec->_page_coherent = BOOK3E_PAGE_COHERENT;
-			machspec->_page_no_cache = BOOK3E_PAGE_NO_CACHE;
-			machspec->_page_writethru = BOOK3E_PAGE_WRITETHRU;
-		} else {
-			machspec->_page_present = FSL_BOOKE_PAGE_PRESENT;
-			machspec->_page_user = FSL_BOOKE_PAGE_USER;
-			machspec->_page_rw = FSL_BOOKE_PAGE_RW;
-			machspec->_page_dirty = FSL_BOOKE_PAGE_DIRTY;
-			machspec->_page_accessed = FSL_BOOKE_PAGE_ACCESSED;
-			machspec->_page_guarded = FSL_BOOKE_PAGE_GUARDED;
-			machspec->_page_coherent = FSL_BOOKE_PAGE_COHERENT;
-			machspec->_page_no_cache = FSL_BOOKE_PAGE_NO_CACHE;
-			machspec->_page_writethru = FSL_BOOKE_PAGE_WRITETHRU;
-		}
-		machspec->_page_hwwrite = 0;
-		machspec->_page_shared = 0;
+			PTE_RPN_SHIFT = BOOKE3E_PTE_RPN_SHIFT;
+			PLATFORM_PAGE_FLAGS_SETUP(BOOK3E);
+		} else
+			PLATFORM_PAGE_FLAGS_SETUP(FSL_BOOKE);
 
 		return TRUE;
 	}
@@ -155,32 +132,20 @@ probe_ppce500_platform(char *name)
 static int
 probe_default_platform(char *name)
 {
-	struct machine_specific *machspec = machdep->machspec;
-
 	if (machdep->flags & PAE) {
 		error(INFO, "platform \"%s\" 64bit PTE fall through\n", name);
 		error(INFO, "vmalloc translation could not work!\n");
 	}
 
 	/* Use the default definitions */
-	machspec->platform = strdup(name);
-
-	machspec->_page_present		= DEFAULT_PAGE_PRESENT;
-	machspec->_page_user 		= DEFAULT_PAGE_USER;
-	machspec->_page_rw 		= DEFAULT_PAGE_RW;
-	machspec->_page_guarded 	= DEFAULT_PAGE_GUARDED;
-	machspec->_page_coherent 	= DEFAULT_PAGE_COHERENT;
-	machspec->_page_no_cache 	= DEFAULT_PAGE_NO_CACHE;
-	machspec->_page_writethru 	= DEFAULT_PAGE_WRITETHRU;
-	machspec->_page_dirty 		= DEFAULT_PAGE_DIRTY;
-	machspec->_page_accessed 	= DEFAULT_PAGE_ACCESSED;
-	machspec->_page_hwwrite 	= DEFAULT_PAGE_HWWRITE;
-	machspec->_page_shared 		= DEFAULT_PAGE_SHARED;
-	
+	PPC_PLATFORM = strdup(name);
+	PLATFORM_PAGE_FLAGS_SETUP(DEFAULT);
 
 	return TRUE;
 }
 
+#undef PLATFORM_PAGE_FLAGS_SETUP
+
 /*
  * Find the platform of the crashing system and set the
  * base_platform accordingly.
@@ -273,17 +238,17 @@ ppc_init(int when)
 
 	case POST_GDB:
 		/* gdb interface got available, resolve PTE right now. */
-		machdep->machspec->pte_size = DATATYPE_SIZE(&pte);
-		if (machdep->machspec->pte_size < 0)
+		PTE_SIZE = DATATYPE_SIZE(&pte);
+		if (PTE_SIZE < 0)
 			error(FATAL,
 			      "gdb could not handle \"pte_t\" size request\n");
 		/* Check if we have 64bit PTE on 32bit system */
-		if (machdep->machspec->pte_size == sizeof(ulonglong))
+		if (PTE_SIZE == sizeof(ulonglong))
 			machdep->flags |= PAE;
 		/* Find the platform where we crashed */
 		ppc_probe_base_platform();
-		if (!machdep->machspec->pte_rpn_shift)
-			machdep->machspec->pte_rpn_shift = PAGE_SHIFT;
+		if (!PTE_RPN_SHIFT)
+			PTE_RPN_SHIFT = PAGE_SHIFT;
 
 		machdep->vmalloc_start = ppc_vmalloc_start;
 		MEMBER_OFFSET_INIT(thread_struct_pg_tables, 
@@ -475,7 +440,7 @@ ppc_pgd_vtop(ulong *pgd, ulong vaddr, physaddr_t *paddr, int verbose)
 			(ulong)page_table);
 
         FILL_PTBL(PAGEBASE((ulong)page_table), KVADDR, PAGESIZE());
-	if (PTE_SIZE == sizeof(ulonglong))
+	if (machdep->flags & PAE)
 		pte = ULONGLONG(machdep->ptbl + PAGEOFFSET((ulong)page_table));
 
 	else	/* Defaults to ulong */
-- 
1.7.0.4


