blob: aafde3dd9fd4996af17f88f4d486aec214cdfe63 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: setup.c,v 1.72 2002/02/09 19:49:30 davem Exp $
2 * 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>
18#include <linux/a.out.h>
Jon Smirl894673e2006-07-10 04:44:13 -070019#include <linux/screen_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/fs.h>
22#include <linux/seq_file.h>
23#include <linux/syscalls.h>
24#include <linux/kdev_t.h>
25#include <linux/major.h>
26#include <linux/string.h>
27#include <linux/init.h>
28#include <linux/inet.h>
29#include <linux/console.h>
30#include <linux/root_dev.h>
31#include <linux/interrupt.h>
32#include <linux/cpu.h>
33#include <linux/initrd.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/system.h>
36#include <asm/io.h>
37#include <asm/processor.h>
38#include <asm/oplib.h>
39#include <asm/page.h>
40#include <asm/pgtable.h>
41#include <asm/idprom.h>
42#include <asm/head.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>
48#include <asm/mmu.h>
David S. Miller5cbc3072007-05-25 15:49:59 -070049#include <asm/ns87303.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#ifdef CONFIG_IP_PNP
52#include <net/ipconfig.h>
53#endif
54
David S. Miller5cbc3072007-05-25 15:49:59 -070055/* Used to synchronize accesses to NatSemi SUPER I/O chip configure
56 * operations in asm/ns87303.h
57 */
58DEFINE_SPINLOCK(ns87303_lock);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060struct screen_info screen_info = {
61 0, 0, /* orig-x, orig-y */
62 0, /* unused */
63 0, /* orig-video-page */
64 0, /* orig-video-mode */
65 128, /* orig-video-cols */
66 0, 0, 0, /* unused, ega_bx, unused */
67 54, /* orig-video-lines */
68 0, /* orig-video-isVGA */
69 16 /* orig-video-points */
70};
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072void (*prom_palette)(int);
73void (*prom_keyboard)(void);
74
75static void
76prom_console_write(struct console *con, const char *s, unsigned n)
77{
78 prom_write(s, n);
79}
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081unsigned int boot_flags = 0;
82#define BOOTME_DEBUG 0x1
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/* Exported for mm/init.c:paging_init. */
85unsigned long cmdline_memory_size = 0;
86
87static struct console prom_debug_console = {
88 .name = "debug",
89 .write = prom_console_write,
90 .flags = CON_PRINTBUFFER,
91 .index = -1,
92};
93
94/* XXX Implement this at some point... */
95void kernel_enter_debugger(void)
96{
97}
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*
100 * Process kernel command line switches that are specific to the
101 * SPARC or that require special low-level processing.
102 */
103static void __init process_switch(char c)
104{
105 switch (c) {
106 case 'd':
107 boot_flags |= BOOTME_DEBUG;
108 break;
109 case 's':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 break;
111 case 'h':
112 prom_printf("boot_flags_init: Halt!\n");
113 prom_halt();
114 break;
115 case 'p':
116 /* Use PROM debug console. */
117 register_console(&prom_debug_console);
118 break;
David S. Miller816242d2005-05-23 15:52:08 -0700119 case 'P':
120 /* Force UltraSPARC-III P-Cache on. */
121 if (tlb_type != cheetah) {
122 printk("BOOT: Ignoring P-Cache force option.\n");
123 break;
124 }
125 cheetah_pcache_forced_on = 1;
126 add_taint(TAINT_MACHINE_CHECK);
127 cheetah_enable_pcache();
128 break;
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 default:
131 printk("Unknown boot switch (-%c)\n", c);
132 break;
133 }
134}
135
136static void __init process_console(char *commands)
137{
138 serial_console = 0;
139 commands += 8;
140 /* Linux-style serial */
141 if (!strncmp(commands, "ttyS", 4))
142 serial_console = simple_strtoul(commands + 4, NULL, 10) + 1;
143 else if (!strncmp(commands, "tty", 3)) {
144 char c = *(commands + 3);
145 /* Solaris-style serial */
146 if (c == 'a' || c == 'b') {
147 serial_console = c - 'a' + 1;
148 prom_printf ("Using /dev/tty%c as console.\n", c);
149 }
150 /* else Linux-style fbcon, not serial */
151 }
152#if defined(CONFIG_PROM_CONSOLE)
153 if (!strncmp(commands, "prom", 4)) {
154 char *p;
155
156 for (p = commands - 8; *p && *p != ' '; p++)
157 *p = ' ';
158 conswitchp = &prom_con;
159 }
160#endif
161}
162
163static void __init boot_flags_init(char *commands)
164{
165 while (*commands) {
166 /* Move to the start of the next "argument". */
167 while (*commands && *commands == ' ')
168 commands++;
169
170 /* Process any command switches, otherwise skip it. */
171 if (*commands == '\0')
172 break;
173 if (*commands == '-') {
174 commands++;
175 while (*commands && *commands != ' ')
176 process_switch(*commands++);
177 continue;
178 }
179 if (!strncmp(commands, "console=", 8)) {
180 process_console(commands);
181 } else if (!strncmp(commands, "mem=", 4)) {
182 /*
183 * "mem=XXX[kKmM]" overrides the PROM-reported
184 * memory size.
185 */
186 cmdline_memory_size = simple_strtoul(commands + 4,
187 &commands, 0);
188 if (*commands == 'K' || *commands == 'k') {
189 cmdline_memory_size <<= 10;
190 commands++;
191 } else if (*commands=='M' || *commands=='m') {
192 cmdline_memory_size <<= 20;
193 commands++;
194 }
195 }
196 while (*commands && *commands != ' ')
197 commands++;
198 }
199}
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201extern void panic_setup(char *, int *);
202
203extern unsigned short root_flags;
204extern unsigned short root_dev;
205extern unsigned short ram_flags;
206#define RAMDISK_IMAGE_START_MASK 0x07FF
207#define RAMDISK_PROMPT_FLAG 0x8000
208#define RAMDISK_LOAD_FLAG 0x4000
209
210extern int root_mountflags;
211
212char reboot_command[COMMAND_LINE_SIZE];
213
214static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
215
David S. Miller951bc822006-05-31 01:24:02 -0700216void __init per_cpu_patch(void)
David S. Miller92704a12006-02-26 23:27:19 -0800217{
David S. Miller92704a12006-02-26 23:27:19 -0800218 struct cpuid_patch_entry *p;
219 unsigned long ver;
220 int is_jbus;
221
222 if (tlb_type == spitfire && !this_is_starfire)
223 return;
224
David S. Millerd82ace72006-02-09 02:52:44 -0800225 is_jbus = 0;
226 if (tlb_type != hypervisor) {
227 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
David S. Millerebd8c562006-02-17 08:38:06 -0800228 is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
229 (ver >> 32UL) == __SERRANO_ID);
David S. Millerd82ace72006-02-09 02:52:44 -0800230 }
David S. Miller92704a12006-02-26 23:27:19 -0800231
232 p = &__cpuid_patch;
233 while (p < &__cpuid_patch_end) {
234 unsigned long addr = p->addr;
235 unsigned int *insns;
236
237 switch (tlb_type) {
238 case spitfire:
239 insns = &p->starfire[0];
240 break;
241 case cheetah:
242 case cheetah_plus:
243 if (is_jbus)
244 insns = &p->cheetah_jbus[0];
245 else
246 insns = &p->cheetah_safari[0];
247 break;
David S. Millerd96b8152006-02-04 15:40:53 -0800248 case hypervisor:
249 insns = &p->sun4v[0];
250 break;
David S. Miller92704a12006-02-26 23:27:19 -0800251 default:
252 prom_printf("Unknown cpu type, halting.\n");
253 prom_halt();
254 };
255
256 *(unsigned int *) (addr + 0) = insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800257 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800258 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
259
260 *(unsigned int *) (addr + 4) = insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800261 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800262 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
263
264 *(unsigned int *) (addr + 8) = insns[2];
David S. Miller840aaef2006-02-06 15:52:05 -0800265 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800266 __asm__ __volatile__("flush %0" : : "r" (addr + 8));
267
268 *(unsigned int *) (addr + 12) = insns[3];
David S. Miller840aaef2006-02-06 15:52:05 -0800269 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800270 __asm__ __volatile__("flush %0" : : "r" (addr + 12));
271
272 p++;
273 }
David S. Miller92704a12006-02-26 23:27:19 -0800274}
275
David S. Miller951bc822006-05-31 01:24:02 -0700276void __init sun4v_patch(void)
David S. Miller936f4822006-02-05 21:29:28 -0800277{
David S. Millerc7754d42007-05-15 17:03:54 -0700278 extern void sun4v_hvapi_init(void);
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800279 struct sun4v_1insn_patch_entry *p1;
280 struct sun4v_2insn_patch_entry *p2;
David S. Miller936f4822006-02-05 21:29:28 -0800281
282 if (tlb_type != hypervisor)
283 return;
284
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800285 p1 = &__sun4v_1insn_patch;
286 while (p1 < &__sun4v_1insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800287 unsigned long addr = p1->addr;
David S. Miller936f4822006-02-05 21:29:28 -0800288
David S. Miller45fec052006-02-05 22:27:28 -0800289 *(unsigned int *) (addr + 0) = p1->insn;
David S. Miller840aaef2006-02-06 15:52:05 -0800290 wmb();
David S. Miller936f4822006-02-05 21:29:28 -0800291 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
292
David S. Miller45fec052006-02-05 22:27:28 -0800293 p1++;
294 }
295
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800296 p2 = &__sun4v_2insn_patch;
297 while (p2 < &__sun4v_2insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800298 unsigned long addr = p2->addr;
299
300 *(unsigned int *) (addr + 0) = p2->insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800301 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800302 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
303
David S. Millerfd050682006-02-11 11:05:52 -0800304 *(unsigned int *) (addr + 4) = p2->insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800305 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800306 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
307
308 p2++;
David S. Miller936f4822006-02-05 21:29:28 -0800309 }
David S. Millerc7754d42007-05-15 17:03:54 -0700310
311 sun4v_hvapi_init();
David S. Miller936f4822006-02-05 21:29:28 -0800312}
313
David S. Miller951bc822006-05-31 01:24:02 -0700314#ifdef CONFIG_SMP
315void __init boot_cpu_id_too_large(int cpu)
316{
317 prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
318 cpu, NR_CPUS);
319 prom_halt();
320}
321#endif
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323void __init setup_arch(char **cmdline_p)
324{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 /* Initialize PROM console and command line. */
326 *cmdline_p = prom_getbootargs();
Alon Bar-Lev383464c2007-02-12 00:54:22 -0800327 strcpy(boot_command_line, *cmdline_p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
David S. Miller3a8c0692006-02-09 02:54:54 -0800329 if (tlb_type == hypervisor)
330 printk("ARCH: SUN4V\n");
331 else
332 printk("ARCH: SUN4U\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334#ifdef CONFIG_DUMMY_CONSOLE
335 conswitchp = &dummy_con;
336#elif defined(CONFIG_PROM_CONSOLE)
337 conswitchp = &prom_con;
338#endif
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 boot_flags_init(*cmdline_p);
341
342 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 if (!root_flags)
345 root_mountflags &= ~MS_RDONLY;
346 ROOT_DEV = old_decode_dev(root_dev);
Andrew Morton467418f2006-03-19 12:46:55 -0800347#ifdef CONFIG_BLK_DEV_RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
349 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
350 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
351#endif
352
Al Virof3169642006-01-12 01:05:42 -0800353 task_thread_info(&init_task)->kregs = &fake_swapper_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355#ifdef CONFIG_IP_PNP
356 if (!ic_set_manually) {
357 int chosen = prom_finddevice ("/chosen");
358 u32 cl, sv, gw;
359
360 cl = prom_getintdefault (chosen, "client-ip", 0);
361 sv = prom_getintdefault (chosen, "server-ip", 0);
362 gw = prom_getintdefault (chosen, "gateway-ip", 0);
363 if (cl && sv) {
364 ic_myaddr = cl;
365 ic_servaddr = sv;
366 if (gw)
367 ic_gateway = gw;
368#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
369 ic_proto_enabled = 0;
370#endif
371 }
372 }
373#endif
374
David S. Miller56fb4df2006-02-26 23:24:22 -0800375 /* Get boot processor trap_block[] setup. */
David S. Miller72aff532006-02-17 01:29:17 -0800376 init_cur_cpu_trap(current_thread_info());
David S. Miller52845cd2006-02-26 23:32:33 -0800377
378 paging_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
381static int __init set_preferred_console(void)
382{
383 int idev, odev;
384
385 /* The user has requested a console so this is already set up. */
386 if (serial_console >= 0)
387 return -EBUSY;
388
389 idev = prom_query_input_device();
390 odev = prom_query_output_device();
391 if (idev == PROMDEV_IKBD && odev == PROMDEV_OSCREEN) {
392 serial_console = 0;
393 } else if (idev == PROMDEV_ITTYA && odev == PROMDEV_OTTYA) {
394 serial_console = 1;
395 } else if (idev == PROMDEV_ITTYB && odev == PROMDEV_OTTYB) {
396 serial_console = 2;
Eddie C. Dostc126cf82006-01-18 14:54:31 -0800397 } else if (idev == PROMDEV_IRSC && odev == PROMDEV_ORSC) {
398 serial_console = 3;
David S. Miller1a7a2422006-02-11 23:24:30 -0800399 } else if (idev == PROMDEV_IVCONS && odev == PROMDEV_OVCONS) {
400 /* sunhv_console_init() doesn't check the serial_console
401 * value anyways...
402 */
403 serial_console = 4;
David S. Millerd5a2aa22006-02-13 21:28:40 -0800404 return add_preferred_console("ttyHV", 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 } else {
406 prom_printf("Inconsistent console: "
407 "input %d, output %d\n",
408 idev, odev);
409 prom_halt();
410 }
411
412 if (serial_console)
413 return add_preferred_console("ttyS", serial_console - 1, NULL);
414
415 return -ENODEV;
416}
417console_initcall(set_preferred_console);
418
419/* BUFFER is PAGE_SIZE bytes long. */
420
421extern char *sparc_cpu_type;
422extern char *sparc_fpu_type;
423
424extern void smp_info(struct seq_file *);
425extern void smp_bogo(struct seq_file *);
426extern void mmu_info(struct seq_file *);
427
David S. Miller80dc0d62005-09-26 00:32:17 -0700428unsigned int dcache_parity_tl1_occurred;
429unsigned int icache_parity_tl1_occurred;
430
David S. Miller5cbc3072007-05-25 15:49:59 -0700431int ncpus_probed;
David S. Miller4d45cba2005-11-11 12:48:56 -0800432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433static int show_cpuinfo(struct seq_file *m, void *__unused)
434{
435 seq_printf(m,
436 "cpu\t\t: %s\n"
437 "fpu\t\t: %s\n"
David S. Miller90a66462006-03-08 17:18:19 -0800438 "prom\t\t: %s\n"
439 "type\t\t: %s\n"
David S. Miller4d45cba2005-11-11 12:48:56 -0800440 "ncpus probed\t: %d\n"
441 "ncpus active\t: %d\n"
David S. Miller80dc0d62005-09-26 00:32:17 -0700442 "D$ parity tl1\t: %u\n"
443 "I$ parity tl1\t: %u\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#ifndef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 "Cpu0ClkTck\t: %016lx\n"
446#endif
447 ,
448 sparc_cpu_type,
449 sparc_fpu_type,
David S. Miller90a66462006-03-08 17:18:19 -0800450 prom_version,
451 ((tlb_type == hypervisor) ?
452 "sun4v" :
453 "sun4u"),
David S. Miller4d45cba2005-11-11 12:48:56 -0800454 ncpus_probed,
455 num_online_cpus(),
David S. Miller80dc0d62005-09-26 00:32:17 -0700456 dcache_parity_tl1_occurred,
Fabio Massimo Di Nitto3ac66e32007-07-16 14:15:39 -0700457 icache_parity_tl1_occurred
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#ifndef CONFIG_SMP
Fabio Massimo Di Nitto3ac66e32007-07-16 14:15:39 -0700459 , cpu_data(0).clock_tick
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460#endif
461 );
462#ifdef CONFIG_SMP
463 smp_bogo(m);
464#endif
465 mmu_info(m);
466#ifdef CONFIG_SMP
467 smp_info(m);
468#endif
469 return 0;
470}
471
472static void *c_start(struct seq_file *m, loff_t *pos)
473{
474 /* The pointer we are returning is arbitrary,
475 * it just has to be non-NULL and not IS_ERR
476 * in the success case.
477 */
478 return *pos == 0 ? &c_start : NULL;
479}
480
481static void *c_next(struct seq_file *m, void *v, loff_t *pos)
482{
483 ++*pos;
484 return c_start(m, pos);
485}
486
487static void c_stop(struct seq_file *m, void *v)
488{
489}
490
491struct seq_operations cpuinfo_op = {
492 .start =c_start,
493 .next = c_next,
494 .stop = c_stop,
495 .show = show_cpuinfo,
496};
497
498extern int stop_a_enabled;
499
500void sun_do_break(void)
501{
502 if (!stop_a_enabled)
503 return;
504
505 prom_printf("\n");
506 flush_user_windows();
507
508 prom_cmdline();
509}
510
511int serial_console = -1;
512int stop_a_enabled = 1;