Module Name:    src
Committed By:   matt
Date:           Mon Jul 11 16:13:28 UTC 2016

Modified Files:
        src/sys/dev: mm.c mm.h

Log Message:
Add mm_md_page_color hook and use to support better page coloring.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/mm.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/mm.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/dev/mm.c
diff -u src/sys/dev/mm.c:1.20 src/sys/dev/mm.c:1.21
--- src/sys/dev/mm.c:1.20	Sun Jan 17 23:17:04 2016
+++ src/sys/dev/mm.c	Mon Jul 11 16:13:28 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mm.c,v 1.20 2016/01/17 23:17:04 christos Exp $	*/
+/*	$NetBSD: mm.c,v 1.21 2016/07/11 16:13:28 matt Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2008, 2010 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mm.c,v 1.20 2016/01/17 23:17:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mm.c,v 1.21 2016/07/11 16:13:28 matt Exp $");
 
 #include "opt_compat_netbsd.h"
 
@@ -128,11 +128,11 @@ mm_init(void)
  * constant, general mapping address otherwise.
  */
 static inline vaddr_t
-dev_mem_getva(paddr_t pa)
+dev_mem_getva(paddr_t pa, int color)
 {
 #ifdef __HAVE_MM_MD_CACHE_ALIASING
 	return uvm_km_alloc(kernel_map, PAGE_SIZE,
-	    atop(pa) & uvmexp.colormask,
+	    color & uvmexp.colormask,
 	    UVM_KMF_VAONLY | UVM_KMF_WAITVA | UVM_KMF_COLORMATCH);
 #else
 	return dev_mem_addr;
@@ -161,6 +161,7 @@ dev_mem_readwrite(struct uio *uio, struc
 	size_t len, offset;
 	bool have_direct;
 	int error;
+	int color = 0;
 
 	/* Check for wrap around. */
 	if ((intptr_t)uio->uio_offset != uio->uio_offset) {
@@ -175,16 +176,24 @@ dev_mem_readwrite(struct uio *uio, struc
 	offset = uio->uio_offset & PAGE_MASK;
 	len = MIN(uio->uio_resid, PAGE_SIZE - offset);
 
+#ifdef __HAVE_MM_MD_CACHE_ALIASING
+	have_direct = mm_md_page_color(paddr, &color);
+#else
+	have_direct = true;
+	color = 0;
+#endif
+
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 	/* Is physical address directly mapped?  Return VA. */
-	have_direct = mm_md_direct_mapped_phys(paddr, &vaddr);
+	if (have_direct)
+		have_direct = mm_md_direct_mapped_phys(paddr, &vaddr);
 #else
 	vaddr = 0;
 	have_direct = false;
 #endif
 	if (!have_direct) {
 		/* Get a special virtual address. */
-		const vaddr_t va = dev_mem_getva(paddr);
+		const vaddr_t va = dev_mem_getva(paddr, color);
 
 		/* Map selected KVA to physical address. */
 		mutex_enter(&dev_mem_lock);

Index: src/sys/dev/mm.h
diff -u src/sys/dev/mm.h:1.2 src/sys/dev/mm.h:1.3
--- src/sys/dev/mm.h:1.2	Sun Jun 12 03:35:51 2011
+++ src/sys/dev/mm.h	Mon Jul 11 16:13:28 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mm.h,v 1.2 2011/06/12 03:35:51 rmind Exp $	*/
+/*	$NetBSD: mm.h,v 1.3 2016/07/11 16:13:28 matt Exp $	*/
 
 /*-
  * Copyright (c) 2008 Joerg Sonnenberger <[email protected]>.
@@ -88,8 +88,10 @@ bool	mm_md_direct_mapped_io(void *, padd
 
 /*
  * Some architectures may need to deal with cache aliasing issues.
- *
- * machine/types.h must define __HAVE_MM_MD_CACHE_ALIASING to note that.
+ * Optional hook to fetch a page's current color and returns whether
+ * that page can be direct mapped.
+ * machine/types.h must define __HAVE_MM_MD_CACHE_ALIASING to use this.
  */
+bool	mm_md_page_color(paddr_t, int *);
 
 #endif /* _SYS_DEV_MM_H_ */

Reply via email to