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/export.h>
13 #include <linux/stddef.h>
14 #include <linux/unistd.h>
15 #include <linux/ptrace.h>
17 #include <linux/user.h>
18 #include <linux/screen_info.h>
19 #include <linux/delay.h>
21 #include <linux/seq_file.h>
22 #include <linux/syscalls.h>
23 #include <linux/kdev_t.h>
24 #include <linux/major.h>
25 #include <linux/string.h>
26 #include <linux/init.h>
27 #include <linux/inet.h>
28 #include <linux/console.h>
29 #include <linux/root_dev.h>
30 #include <linux/interrupt.h>
31 #include <linux/cpu.h>
32 #include <linux/initrd.h>
33 #include <linux/module.h>
35 #include <asm/system.h>
37 #include <asm/processor.h>
38 #include <asm/oplib.h>
40 #include <asm/pgtable.h>
41 #include <asm/idprom.h>
43 #include <asm/starfire.h>
44 #include <asm/mmu_context.h>
45 #include <asm/timer.h>
46 #include <asm/sections.h>
47 #include <asm/setup.h>
49 #include <asm/ns87303.h>
50 #include <asm/btext.h>
52 #include <asm/mdesc.h>
55 #include <net/ipconfig.h>
61 /* Used to synchronize accesses to NatSemi SUPER I/O chip configure
62 * operations in asm/ns87303.h
64 DEFINE_SPINLOCK(ns87303_lock
);
65 EXPORT_SYMBOL(ns87303_lock
);
67 struct screen_info screen_info
= {
68 0, 0, /* orig-x, orig-y */
70 0, /* orig-video-page */
71 0, /* orig-video-mode */
72 128, /* orig-video-cols */
73 0, 0, 0, /* unused, ega_bx, unused */
74 54, /* orig-video-lines */
75 0, /* orig-video-isVGA */
76 16 /* orig-video-points */
80 prom_console_write(struct console
*con
, const char *s
, unsigned n
)
85 /* Exported for mm/init.c:paging_init. */
86 unsigned long cmdline_memory_size
= 0;
88 static struct console prom_early_console
= {
90 .write
= prom_console_write
,
91 .flags
= CON_PRINTBUFFER
| CON_BOOT
| CON_ANYTIME
,
96 * Process kernel command line switches that are specific to the
97 * SPARC or that require special low-level processing.
99 static void __init
process_switch(char c
)
106 prom_printf("boot_flags_init: Halt!\n");
110 /* Just ignore, this behavior is now the default. */
113 /* Force UltraSPARC-III P-Cache on. */
114 if (tlb_type
!= cheetah
) {
115 printk("BOOT: Ignoring P-Cache force option.\n");
118 cheetah_pcache_forced_on
= 1;
119 add_taint(TAINT_MACHINE_CHECK
);
120 cheetah_enable_pcache();
124 printk("Unknown boot switch (-%c)\n", c
);
129 static void __init
boot_flags_init(char *commands
)
132 /* Move to the start of the next "argument". */
133 while (*commands
&& *commands
== ' ')
136 /* Process any command switches, otherwise skip it. */
137 if (*commands
== '\0')
139 if (*commands
== '-') {
141 while (*commands
&& *commands
!= ' ')
142 process_switch(*commands
++);
145 if (!strncmp(commands
, "mem=", 4)) {
147 * "mem=XXX[kKmM]" overrides the PROM-reported
150 cmdline_memory_size
= simple_strtoul(commands
+ 4,
152 if (*commands
== 'K' || *commands
== 'k') {
153 cmdline_memory_size
<<= 10;
155 } else if (*commands
=='M' || *commands
=='m') {
156 cmdline_memory_size
<<= 20;
160 while (*commands
&& *commands
!= ' ')
165 extern unsigned short root_flags
;
166 extern unsigned short root_dev
;
167 extern unsigned short ram_flags
;
168 #define RAMDISK_IMAGE_START_MASK 0x07FF
169 #define RAMDISK_PROMPT_FLAG 0x8000
170 #define RAMDISK_LOAD_FLAG 0x4000
172 extern int root_mountflags
;
174 char reboot_command
[COMMAND_LINE_SIZE
];
176 static struct pt_regs fake_swapper_regs
= { { 0, }, 0, 0, 0, 0 };
178 void __init
per_cpu_patch(void)
180 struct cpuid_patch_entry
*p
;
184 if (tlb_type
== spitfire
&& !this_is_starfire
)
188 if (tlb_type
!= hypervisor
) {
189 __asm__ ("rdpr %%ver, %0" : "=r" (ver
));
190 is_jbus
= ((ver
>> 32UL) == __JALAPENO_ID
||
191 (ver
>> 32UL) == __SERRANO_ID
);
195 while (p
< &__cpuid_patch_end
) {
196 unsigned long addr
= p
->addr
;
201 insns
= &p
->starfire
[0];
206 insns
= &p
->cheetah_jbus
[0];
208 insns
= &p
->cheetah_safari
[0];
211 insns
= &p
->sun4v
[0];
214 prom_printf("Unknown cpu type, halting.\n");
218 *(unsigned int *) (addr
+ 0) = insns
[0];
220 __asm__
__volatile__("flush %0" : : "r" (addr
+ 0));
222 *(unsigned int *) (addr
+ 4) = insns
[1];
224 __asm__
__volatile__("flush %0" : : "r" (addr
+ 4));
226 *(unsigned int *) (addr
+ 8) = insns
[2];
228 __asm__
__volatile__("flush %0" : : "r" (addr
+ 8));
230 *(unsigned int *) (addr
+ 12) = insns
[3];
232 __asm__
__volatile__("flush %0" : : "r" (addr
+ 12));
238 void __init
sun4v_patch(void)
240 extern void sun4v_hvapi_init(void);
241 struct sun4v_1insn_patch_entry
*p1
;
242 struct sun4v_2insn_patch_entry
*p2
;
244 if (tlb_type
!= hypervisor
)
247 p1
= &__sun4v_1insn_patch
;
248 while (p1
< &__sun4v_1insn_patch_end
) {
249 unsigned long addr
= p1
->addr
;
251 *(unsigned int *) (addr
+ 0) = p1
->insn
;
253 __asm__
__volatile__("flush %0" : : "r" (addr
+ 0));
258 p2
= &__sun4v_2insn_patch
;
259 while (p2
< &__sun4v_2insn_patch_end
) {
260 unsigned long addr
= p2
->addr
;
262 *(unsigned int *) (addr
+ 0) = p2
->insns
[0];
264 __asm__
__volatile__("flush %0" : : "r" (addr
+ 0));
266 *(unsigned int *) (addr
+ 4) = p2
->insns
[1];
268 __asm__
__volatile__("flush %0" : : "r" (addr
+ 4));
276 static void __init
popc_patch(void)
278 struct popc_3insn_patch_entry
*p3
;
279 struct popc_6insn_patch_entry
*p6
;
281 p3
= &__popc_3insn_patch
;
282 while (p3
< &__popc_3insn_patch_end
) {
283 unsigned long i
, addr
= p3
->addr
;
285 for (i
= 0; i
< 3; i
++) {
286 *(unsigned int *) (addr
+ (i
* 4)) = p3
->insns
[i
];
288 __asm__
__volatile__("flush %0"
289 : : "r" (addr
+ (i
* 4)));
295 p6
= &__popc_6insn_patch
;
296 while (p6
< &__popc_6insn_patch_end
) {
297 unsigned long i
, addr
= p6
->addr
;
299 for (i
= 0; i
< 6; i
++) {
300 *(unsigned int *) (addr
+ (i
* 4)) = p6
->insns
[i
];
302 __asm__
__volatile__("flush %0"
303 : : "r" (addr
+ (i
* 4)));
311 void __init
boot_cpu_id_too_large(int cpu
)
313 prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
319 /* On Ultra, we support all of the v8 capabilities. */
320 unsigned long sparc64_elf_hwcap
= (HWCAP_SPARC_FLUSH
| HWCAP_SPARC_STBAR
|
321 HWCAP_SPARC_SWAP
| HWCAP_SPARC_MULDIV
|
323 EXPORT_SYMBOL(sparc64_elf_hwcap
);
325 static const char *hwcaps
[] = {
326 "flush", "stbar", "swap", "muldiv", "v9",
327 "ultra3", "blkinit", "n2",
329 /* These strings are as they appear in the machine description
330 * 'hwcap-list' property for cpu nodes.
332 "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
333 "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
337 void cpucap_info(struct seq_file
*m
)
339 unsigned long caps
= sparc64_elf_hwcap
;
342 seq_puts(m
, "cpucaps\t\t: ");
343 for (i
= 0; i
< ARRAY_SIZE(hwcaps
); i
++) {
344 unsigned long bit
= 1UL << i
;
346 seq_printf(m
, "%s%s",
347 printed
? "," : "", hwcaps
[i
]);
354 static void __init
report_hwcaps(unsigned long caps
)
358 printk(KERN_INFO
"CPU CAPS: [");
359 for (i
= 0; i
< ARRAY_SIZE(hwcaps
); i
++) {
360 unsigned long bit
= 1UL << i
;
362 printk(KERN_CONT
"%s%s",
363 printed
? "," : "", hwcaps
[i
]);
364 if (++printed
== 8) {
365 printk(KERN_CONT
"]\n");
366 printk(KERN_INFO
"CPU CAPS: [");
371 printk(KERN_CONT
"]\n");
374 static unsigned long __init
mdesc_cpu_hwcap_list(void)
376 struct mdesc_handle
*hp
;
377 unsigned long caps
= 0;
386 pn
= mdesc_node_by_name(hp
, MDESC_NODE_NULL
, "cpu");
387 if (pn
== MDESC_NODE_NULL
)
390 prop
= mdesc_get_property(hp
, pn
, "hwcap-list", &len
);
397 for (i
= 0; i
< ARRAY_SIZE(hwcaps
); i
++) {
398 unsigned long bit
= 1UL << i
;
400 if (!strcmp(prop
, hwcaps
[i
])) {
406 plen
= strlen(prop
) + 1;
416 /* This yields a mask that user programs can use to figure out what
417 * instruction set this cpu supports.
419 static void __init
init_sparc64_elf_hwcap(void)
421 unsigned long cap
= sparc64_elf_hwcap
;
422 unsigned long mdesc_caps
;
424 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
)
425 cap
|= HWCAP_SPARC_ULTRA3
;
426 else if (tlb_type
== hypervisor
) {
427 if (sun4v_chip_type
== SUN4V_CHIP_NIAGARA1
||
428 sun4v_chip_type
== SUN4V_CHIP_NIAGARA2
||
429 sun4v_chip_type
== SUN4V_CHIP_NIAGARA3
)
430 cap
|= HWCAP_SPARC_BLKINIT
;
431 if (sun4v_chip_type
== SUN4V_CHIP_NIAGARA2
||
432 sun4v_chip_type
== SUN4V_CHIP_NIAGARA3
)
433 cap
|= HWCAP_SPARC_N2
;
436 cap
|= (AV_SPARC_MUL32
| AV_SPARC_DIV32
| AV_SPARC_V8PLUS
);
438 mdesc_caps
= mdesc_cpu_hwcap_list();
440 if (tlb_type
== spitfire
)
442 if (tlb_type
== cheetah
|| tlb_type
== cheetah_plus
)
443 cap
|= AV_SPARC_VIS
| AV_SPARC_VIS2
;
444 if (tlb_type
== cheetah_plus
) {
445 unsigned long impl
, ver
;
447 __asm__
__volatile__("rdpr %%ver, %0" : "=r" (ver
));
448 impl
= ((ver
>> 32) & 0xffff);
449 if (impl
== PANTHER_IMPL
)
450 cap
|= AV_SPARC_POPC
;
452 if (tlb_type
== hypervisor
) {
453 if (sun4v_chip_type
== SUN4V_CHIP_NIAGARA1
)
454 cap
|= AV_SPARC_ASI_BLK_INIT
;
455 if (sun4v_chip_type
== SUN4V_CHIP_NIAGARA2
||
456 sun4v_chip_type
== SUN4V_CHIP_NIAGARA3
)
457 cap
|= (AV_SPARC_VIS
| AV_SPARC_VIS2
|
458 AV_SPARC_ASI_BLK_INIT
|
460 if (sun4v_chip_type
== SUN4V_CHIP_NIAGARA3
)
461 cap
|= (AV_SPARC_VIS3
| AV_SPARC_HPC
|
465 sparc64_elf_hwcap
= cap
| mdesc_caps
;
467 report_hwcaps(sparc64_elf_hwcap
);
469 if (sparc64_elf_hwcap
& AV_SPARC_POPC
)
473 void __init
setup_arch(char **cmdline_p
)
475 /* Initialize PROM console and command line. */
476 *cmdline_p
= prom_getbootargs();
477 strcpy(boot_command_line
, *cmdline_p
);
480 boot_flags_init(*cmdline_p
);
481 #ifdef CONFIG_EARLYFB
482 if (btext_find_display())
484 register_console(&prom_early_console
);
486 if (tlb_type
== hypervisor
)
487 printk("ARCH: SUN4V\n");
489 printk("ARCH: SUN4U\n");
491 #ifdef CONFIG_DUMMY_CONSOLE
492 conswitchp
= &dummy_con
;
498 root_mountflags
&= ~MS_RDONLY
;
499 ROOT_DEV
= old_decode_dev(root_dev
);
500 #ifdef CONFIG_BLK_DEV_RAM
501 rd_image_start
= ram_flags
& RAMDISK_IMAGE_START_MASK
;
502 rd_prompt
= ((ram_flags
& RAMDISK_PROMPT_FLAG
) != 0);
503 rd_doload
= ((ram_flags
& RAMDISK_LOAD_FLAG
) != 0);
506 task_thread_info(&init_task
)->kregs
= &fake_swapper_regs
;
509 if (!ic_set_manually
) {
510 phandle chosen
= prom_finddevice("/chosen");
513 cl
= prom_getintdefault (chosen
, "client-ip", 0);
514 sv
= prom_getintdefault (chosen
, "server-ip", 0);
515 gw
= prom_getintdefault (chosen
, "gateway-ip", 0);
521 #if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
522 ic_proto_enabled
= 0;
528 /* Get boot processor trap_block[] setup. */
529 init_cur_cpu_trap(current_thread_info());
532 init_sparc64_elf_hwcap();
535 extern int stop_a_enabled
;
537 void sun_do_break(void)
543 flush_user_windows();
547 EXPORT_SYMBOL(sun_do_break
);
549 int stop_a_enabled
= 1;
550 EXPORT_SYMBOL(stop_a_enabled
);