blob: 714dc5c2baf16feea48652d4cfacc3a1f503c457 [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 Guptadea82522017-09-21 18:02:44 -0700198
199 if (cpu->core.family >= 0x54) {
200 unsigned int exec_ctrl;
201
202 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
Alexey Brodkin329b4132017-11-23 13:21:55 +0300203 cpu->extn.dual_enb = !(exec_ctrl & 1);
Vineet Guptaf3156852017-11-10 12:40:00 -0800204
205 /* dual issue always present for this core */
206 cpu->extn.dual = 1;
Vineet Guptadea82522017-09-21 18:02:44 -0700207 }
Vineet Gupta56372082014-09-25 16:54:43 +0530208 }
209
210 READ_BCR(ARC_REG_AP_BCR, bcr);
211 cpu->extn.ap = bcr.ver ? 1 : 0;
212
213 READ_BCR(ARC_REG_SMART_BCR, bcr);
214 cpu->extn.smart = bcr.ver ? 1 : 0;
215
Vineet Guptaa44ec8bd2015-03-08 14:18:21 +0530216 READ_BCR(ARC_REG_RTT_BCR, bcr);
217 cpu->extn.rtt = bcr.ver ? 1 : 0;
218
219 cpu->extn.debug = cpu->extn.ap | cpu->extn.smart | cpu->extn.rtt;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700220
Vineet Gupta010a8c92017-09-21 17:46:38 -0700221 READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
222
Vineet Gupta73e284d2016-10-20 17:49:15 -0700223 /* some hacks for lack of feature BCR info in old ARC700 cores */
224 if (is_isa_arcompact()) {
Vineet Gupta010a8c92017-09-21 17:46:38 -0700225 if (!isa.ver) /* ISA BCR absent, use Kconfig info */
Vineet Gupta73e284d2016-10-20 17:49:15 -0700226 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
Vineet Gupta010a8c92017-09-21 17:46:38 -0700227 else {
228 /* ARC700_BUILD only has 2 bits of isa info */
229 struct bcr_generic bcr = *(struct bcr_generic *)&isa;
230 cpu->isa.atomic = bcr.info & 1;
231 }
Vineet Gupta73e284d2016-10-20 17:49:15 -0700232
233 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
Vineet Guptad975cbc2016-10-27 14:33:19 -0700234
235 /* there's no direct way to distinguish 750 vs. 770 */
236 if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
237 cpu->name = "ARC750";
Vineet Gupta010a8c92017-09-21 17:46:38 -0700238 } else {
239 cpu->isa = isa;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700240 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530241}
242
Vineet Gupta8e457d62013-09-04 16:13:35 +0530243static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530244{
Vineet Guptaaf617422013-01-18 15:12:24 +0530245 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
246 struct bcr_identity *core = &cpu->core;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700247 int i, n = 0;
Vineet Gupta56372082014-09-25 16:54:43 +0530248
Vineet Guptaaf617422013-01-18 15:12:24 +0530249 FIX_PTR(cpu);
250
251 n += scnprintf(buf + n, len - n,
Vineet Gupta56372082014-09-25 16:54:43 +0530252 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
253 core->family, core->cpu_id, core->chip_id);
Vineet Guptaaf617422013-01-18 15:12:24 +0530254
Vineet Guptadea82522017-09-21 18:02:44 -0700255 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
Vineet Guptad975cbc2016-10-27 14:33:19 -0700256 cpu_id, cpu->name, cpu->details,
Vineet Gupta73e284d2016-10-20 17:49:15 -0700257 is_isa_arcompact() ? "ARCompact" : "ARCv2",
Vineet Guptadea82522017-09-21 18:02:44 -0700258 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
Vineet Guptaf3156852017-11-10 12:40:00 -0800259 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530260
Vineet Gupta04421422016-10-31 14:26:41 -0700261 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 +0530262 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
263 IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
Vineet Gupta04421422016-10-31 14:26:41 -0700264 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
265 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
Vineet Guptaaf617422013-01-18 15:12:24 +0530266
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530267 n += i = scnprintf(buf + n, len - n, "%s%s%s%s%s",
Vineet Gupta73e284d2016-10-20 17:49:15 -0700268 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530269 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
270 IS_AVAIL1(cpu->isa.unalign, "unalign (not used)"));
Vineet Guptaaf617422013-01-18 15:12:24 +0530271
Vineet Gupta56372082014-09-25 16:54:43 +0530272 if (i)
273 n += scnprintf(buf + n, len - n, "\n\t\t: ");
274
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530275 if (cpu->extn_mpy.ver) {
276 if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */
277 n += scnprintf(buf + n, len - n, "mpy ");
278 } else {
279 int opt = 2; /* stock MPY/MPYH */
280
281 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
282 opt = cpu->extn_mpy.dsp + 6;
283
284 n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt);
285 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530286 }
287
Vineet Gupta56372082014-09-25 16:54:43 +0530288 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530289 IS_AVAIL1(cpu->isa.div_rem, "div_rem "),
Vineet Gupta56372082014-09-25 16:54:43 +0530290 IS_AVAIL1(cpu->extn.norm, "norm "),
291 IS_AVAIL1(cpu->extn.barrel, "barrel-shift "),
292 IS_AVAIL1(cpu->extn.swap, "swap "),
293 IS_AVAIL1(cpu->extn.minmax, "minmax "),
294 IS_AVAIL1(cpu->extn.crc, "crc "),
Vineet Guptaa024fd92016-10-20 18:08:10 -0700295 IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
Vineet Gupta56372082014-09-25 16:54:43 +0530296
297 if (cpu->bpu.ver)
298 n += scnprintf(buf + n, len - n,
Vineet Guptaf3156852017-11-10 12:40:00 -0800299 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d",
Vineet Gupta56372082014-09-25 16:54:43 +0530300 IS_AVAIL1(cpu->bpu.full, "full"),
301 IS_AVAIL1(!cpu->bpu.full, "partial"),
302 cpu->bpu.num_cache, cpu->bpu.num_pred);
Vineet Guptaaf617422013-01-18 15:12:24 +0530303
Vineet Guptaf3156852017-11-10 12:40:00 -0800304 if (is_isa_arcv2()) {
305 struct bcr_lpb lpb;
306
307 READ_BCR(ARC_REG_LPB_BUILD, lpb);
308 if (lpb.ver) {
309 unsigned int ctl;
310 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
311
312 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
313 lpb.entries,
314 IS_DISABLED_RUN(!ctl));
315 }
316 }
317
318 n += scnprintf(buf + n, len - n, "\n");
Vineet Guptaaf617422013-01-18 15:12:24 +0530319 return buf;
320}
321
Vineet Gupta8e457d62013-09-04 16:13:35 +0530322static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530323{
324 int n = 0;
325 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
326
327 FIX_PTR(cpu);
Vineet Guptaaf617422013-01-18 15:12:24 +0530328
Vineet Gupta711c1f22016-10-13 15:53:02 -0700329 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
Vineet Guptaaf617422013-01-18 15:12:24 +0530330
Vineet Gupta56372082014-09-25 16:54:43 +0530331 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
332 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
333 IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
334 IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530335
Vineet Gupta56372082014-09-25 16:54:43 +0530336 if (cpu->extn.debug)
337 n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s%s\n",
338 IS_AVAIL1(cpu->extn.ap, "ActionPoint "),
339 IS_AVAIL1(cpu->extn.smart, "smaRT "),
340 IS_AVAIL1(cpu->extn.rtt, "RTT "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530341
Vineet Gupta56372082014-09-25 16:54:43 +0530342 if (cpu->dccm.sz || cpu->iccm.sz)
343 n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
344 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
Vineet Guptaaf617422013-01-18 15:12:24 +0530345 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
346
Vineet Guptaf3156852017-11-10 12:40:00 -0800347 if (is_isa_arcv2()) {
348
349 /* Error Protection: ECC/Parity */
350 struct bcr_erp erp;
351 READ_BCR(ARC_REG_ERP_BUILD, erp);
352
353 if (erp.ver) {
354 struct ctl_erp ctl;
355 READ_BCR(ARC_REG_ERP_CTRL, ctl);
356
357 /* inverted bits: 0 means enabled */
358 n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
359 IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
360 IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
361 IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
362 }
363 }
364
Vineet Gupta840c0542016-08-10 14:10:57 -0700365 n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
366 EF_ARC_OSABI_CURRENT >> 8,
367 EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
368 "no-legacy-syscalls" : "64-bit data any register aligned");
Vineet Guptaaf617422013-01-18 15:12:24 +0530369
370 return buf;
371}
372
Vineet Guptac4b98562014-09-25 16:07:44 +0530373static void arc_chk_core_config(void)
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530374{
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530375 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700376 int saved = 0, present = 0;
Luis de Bethencourta46f24a2018-01-23 15:16:09 +0000377 char *opt_nm = NULL;
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530378
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530379 if (!cpu->extn.timer0)
Vineet Gupta56372082014-09-25 16:54:43 +0530380 panic("Timer0 is not present!\n");
381
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530382 if (!cpu->extn.timer1)
Vineet Gupta56372082014-09-25 16:54:43 +0530383 panic("Timer1 is not present!\n");
384
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530385#ifdef CONFIG_ARC_HAS_DCCM
386 /*
387 * DCCM can be arbit placed in hardware.
388 * Make sure it's placement/sz matches what Linux is built with
389 */
390 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
391 panic("Linux built with incorrect DCCM Base address\n");
392
393 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
394 panic("Linux built with incorrect DCCM Size\n");
395#endif
396
397#ifdef CONFIG_ARC_HAS_ICCM
398 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
399 panic("Linux built with incorrect ICCM Size\n");
400#endif
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530401
Vineet Guptac4b98562014-09-25 16:07:44 +0530402 /*
403 * FP hardware/software config sanity
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700404 * -If hardware present, kernel needs to save/restore FPU state
Vineet Guptac4b98562014-09-25 16:07:44 +0530405 * -If not, it will crash trying to save/restore the non-existant regs
Vineet Guptac4b98562014-09-25 16:07:44 +0530406 */
Vineet Guptaaf617422013-01-18 15:12:24 +0530407
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700408 if (is_isa_arcompact()) {
409 opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
410 saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
411
412 /* only DPDP checked since SP has no arch visible regs */
413 present = cpu->extn.fpu_dp;
414 } else {
415 opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
416 saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
417
418 /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
419 present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
420 }
421
422 if (present && !saved)
423 pr_warn("Enable %s for working apps\n", opt_nm);
424 else if (!present && saved)
425 panic("Disable %s, hardware NOT present\n", opt_nm);
Vineet Guptac121c502013-01-18 15:12:20 +0530426}
427
428/*
429 * Initialize and setup the processor core
430 * This is called by all the CPUs thus should not do special case stuff
431 * such as only for boot CPU etc
432 */
433
Paul Gortmakerce759952013-06-24 15:30:15 -0400434void setup_processor(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530435{
Vineet Guptaaf617422013-01-18 15:12:24 +0530436 char str[512];
437 int cpu_id = smp_processor_id();
438
Vineet Guptac121c502013-01-18 15:12:20 +0530439 read_arc_build_cfg_regs();
440 arc_init_IRQ();
Vineet Guptaaf617422013-01-18 15:12:24 +0530441
Noam Camus18ee4be2017-06-15 11:43:51 +0300442 pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
Vineet Guptaaf617422013-01-18 15:12:24 +0530443
Vineet Guptac121c502013-01-18 15:12:20 +0530444 arc_mmu_init();
445 arc_cache_init();
Vineet Guptaaf617422013-01-18 15:12:24 +0530446
Noam Camus18ee4be2017-06-15 11:43:51 +0300447 pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
448 pr_info("%s", arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530449
Vineet Guptac4b98562014-09-25 16:07:44 +0530450 arc_chk_core_config();
Vineet Guptac121c502013-01-18 15:12:20 +0530451}
452
Vineet Gupta59ed9412014-01-16 15:01:24 +0530453static inline int is_kernel(unsigned long addr)
454{
455 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
456 return 1;
457 return 0;
458}
459
Vineet Guptac121c502013-01-18 15:12:20 +0530460void __init setup_arch(char **cmdline_p)
461{
Vineet Gupta036b2c52015-03-09 19:40:09 +0530462#ifdef CONFIG_ARC_UBOOT_SUPPORT
Vineet Guptae57d3392014-01-16 15:04:24 +0530463 /* make sure that uboot passed pointer to cmdline/dtb is valid */
464 if (uboot_tag && is_kernel((unsigned long)uboot_arg))
465 panic("Invalid uboot arg\n");
466
467 /* See if u-boot passed an external Device Tree blob */
468 machine_desc = setup_machine_fdt(uboot_arg); /* uboot_tag == 2 */
Vineet Gupta036b2c52015-03-09 19:40:09 +0530469 if (!machine_desc)
470#endif
471 {
Vineet Guptae57d3392014-01-16 15:04:24 +0530472 /* No, so try the embedded one */
Vineet Gupta59ed9412014-01-16 15:01:24 +0530473 machine_desc = setup_machine_fdt(__dtb_start);
474 if (!machine_desc)
475 panic("Embedded DT invalid\n");
Vineet Gupta999159a2013-01-22 17:00:52 +0530476
Vineet Gupta59ed9412014-01-16 15:01:24 +0530477 /*
Vineet Guptae57d3392014-01-16 15:04:24 +0530478 * If we are here, it is established that @uboot_arg didn't
479 * point to DT blob. Instead if u-boot says it is cmdline,
Andrea Gelmini25474762016-05-21 13:45:35 +0200480 * append to embedded DT cmdline.
Vineet Gupta59ed9412014-01-16 15:01:24 +0530481 * setup_machine_fdt() would have populated @boot_command_line
482 */
483 if (uboot_tag == 1) {
Vineet Gupta59ed9412014-01-16 15:01:24 +0530484 /* Ensure a whitespace between the 2 cmdlines */
485 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
486 strlcat(boot_command_line, uboot_arg,
487 COMMAND_LINE_SIZE);
488 }
Vineet Guptae57d3392014-01-16 15:04:24 +0530489 }
Vineet Gupta9593a932013-04-09 16:18:04 +0530490
491 /* Save unparsed command line copy for /proc/cmdline */
492 *cmdline_p = boot_command_line;
493
Vineet Guptac121c502013-01-18 15:12:20 +0530494 /* To force early parsing of things like mem=xxx */
495 parse_early_param();
496
497 /* Platform/board specific: e.g. early console registration */
Vineet Gupta03a6d282013-01-18 15:12:26 +0530498 if (machine_desc->init_early)
499 machine_desc->init_early();
Vineet Guptac121c502013-01-18 15:12:20 +0530500
Vineet Gupta41195d22013-01-18 15:12:23 +0530501 smp_init_cpus();
Vineet Guptae55af4d2015-10-12 16:28:55 +0530502
503 setup_processor();
Vineet Guptac121c502013-01-18 15:12:20 +0530504 setup_arch_memory();
505
Vineet Guptaeab6a082013-02-21 17:37:06 +0530506 /* copy flat DT out of .init and then unflatten it */
Rob Herring1efc9592013-08-26 11:23:27 -0500507 unflatten_and_copy_device_tree();
Vineet Gupta999159a2013-01-22 17:00:52 +0530508
Vineet Guptac121c502013-01-18 15:12:20 +0530509 /* Can be issue if someone passes cmd line arg "ro"
510 * But that is unlikely so keeping it as it is
511 */
512 root_mountflags &= ~MS_RDONLY;
513
Vineet Guptac121c502013-01-18 15:12:20 +0530514#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
515 conswitchp = &dummy_con;
516#endif
517
Vineet Gupta854a0d92013-01-22 17:03:19 +0530518 arc_unwind_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530519}
520
Vineet Gupta92b03312016-10-31 13:26:25 -0700521/*
522 * Called from start_kernel() - boot CPU only
523 */
524void __init time_init(void)
525{
526 of_clk_init(NULL);
Daniel Lezcanoba5d08c2017-05-26 17:40:46 +0200527 timer_probe();
Vineet Gupta92b03312016-10-31 13:26:25 -0700528}
529
Vineet Gupta03a6d282013-01-18 15:12:26 +0530530static int __init customize_machine(void)
531{
Vineet Gupta03a6d282013-01-18 15:12:26 +0530532 if (machine_desc->init_machine)
533 machine_desc->init_machine();
534
535 return 0;
536}
537arch_initcall(customize_machine);
538
539static int __init init_late_machine(void)
540{
541 if (machine_desc->init_late)
542 machine_desc->init_late();
543
544 return 0;
545}
546late_initcall(init_late_machine);
Vineet Guptac121c502013-01-18 15:12:20 +0530547/*
548 * Get CPU information for use by the procfs.
549 */
550
551#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
552#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
553
554static int show_cpuinfo(struct seq_file *m, void *v)
555{
556 char *str;
557 int cpu_id = ptr_to_cpu(v);
Vlad Zakharov7f351442017-03-03 14:30:02 +0300558 struct device *cpu_dev = get_cpu_device(cpu_id);
559 struct clk *cpu_clk;
560 unsigned long freq = 0;
Vineet Guptac121c502013-01-18 15:12:20 +0530561
Vineet Gupta4c862312014-12-12 10:05:03 +0530562 if (!cpu_online(cpu_id)) {
563 seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
564 goto done;
565 }
566
Michal Hocko0ee931c2017-09-13 16:28:29 -0700567 str = (char *)__get_free_page(GFP_KERNEL);
Vineet Guptac121c502013-01-18 15:12:20 +0530568 if (!str)
569 goto done;
570
Vineet Guptaaf617422013-01-18 15:12:24 +0530571 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptac121c502013-01-18 15:12:20 +0530572
Vlad Zakharov7f351442017-03-03 14:30:02 +0300573 cpu_clk = clk_get(cpu_dev, NULL);
574 if (IS_ERR(cpu_clk)) {
575 seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
576 cpu_id);
577 } else {
578 freq = clk_get_rate(cpu_clk);
579 }
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300580 if (freq)
Vlad Zakharov7f351442017-03-03 14:30:02 +0300581 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300582 freq / 1000000, (freq / 10000) % 100);
583
Vineet Gupta56372082014-09-25 16:54:43 +0530584 seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
Vineet Guptac121c502013-01-18 15:12:20 +0530585 loops_per_jiffy / (500000 / HZ),
586 (loops_per_jiffy / (5000 / HZ)) % 100);
587
Vineet Guptaaf617422013-01-18 15:12:24 +0530588 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530589 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530590 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530591 seq_printf(m, arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530592
Vineet Guptac121c502013-01-18 15:12:20 +0530593 free_page((unsigned long)str);
594done:
Vineet Gupta4c862312014-12-12 10:05:03 +0530595 seq_printf(m, "\n");
Vineet Guptac121c502013-01-18 15:12:20 +0530596
597 return 0;
598}
599
600static void *c_start(struct seq_file *m, loff_t *pos)
601{
602 /*
603 * Callback returns cpu-id to iterator for show routine, NULL to stop.
604 * However since NULL is also a valid cpu-id (0), we use a round-about
605 * way to pass it w/o having to kmalloc/free a 2 byte string.
606 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
607 */
Noam Camus3da431042016-10-19 14:25:03 +0300608 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
Vineet Guptac121c502013-01-18 15:12:20 +0530609}
610
611static void *c_next(struct seq_file *m, void *v, loff_t *pos)
612{
613 ++*pos;
614 return c_start(m, pos);
615}
616
617static void c_stop(struct seq_file *m, void *v)
618{
619}
620
621const struct seq_operations cpuinfo_op = {
622 .start = c_start,
623 .next = c_next,
624 .stop = c_stop,
625 .show = show_cpuinfo
626};
627
628static DEFINE_PER_CPU(struct cpu, cpu_topology);
629
630static int __init topology_init(void)
631{
632 int cpu;
633
634 for_each_present_cpu(cpu)
635 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
636
637 return 0;
638}
639
640subsys_initcall(topology_init);