Remove some warnings.
[coreboot.git] / src / cpu / amd / model_fxx / processor_name.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 coresystems GmbH
5  * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
6  * Copyright (C) 2007 University of Mannheim
7  * (Written by Sven Kapferer <skapfere@rumms.uni-mannheim.de> for Uni Ma.)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; version 2 of the License.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
21  */
22
23 /*
24  * This code sets the Processor Name String for AMD64 CPUs.
25  *
26  * Written by Stefan Reinauer <stepan@coresystems.de> using
27  * the Revision Guide for AMD Athlon™ 64 and AMD Opteron™ Processors
28  * Document ID 25759 Rev 3.59, April 2006 (Public Version).
29  *
30  * Updated by Sven Kapferer <skapfere@rumms.uni-mannheim.de> using
31  * the Revision Guide for AMD NPT Family 0Fh Processors
32  * Document ID 33610 Rev 3.00, October 2006 (Public Version).
33  */
34
35 #include <console/console.h>
36 #include <string.h>
37 #include <cpu/x86/msr.h>
38
39 /* The maximum length of CPU names is 48 bytes, including the final NULL byte.
40  * If you change these names your BIOS will _NOT_ pass the AMD validation and
41  * your mainboard will not be posted on the AMD Recommended Motherboard Website
42  */
43
44 #if CONFIG_K8_REV_F_SUPPORT == 0
45 static char *processor_names[]={
46         /* 0x00 */ "AMD Engineering Sample",
47         /* 0x01-0x03 */ NULL, NULL, NULL,
48         /* 0x04 */ "AMD Athlon(tm) 64 Processor XX00+",
49         /* 0x05 */ "AMD Athlon(tm) 64 X2 Dual Core Processor XX00+",
50         /* 0x06-0x07 */ NULL, NULL,
51         /* 0x08 */ "Mobile AMD Athlon(tm) 64 Processor XX00+",
52         /* 0x09 */ "Mobile AMD Athlon(tm) 64 Processor XX00+",
53         /* 0x0A */ "AMD Turion(tm) 64 Mobile Technology ML-XX",
54         /* 0x0B */ "AMD Turion(tm) 64 Mobile Technology MT-XX",
55         /* 0x0C */ "AMD Opteron(tm) Processor 1YY",
56         /* 0x0D */ "AMD Opteron(tm) Processor 1YY",
57         /* 0x0E */ "AMD Opteron(tm) Processor 1YY HE",
58         /* 0x0F */ "AMD Opteron(tm) Processor 1YY EE",
59         /* 0x10 */ "AMD Opteron(tm) Processor 2YY",
60         /* 0x11 */ "AMD Opteron(tm) Processor 2YY",
61         /* 0x12 */ "AMD Opteron(tm) Processor 2YY HE",
62         /* 0x13 */ "AMD Opteron(tm) Processor 2YY EE",
63         /* 0x14 */ "AMD Opteron(tm) Processor 8YY",
64         /* 0x15 */ "AMD Opteron(tm) Processor 8YY",
65         /* 0x16 */ "AMD Opteron(tm) Processor 8YY HE",
66         /* 0x17 */ "AMD Opteron(tm) Processor 8YY EE",
67         /* 0x18 */ "AMD Athlon(tm) 64 Processor VV00+",
68         /* 0x19-0x1C */ NULL, NULL, NULL, NULL,
69         /* 0x1D */ "Mobile AMD Athlon(tm) XP-M Processor XX00+",
70         /* 0x1E */ "Mobile AMD Athlon(tm) XP-M Processor XX00+",
71         /* 0x1F */ NULL,
72         /* 0x20 */ "AMD Athlon(tm) XP Processor XX00+",
73         /* 0x21 */ "Mobile AMD Sempron(tm) Processor TT00+",
74         /* 0x22 */ "AMD Sempron(tm) Processor TT00+",
75         /* 0x23 */ "Mobile AMD Sempron(tm) Processor TT00+",
76         /* 0x24 */ "AMD Athlon(tm) 64 FX-ZZ Processor",
77         /* 0x25 */ NULL,
78         /* 0x26 */ "AMD Sempron(tm) Processor TT00+",
79         /* 0x27-0x28 */ NULL, NULL, 
80         /* 0x29 */ "Dual Core AMD Opteron(tm) Processor 1RR SE",
81         /* 0x2A */ "Dual Core AMD Opteron(tm) Processor 2RR SE",
82         /* 0x2B */ "Dual Core AMD Opteron(tm) Processor 8RR SE",
83         /* 0x2C */ "Dual Core AMD Opteron(tm) Processor 1RR",
84         /* 0x2D */ "Dual Core AMD Opteron(tm) Processor 1RR",
85         /* 0x2E */ "Dual Core AMD Opteron(tm) Processor 1RR HE",
86         /* 0x2F */ "Dual Core AMD Opteron(tm) Processor 1RR EE",
87         /* 0x30 */ "Dual Core AMD Opteron(tm) Processor 2RR",
88         /* 0x31 */ "Dual Core AMD Opteron(tm) Processor 2RR",
89         /* 0x32 */ "Dual Core AMD Opteron(tm) Processor 2RR HE",
90         /* 0x33 */ "Dual Core AMD Opteron(tm) Processor 2RR EE",
91         /* 0x34 */ "Dual Core AMD Opteron(tm) Processor 8RR",
92         /* 0x35 */ "Dual Core AMD Opteron(tm) Processor 8RR",
93         /* 0x36 */ "Dual Core AMD Opteron(tm) Processor 8RR HE",
94         /* 0x37 */ "Dual Core AMD Opteron(tm) Processor 8RR EE",
95         /* 0x38 */ "Dual Core AMD Opteron(tm) Processor 1RR",
96         /* 0x39 */ "Dual Core AMD Opteron(tm) Processor 2RR",
97         /* 0x3A */ "Dual Core AMD Opteron(tm) Processor 8RR"
98 #define MAX_CPU_NUMBER 0x3A
99 };
100 #endif
101
102 /* wrmsr_amd() is from yhlu's changes to model_fxx_init.c */
103
104 static inline void wrmsr_amd(unsigned index, msr_t msr)
105 {
106         __asm__ __volatile__ (
107                 "wrmsr"
108                 : /* No outputs */
109                 : "c" (index), "a" (msr.lo), "d" (msr.hi), "D" (0x9c5a203a)
110                 );
111 }
112
113 static inline unsigned int cpuid_eax(unsigned int op)
114 {
115         unsigned int eax;
116
117         __asm__("cpuid"
118                 : "=a" (eax)
119                 : "0" (op)
120                 : "ebx", "ecx", "edx");
121         return eax;
122 }
123
124 static inline unsigned int cpuid_ebx(unsigned int op)
125 {
126         unsigned int eax, ebx;
127
128         __asm__("cpuid"
129                 : "=a" (eax), "=b" (ebx)
130                 : "0" (op)
131                 : "ecx", "edx" );
132         return ebx;
133 }
134
135 static inline unsigned int cpuid_ecx(unsigned int op)
136 {
137         unsigned int eax, ecx;
138
139         __asm__("cpuid"
140                 : "=a" (eax), "=c" (ecx)
141                 : "0" (op)
142                 : "ebx", "edx" );
143         return ecx;
144 }
145
146 static inline void strcpy(char *dst, const char *src)
147 {
148         while (*src) *dst++ = *src++;
149 }
150
151
152 int init_processor_name(void)
153 {
154 #if CONFIG_K8_REV_F_SUPPORT == 0
155         u32 EightBitBrandId;
156 #endif
157         u32 BrandId;
158         u32 BrandTableIndex;
159         u32 NN;
160         u32 ModelNumber=0;
161         msr_t progmsr;
162         int i;
163
164         const char *processor_name_string=NULL;
165         char program_string[48];
166         unsigned int *program_values = (unsigned int *)program_string;
167
168 #if CONFIG_K8_REV_F_SUPPORT == 0
169         /* Find out which CPU brand it is */
170         EightBitBrandId = cpuid_ebx(0x00000001) & 0xff;
171         BrandId = cpuid_ebx(0x80000001) & 0xffff;
172
173         if(!EightBitBrandId && !BrandId) {
174                 BrandTableIndex = 0;
175                 NN = 0xffffff;
176         } else if(!EightBitBrandId) {
177                 BrandTableIndex = (BrandId >> 6) & 0x3f; // BrandId[11:6]
178                 NN = BrandId & 0x3f; // // BrandId[6:0]
179         } else {
180                 BrandTableIndex = EightBitBrandId >> (5-2) & 0xfc; // { 0b, 8BitBrandId[7:5], 00b }
181                 NN = EightBitBrandId & 0x1f; // 8BitBrandId[4:0]
182         }
183
184         /* Look up the CPU brand in above table */
185         if (BrandTableIndex <= MAX_CPU_NUMBER)
186                 processor_name_string = processor_names[BrandTableIndex];
187
188         if (!processor_name_string)
189                 processor_name_string = "AMD Processor model unknown";
190 #endif
191
192 #if CONFIG_K8_REV_F_SUPPORT == 1
193         u32 Socket;
194         u32 CmpCap;
195         u32 PwrLmt;
196
197         BrandId = cpuid_ebx(0x80000001) & 0xffff;
198         Socket = (cpuid_eax(0x80000001) & 0x00000030) >> 4; // 00b = S1g1, 01b = F (1207), 11b = AM2
199         CmpCap = cpuid_ecx(0x80000008) & 0x03; // Number of CPU cores
200
201         PwrLmt = ((BrandId >> 14) & 0x01) | ((BrandId >> 5) & 0x0e); // BrandId[8:6,14]
202         BrandTableIndex = (BrandId >> 9) & 0x1f; // BrandId[13:9]
203         NN = ((BrandId >> 15) & 0x01) | (BrandId & 0x3f); // BrandId[15,5:0]
204
205         if (((BrandTableIndex == 0) && (PwrLmt == 0)) || (NN == 0)) {
206                 processor_name_string = "AMD Engineering Sample";
207         } else {
208                 /* Use all fields to identify CPU */
209                 switch ((Socket << 16) | (CmpCap << 12) | (BrandTableIndex << 4)
210                         | PwrLmt) {
211                 /* Socket F */
212                 case 0x10012:
213                         processor_name_string =
214                             "AMD Opteron(tm) Processor 22RR EE";
215                         break;
216                 case 0x11002:
217                         processor_name_string =
218                             "Dual-Core AMD Opteron(tm) Processor 12RR EE";
219                         break;
220                 case 0x11006:
221                         processor_name_string =
222                             "Dual-Core AMD Opteron(tm) Processor 12RR HE";
223                         break;
224                 case 0x11012:
225                         processor_name_string =
226                             "Dual-Core AMD Opteron(tm) Processor 22RR EE";
227                         break;
228                 case 0x11016:
229                         processor_name_string =
230                             "Dual-Core AMD Opteron(tm) Processor 22RR HE";
231                         break;
232                 case 0x1101a:
233                         processor_name_string =
234                             "Dual-Core AMD Opteron(tm) Processor 22RR";
235                         break;
236                 case 0x1101c:
237                         processor_name_string =
238                             "Dual-Core AMD Opteron(tm) Processor 22RR SE";
239                         break;
240                 case 0x11042:
241                         processor_name_string =
242                             "Dual-Core AMD Opteron(tm) Processor 82RR EE";
243                         break;
244                 case 0x11046:
245                         processor_name_string =
246                             "Dual-Core AMD Opteron(tm) Processor 82RR HE";
247                         break;
248                 case 0x1104a:
249                         processor_name_string =
250                             "Dual-Core AMD Opteron(tm) Processor 82RR";
251                         break;
252                 case 0x1104c:
253                         processor_name_string =
254                             "Dual-Core AMD Opteron(tm) Processor 82RR SE";
255                         break;
256                 case 0x1106e:
257                         processor_name_string =
258                             "AMD Athlon(tm) 64 Processor FX-ZZ Processor";
259                         break;
260                 /* Socket AM2 */
261                 /* single core */
262                 case 0x30015:
263                         processor_name_string =
264                             "AMD Sempron(tm) Processor LE-1RR0";
265                         break;
266                 case 0x30026:
267                         processor_name_string =
268                             "AMD Athlon(tm) Processor LE-1ZZ0";
269                         break;
270                 case 0x30036:
271                         processor_name_string =
272                             "AMD Athlon(tm) Processor 1ZZ0B";
273                         break;
274                 case 0x30041:
275                 case 0x30042:
276                 case 0x30043:
277                 case 0x30044:
278                 case 0x30045:
279                 case 0x30048:
280                         processor_name_string =
281                             "AMD Athlon(tm) 64 Processor TT00+";
282                         break;
283                 case 0x30052:
284                         processor_name_string =
285                             "AMD Sempron(tm) Processor RR50p";
286                 case 0x30064:
287                 case 0x30068:
288                         processor_name_string =
289                             "AMD Sempron(tm) Processor TT00+";
290                         break;
291                 case 0x30071:
292                 case 0x30072:
293                         processor_name_string =
294                             "AMD Sempron(tm) Processor TT0U";
295                         break;
296                 case 0x30082:
297                 case 0x30083:
298                         processor_name_string =
299                             "AMD Athlon(tm) Processor TT50e";
300                         break;
301                 case 0x30092:
302                         processor_name_string =
303                             "AMD Athlon(tm) Neo Processor MV-TT";
304                         break;
305                 /* dual-core */
306                 case 0x31016:
307                         processor_name_string =
308                             "Dual-Core AMD Opteron(tm) Processor 12RR HE";
309                         break;
310                 case 0x3101a:
311                         processor_name_string =
312                             "Dual-Core AMD Opteron(tm) Processor 12RR";
313                         break;
314                 case 0x3101c:
315                         processor_name_string =
316                             "Dual-Core AMD Opteron(tm) Processor 12RR SE";
317                         break;
318                 case 0x31033:
319                         processor_name_string =
320                             "AMD Athlon(tm) X2 Dual Core Processor BE-2TT0";
321                         break;
322                 case 0x31041:
323                 case 0x31042:
324                 case 0x31046:
325                 case 0x31048:
326                 case 0x3104c:
327                         processor_name_string =
328                             "AMD Athlon(tm) 64 X2 Dual Core Processor TT00+";
329                         break;
330                 case 0x3105c:
331                         processor_name_string =
332                             "AMD Athlon(tm) 64 FX-ZZ Dual Core Processor";
333                         break;
334                 case 0x31066:
335                         processor_name_string =
336                             "AMD Sempron(tm) Dual Core Processor RR00";
337                         break;
338                 case 0x31073:
339                         processor_name_string =
340                             "AMD Athlon(tm) Dual Core Processor TT50e";
341                         break;
342                 case 0x31076:
343                 case 0x31077:
344                         processor_name_string =
345                             "AMD Athlon(tm) Dual Core Processor TT00B";
346                         break;
347                 case 0x31083:
348                         processor_name_string =
349                             "AMD Athlon(tm) Dual Core Processor TT50B";
350                         break;
351                 case 0x31091:
352                         processor_name_string =
353                             "AMD Athlon(tm) X2 Dual Core Processor TT50e";
354                         break;
355                 /* Socket S1g1 */
356                 /* single core */
357                 case 0x00012:
358                         processor_name_string =
359                             "AMD Athlon(tm) 64 Processor TT00+";
360                         break;
361                 case 0x0002c:
362                         processor_name_string =
363                             "AMD Turion(tm) 64 Mobile Technology MK-YY";
364                         break;
365                 case 0x00031:
366                         processor_name_string =
367                             "Mobile AMD Sempron(tm) Processor TT00+";
368                         break;
369                 case 0x00036:
370                         processor_name_string =
371                             "Mobile AMD Sempron(tm) Processor PP00+";
372                         break;
373                 case 0x0003c:
374                         processor_name_string =
375                             "Mobile AMD Sempron(tm) Processor PP00+";
376                         break;
377                 case 0x00042:
378                         processor_name_string =
379                             "AMD Sempron(tm) Processor TT00+";
380                         break;
381                 case 0x00064:
382                 case 0x00066:
383                 case 0x0006c:
384                         processor_name_string =
385                             "AMD Athlon(tm) Processor TF-TT";
386                         break;
387                 /* dual-core */
388                 case 0x0101c:
389                         processor_name_string =
390                             "AMD Sempron(tm) Dual Core Processor TJ-YY";
391                         break;
392                 case 0x0102c:
393                         processor_name_string =
394                             "AMD Turion(tm) 64 X2 Mobile Technology TL-YY";
395                         break;
396                 case 0x01034:
397                 case 0x0103c:
398                         processor_name_string =
399                             "AMD Athlon(tm) 64 X2 Dual-Core Processor TK-YY";
400                         break;
401                 case 0x01054:
402                         processor_name_string =
403                             "AMD Athlon(tm) 64 X2 Dual Core Processor TT00+";
404                         break;
405                 default:
406                         processor_name_string = "AMD Processor model unknown";
407                 }
408         }
409 #endif
410
411         memset(program_string, 0, 48);
412         strcpy(program_string, processor_name_string);
413         
414         /* Now create a model number - See Table 4. Model Number Calculation
415          * in the Revision Guide. NOTE: #6, EE was changed to VV because 
416          * otherwise it clashes with the brand names.
417          */
418         
419         for (i=0; i<47; i++) { // 48 -1 
420                 if(program_string[i] == program_string[i+1]) {
421                         switch (program_string[i]) {
422 #if CONFIG_K8_REV_F_SUPPORT == 0
423                         case 'X': ModelNumber = 22+ NN; break;
424                         case 'Y': ModelNumber = 38 + (2*NN); break;
425                         case 'Z':
426                         case 'T': ModelNumber = 24 + NN; break;
427                         case 'R': ModelNumber = 45 + (5*NN); break;
428                         case 'V': ModelNumber =  9 + NN; break;
429 #endif
430
431 #if CONFIG_K8_REV_F_SUPPORT == 1
432                         case 'R': ModelNumber = NN - 1; break;
433                         case 'P': ModelNumber = 26 + NN; break;
434                         case 'T': ModelNumber = 15 + (CmpCap * 10) + NN; break;
435                         case 'Z': ModelNumber = 57 + NN; break;
436                         case 'Y': ModelNumber = 29 + NN; break;
437 #endif
438                         }
439                         
440                         if(ModelNumber && ModelNumber < 100) {
441                                 // No idea what to do with RR=100. According
442                                 // to the revision guide this is possible.
443                                 // 
444                                 // --> "AMD Opteron(tm) Processor 8100"?
445                                 program_string[i]=(ModelNumber/10)+'0';
446                                 program_string[i+1]=(ModelNumber%10)+'0';
447                                 break;
448                         }
449                 }
450         }
451         
452         printk_debug("CPU model %s\n", program_string);
453
454         for (i=0; i<6; i++) {
455                 progmsr.lo = program_values[(2*i)+0];
456                 progmsr.hi = program_values[(2*i)+1];
457                 wrmsr_amd(0xc0010030+i, progmsr);
458         }
459
460         return 0;
461 }
462