1
2
3
4
5
6#define KMSG_COMPONENT "cpu"
7#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
8
9#include <linux/cpufeature.h>
10#include <linux/bitops.h>
11#include <linux/kernel.h>
12#include <linux/sched/mm.h>
13#include <linux/init.h>
14#include <linux/seq_file.h>
15#include <linux/mm_types.h>
16#include <linux/delay.h>
17#include <linux/cpu.h>
18
19#include <asm/diag.h>
20#include <asm/facility.h>
21#include <asm/elf.h>
22#include <asm/lowcore.h>
23#include <asm/param.h>
24#include <asm/smp.h>
25
26struct cpu_info {
27 unsigned int cpu_mhz_dynamic;
28 unsigned int cpu_mhz_static;
29 struct cpuid cpu_id;
30};
31
32static DEFINE_PER_CPU(struct cpu_info, cpu_info);
33
34static bool machine_has_cpu_mhz;
35
36void __init cpu_detect_mhz_feature(void)
37{
38 if (test_facility(34) && __ecag(ECAG_CPU_ATTRIBUTE, 0) != -1UL)
39 machine_has_cpu_mhz = true;
40}
41
42static void update_cpu_mhz(void *arg)
43{
44 unsigned long mhz;
45 struct cpu_info *c;
46
47 mhz = __ecag(ECAG_CPU_ATTRIBUTE, 0);
48 c = this_cpu_ptr(&cpu_info);
49 c->cpu_mhz_dynamic = mhz >> 32;
50 c->cpu_mhz_static = mhz & 0xffffffff;
51}
52
53void s390_update_cpu_mhz(void)
54{
55 s390_adjust_jiffies();
56 if (machine_has_cpu_mhz)
57 on_each_cpu(update_cpu_mhz, NULL, 0);
58}
59
60void notrace cpu_relax_yield(void)
61{
62 if (!smp_cpu_mtid && MACHINE_HAS_DIAG44) {
63 diag_stat_inc(DIAG_STAT_X044);
64 asm volatile("diag 0,0,0x44");
65 }
66 barrier();
67}
68EXPORT_SYMBOL(cpu_relax_yield);
69
70
71
72
73void cpu_init(void)
74{
75 struct cpuid *id = this_cpu_ptr(&cpu_info.cpu_id);
76
77 get_cpu_id(id);
78 if (machine_has_cpu_mhz)
79 update_cpu_mhz(NULL);
80 mmgrab(&init_mm);
81 current->active_mm = &init_mm;
82 BUG_ON(current->mm);
83 enter_lazy_tlb(&init_mm, current);
84}
85
86
87
88
89int cpu_have_feature(unsigned int num)
90{
91 return elf_hwcap & (1UL << num);
92}
93EXPORT_SYMBOL(cpu_have_feature);
94
95static void show_facilities(struct seq_file *m)
96{
97 unsigned int bit;
98 long *facilities;
99
100 facilities = (long *)&S390_lowcore.stfle_fac_list;
101 seq_puts(m, "facilities :");
102 for_each_set_bit_inv(bit, facilities, MAX_FACILITY_BIT)
103 seq_printf(m, " %d", bit);
104 seq_putc(m, '\n');
105}
106
107static void show_cpu_summary(struct seq_file *m, void *v)
108{
109 static const char *hwcap_str[] = {
110 "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
111 "edat", "etf3eh", "highgprs", "te", "vx", "vxd", "vxe", "gs"
112 };
113 static const char * const int_hwcap_str[] = {
114 "sie"
115 };
116 int i, cpu;
117
118 seq_printf(m, "vendor_id : IBM/S390\n"
119 "# processors : %i\n"
120 "bogomips per cpu: %lu.%02lu\n",
121 num_online_cpus(), loops_per_jiffy/(500000/HZ),
122 (loops_per_jiffy/(5000/HZ))%100);
123 seq_printf(m, "max thread id : %d\n", smp_cpu_mtid);
124 seq_puts(m, "features\t: ");
125 for (i = 0; i < ARRAY_SIZE(hwcap_str); i++)
126 if (hwcap_str[i] && (elf_hwcap & (1UL << i)))
127 seq_printf(m, "%s ", hwcap_str[i]);
128 for (i = 0; i < ARRAY_SIZE(int_hwcap_str); i++)
129 if (int_hwcap_str[i] && (int_hwcap & (1UL << i)))
130 seq_printf(m, "%s ", int_hwcap_str[i]);
131 seq_puts(m, "\n");
132 show_facilities(m);
133 show_cacheinfo(m);
134 for_each_online_cpu(cpu) {
135 struct cpuid *id = &per_cpu(cpu_info.cpu_id, cpu);
136
137 seq_printf(m, "processor %d: "
138 "version = %02X, "
139 "identification = %06X, "
140 "machine = %04X\n",
141 cpu, id->version, id->ident, id->machine);
142 }
143}
144
145static void show_cpu_mhz(struct seq_file *m, unsigned long n)
146{
147 struct cpu_info *c = per_cpu_ptr(&cpu_info, n);
148
149 seq_printf(m, "cpu MHz dynamic : %d\n", c->cpu_mhz_dynamic);
150 seq_printf(m, "cpu MHz static : %d\n", c->cpu_mhz_static);
151}
152
153
154
155
156static int show_cpuinfo(struct seq_file *m, void *v)
157{
158 unsigned long n = (unsigned long) v - 1;
159
160 if (!n)
161 show_cpu_summary(m, v);
162 if (!machine_has_cpu_mhz)
163 return 0;
164 seq_printf(m, "\ncpu number : %ld\n", n);
165 show_cpu_mhz(m, n);
166 return 0;
167}
168
169static inline void *c_update(loff_t *pos)
170{
171 if (*pos)
172 *pos = cpumask_next(*pos - 1, cpu_online_mask);
173 return *pos < nr_cpu_ids ? (void *)*pos + 1 : NULL;
174}
175
176static void *c_start(struct seq_file *m, loff_t *pos)
177{
178 get_online_cpus();
179 return c_update(pos);
180}
181
182static void *c_next(struct seq_file *m, void *v, loff_t *pos)
183{
184 ++*pos;
185 return c_update(pos);
186}
187
188static void c_stop(struct seq_file *m, void *v)
189{
190 put_online_cpus();
191}
192
193const struct seq_operations cpuinfo_op = {
194 .start = c_start,
195 .next = c_next,
196 .stop = c_stop,
197 .show = show_cpuinfo,
198};
199