[coreboot-gerrit] New patch to review for coreboot: mtrr: Define a function for obtaining free var mtrr

Furquan Shaikh (furquan@google.com) gerrit at coreboot.org
Thu Mar 17 00:13:43 CET 2016


Furquan Shaikh (furquan at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14115

-gerrit

commit 6557c4b6ef689a441df5fad0d25a1190a3322a47
Author: Furquan Shaikh <furquan at google.com>
Date:   Wed Mar 16 16:12:06 2016 -0700

    mtrr: Define a function for obtaining free var mtrr
    
    Instead of hard-coding var mtrr numbers in code, use this function to
    identify the first available variable mtrr. If no such mtrr is
    available, the function will return -1.
    
    Change-Id: I2a1e02cdb45c0ab7e30609641977471eaa2431fd
    Signed-off-by: Furquan Shaikh <furquan at google.com>
---
 src/cpu/x86/mtrr/earlymtrr.c | 24 ++++++++++++++++++++++++
 src/include/cpu/x86/mtrr.h   |  1 +
 2 files changed, 25 insertions(+)

diff --git a/src/cpu/x86/mtrr/earlymtrr.c b/src/cpu/x86/mtrr/earlymtrr.c
index a84ecf8..54c09c0 100644
--- a/src/cpu/x86/mtrr/earlymtrr.c
+++ b/src/cpu/x86/mtrr/earlymtrr.c
@@ -2,6 +2,30 @@
 #include <cpu/x86/mtrr.h>
 #include <cpu/x86/msr.h>
 
+/* Get first available variable MTRR.
+ * Returns var# if available, else returns -1.
+ */
+int get_free_var_mtrr(void)
+{
+	msr_t msr, maskm;
+	int vcnt;
+	int i;
+
+	/* Read MTRRCap and get vcnt - variable memory type ranges. */
+	msr = rdmsr(MTRR_CAP_MSR);
+	vcnt = msr.lo & 0xff;
+
+	/* Identify the first var mtrr which is not valid. */
+	for (i = 0; i < vcn5Bt; i++) {
+		maskm = rdmsr(MTRR_PHYS_MASK(i));
+		if (maskm.lo & MTRR_PHYS_MASK_VALID)
+			return i;
+	}
+
+	/* No free var mtrr. */
+	return -1;
+}
+
 #ifdef __ROMCC__
 static
 #endif
diff --git a/src/include/cpu/x86/mtrr.h b/src/include/cpu/x86/mtrr.h
index d158735..4eb4f13 100644
--- a/src/include/cpu/x86/mtrr.h
+++ b/src/include/cpu/x86/mtrr.h
@@ -81,6 +81,7 @@ void x86_mtrr_check(void);
 
 #if !defined(__ASSEMBLER__) && defined(__PRE_RAM__) && !defined(__ROMCC__)
 void set_var_mtrr(unsigned reg, unsigned base, unsigned size, unsigned type);
+int get_free_var_mtrr(void);
 #endif
 
 /* Align up to next power of 2, suitable for ROMCC and assembler too.



More information about the coreboot-gerrit mailing list