Add CPUID processor name string support for Fam10 CPUs.
[coreboot.git] / src / cpu / amd / model_10xxx / model_10xxx_init.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <cpu/x86/msr.h>
22 #include <cpu/amd/mtrr.h>
23 #include <device/device.h>
24 #include <device/pci.h>
25 #include <string.h>
26 #include <cpu/x86/msr.h>
27 #include <cpu/x86/pae.h>
28 #include <pc80/mc146818rtc.h>
29 #include <cpu/x86/lapic.h>
30
31 #include "../../../northbridge/amd/amdfam10/amdfam10.h"
32
33 #include <cpu/amd/model_10xxx_rev.h>
34 #include <cpu/cpu.h>
35 #include <cpu/x86/cache.h>
36 #include <cpu/x86/mtrr.h>
37 #include <cpu/x86/mem.h>
38 #include <cpu/amd/quadcore.h>
39 #include <cpu/amd/model_10xxx_msr.h>
40
41 extern device_t get_node_pci(u32 nodeid, u32 fn);
42 extern int init_processor_name(void);
43
44
45
46 #define MCI_STATUS 0x401
47
48
49 msr_t rdmsr_amd(u32 index)
50 {
51          msr_t result;
52          __asm__ __volatile__ (
53                  "rdmsr"
54                  : "=a" (result.lo), "=d" (result.hi)
55                  : "c" (index), "D" (0x9c5a203a)
56                  );
57          return result;
58 }
59
60
61 void wrmsr_amd(u32 index, msr_t msr)
62 {
63         __asm__ __volatile__ (
64                 "wrmsr"
65                 : /* No outputs */
66                 : "c" (index), "a" (msr.lo), "d" (msr.hi), "D" (0x9c5a203a)
67                 );
68 }
69
70
71 void model_10xxx_init(device_t dev)
72 {
73         u8 i;
74         msr_t msr;
75         struct node_core_id id;
76 #if CONFIG_LOGICAL_CPUS == 1
77         u32 siblings;
78 #endif
79
80         id = get_node_core_id(read_nb_cfg_54()); /* nb_cfg_54 can not be set */
81         printk_debug("nodeid = %02d, coreid = %02d\n", id.nodeid, id.coreid);
82
83         /* Turn on caching if we haven't already */
84         x86_enable_cache();
85         amd_setup_mtrrs();
86         x86_mtrr_check();
87
88         disable_cache();
89
90         /* zero the machine check error status registers */
91         msr.lo = 0;
92         msr.hi = 0;
93         for(i=0; i < 5; i++) {
94                 wrmsr(MCI_STATUS + (i * 4),msr);
95         }
96
97
98         enable_cache();
99
100         /* Enable the local cpu apics */
101         setup_lapic();
102
103         /* Set the processor name string */
104         init_processor_name();
105
106 #if CONFIG_LOGICAL_CPUS == 1
107         siblings = cpuid_ecx(0x80000008) & 0xff;
108
109         if (siblings > 0) {
110                 msr = rdmsr_amd(CPU_ID_FEATURES_MSR);
111                 msr.lo |= 1 << 28;
112                 wrmsr_amd(CPU_ID_FEATURES_MSR, msr);
113
114                 msr = rdmsr_amd(CPU_ID_EXT_FEATURES_MSR);
115                 msr.hi |= 1 << (33-32);
116                 wrmsr_amd(CPU_ID_EXT_FEATURES_MSR, msr);
117         }
118         printk_debug("siblings = %02d, ", siblings);
119 #endif
120
121         /* DisableCf8ExtCfg */
122         msr = rdmsr(NB_CFG_MSR);
123         msr.hi &= ~(1 << (46-32));
124         wrmsr(NB_CFG_MSR, msr);
125
126         /* Write protect SMM space with SMMLOCK. */
127         msr = rdmsr(HWCR_MSR);
128         msr.lo |= (1 << 0);
129         wrmsr(HWCR_MSR, msr);
130
131 }
132
133 static struct device_operations cpu_dev_ops = {
134         .init = model_10xxx_init,
135 };
136 static struct cpu_device_id cpu_table[] = {
137 //AMD_GH_SUPPORT
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         { 0, 0 },
146 };
147 static struct cpu_driver model_10xxx __cpu_driver = {
148         .ops      = &cpu_dev_ops,
149         .id_table = cpu_table,
150 };