blob: b2b1cb645d9e90c4d41cb7e03226eee1fe361a88 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Vineet Guptac121c502013-01-18 15:12:20 +05302/*
3 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
Vineet Guptac121c502013-01-18 15:12:20 +05304 */
5
6#include <linux/seq_file.h>
7#include <linux/fs.h>
8#include <linux/delay.h>
9#include <linux/root_dev.h>
Vlad Zakharov7f351442017-03-03 14:30:02 +030010#include <linux/clk.h>
Vineet Gupta92b03312016-10-31 13:26:25 -070011#include <linux/clocksource.h>
Vineet Guptac121c502013-01-18 15:12:20 +053012#include <linux/console.h>
13#include <linux/module.h>
14#include <linux/cpu.h>
Geert Uytterhoeven3b00b042020-02-12 11:00:47 +010015#include <linux/of_clk.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053016#include <linux/of_fdt.h>
Vineet Gupta1ce0b582016-07-13 13:21:20 -070017#include <linux/of.h>
Sachin Kamat1ec9db12013-03-06 16:53:44 +053018#include <linux/cache.h>
David Howellse262e32d2018-11-01 23:07:23 +000019#include <uapi/linux/mount.h>
Vineet Gupta999159a2013-01-22 17:00:52 +053020#include <asm/sections.h>
Vineet Guptac121c502013-01-18 15:12:20 +053021#include <asm/arcregs.h>
Eugeniy Paltsev240c84b2020-03-05 23:02:49 +030022#include <asm/asserts.h>
Vineet Guptac121c502013-01-18 15:12:20 +053023#include <asm/tlb.h>
Vineet Guptac121c502013-01-18 15:12:20 +053024#include <asm/setup.h>
25#include <asm/page.h>
26#include <asm/irq.h>
Vineet Gupta854a0d92013-01-22 17:03:19 +053027#include <asm/unwind.h>
Vineet Gupta03a6d282013-01-18 15:12:26 +053028#include <asm/mach_desc.h>
Vineet Gupta619f3012014-09-04 10:57:33 +053029#include <asm/smp.h>
Eugeniy Paltsev4827d0c2020-03-05 23:02:50 +030030#include <asm/dsp-impl.h>
Vineet Guptac121c502013-01-18 15:12:20 +053031
32#define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
33
Vineet Gupta4255b072014-09-22 16:51:47 +053034unsigned int intr_to_DE_cnt;
35
Vineet Gupta59ed9412014-01-16 15:01:24 +053036/* Part of U-boot ABI: see head.S */
37int __initdata uboot_tag;
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +030038int __initdata uboot_magic;
Vineet Gupta59ed9412014-01-16 15:01:24 +053039char __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 Gupta00a4ae62019-02-25 11:24:05 -080047static const struct id_to_str arc_legacy_rel[] = {
48 /* ID.ARCVER, Release */
Vineet Gupta73e284d2016-10-20 17:49:15 -070049#ifdef CONFIG_ISA_ARCOMPACT
Vineet Gupta00a4ae62019-02-25 11:24:05 -080050 { 0x34, "R4.10"},
51 { 0x35, "R4.11"},
Vineet Gupta73e284d2016-10-20 17:49:15 -070052#else
Vineet Gupta00a4ae62019-02-25 11:24:05 -080053 { 0x51, "R2.0" },
54 { 0x52, "R2.1" },
55 { 0x53, "R3.0" },
Vineet Gupta73e284d2016-10-20 17:49:15 -070056#endif
Vineet Gupta00a4ae62019-02-25 11:24:05 -080057 { 0x00, NULL }
Vineet Guptad975cbc2016-10-27 14:33:19 -070058};
59
Vineet Gupta00a4ae62019-02-25 11:24:05 -080060static const struct id_to_str arc_cpu_rel[] = {
61 /* UARCH.MAJOR, Release */
62 { 0, "R3.10a"},
63 { 1, "R3.50a"},
64 { 0xFF, NULL }
Vineet Gupta73e284d2016-10-20 17:49:15 -070065};
66
Vineet Guptaa150b082016-02-16 12:36:18 +053067static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
68{
69 if (is_isa_arcompact()) {
70 struct bcr_iccm_arcompact iccm;
71 struct bcr_dccm_arcompact dccm;
72
73 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
74 if (iccm.ver) {
75 cpu->iccm.sz = 4096 << iccm.sz; /* 8K to 512K */
76 cpu->iccm.base_addr = iccm.base << 16;
77 }
78
79 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
80 if (dccm.ver) {
81 unsigned long base;
82 cpu->dccm.sz = 2048 << dccm.sz; /* 2K to 256K */
83
84 base = read_aux_reg(ARC_REG_DCCM_BASE_BUILD);
85 cpu->dccm.base_addr = base & ~0xF;
86 }
87 } else {
88 struct bcr_iccm_arcv2 iccm;
89 struct bcr_dccm_arcv2 dccm;
90 unsigned long region;
91
92 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
93 if (iccm.ver) {
94 cpu->iccm.sz = 256 << iccm.sz00; /* 512B to 16M */
95 if (iccm.sz00 == 0xF && iccm.sz01 > 0)
96 cpu->iccm.sz <<= iccm.sz01;
97
98 region = read_aux_reg(ARC_REG_AUX_ICCM);
99 cpu->iccm.base_addr = region & 0xF0000000;
100 }
101
102 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
103 if (dccm.ver) {
104 cpu->dccm.sz = 256 << dccm.sz0;
105 if (dccm.sz0 == 0xF && dccm.sz1 > 0)
106 cpu->dccm.sz <<= dccm.sz1;
107
108 region = read_aux_reg(ARC_REG_AUX_DCCM);
109 cpu->dccm.base_addr = region & 0xF0000000;
110 }
111 }
112}
113
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800114static void decode_arc_core(struct cpuinfo_arc *cpu)
115{
116 struct bcr_uarch_build_arcv2 uarch;
117 const struct id_to_str *tbl;
118
119 /*
120 * Up until (including) the first core4 release (0x54) things were
121 * simple: AUX IDENTITY.ARCVER was sufficient to identify arc family
122 * and release: 0x50 to 0x53 was HS38, 0x54 was HS48 (dual issue)
123 */
124
125 if (cpu->core.family < 0x54) { /* includes arc700 */
126
127 for (tbl = &arc_legacy_rel[0]; tbl->id != 0; tbl++) {
128 if (cpu->core.family == tbl->id) {
129 cpu->release = tbl->str;
130 break;
131 }
132 }
133
134 if (is_isa_arcompact())
135 cpu->name = "ARC700";
136 else if (tbl->str)
137 cpu->name = "HS38";
138 else
139 cpu->name = cpu->release = "Unknown";
140
141 return;
142 }
143
144 /*
145 * However the subsequent HS release (same 0x54) allow HS38 or HS48
146 * configurations and encode this info in a different BCR.
147 * The BCR was introduced in 0x54 so can't be read unconditionally.
148 */
149
150 READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
151
152 if (uarch.prod == 4) {
153 cpu->name = "HS48";
154 cpu->extn.dual = 1;
155
156 } else {
157 cpu->name = "HS38";
158 }
159
160 for (tbl = &arc_cpu_rel[0]; tbl->id != 0xFF; tbl++) {
161 if (uarch.maj == tbl->id) {
162 cpu->release = tbl->str;
163 break;
164 }
165 }
166}
167
Vineet Gupta8e457d62013-09-04 16:13:35 +0530168static void read_arc_build_cfg_regs(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530169{
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530170 struct bcr_timer timer;
Vineet Gupta56372082014-09-25 16:54:43 +0530171 struct bcr_generic bcr;
Vineet Guptaaf617422013-01-18 15:12:24 +0530172 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Gupta010a8c92017-09-21 17:46:38 -0700173 struct bcr_isa_arcv2 isa;
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800174 struct bcr_actionpoint ap;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700175
Vineet Guptaaf617422013-01-18 15:12:24 +0530176 FIX_PTR(cpu);
177
178 READ_BCR(AUX_IDENTITY, cpu->core);
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800179 decode_arc_core(cpu);
Vineet Gupta73e284d2016-10-20 17:49:15 -0700180
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530181 READ_BCR(ARC_REG_TIMERS_BCR, timer);
182 cpu->extn.timer0 = timer.t0;
183 cpu->extn.timer1 = timer.t1;
184 cpu->extn.rtc = timer.rtc;
185
Vineet Guptaaf617422013-01-18 15:12:24 +0530186 cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
Vineet Guptaaf617422013-01-18 15:12:24 +0530187
Vineet Gupta56372082014-09-25 16:54:43 +0530188 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
Vineet Guptaaf617422013-01-18 15:12:24 +0530189
Vineet Guptaa150b082016-02-16 12:36:18 +0530190 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
191 read_decode_ccm_bcr(cpu);
192
Vineet Guptac121c502013-01-18 15:12:20 +0530193 read_decode_mmu_bcr();
194 read_decode_cache_bcr();
Vineet Guptaaf617422013-01-18 15:12:24 +0530195
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530196 if (is_isa_arcompact()) {
Vineet Gupta56372082014-09-25 16:54:43 +0530197 struct bcr_fp_arcompact sp, dp;
198 struct bcr_bpu_arcompact bpu;
199
200 READ_BCR(ARC_REG_FP_BCR, sp);
201 READ_BCR(ARC_REG_DPFP_BCR, dp);
202 cpu->extn.fpu_sp = sp.ver ? 1 : 0;
203 cpu->extn.fpu_dp = dp.ver ? 1 : 0;
204
205 READ_BCR(ARC_REG_BPU_BCR, bpu);
206 cpu->bpu.ver = bpu.ver;
207 cpu->bpu.full = bpu.fam ? 1 : 0;
208 if (bpu.ent) {
209 cpu->bpu.num_cache = 256 << (bpu.ent - 1);
210 cpu->bpu.num_pred = 256 << (bpu.ent - 1);
211 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530212 } else {
213 struct bcr_fp_arcv2 spdp;
214 struct bcr_bpu_arcv2 bpu;
215
216 READ_BCR(ARC_REG_FP_V2_BCR, spdp);
217 cpu->extn.fpu_sp = spdp.sp ? 1 : 0;
218 cpu->extn.fpu_dp = spdp.dp ? 1 : 0;
219
220 READ_BCR(ARC_REG_BPU_BCR, bpu);
221 cpu->bpu.ver = bpu.ver;
222 cpu->bpu.full = bpu.ft;
223 cpu->bpu.num_cache = 256 << bpu.bce;
224 cpu->bpu.num_pred = 2048 << bpu.pte;
Vineet Gupta97e98132018-12-06 00:17:50 -0800225 cpu->bpu.ret_stk = 4 << bpu.rse;
Vineet Guptadea82522017-09-21 18:02:44 -0700226
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800227 /* if dual issue hardware, is it enabled ? */
228 if (cpu->extn.dual) {
229 unsigned int exec_ctrl;
Vineet Guptadea82522017-09-21 18:02:44 -0700230
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800231 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
232 cpu->extn.dual_enb = !(exec_ctrl & 1);
Vineet Guptadea82522017-09-21 18:02:44 -0700233 }
Vineet Gupta56372082014-09-25 16:54:43 +0530234 }
235
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800236 READ_BCR(ARC_REG_AP_BCR, ap);
237 if (ap.ver) {
238 cpu->extn.ap_num = 2 << ap.num;
Eugeniy Paltsevcdf92962019-02-04 21:41:51 +0300239 cpu->extn.ap_full = !ap.min;
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800240 }
Vineet Gupta56372082014-09-25 16:54:43 +0530241
242 READ_BCR(ARC_REG_SMART_BCR, bcr);
243 cpu->extn.smart = bcr.ver ? 1 : 0;
244
Vineet Guptaa44ec8bd2015-03-08 14:18:21 +0530245 READ_BCR(ARC_REG_RTT_BCR, bcr);
246 cpu->extn.rtt = bcr.ver ? 1 : 0;
247
Vineet Gupta010a8c92017-09-21 17:46:38 -0700248 READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
249
Vineet Gupta73e284d2016-10-20 17:49:15 -0700250 /* some hacks for lack of feature BCR info in old ARC700 cores */
251 if (is_isa_arcompact()) {
Vineet Gupta010a8c92017-09-21 17:46:38 -0700252 if (!isa.ver) /* ISA BCR absent, use Kconfig info */
Vineet Gupta73e284d2016-10-20 17:49:15 -0700253 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
Vineet Gupta010a8c92017-09-21 17:46:38 -0700254 else {
255 /* ARC700_BUILD only has 2 bits of isa info */
256 struct bcr_generic bcr = *(struct bcr_generic *)&isa;
257 cpu->isa.atomic = bcr.info & 1;
258 }
Vineet Gupta73e284d2016-10-20 17:49:15 -0700259
260 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
Vineet Guptad975cbc2016-10-27 14:33:19 -0700261
262 /* there's no direct way to distinguish 750 vs. 770 */
263 if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
264 cpu->name = "ARC750";
Vineet Gupta010a8c92017-09-21 17:46:38 -0700265 } else {
266 cpu->isa = isa;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700267 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530268}
269
Vineet Gupta8e457d62013-09-04 16:13:35 +0530270static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530271{
Vineet Guptaaf617422013-01-18 15:12:24 +0530272 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
273 struct bcr_identity *core = &cpu->core;
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800274 char mpy_opt[16];
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300275 int n = 0;
Vineet Gupta56372082014-09-25 16:54:43 +0530276
Vineet Guptaaf617422013-01-18 15:12:24 +0530277 FIX_PTR(cpu);
278
279 n += scnprintf(buf + n, len - n,
Vineet Gupta56372082014-09-25 16:54:43 +0530280 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
281 core->family, core->cpu_id, core->chip_id);
Vineet Guptaaf617422013-01-18 15:12:24 +0530282
Vineet Guptadea82522017-09-21 18:02:44 -0700283 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800284 cpu_id, cpu->name, cpu->release,
Vineet Gupta73e284d2016-10-20 17:49:15 -0700285 is_isa_arcompact() ? "ARCompact" : "ARCv2",
Vineet Guptadea82522017-09-21 18:02:44 -0700286 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
Vineet Guptaf3156852017-11-10 12:40:00 -0800287 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530288
Vineet Gupta04421422016-10-31 14:26:41 -0700289 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 +0530290 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
291 IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
Vineet Gupta04421422016-10-31 14:26:41 -0700292 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
293 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
Vineet Guptaaf617422013-01-18 15:12:24 +0530294
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800295 if (cpu->extn_mpy.ver) {
296 if (is_isa_arcompact()) {
297 scnprintf(mpy_opt, 16, "mpy");
298 } else {
299
300 int opt = 2; /* stock MPY/MPYH */
301
302 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
303 opt = cpu->extn_mpy.dsp + 6;
304
305 scnprintf(mpy_opt, 16, "mpy[opt %d] ", opt);
306 }
307 }
308
309 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300310 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
311 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800312 IS_AVAIL2(cpu->isa.unalign, "unalign ", CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS),
313 IS_AVAIL1(cpu->extn_mpy.ver, mpy_opt),
314 IS_AVAIL1(cpu->isa.div_rem, "div_rem "));
315
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800316 if (cpu->bpu.ver) {
Vineet Gupta56372082014-09-25 16:54:43 +0530317 n += scnprintf(buf + n, len - n,
Vineet Gupta97e98132018-12-06 00:17:50 -0800318 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d",
Vineet Gupta56372082014-09-25 16:54:43 +0530319 IS_AVAIL1(cpu->bpu.full, "full"),
320 IS_AVAIL1(!cpu->bpu.full, "partial"),
Vineet Gupta97e98132018-12-06 00:17:50 -0800321 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk);
Vineet Guptaaf617422013-01-18 15:12:24 +0530322
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800323 if (is_isa_arcv2()) {
324 struct bcr_lpb lpb;
Vineet Guptaf3156852017-11-10 12:40:00 -0800325
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800326 READ_BCR(ARC_REG_LPB_BUILD, lpb);
327 if (lpb.ver) {
328 unsigned int ctl;
329 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
Vineet Guptaf3156852017-11-10 12:40:00 -0800330
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800331 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
332 lpb.entries,
333 IS_DISABLED_RUN(!ctl));
334 }
Vineet Guptaf3156852017-11-10 12:40:00 -0800335 }
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800336 n += scnprintf(buf + n, len - n, "\n");
Vineet Guptaf3156852017-11-10 12:40:00 -0800337 }
338
Vineet Guptaaf617422013-01-18 15:12:24 +0530339 return buf;
340}
341
Vineet Gupta8e457d62013-09-04 16:13:35 +0530342static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530343{
344 int n = 0;
345 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
346
347 FIX_PTR(cpu);
Vineet Guptaaf617422013-01-18 15:12:24 +0530348
Vineet Gupta711c1f22016-10-13 15:53:02 -0700349 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
Vineet Guptaaf617422013-01-18 15:12:24 +0530350
Vineet Gupta56372082014-09-25 16:54:43 +0530351 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
352 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
353 IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
354 IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530355
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800356 if (cpu->extn.ap_num | cpu->extn.smart | cpu->extn.rtt) {
357 n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s",
Vineet Gupta56372082014-09-25 16:54:43 +0530358 IS_AVAIL1(cpu->extn.smart, "smaRT "),
359 IS_AVAIL1(cpu->extn.rtt, "RTT "));
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800360 if (cpu->extn.ap_num) {
361 n += scnprintf(buf + n, len - n, "ActionPoint %d/%s",
362 cpu->extn.ap_num,
363 cpu->extn.ap_full ? "full":"min");
364 }
365 n += scnprintf(buf + n, len - n, "\n");
366 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530367
Vineet Gupta56372082014-09-25 16:54:43 +0530368 if (cpu->dccm.sz || cpu->iccm.sz)
369 n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
370 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
Vineet Guptaaf617422013-01-18 15:12:24 +0530371 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
372
Vineet Guptaf3156852017-11-10 12:40:00 -0800373 if (is_isa_arcv2()) {
374
375 /* Error Protection: ECC/Parity */
376 struct bcr_erp erp;
377 READ_BCR(ARC_REG_ERP_BUILD, erp);
378
379 if (erp.ver) {
380 struct ctl_erp ctl;
381 READ_BCR(ARC_REG_ERP_CTRL, ctl);
382
383 /* inverted bits: 0 means enabled */
384 n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
385 IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
386 IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
387 IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
388 }
389 }
390
Vineet Guptaaf617422013-01-18 15:12:24 +0530391 return buf;
392}
393
Eugeniy Paltsev240c84b2020-03-05 23:02:49 +0300394void chk_opt_strict(char *opt_name, bool hw_exists, bool opt_ena)
395{
396 if (hw_exists && !opt_ena)
397 pr_warn(" ! Enable %s for working apps\n", opt_name);
398 else if (!hw_exists && opt_ena)
399 panic("Disable %s, hardware NOT present\n", opt_name);
400}
401
Eugeniy Paltsevf09d3172020-03-05 23:02:52 +0300402void chk_opt_weak(char *opt_name, bool hw_exists, bool opt_ena)
403{
404 if (!hw_exists && opt_ena)
405 panic("Disable %s, hardware NOT present\n", opt_name);
406}
407
Vineet Guptac4b98562014-09-25 16:07:44 +0530408static void arc_chk_core_config(void)
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530409{
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530410 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Eugeniy Paltsev240c84b2020-03-05 23:02:49 +0300411 int present = 0;
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530412
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530413 if (!cpu->extn.timer0)
Vineet Gupta56372082014-09-25 16:54:43 +0530414 panic("Timer0 is not present!\n");
415
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530416 if (!cpu->extn.timer1)
Vineet Gupta56372082014-09-25 16:54:43 +0530417 panic("Timer1 is not present!\n");
418
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530419#ifdef CONFIG_ARC_HAS_DCCM
420 /*
421 * DCCM can be arbit placed in hardware.
422 * Make sure it's placement/sz matches what Linux is built with
423 */
424 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
425 panic("Linux built with incorrect DCCM Base address\n");
426
427 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
428 panic("Linux built with incorrect DCCM Size\n");
429#endif
430
431#ifdef CONFIG_ARC_HAS_ICCM
432 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
433 panic("Linux built with incorrect ICCM Size\n");
434#endif
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530435
Vineet Guptac4b98562014-09-25 16:07:44 +0530436 /*
437 * FP hardware/software config sanity
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700438 * -If hardware present, kernel needs to save/restore FPU state
Vineet Guptac4b98562014-09-25 16:07:44 +0530439 * -If not, it will crash trying to save/restore the non-existant regs
Vineet Guptac4b98562014-09-25 16:07:44 +0530440 */
Vineet Guptaaf617422013-01-18 15:12:24 +0530441
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700442 if (is_isa_arcompact()) {
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700443 /* only DPDP checked since SP has no arch visible regs */
444 present = cpu->extn.fpu_dp;
Eugeniy Paltsev240c84b2020-03-05 23:02:49 +0300445 CHK_OPT_STRICT(CONFIG_ARC_FPU_SAVE_RESTORE, present);
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700446 } else {
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700447 /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
448 present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
Eugeniy Paltsev240c84b2020-03-05 23:02:49 +0300449 CHK_OPT_STRICT(CONFIG_ARC_HAS_ACCL_REGS, present);
Eugeniy Paltsev4827d0c2020-03-05 23:02:50 +0300450
451 dsp_config_check();
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700452 }
Vineet Guptac121c502013-01-18 15:12:20 +0530453}
454
455/*
456 * Initialize and setup the processor core
457 * This is called by all the CPUs thus should not do special case stuff
458 * such as only for boot CPU etc
459 */
460
Paul Gortmakerce759952013-06-24 15:30:15 -0400461void setup_processor(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530462{
Vineet Guptaaf617422013-01-18 15:12:24 +0530463 char str[512];
464 int cpu_id = smp_processor_id();
465
Vineet Guptac121c502013-01-18 15:12:20 +0530466 read_arc_build_cfg_regs();
467 arc_init_IRQ();
Vineet Guptaaf617422013-01-18 15:12:24 +0530468
Noam Camus18ee4be2017-06-15 11:43:51 +0300469 pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
Vineet Guptaaf617422013-01-18 15:12:24 +0530470
Vineet Guptac121c502013-01-18 15:12:20 +0530471 arc_mmu_init();
472 arc_cache_init();
Vineet Guptaaf617422013-01-18 15:12:24 +0530473
Noam Camus18ee4be2017-06-15 11:43:51 +0300474 pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
475 pr_info("%s", arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530476
Vineet Guptac4b98562014-09-25 16:07:44 +0530477 arc_chk_core_config();
Vineet Guptac121c502013-01-18 15:12:20 +0530478}
479
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300480static inline bool uboot_arg_invalid(unsigned long addr)
Vineet Gupta59ed9412014-01-16 15:01:24 +0530481{
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300482 /*
483 * Check that it is a untranslated address (although MMU is not enabled
484 * yet, it being a high address ensures this is not by fluke)
485 */
486 if (addr < PAGE_OFFSET)
487 return true;
488
489 /* Check that address doesn't clobber resident kernel image */
490 return addr >= (unsigned long)_stext && addr <= (unsigned long)_end;
491}
492
493#define IGNORE_ARGS "Ignore U-boot args: "
494
495/* uboot_tag values for U-boot - kernel ABI revision 0; see head.S */
496#define UBOOT_TAG_NONE 0
497#define UBOOT_TAG_CMDLINE 1
498#define UBOOT_TAG_DTB 2
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300499/* We always pass 0 as magic from U-boot */
500#define UBOOT_MAGIC_VALUE 0
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300501
502void __init handle_uboot_args(void)
503{
504 bool use_embedded_dtb = true;
505 bool append_cmdline = false;
506
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300507 /* check that we know this tag */
508 if (uboot_tag != UBOOT_TAG_NONE &&
509 uboot_tag != UBOOT_TAG_CMDLINE &&
510 uboot_tag != UBOOT_TAG_DTB) {
511 pr_warn(IGNORE_ARGS "invalid uboot tag: '%08x'\n", uboot_tag);
512 goto ignore_uboot_args;
513 }
514
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300515 if (uboot_magic != UBOOT_MAGIC_VALUE) {
516 pr_warn(IGNORE_ARGS "non zero uboot magic\n");
517 goto ignore_uboot_args;
518 }
519
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300520 if (uboot_tag != UBOOT_TAG_NONE &&
521 uboot_arg_invalid((unsigned long)uboot_arg)) {
522 pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg);
523 goto ignore_uboot_args;
524 }
525
526 /* see if U-boot passed an external Device Tree blob */
527 if (uboot_tag == UBOOT_TAG_DTB) {
528 machine_desc = setup_machine_fdt((void *)uboot_arg);
529
530 /* external Device Tree blob is invalid - use embedded one */
531 use_embedded_dtb = !machine_desc;
532 }
533
534 if (uboot_tag == UBOOT_TAG_CMDLINE)
535 append_cmdline = true;
536
537ignore_uboot_args:
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300538
539 if (use_embedded_dtb) {
540 machine_desc = setup_machine_fdt(__dtb_start);
541 if (!machine_desc)
542 panic("Embedded DT invalid\n");
543 }
544
545 /*
546 * NOTE: @boot_command_line is populated by setup_machine_fdt() so this
547 * append processing can only happen after.
548 */
549 if (append_cmdline) {
550 /* Ensure a whitespace between the 2 cmdlines */
551 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
552 strlcat(boot_command_line, uboot_arg, COMMAND_LINE_SIZE);
553 }
Vineet Gupta59ed9412014-01-16 15:01:24 +0530554}
555
Vineet Guptac121c502013-01-18 15:12:20 +0530556void __init setup_arch(char **cmdline_p)
557{
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300558 handle_uboot_args();
Vineet Gupta9593a932013-04-09 16:18:04 +0530559
560 /* Save unparsed command line copy for /proc/cmdline */
561 *cmdline_p = boot_command_line;
562
Vineet Guptac121c502013-01-18 15:12:20 +0530563 /* To force early parsing of things like mem=xxx */
564 parse_early_param();
565
566 /* Platform/board specific: e.g. early console registration */
Vineet Gupta03a6d282013-01-18 15:12:26 +0530567 if (machine_desc->init_early)
568 machine_desc->init_early();
Vineet Guptac121c502013-01-18 15:12:20 +0530569
Vineet Gupta41195d22013-01-18 15:12:23 +0530570 smp_init_cpus();
Vineet Guptae55af4d2015-10-12 16:28:55 +0530571
572 setup_processor();
Vineet Guptac121c502013-01-18 15:12:20 +0530573 setup_arch_memory();
574
Vineet Guptaeab6a082013-02-21 17:37:06 +0530575 /* copy flat DT out of .init and then unflatten it */
Rob Herring1efc9592013-08-26 11:23:27 -0500576 unflatten_and_copy_device_tree();
Vineet Gupta999159a2013-01-22 17:00:52 +0530577
Vineet Guptac121c502013-01-18 15:12:20 +0530578 /* Can be issue if someone passes cmd line arg "ro"
579 * But that is unlikely so keeping it as it is
580 */
581 root_mountflags &= ~MS_RDONLY;
582
Vineet Gupta854a0d92013-01-22 17:03:19 +0530583 arc_unwind_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530584}
585
Vineet Gupta92b03312016-10-31 13:26:25 -0700586/*
587 * Called from start_kernel() - boot CPU only
588 */
589void __init time_init(void)
590{
591 of_clk_init(NULL);
Daniel Lezcanoba5d08c2017-05-26 17:40:46 +0200592 timer_probe();
Vineet Gupta92b03312016-10-31 13:26:25 -0700593}
594
Vineet Gupta03a6d282013-01-18 15:12:26 +0530595static int __init customize_machine(void)
596{
Vineet Gupta03a6d282013-01-18 15:12:26 +0530597 if (machine_desc->init_machine)
598 machine_desc->init_machine();
599
600 return 0;
601}
602arch_initcall(customize_machine);
603
604static int __init init_late_machine(void)
605{
606 if (machine_desc->init_late)
607 machine_desc->init_late();
608
609 return 0;
610}
611late_initcall(init_late_machine);
Vineet Guptac121c502013-01-18 15:12:20 +0530612/*
613 * Get CPU information for use by the procfs.
614 */
615
616#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
617#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
618
619static int show_cpuinfo(struct seq_file *m, void *v)
620{
621 char *str;
622 int cpu_id = ptr_to_cpu(v);
Vlad Zakharov7f351442017-03-03 14:30:02 +0300623 struct device *cpu_dev = get_cpu_device(cpu_id);
624 struct clk *cpu_clk;
625 unsigned long freq = 0;
Vineet Guptac121c502013-01-18 15:12:20 +0530626
Vineet Gupta4c862312014-12-12 10:05:03 +0530627 if (!cpu_online(cpu_id)) {
628 seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
629 goto done;
630 }
631
Michal Hocko0ee931c2017-09-13 16:28:29 -0700632 str = (char *)__get_free_page(GFP_KERNEL);
Vineet Guptac121c502013-01-18 15:12:20 +0530633 if (!str)
634 goto done;
635
Vineet Guptaaf617422013-01-18 15:12:24 +0530636 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptac121c502013-01-18 15:12:20 +0530637
Vlad Zakharov7f351442017-03-03 14:30:02 +0300638 cpu_clk = clk_get(cpu_dev, NULL);
639 if (IS_ERR(cpu_clk)) {
640 seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
641 cpu_id);
642 } else {
643 freq = clk_get_rate(cpu_clk);
644 }
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300645 if (freq)
Vlad Zakharov7f351442017-03-03 14:30:02 +0300646 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300647 freq / 1000000, (freq / 10000) % 100);
648
Vineet Gupta56372082014-09-25 16:54:43 +0530649 seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
Vineet Guptac121c502013-01-18 15:12:20 +0530650 loops_per_jiffy / (500000 / HZ),
651 (loops_per_jiffy / (5000 / HZ)) % 100);
652
Vineet Guptaaf617422013-01-18 15:12:24 +0530653 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530654 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530655 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530656 seq_printf(m, arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530657
Vineet Guptac121c502013-01-18 15:12:20 +0530658 free_page((unsigned long)str);
659done:
Vineet Gupta4c862312014-12-12 10:05:03 +0530660 seq_printf(m, "\n");
Vineet Guptac121c502013-01-18 15:12:20 +0530661
662 return 0;
663}
664
665static void *c_start(struct seq_file *m, loff_t *pos)
666{
667 /*
668 * Callback returns cpu-id to iterator for show routine, NULL to stop.
669 * However since NULL is also a valid cpu-id (0), we use a round-about
670 * way to pass it w/o having to kmalloc/free a 2 byte string.
671 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
672 */
Noam Camus3da43102016-10-19 14:25:03 +0300673 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
Vineet Guptac121c502013-01-18 15:12:20 +0530674}
675
676static void *c_next(struct seq_file *m, void *v, loff_t *pos)
677{
678 ++*pos;
679 return c_start(m, pos);
680}
681
682static void c_stop(struct seq_file *m, void *v)
683{
684}
685
686const struct seq_operations cpuinfo_op = {
687 .start = c_start,
688 .next = c_next,
689 .stop = c_stop,
690 .show = show_cpuinfo
691};
692
693static DEFINE_PER_CPU(struct cpu, cpu_topology);
694
695static int __init topology_init(void)
696{
697 int cpu;
698
699 for_each_present_cpu(cpu)
700 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
701
702 return 0;
703}
704
705subsys_initcall(topology_init);