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 | |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 19 | DECLARE_SPIN_LOCK(msr_ppin_lock); |
| 20 | |
| 21 | static void lock_msr_ppin_ctl(void *unused) |
| 22 | { |
| 23 | msr_t msr; |
| 24 | |
| 25 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 26 | if ((msr.lo & MSR_PPIN_CAP) == 0) |
| 27 | return; |
| 28 | |
| 29 | spin_lock(&msr_ppin_lock); |
| 30 | |
| 31 | msr = rdmsr(MSR_PPIN_CTL); |
| 32 | if (msr.lo & MSR_PPIN_CTL_LOCK) { |
| 33 | spin_unlock(&msr_ppin_lock); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | /* Clear enable and lock it */ |
| 38 | msr.lo &= ~MSR_PPIN_CTL_ENABLE; |
| 39 | msr.lo |= MSR_PPIN_CTL_LOCK; |
| 40 | wrmsr(MSR_PPIN_CTL, msr); |
| 41 | |
| 42 | spin_unlock(&msr_ppin_lock); |
| 43 | } |
| 44 | |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 45 | static void soc_finalize(void *unused) |
| 46 | { |
| 47 | printk(BIOS_DEBUG, "Finalizing chipset.\n"); |
| 48 | |
Michael Niewöhner | 6b93866 | 2021-09-24 23:57:37 +0200 | [diff] [blame] | 49 | /* |
| 50 | * Disable ACPI PM timer based on Kconfig |
| 51 | * |
| 52 | * Disabling ACPI PM timer is necessary for XTAL OSC shutdown. |
| 53 | * Disabling ACPI PM timer also switches off TCO. |
| 54 | * |
| 55 | * Note: In contrast to other platforms supporting PM timer emulation, |
| 56 | * disabling the PM timer must be done *after* FSP has run on Xeon-SP, |
| 57 | * because FSP makes use of the PM timer. |
| 58 | */ |
| 59 | if (!CONFIG(USE_PM_ACPI_TIMER)) |
| 60 | setbits8(pmc_mmio_regs() + PCH_PWRM_ACPI_TMR_CTL, ACPI_TIM_DIS); |
| 61 | |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 62 | apm_control(APM_CNT_FINALIZE); |
Marc Jones | d77b97d | 2021-04-06 15:28:40 -0600 | [diff] [blame] | 63 | lock_pam0123(); |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 64 | |
Tim Chu | 8e4500a | 2022-12-16 08:45:53 +0000 | [diff] [blame] | 65 | if (CONFIG_MAX_SOCKET > 1) { |
| 66 | /* This MSR is package scope but run for all cpus for code simplicity */ |
| 67 | if (mp_run_on_all_cpus(&lock_msr_ppin_ctl, NULL) != CB_SUCCESS) |
| 68 | printk(BIOS_ERR, "Lock PPIN CTL MSR failed\n"); |
| 69 | } else { |
| 70 | lock_msr_ppin_ctl(NULL); |
| 71 | } |
| 72 | |
lilacious | 40cb3fe | 2023-06-21 23:24:14 +0200 | [diff] [blame] | 73 | post_code(POSTCODE_OS_BOOT); |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 74 | } |
| 75 | |
Tim Chu | 1854500 | 2022-12-16 10:19:54 +0000 | [diff] [blame] | 76 | static void bios_done_finalize(void *unused) |
| 77 | { |
| 78 | if (!CONFIG(SOC_INTEL_HAS_BIOS_DONE_MSR)) |
| 79 | return; |
| 80 | |
| 81 | printk(BIOS_DEBUG, "Setting BIOS_DONE\n"); |
| 82 | /* bios_done_msr() only defined for some Xeon-SP, such as SPR-SP */ |
| 83 | if (mp_run_on_all_cpus(&bios_done_msr, NULL) != CB_SUCCESS) |
| 84 | printk(BIOS_ERR, "Fail to set BIOS_DONE MSR\n"); |
| 85 | |
| 86 | } |
| 87 | |
Marc Jones | 352ca5b | 2021-03-18 17:01:06 -0600 | [diff] [blame] | 88 | 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] | 89 | /* FSP programs certain registers via Notify phase ReadyToBoot that can only be programmed |
| 90 | before BIOS_DONE MSR is set, so coreboot sets BIOS_DONE as late as possible. */ |
| 91 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, bios_done_finalize, NULL); |