2 * This file is part of the coreboot project.
4 * Copyright (C) 2018 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <cpu/x86/mp.h>
17 #include <cpu/x86/msr.h>
18 #include <cpu/amd/msr.h>
19 #include <bootstate.h>
21 #include <console/console.h>
23 static void per_core_finalize(void *unused
)
27 /* Finalize SMM settings */
28 hwcr
= rdmsr(HWCR_MSR
);
29 if (hwcr
.lo
& SMM_LOCK
) /* Skip if already locked, avoid GPF */
32 if (IS_ENABLED(CONFIG_SMM_TSEG
)) {
33 mask
= rdmsr(SMM_MASK_MSR
);
34 mask
.lo
|= SMM_TSEG_VALID
;
35 wrmsr(SMM_MASK_MSR
, mask
);
39 wrmsr(HWCR_MSR
, hwcr
);
42 static void finalize_cores(void)
45 printk(BIOS_SPEW
, "Lock SMM configuration\n");
47 r
= mp_run_on_all_cpus(per_core_finalize
, NULL
, 10 * USECS_PER_MSEC
);
49 printk(BIOS_WARNING
, "Failed to finalize all cores\n");
52 static void soc_finalize(void *unused
)
56 post_code(POST_OS_BOOT
);
59 BOOT_STATE_INIT_ENTRY(BS_OS_RESUME
, BS_ON_ENTRY
, soc_finalize
, NULL
);
60 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD
, BS_ON_EXIT
, soc_finalize
, NULL
);