Add more Fam10 CPUID strings from the AMD revision guide. Includes
[coreboot.git] / src / cpu / amd / model_10xxx / processor_name.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  * Copyright (C) 2008 Peter Stuge
6  * Copyright (C) 2010 Marc Jones <marcj303@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
20  */
21
22 /*
23  * This code sets the Processor Name String for AMD64 CPUs.
24  *
25  * Revision Guide for AMD Family 10h Processors
26  * Publication # 41322 Revision: 3.17 Issue Date: February 2008
27  */
28
29 #include <console/console.h>
30 #include <string.h>
31 #include <cpu/x86/msr.h>
32 #include <cpu/cpu.h>
33 #include <cpu/amd/model_10xxx_rev.h>
34
35 extern void wrmsr_amd(u32 index, msr_t msr);
36
37 /* The maximum length of CPU names is 48 bytes, including the final NULL byte.
38  * If you change these names your BIOS will _NOT_ pass the AMD validation and
39  * your mainboard will not be posted on the AMD Recommended Motherboard Website
40  */
41
42 struct str_s {
43         u8 Pg;
44         u8 NC;
45         u8 String;
46         char const *value;
47 };
48
49
50 static const struct str_s String1_socket_F[] = {
51         {0x00, 0x01, 0x00, "Dual-Core AMD Opteron(tm) Processor 83"},
52         {0x00, 0x01, 0x01, "Dual-Core AMD Opteron(tm) Processor 23"},
53         {0x00, 0x03, 0x00, "Quad-Core AMD Opteron(tm) Processor 83"},
54         {0x00, 0x03, 0x01, "Quad-Core AMD Opteron(tm) Processor 23"},
55         {0x00, 0x03, 0x02, "Embedded AMD Opteron(tm) Processor 83"},
56         {0x00, 0x03, 0x03, "Embedded AMD Opteron(tm) Processor 23"},
57         {0x00, 0x03, 0x04, "Embedded AMD Opteron(tm) Processor 13"},
58         {0x00, 0x03, 0x05, "AMD Phenom(tm) FX-"},
59         {0x01, 0x01, 0x01, "Embedded AMD Opteron(tm) Processor"},
60         {0, 0, 0, NULL}
61 };
62
63 static const struct str_s String2_socket_F[] = {
64         {0x00, 0xFF, 0x0A, " SE"},
65         {0x00, 0xFF, 0x0B, " HE"},
66         {0x00, 0xFF, 0x0C, " EE"},
67         {0x00, 0xFF, 0x0D, " Quad-Core Processor"},
68         {0x00, 0xFF, 0x0F, ""},
69         {0x01, 0x01, 0x01, "GF HE"},
70         {0, 0, 0, NULL}
71 };
72
73
74 static const struct str_s String1_socket_AM2[] = {
75         {0x00, 0x00, 0x00, "AMD Athlon(tm) Processor LE-"},
76         {0x00, 0x00, 0x01, "AMD Sempron(tm) Processor LE-"},
77         {0x00, 0x00, 0x02, "AMD Sempron(tm) 1"},
78         {0x00, 0x00, 0x03, "AMD Athlon(tm) II 1"},
79         {0x00, 0x01, 0x00, "Dual-Core AMD Opteron(tm) Processor 13"},
80         {0x00, 0x01, 0x01, "AMD Athlon(tm)"},
81         {0x00, 0x01, 0x03, "AMD Athlon(tm) II X2 2"},
82         {0x00, 0x01, 0x04, "AMD Athlon(tm) II X2 B"},
83         {0x00, 0x01, 0x05, "AMD Athlon(tm) II X2"},
84         {0x00, 0x01, 0x07, "AMD Phenom(tm) II X2 5"},
85         {0x00, 0x01, 0x0A, "AMD Phenom(tm) II X2"},
86         {0x00, 0x01, 0x0B, "AMD Phenom(tm) II X2 B"},
87         {0x00, 0x02, 0x00, "AMD Phenom(tm)"},
88         {0x00, 0x02, 0x03, "AMD Phenom(tm) II X3 B"},
89         {0x00, 0x02, 0x04, "AMD Phenom(tm) II X3"},
90         {0x00, 0x02, 0x07, "AMD Athlon(tm) II X3 4"},
91         {0x00, 0x02, 0x08, "AMD Phenom(tm) II X3 7"},
92         {0x00, 0x02, 0x0A, "AMD Athlon(tm) II X3"},
93         {0x00, 0x03, 0x00, "Quad-Core AMD Opteron(tm) Processor 13"},
94         {0x00, 0x03, 0x01, "AMD Phenom(tm) FX-"},
95         {0x00, 0x03, 0x02, "AMD Phenom(tm)"},
96         {0x00, 0x03, 0x03, "AMD Phenom(tm) II X4 9"},
97         {0x00, 0x03, 0x04, "AMD Phenom(tm) II X4 8"},
98         {0x00, 0x03, 0x07, "AMD Phenom(tm) II X4 B"},
99         {0x00, 0x03, 0x08, "AMD Phenom(tm) II X4"},
100         {0x00, 0x03, 0x0A, "AMD Athlon(tm) II X4 6"},
101         {0x00, 0x03, 0x0F, "AMD Athlon(tm) II X4"},
102         {0, 0, 0, NULL}
103 };
104
105 static const struct str_s String2_socket_AM2[] = {
106         {0x00, 0x00, 0x00, "00"},
107         {0x00, 0x00, 0x01, "10"},
108         {0x00, 0x00, 0x02, "20"},
109         {0x00, 0x00, 0x03, "30"},
110         {0x00, 0x00, 0x04, "40"},
111         {0x00, 0x00, 0x05, "50"},
112         {0x00, 0x00, 0x06, "60"},
113         {0x00, 0x00, 0x07, "70"},
114         {0x00, 0x00, 0x08, "80"},
115         {0x00, 0x00, 0x09, "90"},
116         {0x00, 0x00, 0x09, " Processor"},
117         {0x00, 0x00, 0x09, "u Processor"},
118         {0x00, 0x01, 0x00, "00 Dual-Core Processor"},
119         {0x00, 0x01, 0x01, "00e Dual-Core Processor"},
120         {0x00, 0x01, 0x02, "00B Dual-Core Processor"},
121         {0x00, 0x01, 0x03, "50 Dual-Core Processor"},
122         {0x00, 0x01, 0x04, "50e Dual-Core Processor"},
123         {0x00, 0x01, 0x05, "50B Dual-Core Processor"},
124         {0x00, 0x01, 0x06, " Processor"},
125         {0x00, 0x01, 0x07, "e Processor"},
126         {0x00, 0x01, 0x09, "0 Processor"},
127         {0x00, 0x01, 0x0A, "0e Processor"},
128         {0x00, 0x01, 0x0B, "u Processor"},
129         {0x00, 0x02, 0x00, "00 Triple-Core Processor"},
130         {0x00, 0x02, 0x01, "00e Triple-Core Processor"},
131         {0x00, 0x02, 0x02, "00B Triple-Core Processor"},
132         {0x00, 0x02, 0x03, "50 Triple-Core Processor"},
133         {0x00, 0x02, 0x04, "50e Triple-Core Processor"},
134         {0x00, 0x02, 0x05, "50B Triple-Core Processor"},
135         {0x00, 0x02, 0x06, " Processor"},
136         {0x00, 0x02, 0x07, "e Processor"},
137         {0x00, 0x02, 0x09, "0e Processor"},
138         {0x00, 0x02, 0x0A, "0 Processor"},
139         {0x00, 0x03, 0x00, "00 Quad-Core Processor"},
140         {0x00, 0x03, 0x01, "00e Quad-Core Processor"},
141         {0x00, 0x03, 0x02, "00B Quad-Core Processor"},
142         {0x00, 0x03, 0x03, "50 Quad-Core Processor"},
143         {0x00, 0x03, 0x04, "50e Quad-Core Processor"},
144         {0x00, 0x03, 0x05, "50B Quad-Core Processor"},
145         {0x00, 0x03, 0x06, " Processor"},
146         {0x00, 0x03, 0x07, "e Processor"},
147         {0x00, 0x03, 0x09, "0e Processor"},
148         {0x00, 0x03, 0x0A, " SE"},
149         {0x00, 0x03, 0x0B, " HE"},
150         {0x00, 0x03, 0x0C, " EE"},
151         {0x00, 0x03, 0x0D, " Quad-Core Processor"},
152         {0x00, 0x03, 0x0E, "0 Processor"},
153         {0x00, 0xFF, 0x0F, ""},
154         {0, 0, 0, NULL}
155 };
156
157
158 const char const *unknown = "AMD Processor model unknown";
159 const char const *unknown2 = " type unknown";
160 const char const *sample = "AMD Engineering Sample";
161 const char const *thermal = "AMD Thermal Test Kit";
162
163
164 static int strcpymax(char *dst, const char *src, int buflen)
165 {
166         int i;
167         for (i = 0; i < buflen && src[i]; i++)
168                 dst[i] = src[i];
169         if (i >= buflen)
170                 i--;
171         dst[i] = 0;
172         return i;
173 }
174
175
176 int init_processor_name(void)
177 {
178         /* variable names taken from fam10 revision guide for clarity */
179         u32 BrandId;    /* CPUID Fn8000_0001_EBX */
180         u8 String1;     /* BrandID[14:11] */
181         u8 String2;     /* BrandID[3:0] */
182         u8 Model;       /* BrandID[10:4] */
183         u8 Pg;          /* BrandID[15] */
184         u8 PkgTyp;      /* BrandID[31:28] */
185         u8 NC;          /* CPUID Fn8000_0008_ECX */
186         const char *processor_name_string = unknown;
187         char program_string[48];
188         u32 *p_program_string = (u32 *)program_string;
189         msr_t msr;
190         int i, j = 0, str2_checkNC = 1;
191         const struct str_s *str, *str2;
192
193
194         /* Find out which CPU brand it is */
195         BrandId = cpuid_ebx(0x80000001);
196         String1 = (u8)((BrandId >> 11) & 0x0F);
197         String2 = (u8)((BrandId >> 0) & 0x0F);
198         Model = (u8)((BrandId >> 4) & 0x7F);
199         Pg = (u8)((BrandId >> 15) & 0x01);
200         PkgTyp = (u8)((BrandId >> 28) & 0x0F);
201         NC = (u8)(cpuid_ecx(0x80000008) & 0xFF);
202
203         /* null the string */
204         memset(program_string, 0, sizeof(program_string));
205
206         if (!Model) {
207                 processor_name_string = Pg ? sample : thermal;
208                 goto done;
209         }
210
211         switch (PkgTyp) {
212         case 0:         /* F1207 */
213                 str = String1_socket_F;
214                 str2 = String2_socket_F;
215                 str2_checkNC = 0;
216                 break;
217         case 1:         /* AM2 */
218                 str = String1_socket_AM2;
219                 str2 = String2_socket_AM2;
220                 break;
221         default:
222                 goto done;
223         }
224
225         /* String1 */
226         for (i = 0; str[i].value; i++) {
227                 if ((str[i].Pg == Pg) &&
228                     (str[i].NC == NC) &&
229                     (str[i].String == String1)) {
230                         processor_name_string = str[i].value;
231                         break;
232                 }
233         }
234
235         if (!str[i].value)
236                 goto done;
237
238         j = strcpymax(program_string, processor_name_string,
239                       sizeof(program_string));
240
241         /* Translate Model from 01-99 to ASCII and put it on the end.
242          * Numbers less than 10 should include a leading zero, e.g., 09.*/
243         if (Model < 100 && j < sizeof(program_string) - 2) {
244                 program_string[j++] = (Model / 10) + '0';
245                 program_string[j++] = (Model % 10) + '0';
246         }
247
248         processor_name_string = unknown2;
249
250         /* String 2 */
251         for(i = 0; str2[i].value; i++) {
252                 if ((str2[i].Pg == Pg) &&
253                     ((str2[i].NC == NC) || !str2_checkNC) &&
254                     (str2[i].String == String2)) {
255                         processor_name_string = str2[i].value;
256                         break;
257                 }
258         }
259
260
261 done:
262         strcpymax(&program_string[j], processor_name_string,
263                   sizeof(program_string) - j);
264
265         printk(BIOS_DEBUG, "CPU model: %s\n", program_string);
266
267         for (i = 0; i < 6; i++) {
268                 msr.lo = p_program_string[(2 * i) + 0];
269                 msr.hi = p_program_string[(2 * i) + 1];
270                 wrmsr_amd(0xC0010030 + i, msr);
271         }
272
273         return 0;
274 }