blob: d3e80ebdeaa6a59f6b95959b1fb313c580c8341c [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
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030047static void post_mp_init(void)
48{
49 global_smi_enable();
Fred Reitberger81ee8e22022-03-24 07:42:40 -040050
51 /* SMMINFO only needs to be set up when booting from S5 */
52 if (!acpi_is_wakeup_s3())
53 apm_control(APM_CNT_SMMINFO);
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030054}
55
Martin Roth5c354b92019-04-22 14:55:16 -060056static const struct mp_ops mp_ops = {
57 .pre_mp_init = pre_mp_init,
58 .get_cpu_count = get_cpu_count,
59 .get_smm_info = get_smm_info,
Felix Heldbc134812021-02-10 02:26:10 +010060 .relocation_handler = smm_relocation_handler,
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030061 .post_mp_init = post_mp_init,
Martin Roth5c354b92019-04-22 14:55:16 -060062};
63
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030064void mp_init_cpus(struct bus *cpu_bus)
Martin Roth5c354b92019-04-22 14:55:16 -060065{
Felix Held28a0a142021-11-02 17:15:58 +010066 if (mp_init_with_smm(cpu_bus, &mp_ops) != CB_SUCCESS)
67 die_with_post_code(POST_HW_INIT_FAILURE,
68 "mp_init_with_smm failed. Halting.\n");
Martin Roth5c354b92019-04-22 14:55:16 -060069
Raul E Rangel93375f22020-06-05 15:48:21 -060070 /* pre_mp_init made the flash not cacheable. Reset to WP for performance. */
Martin Roth5c354b92019-04-22 14:55:16 -060071 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Martin Roth5c354b92019-04-22 14:55:16 -060072}
73
Marshall Dawson34c30562019-07-16 15:18:00 -060074static void model_17_init(struct device *dev)
Martin Roth5c354b92019-04-22 14:55:16 -060075{
76 check_mca();
Chris Wange2497d02020-08-03 22:36:13 +080077 set_cstate_io_addr();
Zheng Bao6ba591b2020-06-09 09:47:06 +080078
79 amd_update_microcode_from_cbfs();
Martin Roth5c354b92019-04-22 14:55:16 -060080}
81
82static struct device_operations cpu_dev_ops = {
Marshall Dawson34c30562019-07-16 15:18:00 -060083 .init = model_17_init,
Martin Roth5c354b92019-04-22 14:55:16 -060084};
85
86static struct cpu_device_id cpu_table[] = {
Felix Held53c173e2020-11-05 17:24:18 +010087 { X86_VENDOR_AMD, RAVEN1_B0_CPUID},
Felix Heldab114c92020-05-22 02:40:40 +020088 { X86_VENDOR_AMD, PICASSO_B0_CPUID },
89 { X86_VENDOR_AMD, PICASSO_B1_CPUID },
90 { X86_VENDOR_AMD, RAVEN2_A0_CPUID },
91 { X86_VENDOR_AMD, RAVEN2_A1_CPUID },
Martin Roth5c354b92019-04-22 14:55:16 -060092 { 0, 0 },
93};
94
Marshall Dawson34c30562019-07-16 15:18:00 -060095static const struct cpu_driver model_17 __cpu_driver = {
Martin Roth5c354b92019-04-22 14:55:16 -060096 .ops = &cpu_dev_ops,
97 .id_table = cpu_table,
98};