cpu/amd: Use common AMD's MSR
[coreboot.git] / src / soc / amd / stoneyridge / finalize.c
blob45e659504bf7f686f37cfb5d56f486974ad97de2
1 /*
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>
20 #include <timer.h>
21 #include <console/console.h>
23 static void per_core_finalize(void *unused)
25 msr_t hwcr, mask;
27 /* Finalize SMM settings */
28 hwcr = rdmsr(HWCR_MSR);
29 if (hwcr.lo & SMM_LOCK) /* Skip if already locked, avoid GPF */
30 return;
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);
38 hwcr.lo |= SMM_LOCK;
39 wrmsr(HWCR_MSR, hwcr);
42 static void finalize_cores(void)
44 int r;
45 printk(BIOS_SPEW, "Lock SMM configuration\n");
47 r = mp_run_on_all_cpus(per_core_finalize, NULL, 10 * USECS_PER_MSEC);
48 if (r)
49 printk(BIOS_WARNING, "Failed to finalize all cores\n");
52 static void soc_finalize(void *unused)
54 finalize_cores();
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);