blob: 6b8395c783603554f314ba4d0bd5765851300a4b [file] [log] [blame]
Marc Jones352ca5b2021-03-18 17:01:06 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <bootstate.h>
4#include <console/console.h>
5#include <console/debug.h>
Tim Chu8e4500a2022-12-16 08:45:53 +00006#include <cpu/x86/mp.h>
Marc Jones352ca5b2021-03-18 17:01:06 -06007#include <cpu/x86/smm.h>
Marc Jonesd77b97d2021-04-06 15:28:40 -06008#include <device/pci.h>
9#include <intelpch/lockdown.h>
Tim Chu8e4500a2022-12-16 08:45:53 +000010#include <soc/msr.h>
Marc Jonesd77b97d2021-04-06 15:28:40 -060011#include <soc/pci_devs.h>
Michael Niewöhner6b938662021-09-24 23:57:37 +020012#include <soc/pm.h>
Marc Jonesd77b97d2021-04-06 15:28:40 -060013#include <soc/util.h>
Tim Chu18545002022-12-16 10:19:54 +000014#include <soc/soc_util.h>
Tim Chu8e4500a2022-12-16 08:45:53 +000015#include <smp/spinlock.h>
Marc Jonesd77b97d2021-04-06 15:28:40 -060016
17#include "chip.h"
18
19static void lock_pam0123(void)
20{
21 const struct device *dev;
22
23 if (get_lockdown_config() != CHIPSET_LOCKDOWN_COREBOOT)
24 return;
25
26 dev = pcidev_path_on_bus(get_stack_busno(1), PCI_DEVFN(SAD_ALL_DEV, SAD_ALL_FUNC));
27 pci_or_config32(dev, SAD_ALL_PAM0123_CSR, PAM_LOCK);
28}
Marc Jones352ca5b2021-03-18 17:01:06 -060029
Tim Chu8e4500a2022-12-16 08:45:53 +000030DECLARE_SPIN_LOCK(msr_ppin_lock);
31
32static void lock_msr_ppin_ctl(void *unused)
33{
34 msr_t msr;
35
36 msr = rdmsr(MSR_PLATFORM_INFO);
37 if ((msr.lo & MSR_PPIN_CAP) == 0)
38 return;
39
40 spin_lock(&msr_ppin_lock);
41
42 msr = rdmsr(MSR_PPIN_CTL);
43 if (msr.lo & MSR_PPIN_CTL_LOCK) {
44 spin_unlock(&msr_ppin_lock);
45 return;
46 }
47
48 /* Clear enable and lock it */
49 msr.lo &= ~MSR_PPIN_CTL_ENABLE;
50 msr.lo |= MSR_PPIN_CTL_LOCK;
51 wrmsr(MSR_PPIN_CTL, msr);
52
53 spin_unlock(&msr_ppin_lock);
54}
55
Marc Jones352ca5b2021-03-18 17:01:06 -060056static void soc_finalize(void *unused)
57{
58 printk(BIOS_DEBUG, "Finalizing chipset.\n");
59
Michael Niewöhner6b938662021-09-24 23:57:37 +020060 /*
61 * Disable ACPI PM timer based on Kconfig
62 *
63 * Disabling ACPI PM timer is necessary for XTAL OSC shutdown.
64 * Disabling ACPI PM timer also switches off TCO.
65 *
66 * Note: In contrast to other platforms supporting PM timer emulation,
67 * disabling the PM timer must be done *after* FSP has run on Xeon-SP,
68 * because FSP makes use of the PM timer.
69 */
70 if (!CONFIG(USE_PM_ACPI_TIMER))
71 setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS);
72
Marc Jones352ca5b2021-03-18 17:01:06 -060073 apm_control(APM_CNT_FINALIZE);
Marc Jonesd77b97d2021-04-06 15:28:40 -060074 lock_pam0123();
Marc Jones352ca5b2021-03-18 17:01:06 -060075
Tim Chu8e4500a2022-12-16 08:45:53 +000076 if (CONFIG_MAX_SOCKET > 1) {
77 /* This MSR is package scope but run for all cpus for code simplicity */
78 if (mp_run_on_all_cpus(&lock_msr_ppin_ctl, NULL) != CB_SUCCESS)
79 printk(BIOS_ERR, "Lock PPIN CTL MSR failed\n");
80 } else {
81 lock_msr_ppin_ctl(NULL);
82 }
83
Marc Jones352ca5b2021-03-18 17:01:06 -060084 post_code(POST_OS_BOOT);
85}
86
Tim Chu18545002022-12-16 10:19:54 +000087static void bios_done_finalize(void *unused)
88{
89 if (!CONFIG(SOC_INTEL_HAS_BIOS_DONE_MSR))
90 return;
91
92 printk(BIOS_DEBUG, "Setting BIOS_DONE\n");
93 /* bios_done_msr() only defined for some Xeon-SP, such as SPR-SP */
94 if (mp_run_on_all_cpus(&bios_done_msr, NULL) != CB_SUCCESS)
95 printk(BIOS_ERR, "Fail to set BIOS_DONE MSR\n");
96
97}
98
Marc Jones352ca5b2021-03-18 17:01:06 -060099BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_ENTRY, soc_finalize, NULL);
Tim Chu18545002022-12-16 10:19:54 +0000100/* FSP programs certain registers via Notify phase ReadyToBoot that can only be programmed
101 before BIOS_DONE MSR is set, so coreboot sets BIOS_DONE as late as possible. */
102BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, bios_done_finalize, NULL);