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