2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
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.
9 #include <linux/seq_file.h>
11 #include <linux/delay.h>
12 #include <linux/root_dev.h>
13 #include <linux/clk.h>
14 #include <linux/clk-provider.h>
15 #include <linux/clocksource.h>
16 #include <linux/console.h>
17 #include <linux/module.h>
18 #include <linux/cpu.h>
19 #include <linux/of_fdt.h>
21 #include <linux/cache.h>
22 #include <uapi/linux/mount.h>
23 #include <asm/sections.h>
24 #include <asm/arcregs.h>
26 #include <asm/setup.h>
29 #include <asm/unwind.h>
30 #include <asm/mach_desc.h>
33 #define FIX_PTR(x) __asm__ __volatile__(";" : "+r"(x))
35 unsigned int intr_to_DE_cnt;
37 /* Part of U-boot ABI: see head.S */
38 int __initdata uboot_tag;
39 int __initdata uboot_magic;
40 char __initdata *uboot_arg;
42 const struct machine_desc *machine_desc;
44 struct task_struct *_current_task[NR_CPUS]; /* For stack switching */
46 struct cpuinfo_arc cpuinfo_arc700[NR_CPUS];
48 static const struct id_to_str arc_legacy_rel[] = {
49 /* ID.ARCVER, Release */
50 #ifdef CONFIG_ISA_ARCOMPACT
61 static const struct id_to_str arc_cpu_rel[] = {
62 /* UARCH.MAJOR, Release */
68 static void read_decode_ccm_bcr(struct cpuinfo_arc *cpu)
70 if (is_isa_arcompact()) {
71 struct bcr_iccm_arcompact iccm;
72 struct bcr_dccm_arcompact dccm;
74 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
76 cpu->iccm.sz = 4096 << iccm.sz; /* 8K to 512K */
77 cpu->iccm.base_addr = iccm.base << 16;
80 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
83 cpu->dccm.sz = 2048 << dccm.sz; /* 2K to 256K */
85 base = read_aux_reg(ARC_REG_DCCM_BASE_BUILD);
86 cpu->dccm.base_addr = base & ~0xF;
89 struct bcr_iccm_arcv2 iccm;
90 struct bcr_dccm_arcv2 dccm;
93 READ_BCR(ARC_REG_ICCM_BUILD, iccm);
95 cpu->iccm.sz = 256 << iccm.sz00; /* 512B to 16M */
96 if (iccm.sz00 == 0xF && iccm.sz01 > 0)
97 cpu->iccm.sz <<= iccm.sz01;
99 region = read_aux_reg(ARC_REG_AUX_ICCM);
100 cpu->iccm.base_addr = region & 0xF0000000;
103 READ_BCR(ARC_REG_DCCM_BUILD, dccm);
105 cpu->dccm.sz = 256 << dccm.sz0;
106 if (dccm.sz0 == 0xF && dccm.sz1 > 0)
107 cpu->dccm.sz <<= dccm.sz1;
109 region = read_aux_reg(ARC_REG_AUX_DCCM);
110 cpu->dccm.base_addr = region & 0xF0000000;
115 static void decode_arc_core(struct cpuinfo_arc *cpu)
117 struct bcr_uarch_build_arcv2 uarch;
118 const struct id_to_str *tbl;
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)
126 if (cpu->core.family < 0x54) { /* includes arc700 */
128 for (tbl = &arc_legacy_rel[0]; tbl->id != 0; tbl++) {
129 if (cpu->core.family == tbl->id) {
130 cpu->release = tbl->str;
135 if (is_isa_arcompact())
136 cpu->name = "ARC700";
140 cpu->name = cpu->release = "Unknown";
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.
151 READ_BCR(ARC_REG_MICRO_ARCH_BCR, uarch);
153 if (uarch.prod == 4) {
161 for (tbl = &arc_cpu_rel[0]; tbl->id != 0xFF; tbl++) {
162 if (uarch.maj == tbl->id) {
163 cpu->release = tbl->str;
169 static void read_arc_build_cfg_regs(void)
171 struct bcr_timer timer;
172 struct bcr_generic bcr;
173 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
174 struct bcr_isa_arcv2 isa;
175 struct bcr_actionpoint ap;
179 READ_BCR(AUX_IDENTITY, cpu->core);
180 decode_arc_core(cpu);
182 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;
187 cpu->vec_base = read_aux_reg(AUX_INTR_VEC_BASE);
189 READ_BCR(ARC_REG_MUL_BCR, cpu->extn_mpy);
191 /* Read CCM BCRs for boot reporting even if not enabled in Kconfig */
192 read_decode_ccm_bcr(cpu);
194 read_decode_mmu_bcr();
195 read_decode_cache_bcr();
197 if (is_isa_arcompact()) {
198 struct bcr_fp_arcompact sp, dp;
199 struct bcr_bpu_arcompact bpu;
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;
206 READ_BCR(ARC_REG_BPU_BCR, bpu);
207 cpu->bpu.ver = bpu.ver;
208 cpu->bpu.full = bpu.fam ? 1 : 0;
210 cpu->bpu.num_cache = 256 << (bpu.ent - 1);
211 cpu->bpu.num_pred = 256 << (bpu.ent - 1);
214 struct bcr_fp_arcv2 spdp;
215 struct bcr_bpu_arcv2 bpu;
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;
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;
226 cpu->bpu.ret_stk = 4 << bpu.rse;
228 /* if dual issue hardware, is it enabled ? */
229 if (cpu->extn.dual) {
230 unsigned int exec_ctrl;
232 READ_BCR(AUX_EXEC_CTRL, exec_ctrl);
233 cpu->extn.dual_enb = !(exec_ctrl & 1);
237 READ_BCR(ARC_REG_AP_BCR, ap);
239 cpu->extn.ap_num = 2 << ap.num;
240 cpu->extn.ap_full = !ap.min;
243 READ_BCR(ARC_REG_SMART_BCR, bcr);
244 cpu->extn.smart = bcr.ver ? 1 : 0;
246 READ_BCR(ARC_REG_RTT_BCR, bcr);
247 cpu->extn.rtt = bcr.ver ? 1 : 0;
249 READ_BCR(ARC_REG_ISA_CFG_BCR, isa);
251 /* some hacks for lack of feature BCR info in old ARC700 cores */
252 if (is_isa_arcompact()) {
253 if (!isa.ver) /* ISA BCR absent, use Kconfig info */
254 cpu->isa.atomic = IS_ENABLED(CONFIG_ARC_HAS_LLSC);
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;
261 cpu->isa.be = IS_ENABLED(CONFIG_CPU_BIG_ENDIAN);
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";
271 static char *arc_cpu_mumbojumbo(int cpu_id, char *buf, int len)
273 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
274 struct bcr_identity *core = &cpu->core;
280 n += scnprintf(buf + n, len - n,
281 "\nIDENTITY\t: ARCVER [%#02x] ARCNUM [%#02x] CHIPID [%#4x]\n",
282 core->family, core->cpu_id, core->chip_id);
284 n += scnprintf(buf + n, len - n, "processor [%d]\t: %s %s (%s ISA) %s%s%s\n",
285 cpu_id, cpu->name, cpu->release,
286 is_isa_arcompact() ? "ARCompact" : "ARCv2",
287 IS_AVAIL1(cpu->isa.be, "[Big-Endian]"),
288 IS_AVAIL3(cpu->extn.dual, cpu->extn.dual_enb, " Dual-Issue "));
290 n += scnprintf(buf + n, len - n, "Timers\t\t: %s%s%s%s%s%s\nISA Extn\t: ",
291 IS_AVAIL1(cpu->extn.timer0, "Timer0 "),
292 IS_AVAIL1(cpu->extn.timer1, "Timer1 "),
293 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));
296 if (cpu->extn_mpy.ver) {
297 if (is_isa_arcompact()) {
298 scnprintf(mpy_opt, 16, "mpy");
301 int opt = 2; /* stock MPY/MPYH */
303 if (cpu->extn_mpy.dsp) /* OPT 7-9 */
304 opt = cpu->extn_mpy.dsp + 6;
306 scnprintf(mpy_opt, 16, "mpy[opt %d] ", opt);
310 n += scnprintf(buf + n, len - n, "%s%s%s%s%s%s%s%s\n",
311 IS_AVAIL2(cpu->isa.atomic, "atomic ", CONFIG_ARC_HAS_LLSC),
312 IS_AVAIL2(cpu->isa.ldd, "ll64 ", CONFIG_ARC_HAS_LL64),
313 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 "));
318 n += scnprintf(buf + n, len - n,
319 "BPU\t\t: %s%s match, cache:%d, Predict Table:%d Return stk: %d",
320 IS_AVAIL1(cpu->bpu.full, "full"),
321 IS_AVAIL1(!cpu->bpu.full, "partial"),
322 cpu->bpu.num_cache, cpu->bpu.num_pred, cpu->bpu.ret_stk);
324 if (is_isa_arcv2()) {
327 READ_BCR(ARC_REG_LPB_BUILD, lpb);
330 ctl = read_aux_reg(ARC_REG_LPB_CTRL);
332 n += scnprintf(buf + n, len - n, " Loop Buffer:%d %s",
334 IS_DISABLED_RUN(!ctl));
337 n += scnprintf(buf + n, len - n, "\n");
343 static char *arc_extn_mumbojumbo(int cpu_id, char *buf, int len)
346 struct cpuinfo_arc *cpu = &cpuinfo_arc700[cpu_id];
350 n += scnprintf(buf + n, len - n, "Vector Table\t: %#x\n", cpu->vec_base);
352 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 "));
357 if (cpu->extn.ap_num | cpu->extn.smart | cpu->extn.rtt) {
358 n += scnprintf(buf + n, len - n, "DEBUG\t\t: %s%s",
359 IS_AVAIL1(cpu->extn.smart, "smaRT "),
360 IS_AVAIL1(cpu->extn.rtt, "RTT "));
361 if (cpu->extn.ap_num) {
362 n += scnprintf(buf + n, len - n, "ActionPoint %d/%s",
364 cpu->extn.ap_full ? "full":"min");
366 n += scnprintf(buf + n, len - n, "\n");
369 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),
372 cpu->iccm.base_addr, TO_KB(cpu->iccm.sz));
374 if (is_isa_arcv2()) {
376 /* Error Protection: ECC/Parity */
378 READ_BCR(ARC_REG_ERP_BUILD, erp);
382 READ_BCR(ARC_REG_ERP_CTRL, ctl);
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 "));
395 static void arc_chk_core_config(void)
397 struct cpuinfo_arc *cpu = &cpuinfo_arc700[smp_processor_id()];
398 int saved = 0, present = 0;
401 if (!cpu->extn.timer0)
402 panic("Timer0 is not present!\n");
404 if (!cpu->extn.timer1)
405 panic("Timer1 is not present!\n");
407 #ifdef CONFIG_ARC_HAS_DCCM
409 * DCCM can be arbit placed in hardware.
410 * Make sure it's placement/sz matches what Linux is built with
412 if ((unsigned int)__arc_dccm_base != cpu->dccm.base_addr)
413 panic("Linux built with incorrect DCCM Base address\n");
415 if (CONFIG_ARC_DCCM_SZ != cpu->dccm.sz)
416 panic("Linux built with incorrect DCCM Size\n");
419 #ifdef CONFIG_ARC_HAS_ICCM
420 if (CONFIG_ARC_ICCM_SZ != cpu->iccm.sz)
421 panic("Linux built with incorrect ICCM Size\n");
425 * FP hardware/software config sanity
426 * -If hardware present, kernel needs to save/restore FPU state
427 * -If not, it will crash trying to save/restore the non-existant regs
430 if (is_isa_arcompact()) {
431 opt_nm = "CONFIG_ARC_FPU_SAVE_RESTORE";
432 saved = IS_ENABLED(CONFIG_ARC_FPU_SAVE_RESTORE);
434 /* only DPDP checked since SP has no arch visible regs */
435 present = cpu->extn.fpu_dp;
437 opt_nm = "CONFIG_ARC_HAS_ACCL_REGS";
438 saved = IS_ENABLED(CONFIG_ARC_HAS_ACCL_REGS);
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;
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);
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
456 void setup_processor(void)
459 int cpu_id = smp_processor_id();
461 read_arc_build_cfg_regs();
464 pr_info("%s", arc_cpu_mumbojumbo(cpu_id, str, sizeof(str)));
469 pr_info("%s", arc_extn_mumbojumbo(cpu_id, str, sizeof(str)));
470 pr_info("%s", arc_platform_smp_cpuinfo());
472 arc_chk_core_config();
475 static inline bool uboot_arg_invalid(unsigned long addr)
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)
481 if (addr < PAGE_OFFSET)
484 /* Check that address doesn't clobber resident kernel image */
485 return addr >= (unsigned long)_stext && addr <= (unsigned long)_end;
488 #define IGNORE_ARGS "Ignore U-boot args: "
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
494 /* We always pass 0 as magic from U-boot */
495 #define UBOOT_MAGIC_VALUE 0
497 void __init handle_uboot_args(void)
499 bool use_embedded_dtb = true;
500 bool append_cmdline = false;
502 /* 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;
510 if (uboot_magic != UBOOT_MAGIC_VALUE) {
511 pr_warn(IGNORE_ARGS "non zero uboot magic\n");
512 goto ignore_uboot_args;
515 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;
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);
525 /* external Device Tree blob is invalid - use embedded one */
526 use_embedded_dtb = !machine_desc;
529 if (uboot_tag == UBOOT_TAG_CMDLINE)
530 append_cmdline = true;
534 if (use_embedded_dtb) {
535 machine_desc = setup_machine_fdt(__dtb_start);
537 panic("Embedded DT invalid\n");
541 * NOTE: @boot_command_line is populated by setup_machine_fdt() so this
542 * append processing can only happen after.
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);
551 void __init setup_arch(char **cmdline_p)
555 /* Save unparsed command line copy for /proc/cmdline */
556 *cmdline_p = boot_command_line;
558 /* To force early parsing of things like mem=xxx */
561 /* Platform/board specific: e.g. early console registration */
562 if (machine_desc->init_early)
563 machine_desc->init_early();
570 /* copy flat DT out of .init and then unflatten it */
571 unflatten_and_copy_device_tree();
573 /* Can be issue if someone passes cmd line arg "ro"
574 * But that is unlikely so keeping it as it is
576 root_mountflags &= ~MS_RDONLY;
578 #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
579 conswitchp = &dummy_con;
586 * Called from start_kernel() - boot CPU only
588 void __init time_init(void)
594 static int __init customize_machine(void)
596 if (machine_desc->init_machine)
597 machine_desc->init_machine();
601 arch_initcall(customize_machine);
603 static int __init init_late_machine(void)
605 if (machine_desc->init_late)
606 machine_desc->init_late();
610 late_initcall(init_late_machine);
612 * Get CPU information for use by the procfs.
615 #define cpu_to_ptr(c) ((void *)(0xFFFF0000 | (unsigned int)(c)))
616 #define ptr_to_cpu(p) (~0xFFFF0000UL & (unsigned int)(p))
618 static int show_cpuinfo(struct seq_file *m, void *v)
621 int cpu_id = ptr_to_cpu(v);
622 struct device *cpu_dev = get_cpu_device(cpu_id);
624 unsigned long freq = 0;
626 if (!cpu_online(cpu_id)) {
627 seq_printf(m, "processor [%d]\t: Offline\n", cpu_id);
631 str = (char *)__get_free_page(GFP_KERNEL);
635 seq_printf(m, arc_cpu_mumbojumbo(cpu_id, str, PAGE_SIZE));
637 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",
642 freq = clk_get_rate(cpu_clk);
645 seq_printf(m, "CPU speed\t: %lu.%02lu Mhz\n",
646 freq / 1000000, (freq / 10000) % 100);
648 seq_printf(m, "Bogo MIPS\t: %lu.%02lu\n",
649 loops_per_jiffy / (500000 / HZ),
650 (loops_per_jiffy / (5000 / HZ)) % 100);
652 seq_printf(m, arc_mmu_mumbojumbo(cpu_id, str, PAGE_SIZE));
653 seq_printf(m, arc_cache_mumbojumbo(cpu_id, str, PAGE_SIZE));
654 seq_printf(m, arc_extn_mumbojumbo(cpu_id, str, PAGE_SIZE));
655 seq_printf(m, arc_platform_smp_cpuinfo());
657 free_page((unsigned long)str);
664 static void *c_start(struct seq_file *m, loff_t *pos)
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.
672 return *pos < nr_cpu_ids ? cpu_to_ptr(*pos) : NULL;
675 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
678 return c_start(m, pos);
681 static void c_stop(struct seq_file *m, void *v)
685 const struct seq_operations cpuinfo_op = {
692 static DEFINE_PER_CPU(struct cpu, cpu_topology);
694 static int __init topology_init(void)
698 for_each_present_cpu(cpu)
699 register_cpu(&per_cpu(cpu_topology, cpu), cpu);
704 subsys_initcall(topology_init);