2 * This file is part of the coreinfo project.
4 * It is derived from the x86info project, which is GPLv2-licensed.
6 * Copyright (C) 2001-2007 Dave Jones <davej@codemonkey.org.uk>
7 * Copyright (C) 2008 Advanced Micro Devices, Inc.
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.
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.
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
25 #ifdef CONFIG_MODULE_CPUINFO
26 #include <arch/rdtsc.h>
28 #define VENDOR_INTEL 0x756e6547
29 #define VENDOR_AMD 0x68747541
30 #define VENDOR_CYRIX 0x69727943
31 #define VENDOR_IDT 0x746e6543
32 #define VENDOR_GEODE 0x646f6547
33 #define VENDOR_RISE 0x52697365
34 #define VENDOR_RISE2 0x65736952
35 #define VENDOR_SIS 0x20536953
37 /* CPUID 0x00000001 EDX flags */
38 static const char *generic_cap_flags
[] = {
39 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
40 "cx8", "apic", NULL
, "sep", "mtrr", "pge", "mca", "cmov",
41 "pat", "pse36", "psn", "clflsh", NULL
, "ds", "acpi", "mmx",
42 "fxsr", "sse", "sse2", "ss", "ht", "tm", NULL
, "pbe"
45 /* CPUID 0x00000001 ECX flags */
46 static const char *intel_cap_generic_ecx_flags
[] = {
47 "sse3", NULL
, NULL
, "monitor", "ds-cpl", "vmx", NULL
, "est",
48 "tm2", "ssse3", "cntx-id", NULL
, NULL
, "cx16", "xTPR", NULL
,
49 NULL
, NULL
, "dca", NULL
, NULL
, NULL
, NULL
, NULL
,
50 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
53 /* CPUID 0x80000001 EDX flags */
54 static const char *intel_cap_extended_edx_flags
[] = {
55 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
56 NULL
, NULL
, NULL
, "SYSCALL", NULL
, NULL
, NULL
, NULL
,
57 NULL
, NULL
, NULL
, NULL
, "xd", NULL
, NULL
, NULL
,
58 NULL
, NULL
, NULL
, NULL
, NULL
, "em64t", NULL
, NULL
,
61 /* CPUID 0x80000001 ECX flags */
62 static const char *intel_cap_extended_ecx_flags
[] = {
63 "lahf_lm", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
64 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
65 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
66 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
69 static const char *amd_cap_generic_ecx_flags
[] = {
70 "sse3", NULL
, NULL
, "mwait", NULL
, NULL
, NULL
, NULL
,
71 NULL
, NULL
, NULL
, NULL
, NULL
, "cmpxchg16b", NULL
, NULL
,
72 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "popcnt",
73 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
76 static const char *amd_cap_extended_edx_flags
[] = {
77 "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
78 "cx8", "apic", NULL
, "sep", "mtrr", "pge", "mca", "cmov",
79 "pat", "pse36", NULL
, "mp", "nx", NULL
, "mmxext", "mmx",
80 "fxsr", "ffxsr", "page1gb", "rdtscp",
81 NULL
, "lm", "3dnowext", "3dnow"
82 }; /* "mp" defined for CPUs prior to AMD family 0xf */
84 static const char *amd_cap_extended_ecx_flags
[] = {
85 "lahf/sahf", "CmpLegacy", "svm", "ExtApicSpace",
86 "LockMovCr0", "abm", "sse4a", "misalignsse",
87 "3dnowPref", "osvw", "ibs", NULL
, "skinit", "wdt", NULL
, NULL
,
88 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
89 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
92 static unsigned long vendor
;
93 static unsigned int cpu_khz
;
95 static void decode_flags(WINDOW
*win
, unsigned long reg
, const char **flags
,
103 for (i
= 0; i
< 32; i
++) {
104 if (flags
[i
] == NULL
)
108 wprintw(win
, "%s ", flags
[i
]);
110 if (i
&& (i
% 16) == 0) {
119 static void get_features(WINDOW
*win
, int *row
)
121 unsigned long eax
, ebx
, ecx
, edx
;
124 wmove(win
, lrow
++, 1);
125 wprintw(win
, "Features: ");
127 docpuid(0x00000001, &eax
, &ebx
, &ecx
, &edx
);
128 decode_flags(win
, edx
, generic_cap_flags
, &lrow
);
134 wmove(win
, lrow
++, 1);
135 wprintw(win
, "AMD Extended Flags: ");
136 decode_flags(win
, ecx
, amd_cap_generic_ecx_flags
, &lrow
);
137 docpuid(0x80000001, &eax
, &ebx
, &ecx
, &edx
);
138 decode_flags(win
, edx
, amd_cap_extended_edx_flags
, &lrow
);
139 decode_flags(win
, ecx
, amd_cap_extended_ecx_flags
, &lrow
);
142 wmove(win
, lrow
++, 1);
143 wprintw(win
, "Intel Extended Flags: ");
144 decode_flags(win
, ecx
, intel_cap_generic_ecx_flags
, &lrow
);
145 docpuid(0x80000001, &eax
, &ebx
, &ecx
, &edx
);
146 decode_flags(win
, edx
, intel_cap_extended_edx_flags
, &lrow
);
147 decode_flags(win
, ecx
, intel_cap_extended_ecx_flags
, &lrow
);
154 static void do_name(WINDOW
*win
, int row
)
157 unsigned long eax
, ebx
, ecx
, edx
;
162 for (i
= 0x80000002; i
<= 0x80000004; i
++) {
163 docpuid(i
, &eax
, &ebx
, &ecx
, &edx
);
168 for (t
= 0; t
< 4; t
++)
169 *p
++ = eax
>> (8 * t
);
170 for (t
= 0; t
< 4; t
++)
171 *p
++ = ebx
>> (8 * t
);
172 for (t
= 0; t
< 4; t
++)
173 *p
++ = ecx
>> (8 * t
);
174 for (t
= 0; t
< 4; t
++)
175 *p
++ = edx
>> (8 * t
);
178 mvwprintw(win
, row
, 1, "Processor: %s", name
);
181 static int cpuinfo_module_redraw(WINDOW
*win
)
183 unsigned long eax
, ebx
, ecx
, edx
;
188 print_module_title(win
, "CPU Information");
190 docpuid(0, NULL
, &vendor
, NULL
, NULL
);
206 vstr
= "NatSemi Geode";
220 mvwprintw(win
, row
++, 1, "Vendor: %s", vstr
);
224 docpuid(0x00000001, &eax
, &ebx
, &ecx
, &edx
);
226 mvwprintw(win
, row
++, 1, "Family: %X", (eax
>> 8) & 0x0f);
227 mvwprintw(win
, row
++, 1, "Model: %X",
228 ((eax
>> 4) & 0xf) | ((eax
>> 16) & 0xf) << 4);
230 mvwprintw(win
, row
++, 1, "Stepping: %X", eax
& 0xf);
232 if (vendor
== VENDOR_AMD
) {
233 docpuid(0x80000001, &eax
, &ebx
, &ecx
, &edx
);
234 brand
= ((ebx
>> 9) & 0x1f);
236 mvwprintw(win
, row
++, 1, "Brand: %X", brand
);
240 mvwprintw(win
, row
++, 1, "CPU Speed: %d Mhz", cpu_khz
/ 1000);
242 mvwprintw(win
, row
++, 1, "CPU Speed: Error");
245 get_features(win
, &row
);
250 static unsigned int getticks(void)
252 unsigned long long start
, end
;
254 /* Read the number of ticks during the period. */
259 return (unsigned int)((end
- start
) / 100);
262 static int cpuinfo_module_init(void)
264 cpu_khz
= getticks();
268 struct coreinfo_module cpuinfo_module
= {
270 .init
= cpuinfo_module_init
,
271 .redraw
= cpuinfo_module_redraw
,
276 struct coreinfo_module cpuinfo_module
= {