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