2 * arch/xtensa/kernel/setup.c
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 1995 Linus Torvalds
9 * Copyright (C) 2001 - 2005 Tensilica Inc.
11 * Chris Zankel <chris@zankel.net>
12 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
14 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
17 #include <linux/errno.h>
18 #include <linux/init.h>
20 #include <linux/proc_fs.h>
21 #include <linux/screen_info.h>
22 #include <linux/bootmem.h>
23 #include <linux/kernel.h>
24 #include <linux/percpu.h>
25 #include <linux/cpu.h>
26 #include <linux/of_fdt.h>
28 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
29 # include <linux/console.h>
33 # include <linux/timex.h>
37 # include <linux/seq_file.h>
40 #include <asm/bootparam.h>
41 #include <asm/mmu_context.h>
42 #include <asm/pgtable.h>
43 #include <asm/processor.h>
44 #include <asm/timex.h>
45 #include <asm/platform.h>
47 #include <asm/setup.h>
48 #include <asm/param.h>
49 #include <asm/traps.h>
51 #include <asm/sysmem.h>
53 #include <platform/hardware.h>
55 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
56 struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16};
59 #ifdef CONFIG_BLK_DEV_FD
60 extern struct fd_ops no_fd_ops;
61 struct fd_ops *fd_ops;
64 extern struct rtc_ops no_rtc_ops;
65 struct rtc_ops *rtc_ops;
67 #ifdef CONFIG_BLK_DEV_INITRD
68 extern unsigned long initrd_start;
69 extern unsigned long initrd_end;
70 int initrd_is_mapped = 0;
71 extern int initrd_below_start_ok;
75 void *dtb_start = __dtb_start;
78 unsigned char aux_device_present;
79 extern unsigned long loops_per_jiffy;
81 /* Command line specified as configuration option. */
83 static char __initdata command_line[COMMAND_LINE_SIZE];
85 #ifdef CONFIG_CMDLINE_BOOL
86 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
90 * Boot parameter parsing.
92 * The Xtensa port uses a list of variable-sized tags to pass data to
93 * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
94 * to be recognised. The list is terminated with a zero-sized
98 typedef struct tagtable {
100 int (*parse)(const bp_tag_t*);
103 #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
104 __attribute__((used, section(".taglist"))) = { tag, fn }
106 /* parse current tag */
108 static int __init parse_tag_mem(const bp_tag_t *tag)
110 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
112 if (mi->type != MEMORY_TYPE_CONVENTIONAL)
115 return add_sysmem_bank(mi->start, mi->end);
118 __tagtable(BP_TAG_MEMORY, parse_tag_mem);
120 #ifdef CONFIG_BLK_DEV_INITRD
122 static int __init parse_tag_initrd(const bp_tag_t* tag)
124 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
126 initrd_start = (unsigned long)__va(mi->start);
127 initrd_end = (unsigned long)__va(mi->end);
132 __tagtable(BP_TAG_INITRD, parse_tag_initrd);
136 static int __init parse_tag_fdt(const bp_tag_t *tag)
138 dtb_start = __va(tag->data[0]);
142 __tagtable(BP_TAG_FDT, parse_tag_fdt);
144 #endif /* CONFIG_OF */
146 #endif /* CONFIG_BLK_DEV_INITRD */
148 static int __init parse_tag_cmdline(const bp_tag_t* tag)
150 strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
154 __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
156 static int __init parse_bootparam(const bp_tag_t* tag)
158 extern tagtable_t __tagtable_begin, __tagtable_end;
161 /* Boot parameters must start with a BP_TAG_FIRST tag. */
163 if (tag->id != BP_TAG_FIRST) {
164 printk(KERN_WARNING "Invalid boot parameters!\n");
168 tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
170 /* Parse all tags. */
172 while (tag != NULL && tag->id != BP_TAG_LAST) {
173 for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
174 if (tag->id == t->tag) {
179 if (t == &__tagtable_end)
180 printk(KERN_WARNING "Ignoring tag "
181 "0x%08x\n", tag->id);
182 tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
189 bool __initdata dt_memory_scan = false;
191 #if !XCHAL_HAVE_PTP_MMU || XCHAL_HAVE_SPANNING_WAY
192 unsigned long xtensa_kio_paddr = XCHAL_KIO_DEFAULT_PADDR;
193 EXPORT_SYMBOL(xtensa_kio_paddr);
195 static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
196 int depth, void *data)
198 const __be32 *ranges;
204 if (!of_flat_dt_is_compatible(node, "simple-bus"))
207 ranges = of_get_flat_dt_prop(node, "ranges", &len);
213 xtensa_kio_paddr = of_read_ulong(ranges+1, 1);
214 /* round down to nearest 256MB boundary */
215 xtensa_kio_paddr &= 0xf0000000;
220 static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
221 int depth, void *data)
227 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
233 add_sysmem_bank(base, base + size);
236 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
238 return __alloc_bootmem(size, align, 0);
241 void __init early_init_devtree(void *params)
243 if (sysmem.nr_banks == 0)
244 dt_memory_scan = true;
246 early_init_dt_scan(params);
247 of_scan_flat_dt(xtensa_dt_io_area, NULL);
249 if (!command_line[0])
250 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
253 #endif /* CONFIG_OF */
256 * Initialize architecture. (Early stage)
259 void __init init_arch(bp_tag_t *bp_start)
261 /* Parse boot parameters */
264 parse_bootparam(bp_start);
267 early_init_devtree(dtb_start);
270 if (sysmem.nr_banks == 0) {
271 add_sysmem_bank(PLATFORM_DEFAULT_MEM_START,
272 PLATFORM_DEFAULT_MEM_START +
273 PLATFORM_DEFAULT_MEM_SIZE);
276 #ifdef CONFIG_CMDLINE_BOOL
277 if (!command_line[0])
278 strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
281 /* Early hook for platforms */
283 platform_init(bp_start);
285 /* Initialize MMU. */
291 * Initialize system. Setup memory and reserve regions.
296 extern char _WindowVectors_text_start;
297 extern char _WindowVectors_text_end;
298 extern char _DebugInterruptVector_literal_start;
299 extern char _DebugInterruptVector_text_end;
300 extern char _KernelExceptionVector_literal_start;
301 extern char _KernelExceptionVector_text_end;
302 extern char _UserExceptionVector_literal_start;
303 extern char _UserExceptionVector_text_end;
304 extern char _DoubleExceptionVector_literal_start;
305 extern char _DoubleExceptionVector_text_end;
306 #if XCHAL_EXCM_LEVEL >= 2
307 extern char _Level2InterruptVector_text_start;
308 extern char _Level2InterruptVector_text_end;
310 #if XCHAL_EXCM_LEVEL >= 3
311 extern char _Level3InterruptVector_text_start;
312 extern char _Level3InterruptVector_text_end;
314 #if XCHAL_EXCM_LEVEL >= 4
315 extern char _Level4InterruptVector_text_start;
316 extern char _Level4InterruptVector_text_end;
318 #if XCHAL_EXCM_LEVEL >= 5
319 extern char _Level5InterruptVector_text_start;
320 extern char _Level5InterruptVector_text_end;
322 #if XCHAL_EXCM_LEVEL >= 6
323 extern char _Level6InterruptVector_text_start;
324 extern char _Level6InterruptVector_text_end;
327 extern char _SecondaryResetVector_text_start;
328 extern char _SecondaryResetVector_text_end;
332 #ifdef CONFIG_S32C1I_SELFTEST
333 #if XCHAL_HAVE_S32C1I
335 static int __initdata rcw_word, rcw_probe_pc, rcw_exc;
338 * Basic atomic compare-and-swap, that records PC of S32C1I for probing.
340 * If *v == cmp, set *v = set. Return previous *v.
342 static inline int probed_compare_swap(int *v, int cmp, int set)
346 __asm__ __volatile__(
349 " wsr %2, scompare1\n"
350 "1: s32c1i %0, %3, 0\n"
351 : "=a" (set), "=&a" (tmp)
352 : "a" (cmp), "a" (v), "a" (&rcw_probe_pc), "0" (set)
358 /* Handle probed exception */
360 static void __init do_probed_exception(struct pt_regs *regs,
361 unsigned long exccause)
363 if (regs->pc == rcw_probe_pc) { /* exception on s32c1i ? */
364 regs->pc += 3; /* skip the s32c1i instruction */
367 do_unhandled(regs, exccause);
371 /* Simple test of S32C1I (soc bringup assist) */
373 static int __init check_s32c1i(void)
375 int n, cause1, cause2;
376 void *handbus, *handdata, *handaddr; /* temporarily saved handlers */
379 handbus = trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR,
380 do_probed_exception);
381 handdata = trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR,
382 do_probed_exception);
383 handaddr = trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR,
384 do_probed_exception);
386 /* First try an S32C1I that does not store: */
389 n = probed_compare_swap(&rcw_word, 0, 2);
392 /* took exception? */
394 /* unclean exception? */
395 if (n != 2 || rcw_word != 1)
396 panic("S32C1I exception error");
397 } else if (rcw_word != 1 || n != 1) {
398 panic("S32C1I compare error");
401 /* Then an S32C1I that stores: */
403 rcw_word = 0x1234567;
404 n = probed_compare_swap(&rcw_word, 0x1234567, 0xabcde);
408 /* unclean exception? */
409 if (n != 0xabcde || rcw_word != 0x1234567)
410 panic("S32C1I exception error (b)");
411 } else if (rcw_word != 0xabcde || n != 0x1234567) {
412 panic("S32C1I store error");
415 /* Verify consistency of exceptions: */
416 if (cause1 || cause2) {
417 pr_warn("S32C1I took exception %d, %d\n", cause1, cause2);
418 /* If emulation of S32C1I upon bus error gets implemented,
419 we can get rid of this panic for single core (not SMP) */
420 panic("S32C1I exceptions not currently supported");
422 if (cause1 != cause2)
423 panic("inconsistent S32C1I exceptions");
425 trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, handbus);
426 trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, handdata);
427 trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, handaddr);
431 #else /* XCHAL_HAVE_S32C1I */
433 /* This condition should not occur with a commercially deployed processor.
434 Display reminder for early engr test or demo chips / FPGA bitstreams */
435 static int __init check_s32c1i(void)
437 pr_warn("Processor configuration lacks atomic compare-and-swap support!\n");
441 #endif /* XCHAL_HAVE_S32C1I */
442 early_initcall(check_s32c1i);
443 #endif /* CONFIG_S32C1I_SELFTEST */
446 void __init setup_arch(char **cmdline_p)
448 strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
449 *cmdline_p = command_line;
451 /* Reserve some memory regions */
453 #ifdef CONFIG_BLK_DEV_INITRD
454 if (initrd_start < initrd_end) {
455 initrd_is_mapped = mem_reserve(__pa(initrd_start),
456 __pa(initrd_end), 0) == 0;
457 initrd_below_start_ok = 1;
463 mem_reserve(__pa(&_stext),__pa(&_end), 1);
465 mem_reserve(__pa(&_WindowVectors_text_start),
466 __pa(&_WindowVectors_text_end), 0);
468 mem_reserve(__pa(&_DebugInterruptVector_literal_start),
469 __pa(&_DebugInterruptVector_text_end), 0);
471 mem_reserve(__pa(&_KernelExceptionVector_literal_start),
472 __pa(&_KernelExceptionVector_text_end), 0);
474 mem_reserve(__pa(&_UserExceptionVector_literal_start),
475 __pa(&_UserExceptionVector_text_end), 0);
477 mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
478 __pa(&_DoubleExceptionVector_text_end), 0);
480 #if XCHAL_EXCM_LEVEL >= 2
481 mem_reserve(__pa(&_Level2InterruptVector_text_start),
482 __pa(&_Level2InterruptVector_text_end), 0);
484 #if XCHAL_EXCM_LEVEL >= 3
485 mem_reserve(__pa(&_Level3InterruptVector_text_start),
486 __pa(&_Level3InterruptVector_text_end), 0);
488 #if XCHAL_EXCM_LEVEL >= 4
489 mem_reserve(__pa(&_Level4InterruptVector_text_start),
490 __pa(&_Level4InterruptVector_text_end), 0);
492 #if XCHAL_EXCM_LEVEL >= 5
493 mem_reserve(__pa(&_Level5InterruptVector_text_start),
494 __pa(&_Level5InterruptVector_text_end), 0);
496 #if XCHAL_EXCM_LEVEL >= 6
497 mem_reserve(__pa(&_Level6InterruptVector_text_start),
498 __pa(&_Level6InterruptVector_text_end), 0);
502 mem_reserve(__pa(&_SecondaryResetVector_text_start),
503 __pa(&_SecondaryResetVector_text_end), 0);
508 unflatten_and_copy_device_tree();
510 platform_setup(cmdline_p);
520 # if defined(CONFIG_VGA_CONSOLE)
521 conswitchp = &vga_con;
522 # elif defined(CONFIG_DUMMY_CONSOLE)
523 conswitchp = &dummy_con;
528 platform_pcibios_init();
532 static DEFINE_PER_CPU(struct cpu, cpu_data);
534 static int __init topology_init(void)
538 for_each_possible_cpu(i) {
539 struct cpu *cpu = &per_cpu(cpu_data, i);
540 cpu->hotpluggable = !!i;
541 register_cpu(cpu, i);
546 subsys_initcall(topology_init);
548 void machine_restart(char * cmd)
553 void machine_halt(void)
559 void machine_power_off(void)
561 platform_power_off();
564 #ifdef CONFIG_PROC_FS
567 * Display some core information through /proc/cpuinfo.
571 c_show(struct seq_file *f, void *slot)
573 /* high-level stuff */
574 seq_printf(f, "CPU count\t: %u\n"
575 "CPU list\t: %*pbl\n"
576 "vendor_id\t: Tensilica\n"
577 "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
578 "core ID\t\t: " XCHAL_CORE_ID "\n"
581 "cpu MHz\t\t: %lu.%02lu\n"
582 "bogomips\t: %lu.%02lu\n",
584 cpumask_pr_args(cpu_online_mask),
585 XCHAL_BUILD_UNIQUE_ID,
586 XCHAL_HAVE_BE ? "big" : "little",
588 (ccount_freq/10000) % 100,
589 loops_per_jiffy/(500000/HZ),
590 (loops_per_jiffy/(5000/HZ)) % 100);
592 seq_printf(f,"flags\t\t: "
602 #if XCHAL_HAVE_DENSITY
605 #if XCHAL_HAVE_BOOLEANS
614 #if XCHAL_HAVE_MINMAX
620 #if XCHAL_HAVE_CLAMPS
632 #if XCHAL_HAVE_MUL32_HIGH
638 #if XCHAL_HAVE_S32C1I
644 seq_printf(f,"physical aregs\t: %d\n"
655 seq_printf(f,"num ints\t: %d\n"
659 "debug level\t: %d\n",
660 XCHAL_NUM_INTERRUPTS,
661 XCHAL_NUM_EXTINTERRUPTS,
667 seq_printf(f,"icache line size: %d\n"
668 "icache ways\t: %d\n"
669 "icache size\t: %d\n"
671 #if XCHAL_ICACHE_LINE_LOCKABLE
675 "dcache line size: %d\n"
676 "dcache ways\t: %d\n"
677 "dcache size\t: %d\n"
679 #if XCHAL_DCACHE_IS_WRITEBACK
682 #if XCHAL_DCACHE_LINE_LOCKABLE
686 XCHAL_ICACHE_LINESIZE,
689 XCHAL_DCACHE_LINESIZE,
697 * We show only CPU #0 info.
700 c_start(struct seq_file *f, loff_t *pos)
702 return (*pos == 0) ? (void *)1 : NULL;
706 c_next(struct seq_file *f, void *v, loff_t *pos)
712 c_stop(struct seq_file *f, void *v)
716 const struct seq_operations cpuinfo_op =
724 #endif /* CONFIG_PROC_FS */