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