blob: ec2fd231ecd9935b41e5c3bd923bdec5a06dc929 [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;
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +030039int __initdata uboot_magic;
Vineet Gupta59ed9412014-01-16 15:01:24 +053040char __initdata *uboot_arg;
41
Rob Herring880beb82013-08-27 21:43:12 -050042const struct machine_desc *machine_desc;
Vineet Guptac121c502013-01-18 15:12:20 +053043
44struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
45
46struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
47
Vineet Guptad975cbc2016-10-27 14:33:19 -070048static const struct id_to_str arc_cpu_rel[] = {
Vineet Gupta73e284d2016-10-20 17:49:15 -070049#ifdef CONFIG_ISA_ARCOMPACT
Vineet Guptad975cbc2016-10-27 14:33:19 -070050 { 0x34, "R4.10"},
51 { 0x35, "R4.11"},
Vineet Gupta73e284d2016-10-20 17:49:15 -070052#else
Vineet Guptad975cbc2016-10-27 14:33:19 -070053 { 0x51, "R2.0" },
54 { 0x52, "R2.1" },
55 { 0x53, "R3.0" },
Vineet Gupta701eda02018-02-21 15:10:02 -080056 { 0x54, "R3.10a" },
Vineet Gupta73e284d2016-10-20 17:49:15 -070057#endif
Vineet Guptad975cbc2016-10-27 14:33:19 -070058 { 0x00, NULL }
59};
60
61static const struct id_to_str arc_cpu_nm[] = {
62#ifdef CONFIG_ISA_ARCOMPACT
63 { 0x20, "ARC 600" },
64 { 0x30, "ARC 770" }, /* 750 identified seperately */
65#else
66 { 0x40, "ARC EM" },
67 { 0x50, "ARC HS38" },
Vineet Guptadea82522017-09-21 18:02:44 -070068 { 0x54, "ARC HS48" },
Vineet Guptad975cbc2016-10-27 14:33:19 -070069#endif
70 { 0x00, "Unknown" }
Vineet Gupta73e284d2016-10-20 17:49:15 -070071};
72
Vineet Guptaa150b082016-02-16 12:36:18 +053073static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
74{
75 if (is_isa_arcompact()) {
76 struct bcr_iccm_arcompact iccm;
77 struct bcr_dccm_arcompact dccm;
78
79 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
80 if (iccm.ver) {
81 cpu->iccm.sz = 4096 << iccm.sz; /* 8K to 512K */
82 cpu->iccm.base_addr = iccm.base << 16;
83 }
84
85 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
86 if (dccm.ver) {
87 unsigned long base;
88 cpu->dccm.sz = 2048 << dccm.sz; /* 2K to 256K */
89
90 base = read_aux_reg(ARC_REG_DCCM_BASE_BUILD);
91 cpu->dccm.base_addr = base & ~0xF;
92 }
93 } else {
94 struct bcr_iccm_arcv2 iccm;
95 struct bcr_dccm_arcv2 dccm;
96 unsigned long region;
97
98 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
99 if (iccm.ver) {
100 cpu->iccm.sz = 256 << iccm.sz00; /* 512B to 16M */
101 if (iccm.sz00 == 0xF && iccm.sz01 > 0)
102 cpu->iccm.sz <<= iccm.sz01;
103
104 region = read_aux_reg(ARC_REG_AUX_ICCM);
105 cpu->iccm.base_addr = region & 0xF0000000;
106 }
107
108 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
109 if (dccm.ver) {
110 cpu->dccm.sz = 256 << dccm.sz0;
111 if (dccm.sz0 == 0xF && dccm.sz1 > 0)
112 cpu->dccm.sz <<= dccm.sz1;
113
114 region = read_aux_reg(ARC_REG_AUX_DCCM);
115 cpu->dccm.base_addr = region & 0xF0000000;
116 }
117 }
118}
119
Vineet Gupta8e457d62013-09-04 16:13:35 +0530120static void read_arc_build_cfg_regs(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530121{
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530122 struct bcr_timer timer;
Vineet Gupta56372082014-09-25 16:54:43 +0530123 struct bcr_generic bcr;
Vineet Guptaaf617422013-01-18 15:12:24 +0530124 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Guptad975cbc2016-10-27 14:33:19 -0700125 const struct id_to_str *tbl;
Vineet Gupta010a8c92017-09-21 17:46:38 -0700126 struct bcr_isa_arcv2 isa;
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800127 struct bcr_actionpoint ap;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700128
Vineet Guptaaf617422013-01-18 15:12:24 +0530129 FIX_PTR(cpu);
130
131 READ_BCR(AUX_IDENTITY, cpu->core);
132
Vineet Guptad975cbc2016-10-27 14:33:19 -0700133 for (tbl = &arc_cpu_rel[0]; tbl->id != 0; tbl++) {
134 if (cpu->core.family == tbl->id) {
135 cpu->details = tbl->str;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700136 break;
137 }
138 }
139
Vineet Guptad975cbc2016-10-27 14:33:19 -0700140 for (tbl = &arc_cpu_nm[0]; tbl->id != 0; tbl++) {
Vineet Guptadea82522017-09-21 18:02:44 -0700141 if ((cpu->core.family & 0xF4) == tbl->id)
Vineet Guptad975cbc2016-10-27 14:33:19 -0700142 break;
143 }
144 cpu->name = tbl->str;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700145
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530146 READ_BCR(ARC_REG_TIMERS_BCR, timer);
147 cpu->extn.timer0 = timer.t0;
148 cpu->extn.timer1 = timer.t1;
149 cpu->extn.rtc = timer.rtc;
150
Vineet Guptaaf617422013-01-18 15:12:24 +0530151 cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
Vineet Guptaaf617422013-01-18 15:12:24 +0530152
Vineet Gupta56372082014-09-25 16:54:43 +0530153 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
Vineet Guptaaf617422013-01-18 15:12:24 +0530154
Vineet Gupta56372082014-09-25 16:54:43 +0530155 cpu->extn.norm = read_aux_reg(ARC_REG_NORM_BCR) > 1 ? 1 : 0; /* 2,3 */
156 cpu->extn.barrel = read_aux_reg(ARC_REG_BARREL_BCR) > 1 ? 1 : 0; /* 2,3 */
157 cpu->extn.swap = read_aux_reg(ARC_REG_SWAP_BCR) ? 1 : 0; /* 1,3 */
158 cpu->extn.crc = read_aux_reg(ARC_REG_CRC_BCR) ? 1 : 0;
159 cpu->extn.minmax = read_aux_reg(ARC_REG_MIXMAX_BCR) > 1 ? 1 : 0; /* 2 */
Vineet Guptaa024fd92016-10-20 18:08:10 -0700160 cpu->extn.swape = (cpu->core.family >= 0x34) ? 1 :
161 IS_ENABLED(CONFIG_ARC_HAS_SWAPE);
162
Vineet Guptaaf617422013-01-18 15:12:24 +0530163 READ_BCR(ARC_REG_XY_MEM_BCR, cpu->extn_xymem);
164
Vineet Guptaa150b082016-02-16 12:36:18 +0530165 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
166 read_decode_ccm_bcr(cpu);
167
Vineet Guptac121c502013-01-18 15:12:20 +0530168 read_decode_mmu_bcr();
169 read_decode_cache_bcr();
Vineet Guptaaf617422013-01-18 15:12:24 +0530170
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530171 if (is_isa_arcompact()) {
Vineet Gupta56372082014-09-25 16:54:43 +0530172 struct bcr_fp_arcompact sp, dp;
173 struct bcr_bpu_arcompact bpu;
174
175 READ_BCR(ARC_REG_FP_BCR, sp);
176 READ_BCR(ARC_REG_DPFP_BCR, dp);
177 cpu->extn.fpu_sp = sp.ver ? 1 : 0;
178 cpu->extn.fpu_dp = dp.ver ? 1 : 0;
179
180 READ_BCR(ARC_REG_BPU_BCR, bpu);
181 cpu->bpu.ver = bpu.ver;
182 cpu->bpu.full = bpu.fam ? 1 : 0;
183 if (bpu.ent) {
184 cpu->bpu.num_cache = 256 << (bpu.ent - 1);
185 cpu->bpu.num_pred = 256 << (bpu.ent - 1);
186 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530187 } else {
188 struct bcr_fp_arcv2 spdp;
189 struct bcr_bpu_arcv2 bpu;
190
191 READ_BCR(ARC_REG_FP_V2_BCR, spdp);
192 cpu->extn.fpu_sp = spdp.sp ? 1 : 0;
193 cpu->extn.fpu_dp = spdp.dp ? 1 : 0;
194
195 READ_BCR(ARC_REG_BPU_BCR, bpu);
196 cpu->bpu.ver = bpu.ver;
197 cpu->bpu.full = bpu.ft;
198 cpu->bpu.num_cache = 256 << bpu.bce;
199 cpu->bpu.num_pred = 2048 << bpu.pte;
Vineet Gupta97e98132018-12-06 00:17:50 -0800200 cpu->bpu.ret_stk = 4 << bpu.rse;
Vineet Guptadea82522017-09-21 18:02:44 -0700201
202 if (cpu->core.family >= 0x54) {
Vineet Guptadea82522017-09-21 18:02:44 -0700203
Vineet Gupta7b2e9322019-02-21 13:44:49 -0800204 struct bcr_uarch_build_arcv2 uarch;
Vineet Guptaf3156852017-11-10 12:40:00 -0800205
Vineet Gupta7b2e9322019-02-21 13:44:49 -0800206 /*
207 * The first 0x54 core (uarch maj:min 0:1 or 0:2) was
208 * dual issue only (HS4x). But next uarch rev (1:0)
209 * allows it be configured for single issue (HS3x)
210 * Ensure we fiddle with dual issue only on HS4x
211 */
212 READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
213
214 if (uarch.prod == 4) {
215 unsigned int exec_ctrl;
216
217 /* dual issue hardware always present */
218 cpu->extn.dual = 1;
219
220 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
221
222 /* dual issue hardware enabled ? */
223 cpu->extn.dual_enb = !(exec_ctrl & 1);
224
225 }
Vineet Guptadea82522017-09-21 18:02:44 -0700226 }
Vineet Gupta56372082014-09-25 16:54:43 +0530227 }
228
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800229 READ_BCR(ARC_REG_AP_BCR, ap);
230 if (ap.ver) {
231 cpu->extn.ap_num = 2 << ap.num;
Eugeniy Paltsevcdf92962019-02-04 21:41:51 +0300232 cpu->extn.ap_full = !ap.min;
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800233 }
Vineet Gupta56372082014-09-25 16:54:43 +0530234
235 READ_BCR(ARC_REG_SMART_BCR, bcr);
236 cpu->extn.smart = bcr.ver ? 1 : 0;
237
Vineet Guptaa44ec8bd2015-03-08 14:18:21 +0530238 READ_BCR(ARC_REG_RTT_BCR, bcr);
239 cpu->extn.rtt = bcr.ver ? 1 : 0;
240
Vineet Gupta010a8c92017-09-21 17:46:38 -0700241 READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
242
Vineet Gupta73e284d2016-10-20 17:49:15 -0700243 /* some hacks for lack of feature BCR info in old ARC700 cores */
244 if (is_isa_arcompact()) {
Vineet Gupta010a8c92017-09-21 17:46:38 -0700245 if (!isa.ver) /* ISA BCR absent, use Kconfig info */
Vineet Gupta73e284d2016-10-20 17:49:15 -0700246 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
Vineet Gupta010a8c92017-09-21 17:46:38 -0700247 else {
248 /* ARC700_BUILD only has 2 bits of isa info */
249 struct bcr_generic bcr = *(struct bcr_generic *)&isa;
250 cpu->isa.atomic = bcr.info & 1;
251 }
Vineet Gupta73e284d2016-10-20 17:49:15 -0700252
253 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
Vineet Guptad975cbc2016-10-27 14:33:19 -0700254
255 /* there's no direct way to distinguish 750 vs. 770 */
256 if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
257 cpu->name = "ARC750";
Vineet Gupta010a8c92017-09-21 17:46:38 -0700258 } else {
259 cpu->isa = isa;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700260 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530261}
262
Vineet Gupta8e457d62013-09-04 16:13:35 +0530263static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530264{
Vineet Guptaaf617422013-01-18 15:12:24 +0530265 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
266 struct bcr_identity *core = &cpu->core;
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300267 int n = 0;
Vineet Gupta56372082014-09-25 16:54:43 +0530268
Vineet Guptaaf617422013-01-18 15:12:24 +0530269 FIX_PTR(cpu);
270
271 n += scnprintf(buf + n, len - n,
Vineet Gupta56372082014-09-25 16:54:43 +0530272 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
273 core->family, core->cpu_id, core->chip_id);
Vineet Guptaaf617422013-01-18 15:12:24 +0530274
Vineet Guptadea82522017-09-21 18:02:44 -0700275 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
Vineet Guptad975cbc2016-10-27 14:33:19 -0700276 cpu_id, cpu->name, cpu->details,
Vineet Gupta73e284d2016-10-20 17:49:15 -0700277 is_isa_arcompact() ? "ARCompact" : "ARCv2",
Vineet Guptadea82522017-09-21 18:02:44 -0700278 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
Vineet Guptaf3156852017-11-10 12:40:00 -0800279 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530280
Vineet Gupta04421422016-10-31 14:26:41 -0700281 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 +0530282 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
283 IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
Vineet Gupta04421422016-10-31 14:26:41 -0700284 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
285 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
Vineet Guptaaf617422013-01-18 15:12:24 +0530286
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300287 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s",
288 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
289 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
290 IS_AVAIL2(cpu->isa.unalign, "unalign ", CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS));
Vineet Guptaaf617422013-01-18 15:12:24 +0530291
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300292#if defined(__ARC_UNALIGNED__) && !defined(CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS)
293 /*
294 * gcc 7.3.1 (GNU 2018.03) onwards generate unaligned access by default
295 * but -mno-unaligned-access to disable that didn't work until gcc 8.2.1
296 * (GNU 2019.03). So landing here implies the interim period, when
297 * despite Kconfig being off, gcc is generating unaligned accesses which
298 * could bomb later on. So better to disallow such broken builds
299 */
300 BUILD_BUG_ON_MSG(1, "gcc doesn't support -mno-unaligned-access");
301#endif
302
303 n += scnprintf(buf + n, len - n, "\n\t\t: ");
Vineet Gupta56372082014-09-25 16:54:43 +0530304
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530305 if (cpu->extn_mpy.ver) {
306 if (cpu->extn_mpy.ver <= 0x2) { /* ARCompact */
307 n += scnprintf(buf + n, len - n, "mpy ");
308 } else {
309 int opt = 2; /* stock MPY/MPYH */
310
311 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
312 opt = cpu->extn_mpy.dsp + 6;
313
314 n += scnprintf(buf + n, len - n, "mpy[opt %d] ", opt);
315 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530316 }
317
Vineet Gupta56372082014-09-25 16:54:43 +0530318 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530319 IS_AVAIL1(cpu->isa.div_rem, "div_rem "),
Vineet Gupta56372082014-09-25 16:54:43 +0530320 IS_AVAIL1(cpu->extn.norm, "norm "),
321 IS_AVAIL1(cpu->extn.barrel, "barrel-shift "),
322 IS_AVAIL1(cpu->extn.swap, "swap "),
323 IS_AVAIL1(cpu->extn.minmax, "minmax "),
324 IS_AVAIL1(cpu->extn.crc, "crc "),
Vineet Guptaa024fd92016-10-20 18:08:10 -0700325 IS_AVAIL2(cpu->extn.swape, "swape", CONFIG_ARC_HAS_SWAPE));
Vineet Gupta56372082014-09-25 16:54:43 +0530326
327 if (cpu->bpu.ver)
328 n += scnprintf(buf + n, len - n,
Vineet Gupta97e98132018-12-06 00:17:50 -0800329 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d",
Vineet Gupta56372082014-09-25 16:54:43 +0530330 IS_AVAIL1(cpu->bpu.full, "full"),
331 IS_AVAIL1(!cpu->bpu.full, "partial"),
Vineet Gupta97e98132018-12-06 00:17:50 -0800332 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk);
Vineet Guptaaf617422013-01-18 15:12:24 +0530333
Vineet Guptaf3156852017-11-10 12:40:00 -0800334 if (is_isa_arcv2()) {
335 struct bcr_lpb lpb;
336
337 READ_BCR(ARC_REG_LPB_BUILD, lpb);
338 if (lpb.ver) {
339 unsigned int ctl;
340 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
341
342 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
343 lpb.entries,
344 IS_DISABLED_RUN(!ctl));
345 }
346 }
347
348 n += scnprintf(buf + n, len - n, "\n");
Vineet Guptaaf617422013-01-18 15:12:24 +0530349 return buf;
350}
351
Vineet Gupta8e457d62013-09-04 16:13:35 +0530352static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530353{
354 int n = 0;
355 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
356
357 FIX_PTR(cpu);
Vineet Guptaaf617422013-01-18 15:12:24 +0530358
Vineet Gupta711c1f22016-10-13 15:53:02 -0700359 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
Vineet Guptaaf617422013-01-18 15:12:24 +0530360
Vineet Gupta56372082014-09-25 16:54:43 +0530361 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
362 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
363 IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
364 IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530365
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800366 if (cpu->extn.ap_num | cpu->extn.smart | cpu->extn.rtt) {
367 n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s",
Vineet Gupta56372082014-09-25 16:54:43 +0530368 IS_AVAIL1(cpu->extn.smart, "smaRT "),
369 IS_AVAIL1(cpu->extn.rtt, "RTT "));
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800370 if (cpu->extn.ap_num) {
371 n += scnprintf(buf + n, len - n, "ActionPoint %d/%s",
372 cpu->extn.ap_num,
373 cpu->extn.ap_full ? "full":"min");
374 }
375 n += scnprintf(buf + n, len - n, "\n");
376 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530377
Vineet Gupta56372082014-09-25 16:54:43 +0530378 if (cpu->dccm.sz || cpu->iccm.sz)
379 n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
380 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
Vineet Guptaaf617422013-01-18 15:12:24 +0530381 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
382
Vineet Guptaf3156852017-11-10 12:40:00 -0800383 if (is_isa_arcv2()) {
384
385 /* Error Protection: ECC/Parity */
386 struct bcr_erp erp;
387 READ_BCR(ARC_REG_ERP_BUILD, erp);
388
389 if (erp.ver) {
390 struct ctl_erp ctl;
391 READ_BCR(ARC_REG_ERP_CTRL, ctl);
392
393 /* inverted bits: 0 means enabled */
394 n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
395 IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
396 IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
397 IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
398 }
399 }
400
Vineet Gupta840c0542016-08-10 14:10:57 -0700401 n += scnprintf(buf + n, len - n, "OS ABI [v%d]\t: %s\n",
402 EF_ARC_OSABI_CURRENT >> 8,
403 EF_ARC_OSABI_CURRENT == EF_ARC_OSABI_V3 ?
404 "no-legacy-syscalls" : "64-bit data any register aligned");
Vineet Guptaaf617422013-01-18 15:12:24 +0530405
406 return buf;
407}
408
Vineet Guptac4b98562014-09-25 16:07:44 +0530409static void arc_chk_core_config(void)
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530410{
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530411 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700412 int saved = 0, present = 0;
Luis de Bethencourta46f24a2018-01-23 15:16:09 +0000413 char *opt_nm = NULL;
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530414
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530415 if (!cpu->extn.timer0)
Vineet Gupta56372082014-09-25 16:54:43 +0530416 panic("Timer0 is not present!\n");
417
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530418 if (!cpu->extn.timer1)
Vineet Gupta56372082014-09-25 16:54:43 +0530419 panic("Timer1 is not present!\n");
420
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530421#ifdef CONFIG_ARC_HAS_DCCM
422 /*
423 * DCCM can be arbit placed in hardware.
424 * Make sure it's placement/sz matches what Linux is built with
425 */
426 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
427 panic("Linux built with incorrect DCCM Base address\n");
428
429 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
430 panic("Linux built with incorrect DCCM Size\n");
431#endif
432
433#ifdef CONFIG_ARC_HAS_ICCM
434 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
435 panic("Linux built with incorrect ICCM Size\n");
436#endif
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530437
Vineet Guptac4b98562014-09-25 16:07:44 +0530438 /*
439 * FP hardware/software config sanity
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700440 * -If hardware present, kernel needs to save/restore FPU state
Vineet Guptac4b98562014-09-25 16:07:44 +0530441 * -If not, it will crash trying to save/restore the non-existant regs
Vineet Guptac4b98562014-09-25 16:07:44 +0530442 */
Vineet Guptaaf617422013-01-18 15:12:24 +0530443
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700444 if (is_isa_arcompact()) {
445 opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
446 saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
447
448 /* only DPDP checked since SP has no arch visible regs */
449 present = cpu->extn.fpu_dp;
450 } else {
451 opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
452 saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
453
454 /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
455 present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
456 }
457
458 if (present && !saved)
459 pr_warn("Enable %s for working apps\n", opt_nm);
460 else if (!present && saved)
461 panic("Disable %s, hardware NOT present\n", opt_nm);
Vineet Guptac121c502013-01-18 15:12:20 +0530462}
463
464/*
465 * Initialize and setup the processor core
466 * This is called by all the CPUs thus should not do special case stuff
467 * such as only for boot CPU etc
468 */
469
Paul Gortmakerce759952013-06-24 15:30:15 -0400470void setup_processor(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530471{
Vineet Guptaaf617422013-01-18 15:12:24 +0530472 char str[512];
473 int cpu_id = smp_processor_id();
474
Vineet Guptac121c502013-01-18 15:12:20 +0530475 read_arc_build_cfg_regs();
476 arc_init_IRQ();
Vineet Guptaaf617422013-01-18 15:12:24 +0530477
Noam Camus18ee4be2017-06-15 11:43:51 +0300478 pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
Vineet Guptaaf617422013-01-18 15:12:24 +0530479
Vineet Guptac121c502013-01-18 15:12:20 +0530480 arc_mmu_init();
481 arc_cache_init();
Vineet Guptaaf617422013-01-18 15:12:24 +0530482
Noam Camus18ee4be2017-06-15 11:43:51 +0300483 pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
484 pr_info("%s", arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530485
Vineet Guptac4b98562014-09-25 16:07:44 +0530486 arc_chk_core_config();
Vineet Guptac121c502013-01-18 15:12:20 +0530487}
488
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300489static inline bool uboot_arg_invalid(unsigned long addr)
Vineet Gupta59ed9412014-01-16 15:01:24 +0530490{
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300491 /*
492 * Check that it is a untranslated address (although MMU is not enabled
493 * yet, it being a high address ensures this is not by fluke)
494 */
495 if (addr < PAGE_OFFSET)
496 return true;
497
498 /* Check that address doesn't clobber resident kernel image */
499 return addr >= (unsigned long)_stext && addr <= (unsigned long)_end;
500}
501
502#define IGNORE_ARGS "Ignore U-boot args: "
503
504/* uboot_tag values for U-boot - kernel ABI revision 0; see head.S */
505#define UBOOT_TAG_NONE 0
506#define UBOOT_TAG_CMDLINE 1
507#define UBOOT_TAG_DTB 2
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300508/* We always pass 0 as magic from U-boot */
509#define UBOOT_MAGIC_VALUE 0
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300510
511void __init handle_uboot_args(void)
512{
513 bool use_embedded_dtb = true;
514 bool append_cmdline = false;
515
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300516 /* check that we know this tag */
517 if (uboot_tag != UBOOT_TAG_NONE &&
518 uboot_tag != UBOOT_TAG_CMDLINE &&
519 uboot_tag != UBOOT_TAG_DTB) {
520 pr_warn(IGNORE_ARGS "invalid uboot tag: '%08x'\n", uboot_tag);
521 goto ignore_uboot_args;
522 }
523
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300524 if (uboot_magic != UBOOT_MAGIC_VALUE) {
525 pr_warn(IGNORE_ARGS "non zero uboot magic\n");
526 goto ignore_uboot_args;
527 }
528
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300529 if (uboot_tag != UBOOT_TAG_NONE &&
530 uboot_arg_invalid((unsigned long)uboot_arg)) {
531 pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg);
532 goto ignore_uboot_args;
533 }
534
535 /* see if U-boot passed an external Device Tree blob */
536 if (uboot_tag == UBOOT_TAG_DTB) {
537 machine_desc = setup_machine_fdt((void *)uboot_arg);
538
539 /* external Device Tree blob is invalid - use embedded one */
540 use_embedded_dtb = !machine_desc;
541 }
542
543 if (uboot_tag == UBOOT_TAG_CMDLINE)
544 append_cmdline = true;
545
546ignore_uboot_args:
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300547
548 if (use_embedded_dtb) {
549 machine_desc = setup_machine_fdt(__dtb_start);
550 if (!machine_desc)
551 panic("Embedded DT invalid\n");
552 }
553
554 /*
555 * NOTE: @boot_command_line is populated by setup_machine_fdt() so this
556 * append processing can only happen after.
557 */
558 if (append_cmdline) {
559 /* Ensure a whitespace between the 2 cmdlines */
560 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
561 strlcat(boot_command_line, uboot_arg, COMMAND_LINE_SIZE);
562 }
Vineet Gupta59ed9412014-01-16 15:01:24 +0530563}
564
Vineet Guptac121c502013-01-18 15:12:20 +0530565void __init setup_arch(char **cmdline_p)
566{
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300567 handle_uboot_args();
Vineet Gupta9593a932013-04-09 16:18:04 +0530568
569 /* Save unparsed command line copy for /proc/cmdline */
570 *cmdline_p = boot_command_line;
571
Vineet Guptac121c502013-01-18 15:12:20 +0530572 /* To force early parsing of things like mem=xxx */
573 parse_early_param();
574
575 /* Platform/board specific: e.g. early console registration */
Vineet Gupta03a6d282013-01-18 15:12:26 +0530576 if (machine_desc->init_early)
577 machine_desc->init_early();
Vineet Guptac121c502013-01-18 15:12:20 +0530578
Vineet Gupta41195d22013-01-18 15:12:23 +0530579 smp_init_cpus();
Vineet Guptae55af4d2015-10-12 16:28:55 +0530580
581 setup_processor();
Vineet Guptac121c502013-01-18 15:12:20 +0530582 setup_arch_memory();
583
Vineet Guptaeab6a082013-02-21 17:37:06 +0530584 /* copy flat DT out of .init and then unflatten it */
Rob Herring1efc9592013-08-26 11:23:27 -0500585 unflatten_and_copy_device_tree();
Vineet Gupta999159a2013-01-22 17:00:52 +0530586
Vineet Guptac121c502013-01-18 15:12:20 +0530587 /* Can be issue if someone passes cmd line arg "ro"
588 * But that is unlikely so keeping it as it is
589 */
590 root_mountflags &= ~MS_RDONLY;
591
Vineet Guptac121c502013-01-18 15:12:20 +0530592#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
593 conswitchp = &dummy_con;
594#endif
595
Vineet Gupta854a0d92013-01-22 17:03:19 +0530596 arc_unwind_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530597}
598
Vineet Gupta92b03312016-10-31 13:26:25 -0700599/*
600 * Called from start_kernel() - boot CPU only
601 */
602void __init time_init(void)
603{
604 of_clk_init(NULL);
Daniel Lezcanoba5d08c2017-05-26 17:40:46 +0200605 timer_probe();
Vineet Gupta92b03312016-10-31 13:26:25 -0700606}
607
Vineet Gupta03a6d282013-01-18 15:12:26 +0530608static int __init customize_machine(void)
609{
Vineet Gupta03a6d282013-01-18 15:12:26 +0530610 if (machine_desc->init_machine)
611 machine_desc->init_machine();
612
613 return 0;
614}
615arch_initcall(customize_machine);
616
617static int __init init_late_machine(void)
618{
619 if (machine_desc->init_late)
620 machine_desc->init_late();
621
622 return 0;
623}
624late_initcall(init_late_machine);
Vineet Guptac121c502013-01-18 15:12:20 +0530625/*
626 * Get CPU information for use by the procfs.
627 */
628
629#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
630#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
631
632static int show_cpuinfo(struct seq_file *m, void *v)
633{
634 char *str;
635 int cpu_id = ptr_to_cpu(v);
Vlad Zakharov7f351442017-03-03 14:30:02 +0300636 struct device *cpu_dev = get_cpu_device(cpu_id);
637 struct clk *cpu_clk;
638 unsigned long freq = 0;
Vineet Guptac121c502013-01-18 15:12:20 +0530639
Vineet Gupta4c862312014-12-12 10:05:03 +0530640 if (!cpu_online(cpu_id)) {
641 seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
642 goto done;
643 }
644
Michal Hocko0ee931c2017-09-13 16:28:29 -0700645 str = (char *)__get_free_page(GFP_KERNEL);
Vineet Guptac121c502013-01-18 15:12:20 +0530646 if (!str)
647 goto done;
648
Vineet Guptaaf617422013-01-18 15:12:24 +0530649 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptac121c502013-01-18 15:12:20 +0530650
Vlad Zakharov7f351442017-03-03 14:30:02 +0300651 cpu_clk = clk_get(cpu_dev, NULL);
652 if (IS_ERR(cpu_clk)) {
653 seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
654 cpu_id);
655 } else {
656 freq = clk_get_rate(cpu_clk);
657 }
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300658 if (freq)
Vlad Zakharov7f351442017-03-03 14:30:02 +0300659 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300660 freq / 1000000, (freq / 10000) % 100);
661
Vineet Gupta56372082014-09-25 16:54:43 +0530662 seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
Vineet Guptac121c502013-01-18 15:12:20 +0530663 loops_per_jiffy / (500000 / HZ),
664 (loops_per_jiffy / (5000 / HZ)) % 100);
665
Vineet Guptaaf617422013-01-18 15:12:24 +0530666 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530667 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530668 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530669 seq_printf(m, arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530670
Vineet Guptac121c502013-01-18 15:12:20 +0530671 free_page((unsigned long)str);
672done:
Vineet Gupta4c862312014-12-12 10:05:03 +0530673 seq_printf(m, "\n");
Vineet Guptac121c502013-01-18 15:12:20 +0530674
675 return 0;
676}
677
678static void *c_start(struct seq_file *m, loff_t *pos)
679{
680 /*
681 * Callback returns cpu-id to iterator for show routine, NULL to stop.
682 * However since NULL is also a valid cpu-id (0), we use a round-about
683 * way to pass it w/o having to kmalloc/free a 2 byte string.
684 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
685 */
Noam Camus3da431042016-10-19 14:25:03 +0300686 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
Vineet Guptac121c502013-01-18 15:12:20 +0530687}
688
689static void *c_next(struct seq_file *m, void *v, loff_t *pos)
690{
691 ++*pos;
692 return c_start(m, pos);
693}
694
695static void c_stop(struct seq_file *m, void *v)
696{
697}
698
699const struct seq_operations cpuinfo_op = {
700 .start = c_start,
701 .next = c_next,
702 .stop = c_stop,
703 .show = show_cpuinfo
704};
705
706static DEFINE_PER_CPU(struct cpu, cpu_topology);
707
708static int __init topology_init(void)
709{
710 int cpu;
711
712 for_each_present_cpu(cpu)
713 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
714
715 return 0;
716}
717
718subsys_initcall(topology_init);