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