payloads/edk2: Add Kconfig to use LAPIC timer

Core 2 platforms have issues with HPET. Enable support to use the LAPIC
driver so those machines actually boot and don't hang.

The LAPIC is actually closer to the CPU than the HPET (on the PCH),
which reduces access latency, leading to higher resolution of the timer.

Tested on a Lenovo X200 with a Core 2 Duo.

Change-Id: I33144d6c1c120e7faa47b99e8262b0997c45c9b9
Signed-off-by: Jean Lucas <jean@4ray.co>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/82000
Reviewed-by: Matt DeVillier <matt.devillier@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Nico Huber <nico.h@gmx.de>
diff --git a/payloads/external/Makefile.mk b/payloads/external/Makefile.mk
index 13703af..c227402 100644
--- a/payloads/external/Makefile.mk
+++ b/payloads/external/Makefile.mk
@@ -197,6 +197,7 @@
 		CONFIG_EDK2_DISABLE_TPM=$(CONFIG_EDK2_DISABLE_TPM) \
 		CONFIG_EDK2_UFS_ENABLE=$(CONFIG_EDK2_UFS_ENABLE) \
 		CONFIG_EDK2_PCO_MMIO_EMMC=$(CONFIG_EDK2_PCO_MMIO_EMMC) \
+		CONFIG_EDK2_USE_LAPIC_TIMER=$(CONFIG_EDK2_USE_LAPIC_TIMER) \
 		GCC_CC_x86_32=$(GCC_CC_x86_32) \
 		GCC_CC_x86_64=$(GCC_CC_x86_64) \
 		GCC_CC_arm=$(GCC_CC_arm) \
diff --git a/payloads/external/edk2/Kconfig b/payloads/external/edk2/Kconfig
index 68eb455..57e38b9 100644
--- a/payloads/external/edk2/Kconfig
+++ b/payloads/external/edk2/Kconfig
@@ -308,6 +308,15 @@
 	  It is needed for AMD Picasso boards with eMMC storage, but will conflict with the
 	  PCI-based eMMC driver, so should only be enabled for AMD Picasso boards.
 
+config EDK2_USE_LAPIC_TIMER
+	bool "Use LAPIC timer instead of HPET"
+	default n
+	help
+	  Select this option to use the LAPIC timer instead of HPET in edk2. The LAPIC is closer
+	  to the CPU than the HPET (on the PCH), resulting in lower latency / higher resolution.
+	  This setting is at least needed for platforms with Core 2 processors, which are reported
+	  to have issues with HPET.
+
 config EDK2_CUSTOM_BUILD_PARAMS
 	string "edk2 additional custom build parameters"
 	default "-D VARIABLE_SUPPORT=SMMSTORE" if EDK2_REPO_MRCHROMEBOX && SMMSTORE_V2
diff --git a/payloads/external/edk2/Makefile b/payloads/external/edk2/Makefile
index e7f11f0..4cb7f0f 100644
--- a/payloads/external/edk2/Makefile
+++ b/payloads/external/edk2/Makefile
@@ -141,6 +141,10 @@
 ifeq ($(CONFIG_EDK2_PCO_MMIO_EMMC),y)
 BUILD_STR += -D USE_PCO_MMIO_EMMC=TRUE
 endif
+# TIMER_SUPPORT			= HPET
+ifeq ($(CONFIG_EDK2_USE_LAPIC_TIMER),y)
+BUILD_STR += -D TIMER_SUPPORT=LAPIC
+endif
 
 endif
 
diff --git a/src/cpu/intel/model_1067x/Kconfig b/src/cpu/intel/model_1067x/Kconfig
index 0b5434b..721e0e9 100644
--- a/src/cpu/intel/model_1067x/Kconfig
+++ b/src/cpu/intel/model_1067x/Kconfig
@@ -11,3 +11,4 @@
 	select CPU_INTEL_COMMON
 	select CPU_INTEL_COMMON_TIMEBASE
 	select SETUP_XIP_CACHE
+	select EDK2_USE_LAPIC_TIMER if PAYLOAD_EDK2
diff --git a/src/cpu/intel/model_6fx/Kconfig b/src/cpu/intel/model_6fx/Kconfig
index d1865f6..670a70f 100644
--- a/src/cpu/intel/model_6fx/Kconfig
+++ b/src/cpu/intel/model_6fx/Kconfig
@@ -12,3 +12,4 @@
 	select CPU_INTEL_COMMON
 	select CPU_INTEL_COMMON_TIMEBASE
 	select SETUP_XIP_CACHE
+	select EDK2_USE_LAPIC_TIMER if PAYLOAD_EDK2