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.
10 * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
12 * Chris Zankel <chris@zankel.net>
13 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
15 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
18 #include <linux/errno.h>
19 #include <linux/init.h>
21 #include <linux/proc_fs.h>
22 #include <linux/screen_info.h>
23 #include <linux/kernel.h>
24 #include <linux/percpu.h>
25 #include <linux/cpu.h>
27 #include <linux/of_fdt.h>
29 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
30 # include <linux/console.h>
34 # include <linux/seq_file.h>
37 #include <asm/bootparam.h>
38 #include <asm/kasan.h>
39 #include <asm/mmu_context.h>
40 #include <asm/processor.h>
41 #include <asm/timex.h>
42 #include <asm/platform.h>
44 #include <asm/setup.h>
45 #include <asm/param.h>
47 #include <asm/sysmem.h>
49 #if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
50 struct screen_info screen_info = {
53 .orig_video_cols = 80,
54 .orig_video_lines = 24,
55 .orig_video_isVGA = 1,
56 .orig_video_points = 16,
60 #ifdef CONFIG_BLK_DEV_INITRD
61 extern unsigned long initrd_start;
62 extern unsigned long initrd_end;
63 extern int initrd_below_start_ok;
67 void *dtb_start = __dtb_start;
70 extern unsigned long loops_per_jiffy;
72 /* Command line specified as configuration option. */
74 static char __initdata command_line[COMMAND_LINE_SIZE];
76 #ifdef CONFIG_CMDLINE_BOOL
77 static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
80 #ifdef CONFIG_PARSE_BOOTPARAM
82 * Boot parameter parsing.
84 * The Xtensa port uses a list of variable-sized tags to pass data to
85 * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
86 * to be recognised. The list is terminated with a zero-sized
90 typedef struct tagtable {
92 int (*parse)(const bp_tag_t*);
95 #define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
96 __section(".taglist") __attribute__((used)) = { tag, fn }
98 /* parse current tag */
100 static int __init parse_tag_mem(const bp_tag_t *tag)
102 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
104 if (mi->type != MEMORY_TYPE_CONVENTIONAL)
107 return memblock_add(mi->start, mi->end - mi->start);
110 __tagtable(BP_TAG_MEMORY, parse_tag_mem);
112 #ifdef CONFIG_BLK_DEV_INITRD
114 static int __init parse_tag_initrd(const bp_tag_t* tag)
116 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
118 initrd_start = (unsigned long)__va(mi->start);
119 initrd_end = (unsigned long)__va(mi->end);
124 __tagtable(BP_TAG_INITRD, parse_tag_initrd);
126 #endif /* CONFIG_BLK_DEV_INITRD */
130 static int __init parse_tag_fdt(const bp_tag_t *tag)
132 dtb_start = __va(tag->data[0]);
136 __tagtable(BP_TAG_FDT, parse_tag_fdt);
138 #endif /* CONFIG_OF */
140 static int __init parse_tag_cmdline(const bp_tag_t* tag)
142 strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
146 __tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
148 static int __init parse_bootparam(const bp_tag_t* tag)
150 extern tagtable_t __tagtable_begin, __tagtable_end;
153 /* Boot parameters must start with a BP_TAG_FIRST tag. */
155 if (tag->id != BP_TAG_FIRST) {
156 pr_warn("Invalid boot parameters!\n");
160 tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
162 /* Parse all tags. */
164 while (tag != NULL && tag->id != BP_TAG_LAST) {
165 for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
166 if (tag->id == t->tag) {
171 if (t == &__tagtable_end)
172 pr_warn("Ignoring tag 0x%08x\n", tag->id);
173 tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
179 static int __init parse_bootparam(const bp_tag_t *tag)
181 pr_info("Ignoring boot parameters at %p\n", tag);
188 #if !XCHAL_HAVE_PTP_MMU || XCHAL_HAVE_SPANNING_WAY
189 unsigned long xtensa_kio_paddr = XCHAL_KIO_DEFAULT_PADDR;
190 EXPORT_SYMBOL(xtensa_kio_paddr);
192 static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
193 int depth, void *data)
195 const __be32 *ranges;
201 if (!of_flat_dt_is_compatible(node, "simple-bus"))
204 ranges = of_get_flat_dt_prop(node, "ranges", &len);
210 xtensa_kio_paddr = of_read_ulong(ranges+1, 1);
211 /* round down to nearest 256MB boundary */
212 xtensa_kio_paddr &= 0xf0000000;
219 static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
220 int depth, void *data)
226 void __init early_init_devtree(void *params)
228 early_init_dt_scan(params);
229 of_scan_flat_dt(xtensa_dt_io_area, NULL);
231 if (!command_line[0])
232 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
235 #endif /* CONFIG_OF */
238 * Initialize architecture. (Early stage)
241 void __init init_arch(bp_tag_t *bp_start)
243 /* Initialize MMU. */
247 /* Initialize initial KASAN shadow map */
251 /* Parse boot parameters */
254 parse_bootparam(bp_start);
257 early_init_devtree(dtb_start);
260 #ifdef CONFIG_CMDLINE_BOOL
261 if (!command_line[0])
262 strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
265 /* Early hook for platforms */
267 platform_init(bp_start);
271 * Initialize system. Setup memory and reserve regions.
275 extern char _stext[];
276 extern char _WindowVectors_text_start;
277 extern char _WindowVectors_text_end;
278 extern char _DebugInterruptVector_text_start;
279 extern char _DebugInterruptVector_text_end;
280 extern char _KernelExceptionVector_text_start;
281 extern char _KernelExceptionVector_text_end;
282 extern char _UserExceptionVector_text_start;
283 extern char _UserExceptionVector_text_end;
284 extern char _DoubleExceptionVector_text_start;
285 extern char _DoubleExceptionVector_text_end;
286 extern char _exception_text_start;
287 extern char _exception_text_end;
288 #if XCHAL_EXCM_LEVEL >= 2
289 extern char _Level2InterruptVector_text_start;
290 extern char _Level2InterruptVector_text_end;
292 #if XCHAL_EXCM_LEVEL >= 3
293 extern char _Level3InterruptVector_text_start;
294 extern char _Level3InterruptVector_text_end;
296 #if XCHAL_EXCM_LEVEL >= 4
297 extern char _Level4InterruptVector_text_start;
298 extern char _Level4InterruptVector_text_end;
300 #if XCHAL_EXCM_LEVEL >= 5
301 extern char _Level5InterruptVector_text_start;
302 extern char _Level5InterruptVector_text_end;
304 #if XCHAL_EXCM_LEVEL >= 6
305 extern char _Level6InterruptVector_text_start;
306 extern char _Level6InterruptVector_text_end;
309 extern char _SecondaryResetVector_text_start;
310 extern char _SecondaryResetVector_text_end;
312 #ifdef CONFIG_XIP_KERNEL
313 extern char _xip_start[];
314 extern char _xip_end[];
317 static inline int __init_memblock mem_reserve(unsigned long start,
320 return memblock_reserve(start, end - start);
323 void __init setup_arch(char **cmdline_p)
325 pr_info("config ID: %08x:%08x\n",
326 xtensa_get_sr(SREG_EPC), xtensa_get_sr(SREG_EXCSAVE));
327 if (xtensa_get_sr(SREG_EPC) != XCHAL_HW_CONFIGID0 ||
328 xtensa_get_sr(SREG_EXCSAVE) != XCHAL_HW_CONFIGID1)
329 pr_info("built for config ID: %08x:%08x\n",
330 XCHAL_HW_CONFIGID0, XCHAL_HW_CONFIGID1);
332 *cmdline_p = command_line;
333 platform_setup(cmdline_p);
334 strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
336 /* Reserve some memory regions */
338 #ifdef CONFIG_BLK_DEV_INITRD
339 if (initrd_start < initrd_end &&
340 !mem_reserve(__pa(initrd_start), __pa(initrd_end)))
341 initrd_below_start_ok = 1;
346 mem_reserve(__pa(_stext), __pa(_end));
347 #ifdef CONFIG_XIP_KERNEL
348 mem_reserve(__pa(_xip_start), __pa(_xip_end));
351 #ifdef CONFIG_VECTORS_ADDR
352 mem_reserve(__pa(&_WindowVectors_text_start),
353 __pa(&_WindowVectors_text_end));
355 mem_reserve(__pa(&_DebugInterruptVector_text_start),
356 __pa(&_DebugInterruptVector_text_end));
358 mem_reserve(__pa(&_KernelExceptionVector_text_start),
359 __pa(&_KernelExceptionVector_text_end));
361 mem_reserve(__pa(&_UserExceptionVector_text_start),
362 __pa(&_UserExceptionVector_text_end));
364 mem_reserve(__pa(&_DoubleExceptionVector_text_start),
365 __pa(&_DoubleExceptionVector_text_end));
367 mem_reserve(__pa(&_exception_text_start),
368 __pa(&_exception_text_end));
369 #if XCHAL_EXCM_LEVEL >= 2
370 mem_reserve(__pa(&_Level2InterruptVector_text_start),
371 __pa(&_Level2InterruptVector_text_end));
373 #if XCHAL_EXCM_LEVEL >= 3
374 mem_reserve(__pa(&_Level3InterruptVector_text_start),
375 __pa(&_Level3InterruptVector_text_end));
377 #if XCHAL_EXCM_LEVEL >= 4
378 mem_reserve(__pa(&_Level4InterruptVector_text_start),
379 __pa(&_Level4InterruptVector_text_end));
381 #if XCHAL_EXCM_LEVEL >= 5
382 mem_reserve(__pa(&_Level5InterruptVector_text_start),
383 __pa(&_Level5InterruptVector_text_end));
385 #if XCHAL_EXCM_LEVEL >= 6
386 mem_reserve(__pa(&_Level6InterruptVector_text_start),
387 __pa(&_Level6InterruptVector_text_end));
390 #endif /* CONFIG_VECTORS_ADDR */
393 mem_reserve(__pa(&_SecondaryResetVector_text_start),
394 __pa(&_SecondaryResetVector_text_end));
399 unflatten_and_copy_device_tree();
409 # if defined(CONFIG_VGA_CONSOLE)
410 conswitchp = &vga_con;
415 static DEFINE_PER_CPU(struct cpu, cpu_data);
417 static int __init topology_init(void)
421 for_each_possible_cpu(i) {
422 struct cpu *cpu = &per_cpu(cpu_data, i);
423 cpu->hotpluggable = !!i;
424 register_cpu(cpu, i);
429 subsys_initcall(topology_init);
433 #if XCHAL_HAVE_PTP_MMU && IS_ENABLED(CONFIG_MMU)
436 * We have full MMU: all autoload ways, ways 7, 8 and 9 of DTLB must
438 * Way 4 is not currently used by linux.
439 * Ways 5 and 6 shall not be touched on MMUv2 as they are hardwired.
440 * Way 5 shall be flushed and way 6 shall be set to identity mapping
443 local_flush_tlb_all();
444 invalidate_page_directory();
445 #if XCHAL_HAVE_SPANNING_WAY
448 unsigned long vaddr = (unsigned long)cpu_reset;
449 unsigned long paddr = __pa(vaddr);
450 unsigned long tmpaddr = vaddr + SZ_512M;
451 unsigned long tmp0, tmp1, tmp2, tmp3;
454 * Find a place for the temporary mapping. It must not be
455 * in the same 512MB region with vaddr or paddr, otherwise
456 * there may be multihit exception either on entry to the
457 * temporary mapping, or on entry to the identity mapping.
458 * (512MB is the biggest page size supported by TLB.)
460 while (((tmpaddr ^ paddr) & -SZ_512M) == 0)
463 /* Invalidate mapping in the selected temporary area */
464 if (itlb_probe(tmpaddr) & BIT(ITLB_HIT_BIT))
465 invalidate_itlb_entry(itlb_probe(tmpaddr));
466 if (itlb_probe(tmpaddr + PAGE_SIZE) & BIT(ITLB_HIT_BIT))
467 invalidate_itlb_entry(itlb_probe(tmpaddr + PAGE_SIZE));
470 * Map two consecutive pages starting at the physical address
471 * of this function to the temporary mapping area.
473 write_itlb_entry(__pte((paddr & PAGE_MASK) |
477 tmpaddr & PAGE_MASK);
478 write_itlb_entry(__pte(((paddr & PAGE_MASK) + PAGE_SIZE) |
482 (tmpaddr & PAGE_MASK) + PAGE_SIZE);
484 /* Reinitialize TLB */
485 __asm__ __volatile__ ("movi %0, 1f\n\t"
491 * No literal, data or stack access
495 /* Initialize *tlbcfg */
497 "wsr %0, itlbcfg\n\t"
498 "wsr %0, dtlbcfg\n\t"
499 /* Invalidate TLB way 5 */
506 "addi %0, %0, -1\n\t"
508 /* Initialize TLB way 6 */
517 "addi %0, %0, -1\n\t"
520 /* Jump to identity mapping */
523 /* Complete way 6 initialization */
526 /* Invalidate temporary mapping */
531 : "=&a"(tmp0), "=&a"(tmp1), "=&a"(tmp2),
533 : "a"(tmpaddr - vaddr),
535 "a"(SZ_128M), "a"(SZ_512M),
537 "a"((tmpaddr + SZ_512M) & PAGE_MASK)
542 __asm__ __volatile__ ("movi a2, 0\n\t"
543 "wsr a2, icountlevel\n\t"
546 #if XCHAL_NUM_IBREAK > 0
547 "wsr a2, ibreakenable\n\t"
557 : "a" (XCHAL_RESET_VECTOR_VADDR)
563 void machine_restart(char * cmd)
568 void machine_halt(void)
574 void machine_power_off(void)
576 platform_power_off();
579 #ifdef CONFIG_PROC_FS
582 * Display some core information through /proc/cpuinfo.
586 c_show(struct seq_file *f, void *slot)
588 /* high-level stuff */
589 seq_printf(f, "CPU count\t: %u\n"
590 "CPU list\t: %*pbl\n"
591 "vendor_id\t: Tensilica\n"
592 "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
593 "core ID\t\t: " XCHAL_CORE_ID "\n"
595 "config ID\t: %08x:%08x\n"
597 "cpu MHz\t\t: %lu.%02lu\n"
598 "bogomips\t: %lu.%02lu\n",
600 cpumask_pr_args(cpu_online_mask),
601 XCHAL_BUILD_UNIQUE_ID,
602 xtensa_get_sr(SREG_EPC), xtensa_get_sr(SREG_EXCSAVE),
603 XCHAL_HAVE_BE ? "big" : "little",
605 (ccount_freq/10000) % 100,
606 loops_per_jiffy/(500000/HZ),
607 (loops_per_jiffy/(5000/HZ)) % 100);
608 seq_puts(f, "flags\t\t: "
618 #if XCHAL_HAVE_DENSITY
621 #if XCHAL_HAVE_BOOLEANS
630 #if XCHAL_HAVE_MINMAX
636 #if XCHAL_HAVE_CLAMPS
648 #if XCHAL_HAVE_MUL32_HIGH
654 #if XCHAL_HAVE_S32C1I
657 #if XCHAL_HAVE_EXCLUSIVE
663 seq_printf(f,"physical aregs\t: %d\n"
674 seq_printf(f,"num ints\t: %d\n"
678 "debug level\t: %d\n",
679 XCHAL_NUM_INTERRUPTS,
680 XCHAL_NUM_EXTINTERRUPTS,
686 seq_printf(f,"icache line size: %d\n"
687 "icache ways\t: %d\n"
688 "icache size\t: %d\n"
690 #if XCHAL_ICACHE_LINE_LOCKABLE
694 "dcache line size: %d\n"
695 "dcache ways\t: %d\n"
696 "dcache size\t: %d\n"
698 #if XCHAL_DCACHE_IS_WRITEBACK
701 #if XCHAL_DCACHE_LINE_LOCKABLE
705 XCHAL_ICACHE_LINESIZE,
708 XCHAL_DCACHE_LINESIZE,
716 * We show only CPU #0 info.
719 c_start(struct seq_file *f, loff_t *pos)
721 return (*pos == 0) ? (void *)1 : NULL;
725 c_next(struct seq_file *f, void *v, loff_t *pos)
728 return c_start(f, pos);
732 c_stop(struct seq_file *f, void *v)
736 const struct seq_operations cpuinfo_op =
744 #endif /* CONFIG_PROC_FS */