[coreboot-gerrit] New patch to review for coreboot: soc/intel/broadwell: Add vmx support via Kconfig option

Matt DeVillier (matt.devillier@gmail.com) gerrit at coreboot.org
Wed Dec 14 18:21:55 CET 2016


Matt DeVillier (matt.devillier at gmail.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17865

-gerrit

commit b7bf0d37a091555e7c233ce4653b6071fbbd93e6
Author: Matt DeVillier <matt.devillier at gmail.com>
Date:   Mon Mar 7 02:05:56 2016 -0600

    soc/intel/broadwell: Add vmx support via Kconfig option
    
    This patch is a copy/paste of VMX support in cpu/intel/haswell.
    Tested/verified working on google/auron, guado, samus.
    
    Change-Id: Ifa5cddafb998db4607b9ae5cff3676c3fb294d3a
    Signed-off-by: Matt DeVillier <matt.devillier at gmail.com>
---
 src/soc/intel/broadwell/Kconfig |  4 ++++
 src/soc/intel/broadwell/cpu.c   | 44 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/src/soc/intel/broadwell/Kconfig b/src/soc/intel/broadwell/Kconfig
index 75cd831..1dd4de8 100644
--- a/src/soc/intel/broadwell/Kconfig
+++ b/src/soc/intel/broadwell/Kconfig
@@ -66,6 +66,10 @@ config SERIAL_CPU_INIT
 	bool
 	default n
 
+config ENABLE_VMX
+	bool "Enable VMX for virtualization"
+	default n
+
 config SMM_TSEG_SIZE
 	hex
 	default 0x800000
diff --git a/src/soc/intel/broadwell/cpu.c b/src/soc/intel/broadwell/cpu.c
index 16f350c..beaaa73 100644
--- a/src/soc/intel/broadwell/cpu.c
+++ b/src/soc/intel/broadwell/cpu.c
@@ -41,6 +41,47 @@
 #include <soc/systemagent.h>
 #include <soc/intel/broadwell/chip.h>
 
+static void enable_vmx(void)
+{
+	struct cpuid_result regs;
+	msr_t msr;
+	int enable = IS_ENABLED(CONFIG_ENABLE_VMX);
+
+	regs = cpuid(1);
+	/* Check that the VMX is supported before reading or writing the MSR. */
+	if (!((regs.ecx & CPUID_VMX) || (regs.ecx & CPUID_SMX)))
+		return;
+
+	msr = rdmsr(IA32_FEATURE_CONTROL);
+
+	if (msr.lo & (1 << 0)) {
+		printk(BIOS_ERR, "VMX is locked, so %s will do nothing\n", __func__);
+		/* VMX locked. If we set it again we get an illegal
+		 * instruction
+		 */
+		return;
+	}
+
+	/* The IA32_FEATURE_CONTROL MSR may initialize with random values.
+	 * It must be cleared regardless of VMX config setting.
+	 */
+	msr.hi = msr.lo = 0;
+
+	printk(BIOS_DEBUG, "%s VMX\n", enable ? "Enabling" : "Disabling");
+
+	if (enable) {
+		msr.lo |= (1 << 2);
+		if (regs.ecx & CPUID_SMX)
+			msr.lo |= (1 << 1);
+	}
+
+	wrmsr(IA32_FEATURE_CONTROL, msr);
+
+	msr.lo |= (1 << 0); /* Set lock bit */
+
+	wrmsr(IA32_FEATURE_CONTROL, msr);
+}
+
 /* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */
 static const u8 power_limit_time_sec_to_msr[] = {
 	[0]   = 0x00,
@@ -580,6 +621,9 @@ static void cpu_core_init(device_t cpu)
 	enable_lapic_tpr();
 	setup_lapic();
 
+	/* Enable virtualization if Kconfig option is set */
+	enable_vmx();
+
 	/* Configure C States */
 	configure_c_states();
 



More information about the coreboot-gerrit mailing list