blob: 2ac30b6b9fd9cc9d7bc15715a80a0bd6e353d74c [file] [log] [blame]
Felix Held060b8ad2021-02-05 22:51:33 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
Felix Heldaa77d132021-02-10 16:13:56 +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 Held7aacdd12021-02-10 23:27:47 +01006#include <amdblocks/smm.h>
Felix Held79f705f2021-04-22 17:08:50 +02007#include <assert.h>
Felix Held060b8ad2021-02-05 22:51:33 +01008#include <console/console.h>
Raul E Rangel35dc4b02021-02-12 16:04:27 -07009#include <cpu/amd/microcode.h>
Felix Held060b8ad2021-02-05 22:51:33 +010010#include <cpu/cpu.h>
Felix Heldaa77d132021-02-10 16:13:56 +010011#include <cpu/x86/lapic.h>
Felix Held7aacdd12021-02-10 23:27:47 +010012#include <cpu/x86/mp.h>
13#include <cpu/x86/mtrr.h>
14#include <cpu/x86/smm.h>
Felix Held060b8ad2021-02-05 22:51:33 +010015#include <device/device.h>
16#include <soc/cpu.h>
Felix Held7aacdd12021-02-10 23:27:47 +010017#include <soc/iomap.h>
Felix Held7aacdd12021-02-10 23:27:47 +010018
Felix Held79f705f2021-04-22 17:08:50 +020019_Static_assert(CONFIG_MAX_CPUS == 16, "Do not override MAX_CPUS. To reduce the number of "
20 "available cores, use the downcore_mode and disable_smt devicetree settings instead.");
21
Felix Held7aacdd12021-02-10 23:27:47 +010022/* MP and SMM loading initialization */
23
24/*
25 * Do essential initialization tasks before APs can be fired up -
26 *
27 * 1. Prevent race condition in MTRR solution. Enable MTRRs on the BSP. This
28 * creates the MTRR solution that the APs will use. Otherwise APs will try to
29 * apply the incomplete solution as the BSP is calculating it.
30 */
31static void pre_mp_init(void)
32{
33 x86_setup_mtrrs_with_detect_no_above_4gb();
34 x86_mtrr_check();
35}
36
37static void post_mp_init(void)
38{
39 global_smi_enable();
40 apm_control(APM_CNT_SMMINFO);
41}
42
43static const struct mp_ops mp_ops = {
44 .pre_mp_init = pre_mp_init,
45 .get_cpu_count = get_cpu_count,
46 .get_smm_info = get_smm_info,
47 .relocation_handler = smm_relocation_handler,
48 .post_mp_init = post_mp_init,
49};
Felix Held060b8ad2021-02-05 22:51:33 +010050
Felix Heldb2d8a5c2021-02-10 16:17:13 +010051void mp_init_cpus(struct bus *cpu_bus)
52{
Felix Held7aacdd12021-02-10 23:27:47 +010053 /* Clear for take-off */
54 if (mp_init_with_smm(cpu_bus, &mp_ops) < 0)
55 printk(BIOS_ERR, "MP initialization failure.\n");
56
57 /* pre_mp_init made the flash not cacheable. Reset to WP for performance. */
58 mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT);
Felix Heldb2d8a5c2021-02-10 16:17:13 +010059}
60
Felix Held060b8ad2021-02-05 22:51:33 +010061static void zen_2_3_init(struct device *dev)
62{
Felix Helda24472a2021-07-13 18:21:27 +020063 check_mca();
Felix Heldaa77d132021-02-10 16:13:56 +010064 setup_lapic();
65 set_cstate_io_addr();
Raul E Rangel35dc4b02021-02-12 16:04:27 -070066
67 amd_update_microcode_from_cbfs();
Felix Held060b8ad2021-02-05 22:51:33 +010068}
69
70static struct device_operations cpu_dev_ops = {
71 .init = zen_2_3_init,
72};
73
74static struct cpu_device_id cpu_table[] = {
75 { X86_VENDOR_AMD, CEZANNE_A0_CPUID},
76 { 0, 0 },
77};
78
79static const struct cpu_driver zen_2_3 __cpu_driver = {
80 .ops = &cpu_dev_ops,
81 .id_table = cpu_table,
82};