[PATCH][RFC] bios: mtrr: check MTRR default memory type

Alex Hung alex.hung at canonical.com
Fri Jul 15 07:02:54 UTC 2016


IA32_MTRR_DEF_TYPE MSR specifies default properties of memory ranges
and it is checked by kernel during MTRR initialization. The result
of kernel message is used as default value when checking MTRR setup.

Signed-off-by: Alex Hung <alex.hung at canonical.com>
---
 src/bios/mtrr/mtrr.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
index 18e1a29..f685c1c 100644
--- a/src/bios/mtrr/mtrr.c
+++ b/src/bios/mtrr/mtrr.c
@@ -49,6 +49,8 @@ static fwts_cpuinfo_x86 *fwts_cpuinfo;
 #define DISABLED	0x0040
 #define UNKNOWN		0x0080
 
+uint8_t mtrr_default = UNCACHED;
+
 struct mtrr_entry {
 	uint8_t  reg;
 	uint64_t start;
@@ -198,6 +200,12 @@ restart:
 	/* if there is no full coverage it's also uncached */
 	if (start != end)
 		type |= DEFAULT;
+
+	if ((type & DEFAULT) && mtrr_default != UNCACHED) {
+		type &= ~DEFAULT;
+		type |= mtrr_default;
+	}
+
 	return type;
 }
 
@@ -442,8 +450,33 @@ static void do_mtrr_resource(fwts_framework *fw)
 	fwts_log_nl(fw);
 }
 
+static void check_mtrr_default(fwts_framework *fw,
+	char *line, int repeated, char *prevline, void *private, int *errors)
+{
+	FWTS_UNUSED(fw);
+	FWTS_UNUSED(repeated);
+	FWTS_UNUSED(prevline);
+	FWTS_UNUSED(private);
+	FWTS_UNUSED(errors);
+
+	if (strstr(line, "MTRR default type:")) {
+		if (strstr(line, "write-back"))
+			mtrr_default = WRITE_BACK;
+		else if (strstr(line, "uncachable"))
+			mtrr_default = UNCACHED;
+		else if (strstr(line, "write-through"))
+			mtrr_default = WRITE_THROUGH;
+		else if (strstr(line, "write-combining"))
+			mtrr_default = WRITE_COMBINING;
+		else if (strstr(line, "write-protect"))
+			mtrr_default = WRITE_PROTECT;
+	}
+}
+
 static int mtrr_init(fwts_framework *fw)
 {
+	int errors = 0;
+
 	if (get_mtrrs() != FWTS_OK) {
 		fwts_log_error(fw, "Failed to read /proc/mtrr.");
 		return FWTS_ERROR;
@@ -464,6 +497,8 @@ static int mtrr_init(fwts_framework *fw)
 
 	do_mtrr_resource(fw);
 
+	fwts_klog_scan(fw, klog, check_mtrr_default, NULL, NULL, &errors);
+
 	return FWTS_OK;
 }
 
-- 
2.7.4




More information about the fwts-devel mailing list