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