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