1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2013 Altera Corporation
4 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
6 * Based on cpuinfo.c from microblaze
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <linux/delay.h>
12 #include <linux/seq_file.h>
13 #include <linux/string.h>
15 #include <asm/cpuinfo.h>
17 struct cpuinfo cpuinfo
;
20 pr_err("ERROR: Nios II " x " different for kernel and DTS\n")
22 static inline u32
fcpu(struct device_node
*cpu
, const char *n
)
26 of_property_read_u32(cpu
, n
, &val
);
31 void __init
setup_cpuinfo(void)
33 struct device_node
*cpu
;
37 cpu
= of_get_cpu_node(0, NULL
);
39 panic("%s: No CPU found in devicetree!\n", __func__
);
41 if (!of_property_read_bool(cpu
, "altr,has-initda"))
42 panic("initda instruction is unimplemented. Please update your "
43 "hardware system to have more than 4-byte line data "
46 cpuinfo
.cpu_clock_freq
= fcpu(cpu
, "clock-frequency");
48 str
= of_get_property(cpu
, "altr,implementation", &len
);
50 strlcpy(cpuinfo
.cpu_impl
, str
, sizeof(cpuinfo
.cpu_impl
));
52 strcpy(cpuinfo
.cpu_impl
, "<unknown>");
54 cpuinfo
.has_div
= of_property_read_bool(cpu
, "altr,has-div");
55 cpuinfo
.has_mul
= of_property_read_bool(cpu
, "altr,has-mul");
56 cpuinfo
.has_mulx
= of_property_read_bool(cpu
, "altr,has-mulx");
57 cpuinfo
.has_bmx
= of_property_read_bool(cpu
, "altr,has-bmx");
58 cpuinfo
.has_cdx
= of_property_read_bool(cpu
, "altr,has-cdx");
59 cpuinfo
.mmu
= of_property_read_bool(cpu
, "altr,has-mmu");
61 if (IS_ENABLED(CONFIG_NIOS2_HW_DIV_SUPPORT
) && !cpuinfo
.has_div
)
64 if (IS_ENABLED(CONFIG_NIOS2_HW_MUL_SUPPORT
) && !cpuinfo
.has_mul
)
67 if (IS_ENABLED(CONFIG_NIOS2_HW_MULX_SUPPORT
) && !cpuinfo
.has_mulx
)
70 if (IS_ENABLED(CONFIG_NIOS2_BMX_SUPPORT
) && !cpuinfo
.has_bmx
)
73 if (IS_ENABLED(CONFIG_NIOS2_CDX_SUPPORT
) && !cpuinfo
.has_cdx
)
76 cpuinfo
.tlb_num_ways
= fcpu(cpu
, "altr,tlb-num-ways");
77 if (!cpuinfo
.tlb_num_ways
)
78 panic("altr,tlb-num-ways can't be 0. Please check your hardware "
80 cpuinfo
.icache_line_size
= fcpu(cpu
, "icache-line-size");
81 cpuinfo
.icache_size
= fcpu(cpu
, "icache-size");
82 if (CONFIG_NIOS2_ICACHE_SIZE
!= cpuinfo
.icache_size
)
83 pr_warn("Warning: icache size configuration mismatch "
84 "(0x%x vs 0x%x) of CONFIG_NIOS2_ICACHE_SIZE vs "
85 "device tree icache-size\n",
86 CONFIG_NIOS2_ICACHE_SIZE
, cpuinfo
.icache_size
);
88 cpuinfo
.dcache_line_size
= fcpu(cpu
, "dcache-line-size");
89 if (CONFIG_NIOS2_DCACHE_LINE_SIZE
!= cpuinfo
.dcache_line_size
)
90 pr_warn("Warning: dcache line size configuration mismatch "
91 "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_LINE_SIZE vs "
92 "device tree dcache-line-size\n",
93 CONFIG_NIOS2_DCACHE_LINE_SIZE
, cpuinfo
.dcache_line_size
);
94 cpuinfo
.dcache_size
= fcpu(cpu
, "dcache-size");
95 if (CONFIG_NIOS2_DCACHE_SIZE
!= cpuinfo
.dcache_size
)
96 pr_warn("Warning: dcache size configuration mismatch "
97 "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_SIZE vs "
98 "device tree dcache-size\n",
99 CONFIG_NIOS2_DCACHE_SIZE
, cpuinfo
.dcache_size
);
101 cpuinfo
.tlb_pid_num_bits
= fcpu(cpu
, "altr,pid-num-bits");
102 cpuinfo
.tlb_num_ways_log2
= ilog2(cpuinfo
.tlb_num_ways
);
103 cpuinfo
.tlb_num_entries
= fcpu(cpu
, "altr,tlb-num-entries");
104 cpuinfo
.tlb_num_lines
= cpuinfo
.tlb_num_entries
/ cpuinfo
.tlb_num_ways
;
105 cpuinfo
.tlb_ptr_sz
= fcpu(cpu
, "altr,tlb-ptr-sz");
107 cpuinfo
.reset_addr
= fcpu(cpu
, "altr,reset-addr");
108 cpuinfo
.exception_addr
= fcpu(cpu
, "altr,exception-addr");
109 cpuinfo
.fast_tlb_miss_exc_addr
= fcpu(cpu
, "altr,fast-tlb-miss-addr");
114 #ifdef CONFIG_PROC_FS
117 * Get CPU information for use by the procfs.
119 static int show_cpuinfo(struct seq_file
*m
, void *v
)
121 const u32 clockfreq
= cpuinfo
.cpu_clock_freq
;
124 "CPU:\t\tNios II/%s\n"
128 "Clocking:\t%u.%02u MHz\n"
129 "BogoMips:\t%lu.%02lu\n"
130 "Calibration:\t%lu loops\n",
132 CONFIG_NIOS2_ARCH_REVISION
,
133 cpuinfo
.mmu
? "present" : "none",
134 clockfreq
/ 1000000, (clockfreq
/ 100000) % 10,
135 (loops_per_jiffy
* HZ
) / 500000,
136 ((loops_per_jiffy
* HZ
) / 5000) % 100,
137 (loops_per_jiffy
* HZ
));
146 cpuinfo
.has_mul
? "yes" : "no",
147 cpuinfo
.has_mulx
? "yes" : "no",
148 cpuinfo
.has_div
? "yes" : "no",
149 cpuinfo
.has_bmx
? "yes" : "no",
150 cpuinfo
.has_cdx
? "yes" : "no");
153 "Icache:\t\t%ukB, line length: %u\n",
154 cpuinfo
.icache_size
>> 10,
155 cpuinfo
.icache_line_size
);
158 "Dcache:\t\t%ukB, line length: %u\n",
159 cpuinfo
.dcache_size
>> 10,
160 cpuinfo
.dcache_line_size
);
163 "TLB:\t\t%u ways, %u entries, %u PID bits\n",
164 cpuinfo
.tlb_num_ways
,
165 cpuinfo
.tlb_num_entries
,
166 cpuinfo
.tlb_pid_num_bits
);
171 static void *cpuinfo_start(struct seq_file
*m
, loff_t
*pos
)
173 unsigned long i
= *pos
;
175 return i
< num_possible_cpus() ? (void *) (i
+ 1) : NULL
;
178 static void *cpuinfo_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
181 return cpuinfo_start(m
, pos
);
184 static void cpuinfo_stop(struct seq_file
*m
, void *v
)
188 const struct seq_operations cpuinfo_op
= {
189 .start
= cpuinfo_start
,
190 .next
= cpuinfo_next
,
191 .stop
= cpuinfo_stop
,
195 #endif /* CONFIG_PROC_FS */