2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Advanced Micro Devices, Inc.
5 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <console/console.h>
18 #include <cpu/x86/msr.h>
19 #include <cpu/amd/mtrr.h>
20 #include <device/device.h>
21 #include <device/pci.h>
23 #include <cpu/x86/msr.h>
24 #include <cpu/x86/smm.h>
25 #include <cpu/x86/pae.h>
26 #include <pc80/mc146818rtc.h>
27 #include <cpu/x86/lapic.h>
28 #include "northbridge/amd/amdfam10/amdfam10.h"
29 #include <cpu/amd/model_10xxx_rev.h>
31 #include <cpu/x86/cache.h>
32 #include <cpu/x86/mtrr.h>
33 #include <cpu/amd/multicore.h>
34 #include <cpu/amd/model_10xxx_msr.h>
36 #define MCI_STATUS 0x401
38 static void model_10xxx_init(device_t dev
)
42 struct node_core_id id
;
43 #if CONFIG_LOGICAL_CPUS
47 id
= get_node_core_id(read_nb_cfg_54()); /* nb_cfg_54 can not be set */
48 printk(BIOS_DEBUG
, "nodeid = %02d, coreid = %02d\n", id
.nodeid
, id
.coreid
);
50 /* Turn on caching if we haven't already */
57 /* zero the machine check error status registers */
60 for (i
= 0; i
< 5; i
++) {
61 wrmsr(MCI_STATUS
+ (i
* 4), msr
);
66 /* Enable the local cpu apics */
69 /* Set the processor name string */
70 init_processor_name();
72 #if CONFIG_LOGICAL_CPUS
73 siblings
= cpuid_ecx(0x80000008) & 0xff;
76 msr
= rdmsr_amd(CPU_ID_FEATURES_MSR
);
78 wrmsr_amd(CPU_ID_FEATURES_MSR
, msr
);
80 msr
= rdmsr_amd(CPU_ID_EXT_FEATURES_MSR
);
81 msr
.hi
|= 1 << (33 - 32);
82 wrmsr_amd(CPU_ID_EXT_FEATURES_MSR
, msr
);
84 printk(BIOS_DEBUG
, "siblings = %02d, ", siblings
);
87 /* DisableCf8ExtCfg */
88 msr
= rdmsr(NB_CFG_MSR
);
89 msr
.hi
&= ~(1 << (46 - 32));
90 wrmsr(NB_CFG_MSR
, msr
);
92 msr
= rdmsr(BU_CFG2_MSR
);
93 /* Clear ClLinesToNbDis */
95 /* Clear bit 35 as per Erratum 343 */
96 msr
.hi
&= ~(1 << (35-32));
97 wrmsr(BU_CFG2_MSR
, msr
);
99 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER
)) {
100 printk(BIOS_DEBUG
, "Initializing SMM ASeg memory\n");
102 /* Set SMM base address for this CPU */
103 msr
= rdmsr(SMM_BASE_MSR
);
104 msr
.lo
= SMM_BASE
- (lapicid() * 0x400);
105 wrmsr(SMM_BASE_MSR
, msr
);
107 /* Enable the SMM memory window */
108 msr
= rdmsr(SMM_MASK_MSR
);
109 msr
.lo
|= (1 << 0); /* Enable ASEG SMRAM Range */
110 wrmsr(SMM_MASK_MSR
, msr
);
112 printk(BIOS_DEBUG
, "Disabling SMM ASeg memory\n");
114 /* Set SMM base address for this CPU */
115 msr
= rdmsr(SMM_BASE_MSR
);
116 msr
.lo
= SMM_BASE
- (lapicid() * 0x400);
117 wrmsr(SMM_BASE_MSR
, msr
);
119 /* Disable the SMM memory window */
122 wrmsr(SMM_MASK_MSR
, msr
);
125 /* Set SMMLOCK to avoid exploits messing with SMM */
126 msr
= rdmsr(HWCR_MSR
);
128 wrmsr(HWCR_MSR
, msr
);
132 static struct device_operations cpu_dev_ops
= {
133 .init
= model_10xxx_init
,
136 static struct cpu_device_id cpu_table
[] = {
138 { X86_VENDOR_AMD
, 0x100f00 }, /* SH-F0 L1 */
139 { X86_VENDOR_AMD
, 0x100f10 }, /* M2 */
140 { X86_VENDOR_AMD
, 0x100f20 }, /* S1g1 */
141 { X86_VENDOR_AMD
, 0x100f21 },
142 { X86_VENDOR_AMD
, 0x100f2A },
143 { X86_VENDOR_AMD
, 0x100f22 },
144 { X86_VENDOR_AMD
, 0x100f23 },
145 { X86_VENDOR_AMD
, 0x100f40 }, /* RB-C0 */
146 { X86_VENDOR_AMD
, 0x100F42 }, /* RB-C2 */
147 { X86_VENDOR_AMD
, 0x100F43 }, /* RB-C3 */
148 { X86_VENDOR_AMD
, 0x100F52 }, /* BL-C2 */
149 { X86_VENDOR_AMD
, 0x100F62 }, /* DA-C2 */
150 { X86_VENDOR_AMD
, 0x100F63 }, /* DA-C3 */
151 { X86_VENDOR_AMD
, 0x100F80 }, /* HY-D0 */
152 { X86_VENDOR_AMD
, 0x100F81 }, /* HY-D1 */
153 { X86_VENDOR_AMD
, 0x100F91 }, /* HY-D1 */
154 { X86_VENDOR_AMD
, 0x100FA0 }, /* PH-E0 */
158 static const struct cpu_driver model_10xxx __cpu_driver
= {
160 .id_table
= cpu_table
,