CVS commit: src/sys/common/pmap/tlb

2012-07-05 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jul  5 16:55:11 UTC 2012

Modified Files:
src/sys/common/pmap/tlb: pmap.c pmap.h pmap_segtab.c

Log Message:
Add 3-level page table support (from MIPS).  Rename a few routines.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/common/pmap/tlb/pmap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/common/pmap/tlb/pmap.h
cvs rdiff -u -r1.5 -r1.6 src/sys/common/pmap/tlb/pmap_segtab.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/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.14 src/sys/common/pmap/tlb/pmap.c:1.15
--- src/sys/common/pmap/tlb/pmap.c:1.14	Wed Jul  4 11:39:42 2012
+++ src/sys/common/pmap/tlb/pmap.c	Thu Jul  5 16:55:11 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.14 2012/07/04 11:39:42 matt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.15 2012/07/05 16:55:11 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.14 2012/07/04 11:39:42 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.15 2012/07/05 16:55:11 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -450,8 +450,8 @@ pmap_steal_memory(vsize_t size, vaddr_t 
 void
 pmap_init(void)
 {
-UVMHIST_INIT_STATIC(pmapexechist, pmapexechistbuf);
-UVMHIST_INIT_STATIC(pmaphist, pmaphistbuf);
+	UVMHIST_INIT_STATIC(pmapexechist, pmapexechistbuf);
+	UVMHIST_INIT_STATIC(pmaphist, pmaphistbuf);
 
 	UVMHIST_FUNC(__func__); UVMHIST_CALLED(pmaphist);
 
@@ -504,7 +504,7 @@ pmap_create(void)
 	pmap-pm_minaddr = VM_MIN_ADDRESS;
 	pmap-pm_maxaddr = VM_MAXUSER_ADDRESS;
 
-	pmap_segtab_alloc(pmap);
+	pmap_segtab_init(pmap);
 
 	UVMHIST_LOG(pmaphist, - pmap %p, pmap,0,0,0);
 	return pmap;
@@ -530,7 +530,7 @@ pmap_destroy(pmap_t pmap)
 	PMAP_COUNT(destroy);
 	kpreempt_disable();
 	pmap_tlb_asid_release_all(pmap);
-	pmap_segtab_free(pmap);
+	pmap_segtab_destroy(pmap);
 
 	pool_put(pmap_pmap_pool, pmap);
 	kpreempt_enable();
@@ -1482,7 +1482,7 @@ pmap_enter_pv(pmap_t pmap, vaddr_t va, s
 	pmap, va, pg, VM_PAGE_TO_PHYS(pg));
 	UVMHIST_LOG(pmaphist, nptep=%p (%#x)), npte, *npte, 0, 0);
 
-KASSERT(kpreempt_disabled());
+	KASSERT(kpreempt_disabled());
 	KASSERT(pmap != pmap_kernel() || !pmap_md_direct_mapped_vaddr_p(va));
 
 	apv = NULL;

Index: src/sys/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.13 src/sys/common/pmap/tlb/pmap.h:1.14
--- src/sys/common/pmap/tlb/pmap.h:1.13	Wed Jul  4 11:39:42 2012
+++ src/sys/common/pmap/tlb/pmap.h	Thu Jul  5 16:55:11 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.13 2012/07/04 11:39:42 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.14 2012/07/05 16:55:11 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -107,8 +107,8 @@ pt_entry_t *pmap_pte_reserve(struct pmap
 void pmap_pte_process(struct pmap *, vaddr_t, vaddr_t, pte_callback_t,
 	uintptr_t);
 void pmap_segtab_activate(struct pmap *, struct lwp *);
-void pmap_segtab_alloc(struct pmap *);
-void pmap_segtab_free(struct pmap *);
+void pmap_segtab_init(struct pmap *);
+void pmap_segtab_destroy(struct pmap *);
 extern kmutex_t pmap_segtab_lock;
 #endif /* _KERNEL */
 

Index: src/sys/common/pmap/tlb/pmap_segtab.c
diff -u src/sys/common/pmap/tlb/pmap_segtab.c:1.5 src/sys/common/pmap/tlb/pmap_segtab.c:1.6
--- src/sys/common/pmap/tlb/pmap_segtab.c:1.5	Wed Jul  4 11:39:42 2012
+++ src/sys/common/pmap/tlb/pmap_segtab.c	Thu Jul  5 16:55:11 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.5 2012/07/04 11:39:42 matt Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.6 2012/07/05 16:55:11 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.5 2012/07/04 11:39:42 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.6 2012/07/05 16:55:11 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -134,7 +134,12 @@ pmap_segmap(struct pmap *pmap, vaddr_t v
 {
 	struct pmap_segtab *stp = pmap-pm_segtab;
 	KASSERT(pmap != pmap_kernel() || !pmap_md_direct_mapped_vaddr_p(va));
-	return stp-seg_tab[va  SEGSHIFT];
+#ifdef _LP64
+	stp = stp-seg_seg[(va  XSEGSHIFT)  (NSEGPG - 1)];
+	if (stp == NULL)
+		return NULL;
+#endif
+	return stp-seg_tab[(va  SEGSHIFT)  (PMAP_SEGTABSIZE - 1)];
 }
 
 pt_entry_t *
@@ -147,6 +152,55 @@ pmap_pte_lookup(pmap_t pmap, vaddr_t va)
 	return pte + ((va  PGSHIFT)  (NPTEPG - 1));
 }
 
+static void
+pmap_segtab_free(struct pmap_segtab *stp)
+{
+	/*
+	 * Insert the the segtab into the segtab freelist.
+	 */
+	mutex_spin_enter(pmap_segtab_lock);
+	stp-seg_tab[0] = (void *) pmap_segtab_info.free_segtab;
+	pmap_segtab_info.free_segtab = stp;
+	SEGTAB_ADD(nput, 1);
+	mutex_spin_exit(pmap_segtab_lock);
+}
+
+static void
+pmap_segtab_release(struct pmap_segtab *stp, u_int level)
+{
+
+	for (size_t i = 0; i  PMAP_SEGTABSIZE; i++) {
+		paddr_t pa;
+#ifdef 

CVS commit: src/sys/common/pmap/tlb

2012-07-05 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jul  5 17:24:54 UTC 2012

Modified Files:
src/sys/common/pmap/tlb: pmap.h pmap_segtab.c

Log Message:
Change seg_tab to seg_ptr and make it a void * from a pt_entry_t * since it
also needs to point to struct pmap_segtab * when used in a 3-level page table.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/common/pmap/tlb/pmap.h
cvs rdiff -u -r1.6 -r1.7 src/sys/common/pmap/tlb/pmap_segtab.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/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.14 src/sys/common/pmap/tlb/pmap.h:1.15
--- src/sys/common/pmap/tlb/pmap.h:1.14	Thu Jul  5 16:55:11 2012
+++ src/sys/common/pmap/tlb/pmap.h	Thu Jul  5 17:24:54 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.14 2012/07/05 16:55:11 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.15 2012/07/05 17:24:54 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -95,7 +95,7 @@ UVMHIST_DECL(pmaphist);
  * Each seg_tab point an array of pt_entry [NPTEPG]
  */
 struct pmap_segtab {
-	pt_entry_t	*seg_tab[PMAP_SEGTABSIZE];
+	void	*seg_ptr[PMAP_SEGTABSIZE];
 };
 
 #ifdef _KERNEL

Index: src/sys/common/pmap/tlb/pmap_segtab.c
diff -u src/sys/common/pmap/tlb/pmap_segtab.c:1.6 src/sys/common/pmap/tlb/pmap_segtab.c:1.7
--- src/sys/common/pmap/tlb/pmap_segtab.c:1.6	Thu Jul  5 16:55:11 2012
+++ src/sys/common/pmap/tlb/pmap_segtab.c	Thu Jul  5 17:24:54 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.6 2012/07/05 16:55:11 matt Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.7 2012/07/05 17:24:54 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.6 2012/07/05 16:55:11 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.7 2012/07/05 17:24:54 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -135,11 +135,11 @@ pmap_segmap(struct pmap *pmap, vaddr_t v
 	struct pmap_segtab *stp = pmap-pm_segtab;
 	KASSERT(pmap != pmap_kernel() || !pmap_md_direct_mapped_vaddr_p(va));
 #ifdef _LP64
-	stp = stp-seg_seg[(va  XSEGSHIFT)  (NSEGPG - 1)];
+	stp = stp-seg_ptr[(va  XSEGSHIFT)  (NSEGPG - 1)];
 	if (stp == NULL)
 		return NULL;
 #endif
-	return stp-seg_tab[(va  SEGSHIFT)  (PMAP_SEGTABSIZE - 1)];
+	return stp-seg_ptr[(va  SEGSHIFT)  (PMAP_SEGTABSIZE - 1)];
 }
 
 pt_entry_t *
@@ -159,7 +159,7 @@ pmap_segtab_free(struct pmap_segtab *stp
 	 * Insert the the segtab into the segtab freelist.
 	 */
 	mutex_spin_enter(pmap_segtab_lock);
-	stp-seg_tab[0] = (void *) pmap_segtab_info.free_segtab;
+	stp-seg_ptr[0] = pmap_segtab_info.free_segtab;
 	pmap_segtab_info.free_segtab = stp;
 	SEGTAB_ADD(nput, 1);
 	mutex_spin_exit(pmap_segtab_lock);
@@ -173,16 +173,16 @@ pmap_segtab_release(struct pmap_segtab *
 		paddr_t pa;
 #ifdef _LP64
 		if (level  0) {
-			if (stp-seg_seg[i] != NULL) {
-pmap_segtab_release(stp-seg_seg[i], level - 1);
-stp-seg_seg[i] = NULL;
+			if (stp-seg_ptr[i] != NULL) {
+pmap_segtab_release(stp-seg_ptr[i], level - 1);
+stp-seg_ptr[i] = NULL;
 			}
 			continue;
 		}
 #endif
 
 		/* get pointer to segment map */
-		pt_entry_t *pte = stp-seg_tab[i];
+		pt_entry_t *pte = stp-seg_ptr[i];
 		if (pte == NULL)
 			continue;
 #ifdef PARANOIADIAG
@@ -195,7 +195,7 @@ pmap_segtab_release(struct pmap_segtab *
 		pa = POOL_VTOPHYS(pte);
 		uvm_pagefree(PHYS_TO_VM_PAGE(pa));
 
-		stp-seg_tab[i] = NULL;
+		stp-seg_ptr[i] = NULL;
 	}
 
 	pmap_segtab_free(stp);
@@ -221,9 +221,8 @@ pmap_segtab_alloc(void)
  again:
 	mutex_spin_enter(pmap_segtab_lock);
 	if (__predict_true((stp = pmap_segtab_info.free_segtab) != NULL)) {
-		pmap_segtab_info.free_segtab =
-		(struct pmap_segtab *)stp-seg_tab[0];
-		stp-seg_tab[0] = NULL;
+		pmap_segtab_info.free_segtab = stp-seg_ptr[0];
+		stp-seg_ptr[0] = NULL;
 		SEGTAB_ADD(nget, 1);
 	}
 	mutex_spin_exit(pmap_segtab_lock);
@@ -248,13 +247,13 @@ pmap_segtab_alloc(void)
 			 * link all the segtabs in this page together
 			 */
 			for (size_t i = 1; i  n - 1; i++) {
-stp[i].seg_tab[0] = (void *)stp[i+1];
+stp[i].seg_ptr[0] = (void *)stp[i+1];
 			}
 			/*
 			 * Now link the new segtabs into the free segtab list.
 			 */
 			mutex_spin_enter(pmap_segtab_lock);
-			stp[n-1].seg_tab[0] = (void *)pmap_segtab_info.free_segtab;
+			stp[n-1].seg_ptr[0] = pmap_segtab_info.free_segtab;
 			pmap_segtab_info.free_segtab = stp + 1;
 			SEGTAB_ADD(nput, n - 1);
 			mutex_spin_exit(pmap_segtab_lock);
@@ -263,8 +262,8 @@ pmap_segtab_alloc(void)
 
 #ifdef PARANOIADIAG
 	for (i = 0; i  PMAP_SEGTABSIZE; i++) {
-		if (stp-seg_tab[i] != 0)
-			panic(pmap_create: pm_segtab.seg_tab[%zu] != 0);
+		if (stp-seg_ptr[i] != 0)
+			panic(pmap_create: pm_segtab.seg_ptr[%zu] != 0);
 	}
 #endif
 	return stp;
@@ -313,7 +312,7 @@ pmap_segtab_activate(struct pmap *pm, st
 		} else {
 			l-l_cpu-ci_pmap_user_segtab = pm-pm_segtab;
 #ifdef 

CVS commit: src/sys/common/pmap/tlb

2012-07-04 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Jul  4 11:39:42 UTC 2012

Modified Files:
src/sys/common/pmap/tlb: pmap.c pmap.h pmap_segtab.c

Log Message:
The lockless list can lead to corruption.  Instead use a spinlock to control
access to the head of the free segtab list.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/common/pmap/tlb/pmap.c
cvs rdiff -u -r1.12 -r1.13 src/sys/common/pmap/tlb/pmap.h
cvs rdiff -u -r1.4 -r1.5 src/sys/common/pmap/tlb/pmap_segtab.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/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.13 src/sys/common/pmap/tlb/pmap.c:1.14
--- src/sys/common/pmap/tlb/pmap.c:1.13	Thu May 17 16:20:19 2012
+++ src/sys/common/pmap/tlb/pmap.c	Wed Jul  4 11:39:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.13 2012/05/17 16:20:19 matt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.14 2012/07/04 11:39:42 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.13 2012/05/17 16:20:19 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.14 2012/07/04 11:39:42 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -456,6 +456,11 @@ pmap_init(void)
 	UVMHIST_FUNC(__func__); UVMHIST_CALLED(pmaphist);
 
 	/*
+	 * Initialize the segtab lock.
+	 */
+	mutex_init(pmap_segtab_lock, MUTEX_DEFAULT, IPL_HIGH);
+
+	/*
 	 * Set a low water mark on the pv_entry pool, so that we are
 	 * more likely to have these around even in extreme memory
 	 * starvation.

Index: src/sys/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.12 src/sys/common/pmap/tlb/pmap.h:1.13
--- src/sys/common/pmap/tlb/pmap.h:1.12	Thu May 17 16:20:19 2012
+++ src/sys/common/pmap/tlb/pmap.h	Wed Jul  4 11:39:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.12 2012/05/17 16:20:19 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.13 2012/07/04 11:39:42 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -109,6 +109,7 @@ void pmap_pte_process(struct pmap *, vad
 void pmap_segtab_activate(struct pmap *, struct lwp *);
 void pmap_segtab_alloc(struct pmap *);
 void pmap_segtab_free(struct pmap *);
+extern kmutex_t pmap_segtab_lock;
 #endif /* _KERNEL */
 
 /*

Index: src/sys/common/pmap/tlb/pmap_segtab.c
diff -u src/sys/common/pmap/tlb/pmap_segtab.c:1.4 src/sys/common/pmap/tlb/pmap_segtab.c:1.5
--- src/sys/common/pmap/tlb/pmap_segtab.c:1.4	Thu Jun 23 08:11:56 2011
+++ src/sys/common/pmap/tlb/pmap_segtab.c	Wed Jul  4 11:39:42 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.4 2011/06/23 08:11:56 matt Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.5 2012/07/04 11:39:42 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.4 2011/06/23 08:11:56 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.5 2012/07/04 11:39:42 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -110,7 +110,7 @@ __KERNEL_RCSID(0, $NetBSD: pmap_segtab.
 CTASSERT(NBPG = sizeof(struct pmap_segtab));
 
 struct pmap_segtab_info {
-	struct pmap_segtab * volatile free_segtab;		/* free list kept locally */
+	struct pmap_segtab *free_segtab;	/* free list kept locally */
 #ifdef DEBUG
 	uint32_t nget_segtab;
 	uint32_t nput_segtab;
@@ -121,6 +121,8 @@ struct pmap_segtab_info {
 #endif
 } pmap_segtab_info;
 
+kmutex_t pmap_segtab_lock __cacheline_aligned;
+
 static inline struct vm_page *
 pmap_pte_pagealloc(void)
 {
@@ -162,20 +164,16 @@ pmap_segtab_alloc(pmap_t pmap)
 {
 	struct pmap_segtab *stp;
  again:
-	stp = NULL;
-	while (__predict_true(pmap_segtab_info.free_segtab != NULL)) {
-		struct pmap_segtab *next_stp;
-		stp = pmap_segtab_info.free_segtab;
-		next_stp = (struct pmap_segtab *)stp-seg_tab[0];
-		if (stp == atomic_cas_ptr(pmap_segtab_info.free_segtab, stp, next_stp)) {
-			SEGTAB_ADD(nget, 1);
-			break;
-		}
+	mutex_spin_enter(pmap_segtab_lock);
+	if (__predict_true((stp = pmap_segtab_info.free_segtab) != NULL)) {
+		pmap_segtab_info.free_segtab =
+		(struct pmap_segtab *)stp-seg_tab[0];
+		stp-seg_tab[0] = NULL;
+		SEGTAB_ADD(nget, 1);
 	}
+	mutex_spin_exit(pmap_segtab_lock);
 	
-	if (__predict_true(stp != NULL)) {
-		stp-seg_tab[0] = NULL;
-	} else {
+	if (__predict_false(stp == NULL)) {
 		struct vm_page * const stp_pg = pmap_pte_pagealloc();
 
 		if (__predict_false(stp_pg == NULL)) {
@@ -200,13 +198,11 @@ pmap_segtab_alloc(pmap_t pmap)
 			/*
 			 * Now link the new segtabs into the free segtab list.
 			 */
-			for (;;) {
-void *tmp = pmap_segtab_info.free_segtab;
-stp[n-1].seg_tab[0] = tmp;
-if (tmp == atomic_cas_ptr(pmap_segtab_info.free_segtab, tmp, stp+1))
-	break;
-			}
+			mutex_spin_enter(pmap_segtab_lock);
+			stp[n-1].seg_tab[0] = (void *)pmap_segtab_info.free_segtab;
+			pmap_segtab_info.free_segtab = stp + 1;
 			SEGTAB_ADD(nput, n - 

CVS commit: src/sys/common/pmap/tlb

2012-05-17 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu May 17 16:20:19 UTC 2012

Modified Files:
src/sys/common/pmap/tlb: pmap.c pmap.h

Log Message:
Add support for PMAP_GROWKERNEL


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/common/pmap/tlb/pmap.c
cvs rdiff -u -r1.11 -r1.12 src/sys/common/pmap/tlb/pmap.h

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

Modified files:

Index: src/sys/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.12 src/sys/common/pmap/tlb/pmap.c:1.13
--- src/sys/common/pmap/tlb/pmap.c:1.12	Wed Jan 18 07:17:09 2012
+++ src/sys/common/pmap/tlb/pmap.c	Thu May 17 16:20:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.12 2012/01/18 07:17:09 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.13 2012/05/17 16:20:19 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.12 2012/01/18 07:17:09 skrll Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.13 2012/05/17 16:20:19 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -220,15 +220,6 @@ struct pmap * const kernel_pmap_ptr = k
 
 struct pmap_limits pmap_limits;
 
-#ifdef PMAP_POOLPAGE_DEBUG
-struct poolpage_info {
-	vaddr_t base;
-	vaddr_t size;
-	vaddr_t hint;
-	pt_entry_t *sysmap;
-} poolpage;
-#endif
-
 #ifdef UVMHIST
 static struct kern_history_ent pmapexechistbuf[1];
 static struct kern_history_ent pmaphistbuf[1];
@@ -348,8 +339,34 @@ void
 pmap_virtual_space(vaddr_t *vstartp, vaddr_t *vendp)
 {
 
-	*vstartp = VM_MIN_KERNEL_ADDRESS;	/* kernel is in K0SEG */
-	*vendp = trunc_page(pmap_limits.virtual_end);	/* XXX need pmap_growkernel() */
+	*vstartp = VM_MIN_KERNEL_ADDRESS;
+	*vendp = VM_MAX_KERNEL_ADDRESS;
+}
+
+vaddr_t
+pmap_growkernel(vaddr_t maxkvaddr)
+{
+	vaddr_t virtual_end = pmap_limits.virtual_end; 
+	maxkvaddr = pmap_round_seg(maxkvaddr) - 1;
+
+	/*
+	 * Reserve PTEs for the new KVA space.
+	 */
+	for (; virtual_end  maxkvaddr; virtual_end += NBSEG) {
+		pmap_pte_reserve(pmap_kernel(), virtual_end, 0);
+	}
+
+	/*
+	 * Don't exceed VM_MAX_KERNEL_ADDRESS!
+	 */
+	if (virtual_end == 0 || virtual_end  VM_MAX_KERNEL_ADDRESS)
+		virtual_end = VM_MAX_KERNEL_ADDRESS;
+
+	/*
+	 * Update new end.
+	 */
+	pmap_limits.virtual_end = virtual_end;
+	return virtual_end;
 }
 
 /*
@@ -414,7 +431,7 @@ pmap_steal_memory(vsize_t size, vaddr_t 
 sizeof(*seg) * (vm_nphysseg - bank));
 		}
 
-		va = pmap_md_direct_map_paddr(pa);
+		va = pmap_md_map_poolpage(pa, size);
 		memset((void *)va, 0, size);
 		return va;
 	}
@@ -1828,7 +1845,7 @@ pmap_map_poolpage(paddr_t pa)
 	struct vm_page_md * const mdpg = VM_PAGE_TO_MD(pg);
 	pmap_page_set_attributes(mdpg, VM_PAGEMD_POOLPAGE);
 
-	const vaddr_t va = pmap_md_direct_map_paddr(pa);
+	const vaddr_t va = pmap_md_map_poolpage(pa, NBPG);
 	pmap_md_vca_add(pg, va, NULL);
 	return va;
 }
@@ -1844,6 +1861,7 @@ pmap_unmap_poolpage(vaddr_t va)
 	KASSERT(pg);
 	struct vm_page_md * const mdpg = VM_PAGE_TO_MD(pg);
 	pmap_page_clear_attributes(mdpg, VM_PAGEMD_POOLPAGE);
+	pmap_md_unmap_poolpage(va, NBPG);
 	pmap_md_vca_remove(pg, va);
 
 	return pa;

Index: src/sys/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.11 src/sys/common/pmap/tlb/pmap.h:1.12
--- src/sys/common/pmap/tlb/pmap.h:1.11	Thu Oct 13 19:50:39 2011
+++ src/sys/common/pmap/tlb/pmap.h	Thu May 17 16:20:19 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.11 2011/10/13 19:50:39 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.12 2012/05/17 16:20:19 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -253,6 +253,7 @@ void	pmap_tlb_asid_check(void);
 uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
 
 #define	PMAP_STEAL_MEMORY	/* enable pmap_steal_memory() */
+#define	PMAP_GROWKERNEL		/* enable pmap_growkernel() */
 
 /*
  * Alternate mapping hooks for pool pages.  Avoids thrashing the TLB.



CVS commit: src/sys/common/pmap/tlb

2012-01-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Wed Jan 18 07:17:09 UTC 2012

Modified Files:
src/sys/common/pmap/tlb: pmap.c

Log Message:
thinko in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/common/pmap/tlb/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/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.11 src/sys/common/pmap/tlb/pmap.c:1.12
--- src/sys/common/pmap/tlb/pmap.c:1.11	Fri Jan  6 09:41:17 2012
+++ src/sys/common/pmap/tlb/pmap.c	Wed Jan 18 07:17:09 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.11 2012/01/06 09:41:17 skrll Exp $	*/
+/*	$NetBSD: pmap.c,v 1.12 2012/01/18 07:17:09 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.11 2012/01/06 09:41:17 skrll Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.12 2012/01/18 07:17:09 skrll Exp $);
 
 /*
  *	Manages physical address maps.
@@ -717,7 +717,7 @@ pmap_page_protect(struct vm_page *pg, vm
 		(void)VM_PAGEMD_PVLIST_LOCK(mdpg, false);
 		pv = mdpg-mdpg_first;
 		/*
-		 * Loop over all current mappings setting/clearing as apropos.
+		 * Loop over all current mappings setting/clearing as appropriate.
 		 */
 		if (pv-pv_pmap != NULL) {
 			while (pv != NULL) {



CVS commit: src/sys/common/pmap/tlb

2012-01-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan  6 09:41:18 UTC 2012

Modified Files:
src/sys/common/pmap/tlb: pmap.c

Log Message:
Log the icache sync only if it's done.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/common/pmap/tlb/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/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.10 src/sys/common/pmap/tlb/pmap.c:1.11
--- src/sys/common/pmap/tlb/pmap.c:1.10	Tue Sep 27 01:02:37 2011
+++ src/sys/common/pmap/tlb/pmap.c	Fri Jan  6 09:41:17 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.10 2011/09/27 01:02:37 jym Exp $	*/
+/*	$NetBSD: pmap.c,v 1.11 2012/01/06 09:41:17 skrll Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.10 2011/09/27 01:02:37 jym Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.11 2012/01/06 09:41:17 skrll Exp $);
 
 /*
  *	Manages physical address maps.
@@ -792,11 +792,11 @@ pmap_pte_protect(pmap_t pmap, vaddr_t sv
 			pmap_md_vca_clean(pg, sva, PMAP_WBINV);
 			if (VM_PAGEMD_EXECPAGE_P(mdpg)) {
 KASSERT(mdpg-mdpg_first.pv_pmap != NULL);
-UVMHIST_LOG(pmapexechist,
-pg %p (pa %#PRIxPADDR): %s,
-pg, VM_PAGE_TO_PHYS(pg),
-syncicached performed, 0);
 if (pte_cached_p(pt_entry)) {
+	UVMHIST_LOG(pmapexechist,
+	pg %p (pa %#PRIxPADDR): %s,
+	pg, VM_PAGE_TO_PHYS(pg),
+	syncicached performed, 0);
 	pmap_page_syncicache(pg);
 	PMAP_COUNT(exec_synced_protect);
 }



CVS commit: src/sys/common/pmap/tlb

2011-10-13 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Oct 13 19:50:39 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap.h

Log Message:
Move pai to end of struct pmap.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/common/pmap/tlb/pmap.h

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

Modified files:

Index: src/sys/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.10 src/sys/common/pmap/tlb/pmap.h:1.11
--- src/sys/common/pmap/tlb/pmap.h:1.10	Thu Jun 23 07:58:19 2011
+++ src/sys/common/pmap/tlb/pmap.h	Thu Oct 13 19:50:39 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.10 2011/06/23 07:58:19 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.11 2011/10/13 19:50:39 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -141,9 +141,9 @@ struct pmap {
 	u_int			pm_flags;
 #define	PMAP_DEFERRED_ACTIVATE	0x0001
 	struct pmap_statistics	pm_stats;	/* pmap statistics */
-	struct pmap_asid_info	pm_pai[1];
 	vaddr_t			pm_minaddr;
 	vaddr_t			pm_maxaddr;
+	struct pmap_asid_info	pm_pai[1];
 };
 
 enum tlb_invalidate_op {



CVS commit: src/sys/common/pmap/tlb

2011-06-28 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Jun 29 05:53:45 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap.c pmap_tlb.c

Log Message:
Multiprocessing fixes.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/common/pmap/tlb/pmap.c
cvs rdiff -u -r1.9 -r1.10 src/sys/common/pmap/tlb/pmap_tlb.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/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.8 src/sys/common/pmap/tlb/pmap.c:1.9
--- src/sys/common/pmap/tlb/pmap.c:1.8	Thu Jun 23 20:46:15 2011
+++ src/sys/common/pmap/tlb/pmap.c	Wed Jun 29 05:53:44 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.8 2011/06/23 20:46:15 matt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.9 2011/06/29 05:53:44 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.8 2011/06/23 20:46:15 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.9 2011/06/29 05:53:44 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -324,7 +324,7 @@
 		for (; pv != NULL; pv = pv-pv_next) {
 #ifdef MULTIPROCESSOR
 			CPUSET_MERGE(onproc, pv-pv_pmap-pm_onproc);
-			if (CPUSET_EQUAL_P(onproc, cpus_running)) {
+			if (CPUSET_EQUAL_P(onproc, cpuset_info.cpus_running)) {
 break;
 			}
 #else
@@ -585,7 +585,7 @@
 	PMAP_COUNT(update);
 
 	kpreempt_disable();
-#ifdef MULTIPROCESSOR
+#if defined(MULTIPROCESSOR)  defined(PMAP_NEED_TLB_SHOOTDOWN)
 	u_int pending = atomic_swap_uint(pmap-pm_shootdown_pending, 0);
 	if (pending  pmap_tlb_shootdown_bystanders(pmap))
 		PMAP_COUNT(shootdown_ipis);

Index: src/sys/common/pmap/tlb/pmap_tlb.c
diff -u src/sys/common/pmap/tlb/pmap_tlb.c:1.9 src/sys/common/pmap/tlb/pmap_tlb.c:1.10
--- src/sys/common/pmap/tlb/pmap_tlb.c:1.9	Thu Jun 23 08:11:56 2011
+++ src/sys/common/pmap/tlb/pmap_tlb.c	Wed Jun 29 05:53:44 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.9 2011/06/23 08:11:56 matt Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.10 2011/06/29 05:53:44 matt Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.9 2011/06/23 08:11:56 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.10 2011/06/29 05:53:44 matt Exp $);
 
 /*
  * Manages address spaces in a TLB.
@@ -162,10 +162,10 @@
 #undef IFCONSTANT
 
 #if defined(MULTIPROCESSOR)
-static struct pmap_tlb_info *pmap_tlbs[MAXCPUS] = {
+struct pmap_tlb_info *pmap_tlbs[MAXCPUS] = {
 	[0] = pmap_tlb0_info,
 };
-static u_int pmap_ntlbs = 1;
+u_int pmap_ntlbs = 1;
 #endif
 
 #define	__BITMAP_SET(bm, n) \
@@ -463,7 +463,7 @@
 		 */
 		struct pmap_asid_info * const pai = PMAP_PAI(ti-ti_victim, ti);
 		KASSERT(ti-ti_victim != pmap_kernel());
-		if (!CPU_EMPTY_P(CPUSET_SUBSET(ti-ti_victim-pm_onproc, ti-ti_cpu_mask))) {
+		if (!CPUSET_EMPTY_P(CPUSET_SUBSET(ti-ti_victim-pm_onproc, ti-ti_cpu_mask))) {
 			/*
 			 * The victim is an active pmap so we will just
 			 * invalidate its TLB entries.
@@ -602,7 +602,7 @@
 			 * change now that we have released the lock but we
 			 * can tolerate spurious shootdowns.
 			 */
-			KASSERT(!CPU_EMPTY_P(onproc));
+			KASSERT(!CPUSET_EMPTY_P(onproc));
 			u_int j = CPUSET_NEXT(onproc);
 			cpu_send_ipi(cpu_lookup(j), IPI_SHOOTDOWN);
 			ipi_sent = true;
@@ -682,8 +682,8 @@
 	KASSERT(pai-pai_asid == 0);
 	KASSERT(pai-pai_link.le_prev == NULL);
 #if defined(MULTIPROCESSOR)
-	KASSERT(CPU_EMPTY_P(CPUSET_SUBSET(pm-pm_onproc, ti-ti_cpu_mask)));
-	KASSERT(CPU_EMPTY_P(CPUSET_SUBSET(pm-pm_active, ti-ti_cpu_mask)));
+	KASSERT(CPUSET_EMPTY_P(CPUSET_SUBSET(pm-pm_onproc, ti-ti_cpu_mask)));
+	KASSERT(CPUSET_EMPTY_P(CPUSET_SUBSET(pm-pm_active, ti-ti_cpu_mask)));
 #endif
 	KASSERT(ti-ti_asids_free  0);
 	KASSERT(ti-ti_asid_hint = ti-ti_asid_max);
@@ -790,7 +790,7 @@
 		 * be changed while this TLBs lock is held unless atomic
 		 * operations are used.
 		 */
-		CPUSET_ADD(pm-pm_onproc, cpu_index(ci));
+		CPUSET_ADD(pm-pm_onproc, cpu_index(ci));
 #endif
 		ci-ci_pmap_asid_cur = pai-pai_asid;
 		tlb_set_asid(pai-pai_asid);
@@ -837,11 +837,11 @@
 {
 	KASSERT(pm != pmap_kernel());
 #if defined(MULTIPROCESSOR)
-	KASSERT(CPUSET_EMPTY(pm-pm_onproc));
-	for (u_int i = 0; !CPUSET_EMPTY(pm-pm_active); i++) {
+	KASSERT(CPUSET_EMPTY_P(pm-pm_onproc));
+	for (u_int i = 0; !CPUSET_EMPTY_P(pm-pm_active); i++) {
 		KASSERT(i  pmap_ntlbs);
 		struct pmap_tlb_info * const ti = pmap_tlbs[i];
-		if (!CPU_EMPTY_P(CPUSET_SUBSET(pm-pm_active, ti-ti_cpu_mask))) {
+		if (!CPUSET_EMPTY_P(CPUSET_SUBSET(pm-pm_active, ti-ti_cpu_mask))) {
 			struct pmap_asid_info * const pai = PMAP_PAI(pm, ti);
 			TLBINFO_LOCK(ti);
 			KASSERT(ti-ti_victim != pm);



CVS commit: src/sys/common/pmap/tlb

2011-06-23 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 23 07:43:20 UTC 2011

Added Files:
src/sys/common/pmap/tlb: pmap_synci.c

Log Message:
Separate code out from pmap_tlb.c which handles the synchronization of the
icache across CPUs.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/common/pmap/tlb/pmap_synci.c

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

Added files:

Index: src/sys/common/pmap/tlb/pmap_synci.c
diff -u /dev/null src/sys/common/pmap/tlb/pmap_synci.c:1.1
--- /dev/null	Thu Jun 23 07:43:20 2011
+++ src/sys/common/pmap/tlb/pmap_synci.c	Thu Jun 23 07:43:19 2011
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+
+__KERNEL_RCSID(0, $NetBSD: pmap_synci.c,v 1.1 2011/06/23 07:43:19 matt Exp $);
+
+#define __PMAP_PRIVATE
+
+#include sys/param.h
+#include sys/systm.h
+#include sys/mutex.h
+#include sys/atomic.h
+#include sys/cpu.h
+ 
+#include uvm/uvm.h
+
+#if defined(MULTIPROCESSOR)
+void
+pmap_syncicache_ast(struct cpu_info *ci)
+{
+	struct pmap_tlb_info * const ti = ci-ci_tlb_info;
+
+	KASSERT(kpreempt_disabled());
+
+	uint32_t page_bitmap = atomic_swap_32(ti-ti_synci_page_bitmap, 0);
+#if 0
+	printf(%s: need to sync %#x\n, __func__, page_bitmap);
+#endif
+	ti-ti_evcnt_synci_asts.ev_count++;
+	/*
+	 * If every bit is set in the bitmap, sync the entire icache.
+	 */
+	if (page_bitmap == pmap_tlb_synci_map_mask) {
+		pmap_md_icache_sync_all();
+		ti-ti_evcnt_synci_all.ev_count++;
+		ti-ti_evcnt_synci_pages.ev_count += pmap_tlb_synci_page_mask+1;
+		kpreempt_enable();
+		return;
+	}
+
+	/*
+	 * Loop through the bitmap clearing each set of indices for each page.
+	 */
+	for (vaddr_t va = 0;
+	 page_bitmap != 0;
+	 page_bitmap = 1, va += PAGE_SIZE) {
+		if (page_bitmap  1) {
+			/*
+			 * Each bit set represents a page index to be synced.
+			 */
+			pmap_md_icache_sync_range_index(va, PAGE_SIZE);
+			ti-ti_evcnt_synci_pages.ev_count++;
+		}
+	}
+
+	kpreempt_enable();
+}
+
+void
+pmap_tlb_syncicache(vaddr_t va, uint32_t page_onproc)
+{
+	KASSERT(kpreempt_disabled());
+	/*
+	 * We don't sync the icache here but let ast do it for us just before
+	 * returning to userspace.  We do this because we don't really know
+	 * on which CPU we will return to userspace and if we synch the icache
+	 * now it might not be on the CPU we need it on.  In addition, others
+	 * threads might sync the icache before we get to return to userland
+	 * so there's no reason for us to do it.
+	 *
+	 * Each TLB/cache keeps a synci sequence number which gets advanced
+	 * each time that TLB/cache performs a pmap_md_sync_icache_all.  When
+	 * we return to userland, we check the pmap's corresponding synci
+	 * sequence number for that TLB/cache.  If they match, it means that
+	 * no one has yet synched the icache so we much do it ourselves.  If
+	 * they don't match someone has already synced the icache for us.
+	 *
+	 * There is a small chance that the generation numbers will wrap and
+	 * then become equal but that's a one in 4 billion cache and will
+	 * just cause an extra sync of the icache.
+	 */
+	const uint32_t cpu_mask = 1L  cpu_index(curcpu());
+	const uint32_t page_mask =
+	1L  ((va  PGSHIFT)  pmap_tlb_synci_page_mask);
+	uint32_t onproc = 0;
+	for (size_t i = 0; i  pmap_ntlbs; i++) {
+		struct pmap_tlb_info * const ti = pmap_tlbs[i];
+		TLBINFO_LOCK(ti);
+		for (;;) {
+			uint32_t old_page_bitmap = 

CVS commit: src/sys/common/pmap/tlb

2011-06-23 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 23 07:45:24 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap.h

Log Message:
Use new names for the pmap_syncicache routines


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/common/pmap/tlb/pmap.h

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

Modified files:

Index: src/sys/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.8 src/sys/common/pmap/tlb/pmap.h:1.9
--- src/sys/common/pmap/tlb/pmap.h:1.8	Thu Jun 23 05:50:24 2011
+++ src/sys/common/pmap/tlb/pmap.h	Thu Jun 23 07:45:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.8 2011/06/23 05:50:24 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.9 2011/06/23 07:45:24 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -234,9 +234,9 @@
 bool	pmap_tlb_shootdown_bystanders(pmap_t pmap);
 void	pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
 void	pmap_md_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
-void	pmap_tlb_syncicache_ast(struct cpu_info *);
-void	pmap_tlb_syncicache_wanted(struct cpu_info *);
-void	pmap_tlb_syncicache(vaddr_t, uint32_t);
+void	pmap_syncicache_ast(struct cpu_info *);
+void	pmap_syncicache_wanted(struct cpu_info *);
+void	pmap_syncicache(vaddr_t, uint32_t);
 #endif
 void	pmap_tlb_info_init(struct pmap_tlb_info *);
 void	pmap_tlb_info_evcnt_attach(struct pmap_tlb_info *);



CVS commit: src/sys/common/pmap/tlb

2011-06-23 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 23 07:58:19 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap.h pmap_tlb.c

Log Message:
Add pmap_tlb_asid_check and use it verify asid handling.
The shared pmap is now in a state that mips could switch to it.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/common/pmap/tlb/pmap.h
cvs rdiff -u -r1.7 -r1.8 src/sys/common/pmap/tlb/pmap_tlb.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/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.9 src/sys/common/pmap/tlb/pmap.h:1.10
--- src/sys/common/pmap/tlb/pmap.h:1.9	Thu Jun 23 07:45:24 2011
+++ src/sys/common/pmap/tlb/pmap.h	Thu Jun 23 07:58:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.9 2011/06/23 07:45:24 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.10 2011/06/23 07:58:19 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -248,6 +248,7 @@
 #define	PMAP_TLB_INSERT		0x02
 void	pmap_tlb_invalidate_addr(pmap_t, vaddr_t);
 void	pmap_tlb_check(pmap_t, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t));
+void	pmap_tlb_asid_check(void);
 
 uint16_t pmap_pvlist_lock(struct vm_page_md *, bool);
 

Index: src/sys/common/pmap/tlb/pmap_tlb.c
diff -u src/sys/common/pmap/tlb/pmap_tlb.c:1.7 src/sys/common/pmap/tlb/pmap_tlb.c:1.8
--- src/sys/common/pmap/tlb/pmap_tlb.c:1.7	Thu Jun 23 05:42:27 2011
+++ src/sys/common/pmap/tlb/pmap_tlb.c	Thu Jun 23 07:58:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.7 2011/06/23 05:42:27 matt Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.8 2011/06/23 07:58:19 matt Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.7 2011/06/23 05:42:27 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.8 2011/06/23 07:58:19 matt Exp $);
 
 /*
  * Manages address spaces in a TLB.
@@ -368,7 +368,9 @@
 		 * allocate a new ASID.
 		 */
 #if !defined(MULTIPROCESSOR) || defined(PMAP_NEED_TLB_SHOOTDOWN)
+		pmap_tlb_asid_check();
 		const u_int asids_found = tlb_record_asids(ti-ti_asid_bitmap);
+		pmap_tlb_asid_check();
 		KASSERT(asids_found == pmap_tlb_asid_count(ti));
 		if (__predict_false(asids_found = ti-ti_asid_max / 2)) {
 			tlb_invalidate_asids(KERNEL_PID + 1, ti-ti_asid_max);
@@ -465,7 +467,9 @@
 			 * invalidate its TLB entries.
 			 */
 			KASSERT(pai-pai_asid  KERNEL_PID);
+			pmap_tlb_asid_check();
 			tlb_invalidate_asids(pai-pai_asid, pai-pai_asid);
+			pmap_tlb_asid_check();
 		} else if (pai-pai_asid) {
 			/*
 			 * The victim is no longer an active pmap for this TLB.
@@ -488,7 +492,9 @@
 		/*
 		 * We need to invalidate all global TLB entries.
 		 */
+		pmap_tlb_asid_check();
 		tlb_invalidate_globals();
+		pmap_tlb_asid_check();
 		break;
 	case TLBINV_ALL:
 		/*
@@ -629,8 +635,10 @@
 
 	TLBINFO_LOCK(ti);
 	if (pm == pmap_kernel() || PMAP_PAI_ASIDVALID_P(pai, ti)) {
+		pmap_tlb_asid_check();
 		rv = tlb_update_addr(va, pai-pai_asid, pt_entry,
 		(flags  PMAP_TLB_INSERT) != 0);
+		pmap_tlb_asid_check();
 	}
 #if defined(MULTIPROCESSOR)  defined(PMAP_NEED_TLB_SHOOTDOWN)
 	pm-pm_shootdown_pending = (flags  PMAP_TLB_NEED_IPI) != 0;
@@ -650,7 +658,9 @@
 
 	TLBINFO_LOCK(ti);
 	if (pm == pmap_kernel() || PMAP_PAI_ASIDVALID_P(pai, ti)) {
+		pmap_tlb_asid_check();
 		tlb_invalidate_addr(va, pai-pai_asid);
+		pmap_tlb_asid_check();
 	}
 #if defined(MULTIPROCESSOR)  defined(PMAP_NEED_TLB_SHOOTDOWN)
 	pm-pm_shootdown_pending = 1;
@@ -782,6 +792,9 @@
 #endif
 		ci-ci_pmap_asid_cur = pai-pai_asid;
 		tlb_set_asid(pai-pai_asid);
+		pmap_tlb_asid_check();
+	} else {
+		printf(%s: l (%p) != curlwp %p\n, __func__, l, curlwp);
 	}
 	TLBINFO_UNLOCK(ti);
 }
@@ -813,6 +826,7 @@
 #elif defined(DEBUG)
 	curcpu()-ci_pmap_asid_cur = 0;
 	tlb_set_asid(0);
+	pmap_tlb_asid_check();
 #endif
 }
 
@@ -848,6 +862,19 @@
 #endif /* MULTIPROCESSOR */
 }
 
+void
+pmap_tlb_asid_check(void)
+{
+#ifdef DEBUG
+	kpreempt_disable();
+	const tlb_asid_t asid = tlb_get_asid();
+	KDASSERTMSG(asid == curcpu()-ci_pmap_asid_cur,
+	   (%s: asid (%#x) != current asid (%#x),
+	__func__, asid, curcpu()-ci_pmap_asid_cur));
+	kpreempt_enable();
+#endif
+}
+
 #ifdef DEBUG
 void
 pmap_tlb_check(pmap_t pm, bool (*func)(void *, vaddr_t, tlb_asid_t, pt_entry_t))



CVS commit: src/sys/common/pmap/tlb

2011-06-23 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 23 08:11:56 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap_segtab.c pmap_synci.c pmap_tlb.c

Log Message:
Make sure to include opt_multiprocessor.h.
Add missing ). (spotted by uebayashi@)


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/common/pmap/tlb/pmap_segtab.c
cvs rdiff -u -r1.1 -r1.2 src/sys/common/pmap/tlb/pmap_synci.c
cvs rdiff -u -r1.8 -r1.9 src/sys/common/pmap/tlb/pmap_tlb.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/common/pmap/tlb/pmap_segtab.c
diff -u src/sys/common/pmap/tlb/pmap_segtab.c:1.3 src/sys/common/pmap/tlb/pmap_segtab.c:1.4
--- src/sys/common/pmap/tlb/pmap_segtab.c:1.3	Tue Jun 21 06:43:38 2011
+++ src/sys/common/pmap/tlb/pmap_segtab.c	Thu Jun 23 08:11:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.3 2011/06/21 06:43:38 matt Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.4 2011/06/23 08:11:56 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.3 2011/06/21 06:43:38 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.4 2011/06/23 08:11:56 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -97,6 +97,8 @@
 
 #define __PMAP_PRIVATE
 
+#include opt_multiprocessor.h
+
 #include sys/param.h
 #include sys/systm.h
 #include sys/proc.h

Index: src/sys/common/pmap/tlb/pmap_synci.c
diff -u src/sys/common/pmap/tlb/pmap_synci.c:1.1 src/sys/common/pmap/tlb/pmap_synci.c:1.2
--- src/sys/common/pmap/tlb/pmap_synci.c:1.1	Thu Jun 23 07:43:19 2011
+++ src/sys/common/pmap/tlb/pmap_synci.c	Thu Jun 23 08:11:56 2011
@@ -29,10 +29,12 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_synci.c,v 1.1 2011/06/23 07:43:19 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_synci.c,v 1.2 2011/06/23 08:11:56 matt Exp $);
 
 #define __PMAP_PRIVATE
 
+#include opt_multiprocessor.h
+
 #include sys/param.h
 #include sys/systm.h
 #include sys/mutex.h

Index: src/sys/common/pmap/tlb/pmap_tlb.c
diff -u src/sys/common/pmap/tlb/pmap_tlb.c:1.8 src/sys/common/pmap/tlb/pmap_tlb.c:1.9
--- src/sys/common/pmap/tlb/pmap_tlb.c:1.8	Thu Jun 23 07:58:19 2011
+++ src/sys/common/pmap/tlb/pmap_tlb.c	Thu Jun 23 08:11:56 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_tlb.c,v 1.8 2011/06/23 07:58:19 matt Exp $	*/
+/*	$NetBSD: pmap_tlb.c,v 1.9 2011/06/23 08:11:56 matt Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.8 2011/06/23 07:58:19 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_tlb.c,v 1.9 2011/06/23 08:11:56 matt Exp $);
 
 /*
  * Manages address spaces in a TLB.
@@ -124,6 +124,8 @@
 
 #define __PMAP_PRIVATE
 
+#include opt_multiprocessor.h
+
 #include sys/param.h
 #include sys/systm.h
 #include sys/proc.h
@@ -415,7 +417,7 @@
 		KASSERT(pm != pmap_kernel());
 		KASSERT(pai-pai_asid  KERNEL_PID);
 #if defined(MULTIPROCESSOR)
-		if (!CPUSET_EMPTY_P(CPUSET_SUBSET(pm-pm_onproc, ti-ti_cpu_mask)) {
+		if (!CPUSET_EMPTY_P(CPUSET_SUBSET(pm-pm_onproc, ti-ti_cpu_mask))) {
 			if (!TLBINFO_ASID_INUSE_P(ti, pai-pai_asid)) {
 TLBINFO_ASID_MARK_USED(ti, pai-pai_asid);
 ti-ti_asids_free--;



CVS commit: src/sys/common/pmap/tlb

2011-06-22 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jun 23 05:50:24 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap.h

Log Message:
Add pmap_md_tlb_info_attach prototype.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/common/pmap/tlb/pmap.h

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

Modified files:

Index: src/sys/common/pmap/tlb/pmap.h
diff -u src/sys/common/pmap/tlb/pmap.h:1.7 src/sys/common/pmap/tlb/pmap.h:1.8
--- src/sys/common/pmap/tlb/pmap.h:1.7	Thu Jun 23 05:42:27 2011
+++ src/sys/common/pmap/tlb/pmap.h	Thu Jun 23 05:50:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.7 2011/06/23 05:42:27 matt Exp $	*/
+/*	$NetBSD: pmap.h,v 1.8 2011/06/23 05:50:24 matt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -233,6 +233,7 @@
 void	pmap_tlb_shootdown_process(void);
 bool	pmap_tlb_shootdown_bystanders(pmap_t pmap);
 void	pmap_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
+void	pmap_md_tlb_info_attach(struct pmap_tlb_info *, struct cpu_info *);
 void	pmap_tlb_syncicache_ast(struct cpu_info *);
 void	pmap_tlb_syncicache_wanted(struct cpu_info *);
 void	pmap_tlb_syncicache(vaddr_t, uint32_t);



CVS commit: src/sys/common/pmap/tlb

2011-06-21 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Jun 21 06:43:38 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap_segtab.c

Log Message:
Add #define __PMAP_PRIVATE


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/common/pmap/tlb/pmap_segtab.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/common/pmap/tlb/pmap_segtab.c
diff -u src/sys/common/pmap/tlb/pmap_segtab.c:1.2 src/sys/common/pmap/tlb/pmap_segtab.c:1.3
--- src/sys/common/pmap/tlb/pmap_segtab.c:1.2	Tue Jan 18 01:11:50 2011
+++ src/sys/common/pmap/tlb/pmap_segtab.c	Tue Jun 21 06:43:38 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap_segtab.c,v 1.2 2011/01/18 01:11:50 matt Exp $	*/
+/*	$NetBSD: pmap_segtab.c,v 1.3 2011/06/21 06:43:38 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.2 2011/01/18 01:11:50 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap_segtab.c,v 1.3 2011/06/21 06:43:38 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -95,6 +95,8 @@
  *	and to when physical maps must be made correct.
  */
 
+#define __PMAP_PRIVATE
+
 #include sys/param.h
 #include sys/systm.h
 #include sys/proc.h



CVS commit: src/sys/common/pmap/tlb

2011-06-20 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Mon Jun 20 19:31:58 UTC 2011

Added Files:
src/sys/common/pmap/tlb: vmpagemd.h

Log Message:
Make the vm_page_md definition common for all users of the shared tlb pmap.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/common/pmap/tlb/vmpagemd.h

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

Added files:

Index: src/sys/common/pmap/tlb/vmpagemd.h
diff -u /dev/null src/sys/common/pmap/tlb/vmpagemd.h:1.1
--- /dev/null	Mon Jun 20 19:31:58 2011
+++ src/sys/common/pmap/tlb/vmpagemd.h	Mon Jun 20 19:31:58 2011
@@ -0,0 +1,112 @@
+/*	$NetBSD: vmpagemd.h,v 1.1 2011/06/20 19:31:58 matt Exp $	*/
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Raytheon BBN Technologies Corp and Defense Advanced Research Projects
+ * Agency and which was developed by Matt Thomas of 3am Software Foundry.
+ *
+ * This material is based upon work supported by the Defense Advanced Research
+ * Projects Agency and Space and Naval Warfare Systems Center, Pacific, under
+ * Contract No. N66001-09-C-2073.
+ * Approved for Public Release, Distribution Unlimited
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _COMMON_PMAP_TLB_VMPAGEMD_H_
+#define _COMMON_PMAP_TLB_VMPAGEMD_H_
+
+#ifdef _LOCORE
+#error use assym.h instead
+#endif
+
+#ifdef _MODULE
+#error this file should not be included by loadable kernel modules
+#endif
+
+#include opt_modular.h
+#include opt_multiprocessor.h
+
+#include sys/mutex.h
+
+#define	__HAVE_VM_PAGE_MD
+
+typedef struct pv_entry {
+	struct pv_entry *pv_next;
+	struct pmap *pv_pmap;
+	vaddr_t pv_va;
+} *pv_entry_t;
+
+#define	VM_PAGEMD_REFERENCED	0x0001	/* page has been recently referenced */
+#define	VM_PAGEMD_MODIFIED	0x0002	/* page has been modified */
+#define	VM_PAGEMD_POOLPAGE	0x0004	/* page is used as a poolpage */
+#define	VM_PAGEMD_EXECPAGE	0x0008	/* page is exec mapped */
+#ifdef __PMAP_VIRTUAL_CACHE_ALIASES
+#define	VM_PAGEMD_UNCACHED	0x0010	/* page is mapped uncached */
+#endif
+
+#ifdef __PMAP_VIRTUAL_CACHE_ALIASES
+#define	VM_PAGEMD_CACHED_P(mdpg)	(((mdpg)-mdpg_attrs  VM_PAGEMD_UNCACHED) == 0)
+#define	VM_PAGEMD_UNCACHED_P(mdpg)	(((mdpg)-mdpg_attrs  VM_PAGEMD_UNCACHED) != 0)
+#endif
+#define	VM_PAGEMD_MODIFIED_P(mdpg)	(((mdpg)-mdpg_attrs  VM_PAGEMD_MODIFIED) != 0)
+#define	VM_PAGEMD_REFERENCED_P(mdpg)	(((mdpg)-mdpg_attrs  VM_PAGEMD_REFERENCED) != 0)
+#define	VM_PAGEMD_POOLPAGE_P(mdpg)	(((mdpg)-mdpg_attrs  VM_PAGEMD_POOLPAGE) != 0)
+#define	VM_PAGEMD_EXECPAGE_P(mdpg)	(((mdpg)-mdpg_attrs  VM_PAGEMD_EXECPAGE) != 0)
+
+struct vm_page_md {
+	volatile u_int mdpg_attrs;	/* page attributes */
+	struct pv_entry mdpg_first;	/* pv_entry first */
+#if defined(MULTIPROCESSOR) || defined(MODULAR)
+	kmutex_t *mdpg_lock;		/* pv list lock */
+#define	VM_PAGEMD_PVLIST_LOCK_INIT(mdpg) 	\
+	(mdpg)-mdpg_lock = NULL
+#define	VM_PAGEMD_PVLIST_LOCK(pg, list_change)	\
+	pmap_pvlist_lock(mdpg, list_change)
+#define	VM_PAGEMD_PVLIST_UNLOCK(mdpg)		\
+	mutex_spin_exit((mdpg)-mdpg_lock)
+#define	VM_PAGEMD_PVLIST_LOCKED_P(mdpg)		\
+	mutex_owner((mdpg)-mdpg_lock)
+#define	VM_PAGEMD_PVLIST_GEN(mdpg)		\
+	((uint16_t)((mdpg)-mdpg_attrs  16))
+#else
+#define	VM_PAGEMD_PVLIST_LOCK_INIT(mdpg)	do { } while (/*CONSTCOND*/ 0)
+#define	VM_PAGEMD_PVLIST_LOCK(mdpg, lc)	(mutex_spin_enter(pmap_pvlist_mutex), 0)
+#define	VM_PAGEMD_PVLIST_UNLOCK(mdpg)	mutex_spin_exit(pmap_pvlist_mutex)
+#define	VM_PAGEMD_PVLIST_LOCKED_P(mdpg)	true
+#define	VM_PAGEMD_PVLIST_GEN(mdpg)		(0)
+#endif /* MULTIPROCESSOR || MODULAR */
+};
+

CVS commit: src/sys/common/pmap/tlb

2011-06-20 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Jun 21 04:55:01 UTC 2011

Added Files:
src/sys/common/pmap/tlb: tlb.h

Log Message:
Add a common struct containing tlb ops needed by the tlb pmap.c


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/common/pmap/tlb/tlb.h

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

Added files:

Index: src/sys/common/pmap/tlb/tlb.h
diff -u /dev/null src/sys/common/pmap/tlb/tlb.h:1.1
--- /dev/null	Tue Jun 21 04:55:01 2011
+++ src/sys/common/pmap/tlb/tlb.h	Tue Jun 21 04:55:01 2011
@@ -0,0 +1,71 @@
+/*	$NetBSD: tlb.h,v 1.1 2011/06/21 04:55:01 matt Exp $	*/
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Matt Thomas of 3am Software Foundry.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _COMMON_PMAP_TLB_TLB_H_
+#define	_COMMON_PMAP_TLB_TLB_H_
+
+#if defined(_KERNEL) || defined(_KMEMUSER)
+
+struct tlbmask;
+
+struct tlb_md_ops {
+	void	(*md_tlb_set_asid)(tlb_asid_t);
+	tlb_asid_t
+		(*md_tlb_get_asid)(void);
+	void	(*md_tlb_invalidate_all)(void);
+	void	(*md_tlb_invalidate_globals)(void);
+	void	(*md_tlb_invalidate_asids)(tlb_asid_t, tlb_asid_t);
+	void	(*md_tlb_invalidate_addr)(vaddr_t, tlb_asid_t);
+	bool	(*md_tlb_update_addr)(vaddr_t, tlb_asid_t, pt_entry_t, bool);
+	void	(*md_tlb_read_entry)(size_t, struct tlbmask *);
+	void	(*md_tlb_write_entry)(size_t, const struct tlbmask *);
+	u_int	(*md_tlb_record_asids)(u_long *);
+	void	(*md_tlb_dump)(void (*)(const char *, ...));
+	void	(*md_tlb_walk)(void *, bool (*)(void *, vaddr_t, tlb_asid_t,
+		pt_entry_t));
+};
+
+tlb_asid_t
+	tlb_get_asid(void);
+void	tlb_set_asid(tlb_asid_t);
+void	tlb_invalidate_all(void);
+void	tlb_invalidate_globals(void);
+void	tlb_invalidate_asids(tlb_asid_t, tlb_asid_t);
+void	tlb_invalidate_addr(vaddr_t, tlb_asid_t);
+bool	tlb_update_addr(vaddr_t, tlb_asid_t, pt_entry_t, bool);
+u_int	tlb_record_asids(u_long *);
+void	tlb_enter_addr(size_t, const struct tlbmask *);
+void	tlb_read_entry(size_t, struct tlbmask *);
+void	tlb_write_entry(size_t, const struct tlbmask *);
+void	tlb_walk(void *, bool (*)(void *, vaddr_t, tlb_asid_t, pt_entry_t));
+void	tlb_dump(void (*)(const char *, ...));
+
+#endif /* _KERNEL || _KMEMUSER */
+
+#endif /* !_COMMON_PMAP_TLB_TLB_H_ */



CVS commit: src/sys/common/pmap/tlb

2011-01-17 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Tue Jan 18 01:20:06 UTC 2011

Modified Files:
src/sys/common/pmap/tlb: pmap.c

Log Message:
Remove forced DEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/common/pmap/tlb/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/common/pmap/tlb/pmap.c
diff -u src/sys/common/pmap/tlb/pmap.c:1.2 src/sys/common/pmap/tlb/pmap.c:1.3
--- src/sys/common/pmap/tlb/pmap.c:1.2	Tue Jan 18 01:11:50 2011
+++ src/sys/common/pmap/tlb/pmap.c	Tue Jan 18 01:20:06 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.2 2011/01/18 01:11:50 matt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.3 2011/01/18 01:20:06 matt Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.2 2011/01/18 01:11:50 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: pmap.c,v 1.3 2011/01/18 01:20:06 matt Exp $);
 
 /*
  *	Manages physical address maps.
@@ -113,8 +113,6 @@
 
 #include uvm/uvm.h
 
-#define DEBUG 1
-
 #define	PMAP_COUNT(name)	(pmap_evcnt_##name.ev_count++ + 0)
 #define PMAP_COUNTER(name, desc) \
 static struct evcnt pmap_evcnt_##name = \