blob: 6d6178efd5872bc946e176c870b24432fab274b9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: setup.c,v 1.72 2002/02/09 19:49:30 davem Exp $
2 * linux/arch/sparc64/kernel/setup.c
3 *
4 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 */
7
8#include <linux/errno.h>
9#include <linux/sched.h>
10#include <linux/kernel.h>
11#include <linux/mm.h>
12#include <linux/stddef.h>
13#include <linux/unistd.h>
14#include <linux/ptrace.h>
15#include <linux/slab.h>
16#include <asm/smp.h>
17#include <linux/user.h>
18#include <linux/a.out.h>
19#include <linux/tty.h>
20#include <linux/delay.h>
21#include <linux/config.h>
22#include <linux/fs.h>
23#include <linux/seq_file.h>
24#include <linux/syscalls.h>
25#include <linux/kdev_t.h>
26#include <linux/major.h>
27#include <linux/string.h>
28#include <linux/init.h>
29#include <linux/inet.h>
30#include <linux/console.h>
31#include <linux/root_dev.h>
32#include <linux/interrupt.h>
33#include <linux/cpu.h>
34#include <linux/initrd.h>
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/system.h>
37#include <asm/io.h>
38#include <asm/processor.h>
39#include <asm/oplib.h>
40#include <asm/page.h>
41#include <asm/pgtable.h>
42#include <asm/idprom.h>
43#include <asm/head.h>
44#include <asm/starfire.h>
45#include <asm/mmu_context.h>
46#include <asm/timer.h>
47#include <asm/sections.h>
48#include <asm/setup.h>
49#include <asm/mmu.h>
50
51#ifdef CONFIG_IP_PNP
52#include <net/ipconfig.h>
53#endif
54
55struct screen_info screen_info = {
56 0, 0, /* orig-x, orig-y */
57 0, /* unused */
58 0, /* orig-video-page */
59 0, /* orig-video-mode */
60 128, /* orig-video-cols */
61 0, 0, 0, /* unused, ega_bx, unused */
62 54, /* orig-video-lines */
63 0, /* orig-video-isVGA */
64 16 /* orig-video-points */
65};
66
67/* Typing sync at the prom prompt calls the function pointed to by
68 * the sync callback which I set to the following function.
69 * This should sync all filesystems and return, for now it just
70 * prints out pretty messages and returns.
71 */
72
73void (*prom_palette)(int);
74void (*prom_keyboard)(void);
75
76static void
77prom_console_write(struct console *con, const char *s, unsigned n)
78{
79 prom_write(s, n);
80}
81
82static struct console prom_console = {
83 .name = "prom",
84 .write = prom_console_write,
85 .flags = CON_CONSDEV | CON_ENABLED,
86 .index = -1,
87};
88
89#define PROM_TRUE -1
90#define PROM_FALSE 0
91
92/* Pretty sick eh? */
93int prom_callback(long *args)
94{
95 struct console *cons, *saved_console = NULL;
96 unsigned long flags;
97 char *cmd;
98 extern spinlock_t prom_entry_lock;
99
100 if (!args)
101 return -1;
102 if (!(cmd = (char *)args[0]))
103 return -1;
104
105 /*
106 * The callback can be invoked on the cpu that first dropped
107 * into prom_cmdline after taking the serial interrupt, or on
108 * a slave processor that was smp_captured() if the
109 * administrator has done a switch-cpu inside obp. In either
110 * case, the cpu is marked as in-interrupt. Drop IRQ locks.
111 */
112 irq_exit();
113
114 /* XXX Revisit the locking here someday. This is a debugging
115 * XXX feature so it isnt all that critical. -DaveM
116 */
117 local_irq_save(flags);
118
119 spin_unlock(&prom_entry_lock);
120 cons = console_drivers;
121 while (cons) {
122 unregister_console(cons);
123 cons->flags &= ~(CON_PRINTBUFFER);
124 cons->next = saved_console;
125 saved_console = cons;
126 cons = console_drivers;
127 }
128 register_console(&prom_console);
129 if (!strcmp(cmd, "sync")) {
130 prom_printf("PROM `%s' command...\n", cmd);
131 show_free_areas();
132 if (current->pid != 0) {
133 local_irq_enable();
134 sys_sync();
135 local_irq_disable();
136 }
137 args[2] = 0;
138 args[args[1] + 3] = -1;
139 prom_printf("Returning to PROM\n");
140 } else if (!strcmp(cmd, "va>tte-data")) {
141 unsigned long ctx, va;
142 unsigned long tte = 0;
143 long res = PROM_FALSE;
144
145 ctx = args[3];
146 va = args[4];
147 if (ctx) {
148 /*
149 * Find process owning ctx, lookup mapping.
150 */
151 struct task_struct *p;
152 struct mm_struct *mm = NULL;
153 pgd_t *pgdp;
154 pud_t *pudp;
155 pmd_t *pmdp;
156 pte_t *ptep;
Hugh Dickinsb8ae4862005-11-07 14:08:46 -0800157 pte_t pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 for_each_process(p) {
160 mm = p->mm;
161 if (CTX_NRBITS(mm->context) == ctx)
162 break;
163 }
164 if (!mm ||
165 CTX_NRBITS(mm->context) != ctx)
166 goto done;
167
168 pgdp = pgd_offset(mm, va);
169 if (pgd_none(*pgdp))
170 goto done;
171 pudp = pud_offset(pgdp, va);
172 if (pud_none(*pudp))
173 goto done;
174 pmdp = pmd_offset(pudp, va);
175 if (pmd_none(*pmdp))
176 goto done;
177
178 /* Preemption implicitly disabled by virtue of
179 * being called from inside OBP.
180 */
181 ptep = pte_offset_map(pmdp, va);
Hugh Dickinsb8ae4862005-11-07 14:08:46 -0800182 pte = *ptep;
183 if (pte_present(pte)) {
184 tte = pte_val(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 res = PROM_TRUE;
186 }
187 pte_unmap(ptep);
188 goto done;
189 }
190
191 if ((va >= KERNBASE) && (va < (KERNBASE + (4 * 1024 * 1024)))) {
David S. Miller0835ae02005-10-04 15:23:20 -0700192 extern unsigned long sparc64_kern_pri_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 /* Spitfire Errata #32 workaround */
195 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
196 "flush %%g6"
197 : /* No outputs */
David S. Miller0835ae02005-10-04 15:23:20 -0700198 : "r" (sparc64_kern_pri_context),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 "r" (PRIMARY_CONTEXT),
200 "i" (ASI_DMMU));
201
202 /*
203 * Locked down tlb entry.
204 */
205
206 if (tlb_type == spitfire)
207 tte = spitfire_get_dtlb_data(SPITFIRE_HIGHEST_LOCKED_TLBENT);
208 else if (tlb_type == cheetah || tlb_type == cheetah_plus)
209 tte = cheetah_get_ldtlb_data(CHEETAH_HIGHEST_LOCKED_TLBENT);
210
211 res = PROM_TRUE;
212 goto done;
213 }
214
215 if (va < PGDIR_SIZE) {
216 /*
217 * vmalloc or prom_inherited mapping.
218 */
219 pgd_t *pgdp;
220 pud_t *pudp;
221 pmd_t *pmdp;
222 pte_t *ptep;
Hugh Dickinsb8ae4862005-11-07 14:08:46 -0800223 pte_t pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 int error;
225
226 if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) {
227 tte = prom_virt_to_phys(va, &error);
228 if (!error)
229 res = PROM_TRUE;
230 goto done;
231 }
232 pgdp = pgd_offset_k(va);
233 if (pgd_none(*pgdp))
234 goto done;
235 pudp = pud_offset(pgdp, va);
236 if (pud_none(*pudp))
237 goto done;
238 pmdp = pmd_offset(pudp, va);
239 if (pmd_none(*pmdp))
240 goto done;
241
242 /* Preemption implicitly disabled by virtue of
243 * being called from inside OBP.
244 */
245 ptep = pte_offset_kernel(pmdp, va);
Hugh Dickinsb8ae4862005-11-07 14:08:46 -0800246 pte = *ptep;
247 if (pte_present(pte)) {
248 tte = pte_val(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 res = PROM_TRUE;
250 }
251 goto done;
252 }
253
254 if (va < PAGE_OFFSET) {
255 /*
256 * No mappings here.
257 */
258 goto done;
259 }
260
261 if (va & (1UL << 40)) {
262 /*
263 * I/O page.
264 */
265
266 tte = (__pa(va) & _PAGE_PADDR) |
267 _PAGE_VALID | _PAGE_SZ4MB |
268 _PAGE_E | _PAGE_P | _PAGE_W;
269 res = PROM_TRUE;
270 goto done;
271 }
272
273 /*
274 * Normal page.
275 */
276 tte = (__pa(va) & _PAGE_PADDR) |
277 _PAGE_VALID | _PAGE_SZ4MB |
278 _PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W;
279 res = PROM_TRUE;
280
281 done:
282 if (res == PROM_TRUE) {
283 args[2] = 3;
284 args[args[1] + 3] = 0;
285 args[args[1] + 4] = res;
286 args[args[1] + 5] = tte;
287 } else {
288 args[2] = 2;
289 args[args[1] + 3] = 0;
290 args[args[1] + 4] = res;
291 }
292 } else if (!strcmp(cmd, ".soft1")) {
293 unsigned long tte;
294
295 tte = args[3];
296 prom_printf("%lx:\"%s%s%s%s%s\" ",
297 (tte & _PAGE_SOFT) >> 7,
298 tte & _PAGE_MODIFIED ? "M" : "-",
299 tte & _PAGE_ACCESSED ? "A" : "-",
300 tte & _PAGE_READ ? "W" : "-",
301 tte & _PAGE_WRITE ? "R" : "-",
302 tte & _PAGE_PRESENT ? "P" : "-");
303
304 args[2] = 2;
305 args[args[1] + 3] = 0;
306 args[args[1] + 4] = PROM_TRUE;
307 } else if (!strcmp(cmd, ".soft2")) {
308 unsigned long tte;
309
310 tte = args[3];
311 prom_printf("%lx ", (tte & 0x07FC000000000000UL) >> 50);
312
313 args[2] = 2;
314 args[args[1] + 3] = 0;
315 args[args[1] + 4] = PROM_TRUE;
316 } else {
317 prom_printf("unknown PROM `%s' command...\n", cmd);
318 }
319 unregister_console(&prom_console);
320 while (saved_console) {
321 cons = saved_console;
322 saved_console = cons->next;
323 register_console(cons);
324 }
325 spin_lock(&prom_entry_lock);
326 local_irq_restore(flags);
327
328 /*
329 * Restore in-interrupt status for a resume from obp.
330 */
331 irq_enter();
332 return 0;
333}
334
335unsigned int boot_flags = 0;
336#define BOOTME_DEBUG 0x1
337#define BOOTME_SINGLE 0x2
338
339/* Exported for mm/init.c:paging_init. */
340unsigned long cmdline_memory_size = 0;
341
342static struct console prom_debug_console = {
343 .name = "debug",
344 .write = prom_console_write,
345 .flags = CON_PRINTBUFFER,
346 .index = -1,
347};
348
349/* XXX Implement this at some point... */
350void kernel_enter_debugger(void)
351{
352}
353
354int obp_system_intr(void)
355{
356 if (boot_flags & BOOTME_DEBUG) {
357 printk("OBP: system interrupted\n");
358 prom_halt();
359 return 1;
360 }
361 return 0;
362}
363
364/*
365 * Process kernel command line switches that are specific to the
366 * SPARC or that require special low-level processing.
367 */
368static void __init process_switch(char c)
369{
370 switch (c) {
371 case 'd':
372 boot_flags |= BOOTME_DEBUG;
373 break;
374 case 's':
375 boot_flags |= BOOTME_SINGLE;
376 break;
377 case 'h':
378 prom_printf("boot_flags_init: Halt!\n");
379 prom_halt();
380 break;
381 case 'p':
382 /* Use PROM debug console. */
383 register_console(&prom_debug_console);
384 break;
David S. Miller816242d2005-05-23 15:52:08 -0700385 case 'P':
386 /* Force UltraSPARC-III P-Cache on. */
387 if (tlb_type != cheetah) {
388 printk("BOOT: Ignoring P-Cache force option.\n");
389 break;
390 }
391 cheetah_pcache_forced_on = 1;
392 add_taint(TAINT_MACHINE_CHECK);
393 cheetah_enable_pcache();
394 break;
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 default:
397 printk("Unknown boot switch (-%c)\n", c);
398 break;
399 }
400}
401
402static void __init process_console(char *commands)
403{
404 serial_console = 0;
405 commands += 8;
406 /* Linux-style serial */
407 if (!strncmp(commands, "ttyS", 4))
408 serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
409 else if (!strncmp(commands, "tty", 3)) {
410 char c = *(commands + 3);
411 /* Solaris-style serial */
412 if (c == 'a' || c == 'b') {
413 serial_console = c - 'a' + 1;
414 prom_printf ("Using /dev/tty%c as console.\n", c);
415 }
416 /* else Linux-style fbcon, not serial */
417 }
418#if defined(CONFIG_PROM_CONSOLE)
419 if (!strncmp(commands, "prom", 4)) {
420 char *p;
421
422 for (p = commands - 8; *p && *p != ' '; p++)
423 *p = ' ';
424 conswitchp = &prom_con;
425 }
426#endif
427}
428
429static void __init boot_flags_init(char *commands)
430{
431 while (*commands) {
432 /* Move to the start of the next "argument". */
433 while (*commands && *commands == ' ')
434 commands++;
435
436 /* Process any command switches, otherwise skip it. */
437 if (*commands == '\0')
438 break;
439 if (*commands == '-') {
440 commands++;
441 while (*commands && *commands != ' ')
442 process_switch(*commands++);
443 continue;
444 }
445 if (!strncmp(commands, "console=", 8)) {
446 process_console(commands);
447 } else if (!strncmp(commands, "mem=", 4)) {
448 /*
449 * "mem=XXX[kKmM]" overrides the PROM-reported
450 * memory size.
451 */
452 cmdline_memory_size = simple_strtoul(commands + 4,
453 &commands, 0);
454 if (*commands == 'K' || *commands == 'k') {
455 cmdline_memory_size <<= 10;
456 commands++;
457 } else if (*commands=='M' || *commands=='m') {
458 cmdline_memory_size <<= 20;
459 commands++;
460 }
461 }
462 while (*commands && *commands != ' ')
463 commands++;
464 }
465}
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467extern void panic_setup(char *, int *);
468
469extern unsigned short root_flags;
470extern unsigned short root_dev;
471extern unsigned short ram_flags;
472#define RAMDISK_IMAGE_START_MASK 0x07FF
473#define RAMDISK_PROMPT_FLAG 0x8000
474#define RAMDISK_LOAD_FLAG 0x4000
475
476extern int root_mountflags;
477
478char reboot_command[COMMAND_LINE_SIZE];
479
480static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
481
482void register_prom_callbacks(void)
483{
484 prom_setcallback(prom_callback);
485 prom_feval(": linux-va>tte-data 2 \" va>tte-data\" $callback drop ; "
486 "' linux-va>tte-data to va>tte-data");
487 prom_feval(": linux-.soft1 1 \" .soft1\" $callback 2drop ; "
488 "' linux-.soft1 to .soft1");
489 prom_feval(": linux-.soft2 1 \" .soft2\" $callback 2drop ; "
490 "' linux-.soft2 to .soft2");
491}
492
David S. Miller92704a12006-02-26 23:27:19 -0800493static void __init per_cpu_patch(void)
494{
495#ifdef CONFIG_SMP
496 struct cpuid_patch_entry *p;
497 unsigned long ver;
498 int is_jbus;
499
500 if (tlb_type == spitfire && !this_is_starfire)
501 return;
502
503 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
504 is_jbus = ((ver >> 32) == __JALAPENO_ID ||
505 (ver >> 32) == __SERRANO_ID);
506
507 p = &__cpuid_patch;
508 while (p < &__cpuid_patch_end) {
509 unsigned long addr = p->addr;
510 unsigned int *insns;
511
512 switch (tlb_type) {
513 case spitfire:
514 insns = &p->starfire[0];
515 break;
516 case cheetah:
517 case cheetah_plus:
518 if (is_jbus)
519 insns = &p->cheetah_jbus[0];
520 else
521 insns = &p->cheetah_safari[0];
522 break;
David S. Millerd96b8152006-02-04 15:40:53 -0800523 case hypervisor:
524 insns = &p->sun4v[0];
525 break;
David S. Miller92704a12006-02-26 23:27:19 -0800526 default:
527 prom_printf("Unknown cpu type, halting.\n");
528 prom_halt();
529 };
530
531 *(unsigned int *) (addr + 0) = insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800532 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800533 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
534
535 *(unsigned int *) (addr + 4) = insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800536 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800537 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
538
539 *(unsigned int *) (addr + 8) = insns[2];
David S. Miller840aaef2006-02-06 15:52:05 -0800540 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800541 __asm__ __volatile__("flush %0" : : "r" (addr + 8));
542
543 *(unsigned int *) (addr + 12) = insns[3];
David S. Miller840aaef2006-02-06 15:52:05 -0800544 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800545 __asm__ __volatile__("flush %0" : : "r" (addr + 12));
546
547 p++;
548 }
549#endif
550}
551
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800552static void __init sun4v_patch(void)
David S. Miller936f4822006-02-05 21:29:28 -0800553{
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800554 struct sun4v_1insn_patch_entry *p1;
555 struct sun4v_2insn_patch_entry *p2;
David S. Miller936f4822006-02-05 21:29:28 -0800556
557 if (tlb_type != hypervisor)
558 return;
559
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800560 p1 = &__sun4v_1insn_patch;
561 while (p1 < &__sun4v_1insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800562 unsigned long addr = p1->addr;
David S. Miller936f4822006-02-05 21:29:28 -0800563
David S. Miller45fec052006-02-05 22:27:28 -0800564 *(unsigned int *) (addr + 0) = p1->insn;
David S. Miller840aaef2006-02-06 15:52:05 -0800565 wmb();
David S. Miller936f4822006-02-05 21:29:28 -0800566 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
567
David S. Miller45fec052006-02-05 22:27:28 -0800568 p1++;
569 }
570
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800571 p2 = &__sun4v_2insn_patch;
572 while (p2 < &__sun4v_2insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800573 unsigned long addr = p2->addr;
574
575 *(unsigned int *) (addr + 0) = p2->insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800576 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800577 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
578
579 *(unsigned int *) (addr + 3) = p2->insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800580 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800581 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
582
583 p2++;
David S. Miller936f4822006-02-05 21:29:28 -0800584 }
585}
586
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587void __init setup_arch(char **cmdline_p)
588{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 /* Initialize PROM console and command line. */
590 *cmdline_p = prom_getbootargs();
591 strcpy(saved_command_line, *cmdline_p);
592
593 printk("ARCH: SUN4U\n");
594
595#ifdef CONFIG_DUMMY_CONSOLE
596 conswitchp = &dummy_con;
597#elif defined(CONFIG_PROM_CONSOLE)
598 conswitchp = &prom_con;
599#endif
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 /* Work out if we are starfire early on */
602 check_if_starfire();
603
David S. Miller92704a12006-02-26 23:27:19 -0800604 /* Now we know enough to patch the get_cpuid sequences
605 * used by trap code.
David S. Miller56fb4df2006-02-26 23:24:22 -0800606 */
607 per_cpu_patch();
608
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800609 sun4v_patch();
David S. Miller936f4822006-02-05 21:29:28 -0800610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 boot_flags_init(*cmdline_p);
612
613 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 if (!root_flags)
616 root_mountflags &= ~MS_RDONLY;
617 ROOT_DEV = old_decode_dev(root_dev);
618#ifdef CONFIG_BLK_DEV_INITRD
619 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
620 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
621 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
622#endif
623
Al Virof3169642006-01-12 01:05:42 -0800624 task_thread_info(&init_task)->kregs = &fake_swapper_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626#ifdef CONFIG_IP_PNP
627 if (!ic_set_manually) {
628 int chosen = prom_finddevice ("/chosen");
629 u32 cl, sv, gw;
630
631 cl = prom_getintdefault (chosen, "client-ip", 0);
632 sv = prom_getintdefault (chosen, "server-ip", 0);
633 gw = prom_getintdefault (chosen, "gateway-ip", 0);
634 if (cl && sv) {
635 ic_myaddr = cl;
636 ic_servaddr = sv;
637 if (gw)
638 ic_gateway = gw;
639#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
640 ic_proto_enabled = 0;
641#endif
642 }
643 }
644#endif
645
David S. Miller7abea922006-02-25 13:39:56 -0800646 smp_setup_cpu_possible_map();
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 paging_init();
David S. Miller56fb4df2006-02-26 23:24:22 -0800649
650 /* Get boot processor trap_block[] setup. */
651 init_cur_cpu_trap();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652}
653
654static int __init set_preferred_console(void)
655{
656 int idev, odev;
657
658 /* The user has requested a console so this is already set up. */
659 if (serial_console >= 0)
660 return -EBUSY;
661
662 idev = prom_query_input_device();
663 odev = prom_query_output_device();
664 if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
665 serial_console = 0;
666 } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
667 serial_console = 1;
668 } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
669 serial_console = 2;
Eddie C. Dostc126cf82006-01-18 14:54:31 -0800670 } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
671 serial_console = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 } else {
673 prom_printf("Inconsistent console: "
674 "input %d, output %d\n",
675 idev, odev);
676 prom_halt();
677 }
678
679 if (serial_console)
680 return add_preferred_console("ttyS", serial_console - 1, NULL);
681
682 return -ENODEV;
683}
684console_initcall(set_preferred_console);
685
686/* BUFFER is PAGE_SIZE bytes long. */
687
688extern char *sparc_cpu_type;
689extern char *sparc_fpu_type;
690
691extern void smp_info(struct seq_file *);
692extern void smp_bogo(struct seq_file *);
693extern void mmu_info(struct seq_file *);
694
David S. Miller80dc0d62005-09-26 00:32:17 -0700695unsigned int dcache_parity_tl1_occurred;
696unsigned int icache_parity_tl1_occurred;
697
David S. Miller4d45cba2005-11-11 12:48:56 -0800698static int ncpus_probed;
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700static int show_cpuinfo(struct seq_file *m, void *__unused)
701{
702 seq_printf(m,
703 "cpu\t\t: %s\n"
704 "fpu\t\t: %s\n"
705 "promlib\t\t: Version 3 Revision %d\n"
706 "prom\t\t: %d.%d.%d\n"
707 "type\t\t: sun4u\n"
David S. Miller4d45cba2005-11-11 12:48:56 -0800708 "ncpus probed\t: %d\n"
709 "ncpus active\t: %d\n"
David S. Miller80dc0d62005-09-26 00:32:17 -0700710 "D$ parity tl1\t: %u\n"
711 "I$ parity tl1\t: %u\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712#ifndef CONFIG_SMP
713 "Cpu0Bogo\t: %lu.%02lu\n"
714 "Cpu0ClkTck\t: %016lx\n"
715#endif
716 ,
717 sparc_cpu_type,
718 sparc_fpu_type,
719 prom_rev,
720 prom_prev >> 16,
721 (prom_prev >> 8) & 0xff,
722 prom_prev & 0xff,
David S. Miller4d45cba2005-11-11 12:48:56 -0800723 ncpus_probed,
724 num_online_cpus(),
David S. Miller80dc0d62005-09-26 00:32:17 -0700725 dcache_parity_tl1_occurred,
726 icache_parity_tl1_occurred
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727#ifndef CONFIG_SMP
728 , cpu_data(0).udelay_val/(500000/HZ),
729 (cpu_data(0).udelay_val/(5000/HZ)) % 100,
730 cpu_data(0).clock_tick
731#endif
732 );
733#ifdef CONFIG_SMP
734 smp_bogo(m);
735#endif
736 mmu_info(m);
737#ifdef CONFIG_SMP
738 smp_info(m);
739#endif
740 return 0;
741}
742
743static void *c_start(struct seq_file *m, loff_t *pos)
744{
745 /* The pointer we are returning is arbitrary,
746 * it just has to be non-NULL and not IS_ERR
747 * in the success case.
748 */
749 return *pos == 0 ? &c_start : NULL;
750}
751
752static void *c_next(struct seq_file *m, void *v, loff_t *pos)
753{
754 ++*pos;
755 return c_start(m, pos);
756}
757
758static void c_stop(struct seq_file *m, void *v)
759{
760}
761
762struct seq_operations cpuinfo_op = {
763 .start =c_start,
764 .next = c_next,
765 .stop = c_stop,
766 .show = show_cpuinfo,
767};
768
769extern int stop_a_enabled;
770
771void sun_do_break(void)
772{
773 if (!stop_a_enabled)
774 return;
775
776 prom_printf("\n");
777 flush_user_windows();
778
779 prom_cmdline();
780}
781
782int serial_console = -1;
783int stop_a_enabled = 1;
784
785static int __init topology_init(void)
786{
787 int i, err;
788
789 err = -ENOMEM;
David S. Miller4d45cba2005-11-11 12:48:56 -0800790
791 /* Count the number of physically present processors in
792 * the machine, even on uniprocessor, so that /proc/cpuinfo
793 * output is consistent with 2.4.x
794 */
795 ncpus_probed = 0;
796 while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
797 ncpus_probed++;
798
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 for (i = 0; i < NR_CPUS; i++) {
800 if (cpu_possible(i)) {
801 struct cpu *p = kmalloc(sizeof(*p), GFP_KERNEL);
802
803 if (p) {
804 memset(p, 0, sizeof(*p));
805 register_cpu(p, i, NULL);
806 err = 0;
807 }
808 }
809 }
810
811 return err;
812}
813
814subsys_initcall(topology_init);