linux-old/arch/i386/kernel/setup.c
<<
>>
Prefs
   1/*
   2 *  linux/arch/i386/kernel/setup.c
   3 *
   4 *  Copyright (C) 1995  Linus Torvalds
   5 *
   6 *  Enhanced CPU type detection by Mike Jagdis, Patrick St. Jean
   7 *  and Martin Mares, November 1997.
   8 *
   9 *  Force Cyrix 6x86(MX) and M II processors to report MTRR capability
  10 *  and Cyrix "coma bug" recognition by
  11 *      Zoltán Böszörményi <zboszor@mail.externet.hu> February 1999.
  12 * 
  13 *  Force Centaur C6 processors to report MTRR capability.
  14 *      Bart Hartgers <bart@etpmod.phys.tue.nl>, May 1999.
  15 *
  16 *  Intel Mobile Pentium II detection fix. Sean Gilley, June 1999.
  17 *
  18 *  IDT Winchip tweaks, misc clean ups.
  19 *      Dave Jones <davej@suse.de>, August 1999
  20 *
  21 *  Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
  22 *
  23 *  Better detection of Centaur/IDT WinChip models.
  24 *      Bart Hartgers <bart@etpmod.phys.tue.nl>, August 1999.
  25 *
  26 *  Memory region support
  27 *      David Parsons <orc@pell.chi.il.us>, July-August 1999
  28 *
  29 *  Cleaned up cache-detection code
  30 *      Dave Jones <davej@suse.de>, October 1999
  31 *
  32 *      Added proper L2 cache detection for Coppermine
  33 *      Dragan Stancevic <visitor@valinux.com>, October 1999
  34 *
  35 *  Added the original array for capability flags but forgot to credit 
  36 *  myself :) (~1998) Fixed/cleaned up some cpu_model_info and other stuff
  37 *      Jauder Ho <jauderho@carumba.com>, January 2000
  38 *
  39 *  Detection for Celeron coppermine, identify_cpu() overhauled,
  40 *  and a few other clean ups.
  41 *  Dave Jones <davej@suse.de>, April 2000
  42 *
  43 *  Pentium III FXSR, SSE support
  44 *  General FPU state handling cleanups
  45 *      Gareth Hughes <gareth@valinux.com>, May 2000
  46 *
  47 *  Added proper Cascades CPU and L2 cache detection for Cascades
  48 *  and 8-way type cache happy bunch from Intel:^)
  49 *  Dragan Stancevic <visitor@valinux.com>, May 2000 
  50 *
  51 *  Forward port AMD Duron errata T13 from 2.2.17pre
  52 *  Dave Jones <davej@suse.de>, August 2000
  53 *
  54 *  Forward port lots of fixes/improvements from 2.2.18pre
  55 *  Cyrix III, Pentium IV support.
  56 *  Dave Jones <davej@suse.de>, October 2000
  57 *
  58 *  Massive cleanup of CPU detection and bug handling;
  59 *  Transmeta CPU detection,
  60 *  H. Peter Anvin <hpa@zytor.com>, November 2000
  61 *
  62 *  Added E820 sanitization routine (removes overlapping memory regions);
  63 *  Brian Moyle <bmoyle@mvista.com>, February 2001
  64 *
  65 *  VIA C3 Support.
  66 *  Dave Jones <davej@suse.de>, March 2001
  67 *
  68 *  AMD Athlon/Duron/Thunderbird bluesmoke support.
  69 *  Dave Jones <davej@suse.de>, April 2001.
  70 *
  71 *  CacheSize bug workaround updates for AMD, Intel & VIA Cyrix.
  72 *  Dave Jones <davej@suse.de>, September, October 2001.
  73 *
  74 *  Provisions for empty E820 memory regions (reported by certain BIOSes).
  75 *  Alex Achenbach <xela@slit.de>, December 2002.
  76 *
  77 */
  78
  79/*
  80 * This file handles the architecture-dependent parts of initialization
  81 */
  82
  83#include <linux/errno.h>
  84#include <linux/sched.h>
  85#include <linux/kernel.h>
  86#include <linux/mm.h>
  87#include <linux/stddef.h>
  88#include <linux/unistd.h>
  89#include <linux/ptrace.h>
  90#include <linux/slab.h>
  91#include <linux/user.h>
  92#include <linux/a.out.h>
  93#include <linux/tty.h>
  94#include <linux/ioport.h>
  95#include <linux/delay.h>
  96#include <linux/config.h>
  97#include <linux/init.h>
  98#include <linux/apm_bios.h>
  99#ifdef CONFIG_BLK_DEV_RAM
 100#include <linux/blk.h>
 101#endif
 102#include <linux/highmem.h>
 103#include <linux/bootmem.h>
 104#include <linux/pci.h>
 105#include <linux/pci_ids.h>
 106#include <linux/seq_file.h>
 107#include <asm/processor.h>
 108#include <linux/console.h>
 109#include <asm/mtrr.h>
 110#include <asm/uaccess.h>
 111#include <asm/system.h>
 112#include <asm/io.h>
 113#include <asm/smp.h>
 114#include <asm/cobalt.h>
 115#include <asm/msr.h>
 116#include <asm/desc.h>
 117#include <asm/e820.h>
 118#include <asm/dma.h>
 119#include <asm/mpspec.h>
 120#include <asm/mmu_context.h>
 121/*
 122 * Machine setup..
 123 */
 124
 125char ignore_irq13;              /* set if exception 16 works */
 126struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1, 1, 0, 0, -1 };
 127
 128unsigned long mmu_cr4_features;
 129
 130/*
 131 * Bus types ..
 132 */
 133#ifdef CONFIG_EISA
 134int EISA_bus;
 135#endif
 136int MCA_bus;
 137
 138/* for MCA, but anyone else can use it if they want */
 139unsigned int machine_id;
 140unsigned int machine_submodel_id;
 141unsigned int BIOS_revision;
 142unsigned int mca_pentium_flag;
 143
 144/* For PCI or other memory-mapped resources */
 145unsigned long pci_mem_start = 0x10000000;
 146
 147/* user-defined highmem size */
 148static unsigned int highmem_pages __initdata = -1;
 149
 150/*
 151 * Setup options
 152 */
 153struct drive_info_struct { char dummy[32]; } drive_info;
 154struct screen_info screen_info;
 155struct apm_info apm_info;
 156struct sys_desc_table_struct {
 157        unsigned short length;
 158        unsigned char table[0];
 159};
 160
 161struct e820map e820;
 162
 163unsigned char aux_device_present;
 164
 165extern void mcheck_init(struct cpuinfo_x86 *c);
 166extern void dmi_scan_machine(void);
 167extern int root_mountflags;
 168extern char _text, _etext, _edata, _end;
 169
 170static int have_cpuid_p(void) __init;
 171
 172static int disable_x86_serial_nr __initdata = 1;
 173static int disable_x86_ht __initdata = 0;
 174static u32 disabled_x86_caps[NCAPINTS] __initdata = { 0 };
 175extern int blk_nohighio;
 176
 177int enable_acpi_smp_table;
 178
 179/*
 180 * This is set up by the setup-routine at boot-time
 181 */
 182#define PARAM   ((unsigned char *)empty_zero_page)
 183#define SCREEN_INFO (*(struct screen_info *) (PARAM+0))
 184#define EXT_MEM_K (*(unsigned short *) (PARAM+2))
 185#define ALT_MEM_K (*(unsigned long *) (PARAM+0x1e0))
 186#define E820_MAP_NR (*(char*) (PARAM+E820NR))
 187#define E820_MAP    ((struct e820entry *) (PARAM+E820MAP))
 188#define APM_BIOS_INFO (*(struct apm_bios_info *) (PARAM+0x40))
 189#define DRIVE_INFO (*(struct drive_info_struct *) (PARAM+0x80))
 190#define SYS_DESC_TABLE (*(struct sys_desc_table_struct*)(PARAM+0xa0))
 191#define MOUNT_ROOT_RDONLY (*(unsigned short *) (PARAM+0x1F2))
 192#define RAMDISK_FLAGS (*(unsigned short *) (PARAM+0x1F8))
 193#define ORIG_ROOT_DEV (*(unsigned short *) (PARAM+0x1FC))
 194#define AUX_DEVICE_INFO (*(unsigned char *) (PARAM+0x1FF))
 195#define LOADER_TYPE (*(unsigned char *) (PARAM+0x210))
 196#define KERNEL_START (*(unsigned long *) (PARAM+0x214))
 197#define INITRD_START (*(unsigned long *) (PARAM+0x218))
 198#define INITRD_SIZE (*(unsigned long *) (PARAM+0x21c))
 199#define COMMAND_LINE ((char *) (PARAM+2048))
 200#define COMMAND_LINE_SIZE 256
 201
 202#define RAMDISK_IMAGE_START_MASK        0x07FF
 203#define RAMDISK_PROMPT_FLAG             0x8000
 204#define RAMDISK_LOAD_FLAG               0x4000  
 205
 206#ifdef  CONFIG_VISWS
 207char visws_board_type = -1;
 208char visws_board_rev = -1;
 209
 210#define PIIX_PM_START           0x0F80
 211
 212#define SIO_GPIO_START          0x0FC0
 213
 214#define SIO_PM_START            0x0FC8
 215
 216#define PMBASE                  PIIX_PM_START
 217#define GPIREG0                 (PMBASE+0x30)
 218#define GPIREG(x)               (GPIREG0+((x)/8))
 219#define PIIX_GPI_BD_ID1         18
 220#define PIIX_GPI_BD_REG         GPIREG(PIIX_GPI_BD_ID1)
 221
 222#define PIIX_GPI_BD_SHIFT       (PIIX_GPI_BD_ID1 % 8)
 223
 224#define SIO_INDEX       0x2e
 225#define SIO_DATA        0x2f
 226
 227#define SIO_DEV_SEL     0x7
 228#define SIO_DEV_ENB     0x30
 229#define SIO_DEV_MSB     0x60
 230#define SIO_DEV_LSB     0x61
 231
 232#define SIO_GP_DEV      0x7
 233
 234#define SIO_GP_BASE     SIO_GPIO_START
 235#define SIO_GP_MSB      (SIO_GP_BASE>>8)
 236#define SIO_GP_LSB      (SIO_GP_BASE&0xff)
 237
 238#define SIO_GP_DATA1    (SIO_GP_BASE+0)
 239
 240#define SIO_PM_DEV      0x8
 241
 242#define SIO_PM_BASE     SIO_PM_START
 243#define SIO_PM_MSB      (SIO_PM_BASE>>8)
 244#define SIO_PM_LSB      (SIO_PM_BASE&0xff)
 245#define SIO_PM_INDEX    (SIO_PM_BASE+0)
 246#define SIO_PM_DATA     (SIO_PM_BASE+1)
 247
 248#define SIO_PM_FER2     0x1
 249
 250#define SIO_PM_GP_EN    0x80
 251
 252static void __init visws_get_board_type_and_rev(void)
 253{
 254        int raw;
 255
 256        visws_board_type = (char)(inb_p(PIIX_GPI_BD_REG) & PIIX_GPI_BD_REG)
 257                                                         >> PIIX_GPI_BD_SHIFT;
 258/*
 259 * Get Board rev.
 260 * First, we have to initialize the 307 part to allow us access
 261 * to the GPIO registers.  Let's map them at 0x0fc0 which is right
 262 * after the PIIX4 PM section.
 263 */
 264        outb_p(SIO_DEV_SEL, SIO_INDEX);
 265        outb_p(SIO_GP_DEV, SIO_DATA);   /* Talk to GPIO regs. */
 266    
 267        outb_p(SIO_DEV_MSB, SIO_INDEX);
 268        outb_p(SIO_GP_MSB, SIO_DATA);   /* MSB of GPIO base address */
 269
 270        outb_p(SIO_DEV_LSB, SIO_INDEX);
 271        outb_p(SIO_GP_LSB, SIO_DATA);   /* LSB of GPIO base address */
 272
 273        outb_p(SIO_DEV_ENB, SIO_INDEX);
 274        outb_p(1, SIO_DATA);            /* Enable GPIO registers. */
 275    
 276/*
 277 * Now, we have to map the power management section to write
 278 * a bit which enables access to the GPIO registers.
 279 * What lunatic came up with this shit?
 280 */
 281        outb_p(SIO_DEV_SEL, SIO_INDEX);
 282        outb_p(SIO_PM_DEV, SIO_DATA);   /* Talk to GPIO regs. */
 283
 284        outb_p(SIO_DEV_MSB, SIO_INDEX);
 285        outb_p(SIO_PM_MSB, SIO_DATA);   /* MSB of PM base address */
 286    
 287        outb_p(SIO_DEV_LSB, SIO_INDEX);
 288        outb_p(SIO_PM_LSB, SIO_DATA);   /* LSB of PM base address */
 289
 290        outb_p(SIO_DEV_ENB, SIO_INDEX);
 291        outb_p(1, SIO_DATA);            /* Enable PM registers. */
 292    
 293/*
 294 * Now, write the PM register which enables the GPIO registers.
 295 */
 296        outb_p(SIO_PM_FER2, SIO_PM_INDEX);
 297        outb_p(SIO_PM_GP_EN, SIO_PM_DATA);
 298    
 299/*
 300 * Now, initialize the GPIO registers.
 301 * We want them all to be inputs which is the
 302 * power on default, so let's leave them alone.
 303 * So, let's just read the board rev!
 304 */
 305        raw = inb_p(SIO_GP_DATA1);
 306        raw &= 0x7f;    /* 7 bits of valid board revision ID. */
 307
 308        if (visws_board_type == VISWS_320) {
 309                if (raw < 0x6) {
 310                        visws_board_rev = 4;
 311                } else if (raw < 0xc) {
 312                        visws_board_rev = 5;
 313                } else {
 314                        visws_board_rev = 6;
 315        
 316                }
 317        } else if (visws_board_type == VISWS_540) {
 318                        visws_board_rev = 2;
 319                } else {
 320                        visws_board_rev = raw;
 321                }
 322
 323                printk(KERN_INFO "Silicon Graphics %s (rev %d)\n",
 324                        visws_board_type == VISWS_320 ? "320" :
 325                        (visws_board_type == VISWS_540 ? "540" :
 326                                        "unknown"),
 327                                        visws_board_rev);
 328        }
 329#endif
 330
 331
 332static char command_line[COMMAND_LINE_SIZE];
 333       char saved_command_line[COMMAND_LINE_SIZE];
 334
 335struct resource standard_io_resources[] = {
 336        { "dma1", 0x00, 0x1f, IORESOURCE_BUSY },
 337        { "pic1", 0x20, 0x3f, IORESOURCE_BUSY },
 338        { "timer", 0x40, 0x5f, IORESOURCE_BUSY },
 339        { "keyboard", 0x60, 0x6f, IORESOURCE_BUSY },
 340        { "dma page reg", 0x80, 0x8f, IORESOURCE_BUSY },
 341        { "pic2", 0xa0, 0xbf, IORESOURCE_BUSY },
 342        { "dma2", 0xc0, 0xdf, IORESOURCE_BUSY },
 343        { "fpu", 0xf0, 0xff, IORESOURCE_BUSY }
 344};
 345
 346#define STANDARD_IO_RESOURCES (sizeof(standard_io_resources)/sizeof(struct resource))
 347
 348static struct resource code_resource = { "Kernel code", 0x100000, 0 };
 349static struct resource data_resource = { "Kernel data", 0, 0 };
 350static struct resource vram_resource = { "Video RAM area", 0xa0000, 0xbffff, IORESOURCE_BUSY };
 351
 352/* System ROM resources */
 353#define MAXROMS 6
 354static struct resource rom_resources[MAXROMS] = {
 355        { "System ROM", 0xF0000, 0xFFFFF, IORESOURCE_BUSY },
 356        { "Video ROM", 0xc0000, 0xc7fff, IORESOURCE_BUSY }
 357};
 358
 359#define romsignature(x) (*(unsigned short *)(x) == 0xaa55)
 360
 361static void __init probe_roms(void)
 362{
 363        int roms = 1;
 364        unsigned long base;
 365        unsigned char *romstart;
 366
 367        request_resource(&iomem_resource, rom_resources+0);
 368
 369        /* Video ROM is standard at C000:0000 - C7FF:0000, check signature */
 370        for (base = 0xC0000; base < 0xE0000; base += 2048) {
 371                romstart = bus_to_virt(base);
 372                if (!romsignature(romstart))
 373                        continue;
 374                request_resource(&iomem_resource, rom_resources + roms);
 375                roms++;
 376                break;
 377        }
 378
 379        /* Extension roms at C800:0000 - DFFF:0000 */
 380        for (base = 0xC8000; base < 0xE0000; base += 2048) {
 381                unsigned long length;
 382
 383                romstart = bus_to_virt(base);
 384                if (!romsignature(romstart))
 385                        continue;
 386                length = romstart[2] * 512;
 387                if (length) {
 388                        unsigned int i;
 389                        unsigned char chksum;
 390
 391                        chksum = 0;
 392                        for (i = 0; i < length; i++)
 393                                chksum += romstart[i];
 394
 395                        /* Good checksum? */
 396                        if (!chksum) {
 397                                rom_resources[roms].start = base;
 398                                rom_resources[roms].end = base + length - 1;
 399                                rom_resources[roms].name = "Extension ROM";
 400                                rom_resources[roms].flags = IORESOURCE_BUSY;
 401
 402                                request_resource(&iomem_resource, rom_resources + roms);
 403                                roms++;
 404                                if (roms >= MAXROMS)
 405                                        return;
 406                        }
 407                }
 408        }
 409
 410        /* Final check for motherboard extension rom at E000:0000 */
 411        base = 0xE0000;
 412        romstart = bus_to_virt(base);
 413
 414        if (romsignature(romstart)) {
 415                rom_resources[roms].start = base;
 416                rom_resources[roms].end = base + 65535;
 417                rom_resources[roms].name = "Extension ROM";
 418                rom_resources[roms].flags = IORESOURCE_BUSY;
 419
 420                request_resource(&iomem_resource, rom_resources + roms);
 421        }
 422}
 423
 424static void __init limit_regions (unsigned long long size)
 425{
 426        unsigned long long current_addr = 0;
 427        int i;
 428
 429        for (i = 0; i < e820.nr_map; i++) {
 430                if (e820.map[i].type == E820_RAM) {
 431                        current_addr = e820.map[i].addr + e820.map[i].size;
 432                        if (current_addr >= size) {
 433                                e820.map[i].size -= current_addr-size;
 434                                e820.nr_map = i + 1;
 435                                return;
 436                        }
 437                }
 438        }
 439}
 440static void __init add_memory_region(unsigned long long start,
 441                                  unsigned long long size, int type)
 442{
 443        int x = e820.nr_map;
 444
 445        if (x == E820MAX) {
 446            printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
 447            return;
 448        }
 449
 450        e820.map[x].addr = start;
 451        e820.map[x].size = size;
 452        e820.map[x].type = type;
 453        e820.nr_map++;
 454} /* add_memory_region */
 455
 456#define E820_DEBUG      1
 457
 458static void __init print_memory_map(char *who)
 459{
 460        int i;
 461
 462        for (i = 0; i < e820.nr_map; i++) {
 463                printk(" %s: %016Lx - %016Lx ", who,
 464                        e820.map[i].addr,
 465                        e820.map[i].addr + e820.map[i].size);
 466                switch (e820.map[i].type) {
 467                case E820_RAM:  printk("(usable)\n");
 468                                break;
 469                case E820_RESERVED:
 470                                printk("(reserved)\n");
 471                                break;
 472                case E820_ACPI:
 473                                printk("(ACPI data)\n");
 474                                break;
 475                case E820_NVS:
 476                                printk("(ACPI NVS)\n");
 477                                break;
 478                default:        printk("type %lu\n", e820.map[i].type);
 479                                break;
 480                }
 481        }
 482}
 483
 484/*
 485 * Sanitize the BIOS e820 map.
 486 *
 487 * Some e820 responses include overlapping entries.  The following 
 488 * replaces the original e820 map with a new one, removing overlaps.
 489 *
 490 */
 491static int __init sanitize_e820_map(struct e820entry * biosmap, char * pnr_map)
 492{
 493        struct change_member {
 494                struct e820entry *pbios; /* pointer to original bios entry */
 495                unsigned long long addr; /* address for this change point */
 496        };
 497        struct change_member change_point_list[2*E820MAX];
 498        struct change_member *change_point[2*E820MAX];
 499        struct e820entry *overlap_list[E820MAX];
 500        struct e820entry new_bios[E820MAX];
 501        struct change_member *change_tmp;
 502        unsigned long current_type, last_type;
 503        unsigned long long last_addr;
 504        int chgidx, still_changing;
 505        int overlap_entries;
 506        int new_bios_entry;
 507        int old_nr, new_nr, chg_nr;
 508        int i;
 509
 510        /*
 511                Visually we're performing the following (1,2,3,4 = memory types)...
 512
 513                Sample memory map (w/overlaps):
 514                   ____22__________________
 515                   ______________________4_
 516                   ____1111________________
 517                   _44_____________________
 518                   11111111________________
 519                   ____________________33__
 520                   ___________44___________
 521                   __________33333_________
 522                   ______________22________
 523                   ___________________2222_
 524                   _________111111111______
 525                   _____________________11_
 526                   _________________4______
 527
 528                Sanitized equivalent (no overlap):
 529                   1_______________________
 530                   _44_____________________
 531                   ___1____________________
 532                   ____22__________________
 533                   ______11________________
 534                   _________1______________
 535                   __________3_____________
 536                   ___________44___________
 537                   _____________33_________
 538                   _______________2________
 539                   ________________1_______
 540                   _________________4______
 541                   ___________________2____
 542                   ____________________33__
 543                   ______________________4_
 544        */
 545
 546        /* if there's only one memory region, don't bother */
 547        if (*pnr_map < 2)
 548                return -1;
 549
 550        old_nr = *pnr_map;
 551
 552        /* bail out if we find any unreasonable addresses in bios map */
 553        for (i=0; i<old_nr; i++)
 554                if (biosmap[i].addr + biosmap[i].size < biosmap[i].addr)
 555                        return -1;
 556
 557        /* create pointers for initial change-point information (for sorting) */
 558        for (i=0; i < 2*old_nr; i++)
 559                change_point[i] = &change_point_list[i];
 560
 561        /* record all known change-points (starting and ending addresses),
 562           omitting those that are for empty memory regions */
 563        chgidx = 0;
 564        for (i=0; i < old_nr; i++)      {
 565                if (biosmap[i].size != 0) {
 566                        change_point[chgidx]->addr = biosmap[i].addr;
 567                        change_point[chgidx++]->pbios = &biosmap[i];
 568                        change_point[chgidx]->addr = biosmap[i].addr + biosmap[i].size;
 569                        change_point[chgidx++]->pbios = &biosmap[i];
 570                }
 571        }
 572        chg_nr = chgidx;        /* true number of change-points */
 573
 574        /* sort change-point list by memory addresses (low -> high) */
 575        still_changing = 1;
 576        while (still_changing)  {
 577                still_changing = 0;
 578                for (i=1; i < chg_nr; i++)  {
 579                        /* if <current_addr> > <last_addr>, swap */
 580                        /* or, if current=<start_addr> & last=<end_addr>, swap */
 581                        if ((change_point[i]->addr < change_point[i-1]->addr) ||
 582                                ((change_point[i]->addr == change_point[i-1]->addr) &&
 583                                 (change_point[i]->addr == change_point[i]->pbios->addr) &&
 584                                 (change_point[i-1]->addr != change_point[i-1]->pbios->addr))
 585                           )
 586                        {
 587                                change_tmp = change_point[i];
 588                                change_point[i] = change_point[i-1];
 589                                change_point[i-1] = change_tmp;
 590                                still_changing=1;
 591                        }
 592                }
 593        }
 594
 595        /* create a new bios memory map, removing overlaps */
 596        overlap_entries=0;       /* number of entries in the overlap table */
 597        new_bios_entry=0;        /* index for creating new bios map entries */
 598        last_type = 0;           /* start with undefined memory type */
 599        last_addr = 0;           /* start with 0 as last starting address */
 600        /* loop through change-points, determining affect on the new bios map */
 601        for (chgidx=0; chgidx < chg_nr; chgidx++)
 602        {
 603                /* keep track of all overlapping bios entries */
 604                if (change_point[chgidx]->addr == change_point[chgidx]->pbios->addr)
 605                {
 606                        /* add map entry to overlap list (> 1 entry implies an overlap) */
 607                        overlap_list[overlap_entries++]=change_point[chgidx]->pbios;
 608                }
 609                else
 610                {
 611                        /* remove entry from list (order independent, so swap with last) */
 612                        for (i=0; i<overlap_entries; i++)
 613                        {
 614                                if (overlap_list[i] == change_point[chgidx]->pbios)
 615                                        overlap_list[i] = overlap_list[overlap_entries-1];
 616                        }
 617                        overlap_entries--;
 618                }
 619                /* if there are overlapping entries, decide which "type" to use */
 620                /* (larger value takes precedence -- 1=usable, 2,3,4,4+=unusable) */
 621                current_type = 0;
 622                for (i=0; i<overlap_entries; i++)
 623                        if (overlap_list[i]->type > current_type)
 624                                current_type = overlap_list[i]->type;
 625                /* continue building up new bios map based on this information */
 626                if (current_type != last_type)  {
 627                        if (last_type != 0)      {
 628                                new_bios[new_bios_entry].size =
 629                                        change_point[chgidx]->addr - last_addr;
 630                                /* move forward only if the new size was non-zero */
 631                                if (new_bios[new_bios_entry].size != 0)
 632                                        if (++new_bios_entry >= E820MAX)
 633                                                break;  /* no more space left for new bios entries */
 634                        }
 635                        if (current_type != 0)  {
 636                                new_bios[new_bios_entry].addr = change_point[chgidx]->addr;
 637                                new_bios[new_bios_entry].type = current_type;
 638                                last_addr=change_point[chgidx]->addr;
 639                        }
 640                        last_type = current_type;
 641                }
 642        }
 643        new_nr = new_bios_entry;   /* retain count for new bios entries */
 644
 645        /* copy new bios mapping into original location */
 646        memcpy(biosmap, new_bios, new_nr*sizeof(struct e820entry));
 647        *pnr_map = new_nr;
 648
 649        return 0;
 650}
 651
 652/*
 653 * Copy the BIOS e820 map into a safe place.
 654 *
 655 * Sanity-check it while we're at it..
 656 *
 657 * If we're lucky and live on a modern system, the setup code
 658 * will have given us a memory map that we can use to properly
 659 * set up memory.  If we aren't, we'll fake a memory map.
 660 *
 661 * We check to see that the memory map contains at least 2 elements
 662 * before we'll use it, because the detection code in setup.S may
 663 * not be perfect and most every PC known to man has two memory
 664 * regions: one from 0 to 640k, and one from 1mb up.  (The IBM
 665 * thinkpad 560x, for example, does not cooperate with the memory
 666 * detection code.)
 667 */
 668static int __init copy_e820_map(struct e820entry * biosmap, int nr_map)
 669{
 670        /* Only one memory region (or negative)? Ignore it */
 671        if (nr_map < 2)
 672                return -1;
 673
 674        do {
 675                unsigned long long start = biosmap->addr;
 676                unsigned long long size = biosmap->size;
 677                unsigned long long end = start + size;
 678                unsigned long type = biosmap->type;
 679
 680                /* Overflow in 64 bits? Ignore the memory map. */
 681                if (start > end)
 682                        return -1;
 683
 684                /*
 685                 * Some BIOSes claim RAM in the 640k - 1M region.
 686                 * Not right. Fix it up.
 687                 */
 688                if (type == E820_RAM) {
 689                        if (start < 0x100000ULL && end > 0xA0000ULL) {
 690                                if (start < 0xA0000ULL)
 691                                        add_memory_region(start, 0xA0000ULL-start, type);
 692                                if (end <= 0x100000ULL)
 693                                        continue;
 694                                start = 0x100000ULL;
 695                                size = end - start;
 696                        }
 697                }
 698                add_memory_region(start, size, type);
 699        } while (biosmap++,--nr_map);
 700        return 0;
 701}
 702
 703/*
 704 * Do NOT EVER look at the BIOS memory size location.
 705 * It does not work on many machines.
 706 */
 707#define LOWMEMSIZE()    (0x9f000)
 708
 709static void __init setup_memory_region(void)
 710{
 711        char *who = "BIOS-e820";
 712
 713        /*
 714         * Try to copy the BIOS-supplied E820-map.
 715         *
 716         * Otherwise fake a memory map; one section from 0k->640k,
 717         * the next section from 1mb->appropriate_mem_k
 718         */
 719        sanitize_e820_map(E820_MAP, &E820_MAP_NR);
 720        if (copy_e820_map(E820_MAP, E820_MAP_NR) < 0) {
 721                unsigned long mem_size;
 722
 723                /* compare results from other methods and take the greater */
 724                if (ALT_MEM_K < EXT_MEM_K) {
 725                        mem_size = EXT_MEM_K;
 726                        who = "BIOS-88";
 727                } else {
 728                        mem_size = ALT_MEM_K;
 729                        who = "BIOS-e801";
 730                }
 731
 732                e820.nr_map = 0;
 733                add_memory_region(0, LOWMEMSIZE(), E820_RAM);
 734                add_memory_region(HIGH_MEMORY, mem_size << 10, E820_RAM);
 735        }
 736        printk(KERN_INFO "BIOS-provided physical RAM map:\n");
 737        print_memory_map(who);
 738} /* setup_memory_region */
 739
 740
 741static void __init parse_cmdline_early (char ** cmdline_p)
 742{
 743        char c = ' ', *to = command_line, *from = COMMAND_LINE;
 744        int len = 0;
 745        int userdef = 0;
 746
 747        /* Save unparsed command line copy for /proc/cmdline */
 748        memcpy(saved_command_line, COMMAND_LINE, COMMAND_LINE_SIZE);
 749        saved_command_line[COMMAND_LINE_SIZE-1] = '\0';
 750
 751        for (;;) {
 752                if (c != ' ')
 753                        goto nextchar;
 754                /*
 755                 * "mem=nopentium" disables the 4MB page tables.
 756                 * "mem=XXX[kKmM]" defines a memory region from HIGH_MEM
 757                 * to <mem>, overriding the bios size.
 758                 * "mem=XXX[KkmM]@XXX[KkmM]" defines a memory region from
 759                 * <start> to <start>+<mem>, overriding the bios size.
 760                 */
 761                if (!memcmp(from, "mem=", 4)) {
 762                        if (to != command_line)
 763                                to--;
 764                        if (!memcmp(from+4, "nopentium", 9)) {
 765                                from += 9+4;
 766                                clear_bit(X86_FEATURE_PSE, &boot_cpu_data.x86_capability);
 767                                set_bit(X86_FEATURE_PSE, &disabled_x86_caps);
 768                        } else if (!memcmp(from+4, "exactmap", 8)) {
 769                                from += 8+4;
 770                                e820.nr_map = 0;
 771                                userdef = 1;
 772                        } else {
 773                                /* If the user specifies memory size, we
 774                                 * limit the BIOS-provided memory map to
 775                                 * that size. exactmap can be used to specify
 776                                 * the exact map. mem=number can be used to
 777                                 * trim the existing memory map.
 778                                 */
 779                                unsigned long long start_at, mem_size;
 780 
 781                                mem_size = memparse(from+4, &from);
 782                                if (*from == '@') {
 783                                        start_at = memparse(from+1, &from);
 784                                        add_memory_region(start_at, mem_size, E820_RAM);
 785                                } else {
 786                                        limit_regions(mem_size);
 787                                        userdef=1;
 788                                }
 789                        }
 790                }
 791
 792                /* "noht" disables HyperThreading (2 logical cpus per Xeon) */
 793                else if (!memcmp(from, "noht", 4)) { 
 794                        disable_x86_ht = 1;
 795                        set_bit(X86_FEATURE_HT, disabled_x86_caps);
 796                }
 797
 798                /* "acpismp=force" forces parsing and use of the ACPI SMP table */
 799                else if (!memcmp(from, "acpismp=force", 13))
 800                        enable_acpi_smp_table = 1;
 801
 802                /*
 803                 * highmem=size forces highmem to be exactly 'size' bytes.
 804                 * This works even on boxes that have no highmem otherwise.
 805                 * This also works to reduce highmem size on bigger boxes.
 806                 */
 807                else if (!memcmp(from, "highmem=", 8))
 808                        highmem_pages = memparse(from+8, &from) >> PAGE_SHIFT;
 809nextchar:
 810                c = *(from++);
 811                if (!c)
 812                        break;
 813                if (COMMAND_LINE_SIZE <= ++len)
 814                        break;
 815                *(to++) = c;
 816        }
 817        *to = '\0';
 818        *cmdline_p = command_line;
 819        if (userdef) {
 820                printk(KERN_INFO "user-defined physical RAM map:\n");
 821                print_memory_map("user");
 822        }
 823}
 824
 825#define PFN_UP(x)       (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
 826#define PFN_DOWN(x)     ((x) >> PAGE_SHIFT)
 827#define PFN_PHYS(x)     ((x) << PAGE_SHIFT)
 828
 829/*
 830 * Reserved space for vmalloc and iomap - defined in asm/page.h
 831 */
 832#define MAXMEM_PFN      PFN_DOWN(MAXMEM)
 833#define MAX_NONPAE_PFN  (1 << 20)
 834
 835/*
 836 * Find the highest page frame number we have available
 837 */
 838static void __init find_max_pfn(void)
 839{
 840        int i;
 841
 842        max_pfn = 0;
 843        for (i = 0; i < e820.nr_map; i++) {
 844                unsigned long start, end;
 845                /* RAM? */
 846                if (e820.map[i].type != E820_RAM)
 847                        continue;
 848                start = PFN_UP(e820.map[i].addr);
 849                end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
 850                if (start >= end)
 851                        continue;
 852                if (end > max_pfn)
 853                        max_pfn = end;
 854        }
 855}
 856
 857/*
 858 * Determine low and high memory ranges:
 859 */
 860static unsigned long __init find_max_low_pfn(void)
 861{
 862        unsigned long max_low_pfn;
 863
 864        max_low_pfn = max_pfn;
 865        if (max_low_pfn > MAXMEM_PFN) {
 866                if (highmem_pages == -1)
 867                        highmem_pages = max_pfn - MAXMEM_PFN;
 868                if (highmem_pages + MAXMEM_PFN < max_pfn)
 869                        max_pfn = MAXMEM_PFN + highmem_pages;
 870                if (highmem_pages + MAXMEM_PFN > max_pfn) {
 871                        printk("only %luMB highmem pages available, ignoring highmem size of %uMB.\n", pages_to_mb(max_pfn - MAXMEM_PFN), pages_to_mb(highmem_pages));
 872                        highmem_pages = 0;
 873                }
 874                max_low_pfn = MAXMEM_PFN;
 875#ifndef CONFIG_HIGHMEM
 876                /* Maximum memory usable is what is directly addressable */
 877                printk(KERN_WARNING "Warning only %ldMB will be used.\n",
 878                                        MAXMEM>>20);
 879                if (max_pfn > MAX_NONPAE_PFN)
 880                        printk(KERN_WARNING "Use a PAE enabled kernel.\n");
 881                else
 882                        printk(KERN_WARNING "Use a HIGHMEM enabled kernel.\n");
 883#else /* !CONFIG_HIGHMEM */
 884#ifndef CONFIG_X86_PAE
 885                if (max_pfn > MAX_NONPAE_PFN) {
 886                        max_pfn = MAX_NONPAE_PFN;
 887                        printk(KERN_WARNING "Warning only 4GB will be used.\n");
 888                        printk(KERN_WARNING "Use a PAE enabled kernel.\n");
 889                }
 890#endif /* !CONFIG_X86_PAE */
 891#endif /* !CONFIG_HIGHMEM */
 892        } else {
 893                if (highmem_pages == -1)
 894                        highmem_pages = 0;
 895#if CONFIG_HIGHMEM
 896                if (highmem_pages >= max_pfn) {
 897                        printk(KERN_ERR "highmem size specified (%uMB) is bigger than pages available (%luMB)!.\n", pages_to_mb(highmem_pages), pages_to_mb(max_pfn));
 898                        highmem_pages = 0;
 899                }
 900                if (highmem_pages) {
 901                        if (max_low_pfn-highmem_pages < 64*1024*1024/PAGE_SIZE){
 902                                printk(KERN_ERR "highmem size %uMB results in smaller than 64MB lowmem, ignoring it.\n", pages_to_mb(highmem_pages));
 903                                highmem_pages = 0;
 904                        }
 905                        max_low_pfn -= highmem_pages;
 906                }
 907#else
 908                if (highmem_pages)
 909                        printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
 910#endif
 911        }
 912
 913        return max_low_pfn;
 914}
 915
 916/*
 917 * Register fully available low RAM pages with the bootmem allocator.
 918 */
 919static void __init register_bootmem_low_pages(unsigned long max_low_pfn)
 920{
 921        int i;
 922
 923        for (i = 0; i < e820.nr_map; i++) {
 924                unsigned long curr_pfn, last_pfn, size;
 925                /*
 926                 * Reserve usable low memory
 927                 */
 928                if (e820.map[i].type != E820_RAM)
 929                        continue;
 930                /*
 931                 * We are rounding up the start address of usable memory:
 932                 */
 933                curr_pfn = PFN_UP(e820.map[i].addr);
 934                if (curr_pfn >= max_low_pfn)
 935                        continue;
 936                /*
 937                 * ... and at the end of the usable range downwards:
 938                 */
 939                last_pfn = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
 940
 941                if (last_pfn > max_low_pfn)
 942                        last_pfn = max_low_pfn;
 943
 944                /*
 945                 * .. finally, did all the rounding and playing
 946                 * around just make the area go away?
 947                 */
 948                if (last_pfn <= curr_pfn)
 949                        continue;
 950
 951                size = last_pfn - curr_pfn;
 952                free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(size));
 953        }
 954}
 955
 956static unsigned long __init setup_memory(void)
 957{
 958        unsigned long bootmap_size, start_pfn, max_low_pfn;
 959
 960        /*
 961         * partially used pages are not usable - thus
 962         * we are rounding upwards:
 963         */
 964        start_pfn = PFN_UP(__pa(&_end));
 965
 966        find_max_pfn();
 967
 968        max_low_pfn = find_max_low_pfn();
 969
 970#ifdef CONFIG_HIGHMEM
 971        highstart_pfn = highend_pfn = max_pfn;
 972        if (max_pfn > max_low_pfn) {
 973                highstart_pfn = max_low_pfn;
 974        }
 975        printk(KERN_NOTICE "%ldMB HIGHMEM available.\n",
 976                pages_to_mb(highend_pfn - highstart_pfn));
 977#endif
 978        printk(KERN_NOTICE "%ldMB LOWMEM available.\n",
 979                        pages_to_mb(max_low_pfn));
 980        /*
 981         * Initialize the boot-time allocator (with low memory only):
 982         */
 983        bootmap_size = init_bootmem(start_pfn, max_low_pfn);
 984
 985        register_bootmem_low_pages(max_low_pfn);
 986
 987        /*
 988         * Reserve the bootmem bitmap itself as well. We do this in two
 989         * steps (first step was init_bootmem()) because this catches
 990         * the (very unlikely) case of us accidentally initializing the
 991         * bootmem allocator with an invalid RAM area.
 992         */
 993        reserve_bootmem(HIGH_MEMORY, (PFN_PHYS(start_pfn) +
 994                         bootmap_size + PAGE_SIZE-1) - (HIGH_MEMORY));
 995
 996        /*
 997         * reserve physical page 0 - it's a special BIOS page on many boxes,
 998         * enabling clean reboots, SMP operation, laptop functions.
 999         */
1000        reserve_bootmem(0, PAGE_SIZE);
1001
1002#ifdef CONFIG_SMP
1003        /*
1004         * But first pinch a few for the stack/trampoline stuff
1005         * FIXME: Don't need the extra page at 4K, but need to fix
1006         * trampoline before removing it. (see the GDT stuff)
1007         */
1008        reserve_bootmem(PAGE_SIZE, PAGE_SIZE);
1009#endif
1010
1011#ifdef CONFIG_X86_LOCAL_APIC
1012        /*
1013         * Find and reserve possible boot-time SMP configuration:
1014         */
1015        find_smp_config();
1016#endif
1017#ifdef CONFIG_BLK_DEV_INITRD
1018        if (LOADER_TYPE && INITRD_START) {
1019                if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
1020                        reserve_bootmem(INITRD_START, INITRD_SIZE);
1021                        initrd_start =
1022                                INITRD_START ? INITRD_START + PAGE_OFFSET : 0;
1023                        initrd_end = initrd_start+INITRD_SIZE;
1024                }
1025                else {
1026                        printk(KERN_ERR "initrd extends beyond end of memory "
1027                            "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
1028                            INITRD_START + INITRD_SIZE,
1029                            max_low_pfn << PAGE_SHIFT);
1030                        initrd_start = 0;
1031                }
1032        }
1033#endif
1034
1035        return max_low_pfn;
1036}
1037 
1038/*
1039 * Request address space for all standard RAM and ROM resources
1040 * and also for regions reported as reserved by the e820.
1041 */
1042static void __init register_memory(unsigned long max_low_pfn)
1043{
1044        unsigned long low_mem_size;
1045        int i;
1046
1047        probe_roms();
1048        for (i = 0; i < e820.nr_map; i++) {
1049                struct resource *res;
1050                if (e820.map[i].addr + e820.map[i].size > 0x100000000ULL)
1051                        continue;
1052                res = alloc_bootmem_low(sizeof(struct resource));
1053                switch (e820.map[i].type) {
1054                case E820_RAM:  res->name = "System RAM"; break;
1055                case E820_ACPI: res->name = "ACPI Tables"; break;
1056                case E820_NVS:  res->name = "ACPI Non-volatile Storage"; break;
1057                default:        res->name = "reserved";
1058                }
1059                res->start = e820.map[i].addr;
1060                res->end = res->start + e820.map[i].size - 1;
1061                res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
1062                request_resource(&iomem_resource, res);
1063                if (e820.map[i].type == E820_RAM) {
1064                        /*
1065                         *  We dont't know which RAM region contains kernel data,
1066                         *  so we try it repeatedly and let the resource manager
1067                         *  test it.
1068                         */
1069                        request_resource(res, &code_resource);
1070                        request_resource(res, &data_resource);
1071                }
1072        }
1073        request_resource(&iomem_resource, &vram_resource);
1074
1075        /* request I/O space for devices used on all i[345]86 PCs */
1076        for (i = 0; i < STANDARD_IO_RESOURCES; i++)
1077                request_resource(&ioport_resource, standard_io_resources+i);
1078
1079        /* Tell the PCI layer not to allocate too close to the RAM area.. */
1080        low_mem_size = ((max_low_pfn << PAGE_SHIFT) + 0xfffff) & ~0xfffff;
1081        if (low_mem_size > pci_mem_start)
1082                pci_mem_start = low_mem_size;
1083}
1084
1085void __init setup_arch(char **cmdline_p)
1086{
1087        unsigned long max_low_pfn;
1088
1089#ifdef CONFIG_VISWS
1090        visws_get_board_type_and_rev();
1091#endif
1092
1093#ifndef CONFIG_HIGHIO
1094        blk_nohighio = 1;
1095#endif
1096
1097        ROOT_DEV = to_kdev_t(ORIG_ROOT_DEV);
1098        drive_info = DRIVE_INFO;
1099        screen_info = SCREEN_INFO;
1100        apm_info.bios = APM_BIOS_INFO;
1101        if( SYS_DESC_TABLE.length != 0 ) {
1102                MCA_bus = SYS_DESC_TABLE.table[3] &0x2;
1103                machine_id = SYS_DESC_TABLE.table[0];
1104                machine_submodel_id = SYS_DESC_TABLE.table[1];
1105                BIOS_revision = SYS_DESC_TABLE.table[2];
1106        }
1107        aux_device_present = AUX_DEVICE_INFO;
1108
1109#ifdef CONFIG_BLK_DEV_RAM
1110        rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
1111        rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
1112        rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
1113#endif
1114        setup_memory_region();
1115
1116        if (!MOUNT_ROOT_RDONLY)
1117                root_mountflags &= ~MS_RDONLY;
1118        init_mm.start_code = (unsigned long) &_text;
1119        init_mm.end_code = (unsigned long) &_etext;
1120        init_mm.end_data = (unsigned long) &_edata;
1121        init_mm.brk = (unsigned long) &_end;
1122
1123        code_resource.start = virt_to_bus(&_text);
1124        code_resource.end = virt_to_bus(&_etext)-1;
1125        data_resource.start = virt_to_bus(&_etext);
1126        data_resource.end = virt_to_bus(&_edata)-1;
1127
1128        parse_cmdline_early(cmdline_p);
1129
1130        max_low_pfn = setup_memory();
1131
1132        /*
1133         * If enable_acpi_smp_table and HT feature present, acpitable.c
1134         * will find all logical cpus despite disable_x86_ht: so if both
1135         * "noht" and "acpismp=force" are specified, let "noht" override
1136         * "acpismp=force" cleanly.  Why retain "acpismp=force"? because
1137         * parsing ACPI SMP table might prove useful on some non-HT cpu.
1138         */
1139        if (disable_x86_ht) {
1140                clear_bit(X86_FEATURE_HT, &boot_cpu_data.x86_capability[0]);
1141                set_bit(X86_FEATURE_HT, disabled_x86_caps);
1142                enable_acpi_smp_table = 0;
1143        }
1144        if (test_bit(X86_FEATURE_HT, &boot_cpu_data.x86_capability[0]))
1145                enable_acpi_smp_table = 1;
1146        
1147
1148        /*
1149         * NOTE: before this point _nobody_ is allowed to allocate
1150         * any memory using the bootmem allocator.
1151         */
1152
1153#ifdef CONFIG_SMP
1154        smp_alloc_memory(); /* AP processor realmode stacks in low memory*/
1155#endif
1156        paging_init();
1157#ifdef CONFIG_X86_LOCAL_APIC
1158        /*
1159         * get boot-time SMP configuration:
1160         */
1161        if (smp_found_config)
1162                get_smp_config();
1163#endif
1164
1165        register_memory(max_low_pfn);
1166
1167#ifdef CONFIG_VT
1168#if defined(CONFIG_VGA_CONSOLE)
1169        conswitchp = &vga_con;
1170#elif defined(CONFIG_DUMMY_CONSOLE)
1171        conswitchp = &dummy_con;
1172#endif
1173#endif
1174        dmi_scan_machine();
1175}
1176
1177static int cachesize_override __initdata = -1;
1178static int __init cachesize_setup(char *str)
1179{
1180        get_option (&str, &cachesize_override);
1181        return 1;
1182}
1183__setup("cachesize=", cachesize_setup);
1184
1185
1186#ifndef CONFIG_X86_TSC
1187static int tsc_disable __initdata = 0;
1188
1189static int __init notsc_setup(char *str)
1190{
1191        tsc_disable = 1;
1192        return 1;
1193}
1194#else
1195static int __init notsc_setup(char *str)
1196{
1197        printk("notsc: Kernel compiled with CONFIG_X86_TSC, cannot disable TSC.\n");
1198        return 1;
1199}
1200#endif
1201__setup("notsc", notsc_setup);
1202
1203static int __init highio_setup(char *str)
1204{
1205        printk("i386: disabling HIGHMEM block I/O\n");
1206        blk_nohighio = 1;
1207        return 1;
1208}
1209__setup("nohighio", highio_setup);
1210
1211static int __init get_model_name(struct cpuinfo_x86 *c)
1212{
1213        unsigned int *v;
1214        char *p, *q;
1215
1216        if (cpuid_eax(0x80000000) < 0x80000004)
1217                return 0;
1218
1219        v = (unsigned int *) c->x86_model_id;
1220        cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
1221        cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
1222        cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
1223        c->x86_model_id[48] = 0;
1224
1225        /* Intel chips right-justify this string for some dumb reason;
1226           undo that brain damage */
1227        p = q = &c->x86_model_id[0];
1228        while ( *p == ' ' )
1229             p++;
1230        if ( p != q ) {
1231             while ( *p )
1232                  *q++ = *p++;
1233             while ( q <= &c->x86_model_id[48] )
1234                  *q++ = '\0';  /* Zero-pad the rest */
1235        }
1236
1237        return 1;
1238}
1239
1240
1241static void __init display_cacheinfo(struct cpuinfo_x86 *c)
1242{
1243        unsigned int n, dummy, ecx, edx, l2size;
1244
1245        n = cpuid_eax(0x80000000);
1246
1247        if (n >= 0x80000005) {
1248                cpuid(0x80000005, &dummy, &dummy, &ecx, &edx);
1249                printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
1250                        edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
1251                c->x86_cache_size=(ecx>>24)+(edx>>24);  
1252        }
1253
1254        if (n < 0x80000006)     /* Some chips just has a large L1. */
1255                return;
1256
1257        ecx = cpuid_ecx(0x80000006);
1258        l2size = ecx >> 16;
1259
1260        /* AMD errata T13 (order #21922) */
1261        if ((c->x86_vendor == X86_VENDOR_AMD) && (c->x86 == 6)) {
1262                if (c->x86_model == 3 && c->x86_mask == 0)      /* Duron Rev A0 */
1263                        l2size = 64;
1264                if (c->x86_model == 4 &&
1265                        (c->x86_mask==0 || c->x86_mask==1))     /* Tbird rev A1/A2 */
1266                        l2size = 256;
1267        }
1268
1269        if (c->x86_vendor == X86_VENDOR_CENTAUR) {
1270                /* VIA C3 CPUs (670-68F) need further shifting. */
1271                if ((c->x86 == 6) &&
1272                    ((c->x86_model == 7) || (c->x86_model == 8))) {
1273                        l2size >>= 8;
1274                }
1275
1276                /* VIA also screwed up Nehemiah stepping 1, and made
1277                   it return '65KB' instead of '64KB'
1278                   - Note, it seems this may only be in engineering samples. */
1279                if ((c->x86==6) && (c->x86_model==9) &&
1280                    (c->x86_mask==1) && (l2size==65))
1281                        l2size -= 1;
1282        }
1283
1284        /* Allow user to override all this if necessary. */
1285        if (cachesize_override != -1)
1286                l2size = cachesize_override;
1287
1288        if ( l2size == 0 )
1289                return;         /* Again, no L2 cache is possible */
1290
1291        c->x86_cache_size = l2size;
1292
1293        printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
1294               l2size, ecx & 0xFF);
1295}
1296
1297/*
1298 *      B step AMD K6 before B 9730xxxx have hardware bugs that can cause
1299 *      misexecution of code under Linux. Owners of such processors should
1300 *      contact AMD for precise details and a CPU swap.
1301 *
1302 *      See     http://www.multimania.com/poulot/k6bug.html
1303 *              http://www.amd.com/K6/k6docs/revgd.html
1304 *
1305 *      The following test is erm.. interesting. AMD neglected to up
1306 *      the chip setting when fixing the bug but they also tweaked some
1307 *      performance at the same time..
1308 */
1309 
1310extern void vide(void);
1311__asm__(".align 4\nvide: ret");
1312
1313static int __init init_amd(struct cpuinfo_x86 *c)
1314{
1315        u32 l, h;
1316        int mbytes = max_mapnr >> (20-PAGE_SHIFT);
1317        int r;
1318
1319        /*
1320         *      FIXME: We should handle the K5 here. Set up the write
1321         *      range and also turn on MSR 83 bits 4 and 31 (write alloc,
1322         *      no bus pipeline)
1323         */
1324
1325        /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1326           3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1327        clear_bit(0*32+31, &c->x86_capability);
1328        
1329        r = get_model_name(c);
1330
1331        switch(c->x86)
1332        {
1333                case 5:
1334                        if( c->x86_model < 6 )
1335                        {
1336                                /* Based on AMD doc 20734R - June 2000 */
1337                                if ( c->x86_model == 0 ) {
1338                                        clear_bit(X86_FEATURE_APIC, &c->x86_capability);
1339                                        set_bit(X86_FEATURE_PGE, &c->x86_capability);
1340                                }
1341                                break;
1342                        }
1343                        
1344                        if ( c->x86_model == 6 && c->x86_mask == 1 ) {
1345                                const int K6_BUG_LOOP = 1000000;
1346                                int n;
1347                                void (*f_vide)(void);
1348                                unsigned long d, d2;
1349                                
1350                                printk(KERN_INFO "AMD K6 stepping B detected - ");
1351                                
1352                                /*
1353                                 * It looks like AMD fixed the 2.6.2 bug and improved indirect 
1354                                 * calls at the same time.
1355                                 */
1356
1357                                n = K6_BUG_LOOP;
1358                                f_vide = vide;
1359                                rdtscl(d);
1360                                while (n--) 
1361                                        f_vide();
1362                                rdtscl(d2);
1363                                d = d2-d;
1364                                
1365                                /* Knock these two lines out if it debugs out ok */
1366                                printk(KERN_INFO "K6 BUG %ld %d (Report these if test report is incorrect)\n", d, 20*K6_BUG_LOOP);
1367                                printk(KERN_INFO "AMD K6 stepping B detected - ");
1368                                /* -- cut here -- */
1369                                if (d > 20*K6_BUG_LOOP) 
1370                                        printk("system stability may be impaired when more than 32 MB are used.\n");
1371                                else 
1372                                        printk("probably OK (after B9730xxxx).\n");
1373                                printk(KERN_INFO "Please see http://www.mygale.com/~poulot/k6bug.html\n");
1374                        }
1375
1376                        /* K6 with old style WHCR */
1377                        if (c->x86_model < 8 ||
1378                           (c->x86_model== 8 && c->x86_mask < 8)) {
1379                                /* We can only write allocate on the low 508Mb */
1380                                if(mbytes>508)
1381                                        mbytes=508;
1382
1383                                rdmsr(MSR_K6_WHCR, l, h);
1384                                if ((l&0x0000FFFF)==0) {
1385                                        unsigned long flags;
1386                                        l=(1<<0)|((mbytes/4)<<1);
1387                                        local_irq_save(flags);
1388                                        wbinvd();
1389                                        wrmsr(MSR_K6_WHCR, l, h);
1390                                        local_irq_restore(flags);
1391                                        printk(KERN_INFO "Enabling old style K6 write allocation for %d Mb\n",
1392                                                mbytes);
1393                                }
1394                                break;
1395                        }
1396
1397                        if ((c->x86_model == 8 && c->x86_mask >7) ||
1398                             c->x86_model == 9 || c->x86_model == 13) {
1399                                /* The more serious chips .. */
1400
1401                                if(mbytes>4092)
1402                                        mbytes=4092;
1403
1404                                rdmsr(MSR_K6_WHCR, l, h);
1405                                if ((l&0xFFFF0000)==0) {
1406                                        unsigned long flags;
1407                                        l=((mbytes>>2)<<22)|(1<<16);
1408                                        local_irq_save(flags);
1409                                        wbinvd();
1410                                        wrmsr(MSR_K6_WHCR, l, h);
1411                                        local_irq_restore(flags);
1412                                        printk(KERN_INFO "Enabling new style K6 write allocation for %d Mb\n",
1413                                                mbytes);
1414                                }
1415
1416                                /*  Set MTRR capability flag if appropriate */
1417                                if (c->x86_model == 13 || c->x86_model == 9 ||
1418                                   (c->x86_model == 8 && c->x86_mask >= 8))
1419                                        set_bit(X86_FEATURE_K6_MTRR, &c->x86_capability);
1420                                break;
1421                        }
1422                        break;
1423
1424                case 6: /* An Athlon/Duron */
1425 
1426                        /* Bit 15 of Athlon specific MSR 15, needs to be 0
1427                         * to enable SSE on Palomino/Morgan CPU's.
1428                         * If the BIOS didn't enable it already, enable it
1429                         * here.
1430                         */
1431                        if (c->x86_model >= 6 && c->x86_model <= 10) {
1432                                if (!test_bit(X86_FEATURE_XMM,
1433                                              &c->x86_capability)) {
1434                                        printk(KERN_INFO
1435                                               "Enabling Disabled K7/SSE Support...\n");
1436                                        rdmsr(MSR_K7_HWCR, l, h);
1437                                        l &= ~0x00008000;
1438                                        wrmsr(MSR_K7_HWCR, l, h);
1439                                        set_bit(X86_FEATURE_XMM,
1440                                                &c->x86_capability);
1441                                }
1442                        }
1443
1444                        /* It's been determined by AMD that Athlons since model 8 stepping 1
1445                         * are more robust with CLK_CTL set to 200xxxxx instead of 600xxxxx
1446                         * As per AMD technical note 27212 0.2
1447                         */
1448                        if ((c->x86_model == 8 && c->x86_mask>=1) || (c->x86_model > 8)) {
1449                                rdmsr(MSR_K7_CLK_CTL, l, h);
1450                                if ((l & 0xfff00000) != 0x20000000) {
1451                                        printk ("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n", l,
1452                                                ((l & 0x000fffff)|0x20000000));
1453                                        wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
1454                                }
1455                        }
1456                        break;
1457        }
1458
1459        display_cacheinfo(c);
1460        return r;
1461}
1462
1463/*
1464 * Read NSC/Cyrix DEVID registers (DIR) to get more detailed info. about the CPU
1465 */
1466static void __init do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
1467{
1468        unsigned char ccr2, ccr3;
1469        unsigned long flags;
1470        
1471        /* we test for DEVID by checking whether CCR3 is writable */
1472        local_irq_save(flags);
1473        ccr3 = getCx86(CX86_CCR3);
1474        setCx86(CX86_CCR3, ccr3 ^ 0x80);
1475        getCx86(0xc0);   /* dummy to change bus */
1476
1477        if (getCx86(CX86_CCR3) == ccr3) {       /* no DEVID regs. */
1478                ccr2 = getCx86(CX86_CCR2);
1479                setCx86(CX86_CCR2, ccr2 ^ 0x04);
1480                getCx86(0xc0);  /* dummy */
1481
1482                if (getCx86(CX86_CCR2) == ccr2) /* old Cx486SLC/DLC */
1483                        *dir0 = 0xfd;
1484                else {                          /* Cx486S A step */
1485                        setCx86(CX86_CCR2, ccr2);
1486                        *dir0 = 0xfe;
1487                }
1488        }
1489        else {
1490                setCx86(CX86_CCR3, ccr3);  /* restore CCR3 */
1491
1492                /* read DIR0 and DIR1 CPU registers */
1493                *dir0 = getCx86(CX86_DIR0);
1494                *dir1 = getCx86(CX86_DIR1);
1495        }
1496        local_irq_restore(flags);
1497}
1498
1499/*
1500 * Cx86_dir0_msb is a HACK needed by check_cx686_cpuid/slop in
1501 * order to identify the Cyrix CPU model after we're out of the
1502 * initial setup.
1503 */
1504static unsigned char Cx86_dir0_msb __initdata = 0;
1505
1506static char Cx86_model[][9] __initdata = {
1507        "Cx486", "Cx486", "5x86 ", "6x86", "MediaGX ", "6x86MX ",
1508        "M II ", "Unknown"
1509};
1510static char Cx486_name[][5] __initdata = {
1511        "SLC", "DLC", "SLC2", "DLC2", "SRx", "DRx",
1512        "SRx2", "DRx2"
1513};
1514static char Cx486S_name[][4] __initdata = {
1515        "S", "S2", "Se", "S2e"
1516};
1517static char Cx486D_name[][4] __initdata = {
1518        "DX", "DX2", "?", "?", "?", "DX4"
1519};
1520static char Cx86_cb[] __initdata = "?.5x Core/Bus Clock";
1521static char cyrix_model_mult1[] __initdata = "12??43";
1522static char cyrix_model_mult2[] __initdata = "12233445";
1523
1524/*
1525 * Reset the slow-loop (SLOP) bit on the 686(L) which is set by some old
1526 * BIOSes for compatability with DOS games.  This makes the udelay loop
1527 * work correctly, and improves performance.
1528 *
1529 * FIXME: our newer udelay uses the tsc. We dont need to frob with SLOP
1530 */
1531
1532extern void calibrate_delay(void) __init;
1533
1534static void __init check_cx686_slop(struct cpuinfo_x86 *c)
1535{
1536        unsigned long flags;
1537        
1538        if (Cx86_dir0_msb == 3) {
1539                unsigned char ccr3, ccr5;
1540
1541                local_irq_save(flags);
1542                ccr3 = getCx86(CX86_CCR3);
1543                setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN  */
1544                ccr5 = getCx86(CX86_CCR5);
1545                if (ccr5 & 2)
1546                        setCx86(CX86_CCR5, ccr5 & 0xfd);  /* reset SLOP */
1547                setCx86(CX86_CCR3, ccr3);                 /* disable MAPEN */
1548                local_irq_restore(flags);
1549
1550                if (ccr5 & 2) { /* possible wrong calibration done */
1551                        printk(KERN_INFO "Recalibrating delay loop with SLOP bit reset\n");
1552                        calibrate_delay();
1553                        c->loops_per_jiffy = loops_per_jiffy;
1554                }
1555        }
1556}
1557
1558static void __init init_cyrix(struct cpuinfo_x86 *c)
1559{
1560        unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
1561        char *buf = c->x86_model_id;
1562        const char *p = NULL;
1563
1564        /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1565           3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1566        clear_bit(0*32+31, &c->x86_capability);
1567
1568        /* Cyrix used bit 24 in extended (AMD) CPUID for Cyrix MMX extensions */
1569        if ( test_bit(1*32+24, &c->x86_capability) ) {
1570                clear_bit(1*32+24, &c->x86_capability);
1571                set_bit(X86_FEATURE_CXMMX, &c->x86_capability);
1572        }
1573
1574        do_cyrix_devid(&dir0, &dir1);
1575
1576        check_cx686_slop(c);
1577
1578        Cx86_dir0_msb = dir0_msn = dir0 >> 4; /* identifies CPU "family"   */
1579        dir0_lsn = dir0 & 0xf;                /* model or clock multiplier */
1580
1581        /* common case step number/rev -- exceptions handled below */
1582        c->x86_model = (dir1 >> 4) + 1;
1583        c->x86_mask = dir1 & 0xf;
1584
1585        /* Now cook; the original recipe is by Channing Corn, from Cyrix.
1586         * We do the same thing for each generation: we work out
1587         * the model, multiplier and stepping.  Black magic included,
1588         * to make the silicon step/rev numbers match the printed ones.
1589         */
1590         
1591        switch (dir0_msn) {
1592                unsigned char tmp;
1593
1594        case 0: /* Cx486SLC/DLC/SRx/DRx */
1595                p = Cx486_name[dir0_lsn & 7];
1596                break;
1597
1598        case 1: /* Cx486S/DX/DX2/DX4 */
1599                p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
1600                        : Cx486S_name[dir0_lsn & 3];
1601                break;
1602
1603        case 2: /* 5x86 */
1604                Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
1605                p = Cx86_cb+2;
1606                break;
1607
1608        case 3: /* 6x86/6x86L */
1609                Cx86_cb[1] = ' ';
1610                Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
1611                if (dir1 > 0x21) { /* 686L */
1612                        Cx86_cb[0] = 'L';
1613                        p = Cx86_cb;
1614                        (c->x86_model)++;
1615                } else             /* 686 */
1616                        p = Cx86_cb+1;
1617                /* Emulate MTRRs using Cyrix's ARRs. */
1618                set_bit(X86_FEATURE_CYRIX_ARR, &c->x86_capability);
1619                /* 6x86's contain this bug */
1620                c->coma_bug = 1;
1621                break;
1622
1623        case 4: /* MediaGX/GXm */
1624#ifdef CONFIG_PCI
1625                /* It isnt really a PCI quirk directly, but the cure is the
1626                   same. The MediaGX has deep magic SMM stuff that handles the
1627                   SB emulation. It thows away the fifo on disable_dma() which
1628                   is wrong and ruins the audio. 
1629                   
1630                   Bug2: VSA1 has a wrap bug so that using maximum sized DMA 
1631                   causes bad things. According to NatSemi VSA2 has another
1632                   bug to do with 'hlt'. I've not seen any boards using VSA2
1633                   and X doesn't seem to support it either so who cares 8).
1634                   VSA1 we work around however.
1635                */
1636
1637                printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bugs.\n");
1638                isa_dma_bridge_buggy = 2;
1639#endif          
1640                c->x86_cache_size=16;   /* Yep 16K integrated cache thats it */
1641
1642                /* GXm supports extended cpuid levels 'ala' AMD */
1643                if (c->cpuid_level == 2) {
1644                        get_model_name(c);  /* get CPU marketing name */
1645                        /*
1646                         *      The 5510/5520 companion chips have a funky PIT
1647                         *      that breaks the TSC synchronizing, so turn it off
1648                         */
1649                        if(pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, NULL) ||
1650                           pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, NULL))
1651                                clear_bit(X86_FEATURE_TSC, c->x86_capability);
1652                        return;
1653                }
1654                else {  /* MediaGX */
1655                        Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
1656                        p = Cx86_cb+2;
1657                        c->x86_model = (dir1 & 0x20) ? 1 : 2;
1658                        if(pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, NULL) ||
1659                           pci_find_device(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, NULL))
1660                                clear_bit(X86_FEATURE_TSC, &c->x86_capability);
1661                }
1662                break;
1663
1664        case 5: /* 6x86MX/M II */
1665                if (dir1 > 7)
1666                {
1667                        dir0_msn++;  /* M II */
1668                        /* Enable MMX extensions (App note 108) */
1669                        setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
1670                }
1671                else
1672                {
1673                        c->coma_bug = 1;      /* 6x86MX, it has the bug. */
1674                }
1675                tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
1676                Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
1677                p = Cx86_cb+tmp;
1678                if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
1679                        (c->x86_model)++;
1680                /* Emulate MTRRs using Cyrix's ARRs. */
1681                set_bit(X86_FEATURE_CYRIX_ARR, &c->x86_capability);
1682                break;
1683
1684        case 0xf:  /* Cyrix 486 without DEVID registers */
1685                switch (dir0_lsn) {
1686                case 0xd:  /* either a 486SLC or DLC w/o DEVID */
1687                        dir0_msn = 0;
1688                        p = Cx486_name[(c->hard_math) ? 1 : 0];
1689                        break;
1690
1691                case 0xe:  /* a 486S A step */
1692                        dir0_msn = 0;
1693                        p = Cx486S_name[0];
1694                        break;
1695                }
1696                break;
1697
1698        default:  /* unknown (shouldn't happen, we know everyone ;-) */
1699                dir0_msn = 7;
1700                break;
1701        }
1702        strcpy(buf, Cx86_model[dir0_msn & 7]);
1703        if (p) strcat(buf, p);
1704        return;
1705}
1706
1707#ifdef CONFIG_X86_OOSTORE
1708
1709static u32 __init power2(u32 x)
1710{
1711        u32 s=1;
1712        while(s<=x)
1713                s<<=1;
1714        return s>>=1;
1715}
1716
1717/*
1718 *      Set up an actual MCR
1719 */
1720 
1721static void __init winchip_mcr_insert(int reg, u32 base, u32 size, int key)
1722{
1723        u32 lo, hi;
1724        
1725        hi = base & ~0xFFF;
1726        lo = ~(size-1);         /* Size is a power of 2 so this makes a mask */
1727        lo &= ~0xFFF;           /* Remove the ctrl value bits */
1728        lo |= key;              /* Attribute we wish to set */
1729        wrmsr(reg+MSR_IDT_MCR0, lo, hi);
1730        mtrr_centaur_report_mcr(reg, lo, hi);   /* Tell the mtrr driver */
1731}
1732
1733/*
1734 *      Figure what we can cover with MCR's
1735 *
1736 *      Shortcut: We know you can't put 4Gig of RAM on a winchip
1737 */
1738
1739static u32 __init ramtop(void)          /* 16388 */
1740{
1741        int i;
1742        u32 top = 0;
1743        u32 clip = 0xFFFFFFFFUL;
1744        
1745        for (i = 0; i < e820.nr_map; i++) {
1746                unsigned long start, end;
1747
1748                if (e820.map[i].addr > 0xFFFFFFFFUL)
1749                        continue;
1750                /*
1751                 *      Don't MCR over reserved space. Ignore the ISA hole
1752                 *      we frob around that catastrophy already
1753                 */
1754                                        
1755                if (e820.map[i].type == E820_RESERVED)
1756                {
1757                        if(e820.map[i].addr >= 0x100000UL && e820.map[i].addr < clip)
1758                                clip = e820.map[i].addr;
1759                        continue;
1760                }
1761                start = e820.map[i].addr;
1762                end = e820.map[i].addr + e820.map[i].size;
1763                if (start >= end)
1764                        continue;
1765                if (end > top)
1766                        top = end;
1767        }
1768        /* Everything below 'top' should be RAM except for the ISA hole.
1769           Because of the limited MCR's we want to map NV/ACPI into our
1770           MCR range for gunk in RAM 
1771           
1772           Clip might cause us to MCR insufficient RAM but that is an
1773           acceptable failure mode and should only bite obscure boxes with
1774           a VESA hole at 15Mb
1775           
1776           The second case Clip sometimes kicks in is when the EBDA is marked
1777           as reserved. Again we fail safe with reasonable results
1778        */
1779        
1780        if(top>clip)
1781                top=clip;
1782                
1783        return top;
1784}
1785
1786/*
1787 *      Compute a set of MCR's to give maximum coverage
1788 */
1789
1790static int __init winchip_mcr_compute(int nr, int key)
1791{
1792        u32 mem = ramtop();
1793        u32 root = power2(mem);
1794        u32 base = root;
1795        u32 top = root;
1796        u32 floor = 0;
1797        int ct = 0;
1798        
1799        while(ct<nr)
1800        {
1801                u32 fspace = 0;
1802
1803                /*
1804                 *      Find the largest block we will fill going upwards
1805                 */
1806
1807                u32 high = power2(mem-top);     
1808
1809                /*
1810                 *      Find the largest block we will fill going downwards
1811                 */
1812
1813                u32 low = base/2;
1814
1815                /*
1816                 *      Don't fill below 1Mb going downwards as there
1817                 *      is an ISA hole in the way.
1818                 */             
1819                 
1820                if(base <= 1024*1024)
1821                        low = 0;
1822                        
1823                /*
1824                 *      See how much space we could cover by filling below
1825                 *      the ISA hole
1826                 */
1827                 
1828                if(floor == 0)
1829                        fspace = 512*1024;
1830                else if(floor ==512*1024)
1831                        fspace = 128*1024;
1832
1833                /* And forget ROM space */
1834                
1835                /*
1836                 *      Now install the largest coverage we get
1837                 */
1838                 
1839                if(fspace > high && fspace > low)
1840                {
1841                        winchip_mcr_insert(ct, floor, fspace, key);
1842                        floor += fspace;
1843                }
1844                else if(high > low)
1845                {
1846                        winchip_mcr_insert(ct, top, high, key);
1847                        top += high;
1848                }
1849                else if(low > 0)
1850                {
1851                        base -= low;
1852                        winchip_mcr_insert(ct, base, low, key);
1853                }
1854                else break;
1855                ct++;
1856        }
1857        /*
1858         *      We loaded ct values. We now need to set the mask. The caller
1859         *      must do this bit.
1860         */
1861         
1862        return ct;
1863}
1864
1865static void __init winchip_create_optimal_mcr(void)
1866{
1867        int i;
1868        /*
1869         *      Allocate up to 6 mcrs to mark as much of ram as possible
1870         *      as write combining and weak write ordered.
1871         *
1872         *      To experiment with: Linux never uses stack operations for 
1873         *      mmio spaces so we could globally enable stack operation wc
1874         *
1875         *      Load the registers with type 31 - full write combining, all
1876         *      writes weakly ordered.
1877         */
1878        int used = winchip_mcr_compute(6, 31);
1879
1880        /*
1881         *      Wipe unused MCRs
1882         */
1883         
1884        for(i=used;i<8;i++)
1885                wrmsr(MSR_IDT_MCR0+i, 0, 0);
1886}
1887
1888static void __init winchip2_create_optimal_mcr(void)
1889{
1890        u32 lo, hi;
1891        int i;
1892
1893        /*
1894         *      Allocate up to 6 mcrs to mark as much of ram as possible
1895         *      as write combining, weak store ordered.
1896         *
1897         *      Load the registers with type 25
1898         *              8       -       weak write ordering
1899         *              16      -       weak read ordering
1900         *              1       -       write combining
1901         */
1902
1903        int used = winchip_mcr_compute(6, 25);
1904        
1905        /*
1906         *      Mark the registers we are using.
1907         */
1908         
1909        rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
1910        for(i=0;i<used;i++)
1911                lo|=1<<(9+i);
1912        wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
1913        
1914        /*
1915         *      Wipe unused MCRs
1916         */
1917         
1918        for(i=used;i<8;i++)
1919                wrmsr(MSR_IDT_MCR0+i, 0, 0);
1920}
1921
1922/*
1923 *      Handle the MCR key on the Winchip 2.
1924 */
1925
1926static void __init winchip2_unprotect_mcr(void)
1927{
1928        u32 lo, hi;
1929        u32 key;
1930        
1931        rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
1932        lo&=~0x1C0;     /* blank bits 8-6 */
1933        key = (lo>>17) & 7;
1934        lo |= key<<6;   /* replace with unlock key */
1935        wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
1936}
1937
1938static void __init winchip2_protect_mcr(void)
1939{
1940        u32 lo, hi;
1941        
1942        rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
1943        lo&=~0x1C0;     /* blank bits 8-6 */
1944        wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
1945}
1946        
1947#endif
1948
1949static void __init init_centaur(struct cpuinfo_x86 *c)
1950{
1951        enum {
1952                ECX8=1<<1,
1953                EIERRINT=1<<2,
1954                DPM=1<<3,
1955                DMCE=1<<4,
1956                DSTPCLK=1<<5,
1957                ELINEAR=1<<6,
1958                DSMC=1<<7,
1959                DTLOCK=1<<8,
1960                EDCTLB=1<<8,
1961                EMMX=1<<9,
1962                DPDC=1<<11,
1963                EBRPRED=1<<12,
1964                DIC=1<<13,
1965                DDC=1<<14,
1966                DNA=1<<15,
1967                ERETSTK=1<<16,
1968                E2MMX=1<<19,
1969                EAMD3D=1<<20,
1970        };
1971
1972        char *name;
1973        u32  fcr_set=0;
1974        u32  fcr_clr=0;
1975        u32  lo,hi,newlo;
1976        u32  aa,bb,cc,dd;
1977
1978        /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
1979           3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
1980        clear_bit(0*32+31, &c->x86_capability);
1981
1982        switch (c->x86) {
1983
1984                case 5:
1985                        switch(c->x86_model) {
1986                        case 4:
1987                                name="C6";
1988                                fcr_set=ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
1989                                fcr_clr=DPDC;
1990                                printk(KERN_NOTICE "Disabling bugged TSC.\n");
1991                                clear_bit(X86_FEATURE_TSC, &c->x86_capability);
1992#ifdef CONFIG_X86_OOSTORE
1993                                winchip_create_optimal_mcr();
1994                                /* Enable
1995                                        write combining on non-stack, non-string
1996                                        write combining on string, all types
1997                                        weak write ordering 
1998                                        
1999                                   The C6 original lacks weak read order 
2000                                   
2001                                   Note 0x120 is write only on Winchip 1 */
2002                                   
2003                                wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0);
2004#endif                          
2005                                break;
2006                        case 8:
2007                                switch(c->x86_mask) {
2008                                default:
2009                                        name="2";
2010                                        break;
2011                                case 7 ... 9:
2012                                        name="2A";
2013                                        break;
2014                                case 10 ... 15:
2015                                        name="2B";
2016                                        break;
2017                                }
2018                                fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
2019                                fcr_clr=DPDC;
2020#ifdef CONFIG_X86_OOSTORE
2021                                winchip2_unprotect_mcr();
2022                                winchip2_create_optimal_mcr();
2023                                rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
2024                                /* Enable
2025                                        write combining on non-stack, non-string
2026                                        write combining on string, all types
2027                                        weak write ordering 
2028                                */
2029                                lo|=31;                         
2030                                wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
2031                                winchip2_protect_mcr();
2032#endif
2033                                break;
2034                        case 9:
2035                                name="3";
2036                                fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
2037                                fcr_clr=DPDC;
2038#ifdef CONFIG_X86_OOSTORE
2039                                winchip2_unprotect_mcr();
2040                                winchip2_create_optimal_mcr();
2041                                rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
2042                                /* Enable
2043                                        write combining on non-stack, non-string
2044                                        write combining on string, all types
2045                                        weak write ordering 
2046                                */
2047                                lo|=31;                         
2048                                wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
2049                                winchip2_protect_mcr();
2050#endif
2051                                break;
2052                        case 10:
2053                                name="4";
2054                                /* no info on the WC4 yet */
2055                                break;
2056                        default:
2057                                name="??";
2058                        }
2059
2060                        rdmsr(MSR_IDT_FCR1, lo, hi);
2061                        newlo=(lo|fcr_set) & (~fcr_clr);
2062
2063                        if (newlo!=lo) {
2064                                printk(KERN_INFO "Centaur FCR was 0x%X now 0x%X\n", lo, newlo );
2065                                wrmsr(MSR_IDT_FCR1, newlo, hi );
2066                        } else {
2067                                printk(KERN_INFO "Centaur FCR is 0x%X\n",lo);
2068                        }
2069                        /* Emulate MTRRs using Centaur's MCR. */
2070                        set_bit(X86_FEATURE_CENTAUR_MCR, &c->x86_capability);
2071                        /* Report CX8 */
2072                        set_bit(X86_FEATURE_CX8, &c->x86_capability);
2073                        /* Set 3DNow! on Winchip 2 and above. */
2074                        if (c->x86_model >=8)
2075                                set_bit(X86_FEATURE_3DNOW, &c->x86_capability);
2076                        /* See if we can find out some more. */
2077                        if ( cpuid_eax(0x80000000) >= 0x80000005 ) {
2078                                /* Yes, we can. */
2079                                cpuid(0x80000005,&aa,&bb,&cc,&dd);
2080                                /* Add L1 data and code cache sizes. */
2081                                c->x86_cache_size = (cc>>24)+(dd>>24);
2082                        }
2083                        sprintf( c->x86_model_id, "WinChip %s", name );
2084                        break;
2085
2086                case 6:
2087                        switch (c->x86_model) {
2088                                case 6 ... 8:           /* Cyrix III family */
2089                                        rdmsr (MSR_VIA_FCR, lo, hi);
2090                                        lo |= (1<<1 | 1<<7);    /* Report CX8 & enable PGE */
2091                                        wrmsr (MSR_VIA_FCR, lo, hi);
2092
2093                                        set_bit(X86_FEATURE_CX8, &c->x86_capability);
2094                                        set_bit(X86_FEATURE_3DNOW, &c->x86_capability);
2095
2096                                        /* fall through */
2097
2098                                case 9: /* Nehemiah */
2099                                default:
2100                                        get_model_name(c);
2101                                        display_cacheinfo(c);
2102                                        break;
2103                        }
2104                        break;
2105        }
2106}
2107
2108
2109static void __init init_transmeta(struct cpuinfo_x86 *c)
2110{
2111        unsigned int cap_mask, uk, max, dummy;
2112        unsigned int cms_rev1, cms_rev2;
2113        unsigned int cpu_rev, cpu_freq, cpu_flags;
2114        char cpu_info[65];
2115
2116        get_model_name(c);      /* Same as AMD/Cyrix */
2117        display_cacheinfo(c);
2118
2119        /* Print CMS and CPU revision */
2120        max = cpuid_eax(0x80860000);
2121        if ( max >= 0x80860001 ) {
2122                cpuid(0x80860001, &dummy, &cpu_rev, &cpu_freq, &cpu_flags); 
2123                printk(KERN_INFO "CPU: Processor revision %u.%u.%u.%u, %u MHz\n",
2124                       (cpu_rev >> 24) & 0xff,
2125                       (cpu_rev >> 16) & 0xff,
2126                       (cpu_rev >> 8) & 0xff,
2127                       cpu_rev & 0xff,
2128                       cpu_freq);
2129        }
2130        if ( max >= 0x80860002 ) {
2131                cpuid(0x80860002, &dummy, &cms_rev1, &cms_rev2, &dummy);
2132                printk(KERN_INFO "CPU: Code Morphing Software revision %u.%u.%u-%u-%u\n",
2133                       (cms_rev1 >> 24) & 0xff,
2134                       (cms_rev1 >> 16) & 0xff,
2135                       (cms_rev1 >> 8) & 0xff,
2136                       cms_rev1 & 0xff,
2137                       cms_rev2);
2138        }
2139        if ( max >= 0x80860006 ) {
2140                cpuid(0x80860003,
2141                      (void *)&cpu_info[0],
2142                      (void *)&cpu_info[4],
2143                      (void *)&cpu_info[8],
2144                      (void *)&cpu_info[12]);
2145                cpuid(0x80860004,
2146                      (void *)&cpu_info[16],
2147                      (void *)&cpu_info[20],
2148                      (void *)&cpu_info[24],
2149                      (void *)&cpu_info[28]);
2150                cpuid(0x80860005,
2151                      (void *)&cpu_info[32],
2152                      (void *)&cpu_info[36],
2153                      (void *)&cpu_info[40],
2154                      (void *)&cpu_info[44]);
2155                cpuid(0x80860006,
2156                      (void *)&cpu_info[48],
2157                      (void *)&cpu_info[52],
2158                      (void *)&cpu_info[56],
2159                      (void *)&cpu_info[60]);
2160                cpu_info[64] = '\0';
2161                printk(KERN_INFO "CPU: %s\n", cpu_info);
2162        }
2163
2164        /* Unhide possibly hidden capability flags */
2165        rdmsr(0x80860004, cap_mask, uk);
2166        wrmsr(0x80860004, ~0, uk);
2167        c->x86_capability[0] = cpuid_edx(0x00000001);
2168        wrmsr(0x80860004, cap_mask, uk);
2169
2170        /* If we can run i686 user-space code, call us an i686 */
2171#define USER686 (X86_FEATURE_TSC|X86_FEATURE_CX8|X86_FEATURE_CMOV)
2172        if ( c->x86 == 5 && (c->x86_capability[0] & USER686) == USER686 )
2173             c->x86 = 6;
2174}
2175
2176
2177static void __init init_rise(struct cpuinfo_x86 *c)
2178{
2179        printk("CPU: Rise iDragon");
2180        if (c->x86_model > 2)
2181                printk(" II");
2182        printk("\n");
2183
2184        /* Unhide possibly hidden capability flags
2185           The mp6 iDragon family don't have MSRs.
2186           We switch on extra features with this cpuid weirdness: */
2187        __asm__ (
2188                "movl $0x6363452a, %%eax\n\t"
2189                "movl $0x3231206c, %%ecx\n\t"
2190                "movl $0x2a32313a, %%edx\n\t"
2191                "cpuid\n\t"
2192                "movl $0x63634523, %%eax\n\t"
2193                "movl $0x32315f6c, %%ecx\n\t"
2194                "movl $0x2333313a, %%edx\n\t"
2195                "cpuid\n\t" : : : "eax", "ebx", "ecx", "edx"
2196        );
2197        set_bit(X86_FEATURE_CX8, &c->x86_capability);
2198}
2199
2200
2201extern void trap_init_f00f_bug(void);
2202
2203#define LVL_1_INST      1
2204#define LVL_1_DATA      2
2205#define LVL_2           3
2206#define LVL_3           4
2207#define LVL_TRACE       5
2208
2209struct _cache_table
2210{
2211        unsigned char descriptor;
2212        char cache_type;
2213        short size;
2214};
2215
2216/* all the cache descriptor types we care about (no TLB or trace cache entries) */
2217static struct _cache_table cache_table[] __initdata =
2218{
2219        { 0x06, LVL_1_INST, 8 },
2220        { 0x08, LVL_1_INST, 16 },
2221        { 0x0A, LVL_1_DATA, 8 },
2222        { 0x0C, LVL_1_DATA, 16 },
2223        { 0x22, LVL_3,      512 },
2224        { 0x23, LVL_3,      1024 },
2225        { 0x25, LVL_3,      2048 },
2226        { 0x29, LVL_3,      4096 },
2227        { 0x39, LVL_2,      128 },
2228        { 0x3b, LVL_2,      128 },
2229        { 0x3C, LVL_2,      256 },
2230        { 0x41, LVL_2,      128 },
2231        { 0x42, LVL_2,      256 },
2232        { 0x43, LVL_2,      512 },
2233        { 0x44, LVL_2,      1024 },
2234        { 0x45, LVL_2,      2048 },
2235        { 0x66, LVL_1_DATA, 8 },
2236        { 0x67, LVL_1_DATA, 16 },
2237        { 0x68, LVL_1_DATA, 32 },
2238        { 0x70, LVL_TRACE,  12 },
2239        { 0x71, LVL_TRACE,  16 },
2240        { 0x72, LVL_TRACE,  32 },
2241        { 0x79, LVL_2,      128 },
2242        { 0x7A, LVL_2,      256 },
2243        { 0x7B, LVL_2,      512 },
2244        { 0x7C, LVL_2,      1024 },
2245        { 0x82, LVL_2,      256 },
2246        { 0x83, LVL_2,      512 },
2247        { 0x84, LVL_2,      1024 },
2248        { 0x85, LVL_2,      2048 },
2249        { 0x00, 0, 0}
2250};
2251
2252static void __init init_intel(struct cpuinfo_x86 *c)
2253{
2254        unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0; /* Cache sizes */
2255        char *p = NULL;
2256#ifndef CONFIG_X86_F00F_WORKS_OK
2257        static int f00f_workaround_enabled = 0;
2258
2259        /*
2260         * All current models of Pentium and Pentium with MMX technology CPUs
2261         * have the F0 0F bug, which lets nonpriviledged users lock up the system.
2262         * Note that the workaround only should be initialized once...
2263         */
2264        c->f00f_bug = 0;
2265        if (c->x86 == 5) {
2266                c->f00f_bug = 1;
2267                if (!f00f_workaround_enabled) {
2268                        trap_init_f00f_bug();
2269                        printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
2270                        f00f_workaround_enabled = 1;
2271                }
2272        }
2273#endif /* CONFIG_X86_F00F_WORKS_OK */
2274
2275        if (c->cpuid_level > 1) {
2276                /* supports eax=2  call */
2277                int i, j, n;
2278                int regs[4];
2279                unsigned char *dp = (unsigned char *)regs;
2280
2281                /* Number of times to iterate */
2282                n = cpuid_eax(2) & 0xFF;
2283
2284                for ( i = 0 ; i < n ; i++ ) {
2285                        cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
2286                        
2287                        /* If bit 31 is set, this is an unknown format */
2288                        for ( j = 0 ; j < 3 ; j++ ) {
2289                                if ( regs[j] < 0 ) regs[j] = 0;
2290                        }
2291
2292                        /* Byte 0 is level count, not a descriptor */
2293                        for ( j = 1 ; j < 16 ; j++ ) {
2294                                unsigned char des = dp[j];
2295                                unsigned char k = 0;
2296
2297                                /* look up this descriptor in the table */
2298                                while (cache_table[k].descriptor != 0)
2299                                {
2300                                        if (cache_table[k].descriptor == des) {
2301                                                switch (cache_table[k].cache_type) {
2302                                                case LVL_1_INST:
2303                                                        l1i += cache_table[k].size;
2304                                                        break;
2305                                                case LVL_1_DATA:
2306                                                        l1d += cache_table[k].size;
2307                                                        break;
2308                                                case LVL_2:
2309                                                        l2 += cache_table[k].size;
2310                                                        break;
2311                                                case LVL_3:
2312                                                        l3 += cache_table[k].size;
2313                                                        break;
2314                                                case LVL_TRACE:
2315                                                        trace += cache_table[k].size;
2316                                                        break;
2317                                                }
2318                                                break;
2319                                        }
2320
2321                                        k++;
2322                                }
2323                        }
2324                }
2325
2326                /* Intel PIII Tualatin. This comes in two flavours.
2327                 * One has 256kb of cache, the other 512. We have no way
2328                 * to determine which, so we use a boottime override
2329                 * for the 512kb model, and assume 256 otherwise.
2330                 */
2331                if ((c->x86 == 6) && (c->x86_model == 11) && (l2 == 0))
2332                        l2 = 256;
2333                /* Allow user to override all this if necessary. */
2334                if (cachesize_override != -1)
2335                        l2 = cachesize_override;
2336
2337                if ( trace )
2338                        printk (KERN_INFO "CPU: Trace cache: %dK uops", trace);
2339                else if ( l1i )
2340                        printk (KERN_INFO "CPU: L1 I cache: %dK", l1i);
2341                if ( l1d )
2342                        printk(", L1 D cache: %dK\n", l1d);
2343
2344                if ( l2 )
2345                        printk(KERN_INFO "CPU: L2 cache: %dK\n", l2);
2346                if ( l3 )
2347                        printk(KERN_INFO "CPU: L3 cache: %dK\n", l3);
2348
2349                /*
2350                 * This assumes the L3 cache is shared; it typically lives in
2351                 * the northbridge.  The L1 caches are included by the L2
2352                 * cache, and so should not be included for the purpose of
2353                 * SMP switching weights.
2354                 */
2355                c->x86_cache_size = l2 ? l2 : (l1i+l1d);
2356        }
2357
2358        /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it */
2359        if ( c->x86 == 6 && c->x86_model < 3 && c->x86_mask < 3 )
2360                clear_bit(X86_FEATURE_SEP, &c->x86_capability);
2361        
2362        /* Names for the Pentium II/Celeron processors 
2363           detectable only by also checking the cache size.
2364           Dixon is NOT a Celeron. */
2365        if (c->x86 == 6) {
2366                switch (c->x86_model) {
2367                case 5:
2368                        if (l2 == 0)
2369                                p = "Celeron (Covington)";
2370                        if (l2 == 256)
2371                                p = "Mobile Pentium II (Dixon)";
2372                        break;
2373                        
2374                case 6:
2375                        if (l2 == 128)
2376                                p = "Celeron (Mendocino)";
2377                        break;
2378                        
2379                case 8:
2380                        if (l2 == 128)
2381                                p = "Celeron (Coppermine)";
2382                        break;
2383                }
2384        }
2385
2386        if ( p )
2387                strcpy(c->x86_model_id, p);
2388        
2389#ifdef CONFIG_SMP
2390        if (test_bit(X86_FEATURE_HT, &c->x86_capability) && !disable_x86_ht) {
2391                extern  int phys_proc_id[NR_CPUS];
2392                
2393                u32     eax, ebx, ecx, edx;
2394                int     index_lsb, index_msb, tmp;
2395                int     initial_apic_id;
2396                int     cpu = smp_processor_id();
2397
2398                cpuid(1, &eax, &ebx, &ecx, &edx);
2399                smp_num_siblings = (ebx & 0xff0000) >> 16;
2400
2401                if (smp_num_siblings == 1) {
2402                        printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
2403                } else if (smp_num_siblings > 1 ) {
2404                        index_lsb = 0;
2405                        index_msb = 31;
2406                        /*
2407                         * At this point we only support two siblings per
2408                         * processor package.
2409                         */
2410#define NR_SIBLINGS     2
2411                        if (smp_num_siblings != NR_SIBLINGS) {
2412                                printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
2413                                smp_num_siblings = 1;
2414                                return;
2415                        }
2416                        tmp = smp_num_siblings;
2417                        while ((tmp & 1) == 0) {
2418                                tmp >>=1 ;
2419                                index_lsb++;
2420                        }
2421                        tmp = smp_num_siblings;
2422                        while ((tmp & 0x80000000 ) == 0) {
2423                                tmp <<=1 ;
2424                                index_msb--;
2425                        }
2426                        if (index_lsb != index_msb )
2427                                index_msb++;
2428                        initial_apic_id = ebx >> 24 & 0xff;
2429                        phys_proc_id[cpu] = initial_apic_id >> index_msb;
2430
2431                        printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
2432                               phys_proc_id[cpu]);
2433                }
2434
2435        }
2436#endif
2437}
2438
2439void __init get_cpu_vendor(struct cpuinfo_x86 *c)
2440{
2441        char *v = c->x86_vendor_id;
2442
2443        if (!strcmp(v, "GenuineIntel"))
2444                c->x86_vendor = X86_VENDOR_INTEL;
2445        else if (!strcmp(v, "AuthenticAMD"))
2446                c->x86_vendor = X86_VENDOR_AMD;
2447        else if (!strcmp(v, "CyrixInstead"))
2448                c->x86_vendor = X86_VENDOR_CYRIX;
2449        else if (!strcmp(v, "Geode by NSC"))
2450                c->x86_vendor = X86_VENDOR_NSC;
2451        else if (!strcmp(v, "UMC UMC UMC "))
2452                c->x86_vendor = X86_VENDOR_UMC;
2453        else if (!strcmp(v, "CentaurHauls"))
2454                c->x86_vendor = X86_VENDOR_CENTAUR;
2455        else if (!strcmp(v, "NexGenDriven"))
2456                c->x86_vendor = X86_VENDOR_NEXGEN;
2457        else if (!strcmp(v, "RiseRiseRise"))
2458                c->x86_vendor = X86_VENDOR_RISE;
2459        else if (!strcmp(v, "GenuineTMx86") ||
2460                 !strcmp(v, "TransmetaCPU"))
2461                c->x86_vendor = X86_VENDOR_TRANSMETA;
2462        else if (!strcmp(v, "SiS SiS SiS "))
2463                c->x86_vendor = X86_VENDOR_SIS;
2464        else
2465                c->x86_vendor = X86_VENDOR_UNKNOWN;
2466}
2467
2468struct cpu_model_info {
2469        int vendor;
2470        int family;
2471        char *model_names[16];
2472};
2473
2474/* Naming convention should be: <Name> [(<Codename>)] */
2475/* This table only is used unless init_<vendor>() below doesn't set it; */
2476/* in particular, if CPUID levels 0x80000002..4 are supported, this isn't used */
2477static struct cpu_model_info cpu_models[] __initdata = {
2478        { X86_VENDOR_INTEL,     4,
2479          { "486 DX-25/33", "486 DX-50", "486 SX", "486 DX/2", "486 SL", 
2480            "486 SX/2", NULL, "486 DX/2-WB", "486 DX/4", "486 DX/4-WB", NULL, 
2481            NULL, NULL, NULL, NULL, NULL }},
2482        { X86_VENDOR_INTEL,     5,
2483          { "Pentium 60/66 A-step", "Pentium 60/66", "Pentium 75 - 200",
2484            "OverDrive PODP5V83", "Pentium MMX", NULL, NULL,
2485            "Mobile Pentium 75 - 200", "Mobile Pentium MMX", NULL, NULL, NULL,
2486            NULL, NULL, NULL, NULL }},
2487        { X86_VENDOR_INTEL,     6,
2488          { "Pentium Pro A-step", "Pentium Pro", NULL, "Pentium II (Klamath)", 
2489            NULL, "Pentium II (Deschutes)", "Mobile Pentium II",
2490            "Pentium III (Katmai)", "Pentium III (Coppermine)", NULL,
2491            "Pentium III (Cascades)", NULL, NULL, NULL, NULL }},
2492        { X86_VENDOR_AMD,       4,
2493          { NULL, NULL, NULL, "486 DX/2", NULL, NULL, NULL, "486 DX/2-WB",
2494            "486 DX/4", "486 DX/4-WB", NULL, NULL, NULL, NULL, "Am5x86-WT",
2495            "Am5x86-WB" }},
2496        { X86_VENDOR_AMD,       5, /* Is this this really necessary?? */
2497          { "K5/SSA5", "K5",
2498            "K5", "K5", NULL, NULL,
2499            "K6", "K6", "K6-2",
2500            "K6-3", NULL, NULL, NULL, NULL, NULL, NULL }},
2501        { X86_VENDOR_AMD,       6, /* Is this this really necessary?? */
2502          { "Athlon", "Athlon",
2503            "Athlon", NULL, "Athlon", NULL,
2504            NULL, NULL, NULL,
2505            NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
2506        { X86_VENDOR_UMC,       4,
2507          { NULL, "U5D", "U5S", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2508            NULL, NULL, NULL, NULL, NULL, NULL }},
2509        { X86_VENDOR_NEXGEN,    5,
2510          { "Nx586", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2511            NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
2512        { X86_VENDOR_RISE,      5,
2513          { "iDragon", NULL, "iDragon", NULL, NULL, NULL, NULL,
2514            NULL, "iDragon II", "iDragon II", NULL, NULL, NULL, NULL, NULL, NULL }},
2515        { X86_VENDOR_SIS,       5,
2516          { NULL, NULL, NULL, NULL, "SiS55x", NULL, NULL,
2517            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }},
2518};
2519
2520/* Look up CPU names by table lookup. */
2521static char __init *table_lookup_model(struct cpuinfo_x86 *c)
2522{
2523        struct cpu_model_info *info = cpu_models;
2524        int i;
2525
2526        if ( c->x86_model >= 16 )
2527                return NULL;    /* Range check */
2528
2529        for ( i = 0 ; i < sizeof(cpu_models)/sizeof(struct cpu_model_info) ; i++ ) {
2530                if ( info->vendor == c->x86_vendor &&
2531                     info->family == c->x86 ) {
2532                        return info->model_names[c->x86_model];
2533                }
2534                info++;
2535        }
2536        return NULL;            /* Not found */
2537}
2538
2539/*
2540 *      Detect a NexGen CPU running without BIOS hypercode new enough
2541 *      to have CPUID. (Thanks to Herbert Oppmann)
2542 */
2543 
2544static int __init deep_magic_nexgen_probe(void)
2545{
2546        int ret;
2547        
2548        __asm__ __volatile__ (
2549                "       movw    $0x5555, %%ax\n"
2550                "       xorw    %%dx,%%dx\n"
2551                "       movw    $2, %%cx\n"
2552                "       divw    %%cx\n"
2553                "       movl    $0, %%eax\n"
2554                "       jnz     1f\n"
2555                "       movl    $1, %%eax\n"
2556                "1:\n" 
2557                : "=a" (ret) : : "cx", "dx" );
2558        return  ret;
2559}
2560
2561static void __init squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
2562{
2563        if( test_bit(X86_FEATURE_PN, &c->x86_capability) &&
2564            disable_x86_serial_nr ) {
2565                /* Disable processor serial number */
2566                unsigned long lo,hi;
2567                rdmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
2568                lo |= 0x200000;
2569                wrmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
2570                printk(KERN_NOTICE "CPU serial number disabled.\n");
2571                clear_bit(X86_FEATURE_PN, &c->x86_capability);
2572
2573                /* Disabling the serial number may affect the cpuid level */
2574                c->cpuid_level = cpuid_eax(0);
2575        }
2576}
2577
2578
2579static int __init x86_serial_nr_setup(char *s)
2580{
2581        disable_x86_serial_nr = 0;
2582        return 1;
2583}
2584__setup("serialnumber", x86_serial_nr_setup);
2585
2586static int __init x86_fxsr_setup(char * s)
2587{
2588        set_bit(X86_FEATURE_XMM, disabled_x86_caps); 
2589        set_bit(X86_FEATURE_FXSR, disabled_x86_caps);
2590        return 1;
2591}
2592__setup("nofxsr", x86_fxsr_setup);
2593
2594
2595/* Standard macro to see if a specific flag is changeable */
2596static inline int flag_is_changeable_p(u32 flag)
2597{
2598        u32 f1, f2;
2599
2600        asm("pushfl\n\t"
2601            "pushfl\n\t"
2602            "popl %0\n\t"
2603            "movl %0,%1\n\t"
2604            "xorl %2,%0\n\t"
2605            "pushl %0\n\t"
2606            "popfl\n\t"
2607            "pushfl\n\t"
2608            "popl %0\n\t"
2609            "popfl\n\t"
2610            : "=&r" (f1), "=&r" (f2)
2611            : "ir" (flag));
2612
2613        return ((f1^f2) & flag) != 0;
2614}
2615
2616
2617/* Probe for the CPUID instruction */
2618static int __init have_cpuid_p(void)
2619{
2620        return flag_is_changeable_p(X86_EFLAGS_ID);
2621}
2622
2623/*
2624 * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
2625 * by the fact that they preserve the flags across the division of 5/2.
2626 * PII and PPro exhibit this behavior too, but they have cpuid available.
2627 */
2628 
2629/*
2630 * Perform the Cyrix 5/2 test. A Cyrix won't change
2631 * the flags, while other 486 chips will.
2632 */
2633static inline int test_cyrix_52div(void)
2634{
2635        unsigned int test;
2636
2637        __asm__ __volatile__(
2638             "sahf\n\t"         /* clear flags (%eax = 0x0005) */
2639             "div %b2\n\t"      /* divide 5 by 2 */
2640             "lahf"             /* store flags into %ah */
2641             : "=a" (test)
2642             : "0" (5), "q" (2)
2643             : "cc");
2644
2645        /* AH is 0x02 on Cyrix after the divide.. */
2646        return (unsigned char) (test >> 8) == 0x02;
2647}
2648
2649/* Try to detect a CPU with disabled CPUID, and if so, enable.  This routine
2650   may also be used to detect non-CPUID processors and fill in some of
2651   the information manually. */
2652static int __init id_and_try_enable_cpuid(struct cpuinfo_x86 *c)
2653{
2654        /* First of all, decide if this is a 486 or higher */
2655        /* It's a 486 if we can modify the AC flag */
2656        if ( flag_is_changeable_p(X86_EFLAGS_AC) )
2657                c->x86 = 4;
2658        else
2659                c->x86 = 3;
2660
2661        /* Detect Cyrix with disabled CPUID */
2662        if ( c->x86 == 4 && test_cyrix_52div() ) {
2663                unsigned char dir0, dir1;
2664                
2665                strcpy(c->x86_vendor_id, "CyrixInstead");
2666                c->x86_vendor = X86_VENDOR_CYRIX;
2667                
2668                /* Actually enable cpuid on the older cyrix */
2669            
2670                /* Retrieve CPU revisions */
2671                
2672                do_cyrix_devid(&dir0, &dir1);
2673
2674                dir0>>=4;               
2675                
2676                /* Check it is an affected model */
2677                
2678                if (dir0 == 5 || dir0 == 3)
2679                {
2680                        unsigned char ccr3, ccr4;
2681                        unsigned long flags;
2682                        printk(KERN_INFO "Enabling CPUID on Cyrix processor.\n");
2683                        local_irq_save(flags);
2684                        ccr3 = getCx86(CX86_CCR3);
2685                        setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN  */
2686                        ccr4 = getCx86(CX86_CCR4);
2687                        setCx86(CX86_CCR4, ccr4 | 0x80);          /* enable cpuid  */
2688                        setCx86(CX86_CCR3, ccr3);                 /* disable MAPEN */
2689                        local_irq_restore(flags);
2690                }
2691        } else
2692
2693        /* Detect NexGen with old hypercode */
2694        if ( deep_magic_nexgen_probe() ) {
2695                strcpy(c->x86_vendor_id, "NexGenDriven");
2696        }
2697
2698        return have_cpuid_p();  /* Check to see if CPUID now enabled? */
2699}
2700
2701/*
2702 * This does the hard work of actually picking apart the CPU stuff...
2703 */
2704void __init identify_cpu(struct cpuinfo_x86 *c)
2705{
2706        int junk, i;
2707        u32 xlvl, tfms;
2708
2709        c->loops_per_jiffy = loops_per_jiffy;
2710        c->x86_cache_size = -1;
2711        c->x86_vendor = X86_VENDOR_UNKNOWN;
2712        c->cpuid_level = -1;    /* CPUID not detected */
2713        c->x86_model = c->x86_mask = 0; /* So far unknown... */
2714        c->x86_vendor_id[0] = '\0'; /* Unset */
2715        c->x86_model_id[0] = '\0';  /* Unset */
2716        memset(&c->x86_capability, 0, sizeof c->x86_capability);
2717
2718        if ( !have_cpuid_p() && !id_and_try_enable_cpuid(c) ) {
2719                /* CPU doesn't have CPUID */
2720
2721                /* If there are any capabilities, they're vendor-specific */
2722                /* enable_cpuid() would have set c->x86 for us. */
2723        } else {
2724                /* CPU does have CPUID */
2725
2726                /* Get vendor name */
2727                cpuid(0x00000000, &c->cpuid_level,
2728                      (int *)&c->x86_vendor_id[0],
2729                      (int *)&c->x86_vendor_id[8],
2730                      (int *)&c->x86_vendor_id[4]);
2731                
2732                get_cpu_vendor(c);
2733                /* Initialize the standard set of capabilities */
2734                /* Note that the vendor-specific code below might override */
2735
2736                /* Intel-defined flags: level 0x00000001 */
2737                if ( c->cpuid_level >= 0x00000001 ) {
2738                        cpuid(0x00000001, &tfms, &junk, &junk,
2739                              &c->x86_capability[0]);
2740                        c->x86 = (tfms >> 8) & 15;
2741                        c->x86_model = (tfms >> 4) & 15;
2742                        c->x86_mask = tfms & 15;
2743                } else {
2744                        /* Have CPUID level 0 only - unheard of */
2745                        c->x86 = 4;
2746                }
2747
2748                /* AMD-defined flags: level 0x80000001 */
2749                xlvl = cpuid_eax(0x80000000);
2750                if ( (xlvl & 0xffff0000) == 0x80000000 ) {
2751                        if ( xlvl >= 0x80000001 )
2752                                c->x86_capability[1] = cpuid_edx(0x80000001);
2753                        if ( xlvl >= 0x80000004 )
2754                                get_model_name(c); /* Default name */
2755                }
2756
2757                /* Transmeta-defined flags: level 0x80860001 */
2758                xlvl = cpuid_eax(0x80860000);
2759                if ( (xlvl & 0xffff0000) == 0x80860000 ) {
2760                        if (  xlvl >= 0x80860001 )
2761                                c->x86_capability[2] = cpuid_edx(0x80860001);
2762                }
2763        }
2764
2765        /*
2766         * Vendor-specific initialization.  In this section we
2767         * canonicalize the feature flags, meaning if there are
2768         * features a certain CPU supports which CPUID doesn't
2769         * tell us, CPUID claiming incorrect flags, or other bugs,
2770         * we handle them here.
2771         *
2772         * At the end of this section, c->x86_capability better
2773         * indicate the features this CPU genuinely supports!
2774         */
2775        switch ( c->x86_vendor ) {
2776        case X86_VENDOR_UNKNOWN:
2777        default:
2778                /* Not much we can do here... */
2779                /* Check if at least it has cpuid */
2780                if (c->cpuid_level == -1)
2781                {
2782                        /* No cpuid. It must be an ancient CPU */
2783                        if (c->x86 == 4)
2784                                strcpy(c->x86_model_id, "486");
2785                        else if (c->x86 == 3)
2786                                strcpy(c->x86_model_id, "386");
2787                }
2788                break;
2789
2790        case X86_VENDOR_CYRIX:
2791                init_cyrix(c);
2792                break;
2793
2794        case X86_VENDOR_NSC:
2795                init_cyrix(c);
2796                break;
2797
2798        case X86_VENDOR_AMD:
2799                init_amd(c);
2800                break;
2801
2802        case X86_VENDOR_CENTAUR:
2803                init_centaur(c);
2804                break;
2805
2806        case X86_VENDOR_INTEL:
2807                init_intel(c);
2808                break;
2809
2810        case X86_VENDOR_NEXGEN:
2811                c->x86_cache_size = 256; /* A few had 1 MB... */
2812                break;
2813
2814        case X86_VENDOR_TRANSMETA:
2815                init_transmeta(c);
2816                break;
2817
2818        case X86_VENDOR_RISE:
2819                init_rise(c);
2820                break;
2821        }
2822
2823        /*
2824         * The vendor-specific functions might have changed features.  Now
2825         * we do "generic changes."
2826         */
2827
2828        /* TSC disabled? */
2829#ifndef CONFIG_X86_TSC
2830        if ( tsc_disable )
2831                clear_bit(X86_FEATURE_TSC, &c->x86_capability);
2832#endif
2833
2834        /* check for caps that have been disabled earlier */ 
2835        for (i = 0; i < NCAPINTS; i++) { 
2836             c->x86_capability[i] &= ~disabled_x86_caps[i];
2837        }
2838
2839        /* Disable the PN if appropriate */
2840        squash_the_stupid_serial_number(c);
2841
2842        /* Init Machine Check Exception if available. */
2843        mcheck_init(c);
2844
2845        /* If the model name is still unset, do table lookup. */
2846        if ( !c->x86_model_id[0] ) {
2847                char *p;
2848                p = table_lookup_model(c);
2849                if ( p )
2850                        strcpy(c->x86_model_id, p);
2851                else
2852                        /* Last resort... */
2853                        sprintf(c->x86_model_id, "%02x/%02x",
2854                                c->x86_vendor, c->x86_model);
2855        }
2856
2857        /* Now the feature flags better reflect actual CPU features! */
2858
2859        printk(KERN_DEBUG "CPU:     After generic, caps: %08x %08x %08x %08x\n",
2860               c->x86_capability[0],
2861               c->x86_capability[1],
2862               c->x86_capability[2],
2863               c->x86_capability[3]);
2864
2865        /*
2866         * On SMP, boot_cpu_data holds the common feature set between
2867         * all CPUs; so make sure that we indicate which features are
2868         * common between the CPUs.  The first time this routine gets
2869         * executed, c == &boot_cpu_data.
2870         */
2871        if ( c != &boot_cpu_data ) {
2872                /* AND the already accumulated flags with these */
2873                for ( i = 0 ; i < NCAPINTS ; i++ )
2874                        boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
2875        }
2876
2877        printk(KERN_DEBUG "CPU:             Common caps: %08x %08x %08x %08x\n",
2878               boot_cpu_data.x86_capability[0],
2879               boot_cpu_data.x86_capability[1],
2880               boot_cpu_data.x86_capability[2],
2881               boot_cpu_data.x86_capability[3]);
2882}
2883/*
2884 *      Perform early boot up checks for a valid TSC. See arch/i386/kernel/time.c
2885 */
2886 
2887void __init dodgy_tsc(void)
2888{
2889        get_cpu_vendor(&boot_cpu_data);
2890
2891        if ( boot_cpu_data.x86_vendor == X86_VENDOR_CYRIX ||
2892             boot_cpu_data.x86_vendor == X86_VENDOR_NSC )
2893                init_cyrix(&boot_cpu_data);
2894}
2895
2896
2897/* These need to match <asm/processor.h> */
2898static char *cpu_vendor_names[] __initdata = {
2899        "Intel", "Cyrix", "AMD", "UMC", "NexGen", 
2900        "Centaur", "Rise", "Transmeta", "NSC"
2901};
2902
2903
2904void __init print_cpu_info(struct cpuinfo_x86 *c)
2905{
2906        char *vendor = NULL;
2907
2908        if (c->x86_vendor < sizeof(cpu_vendor_names)/sizeof(char *))
2909                vendor = cpu_vendor_names[c->x86_vendor];
2910        else if (c->cpuid_level >= 0)
2911                vendor = c->x86_vendor_id;
2912
2913        if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor)))
2914                printk("%s ", vendor);
2915
2916        if (!c->x86_model_id[0])
2917                printk("%d86", c->x86);
2918        else
2919                printk("%s", c->x86_model_id);
2920
2921        if (c->x86_mask || c->cpuid_level >= 0) 
2922                printk(" stepping %02x\n", c->x86_mask);
2923        else
2924                printk("\n");
2925}
2926
2927/*
2928 *      Get CPU information for use by the procfs.
2929 */
2930static int show_cpuinfo(struct seq_file *m, void *v)
2931{
2932        /* 
2933         * These flag bits must match the definitions in <asm/cpufeature.h>.
2934         * NULL means this bit is undefined or reserved; either way it doesn't
2935         * have meaning as far as Linux is concerned.  Note that it's important
2936         * to realize there is a difference between this table and CPUID -- if
2937         * applications want to get the raw CPUID data, they should access
2938         * /dev/cpu/<cpu_nr>/cpuid instead.
2939         */
2940        static char *x86_cap_flags[] = {
2941                /* Intel-defined */
2942                "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
2943                "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
2944                "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
2945                "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
2946
2947                /* AMD-defined */
2948                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2949                NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
2950                NULL, NULL, NULL, NULL, NULL, NULL, "mmxext", NULL,
2951                NULL, NULL, NULL, NULL, NULL, "lm", "3dnowext", "3dnow",
2952
2953                /* Transmeta-defined */
2954                "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
2955                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2956                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2957                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2958
2959                /* Other (Linux-defined) */
2960                "cxmmx", "k6_mtrr", "cyrix_arr", "centaur_mcr", NULL, NULL, NULL, NULL,
2961                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2962                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2963                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2964        };
2965        struct cpuinfo_x86 *c = v;
2966        int i, n = c - cpu_data;
2967        int fpu_exception;
2968
2969#ifdef CONFIG_SMP
2970        if (!(cpu_online_map & (1<<n)))
2971                return 0;
2972#endif
2973        seq_printf(m, "processor\t: %d\n"
2974                "vendor_id\t: %s\n"
2975                "cpu family\t: %d\n"
2976                "model\t\t: %d\n"
2977                "model name\t: %s\n",
2978                n,
2979                c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
2980                c->x86,
2981                c->x86_model,
2982                c->x86_model_id[0] ? c->x86_model_id : "unknown");
2983
2984        if (c->x86_mask || c->cpuid_level >= 0)
2985                seq_printf(m, "stepping\t: %d\n", c->x86_mask);
2986        else
2987                seq_printf(m, "stepping\t: unknown\n");
2988
2989        if ( test_bit(X86_FEATURE_TSC, &c->x86_capability) ) {
2990                seq_printf(m, "cpu MHz\t\t: %lu.%03lu\n",
2991                        cpu_khz / 1000, (cpu_khz % 1000));
2992        }
2993
2994        /* Cache size */
2995        if (c->x86_cache_size >= 0)
2996                seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
2997        
2998        /* We use exception 16 if we have hardware math and we've either seen it or the CPU claims it is internal */
2999        fpu_exception = c->hard_math && (ignore_irq13 || cpu_has_fpu);
3000        seq_printf(m, "fdiv_bug\t: %s\n"
3001                        "hlt_bug\t\t: %s\n"
3002                        "f00f_bug\t: %s\n"
3003                        "coma_bug\t: %s\n"
3004                        "fpu\t\t: %s\n"
3005                        "fpu_exception\t: %s\n"
3006                        "cpuid level\t: %d\n"
3007                        "wp\t\t: %s\n"
3008                        "flags\t\t:",
3009                     c->fdiv_bug ? "yes" : "no",
3010                     c->hlt_works_ok ? "no" : "yes",
3011                     c->f00f_bug ? "yes" : "no",
3012                     c->coma_bug ? "yes" : "no",
3013                     c->hard_math ? "yes" : "no",
3014                     fpu_exception ? "yes" : "no",
3015                     c->cpuid_level,
3016                     c->wp_works_ok ? "yes" : "no");
3017
3018        for ( i = 0 ; i < 32*NCAPINTS ; i++ )
3019                if ( test_bit(i, &c->x86_capability) &&
3020                     x86_cap_flags[i] != NULL )
3021                        seq_printf(m, " %s", x86_cap_flags[i]);
3022
3023        seq_printf(m, "\nbogomips\t: %lu.%02lu\n\n",
3024                     c->loops_per_jiffy/(500000/HZ),
3025                     (c->loops_per_jiffy/(5000/HZ)) % 100);
3026        return 0;
3027}
3028
3029static void *c_start(struct seq_file *m, loff_t *pos)
3030{
3031        return *pos < NR_CPUS ? cpu_data + *pos : NULL;
3032}
3033static void *c_next(struct seq_file *m, void *v, loff_t *pos)
3034{
3035        ++*pos;
3036        return c_start(m, pos);
3037}
3038static void c_stop(struct seq_file *m, void *v)
3039{
3040}
3041struct seq_operations cpuinfo_op = {
3042        start:  c_start,
3043        next:   c_next,
3044        stop:   c_stop,
3045        show:   show_cpuinfo,
3046};
3047
3048unsigned long cpu_initialized __initdata = 0;
3049
3050/*
3051 * cpu_init() initializes state that is per-CPU. Some data is already
3052 * initialized (naturally) in the bootstrap process, such as the GDT
3053 * and IDT. We reload them nevertheless, this function acts as a
3054 * 'CPU state barrier', nothing should get across.
3055 */
3056void __init cpu_init (void)
3057{
3058        int nr = smp_processor_id();
3059        struct tss_struct * t = &init_tss[nr];
3060
3061        if (test_and_set_bit(nr, &cpu_initialized)) {
3062                printk(KERN_WARNING "CPU#%d already initialized!\n", nr);
3063                for (;;) __sti();
3064        }
3065        printk(KERN_INFO "Initializing CPU#%d\n", nr);
3066
3067        if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
3068                clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
3069#ifndef CONFIG_X86_TSC
3070        if (tsc_disable && cpu_has_tsc) {
3071                printk(KERN_NOTICE "Disabling TSC...\n");
3072                /**** FIX-HPA: DOES THIS REALLY BELONG HERE? ****/
3073                clear_bit(X86_FEATURE_TSC, boot_cpu_data.x86_capability);
3074                set_in_cr4(X86_CR4_TSD);
3075        }
3076#endif
3077
3078        __asm__ __volatile__("lgdt %0": "=m" (gdt_descr));
3079        __asm__ __volatile__("lidt %0": "=m" (idt_descr));
3080
3081        /*
3082         * Delete NT
3083         */
3084        __asm__("pushfl ; andl $0xffffbfff,(%esp) ; popfl");
3085
3086        /*
3087         * set up and load the per-CPU TSS and LDT
3088         */
3089        atomic_inc(&init_mm.mm_count);
3090        current->active_mm = &init_mm;
3091        if(current->mm)
3092                BUG();
3093        enter_lazy_tlb(&init_mm, current, nr);
3094
3095        t->esp0 = current->thread.esp0;
3096        set_tss_desc(nr,t);
3097        gdt_table[__TSS(nr)].b &= 0xfffffdff;
3098        load_TR(nr);
3099        load_LDT(&init_mm);
3100
3101        /*
3102         * Clear all 6 debug registers:
3103         */
3104
3105#define CD(register) __asm__("movl %0,%%db" #register ::"r"(0) );
3106
3107        CD(0); CD(1); CD(2); CD(3); /* no db4 and db5 */; CD(6); CD(7);
3108
3109#undef CD
3110
3111        /*
3112         * Force FPU initialization:
3113         */
3114        current->flags &= ~PF_USEDFPU;
3115        current->used_math = 0;
3116        stts();
3117}
3118
3119/*
3120 *      Early probe support logic for ppro memory erratum #50
3121 *
3122 *      This is called before we do cpu ident work
3123 */
3124 
3125int __init ppro_with_ram_bug(void)
3126{
3127        char vendor_id[16];
3128        int ident;
3129
3130        /* Must have CPUID */
3131        if(!have_cpuid_p())
3132                return 0;
3133        if(cpuid_eax(0)<1)
3134                return 0;
3135        
3136        /* Must be Intel */
3137        cpuid(0, &ident, 
3138                (int *)&vendor_id[0],
3139                (int *)&vendor_id[8],
3140                (int *)&vendor_id[4]);
3141        
3142        if(memcmp(vendor_id, "IntelInside", 12))
3143                return 0;
3144        
3145        ident = cpuid_eax(1);
3146
3147        /* Model 6 */
3148
3149        if(((ident>>8)&15)!=6)
3150                return 0;
3151        
3152        /* Pentium Pro */
3153
3154        if(((ident>>4)&15)!=1)
3155                return 0;
3156        
3157        if((ident&15) < 8)
3158        {
3159                printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
3160                return 1;
3161        }
3162        printk(KERN_INFO "Your Pentium Pro seems ok.\n");
3163        return 0;
3164}
3165        
3166/*
3167 * Local Variables:
3168 * mode:c
3169 * c-file-style:"k&r"
3170 * c-basic-offset:8
3171 * End:
3172 */
3173
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.