blob: c8b03a4f68bf8554a5f7e31b0c873474bac730f7 [file] [log] [blame]
Adrian Bunkb00dc832008-05-19 16:52:27 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Jon Smirl894673e2006-07-10 04:44:13 -070018#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/fs.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
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/system.h>
35#include <asm/io.h>
36#include <asm/processor.h>
37#include <asm/oplib.h>
38#include <asm/page.h>
39#include <asm/pgtable.h>
40#include <asm/idprom.h>
41#include <asm/head.h>
42#include <asm/starfire.h>
43#include <asm/mmu_context.h>
44#include <asm/timer.h>
45#include <asm/sections.h>
46#include <asm/setup.h>
47#include <asm/mmu.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070048#include <asm/ns87303.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#ifdef CONFIG_IP_PNP
51#include <net/ipconfig.h>
52#endif
53
David S. Miller3d5ae6b2008-03-25 21:51:40 -070054#include "entry.h"
55
David S. Miller5cbc3072007-05-25 15:49:59 -070056/* Used to synchronize accesses to NatSemi SUPER I/O chip configure
57 * operations in asm/ns87303.h
58 */
59DEFINE_SPINLOCK(ns87303_lock);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061struct screen_info screen_info = {
62 0, 0, /* orig-x, orig-y */
63 0, /* unused */
64 0, /* orig-video-page */
65 0, /* orig-video-mode */
66 128, /* orig-video-cols */
67 0, 0, 0, /* unused, ega_bx, unused */
68 54, /* orig-video-lines */
69 0, /* orig-video-isVGA */
70 16 /* orig-video-points */
71};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static void
74prom_console_write(struct console *con, const char *s, unsigned n)
75{
76 prom_write(s, n);
77}
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079/* Exported for mm/init.c:paging_init. */
80unsigned long cmdline_memory_size = 0;
81
David S. Miller3c62a2d2008-02-17 23:22:50 -080082static struct console prom_early_console = {
83 .name = "earlyprom",
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 .write = prom_console_write,
David S. Millerdb9a7fb2008-04-23 22:22:29 -070085 .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .index = -1,
87};
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/*
90 * Process kernel command line switches that are specific to the
91 * SPARC or that require special low-level processing.
92 */
93static void __init process_switch(char c)
94{
95 switch (c) {
96 case 'd':
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 case 's':
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 break;
99 case 'h':
100 prom_printf("boot_flags_init: Halt!\n");
101 prom_halt();
102 break;
103 case 'p':
David S. Miller3c62a2d2008-02-17 23:22:50 -0800104 /* Just ignore, this behavior is now the default. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 break;
David S. Miller816242d2005-05-23 15:52:08 -0700106 case 'P':
107 /* Force UltraSPARC-III P-Cache on. */
108 if (tlb_type != cheetah) {
109 printk("BOOT: Ignoring P-Cache force option.\n");
110 break;
111 }
112 cheetah_pcache_forced_on = 1;
113 add_taint(TAINT_MACHINE_CHECK);
114 cheetah_enable_pcache();
115 break;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 default:
118 printk("Unknown boot switch (-%c)\n", c);
119 break;
120 }
121}
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123static void __init boot_flags_init(char *commands)
124{
125 while (*commands) {
126 /* Move to the start of the next "argument". */
127 while (*commands && *commands == ' ')
128 commands++;
129
130 /* Process any command switches, otherwise skip it. */
131 if (*commands == '\0')
132 break;
133 if (*commands == '-') {
134 commands++;
135 while (*commands && *commands != ' ')
136 process_switch(*commands++);
137 continue;
138 }
David S. Millerc73fcc82007-07-20 16:59:26 -0700139 if (!strncmp(commands, "mem=", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /*
141 * "mem=XXX[kKmM]" overrides the PROM-reported
142 * memory size.
143 */
144 cmdline_memory_size = simple_strtoul(commands + 4,
145 &commands, 0);
146 if (*commands == 'K' || *commands == 'k') {
147 cmdline_memory_size <<= 10;
148 commands++;
149 } else if (*commands=='M' || *commands=='m') {
150 cmdline_memory_size <<= 20;
151 commands++;
152 }
153 }
154 while (*commands && *commands != ' ')
155 commands++;
156 }
157}
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159extern unsigned short root_flags;
160extern unsigned short root_dev;
161extern unsigned short ram_flags;
162#define RAMDISK_IMAGE_START_MASK 0x07FF
163#define RAMDISK_PROMPT_FLAG 0x8000
164#define RAMDISK_LOAD_FLAG 0x4000
165
166extern int root_mountflags;
167
168char reboot_command[COMMAND_LINE_SIZE];
169
170static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
171
David S. Miller951bc822006-05-31 01:24:02 -0700172void __init per_cpu_patch(void)
David S. Miller92704a12006-02-26 23:27:19 -0800173{
David S. Miller92704a12006-02-26 23:27:19 -0800174 struct cpuid_patch_entry *p;
175 unsigned long ver;
176 int is_jbus;
177
178 if (tlb_type == spitfire && !this_is_starfire)
179 return;
180
David S. Millerd82ace72006-02-09 02:52:44 -0800181 is_jbus = 0;
182 if (tlb_type != hypervisor) {
183 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
David S. Millerebd8c562006-02-17 08:38:06 -0800184 is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
185 (ver >> 32UL) == __SERRANO_ID);
David S. Millerd82ace72006-02-09 02:52:44 -0800186 }
David S. Miller92704a12006-02-26 23:27:19 -0800187
188 p = &__cpuid_patch;
189 while (p < &__cpuid_patch_end) {
190 unsigned long addr = p->addr;
191 unsigned int *insns;
192
193 switch (tlb_type) {
194 case spitfire:
195 insns = &p->starfire[0];
196 break;
197 case cheetah:
198 case cheetah_plus:
199 if (is_jbus)
200 insns = &p->cheetah_jbus[0];
201 else
202 insns = &p->cheetah_safari[0];
203 break;
David S. Millerd96b8152006-02-04 15:40:53 -0800204 case hypervisor:
205 insns = &p->sun4v[0];
206 break;
David S. Miller92704a12006-02-26 23:27:19 -0800207 default:
208 prom_printf("Unknown cpu type, halting.\n");
209 prom_halt();
210 };
211
212 *(unsigned int *) (addr + 0) = insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800213 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800214 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
215
216 *(unsigned int *) (addr + 4) = insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800217 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800218 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
219
220 *(unsigned int *) (addr + 8) = insns[2];
David S. Miller840aaef2006-02-06 15:52:05 -0800221 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800222 __asm__ __volatile__("flush %0" : : "r" (addr + 8));
223
224 *(unsigned int *) (addr + 12) = insns[3];
David S. Miller840aaef2006-02-06 15:52:05 -0800225 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800226 __asm__ __volatile__("flush %0" : : "r" (addr + 12));
227
228 p++;
229 }
David S. Miller92704a12006-02-26 23:27:19 -0800230}
231
David S. Miller951bc822006-05-31 01:24:02 -0700232void __init sun4v_patch(void)
David S. Miller936f4822006-02-05 21:29:28 -0800233{
David S. Millerc7754d42007-05-15 17:03:54 -0700234 extern void sun4v_hvapi_init(void);
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800235 struct sun4v_1insn_patch_entry *p1;
236 struct sun4v_2insn_patch_entry *p2;
David S. Miller936f4822006-02-05 21:29:28 -0800237
238 if (tlb_type != hypervisor)
239 return;
240
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800241 p1 = &__sun4v_1insn_patch;
242 while (p1 < &__sun4v_1insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800243 unsigned long addr = p1->addr;
David S. Miller936f4822006-02-05 21:29:28 -0800244
David S. Miller45fec052006-02-05 22:27:28 -0800245 *(unsigned int *) (addr + 0) = p1->insn;
David S. Miller840aaef2006-02-06 15:52:05 -0800246 wmb();
David S. Miller936f4822006-02-05 21:29:28 -0800247 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
248
David S. Miller45fec052006-02-05 22:27:28 -0800249 p1++;
250 }
251
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800252 p2 = &__sun4v_2insn_patch;
253 while (p2 < &__sun4v_2insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800254 unsigned long addr = p2->addr;
255
256 *(unsigned int *) (addr + 0) = p2->insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800257 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800258 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
259
David S. Millerfd050682006-02-11 11:05:52 -0800260 *(unsigned int *) (addr + 4) = p2->insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800261 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800262 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
263
264 p2++;
David S. Miller936f4822006-02-05 21:29:28 -0800265 }
David S. Millerc7754d42007-05-15 17:03:54 -0700266
267 sun4v_hvapi_init();
David S. Miller936f4822006-02-05 21:29:28 -0800268}
269
David S. Miller951bc822006-05-31 01:24:02 -0700270#ifdef CONFIG_SMP
271void __init boot_cpu_id_too_large(int cpu)
272{
273 prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
274 cpu, NR_CPUS);
275 prom_halt();
276}
277#endif
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279void __init setup_arch(char **cmdline_p)
280{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* Initialize PROM console and command line. */
282 *cmdline_p = prom_getbootargs();
Alon Bar-Lev383464c2007-02-12 00:54:22 -0800283 strcpy(boot_command_line, *cmdline_p);
David S. Millerce3b1d42008-03-19 03:54:09 -0700284 parse_early_param();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
David S. Miller3c62a2d2008-02-17 23:22:50 -0800286 boot_flags_init(*cmdline_p);
287 register_console(&prom_early_console);
288
David S. Miller3a8c0692006-02-09 02:54:54 -0800289 if (tlb_type == hypervisor)
290 printk("ARCH: SUN4V\n");
291 else
292 printk("ARCH: SUN4U\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294#ifdef CONFIG_DUMMY_CONSOLE
295 conswitchp = &dummy_con;
296#elif defined(CONFIG_PROM_CONSOLE)
297 conswitchp = &prom_con;
298#endif
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
302 if (!root_flags)
303 root_mountflags &= ~MS_RDONLY;
304 ROOT_DEV = old_decode_dev(root_dev);
Andrew Morton467418f2006-03-19 12:46:55 -0800305#ifdef CONFIG_BLK_DEV_RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
307 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
308 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
309#endif
310
Al Virof3169642006-01-12 01:05:42 -0800311 task_thread_info(&init_task)->kregs = &fake_swapper_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313#ifdef CONFIG_IP_PNP
314 if (!ic_set_manually) {
315 int chosen = prom_finddevice ("/chosen");
316 u32 cl, sv, gw;
317
318 cl = prom_getintdefault (chosen, "client-ip", 0);
319 sv = prom_getintdefault (chosen, "server-ip", 0);
320 gw = prom_getintdefault (chosen, "gateway-ip", 0);
321 if (cl && sv) {
322 ic_myaddr = cl;
323 ic_servaddr = sv;
324 if (gw)
325 ic_gateway = gw;
326#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
327 ic_proto_enabled = 0;
328#endif
329 }
330 }
331#endif
332
David S. Miller56fb4df2006-02-26 23:24:22 -0800333 /* Get boot processor trap_block[] setup. */
David S. Miller72aff532006-02-17 01:29:17 -0800334 init_cur_cpu_trap(current_thread_info());
David S. Miller52845cd2006-02-26 23:32:33 -0800335
336 paging_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339/* BUFFER is PAGE_SIZE bytes long. */
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341extern void smp_info(struct seq_file *);
342extern void smp_bogo(struct seq_file *);
343extern void mmu_info(struct seq_file *);
344
David S. Miller80dc0d62005-09-26 00:32:17 -0700345unsigned int dcache_parity_tl1_occurred;
346unsigned int icache_parity_tl1_occurred;
347
David S. Miller5cbc3072007-05-25 15:49:59 -0700348int ncpus_probed;
David S. Miller4d45cba2005-11-11 12:48:56 -0800349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350static int show_cpuinfo(struct seq_file *m, void *__unused)
351{
352 seq_printf(m,
353 "cpu\t\t: %s\n"
354 "fpu\t\t: %s\n"
David S. Miller90a66462006-03-08 17:18:19 -0800355 "prom\t\t: %s\n"
356 "type\t\t: %s\n"
David S. Miller4d45cba2005-11-11 12:48:56 -0800357 "ncpus probed\t: %d\n"
358 "ncpus active\t: %d\n"
David S. Miller80dc0d62005-09-26 00:32:17 -0700359 "D$ parity tl1\t: %u\n"
360 "I$ parity tl1\t: %u\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361#ifndef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 "Cpu0ClkTck\t: %016lx\n"
363#endif
364 ,
365 sparc_cpu_type,
366 sparc_fpu_type,
David S. Miller90a66462006-03-08 17:18:19 -0800367 prom_version,
368 ((tlb_type == hypervisor) ?
369 "sun4v" :
370 "sun4u"),
David S. Miller4d45cba2005-11-11 12:48:56 -0800371 ncpus_probed,
372 num_online_cpus(),
David S. Miller80dc0d62005-09-26 00:32:17 -0700373 dcache_parity_tl1_occurred,
Fabio Massimo Di Nitto3ac66e32007-07-16 14:15:39 -0700374 icache_parity_tl1_occurred
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#ifndef CONFIG_SMP
Fabio Massimo Di Nitto3ac66e32007-07-16 14:15:39 -0700376 , cpu_data(0).clock_tick
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#endif
378 );
379#ifdef CONFIG_SMP
380 smp_bogo(m);
381#endif
382 mmu_info(m);
383#ifdef CONFIG_SMP
384 smp_info(m);
385#endif
386 return 0;
387}
388
389static void *c_start(struct seq_file *m, loff_t *pos)
390{
391 /* The pointer we are returning is arbitrary,
392 * it just has to be non-NULL and not IS_ERR
393 * in the success case.
394 */
395 return *pos == 0 ? &c_start : NULL;
396}
397
398static void *c_next(struct seq_file *m, void *v, loff_t *pos)
399{
400 ++*pos;
401 return c_start(m, pos);
402}
403
404static void c_stop(struct seq_file *m, void *v)
405{
406}
407
Jan Engelhardt872e2be2008-01-22 18:29:20 -0800408const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .start =c_start,
410 .next = c_next,
411 .stop = c_stop,
412 .show = show_cpuinfo,
413};
414
415extern int stop_a_enabled;
416
417void sun_do_break(void)
418{
419 if (!stop_a_enabled)
420 return;
421
422 prom_printf("\n");
423 flush_user_windows();
424
425 prom_cmdline();
426}
427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428int stop_a_enabled = 1;