summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authormatt <matt@NetBSD.org>2016-07-11 16:13:28 +0000
committermatt <matt@NetBSD.org>2016-07-11 16:13:28 +0000
commit388e93b5d10e1d069771de62b3f9bf4227dedb34 (patch)
tree14a91d50493a1f5d420511b1f44cf7bbbe517f30 /sys/dev
parent45501783f03926f1275107027e23a2e25d362437 (diff)
Add mm_md_page_color hook and use to support better page coloring.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/mm.c21
-rw-r--r--sys/dev/mm.h8
2 files changed, 20 insertions, 9 deletions
diff --git a/sys/dev/mm.c b/sys/dev/mm.c
index 1f2457d5d83..b168195c16c 100644
--- a/sys/dev/mm.c
+++ b/sys/dev/mm.c
@@ -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, struct iovec *iov)
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, struct iovec *iov)
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);
diff --git a/sys/dev/mm.h b/sys/dev/mm.h
index 30ae2691302..f4f2503fe01 100644
--- a/sys/dev/mm.h
+++ b/sys/dev/mm.h
@@ -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 <joerg@NetBSD.org>.
@@ -88,8 +88,10 @@ bool mm_md_direct_mapped_io(void *, paddr_t *);
/*
* 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_ */