Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / arch / i386 / lib / cpu.c
index 628bb79e91f7035e2d04bbb9eb7c214ba607412e..3732ae296e96d7f0573b572d497b0640d27c496c 100644 (file)
@@ -43,7 +43,7 @@ static int have_cpuid_p(void)
  * 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.
  */
+
 /*
  * Perform the Cyrix 5/2 test. A Cyrix won't change
  * the flags, while other 486 chips will.
@@ -68,11 +68,11 @@ static inline int test_cyrix_52div(void)
  *     Detect a NexGen CPU running without BIOS hypercode new enough
  *     to have CPUID. (Thanks to Herbert Oppmann)
  */
+
 static int deep_magic_nexgen_probe(void)
 {
        int ret;
-       
+
        __asm__ __volatile__ (
                "       movw    $0x5555, %%ax\n"
                "       xorw    %%dx,%%dx\n"
@@ -81,7 +81,7 @@ static int deep_magic_nexgen_probe(void)
                "       movl    $0, %%eax\n"
                "       jnz     1f\n"
                "       movl    $1, %%eax\n"
-               "1:\n" 
+               "1:\n"
                : "=a" (ret) : : "cx", "dx" );
        return  ret;
 }
@@ -95,7 +95,7 @@ static struct {
 } x86_vendors[] = {
        { X86_VENDOR_INTEL,     "GenuineIntel", },
        { X86_VENDOR_CYRIX,     "CyrixInstead", },
-       { X86_VENDOR_AMD,       "AuthenticAMD", },       
+       { X86_VENDOR_AMD,       "AuthenticAMD", },
        { X86_VENDOR_UMC,       "UMC UMC UMC ", },
        { X86_VENDOR_NEXGEN,    "NexGenDriven", },
        { X86_VENDOR_CENTAUR,   "CentaurHauls", },
@@ -123,8 +123,8 @@ static const char *cpu_vendor_name(int vendor)
 {
        const char *name;
        name = "<invalid cpu vendor>";
-       if ((vendor < (sizeof(x86_vendor_name)/sizeof(x86_vendor_name[0]))) &&
-               (x86_vendor_name[vendor] != 0)) 
+       if ((vendor < (ARRAY_SIZE(x86_vendor_name))) &&
+               (x86_vendor_name[vendor] != 0))
        {
                name = x86_vendor_name[vendor];
        }
@@ -134,11 +134,9 @@ static const char *cpu_vendor_name(int vendor)
 static void identify_cpu(struct device *cpu)
 {
        char vendor_name[16];
-       int  cpuid_level;
        int i;
 
        vendor_name[0] = '\0'; /* Unset */
-       cpuid_level    = -1;   /* Maximum supported CPUID level, -1=no CPUID */
 
        /* Find the id and vendor_name */
        if (!have_cpuid_p()) {
@@ -158,6 +156,7 @@ static void identify_cpu(struct device *cpu)
                }
        }
        if (have_cpuid_p()) {
+               int  cpuid_level;
                struct cpuid_result result;
                result = cpuid(0x00000000);
                cpuid_level    = result.eax;
@@ -174,7 +173,7 @@ static void identify_cpu(struct device *cpu)
                vendor_name[10] = (result.ecx >> 16) & 0xff;
                vendor_name[11] = (result.ecx >> 24) & 0xff;
                vendor_name[12] = '\0';
-               
+
                /* Intel-defined flags: level 0x00000001 */
                if (cpuid_level >= 0x00000001) {
                        cpu->device = cpuid_eax(0x00000001);
@@ -185,7 +184,7 @@ static void identify_cpu(struct device *cpu)
                }
        }
        cpu->vendor = X86_VENDOR_UNKNOWN;
-       for(i = 0; i < sizeof(x86_vendors)/sizeof(x86_vendors[0]); i++) {
+       for(i = 0; i < ARRAY_SIZE(x86_vendors); i++) {
                if (memcmp(vendor_name, x86_vendors[i].name, 12) == 0) {
                        cpu->vendor = x86_vendors[i].vendor;
                        break;
@@ -201,13 +200,12 @@ static void set_cpu_ops(struct device *cpu)
                struct cpu_device_id *id;
                for(id = driver->id_table; id->vendor != X86_VENDOR_INVALID; id++) {
                        if ((cpu->vendor == id->vendor) &&
-                               (cpu->device == id->device)) 
+                               (cpu->device == id->device))
                        {
                                goto found;
                        }
                }
        }
-       die("Unknown cpu");
        return;
  found:
        cpu->ops = driver->ops;
@@ -222,41 +220,49 @@ void cpu_initialize(void)
         */
        struct device *cpu;
        struct cpu_info *info;
+       struct cpuinfo_x86 c;
+
        info = cpu_info();
 
-       printk_notice("Initializing CPU #%d\n", info->index);
+       printk(BIOS_INFO, "Initializing CPU #%ld\n", info->index);
 
        cpu = info->cpu;
        if (!cpu) {
                die("CPU: missing cpu device structure");
        }
 
-       // Check that we haven't been passed bad information as the result of a race 
-       // (i.e. BSP timed out while waiting for us to load secondary_stack)
-
-       if (cpu->path.u.apic.apic_id != lapicid()) {
-               printk_err("CPU #%d Initialization FAILED: APIC ID mismatch (%u != %u)\n",
-                                  info->index, cpu->path.u.apic.apic_id, lapicid());
-               // return without setting initialized flag
-       } else {
-               /* Find what type of cpu we are dealing with */
-               identify_cpu(cpu);
-               printk_debug("CPU: vendor %s device %x\n",
-                       cpu_vendor_name(cpu->vendor), cpu->device);
-                       
-               /* Lookup the cpu's operations */
+       /* Find what type of cpu we are dealing with */
+       identify_cpu(cpu);
+       printk(BIOS_DEBUG, "CPU: vendor %s device %x\n",
+               cpu_vendor_name(cpu->vendor), cpu->device);
+
+       get_fms(&c, cpu->device);
+
+       printk(BIOS_DEBUG, "CPU: family %02x, model %02x, stepping %02x\n",
+               c.x86, c.x86_model, c.x86_mask);
+
+       /* Lookup the cpu's operations */
+       set_cpu_ops(cpu);
+
+       if(!cpu->ops) {
+               /* mask out the stepping and try again */
+               cpu->device -= c.x86_mask;
                set_cpu_ops(cpu);
+               cpu->device += c.x86_mask;
+               if(!cpu->ops) die("Unknown cpu");
+               printk(BIOS_DEBUG, "Using generic cpu ops (good)\n");
+       }
 
-               /* Initialize the cpu */
-               if (cpu->ops && cpu->ops->init) {
-                       cpu->enabled = 1;
-                       cpu->initialized = 1;
-                       cpu->ops->init(cpu);
-               }
 
-               printk_info("CPU #%d Initialized\n", info->index);
+       /* Initialize the cpu */
+       if (cpu->ops && cpu->ops->init) {
+               cpu->enabled = 1;
+               cpu->initialized = 1;
+               cpu->ops->init(cpu);
        }
 
+       printk(BIOS_INFO, "CPU #%ld initialized\n", info->index);
+
        return;
 }