blob: 08447e9be350a1a2875fbfbd2a699376fe541373 [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 Held199b10f2022-08-13 00:29:23 +02005#include <amdblocks/iomap.h>
Felix Heldf1093af2021-07-13 23:00:26 +02006#include <amdblocks/mca.h>
Felix Helda5cdf752021-03-10 15:47:00 +01007#include <amdblocks/reset.h>
Felix Heldbc134812021-02-10 02:26:10 +01008#include <amdblocks/smm.h>
Felix Heldf142ba52021-04-22 18:26:43 +02009#include <assert.h>
Martin Roth5c354b92019-04-22 14:55:16 -060010#include <console/console.h>
Zheng Bao6ba591b2020-06-09 09:47:06 +080011#include <cpu/amd/microcode.h>
Arthur Heymans615818f2022-05-31 21:33:43 +020012#include <cpu/amd/mtrr.h>
13#include <cpu/cpu.h>
14#include <cpu/x86/mp.h>
15#include <cpu/x86/msr.h>
16#include <cpu/x86/mtrr.h>
17#include <cpu/x86/smm.h>
18#include <device/device.h>
19#include <device/pci_ops.h>
20#include <soc/cpu.h>
21#include <soc/iomap.h>
22#include <soc/pci_devs.h>
23#include <soc/smi.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020024#include <types.h>
Martin Roth5c354b92019-04-22 14:55:16 -060025
Felix Heldf142ba52021-04-22 18:26:43 +020026_Static_assert(CONFIG_MAX_CPUS == 8, "Do not override MAX_CPUS. To reduce the number of "
27 "available cores, use the downcore_mode and disable_smt devicetree settings instead.");
28
Felix Held79f5feb2021-04-22 18:49:49 +020029/* MP and SMM loading initialization. */
Martin Roth5c354b92019-04-22 14:55:16 -060030
31/*
32 * Do essential initialization tasks before APs can be fired up -
33 *
34 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
35 * creates the MTRR solution that the APs will use. Otherwise APs will try to
36 * apply the incomplete solution as the BSP is calculating it.
37 */
38static void pre_mp_init(void)
39{
Arthur Heymans615818f2022-05-31 21:33:43 +020040 const msr_t syscfg = rdmsr(SYSCFG_MSR);
41 if (syscfg.lo & SYSCFG_MSR_TOM2WB)
42 x86_setup_mtrrs_with_detect_no_above_4gb();
43 else
44 x86_setup_mtrrs_with_detect();
Martin Roth5c354b92019-04-22 14:55:16 -060045 x86_mtrr_check();
46}
47
Martin Roth5c354b92019-04-22 14:55:16 -060048static const struct mp_ops mp_ops = {
49 .pre_mp_init = pre_mp_init,
50 .get_cpu_count = get_cpu_count,
51 .get_smm_info = get_smm_info,
Felix Heldbc134812021-02-10 02:26:10 +010052 .relocation_handler = smm_relocation_handler,
Arthur Heymansa19bc342022-05-31 21:25:53 +020053 .post_mp_init = global_smi_enable,
Martin Roth5c354b92019-04-22 14:55:16 -060054};
55
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030056void mp_init_cpus(struct bus *cpu_bus)
Martin Roth5c354b92019-04-22 14:55:16 -060057{
Felix Held28a0a142021-11-02 17:15:58 +010058 if (mp_init_with_smm(cpu_bus, &mp_ops) != CB_SUCCESS)
59 die_with_post_code(POST_HW_INIT_FAILURE,
60 "mp_init_with_smm failed. Halting.\n");
Martin Roth5c354b92019-04-22 14:55:16 -060061
Raul E Rangel93375f22020-06-05 15:48:21 -060062 /* pre_mp_init made the flash not cacheable. Reset to WP for performance. */
Felix Held199b10f2022-08-13 00:29:23 +020063 mtrr_use_temp_range(FLASH_BELOW_4GB_MAPPING_REGION_BASE,
64 FLASH_BELOW_4GB_MAPPING_REGION_SIZE, MTRR_TYPE_WRPROT);
Arthur Heymansa19bc342022-05-31 21:25:53 +020065
66 /* SMMINFO only needs to be set up when booting from S5 */
67 if (!acpi_is_wakeup_s3())
68 apm_control(APM_CNT_SMMINFO);
69
Martin Roth5c354b92019-04-22 14:55:16 -060070}
71
Marshall Dawson34c30562019-07-16 15:18:00 -060072static void model_17_init(struct device *dev)
Martin Roth5c354b92019-04-22 14:55:16 -060073{
74 check_mca();
Chris Wange2497d02020-08-03 22:36:13 +080075 set_cstate_io_addr();
Zheng Bao6ba591b2020-06-09 09:47:06 +080076
77 amd_update_microcode_from_cbfs();
Martin Roth5c354b92019-04-22 14:55:16 -060078}
79
80static struct device_operations cpu_dev_ops = {
Marshall Dawson34c30562019-07-16 15:18:00 -060081 .init = model_17_init,
Martin Roth5c354b92019-04-22 14:55:16 -060082};
83
84static struct cpu_device_id cpu_table[] = {
Felix Held53c173e2020-11-05 17:24:18 +010085 { X86_VENDOR_AMD, RAVEN1_B0_CPUID},
Felix Heldab114c92020-05-22 02:40:40 +020086 { X86_VENDOR_AMD, PICASSO_B0_CPUID },
87 { X86_VENDOR_AMD, PICASSO_B1_CPUID },
88 { X86_VENDOR_AMD, RAVEN2_A0_CPUID },
89 { X86_VENDOR_AMD, RAVEN2_A1_CPUID },
Martin Roth5c354b92019-04-22 14:55:16 -060090 { 0, 0 },
91};
92
Marshall Dawson34c30562019-07-16 15:18:00 -060093static const struct cpu_driver model_17 __cpu_driver = {
Martin Roth5c354b92019-04-22 14:55:16 -060094 .ops = &cpu_dev_ops,
95 .id_table = cpu_table,
96};