Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <bootstate.h> |
| 4 | #include <console/console.h> |
| 5 | #include <console/debug.h> |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 6 | #include <cpu/x86/mp.h> |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 7 | #include <cpu/x86/smm.h> |
Marc Jones | d77b97d | 2021-04-06 15:28:40 -0600 | [diff] [blame] | 8 | #include <device/pci.h> |
| 9 | #include <intelpch/lockdown.h> |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 10 | #include <soc/msr.h> |
Marc Jones | d77b97d | 2021-04-06 15:28:40 -0600 | [diff] [blame] | 11 | #include <soc/pci_devs.h> |
Michael Niewöhner | 6b93866 | 2021-09-24 23:57:37 +0200 | [diff] [blame] | 12 | #include <soc/pm.h> |
Marc Jones | d77b97d | 2021-04-06 15:28:40 -0600 | [diff] [blame] | 13 | #include <soc/util.h> |
Tim Chu | 1854500 | 2022-12-16 10:19:54 +0000 | [diff] [blame^] | 14 | #include <soc/soc_util.h> |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 15 | #include <smp/spinlock.h> |
Marc Jones | d77b97d | 2021-04-06 15:28:40 -0600 | [diff] [blame] | 16 | |
| 17 | #include "chip.h" |
| 18 | |
| 19 | static 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 Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 29 | |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 30 | DECLARE_SPIN_LOCK(msr_ppin_lock); |
| 31 | |
| 32 | static 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 Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 56 | static void soc_finalize(void *unused) |
| 57 | { |
| 58 | printk(BIOS_DEBUG, "Finalizing chipset.\n"); |
| 59 | |
Michael Niewöhner | 6b93866 | 2021-09-24 23:57:37 +0200 | [diff] [blame] | 60 | /* |
| 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 Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 73 | apm_control(APM_CNT_FINALIZE); |
Marc Jones | d77b97d | 2021-04-06 15:28:40 -0600 | [diff] [blame] | 74 | lock_pam0123(); |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 75 | |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 76 | 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 Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 84 | post_code(POST_OS_BOOT); |
| 85 | } |
| 86 | |
Tim Chu | 1854500 | 2022-12-16 10:19:54 +0000 | [diff] [blame^] | 87 | static 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 Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 99 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_ENTRY, soc_finalize, NULL); |
Tim Chu | 1854500 | 2022-12-16 10:19:54 +0000 | [diff] [blame^] | 100 | /* 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. */ |
| 102 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, bios_done_finalize, NULL); |