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