blob: 5b43a07264589d8a263013eecb5766f942d88aa4 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Bruce Griffith5888d862014-08-15 12:15:33 -06002
Arthur Heymans44807ac2022-09-13 12:43:37 +02003#include <amdblocks/cpu.h>
Arthur Heymans7ae8fa52022-05-31 18:53:47 +02004#include <amdblocks/smm.h>
Michał Żygowskib8d35c12021-04-29 18:12:11 +02005#include <commonlib/helpers.h>
Bruce Griffith5888d862014-08-15 12:15:33 -06006#include <console/console.h>
Michał Żygowski319f0372018-10-25 15:48:54 +02007#include <cpu/amd/microcode.h>
Elyes HAOUAS400ce552018-10-12 10:54:30 +02008#include <cpu/amd/msr.h>
Bruce Griffith5888d862014-08-15 12:15:33 -06009#include <cpu/amd/mtrr.h>
Bruce Griffith5888d862014-08-15 12:15:33 -060010#include <cpu/cpu.h>
11#include <cpu/x86/cache.h>
Arthur Heymans7ae8fa52022-05-31 18:53:47 +020012#include <cpu/x86/msr.h>
13#include <cpu/x86/mtrr.h>
14#include <device/device.h>
15#include <device/pci.h>
Michał Żygowskib8d35c12021-04-29 18:12:11 +020016#include <smp/node.h>
Bruce Griffith5888d862014-08-15 12:15:33 -060017
Elyes HAOUASd2d8a312018-02-08 13:38:21 +010018static void model_16_init(struct device *dev)
Bruce Griffith5888d862014-08-15 12:15:33 -060019{
20 printk(BIOS_DEBUG, "Model 16 Init.\n");
21
Bruce Griffith5888d862014-08-15 12:15:33 -060022 msr_t msr;
Bruce Griffith5888d862014-08-15 12:15:33 -060023 u32 siblings;
Bruce Griffith5888d862014-08-15 12:15:33 -060024
Bruce Griffith5888d862014-08-15 12:15:33 -060025 /* zero the machine check error status registers */
Felix Heldacbf1542021-07-13 16:44:18 +020026 mca_clear_status();
Bruce Griffith5888d862014-08-15 12:15:33 -060027
Michał Żygowskib8d35c12021-04-29 18:12:11 +020028 if (CONFIG(LOGICAL_CPUS)) {
Arthur Heymans44807ac2022-09-13 12:43:37 +020029 siblings = get_cpu_count() - 1; // minus BSP
Bruce Griffith5888d862014-08-15 12:15:33 -060030
Michał Żygowskib8d35c12021-04-29 18:12:11 +020031 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 Griffith5888d862014-08-15 12:15:33 -060035
Michał Żygowskib8d35c12021-04-29 18:12:11 +020036 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 Griffith5888d862014-08-15 12:15:33 -060041 }
Bruce Griffith5888d862014-08-15 12:15:33 -060042
43 /* DisableCf8ExtCfg */
44 msr = rdmsr(NB_CFG_MSR);
45 msr.hi &= ~(1 << (46 - 32));
46 wrmsr(NB_CFG_MSR, msr);
47
Bruce Griffith5888d862014-08-15 12:15:33 -060048 /* Write protect SMM space with SMMLOCK. */
Arthur Heymans7ae8fa52022-05-31 18:53:47 +020049 lock_smm();
Michał Żygowski319f0372018-10-25 15:48:54 +020050
Zheng Baob8c473e2020-06-09 09:30:39 +080051 amd_update_microcode_from_cbfs();
Michał Żygowskib8d35c12021-04-29 18:12:11 +020052
53 display_mtrrs();
Bruce Griffith5888d862014-08-15 12:15:33 -060054}
55
56static struct device_operations cpu_dev_ops = {
57 .init = model_16_init,
58};
59
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +010060static const struct cpu_device_id cpu_table[] = {
Kyösti Mälkkied98e942015-05-27 07:58:22 +030061 { X86_VENDOR_AMD, 0x730F00 },
62 { X86_VENDOR_AMD, 0x730F01 },
Bruce Griffith5888d862014-08-15 12:15:33 -060063 { 0, 0 },
64};
65
66static const struct cpu_driver model_16 __cpu_driver = {
67 .ops = &cpu_dev_ops,
68 .id_table = cpu_table,
69};