blob: cec921f6cdbf33bf156936ca96beccaa4fc00343 [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. Miller8b11bd12006-02-07 22:13:05 -0800192 if (tlb_type == spitfire) {
193 extern unsigned long sparc64_kern_pri_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
David S. Miller8b11bd12006-02-07 22:13:05 -0800195 /* Spitfire Errata #32 workaround */
196 __asm__ __volatile__(
197 "stxa %0, [%1] %2\n\t"
198 "flush %%g6"
199 : /* No outputs */
200 : "r" (sparc64_kern_pri_context),
201 "r" (PRIMARY_CONTEXT),
202 "i" (ASI_DMMU));
203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 /*
206 * Locked down tlb entry.
207 */
208
David S. Miller8b11bd12006-02-07 22:13:05 -0800209 if (tlb_type == spitfire) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 tte = spitfire_get_dtlb_data(SPITFIRE_HIGHEST_LOCKED_TLBENT);
David S. Miller8b11bd12006-02-07 22:13:05 -0800211 res = PROM_TRUE;
212 } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 tte = cheetah_get_ldtlb_data(CHEETAH_HIGHEST_LOCKED_TLBENT);
David S. Miller8b11bd12006-02-07 22:13:05 -0800214 res = PROM_TRUE;
215 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 goto done;
217 }
218
219 if (va < PGDIR_SIZE) {
220 /*
221 * vmalloc or prom_inherited mapping.
222 */
223 pgd_t *pgdp;
224 pud_t *pudp;
225 pmd_t *pmdp;
226 pte_t *ptep;
Hugh Dickinsb8ae4862005-11-07 14:08:46 -0800227 pte_t pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 int error;
229
230 if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) {
231 tte = prom_virt_to_phys(va, &error);
232 if (!error)
233 res = PROM_TRUE;
234 goto done;
235 }
236 pgdp = pgd_offset_k(va);
237 if (pgd_none(*pgdp))
238 goto done;
239 pudp = pud_offset(pgdp, va);
240 if (pud_none(*pudp))
241 goto done;
242 pmdp = pmd_offset(pudp, va);
243 if (pmd_none(*pmdp))
244 goto done;
245
246 /* Preemption implicitly disabled by virtue of
247 * being called from inside OBP.
248 */
249 ptep = pte_offset_kernel(pmdp, va);
Hugh Dickinsb8ae4862005-11-07 14:08:46 -0800250 pte = *ptep;
251 if (pte_present(pte)) {
252 tte = pte_val(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 res = PROM_TRUE;
254 }
255 goto done;
256 }
257
258 if (va < PAGE_OFFSET) {
259 /*
260 * No mappings here.
261 */
262 goto done;
263 }
264
265 if (va & (1UL << 40)) {
266 /*
267 * I/O page.
268 */
269
270 tte = (__pa(va) & _PAGE_PADDR) |
271 _PAGE_VALID | _PAGE_SZ4MB |
272 _PAGE_E | _PAGE_P | _PAGE_W;
273 res = PROM_TRUE;
274 goto done;
275 }
276
277 /*
278 * Normal page.
279 */
280 tte = (__pa(va) & _PAGE_PADDR) |
281 _PAGE_VALID | _PAGE_SZ4MB |
282 _PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W;
283 res = PROM_TRUE;
284
285 done:
286 if (res == PROM_TRUE) {
287 args[2] = 3;
288 args[args[1] + 3] = 0;
289 args[args[1] + 4] = res;
290 args[args[1] + 5] = tte;
291 } else {
292 args[2] = 2;
293 args[args[1] + 3] = 0;
294 args[args[1] + 4] = res;
295 }
296 } else if (!strcmp(cmd, ".soft1")) {
297 unsigned long tte;
298
299 tte = args[3];
300 prom_printf("%lx:\"%s%s%s%s%s\" ",
301 (tte & _PAGE_SOFT) >> 7,
302 tte & _PAGE_MODIFIED ? "M" : "-",
303 tte & _PAGE_ACCESSED ? "A" : "-",
304 tte & _PAGE_READ ? "W" : "-",
305 tte & _PAGE_WRITE ? "R" : "-",
306 tte & _PAGE_PRESENT ? "P" : "-");
307
308 args[2] = 2;
309 args[args[1] + 3] = 0;
310 args[args[1] + 4] = PROM_TRUE;
311 } else if (!strcmp(cmd, ".soft2")) {
312 unsigned long tte;
313
314 tte = args[3];
315 prom_printf("%lx ", (tte & 0x07FC000000000000UL) >> 50);
316
317 args[2] = 2;
318 args[args[1] + 3] = 0;
319 args[args[1] + 4] = PROM_TRUE;
320 } else {
321 prom_printf("unknown PROM `%s' command...\n", cmd);
322 }
323 unregister_console(&prom_console);
324 while (saved_console) {
325 cons = saved_console;
326 saved_console = cons->next;
327 register_console(cons);
328 }
329 spin_lock(&prom_entry_lock);
330 local_irq_restore(flags);
331
332 /*
333 * Restore in-interrupt status for a resume from obp.
334 */
335 irq_enter();
336 return 0;
337}
338
339unsigned int boot_flags = 0;
340#define BOOTME_DEBUG 0x1
341#define BOOTME_SINGLE 0x2
342
343/* Exported for mm/init.c:paging_init. */
344unsigned long cmdline_memory_size = 0;
345
346static struct console prom_debug_console = {
347 .name = "debug",
348 .write = prom_console_write,
349 .flags = CON_PRINTBUFFER,
350 .index = -1,
351};
352
353/* XXX Implement this at some point... */
354void kernel_enter_debugger(void)
355{
356}
357
358int obp_system_intr(void)
359{
360 if (boot_flags & BOOTME_DEBUG) {
361 printk("OBP: system interrupted\n");
362 prom_halt();
363 return 1;
364 }
365 return 0;
366}
367
368/*
369 * Process kernel command line switches that are specific to the
370 * SPARC or that require special low-level processing.
371 */
372static void __init process_switch(char c)
373{
374 switch (c) {
375 case 'd':
376 boot_flags |= BOOTME_DEBUG;
377 break;
378 case 's':
379 boot_flags |= BOOTME_SINGLE;
380 break;
381 case 'h':
382 prom_printf("boot_flags_init: Halt!\n");
383 prom_halt();
384 break;
385 case 'p':
386 /* Use PROM debug console. */
387 register_console(&prom_debug_console);
388 break;
David S. Miller816242d2005-05-23 15:52:08 -0700389 case 'P':
390 /* Force UltraSPARC-III P-Cache on. */
391 if (tlb_type != cheetah) {
392 printk("BOOT: Ignoring P-Cache force option.\n");
393 break;
394 }
395 cheetah_pcache_forced_on = 1;
396 add_taint(TAINT_MACHINE_CHECK);
397 cheetah_enable_pcache();
398 break;
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 default:
401 printk("Unknown boot switch (-%c)\n", c);
402 break;
403 }
404}
405
406static void __init process_console(char *commands)
407{
408 serial_console = 0;
409 commands += 8;
410 /* Linux-style serial */
411 if (!strncmp(commands, "ttyS", 4))
412 serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
413 else if (!strncmp(commands, "tty", 3)) {
414 char c = *(commands + 3);
415 /* Solaris-style serial */
416 if (c == 'a' || c == 'b') {
417 serial_console = c - 'a' + 1;
418 prom_printf ("Using /dev/tty%c as console.\n", c);
419 }
420 /* else Linux-style fbcon, not serial */
421 }
422#if defined(CONFIG_PROM_CONSOLE)
423 if (!strncmp(commands, "prom", 4)) {
424 char *p;
425
426 for (p = commands - 8; *p && *p != ' '; p++)
427 *p = ' ';
428 conswitchp = &prom_con;
429 }
430#endif
431}
432
433static void __init boot_flags_init(char *commands)
434{
435 while (*commands) {
436 /* Move to the start of the next "argument". */
437 while (*commands && *commands == ' ')
438 commands++;
439
440 /* Process any command switches, otherwise skip it. */
441 if (*commands == '\0')
442 break;
443 if (*commands == '-') {
444 commands++;
445 while (*commands && *commands != ' ')
446 process_switch(*commands++);
447 continue;
448 }
449 if (!strncmp(commands, "console=", 8)) {
450 process_console(commands);
451 } else if (!strncmp(commands, "mem=", 4)) {
452 /*
453 * "mem=XXX[kKmM]" overrides the PROM-reported
454 * memory size.
455 */
456 cmdline_memory_size = simple_strtoul(commands + 4,
457 &commands, 0);
458 if (*commands == 'K' || *commands == 'k') {
459 cmdline_memory_size <<= 10;
460 commands++;
461 } else if (*commands=='M' || *commands=='m') {
462 cmdline_memory_size <<= 20;
463 commands++;
464 }
465 }
466 while (*commands && *commands != ' ')
467 commands++;
468 }
469}
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471extern void panic_setup(char *, int *);
472
473extern unsigned short root_flags;
474extern unsigned short root_dev;
475extern unsigned short ram_flags;
476#define RAMDISK_IMAGE_START_MASK 0x07FF
477#define RAMDISK_PROMPT_FLAG 0x8000
478#define RAMDISK_LOAD_FLAG 0x4000
479
480extern int root_mountflags;
481
482char reboot_command[COMMAND_LINE_SIZE];
483
484static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
485
486void register_prom_callbacks(void)
487{
488 prom_setcallback(prom_callback);
489 prom_feval(": linux-va>tte-data 2 \" va>tte-data\" $callback drop ; "
490 "' linux-va>tte-data to va>tte-data");
491 prom_feval(": linux-.soft1 1 \" .soft1\" $callback 2drop ; "
492 "' linux-.soft1 to .soft1");
493 prom_feval(": linux-.soft2 1 \" .soft2\" $callback 2drop ; "
494 "' linux-.soft2 to .soft2");
495}
496
David S. Miller92704a12006-02-26 23:27:19 -0800497static void __init per_cpu_patch(void)
498{
499#ifdef CONFIG_SMP
500 struct cpuid_patch_entry *p;
501 unsigned long ver;
502 int is_jbus;
503
504 if (tlb_type == spitfire && !this_is_starfire)
505 return;
506
David S. Millerd82ace72006-02-09 02:52:44 -0800507 is_jbus = 0;
508 if (tlb_type != hypervisor) {
509 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
510 is_jbus = ((ver >> 32) == __JALAPENO_ID ||
511 (ver >> 32) == __SERRANO_ID);
512 }
David S. Miller92704a12006-02-26 23:27:19 -0800513
514 p = &__cpuid_patch;
515 while (p < &__cpuid_patch_end) {
516 unsigned long addr = p->addr;
517 unsigned int *insns;
518
519 switch (tlb_type) {
520 case spitfire:
521 insns = &p->starfire[0];
522 break;
523 case cheetah:
524 case cheetah_plus:
525 if (is_jbus)
526 insns = &p->cheetah_jbus[0];
527 else
528 insns = &p->cheetah_safari[0];
529 break;
David S. Millerd96b8152006-02-04 15:40:53 -0800530 case hypervisor:
531 insns = &p->sun4v[0];
532 break;
David S. Miller92704a12006-02-26 23:27:19 -0800533 default:
534 prom_printf("Unknown cpu type, halting.\n");
535 prom_halt();
536 };
537
538 *(unsigned int *) (addr + 0) = insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800539 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800540 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
541
542 *(unsigned int *) (addr + 4) = insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800543 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800544 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
545
546 *(unsigned int *) (addr + 8) = insns[2];
David S. Miller840aaef2006-02-06 15:52:05 -0800547 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800548 __asm__ __volatile__("flush %0" : : "r" (addr + 8));
549
550 *(unsigned int *) (addr + 12) = insns[3];
David S. Miller840aaef2006-02-06 15:52:05 -0800551 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800552 __asm__ __volatile__("flush %0" : : "r" (addr + 12));
553
554 p++;
555 }
556#endif
557}
558
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800559static void __init sun4v_patch(void)
David S. Miller936f4822006-02-05 21:29:28 -0800560{
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800561 struct sun4v_1insn_patch_entry *p1;
562 struct sun4v_2insn_patch_entry *p2;
David S. Miller936f4822006-02-05 21:29:28 -0800563
564 if (tlb_type != hypervisor)
565 return;
566
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800567 p1 = &__sun4v_1insn_patch;
568 while (p1 < &__sun4v_1insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800569 unsigned long addr = p1->addr;
David S. Miller936f4822006-02-05 21:29:28 -0800570
David S. Miller45fec052006-02-05 22:27:28 -0800571 *(unsigned int *) (addr + 0) = p1->insn;
David S. Miller840aaef2006-02-06 15:52:05 -0800572 wmb();
David S. Miller936f4822006-02-05 21:29:28 -0800573 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
574
David S. Miller45fec052006-02-05 22:27:28 -0800575 p1++;
576 }
577
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800578 p2 = &__sun4v_2insn_patch;
579 while (p2 < &__sun4v_2insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800580 unsigned long addr = p2->addr;
581
582 *(unsigned int *) (addr + 0) = p2->insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800583 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800584 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
585
586 *(unsigned int *) (addr + 3) = p2->insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800587 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800588 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
589
590 p2++;
David S. Miller936f4822006-02-05 21:29:28 -0800591 }
592}
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594void __init setup_arch(char **cmdline_p)
595{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 /* Initialize PROM console and command line. */
597 *cmdline_p = prom_getbootargs();
598 strcpy(saved_command_line, *cmdline_p);
599
David S. Miller3a8c0692006-02-09 02:54:54 -0800600 if (tlb_type == hypervisor)
601 printk("ARCH: SUN4V\n");
602 else
603 printk("ARCH: SUN4U\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605#ifdef CONFIG_DUMMY_CONSOLE
606 conswitchp = &dummy_con;
607#elif defined(CONFIG_PROM_CONSOLE)
608 conswitchp = &prom_con;
609#endif
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 /* Work out if we are starfire early on */
612 check_if_starfire();
613
David S. Miller92704a12006-02-26 23:27:19 -0800614 /* Now we know enough to patch the get_cpuid sequences
615 * used by trap code.
David S. Miller56fb4df2006-02-26 23:24:22 -0800616 */
617 per_cpu_patch();
618
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800619 sun4v_patch();
David S. Miller936f4822006-02-05 21:29:28 -0800620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 boot_flags_init(*cmdline_p);
622
623 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 if (!root_flags)
626 root_mountflags &= ~MS_RDONLY;
627 ROOT_DEV = old_decode_dev(root_dev);
628#ifdef CONFIG_BLK_DEV_INITRD
629 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
630 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
631 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
632#endif
633
Al Virof3169642006-01-12 01:05:42 -0800634 task_thread_info(&init_task)->kregs = &fake_swapper_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636#ifdef CONFIG_IP_PNP
637 if (!ic_set_manually) {
638 int chosen = prom_finddevice ("/chosen");
639 u32 cl, sv, gw;
640
641 cl = prom_getintdefault (chosen, "client-ip", 0);
642 sv = prom_getintdefault (chosen, "server-ip", 0);
643 gw = prom_getintdefault (chosen, "gateway-ip", 0);
644 if (cl && sv) {
645 ic_myaddr = cl;
646 ic_servaddr = sv;
647 if (gw)
648 ic_gateway = gw;
649#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
650 ic_proto_enabled = 0;
651#endif
652 }
653 }
654#endif
655
David S. Miller7abea922006-02-25 13:39:56 -0800656 smp_setup_cpu_possible_map();
657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 paging_init();
David S. Miller56fb4df2006-02-26 23:24:22 -0800659
660 /* Get boot processor trap_block[] setup. */
661 init_cur_cpu_trap();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
664static int __init set_preferred_console(void)
665{
666 int idev, odev;
667
668 /* The user has requested a console so this is already set up. */
669 if (serial_console >= 0)
670 return -EBUSY;
671
672 idev = prom_query_input_device();
673 odev = prom_query_output_device();
674 if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
675 serial_console = 0;
676 } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
677 serial_console = 1;
678 } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
679 serial_console = 2;
Eddie C. Dostc126cf82006-01-18 14:54:31 -0800680 } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
681 serial_console = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 } else {
683 prom_printf("Inconsistent console: "
684 "input %d, output %d\n",
685 idev, odev);
686 prom_halt();
687 }
688
689 if (serial_console)
690 return add_preferred_console("ttyS", serial_console - 1, NULL);
691
692 return -ENODEV;
693}
694console_initcall(set_preferred_console);
695
696/* BUFFER is PAGE_SIZE bytes long. */
697
698extern char *sparc_cpu_type;
699extern char *sparc_fpu_type;
700
701extern void smp_info(struct seq_file *);
702extern void smp_bogo(struct seq_file *);
703extern void mmu_info(struct seq_file *);
704
David S. Miller80dc0d62005-09-26 00:32:17 -0700705unsigned int dcache_parity_tl1_occurred;
706unsigned int icache_parity_tl1_occurred;
707
David S. Miller4d45cba2005-11-11 12:48:56 -0800708static int ncpus_probed;
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710static int show_cpuinfo(struct seq_file *m, void *__unused)
711{
712 seq_printf(m,
713 "cpu\t\t: %s\n"
714 "fpu\t\t: %s\n"
715 "promlib\t\t: Version 3 Revision %d\n"
716 "prom\t\t: %d.%d.%d\n"
717 "type\t\t: sun4u\n"
David S. Miller4d45cba2005-11-11 12:48:56 -0800718 "ncpus probed\t: %d\n"
719 "ncpus active\t: %d\n"
David S. Miller80dc0d62005-09-26 00:32:17 -0700720 "D$ parity tl1\t: %u\n"
721 "I$ parity tl1\t: %u\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#ifndef CONFIG_SMP
723 "Cpu0Bogo\t: %lu.%02lu\n"
724 "Cpu0ClkTck\t: %016lx\n"
725#endif
726 ,
727 sparc_cpu_type,
728 sparc_fpu_type,
729 prom_rev,
730 prom_prev >> 16,
731 (prom_prev >> 8) & 0xff,
732 prom_prev & 0xff,
David S. Miller4d45cba2005-11-11 12:48:56 -0800733 ncpus_probed,
734 num_online_cpus(),
David S. Miller80dc0d62005-09-26 00:32:17 -0700735 dcache_parity_tl1_occurred,
736 icache_parity_tl1_occurred
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#ifndef CONFIG_SMP
738 , cpu_data(0).udelay_val/(500000/HZ),
739 (cpu_data(0).udelay_val/(5000/HZ)) % 100,
740 cpu_data(0).clock_tick
741#endif
742 );
743#ifdef CONFIG_SMP
744 smp_bogo(m);
745#endif
746 mmu_info(m);
747#ifdef CONFIG_SMP
748 smp_info(m);
749#endif
750 return 0;
751}
752
753static void *c_start(struct seq_file *m, loff_t *pos)
754{
755 /* The pointer we are returning is arbitrary,
756 * it just has to be non-NULL and not IS_ERR
757 * in the success case.
758 */
759 return *pos == 0 ? &c_start : NULL;
760}
761
762static void *c_next(struct seq_file *m, void *v, loff_t *pos)
763{
764 ++*pos;
765 return c_start(m, pos);
766}
767
768static void c_stop(struct seq_file *m, void *v)
769{
770}
771
772struct seq_operations cpuinfo_op = {
773 .start =c_start,
774 .next = c_next,
775 .stop = c_stop,
776 .show = show_cpuinfo,
777};
778
779extern int stop_a_enabled;
780
781void sun_do_break(void)
782{
783 if (!stop_a_enabled)
784 return;
785
786 prom_printf("\n");
787 flush_user_windows();
788
789 prom_cmdline();
790}
791
792int serial_console = -1;
793int stop_a_enabled = 1;
794
795static int __init topology_init(void)
796{
797 int i, err;
798
799 err = -ENOMEM;
David S. Miller4d45cba2005-11-11 12:48:56 -0800800
801 /* Count the number of physically present processors in
802 * the machine, even on uniprocessor, so that /proc/cpuinfo
803 * output is consistent with 2.4.x
804 */
805 ncpus_probed = 0;
806 while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
807 ncpus_probed++;
808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 for (i = 0; i < NR_CPUS; i++) {
810 if (cpu_possible(i)) {
811 struct cpu *p = kmalloc(sizeof(*p), GFP_KERNEL);
812
813 if (p) {
814 memset(p, 0, sizeof(*p));
815 register_cpu(p, i, NULL);
816 err = 0;
817 }
818 }
819 }
820
821 return err;
822}
823
824subsys_initcall(topology_init);