Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 2 | |
Felix Held | f1093af | 2021-07-13 23:00:26 +0200 | [diff] [blame] | 3 | #include <amdblocks/mca.h> |
Felix Held | a5cdf75 | 2021-03-10 15:47:00 +0100 | [diff] [blame] | 4 | #include <amdblocks/reset.h> |
Felix Held | bc13481 | 2021-02-10 02:26:10 +0100 | [diff] [blame] | 5 | #include <amdblocks/smm.h> |
Arthur Heymans | 615818f | 2022-05-31 21:33:43 +0200 | [diff] [blame] | 6 | #include <console/console.h> |
Felix Held | 285dd6e | 2021-02-17 22:16:40 +0100 | [diff] [blame] | 7 | #include <cpu/amd/msr.h> |
Arthur Heymans | 615818f | 2022-05-31 21:33:43 +0200 | [diff] [blame] | 8 | #include <cpu/amd/mtrr.h> |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 9 | #include <cpu/cpu.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 10 | #include <cpu/x86/mp.h> |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 11 | #include <cpu/x86/msr.h> |
Arthur Heymans | 615818f | 2022-05-31 21:33:43 +0200 | [diff] [blame] | 12 | #include <cpu/x86/mtrr.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 13 | #include <cpu/x86/smm.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 14 | #include <device/device.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 15 | #include <device/pci_ops.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 16 | #include <soc/cpu.h> |
Marshall Dawson | 0814b12 | 2018-01-10 11:35:24 -0700 | [diff] [blame] | 17 | #include <soc/iomap.h> |
Arthur Heymans | 615818f | 2022-05-31 21:33:43 +0200 | [diff] [blame] | 18 | #include <soc/northbridge.h> |
| 19 | #include <soc/pci_devs.h> |
| 20 | #include <soc/smi.h> |
Felix Held | d27ef5b | 2021-10-20 20:18:12 +0200 | [diff] [blame] | 21 | #include <types.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 22 | |
| 23 | /* |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 24 | * MP and SMM loading initialization. |
| 25 | */ |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 26 | |
| 27 | /* |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 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 | */ |
| 34 | static void pre_mp_init(void) |
| 35 | { |
Arthur Heymans | 615818f | 2022-05-31 21:33:43 +0200 | [diff] [blame] | 36 | const msr_t syscfg = rdmsr(SYSCFG_MSR); |
| 37 | if (syscfg.lo & SYSCFG_MSR_TOM2WB) |
| 38 | x86_setup_mtrrs_with_detect_no_above_4gb(); |
| 39 | else |
| 40 | x86_setup_mtrrs_with_detect(); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 41 | x86_mtrr_check(); |
| 42 | } |
| 43 | |
| 44 | static int get_cpu_count(void) |
| 45 | { |
Arthur Heymans | c056d18 | 2022-05-31 21:40:30 +0200 | [diff] [blame] | 46 | return 1 + (cpuid_ecx(0x80000008) & 0xff); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static const struct mp_ops mp_ops = { |
| 50 | .pre_mp_init = pre_mp_init, |
| 51 | .get_cpu_count = get_cpu_count, |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 52 | .get_smm_info = get_smm_info, |
Felix Held | bc13481 | 2021-02-10 02:26:10 +0100 | [diff] [blame] | 53 | .relocation_handler = smm_relocation_handler, |
Kyösti Mälkki | 87e6796 | 2020-05-31 09:59:14 +0300 | [diff] [blame] | 54 | .post_mp_init = global_smi_enable, |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 55 | }; |
| 56 | |
Kyösti Mälkki | 79e12ab | 2020-05-31 09:21:07 +0300 | [diff] [blame] | 57 | void mp_init_cpus(struct bus *cpu_bus) |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 58 | { |
Felix Held | 28a0a14 | 2021-11-02 17:15:58 +0100 | [diff] [blame] | 59 | if (mp_init_with_smm(cpu_bus, &mp_ops) != CB_SUCCESS) |
| 60 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 61 | "mp_init_with_smm failed. Halting.\n"); |
Marshall Dawson | 8f031d8 | 2018-04-09 22:15:06 -0600 | [diff] [blame] | 62 | |
| 63 | /* The flash is now no longer cacheable. Reset to WP for performance. */ |
| 64 | mtrr_use_temp_range(FLASH_BASE_ADDR, CONFIG_ROM_SIZE, MTRR_TYPE_WRPROT); |
Marshall Dawson | 2e49cf12 | 2018-08-03 17:05:22 -0600 | [diff] [blame] | 65 | |
| 66 | set_warm_reset_flag(); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 67 | } |
Marshall Dawson | 178e65d | 2017-10-20 13:20:25 -0600 | [diff] [blame] | 68 | |
Marshall Dawson | 74473ec | 2018-08-05 10:42:17 -0600 | [diff] [blame] | 69 | static void model_15_init(struct device *dev) |
| 70 | { |
| 71 | check_mca(); |
Marshall Dawson | 638bd13 | 2018-09-14 10:16:40 -0600 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * Per AMD, sync an undocumented MSR with the PSP base address. |
| 75 | * Experiments showed that if you write to the MSR after it has |
| 76 | * been previously programmed, it causes a general protection fault. |
| 77 | * Also, the MSR survives warm reset and S3 cycles, so we need to |
| 78 | * test if it was previously written before writing to it. |
| 79 | */ |
| 80 | msr_t psp_msr; |
| 81 | uint32_t psp_bar; /* Note: NDA BKDG names this 32-bit register BAR3 */ |
| 82 | psp_bar = pci_read_config32(SOC_PSP_DEV, PCI_BASE_ADDRESS_4); |
| 83 | psp_bar &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
Felix Held | e09294f | 2021-02-17 22:22:21 +0100 | [diff] [blame] | 84 | psp_msr = rdmsr(PSP_ADDR_MSR); |
Marshall Dawson | 638bd13 | 2018-09-14 10:16:40 -0600 | [diff] [blame] | 85 | if (psp_msr.lo == 0) { |
| 86 | psp_msr.lo = psp_bar; |
Felix Held | e09294f | 2021-02-17 22:22:21 +0100 | [diff] [blame] | 87 | wrmsr(PSP_ADDR_MSR, psp_msr); |
Marshall Dawson | 638bd13 | 2018-09-14 10:16:40 -0600 | [diff] [blame] | 88 | } |
Marshall Dawson | 178e65d | 2017-10-20 13:20:25 -0600 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static struct device_operations cpu_dev_ops = { |
| 92 | .init = model_15_init, |
| 93 | }; |
| 94 | |
| 95 | static struct cpu_device_id cpu_table[] = { |
Richard Spiegel | 9247e86 | 2019-06-28 09:18:47 -0700 | [diff] [blame] | 96 | { X86_VENDOR_AMD, 0x660f01 }, |
Marshall Dawson | 178e65d | 2017-10-20 13:20:25 -0600 | [diff] [blame] | 97 | { X86_VENDOR_AMD, 0x670f00 }, |
| 98 | { 0, 0 }, |
| 99 | }; |
| 100 | |
| 101 | static const struct cpu_driver model_15 __cpu_driver = { |
| 102 | .ops = &cpu_dev_ops, |
| 103 | .id_table = cpu_table, |
| 104 | }; |