blob: c7931a15b64e3393f0b0c8ee83cf51ef6e25fbbd [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth5c354b92019-04-22 14:55:16 -06002
Arthur Heymans615818f2022-05-31 21:33:43 +02003#include <acpi/acpi.h>
Felix Helddd2f3fa2021-02-08 22:23:54 +01004#include <amdblocks/cpu.h>
Felix Heldf1093af2021-07-13 23:00:26 +02005#include <amdblocks/mca.h>
Felix Helda5cdf752021-03-10 15:47:00 +01006#include <amdblocks/reset.h>
Felix Heldbc134812021-02-10 02:26:10 +01007#include <amdblocks/smm.h>
Felix Heldf142ba52021-04-22 18:26:43 +02008#include <assert.h>
Martin Roth5c354b92019-04-22 14:55:16 -06009#include <console/console.h>
Zheng Bao6ba591b2020-06-09 09:47:06 +080010#include <cpu/amd/microcode.h>
Arthur Heymans615818f2022-05-31 21:33:43 +020011#include <cpu/amd/mtrr.h>
12#include <cpu/cpu.h>
13#include <cpu/x86/mp.h>
14#include <cpu/x86/msr.h>
15#include <cpu/x86/mtrr.h>
16#include <cpu/x86/smm.h>
17#include <device/device.h>
18#include <device/pci_ops.h>
19#include <soc/cpu.h>
20#include <soc/iomap.h>
21#include <soc/pci_devs.h>
22#include <soc/smi.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020023#include <types.h>
Martin Roth5c354b92019-04-22 14:55:16 -060024
Felix Heldf142ba52021-04-22 18:26:43 +020025_Static_assert(CONFIG_MAX_CPUS == 8, "Do not override MAX_CPUS. To reduce the number of "
26 "available cores, use the downcore_mode and disable_smt devicetree settings instead.");
27
Felix Held79f5feb2021-04-22 18:49:49 +020028/* MP and SMM loading initialization. */
Martin Roth5c354b92019-04-22 14:55:16 -060029
30/*
31 * Do essential initialization tasks before APs can be fired up -
32 *
33 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
34 * creates the MTRR solution that the APs will use. Otherwise APs will try to
35 * apply the incomplete solution as the BSP is calculating it.
36 */
37static void pre_mp_init(void)
38{
Arthur Heymans615818f2022-05-31 21:33:43 +020039 const msr_t syscfg = rdmsr(SYSCFG_MSR);
40 if (syscfg.lo & SYSCFG_MSR_TOM2WB)
41 x86_setup_mtrrs_with_detect_no_above_4gb();
42 else
43 x86_setup_mtrrs_with_detect();
Martin Roth5c354b92019-04-22 14:55:16 -060044 x86_mtrr_check();
45}
46
Martin Roth5c354b92019-04-22 14:55:16 -060047static const struct mp_ops mp_ops = {
48 .pre_mp_init = pre_mp_init,
49 .get_cpu_count = get_cpu_count,
50 .get_smm_info = get_smm_info,
Felix Heldbc134812021-02-10 02:26:10 +010051 .relocation_handler = smm_relocation_handler,
Arthur Heymansa19bc342022-05-31 21:25:53 +020052 .post_mp_init = global_smi_enable,
Martin Roth5c354b92019-04-22 14:55:16 -060053};
54
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030055void mp_init_cpus(struct bus *cpu_bus)
Martin Roth5c354b92019-04-22 14:55:16 -060056{
Felix Held28a0a142021-11-02 17:15:58 +010057 if (mp_init_with_smm(cpu_bus, &mp_ops) != CB_SUCCESS)
58 die_with_post_code(POST_HW_INIT_FAILURE,
59 "mp_init_with_smm failed. Halting.\n");
Martin Roth5c354b92019-04-22 14:55:16 -060060
Raul E Rangel93375f22020-06-05 15:48:21 -060061 /* pre_mp_init made the flash not cacheable. Reset to WP for performance. */
Martin Roth5c354b92019-04-22 14:55:16 -060062 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Arthur Heymansa19bc342022-05-31 21:25:53 +020063
64 /* SMMINFO only needs to be set up when booting from S5 */
65 if (!acpi_is_wakeup_s3())
66 apm_control(APM_CNT_SMMINFO);
67
Martin Roth5c354b92019-04-22 14:55:16 -060068}
69
Marshall Dawson34c30562019-07-16 15:18:00 -060070static void model_17_init(struct device *dev)
Martin Roth5c354b92019-04-22 14:55:16 -060071{
72 check_mca();
Chris Wange2497d02020-08-03 22:36:13 +080073 set_cstate_io_addr();
Zheng Bao6ba591b2020-06-09 09:47:06 +080074
75 amd_update_microcode_from_cbfs();
Martin Roth5c354b92019-04-22 14:55:16 -060076}
77
78static struct device_operations cpu_dev_ops = {
Marshall Dawson34c30562019-07-16 15:18:00 -060079 .init = model_17_init,
Martin Roth5c354b92019-04-22 14:55:16 -060080};
81
82static struct cpu_device_id cpu_table[] = {
Felix Held53c173e2020-11-05 17:24:18 +010083 { X86_VENDOR_AMD, RAVEN1_B0_CPUID},
Felix Heldab114c92020-05-22 02:40:40 +020084 { X86_VENDOR_AMD, PICASSO_B0_CPUID },
85 { X86_VENDOR_AMD, PICASSO_B1_CPUID },
86 { X86_VENDOR_AMD, RAVEN2_A0_CPUID },
87 { X86_VENDOR_AMD, RAVEN2_A1_CPUID },
Martin Roth5c354b92019-04-22 14:55:16 -060088 { 0, 0 },
89};
90
Marshall Dawson34c30562019-07-16 15:18:00 -060091static const struct cpu_driver model_17 __cpu_driver = {
Martin Roth5c354b92019-04-22 14:55:16 -060092 .ops = &cpu_dev_ops,
93 .id_table = cpu_table,
94};