summaryrefslogtreecommitdiff
path: root/src/soc/amd/common/block/cpu/smm
diff options
context:
space:
mode:
Diffstat (limited to 'src/soc/amd/common/block/cpu/smm')
-rw-r--r--src/soc/amd/common/block/cpu/smm/Makefile.inc3
-rw-r--r--src/soc/amd/common/block/cpu/smm/smm_helper.c28
2 files changed, 31 insertions, 0 deletions
diff --git a/src/soc/amd/common/block/cpu/smm/Makefile.inc b/src/soc/amd/common/block/cpu/smm/Makefile.inc
index df54d93389..3008868760 100644
--- a/src/soc/amd/common/block/cpu/smm/Makefile.inc
+++ b/src/soc/amd/common/block/cpu/smm/Makefile.inc
@@ -2,7 +2,10 @@ ifeq ($(CONFIG_SOC_AMD_COMMON_BLOCK_SMM),y)
subdirs-y += ../../../../../../cpu/x86/smm
+romstage-y += smm_helper.c
+postcar-y += smm_helper.c
ramstage-y += smm_relocate.c
+ramstage-y += smm_helper.c
smm-y += smi_handler.c
endif # CONFIG_SOC_AMD_COMMON_BLOCK_SMM
diff --git a/src/soc/amd/common/block/cpu/smm/smm_helper.c b/src/soc/amd/common/block/cpu/smm/smm_helper.c
new file mode 100644
index 0000000000..bf01b8b965
--- /dev/null
+++ b/src/soc/amd/common/block/cpu/smm/smm_helper.c
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <amdblocks/smm.h>
+#include <console/console.h>
+#include <cpu/x86/msr.h>
+#include <cpu/amd/msr.h>
+
+/*
+ * For data stored in TSEG, ensure TValid is clear so R/W access can reach
+ * the DRAM when not in SMM.
+ */
+void clear_tvalid(void)
+{
+ msr_t hwcr = rdmsr(HWCR_MSR);
+ msr_t mask = rdmsr(SMM_MASK_MSR);
+ int tvalid = !!(mask.lo & SMM_TSEG_VALID);
+
+ if (hwcr.lo & SMM_LOCK) {
+ if (!tvalid) /* not valid but locked means still accessible */
+ return;
+
+ printk(BIOS_ERR, "Error: can't clear TValid, already locked\n");
+ return;
+ }
+
+ mask.lo &= ~SMM_TSEG_VALID;
+ wrmsr(SMM_MASK_MSR, mask);
+}