blob: 5cb8a62e091c77619081973fe488b04a79437dd7 [file] [log] [blame]
Chris Zankel5a0015d2005-06-23 22:01:16 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * arch/xtensa/kernel/setup.c
Chris Zankel5a0015d2005-06-23 22:01:16 -07003 *
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
6 * for more details.
7 *
8 * Copyright (C) 1995 Linus Torvalds
9 * Copyright (C) 2001 - 2005 Tensilica Inc.
Max Filippov0e46c112016-04-25 22:08:20 +030010 * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
Chris Zankel5a0015d2005-06-23 22:01:16 -070011 *
12 * Chris Zankel <chris@zankel.net>
13 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
14 * Kevin Chea
15 * Marc Gauthier<marc@tensilica.com> <marc@alumni.uwaterloo.ca>
16 */
17
Chris Zankel5a0015d2005-06-23 22:01:16 -070018#include <linux/errno.h>
19#include <linux/init.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070020#include <linux/mm.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070021#include <linux/proc_fs.h>
Jon Smirl894673e2006-07-10 04:44:13 -070022#include <linux/screen_info.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070023#include <linux/kernel.h>
Max Filippovf6151362013-10-17 02:42:26 +040024#include <linux/percpu.h>
25#include <linux/cpu.h>
Guenter Roeckd02014b2016-07-23 17:24:55 -070026#include <linux/of.h>
Max Filippovda844a82012-11-04 00:30:13 +040027#include <linux/of_fdt.h>
Max Filippovda844a82012-11-04 00:30:13 +040028
Chris Zankel5a0015d2005-06-23 22:01:16 -070029#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
30# include <linux/console.h>
31#endif
32
Chris Zankel5a0015d2005-06-23 22:01:16 -070033#ifdef CONFIG_PROC_FS
34# include <linux/seq_file.h>
35#endif
36
Chris Zankel5a0015d2005-06-23 22:01:16 -070037#include <asm/bootparam.h>
Max Filippovc6335442017-12-03 13:28:52 -080038#include <asm/kasan.h>
Max Filippovc8f3a7d2013-10-17 02:42:21 +040039#include <asm/mmu_context.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070040#include <asm/pgtable.h>
41#include <asm/processor.h>
42#include <asm/timex.h>
43#include <asm/platform.h>
44#include <asm/page.h>
45#include <asm/setup.h>
Chris Zankelde4f6e52007-05-31 17:47:01 -070046#include <asm/param.h>
Max Filippovf6151362013-10-17 02:42:26 +040047#include <asm/smp.h>
Max Filippov9ba067f2014-03-23 03:17:43 +040048#include <asm/sysmem.h>
Chris Zankel5a0015d2005-06-23 22:01:16 -070049
Chris Zankel5a0015d2005-06-23 22:01:16 -070050#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
Max Filippov03eae3a2016-11-15 18:08:07 -080051struct screen_info screen_info = {
52 .orig_x = 0,
53 .orig_y = 24,
54 .orig_video_cols = 80,
55 .orig_video_lines = 24,
56 .orig_video_isVGA = 1,
57 .orig_video_points = 16,
58};
Chris Zankel5a0015d2005-06-23 22:01:16 -070059#endif
60
Chris Zankel5a0015d2005-06-23 22:01:16 -070061#ifdef CONFIG_BLK_DEV_INITRD
Rob Herring29eb45a2013-08-30 17:06:53 -050062extern unsigned long initrd_start;
63extern unsigned long initrd_end;
Chris Zankel5a0015d2005-06-23 22:01:16 -070064int initrd_is_mapped = 0;
65extern int initrd_below_start_ok;
66#endif
67
Max Filippovda844a82012-11-04 00:30:13 +040068#ifdef CONFIG_OF
Max Filippovda844a82012-11-04 00:30:13 +040069void *dtb_start = __dtb_start;
70#endif
71
Chris Zankel5a0015d2005-06-23 22:01:16 -070072extern unsigned long loops_per_jiffy;
73
74/* Command line specified as configuration option. */
75
Alon Bar-Levd3e9cce2007-02-12 00:54:25 -080076static char __initdata command_line[COMMAND_LINE_SIZE];
Chris Zankel5a0015d2005-06-23 22:01:16 -070077
78#ifdef CONFIG_CMDLINE_BOOL
79static char default_command_line[COMMAND_LINE_SIZE] __initdata = CONFIG_CMDLINE;
80#endif
81
Max Filippovbaac1d362018-08-13 18:56:37 -070082#ifdef CONFIG_PARSE_BOOTPARAM
Chris Zankel5a0015d2005-06-23 22:01:16 -070083/*
84 * Boot parameter parsing.
85 *
86 * The Xtensa port uses a list of variable-sized tags to pass data to
87 * the kernel. The first tag must be a BP_TAG_FIRST tag for the list
88 * to be recognised. The list is terminated with a zero-sized
89 * BP_TAG_LAST tag.
90 */
91
92typedef struct tagtable {
93 u32 tag;
94 int (*parse)(const bp_tag_t*);
95} tagtable_t;
96
97#define __tagtable(tag, fn) static tagtable_t __tagtable_##fn \
Max Filippovf4349b62012-10-15 03:55:37 +040098 __attribute__((used, section(".taglist"))) = { tag, fn }
Chris Zankel5a0015d2005-06-23 22:01:16 -070099
100/* parse current tag */
101
102static int __init parse_tag_mem(const bp_tag_t *tag)
103{
Max Filippov9ba067f2014-03-23 03:17:43 +0400104 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700105
106 if (mi->type != MEMORY_TYPE_CONVENTIONAL)
107 return -1;
108
Max Filippov0e46c112016-04-25 22:08:20 +0300109 return memblock_add(mi->start, mi->end - mi->start);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700110}
111
112__tagtable(BP_TAG_MEMORY, parse_tag_mem);
113
114#ifdef CONFIG_BLK_DEV_INITRD
115
116static int __init parse_tag_initrd(const bp_tag_t* tag)
117{
Max Filippov9ba067f2014-03-23 03:17:43 +0400118 struct bp_meminfo *mi = (struct bp_meminfo *)(tag->data);
119
Rob Herring29eb45a2013-08-30 17:06:53 -0500120 initrd_start = (unsigned long)__va(mi->start);
121 initrd_end = (unsigned long)__va(mi->end);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700122
123 return 0;
124}
125
126__tagtable(BP_TAG_INITRD, parse_tag_initrd);
127
Max Filippov4ab18702017-01-03 09:37:34 -0800128#endif /* CONFIG_BLK_DEV_INITRD */
129
Max Filippovda844a82012-11-04 00:30:13 +0400130#ifdef CONFIG_OF
131
132static int __init parse_tag_fdt(const bp_tag_t *tag)
133{
Max Filippovc5a771d2013-06-09 04:52:11 +0400134 dtb_start = __va(tag->data[0]);
Max Filippovda844a82012-11-04 00:30:13 +0400135 return 0;
136}
137
138__tagtable(BP_TAG_FDT, parse_tag_fdt);
139
Max Filippovda844a82012-11-04 00:30:13 +0400140#endif /* CONFIG_OF */
141
Chris Zankel5a0015d2005-06-23 22:01:16 -0700142static int __init parse_tag_cmdline(const bp_tag_t* tag)
143{
Max Filippovda844a82012-11-04 00:30:13 +0400144 strlcpy(command_line, (char *)(tag->data), COMMAND_LINE_SIZE);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700145 return 0;
146}
147
148__tagtable(BP_TAG_COMMAND_LINE, parse_tag_cmdline);
149
150static int __init parse_bootparam(const bp_tag_t* tag)
151{
152 extern tagtable_t __tagtable_begin, __tagtable_end;
153 tagtable_t *t;
154
155 /* Boot parameters must start with a BP_TAG_FIRST tag. */
156
157 if (tag->id != BP_TAG_FIRST) {
Max Filippovc130d3b2017-12-15 12:00:30 -0800158 pr_warn("Invalid boot parameters!\n");
Chris Zankel5a0015d2005-06-23 22:01:16 -0700159 return 0;
160 }
161
162 tag = (bp_tag_t*)((unsigned long)tag + sizeof(bp_tag_t) + tag->size);
163
164 /* Parse all tags. */
165
166 while (tag != NULL && tag->id != BP_TAG_LAST) {
Max Filippovc130d3b2017-12-15 12:00:30 -0800167 for (t = &__tagtable_begin; t < &__tagtable_end; t++) {
Chris Zankel5a0015d2005-06-23 22:01:16 -0700168 if (tag->id == t->tag) {
169 t->parse(tag);
170 break;
171 }
172 }
173 if (t == &__tagtable_end)
Max Filippovc130d3b2017-12-15 12:00:30 -0800174 pr_warn("Ignoring tag 0x%08x\n", tag->id);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700175 tag = (bp_tag_t*)((unsigned long)(tag + 1) + tag->size);
176 }
177
178 return 0;
179}
Max Filippovbaac1d362018-08-13 18:56:37 -0700180#else
181static int __init parse_bootparam(const bp_tag_t *tag)
182{
183 pr_info("Ignoring boot parameters at %p\n", tag);
184 return 0;
185}
186#endif
Chris Zankel5a0015d2005-06-23 22:01:16 -0700187
Max Filippovda844a82012-11-04 00:30:13 +0400188#ifdef CONFIG_OF
189
Max Filippov260c64b2015-09-24 23:36:45 +0300190#if !XCHAL_HAVE_PTP_MMU || XCHAL_HAVE_SPANNING_WAY
Baruch Siach6cb971112013-12-29 11:03:30 +0200191unsigned long xtensa_kio_paddr = XCHAL_KIO_DEFAULT_PADDR;
192EXPORT_SYMBOL(xtensa_kio_paddr);
193
194static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
195 int depth, void *data)
196{
197 const __be32 *ranges;
Rob Herring9d0c4df2014-04-01 23:49:03 -0500198 int len;
Baruch Siach6cb971112013-12-29 11:03:30 +0200199
200 if (depth > 1)
201 return 0;
202
203 if (!of_flat_dt_is_compatible(node, "simple-bus"))
204 return 0;
205
206 ranges = of_get_flat_dt_prop(node, "ranges", &len);
207 if (!ranges)
208 return 1;
209 if (len == 0)
210 return 1;
211
212 xtensa_kio_paddr = of_read_ulong(ranges+1, 1);
213 /* round down to nearest 256MB boundary */
214 xtensa_kio_paddr &= 0xf0000000;
215
Max Filippovc2edb352017-12-15 20:45:35 -0800216 init_kio();
217
Baruch Siach6cb971112013-12-29 11:03:30 +0200218 return 1;
219}
220#else
221static int __init xtensa_dt_io_area(unsigned long node, const char *uname,
222 int depth, void *data)
223{
224 return 1;
225}
226#endif
227
Max Filippovda844a82012-11-04 00:30:13 +0400228void __init early_init_devtree(void *params)
229{
Rob Herring7745fc12013-08-28 10:05:10 -0500230 early_init_dt_scan(params);
Baruch Siach6cb971112013-12-29 11:03:30 +0200231 of_scan_flat_dt(xtensa_dt_io_area, NULL);
Rob Herring7745fc12013-08-28 10:05:10 -0500232
233 if (!command_line[0])
234 strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
Max Filippovda844a82012-11-04 00:30:13 +0400235}
236
Max Filippovda844a82012-11-04 00:30:13 +0400237#endif /* CONFIG_OF */
238
Chris Zankel5a0015d2005-06-23 22:01:16 -0700239/*
240 * Initialize architecture. (Early stage)
241 */
242
243void __init init_arch(bp_tag_t *bp_start)
244{
Max Filippovc2edb352017-12-15 20:45:35 -0800245 /* Initialize MMU. */
246
247 init_mmu();
248
Max Filippovc6335442017-12-03 13:28:52 -0800249 /* Initialize initial KASAN shadow map */
250
251 kasan_early_init();
252
Chris Zankel5a0015d2005-06-23 22:01:16 -0700253 /* Parse boot parameters */
254
Chris Zankelc4c45942012-11-28 16:53:51 -0800255 if (bp_start)
Max Filippovda844a82012-11-04 00:30:13 +0400256 parse_bootparam(bp_start);
257
258#ifdef CONFIG_OF
259 early_init_devtree(dtb_start);
260#endif
Chris Zankel5a0015d2005-06-23 22:01:16 -0700261
Max Filippovda844a82012-11-04 00:30:13 +0400262#ifdef CONFIG_CMDLINE_BOOL
263 if (!command_line[0])
264 strlcpy(command_line, default_command_line, COMMAND_LINE_SIZE);
265#endif
266
Chris Zankel5a0015d2005-06-23 22:01:16 -0700267 /* Early hook for platforms */
268
269 platform_init(bp_start);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700270}
271
272/*
273 * Initialize system. Setup memory and reserve regions.
274 */
275
Masami Hiramatsu18244362017-08-03 11:36:09 +0900276extern char _end[];
277extern char _stext[];
Chris Zankel5a0015d2005-06-23 22:01:16 -0700278extern char _WindowVectors_text_start;
279extern char _WindowVectors_text_end;
Max Filippovf8f02ca2017-12-03 20:55:35 -0800280extern char _DebugInterruptVector_text_start;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700281extern char _DebugInterruptVector_text_end;
Max Filippovf8f02ca2017-12-03 20:55:35 -0800282extern char _KernelExceptionVector_text_start;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700283extern char _KernelExceptionVector_text_end;
Max Filippovf8f02ca2017-12-03 20:55:35 -0800284extern char _UserExceptionVector_text_start;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700285extern char _UserExceptionVector_text_end;
Max Filippovf8f02ca2017-12-03 20:55:35 -0800286extern char _DoubleExceptionVector_text_start;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700287extern char _DoubleExceptionVector_text_end;
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400288#if XCHAL_EXCM_LEVEL >= 2
289extern char _Level2InterruptVector_text_start;
290extern char _Level2InterruptVector_text_end;
291#endif
292#if XCHAL_EXCM_LEVEL >= 3
293extern char _Level3InterruptVector_text_start;
294extern char _Level3InterruptVector_text_end;
295#endif
296#if XCHAL_EXCM_LEVEL >= 4
297extern char _Level4InterruptVector_text_start;
298extern char _Level4InterruptVector_text_end;
299#endif
300#if XCHAL_EXCM_LEVEL >= 5
301extern char _Level5InterruptVector_text_start;
302extern char _Level5InterruptVector_text_end;
303#endif
304#if XCHAL_EXCM_LEVEL >= 6
305extern char _Level6InterruptVector_text_start;
306extern char _Level6InterruptVector_text_end;
307#endif
Max Filippovab45fb12015-10-16 17:01:04 +0300308#ifdef CONFIG_SMP
309extern char _SecondaryResetVector_text_start;
310extern char _SecondaryResetVector_text_end;
311#endif
Chris Zankel5a0015d2005-06-23 22:01:16 -0700312
Guenter Roeckadefd052019-05-30 05:41:38 -0700313static inline int __init_memblock mem_reserve(unsigned long start,
314 unsigned long end)
Max Filippov0e46c112016-04-25 22:08:20 +0300315{
316 return memblock_reserve(start, end - start);
317}
Max Filippov00273122012-11-28 11:33:02 +0400318
Chris Zankel5a0015d2005-06-23 22:01:16 -0700319void __init setup_arch(char **cmdline_p)
320{
Max Filippovaa6476f2017-08-08 14:06:14 -0700321 pr_info("config ID: %08x:%08x\n",
Max Filippovcad6fad2018-11-27 16:27:47 -0800322 xtensa_get_sr(SREG_EPC), xtensa_get_sr(SREG_EXCSAVE));
323 if (xtensa_get_sr(SREG_EPC) != XCHAL_HW_CONFIGID0 ||
324 xtensa_get_sr(SREG_EXCSAVE) != XCHAL_HW_CONFIGID1)
Max Filippovaa6476f2017-08-08 14:06:14 -0700325 pr_info("built for config ID: %08x:%08x\n",
326 XCHAL_HW_CONFIGID0, XCHAL_HW_CONFIGID1);
327
Chris Zankel5a0015d2005-06-23 22:01:16 -0700328 *cmdline_p = command_line;
Max Filippovfbe22d22017-03-13 10:34:36 -0700329 platform_setup(cmdline_p);
330 strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE);
Chris Zankel5a0015d2005-06-23 22:01:16 -0700331
332 /* Reserve some memory regions */
333
334#ifdef CONFIG_BLK_DEV_INITRD
335 if (initrd_start < initrd_end) {
336 initrd_is_mapped = mem_reserve(__pa(initrd_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300337 __pa(initrd_end)) == 0;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700338 initrd_below_start_ok = 1;
Chris Zankelc4c45942012-11-28 16:53:51 -0800339 } else {
Chris Zankel5a0015d2005-06-23 22:01:16 -0700340 initrd_start = 0;
341 }
342#endif
343
Masami Hiramatsu18244362017-08-03 11:36:09 +0900344 mem_reserve(__pa(_stext), __pa(_end));
Chris Zankel5a0015d2005-06-23 22:01:16 -0700345
Max Filippovb46dcfa2017-01-04 10:40:49 -0800346#ifdef CONFIG_VECTORS_OFFSET
Chris Zankel5a0015d2005-06-23 22:01:16 -0700347 mem_reserve(__pa(&_WindowVectors_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300348 __pa(&_WindowVectors_text_end));
Chris Zankel5a0015d2005-06-23 22:01:16 -0700349
Max Filippovf8f02ca2017-12-03 20:55:35 -0800350 mem_reserve(__pa(&_DebugInterruptVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300351 __pa(&_DebugInterruptVector_text_end));
Chris Zankel5a0015d2005-06-23 22:01:16 -0700352
Max Filippovf8f02ca2017-12-03 20:55:35 -0800353 mem_reserve(__pa(&_KernelExceptionVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300354 __pa(&_KernelExceptionVector_text_end));
Chris Zankel5a0015d2005-06-23 22:01:16 -0700355
Max Filippovf8f02ca2017-12-03 20:55:35 -0800356 mem_reserve(__pa(&_UserExceptionVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300357 __pa(&_UserExceptionVector_text_end));
Chris Zankel5a0015d2005-06-23 22:01:16 -0700358
Max Filippovf8f02ca2017-12-03 20:55:35 -0800359 mem_reserve(__pa(&_DoubleExceptionVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300360 __pa(&_DoubleExceptionVector_text_end));
Chris Zankel5a0015d2005-06-23 22:01:16 -0700361
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400362#if XCHAL_EXCM_LEVEL >= 2
363 mem_reserve(__pa(&_Level2InterruptVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300364 __pa(&_Level2InterruptVector_text_end));
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400365#endif
366#if XCHAL_EXCM_LEVEL >= 3
367 mem_reserve(__pa(&_Level3InterruptVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300368 __pa(&_Level3InterruptVector_text_end));
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400369#endif
370#if XCHAL_EXCM_LEVEL >= 4
371 mem_reserve(__pa(&_Level4InterruptVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300372 __pa(&_Level4InterruptVector_text_end));
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400373#endif
374#if XCHAL_EXCM_LEVEL >= 5
375 mem_reserve(__pa(&_Level5InterruptVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300376 __pa(&_Level5InterruptVector_text_end));
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400377#endif
378#if XCHAL_EXCM_LEVEL >= 6
379 mem_reserve(__pa(&_Level6InterruptVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300380 __pa(&_Level6InterruptVector_text_end));
Marc Gauthier2d1c6452013-01-05 04:57:17 +0400381#endif
382
Max Filippovb46dcfa2017-01-04 10:40:49 -0800383#endif /* CONFIG_VECTORS_OFFSET */
384
Max Filippovab45fb12015-10-16 17:01:04 +0300385#ifdef CONFIG_SMP
386 mem_reserve(__pa(&_SecondaryResetVector_text_start),
Max Filippov0e46c112016-04-25 22:08:20 +0300387 __pa(&_SecondaryResetVector_text_end));
Max Filippovab45fb12015-10-16 17:01:04 +0300388#endif
Max Filippov06bd2822014-03-21 21:04:40 +0400389 parse_early_param();
Chris Zankel5a0015d2005-06-23 22:01:16 -0700390 bootmem_init();
Max Filippovc6335442017-12-03 13:28:52 -0800391 kasan_init();
Rob Herring31040212013-08-26 11:24:11 -0500392 unflatten_and_copy_device_tree();
Chris Zankel5a0015d2005-06-23 22:01:16 -0700393
Max Filippovf6151362013-10-17 02:42:26 +0400394#ifdef CONFIG_SMP
395 smp_init_cpus();
396#endif
397
Chris Zankel5a0015d2005-06-23 22:01:16 -0700398 paging_init();
Johannes Weinere5083a62009-03-04 16:21:31 +0100399 zones_init();
Chris Zankel5a0015d2005-06-23 22:01:16 -0700400
401#ifdef CONFIG_VT
402# if defined(CONFIG_VGA_CONSOLE)
403 conswitchp = &vga_con;
404# elif defined(CONFIG_DUMMY_CONSOLE)
405 conswitchp = &dummy_con;
406# endif
407#endif
Chris Zankel5a0015d2005-06-23 22:01:16 -0700408}
409
Max Filippovf6151362013-10-17 02:42:26 +0400410static DEFINE_PER_CPU(struct cpu, cpu_data);
411
412static int __init topology_init(void)
413{
414 int i;
415
416 for_each_possible_cpu(i) {
417 struct cpu *cpu = &per_cpu(cpu_data, i);
Max Filippov49b424f2013-10-17 02:42:28 +0400418 cpu->hotpluggable = !!i;
Max Filippovf6151362013-10-17 02:42:26 +0400419 register_cpu(cpu, i);
420 }
421
422 return 0;
423}
424subsys_initcall(topology_init);
425
Max Filippov4f205682016-09-07 13:33:47 -0700426void cpu_reset(void)
427{
Max Filippov4b3e6f22017-01-31 18:35:37 -0800428#if XCHAL_HAVE_PTP_MMU && IS_ENABLED(CONFIG_MMU)
Max Filippovbf15f862016-09-11 21:35:07 -0700429 local_irq_disable();
430 /*
431 * We have full MMU: all autoload ways, ways 7, 8 and 9 of DTLB must
432 * be flushed.
433 * Way 4 is not currently used by linux.
434 * Ways 5 and 6 shall not be touched on MMUv2 as they are hardwired.
435 * Way 5 shall be flushed and way 6 shall be set to identity mapping
436 * on MMUv3.
437 */
438 local_flush_tlb_all();
439 invalidate_page_directory();
440#if XCHAL_HAVE_SPANNING_WAY
441 /* MMU v3 */
442 {
443 unsigned long vaddr = (unsigned long)cpu_reset;
444 unsigned long paddr = __pa(vaddr);
445 unsigned long tmpaddr = vaddr + SZ_512M;
446 unsigned long tmp0, tmp1, tmp2, tmp3;
447
448 /*
449 * Find a place for the temporary mapping. It must not be
450 * in the same 512MB region with vaddr or paddr, otherwise
451 * there may be multihit exception either on entry to the
452 * temporary mapping, or on entry to the identity mapping.
453 * (512MB is the biggest page size supported by TLB.)
454 */
455 while (((tmpaddr ^ paddr) & -SZ_512M) == 0)
456 tmpaddr += SZ_512M;
457
458 /* Invalidate mapping in the selected temporary area */
Max Filippov60e22cff2017-03-29 19:53:49 -0700459 if (itlb_probe(tmpaddr) & BIT(ITLB_HIT_BIT))
Max Filippovbf15f862016-09-11 21:35:07 -0700460 invalidate_itlb_entry(itlb_probe(tmpaddr));
Max Filippov60e22cff2017-03-29 19:53:49 -0700461 if (itlb_probe(tmpaddr + PAGE_SIZE) & BIT(ITLB_HIT_BIT))
Max Filippovbf15f862016-09-11 21:35:07 -0700462 invalidate_itlb_entry(itlb_probe(tmpaddr + PAGE_SIZE));
463
464 /*
465 * Map two consecutive pages starting at the physical address
466 * of this function to the temporary mapping area.
467 */
468 write_itlb_entry(__pte((paddr & PAGE_MASK) |
469 _PAGE_HW_VALID |
470 _PAGE_HW_EXEC |
471 _PAGE_CA_BYPASS),
472 tmpaddr & PAGE_MASK);
473 write_itlb_entry(__pte(((paddr & PAGE_MASK) + PAGE_SIZE) |
474 _PAGE_HW_VALID |
475 _PAGE_HW_EXEC |
476 _PAGE_CA_BYPASS),
477 (tmpaddr & PAGE_MASK) + PAGE_SIZE);
478
479 /* Reinitialize TLB */
480 __asm__ __volatile__ ("movi %0, 1f\n\t"
481 "movi %3, 2f\n\t"
482 "add %0, %0, %4\n\t"
483 "add %3, %3, %5\n\t"
484 "jx %0\n"
485 /*
486 * No literal, data or stack access
487 * below this point
488 */
489 "1:\n\t"
490 /* Initialize *tlbcfg */
491 "movi %0, 0\n\t"
492 "wsr %0, itlbcfg\n\t"
493 "wsr %0, dtlbcfg\n\t"
494 /* Invalidate TLB way 5 */
495 "movi %0, 4\n\t"
496 "movi %1, 5\n"
497 "1:\n\t"
498 "iitlb %1\n\t"
499 "idtlb %1\n\t"
500 "add %1, %1, %6\n\t"
501 "addi %0, %0, -1\n\t"
502 "bnez %0, 1b\n\t"
503 /* Initialize TLB way 6 */
504 "movi %0, 7\n\t"
505 "addi %1, %9, 3\n\t"
506 "addi %2, %9, 6\n"
507 "1:\n\t"
508 "witlb %1, %2\n\t"
509 "wdtlb %1, %2\n\t"
510 "add %1, %1, %7\n\t"
511 "add %2, %2, %7\n\t"
512 "addi %0, %0, -1\n\t"
513 "bnez %0, 1b\n\t"
514 /* Jump to identity mapping */
515 "jx %3\n"
516 "2:\n\t"
517 /* Complete way 6 initialization */
518 "witlb %1, %2\n\t"
519 "wdtlb %1, %2\n\t"
520 /* Invalidate temporary mapping */
521 "sub %0, %9, %7\n\t"
522 "iitlb %0\n\t"
523 "add %0, %0, %8\n\t"
524 "iitlb %0"
525 : "=&a"(tmp0), "=&a"(tmp1), "=&a"(tmp2),
526 "=&a"(tmp3)
527 : "a"(tmpaddr - vaddr),
528 "a"(paddr - vaddr),
529 "a"(SZ_128M), "a"(SZ_512M),
530 "a"(PAGE_SIZE),
531 "a"((tmpaddr + SZ_512M) & PAGE_MASK)
532 : "memory");
533 }
534#endif
535#endif
Max Filippovea951c32016-09-11 22:05:32 -0700536 __asm__ __volatile__ ("movi a2, 0\n\t"
Max Filippov4f205682016-09-07 13:33:47 -0700537 "wsr a2, icountlevel\n\t"
538 "movi a2, 0\n\t"
539 "wsr a2, icount\n\t"
540#if XCHAL_NUM_IBREAK > 0
541 "wsr a2, ibreakenable\n\t"
542#endif
543#if XCHAL_HAVE_LOOPS
544 "wsr a2, lcount\n\t"
545#endif
546 "movi a2, 0x1f\n\t"
547 "wsr a2, ps\n\t"
548 "isync\n\t"
549 "jx %0\n\t"
550 :
551 : "a" (XCHAL_RESET_VECTOR_VADDR)
552 : "a2");
553 for (;;)
554 ;
555}
556
Chris Zankel5a0015d2005-06-23 22:01:16 -0700557void machine_restart(char * cmd)
558{
559 platform_restart();
560}
561
562void machine_halt(void)
563{
564 platform_halt();
565 while (1);
566}
567
568void machine_power_off(void)
569{
570 platform_power_off();
571 while (1);
572}
573#ifdef CONFIG_PROC_FS
574
575/*
576 * Display some core information through /proc/cpuinfo.
577 */
578
579static int
580c_show(struct seq_file *f, void *slot)
581{
582 /* high-level stuff */
Max Filippovf6151362013-10-17 02:42:26 +0400583 seq_printf(f, "CPU count\t: %u\n"
Tejun Heo625189942015-02-13 14:37:17 -0800584 "CPU list\t: %*pbl\n"
Max Filippovf6151362013-10-17 02:42:26 +0400585 "vendor_id\t: Tensilica\n"
586 "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
587 "core ID\t\t: " XCHAL_CORE_ID "\n"
588 "build ID\t: 0x%x\n"
Max Filippovaa6476f2017-08-08 14:06:14 -0700589 "config ID\t: %08x:%08x\n"
Max Filippovf6151362013-10-17 02:42:26 +0400590 "byte order\t: %s\n"
591 "cpu MHz\t\t: %lu.%02lu\n"
592 "bogomips\t: %lu.%02lu\n",
593 num_online_cpus(),
Tejun Heo625189942015-02-13 14:37:17 -0800594 cpumask_pr_args(cpu_online_mask),
Max Filippovf6151362013-10-17 02:42:26 +0400595 XCHAL_BUILD_UNIQUE_ID,
Max Filippovcad6fad2018-11-27 16:27:47 -0800596 xtensa_get_sr(SREG_EPC), xtensa_get_sr(SREG_EXCSAVE),
Max Filippovf6151362013-10-17 02:42:26 +0400597 XCHAL_HAVE_BE ? "big" : "little",
598 ccount_freq/1000000,
599 (ccount_freq/10000) % 100,
600 loops_per_jiffy/(500000/HZ),
601 (loops_per_jiffy/(5000/HZ)) % 100);
Markus Elfringc32537d2017-05-07 21:24:51 +0200602 seq_puts(f, "flags\t\t: "
Chris Zankel5a0015d2005-06-23 22:01:16 -0700603#if XCHAL_HAVE_NMI
604 "nmi "
605#endif
606#if XCHAL_HAVE_DEBUG
607 "debug "
608# if XCHAL_HAVE_OCD
609 "ocd "
610# endif
611#endif
612#if XCHAL_HAVE_DENSITY
613 "density "
614#endif
615#if XCHAL_HAVE_BOOLEANS
616 "boolean "
617#endif
618#if XCHAL_HAVE_LOOPS
619 "loop "
620#endif
621#if XCHAL_HAVE_NSA
622 "nsa "
623#endif
624#if XCHAL_HAVE_MINMAX
625 "minmax "
626#endif
627#if XCHAL_HAVE_SEXT
628 "sext "
629#endif
630#if XCHAL_HAVE_CLAMPS
631 "clamps "
632#endif
633#if XCHAL_HAVE_MAC16
634 "mac16 "
635#endif
636#if XCHAL_HAVE_MUL16
637 "mul16 "
638#endif
639#if XCHAL_HAVE_MUL32
640 "mul32 "
641#endif
642#if XCHAL_HAVE_MUL32_HIGH
643 "mul32h "
644#endif
645#if XCHAL_HAVE_FP
646 "fpu "
647#endif
Max Filippov2f6ea6a2012-11-11 04:44:22 +0400648#if XCHAL_HAVE_S32C1I
649 "s32c1i "
650#endif
Max Filippovf7c34872018-12-20 17:18:12 -0800651#if XCHAL_HAVE_EXCLUSIVE
652 "exclusive "
653#endif
Chris Zankel5a0015d2005-06-23 22:01:16 -0700654 "\n");
655
656 /* Registers. */
657 seq_printf(f,"physical aregs\t: %d\n"
658 "misc regs\t: %d\n"
659 "ibreak\t\t: %d\n"
660 "dbreak\t\t: %d\n",
661 XCHAL_NUM_AREGS,
662 XCHAL_NUM_MISC_REGS,
663 XCHAL_NUM_IBREAK,
664 XCHAL_NUM_DBREAK);
665
666
667 /* Interrupt. */
668 seq_printf(f,"num ints\t: %d\n"
669 "ext ints\t: %d\n"
670 "int levels\t: %d\n"
671 "timers\t\t: %d\n"
672 "debug level\t: %d\n",
673 XCHAL_NUM_INTERRUPTS,
674 XCHAL_NUM_EXTINTERRUPTS,
675 XCHAL_NUM_INTLEVELS,
676 XCHAL_NUM_TIMERS,
677 XCHAL_DEBUGLEVEL);
678
Chris Zankel5a0015d2005-06-23 22:01:16 -0700679 /* Cache */
680 seq_printf(f,"icache line size: %d\n"
681 "icache ways\t: %d\n"
682 "icache size\t: %d\n"
683 "icache flags\t: "
684#if XCHAL_ICACHE_LINE_LOCKABLE
Max Filippov415217e2012-11-11 01:29:10 +0400685 "lock "
Chris Zankel5a0015d2005-06-23 22:01:16 -0700686#endif
687 "\n"
688 "dcache line size: %d\n"
689 "dcache ways\t: %d\n"
690 "dcache size\t: %d\n"
691 "dcache flags\t: "
692#if XCHAL_DCACHE_IS_WRITEBACK
Max Filippov415217e2012-11-11 01:29:10 +0400693 "writeback "
Chris Zankel5a0015d2005-06-23 22:01:16 -0700694#endif
695#if XCHAL_DCACHE_LINE_LOCKABLE
Max Filippov415217e2012-11-11 01:29:10 +0400696 "lock "
Chris Zankel5a0015d2005-06-23 22:01:16 -0700697#endif
698 "\n",
699 XCHAL_ICACHE_LINESIZE,
700 XCHAL_ICACHE_WAYS,
701 XCHAL_ICACHE_SIZE,
702 XCHAL_DCACHE_LINESIZE,
703 XCHAL_DCACHE_WAYS,
704 XCHAL_DCACHE_SIZE);
705
Chris Zankel5a0015d2005-06-23 22:01:16 -0700706 return 0;
707}
708
709/*
710 * We show only CPU #0 info.
711 */
712static void *
713c_start(struct seq_file *f, loff_t *pos)
714{
Max Filippovf6151362013-10-17 02:42:26 +0400715 return (*pos == 0) ? (void *)1 : NULL;
Chris Zankel5a0015d2005-06-23 22:01:16 -0700716}
717
718static void *
719c_next(struct seq_file *f, void *v, loff_t *pos)
720{
721 return NULL;
722}
723
724static void
725c_stop(struct seq_file *f, void *v)
726{
727}
728
Jan Engelhardt03a44822008-02-08 04:21:19 -0800729const struct seq_operations cpuinfo_op =
Chris Zankel5a0015d2005-06-23 22:01:16 -0700730{
Max Filippovf6151362013-10-17 02:42:26 +0400731 .start = c_start,
732 .next = c_next,
733 .stop = c_stop,
734 .show = c_show,
Chris Zankel5a0015d2005-06-23 22:01:16 -0700735};
736
737#endif /* CONFIG_PROC_FS */