blob: 4e9c9a9cac3621dedf773c4fe23031c050931c4e [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
Felix Helddd2f3fa2021-02-08 22:23:54 +01003#include <amdblocks/cpu.h>
Felix Helda5cdf752021-03-10 15:47:00 +01004#include <amdblocks/reset.h>
Felix Heldbc134812021-02-10 02:26:10 +01005#include <amdblocks/smm.h>
Felix Heldf142ba52021-04-22 18:26:43 +02006#include <assert.h>
Martin Roth5c354b92019-04-22 14:55:16 -06007#include <cpu/cpu.h>
8#include <cpu/x86/mp.h>
9#include <cpu/x86/mtrr.h>
10#include <cpu/x86/msr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030011#include <cpu/x86/smm.h>
Martin Roth5c354b92019-04-22 14:55:16 -060012#include <cpu/x86/lapic.h>
13#include <device/device.h>
14#include <device/pci_ops.h>
15#include <soc/pci_devs.h>
16#include <soc/cpu.h>
Martin Roth5c354b92019-04-22 14:55:16 -060017#include <soc/smi.h>
18#include <soc/iomap.h>
19#include <console/console.h>
Zheng Bao6ba591b2020-06-09 09:47:06 +080020#include <cpu/amd/microcode.h>
Martin Roth5c354b92019-04-22 14:55:16 -060021
Felix Heldf142ba52021-04-22 18:26:43 +020022_Static_assert(CONFIG_MAX_CPUS == 8, "Do not override MAX_CPUS. To reduce the number of "
23 "available cores, use the downcore_mode and disable_smt devicetree settings instead.");
24
Felix Held79f5feb2021-04-22 18:49:49 +020025/* MP and SMM loading initialization. */
Martin Roth5c354b92019-04-22 14:55:16 -060026
27/*
28 * Do essential initialization tasks before APs can be fired up -
29 *
30 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
31 * creates the MTRR solution that the APs will use. Otherwise APs will try to
32 * apply the incomplete solution as the BSP is calculating it.
33 */
34static void pre_mp_init(void)
35{
Aaron Durbina2c045b2020-05-28 10:19:18 -060036 x86_setup_mtrrs_with_detect_no_above_4gb();
Martin Roth5c354b92019-04-22 14:55:16 -060037 x86_mtrr_check();
38}
39
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030040static void post_mp_init(void)
41{
42 global_smi_enable();
43 apm_control(APM_CNT_SMMINFO);
44}
45
Martin Roth5c354b92019-04-22 14:55:16 -060046static const struct mp_ops mp_ops = {
47 .pre_mp_init = pre_mp_init,
48 .get_cpu_count = get_cpu_count,
49 .get_smm_info = get_smm_info,
Felix Heldbc134812021-02-10 02:26:10 +010050 .relocation_handler = smm_relocation_handler,
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030051 .post_mp_init = post_mp_init,
Martin Roth5c354b92019-04-22 14:55:16 -060052};
53
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030054void mp_init_cpus(struct bus *cpu_bus)
Martin Roth5c354b92019-04-22 14:55:16 -060055{
56 /* Clear for take-off */
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030057 if (mp_init_with_smm(cpu_bus, &mp_ops) < 0)
Martin Roth5c354b92019-04-22 14:55:16 -060058 printk(BIOS_ERR, "MP initialization failure.\n");
59
Raul E Rangel93375f22020-06-05 15:48:21 -060060 /* pre_mp_init made the flash not cacheable. Reset to WP for performance. */
Martin Roth5c354b92019-04-22 14:55:16 -060061 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Martin Roth5c354b92019-04-22 14:55:16 -060062}
63
Marshall Dawson34c30562019-07-16 15:18:00 -060064static void model_17_init(struct device *dev)
Martin Roth5c354b92019-04-22 14:55:16 -060065{
66 check_mca();
67 setup_lapic();
Chris Wange2497d02020-08-03 22:36:13 +080068 set_cstate_io_addr();
Zheng Bao6ba591b2020-06-09 09:47:06 +080069
70 amd_update_microcode_from_cbfs();
Martin Roth5c354b92019-04-22 14:55:16 -060071}
72
73static struct device_operations cpu_dev_ops = {
Marshall Dawson34c30562019-07-16 15:18:00 -060074 .init = model_17_init,
Martin Roth5c354b92019-04-22 14:55:16 -060075};
76
77static struct cpu_device_id cpu_table[] = {
Felix Held53c173e2020-11-05 17:24:18 +010078 { X86_VENDOR_AMD, RAVEN1_B0_CPUID},
Felix Heldab114c92020-05-22 02:40:40 +020079 { X86_VENDOR_AMD, PICASSO_B0_CPUID },
80 { X86_VENDOR_AMD, PICASSO_B1_CPUID },
81 { X86_VENDOR_AMD, RAVEN2_A0_CPUID },
82 { X86_VENDOR_AMD, RAVEN2_A1_CPUID },
Martin Roth5c354b92019-04-22 14:55:16 -060083 { 0, 0 },
84};
85
Marshall Dawson34c30562019-07-16 15:18:00 -060086static const struct cpu_driver model_17 __cpu_driver = {
Martin Roth5c354b92019-04-22 14:55:16 -060087 .ops = &cpu_dev_ops,
88 .id_table = cpu_table,
89};