blob: bf01b8b965f2d08b49e059601cc22e3716abbfcc [file] [log] [blame]
Felix Helda90854d2021-02-10 04:05:27 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <amdblocks/smm.h>
4#include <console/console.h>
5#include <cpu/x86/msr.h>
6#include <cpu/amd/msr.h>
7
8/*
9 * For data stored in TSEG, ensure TValid is clear so R/W access can reach
10 * the DRAM when not in SMM.
11 */
12void clear_tvalid(void)
13{
14 msr_t hwcr = rdmsr(HWCR_MSR);
15 msr_t mask = rdmsr(SMM_MASK_MSR);
16 int tvalid = !!(mask.lo & SMM_TSEG_VALID);
17
18 if (hwcr.lo & SMM_LOCK) {
19 if (!tvalid) /* not valid but locked means still accessible */
20 return;
21
22 printk(BIOS_ERR, "Error: can't clear TValid, already locked\n");
23 return;
24 }
25
26 mask.lo &= ~SMM_TSEG_VALID;
27 wrmsr(SMM_MASK_MSR, mask);
28}