1 /* $Id: setup.c,v 1.72 2002/02/09 19:49:30 davem Exp $
2 * linux/arch/sparc64/kernel/setup.c
4 * Copyright (C) 1995,1996 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
12 #include <linux/stddef.h>
13 #include <linux/unistd.h>
14 #include <linux/ptrace.h>
15 #include <linux/slab.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>
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>
36 #include <asm/system.h>
38 #include <asm/processor.h>
39 #include <asm/oplib.h>
41 #include <asm/pgtable.h>
42 #include <asm/idprom.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>
52 #include <net/ipconfig.h>
55 struct screen_info screen_info = {
56 0, 0, /* orig-x, orig-y */
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 */
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.
73 void (*prom_palette)(int);
74 void (*prom_keyboard)(void);
77 prom_console_write(struct console *con, const char *s, unsigned n)
82 static struct console prom_console = {
84 .write = prom_console_write,
85 .flags = CON_CONSDEV | CON_ENABLED,
93 int prom_callback(long *args)
95 struct console *cons, *saved_console = NULL;
98 extern spinlock_t prom_entry_lock;
102 if (!(cmd = (char *)args[0]))
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.
114 /* XXX Revisit the locking here someday. This is a debugging
115 * XXX feature so it isnt all that critical. -DaveM
117 local_irq_save(flags);
119 spin_unlock(&prom_entry_lock);
120 cons = console_drivers;
122 unregister_console(cons);
123 cons->flags &= ~(CON_PRINTBUFFER);
124 cons->next = saved_console;
125 saved_console = cons;
126 cons = console_drivers;
128 register_console(&prom_console);
129 if (!strcmp(cmd, "sync")) {
130 prom_printf("PROM `%s' command...\n", cmd);
132 if (current->pid != 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;
149 * Find process owning ctx, lookup mapping.
151 struct task_struct *p;
152 struct mm_struct *mm = NULL;
159 for_each_process(p) {
161 if (CTX_NRBITS(mm->context) == ctx)
165 CTX_NRBITS(mm->context) != ctx)
168 pgdp = pgd_offset(mm, va);
171 pudp = pud_offset(pgdp, va);
174 pmdp = pmd_offset(pudp, va);
178 /* Preemption implicitly disabled by virtue of
179 * being called from inside OBP.
181 ptep = pte_offset_map(pmdp, va);
183 if (pte_present(pte)) {
191 if ((va >= KERNBASE) && (va < (KERNBASE + (4 * 1024 * 1024)))) {
192 if (tlb_type == spitfire) {
193 extern unsigned long sparc64_kern_pri_context;
195 /* Spitfire Errata #32 workaround */
196 __asm__ __volatile__(
197 "stxa %0, [%1] %2\n\t"
200 : "r" (sparc64_kern_pri_context),
201 "r" (PRIMARY_CONTEXT),
206 * Locked down tlb entry.
209 if (tlb_type == spitfire) {
210 tte = spitfire_get_dtlb_data(SPITFIRE_HIGHEST_LOCKED_TLBENT);
212 } else if (tlb_type == cheetah || tlb_type == cheetah_plus) {
213 tte = cheetah_get_ldtlb_data(CHEETAH_HIGHEST_LOCKED_TLBENT);
219 if (va < PGDIR_SIZE) {
221 * vmalloc or prom_inherited mapping.
230 if ((va >= LOW_OBP_ADDRESS) && (va < HI_OBP_ADDRESS)) {
231 tte = prom_virt_to_phys(va, &error);
236 pgdp = pgd_offset_k(va);
239 pudp = pud_offset(pgdp, va);
242 pmdp = pmd_offset(pudp, va);
246 /* Preemption implicitly disabled by virtue of
247 * being called from inside OBP.
249 ptep = pte_offset_kernel(pmdp, va);
251 if (pte_present(pte)) {
258 if (va < PAGE_OFFSET) {
265 if (va & (1UL << 40)) {
270 tte = (__pa(va) & _PAGE_PADDR) |
271 _PAGE_VALID | _PAGE_SZ4MB |
272 _PAGE_E | _PAGE_P | _PAGE_W;
280 tte = (__pa(va) & _PAGE_PADDR) |
281 _PAGE_VALID | _PAGE_SZ4MB |
282 _PAGE_CP | _PAGE_CV | _PAGE_P | _PAGE_W;
286 if (res == PROM_TRUE) {
288 args[args[1] + 3] = 0;
289 args[args[1] + 4] = res;
290 args[args[1] + 5] = tte;
293 args[args[1] + 3] = 0;
294 args[args[1] + 4] = res;
296 } else if (!strcmp(cmd, ".soft1")) {
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" : "-");
309 args[args[1] + 3] = 0;
310 args[args[1] + 4] = PROM_TRUE;
311 } else if (!strcmp(cmd, ".soft2")) {
315 prom_printf("%lx ", (tte & 0x07FC000000000000UL) >> 50);
318 args[args[1] + 3] = 0;
319 args[args[1] + 4] = PROM_TRUE;
321 prom_printf("unknown PROM `%s' command...\n", cmd);
323 unregister_console(&prom_console);
324 while (saved_console) {
325 cons = saved_console;
326 saved_console = cons->next;
327 register_console(cons);
329 spin_lock(&prom_entry_lock);
330 local_irq_restore(flags);
333 * Restore in-interrupt status for a resume from obp.
339 unsigned int boot_flags = 0;
340 #define BOOTME_DEBUG 0x1
341 #define BOOTME_SINGLE 0x2
343 /* Exported for mm/init.c:paging_init. */
344 unsigned long cmdline_memory_size = 0;
346 static struct console prom_debug_console = {
348 .write = prom_console_write,
349 .flags = CON_PRINTBUFFER,
353 /* XXX Implement this at some point... */
354 void kernel_enter_debugger(void)
358 int obp_system_intr(void)
360 if (boot_flags & BOOTME_DEBUG) {
361 printk("OBP: system interrupted\n");
369 * Process kernel command line switches that are specific to the
370 * SPARC or that require special low-level processing.
372 static void __init process_switch(char c)
376 boot_flags |= BOOTME_DEBUG;
379 boot_flags |= BOOTME_SINGLE;
382 prom_printf("boot_flags_init: Halt!\n");
386 /* Use PROM debug console. */
387 register_console(&prom_debug_console);
390 /* Force UltraSPARC-III P-Cache on. */
391 if (tlb_type != cheetah) {
392 printk("BOOT: Ignoring P-Cache force option.\n");
395 cheetah_pcache_forced_on = 1;
396 add_taint(TAINT_MACHINE_CHECK);
397 cheetah_enable_pcache();
401 printk("Unknown boot switch (-%c)\n", c);
406 static void __init process_console(char *commands)
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);
420 /* else Linux-style fbcon, not serial */
422 #if defined(CONFIG_PROM_CONSOLE)
423 if (!strncmp(commands, "prom", 4)) {
426 for (p = commands - 8; *p && *p != ' '; p++)
428 conswitchp = &prom_con;
433 static void __init boot_flags_init(char *commands)
436 /* Move to the start of the next "argument". */
437 while (*commands && *commands == ' ')
440 /* Process any command switches, otherwise skip it. */
441 if (*commands == '\0')
443 if (*commands == '-') {
445 while (*commands && *commands != ' ')
446 process_switch(*commands++);
449 if (!strncmp(commands, "console=", 8)) {
450 process_console(commands);
451 } else if (!strncmp(commands, "mem=", 4)) {
453 * "mem=XXX[kKmM]" overrides the PROM-reported
456 cmdline_memory_size = simple_strtoul(commands + 4,
458 if (*commands == 'K' || *commands == 'k') {
459 cmdline_memory_size <<= 10;
461 } else if (*commands=='M' || *commands=='m') {
462 cmdline_memory_size <<= 20;
466 while (*commands && *commands != ' ')
471 extern void panic_setup(char *, int *);
473 extern unsigned short root_flags;
474 extern unsigned short root_dev;
475 extern unsigned short ram_flags;
476 #define RAMDISK_IMAGE_START_MASK 0x07FF
477 #define RAMDISK_PROMPT_FLAG 0x8000
478 #define RAMDISK_LOAD_FLAG 0x4000
480 extern int root_mountflags;
482 char reboot_command[COMMAND_LINE_SIZE];
484 static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
486 void register_prom_callbacks(void)
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");
497 static void __init per_cpu_patch(void)
500 struct cpuid_patch_entry *p;
504 if (tlb_type == spitfire && !this_is_starfire)
508 if (tlb_type != hypervisor) {
509 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
510 is_jbus = ((ver >> 32) == __JALAPENO_ID ||
511 (ver >> 32) == __SERRANO_ID);
515 while (p < &__cpuid_patch_end) {
516 unsigned long addr = p->addr;
521 insns = &p->starfire[0];
526 insns = &p->cheetah_jbus[0];
528 insns = &p->cheetah_safari[0];
531 insns = &p->sun4v[0];
534 prom_printf("Unknown cpu type, halting.\n");
538 *(unsigned int *) (addr + 0) = insns[0];
540 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
542 *(unsigned int *) (addr + 4) = insns[1];
544 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
546 *(unsigned int *) (addr + 8) = insns[2];
548 __asm__ __volatile__("flush %0" : : "r" (addr + 8));
550 *(unsigned int *) (addr + 12) = insns[3];
552 __asm__ __volatile__("flush %0" : : "r" (addr + 12));
559 static void __init sun4v_patch(void)
561 struct sun4v_1insn_patch_entry *p1;
562 struct sun4v_2insn_patch_entry *p2;
564 if (tlb_type != hypervisor)
567 p1 = &__sun4v_1insn_patch;
568 while (p1 < &__sun4v_1insn_patch_end) {
569 unsigned long addr = p1->addr;
571 *(unsigned int *) (addr + 0) = p1->insn;
573 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
578 p2 = &__sun4v_2insn_patch;
579 while (p2 < &__sun4v_2insn_patch_end) {
580 unsigned long addr = p2->addr;
582 *(unsigned int *) (addr + 0) = p2->insns[0];
584 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
586 *(unsigned int *) (addr + 3) = p2->insns[1];
588 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
594 void __init setup_arch(char **cmdline_p)
596 /* Initialize PROM console and command line. */
597 *cmdline_p = prom_getbootargs();
598 strcpy(saved_command_line, *cmdline_p);
600 printk("ARCH: SUN4U\n");
602 #ifdef CONFIG_DUMMY_CONSOLE
603 conswitchp = &dummy_con;
604 #elif defined(CONFIG_PROM_CONSOLE)
605 conswitchp = &prom_con;
608 /* Work out if we are starfire early on */
611 /* Now we know enough to patch the get_cpuid sequences
618 boot_flags_init(*cmdline_p);
623 root_mountflags &= ~MS_RDONLY;
624 ROOT_DEV = old_decode_dev(root_dev);
625 #ifdef CONFIG_BLK_DEV_INITRD
626 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
627 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
628 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
631 task_thread_info(&init_task)->kregs = &fake_swapper_regs;
634 if (!ic_set_manually) {
635 int chosen = prom_finddevice ("/chosen");
638 cl = prom_getintdefault (chosen, "client-ip", 0);
639 sv = prom_getintdefault (chosen, "server-ip", 0);
640 gw = prom_getintdefault (chosen, "gateway-ip", 0);
646 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
647 ic_proto_enabled = 0;
653 smp_setup_cpu_possible_map();
657 /* Get boot processor trap_block[] setup. */
661 static int __init set_preferred_console(void)
665 /* The user has requested a console so this is already set up. */
666 if (serial_console >= 0)
669 idev = prom_query_input_device();
670 odev = prom_query_output_device();
671 if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
673 } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
675 } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
677 } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
680 prom_printf("Inconsistent console: "
681 "input %d, output %d\n",
687 return add_preferred_console("ttyS", serial_console - 1, NULL);
691 console_initcall(set_preferred_console);
693 /* BUFFER is PAGE_SIZE bytes long. */
695 extern char *sparc_cpu_type;
696 extern char *sparc_fpu_type;
698 extern void smp_info(struct seq_file *);
699 extern void smp_bogo(struct seq_file *);
700 extern void mmu_info(struct seq_file *);
702 unsigned int dcache_parity_tl1_occurred;
703 unsigned int icache_parity_tl1_occurred;
705 static int ncpus_probed;
707 static int show_cpuinfo(struct seq_file *m, void *__unused)
712 "promlib\t\t: Version 3 Revision %d\n"
713 "prom\t\t: %d.%d.%d\n"
715 "ncpus probed\t: %d\n"
716 "ncpus active\t: %d\n"
717 "D$ parity tl1\t: %u\n"
718 "I$ parity tl1\t: %u\n"
720 "Cpu0Bogo\t: %lu.%02lu\n"
721 "Cpu0ClkTck\t: %016lx\n"
728 (prom_prev >> 8) & 0xff,
732 dcache_parity_tl1_occurred,
733 icache_parity_tl1_occurred
735 , cpu_data(0).udelay_val/(500000/HZ),
736 (cpu_data(0).udelay_val/(5000/HZ)) % 100,
737 cpu_data(0).clock_tick
750 static void *c_start(struct seq_file *m, loff_t *pos)
752 /* The pointer we are returning is arbitrary,
753 * it just has to be non-NULL and not IS_ERR
754 * in the success case.
756 return *pos == 0 ? &c_start : NULL;
759 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
762 return c_start(m, pos);
765 static void c_stop(struct seq_file *m, void *v)
769 struct seq_operations cpuinfo_op = {
773 .show = show_cpuinfo,
776 extern int stop_a_enabled;
778 void sun_do_break(void)
784 flush_user_windows();
789 int serial_console = -1;
790 int stop_a_enabled = 1;
792 static int __init topology_init(void)
798 /* Count the number of physically present processors in
799 * the machine, even on uniprocessor, so that /proc/cpuinfo
800 * output is consistent with 2.4.x
803 while (!cpu_find_by_instance(ncpus_probed, NULL, NULL))
806 for (i = 0; i < NR_CPUS; i++) {
807 if (cpu_possible(i)) {
808 struct cpu *p = kmalloc(sizeof(*p), GFP_KERNEL);
811 memset(p, 0, sizeof(*p));
812 register_cpu(p, i, NULL);
821 subsys_initcall(topology_init);