Module Name:    src
Committed By:   jym
Date:           Tue Feb 16 00:48:17 UTC 2010

Modified Files:
        src/sys/arch/x86/x86: pmap.c

Log Message:
- re-factor code in pmap_map_ptes() slightly, and make it PAE-ready for
native i386 by using PDP_SIZE

- introduce pmap_unmap_apdp(), used to clear the APDP entries in PD, and
replace the relevant code parts with this function.

Comes from Jeremy Morse's patch for i386 PAE support. Adjustments by me.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.103 src/sys/arch/x86/x86/pmap.c:1.104
--- src/sys/arch/x86/x86/pmap.c:1.103	Fri Feb 12 01:55:45 2010
+++ src/sys/arch/x86/x86/pmap.c	Tue Feb 16 00:48:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.103 2010/02/12 01:55:45 jym Exp $	*/
+/*	$NetBSD: pmap.c,v 1.104 2010/02/16 00:48:17 jym Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -149,7 +149,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.103 2010/02/12 01:55:45 jym Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.104 2010/02/16 00:48:17 jym Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -590,6 +590,7 @@
 					  struct pv_entry **);
 
 static void		 pmap_unmap_ptes(struct pmap *, struct pmap *);
+static void		 pmap_unmap_apdp(void);
 static bool		 pmap_get_physpage(vaddr_t, int, paddr_t *);
 static int		 pmap_pdes_invalid(vaddr_t, pd_entry_t * const *,
 					   pd_entry_t *);
@@ -746,6 +747,22 @@
 }
 
 /*
+ * Unmap the content of APDP PDEs
+ */
+static void
+pmap_unmap_apdp(void) {
+	int i;
+
+	for (i = 0; i < PDP_SIZE; i++) {
+		pmap_pte_set(APDP_PDE+i, 0);
+#if defined (XEN) && defined (PAE)
+		/* clear shadow entries too */
+		pmap_pte_set(APDP_PDE_SHADOW+i, 0);
+#endif
+	}
+}
+
+/*
  *	Add a reference to the specified pmap.
  */
 
@@ -833,9 +850,9 @@
 	/* need to load a new alternate pt space into curpmap? */
 	COUNT(apdp_pde_map);
 	opde = *APDP_PDE;
-#ifdef XEN
 	if (!pmap_valid_entry(opde) ||
 	    pmap_pte2pa(opde) != pmap_pdirpa(pmap, 0)) {
+#ifdef XEN
 		int i;
 		s = splvm();
 		/* Make recursive entry usable in user PGD */
@@ -858,17 +875,18 @@
 		if (pmap_valid_entry(opde))
 			pmap_apte_flush(ourpmap);
 		splx(s);
-	}
 #else /* XEN */
-	npde = pmap_pa2pte(pmap_pdirpa(pmap, 0)) | PG_RW | PG_V;
-	if (!pmap_valid_entry(opde) ||
-	    pmap_pte2pa(opde) != pmap_pdirpa(pmap, 0)) {
-		pmap_pte_set(APDP_PDE, npde);
+		int i;
+		for (i = 0; i < PDP_SIZE; i++) {
+			npde = pmap_pa2pte(
+			    pmap_pdirpa(pmap, i * NPDPG)) | PG_RW | PG_V;
+			pmap_pte_set(APDP_PDE+i, npde);
+		}
 		pmap_pte_flush();
 		if (pmap_valid_entry(opde))
 			pmap_apte_flush(ourpmap);
-	}
 #endif /* XEN */
+	}
 	*pmap2 = ourpmap;
 	*ptepp = APTE_BASE;
 	*pdeppp = alternate_pdes;
@@ -913,7 +931,7 @@
 		KASSERT(curcpu()->ci_pmap == pmap2);
 #endif
 #if defined(MULTIPROCESSOR)
-		pmap_pte_set(APDP_PDE, 0);
+		pmap_unmap_apdp();
 		pmap_pte_flush();
 		pmap_apte_flush(pmap2);
 #endif
@@ -2301,13 +2319,7 @@
 	 */
 	if (xpmap_ptom_masked(pmap_pdirpa(pmap, 0)) == (*APDP_PDE & PG_FRAME)) {
 		kpreempt_disable();
-		for (i = 0; i < PDP_SIZE; i++) {
-	        	pmap_pte_set(&APDP_PDE[i], 0);
-#ifdef PAE
-			/* clear shadow entry too */
-	    		pmap_pte_set(&APDP_PDE_SHADOW[i], 0);
-#endif
-		}
+		pmap_unmap_apdp();
 		pmap_pte_flush();
 	        pmap_apte_flush(pmap_kernel());
 	        kpreempt_enable();
@@ -2752,14 +2764,7 @@
 	 * been freed
 	 */
 	if (*APDP_PDE) {
-		int i;
-		for (i = 0; i < PDP_SIZE; i++) {
-			pmap_pte_set(&APDP_PDE[i], 0);
-#ifdef PAE
-			/* clear shadow entry too */
-			pmap_pte_set(&APDP_PDE_SHADOW[i], 0);
-#endif
-		}
+		pmap_unmap_apdp();
 	}
 	/* lldt() does pmap_pte_flush() */
 #else /* XEN */

Reply via email to