Module Name:    src
Committed By:   skrll
Date:           Wed May 10 22:19:31 UTC 2017

Modified Files:
        src/sys/arch/mips/mips: vm_machdep.c

Log Message:
Make cpu_uarea_{alloc,free} conditional on PMAP_{,UN}MAP_POOLPAGE and
use PMAP_{,UN}_POOLPAGE to ensure cache aliases are handled correctly
and for all the pages used.


To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.156 src/sys/arch/mips/mips/vm_machdep.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/mips/mips/vm_machdep.c
diff -u src/sys/arch/mips/mips/vm_machdep.c:1.155 src/sys/arch/mips/mips/vm_machdep.c:1.156
--- src/sys/arch/mips/mips/vm_machdep.c:1.155	Wed May 10 12:12:21 2017
+++ src/sys/arch/mips/mips/vm_machdep.c	Wed May 10 22:19:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.155 2017/05/10 12:12:21 skrll Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.156 2017/05/10 22:19:31 skrll Exp $	*/
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.155 2017/05/10 12:12:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.156 2017/05/10 22:19:31 skrll Exp $");
 
 #include "opt_ddb.h"
 #include "opt_coredump.h"
@@ -172,6 +172,8 @@ cpu_proc_fork(struct proc *p1, struct pr
 void *
 cpu_uarea_alloc(bool system)
 {
+#ifdef PMAP_MAP_POOLPAGE
+
 	struct pglist pglist;
 #ifdef _LP64
 	const paddr_t high = pmap_limits.avail_end;
@@ -212,15 +214,25 @@ cpu_uarea_alloc(bool system)
 	     pa, pmap_limits.avail_end);
 
 	/*
-	 * we need to return a direct-mapped VA for the pa.
+	 * we need to return a direct-mapped VA for the pa of the first (maybe
+	 * only) page and call PMAP_MAP_POOLPAGE on all pages in the list, so
+	 * that cache aliases are handled correctly.
 	 */
-#ifdef _LP64
-	const vaddr_t va = MIPS_PHYS_TO_XKPHYS_CACHED(pa);
-#else
-	const vaddr_t va = MIPS_PHYS_TO_KSEG0(pa);
-#endif
+
+	/* Initialise to unexpected result */
+	vaddr_t va = MIPS_KSEG2_START;
+	const struct vm_page *pglv;
+	TAILQ_FOREACH_REVERSE(pglv, &pglist, pglist, pageq.queue) {
+		const paddr_t palv = VM_PAGE_TO_PHYS(pglv);
+		va = PMAP_MAP_POOLPAGE(palv);
+	}
+
+	KASSERT(va != MIPS_KSEG2_START);
 
 	return (void *)va;
+#else
+	return NULL;
+#endif
 }
 
 /*
@@ -229,27 +241,28 @@ cpu_uarea_alloc(bool system)
 bool
 cpu_uarea_free(void *va)
 {
+#ifdef PMAP_UNMAP_POOLPAGE
 #ifdef _LP64
 	if (!MIPS_XKPHYS_P(va))
 		return false;
-	paddr_t pa = MIPS_XKPHYS_TO_PHYS(va);
 #else
 	if (!MIPS_KSEG0_P(va))
 		return false;
-	paddr_t pa = MIPS_KSEG0_TO_PHYS(va);
-#endif
-
-#ifdef MIPS3_PLUS
-	if (MIPS_CACHE_VIRTUAL_ALIAS)
-		mips_dcache_inv_range((intptr_t)va, USPACE);
 #endif
 
-	for (const paddr_t epa = pa + USPACE; pa < epa; pa += PAGE_SIZE) {
-		struct vm_page * const pg = PHYS_TO_VM_PAGE(pa);
+	vaddr_t valv = (vaddr_t)va;
+	for (size_t i = 0; i < UPAGES; i++, valv += NBPG) {
+		const paddr_t pa = PMAP_UNMAP_POOLPAGE(valv);
+	    	struct vm_page * const pg = PHYS_TO_VM_PAGE(pa);
 		KASSERT(pg != NULL);
 		uvm_pagefree(pg);
 	}
+
 	return true;
+#else
+	return false;
+#endif
+
 }
 
 void

Reply via email to