Module Name:    src
Committed By:   matt
Date:           Tue Sep  8 08:11:30 UTC 2009

Modified Files:
        src/sys/arch/mips/mips [matt-nb5-mips64]: bus_dma.c
            bus_space_alignstride_chipdep.c mem.c mips_machdep.c pmap.c

Log Message:
For LP64 kernels, only use KSEG0 for pmap_steal_memory.  Everything else uses
XKPHYS.  Use the new MIPS_PHYS_TO_XKPHYS_{,UN}CACHED macros.


To generate a diff of this commit:
cvs rdiff -u -r1.22.16.4 -r1.22.16.5 src/sys/arch/mips/mips/bus_dma.c
cvs rdiff -u -r1.10 -r1.10.18.1 \
    src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c
cvs rdiff -u -r1.35.38.1 -r1.35.38.2 src/sys/arch/mips/mips/mem.c
cvs rdiff -u -r1.205.4.1.2.1.2.6 -r1.205.4.1.2.1.2.7 \
    src/sys/arch/mips/mips/mips_machdep.c
cvs rdiff -u -r1.179.16.4 -r1.179.16.5 src/sys/arch/mips/mips/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/mips/mips/bus_dma.c
diff -u src/sys/arch/mips/mips/bus_dma.c:1.22.16.4 src/sys/arch/mips/mips/bus_dma.c:1.22.16.5
--- src/sys/arch/mips/mips/bus_dma.c:1.22.16.4	Mon Sep  7 22:28:24 2009
+++ src/sys/arch/mips/mips/bus_dma.c	Tue Sep  8 08:11:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.22.16.4 2009/09/07 22:28:24 matt Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.22.16.5 2009/09/08 08:11:29 matt Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.22.16.4 2009/09/07 22:28:24 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.22.16.5 2009/09/08 08:11:29 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -660,20 +660,18 @@
 	 */
 	if (nsegs == 1) {
 #ifdef _LP64
-		if (segs[0].ds_addr + segs[0].ds_len > MIPS_PHYS_MASK) {
-			unsigned long cca;
-			if (flags & BUS_DMA_COHERENT)
-				cca = MIPS3_PG_TO_CCA(MIPS3_PG_UNCACHED);
-			else
-				cca = MIPS3_PG_TO_CCA(MIPS3_PG_CACHED);
-			*kvap = (void *)MIPS_PHYS_TO_XKPHYS(cca,
+		if (flags & BUS_DMA_COHERENT)
+			*kvap = (void *)MIPS_PHYS_TO_XKPHYS_UNCACHED(
 			    segs[0].ds_addr);
-		} else
-#endif
+		else
+			*kvap = (void *)MIPS_PHYS_TO_XKPHYS_CACHED(
+			    segs[0].ds_addr);
+#else
 		if (flags & BUS_DMA_COHERENT)
 			*kvap = (void *)MIPS_PHYS_TO_KSEG1(segs[0].ds_addr);
 		else
 			*kvap = (void *)MIPS_PHYS_TO_KSEG0(segs[0].ds_addr);
+#endif
 		return (0);
 	}
 

Index: src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c
diff -u src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c:1.10 src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c:1.10.18.1
--- src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c:1.10	Mon Apr 28 20:23:28 2008
+++ src/sys/arch/mips/mips/bus_space_alignstride_chipdep.c	Tue Sep  8 08:11:29 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_space_alignstride_chipdep.c,v 1.10 2008/04/28 20:23:28 martin Exp $ */
+/* $NetBSD: bus_space_alignstride_chipdep.c,v 1.10.18.1 2009/09/08 08:11:29 matt Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_space_alignstride_chipdep.c,v 1.10 2008/04/28 20:23:28 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_space_alignstride_chipdep.c,v 1.10.18.1 2009/09/08 08:11:29 matt Exp $");
 
 #ifdef CHIP_EXTENT
 #include <sys/extent.h>
@@ -729,12 +729,21 @@
 
  mapit:
 #endif /* CHIP_EXTENT */
+#ifdef _LP64
+	if (flags & BUS_SPACE_MAP_CACHEABLE)
+		*hp = MIPS_PHYS_TO_XKPHYS_CACHED(mbst.mbst_sys_start +
+		    (addr - mbst.mbst_bus_start));
+	else
+		*hp = MIPS_PHYS_TO_XKPHYS_UNCACHED(mbst.mbst_sys_start +
+		    (addr - mbst.mbst_bus_start));
+#else
 	if (flags & BUS_SPACE_MAP_CACHEABLE)
 		*hp = MIPS_PHYS_TO_KSEG0(mbst.mbst_sys_start +
 		    (addr - mbst.mbst_bus_start));
 	else
 		*hp = MIPS_PHYS_TO_KSEG1(mbst.mbst_sys_start +
 		    (addr - mbst.mbst_bus_start));
+#endif
 
 	return (0);
 }
@@ -753,10 +762,15 @@
 	printf("xxx: freeing handle 0x%lx for 0x%lx\n", h, size);
 #endif
 
-	if (h >= MIPS_KSEG0_START && h < MIPS_KSEG1_START)
+#ifdef _LP64
+	KASSERT(MIPS_XKPHYS_P(h));
+	h = MIPS_XKPHYS_TO_PHYS(h);
+#else
+	if (MIPS_KSEG0_P(h))
 		h = MIPS_KSEG0_TO_PHYS(h);
 	else
 		h = MIPS_KSEG1_TO_PHYS(h);
+#endif
 
 #ifdef CHIP_W1_BUS_START
 	if (h >= CHIP_W1_SYS_START(v) && h <= CHIP_W1_SYS_END(v)) {
@@ -867,12 +881,21 @@
 	}
 
 	*addrp = addr;
+#ifdef _LP64
+	if (flags & BUS_SPACE_MAP_CACHEABLE)
+		*bshp = MIPS_PHYS_TO_XKPHYS_CACHED(mbst.mbst_sys_start +
+		    (addr - mbst.mbst_bus_start));
+	else
+		*bshp = MIPS_PHYS_TO_XKPHYS_UNCACHED(mbst.mbst_sys_start +
+		    (addr - mbst.mbst_bus_start));
+#else
 	if (flags & BUS_SPACE_MAP_CACHEABLE)
 		*bshp = MIPS_PHYS_TO_KSEG0(mbst.mbst_sys_start +
 		    (addr - mbst.mbst_bus_start));
 	else
 		*bshp = MIPS_PHYS_TO_KSEG1(mbst.mbst_sys_start +
 		    (addr - mbst.mbst_bus_start));
+#endif
 
 	return (0);
 #else /* ! CHIP_EXTENT */

Index: src/sys/arch/mips/mips/mem.c
diff -u src/sys/arch/mips/mips/mem.c:1.35.38.1 src/sys/arch/mips/mips/mem.c:1.35.38.2
--- src/sys/arch/mips/mips/mem.c:1.35.38.1	Tue Sep  8 00:24:01 2009
+++ src/sys/arch/mips/mips/mem.c	Tue Sep  8 08:11:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: mem.c,v 1.35.38.1 2009/09/08 00:24:01 matt Exp $	*/
+/*	$NetBSD: mem.c,v 1.35.38.2 2009/09/08 08:11:29 matt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -80,7 +80,7 @@
 #include "opt_mips_cache.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.35.38.1 2009/09/08 00:24:01 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mem.c,v 1.35.38.2 2009/09/08 08:11:29 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -150,8 +150,7 @@
 			if (v + c > ctob(physmem))
 				return (EFAULT);
 #ifdef _LP64
-			v = MIPS_PHYS_TO_XKPHYS(
-			     MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), v);
+			v = MIPS_PHYS_TO_XKPHYS_CACHED(v);
 #else
 			v = MIPS_PHYS_TO_KSEG0(v);
 #endif

Index: src/sys/arch/mips/mips/mips_machdep.c
diff -u src/sys/arch/mips/mips/mips_machdep.c:1.205.4.1.2.1.2.6 src/sys/arch/mips/mips/mips_machdep.c:1.205.4.1.2.1.2.7
--- src/sys/arch/mips/mips/mips_machdep.c:1.205.4.1.2.1.2.6	Tue Sep  8 07:46:14 2009
+++ src/sys/arch/mips/mips/mips_machdep.c	Tue Sep  8 08:11:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: mips_machdep.c,v 1.205.4.1.2.1.2.6 2009/09/08 07:46:14 uebayasi Exp $	*/
+/*	$NetBSD: mips_machdep.c,v 1.205.4.1.2.1.2.7 2009/09/08 08:11:29 matt Exp $	*/
 
 /*
  * Copyright 2002 Wasabi Systems, Inc.
@@ -112,7 +112,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.205.4.1.2.1.2.6 2009/09/08 07:46:14 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mips_machdep.c,v 1.205.4.1.2.1.2.7 2009/09/08 08:11:29 matt Exp $");
 
 #include "opt_cputype.h"
 
@@ -202,6 +202,9 @@
 int mips_has_llsc;
 int mips_has_r4k_mmu;
 int mips3_pg_cached;
+#ifdef _LP64
+uint64_t mips3_xkphys_cached;
+#endif
 u_int mips3_pg_shift;
 
 struct	user *proc0paddr;
@@ -878,8 +881,15 @@
 		cca = (ct->cpu_flags & CPU_MIPS_CACHED_CCA_MASK) >>
 		    CPU_MIPS_CACHED_CCA_SHIFT;
 		mips3_pg_cached = MIPS3_CCA_TO_PG(cca);
-	} else
+#ifdef _LP64
+		mips3_xkphys_cached = MIPS_PHYS_TO_XKPHYS(cca, 0);
+#endif
+	} else {
 		mips3_pg_cached = MIPS3_DEFAULT_PG_CACHED;
+#ifdef _LP64
+		mips3_xkphys_cached = MIPS3_DEFAULT_XKPHYS_CACHED;
+#endif
+	}
 
 #ifdef __HAVE_MIPS_MACHDEP_CACHE_CONFIG
 	mips_machdep_cache_config();

Index: src/sys/arch/mips/mips/pmap.c
diff -u src/sys/arch/mips/mips/pmap.c:1.179.16.4 src/sys/arch/mips/mips/pmap.c:1.179.16.5
--- src/sys/arch/mips/mips/pmap.c:1.179.16.4	Mon Sep  7 22:19:53 2009
+++ src/sys/arch/mips/mips/pmap.c	Tue Sep  8 08:11:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.179.16.4 2009/09/07 22:19:53 matt Exp $	*/
+/*	$NetBSD: pmap.c,v 1.179.16.5 2009/09/08 08:11:29 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.179.16.4 2009/09/07 22:19:53 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.179.16.5 2009/09/08 08:11:29 matt Exp $");
 
 /*
  *	Manages physical address maps.
@@ -478,16 +478,15 @@
 			}
 		}
 
-		if (pa <= MIPS_PHYS_MASK)
-			va = MIPS_PHYS_TO_KSEG0(pa);
-		else
-#ifdef _LP64
-			va = MIPS_PHYS_TO_XKPHYS(
-			    MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), pa);
-#else
+		/*
+		 * We don't use XKPHYS here since we don't know what CCA
+		 * to use for cached access yet.
+		 */
+		if (pa + size > MIPS_KSEG1_START)
 			panic("pmap_steal_memory: "
 			      "pa can not be mapped into K0");
-#endif
+
+		va = MIPS_PHYS_TO_KSEG0(pa);
 		memset((void *)va, 0, size);
 		return va;
 	}
@@ -611,12 +610,11 @@
 
 		stp_pa = VM_PAGE_TO_PHYS(stp_pg);
 #ifdef _LP64
-		if (stp_pa > MIPS_PHYS_MASK)
-			stp = (struct segtab *)MIPS_PHYS_TO_XKPHYS(
-			    MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), stp_pa);
-		else
+		KASSERT(mips3_xkphys_cached);
+		stp = (struct segtab *)MIPS_PHYS_TO_XKPHYS_CACHED(stp_pa);
+#else
+		stp = (struct segtab *)MIPS_PHYS_TO_KSEG0(stp_pa);
 #endif
-			stp = (struct segtab *)MIPS_PHYS_TO_KSEG0(stp_pa);
 		pmap->pm_segtab = stp;
 		i = NBPG / sizeof(struct segtab);
 		while (--i != 0) {
@@ -687,11 +685,11 @@
 				mips_dcache_inv_range((vaddr_t)pte, PAGE_SIZE);
 #endif	/* MIPS3_PLUS */
 #ifdef _LP64
-			if (MIPS_XKPHYS_P(pte))
-				pa = MIPS_XKPHYS_TO_PHYS(pte);
-			else
+			KASSERT(MIPS_XKPHYS_P(pte));
+			pa = MIPS_XKPHYS_TO_PHYS(pte);
+#else
+			pa = MIPS_KSEG0_TO_PHYS(pte);
 #endif
-				pa = MIPS_KSEG0_TO_PHYS(pte);
 			uvm_pagefree(PHYS_TO_VM_PAGE(pa));
 
 			pmap->pm_segtab->seg_tab[i] = NULL;
@@ -1314,12 +1312,11 @@
 
 		phys = VM_PAGE_TO_PHYS(mem);
 #ifdef _LP64
-		if ((vaddr_t)pte > MIPS_PHYS_MASK)
-			pte = (pt_entry_t *)MIPS_PHYS_TO_XKPHYS(
-			    MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), phys);
-		else
+		KASSERT(mips3_xkphys_cached);
+		pte = (pt_entry_t *)MIPS_PHYS_TO_XKPHYS_CACHED(phys);
+#else
+		pte = (pt_entry_t *)MIPS_PHYS_TO_KSEG0(phys);
 #endif
-			pte = (pt_entry_t *)MIPS_PHYS_TO_KSEG0(phys);
 		pmap_segmap(pmap, va) = pte;
 #ifdef PARANOIADIAG
 	    {
@@ -1659,11 +1656,11 @@
 		printf("pmap_zero_page(%#"PRIxPADDR") nonphys\n", phys);
 #endif
 #ifdef _LP64
-	if (phys > MIPS_PHYS_MASK)
-		va = MIPS_PHYS_TO_XKPHYS(MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), phys);
-	else
+	KASSERT(mips3_xkphys_cached);
+	va = MIPS_PHYS_TO_XKPHYS_CACHED(phys);
+#else
+	va = MIPS_PHYS_TO_KSEG0(phys);
 #endif
-		va = MIPS_PHYS_TO_KSEG0(phys);
 
 #if defined(MIPS3_PLUS)	/* XXX mmu XXX */
 	pg = PHYS_TO_VM_PAGE(phys);
@@ -1704,17 +1701,13 @@
 		printf("pmap_copy_page(%#"PRIxPADDR", %#"PRIxPADDR")\n", src, dst);
 #endif
 #ifdef _LP64
-	if (src > MIPS_PHYS_MASK)
-		src_va = MIPS_PHYS_TO_XKPHYS(MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), src);
-	else
-#endif
-		src_va = MIPS_PHYS_TO_KSEG0(src);
-#ifdef _LP64
-	if (dst > MIPS_PHYS_MASK)
-		dst_va = MIPS_PHYS_TO_XKPHYS(MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), dst);
-	else
+	KASSERT(mips3_xkphys_cached);
+	src_va = MIPS_PHYS_TO_XKPHYS_CACHED(src);
+	dst_va = MIPS_PHYS_TO_XKPHYS_CACHED(dst);
+#else
+	src_va = MIPS_PHYS_TO_KSEG0(src);
+	dst_va = MIPS_PHYS_TO_KSEG0(dst);
 #endif
-		dst_va = MIPS_PHYS_TO_KSEG0(dst);
 #if !defined(_LP64) && defined(PARANOIADIAG)
 	if (!(src < MIPS_MAX_MEM_ADDR))
 		printf("pmap_copy_page(%#"PRIxPADDR") src nonphys\n", src);
@@ -2183,16 +2176,16 @@
 	vaddr_t va;
 
 	pg = uvm_pagealloc(NULL, 0, NULL, UVM_PGA_USERESERVE);
-	if (pg == NULL) {
+	if (pg == NULL)
 		return NULL;
-	}
+
 	phys = VM_PAGE_TO_PHYS(pg);
 #ifdef _LP64
-	if (phys > MIPS_PHYS_MASK)
-		va = MIPS_PHYS_TO_XKPHYS(MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), phys);
-	else
+	KASSERT(mips3_xkphys_cached);
+	va = MIPS_PHYS_TO_XKPHYS_CACHED(phys);
+#else
+	va = MIPS_PHYS_TO_KSEG0(phys);
 #endif
-		va = MIPS_PHYS_TO_KSEG0(phys);
 #if defined(MIPS3_PLUS)
 	if (mips_cache_virtual_alias) {
 		pg = PHYS_TO_VM_PAGE(phys);
@@ -2220,11 +2213,11 @@
 		mips_dcache_inv_range((vaddr_t)v, PAGE_SIZE);
 #endif
 #ifdef _LP64
-	if (MIPS_XKPHYS_P(v))
-		phys = MIPS_XKPHYS_TO_PHYS((vaddr_t)v);
-	else
+	KASSERT(MIPS_XKPHYS_P(v));
+	phys = MIPS_XKPHYS_TO_PHYS((vaddr_t)v);
+#else
+	phys = MIPS_KSEG0_TO_PHYS((vaddr_t)v);
 #endif
-		phys = MIPS_KSEG0_TO_PHYS((vaddr_t)v);
 	uvm_pagefree(PHYS_TO_VM_PAGE(phys));
 }
 
@@ -2272,12 +2265,13 @@
 	pv_entry_t pv;
 #endif
 
+#ifdef _LP64
+	KASSERT(mips3_xkphys_cached);
+	va = MIPS_PHYS_TO_XKPHYS_CACHED(pa);
+#else
 	if (pa <= MIPS_PHYS_MASK)
 		va = MIPS_PHYS_TO_KSEG0(pa);
 	else
-#ifdef _LP64
-		va = MIPS_PHYS_TO_XKPHYS(MIPS3_PG_TO_CCA(MIPS3_PG_CACHED), pa);
-#else
 		panic("mips_pmap_map_poolpage: "
 		    "pa #%"PRIxPADDR" can not be mapped into KSEG0", pa);
 #endif
@@ -2299,11 +2293,11 @@
 	paddr_t pa;
 
 #ifdef _LP64
-	if (MIPS_XKPHYS_P(va))
-		pa = MIPS_XKPHYS_TO_PHYS(va);
-	else
+	KASSERT(MIPS_XKPHYS_P(va));
+	pa = MIPS_XKPHYS_TO_PHYS(va);
+#else
+	pa = MIPS_KSEG0_TO_PHYS(va);
 #endif
-		pa = MIPS_KSEG0_TO_PHYS(va);
 #if defined(MIPS3_PLUS)
 	if (mips_cache_virtual_alias) {
 		mips_dcache_inv_range(va, PAGE_SIZE);

Reply via email to