blob: c052313f4dc578700193abaf5fc6e9b127e66e0a [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#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/traps.h>
42#include <asm/vaddrs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/mbus.h>
44#include <asm/idprom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <asm/cpudata.h>
46#include <asm/setup.h>
David Howellsd550bbd2012-03-28 18:30:03 +010047#include <asm/cacheflush.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Sam Ravnborg53ae3412008-12-07 00:02:08 -080049#include "kernel.h"
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051struct screen_info screen_info = {
52 0, 0, /* orig-x, orig-y */
53 0, /* unused */
54 0, /* orig-video-page */
55 0, /* orig-video-mode */
56 128, /* orig-video-cols */
57 0,0,0, /* ega_ax, ega_bx, ega_cx */
58 54, /* orig-video-lines */
59 0, /* orig-video-isVGA */
60 16 /* orig-video-points */
61};
62
63/* Typing sync at the prom prompt calls the function pointed to by
64 * romvec->pv_synchook which I set to the following function.
65 * This should sync all filesystems and return, for now it just
66 * prints out pretty messages and returns.
67 */
68
69extern unsigned long trapbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* Pretty sick eh? */
Adrian Bunkc61c65c2008-06-05 11:40:58 -070072static void prom_sync_me(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 unsigned long prom_tbr, flags;
75
76 /* XXX Badly broken. FIX! - Anton */
77 local_irq_save(flags);
78 __asm__ __volatile__("rd %%tbr, %0\n\t" : "=r" (prom_tbr));
79 __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
80 "nop\n\t"
81 "nop\n\t"
82 "nop\n\t" : : "r" (&trapbase));
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 prom_printf("PROM SYNC COMMAND...\n");
David Rientjes7bf02ea2011-05-24 17:11:16 -070085 show_free_areas(0);
Paul E. McKenney29f043a2011-11-10 15:56:46 -080086 if (!is_idle_task(current)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 local_irq_enable();
88 sys_sync();
89 local_irq_disable();
90 }
91 prom_printf("Returning to prom\n");
92
93 __asm__ __volatile__("wr %0, 0x0, %%tbr\n\t"
94 "nop\n\t"
95 "nop\n\t"
96 "nop\n\t" : : "r" (prom_tbr));
97 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700100static unsigned int boot_flags __initdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#define BOOTME_DEBUG 0x1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/* Exported for mm/init.c:paging_init. */
104unsigned long cmdline_memory_size __initdata = 0;
105
Daniel Hellstrom5fcafb72011-04-21 04:20:23 +0000106/* which CPU booted us (0xff = not set) */
107unsigned char boot_cpu_id = 0xff; /* 0xff will make it into DATA section... */
Daniel Hellstrom5fcafb72011-04-21 04:20:23 +0000108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static void
110prom_console_write(struct console *con, const char *s, unsigned n)
111{
112 prom_write(s, n);
113}
114
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700115static struct console prom_early_console = {
116 .name = "earlyprom",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .write = prom_console_write,
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700118 .flags = CON_PRINTBUFFER | CON_BOOT,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .index = -1,
120};
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/*
123 * Process kernel command line switches that are specific to the
124 * SPARC or that require special low-level processing.
125 */
126static void __init process_switch(char c)
127{
128 switch (c) {
129 case 'd':
130 boot_flags |= BOOTME_DEBUG;
131 break;
132 case 's':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 break;
134 case 'h':
135 prom_printf("boot_flags_init: Halt!\n");
136 prom_halt();
137 break;
138 case 'p':
David S. Miller11032c12011-09-21 12:48:06 -0700139 prom_early_console.flags &= ~CON_BOOT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 break;
141 default:
142 printk("Unknown boot switch (-%c)\n", c);
143 break;
144 }
145}
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static void __init boot_flags_init(char *commands)
148{
149 while (*commands) {
150 /* Move to the start of the next "argument". */
151 while (*commands && *commands == ' ')
152 commands++;
153
154 /* Process any command switches, otherwise skip it. */
155 if (*commands == '\0')
156 break;
157 if (*commands == '-') {
158 commands++;
159 while (*commands && *commands != ' ')
160 process_switch(*commands++);
161 continue;
162 }
David S. Millerc73fcc82007-07-20 16:59:26 -0700163 if (!strncmp(commands, "mem=", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 /*
165 * "mem=XXX[kKmM] overrides the PROM-reported
166 * memory size.
167 */
168 cmdline_memory_size = simple_strtoul(commands + 4,
169 &commands, 0);
170 if (*commands == 'K' || *commands == 'k') {
171 cmdline_memory_size <<= 10;
172 commands++;
173 } else if (*commands=='M' || *commands=='m') {
174 cmdline_memory_size <<= 20;
175 commands++;
176 }
177 }
178 while (*commands && *commands != ' ')
179 commands++;
180 }
181}
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183extern unsigned short root_flags;
184extern unsigned short root_dev;
185extern unsigned short ram_flags;
186#define RAMDISK_IMAGE_START_MASK 0x07FF
187#define RAMDISK_PROMPT_FLAG 0x8000
188#define RAMDISK_LOAD_FLAG 0x4000
189
190extern int root_mountflags;
191
192char reboot_command[COMMAND_LINE_SIZE];
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800193
David S. Millerc68e5d32012-05-13 23:09:04 -0700194struct cpuid_patch_entry {
195 unsigned int addr;
196 unsigned int sun4d[3];
197 unsigned int leon[3];
198};
199extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
200
201static void __init per_cpu_patch(void)
202{
203 struct cpuid_patch_entry *p;
204
205 if (sparc_cpu_model == sun4m) {
206 /* Nothing to do, this is what the unpatched code
207 * targets.
208 */
209 return;
210 }
211
212 p = &__cpuid_patch;
213 while (p < &__cpuid_patch_end) {
214 unsigned long addr = p->addr;
215 unsigned int *insns;
216
217 switch (sparc_cpu_model) {
218 case sun4d:
219 insns = &p->sun4d[0];
220 break;
221
222 case sparc_leon:
223 insns = &p->leon[0];
224 break;
225 default:
226 prom_printf("Unknown cpu type, halting.\n");
227 prom_halt();
228 }
229 *(unsigned int *) (addr + 0) = insns[0];
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200230 flushi(addr + 0);
David S. Millerc68e5d32012-05-13 23:09:04 -0700231 *(unsigned int *) (addr + 4) = insns[1];
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200232 flushi(addr + 4);
David S. Millerc68e5d32012-05-13 23:09:04 -0700233 *(unsigned int *) (addr + 8) = insns[2];
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200234 flushi(addr + 8);
Sam Ravnborg9cd5f822012-05-20 17:24:20 +0200235
236 p++;
David S. Millerc68e5d32012-05-13 23:09:04 -0700237 }
David S. Millerc68e5d32012-05-13 23:09:04 -0700238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240enum sparc_cpu sparc_cpu_model;
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800241EXPORT_SYMBOL(sparc_cpu_model);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243struct tt_entry *sparc_ttable;
244
245struct pt_regs fake_swapper_regs;
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247void __init setup_arch(char **cmdline_p)
248{
249 int i;
250 unsigned long highest_paddr;
251
Sam Ravnborge405ae72011-01-04 11:39:11 +0000252 sparc_ttable = (struct tt_entry *) &trapbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254 /* Initialize PROM console and command line. */
255 *cmdline_p = prom_getbootargs();
Alon Bar-Lev08e7ca12007-02-12 00:54:21 -0800256 strcpy(boot_command_line, *cmdline_p);
David S. Miller3fbe36d2008-09-10 23:40:32 -0700257 parse_early_param();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700259 boot_flags_init(*cmdline_p);
260
261 register_console(&prom_early_console);
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 /* Set sparc_cpu_model */
264 sparc_cpu_model = sun_unknown;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000265 if (!strcmp(&cputypval[0], "sun4m"))
David S. Miller365b50f2008-09-02 01:13:31 -0700266 sparc_cpu_model = sun4m;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000267 if (!strcmp(&cputypval[0], "sun4s"))
David S. Miller365b50f2008-09-02 01:13:31 -0700268 sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000269 if (!strcmp(&cputypval[0], "sun4d"))
David S. Miller365b50f2008-09-02 01:13:31 -0700270 sparc_cpu_model = sun4d;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000271 if (!strcmp(&cputypval[0], "sun4e"))
David S. Miller365b50f2008-09-02 01:13:31 -0700272 sparc_cpu_model = sun4e;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000273 if (!strcmp(&cputypval[0], "sun4u"))
David S. Miller365b50f2008-09-02 01:13:31 -0700274 sparc_cpu_model = sun4u;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000275 if (!strncmp(&cputypval[0], "leon" , 4))
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000276 sparc_cpu_model = sparc_leon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 printk("ARCH: ");
279 switch(sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 case sun4m:
281 printk("SUN4M\n");
282 break;
283 case sun4d:
284 printk("SUN4D\n");
285 break;
286 case sun4e:
287 printk("SUN4E\n");
288 break;
289 case sun4u:
290 printk("SUN4U\n");
291 break;
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000292 case sparc_leon:
293 printk("LEON\n");
294 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 default:
296 printk("UNKNOWN!\n");
297 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000298 }
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 load_mmu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 phys_base = 0xffffffffUL;
308 highest_paddr = 0UL;
309 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
310 unsigned long top;
311
312 if (sp_banks[i].base_addr < phys_base)
313 phys_base = sp_banks[i].base_addr;
314 top = sp_banks[i].base_addr +
315 sp_banks[i].num_bytes;
316 if (highest_paddr < top)
317 highest_paddr = top;
318 }
319 pfn_base = phys_base >> PAGE_SHIFT;
320
321 if (!root_flags)
322 root_mountflags &= ~MS_RDONLY;
323 ROOT_DEV = old_decode_dev(root_dev);
Al Viro5d2170a2006-06-22 14:47:14 -0700324#ifdef CONFIG_BLK_DEV_RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
326 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
327 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
328#endif
329
330 prom_setsync(prom_sync_me);
331
332 if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
333 ((*(short *)linux_dbvec) != -1)) {
334 printk("Booted under KADB. Syncing trap table.\n");
335 (*(linux_dbvec->teach_debugger))();
336 }
337
338 init_mm.context = (unsigned long) NO_CONTEXT;
339 init_task.thread.kregs = &fake_swapper_regs;
340
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200341 /* Run-time patch instructions to match the cpu model */
David S. Millerc68e5d32012-05-13 23:09:04 -0700342 per_cpu_patch();
343
Sam Ravnborg1edc1782012-05-20 17:27:53 +0200344 paging_init();
345
Krzysztof Helta23b4232006-08-25 00:46:02 -0700346 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349extern int stop_a_enabled;
350
351void sun_do_break(void)
352{
353 if (!stop_a_enabled)
354 return;
355
356 printk("\n");
357 flush_user_windows();
358
359 prom_cmdline();
360}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800361EXPORT_SYMBOL(sun_do_break);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363int stop_a_enabled = 1;
Bob Breuera8cbdce2006-06-20 00:28:33 -0700364
365static int __init topology_init(void)
366{
367 int i, ncpus, err;
368
369 /* Count the number of physically present processors in
370 * the machine, even on uniprocessor, so that /proc/cpuinfo
371 * output is consistent with 2.4.x
372 */
373 ncpus = 0;
374 while (!cpu_find_by_instance(ncpus, NULL, NULL))
375 ncpus++;
376 ncpus_probed = ncpus;
377
378 err = 0;
379 for_each_online_cpu(i) {
380 struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
381 if (!p)
382 err = -ENOMEM;
383 else
Andrew Morton94583772006-06-29 02:24:27 -0700384 register_cpu(p, i);
Bob Breuera8cbdce2006-06-20 00:28:33 -0700385 }
386
387 return err;
388}
389
390subsys_initcall(topology_init);