2008-03-20 01:11:05 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreinfo project.
|
|
|
|
*
|
|
|
|
* It is derived from the x86info project, which is GPLv2-licensed.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001-2007 Dave Jones <davej@codemonkey.org.uk>
|
|
|
|
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "coreinfo.h"
|
|
|
|
#include <arch/rdtsc.h>
|
|
|
|
|
2008-03-31 22:30:18 +02:00
|
|
|
#ifdef CONFIG_MODULE_CPUINFO
|
|
|
|
|
2008-03-20 01:11:05 +01:00
|
|
|
#define VENDOR_INTEL 0x756e6547
|
|
|
|
#define VENDOR_AMD 0x68747541
|
|
|
|
#define VENDOR_CYRIX 0x69727943
|
|
|
|
#define VENDOR_IDT 0x746e6543
|
|
|
|
#define VENDOR_GEODE 0x646f6547
|
|
|
|
#define VENDOR_RISE 0x52697365
|
|
|
|
#define VENDOR_RISE2 0x65736952
|
|
|
|
#define VENDOR_SIS 0x20536953
|
|
|
|
|
|
|
|
/* CPUID 0x00000001 EDX flags */
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *generic_cap_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
|
|
|
|
"cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
|
|
|
|
"pat", "pse36", "psn", "clflsh", NULL, "ds", "acpi", "mmx",
|
|
|
|
"fxsr", "sse", "sse2", "ss", "ht", "tm", NULL, "pbe"
|
|
|
|
};
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
/* CPUID 0x00000001 ECX flags */
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *intel_cap_generic_ecx_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
"sse3", NULL, NULL, "monitor", "ds-cpl", "vmx", NULL, "est",
|
|
|
|
"tm2", "ssse3", "cntx-id", NULL, NULL, "cx16", "xTPR", NULL,
|
|
|
|
NULL, NULL, "dca", NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
|
|
|
};
|
2008-03-20 02:11:28 +01:00
|
|
|
|
2008-03-20 01:11:05 +01:00
|
|
|
/* CPUID 0x80000001 EDX flags */
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *intel_cap_extended_edx_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, "SYSCALL", NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, "xd", NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, "em64t", NULL, NULL,
|
|
|
|
};
|
2008-03-20 02:11:28 +01:00
|
|
|
|
2008-03-20 01:11:05 +01:00
|
|
|
/* CPUID 0x80000001 ECX flags */
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *intel_cap_extended_ecx_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
"lahf_lm", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
};
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *amd_cap_generic_ecx_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
"sse3", NULL, NULL, "mwait", NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, "cmpxchg16b", NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, "popcnt",
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *amd_cap_extended_edx_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
"fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
|
|
|
|
"cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
|
|
|
|
"pat", "pse36", NULL, "mp", "nx", NULL, "mmxext", "mmx",
|
|
|
|
"fxsr", "ffxsr", "page1gb", "rdtscp",
|
|
|
|
NULL, "lm", "3dnowext", "3dnow"
|
|
|
|
}; /* "mp" defined for CPUs prior to AMD family 0xf */
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static const char *amd_cap_extended_ecx_flags[] = {
|
2008-03-20 01:11:05 +01:00
|
|
|
"lahf/sahf", "CmpLegacy", "svm", "ExtApicSpace",
|
|
|
|
"LockMovCr0", "abm", "sse4a", "misalignsse",
|
|
|
|
"3dnowPref", "osvw", "ibs", NULL, "skinit", "wdt", NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned long vendor;
|
|
|
|
static unsigned int cpu_khz;
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static void decode_flags(WINDOW *win, unsigned long reg, const char **flags,
|
|
|
|
int *row)
|
2008-03-20 01:11:05 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int lrow = *row;
|
|
|
|
|
|
|
|
wmove(win, lrow, 2);
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
for (i = 0; i < 32; i++) {
|
2008-03-20 01:11:05 +01:00
|
|
|
if (flags[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
if (reg & (1 << i))
|
2008-03-20 01:11:05 +01:00
|
|
|
wprintw(win, "%s ", flags[i]);
|
|
|
|
|
|
|
|
if (i && (i % 16) == 0) {
|
|
|
|
lrow++;
|
|
|
|
wmove(win, lrow, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*row = lrow;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_features(WINDOW *win, int *row)
|
|
|
|
{
|
|
|
|
unsigned long eax, ebx, ecx, edx;
|
|
|
|
int lrow = *row;
|
|
|
|
|
|
|
|
wmove(win, lrow++, 1);
|
|
|
|
wprintw(win, "Features: ");
|
|
|
|
|
|
|
|
docpuid(0x00000001, &eax, &ebx, &ecx, &edx);
|
|
|
|
decode_flags(win, edx, generic_cap_flags, &lrow);
|
|
|
|
|
|
|
|
lrow++;
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
switch (vendor) {
|
2008-03-20 01:11:05 +01:00
|
|
|
case VENDOR_AMD:
|
|
|
|
wmove(win, lrow++, 1);
|
|
|
|
wprintw(win, "AMD Extended Flags: ");
|
|
|
|
decode_flags(win, ecx, amd_cap_generic_ecx_flags, &lrow);
|
|
|
|
docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
|
|
|
|
decode_flags(win, edx, amd_cap_extended_edx_flags, &lrow);
|
|
|
|
decode_flags(win, ecx, amd_cap_extended_ecx_flags, &lrow);
|
|
|
|
break;
|
|
|
|
case VENDOR_INTEL:
|
|
|
|
wmove(win, lrow++, 1);
|
|
|
|
wprintw(win, "Intel Extended Flags: ");
|
|
|
|
decode_flags(win, ecx, intel_cap_generic_ecx_flags, &lrow);
|
|
|
|
docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
|
|
|
|
decode_flags(win, edx, intel_cap_extended_edx_flags, &lrow);
|
|
|
|
decode_flags(win, ecx, intel_cap_extended_ecx_flags, &lrow);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*row = lrow;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_name(WINDOW *win, int row)
|
|
|
|
{
|
2008-03-20 21:05:22 +01:00
|
|
|
char name[49], *p;
|
2008-03-20 01:11:05 +01:00
|
|
|
unsigned long eax, ebx, ecx, edx;
|
|
|
|
int i, t;
|
|
|
|
|
|
|
|
p = name;
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
for (i = 0x80000002; i <= 0x80000004; i++) {
|
2008-03-20 01:11:05 +01:00
|
|
|
docpuid(i, &eax, &ebx, &ecx, &edx);
|
|
|
|
|
|
|
|
if (eax == 0)
|
|
|
|
break;
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
for (t = 0; t < 4; t++)
|
2008-03-20 01:11:05 +01:00
|
|
|
*p++ = eax >> (8 * t);
|
2008-03-20 02:11:28 +01:00
|
|
|
for (t = 0; t < 4; t++)
|
2008-03-20 01:11:05 +01:00
|
|
|
*p++ = ebx >> (8 * t);
|
2008-03-20 02:11:28 +01:00
|
|
|
for (t = 0; t < 4; t++)
|
2008-03-20 01:11:05 +01:00
|
|
|
*p++ = ecx >> (8 * t);
|
2008-03-20 02:11:28 +01:00
|
|
|
for (t = 0; t < 4; t++)
|
2008-03-20 01:11:05 +01:00
|
|
|
*p++ = edx >> (8 * t);
|
|
|
|
}
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
mvwprintw(win, row, 1, "Processor: %s", name);
|
2008-03-20 01:11:05 +01:00
|
|
|
}
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static int cpuinfo_module_redraw(WINDOW *win)
|
2008-03-20 01:11:05 +01:00
|
|
|
{
|
|
|
|
unsigned long eax, ebx, ecx, edx;
|
|
|
|
unsigned int brand;
|
2008-03-20 21:05:22 +01:00
|
|
|
char *vstr;
|
2008-03-20 01:11:05 +01:00
|
|
|
int row = 2;
|
|
|
|
|
|
|
|
print_module_title(win, "CPU Information");
|
|
|
|
|
|
|
|
docpuid(0, NULL, &vendor, NULL, NULL);
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
switch (vendor) {
|
|
|
|
case VENDOR_INTEL:
|
2008-03-20 01:11:05 +01:00
|
|
|
vstr = "Intel";
|
|
|
|
break;
|
|
|
|
case VENDOR_AMD:
|
|
|
|
vstr = "AMD";
|
|
|
|
break;
|
|
|
|
case VENDOR_CYRIX:
|
|
|
|
vstr = "Cyrix";
|
|
|
|
break;
|
|
|
|
case VENDOR_IDT:
|
|
|
|
vstr = "IDT";
|
|
|
|
break;
|
|
|
|
case VENDOR_GEODE:
|
|
|
|
vstr = "NatSemi Geode";
|
|
|
|
break;
|
|
|
|
case VENDOR_RISE:
|
|
|
|
case VENDOR_RISE2:
|
|
|
|
vstr = "RISE";
|
|
|
|
break;
|
|
|
|
case VENDOR_SIS:
|
|
|
|
vstr = "SiS";
|
2008-03-20 21:05:22 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
vstr = "Unknown";
|
|
|
|
break;
|
2008-03-20 01:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mvwprintw(win, row++, 1, "Vendor: %s", vstr);
|
|
|
|
|
|
|
|
do_name(win, row++);
|
|
|
|
|
|
|
|
docpuid(0x00000001, &eax, &ebx, &ecx, &edx);
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
mvwprintw(win, row++, 1, "Family: %X", (eax >> 8) & 0x0f);
|
2008-03-20 01:11:05 +01:00
|
|
|
mvwprintw(win, row++, 1, "Model: %X",
|
|
|
|
((eax >> 4) & 0xf) | ((eax >> 16) & 0xf) << 4);
|
|
|
|
|
|
|
|
mvwprintw(win, row++, 1, "Stepping: %X", eax & 0xf);
|
|
|
|
|
|
|
|
if (vendor == VENDOR_AMD) {
|
|
|
|
docpuid(0x80000001, &eax, &ebx, &ecx, &edx);
|
2008-03-20 02:11:28 +01:00
|
|
|
brand = ((ebx >> 9) & 0x1f);
|
2008-03-20 01:11:05 +01:00
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
mvwprintw(win, row++, 1, "Brand: %X", brand);
|
2008-03-20 01:11:05 +01:00
|
|
|
}
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
if (cpu_khz != 0)
|
|
|
|
mvwprintw(win, row++, 1, "CPU Speed: %d Mhz", cpu_khz / 1000);
|
|
|
|
else
|
2008-03-20 01:11:05 +01:00
|
|
|
mvwprintw(win, row++, 1, "CPU Speed: Error");
|
|
|
|
|
|
|
|
row++;
|
|
|
|
get_features(win, &row);
|
2008-03-20 21:05:22 +01:00
|
|
|
|
|
|
|
return 0;
|
2008-03-20 01:11:05 +01:00
|
|
|
}
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static unsigned int getticks(void)
|
2008-03-20 01:11:05 +01:00
|
|
|
{
|
|
|
|
unsigned long long start, end;
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
/* Read the number of ticks during the period. */
|
2008-03-20 01:11:05 +01:00
|
|
|
start = rdtsc();
|
|
|
|
mdelay(100);
|
|
|
|
end = rdtsc();
|
|
|
|
|
2008-03-20 02:11:28 +01:00
|
|
|
return (unsigned int)((end - start) / 100);
|
2008-03-20 01:11:05 +01:00
|
|
|
}
|
|
|
|
|
2008-03-23 16:34:04 +01:00
|
|
|
static int cpuinfo_module_init(void)
|
2008-03-20 01:11:05 +01:00
|
|
|
{
|
|
|
|
cpu_khz = getticks();
|
2008-03-20 21:05:22 +01:00
|
|
|
return 0;
|
2008-03-20 01:11:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct coreinfo_module cpuinfo_module = {
|
|
|
|
.name = "CPU Info",
|
|
|
|
.init = cpuinfo_module_init,
|
|
|
|
.redraw = cpuinfo_module_redraw,
|
|
|
|
};
|
2008-03-31 22:30:18 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
struct coreinfo_module cpuinfo_module = {
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|