s390/sysinfo: convert /proc/sysinfo to seqfile
[linux-block.git] / arch / s390 / kernel / sysinfo.c
CommitLineData
1da177e4 1/*
94f5b09d
HC
2 * Copyright IBM Corp. 2001, 2009
3 * Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
4 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
1da177e4
LT
5 */
6
1da177e4
LT
7#include <linux/kernel.h>
8#include <linux/mm.h>
9#include <linux/proc_fs.h>
6bcac508 10#include <linux/seq_file.h>
1da177e4 11#include <linux/init.h>
31ee4b2f 12#include <linux/delay.h>
6bcac508 13#include <linux/module.h>
5a0e3ad6 14#include <linux/slab.h>
1da177e4 15#include <asm/ebcdic.h>
aa24f7f0 16#include <asm/sysinfo.h>
6bcac508 17#include <asm/cpcmd.h>
96f4a70d 18#include <asm/topology.h>
1da177e4 19
31ee4b2f
MS
20/* Sigh, math-emu. Don't ask. */
21#include <asm/sfp-util.h>
22#include <math-emu/soft-fp.h>
23#include <math-emu/single.h>
24
0fee644a 25static inline int stsi_0(void)
1da177e4 26{
94f5b09d 27 int rc = stsi(NULL, 0, 0, 0);
0facaa17 28
0fee644a 29 return rc == -ENOSYS ? rc : (((unsigned int) rc) >> 28);
1da177e4
LT
30}
31
0facaa17 32static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
1da177e4 33{
0fee644a 34 if (stsi(info, 1, 1, 1) == -ENOSYS)
0facaa17 35 return;
0fee644a
MS
36 EBCASC(info->manufacturer, sizeof(info->manufacturer));
37 EBCASC(info->type, sizeof(info->type));
38 EBCASC(info->model, sizeof(info->model));
39 EBCASC(info->sequence, sizeof(info->sequence));
40 EBCASC(info->plant, sizeof(info->plant));
41 EBCASC(info->model_capacity, sizeof(info->model_capacity));
cbce70e6
MS
42 EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
43 EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
0facaa17
HC
44 seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
45 seq_printf(m, "Type: %-4.4s\n", info->type);
46 /*
47 * Sigh: the model field has been renamed with System z9
48 * to model_capacity and a new model field has been added
49 * after the plant field. To avoid confusing older programs
50 * the "Model:" prints "model_capacity model" or just
51 * "model_capacity" if the model string is empty .
52 */
53 seq_printf(m, "Model: %-16.16s", info->model_capacity);
0fee644a 54 if (info->model[0] != '\0')
0facaa17
HC
55 seq_printf(m, " %-16.16s", info->model);
56 seq_putc(m, '\n');
57 seq_printf(m, "Sequence Code: %-16.16s\n", info->sequence);
58 seq_printf(m, "Plant: %-4.4s\n", info->plant);
59 seq_printf(m, "Model Capacity: %-16.16s %08u\n",
60 info->model_capacity, *(u32 *) info->model_cap_rating);
cbce70e6 61 if (info->model_perm_cap[0] != '\0')
0facaa17
HC
62 seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
63 info->model_perm_cap,
64 *(u32 *) info->model_perm_cap_rating);
cbce70e6 65 if (info->model_temp_cap[0] != '\0')
0facaa17
HC
66 seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
67 info->model_temp_cap,
68 *(u32 *) info->model_temp_cap_rating);
7aca2eda 69 if (info->cai) {
0facaa17
HC
70 seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
71 seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
7aca2eda 72 }
1da177e4
LT
73}
74
0facaa17 75static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
96f4a70d
HC
76{
77 static int max_mnest;
78 int i, rc;
79
0facaa17 80 seq_putc(m, '\n');
96f4a70d 81 if (!MACHINE_HAS_TOPOLOGY)
0facaa17 82 return;
96f4a70d
HC
83 if (max_mnest) {
84 stsi(info, 15, 1, max_mnest);
85 } else {
86 for (max_mnest = 6; max_mnest > 1; max_mnest--) {
87 rc = stsi(info, 15, 1, max_mnest);
88 if (rc != -ENOSYS)
89 break;
90 }
91 }
0facaa17 92 seq_printf(m, "CPU Topology HW: ");
96f4a70d 93 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
0facaa17
HC
94 seq_printf(m, " %d", info->mag[i]);
95 seq_putc(m, '\n');
8d11e021 96#ifdef CONFIG_SCHED_MC
96f4a70d 97 store_topology(info);
0facaa17 98 seq_printf(m, "CPU Topology SW: ");
96f4a70d 99 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
0facaa17
HC
100 seq_printf(m, " %d", info->mag[i]);
101 seq_putc(m, '\n');
8d11e021 102#endif
96f4a70d
HC
103}
104
0facaa17 105static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
1da177e4 106{
0fee644a
MS
107 struct sysinfo_1_2_2_extension *ext;
108 int i;
109
110 if (stsi(info, 1, 2, 2) == -ENOSYS)
0facaa17 111 return;
0fee644a
MS
112 ext = (struct sysinfo_1_2_2_extension *)
113 ((unsigned long) info + info->acc_offset);
0facaa17
HC
114 seq_printf(m, "CPUs Total: %d\n", info->cpus_total);
115 seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured);
116 seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby);
117 seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved);
118 /*
119 * Sigh 2. According to the specification the alternate
120 * capability field is a 32 bit floating point number
121 * if the higher order 8 bits are not zero. Printing
122 * a floating point number in the kernel is a no-no,
123 * always print the number as 32 bit unsigned integer.
124 * The user-space needs to know about the strange
125 * encoding of the alternate cpu capability.
126 */
127 seq_printf(m, "Capability: %u", info->capability);
128 if (info->format == 1)
129 seq_printf(m, " %u", ext->alt_capability);
130 seq_putc(m, '\n');
131 for (i = 2; i <= info->cpus_total; i++) {
132 seq_printf(m, "Adjustment %02d-way: %u",
133 i, info->adjustment[i-2]);
134 if (info->format == 1)
135 seq_printf(m, " %u", ext->alt_adjustment[i-2]);
136 seq_putc(m, '\n');
0fee644a 137 }
0facaa17
HC
138 if (info->secondary_capability)
139 seq_printf(m, "Secondary Capability: %d\n",
140 info->secondary_capability);
1da177e4
LT
141}
142
0facaa17 143static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
1da177e4 144{
0fee644a 145 if (stsi(info, 2, 2, 2) == -ENOSYS)
0facaa17 146 return;
94f5b09d 147 EBCASC(info->name, sizeof(info->name));
0facaa17
HC
148 seq_putc(m, '\n');
149 seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
150 seq_printf(m, "LPAR Characteristics: ");
0fee644a 151 if (info->characteristics & LPAR_CHAR_DEDICATED)
0facaa17 152 seq_printf(m, "Dedicated ");
0fee644a 153 if (info->characteristics & LPAR_CHAR_SHARED)
0facaa17 154 seq_printf(m, "Shared ");
0fee644a 155 if (info->characteristics & LPAR_CHAR_LIMITED)
0facaa17
HC
156 seq_printf(m, "Limited ");
157 seq_putc(m, '\n');
158 seq_printf(m, "LPAR Name: %-8.8s\n", info->name);
159 seq_printf(m, "LPAR Adjustment: %d\n", info->caf);
160 seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total);
161 seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
162 seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby);
163 seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved);
164 seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated);
165 seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared);
1da177e4
LT
166}
167
0facaa17 168static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
1da177e4 169{
0fee644a
MS
170 int i;
171
172 if (stsi(info, 3, 2, 2) == -ENOSYS)
0facaa17 173 return;
0fee644a 174 for (i = 0; i < info->count; i++) {
94f5b09d
HC
175 EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
176 EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
0facaa17
HC
177 seq_putc(m, '\n');
178 seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name);
179 seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
180 seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf);
181 seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total);
182 seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
183 seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby);
184 seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved);
1da177e4 185 }
1da177e4
LT
186}
187
0facaa17 188static int sysinfo_show(struct seq_file *m, void *v)
1da177e4 189{
0facaa17
HC
190 void *info = (void *)get_zeroed_page(GFP_KERNEL);
191 int level;
94f5b09d 192
1da177e4
LT
193 if (!info)
194 return 0;
0fee644a
MS
195 level = stsi_0();
196 if (level >= 1)
0facaa17 197 stsi_1_1_1(m, info);
0fee644a 198 if (level >= 1)
0facaa17 199 stsi_15_1_x(m, info);
96f4a70d 200 if (level >= 1)
0facaa17 201 stsi_1_2_2(m, info);
0fee644a 202 if (level >= 2)
0facaa17 203 stsi_2_2_2(m, info);
0fee644a 204 if (level >= 3)
0facaa17
HC
205 stsi_3_2_2(m, info);
206 free_page((unsigned long)info);
207 return 0;
208}
1da177e4 209
0facaa17
HC
210static int sysinfo_open(struct inode *inode, struct file *file)
211{
212 return single_open(file, sysinfo_show, NULL);
1da177e4
LT
213}
214
0facaa17
HC
215static const struct file_operations sysinfo_fops = {
216 .open = sysinfo_open,
217 .read = seq_read,
218 .llseek = seq_lseek,
219 .release = single_release,
220};
221
222static int __init sysinfo_create_proc(void)
1da177e4 223{
0facaa17 224 proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
1da177e4
LT
225 return 0;
226}
0facaa17 227device_initcall(sysinfo_create_proc);
1da177e4 228
6bcac508
MS
229/*
230 * Service levels interface.
231 */
232
233static DECLARE_RWSEM(service_level_sem);
234static LIST_HEAD(service_level_list);
235
236int register_service_level(struct service_level *slr)
237{
238 struct service_level *ptr;
239
240 down_write(&service_level_sem);
241 list_for_each_entry(ptr, &service_level_list, list)
242 if (ptr == slr) {
243 up_write(&service_level_sem);
244 return -EEXIST;
245 }
246 list_add_tail(&slr->list, &service_level_list);
247 up_write(&service_level_sem);
248 return 0;
249}
250EXPORT_SYMBOL(register_service_level);
251
252int unregister_service_level(struct service_level *slr)
253{
254 struct service_level *ptr, *next;
255 int rc = -ENOENT;
256
257 down_write(&service_level_sem);
258 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
259 if (ptr != slr)
260 continue;
261 list_del(&ptr->list);
262 rc = 0;
263 break;
264 }
265 up_write(&service_level_sem);
266 return rc;
267}
268EXPORT_SYMBOL(unregister_service_level);
269
270static void *service_level_start(struct seq_file *m, loff_t *pos)
271{
272 down_read(&service_level_sem);
273 return seq_list_start(&service_level_list, *pos);
274}
275
276static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
277{
278 return seq_list_next(p, &service_level_list, pos);
279}
280
281static void service_level_stop(struct seq_file *m, void *p)
282{
283 up_read(&service_level_sem);
284}
285
286static int service_level_show(struct seq_file *m, void *p)
287{
288 struct service_level *slr;
289
290 slr = list_entry(p, struct service_level, list);
291 slr->seq_print(m, slr);
292 return 0;
293}
294
295static const struct seq_operations service_level_seq_ops = {
296 .start = service_level_start,
297 .next = service_level_next,
298 .stop = service_level_stop,
299 .show = service_level_show
300};
301
302static int service_level_open(struct inode *inode, struct file *file)
303{
304 return seq_open(file, &service_level_seq_ops);
305}
306
307static const struct file_operations service_level_ops = {
308 .open = service_level_open,
309 .read = seq_read,
310 .llseek = seq_lseek,
311 .release = seq_release
312};
313
314static void service_level_vm_print(struct seq_file *m,
315 struct service_level *slr)
316{
317 char *query_buffer, *str;
318
319 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
320 if (!query_buffer)
321 return;
322 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
323 str = strchr(query_buffer, '\n');
324 if (str)
325 *str = 0;
326 seq_printf(m, "VM: %s\n", query_buffer);
327 kfree(query_buffer);
328}
329
330static struct service_level service_level_vm = {
331 .seq_print = service_level_vm_print
332};
333
334static __init int create_proc_service_level(void)
335{
336 proc_create("service_levels", 0, NULL, &service_level_ops);
337 if (MACHINE_IS_VM)
338 register_service_level(&service_level_vm);
339 return 0;
340}
6bcac508
MS
341subsys_initcall(create_proc_service_level);
342
31ee4b2f
MS
343/*
344 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
345 */
346void s390_adjust_jiffies(void)
347{
348 struct sysinfo_1_2_2 *info;
349 const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */
350 FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
351 FP_DECL_EX;
352 unsigned int capability;
353
354 info = (void *) get_zeroed_page(GFP_KERNEL);
355 if (!info)
356 return;
357
358 if (stsi(info, 1, 2, 2) != -ENOSYS) {
359 /*
360 * Major sigh. The cpu capability encoding is "special".
361 * If the first 9 bits of info->capability are 0 then it
362 * is a 32 bit unsigned integer in the range 0 .. 2^23.
363 * If the first 9 bits are != 0 then it is a 32 bit float.
364 * In addition a lower value indicates a proportionally
365 * higher cpu capacity. Bogomips are the other way round.
366 * To get to a halfway suitable number we divide 1e7
367 * by the cpu capability number. Yes, that means a floating
368 * point division .. math-emu here we come :-)
369 */
370 FP_UNPACK_SP(SA, &fmil);
371 if ((info->capability >> 23) == 0)
5b479a79 372 FP_FROM_INT_S(SB, (long) info->capability, 64, long);
31ee4b2f
MS
373 else
374 FP_UNPACK_SP(SB, &info->capability);
375 FP_DIV_S(SR, SA, SB);
376 FP_TO_INT_S(capability, SR, 32, 0);
377 } else
378 /*
379 * Really old machine without stsi block for basic
380 * cpu information. Report 42.0 bogomips.
381 */
382 capability = 42;
383 loops_per_jiffy = capability * (500000/HZ);
384 free_page((unsigned long) info);
385}
386
387/*
388 * calibrate the delay loop
389 */
6c81c32f 390void __cpuinit calibrate_delay(void)
31ee4b2f
MS
391{
392 s390_adjust_jiffies();
393 /* Print the good old Bogomips line .. */
394 printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
395 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
396 (loops_per_jiffy/(5000/HZ)) % 100);
397}