Module Name:    src
Committed By:   bouyer
Date:           Wed Feb 16 20:54:13 UTC 2011

Modified Files:
        src/sys/arch/x86/x86 [netbsd-5]: mtrr_i686.c

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1547):
        sys/arch/x86/x86/mtrr_i686.c: revisions 1.23, 1.24
allows overlapping uncached and cached mappings
corrects an off-by-one which prevents adjacent mappings from being setup.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.4.1 src/sys/arch/x86/x86/mtrr_i686.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/x86/x86/mtrr_i686.c
diff -u src/sys/arch/x86/x86/mtrr_i686.c:1.19 src/sys/arch/x86/x86/mtrr_i686.c:1.19.4.1
--- src/sys/arch/x86/x86/mtrr_i686.c:1.19	Mon Oct 13 10:27:10 2008
+++ src/sys/arch/x86/x86/mtrr_i686.c	Wed Feb 16 20:54:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mtrr_i686.c,v 1.19 2008/10/13 10:27:10 sborrill Exp $ */
+/*	$NetBSD: mtrr_i686.c,v 1.19.4.1 2011/02/16 20:54:13 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mtrr_i686.c,v 1.19 2008/10/13 10:27:10 sborrill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mtrr_i686.c,v 1.19.4.1 2011/02/16 20:54:13 bouyer Exp $");
 
 #include "opt_multiprocessor.h"
 
@@ -64,7 +64,7 @@
 static void i686_raw2soft(void);
 static void i686_mtrr_commit(void);
 static int i686_mtrr_setone(struct mtrr *, struct proc *p);
-
+static int i686_mtrr_conflict(uint8_t, uint8_t);
 
 static struct mtrr_state
 mtrr_raw[] = {
@@ -482,6 +482,14 @@
 	    || mtrrp->type > MTRR_TYPE_WB) && (mtrrp->flags & MTRR_VALID))
 		return EINVAL;
 
+	/* 
+	 * If write-combining is requested, make sure that the WC feature   
+	 * is supported by the processor.
+	 */
+	if (mtrrp->type == MTRR_TYPE_WC &&
+	    !(i686_mtrr_cap & MTRR_I686_CAP_WC_MASK))
+		return ENODEV;
+
 	/*
 	 * Only use fixed ranges < 1M.
 	 */
@@ -605,7 +613,7 @@
 	 * XXX could be more sophisticated here by merging ranges.
 	 */
 	low = mtrrp->base;
-	high = low + mtrrp->len;
+	high = low + mtrrp->len - 1;
 	freep = NULL;
 	for (i = 0; i < i686_mtrr_vcnt; i++) {
 		if (!(mtrr_var[i].flags & MTRR_VALID)) {
@@ -613,7 +621,7 @@
 			continue;
 		}
 		curlow = mtrr_var[i].base;
-		curhigh = curlow + mtrr_var[i].len;
+		curhigh = curlow + mtrr_var[i].len - 1;
 		if (low == curlow && high == curhigh &&
 		    (!(mtrr_var[i].flags & MTRR_PRIVATE) ||
 		     ((mtrrp->flags & MTRR_PRIVATE) && (p != NULL) &&
@@ -623,7 +631,7 @@
 		}
 		if (((high >= curlow && high < curhigh) ||
 		    (low >= curlow && low < curhigh)) &&
-	 	    ((mtrr_var[i].type != mtrrp->type) ||
+	 	    (i686_mtrr_conflict(mtrr_var[i].type, mtrrp->type) ||
 		     ((mtrr_var[i].flags & MTRR_PRIVATE) &&
  		      (!(mtrrp->flags & MTRR_PRIVATE) || (p == NULL) ||
 		       (mtrr_var[i].owner != p->p_pid))))) {
@@ -639,6 +647,17 @@
 	return 0;
 }
 
+static int
+i686_mtrr_conflict(uint8_t type1, uint8_t type2)
+{
+	if (type1 == MTRR_TYPE_UC || type2 == MTRR_TYPE_UC)
+		return 0;
+	if ((type1 == MTRR_TYPE_WT && type2 == MTRR_TYPE_WB) ||
+	    (type1 == MTRR_TYPE_WB && type2 == MTRR_TYPE_WT))
+		return 0;
+	return 1;
+}
+
 static void
 i686_mtrr_clean(struct proc *p)
 {

Reply via email to