blob: f2df3cecde3447bd664e49536308b7cc9882e3f7 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -06002
Arthur Heymans44807ac2022-09-13 12:43:37 +02003#include <amdblocks/cpu.h>
Felix Held199b10f2022-08-13 00:29:23 +02004#include <amdblocks/iomap.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 Held285dd6e2021-02-17 22:16:40 +01007#include <cpu/amd/msr.h>
Marshall Dawsonb6172112017-09-13 17:47:31 -06008#include <cpu/cpu.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -06009#include <cpu/x86/mp.h>
Arthur Heymans615818f2022-05-31 21:33:43 +020010#include <cpu/x86/mtrr.h>
Arthur Heymanse48dcb72022-05-31 21:48:15 +020011#include <cpu/x86/msr.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060012#include <device/device.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020013#include <device/pci_ops.h>
Arthur Heymanse48dcb72022-05-31 21:48:15 +020014#include <soc/pci_devs.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060015#include <soc/cpu.h>
Marshall Dawson0814b122018-01-10 11:35:24 -070016#include <soc/iomap.h>
Arthur Heymanse48dcb72022-05-31 21:48:15 +020017#include <console/console.h>
Felix Held2323aca2023-03-25 02:51:41 +010018#include <types.h>
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060019
20/*
Marshall Dawsonb6172112017-09-13 17:47:31 -060021 * MP and SMM loading initialization.
22 */
Kyösti Mälkki79e12ab2020-05-31 09:21:07 +030023void mp_init_cpus(struct bus *cpu_bus)
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060024{
Arthur Heymanse48dcb72022-05-31 21:48:15 +020025 extern const struct mp_ops amd_mp_ops_with_smm;
26 if (mp_init_with_smm(cpu_bus, &amd_mp_ops_with_smm) != CB_SUCCESS)
lilacious40cb3fe2023-06-21 23:24:14 +020027 die_with_post_code(POSTCODE_HW_INIT_FAILURE,
Felix Held28a0a142021-11-02 17:15:58 +010028 "mp_init_with_smm failed. Halting.\n");
Marshall Dawson8f031d82018-04-09 22:15:06 -060029
30 /* The flash is now no longer cacheable. Reset to WP for performance. */
Felix Held199b10f2022-08-13 00:29:23 +020031 mtrr_use_temp_range(FLASH_BELOW_4GB_MAPPING_REGION_BASE,
32 FLASH_BELOW_4GB_MAPPING_REGION_SIZE, MTRR_TYPE_WRPROT);
Marshall Dawson2e49cf122018-08-03 17:05:22 -060033
34 set_warm_reset_flag();
Marshall Dawsona7bfbbe2017-09-13 17:24:53 -060035}
Marshall Dawson178e65d2017-10-20 13:20:25 -060036
Marshall Dawson74473ec2018-08-05 10:42:17 -060037static void model_15_init(struct device *dev)
38{
39 check_mca();
Marshall Dawson638bd132018-09-14 10:16:40 -060040
41 /*
42 * Per AMD, sync an undocumented MSR with the PSP base address.
43 * Experiments showed that if you write to the MSR after it has
44 * been previously programmed, it causes a general protection fault.
45 * Also, the MSR survives warm reset and S3 cycles, so we need to
46 * test if it was previously written before writing to it.
47 */
48 msr_t psp_msr;
49 uint32_t psp_bar; /* Note: NDA BKDG names this 32-bit register BAR3 */
50 psp_bar = pci_read_config32(SOC_PSP_DEV, PCI_BASE_ADDRESS_4);
51 psp_bar &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK;
Felix Helde09294f2021-02-17 22:22:21 +010052 psp_msr = rdmsr(PSP_ADDR_MSR);
Marshall Dawson638bd132018-09-14 10:16:40 -060053 if (psp_msr.lo == 0) {
54 psp_msr.lo = psp_bar;
Felix Helde09294f2021-02-17 22:22:21 +010055 wrmsr(PSP_ADDR_MSR, psp_msr);
Marshall Dawson638bd132018-09-14 10:16:40 -060056 }
Marshall Dawson178e65d2017-10-20 13:20:25 -060057}
58
59static struct device_operations cpu_dev_ops = {
60 .init = model_15_init,
61};
62
63static struct cpu_device_id cpu_table[] = {
Felix Held3ecf3772023-02-06 21:13:19 +010064 { X86_VENDOR_AMD, CPUID_FROM_FMS(0x15, 0x60, 0), CPUID_ALL_STEPPINGS_MASK },
65 { X86_VENDOR_AMD, CPUID_FROM_FMS(0x15, 0x70, 0), CPUID_ALL_STEPPINGS_MASK },
Felix Held1e781652023-02-08 11:39:16 +010066 CPU_TABLE_END
Marshall Dawson178e65d2017-10-20 13:20:25 -060067};
68
69static const struct cpu_driver model_15 __cpu_driver = {
70 .ops = &cpu_dev_ops,
71 .id_table = cpu_table,
72};