blob: 2f7cfb5f7569dbc4f27d06b24f7042f2c3b52b84 [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... */
108unsigned char boot_cpu_id4; /* boot_cpu_id << 2 */
109
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];
231 *(unsigned int *) (addr + 4) = insns[1];
232 *(unsigned int *) (addr + 8) = insns[2];
233 }
234#ifdef CONFIG_SMP
235 local_ops->cache_all();
236#else
237 sparc32_cachetlb_ops->cache_all();
238#endif
239}
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248void __init setup_arch(char **cmdline_p)
249{
250 int i;
251 unsigned long highest_paddr;
252
Sam Ravnborge405ae72011-01-04 11:39:11 +0000253 sparc_ttable = (struct tt_entry *) &trapbase;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 /* Initialize PROM console and command line. */
256 *cmdline_p = prom_getbootargs();
Alon Bar-Lev08e7ca12007-02-12 00:54:21 -0800257 strcpy(boot_command_line, *cmdline_p);
David S. Miller3fbe36d2008-09-10 23:40:32 -0700258 parse_early_param();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Sam Ravnborg7671fa22011-04-21 15:47:35 -0700260 boot_flags_init(*cmdline_p);
261
262 register_console(&prom_early_console);
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 /* Set sparc_cpu_model */
265 sparc_cpu_model = sun_unknown;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000266 if (!strcmp(&cputypval[0], "sun4m"))
David S. Miller365b50f2008-09-02 01:13:31 -0700267 sparc_cpu_model = sun4m;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000268 if (!strcmp(&cputypval[0], "sun4s"))
David S. Miller365b50f2008-09-02 01:13:31 -0700269 sparc_cpu_model = sun4m; /* CP-1200 with PROM 2.30 -E */
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000270 if (!strcmp(&cputypval[0], "sun4d"))
David S. Miller365b50f2008-09-02 01:13:31 -0700271 sparc_cpu_model = sun4d;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000272 if (!strcmp(&cputypval[0], "sun4e"))
David S. Miller365b50f2008-09-02 01:13:31 -0700273 sparc_cpu_model = sun4e;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000274 if (!strcmp(&cputypval[0], "sun4u"))
David S. Miller365b50f2008-09-02 01:13:31 -0700275 sparc_cpu_model = sun4u;
Sam Ravnborgb7afdb72011-01-28 22:08:18 +0000276 if (!strncmp(&cputypval[0], "leon" , 4))
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000277 sparc_cpu_model = sparc_leon;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 printk("ARCH: ");
280 switch(sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 case sun4m:
282 printk("SUN4M\n");
283 break;
284 case sun4d:
285 printk("SUN4D\n");
286 break;
287 case sun4e:
288 printk("SUN4E\n");
289 break;
290 case sun4u:
291 printk("SUN4U\n");
292 break;
Konrad Eisele0fd7ef12009-08-17 00:13:31 +0000293 case sparc_leon:
294 printk("LEON\n");
295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 default:
297 printk("UNKNOWN!\n");
298 break;
Joe Perches6cb79b32011-06-03 14:45:23 +0000299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301#ifdef CONFIG_DUMMY_CONSOLE
302 conswitchp = &dummy_con;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 idprom_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 load_mmu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 phys_base = 0xffffffffUL;
309 highest_paddr = 0UL;
310 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
311 unsigned long top;
312
313 if (sp_banks[i].base_addr < phys_base)
314 phys_base = sp_banks[i].base_addr;
315 top = sp_banks[i].base_addr +
316 sp_banks[i].num_bytes;
317 if (highest_paddr < top)
318 highest_paddr = top;
319 }
320 pfn_base = phys_base >> PAGE_SHIFT;
321
322 if (!root_flags)
323 root_mountflags &= ~MS_RDONLY;
324 ROOT_DEV = old_decode_dev(root_dev);
Al Viro5d2170a2006-06-22 14:47:14 -0700325#ifdef CONFIG_BLK_DEV_RAM
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 rd_image_start = ram_flags & RAMDISK_IMAGE_START_MASK;
327 rd_prompt = ((ram_flags & RAMDISK_PROMPT_FLAG) != 0);
328 rd_doload = ((ram_flags & RAMDISK_LOAD_FLAG) != 0);
329#endif
330
331 prom_setsync(prom_sync_me);
332
333 if((boot_flags&BOOTME_DEBUG) && (linux_dbvec!=0) &&
334 ((*(short *)linux_dbvec) != -1)) {
335 printk("Booted under KADB. Syncing trap table.\n");
336 (*(linux_dbvec->teach_debugger))();
337 }
338
339 init_mm.context = (unsigned long) NO_CONTEXT;
340 init_task.thread.kregs = &fake_swapper_regs;
341
342 paging_init();
Krzysztof Helta23b4232006-08-25 00:46:02 -0700343
David S. Millerc68e5d32012-05-13 23:09:04 -0700344 /* Now that we have the cache ops hooked up, we can patch
345 * instructions.
346 */
347 per_cpu_patch();
348
Krzysztof Helta23b4232006-08-25 00:46:02 -0700349 smp_setup_cpu_possible_map();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352extern int stop_a_enabled;
353
354void sun_do_break(void)
355{
356 if (!stop_a_enabled)
357 return;
358
359 printk("\n");
360 flush_user_windows();
361
362 prom_cmdline();
363}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800364EXPORT_SYMBOL(sun_do_break);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366int stop_a_enabled = 1;
Bob Breuera8cbdce2006-06-20 00:28:33 -0700367
368static int __init topology_init(void)
369{
370 int i, ncpus, err;
371
372 /* Count the number of physically present processors in
373 * the machine, even on uniprocessor, so that /proc/cpuinfo
374 * output is consistent with 2.4.x
375 */
376 ncpus = 0;
377 while (!cpu_find_by_instance(ncpus, NULL, NULL))
378 ncpus++;
379 ncpus_probed = ncpus;
380
381 err = 0;
382 for_each_online_cpu(i) {
383 struct cpu *p = kzalloc(sizeof(*p), GFP_KERNEL);
384 if (!p)
385 err = -ENOMEM;
386 else
Andrew Morton94583772006-06-29 02:24:27 -0700387 register_cpu(p, i);
Bob Breuera8cbdce2006-06-20 00:28:33 -0700388 }
389
390 return err;
391}
392
393subsys_initcall(topology_init);