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