linux/arch/alpha/kernel/setup.c
<<
>>
Prefs
   1/*
   2 *  linux/arch/alpha/kernel/setup.c
   3 *
   4 *  Copyright (C) 1995  Linus Torvalds
   5 */
   6
   7/* 2.3.x bootmem, 1999 Andrea Arcangeli <andrea@suse.de> */
   8
   9/*
  10 * Bootup setup stuff.
  11 */
  12
  13#include <linux/sched.h>
  14#include <linux/kernel.h>
  15#include <linux/mm.h>
  16#include <linux/stddef.h>
  17#include <linux/unistd.h>
  18#include <linux/ptrace.h>
  19#include <linux/slab.h>
  20#include <linux/user.h>
  21#include <linux/a.out.h>
  22#include <linux/screen_info.h>
  23#include <linux/delay.h>
  24#include <linux/mc146818rtc.h>
  25#include <linux/console.h>
  26#include <linux/cpu.h>
  27#include <linux/errno.h>
  28#include <linux/init.h>
  29#include <linux/string.h>
  30#include <linux/ioport.h>
  31#include <linux/platform_device.h>
  32#include <linux/bootmem.h>
  33#include <linux/pci.h>
  34#include <linux/seq_file.h>
  35#include <linux/root_dev.h>
  36#include <linux/initrd.h>
  37#include <linux/eisa.h>
  38#include <linux/pfn.h>
  39#ifdef CONFIG_MAGIC_SYSRQ
  40#include <linux/sysrq.h>
  41#include <linux/reboot.h>
  42#endif
  43#include <linux/notifier.h>
  44#include <asm/setup.h>
  45#include <asm/io.h>
  46#include <linux/log2.h>
  47
  48extern struct atomic_notifier_head panic_notifier_list;
  49static int alpha_panic_event(struct notifier_block *, unsigned long, void *);
  50static struct notifier_block alpha_panic_block = {
  51        alpha_panic_event,
  52        NULL,
  53        INT_MAX /* try to do it first */
  54};
  55
  56#include <asm/uaccess.h>
  57#include <asm/pgtable.h>
  58#include <asm/system.h>
  59#include <asm/hwrpb.h>
  60#include <asm/dma.h>
  61#include <asm/io.h>
  62#include <asm/mmu_context.h>
  63#include <asm/console.h>
  64
  65#include "proto.h"
  66#include "pci_impl.h"
  67
  68
  69struct hwrpb_struct *hwrpb;
  70EXPORT_SYMBOL(hwrpb);
  71unsigned long srm_hae;
  72
  73int alpha_l1i_cacheshape;
  74int alpha_l1d_cacheshape;
  75int alpha_l2_cacheshape;
  76int alpha_l3_cacheshape;
  77
  78#ifdef CONFIG_VERBOSE_MCHECK
  79/* 0=minimum, 1=verbose, 2=all */
  80/* These can be overridden via the command line, ie "verbose_mcheck=2") */
  81unsigned long alpha_verbose_mcheck = CONFIG_VERBOSE_MCHECK_ON;
  82#endif
  83
  84/* Which processor we booted from.  */
  85int boot_cpuid;
  86
  87/*
  88 * Using SRM callbacks for initial console output. This works from
  89 * setup_arch() time through the end of time_init(), as those places
  90 * are under our (Alpha) control.
  91
  92 * "srmcons" specified in the boot command arguments allows us to
  93 * see kernel messages during the period of time before the true
  94 * console device is "registered" during console_init(). 
  95 * As of this version (2.5.59), console_init() will call
  96 * disable_early_printk() as the last action before initializing
  97 * the console drivers. That's the last possible time srmcons can be 
  98 * unregistered without interfering with console behavior.
  99 *
 100 * By default, OFF; set it with a bootcommand arg of "srmcons" or 
 101 * "console=srm". The meaning of these two args is:
 102 *     "srmcons"     - early callback prints 
 103 *     "console=srm" - full callback based console, including early prints
 104 */
 105int srmcons_output = 0;
 106
 107/* Enforce a memory size limit; useful for testing. By default, none. */
 108unsigned long mem_size_limit = 0;
 109
 110/* Set AGP GART window size (0 means disabled). */
 111unsigned long alpha_agpgart_size = DEFAULT_AGP_APER_SIZE;
 112
 113#ifdef CONFIG_ALPHA_GENERIC
 114struct alpha_machine_vector alpha_mv;
 115int alpha_using_srm;
 116EXPORT_SYMBOL(alpha_using_srm);
 117#endif
 118
 119static struct alpha_machine_vector *get_sysvec(unsigned long, unsigned long,
 120                                               unsigned long);
 121static struct alpha_machine_vector *get_sysvec_byname(const char *);
 122static void get_sysnames(unsigned long, unsigned long, unsigned long,
 123                         char **, char **);
 124static void determine_cpu_caches (unsigned int);
 125
 126static char __initdata command_line[COMMAND_LINE_SIZE];
 127
 128/*
 129 * The format of "screen_info" is strange, and due to early
 130 * i386-setup code. This is just enough to make the console
 131 * code think we're on a VGA color display.
 132 */
 133
 134struct screen_info screen_info = {
 135        .orig_x = 0,
 136        .orig_y = 25,
 137        .orig_video_cols = 80,
 138        .orig_video_lines = 25,
 139        .orig_video_isVGA = 1,
 140        .orig_video_points = 16
 141};
 142
 143EXPORT_SYMBOL(screen_info);
 144
 145/*
 146 * The direct map I/O window, if any.  This should be the same
 147 * for all busses, since it's used by virt_to_bus.
 148 */
 149
 150unsigned long __direct_map_base;
 151unsigned long __direct_map_size;
 152EXPORT_SYMBOL(__direct_map_base);
 153EXPORT_SYMBOL(__direct_map_size);
 154
 155/*
 156 * Declare all of the machine vectors.
 157 */
 158
 159/* GCC 2.7.2 (on alpha at least) is lame.  It does not support either 
 160   __attribute__((weak)) or #pragma weak.  Bypass it and talk directly
 161   to the assembler.  */
 162
 163#define WEAK(X) \
 164        extern struct alpha_machine_vector X; \
 165        asm(".weak "#X)
 166
 167WEAK(alcor_mv);
 168WEAK(alphabook1_mv);
 169WEAK(avanti_mv);
 170WEAK(cabriolet_mv);
 171WEAK(clipper_mv);
 172WEAK(dp264_mv);
 173WEAK(eb164_mv);
 174WEAK(eb64p_mv);
 175WEAK(eb66_mv);
 176WEAK(eb66p_mv);
 177WEAK(eiger_mv);
 178WEAK(jensen_mv);
 179WEAK(lx164_mv);
 180WEAK(lynx_mv);
 181WEAK(marvel_ev7_mv);
 182WEAK(miata_mv);
 183WEAK(mikasa_mv);
 184WEAK(mikasa_primo_mv);
 185WEAK(monet_mv);
 186WEAK(nautilus_mv);
 187WEAK(noname_mv);
 188WEAK(noritake_mv);
 189WEAK(noritake_primo_mv);
 190WEAK(p2k_mv);
 191WEAK(pc164_mv);
 192WEAK(privateer_mv);
 193WEAK(rawhide_mv);
 194WEAK(ruffian_mv);
 195WEAK(rx164_mv);
 196WEAK(sable_mv);
 197WEAK(sable_gamma_mv);
 198WEAK(shark_mv);
 199WEAK(sx164_mv);
 200WEAK(takara_mv);
 201WEAK(titan_mv);
 202WEAK(webbrick_mv);
 203WEAK(wildfire_mv);
 204WEAK(xl_mv);
 205WEAK(xlt_mv);
 206
 207#undef WEAK
 208
 209/*
 210 * I/O resources inherited from PeeCees.  Except for perhaps the
 211 * turbochannel alphas, everyone has these on some sort of SuperIO chip.
 212 *
 213 * ??? If this becomes less standard, move the struct out into the
 214 * machine vector.
 215 */
 216
 217static void __init
 218reserve_std_resources(void)
 219{
 220        static struct resource standard_io_resources[] = {
 221                { .name = "rtc", .start = -1, .end = -1 },
 222                { .name = "dma1", .start = 0x00, .end = 0x1f },
 223                { .name = "pic1", .start = 0x20, .end = 0x3f },
 224                { .name = "timer", .start = 0x40, .end = 0x5f },
 225                { .name = "keyboard", .start = 0x60, .end = 0x6f },
 226                { .name = "dma page reg", .start = 0x80, .end = 0x8f },
 227                { .name = "pic2", .start = 0xa0, .end = 0xbf },
 228                { .name = "dma2", .start = 0xc0, .end = 0xdf },
 229        };
 230
 231        struct resource *io = &ioport_resource;
 232        size_t i;
 233
 234        if (hose_head) {
 235                struct pci_controller *hose;
 236                for (hose = hose_head; hose; hose = hose->next)
 237                        if (hose->index == 0) {
 238                                io = hose->io_space;
 239                                break;
 240                        }
 241        }
 242
 243        /* Fix up for the Jensen's queer RTC placement.  */
 244        standard_io_resources[0].start = RTC_PORT(0);
 245        standard_io_resources[0].end = RTC_PORT(0) + 0x10;
 246
 247        for (i = 0; i < ARRAY_SIZE(standard_io_resources); ++i)
 248                request_resource(io, standard_io_resources+i);
 249}
 250
 251#define PFN_MAX         PFN_DOWN(0x80000000)
 252#define for_each_mem_cluster(memdesc, cluster, i)               \
 253        for ((cluster) = (memdesc)->cluster, (i) = 0;           \
 254             (i) < (memdesc)->numclusters; (i)++, (cluster)++)
 255
 256static unsigned long __init
 257get_mem_size_limit(char *s)
 258{
 259        unsigned long end = 0;
 260        char *from = s;
 261
 262        end = simple_strtoul(from, &from, 0);
 263        if ( *from == 'K' || *from == 'k' ) {
 264                end = end << 10;
 265                from++;
 266        } else if ( *from == 'M' || *from == 'm' ) {
 267                end = end << 20;
 268                from++;
 269        } else if ( *from == 'G' || *from == 'g' ) {
 270                end = end << 30;
 271                from++;
 272        }
 273        return end >> PAGE_SHIFT; /* Return the PFN of the limit. */
 274}
 275
 276#ifdef CONFIG_BLK_DEV_INITRD
 277void * __init
 278move_initrd(unsigned long mem_limit)
 279{
 280        void *start;
 281        unsigned long size;
 282
 283        size = initrd_end - initrd_start;
 284        start = __alloc_bootmem(PAGE_ALIGN(size), PAGE_SIZE, 0);
 285        if (!start || __pa(start) + size > mem_limit) {
 286                initrd_start = initrd_end = 0;
 287                return NULL;
 288        }
 289        memmove(start, (void *)initrd_start, size);
 290        initrd_start = (unsigned long)start;
 291        initrd_end = initrd_start + size;
 292        printk("initrd moved to %p\n", start);
 293        return start;
 294}
 295#endif
 296
 297#ifndef CONFIG_DISCONTIGMEM
 298static void __init
 299setup_memory(void *kernel_end)
 300{
 301        struct memclust_struct * cluster;
 302        struct memdesc_struct * memdesc;
 303        unsigned long start_kernel_pfn, end_kernel_pfn;
 304        unsigned long bootmap_size, bootmap_pages, bootmap_start;
 305        unsigned long start, end;
 306        unsigned long i;
 307
 308        /* Find free clusters, and init and free the bootmem accordingly.  */
 309        memdesc = (struct memdesc_struct *)
 310          (hwrpb->mddt_offset + (unsigned long) hwrpb);
 311
 312        for_each_mem_cluster(memdesc, cluster, i) {
 313                printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
 314                       i, cluster->usage, cluster->start_pfn,
 315                       cluster->start_pfn + cluster->numpages);
 316
 317                /* Bit 0 is console/PALcode reserved.  Bit 1 is
 318                   non-volatile memory -- we might want to mark
 319                   this for later.  */
 320                if (cluster->usage & 3)
 321                        continue;
 322
 323                end = cluster->start_pfn + cluster->numpages;
 324                if (end > max_low_pfn)
 325                        max_low_pfn = end;
 326        }
 327
 328        /*
 329         * Except for the NUMA systems (wildfire, marvel) all of the 
 330         * Alpha systems we run on support 32GB of memory or less.
 331         * Since the NUMA systems introduce large holes in memory addressing,
 332         * we can get into a situation where there is not enough contiguous
 333         * memory for the memory map. 
 334         *
 335         * Limit memory to the first 32GB to limit the NUMA systems to 
 336         * memory on their first node (wildfire) or 2 (marvel) to avoid 
 337         * not being able to produce the memory map. In order to access 
 338         * all of the memory on the NUMA systems, build with discontiguous
 339         * memory support.
 340         *
 341         * If the user specified a memory limit, let that memory limit stand.
 342         */
 343        if (!mem_size_limit) 
 344                mem_size_limit = (32ul * 1024 * 1024 * 1024) >> PAGE_SHIFT;
 345
 346        if (mem_size_limit && max_low_pfn >= mem_size_limit)
 347        {
 348                printk("setup: forcing memory size to %ldK (from %ldK).\n",
 349                       mem_size_limit << (PAGE_SHIFT - 10),
 350                       max_low_pfn    << (PAGE_SHIFT - 10));
 351                max_low_pfn = mem_size_limit;
 352        }
 353
 354        /* Find the bounds of kernel memory.  */
 355        start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
 356        end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
 357        bootmap_start = -1;
 358
 359 try_again:
 360        if (max_low_pfn <= end_kernel_pfn)
 361                panic("not enough memory to boot");
 362
 363        /* We need to know how many physically contiguous pages
 364           we'll need for the bootmap.  */
 365        bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
 366
 367        /* Now find a good region where to allocate the bootmap.  */
 368        for_each_mem_cluster(memdesc, cluster, i) {
 369                if (cluster->usage & 3)
 370                        continue;
 371
 372                start = cluster->start_pfn;
 373                end = start + cluster->numpages;
 374                if (start >= max_low_pfn)
 375                        continue;
 376                if (end > max_low_pfn)
 377                        end = max_low_pfn;
 378                if (start < start_kernel_pfn) {
 379                        if (end > end_kernel_pfn
 380                            && end - end_kernel_pfn >= bootmap_pages) {
 381                                bootmap_start = end_kernel_pfn;
 382                                break;
 383                        } else if (end > start_kernel_pfn)
 384                                end = start_kernel_pfn;
 385                } else if (start < end_kernel_pfn)
 386                        start = end_kernel_pfn;
 387                if (end - start >= bootmap_pages) {
 388                        bootmap_start = start;
 389                        break;
 390                }
 391        }
 392
 393        if (bootmap_start == ~0UL) {
 394                max_low_pfn >>= 1;
 395                goto try_again;
 396        }
 397
 398        /* Allocate the bootmap and mark the whole MM as reserved.  */
 399        bootmap_size = init_bootmem(bootmap_start, max_low_pfn);
 400
 401        /* Mark the free regions.  */
 402        for_each_mem_cluster(memdesc, cluster, i) {
 403                if (cluster->usage & 3)
 404                        continue;
 405
 406                start = cluster->start_pfn;
 407                end = cluster->start_pfn + cluster->numpages;
 408                if (start >= max_low_pfn)
 409                        continue;
 410                if (end > max_low_pfn)
 411                        end = max_low_pfn;
 412                if (start < start_kernel_pfn) {
 413                        if (end > end_kernel_pfn) {
 414                                free_bootmem(PFN_PHYS(start),
 415                                             (PFN_PHYS(start_kernel_pfn)
 416                                              - PFN_PHYS(start)));
 417                                printk("freeing pages %ld:%ld\n",
 418                                       start, start_kernel_pfn);
 419                                start = end_kernel_pfn;
 420                        } else if (end > start_kernel_pfn)
 421                                end = start_kernel_pfn;
 422                } else if (start < end_kernel_pfn)
 423                        start = end_kernel_pfn;
 424                if (start >= end)
 425                        continue;
 426
 427                free_bootmem(PFN_PHYS(start), PFN_PHYS(end) - PFN_PHYS(start));
 428                printk("freeing pages %ld:%ld\n", start, end);
 429        }
 430
 431        /* Reserve the bootmap memory.  */
 432        reserve_bootmem(PFN_PHYS(bootmap_start), bootmap_size);
 433        printk("reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));
 434
 435#ifdef CONFIG_BLK_DEV_INITRD
 436        initrd_start = INITRD_START;
 437        if (initrd_start) {
 438                initrd_end = initrd_start+INITRD_SIZE;
 439                printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
 440                       (void *) initrd_start, INITRD_SIZE);
 441
 442                if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
 443                        if (!move_initrd(PFN_PHYS(max_low_pfn)))
 444                                printk("initrd extends beyond end of memory "
 445                                       "(0x%08lx > 0x%p)\ndisabling initrd\n",
 446                                       initrd_end,
 447                                       phys_to_virt(PFN_PHYS(max_low_pfn)));
 448                } else {
 449                        reserve_bootmem(virt_to_phys((void *)initrd_start),
 450                                        INITRD_SIZE);
 451                }
 452        }
 453#endif /* CONFIG_BLK_DEV_INITRD */
 454}
 455#else
 456extern void setup_memory(void *);
 457#endif /* !CONFIG_DISCONTIGMEM */
 458
 459int __init
 460page_is_ram(unsigned long pfn)
 461{
 462        struct memclust_struct * cluster;
 463        struct memdesc_struct * memdesc;
 464        unsigned long i;
 465
 466        memdesc = (struct memdesc_struct *)
 467                (hwrpb->mddt_offset + (unsigned long) hwrpb);
 468        for_each_mem_cluster(memdesc, cluster, i)
 469        {
 470                if (pfn >= cluster->start_pfn  &&
 471                    pfn < cluster->start_pfn + cluster->numpages) {
 472                        return (cluster->usage & 3) ? 0 : 1;
 473                }
 474        }
 475
 476        return 0;
 477}
 478
 479static int __init
 480register_cpus(void)
 481{
 482        int i;
 483
 484        for_each_possible_cpu(i) {
 485                struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
 486                if (!p)
 487                        return -ENOMEM;
 488                register_cpu(p, i);
 489        }
 490        return 0;
 491}
 492
 493arch_initcall(register_cpus);
 494
 495void __init
 496setup_arch(char **cmdline_p)
 497{
 498        extern char _end[];
 499
 500        struct alpha_machine_vector *vec = NULL;
 501        struct percpu_struct *cpu;
 502        char *type_name, *var_name, *p;
 503        void *kernel_end = _end; /* end of kernel */
 504        char *args = command_line;
 505
 506        hwrpb = (struct hwrpb_struct*) __va(INIT_HWRPB->phys_addr);
 507        boot_cpuid = hard_smp_processor_id();
 508
 509        /*
 510         * Pre-process the system type to make sure it will be valid.
 511         *
 512         * This may restore real CABRIO and EB66+ family names, ie
 513         * EB64+ and EB66.
 514         *
 515         * Oh, and "white box" AS800 (aka DIGITAL Server 3000 series)
 516         * and AS1200 (DIGITAL Server 5000 series) have the type as
 517         * the negative of the real one.
 518         */
 519        if ((long)hwrpb->sys_type < 0) {
 520                hwrpb->sys_type = -((long)hwrpb->sys_type);
 521                hwrpb_update_checksum(hwrpb);
 522        }
 523
 524        /* Register a call for panic conditions. */
 525        atomic_notifier_chain_register(&panic_notifier_list,
 526                        &alpha_panic_block);
 527
 528#ifdef CONFIG_ALPHA_GENERIC
 529        /* Assume that we've booted from SRM if we haven't booted from MILO.
 530           Detect the later by looking for "MILO" in the system serial nr.  */
 531        alpha_using_srm = strncmp((const char *)hwrpb->ssn, "MILO", 4) != 0;
 532#endif
 533
 534        /* If we are using SRM, we want to allow callbacks
 535           as early as possible, so do this NOW, and then
 536           they should work immediately thereafter.
 537        */
 538        kernel_end = callback_init(kernel_end);
 539
 540        /* 
 541         * Locate the command line.
 542         */
 543        /* Hack for Jensen... since we're restricted to 8 or 16 chars for
 544           boot flags depending on the boot mode, we need some shorthand.
 545           This should do for installation.  */
 546        if (strcmp(COMMAND_LINE, "INSTALL") == 0) {
 547                strlcpy(command_line, "root=/dev/fd0 load_ramdisk=1", sizeof command_line);
 548        } else {
 549                strlcpy(command_line, COMMAND_LINE, sizeof command_line);
 550        }
 551        strcpy(boot_command_line, command_line);
 552        *cmdline_p = command_line;
 553
 554        /* 
 555         * Process command-line arguments.
 556         */
 557        while ((p = strsep(&args, " \t")) != NULL) {
 558                if (!*p) continue;
 559                if (strncmp(p, "alpha_mv=", 9) == 0) {
 560                        vec = get_sysvec_byname(p+9);
 561                        continue;
 562                }
 563                if (strncmp(p, "cycle=", 6) == 0) {
 564                        est_cycle_freq = simple_strtol(p+6, NULL, 0);
 565                        continue;
 566                }
 567                if (strncmp(p, "mem=", 4) == 0) {
 568                        mem_size_limit = get_mem_size_limit(p+4);
 569                        continue;
 570                }
 571                if (strncmp(p, "srmcons", 7) == 0) {
 572                        srmcons_output |= 1;
 573                        continue;
 574                }
 575                if (strncmp(p, "console=srm", 11) == 0) {
 576                        srmcons_output |= 2;
 577                        continue;
 578                }
 579                if (strncmp(p, "gartsize=", 9) == 0) {
 580                        alpha_agpgart_size =
 581                                get_mem_size_limit(p+9) << PAGE_SHIFT;
 582                        continue;
 583                }
 584#ifdef CONFIG_VERBOSE_MCHECK
 585                if (strncmp(p, "verbose_mcheck=", 15) == 0) {
 586                        alpha_verbose_mcheck = simple_strtol(p+15, NULL, 0);
 587                        continue;
 588                }
 589#endif
 590        }
 591
 592        /* Replace the command line, now that we've killed it with strsep.  */
 593        strcpy(command_line, boot_command_line);
 594
 595        /* If we want SRM console printk echoing early, do it now. */
 596        if (alpha_using_srm && srmcons_output) {
 597                register_srm_console();
 598
 599                /*
 600                 * If "console=srm" was specified, clear the srmcons_output
 601                 * flag now so that time.c won't unregister_srm_console
 602                 */
 603                if (srmcons_output & 2)
 604                        srmcons_output = 0;
 605        }
 606
 607#ifdef CONFIG_MAGIC_SYSRQ
 608        /* If we're using SRM, make sysrq-b halt back to the prom,
 609           not auto-reboot.  */
 610        if (alpha_using_srm) {
 611                struct sysrq_key_op *op = __sysrq_get_key_op('b');
 612                op->handler = (void *) machine_halt;
 613        }
 614#endif
 615
 616        /*
 617         * Identify and reconfigure for the current system.
 618         */
 619        cpu = (struct percpu_struct*)((char*)hwrpb + hwrpb->processor_offset);
 620
 621        get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,
 622                     cpu->type, &type_name, &var_name);
 623        if (*var_name == '0')
 624                var_name = "";
 625
 626        if (!vec) {
 627                vec = get_sysvec(hwrpb->sys_type, hwrpb->sys_variation,
 628                                 cpu->type);
 629        }
 630
 631        if (!vec) {
 632                panic("Unsupported system type: %s%s%s (%ld %ld)\n",
 633                      type_name, (*var_name ? " variation " : ""), var_name,
 634                      hwrpb->sys_type, hwrpb->sys_variation);
 635        }
 636        if (vec != &alpha_mv) {
 637                alpha_mv = *vec;
 638        }
 639        
 640        printk("Booting "
 641#ifdef CONFIG_ALPHA_GENERIC
 642               "GENERIC "
 643#endif
 644               "on %s%s%s using machine vector %s from %s\n",
 645               type_name, (*var_name ? " variation " : ""),
 646               var_name, alpha_mv.vector_name,
 647               (alpha_using_srm ? "SRM" : "MILO"));
 648
 649        printk("Major Options: "
 650#ifdef CONFIG_SMP
 651               "SMP "
 652#endif
 653#ifdef CONFIG_ALPHA_EV56
 654               "EV56 "
 655#endif
 656#ifdef CONFIG_ALPHA_EV67
 657               "EV67 "
 658#endif
 659#ifdef CONFIG_ALPHA_LEGACY_START_ADDRESS
 660               "LEGACY_START "
 661#endif
 662#ifdef CONFIG_VERBOSE_MCHECK
 663               "VERBOSE_MCHECK "
 664#endif
 665
 666#ifdef CONFIG_DISCONTIGMEM
 667               "DISCONTIGMEM "
 668#ifdef CONFIG_NUMA
 669               "NUMA "
 670#endif
 671#endif
 672
 673#ifdef CONFIG_DEBUG_SPINLOCK
 674               "DEBUG_SPINLOCK "
 675#endif
 676#ifdef CONFIG_MAGIC_SYSRQ
 677               "MAGIC_SYSRQ "
 678#endif
 679               "\n");
 680
 681        printk("Command line: %s\n", command_line);
 682
 683        /* 
 684         * Sync up the HAE.
 685         * Save the SRM's current value for restoration.
 686         */
 687        srm_hae = *alpha_mv.hae_register;
 688        __set_hae(alpha_mv.hae_cache);
 689
 690        /* Reset enable correctable error reports.  */
 691        wrmces(0x7);
 692
 693        /* Find our memory.  */
 694        setup_memory(kernel_end);
 695
 696        /* First guess at cpu cache sizes.  Do this before init_arch.  */
 697        determine_cpu_caches(cpu->type);
 698
 699        /* Initialize the machine.  Usually has to do with setting up
 700           DMA windows and the like.  */
 701        if (alpha_mv.init_arch)
 702                alpha_mv.init_arch();
 703
 704        /* Reserve standard resources.  */
 705        reserve_std_resources();
 706
 707        /* 
 708         * Give us a default console.  TGA users will see nothing until
 709         * chr_dev_init is called, rather late in the boot sequence.
 710         */
 711
 712#ifdef CONFIG_VT
 713#if defined(CONFIG_VGA_CONSOLE)
 714        conswitchp = &vga_con;
 715#elif defined(CONFIG_DUMMY_CONSOLE)
 716        conswitchp = &dummy_con;
 717#endif
 718#endif
 719
 720        /* Default root filesystem to sda2.  */
 721        ROOT_DEV = Root_SDA2;
 722
 723#ifdef CONFIG_EISA
 724        /* FIXME:  only set this when we actually have EISA in this box? */
 725        EISA_bus = 1;
 726#endif
 727
 728        /*
 729         * Check ASN in HWRPB for validity, report if bad.
 730         * FIXME: how was this failing?  Should we trust it instead,
 731         * and copy the value into alpha_mv.max_asn?
 732         */
 733
 734        if (hwrpb->max_asn != MAX_ASN) {
 735                printk("Max ASN from HWRPB is bad (0x%lx)\n", hwrpb->max_asn);
 736        }
 737
 738        /*
 739         * Identify the flock of penguins.
 740         */
 741
 742#ifdef CONFIG_SMP
 743        setup_smp();
 744#endif
 745        paging_init();
 746}
 747
 748static char sys_unknown[] = "Unknown";
 749static char systype_names[][16] = {
 750        "0",
 751        "ADU", "Cobra", "Ruby", "Flamingo", "Mannequin", "Jensen",
 752        "Pelican", "Morgan", "Sable", "Medulla", "Noname",
 753        "Turbolaser", "Avanti", "Mustang", "Alcor", "Tradewind",
 754        "Mikasa", "EB64", "EB66", "EB64+", "AlphaBook1",
 755        "Rawhide", "K2", "Lynx", "XL", "EB164", "Noritake",
 756        "Cortex", "29", "Miata", "XXM", "Takara", "Yukon",
 757        "Tsunami", "Wildfire", "CUSCO", "Eiger", "Titan", "Marvel"
 758};
 759
 760static char unofficial_names[][8] = {"100", "Ruffian"};
 761
 762static char api_names[][16] = {"200", "Nautilus"};
 763
 764static char eb164_names[][8] = {"EB164", "PC164", "LX164", "SX164", "RX164"};
 765static int eb164_indices[] = {0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,4};
 766
 767static char alcor_names[][16] = {"Alcor", "Maverick", "Bret"};
 768static int alcor_indices[] = {0,0,0,1,1,1,0,0,0,0,0,0,2,2,2,2,2,2};
 769
 770static char eb64p_names[][16] = {"EB64+", "Cabriolet", "AlphaPCI64"};
 771static int eb64p_indices[] = {0,0,1,2};
 772
 773static char eb66_names[][8] = {"EB66", "EB66+"};
 774static int eb66_indices[] = {0,0,1};
 775
 776static char marvel_names[][16] = {
 777        "Marvel/EV7"
 778};
 779static int marvel_indices[] = { 0 };
 780
 781static char rawhide_names[][16] = {
 782        "Dodge", "Wrangler", "Durango", "Tincup", "DaVinci"
 783};
 784static int rawhide_indices[] = {0,0,0,1,1,2,2,3,3,4,4};
 785
 786static char titan_names[][16] = {
 787        "DEFAULT", "Privateer", "Falcon", "Granite"
 788};
 789static int titan_indices[] = {0,1,2,2,3};
 790
 791static char tsunami_names[][16] = {
 792        "0", "DP264", "Warhol", "Windjammer", "Monet", "Clipper",
 793        "Goldrush", "Webbrick", "Catamaran", "Brisbane", "Melbourne",
 794        "Flying Clipper", "Shark"
 795};
 796static int tsunami_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12};
 797
 798static struct alpha_machine_vector * __init
 799get_sysvec(unsigned long type, unsigned long variation, unsigned long cpu)
 800{
 801        static struct alpha_machine_vector *systype_vecs[] __initdata =
 802        {
 803                NULL,           /* 0 */
 804                NULL,           /* ADU */
 805                NULL,           /* Cobra */
 806                NULL,           /* Ruby */
 807                NULL,           /* Flamingo */
 808                NULL,           /* Mannequin */
 809                &jensen_mv,
 810                NULL,           /* Pelican */
 811                NULL,           /* Morgan */
 812                NULL,           /* Sable -- see below.  */
 813                NULL,           /* Medulla */
 814                &noname_mv,
 815                NULL,           /* Turbolaser */
 816                &avanti_mv,
 817                NULL,           /* Mustang */
 818                NULL,           /* Alcor, Bret, Maverick. HWRPB inaccurate? */
 819                NULL,           /* Tradewind */
 820                NULL,           /* Mikasa -- see below.  */
 821                NULL,           /* EB64 */
 822                NULL,           /* EB66 -- see variation.  */
 823                NULL,           /* EB64+ -- see variation.  */
 824                &alphabook1_mv,
 825                &rawhide_mv,
 826                NULL,           /* K2 */
 827                &lynx_mv,       /* Lynx */
 828                &xl_mv,
 829                NULL,           /* EB164 -- see variation.  */
 830                NULL,           /* Noritake -- see below.  */
 831                NULL,           /* Cortex */
 832                NULL,           /* 29 */
 833                &miata_mv,
 834                NULL,           /* XXM */
 835                &takara_mv,
 836                NULL,           /* Yukon */
 837                NULL,           /* Tsunami -- see variation.  */
 838                &wildfire_mv,   /* Wildfire */
 839                NULL,           /* CUSCO */
 840                &eiger_mv,      /* Eiger */
 841                NULL,           /* Titan */
 842                NULL,           /* Marvel */
 843        };
 844
 845        static struct alpha_machine_vector *unofficial_vecs[] __initdata =
 846        {
 847                NULL,           /* 100 */
 848                &ruffian_mv,
 849        };
 850
 851        static struct alpha_machine_vector *api_vecs[] __initdata =
 852        {
 853                NULL,           /* 200 */
 854                &nautilus_mv,
 855        };
 856
 857        static struct alpha_machine_vector *alcor_vecs[] __initdata = 
 858        {
 859                &alcor_mv, &xlt_mv, &xlt_mv
 860        };
 861
 862        static struct alpha_machine_vector *eb164_vecs[] __initdata =
 863        {
 864                &eb164_mv, &pc164_mv, &lx164_mv, &sx164_mv, &rx164_mv
 865        };
 866
 867        static struct alpha_machine_vector *eb64p_vecs[] __initdata =
 868        {
 869                &eb64p_mv,
 870                &cabriolet_mv,
 871                &cabriolet_mv           /* AlphaPCI64 */
 872        };
 873
 874        static struct alpha_machine_vector *eb66_vecs[] __initdata =
 875        {
 876                &eb66_mv,
 877                &eb66p_mv
 878        };
 879
 880        static struct alpha_machine_vector *marvel_vecs[] __initdata =
 881        {
 882                &marvel_ev7_mv,
 883        };
 884
 885        static struct alpha_machine_vector *titan_vecs[] __initdata =
 886        {
 887                &titan_mv,              /* default   */
 888                &privateer_mv,          /* privateer */
 889                &titan_mv,              /* falcon    */
 890                &privateer_mv,          /* granite   */
 891        };
 892
 893        static struct alpha_machine_vector *tsunami_vecs[]  __initdata =
 894        {
 895                NULL,
 896                &dp264_mv,              /* dp264 */
 897                &dp264_mv,              /* warhol */
 898                &dp264_mv,              /* windjammer */
 899                &monet_mv,              /* monet */
 900                &clipper_mv,            /* clipper */
 901                &dp264_mv,              /* goldrush */
 902                &webbrick_mv,           /* webbrick */
 903                &dp264_mv,              /* catamaran */
 904                NULL,                   /* brisbane? */
 905                NULL,                   /* melbourne? */
 906                NULL,                   /* flying clipper? */
 907                &shark_mv,              /* shark */
 908        };
 909
 910        /* ??? Do we need to distinguish between Rawhides?  */
 911
 912        struct alpha_machine_vector *vec;
 913
 914        /* Search the system tables first... */
 915        vec = NULL;
 916        if (type < ARRAY_SIZE(systype_vecs)) {
 917                vec = systype_vecs[type];
 918        } else if ((type > ST_API_BIAS) &&
 919                   (type - ST_API_BIAS) < ARRAY_SIZE(api_vecs)) {
 920                vec = api_vecs[type - ST_API_BIAS];
 921        } else if ((type > ST_UNOFFICIAL_BIAS) &&
 922                   (type - ST_UNOFFICIAL_BIAS) < ARRAY_SIZE(unofficial_vecs)) {
 923                vec = unofficial_vecs[type - ST_UNOFFICIAL_BIAS];
 924        }
 925
 926        /* If we've not found one, try for a variation.  */
 927
 928        if (!vec) {
 929                /* Member ID is a bit-field. */
 930                unsigned long member = (variation >> 10) & 0x3f;
 931
 932                cpu &= 0xffffffff; /* make it usable */
 933
 934                switch (type) {
 935                case ST_DEC_ALCOR:
 936                        if (member < ARRAY_SIZE(alcor_indices))
 937                                vec = alcor_vecs[alcor_indices[member]];
 938                        break;
 939                case ST_DEC_EB164:
 940                        if (member < ARRAY_SIZE(eb164_indices))
 941                                vec = eb164_vecs[eb164_indices[member]];
 942                        /* PC164 may show as EB164 variation with EV56 CPU,
 943                           but, since no true EB164 had anything but EV5... */
 944                        if (vec == &eb164_mv && cpu == EV56_CPU)
 945                                vec = &pc164_mv;
 946                        break;
 947                case ST_DEC_EB64P:
 948                        if (member < ARRAY_SIZE(eb64p_indices))
 949                                vec = eb64p_vecs[eb64p_indices[member]];
 950                        break;
 951                case ST_DEC_EB66:
 952                        if (member < ARRAY_SIZE(eb66_indices))
 953                                vec = eb66_vecs[eb66_indices[member]];
 954                        break;
 955                case ST_DEC_MARVEL:
 956                        if (member < ARRAY_SIZE(marvel_indices))
 957                                vec = marvel_vecs[marvel_indices[member]];
 958                        break;
 959                case ST_DEC_TITAN:
 960                        vec = titan_vecs[0];    /* default */
 961                        if (member < ARRAY_SIZE(titan_indices))
 962                                vec = titan_vecs[titan_indices[member]];
 963                        break;
 964                case ST_DEC_TSUNAMI:
 965                        if (member < ARRAY_SIZE(tsunami_indices))
 966                                vec = tsunami_vecs[tsunami_indices[member]];
 967                        break;
 968                case ST_DEC_1000:
 969                        if (cpu == EV5_CPU || cpu == EV56_CPU)
 970                                vec = &mikasa_primo_mv;
 971                        else
 972                                vec = &mikasa_mv;
 973                        break;
 974                case ST_DEC_NORITAKE:
 975                        if (cpu == EV5_CPU || cpu == EV56_CPU)
 976                                vec = &noritake_primo_mv;
 977                        else
 978                                vec = &noritake_mv;
 979                        break;
 980                case ST_DEC_2100_A500:
 981                        if (cpu == EV5_CPU || cpu == EV56_CPU)
 982                                vec = &sable_gamma_mv;
 983                        else
 984                                vec = &sable_mv;
 985                        break;
 986                }
 987        }
 988        return vec;
 989}
 990
 991static struct alpha_machine_vector * __init
 992get_sysvec_byname(const char *name)
 993{
 994        static struct alpha_machine_vector *all_vecs[] __initdata =
 995        {
 996                &alcor_mv,
 997                &alphabook1_mv,
 998                &avanti_mv,
 999                &cabriolet_mv,
1000                &clipper_mv,
1001                &dp264_mv,
1002                &eb164_mv,
1003                &eb64p_mv,
1004                &eb66_mv,
1005                &eb66p_mv,
1006                &eiger_mv,
1007                &jensen_mv,
1008                &lx164_mv,
1009                &lynx_mv,
1010                &miata_mv,
1011                &mikasa_mv,
1012                &mikasa_primo_mv,
1013                &monet_mv,
1014                &nautilus_mv,
1015                &noname_mv,
1016                &noritake_mv,
1017                &noritake_primo_mv,
1018                &p2k_mv,
1019                &pc164_mv,
1020                &privateer_mv,
1021                &rawhide_mv,
1022                &ruffian_mv,
1023                &rx164_mv,
1024                &sable_mv,
1025                &sable_gamma_mv,
1026                &shark_mv,
1027                &sx164_mv,
1028                &takara_mv,
1029                &webbrick_mv,
1030                &wildfire_mv,
1031                &xl_mv,
1032                &xlt_mv
1033        };
1034
1035        size_t i;
1036
1037        for (i = 0; i < ARRAY_SIZE(all_vecs); ++i) {
1038                struct alpha_machine_vector *mv = all_vecs[i];
1039                if (strcasecmp(mv->vector_name, name) == 0)
1040                        return mv;
1041        }
1042        return NULL;
1043}
1044
1045static void
1046get_sysnames(unsigned long type, unsigned long variation, unsigned long cpu,
1047             char **type_name, char **variation_name)
1048{
1049        unsigned long member;
1050
1051        /* If not in the tables, make it UNKNOWN,
1052           else set type name to family */
1053        if (type < ARRAY_SIZE(systype_names)) {
1054                *type_name = systype_names[type];
1055        } else if ((type > ST_API_BIAS) &&
1056                   (type - ST_API_BIAS) < ARRAY_SIZE(api_names)) {
1057                *type_name = api_names[type - ST_API_BIAS];
1058        } else if ((type > ST_UNOFFICIAL_BIAS) &&
1059                   (type - ST_UNOFFICIAL_BIAS) < ARRAY_SIZE(unofficial_names)) {
1060                *type_name = unofficial_names[type - ST_UNOFFICIAL_BIAS];
1061        } else {
1062                *type_name = sys_unknown;
1063                *variation_name = sys_unknown;
1064                return;
1065        }
1066
1067        /* Set variation to "0"; if variation is zero, done.  */
1068        *variation_name = systype_names[0];
1069        if (variation == 0) {
1070                return;
1071        }
1072
1073        member = (variation >> 10) & 0x3f; /* member ID is a bit-field */
1074
1075        cpu &= 0xffffffff; /* make it usable */
1076
1077        switch (type) { /* select by family */
1078        default: /* default to variation "0" for now */
1079                break;
1080        case ST_DEC_EB164:
1081                if (member < ARRAY_SIZE(eb164_indices))
1082                        *variation_name = eb164_names[eb164_indices[member]];
1083                /* PC164 may show as EB164 variation, but with EV56 CPU,
1084                   so, since no true EB164 had anything but EV5... */
1085                if (eb164_indices[member] == 0 && cpu == EV56_CPU)
1086                        *variation_name = eb164_names[1]; /* make it PC164 */
1087                break;
1088        case ST_DEC_ALCOR:
1089                if (member < ARRAY_SIZE(alcor_indices))
1090                        *variation_name = alcor_names[alcor_indices[member]];
1091                break;
1092        case ST_DEC_EB64P:
1093                if (member < ARRAY_SIZE(eb64p_indices))
1094                        *variation_name = eb64p_names[eb64p_indices[member]];
1095                break;
1096        case ST_DEC_EB66:
1097                if (member < ARRAY_SIZE(eb66_indices))
1098                        *variation_name = eb66_names[eb66_indices[member]];
1099                break;
1100        case ST_DEC_MARVEL:
1101                if (member < ARRAY_SIZE(marvel_indices))
1102                        *variation_name = marvel_names[marvel_indices[member]];
1103                break;
1104        case ST_DEC_RAWHIDE:
1105                if (member < ARRAY_SIZE(rawhide_indices))
1106                        *variation_name = rawhide_names[rawhide_indices[member]];
1107                break;
1108        case ST_DEC_TITAN:
1109                *variation_name = titan_names[0];       /* default */
1110                if (member < ARRAY_SIZE(titan_indices))
1111                        *variation_name = titan_names[titan_indices[member]];
1112                break;
1113        case ST_DEC_TSUNAMI:
1114                if (member < ARRAY_SIZE(tsunami_indices))
1115                        *variation_name = tsunami_names[tsunami_indices[member]];
1116                break;
1117        }
1118}
1119
1120/*
1121 * A change was made to the HWRPB via an ECO and the following code
1122 * tracks a part of the ECO.  In HWRPB versions less than 5, the ECO
1123 * was not implemented in the console firmware.  If it's revision 5 or
1124 * greater we can get the name of the platform as an ASCII string from
1125 * the HWRPB.  That's what this function does.  It checks the revision
1126 * level and if the string is in the HWRPB it returns the address of
1127 * the string--a pointer to the name of the platform.
1128 *
1129 * Returns:
1130 *      - Pointer to a ASCII string if it's in the HWRPB
1131 *      - Pointer to a blank string if the data is not in the HWRPB.
1132 */
1133
1134static char *
1135platform_string(void)
1136{
1137        struct dsr_struct *dsr;
1138        static char unk_system_string[] = "N/A";
1139
1140        /* Go to the console for the string pointer.
1141         * If the rpb_vers is not 5 or greater the rpb
1142         * is old and does not have this data in it.
1143         */
1144        if (hwrpb->revision < 5)
1145                return (unk_system_string);
1146        else {
1147                /* The Dynamic System Recognition struct
1148                 * has the system platform name starting
1149                 * after the character count of the string.
1150                 */
1151                dsr =  ((struct dsr_struct *)
1152                        ((char *)hwrpb + hwrpb->dsr_offset));
1153                return ((char *)dsr + (dsr->sysname_off +
1154                                       sizeof(long)));
1155        }
1156}
1157
1158static int
1159get_nr_processors(struct percpu_struct *cpubase, unsigned long num)
1160{
1161        struct percpu_struct *cpu;
1162        unsigned long i;
1163        int count = 0;
1164
1165        for (i = 0; i < num; i++) {
1166                cpu = (struct percpu_struct *)
1167                        ((char *)cpubase + i*hwrpb->processor_size);
1168                if ((cpu->flags & 0x1cc) == 0x1cc)
1169                        count++;
1170        }
1171        return count;
1172}
1173
1174static void
1175show_cache_size (struct seq_file *f, const char *which, int shape)
1176{
1177        if (shape == -1)
1178                seq_printf (f, "%s\t\t: n/a\n", which);
1179        else if (shape == 0)
1180                seq_printf (f, "%s\t\t: unknown\n", which);
1181        else
1182                seq_printf (f, "%s\t\t: %dK, %d-way, %db line\n",
1183                            which, shape >> 10, shape & 15,
1184                            1 << ((shape >> 4) & 15));
1185}
1186
1187static int
1188show_cpuinfo(struct seq_file *f, void *slot)
1189{
1190        extern struct unaligned_stat {
1191                unsigned long count, va, pc;
1192        } unaligned[2];
1193
1194        static char cpu_names[][8] = {
1195                "EV3", "EV4", "Simulate", "LCA4", "EV5", "EV45", "EV56",
1196                "EV6", "PCA56", "PCA57", "EV67", "EV68CB", "EV68AL",
1197                "EV68CX", "EV7", "EV79", "EV69"
1198        };
1199
1200        struct percpu_struct *cpu = slot;
1201        unsigned int cpu_index;
1202        char *cpu_name;
1203        char *systype_name;
1204        char *sysvariation_name;
1205        int nr_processors;
1206
1207        cpu_index = (unsigned) (cpu->type - 1);
1208        cpu_name = "Unknown";
1209        if (cpu_index < ARRAY_SIZE(cpu_names))
1210                cpu_name = cpu_names[cpu_index];
1211
1212        get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,
1213                     cpu->type, &systype_name, &sysvariation_name);
1214
1215        nr_processors = get_nr_processors(cpu, hwrpb->nr_processors);
1216
1217        seq_printf(f, "cpu\t\t\t: Alpha\n"
1218                      "cpu model\t\t: %s\n"
1219                      "cpu variation\t\t: %ld\n"
1220                      "cpu revision\t\t: %ld\n"
1221                      "cpu serial number\t: %s\n"
1222                      "system type\t\t: %s\n"
1223                      "system variation\t: %s\n"
1224                      "system revision\t\t: %ld\n"
1225                      "system serial number\t: %s\n"
1226                      "cycle frequency [Hz]\t: %lu %s\n"
1227                      "timer frequency [Hz]\t: %lu.%02lu\n"
1228                      "page size [bytes]\t: %ld\n"
1229                      "phys. address bits\t: %ld\n"
1230                      "max. addr. space #\t: %ld\n"
1231                      "BogoMIPS\t\t: %lu.%02lu\n"
1232                      "kernel unaligned acc\t: %ld (pc=%lx,va=%lx)\n"
1233                      "user unaligned acc\t: %ld (pc=%lx,va=%lx)\n"
1234                      "platform string\t\t: %s\n"
1235                      "cpus detected\t\t: %d\n",
1236                       cpu_name, cpu->variation, cpu->revision,
1237                       (char*)cpu->serial_no,
1238                       systype_name, sysvariation_name, hwrpb->sys_revision,
1239                       (char*)hwrpb->ssn,
1240                       est_cycle_freq ? : hwrpb->cycle_freq,
1241                       est_cycle_freq ? "est." : "",
1242                       hwrpb->intr_freq / 4096,
1243                       (100 * hwrpb->intr_freq / 4096) % 100,
1244                       hwrpb->pagesize,
1245                       hwrpb->pa_bits,
1246                       hwrpb->max_asn,
1247                       loops_per_jiffy / (500000/HZ),
1248                       (loops_per_jiffy / (5000/HZ)) % 100,
1249                       unaligned[0].count, unaligned[0].pc, unaligned[0].va,
1250                       unaligned[1].count, unaligned[1].pc, unaligned[1].va,
1251                       platform_string(), nr_processors);
1252
1253#ifdef CONFIG_SMP
1254        seq_printf(f, "cpus active\t\t: %d\n"
1255                      "cpu active mask\t\t: %016lx\n",
1256                       num_online_cpus(), cpus_addr(cpu_possible_map)[0]);
1257#endif
1258
1259        show_cache_size (f, "L1 Icache", alpha_l1i_cacheshape);
1260        show_cache_size (f, "L1 Dcache", alpha_l1d_cacheshape);
1261        show_cache_size (f, "L2 cache", alpha_l2_cacheshape);
1262        show_cache_size (f, "L3 cache", alpha_l3_cacheshape);
1263
1264        return 0;
1265}
1266
1267static int __init
1268read_mem_block(int *addr, int stride, int size)
1269{
1270        long nloads = size / stride, cnt, tmp;
1271
1272        __asm__ __volatile__(
1273        "       rpcc    %0\n"
1274        "1:     ldl     %3,0(%2)\n"
1275        "       subq    %1,1,%1\n"
1276        /* Next two XORs introduce an explicit data dependency between
1277           consecutive loads in the loop, which will give us true load
1278           latency. */
1279        "       xor     %3,%2,%2\n"
1280        "       xor     %3,%2,%2\n"
1281        "       addq    %2,%4,%2\n"
1282        "       bne     %1,1b\n"
1283        "       rpcc    %3\n"
1284        "       subl    %3,%0,%0\n"
1285        : "=&r" (cnt), "=&r" (nloads), "=&r" (addr), "=&r" (tmp)
1286        : "r" (stride), "1" (nloads), "2" (addr));
1287
1288        return cnt / (size / stride);
1289}
1290
1291#define CSHAPE(totalsize, linesize, assoc) \
1292  ((totalsize & ~0xff) | (linesize << 4) | assoc)
1293
1294/* ??? EV5 supports up to 64M, but did the systems with more than
1295   16M of BCACHE ever exist? */
1296#define MAX_BCACHE_SIZE 16*1024*1024
1297
1298/* Note that the offchip caches are direct mapped on all Alphas. */
1299static int __init
1300external_cache_probe(int minsize, int width)
1301{
1302        int cycles, prev_cycles = 1000000;
1303        int stride = 1 << width;
1304        long size = minsize, maxsize = MAX_BCACHE_SIZE * 2;
1305
1306        if (maxsize > (max_low_pfn + 1) << PAGE_SHIFT)
1307                maxsize = 1 << (ilog2(max_low_pfn + 1) + PAGE_SHIFT);
1308
1309        /* Get the first block cached. */
1310        read_mem_block(__va(0), stride, size);
1311
1312        while (size < maxsize) {
1313                /* Get an average load latency in cycles. */
1314                cycles = read_mem_block(__va(0), stride, size);
1315                if (cycles > prev_cycles * 2) {
1316                        /* Fine, we exceed the cache. */
1317                        printk("%ldK Bcache detected; load hit latency %d "
1318                               "cycles, load miss latency %d cycles\n",
1319                               size >> 11, prev_cycles, cycles);
1320                        return CSHAPE(size >> 1, width, 1);
1321                }
1322                /* Try to get the next block cached. */
1323                read_mem_block(__va(size), stride, size);
1324                prev_cycles = cycles;
1325                size <<= 1;
1326        }
1327        return -1;      /* No BCACHE found. */
1328}
1329
1330static void __init
1331determine_cpu_caches (unsigned int cpu_type)
1332{
1333        int L1I, L1D, L2, L3;
1334
1335        switch (cpu_type) {
1336        case EV4_CPU:
1337        case EV45_CPU:
1338          {
1339                if (cpu_type == EV4_CPU)
1340                        L1I = CSHAPE(8*1024, 5, 1);
1341                else
1342                        L1I = CSHAPE(16*1024, 5, 1);
1343                L1D = L1I;
1344                L3 = -1;
1345        
1346                /* BIU_CTL is a write-only Abox register.  PALcode has a
1347                   shadow copy, and may be available from some versions
1348                   of the CSERVE PALcall.  If we can get it, then
1349
1350                        unsigned long biu_ctl, size;
1351                        size = 128*1024 * (1 << ((biu_ctl >> 28) & 7));
1352                        L2 = CSHAPE (size, 5, 1);
1353
1354                   Unfortunately, we can't rely on that.
1355                */
1356                L2 = external_cache_probe(128*1024, 5);
1357                break;
1358          }
1359
1360        case LCA4_CPU:
1361          {
1362                unsigned long car, size;
1363
1364                L1I = L1D = CSHAPE(8*1024, 5, 1);
1365                L3 = -1;
1366
1367                car = *(vuip) phys_to_virt (0x120000078UL);
1368                size = 64*1024 * (1 << ((car >> 5) & 7));
1369                /* No typo -- 8 byte cacheline size.  Whodathunk.  */
1370                L2 = (car & 1 ? CSHAPE (size, 3, 1) : -1);
1371                break;
1372          }
1373
1374        case EV5_CPU:
1375        case EV56_CPU:
1376          {
1377                unsigned long sc_ctl, width;
1378
1379                L1I = L1D = CSHAPE(8*1024, 5, 1);
1380
1381                /* Check the line size of the Scache.  */
1382                sc_ctl = *(vulp) phys_to_virt (0xfffff000a8UL);
1383                width = sc_ctl & 0x1000 ? 6 : 5;
1384                L2 = CSHAPE (96*1024, width, 3);
1385
1386                /* BC_CONTROL and BC_CONFIG are write-only IPRs.  PALcode
1387                   has a shadow copy, and may be available from some versions
1388                   of the CSERVE PALcall.  If we can get it, then
1389
1390                        unsigned long bc_control, bc_config, size;
1391                        size = 1024*1024 * (1 << ((bc_config & 7) - 1));
1392                        L3 = (bc_control & 1 ? CSHAPE (size, width, 1) : -1);
1393
1394                   Unfortunately, we can't rely on that.
1395                */
1396                L3 = external_cache_probe(1024*1024, width);
1397                break;
1398          }
1399
1400        case PCA56_CPU:
1401        case PCA57_CPU:
1402          {
1403                unsigned long cbox_config, size;
1404
1405                if (cpu_type == PCA56_CPU) {
1406                        L1I = CSHAPE(16*1024, 6, 1);
1407                        L1D = CSHAPE(8*1024, 5, 1);
1408                } else {
1409                        L1I = CSHAPE(32*1024, 6, 2);
1410                        L1D = CSHAPE(16*1024, 5, 1);
1411                }
1412                L3 = -1;
1413
1414                cbox_config = *(vulp) phys_to_virt (0xfffff00008UL);
1415                size = 512*1024 * (1 << ((cbox_config >> 12) & 3));
1416
1417#if 0
1418                L2 = ((cbox_config >> 31) & 1 ? CSHAPE (size, 6, 1) : -1);
1419#else
1420                L2 = external_cache_probe(512*1024, 6);
1421#endif
1422                break;
1423          }
1424
1425        case EV6_CPU:
1426        case EV67_CPU:
1427        case EV68CB_CPU:
1428        case EV68AL_CPU:
1429        case EV68CX_CPU:
1430        case EV69_CPU:
1431                L1I = L1D = CSHAPE(64*1024, 6, 2);
1432                L2 = external_cache_probe(1024*1024, 6);
1433                L3 = -1;
1434                break;
1435
1436        case EV7_CPU:
1437        case EV79_CPU:
1438                L1I = L1D = CSHAPE(64*1024, 6, 2);
1439                L2 = CSHAPE(7*1024*1024/4, 6, 7);
1440                L3 = -1;
1441                break;
1442
1443        default:
1444                /* Nothing known about this cpu type.  */
1445                L1I = L1D = L2 = L3 = 0;
1446                break;
1447        }
1448
1449        alpha_l1i_cacheshape = L1I;
1450        alpha_l1d_cacheshape = L1D;
1451        alpha_l2_cacheshape = L2;
1452        alpha_l3_cacheshape = L3;
1453}
1454
1455/*
1456 * We show only CPU #0 info.
1457 */
1458static void *
1459c_start(struct seq_file *f, loff_t *pos)
1460{
1461        return *pos ? NULL : (char *)hwrpb + hwrpb->processor_offset;
1462}
1463
1464static void *
1465c_next(struct seq_file *f, void *v, loff_t *pos)
1466{
1467        return NULL;
1468}
1469
1470static void
1471c_stop(struct seq_file *f, void *v)
1472{
1473}
1474
1475struct seq_operations cpuinfo_op = {
1476        .start  = c_start,
1477        .next   = c_next,
1478        .stop   = c_stop,
1479        .show   = show_cpuinfo,
1480};
1481
1482
1483static int
1484alpha_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
1485{
1486#if 1
1487        /* FIXME FIXME FIXME */
1488        /* If we are using SRM and serial console, just hard halt here. */
1489        if (alpha_using_srm && srmcons_output)
1490                __halt();
1491#endif
1492        return NOTIFY_DONE;
1493}
1494
1495static __init int add_pcspkr(void)
1496{
1497        struct platform_device *pd;
1498        int ret;
1499
1500        pd = platform_device_alloc("pcspkr", -1);
1501        if (!pd)
1502                return -ENOMEM;
1503
1504        ret = platform_device_add(pd);
1505        if (ret)
1506                platform_device_put(pd);
1507
1508        return ret;
1509}
1510device_initcall(add_pcspkr);
1511