cpu/amd: Add common helpers for TSEG and SMM
Change-Id: I73174766980e0405e7b8efd4f059bb400c0c0a25
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/64866
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
diff --git a/src/cpu/amd/agesa/Makefile.inc b/src/cpu/amd/agesa/Makefile.inc
index 1f9cca5..ac16e00 100644
--- a/src/cpu/amd/agesa/Makefile.inc
+++ b/src/cpu/amd/agesa/Makefile.inc
@@ -3,3 +3,7 @@
subdirs-$(CONFIG_CPU_AMD_AGESA_FAMILY14) += family14
subdirs-$(CONFIG_CPU_AMD_AGESA_FAMILY15_TN) += family15tn
subdirs-$(CONFIG_CPU_AMD_AGESA_FAMILY16_KB) += family16kb
+
+romstage-y += ../../../soc/amd/common/block/cpu/smm/smm_helper.c
+postcar-y += ../../../soc/amd/common/block/cpu/smm/smm_helper.c
+ramstage-y += ../../../soc/amd/common/block/cpu/smm/smm_helper.c
diff --git a/src/cpu/amd/agesa/family14/model_14_init.c b/src/cpu/amd/agesa/family14/model_14_init.c
index 41fa1ef..21ef584 100644
--- a/src/cpu/amd/agesa/family14/model_14_init.c
+++ b/src/cpu/amd/agesa/family14/model_14_init.c
@@ -1,14 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#include <acpi/acpi.h>
+#include <amdblocks/smm.h>
#include <console/console.h>
-#include <cpu/x86/msr.h>
#include <cpu/amd/msr.h>
-#include <cpu/x86/mtrr.h>
#include <cpu/amd/mtrr.h>
-#include <device/device.h>
#include <cpu/cpu.h>
#include <cpu/x86/cache.h>
-#include <acpi/acpi.h>
+#include <cpu/x86/msr.h>
+#include <cpu/x86/mtrr.h>
+#include <device/device.h>
#include <northbridge/amd/agesa/agesa_helper.h>
static void model_14_init(struct device *dev)
@@ -76,9 +77,7 @@
wrmsr(NB_CFG_MSR, msr);
/* Write protect SMM space with SMMLOCK. */
- msr = rdmsr(HWCR_MSR);
- msr.lo |= (1 << 0);
- wrmsr(HWCR_MSR, msr);
+ lock_smm();
}
static struct device_operations cpu_dev_ops = {
diff --git a/src/cpu/amd/agesa/family15tn/model_15_init.c b/src/cpu/amd/agesa/family15tn/model_15_init.c
index e246383..de44230 100644
--- a/src/cpu/amd/agesa/family15tn/model_15_init.c
+++ b/src/cpu/amd/agesa/family15tn/model_15_init.c
@@ -1,15 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#include <acpi/acpi.h>
+#include <amdblocks/smm.h>
#include <console/console.h>
-#include <cpu/x86/msr.h>
#include <cpu/amd/msr.h>
-#include <cpu/x86/mtrr.h>
#include <cpu/amd/mtrr.h>
-#include <cpu/x86/smm.h>
-#include <device/device.h>
#include <cpu/cpu.h>
#include <cpu/x86/cache.h>
-#include <acpi/acpi.h>
+#include <cpu/x86/msr.h>
+#include <cpu/x86/mtrr.h>
+#include <cpu/x86/smm.h>
+#include <device/device.h>
#include <northbridge/amd/agesa/agesa_helper.h>
static void model_15_init(struct device *dev)
@@ -93,9 +94,7 @@
}
/* Write protect SMM space with SMMLOCK. */
- msr = rdmsr(HWCR_MSR);
- msr.lo |= (1 << 0);
- wrmsr(HWCR_MSR, msr);
+ lock_smm();
}
static struct device_operations cpu_dev_ops = {
diff --git a/src/cpu/amd/agesa/family16kb/model_16_init.c b/src/cpu/amd/agesa/family16kb/model_16_init.c
index 3c2202a..3698a8f 100644
--- a/src/cpu/amd/agesa/family16kb/model_16_init.c
+++ b/src/cpu/amd/agesa/family16kb/model_16_init.c
@@ -1,14 +1,15 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#include <acpi/acpi.h>
+#include <amdblocks/smm.h>
#include <console/console.h>
-#include <cpu/x86/msr.h>
#include <cpu/amd/msr.h>
-#include <cpu/x86/mtrr.h>
#include <cpu/amd/mtrr.h>
-#include <device/device.h>
#include <cpu/cpu.h>
#include <cpu/x86/cache.h>
-#include <acpi/acpi.h>
+#include <cpu/x86/msr.h>
+#include <cpu/x86/mtrr.h>
+#include <device/device.h>
#include <northbridge/amd/agesa/agesa_helper.h>
static void model_16_init(struct device *dev)
@@ -76,9 +77,7 @@
wrmsr(NB_CFG_MSR, msr);
/* Write protect SMM space with SMMLOCK. */
- msr = rdmsr(HWCR_MSR);
- msr.lo |= (1 << 0);
- wrmsr(HWCR_MSR, msr);
+ lock_smm();
}
static struct device_operations cpu_dev_ops = {
diff --git a/src/cpu/amd/pi/00730F01/model_16_init.c b/src/cpu/amd/pi/00730F01/model_16_init.c
index 1a9a2e3..a33b5f3 100644
--- a/src/cpu/amd/pi/00730F01/model_16_init.c
+++ b/src/cpu/amd/pi/00730F01/model_16_init.c
@@ -1,16 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0-only */
+#include <amdblocks/smm.h>
#include <commonlib/helpers.h>
#include <console/console.h>
#include <cpu/amd/microcode.h>
-#include <cpu/x86/msr.h>
#include <cpu/amd/msr.h>
-#include <cpu/x86/mtrr.h>
#include <cpu/amd/mtrr.h>
-#include <device/device.h>
-#include <device/pci.h>
#include <cpu/cpu.h>
#include <cpu/x86/cache.h>
+#include <cpu/x86/msr.h>
+#include <cpu/x86/mtrr.h>
+#include <device/device.h>
+#include <device/pci.h>
#include <smp/node.h>
static void model_16_init(struct device *dev)
@@ -44,9 +45,7 @@
wrmsr(NB_CFG_MSR, msr);
/* Write protect SMM space with SMMLOCK. */
- msr = rdmsr(HWCR_MSR);
- msr.lo |= (1 << 0);
- wrmsr(HWCR_MSR, msr);
+ lock_smm();
amd_update_microcode_from_cbfs();
diff --git a/src/cpu/amd/pi/Makefile.inc b/src/cpu/amd/pi/Makefile.inc
index ae04253..ad62e4d 100644
--- a/src/cpu/amd/pi/Makefile.inc
+++ b/src/cpu/amd/pi/Makefile.inc
@@ -1,3 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
subdirs-$(CONFIG_CPU_AMD_PI_00730F01) += 00730F01
+
+romstage-y += ../../../soc/amd/common/block/cpu/smm/smm_helper.c
+postcar-y += ../../../soc/amd/common/block/cpu/smm/smm_helper.c
+ramstage-y += ../../../soc/amd/common/block/cpu/smm/smm_helper.c