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/clk-provider.h>
26 #include <linux/cpu.h>
27 #include <linux/of_fdt.h>
28 #include <linux/of_platform.h>
30 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
31 # include <linux/console.h>
35 # include <linux/timex.h>
39 # include <linux/seq_file.h>
42 #include <asm/bootparam.h>
43 #include <asm/mmu_context.h>
44 #include <asm/pgtable.h>
45 #include <asm/processor.h>
46 #include <asm/timex.h>
47 #include <asm/platform.h>
49 #include <asm/setup.h>
50 #include <asm/param.h>
51 #include <asm/traps.h>
53 #include <asm/sysmem.h>
55 #include <platform/hardware.h>
57 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
58 struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16};
61 #ifdef CONFIG_BLK_DEV_FD
62 extern struct fd_ops no_fd_ops;
63 struct fd_ops *fd_ops;
66 extern struct rtc_ops no_rtc_ops;
67 struct rtc_ops *rtc_ops;
69 #ifdef CONFIG_BLK_DEV_INITRD
70 extern unsigned long initrd_start;
71 extern unsigned long initrd_end;
72 int initrd_is_mapped = 0;
73 extern int initrd_below_start_ok;
77 void *dtb_start = __dtb_start;
80 unsigned char aux_device_present;
81 extern unsigned long loops_per_jiffy;
83 /* Command line specified as configuration option. */
85 static char __initdata command_line[COMMAND_LINE_SIZE];
87 #ifdef CONFIG_CMDLINE_BOOL
88 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
92 * Boot parameter parsing.
94 * The Xtensa port uses a list of variable-sized tags to pass data to
95 * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
96 * to be recognised. The list is terminated with a zero-sized
100 typedef struct tagtable {
102 int (*parse)(const bp_tag_t*);
105 #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
106 __attribute__((used, section(".taglist"))) = { tag, fn }
108 /* parse current tag */
110 static int __init parse_tag_mem(const bp_tag_t *tag)
112 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
114 if (mi->type != MEMORY_TYPE_CONVENTIONAL)
117 return add_sysmem_bank(mi->start, mi->end);
120 __tagtable(BP_TAG_MEMORY, parse_tag_mem);
122 #ifdef CONFIG_BLK_DEV_INITRD
124 static int __init parse_tag_initrd(const bp_tag_t* tag)
126 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
128 initrd_start = (unsigned long)__va(mi->start);
129 initrd_end = (unsigned long)__va(mi->end);
134 __tagtable(BP_TAG_INITRD, parse_tag_initrd);
138 static int __init parse_tag_fdt(const bp_tag_t *tag)
140 dtb_start = __va(tag->data[0]);
144 __tagtable(BP_TAG_FDT, parse_tag_fdt);
146 #endif /* CONFIG_OF */
148 #endif /* CONFIG_BLK_DEV_INITRD */
150 static int __init parse_tag_cmdline(const bp_tag_t* tag)
152 strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
156 __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
158 static int __init parse_bootparam(const bp_tag_t* tag)
160 extern tagtable_t __tagtable_begin, __tagtable_end;
163 /* Boot parameters must start with a BP_TAG_FIRST tag. */
165 if (tag->id != BP_TAG_FIRST) {
166 printk(KERN_WARNING "Invalid boot parameters!\n");
170 tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
172 /* Parse all tags. */
174 while (tag != NULL && tag->id != BP_TAG_LAST) {
175 for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
176 if (tag->id == t->tag) {
181 if (t == &__tagtable_end)
182 printk(KERN_WARNING "Ignoring tag "
183 "0x%08x\n", tag->id);
184 tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
191 bool __initdata dt_memory_scan = false;
193 #if !XCHAL_HAVE_PTP_MMU || XCHAL_HAVE_SPANNING_WAY
194 unsigned long xtensa_kio_paddr = XCHAL_KIO_DEFAULT_PADDR;
195 EXPORT_SYMBOL(xtensa_kio_paddr);
197 static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
198 int depth, void *data)
200 const __be32 *ranges;
206 if (!of_flat_dt_is_compatible(node, "simple-bus"))
209 ranges = of_get_flat_dt_prop(node, "ranges", &len);
215 xtensa_kio_paddr = of_read_ulong(ranges+1, 1);
216 /* round down to nearest 256MB boundary */
217 xtensa_kio_paddr &= 0xf0000000;
222 static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
223 int depth, void *data)
229 void __init early_init_dt_add_memory_arch(u64 base, u64 size)
235 add_sysmem_bank(base, base + size);
238 void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
240 return __alloc_bootmem(size, align, 0);
243 void __init early_init_devtree(void *params)
245 if (sysmem.nr_banks == 0)
246 dt_memory_scan = true;
248 early_init_dt_scan(params);
249 of_scan_flat_dt(xtensa_dt_io_area, NULL);
251 if (!command_line[0])
252 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
255 static int __init xtensa_device_probe(void)
258 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
262 device_initcall(xtensa_device_probe);
264 #endif /* CONFIG_OF */
267 * Initialize architecture. (Early stage)
270 void __init init_arch(bp_tag_t *bp_start)
272 /* Parse boot parameters */
275 parse_bootparam(bp_start);
278 early_init_devtree(dtb_start);
281 if (sysmem.nr_banks == 0) {
282 add_sysmem_bank(PLATFORM_DEFAULT_MEM_START,
283 PLATFORM_DEFAULT_MEM_START +
284 PLATFORM_DEFAULT_MEM_SIZE);
287 #ifdef CONFIG_CMDLINE_BOOL
288 if (!command_line[0])
289 strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
292 /* Early hook for platforms */
294 platform_init(bp_start);
296 /* Initialize MMU. */
302 * Initialize system. Setup memory and reserve regions.
307 extern char _WindowVectors_text_start;
308 extern char _WindowVectors_text_end;
309 extern char _DebugInterruptVector_literal_start;
310 extern char _DebugInterruptVector_text_end;
311 extern char _KernelExceptionVector_literal_start;
312 extern char _KernelExceptionVector_text_end;
313 extern char _UserExceptionVector_literal_start;
314 extern char _UserExceptionVector_text_end;
315 extern char _DoubleExceptionVector_literal_start;
316 extern char _DoubleExceptionVector_text_end;
317 #if XCHAL_EXCM_LEVEL >= 2
318 extern char _Level2InterruptVector_text_start;
319 extern char _Level2InterruptVector_text_end;
321 #if XCHAL_EXCM_LEVEL >= 3
322 extern char _Level3InterruptVector_text_start;
323 extern char _Level3InterruptVector_text_end;
325 #if XCHAL_EXCM_LEVEL >= 4
326 extern char _Level4InterruptVector_text_start;
327 extern char _Level4InterruptVector_text_end;
329 #if XCHAL_EXCM_LEVEL >= 5
330 extern char _Level5InterruptVector_text_start;
331 extern char _Level5InterruptVector_text_end;
333 #if XCHAL_EXCM_LEVEL >= 6
334 extern char _Level6InterruptVector_text_start;
335 extern char _Level6InterruptVector_text_end;
338 extern char _SecondaryResetVector_text_start;
339 extern char _SecondaryResetVector_text_end;
343 #ifdef CONFIG_S32C1I_SELFTEST
344 #if XCHAL_HAVE_S32C1I
346 static int __initdata rcw_word, rcw_probe_pc, rcw_exc;
349 * Basic atomic compare-and-swap, that records PC of S32C1I for probing.
351 * If *v == cmp, set *v = set. Return previous *v.
353 static inline int probed_compare_swap(int *v, int cmp, int set)
357 __asm__ __volatile__(
360 " wsr %2, scompare1\n"
361 "1: s32c1i %0, %3, 0\n"
362 : "=a" (set), "=&a" (tmp)
363 : "a" (cmp), "a" (v), "a" (&rcw_probe_pc), "0" (set)
369 /* Handle probed exception */
371 static void __init do_probed_exception(struct pt_regs *regs,
372 unsigned long exccause)
374 if (regs->pc == rcw_probe_pc) { /* exception on s32c1i ? */
375 regs->pc += 3; /* skip the s32c1i instruction */
378 do_unhandled(regs, exccause);
382 /* Simple test of S32C1I (soc bringup assist) */
384 static int __init check_s32c1i(void)
386 int n, cause1, cause2;
387 void *handbus, *handdata, *handaddr; /* temporarily saved handlers */
390 handbus = trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR,
391 do_probed_exception);
392 handdata = trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR,
393 do_probed_exception);
394 handaddr = trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR,
395 do_probed_exception);
397 /* First try an S32C1I that does not store: */
400 n = probed_compare_swap(&rcw_word, 0, 2);
403 /* took exception? */
405 /* unclean exception? */
406 if (n != 2 || rcw_word != 1)
407 panic("S32C1I exception error");
408 } else if (rcw_word != 1 || n != 1) {
409 panic("S32C1I compare error");
412 /* Then an S32C1I that stores: */
414 rcw_word = 0x1234567;
415 n = probed_compare_swap(&rcw_word, 0x1234567, 0xabcde);
419 /* unclean exception? */
420 if (n != 0xabcde || rcw_word != 0x1234567)
421 panic("S32C1I exception error (b)");
422 } else if (rcw_word != 0xabcde || n != 0x1234567) {
423 panic("S32C1I store error");
426 /* Verify consistency of exceptions: */
427 if (cause1 || cause2) {
428 pr_warn("S32C1I took exception %d, %d\n", cause1, cause2);
429 /* If emulation of S32C1I upon bus error gets implemented,
430 we can get rid of this panic for single core (not SMP) */
431 panic("S32C1I exceptions not currently supported");
433 if (cause1 != cause2)
434 panic("inconsistent S32C1I exceptions");
436 trap_set_handler(EXCCAUSE_LOAD_STORE_ERROR, handbus);
437 trap_set_handler(EXCCAUSE_LOAD_STORE_DATA_ERROR, handdata);
438 trap_set_handler(EXCCAUSE_LOAD_STORE_ADDR_ERROR, handaddr);
442 #else /* XCHAL_HAVE_S32C1I */
444 /* This condition should not occur with a commercially deployed processor.
445 Display reminder for early engr test or demo chips / FPGA bitstreams */
446 static int __init check_s32c1i(void)
448 pr_warn("Processor configuration lacks atomic compare-and-swap support!\n");
452 #endif /* XCHAL_HAVE_S32C1I */
453 early_initcall(check_s32c1i);
454 #endif /* CONFIG_S32C1I_SELFTEST */
457 void __init setup_arch(char **cmdline_p)
459 strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
460 *cmdline_p = command_line;
462 /* Reserve some memory regions */
464 #ifdef CONFIG_BLK_DEV_INITRD
465 if (initrd_start < initrd_end) {
466 initrd_is_mapped = mem_reserve(__pa(initrd_start),
467 __pa(initrd_end), 0) == 0;
468 initrd_below_start_ok = 1;
474 mem_reserve(__pa(&_stext),__pa(&_end), 1);
476 mem_reserve(__pa(&_WindowVectors_text_start),
477 __pa(&_WindowVectors_text_end), 0);
479 mem_reserve(__pa(&_DebugInterruptVector_literal_start),
480 __pa(&_DebugInterruptVector_text_end), 0);
482 mem_reserve(__pa(&_KernelExceptionVector_literal_start),
483 __pa(&_KernelExceptionVector_text_end), 0);
485 mem_reserve(__pa(&_UserExceptionVector_literal_start),
486 __pa(&_UserExceptionVector_text_end), 0);
488 mem_reserve(__pa(&_DoubleExceptionVector_literal_start),
489 __pa(&_DoubleExceptionVector_text_end), 0);
491 #if XCHAL_EXCM_LEVEL >= 2
492 mem_reserve(__pa(&_Level2InterruptVector_text_start),
493 __pa(&_Level2InterruptVector_text_end), 0);
495 #if XCHAL_EXCM_LEVEL >= 3
496 mem_reserve(__pa(&_Level3InterruptVector_text_start),
497 __pa(&_Level3InterruptVector_text_end), 0);
499 #if XCHAL_EXCM_LEVEL >= 4
500 mem_reserve(__pa(&_Level4InterruptVector_text_start),
501 __pa(&_Level4InterruptVector_text_end), 0);
503 #if XCHAL_EXCM_LEVEL >= 5
504 mem_reserve(__pa(&_Level5InterruptVector_text_start),
505 __pa(&_Level5InterruptVector_text_end), 0);
507 #if XCHAL_EXCM_LEVEL >= 6
508 mem_reserve(__pa(&_Level6InterruptVector_text_start),
509 __pa(&_Level6InterruptVector_text_end), 0);
513 mem_reserve(__pa(&_SecondaryResetVector_text_start),
514 __pa(&_SecondaryResetVector_text_end), 0);
519 unflatten_and_copy_device_tree();
521 platform_setup(cmdline_p);
531 # if defined(CONFIG_VGA_CONSOLE)
532 conswitchp = &vga_con;
533 # elif defined(CONFIG_DUMMY_CONSOLE)
534 conswitchp = &dummy_con;
539 platform_pcibios_init();
543 static DEFINE_PER_CPU(struct cpu, cpu_data);
545 static int __init topology_init(void)
549 for_each_possible_cpu(i) {
550 struct cpu *cpu = &per_cpu(cpu_data, i);
551 cpu->hotpluggable = !!i;
552 register_cpu(cpu, i);
557 subsys_initcall(topology_init);
559 void machine_restart(char * cmd)
564 void machine_halt(void)
570 void machine_power_off(void)
572 platform_power_off();
575 #ifdef CONFIG_PROC_FS
578 * Display some core information through /proc/cpuinfo.
582 c_show(struct seq_file *f, void *slot)
584 /* high-level stuff */
585 seq_printf(f, "CPU count\t: %u\n"
586 "CPU list\t: %*pbl\n"
587 "vendor_id\t: Tensilica\n"
588 "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
589 "core ID\t\t: " XCHAL_CORE_ID "\n"
592 "cpu MHz\t\t: %lu.%02lu\n"
593 "bogomips\t: %lu.%02lu\n",
595 cpumask_pr_args(cpu_online_mask),
596 XCHAL_BUILD_UNIQUE_ID,
597 XCHAL_HAVE_BE ? "big" : "little",
599 (ccount_freq/10000) % 100,
600 loops_per_jiffy/(500000/HZ),
601 (loops_per_jiffy/(5000/HZ)) % 100);
603 seq_printf(f,"flags\t\t: "
613 #if XCHAL_HAVE_DENSITY
616 #if XCHAL_HAVE_BOOLEANS
625 #if XCHAL_HAVE_MINMAX
631 #if XCHAL_HAVE_CLAMPS
643 #if XCHAL_HAVE_MUL32_HIGH
649 #if XCHAL_HAVE_S32C1I
655 seq_printf(f,"physical aregs\t: %d\n"
666 seq_printf(f,"num ints\t: %d\n"
670 "debug level\t: %d\n",
671 XCHAL_NUM_INTERRUPTS,
672 XCHAL_NUM_EXTINTERRUPTS,
678 seq_printf(f,"icache line size: %d\n"
679 "icache ways\t: %d\n"
680 "icache size\t: %d\n"
682 #if XCHAL_ICACHE_LINE_LOCKABLE
686 "dcache line size: %d\n"
687 "dcache ways\t: %d\n"
688 "dcache size\t: %d\n"
690 #if XCHAL_DCACHE_IS_WRITEBACK
693 #if XCHAL_DCACHE_LINE_LOCKABLE
697 XCHAL_ICACHE_LINESIZE,
700 XCHAL_DCACHE_LINESIZE,
708 * We show only CPU #0 info.
711 c_start(struct seq_file *f, loff_t *pos)
713 return (*pos == 0) ? (void *)1 : NULL;
717 c_next(struct seq_file *f, void *v, loff_t *pos)
723 c_stop(struct seq_file *f, void *v)
727 const struct seq_operations cpuinfo_op =
735 #endif /* CONFIG_PROC_FS */