1 /*
2  *  linux/arch/alpha/kernel/setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  */
6 
7 /* 2.3.x bootmem, 1999 Andrea Arcangeli <andrea@suse.de> */
8 
9 /*
10  * Bootup setup stuff.
11  */
12 
13 #include <linux/sched.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/stddef.h>
17 #include <linux/unistd.h>
18 #include <linux/ptrace.h>
19 #include <linux/slab.h>
20 #include <linux/user.h>
21 #include <linux/a.out.h>
22 #include <linux/tty.h>
23 #include <linux/delay.h>
24 #include <linux/config.h>	/* CONFIG_ALPHA_LCA etc */
25 #include <linux/mc146818rtc.h>
26 #include <linux/console.h>
27 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/string.h>
30 #include <linux/ioport.h>
31 #include <linux/bootmem.h>
32 #include <linux/pci.h>
33 #include <linux/seq_file.h>
34 
35 #ifdef CONFIG_BLK_DEV_INITRD
36 #include <linux/blk.h>
37 #endif
38 
39 #include <linux/notifier.h>
40 extern struct notifier_block *panic_notifier_list;
41 static int alpha_panic_event(struct notifier_block *, unsigned long, void *);
42 static struct notifier_block alpha_panic_block = {
43 	alpha_panic_event,
44         NULL,
45         INT_MAX /* try to do it first */
46 };
47 
48 #include <asm/uaccess.h>
49 #include <asm/pgtable.h>
50 #include <asm/system.h>
51 #include <asm/hwrpb.h>
52 #include <asm/dma.h>
53 #include <asm/io.h>
54 #include <asm/mmu_context.h>
55 #include <asm/console.h>
56 
57 #include "proto.h"
58 #include "pci_impl.h"
59 
60 
61 struct hwrpb_struct *hwrpb;
62 unsigned long srm_hae;
63 
64 /* Which processor we booted from.  */
65 int boot_cpuid;
66 
67 /*
68  * Using SRM callbacks for initial console output. This works from
69  * setup_arch() time through the end of time_init(), as those places
70  * are under our (Alpha) control.
71 
72  * "srmcons" specified in the boot command arguments allows us to
73  * see kernel messages during the period of time before the true
74  * console device is "registered" during console_init().
75  * As of this version (2.4.20), console_init() will call
76  * disable_early_printk() as the last action before initializing
77  * the console drivers. That's the last possible time srmcons can be
78  * unregistered without interfering with console behavior.
79  *
80  * By default, OFF; set it with a bootcommand arg of "srmcons" or
81  * "console=srm". The meaning of these two args is:
82  *     "srmcons"     - early callback prints
83  *     "console=srm" - full callback based console, including early prints
84  */
85 int srmcons_output = 0;
86 
87 /* Enforce a memory size limit; useful for testing. By default, none. */
88 unsigned long mem_size_limit = 0;
89 
90 /* Set AGP GART window size (0 means disabled). */
91 unsigned long alpha_agpgart_size = DEFAULT_AGP_APER_SIZE;
92 
93 #ifdef CONFIG_ALPHA_GENERIC
94 struct alpha_machine_vector alpha_mv;
95 int alpha_using_srm;
96 #endif
97 
98 unsigned char aux_device_present = 0xaa;
99 
100 #define N(a) (sizeof(a)/sizeof(a[0]))
101 
102 static struct alpha_machine_vector *get_sysvec(long, long, long);
103 static struct alpha_machine_vector *get_sysvec_byname(const char *);
104 static void get_sysnames(long, long, long, char **, char **);
105 
106 static char command_line[COMMAND_LINE_SIZE];
107 char saved_command_line[COMMAND_LINE_SIZE];
108 
109 /*
110  * The format of "screen_info" is strange, and due to early
111  * i386-setup code. This is just enough to make the console
112  * code think we're on a VGA color display.
113  */
114 
115 struct screen_info screen_info = {
116 	orig_x: 0,
117 	orig_y: 25,
118 	orig_video_cols: 80,
119 	orig_video_lines: 25,
120 	orig_video_isVGA: 1,
121 	orig_video_points: 16
122 };
123 
124 /*
125  * The direct map I/O window, if any.  This should be the same
126  * for all busses, since it's used by virt_to_bus.
127  */
128 
129 unsigned long __direct_map_base;
130 unsigned long __direct_map_size;
131 
132 /*
133  * Declare all of the machine vectors.
134  */
135 
136 /* GCC 2.7.2 (on alpha at least) is lame.  It does not support either
137    __attribute__((weak)) or #pragma weak.  Bypass it and talk directly
138    to the assembler.  */
139 
140 #define WEAK(X) \
141 	extern struct alpha_machine_vector X; \
142 	asm(".weak "#X)
143 
144 WEAK(alcor_mv);
145 WEAK(alphabook1_mv);
146 WEAK(avanti_mv);
147 WEAK(cabriolet_mv);
148 WEAK(clipper_mv);
149 WEAK(dp264_mv);
150 WEAK(eb164_mv);
151 WEAK(eb64p_mv);
152 WEAK(eb66_mv);
153 WEAK(eb66p_mv);
154 WEAK(eiger_mv);
155 WEAK(jensen_mv);
156 WEAK(lx164_mv);
157 WEAK(lynx_mv);
158 WEAK(marvel_ev7_mv);
159 WEAK(miata_mv);
160 WEAK(mikasa_mv);
161 WEAK(mikasa_primo_mv);
162 WEAK(monet_mv);
163 WEAK(nautilus_mv);
164 WEAK(noname_mv);
165 WEAK(noritake_mv);
166 WEAK(noritake_primo_mv);
167 WEAK(p2k_mv);
168 WEAK(pc164_mv);
169 WEAK(privateer_mv);
170 WEAK(rawhide_mv);
171 WEAK(ruffian_mv);
172 WEAK(rx164_mv);
173 WEAK(sable_mv);
174 WEAK(sable_gamma_mv);
175 WEAK(shark_mv);
176 WEAK(sx164_mv);
177 WEAK(takara_mv);
178 WEAK(titan_mv);
179 WEAK(webbrick_mv);
180 WEAK(wildfire_mv);
181 WEAK(xl_mv);
182 WEAK(xlt_mv);
183 
184 #undef WEAK
185 
186 /*
187  * I/O resources inherited from PeeCees.  Except for perhaps the
188  * turbochannel alphas, everyone has these on some sort of SuperIO chip.
189  *
190  * ??? If this becomes less standard, move the struct out into the
191  * machine vector.
192  */
193 
194 static void __init
reserve_std_resources(void)195 reserve_std_resources(void)
196 {
197 	static struct resource standard_io_resources[] = {
198 		{ "rtc", -1, -1 },
199         	{ "dma1", 0x00, 0x1f },
200         	{ "pic1", 0x20, 0x3f },
201         	{ "timer", 0x40, 0x5f },
202         	{ "keyboard", 0x60, 0x6f },
203         	{ "dma page reg", 0x80, 0x8f },
204         	{ "pic2", 0xa0, 0xbf },
205         	{ "dma2", 0xc0, 0xdf },
206 	};
207 
208 	struct resource *io = &ioport_resource;
209 	long i;
210 
211 	if (hose_head) {
212 		struct pci_controller *hose;
213 		for (hose = hose_head; hose; hose = hose->next)
214 			if (hose->index == 0) {
215 				io = hose->io_space;
216 				break;
217 			}
218 	}
219 
220 	/* Fix up for the Jensen's queer RTC placement.  */
221 	standard_io_resources[0].start = RTC_PORT(0);
222 	standard_io_resources[0].end = RTC_PORT(0) + 0x10;
223 
224 	for (i = 0; i < N(standard_io_resources); ++i)
225 		request_resource(io, standard_io_resources+i);
226 }
227 
228 #define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
229 #define PFN_DOWN(x)	((x) >> PAGE_SHIFT)
230 #define PFN_PHYS(x)	((x) << PAGE_SHIFT)
231 #define PFN_MAX		PFN_DOWN(0x80000000)
232 #define for_each_mem_cluster(memdesc, cluster, i)		\
233 	for ((cluster) = (memdesc)->cluster, (i) = 0;		\
234 	     (i) < (memdesc)->numclusters; (i)++, (cluster)++)
235 
236 static unsigned long __init
get_mem_size_limit(char * s)237 get_mem_size_limit(char *s)
238 {
239         unsigned long end = 0;
240         char *from = s;
241 
242         end = simple_strtoul(from, &from, 0);
243         if ( *from == 'K' || *from == 'k' ) {
244                 end = end << 10;
245                 from++;
246         } else if ( *from == 'M' || *from == 'm' ) {
247                 end = end << 20;
248                 from++;
249         } else if ( *from == 'G' || *from == 'g' ) {
250                 end = end << 30;
251                 from++;
252         }
253         return end >> PAGE_SHIFT; /* Return the PFN of the limit. */
254 }
255 
256 #ifdef CONFIG_BLK_DEV_INITRD
257 void * __init
move_initrd(unsigned long mem_limit)258 move_initrd(unsigned long mem_limit)
259 {
260 	void *start;
261 	unsigned long size;
262 
263 	size = initrd_end - initrd_start;
264 	start = __alloc_bootmem(PAGE_ALIGN(size), PAGE_SIZE, 0);
265 	if (!start || __pa(start) + size > mem_limit) {
266 		initrd_start = initrd_end = 0;
267 		return NULL;
268 	}
269 	memmove(start, (void *)initrd_start, size);
270 	initrd_start = (unsigned long)start;
271 	initrd_end = initrd_start + size;
272 	printk(KERN_INFO "initrd moved to %p\n", start);
273 	return start;
274 }
275 #endif
276 
277 #ifndef CONFIG_DISCONTIGMEM
278 static void __init
setup_memory(void * kernel_end)279 setup_memory(void *kernel_end)
280 {
281 	struct memclust_struct * cluster;
282 	struct memdesc_struct * memdesc;
283 	unsigned long start_kernel_pfn, end_kernel_pfn;
284 	unsigned long bootmap_size, bootmap_pages, bootmap_start;
285 	unsigned long start, end;
286 	int i;
287 
288 	/* Find free clusters, and init and free the bootmem accordingly.  */
289 	memdesc = (struct memdesc_struct *)
290 	  (hwrpb->mddt_offset + (unsigned long) hwrpb);
291 
292 	for_each_mem_cluster(memdesc, cluster, i) {
293 		printk("memcluster %d, usage %01lx, start %8lu, end %8lu\n",
294 		       i, cluster->usage, cluster->start_pfn,
295 		       cluster->start_pfn + cluster->numpages);
296 
297 		/* Bit 0 is console/PALcode reserved.  Bit 1 is
298 		   non-volatile memory -- we might want to mark
299 		   this for later.  */
300 		if (cluster->usage & 3)
301 			continue;
302 
303 		end = cluster->start_pfn + cluster->numpages;
304 		if (end > max_low_pfn)
305 			max_low_pfn = end;
306 	}
307 
308 	/*
309 	 * Except for the NUMA systems (wildfire, marvel) all of the
310 	 * Alpha systems we run on support 32GB of memory or less.
311 	 * Since the NUMA systems introduce large holes in memory addressing,
312 	 * we can get into a situation where there is not enough contiguous
313 	 * memory for the memory map.
314 	 *
315 	 * Limit memory to the first 32GB to limit the NUMA systems to
316 	 * memory on their first node (wildfire) or 2 (marvel) to avoid
317 	 * not being able to produce the memory map. In order to access
318 	 * all of the memory on the NUMA systems, build with discontiguous
319 	 * memory support.
320 	 *
321 	 * If the user specified a memory limit, let that memory limit stand.
322 	 */
323 	if (!mem_size_limit)
324 		mem_size_limit = (32ul * 1024 * 1024 * 1024) >> PAGE_SHIFT;
325 
326 	if (mem_size_limit && max_low_pfn >= mem_size_limit)
327 	{
328 		printk("setup: forcing memory size to %ldK (from %ldK).\n",
329 		       mem_size_limit << (PAGE_SHIFT - 10),
330 		       max_low_pfn    << (PAGE_SHIFT - 10));
331 		max_low_pfn = mem_size_limit;
332 	}
333 
334 	/* Find the bounds of kernel memory.  */
335 	start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
336 	end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
337 	bootmap_start = -1;
338 
339  try_again:
340 	if (max_low_pfn <= end_kernel_pfn)
341 		panic("not enough memory to boot");
342 
343 	/* We need to know how many physically contiguous pages
344 	   we'll need for the bootmap.  */
345 	bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
346 
347 	/* Now find a good region where to allocate the bootmap.  */
348 	for_each_mem_cluster(memdesc, cluster, i) {
349 		if (cluster->usage & 3)
350 			continue;
351 
352 		start = cluster->start_pfn;
353 		end = start + cluster->numpages;
354 		if (start >= max_low_pfn)
355 			continue;
356 		if (end > max_low_pfn)
357 			end = max_low_pfn;
358 		if (start < start_kernel_pfn) {
359 			if (end > end_kernel_pfn
360 			    && end - end_kernel_pfn >= bootmap_pages) {
361 				bootmap_start = end_kernel_pfn;
362 				break;
363 			} else if (end > start_kernel_pfn)
364 				end = start_kernel_pfn;
365 		} else if (start < end_kernel_pfn)
366 			start = end_kernel_pfn;
367 		if (end - start >= bootmap_pages) {
368 			bootmap_start = start;
369 			break;
370 		}
371 	}
372 
373 	if (bootmap_start == -1) {
374 		max_low_pfn >>= 1;
375 		goto try_again;
376 	}
377 
378 	/* Allocate the bootmap and mark the whole MM as reserved.  */
379 	bootmap_size = init_bootmem(bootmap_start, max_low_pfn);
380 
381 	/* Mark the free regions.  */
382 	for_each_mem_cluster(memdesc, cluster, i) {
383 		if (cluster->usage & 3)
384 			continue;
385 
386 		start = cluster->start_pfn;
387 		end = cluster->start_pfn + cluster->numpages;
388 		if (start >= max_low_pfn)
389 			continue;
390 		if (end > max_low_pfn)
391 			end = max_low_pfn;
392 		if (start < start_kernel_pfn) {
393 			if (end > end_kernel_pfn) {
394 				free_bootmem(PFN_PHYS(start),
395 					     (PFN_PHYS(start_kernel_pfn)
396 					      - PFN_PHYS(start)));
397 				printk("freeing pages %ld:%ld\n",
398 				       start, start_kernel_pfn);
399 				start = end_kernel_pfn;
400 			} else if (end > start_kernel_pfn)
401 				end = start_kernel_pfn;
402 		} else if (start < end_kernel_pfn)
403 			start = end_kernel_pfn;
404 		if (start >= end)
405 			continue;
406 
407 		free_bootmem(PFN_PHYS(start), PFN_PHYS(end) - PFN_PHYS(start));
408 		printk("freeing pages %ld:%ld\n", start, end);
409 	}
410 
411 	/* Reserve the bootmap memory.  */
412 	reserve_bootmem(PFN_PHYS(bootmap_start), bootmap_size);
413 	printk("reserving pages %ld:%ld\n", bootmap_start, bootmap_start+PFN_UP(bootmap_size));
414 
415 #ifdef CONFIG_BLK_DEV_INITRD
416 	initrd_start = INITRD_START;
417 	if (initrd_start) {
418 		initrd_end = initrd_start+INITRD_SIZE;
419 		printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
420 		       (void *) initrd_start, INITRD_SIZE);
421 
422 		if ((void *)initrd_end > phys_to_virt(PFN_PHYS(max_low_pfn))) {
423 			if (!move_initrd(PFN_PHYS(max_low_pfn)))
424 				printk("initrd extends beyond end of memory "
425 				       "(0x%08lx > 0x%p)\ndisabling initrd\n",
426 				       initrd_end,
427 				       phys_to_virt(PFN_PHYS(max_low_pfn)));
428 		} else {
429 			reserve_bootmem(virt_to_phys((void *)initrd_start),
430 					INITRD_SIZE);
431 		}
432 	}
433 #endif /* CONFIG_BLK_DEV_INITRD */
434 }
435 #else
436 extern void setup_memory(void *);
437 #endif /* !CONFIG_DISCONTIGMEM */
438 
439 int __init
page_is_ram(unsigned long pfn)440 page_is_ram(unsigned long pfn)
441 {
442 	struct memclust_struct * cluster;
443 	struct memdesc_struct * memdesc;
444 	int i;
445 
446 	memdesc = (struct memdesc_struct *)
447 		(hwrpb->mddt_offset + (unsigned long) hwrpb);
448 	for_each_mem_cluster(memdesc, cluster, i)
449 	{
450 		if (pfn >= cluster->start_pfn  &&
451 		    pfn < cluster->start_pfn + cluster->numpages) {
452 			return (cluster->usage & 3) ? 0 : 1;
453 		}
454 	}
455 
456 	return 0;
457 }
458 
459 #undef PFN_UP
460 #undef PFN_DOWN
461 #undef PFN_PHYS
462 #undef PFN_MAX
463 
464 void __init
setup_arch(char ** cmdline_p)465 setup_arch(char **cmdline_p)
466 {
467 	extern char _end[];
468 
469 	struct alpha_machine_vector *vec = NULL;
470 	struct percpu_struct *cpu;
471 	char *type_name, *var_name, *p;
472 	void *kernel_end = _end; /* end of kernel */
473 
474 	hwrpb = (struct hwrpb_struct*) __va(INIT_HWRPB->phys_addr);
475 	boot_cpuid = hard_smp_processor_id();
476 
477 	/* Register a call for panic conditions. */
478 	notifier_chain_register(&panic_notifier_list, &alpha_panic_block);
479 
480 #ifdef CONFIG_ALPHA_GENERIC
481 	/* Assume that we've booted from SRM if we havn't booted from MILO.
482 	   Detect the later by looking for "MILO" in the system serial nr.  */
483 	alpha_using_srm = strncmp((const char *)hwrpb->ssn, "MILO", 4) != 0;
484 #endif
485 
486 	/* If we are using SRM, we want to allow callbacks
487 	   as early as possible, so do this NOW, and then
488 	   they should work immediately thereafter.
489 	*/
490 	kernel_end = callback_init(kernel_end);
491 
492 	/*
493 	 * Locate the command line.
494 	 */
495 	/* Hack for Jensen... since we're restricted to 8 or 16 chars for
496 	   boot flags depending on the boot mode, we need some shorthand.
497 	   This should do for installation.  */
498 	if (strcmp(COMMAND_LINE, "INSTALL") == 0) {
499 		strcpy(command_line, "root=/dev/fd0 load_ramdisk=1");
500 	} else {
501 		strncpy(command_line, COMMAND_LINE, sizeof command_line);
502 		command_line[sizeof(command_line)-1] = 0;
503 	}
504 	strcpy(saved_command_line, command_line);
505 	*cmdline_p = command_line;
506 
507 	/*
508 	 * Process command-line arguments.
509 	 */
510 	for (p = strtok(command_line, " \t"); p ; p = strtok(NULL, " \t")) {
511 		if (strncmp(p, "alpha_mv=", 9) == 0) {
512 			vec = get_sysvec_byname(p+9);
513 			continue;
514 		}
515 		if (strncmp(p, "cycle=", 6) == 0) {
516 			est_cycle_freq = simple_strtol(p+6, NULL, 0);
517 			continue;
518 		}
519 		if (strncmp(p, "mem=", 4) == 0) {
520 			mem_size_limit = get_mem_size_limit(p+4);
521 			continue;
522 		}
523 		if (strncmp(p, "srmcons", 7) == 0) {
524 			srmcons_output |= 1;
525 			continue;
526 		}
527 		if (strncmp(p, "console=srm", 11) == 0) {
528 			srmcons_output |= 2;
529 			continue;
530 		}
531 		if (strncmp(p, "gartsize=", 9) == 0) {
532 			alpha_agpgart_size =
533 				get_mem_size_limit(p+9) << PAGE_SHIFT;
534 			continue;
535 		}
536 	}
537 
538 	/* Replace the command line, now that we've killed it with strtok.  */
539 	strcpy(command_line, saved_command_line);
540 
541 	/* If we want SRM console printk echoing early, do it now. */
542 	if (alpha_using_srm && srmcons_output) {
543 		register_srm_console();
544 
545 		/*
546 		 * If "console=srm" was specified, clear the srmcons_output
547 		 * flag now so that time.c won't unregister_srm_console
548 		 */
549 		if (srmcons_output & 2)
550 			srmcons_output = 0;
551 	}
552 
553 	/*
554 	 * Indentify and reconfigure for the current system.
555 	 */
556 	cpu = (struct percpu_struct*)((char*)hwrpb + hwrpb->processor_offset);
557 
558 	get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,
559 		     cpu->type, &type_name, &var_name);
560 	if (*var_name == '0')
561 		var_name = "";
562 
563 	if (!vec) {
564 		vec = get_sysvec(hwrpb->sys_type, hwrpb->sys_variation,
565 				 cpu->type);
566 	}
567 
568 	if (!vec) {
569 		panic("Unsupported system type: %s%s%s (%ld %ld)\n",
570 		      type_name, (*var_name ? " variation " : ""), var_name,
571 		      hwrpb->sys_type, hwrpb->sys_variation);
572 	}
573 	if (vec != &alpha_mv) {
574 		alpha_mv = *vec;
575 	}
576 
577 	printk("Booting "
578 #ifdef CONFIG_ALPHA_GENERIC
579 	       "GENERIC "
580 #endif
581 	       "on %s%s%s using machine vector %s from %s\n",
582 	       type_name, (*var_name ? " variation " : ""),
583 	       var_name, alpha_mv.vector_name,
584 	       (alpha_using_srm ? "SRM" : "MILO"));
585 
586 	printk("Major Options: "
587 #ifdef CONFIG_SMP
588 	       "SMP "
589 #endif
590 #ifdef CONFIG_ALPHA_EV56
591 	       "EV56 "
592 #endif
593 #ifdef CONFIG_ALPHA_EV67
594 	       "EV67 "
595 #endif
596 #ifdef CONFIG_ALPHA_LEGACY_START_ADDRESS
597 	       "LEGACY_START "
598 #endif
599 
600 #ifdef CONFIG_DISCONTIGMEM
601 	       "DISCONTIGMEM "
602 #ifdef CONFIG_NUMA
603 	       "NUMA "
604 #endif
605 #endif
606 
607 #ifdef CONFIG_DEBUG_SPINLOCK
608 	       "DEBUG_SPINLOCK "
609 #endif
610 #ifdef CONFIG_MAGIC_SYSRQ
611 	       "MAGIC_SYSRQ "
612 #endif
613 	       "\n");
614 
615 	printk("Command line: %s\n", command_line);
616 
617 	/*
618 	 * Sync up the HAE.
619 	 * Save the SRM's current value for restoration.
620 	 */
621 	srm_hae = *alpha_mv.hae_register;
622 	__set_hae(alpha_mv.hae_cache);
623 
624 	/* Reset enable correctable error reports.  */
625 	wrmces(0x7);
626 
627 	/* Find our memory.  */
628 	setup_memory(kernel_end);
629 
630 	/* Initialize the machine.  Usually has to do with setting up
631 	   DMA windows and the like.  */
632 	if (alpha_mv.init_arch)
633 		alpha_mv.init_arch();
634 
635 	/* Reserve standard resources.  */
636 	reserve_std_resources();
637 
638 	/*
639 	 * Give us a default console.  TGA users will see nothing until
640 	 * chr_dev_init is called, rather late in the boot sequence.
641 	 */
642 
643 #ifdef CONFIG_VT
644 #if defined(CONFIG_VGA_CONSOLE)
645 	conswitchp = &vga_con;
646 #elif defined(CONFIG_DUMMY_CONSOLE)
647 	conswitchp = &dummy_con;
648 #endif
649 #endif
650 
651 	/* Default root filesystem to sda2.  */
652 	ROOT_DEV = to_kdev_t(0x0802);
653 
654  	/*
655 	 * Check ASN in HWRPB for validity, report if bad.
656 	 * FIXME: how was this failing?  Should we trust it instead,
657 	 * and copy the value into alpha_mv.max_asn?
658  	 */
659 
660  	if (hwrpb->max_asn != MAX_ASN) {
661 		printk("Max ASN from HWRPB is bad (0x%lx)\n", hwrpb->max_asn);
662  	}
663 
664 	/*
665 	 * Identify the flock of penguins.
666 	 */
667 
668 #ifdef CONFIG_SMP
669 	setup_smp();
670 #endif
671 	paging_init();
672 }
673 
674 void __init
disable_early_printk(void)675 disable_early_printk(void)
676 {
677 	if (alpha_using_srm && srmcons_output) {
678 		unregister_srm_console();
679 		srmcons_output = 0;
680 	}
681 }
682 
683 static char sys_unknown[] = "Unknown";
684 static char systype_names[][16] = {
685 	"0",
686 	"ADU", "Cobra", "Ruby", "Flamingo", "Mannequin", "Jensen",
687 	"Pelican", "Morgan", "Sable", "Medulla", "Noname",
688 	"Turbolaser", "Avanti", "Mustang", "Alcor", "Tradewind",
689 	"Mikasa", "EB64", "EB66", "EB64+", "AlphaBook1",
690 	"Rawhide", "K2", "Lynx", "XL", "EB164", "Noritake",
691 	"Cortex", "29", "Miata", "XXM", "Takara", "Yukon",
692 	"Tsunami", "Wildfire", "CUSCO", "Eiger", "Titan", "Marvel"
693 };
694 
695 static char unofficial_names[][8] = {"100", "Ruffian"};
696 
697 static char api_names[][16] = {"200", "Nautilus"};
698 
699 static char eb164_names[][8] = {"EB164", "PC164", "LX164", "SX164", "RX164"};
700 static int eb164_indices[] = {0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,4};
701 
702 static char alcor_names[][16] = {"Alcor", "Maverick", "Bret"};
703 static int alcor_indices[] = {0,0,0,1,1,1,0,0,0,0,0,0,2,2,2,2,2,2};
704 
705 static char eb64p_names[][16] = {"EB64+", "Cabriolet", "AlphaPCI64"};
706 static int eb64p_indices[] = {0,0,1,2};
707 
708 static char eb66_names[][8] = {"EB66", "EB66+"};
709 static int eb66_indices[] = {0,0,1};
710 
711 static char marvel_names[][16] = {
712 	"Marvel/EV7"
713 };
714 static int marvel_indices[] = { 0 };
715 
716 static char rawhide_names[][16] = {
717 	"Dodge", "Wrangler", "Durango", "Tincup", "DaVinci"
718 };
719 static int rawhide_indices[] = {0,0,0,1,1,2,2,3,3,4,4};
720 
721 static char titan_names[][16] = {
722 	"DEFAULT", "Privateer", "Falcon", "Granite"
723 };
724 static int titan_indices[] = {0,1,2,2,3};
725 
726 static char tsunami_names[][16] = {
727 	"0", "DP264", "Warhol", "Windjammer", "Monet", "Clipper",
728 	"Goldrush", "Webbrick", "Catamaran", "Brisbane", "Melbourne",
729 	"Flying Clipper", "Shark"
730 };
731 static int tsunami_indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12};
732 
733 static struct alpha_machine_vector * __init
get_sysvec(long type,long variation,long cpu)734 get_sysvec(long type, long variation, long cpu)
735 {
736 	static struct alpha_machine_vector *systype_vecs[] __initdata =
737 	{
738 		NULL,		/* 0 */
739 		NULL,		/* ADU */
740 		NULL,		/* Cobra */
741 		NULL,		/* Ruby */
742 		NULL,		/* Flamingo */
743 		NULL,		/* Mannequin */
744 		&jensen_mv,
745 		NULL, 		/* Pelican */
746 		NULL,		/* Morgan */
747 		NULL,		/* Sable -- see below.  */
748 		NULL,		/* Medulla */
749 		&noname_mv,
750 		NULL,		/* Turbolaser */
751 		&avanti_mv,
752 		NULL,		/* Mustang */
753 		NULL,		/* Alcor, Bret, Maverick. HWRPB inaccurate? */
754 		NULL,		/* Tradewind */
755 		NULL,		/* Mikasa -- see below.  */
756 		NULL,		/* EB64 */
757 		NULL,		/* EB66 -- see variation.  */
758 		NULL,		/* EB64+ -- see variation.  */
759 		&alphabook1_mv,
760 		&rawhide_mv,
761 		NULL,		/* K2 */
762 		&lynx_mv,	/* Lynx */
763 		&xl_mv,
764 		NULL,		/* EB164 -- see variation.  */
765 		NULL,		/* Noritake -- see below.  */
766 		NULL,		/* Cortex */
767 		NULL,		/* 29 */
768 		&miata_mv,
769 		NULL,		/* XXM */
770 		&takara_mv,
771 		NULL,		/* Yukon */
772 		NULL,		/* Tsunami -- see variation.  */
773 		&wildfire_mv,	/* Wildfire */
774 		NULL,		/* CUSCO */
775 		&eiger_mv,	/* Eiger */
776 		NULL,		/* Titan */
777 		NULL,		/* Marvel */
778 	};
779 
780 	static struct alpha_machine_vector *unofficial_vecs[] __initdata =
781 	{
782 		NULL,		/* 100 */
783 		&ruffian_mv,
784 	};
785 
786 	static struct alpha_machine_vector *api_vecs[] __initdata =
787 	{
788 		NULL,		/* 200 */
789 		&nautilus_mv,
790 	};
791 
792 	static struct alpha_machine_vector *alcor_vecs[] __initdata =
793 	{
794 		&alcor_mv, &xlt_mv, &xlt_mv
795 	};
796 
797 	static struct alpha_machine_vector *eb164_vecs[] __initdata =
798 	{
799 		&eb164_mv, &pc164_mv, &lx164_mv, &sx164_mv, &rx164_mv
800 	};
801 
802 	static struct alpha_machine_vector *eb64p_vecs[] __initdata =
803 	{
804 		&eb64p_mv,
805 		&cabriolet_mv,
806 		&cabriolet_mv		/* AlphaPCI64 */
807 	};
808 
809 	static struct alpha_machine_vector *eb66_vecs[] __initdata =
810 	{
811 		&eb66_mv,
812 		&eb66p_mv
813 	};
814 
815 	static struct alpha_machine_vector *marvel_vecs[] __initdata =
816 	{
817 		&marvel_ev7_mv,
818 	};
819 
820 	static struct alpha_machine_vector *titan_vecs[] __initdata =
821 	{
822 		&titan_mv,		/* default   */
823 		&privateer_mv,		/* privateer */
824 		&titan_mv,		/* falcon    */
825 		&privateer_mv,		/* granite   */
826 	};
827 
828 	static struct alpha_machine_vector *tsunami_vecs[]  __initdata =
829 	{
830 		NULL,
831 		&dp264_mv,		/* dp264 */
832 		&dp264_mv,		/* warhol */
833 		&dp264_mv,		/* windjammer */
834 		&monet_mv,		/* monet */
835 		&clipper_mv,		/* clipper */
836 		&dp264_mv,		/* goldrush */
837 		&webbrick_mv,		/* webbrick */
838 		&dp264_mv,		/* catamaran */
839 		NULL,			/* brisbane? */
840 		NULL,			/* melbourne? */
841 		NULL,			/* flying clipper? */
842 		&shark_mv,		/* shark */
843 	};
844 
845 	/* ??? Do we need to distinguish between Rawhides?  */
846 
847 	struct alpha_machine_vector *vec;
848 
849 	/* Restore real CABRIO and EB66+ family names, ie EB64+ and EB66 */
850 	if (type < 0)
851 		type = -type;
852 
853 	/* Search the system tables first... */
854 	vec = NULL;
855 	if (type < N(systype_vecs)) {
856 		vec = systype_vecs[type];
857 	} else if ((type > ST_API_BIAS) &&
858 		   (type - ST_API_BIAS) < N(api_vecs)) {
859 		vec = api_vecs[type - ST_API_BIAS];
860 	} else if ((type > ST_UNOFFICIAL_BIAS) &&
861 		   (type - ST_UNOFFICIAL_BIAS) < N(unofficial_vecs)) {
862 		vec = unofficial_vecs[type - ST_UNOFFICIAL_BIAS];
863 	}
864 
865 	/* If we've not found one, try for a variation.  */
866 
867 	if (!vec) {
868 		/* Member ID is a bit-field. */
869 		long member = (variation >> 10) & 0x3f;
870 
871 		cpu &= 0xffffffff; /* make it usable */
872 
873 		switch (type) {
874 		case ST_DEC_ALCOR:
875 			if (member < N(alcor_indices))
876 				vec = alcor_vecs[alcor_indices[member]];
877 			break;
878 		case ST_DEC_EB164:
879 			if (member < N(eb164_indices))
880 				vec = eb164_vecs[eb164_indices[member]];
881 			/* PC164 may show as EB164 variation with EV56 CPU,
882 			   but, since no true EB164 had anything but EV5... */
883 			if (vec == &eb164_mv && cpu == EV56_CPU)
884 				vec = &pc164_mv;
885 			break;
886 		case ST_DEC_EB64P:
887 			if (member < N(eb64p_indices))
888 				vec = eb64p_vecs[eb64p_indices[member]];
889 			break;
890 		case ST_DEC_EB66:
891 			if (member < N(eb66_indices))
892 				vec = eb66_vecs[eb66_indices[member]];
893 			break;
894 		case ST_DEC_MARVEL:
895 			if (member < N(marvel_indices))
896 				vec = marvel_vecs[marvel_indices[member]];
897 			break;
898 		case ST_DEC_TITAN:
899 			vec = titan_vecs[0];	/* default */
900 			if (member < N(titan_indices))
901 				vec = titan_vecs[titan_indices[member]];
902 			break;
903 		case ST_DEC_TSUNAMI:
904 			if (member < N(tsunami_indices))
905 				vec = tsunami_vecs[tsunami_indices[member]];
906 			break;
907 		case ST_DEC_1000:
908 			if (cpu == EV5_CPU || cpu == EV56_CPU)
909 				vec = &mikasa_primo_mv;
910 			else
911 				vec = &mikasa_mv;
912 			break;
913 		case ST_DEC_NORITAKE:
914 			if (cpu == EV5_CPU || cpu == EV56_CPU)
915 				vec = &noritake_primo_mv;
916 			else
917 				vec = &noritake_mv;
918 			break;
919 		case ST_DEC_2100_A500:
920 			if (cpu == EV5_CPU || cpu == EV56_CPU)
921 				vec = &sable_gamma_mv;
922 			else
923 				vec = &sable_mv;
924 			break;
925 		}
926 	}
927 	return vec;
928 }
929 
930 static struct alpha_machine_vector * __init
get_sysvec_byname(const char * name)931 get_sysvec_byname(const char *name)
932 {
933 	static struct alpha_machine_vector *all_vecs[] __initdata =
934 	{
935 		&alcor_mv,
936 		&alphabook1_mv,
937 		&avanti_mv,
938 		&cabriolet_mv,
939 		&clipper_mv,
940 		&dp264_mv,
941 		&eb164_mv,
942 		&eb64p_mv,
943 		&eb66_mv,
944 		&eb66p_mv,
945 		&eiger_mv,
946 		&jensen_mv,
947 		&lx164_mv,
948 		&lynx_mv,
949 		&miata_mv,
950 		&mikasa_mv,
951 		&mikasa_primo_mv,
952 		&monet_mv,
953 		&nautilus_mv,
954 		&noname_mv,
955 		&noritake_mv,
956 		&noritake_primo_mv,
957 		&p2k_mv,
958 		&pc164_mv,
959 		&privateer_mv,
960 		&rawhide_mv,
961 		&ruffian_mv,
962 		&rx164_mv,
963 		&sable_mv,
964 		&sable_gamma_mv,
965 		&shark_mv,
966 		&sx164_mv,
967 		&takara_mv,
968 		&webbrick_mv,
969 		&wildfire_mv,
970 		&xl_mv,
971 		&xlt_mv
972 	};
973 
974 	int i, n = sizeof(all_vecs)/sizeof(*all_vecs);
975 	for (i = 0; i < n; ++i) {
976 		struct alpha_machine_vector *mv = all_vecs[i];
977 		if (strcasecmp(mv->vector_name, name) == 0)
978 			return mv;
979 	}
980 	return NULL;
981 }
982 
983 static void
get_sysnames(long type,long variation,long cpu,char ** type_name,char ** variation_name)984 get_sysnames(long type, long variation, long cpu,
985 	     char **type_name, char **variation_name)
986 {
987 	long member;
988 
989 	/* Restore real CABRIO and EB66+ family names, ie EB64+ and EB66 */
990 	if (type < 0)
991 		type = -type;
992 
993 	/* If not in the tables, make it UNKNOWN,
994 	   else set type name to family */
995 	if (type < N(systype_names)) {
996 		*type_name = systype_names[type];
997 	} else if ((type > ST_API_BIAS) &&
998 		   (type - ST_API_BIAS) < N(api_names)) {
999 		*type_name = api_names[type - ST_API_BIAS];
1000 	} else if ((type > ST_UNOFFICIAL_BIAS) &&
1001 		   (type - ST_UNOFFICIAL_BIAS) < N(unofficial_names)) {
1002 		*type_name = unofficial_names[type - ST_UNOFFICIAL_BIAS];
1003 	} else {
1004 		*type_name = sys_unknown;
1005 		*variation_name = sys_unknown;
1006 		return;
1007 	}
1008 
1009 	/* Set variation to "0"; if variation is zero, done */
1010 	*variation_name = systype_names[0];
1011 	if (variation == 0) {
1012 		return;
1013 	}
1014 
1015 	member = (variation >> 10) & 0x3f; /* member ID is a bit-field */
1016 
1017 	cpu &= 0xffffffff; /* make it usable */
1018 
1019 	switch (type) { /* select by family */
1020 	default: /* default to variation "0" for now */
1021 		break;
1022 	case ST_DEC_EB164:
1023 		if (member < N(eb164_indices))
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 < N(alcor_indices))
1032 			*variation_name = alcor_names[alcor_indices[member]];
1033 		break;
1034 	case ST_DEC_EB64P:
1035 		if (member < N(eb64p_indices))
1036 			*variation_name = eb64p_names[eb64p_indices[member]];
1037 		break;
1038 	case ST_DEC_EB66:
1039 		if (member < N(eb66_indices))
1040 			*variation_name = eb66_names[eb66_indices[member]];
1041 		break;
1042 	case ST_DEC_MARVEL:
1043 		if (member < N(marvel_indices))
1044 			*variation_name = marvel_names[marvel_indices[member]];
1045 		break;
1046 	case ST_DEC_RAWHIDE:
1047 		if (member < N(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 < N(titan_indices))
1053 			*variation_name = titan_names[titan_indices[member]];
1054 		break;
1055 	case ST_DEC_TSUNAMI:
1056 		if (member < N(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 *
platform_string(void)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
get_nr_processors(struct percpu_struct * cpubase,unsigned long num)1101 get_nr_processors(struct percpu_struct *cpubase, unsigned long num)
1102 {
1103 	struct percpu_struct *cpu;
1104 	int i, count = 0;
1105 
1106 	for (i = 0; i < num; i++) {
1107 		cpu = (struct percpu_struct *)
1108 			((char *)cpubase + i*hwrpb->processor_size);
1109 		if ((cpu->flags & 0x1cc) == 0x1cc)
1110 			count++;
1111 	}
1112 	return count;
1113 }
1114 
1115 
1116 static int
show_cpuinfo(struct seq_file * f,void * slot)1117 show_cpuinfo(struct seq_file *f, void *slot)
1118 {
1119 	extern struct unaligned_stat {
1120 		unsigned long count, va, pc;
1121 	} unaligned[2];
1122 
1123 	static char cpu_names[][8] = {
1124 		"EV3", "EV4", "Simulate", "LCA4", "EV5", "EV45", "EV56",
1125 		"EV6", "PCA56", "PCA57", "EV67", "EV68CB", "EV68AL",
1126 		"EV68CX", "EV7", "EV79", "EV69"
1127 	};
1128 
1129 	struct percpu_struct *cpu = slot;
1130 	unsigned int cpu_index;
1131 	char *cpu_name;
1132 	char *systype_name;
1133 	char *sysvariation_name;
1134 	int nr_processors;
1135 
1136 	cpu_index = (unsigned) (cpu->type - 1);
1137 	cpu_name = "Unknown";
1138 	if (cpu_index < N(cpu_names))
1139 		cpu_name = cpu_names[cpu_index];
1140 
1141 	get_sysnames(hwrpb->sys_type, hwrpb->sys_variation,
1142 		     cpu->type, &systype_name, &sysvariation_name);
1143 
1144 	nr_processors = get_nr_processors(cpu, hwrpb->nr_processors);
1145 
1146 	seq_printf(f, "cpu\t\t\t: Alpha\n"
1147 		      "cpu model\t\t: %s\n"
1148 		      "cpu variation\t\t: %ld\n"
1149 		      "cpu revision\t\t: %ld\n"
1150 		      "cpu serial number\t: %s\n"
1151 		      "system type\t\t: %s\n"
1152 		      "system variation\t: %s\n"
1153 		      "system revision\t\t: %ld\n"
1154 		      "system serial number\t: %s\n"
1155 		      "cycle frequency [Hz]\t: %lu %s\n"
1156 		      "timer frequency [Hz]\t: %lu.%02lu\n"
1157 		      "page size [bytes]\t: %ld\n"
1158 		      "phys. address bits\t: %ld\n"
1159 		      "max. addr. space #\t: %ld\n"
1160 		      "BogoMIPS\t\t: %lu.%02lu\n"
1161 		      "kernel unaligned acc\t: %ld (pc=%lx,va=%lx)\n"
1162 		      "user unaligned acc\t: %ld (pc=%lx,va=%lx)\n"
1163 		      "platform string\t\t: %s\n"
1164 		      "cpus detected\t\t: %d\n",
1165 		       cpu_name, cpu->variation, cpu->revision,
1166 		       (char*)cpu->serial_no,
1167 		       systype_name, sysvariation_name, hwrpb->sys_revision,
1168 		       (char*)hwrpb->ssn,
1169 		       est_cycle_freq ? : hwrpb->cycle_freq,
1170 		       est_cycle_freq ? "est." : "",
1171 		       hwrpb->intr_freq / 4096,
1172 		       (100 * hwrpb->intr_freq / 4096) % 100,
1173 		       hwrpb->pagesize,
1174 		       hwrpb->pa_bits,
1175 		       hwrpb->max_asn,
1176 		       loops_per_jiffy / (500000/HZ),
1177 		       (loops_per_jiffy / (5000/HZ)) % 100,
1178 		       unaligned[0].count, unaligned[0].pc, unaligned[0].va,
1179 		       unaligned[1].count, unaligned[1].pc, unaligned[1].va,
1180 		       platform_string(), nr_processors);
1181 
1182 #ifdef CONFIG_SMP
1183 	seq_printf(f, "cpus active\t\t: %d\n"
1184 		      "cpu active mask\t\t: %016lx\n",
1185 		       smp_num_cpus, cpu_present_mask);
1186 #endif
1187 
1188 	return 0;
1189 }
1190 
1191 /*
1192  * We show only CPU #0 info.
1193  */
1194 static void *
c_start(struct seq_file * f,loff_t * pos)1195 c_start(struct seq_file *f, loff_t *pos)
1196 {
1197 	return *pos ? NULL : (char *)hwrpb + hwrpb->processor_offset;
1198 }
1199 
1200 static void *
c_next(struct seq_file * f,void * v,loff_t * pos)1201 c_next(struct seq_file *f, void *v, loff_t *pos)
1202 {
1203 	return NULL;
1204 }
1205 
1206 static void
c_stop(struct seq_file * f,void * v)1207 c_stop(struct seq_file *f, void *v)
1208 {
1209 }
1210 
1211 struct seq_operations cpuinfo_op = {
1212 	start:	c_start,
1213 	next:	c_next,
1214 	stop:	c_stop,
1215 	show:	show_cpuinfo,
1216 };
1217 
1218 
alpha_panic_event(struct notifier_block * this,unsigned long event,void * ptr)1219 static int alpha_panic_event(struct notifier_block *this,
1220 			     unsigned long event,
1221 			     void *ptr)
1222 {
1223 #if 1
1224 	/* FIXME FIXME FIXME */
1225 	/* If we are using SRM and serial console, just hard halt here. */
1226 	if (alpha_using_srm && srmcons_output)
1227 		__halt();
1228 #endif
1229         return NOTIFY_DONE;
1230 }
1231