blob: e00763753a001982a3fb0abf6036a9135bd0e8e9 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -06002
Felix Helda5cdf752021-03-10 15:47:00 +01003#include <amdblocks/reset.h>
Felix Heldbc134812021-02-10 02:26:10 +01004#include <amdblocks/smm.h>
Felix Held285dd6e2021-02-17 22:16:40 +01005#include <cpu/amd/msr.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -06006#include <cpu/cpu.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -06007#include <cpu/x86/mp.h>
8#include <cpu/x86/mtrr.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -06009#include <cpu/x86/msr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030010#include <cpu/x86/smm.h>
Marshall Dawson178e65d2017-10-20 13:20:25 -060011#include <cpu/x86/lapic.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060012#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020013#include <device/pci_ops.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060014#include <soc/pci_devs.h>
15#include <soc/cpu.h>
16#include <soc/northbridge.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -060017#include <soc/smi.h>
Marshall Dawson0814b122018-01-10 11:35:24 -070018#include <soc/iomap.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060019#include <console/console.h>
20
21/*
Marshall Dawsonb6172112017-09-13 17:47:31 -060022 * MP and SMM loading initialization.
23 */
Marshall Dawsonb6172112017-09-13 17:47:31 -060024
25/*
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060026 * Do essential initialization tasks before APs can be fired up -
27 *
28 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
29 * creates the MTRR solution that the APs will use. Otherwise APs will try to
30 * apply the incomplete solution as the BSP is calculating it.
31 */
32static void pre_mp_init(void)
33{
34 x86_setup_mtrrs_with_detect();
35 x86_mtrr_check();
36}
37
38static int get_cpu_count(void)
39{
Martin Roth1956a002018-10-30 22:31:40 -060040 return (pci_read_config16(SOC_HT_DEV, D18F0_CPU_CNT) & CPU_CNT_MASK)
Richard Spiegel41baf0c2018-10-22 13:57:18 -070041 + 1;
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060042}
43
44static const struct mp_ops mp_ops = {
45 .pre_mp_init = pre_mp_init,
46 .get_cpu_count = get_cpu_count,
Marshall Dawsonb6172112017-09-13 17:47:31 -060047 .get_smm_info = get_smm_info,
Felix Heldbc134812021-02-10 02:26:10 +010048 .relocation_handler = smm_relocation_handler,
Kyösti Mälkki87e67962020-05-31 09:59:14 +030049 .post_mp_init = global_smi_enable,
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060050};
51
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030052void mp_init_cpus(struct bus *cpu_bus)
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060053{
54 /* Clear for take-off */
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030055 if (mp_init_with_smm(cpu_bus, &mp_ops) < 0)
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060056 printk(BIOS_ERR, "MP initialization failure.\n");
Marshall Dawson8f031d82018-04-09 22:15:06 -060057
58 /* The flash is now no longer cacheable. Reset to WP for performance. */
59 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Marshall Dawson2e49cf122018-08-03 17:05:22 -060060
61 set_warm_reset_flag();
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060062}
Marshall Dawson178e65d2017-10-20 13:20:25 -060063
Marshall Dawson74473ec2018-08-05 10:42:17 -060064static void model_15_init(struct device *dev)
65{
66 check_mca();
Marshall Dawson178e65d2017-10-20 13:20:25 -060067 setup_lapic();
Marshall Dawson638bd132018-09-14 10:16:40 -060068
69 /*
70 * Per AMD, sync an undocumented MSR with the PSP base address.
71 * Experiments showed that if you write to the MSR after it has
72 * been previously programmed, it causes a general protection fault.
73 * Also, the MSR survives warm reset and S3 cycles, so we need to
74 * test if it was previously written before writing to it.
75 */
76 msr_t psp_msr;
77 uint32_t psp_bar; /* Note: NDA BKDG names this 32-bit register BAR3 */
78 psp_bar = pci_read_config32(SOC_PSP_DEV, PCI_BASE_ADDRESS_4);
79 psp_bar &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK;
Felix Helde09294f2021-02-17 22:22:21 +010080 psp_msr = rdmsr(PSP_ADDR_MSR);
Marshall Dawson638bd132018-09-14 10:16:40 -060081 if (psp_msr.lo == 0) {
82 psp_msr.lo = psp_bar;
Felix Helde09294f2021-02-17 22:22:21 +010083 wrmsr(PSP_ADDR_MSR, psp_msr);
Marshall Dawson638bd132018-09-14 10:16:40 -060084 }
Marshall Dawson178e65d2017-10-20 13:20:25 -060085}
86
87static struct device_operations cpu_dev_ops = {
88 .init = model_15_init,
89};
90
91static struct cpu_device_id cpu_table[] = {
Richard Spiegel9247e862019-06-28 09:18:47 -070092 { X86_VENDOR_AMD, 0x660f01 },
Marshall Dawson178e65d2017-10-20 13:20:25 -060093 { X86_VENDOR_AMD, 0x670f00 },
94 { 0, 0 },
95};
96
97static const struct cpu_driver model_15 __cpu_driver = {
98 .ops = &cpu_dev_ops,
99 .id_table = cpu_table,
100};