2020-04-04 18:50:57 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2018-01-24 20:07:11 +01:00
|
|
|
|
2020-05-02 19:24:23 +02:00
|
|
|
#include <acpi/acpi.h>
|
2018-01-24 20:07:11 +01:00
|
|
|
#include <cpu/x86/mp.h>
|
|
|
|
#include <cpu/x86/msr.h>
|
2018-10-12 10:54:30 +02:00
|
|
|
#include <cpu/amd/msr.h>
|
2018-01-24 20:07:11 +01:00
|
|
|
#include <bootstate.h>
|
|
|
|
#include <console/console.h>
|
2019-10-08 18:25:57 +02:00
|
|
|
#include <amdblocks/acpi.h>
|
2018-01-24 20:07:11 +01:00
|
|
|
|
2018-04-24 10:15:30 +02:00
|
|
|
static void per_core_finalize(void *unused)
|
2018-01-24 20:07:11 +01:00
|
|
|
{
|
|
|
|
msr_t hwcr, mask;
|
|
|
|
|
|
|
|
/* Finalize SMM settings */
|
|
|
|
hwcr = rdmsr(HWCR_MSR);
|
|
|
|
if (hwcr.lo & SMM_LOCK) /* Skip if already locked, avoid GPF */
|
|
|
|
return;
|
|
|
|
|
2019-07-08 08:16:13 +02:00
|
|
|
if (CONFIG(HAVE_SMI_HANDLER)) {
|
2018-10-12 10:54:30 +02:00
|
|
|
mask = rdmsr(SMM_MASK_MSR);
|
2018-01-24 20:07:11 +01:00
|
|
|
mask.lo |= SMM_TSEG_VALID;
|
2018-10-12 10:54:30 +02:00
|
|
|
wrmsr(SMM_MASK_MSR, mask);
|
2018-01-24 20:07:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hwcr.lo |= SMM_LOCK;
|
|
|
|
wrmsr(HWCR_MSR, hwcr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void finalize_cores(void)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
printk(BIOS_SPEW, "Lock SMM configuration\n");
|
|
|
|
|
2019-07-26 14:47:32 +02:00
|
|
|
r = mp_run_on_all_cpus(per_core_finalize, NULL);
|
2018-01-24 20:07:11 +01:00
|
|
|
if (r)
|
|
|
|
printk(BIOS_WARNING, "Failed to finalize all cores\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void soc_finalize(void *unused)
|
|
|
|
{
|
|
|
|
finalize_cores();
|
|
|
|
|
2019-10-08 18:25:57 +02:00
|
|
|
if (!acpi_is_wakeup_s3()) {
|
|
|
|
if (CONFIG(HAVE_SMI_HANDLER))
|
|
|
|
acpi_disable_sci();
|
|
|
|
else
|
|
|
|
acpi_enable_sci();
|
|
|
|
}
|
|
|
|
|
2018-01-24 20:07:11 +01:00
|
|
|
post_code(POST_OS_BOOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, soc_finalize, NULL);
|
|
|
|
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, soc_finalize, NULL);
|