Wolf: haswell: Add small delay before Flex Ratio reboot

cherry picked from commit fee36012a575f84032c7f567a5a2107a031b0534

BUG=chrome-os-partner:41609
TEST="emerge-wolf coreboot"

Change-Id: I4acb4e7282b26383ce164f1f6866adee3393945c
Signed-off-by: Mohammed Habibulla <moch@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/289680
Commit-Queue: Mohammed Habibulla <moch@google.com>
Tested-by: Mohammed Habibulla <moch@google.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
diff --git a/src/cpu/intel/haswell/bootblock.c b/src/cpu/intel/haswell/bootblock.c
index e502cfa..7e6c4eb 100644
--- a/src/cpu/intel/haswell/bootblock.c
+++ b/src/cpu/intel/haswell/bootblock.c
@@ -64,6 +64,17 @@
 	wrmsr(MTRRdefType_MSR, msr);
 }
 
+static void bootblock_mdelay(int ms)
+{
+	u32 target = ms * 24 * 1000;
+	msr_t current;
+	msr_t start = rdmsr(MSR_COUNTER_24_MHz);
+
+	do {
+		current = rdmsr(MSR_COUNTER_24_MHz);
+	} while ((current.lo - start.lo) < target);
+}
+
 static void set_flex_ratio_to_tdp_nominal(void)
 {
 	msr_t flex_ratio, msr;
@@ -101,6 +112,9 @@
 	soft_reset |= (nominal_ratio & 0x3f) << 6;
 	RCBA32(SOFT_RESET_DATA) = soft_reset;
 
+	/* Delay before reset to avoid potential TPM lockout */
+	bootblock_mdelay(30);
+
 	/* Set soft reset control to use register value */
 	RCBA32_OR(SOFT_RESET_CTRL, 1);
 
diff --git a/src/cpu/intel/haswell/haswell.h b/src/cpu/intel/haswell/haswell.h
index fb464d0..2478b2f 100644
--- a/src/cpu/intel/haswell/haswell.h
+++ b/src/cpu/intel/haswell/haswell.h
@@ -148,6 +148,8 @@
 #define RESERVED_SMM_OFFSET \
 	(CONFIG_SMM_TSEG_SIZE - CONFIG_IED_REGION_SIZE - RESERVED_SMM_SIZE)
 
+#define MSR_COUNTER_24_MHz		0x637
+
 /* Sanity check config options. */
 #if (CONFIG_SMM_TSEG_SIZE <= (CONFIG_IED_REGION_SIZE + RESERVED_SMM_SIZE))
 # error "CONFIG_SMM_TSEG_SIZE <= (CONFIG_IED_REGION_SIZE + RESERVED_SMM_SIZE)"
diff --git a/src/cpu/intel/haswell/monotonic_timer.c b/src/cpu/intel/haswell/monotonic_timer.c
index c51bcbd..0c8e34b 100644
--- a/src/cpu/intel/haswell/monotonic_timer.c
+++ b/src/cpu/intel/haswell/monotonic_timer.c
@@ -19,8 +19,8 @@
 #include <stdint.h>
 #include <cpu/x86/msr.h>
 #include <timer.h>
+#include "haswell.h"
 
-#define MSR_COUNTER_24_MHz 0x637
 static struct monotonic_counter {
 	int initialized;
 	struct mono_time time;