blob: a2a79e76344f78c606fed829ce18c4c77775b3ac [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>
David S. Millerc57ec522009-11-27 17:33:43 -080049#include <asm/btext.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#ifdef CONFIG_IP_PNP
52#include <net/ipconfig.h>
53#endif
54
David S. Miller3d5ae6b2008-03-25 21:51:40 -070055#include "entry.h"
Sam Ravnborg53ae3412008-12-07 00:02:08 -080056#include "kernel.h"
David S. Miller3d5ae6b2008-03-25 21:51:40 -070057
David S. Miller5cbc3072007-05-25 15:49:59 -070058/* Used to synchronize accesses to NatSemi SUPER I/O chip configure
59 * operations in asm/ns87303.h
60 */
61DEFINE_SPINLOCK(ns87303_lock);
Sam Ravnborg917c3662009-01-08 16:58:20 -080062EXPORT_SYMBOL(ns87303_lock);
David S. Miller5cbc3072007-05-25 15:49:59 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064struct screen_info screen_info = {
65 0, 0, /* orig-x, orig-y */
66 0, /* unused */
67 0, /* orig-video-page */
68 0, /* orig-video-mode */
69 128, /* orig-video-cols */
70 0, 0, 0, /* unused, ega_bx, unused */
71 54, /* orig-video-lines */
72 0, /* orig-video-isVGA */
73 16 /* orig-video-points */
74};
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076static void
77prom_console_write(struct console *con, const char *s, unsigned n)
78{
79 prom_write(s, n);
80}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/* Exported for mm/init.c:paging_init. */
83unsigned long cmdline_memory_size = 0;
84
David S. Miller3c62a2d2008-02-17 23:22:50 -080085static struct console prom_early_console = {
86 .name = "earlyprom",
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 .write = prom_console_write,
David S. Millerdb9a7fb2008-04-23 22:22:29 -070088 .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .index = -1,
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/*
93 * Process kernel command line switches that are specific to the
94 * SPARC or that require special low-level processing.
95 */
96static void __init process_switch(char c)
97{
98 switch (c) {
99 case 'd':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 case 's':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 break;
102 case 'h':
103 prom_printf("boot_flags_init: Halt!\n");
104 prom_halt();
105 break;
106 case 'p':
David S. Miller3c62a2d2008-02-17 23:22:50 -0800107 /* Just ignore, this behavior is now the default. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 break;
David S. Miller816242d2005-05-23 15:52:08 -0700109 case 'P':
110 /* Force UltraSPARC-III P-Cache on. */
111 if (tlb_type != cheetah) {
112 printk("BOOT: Ignoring P-Cache force option.\n");
113 break;
114 }
115 cheetah_pcache_forced_on = 1;
116 add_taint(TAINT_MACHINE_CHECK);
117 cheetah_enable_pcache();
118 break;
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 default:
121 printk("Unknown boot switch (-%c)\n", c);
122 break;
123 }
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static void __init boot_flags_init(char *commands)
127{
128 while (*commands) {
129 /* Move to the start of the next "argument". */
130 while (*commands && *commands == ' ')
131 commands++;
132
133 /* Process any command switches, otherwise skip it. */
134 if (*commands == '\0')
135 break;
136 if (*commands == '-') {
137 commands++;
138 while (*commands && *commands != ' ')
139 process_switch(*commands++);
140 continue;
141 }
David S. Millerc73fcc82007-07-20 16:59:26 -0700142 if (!strncmp(commands, "mem=", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 /*
144 * "mem=XXX[kKmM]" overrides the PROM-reported
145 * memory size.
146 */
147 cmdline_memory_size = simple_strtoul(commands + 4,
148 &commands, 0);
149 if (*commands == 'K' || *commands == 'k') {
150 cmdline_memory_size <<= 10;
151 commands++;
152 } else if (*commands=='M' || *commands=='m') {
153 cmdline_memory_size <<= 20;
154 commands++;
155 }
156 }
157 while (*commands && *commands != ' ')
158 commands++;
159 }
160}
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162extern unsigned short root_flags;
163extern unsigned short root_dev;
164extern unsigned short ram_flags;
165#define RAMDISK_IMAGE_START_MASK 0x07FF
166#define RAMDISK_PROMPT_FLAG 0x8000
167#define RAMDISK_LOAD_FLAG 0x4000
168
169extern int root_mountflags;
170
171char reboot_command[COMMAND_LINE_SIZE];
172
173static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
174
David S. Miller951bc822006-05-31 01:24:02 -0700175void __init per_cpu_patch(void)
David S. Miller92704a12006-02-26 23:27:19 -0800176{
David S. Miller92704a12006-02-26 23:27:19 -0800177 struct cpuid_patch_entry *p;
178 unsigned long ver;
179 int is_jbus;
180
181 if (tlb_type == spitfire && !this_is_starfire)
182 return;
183
David S. Millerd82ace72006-02-09 02:52:44 -0800184 is_jbus = 0;
185 if (tlb_type != hypervisor) {
186 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
David S. Millerebd8c562006-02-17 08:38:06 -0800187 is_jbus = ((ver >> 32UL) == __JALAPENO_ID ||
188 (ver >> 32UL) == __SERRANO_ID);
David S. Millerd82ace72006-02-09 02:52:44 -0800189 }
David S. Miller92704a12006-02-26 23:27:19 -0800190
191 p = &__cpuid_patch;
192 while (p < &__cpuid_patch_end) {
193 unsigned long addr = p->addr;
194 unsigned int *insns;
195
196 switch (tlb_type) {
197 case spitfire:
198 insns = &p->starfire[0];
199 break;
200 case cheetah:
201 case cheetah_plus:
202 if (is_jbus)
203 insns = &p->cheetah_jbus[0];
204 else
205 insns = &p->cheetah_safari[0];
206 break;
David S. Millerd96b8152006-02-04 15:40:53 -0800207 case hypervisor:
208 insns = &p->sun4v[0];
209 break;
David S. Miller92704a12006-02-26 23:27:19 -0800210 default:
211 prom_printf("Unknown cpu type, halting.\n");
212 prom_halt();
213 };
214
215 *(unsigned int *) (addr + 0) = insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800216 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800217 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
218
219 *(unsigned int *) (addr + 4) = insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800220 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800221 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
222
223 *(unsigned int *) (addr + 8) = insns[2];
David S. Miller840aaef2006-02-06 15:52:05 -0800224 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800225 __asm__ __volatile__("flush %0" : : "r" (addr + 8));
226
227 *(unsigned int *) (addr + 12) = insns[3];
David S. Miller840aaef2006-02-06 15:52:05 -0800228 wmb();
David S. Miller92704a12006-02-26 23:27:19 -0800229 __asm__ __volatile__("flush %0" : : "r" (addr + 12));
230
231 p++;
232 }
David S. Miller92704a12006-02-26 23:27:19 -0800233}
234
David S. Miller951bc822006-05-31 01:24:02 -0700235void __init sun4v_patch(void)
David S. Miller936f4822006-02-05 21:29:28 -0800236{
David S. Millerc7754d42007-05-15 17:03:54 -0700237 extern void sun4v_hvapi_init(void);
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800238 struct sun4v_1insn_patch_entry *p1;
239 struct sun4v_2insn_patch_entry *p2;
David S. Miller936f4822006-02-05 21:29:28 -0800240
241 if (tlb_type != hypervisor)
242 return;
243
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800244 p1 = &__sun4v_1insn_patch;
245 while (p1 < &__sun4v_1insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800246 unsigned long addr = p1->addr;
David S. Miller936f4822006-02-05 21:29:28 -0800247
David S. Miller45fec052006-02-05 22:27:28 -0800248 *(unsigned int *) (addr + 0) = p1->insn;
David S. Miller840aaef2006-02-06 15:52:05 -0800249 wmb();
David S. Miller936f4822006-02-05 21:29:28 -0800250 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
251
David S. Miller45fec052006-02-05 22:27:28 -0800252 p1++;
253 }
254
David S. Millerdf7d6ae2006-02-07 00:00:16 -0800255 p2 = &__sun4v_2insn_patch;
256 while (p2 < &__sun4v_2insn_patch_end) {
David S. Miller45fec052006-02-05 22:27:28 -0800257 unsigned long addr = p2->addr;
258
259 *(unsigned int *) (addr + 0) = p2->insns[0];
David S. Miller840aaef2006-02-06 15:52:05 -0800260 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800261 __asm__ __volatile__("flush %0" : : "r" (addr + 0));
262
David S. Millerfd050682006-02-11 11:05:52 -0800263 *(unsigned int *) (addr + 4) = p2->insns[1];
David S. Miller840aaef2006-02-06 15:52:05 -0800264 wmb();
David S. Miller45fec052006-02-05 22:27:28 -0800265 __asm__ __volatile__("flush %0" : : "r" (addr + 4));
266
267 p2++;
David S. Miller936f4822006-02-05 21:29:28 -0800268 }
David S. Millerc7754d42007-05-15 17:03:54 -0700269
270 sun4v_hvapi_init();
David S. Miller936f4822006-02-05 21:29:28 -0800271}
272
David S. Miller951bc822006-05-31 01:24:02 -0700273#ifdef CONFIG_SMP
274void __init boot_cpu_id_too_large(int cpu)
275{
276 prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
277 cpu, NR_CPUS);
278 prom_halt();
279}
280#endif
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282void __init setup_arch(char **cmdline_p)
283{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 /* Initialize PROM console and command line. */
285 *cmdline_p = prom_getbootargs();
Alon Bar-Lev383464c2007-02-12 00:54:22 -0800286 strcpy(boot_command_line, *cmdline_p);
David S. Millerce3b1d42008-03-19 03:54:09 -0700287 parse_early_param();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
David S. Miller3c62a2d2008-02-17 23:22:50 -0800289 boot_flags_init(*cmdline_p);
David S. Millerc57ec522009-11-27 17:33:43 -0800290#ifdef CONFIG_EARLYFB
291 if (btext_find_display())
292#endif
293 register_console(&prom_early_console);
David S. Miller3c62a2d2008-02-17 23:22:50 -0800294
David S. Miller3a8c0692006-02-09 02:54:54 -0800295 if (tlb_type == hypervisor)
296 printk("ARCH: SUN4V\n");
297 else
298 printk("ARCH: SUN4U\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300#ifdef CONFIG_DUMMY_CONSOLE
301 conswitchp = &dummy_con;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302#endif
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 if (!root_flags)
307 root_mountflags &= ~MS_RDONLY;
308 ROOT_DEV = old_decode_dev(root_dev);
Andrew Morton467418f2006-03-19 12:46:55 -0800309#ifdef CONFIG_BLK_DEV_RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
311 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
312 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
313#endif
314
Al Virof3169642006-01-12 01:05:42 -0800315 task_thread_info(&init_task)->kregs = &fake_swapper_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317#ifdef CONFIG_IP_PNP
318 if (!ic_set_manually) {
319 int chosen = prom_finddevice ("/chosen");
320 u32 cl, sv, gw;
321
322 cl = prom_getintdefault (chosen, "client-ip", 0);
323 sv = prom_getintdefault (chosen, "server-ip", 0);
324 gw = prom_getintdefault (chosen, "gateway-ip", 0);
325 if (cl && sv) {
326 ic_myaddr = cl;
327 ic_servaddr = sv;
328 if (gw)
329 ic_gateway = gw;
330#if defined(CONFIG_IP_PNP_BOOTP) || defined(CONFIG_IP_PNP_RARP)
331 ic_proto_enabled = 0;
332#endif
333 }
334 }
335#endif
336
David S. Miller56fb4df2006-02-26 23:24:22 -0800337 /* Get boot processor trap_block[] setup. */
David S. Miller72aff532006-02-17 01:29:17 -0800338 init_cur_cpu_trap(current_thread_info());
David S. Miller52845cd2006-02-26 23:32:33 -0800339
340 paging_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/* BUFFER is PAGE_SIZE bytes long. */
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345extern void smp_info(struct seq_file *);
346extern void smp_bogo(struct seq_file *);
347extern void mmu_info(struct seq_file *);
348
David S. Miller80dc0d62005-09-26 00:32:17 -0700349unsigned int dcache_parity_tl1_occurred;
350unsigned int icache_parity_tl1_occurred;
351
David S. Miller5cbc3072007-05-25 15:49:59 -0700352int ncpus_probed;
David S. Miller4d45cba2005-11-11 12:48:56 -0800353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354static int show_cpuinfo(struct seq_file *m, void *__unused)
355{
356 seq_printf(m,
357 "cpu\t\t: %s\n"
358 "fpu\t\t: %s\n"
David S. Millerc3cf5e82009-01-21 23:16:40 -0800359 "pmu\t\t: %s\n"
David S. Miller90a66462006-03-08 17:18:19 -0800360 "prom\t\t: %s\n"
361 "type\t\t: %s\n"
David S. Miller4d45cba2005-11-11 12:48:56 -0800362 "ncpus probed\t: %d\n"
363 "ncpus active\t: %d\n"
David S. Miller80dc0d62005-09-26 00:32:17 -0700364 "D$ parity tl1\t: %u\n"
365 "I$ parity tl1\t: %u\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366#ifndef CONFIG_SMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 "Cpu0ClkTck\t: %016lx\n"
368#endif
369 ,
370 sparc_cpu_type,
371 sparc_fpu_type,
David S. Millerc3cf5e82009-01-21 23:16:40 -0800372 sparc_pmu_type,
David S. Miller90a66462006-03-08 17:18:19 -0800373 prom_version,
374 ((tlb_type == hypervisor) ?
375 "sun4v" :
376 "sun4u"),
David S. Miller4d45cba2005-11-11 12:48:56 -0800377 ncpus_probed,
378 num_online_cpus(),
David S. Miller80dc0d62005-09-26 00:32:17 -0700379 dcache_parity_tl1_occurred,
Fabio Massimo Di Nitto3ac66e32007-07-16 14:15:39 -0700380 icache_parity_tl1_occurred
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381#ifndef CONFIG_SMP
Fabio Massimo Di Nitto3ac66e32007-07-16 14:15:39 -0700382 , cpu_data(0).clock_tick
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#endif
384 );
385#ifdef CONFIG_SMP
386 smp_bogo(m);
387#endif
388 mmu_info(m);
389#ifdef CONFIG_SMP
390 smp_info(m);
391#endif
392 return 0;
393}
394
395static void *c_start(struct seq_file *m, loff_t *pos)
396{
397 /* The pointer we are returning is arbitrary,
398 * it just has to be non-NULL and not IS_ERR
399 * in the success case.
400 */
401 return *pos == 0 ? &c_start : NULL;
402}
403
404static void *c_next(struct seq_file *m, void *v, loff_t *pos)
405{
406 ++*pos;
407 return c_start(m, pos);
408}
409
410static void c_stop(struct seq_file *m, void *v)
411{
412}
413
Jan Engelhardt872e2be2008-01-22 18:29:20 -0800414const struct seq_operations cpuinfo_op = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 .start =c_start,
416 .next = c_next,
417 .stop = c_stop,
418 .show = show_cpuinfo,
419};
420
421extern int stop_a_enabled;
422
423void sun_do_break(void)
424{
425 if (!stop_a_enabled)
426 return;
427
428 prom_printf("\n");
429 flush_user_windows();
430
431 prom_cmdline();
432}
Sam Ravnborg917c3662009-01-08 16:58:20 -0800433EXPORT_SYMBOL(sun_do_break);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435int stop_a_enabled = 1;
Sam Ravnborg917c3662009-01-08 16:58:20 -0800436EXPORT_SYMBOL(stop_a_enabled);