blob: 33e232145d8396deb366eae8a9d1bc6364902d39 [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>
Vlad Zakharov7f351442017-03-03 14:30:02 +030013#include <linux/clk.h>
Vineet Gupta92b03312016-10-31 13:26:25 -070014#include <linux/clk-provider.h>
15#include <linux/clocksource.h>
Vineet Guptac121c502013-01-18 15:12:20 +053016#include <linux/console.h>
17#include <linux/module.h>
18#include <linux/cpu.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053019#include <linux/of_fdt.h>
Vineet Gupta1ce0b582016-07-13 13:21:20 -070020#include <linux/of.h>
Sachin Kamat1ec9db12013-03-06 16:53:44 +053021#include <linux/cache.h>
David Howellse262e32d2018-11-01 23:07:23 +000022#include <uapi/linux/mount.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053023#include <asm/sections.h>
Vineet Guptac121c502013-01-18 15:12:20 +053024#include <asm/arcregs.h>
25#include <asm/tlb.h>
Vineet Guptac121c502013-01-18 15:12:20 +053026#include <asm/setup.h>
27#include <asm/page.h>
28#include <asm/irq.h>
Vineet Gupta854a0d92013-01-22 17:03:19 +053029#include <asm/unwind.h>
Vineet Gupta03a6d282013-01-18 15:12:26 +053030#include <asm/mach_desc.h>
Vineet Gupta619f3012014-09-04 10:57:33 +053031#include <asm/smp.h>
Vineet Guptac121c502013-01-18 15:12:20 +053032
33#define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
34
Vineet Gupta4255b072014-09-22 16:51:47 +053035unsigned int intr_to_DE_cnt;
36
Vineet Gupta59ed9412014-01-16 15:01:24 +053037/* Part of U-boot ABI: see head.S */
38int __initdata uboot_tag;
39char __initdata *uboot_arg;
40
Rob Herring880beb82013-08-27 21:43:12 -050041const struct machine_desc *machine_desc;
Vineet Guptac121c502013-01-18 15:12:20 +053042
43struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
44
45struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
46
Vineet Guptad975cbc2016-10-27 14:33:19 -070047static const struct id_to_str arc_cpu_rel[] = {
Vineet Gupta73e284d2016-10-20 17:49:15 -070048#ifdef CONFIG_ISA_ARCOMPACT
Vineet Guptad975cbc2016-10-27 14:33:19 -070049 { 0x34, "R4.10"},
50 { 0x35, "R4.11"},
Vineet Gupta73e284d2016-10-20 17:49:15 -070051#else
Vineet Guptad975cbc2016-10-27 14:33:19 -070052 { 0x51, "R2.0" },
53 { 0x52, "R2.1" },
54 { 0x53, "R3.0" },
Vineet Gupta701eda02018-02-21 15:10:02 -080055 { 0x54, "R3.10a" },
Vineet Gupta73e284d2016-10-20 17:49:15 -070056#endif
Vineet Guptad975cbc2016-10-27 14:33:19 -070057 { 0x00, NULL }
58};
59
60static const struct id_to_str arc_cpu_nm[] = {
61#ifdef CONFIG_ISA_ARCOMPACT
62 { 0x20, "ARC 600" },
63 { 0x30, "ARC 770" }, /* 750 identified seperately */
64#else
65 { 0x40, "ARC EM" },
66 { 0x50, "ARC HS38" },
Vineet Guptadea82522017-09-21 18:02:44 -070067 { 0x54, "ARC HS48" },
Vineet Guptad975cbc2016-10-27 14:33:19 -070068#endif
69 { 0x00, "Unknown" }
Vineet Gupta73e284d2016-10-20 17:49:15 -070070};
71
Vineet Guptaa150b082016-02-16 12:36:18 +053072static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
73{
74 if (is_isa_arcompact()) {
75 struct bcr_iccm_arcompact iccm;
76 struct bcr_dccm_arcompact dccm;
77
78 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
79 if (iccm.ver) {
80 cpu->iccm.sz = 4096 << iccm.sz; /* 8K to 512K */
81 cpu->iccm.base_addr = iccm.base << 16;
82 }
83
84 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
85 if (dccm.ver) {
86 unsigned long base;
87 cpu->dccm.sz = 2048 << dccm.sz; /* 2K to 256K */
88
89 base = read_aux_reg(ARC_REG_DCCM_BASE_BUILD);
90 cpu->dccm.base_addr = base & ~0xF;
91 }
92 } else {
93 struct bcr_iccm_arcv2 iccm;
94 struct bcr_dccm_arcv2 dccm;
95 unsigned long region;
96
97 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
98 if (iccm.ver) {
99 cpu->iccm.sz = 256 << iccm.sz00; /* 512B to 16M */
100 if (iccm.sz00 == 0xF && iccm.sz01 > 0)
101 cpu->iccm.sz <<= iccm.sz01;
102
103 region = read_aux_reg(ARC_REG_AUX_ICCM);
104 cpu->iccm.base_addr = region & 0xF0000000;
105 }
106
107 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
108 if (dccm.ver) {
109 cpu->dccm.sz = 256 << dccm.sz0;
110 if (dccm.sz0 == 0xF && dccm.sz1 > 0)
111 cpu->dccm.sz <<= dccm.sz1;
112
113 region = read_aux_reg(ARC_REG_AUX_DCCM);
114 cpu->dccm.base_addr = region & 0xF0000000;
115 }
116 }
117}
118
Vineet Gupta8e457d62013-09-04 16:13:35 +0530119static void read_arc_build_cfg_regs(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530120{
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530121 struct bcr_timer timer;
Vineet Gupta56372082014-09-25 16:54:43 +0530122 struct bcr_generic bcr;
Vineet Guptaaf617422013-01-18 15:12:24 +0530123 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Guptad975cbc2016-10-27 14:33:19 -0700124 const struct id_to_str *tbl;
Vineet Gupta010a8c92017-09-21 17:46:38 -0700125 struct bcr_isa_arcv2 isa;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700126
Vineet Guptaaf617422013-01-18 15:12:24 +0530127 FIX_PTR(cpu);
128
129 READ_BCR(AUX_IDENTITY, cpu->core);
130
Vineet Guptad975cbc2016-10-27 14:33:19 -0700131 for (tbl = &arc_cpu_rel[0]; tbl->id != 0; tbl++) {
132 if (cpu->core.family == tbl->id) {
133 cpu->details = tbl->str;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700134 break;
135 }
136 }
137
Vineet Guptad975cbc2016-10-27 14:33:19 -0700138 for (tbl = &arc_cpu_nm[0]; tbl->id != 0; tbl++) {
Vineet Guptadea82522017-09-21 18:02:44 -0700139 if ((cpu->core.family & 0xF4) == tbl->id)
Vineet Guptad975cbc2016-10-27 14:33:19 -0700140 break;
141 }
142 cpu->name = tbl->str;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700143
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530144 READ_BCR(ARC_REG_TIMERS_BCR, timer);
145 cpu->extn.timer0 = timer.t0;
146 cpu->extn.timer1 = timer.t1;
147 cpu->extn.rtc = timer.rtc;
148
Vineet Guptaaf617422013-01-18 15:12:24 +0530149 cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
Vineet Guptaaf617422013-01-18 15:12:24 +0530150
Vineet Gupta56372082014-09-25 16:54:43 +0530151 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
Vineet Guptaaf617422013-01-18 15:12:24 +0530152
Vineet Gupta56372082014-09-25 16:54:43 +0530153 cpu->extn.norm = read_aux_reg(ARC_REG_NORM_BCR) > 1 ? 1 : 0; /* 2,3 */
154 cpu->extn.barrel = read_aux_reg(ARC_REG_BARREL_BCR) > 1 ? 1 : 0; /* 2,3 */
155 cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR) ? 1 : 0; /* 1,3 */
156 cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR) ? 1 : 0;
157 cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR) > 1 ? 1 : 0; /* 2 */
Vineet Guptaa024fd92016-10-20 18:08:10 -0700158 cpu->extn.swape = (cpu->core.family >= 0x34) ? 1 :
159 IS_ENABLED(CONFIG_ARC_HAS_SWAPE);
160
Vineet Guptaaf617422013-01-18 15:12:24 +0530161 READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
162
Vineet Guptaa150b082016-02-16 12:36:18 +0530163 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
164 read_decode_ccm_bcr(cpu);
165
Vineet Guptac121c502013-01-18 15:12:20 +0530166 read_decode_mmu_bcr();
167 read_decode_cache_bcr();
Vineet Guptaaf617422013-01-18 15:12:24 +0530168
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530169 if (is_isa_arcompact()) {
Vineet Gupta56372082014-09-25 16:54:43 +0530170 struct bcr_fp_arcompact sp, dp;
171 struct bcr_bpu_arcompact bpu;
172
173 READ_BCR(ARC_REG_FP_BCR, sp);
174 READ_BCR(ARC_REG_DPFP_BCR, dp);
175 cpu->extn.fpu_sp = sp.ver ? 1 : 0;
176 cpu->extn.fpu_dp = dp.ver ? 1 : 0;
177
178 READ_BCR(ARC_REG_BPU_BCR, bpu);
179 cpu->bpu.ver = bpu.ver;
180 cpu->bpu.full = bpu.fam ? 1 : 0;
181 if (bpu.ent) {
182 cpu->bpu.num_cache = 256 << (bpu.ent - 1);
183 cpu->bpu.num_pred = 256 << (bpu.ent - 1);
184 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530185 } else {
186 struct bcr_fp_arcv2 spdp;
187 struct bcr_bpu_arcv2 bpu;
188
189 READ_BCR(ARC_REG_FP_V2_BCR, spdp);
190 cpu->extn.fpu_sp = spdp.sp ? 1 : 0;
191 cpu->extn.fpu_dp = spdp.dp ? 1 : 0;
192
193 READ_BCR(ARC_REG_BPU_BCR, bpu);
194 cpu->bpu.ver = bpu.ver;
195 cpu->bpu.full = bpu.ft;
196 cpu->bpu.num_cache = 256 << bpu.bce;
197 cpu->bpu.num_pred = 2048 << bpu.pte;
Vineet Gupta97e98132018-12-06 00:17:50 -0800198 cpu->bpu.ret_stk = 4 << bpu.rse;
Vineet Guptadea82522017-09-21 18:02:44 -0700199
200 if (cpu->core.family >= 0x54) {
201 unsigned int exec_ctrl;
202
203 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
Alexey Brodkin329b4132017-11-23 13:21:55 +0300204 cpu->extn.dual_enb = !(exec_ctrl & 1);
Vineet Guptaf3156852017-11-10 12:40:00 -0800205
206 /* dual issue always present for this core */
207 cpu->extn.dual = 1;
Vineet Guptadea82522017-09-21 18:02:44 -0700208 }
Vineet Gupta56372082014-09-25 16:54:43 +0530209 }
210
211 READ_BCR(ARC_REG_AP_BCR, bcr);
212 cpu->extn.ap = bcr.ver ? 1 : 0;
213
214 READ_BCR(ARC_REG_SMART_BCR, bcr);
215 cpu->extn.smart = bcr.ver ? 1 : 0;
216
Vineet Guptaa44ec8bd2015-03-08 14:18:21 +0530217 READ_BCR(ARC_REG_RTT_BCR, bcr);
218 cpu->extn.rtt = bcr.ver ? 1 : 0;
219
220 cpu->extn.debug = cpu->extn.ap | cpu->extn.smart | cpu->extn.rtt;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700221
Vineet Gupta010a8c92017-09-21 17:46:38 -0700222 READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
223
Vineet Gupta73e284d2016-10-20 17:49:15 -0700224 /* some hacks for lack of feature BCR info in old ARC700 cores */
225 if (is_isa_arcompact()) {
Vineet Gupta010a8c92017-09-21 17:46:38 -0700226 if (!isa.ver) /* ISA BCR absent, use Kconfig info */
Vineet Gupta73e284d2016-10-20 17:49:15 -0700227 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
Vineet Gupta010a8c92017-09-21 17:46:38 -0700228 else {
229 /* ARC700_BUILD only has 2 bits of isa info */
230 struct bcr_generic bcr = *(struct bcr_generic *)&isa;
231 cpu->isa.atomic = bcr.info & 1;
232 }
Vineet Gupta73e284d2016-10-20 17:49:15 -0700233
234 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
Vineet Guptad975cbc2016-10-27 14:33:19 -0700235
236 /* there's no direct way to distinguish 750 vs. 770 */
237 if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
238 cpu->name = "ARC750";
Vineet Gupta010a8c92017-09-21 17:46:38 -0700239 } else {
240 cpu->isa = isa;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700241 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530242}
243
Vineet Gupta8e457d62013-09-04 16:13:35 +0530244static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530245{
Vineet Guptaaf617422013-01-18 15:12:24 +0530246 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
247 struct bcr_identity *core = &cpu->core;
Vineet Guptaafba5d12018-10-29 09:44:18 -0700248 int i, n = 0, ua = 0;
Vineet Gupta56372082014-09-25 16:54:43 +0530249
Vineet Guptaaf617422013-01-18 15:12:24 +0530250 FIX_PTR(cpu);
251
252 n += scnprintf(buf + n, len - n,
Vineet Gupta56372082014-09-25 16:54:43 +0530253 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
254 core->family, core->cpu_id, core->chip_id);
Vineet Guptaaf617422013-01-18 15:12:24 +0530255
Vineet Guptadea82522017-09-21 18:02:44 -0700256 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
Vineet Guptad975cbc2016-10-27 14:33:19 -0700257 cpu_id, cpu->name, cpu->details,
Vineet Gupta73e284d2016-10-20 17:49:15 -0700258 is_isa_arcompact() ? "ARCompact" : "ARCv2",
Vineet Guptadea82522017-09-21 18:02:44 -0700259 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
Vineet Guptaf3156852017-11-10 12:40:00 -0800260 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530261
Vineet Gupta04421422016-10-31 14:26:41 -0700262 n += scnprintf(buf + n, len - n, "Timers\t\t: %s%s%s%s%s%s\nISA Extn\t: ",
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530263 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
264 IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
Vineet Gupta04421422016-10-31 14:26:41 -0700265 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
266 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
Vineet Guptaaf617422013-01-18 15:12:24 +0530267
Vineet Guptaafba5d12018-10-29 09:44:18 -0700268#ifdef __ARC_UNALIGNED__
269 ua = 1;
270#endif
271 n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s%s",
Vineet Gupta73e284d2016-10-20 17:49:15 -0700272 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530273 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
Vineet Guptaafba5d12018-10-29 09:44:18 -0700274 IS_AVAIL1(cpu->isa.unalign, "unalign "), IS_USED_RUN(ua));
Vineet Guptaaf617422013-01-18 15:12:24 +0530275
Vineet Gupta56372082014-09-25 16:54:43 +0530276 if (i)
277 n += scnprintf(buf + n, len - n, "\n\t\t: ");
278
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530279 if (cpu->extn_mpy.ver) {
280 if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */
281 n += scnprintf(buf + n, len - n, "mpy ");
282 } else {
283 int opt = 2; /* stock MPY/MPYH */
284
285 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
286 opt = cpu->extn_mpy.dsp + 6;
287
288 n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt);
289 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530290 }
291
Vineet Gupta56372082014-09-25 16:54:43 +0530292 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530293 IS_AVAIL1(cpu->isa.div_rem, "div_rem "),
Vineet Gupta56372082014-09-25 16:54:43 +0530294 IS_AVAIL1(cpu->extn.norm, "norm "),
295 IS_AVAIL1(cpu->extn.barrel, "barrel-shift "),
296 IS_AVAIL1(cpu->extn.swap, "swap "),
297 IS_AVAIL1(cpu->extn.minmax, "minmax "),
298 IS_AVAIL1(cpu->extn.crc, "crc "),
Vineet Guptaa024fd92016-10-20 18:08:10 -0700299 IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
Vineet Gupta56372082014-09-25 16:54:43 +0530300
301 if (cpu->bpu.ver)
302 n += scnprintf(buf + n, len - n,
Vineet Gupta97e98132018-12-06 00:17:50 -0800303 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d",
Vineet Gupta56372082014-09-25 16:54:43 +0530304 IS_AVAIL1(cpu->bpu.full, "full"),
305 IS_AVAIL1(!cpu->bpu.full, "partial"),
Vineet Gupta97e98132018-12-06 00:17:50 -0800306 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk);
Vineet Guptaaf617422013-01-18 15:12:24 +0530307
Vineet Guptaf3156852017-11-10 12:40:00 -0800308 if (is_isa_arcv2()) {
309 struct bcr_lpb lpb;
310
311 READ_BCR(ARC_REG_LPB_BUILD, lpb);
312 if (lpb.ver) {
313 unsigned int ctl;
314 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
315
316 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
317 lpb.entries,
318 IS_DISABLED_RUN(!ctl));
319 }
320 }
321
322 n += scnprintf(buf + n, len - n, "\n");
Vineet Guptaaf617422013-01-18 15:12:24 +0530323 return buf;
324}
325
Vineet Gupta8e457d62013-09-04 16:13:35 +0530326static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530327{
328 int n = 0;
329 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
330
331 FIX_PTR(cpu);
Vineet Guptaaf617422013-01-18 15:12:24 +0530332
Vineet Gupta711c1f22016-10-13 15:53:02 -0700333 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
Vineet Guptaaf617422013-01-18 15:12:24 +0530334
Vineet Gupta56372082014-09-25 16:54:43 +0530335 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
336 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
337 IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
338 IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530339
Vineet Gupta56372082014-09-25 16:54:43 +0530340 if (cpu->extn.debug)
341 n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s%s\n",
342 IS_AVAIL1(cpu->extn.ap, "ActionPoint "),
343 IS_AVAIL1(cpu->extn.smart, "smaRT "),
344 IS_AVAIL1(cpu->extn.rtt, "RTT "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530345
Vineet Gupta56372082014-09-25 16:54:43 +0530346 if (cpu->dccm.sz || cpu->iccm.sz)
347 n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
348 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
Vineet Guptaaf617422013-01-18 15:12:24 +0530349 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
350
Vineet Guptaf3156852017-11-10 12:40:00 -0800351 if (is_isa_arcv2()) {
352
353 /* Error Protection: ECC/Parity */
354 struct bcr_erp erp;
355 READ_BCR(ARC_REG_ERP_BUILD, erp);
356
357 if (erp.ver) {
358 struct ctl_erp ctl;
359 READ_BCR(ARC_REG_ERP_CTRL, ctl);
360
361 /* inverted bits: 0 means enabled */
362 n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
363 IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
364 IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
365 IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
366 }
367 }
368
Vineet Gupta840c0542016-08-10 14:10:57 -0700369 n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
370 EF_ARC_OSABI_CURRENT >> 8,
371 EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
372 "no-legacy-syscalls" : "64-bit data any register aligned");
Vineet Guptaaf617422013-01-18 15:12:24 +0530373
374 return buf;
375}
376
Vineet Guptac4b98562014-09-25 16:07:44 +0530377static void arc_chk_core_config(void)
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530378{
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530379 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700380 int saved = 0, present = 0;
Luis de Bethencourta46f24a2018-01-23 15:16:09 +0000381 char *opt_nm = NULL;
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530382
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530383 if (!cpu->extn.timer0)
Vineet Gupta56372082014-09-25 16:54:43 +0530384 panic("Timer0 is not present!\n");
385
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530386 if (!cpu->extn.timer1)
Vineet Gupta56372082014-09-25 16:54:43 +0530387 panic("Timer1 is not present!\n");
388
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530389#ifdef CONFIG_ARC_HAS_DCCM
390 /*
391 * DCCM can be arbit placed in hardware.
392 * Make sure it's placement/sz matches what Linux is built with
393 */
394 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
395 panic("Linux built with incorrect DCCM Base address\n");
396
397 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
398 panic("Linux built with incorrect DCCM Size\n");
399#endif
400
401#ifdef CONFIG_ARC_HAS_ICCM
402 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
403 panic("Linux built with incorrect ICCM Size\n");
404#endif
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530405
Vineet Guptac4b98562014-09-25 16:07:44 +0530406 /*
407 * FP hardware/software config sanity
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700408 * -If hardware present, kernel needs to save/restore FPU state
Vineet Guptac4b98562014-09-25 16:07:44 +0530409 * -If not, it will crash trying to save/restore the non-existant regs
Vineet Guptac4b98562014-09-25 16:07:44 +0530410 */
Vineet Guptaaf617422013-01-18 15:12:24 +0530411
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700412 if (is_isa_arcompact()) {
413 opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
414 saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
415
416 /* only DPDP checked since SP has no arch visible regs */
417 present = cpu->extn.fpu_dp;
418 } else {
419 opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
420 saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
421
422 /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
423 present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
424 }
425
426 if (present && !saved)
427 pr_warn("Enable %s for working apps\n", opt_nm);
428 else if (!present && saved)
429 panic("Disable %s, hardware NOT present\n", opt_nm);
Vineet Guptac121c502013-01-18 15:12:20 +0530430}
431
432/*
433 * Initialize and setup the processor core
434 * This is called by all the CPUs thus should not do special case stuff
435 * such as only for boot CPU etc
436 */
437
Paul Gortmakerce759952013-06-24 15:30:15 -0400438void setup_processor(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530439{
Vineet Guptaaf617422013-01-18 15:12:24 +0530440 char str[512];
441 int cpu_id = smp_processor_id();
442
Vineet Guptac121c502013-01-18 15:12:20 +0530443 read_arc_build_cfg_regs();
444 arc_init_IRQ();
Vineet Guptaaf617422013-01-18 15:12:24 +0530445
Noam Camus18ee4be2017-06-15 11:43:51 +0300446 pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
Vineet Guptaaf617422013-01-18 15:12:24 +0530447
Vineet Guptac121c502013-01-18 15:12:20 +0530448 arc_mmu_init();
449 arc_cache_init();
Vineet Guptaaf617422013-01-18 15:12:24 +0530450
Noam Camus18ee4be2017-06-15 11:43:51 +0300451 pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
452 pr_info("%s", arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530453
Vineet Guptac4b98562014-09-25 16:07:44 +0530454 arc_chk_core_config();
Vineet Guptac121c502013-01-18 15:12:20 +0530455}
456
Vineet Gupta59ed9412014-01-16 15:01:24 +0530457static inline int is_kernel(unsigned long addr)
458{
459 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
460 return 1;
461 return 0;
462}
463
Vineet Guptac121c502013-01-18 15:12:20 +0530464void __init setup_arch(char **cmdline_p)
465{
Vineet Gupta036b2c52015-03-09 19:40:09 +0530466#ifdef CONFIG_ARC_UBOOT_SUPPORT
Vineet Guptae57d3392014-01-16 15:04:24 +0530467 /* make sure that uboot passed pointer to cmdline/dtb is valid */
468 if (uboot_tag && is_kernel((unsigned long)uboot_arg))
469 panic("Invalid uboot arg\n");
470
471 /* See if u-boot passed an external Device Tree blob */
472 machine_desc = setup_machine_fdt(uboot_arg); /* uboot_tag == 2 */
Vineet Gupta036b2c52015-03-09 19:40:09 +0530473 if (!machine_desc)
474#endif
475 {
Vineet Guptae57d3392014-01-16 15:04:24 +0530476 /* No, so try the embedded one */
Vineet Gupta59ed9412014-01-16 15:01:24 +0530477 machine_desc = setup_machine_fdt(__dtb_start);
478 if (!machine_desc)
479 panic("Embedded DT invalid\n");
Vineet Gupta999159a2013-01-22 17:00:52 +0530480
Vineet Gupta59ed9412014-01-16 15:01:24 +0530481 /*
Vineet Guptae57d3392014-01-16 15:04:24 +0530482 * If we are here, it is established that @uboot_arg didn't
483 * point to DT blob. Instead if u-boot says it is cmdline,
Andrea Gelmini25474762016-05-21 13:45:35 +0200484 * append to embedded DT cmdline.
Vineet Gupta59ed9412014-01-16 15:01:24 +0530485 * setup_machine_fdt() would have populated @boot_command_line
486 */
487 if (uboot_tag == 1) {
Vineet Gupta59ed9412014-01-16 15:01:24 +0530488 /* Ensure a whitespace between the 2 cmdlines */
489 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
490 strlcat(boot_command_line, uboot_arg,
491 COMMAND_LINE_SIZE);
492 }
Vineet Guptae57d3392014-01-16 15:04:24 +0530493 }
Vineet Gupta9593a932013-04-09 16:18:04 +0530494
495 /* Save unparsed command line copy for /proc/cmdline */
496 *cmdline_p = boot_command_line;
497
Vineet Guptac121c502013-01-18 15:12:20 +0530498 /* To force early parsing of things like mem=xxx */
499 parse_early_param();
500
501 /* Platform/board specific: e.g. early console registration */
Vineet Gupta03a6d282013-01-18 15:12:26 +0530502 if (machine_desc->init_early)
503 machine_desc->init_early();
Vineet Guptac121c502013-01-18 15:12:20 +0530504
Vineet Gupta41195d22013-01-18 15:12:23 +0530505 smp_init_cpus();
Vineet Guptae55af4d2015-10-12 16:28:55 +0530506
507 setup_processor();
Vineet Guptac121c502013-01-18 15:12:20 +0530508 setup_arch_memory();
509
Vineet Guptaeab6a082013-02-21 17:37:06 +0530510 /* copy flat DT out of .init and then unflatten it */
Rob Herring1efc9592013-08-26 11:23:27 -0500511 unflatten_and_copy_device_tree();
Vineet Gupta999159a2013-01-22 17:00:52 +0530512
Vineet Guptac121c502013-01-18 15:12:20 +0530513 /* Can be issue if someone passes cmd line arg "ro"
514 * But that is unlikely so keeping it as it is
515 */
516 root_mountflags &= ~MS_RDONLY;
517
Vineet Guptac121c502013-01-18 15:12:20 +0530518#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
519 conswitchp = &dummy_con;
520#endif
521
Vineet Gupta854a0d92013-01-22 17:03:19 +0530522 arc_unwind_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530523}
524
Vineet Gupta92b03312016-10-31 13:26:25 -0700525/*
526 * Called from start_kernel() - boot CPU only
527 */
528void __init time_init(void)
529{
530 of_clk_init(NULL);
Daniel Lezcanoba5d08c2017-05-26 17:40:46 +0200531 timer_probe();
Vineet Gupta92b03312016-10-31 13:26:25 -0700532}
533
Vineet Gupta03a6d282013-01-18 15:12:26 +0530534static int __init customize_machine(void)
535{
Vineet Gupta03a6d282013-01-18 15:12:26 +0530536 if (machine_desc->init_machine)
537 machine_desc->init_machine();
538
539 return 0;
540}
541arch_initcall(customize_machine);
542
543static int __init init_late_machine(void)
544{
545 if (machine_desc->init_late)
546 machine_desc->init_late();
547
548 return 0;
549}
550late_initcall(init_late_machine);
Vineet Guptac121c502013-01-18 15:12:20 +0530551/*
552 * Get CPU information for use by the procfs.
553 */
554
555#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
556#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
557
558static int show_cpuinfo(struct seq_file *m, void *v)
559{
560 char *str;
561 int cpu_id = ptr_to_cpu(v);
Vlad Zakharov7f351442017-03-03 14:30:02 +0300562 struct device *cpu_dev = get_cpu_device(cpu_id);
563 struct clk *cpu_clk;
564 unsigned long freq = 0;
Vineet Guptac121c502013-01-18 15:12:20 +0530565
Vineet Gupta4c862312014-12-12 10:05:03 +0530566 if (!cpu_online(cpu_id)) {
567 seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
568 goto done;
569 }
570
Michal Hocko0ee931c2017-09-13 16:28:29 -0700571 str = (char *)__get_free_page(GFP_KERNEL);
Vineet Guptac121c502013-01-18 15:12:20 +0530572 if (!str)
573 goto done;
574
Vineet Guptaaf617422013-01-18 15:12:24 +0530575 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptac121c502013-01-18 15:12:20 +0530576
Vlad Zakharov7f351442017-03-03 14:30:02 +0300577 cpu_clk = clk_get(cpu_dev, NULL);
578 if (IS_ERR(cpu_clk)) {
579 seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
580 cpu_id);
581 } else {
582 freq = clk_get_rate(cpu_clk);
583 }
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300584 if (freq)
Vlad Zakharov7f351442017-03-03 14:30:02 +0300585 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300586 freq / 1000000, (freq / 10000) % 100);
587
Vineet Gupta56372082014-09-25 16:54:43 +0530588 seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
Vineet Guptac121c502013-01-18 15:12:20 +0530589 loops_per_jiffy / (500000 / HZ),
590 (loops_per_jiffy / (5000 / HZ)) % 100);
591
Vineet Guptaaf617422013-01-18 15:12:24 +0530592 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530593 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530594 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530595 seq_printf(m, arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530596
Vineet Guptac121c502013-01-18 15:12:20 +0530597 free_page((unsigned long)str);
598done:
Vineet Gupta4c862312014-12-12 10:05:03 +0530599 seq_printf(m, "\n");
Vineet Guptac121c502013-01-18 15:12:20 +0530600
601 return 0;
602}
603
604static void *c_start(struct seq_file *m, loff_t *pos)
605{
606 /*
607 * Callback returns cpu-id to iterator for show routine, NULL to stop.
608 * However since NULL is also a valid cpu-id (0), we use a round-about
609 * way to pass it w/o having to kmalloc/free a 2 byte string.
610 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
611 */
Noam Camus3da431042016-10-19 14:25:03 +0300612 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
Vineet Guptac121c502013-01-18 15:12:20 +0530613}
614
615static void *c_next(struct seq_file *m, void *v, loff_t *pos)
616{
617 ++*pos;
618 return c_start(m, pos);
619}
620
621static void c_stop(struct seq_file *m, void *v)
622{
623}
624
625const struct seq_operations cpuinfo_op = {
626 .start = c_start,
627 .next = c_next,
628 .stop = c_stop,
629 .show = show_cpuinfo
630};
631
632static DEFINE_PER_CPU(struct cpu, cpu_topology);
633
634static int __init topology_init(void)
635{
636 int cpu;
637
638 for_each_present_cpu(cpu)
639 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
640
641 return 0;
642}
643
644subsys_initcall(topology_init);