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/segment.h>
37 #include <asm/system.h>
39 #include <asm/processor.h>
40 #include <asm/oplib.h>
42 #include <asm/pgtable.h>
43 #include <asm/idprom.h>
45 #include <asm/starfire.h>
46 #include <asm/mmu_context.h>
47 #include <asm/timer.h>
48 #include <asm/sections.h>
49 #include <asm/setup.h>
53 #include <net/ipconfig.h>
56 struct screen_info screen_info
= {
57 0, 0, /* orig-x, orig-y */
59 0, /* orig-video-page */
60 0, /* orig-video-mode */
61 128, /* orig-video-cols */
62 0, 0, 0, /* unused, ega_bx, unused */
63 54, /* orig-video-lines */
64 0, /* orig-video-isVGA */
65 16 /* orig-video-points */
68 /* Typing sync at the prom prompt calls the function pointed to by
69 * the sync callback which I set to the following function.
70 * This should sync all filesystems and return, for now it just
71 * prints out pretty messages and returns.
74 void (*prom_palette
)(int);
75 void (*prom_keyboard
)(void);
78 prom_console_write(struct console
*con
, const char *s
, unsigned n
)
83 static struct console prom_console
= {
85 .write
= prom_console_write
,
86 .flags
= CON_CONSDEV
| CON_ENABLED
,
94 int prom_callback(long *args
)
96 struct console
*cons
, *saved_console
= NULL
;
99 extern spinlock_t prom_entry_lock
;
103 if (!(cmd
= (char *)args
[0]))
107 * The callback can be invoked on the cpu that first dropped
108 * into prom_cmdline after taking the serial interrupt, or on
109 * a slave processor that was smp_captured() if the
110 * administrator has done a switch-cpu inside obp. In either
111 * case, the cpu is marked as in-interrupt. Drop IRQ locks.
115 /* XXX Revisit the locking here someday. This is a debugging
116 * XXX feature so it isnt all that critical. -DaveM
118 local_irq_save(flags
);
120 spin_unlock(&prom_entry_lock
);
121 cons
= console_drivers
;
123 unregister_console(cons
);
124 cons
->flags
&= ~(CON_PRINTBUFFER
);
125 cons
->next
= saved_console
;
126 saved_console
= cons
;
127 cons
= console_drivers
;
129 register_console(&prom_console
);
130 if (!strcmp(cmd
, "sync")) {
131 prom_printf("PROM `%s' command...\n", cmd
);
133 if (current
->pid
!= 0) {
139 args
[args
[1] + 3] = -1;
140 prom_printf("Returning to PROM\n");
141 } else if (!strcmp(cmd
, "va>tte-data")) {
142 unsigned long ctx
, va
;
143 unsigned long tte
= 0;
144 long res
= PROM_FALSE
;
150 * Find process owning ctx, lookup mapping.
152 struct task_struct
*p
;
153 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
);
182 if (pte_present(*ptep
)) {
183 tte
= pte_val(*ptep
);
190 if ((va
>= KERNBASE
) && (va
< (KERNBASE
+ (4 * 1024 * 1024)))) {
191 unsigned long kernel_pctx
= 0;
193 if (tlb_type
== cheetah_plus
)
194 kernel_pctx
|= (CTX_CHEETAH_PLUS_NUC
|
195 CTX_CHEETAH_PLUS_CTX0
);
197 /* Spitfire Errata #32 workaround */
198 __asm__
__volatile__("stxa %0, [%1] %2\n\t"
202 "r" (PRIMARY_CONTEXT
),
206 * Locked down tlb entry.
209 if (tlb_type
== spitfire
)
210 tte
= spitfire_get_dtlb_data(SPITFIRE_HIGHEST_LOCKED_TLBENT
);
211 else if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
)
212 tte
= cheetah_get_ldtlb_data(CHEETAH_HIGHEST_LOCKED_TLBENT
);
218 if (va
< PGDIR_SIZE
) {
220 * vmalloc or prom_inherited mapping.
228 if ((va
>= LOW_OBP_ADDRESS
) && (va
< HI_OBP_ADDRESS
)) {
229 tte
= prom_virt_to_phys(va
, &error
);
234 pgdp
= pgd_offset_k(va
);
237 pudp
= pud_offset(pgdp
, va
);
240 pmdp
= pmd_offset(pudp
, va
);
244 /* Preemption implicitly disabled by virtue of
245 * being called from inside OBP.
247 ptep
= pte_offset_kernel(pmdp
, va
);
248 if (pte_present(*ptep
)) {
249 tte
= pte_val(*ptep
);
255 if (va
< PAGE_OFFSET
) {
262 if (va
& (1UL << 40)) {
267 tte
= (__pa(va
) & _PAGE_PADDR
) |
268 _PAGE_VALID
| _PAGE_SZ4MB
|
269 _PAGE_E
| _PAGE_P
| _PAGE_W
;
277 tte
= (__pa(va
) & _PAGE_PADDR
) |
278 _PAGE_VALID
| _PAGE_SZ4MB
|
279 _PAGE_CP
| _PAGE_CV
| _PAGE_P
| _PAGE_W
;
283 if (res
== PROM_TRUE
) {
285 args
[args
[1] + 3] = 0;
286 args
[args
[1] + 4] = res
;
287 args
[args
[1] + 5] = tte
;
290 args
[args
[1] + 3] = 0;
291 args
[args
[1] + 4] = res
;
293 } else if (!strcmp(cmd
, ".soft1")) {
297 prom_printf("%lx:\"%s%s%s%s%s\" ",
298 (tte
& _PAGE_SOFT
) >> 7,
299 tte
& _PAGE_MODIFIED
? "M" : "-",
300 tte
& _PAGE_ACCESSED
? "A" : "-",
301 tte
& _PAGE_READ
? "W" : "-",
302 tte
& _PAGE_WRITE
? "R" : "-",
303 tte
& _PAGE_PRESENT
? "P" : "-");
306 args
[args
[1] + 3] = 0;
307 args
[args
[1] + 4] = PROM_TRUE
;
308 } else if (!strcmp(cmd
, ".soft2")) {
312 prom_printf("%lx ", (tte
& 0x07FC000000000000UL
) >> 50);
315 args
[args
[1] + 3] = 0;
316 args
[args
[1] + 4] = PROM_TRUE
;
318 prom_printf("unknown PROM `%s' command...\n", cmd
);
320 unregister_console(&prom_console
);
321 while (saved_console
) {
322 cons
= saved_console
;
323 saved_console
= cons
->next
;
324 register_console(cons
);
326 spin_lock(&prom_entry_lock
);
327 local_irq_restore(flags
);
330 * Restore in-interrupt status for a resume from obp.
336 unsigned int boot_flags
= 0;
337 #define BOOTME_DEBUG 0x1
338 #define BOOTME_SINGLE 0x2
340 /* Exported for mm/init.c:paging_init. */
341 unsigned long cmdline_memory_size
= 0;
343 static struct console prom_debug_console
= {
345 .write
= prom_console_write
,
346 .flags
= CON_PRINTBUFFER
,
350 /* XXX Implement this at some point... */
351 void kernel_enter_debugger(void)
355 int obp_system_intr(void)
357 if (boot_flags
& BOOTME_DEBUG
) {
358 printk("OBP: system interrupted\n");
366 * Process kernel command line switches that are specific to the
367 * SPARC or that require special low-level processing.
369 static void __init
process_switch(char c
)
373 boot_flags
|= BOOTME_DEBUG
;
376 boot_flags
|= BOOTME_SINGLE
;
379 prom_printf("boot_flags_init: Halt!\n");
383 /* Use PROM debug console. */
384 register_console(&prom_debug_console
);
387 printk("Unknown boot switch (-%c)\n", c
);
392 static void __init
process_console(char *commands
)
396 /* Linux-style serial */
397 if (!strncmp(commands
, "ttyS", 4))
398 serial_console
= simple_strtoul(commands
+ 4, NULL
, 10) + 1;
399 else if (!strncmp(commands
, "tty", 3)) {
400 char c
= *(commands
+ 3);
401 /* Solaris-style serial */
402 if (c
== 'a' || c
== 'b') {
403 serial_console
= c
- 'a' + 1;
404 prom_printf ("Using /dev/tty%c as console.\n", c
);
406 /* else Linux-style fbcon, not serial */
408 #if defined(CONFIG_PROM_CONSOLE)
409 if (!strncmp(commands
, "prom", 4)) {
412 for (p
= commands
- 8; *p
&& *p
!= ' '; p
++)
414 conswitchp
= &prom_con
;
419 static void __init
boot_flags_init(char *commands
)
422 /* Move to the start of the next "argument". */
423 while (*commands
&& *commands
== ' ')
426 /* Process any command switches, otherwise skip it. */
427 if (*commands
== '\0')
429 if (*commands
== '-') {
431 while (*commands
&& *commands
!= ' ')
432 process_switch(*commands
++);
435 if (!strncmp(commands
, "console=", 8)) {
436 process_console(commands
);
437 } else if (!strncmp(commands
, "mem=", 4)) {
439 * "mem=XXX[kKmM]" overrides the PROM-reported
442 cmdline_memory_size
= simple_strtoul(commands
+ 4,
444 if (*commands
== 'K' || *commands
== 'k') {
445 cmdline_memory_size
<<= 10;
447 } else if (*commands
=='M' || *commands
=='m') {
448 cmdline_memory_size
<<= 20;
452 while (*commands
&& *commands
!= ' ')
457 extern int prom_probe_memory(void);
458 extern unsigned long start
, end
;
459 extern void panic_setup(char *, int *);
461 extern unsigned short root_flags
;
462 extern unsigned short root_dev
;
463 extern unsigned short ram_flags
;
464 #define RAMDISK_IMAGE_START_MASK 0x07FF
465 #define RAMDISK_PROMPT_FLAG 0x8000
466 #define RAMDISK_LOAD_FLAG 0x4000
468 extern int root_mountflags
;
470 char reboot_command
[COMMAND_LINE_SIZE
];
472 static struct pt_regs fake_swapper_regs
= { { 0, }, 0, 0, 0, 0 };
474 void register_prom_callbacks(void)
476 prom_setcallback(prom_callback
);
477 prom_feval(": linux-va>tte-data 2 \" va>tte-data\" $callback drop ; "
478 "' linux-va>tte-data to va>tte-data");
479 prom_feval(": linux-.soft1 1 \" .soft1\" $callback 2drop ; "
480 "' linux-.soft1 to .soft1");
481 prom_feval(": linux-.soft2 1 \" .soft2\" $callback 2drop ; "
482 "' linux-.soft2 to .soft2");
485 extern void paging_init(void);
487 void __init
setup_arch(char **cmdline_p
)
489 unsigned long highest_paddr
;
492 /* Initialize PROM console and command line. */
493 *cmdline_p
= prom_getbootargs();
494 strcpy(saved_command_line
, *cmdline_p
);
496 printk("ARCH: SUN4U\n");
498 #ifdef CONFIG_DUMMY_CONSOLE
499 conswitchp
= &dummy_con
;
500 #elif defined(CONFIG_PROM_CONSOLE)
501 conswitchp
= &prom_con
;
505 i
= (unsigned long)&irq_stat
[1] - (unsigned long)&irq_stat
[0];
506 if ((i
== SMP_CACHE_BYTES
) || (i
== (2 * SMP_CACHE_BYTES
))) {
507 extern unsigned int irqsz_patchme
[1];
508 irqsz_patchme
[0] |= ((i
== SMP_CACHE_BYTES
) ? SMP_CACHE_BYTES_SHIFT
: \
509 SMP_CACHE_BYTES_SHIFT
+ 1);
510 flushi((long)&irqsz_patchme
[0]);
512 prom_printf("Unexpected size of irq_stat[] elements\n");
516 /* Work out if we are starfire early on */
519 boot_flags_init(*cmdline_p
);
522 (void) prom_probe_memory();
524 /* In paging_init() we tip off this value to see if we need
525 * to change init_mm.pgd to point to the real alias mapping.
527 phys_base
= 0xffffffffffffffffUL
;
529 for (i
= 0; sp_banks
[i
].num_bytes
!= 0; i
++) {
532 if (sp_banks
[i
].base_addr
< phys_base
)
533 phys_base
= sp_banks
[i
].base_addr
;
534 top
= sp_banks
[i
].base_addr
+
535 sp_banks
[i
].num_bytes
;
536 if (highest_paddr
< top
)
539 pfn_base
= phys_base
>> PAGE_SHIFT
;
544 kern_base
= spitfire_get_itlb_data(sparc64_highest_locked_tlbent());
545 kern_base
&= _PAGE_PADDR_SF
;
550 kern_base
= cheetah_get_litlb_data(sparc64_highest_locked_tlbent());
551 kern_base
&= _PAGE_PADDR
;
555 kern_size
= (unsigned long)&_end
- (unsigned long)KERNBASE
;
558 root_mountflags
&= ~MS_RDONLY
;
559 ROOT_DEV
= old_decode_dev(root_dev
);
560 #ifdef CONFIG_BLK_DEV_INITRD
561 rd_image_start
= ram_flags
& RAMDISK_IMAGE_START_MASK
;
562 rd_prompt
= ((ram_flags
& RAMDISK_PROMPT_FLAG
) != 0);
563 rd_doload
= ((ram_flags
& RAMDISK_LOAD_FLAG
) != 0);
566 init_task
.thread_info
->kregs
= &fake_swapper_regs
;
569 if (!ic_set_manually
) {
570 int chosen
= prom_finddevice ("/chosen");
573 cl
= prom_getintdefault (chosen
, "client-ip", 0);
574 sv
= prom_getintdefault (chosen
, "server-ip", 0);
575 gw
= prom_getintdefault (chosen
, "gateway-ip", 0);
581 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
582 ic_proto_enabled
= 0;
591 static int __init
set_preferred_console(void)
595 /* The user has requested a console so this is already set up. */
596 if (serial_console
>= 0)
599 idev
= prom_query_input_device();
600 odev
= prom_query_output_device();
601 if (idev
== PROMDEV_IKBD
&& odev
== PROMDEV_OSCREEN
) {
603 } else if (idev
== PROMDEV_ITTYA
&& odev
== PROMDEV_OTTYA
) {
605 } else if (idev
== PROMDEV_ITTYB
&& odev
== PROMDEV_OTTYB
) {
608 prom_printf("Inconsistent console: "
609 "input %d, output %d\n",
615 return add_preferred_console("ttyS", serial_console
- 1, NULL
);
619 console_initcall(set_preferred_console
);
621 /* BUFFER is PAGE_SIZE bytes long. */
623 extern char *sparc_cpu_type
;
624 extern char *sparc_fpu_type
;
626 extern void smp_info(struct seq_file
*);
627 extern void smp_bogo(struct seq_file
*);
628 extern void mmu_info(struct seq_file
*);
630 static int show_cpuinfo(struct seq_file
*m
, void *__unused
)
635 "promlib\t\t: Version 3 Revision %d\n"
636 "prom\t\t: %d.%d.%d\n"
638 "ncpus probed\t: %ld\n"
639 "ncpus active\t: %ld\n"
641 "Cpu0Bogo\t: %lu.%02lu\n"
642 "Cpu0ClkTck\t: %016lx\n"
649 (prom_prev
>> 8) & 0xff,
651 (long)num_possible_cpus(),
652 (long)num_online_cpus()
654 , cpu_data(0).udelay_val
/(500000/HZ
),
655 (cpu_data(0).udelay_val
/(5000/HZ
)) % 100,
656 cpu_data(0).clock_tick
669 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
671 /* The pointer we are returning is arbitrary,
672 * it just has to be non-NULL and not IS_ERR
673 * in the success case.
675 return *pos
== 0 ? &c_start
: NULL
;
678 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
681 return c_start(m
, pos
);
684 static void c_stop(struct seq_file
*m
, void *v
)
688 struct seq_operations cpuinfo_op
= {
692 .show
= show_cpuinfo
,
695 extern int stop_a_enabled
;
697 void sun_do_break(void)
703 flush_user_windows();
708 int serial_console
= -1;
709 int stop_a_enabled
= 1;
711 static int __init
topology_init(void)
716 for (i
= 0; i
< NR_CPUS
; i
++) {
717 if (cpu_possible(i
)) {
718 struct cpu
*p
= kmalloc(sizeof(*p
), GFP_KERNEL
);
721 memset(p
, 0, sizeof(*p
));
722 register_cpu(p
, i
, NULL
);
731 subsys_initcall(topology_init
);