2003-04-22 21:02:15 +02:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <cpu/cpu.h>
|
|
|
|
#include <arch/io.h>
|
|
|
|
#include <string.h>
|
2004-10-14 22:54:17 +02:00
|
|
|
#include <cpu/x86/mtrr.h>
|
|
|
|
#include <cpu/x86/msr.h>
|
|
|
|
#include <cpu/x86/lapic.h>
|
|
|
|
#include <arch/cpu.h>
|
|
|
|
#include <device/path.h>
|
|
|
|
#include <device/device.h>
|
|
|
|
#include <smp/spinlock.h>
|
|
|
|
|
|
|
|
/* Standard macro to see if a specific flag is changeable */
|
|
|
|
static inline int flag_is_changeable_p(uint32_t flag)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2004-10-14 22:54:17 +02:00
|
|
|
uint32_t f1, f2;
|
|
|
|
|
|
|
|
asm(
|
|
|
|
"pushfl\n\t"
|
|
|
|
"pushfl\n\t"
|
|
|
|
"popl %0\n\t"
|
|
|
|
"movl %0,%1\n\t"
|
|
|
|
"xorl %2,%0\n\t"
|
|
|
|
"pushl %0\n\t"
|
|
|
|
"popfl\n\t"
|
|
|
|
"pushfl\n\t"
|
|
|
|
"popl %0\n\t"
|
|
|
|
"popfl\n\t"
|
|
|
|
: "=&r" (f1), "=&r" (f2)
|
|
|
|
: "ir" (flag));
|
|
|
|
return ((f1^f2) & flag) != 0;
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/* Probe for the CPUID instruction */
|
2012-02-25 23:51:12 +01:00
|
|
|
int cpu_have_cpuid(void)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
2004-10-14 22:54:17 +02:00
|
|
|
return flag_is_changeable_p(X86_EFLAGS_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
|
|
|
|
* by the fact that they preserve the flags across the division of 5/2.
|
|
|
|
* PII and PPro exhibit this behavior too, but they have cpuid available.
|
|
|
|
*/
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/*
|
|
|
|
* Perform the Cyrix 5/2 test. A Cyrix won't change
|
|
|
|
* the flags, while other 486 chips will.
|
|
|
|
*/
|
|
|
|
static inline int test_cyrix_52div(void)
|
|
|
|
{
|
|
|
|
unsigned int test;
|
|
|
|
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"sahf\n\t" /* clear flags (%eax = 0x0005) */
|
|
|
|
"div %b2\n\t" /* divide 5 by 2 */
|
|
|
|
"lahf" /* store flags into %ah */
|
|
|
|
: "=a" (test)
|
|
|
|
: "0" (5), "q" (2)
|
|
|
|
: "cc");
|
|
|
|
|
|
|
|
/* AH is 0x02 on Cyrix after the divide.. */
|
|
|
|
return (unsigned char) (test >> 8) == 0x02;
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/*
|
|
|
|
* Detect a NexGen CPU running without BIOS hypercode new enough
|
|
|
|
* to have CPUID. (Thanks to Herbert Oppmann)
|
|
|
|
*/
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
static int deep_magic_nexgen_probe(void)
|
|
|
|
{
|
|
|
|
int ret;
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
" movw $0x5555, %%ax\n"
|
|
|
|
" xorw %%dx,%%dx\n"
|
|
|
|
" movw $2, %%cx\n"
|
|
|
|
" divw %%cx\n"
|
|
|
|
" movl $0, %%eax\n"
|
|
|
|
" jnz 1f\n"
|
|
|
|
" movl $1, %%eax\n"
|
2010-04-27 08:56:47 +02:00
|
|
|
"1:\n"
|
2004-10-14 22:54:17 +02:00
|
|
|
: "=a" (ret) : : "cx", "dx" );
|
|
|
|
return ret;
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/* List of cpu vendor strings along with their normalized
|
|
|
|
* id values.
|
|
|
|
*/
|
|
|
|
static struct {
|
|
|
|
int vendor;
|
|
|
|
const char *name;
|
|
|
|
} x86_vendors[] = {
|
|
|
|
{ X86_VENDOR_INTEL, "GenuineIntel", },
|
|
|
|
{ X86_VENDOR_CYRIX, "CyrixInstead", },
|
2010-04-27 08:56:47 +02:00
|
|
|
{ X86_VENDOR_AMD, "AuthenticAMD", },
|
2004-10-14 22:54:17 +02:00
|
|
|
{ X86_VENDOR_UMC, "UMC UMC UMC ", },
|
|
|
|
{ X86_VENDOR_NEXGEN, "NexGenDriven", },
|
|
|
|
{ X86_VENDOR_CENTAUR, "CentaurHauls", },
|
|
|
|
{ X86_VENDOR_RISE, "RiseRiseRise", },
|
|
|
|
{ X86_VENDOR_TRANSMETA, "GenuineTMx86", },
|
|
|
|
{ X86_VENDOR_TRANSMETA, "TransmetaCPU", },
|
|
|
|
{ X86_VENDOR_NSC, "Geode by NSC", },
|
|
|
|
{ X86_VENDOR_SIS, "SiS SiS SiS ", },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *x86_vendor_name[] = {
|
|
|
|
[X86_VENDOR_INTEL] = "Intel",
|
|
|
|
[X86_VENDOR_CYRIX] = "Cyrix",
|
|
|
|
[X86_VENDOR_AMD] = "AMD",
|
|
|
|
[X86_VENDOR_UMC] = "UMC",
|
|
|
|
[X86_VENDOR_NEXGEN] = "NexGen",
|
|
|
|
[X86_VENDOR_CENTAUR] = "Centaur",
|
|
|
|
[X86_VENDOR_RISE] = "Rise",
|
|
|
|
[X86_VENDOR_TRANSMETA] = "Transmeta",
|
|
|
|
[X86_VENDOR_NSC] = "NSC",
|
|
|
|
[X86_VENDOR_SIS] = "SiS",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *cpu_vendor_name(int vendor)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
name = "<invalid cpu vendor>";
|
2008-10-01 14:52:52 +02:00
|
|
|
if ((vendor < (ARRAY_SIZE(x86_vendor_name))) &&
|
2010-04-27 08:56:47 +02:00
|
|
|
(x86_vendor_name[vendor] != 0))
|
2004-10-14 22:54:17 +02:00
|
|
|
{
|
|
|
|
name = x86_vendor_name[vendor];
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2012-01-10 12:01:43 +01:00
|
|
|
static int cpu_cpuid_extended_level(void)
|
|
|
|
{
|
|
|
|
return cpuid_eax(0x80000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CPUID_FEATURE_PAE (1 << 6)
|
|
|
|
#define CPUID_FEATURE_PSE36 (1 << 17)
|
|
|
|
|
|
|
|
int cpu_phys_address_size(void)
|
|
|
|
{
|
2012-02-25 23:51:12 +01:00
|
|
|
if (!(cpu_have_cpuid()))
|
2012-01-10 12:01:43 +01:00
|
|
|
return 32;
|
|
|
|
|
2012-01-31 22:10:28 +01:00
|
|
|
if (cpu_cpuid_extended_level() >= 0x80000008)
|
2012-01-10 12:01:43 +01:00
|
|
|
return cpuid_eax(0x80000008) & 0xff;
|
|
|
|
|
2012-02-29 20:17:18 +01:00
|
|
|
if (cpuid_edx(1) & (CPUID_FEATURE_PAE | CPUID_FEATURE_PSE36))
|
2012-01-10 12:01:43 +01:00
|
|
|
return 36;
|
|
|
|
return 32;
|
|
|
|
}
|
2004-10-14 22:54:17 +02:00
|
|
|
static void identify_cpu(struct device *cpu)
|
|
|
|
{
|
|
|
|
char vendor_name[16];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
vendor_name[0] = '\0'; /* Unset */
|
|
|
|
|
|
|
|
/* Find the id and vendor_name */
|
2012-02-25 23:51:12 +01:00
|
|
|
if (!cpu_have_cpuid()) {
|
2004-10-14 22:54:17 +02:00
|
|
|
/* Its a 486 if we can modify the AC flag */
|
|
|
|
if (flag_is_changeable_p(X86_EFLAGS_AC)) {
|
|
|
|
cpu->device = 0x00000400; /* 486 */
|
|
|
|
} else {
|
|
|
|
cpu->device = 0x00000300; /* 386 */
|
|
|
|
}
|
|
|
|
if ((cpu->device == 0x00000400) && test_cyrix_52div()) {
|
|
|
|
memcpy(vendor_name, "CyrixInstead", 13);
|
|
|
|
/* If we ever care we can enable cpuid here */
|
|
|
|
}
|
|
|
|
/* Detect NexGen with old hypercode */
|
|
|
|
else if (deep_magic_nexgen_probe()) {
|
|
|
|
memcpy(vendor_name, "NexGenDriven", 13);
|
|
|
|
}
|
|
|
|
}
|
2012-02-25 23:51:12 +01:00
|
|
|
if (cpu_have_cpuid()) {
|
2009-05-26 14:33:06 +02:00
|
|
|
int cpuid_level;
|
2004-10-14 22:54:17 +02:00
|
|
|
struct cpuid_result result;
|
|
|
|
result = cpuid(0x00000000);
|
|
|
|
cpuid_level = result.eax;
|
|
|
|
vendor_name[ 0] = (result.ebx >> 0) & 0xff;
|
|
|
|
vendor_name[ 1] = (result.ebx >> 8) & 0xff;
|
|
|
|
vendor_name[ 2] = (result.ebx >> 16) & 0xff;
|
|
|
|
vendor_name[ 3] = (result.ebx >> 24) & 0xff;
|
|
|
|
vendor_name[ 4] = (result.edx >> 0) & 0xff;
|
|
|
|
vendor_name[ 5] = (result.edx >> 8) & 0xff;
|
|
|
|
vendor_name[ 6] = (result.edx >> 16) & 0xff;
|
|
|
|
vendor_name[ 7] = (result.edx >> 24) & 0xff;
|
|
|
|
vendor_name[ 8] = (result.ecx >> 0) & 0xff;
|
|
|
|
vendor_name[ 9] = (result.ecx >> 8) & 0xff;
|
|
|
|
vendor_name[10] = (result.ecx >> 16) & 0xff;
|
|
|
|
vendor_name[11] = (result.ecx >> 24) & 0xff;
|
|
|
|
vendor_name[12] = '\0';
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2004-10-14 22:54:17 +02:00
|
|
|
/* Intel-defined flags: level 0x00000001 */
|
|
|
|
if (cpuid_level >= 0x00000001) {
|
|
|
|
cpu->device = cpuid_eax(0x00000001);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Have CPUID level 0 only unheard of */
|
|
|
|
cpu->device = 0x00000400;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cpu->vendor = X86_VENDOR_UNKNOWN;
|
2008-10-01 14:52:52 +02:00
|
|
|
for(i = 0; i < ARRAY_SIZE(x86_vendors); i++) {
|
2004-10-14 22:54:17 +02:00
|
|
|
if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) {
|
|
|
|
cpu->vendor = x86_vendors[i].vendor;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-04-22 21:02:15 +02:00
|
|
|
|
2012-04-04 01:07:56 +02:00
|
|
|
struct cpu_driver *find_cpu_driver(struct device *cpu)
|
2004-10-14 22:54:17 +02:00
|
|
|
{
|
|
|
|
struct cpu_driver *driver;
|
|
|
|
for (driver = cpu_drivers; driver < ecpu_drivers; driver++) {
|
|
|
|
struct cpu_device_id *id;
|
2012-04-04 01:07:56 +02:00
|
|
|
for (id = driver->id_table;
|
|
|
|
id->vendor != X86_VENDOR_INVALID; id++) {
|
2004-10-14 22:54:17 +02:00
|
|
|
if ((cpu->vendor == id->vendor) &&
|
2010-04-27 08:56:47 +02:00
|
|
|
(cpu->device == id->device))
|
2004-10-14 22:54:17 +02:00
|
|
|
{
|
2012-04-04 01:07:56 +02:00
|
|
|
return driver;
|
2004-10-14 22:54:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-04 01:07:56 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_cpu_ops(struct device *cpu)
|
|
|
|
{
|
|
|
|
struct cpu_driver *driver = find_cpu_driver(cpu);
|
|
|
|
cpu->ops = driver ? driver->ops : NULL;
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|
2012-06-05 23:41:27 +02:00
|
|
|
void cpu_initialize(unsigned int index)
|
2003-04-22 21:02:15 +02:00
|
|
|
{
|
|
|
|
/* Because we busy wait at the printk spinlock.
|
|
|
|
* It is important to keep the number of printed messages
|
|
|
|
* from secondary cpus to a minimum, when debugging is
|
|
|
|
* disabled.
|
|
|
|
*/
|
2004-10-14 22:54:17 +02:00
|
|
|
struct device *cpu;
|
2012-07-29 19:18:03 +02:00
|
|
|
struct cpu_info *info;
|
2006-10-04 22:46:15 +02:00
|
|
|
struct cpuinfo_x86 c;
|
2012-06-17 10:32:55 +02:00
|
|
|
|
2012-07-29 19:18:03 +02:00
|
|
|
info = cpu_info();
|
2012-06-17 10:32:55 +02:00
|
|
|
|
2012-06-05 23:41:27 +02:00
|
|
|
printk(BIOS_INFO, "Initializing CPU #%d\n", index);
|
2012-07-10 09:19:40 +02:00
|
|
|
|
2012-07-29 19:18:03 +02:00
|
|
|
cpu = info->cpu;
|
|
|
|
if (!cpu) {
|
|
|
|
die("CPU: missing cpu device structure");
|
|
|
|
}
|
2004-10-14 22:54:17 +02:00
|
|
|
|
2007-04-06 21:57:42 +02:00
|
|
|
/* Find what type of cpu we are dealing with */
|
|
|
|
identify_cpu(cpu);
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "CPU: vendor %s device %x\n",
|
2007-04-06 21:57:42 +02:00
|
|
|
cpu_vendor_name(cpu->vendor), cpu->device);
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2007-04-06 21:57:42 +02:00
|
|
|
get_fms(&c, cpu->device);
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2010-04-25 22:42:02 +02:00
|
|
|
printk(BIOS_DEBUG, "CPU: family %02x, model %02x, stepping %02x\n",
|
|
|
|
c.x86, c.x86_model, c.x86_mask);
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2007-04-06 21:57:42 +02:00
|
|
|
/* Lookup the cpu's operations */
|
|
|
|
set_cpu_ops(cpu);
|
2006-10-04 22:46:15 +02:00
|
|
|
|
2010-04-27 08:56:47 +02:00
|
|
|
if(!cpu->ops) {
|
2007-04-06 21:57:42 +02:00
|
|
|
/* mask out the stepping and try again */
|
|
|
|
cpu->device -= c.x86_mask;
|
2005-09-14 15:53:45 +02:00
|
|
|
set_cpu_ops(cpu);
|
2007-04-06 21:57:42 +02:00
|
|
|
cpu->device += c.x86_mask;
|
|
|
|
if(!cpu->ops) die("Unknown cpu");
|
2010-03-22 12:42:32 +01:00
|
|
|
printk(BIOS_DEBUG, "Using generic cpu ops (good)\n");
|
2007-04-06 21:57:42 +02:00
|
|
|
}
|
2010-04-27 08:56:47 +02:00
|
|
|
|
2012-07-29 19:18:03 +02:00
|
|
|
|
2007-04-06 21:57:42 +02:00
|
|
|
/* Initialize the cpu */
|
|
|
|
if (cpu->ops && cpu->ops->init) {
|
|
|
|
cpu->enabled = 1;
|
|
|
|
cpu->initialized = 1;
|
|
|
|
cpu->ops->init(cpu);
|
|
|
|
}
|
2005-09-14 15:53:45 +02:00
|
|
|
|
2012-06-05 23:41:27 +02:00
|
|
|
printk(BIOS_INFO, "CPU #%d initialized\n", index);
|
2004-10-14 22:54:17 +02:00
|
|
|
|
|
|
|
return;
|
2003-04-22 21:02:15 +02:00
|
|
|
}
|
|
|
|
|