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