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 void (*prom_palette
)(int);
68 void (*prom_keyboard
)(void);
71 prom_console_write(struct console
*con
, const char *s
, unsigned n
)
76 unsigned int boot_flags
= 0;
77 #define BOOTME_DEBUG 0x1
78 #define BOOTME_SINGLE 0x2
80 /* Exported for mm/init.c:paging_init. */
81 unsigned long cmdline_memory_size
= 0;
83 static struct console prom_debug_console
= {
85 .write
= prom_console_write
,
86 .flags
= CON_PRINTBUFFER
,
90 /* XXX Implement this at some point... */
91 void kernel_enter_debugger(void)
95 int obp_system_intr(void)
97 if (boot_flags
& BOOTME_DEBUG
) {
98 printk("OBP: system interrupted\n");
106 * Process kernel command line switches that are specific to the
107 * SPARC or that require special low-level processing.
109 static void __init
process_switch(char c
)
113 boot_flags
|= BOOTME_DEBUG
;
116 boot_flags
|= BOOTME_SINGLE
;
119 prom_printf("boot_flags_init: Halt!\n");
123 /* Use PROM debug console. */
124 register_console(&prom_debug_console
);
127 /* Force UltraSPARC-III P-Cache on. */
128 if (tlb_type
!= cheetah
) {
129 printk("BOOT: Ignoring P-Cache force option.\n");
132 cheetah_pcache_forced_on
= 1;
133 add_taint(TAINT_MACHINE_CHECK
);
134 cheetah_enable_pcache();
138 printk("Unknown boot switch (-%c)\n", c
);
143 static void __init
process_console(char *commands
)
147 /* Linux-style serial */
148 if (!strncmp(commands
, "ttyS", 4))
149 serial_console
= simple_strtoul(commands
+ 4, NULL
, 10) + 1;
150 else if (!strncmp(commands
, "tty", 3)) {
151 char c
= *(commands
+ 3);
152 /* Solaris-style serial */
153 if (c
== 'a' || c
== 'b') {
154 serial_console
= c
- 'a' + 1;
155 prom_printf ("Using /dev/tty%c as console.\n", c
);
157 /* else Linux-style fbcon, not serial */
159 #if defined(CONFIG_PROM_CONSOLE)
160 if (!strncmp(commands
, "prom", 4)) {
163 for (p
= commands
- 8; *p
&& *p
!= ' '; p
++)
165 conswitchp
= &prom_con
;
170 static void __init
boot_flags_init(char *commands
)
173 /* Move to the start of the next "argument". */
174 while (*commands
&& *commands
== ' ')
177 /* Process any command switches, otherwise skip it. */
178 if (*commands
== '\0')
180 if (*commands
== '-') {
182 while (*commands
&& *commands
!= ' ')
183 process_switch(*commands
++);
186 if (!strncmp(commands
, "console=", 8)) {
187 process_console(commands
);
188 } else if (!strncmp(commands
, "mem=", 4)) {
190 * "mem=XXX[kKmM]" overrides the PROM-reported
193 cmdline_memory_size
= simple_strtoul(commands
+ 4,
195 if (*commands
== 'K' || *commands
== 'k') {
196 cmdline_memory_size
<<= 10;
198 } else if (*commands
=='M' || *commands
=='m') {
199 cmdline_memory_size
<<= 20;
203 while (*commands
&& *commands
!= ' ')
208 extern void panic_setup(char *, int *);
210 extern unsigned short root_flags
;
211 extern unsigned short root_dev
;
212 extern unsigned short ram_flags
;
213 #define RAMDISK_IMAGE_START_MASK 0x07FF
214 #define RAMDISK_PROMPT_FLAG 0x8000
215 #define RAMDISK_LOAD_FLAG 0x4000
217 extern int root_mountflags
;
219 char reboot_command
[COMMAND_LINE_SIZE
];
221 static struct pt_regs fake_swapper_regs
= { { 0, }, 0, 0, 0, 0 };
223 static void __init
per_cpu_patch(void)
226 struct cpuid_patch_entry
*p
;
230 if (tlb_type
== spitfire
&& !this_is_starfire
)
234 if (tlb_type
!= hypervisor
) {
235 __asm__ ("rdpr %%ver, %0" : "=r" (ver
));
236 is_jbus
= ((ver
>> 32) == __JALAPENO_ID
||
237 (ver
>> 32) == __SERRANO_ID
);
241 while (p
< &__cpuid_patch_end
) {
242 unsigned long addr
= p
->addr
;
247 insns
= &p
->starfire
[0];
252 insns
= &p
->cheetah_jbus
[0];
254 insns
= &p
->cheetah_safari
[0];
257 insns
= &p
->sun4v
[0];
260 prom_printf("Unknown cpu type, halting.\n");
264 *(unsigned int *) (addr
+ 0) = insns
[0];
266 __asm__
__volatile__("flush %0" : : "r" (addr
+ 0));
268 *(unsigned int *) (addr
+ 4) = insns
[1];
270 __asm__
__volatile__("flush %0" : : "r" (addr
+ 4));
272 *(unsigned int *) (addr
+ 8) = insns
[2];
274 __asm__
__volatile__("flush %0" : : "r" (addr
+ 8));
276 *(unsigned int *) (addr
+ 12) = insns
[3];
278 __asm__
__volatile__("flush %0" : : "r" (addr
+ 12));
285 static void __init
sun4v_patch(void)
287 struct sun4v_1insn_patch_entry
*p1
;
288 struct sun4v_2insn_patch_entry
*p2
;
290 if (tlb_type
!= hypervisor
)
293 p1
= &__sun4v_1insn_patch
;
294 while (p1
< &__sun4v_1insn_patch_end
) {
295 unsigned long addr
= p1
->addr
;
297 *(unsigned int *) (addr
+ 0) = p1
->insn
;
299 __asm__
__volatile__("flush %0" : : "r" (addr
+ 0));
304 p2
= &__sun4v_2insn_patch
;
305 while (p2
< &__sun4v_2insn_patch_end
) {
306 unsigned long addr
= p2
->addr
;
308 *(unsigned int *) (addr
+ 0) = p2
->insns
[0];
310 __asm__
__volatile__("flush %0" : : "r" (addr
+ 0));
312 *(unsigned int *) (addr
+ 4) = p2
->insns
[1];
314 __asm__
__volatile__("flush %0" : : "r" (addr
+ 4));
320 void __init
setup_arch(char **cmdline_p
)
322 /* Initialize PROM console and command line. */
323 *cmdline_p
= prom_getbootargs();
324 strcpy(saved_command_line
, *cmdline_p
);
326 if (tlb_type
== hypervisor
)
327 printk("ARCH: SUN4V\n");
329 printk("ARCH: SUN4U\n");
331 #ifdef CONFIG_DUMMY_CONSOLE
332 conswitchp
= &dummy_con
;
333 #elif defined(CONFIG_PROM_CONSOLE)
334 conswitchp
= &prom_con
;
337 /* Work out if we are starfire early on */
340 /* Now we know enough to patch the get_cpuid sequences
347 boot_flags_init(*cmdline_p
);
352 root_mountflags
&= ~MS_RDONLY
;
353 ROOT_DEV
= old_decode_dev(root_dev
);
354 #ifdef CONFIG_BLK_DEV_INITRD
355 rd_image_start
= ram_flags
& RAMDISK_IMAGE_START_MASK
;
356 rd_prompt
= ((ram_flags
& RAMDISK_PROMPT_FLAG
) != 0);
357 rd_doload
= ((ram_flags
& RAMDISK_LOAD_FLAG
) != 0);
360 task_thread_info(&init_task
)->kregs
= &fake_swapper_regs
;
363 if (!ic_set_manually
) {
364 int chosen
= prom_finddevice ("/chosen");
367 cl
= prom_getintdefault (chosen
, "client-ip", 0);
368 sv
= prom_getintdefault (chosen
, "server-ip", 0);
369 gw
= prom_getintdefault (chosen
, "gateway-ip", 0);
375 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
376 ic_proto_enabled
= 0;
382 smp_setup_cpu_possible_map();
386 /* Get boot processor trap_block[] setup. */
387 init_cur_cpu_trap(current_thread_info());
390 static int __init
set_preferred_console(void)
394 /* The user has requested a console so this is already set up. */
395 if (serial_console
>= 0)
398 idev
= prom_query_input_device();
399 odev
= prom_query_output_device();
400 if (idev
== PROMDEV_IKBD
&& odev
== PROMDEV_OSCREEN
) {
402 } else if (idev
== PROMDEV_ITTYA
&& odev
== PROMDEV_OTTYA
) {
404 } else if (idev
== PROMDEV_ITTYB
&& odev
== PROMDEV_OTTYB
) {
406 } else if (idev
== PROMDEV_IRSC
&& odev
== PROMDEV_ORSC
) {
408 } else if (idev
== PROMDEV_IVCONS
&& odev
== PROMDEV_OVCONS
) {
409 /* sunhv_console_init() doesn't check the serial_console
413 return add_preferred_console("ttyHV", 0, NULL
);
415 prom_printf("Inconsistent console: "
416 "input %d, output %d\n",
422 return add_preferred_console("ttyS", serial_console
- 1, NULL
);
426 console_initcall(set_preferred_console
);
428 /* BUFFER is PAGE_SIZE bytes long. */
430 extern char *sparc_cpu_type
;
431 extern char *sparc_fpu_type
;
433 extern void smp_info(struct seq_file
*);
434 extern void smp_bogo(struct seq_file
*);
435 extern void mmu_info(struct seq_file
*);
437 unsigned int dcache_parity_tl1_occurred
;
438 unsigned int icache_parity_tl1_occurred
;
440 static int ncpus_probed
;
442 static int show_cpuinfo(struct seq_file
*m
, void *__unused
)
447 "promlib\t\t: Version 3 Revision %d\n"
448 "prom\t\t: %d.%d.%d\n"
450 "ncpus probed\t: %d\n"
451 "ncpus active\t: %d\n"
452 "D$ parity tl1\t: %u\n"
453 "I$ parity tl1\t: %u\n"
455 "Cpu0Bogo\t: %lu.%02lu\n"
456 "Cpu0ClkTck\t: %016lx\n"
463 (prom_prev
>> 8) & 0xff,
467 dcache_parity_tl1_occurred
,
468 icache_parity_tl1_occurred
470 , cpu_data(0).udelay_val
/(500000/HZ
),
471 (cpu_data(0).udelay_val
/(5000/HZ
)) % 100,
472 cpu_data(0).clock_tick
485 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
487 /* The pointer we are returning is arbitrary,
488 * it just has to be non-NULL and not IS_ERR
489 * in the success case.
491 return *pos
== 0 ? &c_start
: NULL
;
494 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
497 return c_start(m
, pos
);
500 static void c_stop(struct seq_file
*m
, void *v
)
504 struct seq_operations cpuinfo_op
= {
508 .show
= show_cpuinfo
,
511 extern int stop_a_enabled
;
513 void sun_do_break(void)
519 flush_user_windows();
524 int serial_console
= -1;
525 int stop_a_enabled
= 1;
527 static int __init
topology_init(void)
533 /* Count the number of physically present processors in
534 * the machine, even on uniprocessor, so that /proc/cpuinfo
535 * output is consistent with 2.4.x
538 while (!cpu_find_by_instance(ncpus_probed
, NULL
, NULL
))
541 for (i
= 0; i
< NR_CPUS
; i
++) {
542 if (cpu_possible(i
)) {
543 struct cpu
*p
= kmalloc(sizeof(*p
), GFP_KERNEL
);
546 memset(p
, 0, sizeof(*p
));
547 register_cpu(p
, i
, NULL
);
556 subsys_initcall(topology_init
);