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