blob: 9822326afe36f84687c9d84a06ee36e523caad69 [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 Heldf1093af2021-07-13 23:00:26 +02004#include <amdblocks/mca.h>
Felix Helda5cdf752021-03-10 15:47:00 +01005#include <amdblocks/reset.h>
Felix Heldbc134812021-02-10 02:26:10 +01006#include <amdblocks/smm.h>
Felix Heldf142ba52021-04-22 18:26:43 +02007#include <assert.h>
Martin Roth5c354b92019-04-22 14:55:16 -06008#include <cpu/cpu.h>
9#include <cpu/x86/mp.h>
10#include <cpu/x86/mtrr.h>
11#include <cpu/x86/msr.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +030012#include <cpu/x86/smm.h>
Martin Roth5c354b92019-04-22 14:55:16 -060013#include <cpu/x86/lapic.h>
14#include <device/device.h>
15#include <device/pci_ops.h>
16#include <soc/pci_devs.h>
17#include <soc/cpu.h>
Martin Roth5c354b92019-04-22 14:55:16 -060018#include <soc/smi.h>
19#include <soc/iomap.h>
20#include <console/console.h>
Zheng Bao6ba591b2020-06-09 09:47:06 +080021#include <cpu/amd/microcode.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020022#include <types.h>
Martin Roth5c354b92019-04-22 14:55:16 -060023
Felix Heldf142ba52021-04-22 18:26:43 +020024_Static_assert(CONFIG_MAX_CPUS == 8, "Do not override MAX_CPUS. To reduce the number of "
25 "available cores, use the downcore_mode and disable_smt devicetree settings instead.");
26
Felix Held79f5feb2021-04-22 18:49:49 +020027/* MP and SMM loading initialization. */
Martin Roth5c354b92019-04-22 14:55:16 -060028
29/*
30 * Do essential initialization tasks before APs can be fired up -
31 *
32 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
33 * creates the MTRR solution that the APs will use. Otherwise APs will try to
34 * apply the incomplete solution as the BSP is calculating it.
35 */
36static void pre_mp_init(void)
37{
Aaron Durbina2c045b2020-05-28 10:19:18 -060038 x86_setup_mtrrs_with_detect_no_above_4gb();
Martin Roth5c354b92019-04-22 14:55:16 -060039 x86_mtrr_check();
40}
41
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030042static void post_mp_init(void)
43{
44 global_smi_enable();
45 apm_control(APM_CNT_SMMINFO);
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,
Kyösti Mälkki2fec39492020-07-01 15:59:20 +030053 .post_mp_init = post_mp_init,
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{
58 /* Clear for take-off */
Felix Held4dd7d112021-10-20 23:31:43 +020059 /* TODO: Handle mp_init_with_smm failure? */
60 mp_init_with_smm(cpu_bus, &mp_ops);
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. */
Martin Roth5c354b92019-04-22 14:55:16 -060063 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Martin Roth5c354b92019-04-22 14:55:16 -060064}
65
Marshall Dawson34c30562019-07-16 15:18:00 -060066static void model_17_init(struct device *dev)
Martin Roth5c354b92019-04-22 14:55:16 -060067{
68 check_mca();
69 setup_lapic();
Chris Wange2497d02020-08-03 22:36:13 +080070 set_cstate_io_addr();
Zheng Bao6ba591b2020-06-09 09:47:06 +080071
72 amd_update_microcode_from_cbfs();
Martin Roth5c354b92019-04-22 14:55:16 -060073}
74
75static struct device_operations cpu_dev_ops = {
Marshall Dawson34c30562019-07-16 15:18:00 -060076 .init = model_17_init,
Martin Roth5c354b92019-04-22 14:55:16 -060077};
78
79static struct cpu_device_id cpu_table[] = {
Felix Held53c173e2020-11-05 17:24:18 +010080 { X86_VENDOR_AMD, RAVEN1_B0_CPUID},
Felix Heldab114c92020-05-22 02:40:40 +020081 { X86_VENDOR_AMD, PICASSO_B0_CPUID },
82 { X86_VENDOR_AMD, PICASSO_B1_CPUID },
83 { X86_VENDOR_AMD, RAVEN2_A0_CPUID },
84 { X86_VENDOR_AMD, RAVEN2_A1_CPUID },
Martin Roth5c354b92019-04-22 14:55:16 -060085 { 0, 0 },
86};
87
Marshall Dawson34c30562019-07-16 15:18:00 -060088static const struct cpu_driver model_17 __cpu_driver = {
Martin Roth5c354b92019-04-22 14:55:16 -060089 .ops = &cpu_dev_ops,
90 .id_table = cpu_table,
91};