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 | |
Arthur Heymans | 44807ac | 2022-09-13 12:43:37 +0200 | [diff] [blame] | 3 | #include <amdblocks/cpu.h> |
Felix Held | 199b10f | 2022-08-13 00:29:23 +0200 | [diff] [blame] | 4 | #include <amdblocks/iomap.h> |
Felix Held | f1093af | 2021-07-13 23:00:26 +0200 | [diff] [blame] | 5 | #include <amdblocks/mca.h> |
Felix Held | a5cdf75 | 2021-03-10 15:47:00 +0100 | [diff] [blame] | 6 | #include <amdblocks/reset.h> |
Felix Held | 285dd6e | 2021-02-17 22:16:40 +0100 | [diff] [blame] | 7 | #include <cpu/amd/msr.h> |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 8 | #include <cpu/cpu.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 9 | #include <cpu/x86/mp.h> |
Arthur Heymans | 615818f | 2022-05-31 21:33:43 +0200 | [diff] [blame] | 10 | #include <cpu/x86/mtrr.h> |
Arthur Heymans | e48dcb7 | 2022-05-31 21:48:15 +0200 | [diff] [blame] | 11 | #include <cpu/x86/msr.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 12 | #include <device/device.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 13 | #include <device/pci_ops.h> |
Arthur Heymans | e48dcb7 | 2022-05-31 21:48:15 +0200 | [diff] [blame] | 14 | #include <soc/pci_devs.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 15 | #include <soc/cpu.h> |
Marshall Dawson | 0814b12 | 2018-01-10 11:35:24 -0700 | [diff] [blame] | 16 | #include <soc/iomap.h> |
Arthur Heymans | e48dcb7 | 2022-05-31 21:48:15 +0200 | [diff] [blame] | 17 | #include <console/console.h> |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 18 | |
| 19 | /* |
Marshall Dawson | b617211 | 2017-09-13 17:47:31 -0600 | [diff] [blame] | 20 | * MP and SMM loading initialization. |
| 21 | */ |
Kyösti Mälkki | 79e12ab | 2020-05-31 09:21:07 +0300 | [diff] [blame] | 22 | void mp_init_cpus(struct bus *cpu_bus) |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 23 | { |
Arthur Heymans | e48dcb7 | 2022-05-31 21:48:15 +0200 | [diff] [blame] | 24 | extern const struct mp_ops amd_mp_ops_with_smm; |
| 25 | if (mp_init_with_smm(cpu_bus, &amd_mp_ops_with_smm) != CB_SUCCESS) |
Felix Held | 28a0a14 | 2021-11-02 17:15:58 +0100 | [diff] [blame] | 26 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 27 | "mp_init_with_smm failed. Halting.\n"); |
Marshall Dawson | 8f031d8 | 2018-04-09 22:15:06 -0600 | [diff] [blame] | 28 | |
| 29 | /* The flash is now no longer cacheable. Reset to WP for performance. */ |
Felix Held | 199b10f | 2022-08-13 00:29:23 +0200 | [diff] [blame] | 30 | mtrr_use_temp_range(FLASH_BELOW_4GB_MAPPING_REGION_BASE, |
| 31 | FLASH_BELOW_4GB_MAPPING_REGION_SIZE, MTRR_TYPE_WRPROT); |
Marshall Dawson | 2e49cf12 | 2018-08-03 17:05:22 -0600 | [diff] [blame] | 32 | |
| 33 | set_warm_reset_flag(); |
Marshall Dawson | a7bfbbe | 2017-09-13 17:24:53 -0600 | [diff] [blame] | 34 | } |
Marshall Dawson | 178e65d | 2017-10-20 13:20:25 -0600 | [diff] [blame] | 35 | |
Marshall Dawson | 74473ec | 2018-08-05 10:42:17 -0600 | [diff] [blame] | 36 | static void model_15_init(struct device *dev) |
| 37 | { |
| 38 | check_mca(); |
Marshall Dawson | 638bd13 | 2018-09-14 10:16:40 -0600 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * Per AMD, sync an undocumented MSR with the PSP base address. |
| 42 | * Experiments showed that if you write to the MSR after it has |
| 43 | * been previously programmed, it causes a general protection fault. |
| 44 | * Also, the MSR survives warm reset and S3 cycles, so we need to |
| 45 | * test if it was previously written before writing to it. |
| 46 | */ |
| 47 | msr_t psp_msr; |
| 48 | uint32_t psp_bar; /* Note: NDA BKDG names this 32-bit register BAR3 */ |
| 49 | psp_bar = pci_read_config32(SOC_PSP_DEV, PCI_BASE_ADDRESS_4); |
| 50 | psp_bar &= ~PCI_BASE_ADDRESS_MEM_ATTR_MASK; |
Felix Held | e09294f | 2021-02-17 22:22:21 +0100 | [diff] [blame] | 51 | psp_msr = rdmsr(PSP_ADDR_MSR); |
Marshall Dawson | 638bd13 | 2018-09-14 10:16:40 -0600 | [diff] [blame] | 52 | if (psp_msr.lo == 0) { |
| 53 | psp_msr.lo = psp_bar; |
Felix Held | e09294f | 2021-02-17 22:22:21 +0100 | [diff] [blame] | 54 | wrmsr(PSP_ADDR_MSR, psp_msr); |
Marshall Dawson | 638bd13 | 2018-09-14 10:16:40 -0600 | [diff] [blame] | 55 | } |
Marshall Dawson | 178e65d | 2017-10-20 13:20:25 -0600 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static struct device_operations cpu_dev_ops = { |
| 59 | .init = model_15_init, |
| 60 | }; |
| 61 | |
| 62 | static struct cpu_device_id cpu_table[] = { |
Richard Spiegel | 9247e86 | 2019-06-28 09:18:47 -0700 | [diff] [blame] | 63 | { X86_VENDOR_AMD, 0x660f01 }, |
Marshall Dawson | 178e65d | 2017-10-20 13:20:25 -0600 | [diff] [blame] | 64 | { X86_VENDOR_AMD, 0x670f00 }, |
| 65 | { 0, 0 }, |
| 66 | }; |
| 67 | |
| 68 | static const struct cpu_driver model_15 __cpu_driver = { |
| 69 | .ops = &cpu_dev_ops, |
| 70 | .id_table = cpu_table, |
| 71 | }; |