1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2a9b27bccSPaul Mundt #include <linux/seq_file.h>
3a9b27bccSPaul Mundt #include <linux/kernel.h>
4a9b27bccSPaul Mundt #include <linux/module.h>
5a9b27bccSPaul Mundt #include <asm/machvec.h>
6a9b27bccSPaul Mundt #include <asm/processor.h>
7a9b27bccSPaul Mundt
8a9b27bccSPaul Mundt static const char *cpu_name[] = {
9a9b27bccSPaul Mundt [CPU_SH7201] = "SH7201",
10a9b27bccSPaul Mundt [CPU_SH7203] = "SH7203", [CPU_SH7263] = "SH7263",
110b25b7c8SPhil Edworthy [CPU_SH7264] = "SH7264", [CPU_SH7269] = "SH7269",
12a9b27bccSPaul Mundt [CPU_SH7206] = "SH7206", [CPU_SH7619] = "SH7619",
13a9b27bccSPaul Mundt [CPU_SH7705] = "SH7705", [CPU_SH7706] = "SH7706",
14a9b27bccSPaul Mundt [CPU_SH7707] = "SH7707", [CPU_SH7708] = "SH7708",
15a9b27bccSPaul Mundt [CPU_SH7709] = "SH7709", [CPU_SH7710] = "SH7710",
16a9b27bccSPaul Mundt [CPU_SH7712] = "SH7712", [CPU_SH7720] = "SH7720",
17a9b27bccSPaul Mundt [CPU_SH7721] = "SH7721", [CPU_SH7729] = "SH7729",
18a9b27bccSPaul Mundt [CPU_SH7750] = "SH7750", [CPU_SH7750S] = "SH7750S",
19a9b27bccSPaul Mundt [CPU_SH7750R] = "SH7750R", [CPU_SH7751] = "SH7751",
20a9b27bccSPaul Mundt [CPU_SH7751R] = "SH7751R", [CPU_SH7760] = "SH7760",
21a9b27bccSPaul Mundt [CPU_SH4_202] = "SH4-202", [CPU_SH4_501] = "SH4-501",
22a9b27bccSPaul Mundt [CPU_SH7763] = "SH7763", [CPU_SH7770] = "SH7770",
23a9b27bccSPaul Mundt [CPU_SH7780] = "SH7780", [CPU_SH7781] = "SH7781",
24a9b27bccSPaul Mundt [CPU_SH7343] = "SH7343", [CPU_SH7785] = "SH7785",
25a9b27bccSPaul Mundt [CPU_SH7786] = "SH7786", [CPU_SH7757] = "SH7757",
26a9b27bccSPaul Mundt [CPU_SH7722] = "SH7722", [CPU_SHX3] = "SH-X3",
27a9b27bccSPaul Mundt [CPU_MXG] = "MX-G", [CPU_SH7723] = "SH7723",
28a9b27bccSPaul Mundt [CPU_SH7366] = "SH7366", [CPU_SH7724] = "SH7724",
29fea88a0cSNobuhiro Iwamatsu [CPU_SH7372] = "SH7372", [CPU_SH7734] = "SH7734",
305a846abaSRich Felker [CPU_J2] = "J2",
31fea88a0cSNobuhiro Iwamatsu [CPU_SH_NONE] = "Unknown"
32a9b27bccSPaul Mundt };
33a9b27bccSPaul Mundt
get_cpu_subtype(struct sh_cpuinfo * c)34a9b27bccSPaul Mundt const char *get_cpu_subtype(struct sh_cpuinfo *c)
35a9b27bccSPaul Mundt {
36a9b27bccSPaul Mundt return cpu_name[c->type];
37a9b27bccSPaul Mundt }
38a9b27bccSPaul Mundt EXPORT_SYMBOL(get_cpu_subtype);
39a9b27bccSPaul Mundt
40a9b27bccSPaul Mundt #ifdef CONFIG_PROC_FS
41a9b27bccSPaul Mundt /* Symbolic CPU flags, keep in sync with asm/cpu-features.h */
42a9b27bccSPaul Mundt static const char *cpu_flags[] = {
43a9b27bccSPaul Mundt "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr",
44a9b27bccSPaul Mundt "ptea", "llsc", "l2", "op32", "pteaex", NULL
45a9b27bccSPaul Mundt };
46a9b27bccSPaul Mundt
show_cpuflags(struct seq_file * m,struct sh_cpuinfo * c)47a9b27bccSPaul Mundt static void show_cpuflags(struct seq_file *m, struct sh_cpuinfo *c)
48a9b27bccSPaul Mundt {
49a9b27bccSPaul Mundt unsigned long i;
50a9b27bccSPaul Mundt
51a9b27bccSPaul Mundt seq_printf(m, "cpu flags\t:");
52a9b27bccSPaul Mundt
53a9b27bccSPaul Mundt if (!c->flags) {
54a9b27bccSPaul Mundt seq_printf(m, " %s\n", cpu_flags[0]);
55a9b27bccSPaul Mundt return;
56a9b27bccSPaul Mundt }
57a9b27bccSPaul Mundt
58a9b27bccSPaul Mundt for (i = 0; cpu_flags[i]; i++)
59a9b27bccSPaul Mundt if ((c->flags & (1 << i)))
60a9b27bccSPaul Mundt seq_printf(m, " %s", cpu_flags[i+1]);
61a9b27bccSPaul Mundt
62a9b27bccSPaul Mundt seq_printf(m, "\n");
63a9b27bccSPaul Mundt }
64a9b27bccSPaul Mundt
show_cacheinfo(struct seq_file * m,const char * type,struct cache_info info)65a9b27bccSPaul Mundt static void show_cacheinfo(struct seq_file *m, const char *type,
66a9b27bccSPaul Mundt struct cache_info info)
67a9b27bccSPaul Mundt {
68a9b27bccSPaul Mundt unsigned int cache_size;
69a9b27bccSPaul Mundt
70a9b27bccSPaul Mundt cache_size = info.ways * info.sets * info.linesz;
71a9b27bccSPaul Mundt
72a9b27bccSPaul Mundt seq_printf(m, "%s size\t: %2dKiB (%d-way)\n",
73a9b27bccSPaul Mundt type, cache_size >> 10, info.ways);
74a9b27bccSPaul Mundt }
75a9b27bccSPaul Mundt
76a9b27bccSPaul Mundt /*
77a9b27bccSPaul Mundt * Get CPU information for use by the procfs.
78a9b27bccSPaul Mundt */
show_cpuinfo(struct seq_file * m,void * v)79a9b27bccSPaul Mundt static int show_cpuinfo(struct seq_file *m, void *v)
80a9b27bccSPaul Mundt {
81a9b27bccSPaul Mundt struct sh_cpuinfo *c = v;
82a9b27bccSPaul Mundt unsigned int cpu = c - cpu_data;
83a9b27bccSPaul Mundt
84a9b27bccSPaul Mundt if (!cpu_online(cpu))
85a9b27bccSPaul Mundt return 0;
86a9b27bccSPaul Mundt
87a9b27bccSPaul Mundt if (cpu == 0)
88a9b27bccSPaul Mundt seq_printf(m, "machine\t\t: %s\n", get_system_type());
89a9b27bccSPaul Mundt else
90a9b27bccSPaul Mundt seq_printf(m, "\n");
91a9b27bccSPaul Mundt
92a9b27bccSPaul Mundt seq_printf(m, "processor\t: %d\n", cpu);
93a9b27bccSPaul Mundt seq_printf(m, "cpu family\t: %s\n", init_utsname()->machine);
94a9b27bccSPaul Mundt seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype(c));
95a9b27bccSPaul Mundt if (c->cut_major == -1)
96a9b27bccSPaul Mundt seq_printf(m, "cut\t\t: unknown\n");
97a9b27bccSPaul Mundt else if (c->cut_minor == -1)
98a9b27bccSPaul Mundt seq_printf(m, "cut\t\t: %d.x\n", c->cut_major);
99a9b27bccSPaul Mundt else
100a9b27bccSPaul Mundt seq_printf(m, "cut\t\t: %d.%d\n", c->cut_major, c->cut_minor);
101a9b27bccSPaul Mundt
102a9b27bccSPaul Mundt show_cpuflags(m, c);
103a9b27bccSPaul Mundt
104a9b27bccSPaul Mundt seq_printf(m, "cache type\t: ");
105a9b27bccSPaul Mundt
106a9b27bccSPaul Mundt /*
107a9b27bccSPaul Mundt * Check for what type of cache we have, we support both the
108a9b27bccSPaul Mundt * unified cache on the SH-2 and SH-3, as well as the harvard
109a9b27bccSPaul Mundt * style cache on the SH-4.
110a9b27bccSPaul Mundt */
111a9b27bccSPaul Mundt if (c->icache.flags & SH_CACHE_COMBINED) {
112a9b27bccSPaul Mundt seq_printf(m, "unified\n");
113a9b27bccSPaul Mundt show_cacheinfo(m, "cache", c->icache);
114a9b27bccSPaul Mundt } else {
115a9b27bccSPaul Mundt seq_printf(m, "split (harvard)\n");
116a9b27bccSPaul Mundt show_cacheinfo(m, "icache", c->icache);
117a9b27bccSPaul Mundt show_cacheinfo(m, "dcache", c->dcache);
118a9b27bccSPaul Mundt }
119a9b27bccSPaul Mundt
120a9b27bccSPaul Mundt /* Optional secondary cache */
121a9b27bccSPaul Mundt if (c->flags & CPU_HAS_L2_CACHE)
122a9b27bccSPaul Mundt show_cacheinfo(m, "scache", c->scache);
123a9b27bccSPaul Mundt
124a9b27bccSPaul Mundt seq_printf(m, "address sizes\t: %u bits physical\n", c->phys_bits);
125a9b27bccSPaul Mundt
126a9b27bccSPaul Mundt seq_printf(m, "bogomips\t: %lu.%02lu\n",
127a9b27bccSPaul Mundt c->loops_per_jiffy/(500000/HZ),
128a9b27bccSPaul Mundt (c->loops_per_jiffy/(5000/HZ)) % 100);
129a9b27bccSPaul Mundt
130a9b27bccSPaul Mundt return 0;
131a9b27bccSPaul Mundt }
132a9b27bccSPaul Mundt
c_start(struct seq_file * m,loff_t * pos)133a9b27bccSPaul Mundt static void *c_start(struct seq_file *m, loff_t *pos)
134a9b27bccSPaul Mundt {
135*09faf32cSHuacai Chen return *pos < nr_cpu_ids ? cpu_data + *pos : NULL;
136a9b27bccSPaul Mundt }
c_next(struct seq_file * m,void * v,loff_t * pos)137a9b27bccSPaul Mundt static void *c_next(struct seq_file *m, void *v, loff_t *pos)
138a9b27bccSPaul Mundt {
139a9b27bccSPaul Mundt ++*pos;
140a9b27bccSPaul Mundt return c_start(m, pos);
141a9b27bccSPaul Mundt }
c_stop(struct seq_file * m,void * v)142a9b27bccSPaul Mundt static void c_stop(struct seq_file *m, void *v)
143a9b27bccSPaul Mundt {
144a9b27bccSPaul Mundt }
145a9b27bccSPaul Mundt const struct seq_operations cpuinfo_op = {
146a9b27bccSPaul Mundt .start = c_start,
147a9b27bccSPaul Mundt .next = c_next,
148a9b27bccSPaul Mundt .stop = c_stop,
149a9b27bccSPaul Mundt .show = show_cpuinfo,
150a9b27bccSPaul Mundt };
151a9b27bccSPaul Mundt #endif /* CONFIG_PROC_FS */
152