blob: 68dd63dea36f456a727a1636af7473dc311a6ebf [file] [log] [blame]
Adrian Bunk88278ca2008-05-19 16:53:02 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * linux/arch/sparc/kernel/setup.c
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
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 <linux/initrd.h>
17#include <asm/smp.h>
18#include <linux/user.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/interrupt.h>
29#include <linux/console.h>
30#include <linux/spinlock.h>
31#include <linux/root_dev.h>
Bob Breuera8cbdce2006-06-20 00:28:33 -070032#include <linux/cpu.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070033#include <linux/kdebug.h>
Paul Gortmaker7b64db62011-07-18 15:57:46 -040034#include <linux/export.h>
Sam Ravnborg4efb55e2012-05-25 21:20:08 +000035#include <linux/start_kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/io.h>
38#include <asm/processor.h>
39#include <asm/oplib.h>
40#include <asm/page.h>
41#include <asm/pgtable.h>
42#include <asm/traps.h>
43#include <asm/vaddrs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <asm/mbus.h>
45#include <asm/idprom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/cpudata.h>
47#include <asm/setup.h>
David Howellsd550bbd2012-03-28 18:30:03 +010048#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Sam Ravnborg53ae3412008-12-07 00:02:08 -080050#include "kernel.h"
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052struct screen_info screen_info = {
53 0, 0, /* orig-x, orig-y */
54 0, /* unused */
55 0, /* orig-video-page */
56 0, /* orig-video-mode */
57 128, /* orig-video-cols */
58 0,0,0, /* ega_ax, ega_bx, ega_cx */
59 54, /* orig-video-lines */
60 0, /* orig-video-isVGA */
61 16 /* orig-video-points */
62};
63
64/* Typing sync at the prom prompt calls the function pointed to by
65 * romvec->pv_synchook which I set to the following function.
66 * This should sync all filesystems and return, for now it just
67 * prints out pretty messages and returns.
68 */
69
70extern unsigned long trapbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/* Pretty sick eh? */
Adrian Bunkc61c65c2008-06-05 11:40:58 -070073static void prom_sync_me(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 unsigned long prom_tbr, flags;
76
77 /* XXX Badly broken. FIX! - Anton */
78 local_irq_save(flags);
79 __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
80 __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
81 "nop\n\t"
82 "nop\n\t"
83 "nop\n\t" : : "r" (&trapbase));
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 prom_printf("PROM SYNC COMMAND...\n");
David Rientjes7bf02ea2011-05-24 17:11:16 -070086 show_free_areas(0);
Paul E. McKenney29f043a2011-11-10 15:56:46 -080087 if (!is_idle_task(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 local_irq_enable();
89 sys_sync();
90 local_irq_disable();
91 }
92 prom_printf("Returning to prom\n");
93
94 __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
95 "nop\n\t"
96 "nop\n\t"
97 "nop\n\t" : : "r" (prom_tbr));
98 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}
100
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700101static unsigned int boot_flags __initdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define BOOTME_DEBUG 0x1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104/* Exported for mm/init.c:paging_init. */
105unsigned long cmdline_memory_size __initdata = 0;
106
Daniel Hellstrom5fcafb72011-04-21 04:20:23 +0000107/* which CPU booted us (0xff = not set) */
108unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
Daniel Hellstrom5fcafb72011-04-21 04:20:23 +0000109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static void
111prom_console_write(struct console *con, const char *s, unsigned n)
112{
113 prom_write(s, n);
114}
115
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700116static struct console prom_early_console = {
117 .name = "earlyprom",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .write = prom_console_write,
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700119 .flags = CON_PRINTBUFFER | CON_BOOT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .index = -1,
121};
122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123/*
124 * Process kernel command line switches that are specific to the
125 * SPARC or that require special low-level processing.
126 */
127static void __init process_switch(char c)
128{
129 switch (c) {
130 case 'd':
131 boot_flags |= BOOTME_DEBUG;
132 break;
133 case 's':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 break;
135 case 'h':
136 prom_printf("boot_flags_init: Halt!\n");
137 prom_halt();
138 break;
139 case 'p':
David S. Miller11032c12011-09-21 12:48:06 -0700140 prom_early_console.flags &= ~CON_BOOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 break;
142 default:
143 printk("Unknown boot switch (-%c)\n", c);
144 break;
145 }
146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static void __init boot_flags_init(char *commands)
149{
150 while (*commands) {
151 /* Move to the start of the next "argument". */
152 while (*commands && *commands == ' ')
153 commands++;
154
155 /* Process any command switches, otherwise skip it. */
156 if (*commands == '\0')
157 break;
158 if (*commands == '-') {
159 commands++;
160 while (*commands && *commands != ' ')
161 process_switch(*commands++);
162 continue;
163 }
David S. Millerc73fcc82007-07-20 16:59:26 -0700164 if (!strncmp(commands, "mem=", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /*
166 * "mem=XXX[kKmM] overrides the PROM-reported
167 * memory size.
168 */
169 cmdline_memory_size = simple_strtoul(commands + 4,
170 &commands, 0);
171 if (*commands == 'K' || *commands == 'k') {
172 cmdline_memory_size <<= 10;
173 commands++;
174 } else if (*commands=='M' || *commands=='m') {
175 cmdline_memory_size <<= 20;
176 commands++;
177 }
178 }
179 while (*commands && *commands != ' ')
180 commands++;
181 }
182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184extern unsigned short root_flags;
185extern unsigned short root_dev;
186extern unsigned short ram_flags;
187#define RAMDISK_IMAGE_START_MASK 0x07FF
188#define RAMDISK_PROMPT_FLAG 0x8000
189#define RAMDISK_LOAD_FLAG 0x4000
190
191extern int root_mountflags;
192
193char reboot_command[COMMAND_LINE_SIZE];
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800194
David S. Millerc68e5d32012-05-13 23:09:04 -0700195struct cpuid_patch_entry {
196 unsigned int addr;
197 unsigned int sun4d[3];
198 unsigned int leon[3];
199};
200extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
201
202static void __init per_cpu_patch(void)
203{
204 struct cpuid_patch_entry *p;
205
206 if (sparc_cpu_model == sun4m) {
207 /* Nothing to do, this is what the unpatched code
208 * targets.
209 */
210 return;
211 }
212
213 p = &__cpuid_patch;
214 while (p < &__cpuid_patch_end) {
215 unsigned long addr = p->addr;
216 unsigned int *insns;
217
218 switch (sparc_cpu_model) {
219 case sun4d:
220 insns = &p->sun4d[0];
221 break;
222
223 case sparc_leon:
224 insns = &p->leon[0];
225 break;
226 default:
227 prom_printf("Unknown cpu type, halting.\n");
228 prom_halt();
229 }
230 *(unsigned int *) (addr + 0) = insns[0];
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200231 flushi(addr + 0);
David S. Millerc68e5d32012-05-13 23:09:04 -0700232 *(unsigned int *) (addr + 4) = insns[1];
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200233 flushi(addr + 4);
David S. Millerc68e5d32012-05-13 23:09:04 -0700234 *(unsigned int *) (addr + 8) = insns[2];
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200235 flushi(addr + 8);
Sam Ravnborg9cd5f822012-05-20 17:24:20 +0200236
237 p++;
David S. Millerc68e5d32012-05-13 23:09:04 -0700238 }
David S. Millerc68e5d32012-05-13 23:09:04 -0700239}
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241enum sparc_cpu sparc_cpu_model;
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800242EXPORT_SYMBOL(sparc_cpu_model);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244struct tt_entry *sparc_ttable;
245
246struct pt_regs fake_swapper_regs;
247
Sam Ravnborg4efb55e2012-05-25 21:20:08 +0000248/* Called from head_32.S - before we have setup anything
249 * in the kernel. Be very careful with what you do here.
250 */
251void __init sparc32_start_kernel(struct linux_romvec *rp)
252{
253 prom_init(rp);
254 start_kernel();
255}
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257void __init setup_arch(char **cmdline_p)
258{
259 int i;
260 unsigned long highest_paddr;
261
Sam Ravnborge405ae72011-01-04 11:39:11 +0000262 sparc_ttable = (struct tt_entry *) &trapbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 /* Initialize PROM console and command line. */
265 *cmdline_p = prom_getbootargs();
Alon Bar-Lev08e7ca12007-02-12 00:54:21 -0800266 strcpy(boot_command_line, *cmdline_p);
David S. Miller3fbe36d2008-09-10 23:40:32 -0700267 parse_early_param();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700269 boot_flags_init(*cmdline_p);
270
271 register_console(&prom_early_console);
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 /* Set sparc_cpu_model */
274 sparc_cpu_model = sun_unknown;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000275 if (!strcmp(&cputypval[0], "sun4m"))
David S. Miller365b50f2008-09-02 01:13:31 -0700276 sparc_cpu_model = sun4m;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000277 if (!strcmp(&cputypval[0], "sun4s"))
David S. Miller365b50f2008-09-02 01:13:31 -0700278 sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000279 if (!strcmp(&cputypval[0], "sun4d"))
David S. Miller365b50f2008-09-02 01:13:31 -0700280 sparc_cpu_model = sun4d;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000281 if (!strcmp(&cputypval[0], "sun4e"))
David S. Miller365b50f2008-09-02 01:13:31 -0700282 sparc_cpu_model = sun4e;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000283 if (!strcmp(&cputypval[0], "sun4u"))
David S. Miller365b50f2008-09-02 01:13:31 -0700284 sparc_cpu_model = sun4u;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000285 if (!strncmp(&cputypval[0], "leon" , 4))
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000286 sparc_cpu_model = sparc_leon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 printk("ARCH: ");
289 switch(sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 case sun4m:
291 printk("SUN4M\n");
292 break;
293 case sun4d:
294 printk("SUN4D\n");
295 break;
296 case sun4e:
297 printk("SUN4E\n");
298 break;
299 case sun4u:
300 printk("SUN4U\n");
301 break;
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000302 case sparc_leon:
303 printk("LEON\n");
304 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 default:
306 printk("UNKNOWN!\n");
307 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310#ifdef CONFIG_DUMMY_CONSOLE
311 conswitchp = &dummy_con;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 load_mmu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 phys_base = 0xffffffffUL;
318 highest_paddr = 0UL;
319 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
320 unsigned long top;
321
322 if (sp_banks[i].base_addr < phys_base)
323 phys_base = sp_banks[i].base_addr;
324 top = sp_banks[i].base_addr +
325 sp_banks[i].num_bytes;
326 if (highest_paddr < top)
327 highest_paddr = top;
328 }
329 pfn_base = phys_base >> PAGE_SHIFT;
330
331 if (!root_flags)
332 root_mountflags &= ~MS_RDONLY;
333 ROOT_DEV = old_decode_dev(root_dev);
Al Viro5d2170a2006-06-22 14:47:14 -0700334#ifdef CONFIG_BLK_DEV_RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
336 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
337 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
338#endif
339
340 prom_setsync(prom_sync_me);
341
342 if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
343 ((*(short *)linux_dbvec) != -1)) {
344 printk("Booted under KADB. Syncing trap table.\n");
345 (*(linux_dbvec->teach_debugger))();
346 }
347
348 init_mm.context = (unsigned long) NO_CONTEXT;
349 init_task.thread.kregs = &fake_swapper_regs;
350
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200351 /* Run-time patch instructions to match the cpu model */
David S. Millerc68e5d32012-05-13 23:09:04 -0700352 per_cpu_patch();
353
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200354 paging_init();
355
Krzysztof Helta23b4232006-08-25 00:46:02 -0700356 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359extern int stop_a_enabled;
360
361void sun_do_break(void)
362{
363 if (!stop_a_enabled)
364 return;
365
366 printk("\n");
367 flush_user_windows();
368
369 prom_cmdline();
370}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800371EXPORT_SYMBOL(sun_do_break);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373int stop_a_enabled = 1;
Bob Breuera8cbdce2006-06-20 00:28:33 -0700374
375static int __init topology_init(void)
376{
377 int i, ncpus, err;
378
379 /* Count the number of physically present processors in
380 * the machine, even on uniprocessor, so that /proc/cpuinfo
381 * output is consistent with 2.4.x
382 */
383 ncpus = 0;
384 while (!cpu_find_by_instance(ncpus, NULL, NULL))
385 ncpus++;
386 ncpus_probed = ncpus;
387
388 err = 0;
389 for_each_online_cpu(i) {
390 struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
391 if (!p)
392 err = -ENOMEM;
393 else
Andrew Morton94583772006-06-29 02:24:27 -0700394 register_cpu(p, i);
Bob Breuera8cbdce2006-06-20 00:28:33 -0700395 }
396
397 return err;
398}
399
400subsys_initcall(topology_init);