blob: a9c88b7e9182f6232b3f319a00865c8c9946b38f [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 Gupta00a4ae62019-02-25 11:24:05 -080048static const struct id_to_str arc_legacy_rel[] = {
49 /* ID.ARCVER, Release */
Vineet Gupta73e284d2016-10-20 17:49:15 -070050#ifdef CONFIG_ISA_ARCOMPACT
Vineet Gupta00a4ae62019-02-25 11:24:05 -080051 { 0x34, "R4.10"},
52 { 0x35, "R4.11"},
Vineet Gupta73e284d2016-10-20 17:49:15 -070053#else
Vineet Gupta00a4ae62019-02-25 11:24:05 -080054 { 0x51, "R2.0" },
55 { 0x52, "R2.1" },
56 { 0x53, "R3.0" },
Vineet Gupta73e284d2016-10-20 17:49:15 -070057#endif
Vineet Gupta00a4ae62019-02-25 11:24:05 -080058 { 0x00, NULL }
Vineet Guptad975cbc2016-10-27 14:33:19 -070059};
60
Vineet Gupta00a4ae62019-02-25 11:24:05 -080061static const struct id_to_str arc_cpu_rel[] = {
62 /* UARCH.MAJOR, Release */
63 { 0, "R3.10a"},
64 { 1, "R3.50a"},
65 { 0xFF, NULL }
Vineet Gupta73e284d2016-10-20 17:49:15 -070066};
67
Vineet Guptaa150b082016-02-16 12:36:18 +053068static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
69{
70 if (is_isa_arcompact()) {
71 struct bcr_iccm_arcompact iccm;
72 struct bcr_dccm_arcompact dccm;
73
74 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
75 if (iccm.ver) {
76 cpu->iccm.sz = 4096 << iccm.sz; /* 8K to 512K */
77 cpu->iccm.base_addr = iccm.base << 16;
78 }
79
80 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
81 if (dccm.ver) {
82 unsigned long base;
83 cpu->dccm.sz = 2048 << dccm.sz; /* 2K to 256K */
84
85 base = read_aux_reg(ARC_REG_DCCM_BASE_BUILD);
86 cpu->dccm.base_addr = base & ~0xF;
87 }
88 } else {
89 struct bcr_iccm_arcv2 iccm;
90 struct bcr_dccm_arcv2 dccm;
91 unsigned long region;
92
93 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
94 if (iccm.ver) {
95 cpu->iccm.sz = 256 << iccm.sz00; /* 512B to 16M */
96 if (iccm.sz00 == 0xF && iccm.sz01 > 0)
97 cpu->iccm.sz <<= iccm.sz01;
98
99 region = read_aux_reg(ARC_REG_AUX_ICCM);
100 cpu->iccm.base_addr = region & 0xF0000000;
101 }
102
103 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
104 if (dccm.ver) {
105 cpu->dccm.sz = 256 << dccm.sz0;
106 if (dccm.sz0 == 0xF && dccm.sz1 > 0)
107 cpu->dccm.sz <<= dccm.sz1;
108
109 region = read_aux_reg(ARC_REG_AUX_DCCM);
110 cpu->dccm.base_addr = region & 0xF0000000;
111 }
112 }
113}
114
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800115static void decode_arc_core(struct cpuinfo_arc *cpu)
116{
117 struct bcr_uarch_build_arcv2 uarch;
118 const struct id_to_str *tbl;
119
120 /*
121 * Up until (including) the first core4 release (0x54) things were
122 * simple: AUX IDENTITY.ARCVER was sufficient to identify arc family
123 * and release: 0x50 to 0x53 was HS38, 0x54 was HS48 (dual issue)
124 */
125
126 if (cpu->core.family < 0x54) { /* includes arc700 */
127
128 for (tbl = &arc_legacy_rel[0]; tbl->id != 0; tbl++) {
129 if (cpu->core.family == tbl->id) {
130 cpu->release = tbl->str;
131 break;
132 }
133 }
134
135 if (is_isa_arcompact())
136 cpu->name = "ARC700";
137 else if (tbl->str)
138 cpu->name = "HS38";
139 else
140 cpu->name = cpu->release = "Unknown";
141
142 return;
143 }
144
145 /*
146 * However the subsequent HS release (same 0x54) allow HS38 or HS48
147 * configurations and encode this info in a different BCR.
148 * The BCR was introduced in 0x54 so can't be read unconditionally.
149 */
150
151 READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
152
153 if (uarch.prod == 4) {
154 cpu->name = "HS48";
155 cpu->extn.dual = 1;
156
157 } else {
158 cpu->name = "HS38";
159 }
160
161 for (tbl = &arc_cpu_rel[0]; tbl->id != 0xFF; tbl++) {
162 if (uarch.maj == tbl->id) {
163 cpu->release = tbl->str;
164 break;
165 }
166 }
167}
168
Vineet Gupta8e457d62013-09-04 16:13:35 +0530169static void read_arc_build_cfg_regs(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530170{
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530171 struct bcr_timer timer;
Vineet Gupta56372082014-09-25 16:54:43 +0530172 struct bcr_generic bcr;
Vineet Guptaaf617422013-01-18 15:12:24 +0530173 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Gupta010a8c92017-09-21 17:46:38 -0700174 struct bcr_isa_arcv2 isa;
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800175 struct bcr_actionpoint ap;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700176
Vineet Guptaaf617422013-01-18 15:12:24 +0530177 FIX_PTR(cpu);
178
179 READ_BCR(AUX_IDENTITY, cpu->core);
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800180 decode_arc_core(cpu);
Vineet Gupta73e284d2016-10-20 17:49:15 -0700181
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530182 READ_BCR(ARC_REG_TIMERS_BCR, timer);
183 cpu->extn.timer0 = timer.t0;
184 cpu->extn.timer1 = timer.t1;
185 cpu->extn.rtc = timer.rtc;
186
Vineet Guptaaf617422013-01-18 15:12:24 +0530187 cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
Vineet Guptaaf617422013-01-18 15:12:24 +0530188
Vineet Gupta56372082014-09-25 16:54:43 +0530189 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
Vineet Guptaaf617422013-01-18 15:12:24 +0530190
Vineet Guptaa150b082016-02-16 12:36:18 +0530191 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
192 read_decode_ccm_bcr(cpu);
193
Vineet Guptac121c502013-01-18 15:12:20 +0530194 read_decode_mmu_bcr();
195 read_decode_cache_bcr();
Vineet Guptaaf617422013-01-18 15:12:24 +0530196
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530197 if (is_isa_arcompact()) {
Vineet Gupta56372082014-09-25 16:54:43 +0530198 struct bcr_fp_arcompact sp, dp;
199 struct bcr_bpu_arcompact bpu;
200
201 READ_BCR(ARC_REG_FP_BCR, sp);
202 READ_BCR(ARC_REG_DPFP_BCR, dp);
203 cpu->extn.fpu_sp = sp.ver ? 1 : 0;
204 cpu->extn.fpu_dp = dp.ver ? 1 : 0;
205
206 READ_BCR(ARC_REG_BPU_BCR, bpu);
207 cpu->bpu.ver = bpu.ver;
208 cpu->bpu.full = bpu.fam ? 1 : 0;
209 if (bpu.ent) {
210 cpu->bpu.num_cache = 256 << (bpu.ent - 1);
211 cpu->bpu.num_pred = 256 << (bpu.ent - 1);
212 }
Vineet Gupta1f6ccff2013-05-13 18:30:41 +0530213 } else {
214 struct bcr_fp_arcv2 spdp;
215 struct bcr_bpu_arcv2 bpu;
216
217 READ_BCR(ARC_REG_FP_V2_BCR, spdp);
218 cpu->extn.fpu_sp = spdp.sp ? 1 : 0;
219 cpu->extn.fpu_dp = spdp.dp ? 1 : 0;
220
221 READ_BCR(ARC_REG_BPU_BCR, bpu);
222 cpu->bpu.ver = bpu.ver;
223 cpu->bpu.full = bpu.ft;
224 cpu->bpu.num_cache = 256 << bpu.bce;
225 cpu->bpu.num_pred = 2048 << bpu.pte;
Vineet Gupta97e98132018-12-06 00:17:50 -0800226 cpu->bpu.ret_stk = 4 << bpu.rse;
Vineet Guptadea82522017-09-21 18:02:44 -0700227
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800228 /* if dual issue hardware, is it enabled ? */
229 if (cpu->extn.dual) {
230 unsigned int exec_ctrl;
Vineet Guptadea82522017-09-21 18:02:44 -0700231
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800232 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
233 cpu->extn.dual_enb = !(exec_ctrl & 1);
Vineet Guptadea82522017-09-21 18:02:44 -0700234 }
Vineet Gupta56372082014-09-25 16:54:43 +0530235 }
236
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800237 READ_BCR(ARC_REG_AP_BCR, ap);
238 if (ap.ver) {
239 cpu->extn.ap_num = 2 << ap.num;
Eugeniy Paltsevcdf92962019-02-04 21:41:51 +0300240 cpu->extn.ap_full = !ap.min;
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800241 }
Vineet Gupta56372082014-09-25 16:54:43 +0530242
243 READ_BCR(ARC_REG_SMART_BCR, bcr);
244 cpu->extn.smart = bcr.ver ? 1 : 0;
245
Vineet Guptaa44ec8bd2015-03-08 14:18:21 +0530246 READ_BCR(ARC_REG_RTT_BCR, bcr);
247 cpu->extn.rtt = bcr.ver ? 1 : 0;
248
Vineet Gupta010a8c92017-09-21 17:46:38 -0700249 READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
250
Vineet Gupta73e284d2016-10-20 17:49:15 -0700251 /* some hacks for lack of feature BCR info in old ARC700 cores */
252 if (is_isa_arcompact()) {
Vineet Gupta010a8c92017-09-21 17:46:38 -0700253 if (!isa.ver) /* ISA BCR absent, use Kconfig info */
Vineet Gupta73e284d2016-10-20 17:49:15 -0700254 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
Vineet Gupta010a8c92017-09-21 17:46:38 -0700255 else {
256 /* ARC700_BUILD only has 2 bits of isa info */
257 struct bcr_generic bcr = *(struct bcr_generic *)&isa;
258 cpu->isa.atomic = bcr.info & 1;
259 }
Vineet Gupta73e284d2016-10-20 17:49:15 -0700260
261 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
Vineet Guptad975cbc2016-10-27 14:33:19 -0700262
263 /* there's no direct way to distinguish 750 vs. 770 */
264 if (unlikely(cpu->core.family < 0x34 || cpu->mmu.ver < 3))
265 cpu->name = "ARC750";
Vineet Gupta010a8c92017-09-21 17:46:38 -0700266 } else {
267 cpu->isa = isa;
Vineet Gupta73e284d2016-10-20 17:49:15 -0700268 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530269}
270
Vineet Gupta8e457d62013-09-04 16:13:35 +0530271static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530272{
Vineet Guptaaf617422013-01-18 15:12:24 +0530273 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
274 struct bcr_identity *core = &cpu->core;
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800275 char mpy_opt[16];
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300276 int n = 0;
Vineet Gupta56372082014-09-25 16:54:43 +0530277
Vineet Guptaaf617422013-01-18 15:12:24 +0530278 FIX_PTR(cpu);
279
280 n += scnprintf(buf + n, len - n,
Vineet Gupta56372082014-09-25 16:54:43 +0530281 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
282 core->family, core->cpu_id, core->chip_id);
Vineet Guptaaf617422013-01-18 15:12:24 +0530283
Vineet Guptadea82522017-09-21 18:02:44 -0700284 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
Vineet Gupta00a4ae62019-02-25 11:24:05 -0800285 cpu_id, cpu->name, cpu->release,
Vineet Gupta73e284d2016-10-20 17:49:15 -0700286 is_isa_arcompact() ? "ARCompact" : "ARCv2",
Vineet Guptadea82522017-09-21 18:02:44 -0700287 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
Vineet Guptaf3156852017-11-10 12:40:00 -0800288 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530289
Vineet Gupta04421422016-10-31 14:26:41 -0700290 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 +0530291 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
292 IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
Vineet Gupta04421422016-10-31 14:26:41 -0700293 IS_AVAIL2(cpu->extn.rtc, "RTC [UP 64-bit] ", CONFIG_ARC_TIMERS_64BIT),
294 IS_AVAIL2(cpu->extn.gfrc, "GFRC [SMP 64-bit] ", CONFIG_ARC_TIMERS_64BIT));
Vineet Guptaaf617422013-01-18 15:12:24 +0530295
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800296 if (cpu->extn_mpy.ver) {
297 if (is_isa_arcompact()) {
298 scnprintf(mpy_opt, 16, "mpy");
299 } else {
300
301 int opt = 2; /* stock MPY/MPYH */
302
303 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
304 opt = cpu->extn_mpy.dsp + 6;
305
306 scnprintf(mpy_opt, 16, "mpy[opt %d] ", opt);
307 }
308 }
309
310 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
Eugeniy Paltsev76551462019-01-30 19:32:41 +0300311 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
312 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800313 IS_AVAIL2(cpu->isa.unalign, "unalign ", CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS),
314 IS_AVAIL1(cpu->extn_mpy.ver, mpy_opt),
315 IS_AVAIL1(cpu->isa.div_rem, "div_rem "));
316
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800317 if (cpu->bpu.ver) {
Vineet Gupta56372082014-09-25 16:54:43 +0530318 n += scnprintf(buf + n, len - n,
Vineet Gupta97e98132018-12-06 00:17:50 -0800319 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d",
Vineet Gupta56372082014-09-25 16:54:43 +0530320 IS_AVAIL1(cpu->bpu.full, "full"),
321 IS_AVAIL1(!cpu->bpu.full, "partial"),
Vineet Gupta97e98132018-12-06 00:17:50 -0800322 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk);
Vineet Guptaaf617422013-01-18 15:12:24 +0530323
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800324 if (is_isa_arcv2()) {
325 struct bcr_lpb lpb;
Vineet Guptaf3156852017-11-10 12:40:00 -0800326
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800327 READ_BCR(ARC_REG_LPB_BUILD, lpb);
328 if (lpb.ver) {
329 unsigned int ctl;
330 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
Vineet Guptaf3156852017-11-10 12:40:00 -0800331
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800332 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
333 lpb.entries,
334 IS_DISABLED_RUN(!ctl));
335 }
Vineet Guptaf3156852017-11-10 12:40:00 -0800336 }
Vineet Gupta85d6adc2019-02-25 11:56:28 -0800337 n += scnprintf(buf + n, len - n, "\n");
Vineet Guptaf3156852017-11-10 12:40:00 -0800338 }
339
Vineet Guptaaf617422013-01-18 15:12:24 +0530340 return buf;
341}
342
Vineet Gupta8e457d62013-09-04 16:13:35 +0530343static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
Vineet Guptaaf617422013-01-18 15:12:24 +0530344{
345 int n = 0;
346 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
347
348 FIX_PTR(cpu);
Vineet Guptaaf617422013-01-18 15:12:24 +0530349
Vineet Gupta711c1f22016-10-13 15:53:02 -0700350 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
Vineet Guptaaf617422013-01-18 15:12:24 +0530351
Vineet Gupta56372082014-09-25 16:54:43 +0530352 if (cpu->extn.fpu_sp || cpu->extn.fpu_dp)
353 n += scnprintf(buf + n, len - n, "FPU\t\t: %s%s\n",
354 IS_AVAIL1(cpu->extn.fpu_sp, "SP "),
355 IS_AVAIL1(cpu->extn.fpu_dp, "DP "));
Vineet Guptaaf617422013-01-18 15:12:24 +0530356
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800357 if (cpu->extn.ap_num | cpu->extn.smart | cpu->extn.rtt) {
358 n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s",
Vineet Gupta56372082014-09-25 16:54:43 +0530359 IS_AVAIL1(cpu->extn.smart, "smaRT "),
360 IS_AVAIL1(cpu->extn.rtt, "RTT "));
Vineet Gupta7dd380c2019-01-09 09:36:00 -0800361 if (cpu->extn.ap_num) {
362 n += scnprintf(buf + n, len - n, "ActionPoint %d/%s",
363 cpu->extn.ap_num,
364 cpu->extn.ap_full ? "full":"min");
365 }
366 n += scnprintf(buf + n, len - n, "\n");
367 }
Vineet Guptaaf617422013-01-18 15:12:24 +0530368
Vineet Gupta56372082014-09-25 16:54:43 +0530369 if (cpu->dccm.sz || cpu->iccm.sz)
370 n += scnprintf(buf + n, len - n, "Extn [CCM]\t: DCCM @ %x, %d KB / ICCM: @ %x, %d KB\n",
371 cpu->dccm.base_addr, TO_KB(cpu->dccm.sz),
Vineet Guptaaf617422013-01-18 15:12:24 +0530372 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
373
Vineet Guptaf3156852017-11-10 12:40:00 -0800374 if (is_isa_arcv2()) {
375
376 /* Error Protection: ECC/Parity */
377 struct bcr_erp erp;
378 READ_BCR(ARC_REG_ERP_BUILD, erp);
379
380 if (erp.ver) {
381 struct ctl_erp ctl;
382 READ_BCR(ARC_REG_ERP_CTRL, ctl);
383
384 /* inverted bits: 0 means enabled */
385 n += scnprintf(buf + n, len - n, "Extn [ECC]\t: %s%s%s%s%s%s\n",
386 IS_AVAIL3(erp.ic, !ctl.dpi, "IC "),
387 IS_AVAIL3(erp.dc, !ctl.dpd, "DC "),
388 IS_AVAIL3(erp.mmu, !ctl.mpd, "MMU "));
389 }
390 }
391
Vineet Guptaaf617422013-01-18 15:12:24 +0530392 return buf;
393}
394
Vineet Guptac4b98562014-09-25 16:07:44 +0530395static void arc_chk_core_config(void)
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530396{
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530397 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700398 int saved = 0, present = 0;
Luis de Bethencourta46f24a2018-01-23 15:16:09 +0000399 char *opt_nm = NULL;
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530400
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530401 if (!cpu->extn.timer0)
Vineet Gupta56372082014-09-25 16:54:43 +0530402 panic("Timer0 is not present!\n");
403
Vineet Guptab89bd1f2016-01-22 15:20:18 +0530404 if (!cpu->extn.timer1)
Vineet Gupta56372082014-09-25 16:54:43 +0530405 panic("Timer1 is not present!\n");
406
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530407#ifdef CONFIG_ARC_HAS_DCCM
408 /*
409 * DCCM can be arbit placed in hardware.
410 * Make sure it's placement/sz matches what Linux is built with
411 */
412 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
413 panic("Linux built with incorrect DCCM Base address\n");
414
415 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
416 panic("Linux built with incorrect DCCM Size\n");
417#endif
418
419#ifdef CONFIG_ARC_HAS_ICCM
420 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
421 panic("Linux built with incorrect ICCM Size\n");
422#endif
Vineet Gupta8b5850f2013-01-18 15:12:25 +0530423
Vineet Guptac4b98562014-09-25 16:07:44 +0530424 /*
425 * FP hardware/software config sanity
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700426 * -If hardware present, kernel needs to save/restore FPU state
Vineet Guptac4b98562014-09-25 16:07:44 +0530427 * -If not, it will crash trying to save/restore the non-existant regs
Vineet Guptac4b98562014-09-25 16:07:44 +0530428 */
Vineet Guptaaf617422013-01-18 15:12:24 +0530429
Vineet Gupta3d5e8012017-04-20 15:36:51 -0700430 if (is_isa_arcompact()) {
431 opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
432 saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
433
434 /* only DPDP checked since SP has no arch visible regs */
435 present = cpu->extn.fpu_dp;
436 } else {
437 opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
438 saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
439
440 /* Accumulator Low:High pair (r58:59) present if DSP MPY or FPU */
441 present = cpu->extn_mpy.dsp | cpu->extn.fpu_sp | cpu->extn.fpu_dp;
442 }
443
444 if (present && !saved)
445 pr_warn("Enable %s for working apps\n", opt_nm);
446 else if (!present && saved)
447 panic("Disable %s, hardware NOT present\n", opt_nm);
Vineet Guptac121c502013-01-18 15:12:20 +0530448}
449
450/*
451 * Initialize and setup the processor core
452 * This is called by all the CPUs thus should not do special case stuff
453 * such as only for boot CPU etc
454 */
455
Paul Gortmakerce759952013-06-24 15:30:15 -0400456void setup_processor(void)
Vineet Guptac121c502013-01-18 15:12:20 +0530457{
Vineet Guptaaf617422013-01-18 15:12:24 +0530458 char str[512];
459 int cpu_id = smp_processor_id();
460
Vineet Guptac121c502013-01-18 15:12:20 +0530461 read_arc_build_cfg_regs();
462 arc_init_IRQ();
Vineet Guptaaf617422013-01-18 15:12:24 +0530463
Noam Camus18ee4be2017-06-15 11:43:51 +0300464 pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
Vineet Guptaaf617422013-01-18 15:12:24 +0530465
Vineet Guptac121c502013-01-18 15:12:20 +0530466 arc_mmu_init();
467 arc_cache_init();
Vineet Guptaaf617422013-01-18 15:12:24 +0530468
Noam Camus18ee4be2017-06-15 11:43:51 +0300469 pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
470 pr_info("%s", arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530471
Vineet Guptac4b98562014-09-25 16:07:44 +0530472 arc_chk_core_config();
Vineet Guptac121c502013-01-18 15:12:20 +0530473}
474
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300475static inline bool uboot_arg_invalid(unsigned long addr)
Vineet Gupta59ed9412014-01-16 15:01:24 +0530476{
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300477 /*
478 * Check that it is a untranslated address (although MMU is not enabled
479 * yet, it being a high address ensures this is not by fluke)
480 */
481 if (addr < PAGE_OFFSET)
482 return true;
483
484 /* Check that address doesn't clobber resident kernel image */
485 return addr >= (unsigned long)_stext && addr <= (unsigned long)_end;
486}
487
488#define IGNORE_ARGS "Ignore U-boot args: "
489
490/* uboot_tag values for U-boot - kernel ABI revision 0; see head.S */
491#define UBOOT_TAG_NONE 0
492#define UBOOT_TAG_CMDLINE 1
493#define UBOOT_TAG_DTB 2
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300494/* We always pass 0 as magic from U-boot */
495#define UBOOT_MAGIC_VALUE 0
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300496
497void __init handle_uboot_args(void)
498{
499 bool use_embedded_dtb = true;
500 bool append_cmdline = false;
501
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300502 /* check that we know this tag */
503 if (uboot_tag != UBOOT_TAG_NONE &&
504 uboot_tag != UBOOT_TAG_CMDLINE &&
505 uboot_tag != UBOOT_TAG_DTB) {
506 pr_warn(IGNORE_ARGS "invalid uboot tag: '%08x'\n", uboot_tag);
507 goto ignore_uboot_args;
508 }
509
Eugeniy Paltsevedb64bc2019-02-25 20:16:01 +0300510 if (uboot_magic != UBOOT_MAGIC_VALUE) {
511 pr_warn(IGNORE_ARGS "non zero uboot magic\n");
512 goto ignore_uboot_args;
513 }
514
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300515 if (uboot_tag != UBOOT_TAG_NONE &&
516 uboot_arg_invalid((unsigned long)uboot_arg)) {
517 pr_warn(IGNORE_ARGS "invalid uboot arg: '%px'\n", uboot_arg);
518 goto ignore_uboot_args;
519 }
520
521 /* see if U-boot passed an external Device Tree blob */
522 if (uboot_tag == UBOOT_TAG_DTB) {
523 machine_desc = setup_machine_fdt((void *)uboot_arg);
524
525 /* external Device Tree blob is invalid - use embedded one */
526 use_embedded_dtb = !machine_desc;
527 }
528
529 if (uboot_tag == UBOOT_TAG_CMDLINE)
530 append_cmdline = true;
531
532ignore_uboot_args:
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300533
534 if (use_embedded_dtb) {
535 machine_desc = setup_machine_fdt(__dtb_start);
536 if (!machine_desc)
537 panic("Embedded DT invalid\n");
538 }
539
540 /*
541 * NOTE: @boot_command_line is populated by setup_machine_fdt() so this
542 * append processing can only happen after.
543 */
544 if (append_cmdline) {
545 /* Ensure a whitespace between the 2 cmdlines */
546 strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
547 strlcat(boot_command_line, uboot_arg, COMMAND_LINE_SIZE);
548 }
Vineet Gupta59ed9412014-01-16 15:01:24 +0530549}
550
Vineet Guptac121c502013-01-18 15:12:20 +0530551void __init setup_arch(char **cmdline_p)
552{
Eugeniy Paltseva66f2e52019-02-14 18:07:44 +0300553 handle_uboot_args();
Vineet Gupta9593a932013-04-09 16:18:04 +0530554
555 /* Save unparsed command line copy for /proc/cmdline */
556 *cmdline_p = boot_command_line;
557
Vineet Guptac121c502013-01-18 15:12:20 +0530558 /* To force early parsing of things like mem=xxx */
559 parse_early_param();
560
561 /* Platform/board specific: e.g. early console registration */
Vineet Gupta03a6d282013-01-18 15:12:26 +0530562 if (machine_desc->init_early)
563 machine_desc->init_early();
Vineet Guptac121c502013-01-18 15:12:20 +0530564
Vineet Gupta41195d22013-01-18 15:12:23 +0530565 smp_init_cpus();
Vineet Guptae55af4d2015-10-12 16:28:55 +0530566
567 setup_processor();
Vineet Guptac121c502013-01-18 15:12:20 +0530568 setup_arch_memory();
569
Vineet Guptaeab6a082013-02-21 17:37:06 +0530570 /* copy flat DT out of .init and then unflatten it */
Rob Herring1efc9592013-08-26 11:23:27 -0500571 unflatten_and_copy_device_tree();
Vineet Gupta999159a2013-01-22 17:00:52 +0530572
Vineet Guptac121c502013-01-18 15:12:20 +0530573 /* Can be issue if someone passes cmd line arg "ro"
574 * But that is unlikely so keeping it as it is
575 */
576 root_mountflags &= ~MS_RDONLY;
577
Vineet Guptac121c502013-01-18 15:12:20 +0530578#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
579 conswitchp = &dummy_con;
580#endif
581
Vineet Gupta854a0d92013-01-22 17:03:19 +0530582 arc_unwind_init();
Vineet Guptac121c502013-01-18 15:12:20 +0530583}
584
Vineet Gupta92b03312016-10-31 13:26:25 -0700585/*
586 * Called from start_kernel() - boot CPU only
587 */
588void __init time_init(void)
589{
590 of_clk_init(NULL);
Daniel Lezcanoba5d08c2017-05-26 17:40:46 +0200591 timer_probe();
Vineet Gupta92b03312016-10-31 13:26:25 -0700592}
593
Vineet Gupta03a6d282013-01-18 15:12:26 +0530594static int __init customize_machine(void)
595{
Vineet Gupta03a6d282013-01-18 15:12:26 +0530596 if (machine_desc->init_machine)
597 machine_desc->init_machine();
598
599 return 0;
600}
601arch_initcall(customize_machine);
602
603static int __init init_late_machine(void)
604{
605 if (machine_desc->init_late)
606 machine_desc->init_late();
607
608 return 0;
609}
610late_initcall(init_late_machine);
Vineet Guptac121c502013-01-18 15:12:20 +0530611/*
612 * Get CPU information for use by the procfs.
613 */
614
615#define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
616#define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
617
618static int show_cpuinfo(struct seq_file *m, void *v)
619{
620 char *str;
621 int cpu_id = ptr_to_cpu(v);
Vlad Zakharov7f351442017-03-03 14:30:02 +0300622 struct device *cpu_dev = get_cpu_device(cpu_id);
623 struct clk *cpu_clk;
624 unsigned long freq = 0;
Vineet Guptac121c502013-01-18 15:12:20 +0530625
Vineet Gupta4c862312014-12-12 10:05:03 +0530626 if (!cpu_online(cpu_id)) {
627 seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
628 goto done;
629 }
630
Michal Hocko0ee931c2017-09-13 16:28:29 -0700631 str = (char *)__get_free_page(GFP_KERNEL);
Vineet Guptac121c502013-01-18 15:12:20 +0530632 if (!str)
633 goto done;
634
Vineet Guptaaf617422013-01-18 15:12:24 +0530635 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptac121c502013-01-18 15:12:20 +0530636
Vlad Zakharov7f351442017-03-03 14:30:02 +0300637 cpu_clk = clk_get(cpu_dev, NULL);
638 if (IS_ERR(cpu_clk)) {
639 seq_printf(m, "CPU speed \t: Cannot get clock for processor [%d]\n",
640 cpu_id);
641 } else {
642 freq = clk_get_rate(cpu_clk);
643 }
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300644 if (freq)
Vlad Zakharov7f351442017-03-03 14:30:02 +0300645 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
Alexey Brodkin20c7dbb2016-02-01 17:30:17 +0300646 freq / 1000000, (freq / 10000) % 100);
647
Vineet Gupta56372082014-09-25 16:54:43 +0530648 seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
Vineet Guptac121c502013-01-18 15:12:20 +0530649 loops_per_jiffy / (500000 / HZ),
650 (loops_per_jiffy / (5000 / HZ)) % 100);
651
Vineet Guptaaf617422013-01-18 15:12:24 +0530652 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530653 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530654 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
Vineet Guptaaf617422013-01-18 15:12:24 +0530655 seq_printf(m, arc_platform_smp_cpuinfo());
Vineet Guptaaf617422013-01-18 15:12:24 +0530656
Vineet Guptac121c502013-01-18 15:12:20 +0530657 free_page((unsigned long)str);
658done:
Vineet Gupta4c862312014-12-12 10:05:03 +0530659 seq_printf(m, "\n");
Vineet Guptac121c502013-01-18 15:12:20 +0530660
661 return 0;
662}
663
664static void *c_start(struct seq_file *m, loff_t *pos)
665{
666 /*
667 * Callback returns cpu-id to iterator for show routine, NULL to stop.
668 * However since NULL is also a valid cpu-id (0), we use a round-about
669 * way to pass it w/o having to kmalloc/free a 2 byte string.
670 * Encode cpu-id as 0xFFcccc, which is decoded by show routine.
671 */
Noam Camus3da431042016-10-19 14:25:03 +0300672 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
Vineet Guptac121c502013-01-18 15:12:20 +0530673}
674
675static void *c_next(struct seq_file *m, void *v, loff_t *pos)
676{
677 ++*pos;
678 return c_start(m, pos);
679}
680
681static void c_stop(struct seq_file *m, void *v)
682{
683}
684
685const struct seq_operations cpuinfo_op = {
686 .start = c_start,
687 .next = c_next,
688 .stop = c_stop,
689 .show = show_cpuinfo
690};
691
692static DEFINE_PER_CPU(struct cpu, cpu_topology);
693
694static int __init topology_init(void)
695{
696 int cpu;
697
698 for_each_present_cpu(cpu)
699 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
700
701 return 0;
702}
703
704subsys_initcall(topology_init);