blob: 18763153e07c4d6c7755fc16076aed0320fde648 [file] [log] [blame]
Vineet Guptac121c502013-01-18 15:12:20 +05301/*
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>
Vineet Gupta999159a2013-01-22 17:00:52 +053016#include <linux/of_fdt.h>
Sachin Kamat1ec9db12013-03-06 16:53:44 +053017#include <linux/cache.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053018#include <asm/sections.h>
Vineet Guptac121c502013-01-18 15:12:20 +053019#include <asm/arcregs.h>
20#include <asm/tlb.h>
Vineet Guptac121c502013-01-18 15:12:20 +053021#include <asm/setup.h>
22#include <asm/page.h>
23#include <asm/irq.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053024#include <asm/prom.h>
Vineet Gupta854a0d92013-01-22 17:03:19 +053025#include <asm/unwind.h>
Vineet Guptaaf617422013-01-18 15:12:24 +053026#include <asm/clk.h>
Vineet Gupta03a6d282013-01-18 15:12:26 +053027#include <asm/mach_desc.h>
Vineet Guptac121c502013-01-18 15:12:20 +053028
29#define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
30
31int running_on_hw = 1; /* vs. on ISS */
32
33char __initdata command_line[COMMAND_LINE_SIZE];
Vineet Gupta30ecee82013-04-09 17:18:12 +053034struct machine_desc *machine_desc __cpuinitdata;
Vineet Guptac121c502013-01-18 15:12:20 +053035
36struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
37
38struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
39
Vineet Guptaaf617422013-01-18 15:12:24 +053040
Vineet Gupta30ecee82013-04-09 17:18:12 +053041void __cpuinit read_arc_build_cfg_regs(void)
Vineet Guptac121c502013-01-18 15:12:20 +053042{
Vineet Guptaaf617422013-01-18 15:12:24 +053043 struct bcr_perip uncached_space;
44 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
45 FIX_PTR(cpu);
46
47 READ_BCR(AUX_IDENTITY, cpu->core);
48
49 cpu->timers = read_aux_reg(ARC_REG_TIMERS_BCR);
50
51 cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
52 if (cpu->vec_base == 0)
53 cpu->vec_base = (unsigned int)_int_vec_base_lds;
54
55 READ_BCR(ARC_REG_D_UNCACH_BCR, uncached_space);
56 cpu->uncached_base = uncached_space.start << 24;
57
58 cpu->extn.mul = read_aux_reg(ARC_REG_MUL_BCR);
59 cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR);
60 cpu->extn.norm = read_aux_reg(ARC_REG_NORM_BCR);
61 cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR);
62 cpu->extn.barrel = read_aux_reg(ARC_REG_BARREL_BCR);
63 READ_BCR(ARC_REG_MAC_BCR, cpu->extn_mac_mul);
64
65 cpu->extn.ext_arith = read_aux_reg(ARC_REG_EXTARITH_BCR);
66 cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR);
67
Vineet Gupta8b5850f2013-01-18 15:12:25 +053068 /* Note that we read the CCM BCRs independent of kernel config
69 * This is to catch the cases where user doesn't know that
70 * CCMs are present in hardware build
71 */
72 {
73 struct bcr_iccm iccm;
74 struct bcr_dccm dccm;
75 struct bcr_dccm_base dccm_base;
76 unsigned int bcr_32bit_val;
77
78 bcr_32bit_val = read_aux_reg(ARC_REG_ICCM_BCR);
79 if (bcr_32bit_val) {
80 iccm = *((struct bcr_iccm *)&bcr_32bit_val);
81 cpu->iccm.base_addr = iccm.base << 16;
82 cpu->iccm.sz = 0x2000 << (iccm.sz - 1);
83 }
84
85 bcr_32bit_val = read_aux_reg(ARC_REG_DCCM_BCR);
86 if (bcr_32bit_val) {
87 dccm = *((struct bcr_dccm *)&bcr_32bit_val);
88 cpu->dccm.sz = 0x800 << (dccm.sz);
89
90 READ_BCR(ARC_REG_DCCMBASE_BCR, dccm_base);
91 cpu->dccm.base_addr = dccm_base.addr << 8;
92 }
93 }
94
Vineet Guptaaf617422013-01-18 15:12:24 +053095 READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
96
Vineet Guptac121c502013-01-18 15:12:20 +053097 read_decode_mmu_bcr();
98 read_decode_cache_bcr();
Vineet Guptaaf617422013-01-18 15:12:24 +053099
100 READ_BCR(ARC_REG_FP_BCR, cpu->fp);
101 READ_BCR(ARC_REG_DPFP_BCR, cpu->dpfp);
102}
103
104static const struct cpuinfo_data arc_cpu_tbl[] = {
105 { {0x10, "ARCTangent A5"}, 0x1F},
106 { {0x20, "ARC 600" }, 0x2F},
107 { {0x30, "ARC 700" }, 0x33},
108 { {0x34, "ARC 700 R4.10"}, 0x34},
109 { {0x00, NULL } }
110};
111
112char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
113{
114 int n = 0;
115 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
116 struct bcr_identity *core = &cpu->core;
117 const struct cpuinfo_data *tbl;
118 int be = 0;
119#ifdef CONFIG_CPU_BIG_ENDIAN
120 be = 1;
121#endif
122 FIX_PTR(cpu);
123
124 n += scnprintf(buf + n, len - n,
125 "\nARC IDENTITY\t: Family [%#02x]"
126 " Cpu-id [%#02x] Chip-id [%#4x]\n",
127 core->family, core->cpu_id,
128 core->chip_id);
129
130 for (tbl = &arc_cpu_tbl[0]; tbl->info.id != 0; tbl++) {
131 if ((core->family >= tbl->info.id) &&
132 (core->family <= tbl->up_range)) {
133 n += scnprintf(buf + n, len - n,
134 "processor\t: %s %s\n",
135 tbl->info.str,
136 be ? "[Big Endian]" : "");
137 break;
138 }
139 }
140
141 if (tbl->info.id == 0)
142 n += scnprintf(buf + n, len - n, "UNKNOWN ARC Processor\n");
143
144 n += scnprintf(buf + n, len - n, "CPU speed\t: %u.%02u Mhz\n",
145 (unsigned int)(arc_get_core_freq() / 1000000),
146 (unsigned int)(arc_get_core_freq() / 10000) % 100);
147
148 n += scnprintf(buf + n, len - n, "Timers\t\t: %s %s\n",
149 (cpu->timers & 0x200) ? "TIMER1" : "",
150 (cpu->timers & 0x100) ? "TIMER0" : "");
151
152 n += scnprintf(buf + n, len - n, "Vect Tbl Base\t: %#x\n",
153 cpu->vec_base);
154
155 n += scnprintf(buf + n, len - n, "UNCACHED Base\t: %#x\n",
156 cpu->uncached_base);
157
158 return buf;
159}
160
161static const struct id_to_str mul_type_nm[] = {
162 { 0x0, "N/A"},
163 { 0x1, "32x32 (spl Result Reg)" },
164 { 0x2, "32x32 (ANY Result Reg)" }
165};
166
167static const struct id_to_str mac_mul_nm[] = {
168 {0x0, "N/A"},
169 {0x1, "N/A"},
170 {0x2, "Dual 16 x 16"},
171 {0x3, "N/A"},
172 {0x4, "32x16"},
173 {0x5, "N/A"},
174 {0x6, "Dual 16x16 and 32x16"}
175};
176
177char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
178{
179 int n = 0;
180 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
181
182 FIX_PTR(cpu);
183#define IS_AVAIL1(var, str) ((var) ? str : "")
184#define IS_AVAIL2(var, str) ((var == 0x2) ? str : "")
185#define IS_USED(var) ((var) ? "(in-use)" : "(not used)")
186
187 n += scnprintf(buf + n, len - n,
188 "Extn [700-Base]\t: %s %s %s %s %s %s\n",
189 IS_AVAIL2(cpu->extn.norm, "norm,"),
190 IS_AVAIL2(cpu->extn.barrel, "barrel-shift,"),
191 IS_AVAIL1(cpu->extn.swap, "swap,"),
192 IS_AVAIL2(cpu->extn.minmax, "minmax,"),
193 IS_AVAIL1(cpu->extn.crc, "crc,"),
194 IS_AVAIL2(cpu->extn.ext_arith, "ext-arith"));
195
196 n += scnprintf(buf + n, len - n, "Extn [700-MPY]\t: %s",
197 mul_type_nm[cpu->extn.mul].str);
198
199 n += scnprintf(buf + n, len - n, " MAC MPY: %s\n",
200 mac_mul_nm[cpu->extn_mac_mul.type].str);
201
202 if (cpu->core.family == 0x34) {
203 n += scnprintf(buf + n, len - n,
204 "Extn [700-4.10]\t: LLOCK/SCOND %s, SWAPE %s, RTSC %s\n",
205 IS_USED(__CONFIG_ARC_HAS_LLSC_VAL),
206 IS_USED(__CONFIG_ARC_HAS_SWAPE_VAL),
207 IS_USED(__CONFIG_ARC_HAS_RTSC_VAL));
208 }
209
210 n += scnprintf(buf + n, len - n, "Extn [CCM]\t: %s",
211 !(cpu->dccm.sz || cpu->iccm.sz) ? "N/A" : "");
212
213 if (cpu->dccm.sz)
214 n += scnprintf(buf + n, len - n, "DCCM: @ %x, %d KB ",
215 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz));
216
217 if (cpu->iccm.sz)
218 n += scnprintf(buf + n, len - n, "ICCM: @ %x, %d KB",
219 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
220
221 n += scnprintf(buf + n, len - n, "\nExtn [FPU]\t: %s",
222 !(cpu->fp.ver || cpu->dpfp.ver) ? "N/A" : "");
223
224 if (cpu->fp.ver)
225 n += scnprintf(buf + n, len - n, "SP [v%d] %s",
226 cpu->fp.ver, cpu->fp.fast ? "(fast)" : "");
227
228 if (cpu->dpfp.ver)
229 n += scnprintf(buf + n, len - n, "DP [v%d] %s",
230 cpu->dpfp.ver, cpu->dpfp.fast ? "(fast)" : "");
231
232 n += scnprintf(buf + n, len - n, "\n");
233
Vineet Guptaaf617422013-01-18 15:12:24 +0530234 n += scnprintf(buf + n, len - n,
Vineet Gupta8ff14bb2013-03-06 14:33:27 +0530235 "OS ABI [v3]\t: no-legacy-syscalls\n");
Vineet Guptaaf617422013-01-18 15:12:24 +0530236
237 return buf;
238}
239
Vineet Gupta30ecee82013-04-09 17:18:12 +0530240void __cpuinit arc_chk_ccms(void)
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530241{
242#if defined(CONFIG_ARC_HAS_DCCM) || defined(CONFIG_ARC_HAS_ICCM)
243 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
244
245#ifdef CONFIG_ARC_HAS_DCCM
246 /*
247 * DCCM can be arbit placed in hardware.
248 * Make sure it's placement/sz matches what Linux is built with
249 */
250 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
251 panic("Linux built with incorrect DCCM Base address\n");
252
253 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
254 panic("Linux built with incorrect DCCM Size\n");
255#endif
256
257#ifdef CONFIG_ARC_HAS_ICCM
258 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
259 panic("Linux built with incorrect ICCM Size\n");
260#endif
261#endif
262}
263
Vineet Guptaaf617422013-01-18 15:12:24 +0530264/*
265 * Ensure that FP hardware and kernel config match
266 * -If hardware contains DPFP, kernel needs to save/restore FPU state
267 * across context switches
268 * -If hardware lacks DPFP, but kernel configured to save FPU state then
269 * kernel trying to access non-existant DPFP regs will crash
270 *
271 * We only check for Dbl precision Floating Point, because only DPFP
272 * hardware has dedicated regs which need to be saved/restored on ctx-sw
273 * (Single Precision uses core regs), thus kernel is kind of oblivious to it
274 */
Vineet Gupta30ecee82013-04-09 17:18:12 +0530275void __cpuinit arc_chk_fpu(void)
Vineet Guptaaf617422013-01-18 15:12:24 +0530276{
277 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
278
279 if (cpu->dpfp.ver) {
280#ifndef CONFIG_ARC_FPU_SAVE_RESTORE
281 pr_warn("DPFP support broken in this kernel...\n");
282#endif
283 } else {
284#ifdef CONFIG_ARC_FPU_SAVE_RESTORE
285 panic("H/w lacks DPFP support, apps won't work\n");
286#endif
287 }
Vineet Guptac121c502013-01-18 15:12:20 +0530288}
289
290/*
291 * Initialize and setup the processor core
292 * This is called by all the CPUs thus should not do special case stuff
293 * such as only for boot CPU etc
294 */
295
Vineet Gupta30ecee82013-04-09 17:18:12 +0530296void __cpuinit setup_processor(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530297{
Vineet Guptaaf617422013-01-18 15:12:24 +0530298 char str[512];
299 int cpu_id = smp_processor_id();
300
Vineet Guptac121c502013-01-18 15:12:20 +0530301 read_arc_build_cfg_regs();
302 arc_init_IRQ();
Vineet Guptaaf617422013-01-18 15:12:24 +0530303
304 printk(arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
305
Vineet Guptac121c502013-01-18 15:12:20 +0530306 arc_mmu_init();
307 arc_cache_init();
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530308 arc_chk_ccms();
Vineet Guptaaf617422013-01-18 15:12:24 +0530309
310 printk(arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
311
312#ifdef CONFIG_SMP
313 printk(arc_platform_smp_cpuinfo());
314#endif
315
316 arc_chk_fpu();
Vineet Guptac121c502013-01-18 15:12:20 +0530317}
318
Vineet Guptac121c502013-01-18 15:12:20 +0530319void __init setup_arch(char **cmdline_p)
320{
321#ifdef CONFIG_CMDLINE_UBOOT
322 /* Make sure that a whitespace is inserted before */
323 strlcat(command_line, " ", sizeof(command_line));
324#endif
Vineet Guptac121c502013-01-18 15:12:20 +0530325
326 /* Save unparsed command line copy for /proc/cmdline */
327 strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
328 *cmdline_p = command_line;
329
Vineet Gupta03a6d282013-01-18 15:12:26 +0530330 machine_desc = setup_machine_fdt(__dtb_start);
331 if (!machine_desc)
332 panic("Embedded DT invalid\n");
Vineet Gupta999159a2013-01-22 17:00:52 +0530333
Vineet Guptac121c502013-01-18 15:12:20 +0530334 /* To force early parsing of things like mem=xxx */
335 parse_early_param();
336
337 /* Platform/board specific: e.g. early console registration */
Vineet Gupta03a6d282013-01-18 15:12:26 +0530338 if (machine_desc->init_early)
339 machine_desc->init_early();
Vineet Guptac121c502013-01-18 15:12:20 +0530340
341 setup_processor();
342
Vineet Gupta41195d22013-01-18 15:12:23 +0530343#ifdef CONFIG_SMP
344 smp_init_cpus();
345#endif
346
Vineet Guptac121c502013-01-18 15:12:20 +0530347 setup_arch_memory();
348
Vineet Guptaeab6a082013-02-21 17:37:06 +0530349 /* copy flat DT out of .init and then unflatten it */
350 copy_devtree();
Vineet Gupta999159a2013-01-22 17:00:52 +0530351 unflatten_device_tree();
352
Vineet Guptac121c502013-01-18 15:12:20 +0530353 /* Can be issue if someone passes cmd line arg "ro"
354 * But that is unlikely so keeping it as it is
355 */
356 root_mountflags &= ~MS_RDONLY;
357
358 console_verbose();
359
360#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
361 conswitchp = &dummy_con;
362#endif
363
Vineet Gupta854a0d92013-01-22 17:03:19 +0530364 arc_unwind_init();
365 arc_unwind_setup();
Vineet Guptac121c502013-01-18 15:12:20 +0530366}
367
Vineet Gupta03a6d282013-01-18 15:12:26 +0530368static int __init customize_machine(void)
369{
370 /* Add platform devices */
371 if (machine_desc->init_machine)
372 machine_desc->init_machine();
373
374 return 0;
375}
376arch_initcall(customize_machine);
377
378static int __init init_late_machine(void)
379{
380 if (machine_desc->init_late)
381 machine_desc->init_late();
382
383 return 0;
384}
385late_initcall(init_late_machine);
Vineet Guptac121c502013-01-18 15:12:20 +0530386/*
387 * Get CPU information for use by the procfs.
388 */
389
390#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
391#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
392
393static int show_cpuinfo(struct seq_file *m, void *v)
394{
395 char *str;
396 int cpu_id = ptr_to_cpu(v);
397
398 str = (char *)__get_free_page(GFP_TEMPORARY);
399 if (!str)
400 goto done;
401
Vineet Guptaaf617422013-01-18 15:12:24 +0530402 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptac121c502013-01-18 15:12:20 +0530403
404 seq_printf(m, "Bogo MIPS : \t%lu.%02lu\n",
405 loops_per_jiffy / (500000 / HZ),
406 (loops_per_jiffy / (5000 / HZ)) % 100);
407
Vineet Guptaaf617422013-01-18 15:12:24 +0530408 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
409
410 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
411
412 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
413
414#ifdef CONFIG_SMP
415 seq_printf(m, arc_platform_smp_cpuinfo());
416#endif
417
Vineet Guptac121c502013-01-18 15:12:20 +0530418 free_page((unsigned long)str);
419done:
420 seq_printf(m, "\n\n");
421
422 return 0;
423}
424
425static void *c_start(struct seq_file *m, loff_t *pos)
426{
427 /*
428 * Callback returns cpu-id to iterator for show routine, NULL to stop.
429 * However since NULL is also a valid cpu-id (0), we use a round-about
430 * way to pass it w/o having to kmalloc/free a 2 byte string.
431 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
432 */
433 return *pos < num_possible_cpus() ? cpu_to_ptr(*pos) : NULL;
434}
435
436static void *c_next(struct seq_file *m, void *v, loff_t *pos)
437{
438 ++*pos;
439 return c_start(m, pos);
440}
441
442static void c_stop(struct seq_file *m, void *v)
443{
444}
445
446const struct seq_operations cpuinfo_op = {
447 .start = c_start,
448 .next = c_next,
449 .stop = c_stop,
450 .show = show_cpuinfo
451};
452
453static DEFINE_PER_CPU(struct cpu, cpu_topology);
454
455static int __init topology_init(void)
456{
457 int cpu;
458
459 for_each_present_cpu(cpu)
460 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
461
462 return 0;
463}
464
465subsys_initcall(topology_init);