ARC: DWARF2 .debug_frame based stack unwinder
[firefly-linux-kernel-4.4.55.git] / arch / arc / kernel / setup.c
1 /*
2  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/seq_file.h>
10 #include <linux/fs.h>
11 #include <linux/delay.h>
12 #include <linux/root_dev.h>
13 #include <linux/console.h>
14 #include <linux/module.h>
15 #include <linux/cpu.h>
16 #include <linux/of_fdt.h>
17 #include <asm/sections.h>
18 #include <asm/arcregs.h>
19 #include <asm/tlb.h>
20 #include <asm/cache.h>
21 #include <asm/setup.h>
22 #include <asm/page.h>
23 #include <asm/irq.h>
24 #include <asm/arcregs.h>
25 #include <asm/prom.h>
26 #include <asm/unwind.h>
27
28 #define FIX_PTR(x)  __asm__ __volatile__(";" : "+r"(x))
29
30 int running_on_hw = 1;  /* vs. on ISS */
31
32 char __initdata command_line[COMMAND_LINE_SIZE];
33
34 struct task_struct *_current_task[NR_CPUS];     /* For stack switching */
35
36 struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
37
38 void __init read_arc_build_cfg_regs(void)
39 {
40         read_decode_mmu_bcr();
41         read_decode_cache_bcr();
42 }
43
44 /*
45  * Initialize and setup the processor core
46  * This is called by all the CPUs thus should not do special case stuff
47  *    such as only for boot CPU etc
48  */
49
50 void __init setup_processor(void)
51 {
52         read_arc_build_cfg_regs();
53         arc_init_IRQ();
54         arc_mmu_init();
55         arc_cache_init();
56 }
57
58 void __init __attribute__((weak)) arc_platform_early_init(void)
59 {
60 }
61
62 void __init setup_arch(char **cmdline_p)
63 {
64         int rc;
65
66 #ifdef CONFIG_CMDLINE_UBOOT
67         /* Make sure that a whitespace is inserted before */
68         strlcat(command_line, " ", sizeof(command_line));
69 #endif
70         /*
71          * Append .config cmdline to base command line, which might already
72          * contain u-boot "bootargs" (handled by head.S, if so configured)
73          */
74         strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line));
75
76         /* Save unparsed command line copy for /proc/cmdline */
77         strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
78         *cmdline_p = command_line;
79
80         rc = setup_machine_fdt(__dtb_start);
81
82         /* To force early parsing of things like mem=xxx */
83         parse_early_param();
84
85         /* Platform/board specific: e.g. early console registration */
86         arc_platform_early_init();
87
88         setup_processor();
89
90 #ifdef CONFIG_SMP
91         smp_init_cpus();
92 #endif
93
94         setup_arch_memory();
95
96         unflatten_device_tree();
97
98         /* Can be issue if someone passes cmd line arg "ro"
99          * But that is unlikely so keeping it as it is
100          */
101         root_mountflags &= ~MS_RDONLY;
102
103         console_verbose();
104
105 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
106         conswitchp = &dummy_con;
107 #endif
108
109         arc_unwind_init();
110         arc_unwind_setup();
111 }
112
113 /*
114  *  Get CPU information for use by the procfs.
115  */
116
117 #define cpu_to_ptr(c)   ((void *)(0xFFFF0000 | (unsigned int)(c)))
118 #define ptr_to_cpu(p)   (~0xFFFF0000UL & (unsigned int)(p))
119
120 static int show_cpuinfo(struct seq_file *m, void *v)
121 {
122         char *str;
123         int cpu_id = ptr_to_cpu(v);
124
125         str = (char *)__get_free_page(GFP_TEMPORARY);
126         if (!str)
127                 goto done;
128
129         seq_printf(m, "ARC700 #%d\n", cpu_id);
130
131         seq_printf(m, "Bogo MIPS : \t%lu.%02lu\n",
132                    loops_per_jiffy / (500000 / HZ),
133                    (loops_per_jiffy / (5000 / HZ)) % 100);
134
135         free_page((unsigned long)str);
136 done:
137         seq_printf(m, "\n\n");
138
139         return 0;
140 }
141
142 static void *c_start(struct seq_file *m, loff_t *pos)
143 {
144         /*
145          * Callback returns cpu-id to iterator for show routine, NULL to stop.
146          * However since NULL is also a valid cpu-id (0), we use a round-about
147          * way to pass it w/o having to kmalloc/free a 2 byte string.
148          * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
149          */
150         return *pos < num_possible_cpus() ? cpu_to_ptr(*pos) : NULL;
151 }
152
153 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
154 {
155         ++*pos;
156         return c_start(m, pos);
157 }
158
159 static void c_stop(struct seq_file *m, void *v)
160 {
161 }
162
163 const struct seq_operations cpuinfo_op = {
164         .start  = c_start,
165         .next   = c_next,
166         .stop   = c_stop,
167         .show   = show_cpuinfo
168 };
169
170 static DEFINE_PER_CPU(struct cpu, cpu_topology);
171
172 static int __init topology_init(void)
173 {
174         int cpu;
175
176         for_each_present_cpu(cpu)
177             register_cpu(&per_cpu(cpu_topology, cpu), cpu);
178
179         return 0;
180 }
181
182 subsys_initcall(topology_init);