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