Module Name:    src
Committed By:   martin
Date:           Mon Mar  9 10:36:42 UTC 2020

Modified Files:
        src/sys/arch/powerpc/ibm4xx [netbsd-9]: pmap.c
        src/sys/arch/powerpc/include/ibm4xx [netbsd-9]: pmap.h tlb.h

Log Message:
Pull up following revision(s) (requested by rin in ticket #773):

        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.81
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.82
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.83
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.84
        sys/arch/powerpc/ibm4xx/pmap.c: revision 1.85
        sys/arch/powerpc/include/ibm4xx/tlb.h: revision 1.6
        sys/arch/powerpc/include/ibm4xx/pmap.h: revision 1.20

Misc non-critical fixes.
- __asm --> __asm volatile for sure
- turn DEBUG code in __asm into DIAGNOSTIC code in C
- style

ppc4xx_tlb_enter(): invalidate entry after clearing MSR for sure.

pmap_procwr(): use dcbst instead of dcbf as a tiny optimization.

Retire tlbpid_t (u_short):
- PID (ctx, ASID) is 8-bit length, not half word.
- For struct pmap, no need to use integer types smaller than word as
  pm_ctx because of alignment.
- For ppc4xx_tlb_enter(), we need word-length storage for pid (and msr).
XXX
Better to rewrite pmap module with more suggestive integer types rather
than char, int, long, and so on.

Fix pmap_procwr().
While we need to turn off IMMU, DMMU should be kept on. Otherwise,
dcbst (and also icbi probably, though not documented clearly both
for 405 and 403) should not work correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.76.20.1 -r1.76.20.2 src/sys/arch/powerpc/ibm4xx/pmap.c
cvs rdiff -u -r1.19 -r1.19.2.1 src/sys/arch/powerpc/include/ibm4xx/pmap.h
cvs rdiff -u -r1.5 -r1.5.6.1 src/sys/arch/powerpc/include/ibm4xx/tlb.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/arch/powerpc/ibm4xx/pmap.c
diff -u src/sys/arch/powerpc/ibm4xx/pmap.c:1.76.20.1 src/sys/arch/powerpc/ibm4xx/pmap.c:1.76.20.2
--- src/sys/arch/powerpc/ibm4xx/pmap.c:1.76.20.1	Thu Feb 27 18:23:10 2020
+++ src/sys/arch/powerpc/ibm4xx/pmap.c	Mon Mar  9 10:36:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.76.20.1 2020/02/27 18:23:10 martin Exp $	*/
+/*	$NetBSD: pmap.c,v 1.76.20.2 2020/03/09 10:36:42 martin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.76.20.1 2020/02/27 18:23:10 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.76.20.2 2020/03/09 10:36:42 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -1173,16 +1173,18 @@ pmap_procwr(struct proc *p, vaddr_t va, 
 		ctx_alloc(pm);
 		ctx = pm->pm_ctx;
 	}
-	__asm volatile("mfmsr %0;"
-		"li %1, %7;"
+	__asm volatile(
+		"mfmsr %0;"
+		"li %1,0x20;"		/* Turn off IMMU */
 		"andc %1,%0,%1;"
+		"ori %1,%1,0x10;"	/* Turn on DMMU for sure */
 		"mtmsr %1;"
 		"sync;isync;"
 		"mfpid %1;"
 		"mtpid %2;"
 		"sync; isync;"
 		"1:"
-		"dcbf 0,%3;"
+		"dcbst 0,%3;"
 		"icbi 0,%3;"
 		"add %3,%3,%5;"
 		"addc. %4,%4,%6;"
@@ -1191,8 +1193,7 @@ pmap_procwr(struct proc *p, vaddr_t va, 
 		"mtmsr %0;"
 		"sync; isync"
 		: "=&r" (msr), "=&r" (opid)
-		: "r" (ctx), "r" (va), "r" (len), "r" (step), "r" (-step),
-		  "K" (PSL_IR | PSL_DR));
+		: "r" (ctx), "r" (va), "r" (len), "r" (step), "r" (-step));
 }
 
 
@@ -1207,7 +1208,8 @@ ppc4xx_tlb_flush(vaddr_t va, int pid)
 	if (!pid)
 		return;
 
-	__asm( 	"mfpid %1;"		/* Save PID */
+	__asm volatile(
+		"mfpid %1;"		/* Save PID */
 		"mfmsr %2;"		/* Save MSR */
 		"li %0,0;"		/* Now clear MSR */
 		"mtmsr %0;"
@@ -1225,7 +1227,6 @@ ppc4xx_tlb_flush(vaddr_t va, int pid)
 		: "=&r" (i), "=&r" (found), "=&r" (msr)
 		: "r" (va), "r" (pid));
 	if (found && !TLB_LOCKED(i)) {
-
 		/* Now flush translation */
 		__asm volatile(
 			"tlbwe %0,%1,0;"
@@ -1292,8 +1293,7 @@ void
 ppc4xx_tlb_enter(int ctx, vaddr_t va, u_int pte)
 {
 	u_long th, tl, idx;
-	tlbpid_t pid;
-	u_short msr;
+	int msr, pid;
 	paddr_t pa;
 	int sz;
 
@@ -1308,7 +1308,7 @@ ppc4xx_tlb_enter(int ctx, vaddr_t va, u_
 	idx = ppc4xx_tlb_find_victim();
 
 #ifdef DIAGNOSTIC
-	if ((idx < tlb_nreserved) || (idx >= NTLB)) {
+	if ((idx < tlb_nreserved) || (idx >= NTLB) || (idx & 63) == 0) {
 		panic("ppc4xx_tlb_enter: replacing entry %ld", idx);
 	}
 #endif
@@ -1320,15 +1320,11 @@ ppc4xx_tlb_enter(int ctx, vaddr_t va, u_
 	__asm volatile(
 		"mfmsr %0;"			/* Save MSR */
 		"li %1,0;"
-		"tlbwe %1,%3,0;"		/* Invalidate old entry. */
 		"mtmsr %1;"			/* Clear MSR */
+		"tlbwe %1,%3,0;"		/* Invalidate old entry. */
 		"mfpid %1;"			/* Save old PID */
 		"mtpid %2;"			/* Load translation ctx */
 		"sync; isync;"
-#ifdef DEBUG
-		"andi. %3,%3,63;"
-		"tweqi %3,0;" 			/* XXXXX DEBUG trap on index 0 */
-#endif
 		"tlbwe %4,%3,1; tlbwe %5,%3,0;"	/* Set TLB */
 		"sync; isync;"
 		"mtpid %1; mtmsr %0;"		/* Restore PID and MSR */

Index: src/sys/arch/powerpc/include/ibm4xx/pmap.h
diff -u src/sys/arch/powerpc/include/ibm4xx/pmap.h:1.19 src/sys/arch/powerpc/include/ibm4xx/pmap.h:1.19.2.1
--- src/sys/arch/powerpc/include/ibm4xx/pmap.h:1.19	Wed Jul 17 08:39:03 2019
+++ src/sys/arch/powerpc/include/ibm4xx/pmap.h	Mon Mar  9 10:36:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.19 2019/07/17 08:39:03 skrll Exp $	*/
+/*	$NetBSD: pmap.h,v 1.19.2.1 2020/03/09 10:36:42 martin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -143,7 +143,7 @@
  * Pmap stuff
  */
 struct pmap {
-	volatile tlbpid_t pm_ctx;	/* PID to identify PMAP's entries in TLB */
+	volatile int pm_ctx;	/* PID to identify PMAP's entries in TLB */
 	int pm_refs;			/* ref count */
 	struct pmap_statistics pm_stats; /* pmap statistics */
 	volatile u_int *pm_ptbl[STSZ];	/* Array of 64 pointers to page tables. */

Index: src/sys/arch/powerpc/include/ibm4xx/tlb.h
diff -u src/sys/arch/powerpc/include/ibm4xx/tlb.h:1.5 src/sys/arch/powerpc/include/ibm4xx/tlb.h:1.5.6.1
--- src/sys/arch/powerpc/include/ibm4xx/tlb.h:1.5	Thu Apr 19 21:50:07 2018
+++ src/sys/arch/powerpc/include/ibm4xx/tlb.h	Mon Mar  9 10:36:42 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: tlb.h,v 1.5 2018/04/19 21:50:07 christos Exp $	*/
+/*	$NetBSD: tlb.h,v 1.5.6.1 2020/03/09 10:36:42 martin Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -89,7 +89,6 @@
 
 #ifndef _LOCORE
 
-typedef u_short tlbpid_t;
 typedef struct tlb_s {
 	u_int tlb_hi;
 	u_int tlb_lo;

Reply via email to