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