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