Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 2 | |
Arthur Heymans | 44807ac | 2022-09-13 12:43:37 +0200 | [diff] [blame] | 3 | #include <amdblocks/cpu.h> |
Arthur Heymans | 7ae8fa5 | 2022-05-31 18:53:47 +0200 | [diff] [blame] | 4 | #include <amdblocks/smm.h> |
Michał Żygowski | b8d35c1 | 2021-04-29 18:12:11 +0200 | [diff] [blame] | 5 | #include <commonlib/helpers.h> |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 6 | #include <console/console.h> |
Michał Żygowski | 319f037 | 2018-10-25 15:48:54 +0200 | [diff] [blame] | 7 | #include <cpu/amd/microcode.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 8 | #include <cpu/amd/msr.h> |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 9 | #include <cpu/amd/mtrr.h> |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 10 | #include <cpu/cpu.h> |
| 11 | #include <cpu/x86/cache.h> |
Arthur Heymans | 7ae8fa5 | 2022-05-31 18:53:47 +0200 | [diff] [blame] | 12 | #include <cpu/x86/msr.h> |
| 13 | #include <cpu/x86/mtrr.h> |
| 14 | #include <device/device.h> |
| 15 | #include <device/pci.h> |
Michał Żygowski | b8d35c1 | 2021-04-29 18:12:11 +0200 | [diff] [blame] | 16 | #include <smp/node.h> |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 17 | |
Elyes HAOUAS | d2d8a31 | 2018-02-08 13:38:21 +0100 | [diff] [blame] | 18 | static void model_16_init(struct device *dev) |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 19 | { |
| 20 | printk(BIOS_DEBUG, "Model 16 Init.\n"); |
| 21 | |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 22 | msr_t msr; |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 23 | u32 siblings; |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 24 | |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 25 | /* zero the machine check error status registers */ |
Felix Held | acbf154 | 2021-07-13 16:44:18 +0200 | [diff] [blame] | 26 | mca_clear_status(); |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 27 | |
Michał Żygowski | b8d35c1 | 2021-04-29 18:12:11 +0200 | [diff] [blame] | 28 | if (CONFIG(LOGICAL_CPUS)) { |
Arthur Heymans | 44807ac | 2022-09-13 12:43:37 +0200 | [diff] [blame] | 29 | siblings = get_cpu_count() - 1; // minus BSP |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 30 | |
Michał Żygowski | b8d35c1 | 2021-04-29 18:12:11 +0200 | [diff] [blame] | 31 | if (siblings > 0) { |
| 32 | msr = rdmsr_amd(CPU_ID_FEATURES_MSR); |
| 33 | msr.lo |= 1 << 28; |
| 34 | wrmsr_amd(CPU_ID_FEATURES_MSR, msr); |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 35 | |
Michał Żygowski | b8d35c1 | 2021-04-29 18:12:11 +0200 | [diff] [blame] | 36 | msr = rdmsr_amd(CPU_ID_EXT_FEATURES_MSR); |
| 37 | msr.hi |= 1 << (33 - 32); |
| 38 | wrmsr_amd(CPU_ID_EXT_FEATURES_MSR, msr); |
| 39 | } |
| 40 | printk(BIOS_DEBUG, "siblings = %02d, ", siblings); |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 41 | } |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 42 | |
| 43 | /* DisableCf8ExtCfg */ |
| 44 | msr = rdmsr(NB_CFG_MSR); |
| 45 | msr.hi &= ~(1 << (46 - 32)); |
| 46 | wrmsr(NB_CFG_MSR, msr); |
| 47 | |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 48 | /* Write protect SMM space with SMMLOCK. */ |
Arthur Heymans | 7ae8fa5 | 2022-05-31 18:53:47 +0200 | [diff] [blame] | 49 | lock_smm(); |
Michał Żygowski | 319f037 | 2018-10-25 15:48:54 +0200 | [diff] [blame] | 50 | |
Zheng Bao | b8c473e | 2020-06-09 09:30:39 +0800 | [diff] [blame] | 51 | amd_update_microcode_from_cbfs(); |
Michał Żygowski | b8d35c1 | 2021-04-29 18:12:11 +0200 | [diff] [blame] | 52 | |
| 53 | display_mtrrs(); |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static struct device_operations cpu_dev_ops = { |
| 57 | .init = model_16_init, |
| 58 | }; |
| 59 | |
Jonathan Neuschäfer | 8f06ce3 | 2017-11-20 01:56:44 +0100 | [diff] [blame] | 60 | static const struct cpu_device_id cpu_table[] = { |
Felix Held | 6a6ac1e | 2023-02-06 15:19:11 +0100 | [diff] [blame] | 61 | { X86_VENDOR_AMD, 0x730F00, CPUID_EXACT_MATCH_MASK }, |
| 62 | { X86_VENDOR_AMD, 0x730F01, CPUID_EXACT_MATCH_MASK }, |
Felix Held | 1e78165 | 2023-02-08 11:39:16 +0100 | [diff] [blame^] | 63 | CPU_TABLE_END |
Bruce Griffith | 5888d86 | 2014-08-15 12:15:33 -0600 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static const struct cpu_driver model_16 __cpu_driver = { |
| 67 | .ops = &cpu_dev_ops, |
| 68 | .id_table = cpu_table, |
| 69 | }; |