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