This is part of the outstanding mcp55 commit from January 18th. It will
[coreboot.git] / src / cpu / amd / model_fxx / processor_name.c
1 /*
2  * processor_name.c
3  *
4  * This code sets the Processor Name String for AMD64 CPUs.
5  *
6  * Written by Stefan Reinauer <stepan@coresystems.de> using
7  * the Revision Guide for AMD Athlon™ 64 and AMD Opteron™ Processors
8  * Document ID 25759 Rev 3.59, April 2006 (Public Version)
9  *
10  * (C) 2006 by coresystems GmbH <info@coresystems.de>
11  *
12  * This file is subject to the terms and conditions of the GNU General
13  * Public License. See the file COPYING in the main directory of this
14  * archive for more details.
15  *
16  */
17
18 #include <console/console.h>
19
20 #include <string.h>
21 #include <cpu/x86/msr.h>
22
23 /* The maximum length of CPU names is 48 bytes, including the final NULL byte.
24  * If you change these names your BIOS will _NOT_ pass the AMD validation and
25  * your mainboard will not be posted on the AMD Recommended Motherboard Website
26  */
27
28 static char *processor_names[]={
29         /* 0x00 */ "AMD Engineering Sample",
30         /* 0x01-0x03 */ NULL, NULL, NULL,
31         /* 0x04 */ "AMD Athlon(tm) 64 Processor XX00+",
32         /* 0x05 */ "AMD Athlon(tm) 64 X2 Dual Core Processor XX00+",
33         /* 0x06-0x07 */ NULL, NULL,
34         /* 0x08 */ "Mobile AMD Athlon(tm) 64 Processor XX00+",
35         /* 0x09 */ "Mobile AMD Athlon(tm) 64 Processor XX00+",
36         /* 0x0A */ "AMD Turion(tm) 64 Mobile Technology ML-XX",
37         /* 0x0B */ "AMD Turion(tm) 64 Mobile Technology MT-XX",
38         /* 0x0C */ "AMD Opteron(tm) Processor 1YY",
39         /* 0x0D */ "AMD Opteron(tm) Processor 1YY",
40         /* 0x0E */ "AMD Opteron(tm) Processor 1YY HE",
41         /* 0x0F */ "AMD Opteron(tm) Processor 1YY EE",
42         /* 0x10 */ "AMD Opteron(tm) Processor 2YY",
43         /* 0x11 */ "AMD Opteron(tm) Processor 2YY",
44         /* 0x12 */ "AMD Opteron(tm) Processor 2YY HE",
45         /* 0x13 */ "AMD Opteron(tm) Processor 2YY EE",
46         /* 0x14 */ "AMD Opteron(tm) Processor 8YY",
47         /* 0x15 */ "AMD Opteron(tm) Processor 8YY",
48         /* 0x16 */ "AMD Opteron(tm) Processor 8YY HE",
49         /* 0x17 */ "AMD Opteron(tm) Processor 8YY EE",
50         /* 0x18 */ "AMD Athlon(tm) 64 Processor VV00+",
51         /* 0x19-0x1C */ NULL, NULL, NULL, NULL,
52         /* 0x1D */ "Mobile AMD Athlon(tm) XP-M Processor XX00+",
53         /* 0x1E */ "Mobile AMD Athlon(tm) XP-M Processor XX00+",
54         /* 0x1F */ NULL,
55         /* 0x20 */ "AMD Athlon(tm) XP Processor XX00+",
56         /* 0x21 */ "Mobile AMD Sempron(tm) Processor TT00+",
57         /* 0x22 */ "AMD Sempron(tm) Processor TT00+",
58         /* 0x23 */ "Mobile AMD Sempron(tm) Processor TT00+",
59         /* 0x24 */ "AMD Athlon(tm) 64 FX-ZZ Processor",
60         /* 0x25 */ NULL,
61         /* 0x26 */ "AMD Sempron(tm) Processor TT00+",
62         /* 0x27-0x28 */ NULL, NULL, 
63         /* 0x29 */ "Dual Core AMD Opteron(tm) Processor 1RR SE",
64         /* 0x2A */ "Dual Core AMD Opteron(tm) Processor 2RR SE",
65         /* 0x2B */ "Dual Core AMD Opteron(tm) Processor 8RR SE",
66         /* 0x2C */ "Dual Core AMD Opteron(tm) Processor 1RR",
67         /* 0x2D */ "Dual Core AMD Opteron(tm) Processor 1RR",
68         /* 0x2E */ "Dual Core AMD Opteron(tm) Processor 1RR HE",
69         /* 0x2F */ "Dual Core AMD Opteron(tm) Processor 1RR EE",
70         /* 0x30 */ "Dual Core AMD Opteron(tm) Processor 2RR",
71         /* 0x31 */ "Dual Core AMD Opteron(tm) Processor 2RR",
72         /* 0x32 */ "Dual Core AMD Opteron(tm) Processor 2RR HE",
73         /* 0x33 */ "Dual Core AMD Opteron(tm) Processor 2RR EE",
74         /* 0x34 */ "Dual Core AMD Opteron(tm) Processor 8RR",
75         /* 0x35 */ "Dual Core AMD Opteron(tm) Processor 8RR",
76         /* 0x36 */ "Dual Core AMD Opteron(tm) Processor 8RR HE",
77         /* 0x37 */ "Dual Core AMD Opteron(tm) Processor 8RR EE",
78         /* 0x38 */ "Dual Core AMD Opteron(tm) Processor 1RR",
79         /* 0x39 */ "Dual Core AMD Opteron(tm) Processor 2RR",
80         /* 0x3A */ "Dual Core AMD Opteron(tm) Processor 8RR"
81 #define MAX_CPU_NUMBER 0x3A
82 };
83
84 /* wrmsr_amd() is from yhlu's changes to model_fxx_init.c */
85
86 static inline void wrmsr_amd(unsigned index, msr_t msr)
87 {
88         __asm__ __volatile__ (
89                 "wrmsr"
90                 : /* No outputs */
91                 : "c" (index), "a" (msr.lo), "d" (msr.hi), "D" (0x9c5a203a)
92                 );
93 }
94
95 static inline unsigned int cpuid_ebx(unsigned int op)
96 {
97         unsigned int eax, ebx;
98
99         __asm__("cpuid"
100                 : "=a" (eax), "=b" (ebx)
101                 : "0" (op)
102                 : "ecx", "edx" );
103         return ebx;
104 }
105
106 static inline void strcpy(char *dst, char *src) 
107 {
108         while (*src) *dst++ = *src++;
109 }
110
111
112 int init_processor_name(void)
113 {
114         u32 EightBitBrandId;
115         u32 BrandId;
116         u32 BrandTableIndex;
117         u32 NN;
118         u32 ModelNumber=0;
119         msr_t progmsr;
120         int i;
121
122         char *processor_name_string=NULL;
123         char program_string[48];
124         unsigned int *program_values = (unsigned int *)program_string;
125
126         /* Find out which CPU brand it is */
127         EightBitBrandId = cpuid_ebx(0x00000001) & 0xff;
128         BrandId = cpuid_ebx(0x80000001) & 0xffff;
129
130         if(!EightBitBrandId && !BrandId) {
131                 BrandTableIndex = 0;
132                 NN = 0xffffff;
133         } else if(!EightBitBrandId) {
134                 BrandTableIndex = (BrandId >> 6) & 0x3f; // BrandId[11:6]
135                 NN = BrandId & 0x3f; // // BrandId[6:0]
136         } else {
137                 BrandTableIndex = EightBitBrandId >> (5-2) & 0xfc; // { 0b, 8BitBrandId[7:5], 00b }
138                 NN = EightBitBrandId & 0x1f; // 8BitBrandId[4:0]
139         }
140
141         /* Look up the CPU brand in above table */
142         if (BrandTableIndex <= MAX_CPU_NUMBER)
143                 processor_name_string = processor_names[BrandTableIndex];
144
145         if (!processor_name_string)
146                 processor_name_string = "AMD Processor model unknown";
147
148         memset(program_string, 0, 48);
149         strcpy(program_string, processor_name_string);
150         
151         /* Now create a model number - See Table 4. Model Number Calculation
152          * in the Revision Guide. NOTE: #6, EE was changed to VV because 
153          * otherwise it clashes with the brand names.
154          */
155         
156         for (i=0; i<47; i++) { // 48 -1 
157                 if(program_string[i] == program_string[i+1]) {
158                         switch (program_string[i]) {
159                         case 'X': ModelNumber = 22+ NN; break;
160                         case 'Y': ModelNumber = 38 + (2*NN); break;
161                         case 'Z':
162                         case 'T': ModelNumber = 24 + NN; break;
163                         case 'R': ModelNumber = 45 + (5*NN); break;
164                         case 'V': ModelNumber =  9 + NN; break;
165                         }
166                         
167                         if(ModelNumber && ModelNumber < 100) {
168                                 // No idea what to do with RR=100. According
169                                 // to the revision guide this is possible.
170                                 // 
171                                 // --> "AMD Opteron(tm) Processor 8100"?
172                                 program_string[i]=(ModelNumber/10)+'0';
173                                 program_string[i+1]=(ModelNumber%10)+'0';
174                                 break;
175                         }
176                 }
177         }
178         
179         printk_debug("CPU model %s\n", program_string);
180
181         for (i=0; i<6; i++) {
182                 progmsr.lo = program_values[(2*i)+0];
183                 progmsr.hi = program_values[(2*i)+1];
184                 wrmsr_amd(0xc0010030+i, progmsr);
185         }
186
187         return 0;
188 }
189