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