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 inline uint8_t is_fam15h(void)
43 family
= cpuid_eax(0x80000001);
44 family
= ((family
& 0xf00000) >> 16) | ((family
& 0xf00) >> 8);
47 /* Family 15h or later */
53 static inline uint8_t is_gt_rev_d(void)
56 uint8_t rev_gte_d
= 0;
60 family
= model
= cpuid_eax(0x80000001);
61 model
= ((model
& 0xf0000) >> 12) | ((model
& 0xf0) >> 4);
62 family
= ((family
& 0xf00000) >> 16) | ((family
& 0xf00) >> 8);
65 /* Family 15h or later */
68 if ((model
>= 0x8) || fam15h
)
69 /* Revision D or later */
75 static volatile uint8_t fam15h_startup_flags
[MAX_NODES_SUPPORTED
][MAX_CORES_SUPPORTED
] = {{ 0 }};
77 static void model_10xxx_init(device_t dev
)
81 struct node_core_id id
;
82 #if CONFIG_LOGICAL_CPUS
87 id
= get_node_core_id(read_nb_cfg_54()); /* nb_cfg_54 can not be set */
88 printk(BIOS_DEBUG
, "nodeid = %02d, coreid = %02d\n", id
.nodeid
, id
.coreid
);
91 delay_start
= !!(id
.coreid
& 0x1);
95 /* Turn on caching if we haven't already */
99 /* Initialize all variable MTRRs except the first pair.
100 * This prevents Linux from having to correct an inconsistent
101 * MTRR setup, which would crash Family 15h CPUs due to the
102 * compute unit structure sharing MTRR MSRs between AP cores.
109 for (i
= 0x2; i
< 0x10; i
++) {
110 wrmsr(0x00000200 | i
, msr
);
115 /* Set up other MTRRs */
118 while (!fam15h_startup_flags
[id
.nodeid
][id
.coreid
- 1]) {
119 /* Wait for CU first core startup */
127 /* zero the machine check error status registers */
130 for (i
= 0; i
< 5; i
++) {
131 wrmsr(MCI_STATUS
+ (i
* 4), msr
);
136 /* Enable the local cpu apics */
139 /* Set the processor name string */
140 init_processor_name();
142 #if CONFIG_LOGICAL_CPUS
143 siblings
= cpuid_ecx(0x80000008) & 0xff;
146 msr
= rdmsr_amd(CPU_ID_FEATURES_MSR
);
148 wrmsr_amd(CPU_ID_FEATURES_MSR
, msr
);
150 msr
= rdmsr_amd(CPU_ID_EXT_FEATURES_MSR
);
151 msr
.hi
|= 1 << (33 - 32);
152 wrmsr_amd(CPU_ID_EXT_FEATURES_MSR
, msr
);
154 printk(BIOS_DEBUG
, "siblings = %02d, ", siblings
);
157 /* Set bus unit configuration */
161 uint8_t compute_unit_count
= 0;
162 f5x80
= pci_read_config32(dev_find_slot(0, PCI_DEVFN(0x18 + id
.nodeid
, 5)), 0x80);
163 enabled
= f5x80
& 0xf;
165 compute_unit_count
= 1;
167 compute_unit_count
= 2;
169 compute_unit_count
= 3;
171 compute_unit_count
= 4;
172 msr
= rdmsr(BU_CFG2_MSR
);
173 msr
.lo
&= ~(0x3 << 6); /* ThrottleNbInterface[1:0] */
174 msr
.lo
|= (((compute_unit_count
- 1) & 0x3) << 6);
175 wrmsr(BU_CFG2_MSR
, msr
);
179 uint8_t core_count
= 0;
180 uint8_t node_count
= 0;
181 f0x60
= pci_read_config32(dev_find_slot(0, PCI_DEVFN(0x18 + id
.nodeid
, 0)), 0x60);
182 core_count
= (f0x60
>> 16) & 0x1f;
183 node_count
= ((f0x60
>> 4) & 0x7) + 1;
185 f0x160
= pci_read_config32(dev_find_slot(0, PCI_DEVFN(0x18 + id
.nodeid
, 0)), 0x160);
186 core_count
|= ((f0x160
>> 16) & 0x7) << 5;
189 core_count
/= node_count
;
190 msr
= rdmsr(BU_CFG2_MSR
);
192 msr
.hi
&= ~(0x3 << (36 - 32)); /* ThrottleNbInterface[3:2] */
193 msr
.hi
|= ((((core_count
- 1) >> 2) & 0x3) << (36 - 32));
195 msr
.lo
&= ~(0x3 << 6); /* ThrottleNbInterface[1:0] */
196 msr
.lo
|= (((core_count
- 1) & 0x3) << 6);
197 msr
.lo
&= ~(0x1 << 24); /* WcPlusDis = 0 */
198 wrmsr(BU_CFG2_MSR
, msr
);
201 /* Disable Cf8ExtCfg */
202 msr
= rdmsr(NB_CFG_MSR
);
203 msr
.hi
&= ~(1 << (46 - 32));
204 wrmsr(NB_CFG_MSR
, msr
);
207 msr
= rdmsr(BU_CFG3_MSR
);
208 /* Set CombineCr0Cd */
209 msr
.hi
|= (1 << (49-32));
210 wrmsr(BU_CFG3_MSR
, msr
);
212 msr
= rdmsr(BU_CFG2_MSR
);
213 /* Clear ClLinesToNbDis */
214 msr
.lo
&= ~(1 << 15);
215 /* Clear bit 35 as per Erratum 343 */
216 msr
.hi
&= ~(1 << (35-32));
217 wrmsr(BU_CFG2_MSR
, msr
);
220 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER
)) {
221 printk(BIOS_DEBUG
, "Initializing SMM ASeg memory\n");
223 /* Set SMM base address for this CPU */
224 msr
= rdmsr(SMM_BASE_MSR
);
225 msr
.lo
= SMM_BASE
- (lapicid() * 0x400);
226 wrmsr(SMM_BASE_MSR
, msr
);
228 /* Enable the SMM memory window */
229 msr
= rdmsr(SMM_MASK_MSR
);
230 msr
.lo
|= (1 << 0); /* Enable ASEG SMRAM Range */
231 wrmsr(SMM_MASK_MSR
, msr
);
233 printk(BIOS_DEBUG
, "Disabling SMM ASeg memory\n");
235 /* Set SMM base address for this CPU */
236 msr
= rdmsr(SMM_BASE_MSR
);
237 msr
.lo
= SMM_BASE
- (lapicid() * 0x400);
238 wrmsr(SMM_BASE_MSR
, msr
);
240 /* Disable the SMM memory window */
243 wrmsr(SMM_MASK_MSR
, msr
);
246 /* Set SMMLOCK to avoid exploits messing with SMM */
247 msr
= rdmsr(HWCR_MSR
);
249 wrmsr(HWCR_MSR
, msr
);
251 fam15h_startup_flags
[id
.nodeid
][id
.coreid
] = 1;
254 static struct device_operations cpu_dev_ops
= {
255 .init
= model_10xxx_init
,
258 static struct cpu_device_id cpu_table
[] = {
260 { X86_VENDOR_AMD
, 0x100f00 }, /* SH-F0 L1 */
261 { X86_VENDOR_AMD
, 0x100f10 }, /* M2 */
262 { X86_VENDOR_AMD
, 0x100f20 }, /* S1g1 */
263 { X86_VENDOR_AMD
, 0x100f21 },
264 { X86_VENDOR_AMD
, 0x100f2A },
265 { X86_VENDOR_AMD
, 0x100f22 },
266 { X86_VENDOR_AMD
, 0x100f23 },
267 { X86_VENDOR_AMD
, 0x100f40 }, /* RB-C0 */
268 { X86_VENDOR_AMD
, 0x100f42 }, /* RB-C2 */
269 { X86_VENDOR_AMD
, 0x100f43 }, /* RB-C3 */
270 { X86_VENDOR_AMD
, 0x100f52 }, /* BL-C2 */
271 { X86_VENDOR_AMD
, 0x100f62 }, /* DA-C2 */
272 { X86_VENDOR_AMD
, 0x100f63 }, /* DA-C3 */
273 { X86_VENDOR_AMD
, 0x100f80 }, /* HY-D0 */
274 { X86_VENDOR_AMD
, 0x100f81 }, /* HY-D1 */
275 { X86_VENDOR_AMD
, 0x100f91 }, /* HY-D1 */
276 { X86_VENDOR_AMD
, 0x100fa0 }, /* PH-E0 */
277 { X86_VENDOR_AMD
, 0x600f12 }, /* OR-B2 */
278 { X86_VENDOR_AMD
, 0x600f20 }, /* OR-C0 */
282 static const struct cpu_driver model_10xxx __cpu_driver
= {
284 .id_table
= cpu_table
,