blob: c1f34237cdf2f2cc1777c7e4842d3b3da6a3610e [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;
157
158 for_each_process(p) {
159 mm = p->mm;
160 if (CTX_NRBITS(mm->context) == ctx)
161 break;
162 }
163 if (!mm ||
164 CTX_NRBITS(mm->context) != ctx)
165 goto done;
166
167 pgdp = pgd_offset(mm, va);
168 if (pgd_none(*pgdp))
169 goto done;
170 pudp = pud_offset(pgdp, va);
171 if (pud_none(*pudp))
172 goto done;
173 pmdp = pmd_offset(pudp, va);
174 if (pmd_none(*pmdp))
175 goto done;
176
177 /* Preemption implicitly disabled by virtue of
178 * being called from inside OBP.
179 */
180 ptep = pte_offset_map(pmdp, va);
181 if (pte_present(*ptep)) {
182 tte = pte_val(*ptep);
183 res = PROM_TRUE;
184 }
185 pte_unmap(ptep);
186 goto done;
187 }
188
189 if ((va >= KERNBASE) && (va < (KERNBASE + (4 * 1024 * 1024)))) {
David S. Miller0835ae02005-10-04 15:23:20 -0700190 extern unsigned long sparc64_kern_pri_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 /* Spitfire Errata #32 workaround */
193 __asm__ __volatile__("stxa %0, [%1] %2\n\t"
194 "flush %%g6"
195 : /* No outputs */
David S. Miller0835ae02005-10-04 15:23:20 -0700196 : "r" (sparc64_kern_pri_context),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 "r" (PRIMARY_CONTEXT),
198 "i" (ASI_DMMU));
199
200 /*
201 * Locked down tlb entry.
202 */
203
204 if (tlb_type == spitfire)
205 tte = spitfire_get_dtlb_data(SPITFIRE_HIGHEST_LOCKED_TLBENT);
206 else if (tlb_type == cheetah || tlb_type == cheetah_plus)
207 tte = cheetah_get_ldtlb_data(CHEETAH_HIGHEST_LOCKED_TLBENT);
208
209 res = PROM_TRUE;
210 goto done;
211 }
212
213 if (va < PGDIR_SIZE) {
214 /*
215 * vmalloc or prom_inherited mapping.
216 */
217 pgd_t *pgdp;
218 pud_t *pudp;
219 pmd_t *pmdp;
220 pte_t *ptep;
221 int error;
222
223 if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) {
224 tte = prom_virt_to_phys(va, &error);
225 if (!error)
226 res = PROM_TRUE;
227 goto done;
228 }
229 pgdp = pgd_offset_k(va);
230 if (pgd_none(*pgdp))
231 goto done;
232 pudp = pud_offset(pgdp, va);
233 if (pud_none(*pudp))
234 goto done;
235 pmdp = pmd_offset(pudp, va);
236 if (pmd_none(*pmdp))
237 goto done;
238
239 /* Preemption implicitly disabled by virtue of
240 * being called from inside OBP.
241 */
242 ptep = pte_offset_kernel(pmdp, va);
243 if (pte_present(*ptep)) {
244 tte = pte_val(*ptep);
245 res = PROM_TRUE;
246 }
247 goto done;
248 }
249
250 if (va < PAGE_OFFSET) {
251 /*
252 * No mappings here.
253 */
254 goto done;
255 }
256
257 if (va & (1UL << 40)) {
258 /*
259 * I/O page.
260 */
261
262 tte = (__pa(va) & _PAGE_PADDR) |
263 _PAGE_VALID | _PAGE_SZ4MB |
264 _PAGE_E | _PAGE_P | _PAGE_W;
265 res = PROM_TRUE;
266 goto done;
267 }
268
269 /*
270 * Normal page.
271 */
272 tte = (__pa(va) & _PAGE_PADDR) |
273 _PAGE_VALID | _PAGE_SZ4MB |
274 _PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W;
275 res = PROM_TRUE;
276
277 done:
278 if (res == PROM_TRUE) {
279 args[2] = 3;
280 args[args[1] + 3] = 0;
281 args[args[1] + 4] = res;
282 args[args[1] + 5] = tte;
283 } else {
284 args[2] = 2;
285 args[args[1] + 3] = 0;
286 args[args[1] + 4] = res;
287 }
288 } else if (!strcmp(cmd, ".soft1")) {
289 unsigned long tte;
290
291 tte = args[3];
292 prom_printf("%lx:\"%s%s%s%s%s\" ",
293 (tte & _PAGE_SOFT) >> 7,
294 tte & _PAGE_MODIFIED ? "M" : "-",
295 tte & _PAGE_ACCESSED ? "A" : "-",
296 tte & _PAGE_READ ? "W" : "-",
297 tte & _PAGE_WRITE ? "R" : "-",
298 tte & _PAGE_PRESENT ? "P" : "-");
299
300 args[2] = 2;
301 args[args[1] + 3] = 0;
302 args[args[1] + 4] = PROM_TRUE;
303 } else if (!strcmp(cmd, ".soft2")) {
304 unsigned long tte;
305
306 tte = args[3];
307 prom_printf("%lx ", (tte & 0x07FC000000000000UL) >> 50);
308
309 args[2] = 2;
310 args[args[1] + 3] = 0;
311 args[args[1] + 4] = PROM_TRUE;
312 } else {
313 prom_printf("unknown PROM `%s' command...\n", cmd);
314 }
315 unregister_console(&prom_console);
316 while (saved_console) {
317 cons = saved_console;
318 saved_console = cons->next;
319 register_console(cons);
320 }
321 spin_lock(&prom_entry_lock);
322 local_irq_restore(flags);
323
324 /*
325 * Restore in-interrupt status for a resume from obp.
326 */
327 irq_enter();
328 return 0;
329}
330
331unsigned int boot_flags = 0;
332#define BOOTME_DEBUG 0x1
333#define BOOTME_SINGLE 0x2
334
335/* Exported for mm/init.c:paging_init. */
336unsigned long cmdline_memory_size = 0;
337
338static struct console prom_debug_console = {
339 .name = "debug",
340 .write = prom_console_write,
341 .flags = CON_PRINTBUFFER,
342 .index = -1,
343};
344
345/* XXX Implement this at some point... */
346void kernel_enter_debugger(void)
347{
348}
349
350int obp_system_intr(void)
351{
352 if (boot_flags & BOOTME_DEBUG) {
353 printk("OBP: system interrupted\n");
354 prom_halt();
355 return 1;
356 }
357 return 0;
358}
359
360/*
361 * Process kernel command line switches that are specific to the
362 * SPARC or that require special low-level processing.
363 */
364static void __init process_switch(char c)
365{
366 switch (c) {
367 case 'd':
368 boot_flags |= BOOTME_DEBUG;
369 break;
370 case 's':
371 boot_flags |= BOOTME_SINGLE;
372 break;
373 case 'h':
374 prom_printf("boot_flags_init: Halt!\n");
375 prom_halt();
376 break;
377 case 'p':
378 /* Use PROM debug console. */
379 register_console(&prom_debug_console);
380 break;
David S. Miller816242d2005-05-23 15:52:08 -0700381 case 'P':
382 /* Force UltraSPARC-III P-Cache on. */
383 if (tlb_type != cheetah) {
384 printk("BOOT: Ignoring P-Cache force option.\n");
385 break;
386 }
387 cheetah_pcache_forced_on = 1;
388 add_taint(TAINT_MACHINE_CHECK);
389 cheetah_enable_pcache();
390 break;
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 default:
393 printk("Unknown boot switch (-%c)\n", c);
394 break;
395 }
396}
397
398static void __init process_console(char *commands)
399{
400 serial_console = 0;
401 commands += 8;
402 /* Linux-style serial */
403 if (!strncmp(commands, "ttyS", 4))
404 serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
405 else if (!strncmp(commands, "tty", 3)) {
406 char c = *(commands + 3);
407 /* Solaris-style serial */
408 if (c == 'a' || c == 'b') {
409 serial_console = c - 'a' + 1;
410 prom_printf ("Using /dev/tty%c as console.\n", c);
411 }
412 /* else Linux-style fbcon, not serial */
413 }
414#if defined(CONFIG_PROM_CONSOLE)
415 if (!strncmp(commands, "prom", 4)) {
416 char *p;
417
418 for (p = commands - 8; *p && *p != ' '; p++)
419 *p = ' ';
420 conswitchp = &prom_con;
421 }
422#endif
423}
424
425static void __init boot_flags_init(char *commands)
426{
427 while (*commands) {
428 /* Move to the start of the next "argument". */
429 while (*commands && *commands == ' ')
430 commands++;
431
432 /* Process any command switches, otherwise skip it. */
433 if (*commands == '\0')
434 break;
435 if (*commands == '-') {
436 commands++;
437 while (*commands && *commands != ' ')
438 process_switch(*commands++);
439 continue;
440 }
441 if (!strncmp(commands, "console=", 8)) {
442 process_console(commands);
443 } else if (!strncmp(commands, "mem=", 4)) {
444 /*
445 * "mem=XXX[kKmM]" overrides the PROM-reported
446 * memory size.
447 */
448 cmdline_memory_size = simple_strtoul(commands + 4,
449 &commands, 0);
450 if (*commands == 'K' || *commands == 'k') {
451 cmdline_memory_size <<= 10;
452 commands++;
453 } else if (*commands=='M' || *commands=='m') {
454 cmdline_memory_size <<= 20;
455 commands++;
456 }
457 }
458 while (*commands && *commands != ' ')
459 commands++;
460 }
461}
462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463extern void panic_setup(char *, int *);
464
465extern unsigned short root_flags;
466extern unsigned short root_dev;
467extern unsigned short ram_flags;
468#define RAMDISK_IMAGE_START_MASK 0x07FF
469#define RAMDISK_PROMPT_FLAG 0x8000
470#define RAMDISK_LOAD_FLAG 0x4000
471
472extern int root_mountflags;
473
474char reboot_command[COMMAND_LINE_SIZE];
475
476static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
477
478void register_prom_callbacks(void)
479{
480 prom_setcallback(prom_callback);
481 prom_feval(": linux-va>tte-data 2 \" va>tte-data\" $callback drop ; "
482 "' linux-va>tte-data to va>tte-data");
483 prom_feval(": linux-.soft1 1 \" .soft1\" $callback 2drop ; "
484 "' linux-.soft1 to .soft1");
485 prom_feval(": linux-.soft2 1 \" .soft2\" $callback 2drop ; "
486 "' linux-.soft2 to .soft2");
487}
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489void __init setup_arch(char **cmdline_p)
490{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /* Initialize PROM console and command line. */
492 *cmdline_p = prom_getbootargs();
493 strcpy(saved_command_line, *cmdline_p);
494
495 printk("ARCH: SUN4U\n");
496
497#ifdef CONFIG_DUMMY_CONSOLE
498 conswitchp = &dummy_con;
499#elif defined(CONFIG_PROM_CONSOLE)
500 conswitchp = &prom_con;
501#endif
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /* Work out if we are starfire early on */
504 check_if_starfire();
505
506 boot_flags_init(*cmdline_p);
507
508 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 if (!root_flags)
511 root_mountflags &= ~MS_RDONLY;
512 ROOT_DEV = old_decode_dev(root_dev);
513#ifdef CONFIG_BLK_DEV_INITRD
514 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
515 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
516 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
517#endif
518
519 init_task.thread_info->kregs = &fake_swapper_regs;
520
521#ifdef CONFIG_IP_PNP
522 if (!ic_set_manually) {
523 int chosen = prom_finddevice ("/chosen");
524 u32 cl, sv, gw;
525
526 cl = prom_getintdefault (chosen, "client-ip", 0);
527 sv = prom_getintdefault (chosen, "server-ip", 0);
528 gw = prom_getintdefault (chosen, "gateway-ip", 0);
529 if (cl && sv) {
530 ic_myaddr = cl;
531 ic_servaddr = sv;
532 if (gw)
533 ic_gateway = gw;
534#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
535 ic_proto_enabled = 0;
536#endif
537 }
538 }
539#endif
540
541 paging_init();
542}
543
544static int __init set_preferred_console(void)
545{
546 int idev, odev;
547
548 /* The user has requested a console so this is already set up. */
549 if (serial_console >= 0)
550 return -EBUSY;
551
552 idev = prom_query_input_device();
553 odev = prom_query_output_device();
554 if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
555 serial_console = 0;
556 } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
557 serial_console = 1;
558 } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
559 serial_console = 2;
560 } else {
561 prom_printf("Inconsistent console: "
562 "input %d, output %d\n",
563 idev, odev);
564 prom_halt();
565 }
566
567 if (serial_console)
568 return add_preferred_console("ttyS", serial_console - 1, NULL);
569
570 return -ENODEV;
571}
572console_initcall(set_preferred_console);
573
574/* BUFFER is PAGE_SIZE bytes long. */
575
576extern char *sparc_cpu_type;
577extern char *sparc_fpu_type;
578
579extern void smp_info(struct seq_file *);
580extern void smp_bogo(struct seq_file *);
581extern void mmu_info(struct seq_file *);
582
David S. Miller80dc0d62005-09-26 00:32:17 -0700583unsigned int dcache_parity_tl1_occurred;
584unsigned int icache_parity_tl1_occurred;
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586static int show_cpuinfo(struct seq_file *m, void *__unused)
587{
588 seq_printf(m,
589 "cpu\t\t: %s\n"
590 "fpu\t\t: %s\n"
591 "promlib\t\t: Version 3 Revision %d\n"
592 "prom\t\t: %d.%d.%d\n"
593 "type\t\t: sun4u\n"
594 "ncpus probed\t: %ld\n"
595 "ncpus active\t: %ld\n"
David S. Miller80dc0d62005-09-26 00:32:17 -0700596 "D$ parity tl1\t: %u\n"
597 "I$ parity tl1\t: %u\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#ifndef CONFIG_SMP
599 "Cpu0Bogo\t: %lu.%02lu\n"
600 "Cpu0ClkTck\t: %016lx\n"
601#endif
602 ,
603 sparc_cpu_type,
604 sparc_fpu_type,
605 prom_rev,
606 prom_prev >> 16,
607 (prom_prev >> 8) & 0xff,
608 prom_prev & 0xff,
609 (long)num_possible_cpus(),
David S. Miller80dc0d62005-09-26 00:32:17 -0700610 (long)num_online_cpus(),
611 dcache_parity_tl1_occurred,
612 icache_parity_tl1_occurred
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613#ifndef CONFIG_SMP
614 , cpu_data(0).udelay_val/(500000/HZ),
615 (cpu_data(0).udelay_val/(5000/HZ)) % 100,
616 cpu_data(0).clock_tick
617#endif
618 );
619#ifdef CONFIG_SMP
620 smp_bogo(m);
621#endif
622 mmu_info(m);
623#ifdef CONFIG_SMP
624 smp_info(m);
625#endif
626 return 0;
627}
628
629static void *c_start(struct seq_file *m, loff_t *pos)
630{
631 /* The pointer we are returning is arbitrary,
632 * it just has to be non-NULL and not IS_ERR
633 * in the success case.
634 */
635 return *pos == 0 ? &c_start : NULL;
636}
637
638static void *c_next(struct seq_file *m, void *v, loff_t *pos)
639{
640 ++*pos;
641 return c_start(m, pos);
642}
643
644static void c_stop(struct seq_file *m, void *v)
645{
646}
647
648struct seq_operations cpuinfo_op = {
649 .start =c_start,
650 .next = c_next,
651 .stop = c_stop,
652 .show = show_cpuinfo,
653};
654
655extern int stop_a_enabled;
656
657void sun_do_break(void)
658{
659 if (!stop_a_enabled)
660 return;
661
662 prom_printf("\n");
663 flush_user_windows();
664
665 prom_cmdline();
666}
667
668int serial_console = -1;
669int stop_a_enabled = 1;
670
671static int __init topology_init(void)
672{
673 int i, err;
674
675 err = -ENOMEM;
676 for (i = 0; i < NR_CPUS; i++) {
677 if (cpu_possible(i)) {
678 struct cpu *p = kmalloc(sizeof(*p), GFP_KERNEL);
679
680 if (p) {
681 memset(p, 0, sizeof(*p));
682 register_cpu(p, i, NULL);
683 err = 0;
684 }
685 }
686 }
687
688 return err;
689}
690
691subsys_initcall(topology_init);