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>
27 #include <linux/of_platform.h>
29 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
30 # include <linux/console.h>
34 # include <linux/timex.h>
38 # include <linux/seq_file.h>
41 #include <asm/bootparam.h>
42 #include <asm/mmu_context.h>
43 #include <asm/pgtable.h>
44 #include <asm/processor.h>
45 #include <asm/timex.h>
46 #include <asm/platform.h>
48 #include <asm/setup.h>
49 #include <asm/param.h>
50 #include <asm/traps.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 extern u32 __dtb_start[];
76 void *dtb_start = __dtb_start;
79 unsigned char aux_device_present;
80 extern unsigned long loops_per_jiffy;
82 /* Command line specified as configuration option. */
84 static char __initdata command_line[COMMAND_LINE_SIZE];
86 #ifdef CONFIG_CMDLINE_BOOL
87 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
90 sysmem_info_t __initdata sysmem;
92 extern int mem_reserve(unsigned long, unsigned long, int);
93 extern void bootmem_init(void);
94 extern void zones_init(void);
97 * Boot parameter parsing.
99 * The Xtensa port uses a list of variable-sized tags to pass data to
100 * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
101 * to be recognised. The list is terminated with a zero-sized
105 typedef struct tagtable {
107 int (*parse)(const bp_tag_t*);
110 #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
111 __attribute__((used, section(".taglist"))) = { tag, fn }
113 /* parse current tag */
115 static int __init add_sysmem_bank(unsigned long type, unsigned long start,
118 if (sysmem.nr_banks >= SYSMEM_BANKS_MAX) {
120 "Ignoring memory bank 0x%08lx size %ldKB\n",
124 sysmem.bank[sysmem.nr_banks].type = type;
125 sysmem.bank[sysmem.nr_banks].start = PAGE_ALIGN(start);
126 sysmem.bank[sysmem.nr_banks].end = end & PAGE_MASK;
132 static int __init parse_tag_mem(const bp_tag_t *tag)
134 meminfo_t *mi = (meminfo_t *)(tag->data);
136 if (mi->type != MEMORY_TYPE_CONVENTIONAL)
139 return add_sysmem_bank(mi->type, mi->start, mi->end);
142 __tagtable(BP_TAG_MEMORY, parse_tag_mem);
144 #ifdef CONFIG_BLK_DEV_INITRD
146 static int __init parse_tag_initrd(const bp_tag_t* tag)
149 mi = (meminfo_t*)(tag->data);
150 initrd_start = (unsigned long)__va(mi->start);
151 initrd_end = (unsigned long)__va(mi->end);
156 __tagtable(BP_TAG_INITRD, parse_tag_initrd);
160 static int __init parse_tag_fdt(const bp_tag_t *tag)
162 dtb_start = __va(tag->data[0]);
166 __tagtable(BP_TAG_FDT, parse_tag_fdt);
168 #endif /* CONFIG_OF */
170 #endif /* CONFIG_BLK_DEV_INITRD */
172 static int __init parse_tag_cmdline(const bp_tag_t* tag)
174 strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
178 __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
180 static int __init parse_bootparam(const bp_tag_t* tag)
182 extern tagtable_t __tagtable_begin, __tagtable_end;
185 /* Boot parameters must start with a BP_TAG_FIRST tag. */
187 if (tag->id != BP_TAG_FIRST) {
188 printk(KERN_WARNING "Invalid boot parameters!\n");
192 tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
194 /* Parse all tags. */
196 while (tag != NULL && tag->id != BP_TAG_LAST) {
197 for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
198 if (tag->id == t->tag) {
203 if (t == &__tagtable_end)
204 printk(KERN_WARNING "Ignoring tag "
205 "0x%08x\n", tag->id);
206 tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
213 bool __initdata dt_memory_scan = false;
215 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
221 add_sysmem_bank(MEMORY_TYPE_CONVENTIONAL, base, base + size);
224 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
226 return __alloc_bootmem(size, align, 0);
229 void __init early_init_devtree(void *params)
231 if (sysmem.nr_banks == 0)
232 dt_memory_scan = true;
234 early_init_dt_scan(params);
236 if (!command_line[0])
237 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
240 static int __init xtensa_device_probe(void)
242 of_platform_populate(NULL, NULL, NULL, NULL);
246 device_initcall(xtensa_device_probe);
248 #endif /* CONFIG_OF */
251 * Initialize architecture. (Early stage)
254 void __init init_arch(bp_tag_t *bp_start)
258 /* Parse boot parameters */
261 parse_bootparam(bp_start);
264 early_init_devtree(dtb_start);
267 if (sysmem.nr_banks == 0) {
269 sysmem.bank[0].start = PLATFORM_DEFAULT_MEM_START;
270 sysmem.bank[0].end = PLATFORM_DEFAULT_MEM_START
271 + PLATFORM_DEFAULT_MEM_SIZE;
274 #ifdef CONFIG_CMDLINE_BOOL
275 if (!command_line[0])
276 strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
279 /* Early hook for platforms */
281 platform_init(bp_start);
283 /* Initialize MMU. */
289 * Initialize system. Setup memory and reserve regions.
294 extern char _WindowVectors_text_start;
295 extern char _WindowVectors_text_end;
296 extern char _DebugInterruptVector_literal_start;
297 extern char _DebugInterruptVector_text_end;
298 extern char _KernelExceptionVector_literal_start;
299 extern char _KernelExceptionVector_text_end;
300 extern char _UserExceptionVector_literal_start;
301 extern char _UserExceptionVector_text_end;
302 extern char _DoubleExceptionVector_literal_start;
303 extern char _DoubleExceptionVector_text_end;
304 #if XCHAL_EXCM_LEVEL >= 2
305 extern char _Level2InterruptVector_text_start;
306 extern char _Level2InterruptVector_text_end;
308 #if XCHAL_EXCM_LEVEL >= 3
309 extern char _Level3InterruptVector_text_start;
310 extern char _Level3InterruptVector_text_end;
312 #if XCHAL_EXCM_LEVEL >= 4
313 extern char _Level4InterruptVector_text_start;
314 extern char _Level4InterruptVector_text_end;
316 #if XCHAL_EXCM_LEVEL >= 5
317 extern char _Level5InterruptVector_text_start;
318 extern char _Level5InterruptVector_text_end;
320 #if XCHAL_EXCM_LEVEL >= 6
321 extern char _Level6InterruptVector_text_start;
322 extern char _Level6InterruptVector_text_end;
327 #ifdef CONFIG_S32C1I_SELFTEST
328 #if XCHAL_HAVE_S32C1I
330 static int __initdata rcw_word, rcw_probe_pc, rcw_exc;
333 * Basic atomic compare-and-swap, that records PC of S32C1I for probing.
335 * If *v == cmp, set *v = set. Return previous *v.
337 static inline int probed_compare_swap(int *v, int cmp, int set)
341 __asm__ __volatile__(
344 " wsr %2, scompare1\n"
345 "1: s32c1i %0, %3, 0\n"
346 : "=a" (set), "=&a" (tmp)
347 : "a" (cmp), "a" (v), "a" (&rcw_probe_pc), "0" (set)
353 /* Handle probed exception */
355 static void __init do_probed_exception(struct pt_regs *regs,
356 unsigned long exccause)
358 if (regs->pc == rcw_probe_pc) { /* exception on s32c1i ? */
359 regs->pc += 3; /* skip the s32c1i instruction */
362 do_unhandled(regs, exccause);
366 /* Simple test of S32C1I (soc bringup assist) */
368 static int __init check_s32c1i(void)
370 int n, cause1, cause2;
371 void *handbus, *handdata, *handaddr; /* temporarily saved handlers */
374 handbus = trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR,
375 do_probed_exception);
376 handdata = trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR,
377 do_probed_exception);
378 handaddr = trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR,
379 do_probed_exception);
381 /* First try an S32C1I that does not store: */
384 n = probed_compare_swap(&rcw_word, 0, 2);
387 /* took exception? */
389 /* unclean exception? */
390 if (n != 2 || rcw_word != 1)
391 panic("S32C1I exception error");
392 } else if (rcw_word != 1 || n != 1) {
393 panic("S32C1I compare error");
396 /* Then an S32C1I that stores: */
398 rcw_word = 0x1234567;
399 n = probed_compare_swap(&rcw_word, 0x1234567, 0xabcde);
403 /* unclean exception? */
404 if (n != 0xabcde || rcw_word != 0x1234567)
405 panic("S32C1I exception error (b)");
406 } else if (rcw_word != 0xabcde || n != 0x1234567) {
407 panic("S32C1I store error");
410 /* Verify consistency of exceptions: */
411 if (cause1 || cause2) {
412 pr_warn("S32C1I took exception %d, %d\n", cause1, cause2);
413 /* If emulation of S32C1I upon bus error gets implemented,
414 we can get rid of this panic for single core (not SMP) */
415 panic("S32C1I exceptions not currently supported");
417 if (cause1 != cause2)
418 panic("inconsistent S32C1I exceptions");
420 trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, handbus);
421 trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, handdata);
422 trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, handaddr);
426 #else /* XCHAL_HAVE_S32C1I */
428 /* This condition should not occur with a commercially deployed processor.
429 Display reminder for early engr test or demo chips / FPGA bitstreams */
430 static int __init check_s32c1i(void)
432 pr_warn("Processor configuration lacks atomic compare-and-swap support!\n");
436 #endif /* XCHAL_HAVE_S32C1I */
437 early_initcall(check_s32c1i);
438 #endif /* CONFIG_S32C1I_SELFTEST */
441 void __init setup_arch(char **cmdline_p)
443 strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
444 *cmdline_p = command_line;
446 /* Reserve some memory regions */
448 #ifdef CONFIG_BLK_DEV_INITRD
449 if (initrd_start < initrd_end) {
450 initrd_is_mapped = mem_reserve(__pa(initrd_start),
451 __pa(initrd_end), 0);
452 initrd_below_start_ok = 1;
458 mem_reserve(__pa(&_stext),__pa(&_end), 1);
460 mem_reserve(__pa(&_WindowVectors_text_start),
461 __pa(&_WindowVectors_text_end), 0);
463 mem_reserve(__pa(&_DebugInterruptVector_literal_start),
464 __pa(&_DebugInterruptVector_text_end), 0);
466 mem_reserve(__pa(&_KernelExceptionVector_literal_start),
467 __pa(&_KernelExceptionVector_text_end), 0);
469 mem_reserve(__pa(&_UserExceptionVector_literal_start),
470 __pa(&_UserExceptionVector_text_end), 0);
472 mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
473 __pa(&_DoubleExceptionVector_text_end), 0);
475 #if XCHAL_EXCM_LEVEL >= 2
476 mem_reserve(__pa(&_Level2InterruptVector_text_start),
477 __pa(&_Level2InterruptVector_text_end), 0);
479 #if XCHAL_EXCM_LEVEL >= 3
480 mem_reserve(__pa(&_Level3InterruptVector_text_start),
481 __pa(&_Level3InterruptVector_text_end), 0);
483 #if XCHAL_EXCM_LEVEL >= 4
484 mem_reserve(__pa(&_Level4InterruptVector_text_start),
485 __pa(&_Level4InterruptVector_text_end), 0);
487 #if XCHAL_EXCM_LEVEL >= 5
488 mem_reserve(__pa(&_Level5InterruptVector_text_start),
489 __pa(&_Level5InterruptVector_text_end), 0);
491 #if XCHAL_EXCM_LEVEL >= 6
492 mem_reserve(__pa(&_Level6InterruptVector_text_start),
493 __pa(&_Level6InterruptVector_text_end), 0);
498 unflatten_and_copy_device_tree();
500 platform_setup(cmdline_p);
510 # if defined(CONFIG_VGA_CONSOLE)
511 conswitchp = &vga_con;
512 # elif defined(CONFIG_DUMMY_CONSOLE)
513 conswitchp = &dummy_con;
518 platform_pcibios_init();
522 static DEFINE_PER_CPU(struct cpu, cpu_data);
524 static int __init topology_init(void)
528 for_each_possible_cpu(i) {
529 struct cpu *cpu = &per_cpu(cpu_data, i);
530 cpu->hotpluggable = !!i;
531 register_cpu(cpu, i);
536 subsys_initcall(topology_init);
538 void machine_restart(char * cmd)
543 void machine_halt(void)
549 void machine_power_off(void)
551 platform_power_off();
554 #ifdef CONFIG_PROC_FS
557 * Display some core information through /proc/cpuinfo.
561 c_show(struct seq_file *f, void *slot)
563 char buf[NR_CPUS * 5];
565 cpulist_scnprintf(buf, sizeof(buf), cpu_online_mask);
566 /* high-level stuff */
567 seq_printf(f, "CPU count\t: %u\n"
569 "vendor_id\t: Tensilica\n"
570 "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
571 "core ID\t\t: " XCHAL_CORE_ID "\n"
574 "cpu MHz\t\t: %lu.%02lu\n"
575 "bogomips\t: %lu.%02lu\n",
578 XCHAL_BUILD_UNIQUE_ID,
579 XCHAL_HAVE_BE ? "big" : "little",
581 (ccount_freq/10000) % 100,
582 loops_per_jiffy/(500000/HZ),
583 (loops_per_jiffy/(5000/HZ)) % 100);
585 seq_printf(f,"flags\t\t: "
595 #if XCHAL_HAVE_DENSITY
598 #if XCHAL_HAVE_BOOLEANS
607 #if XCHAL_HAVE_MINMAX
613 #if XCHAL_HAVE_CLAMPS
625 #if XCHAL_HAVE_MUL32_HIGH
631 #if XCHAL_HAVE_S32C1I
637 seq_printf(f,"physical aregs\t: %d\n"
648 seq_printf(f,"num ints\t: %d\n"
652 "debug level\t: %d\n",
653 XCHAL_NUM_INTERRUPTS,
654 XCHAL_NUM_EXTINTERRUPTS,
660 seq_printf(f,"icache line size: %d\n"
661 "icache ways\t: %d\n"
662 "icache size\t: %d\n"
664 #if XCHAL_ICACHE_LINE_LOCKABLE
668 "dcache line size: %d\n"
669 "dcache ways\t: %d\n"
670 "dcache size\t: %d\n"
672 #if XCHAL_DCACHE_IS_WRITEBACK
675 #if XCHAL_DCACHE_LINE_LOCKABLE
679 XCHAL_ICACHE_LINESIZE,
682 XCHAL_DCACHE_LINESIZE,
690 * We show only CPU #0 info.
693 c_start(struct seq_file *f, loff_t *pos)
695 return (*pos == 0) ? (void *)1 : NULL;
699 c_next(struct seq_file *f, void *v, loff_t *pos)
705 c_stop(struct seq_file *f, void *v)
709 const struct seq_operations cpuinfo_op =
717 #endif /* CONFIG_PROC_FS */