blob: 0eea90781385784ae4ab838dce905dcaf4942a89 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/sysinfo.c
3 *
Martin Schwidefsky6bcac502008-12-25 13:38:49 +01004 * Copyright IBM Corp. 2001, 2008
5 * Author(s): Ulrich Weigand (Ulrich.Weigand@de.ibm.com)
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/kernel.h>
10#include <linux/mm.h>
11#include <linux/proc_fs.h>
Martin Schwidefsky6bcac502008-12-25 13:38:49 +010012#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +010014#include <linux/delay.h>
Martin Schwidefsky6bcac502008-12-25 13:38:49 +010015#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/ebcdic.h>
Christian Borntraegeraa24f7f2008-04-17 07:46:09 +020017#include <asm/sysinfo.h>
Martin Schwidefsky6bcac502008-12-25 13:38:49 +010018#include <asm/cpcmd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +010020/* 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
Martin Schwidefsky0fee6442006-09-20 15:59:10 +020025static inline int stsi_0(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
27 int rc = stsi (NULL, 0, 0, 0);
Martin Schwidefsky0fee6442006-09-20 15:59:10 +020028 return rc == -ENOSYS ? rc : (((unsigned int) rc) >> 28);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
Martin Schwidefsky0fee6442006-09-20 15:59:10 +020031static int stsi_1_1_1(struct sysinfo_1_1_1 *info, char *page, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Martin Schwidefsky0fee6442006-09-20 15:59:10 +020033 if (stsi(info, 1, 1, 1) == -ENOSYS)
34 return len;
35
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));
Martin Schwidefskycbce70e2008-04-17 07:46:10 +020042 EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
43 EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
Martin Schwidefsky0fee6442006-09-20 15:59:10 +020044 len += sprintf(page + len, "Manufacturer: %-16.16s\n",
45 info->manufacturer);
46 len += sprintf(page + len, "Type: %-4.4s\n",
47 info->type);
48 if (info->model[0] != '\0')
49 /*
50 * Sigh: the model field has been renamed with System z9
51 * to model_capacity and a new model field has been added
52 * after the plant field. To avoid confusing older programs
53 * the "Model:" prints "model_capacity model" or just
54 * "model_capacity" if the model string is empty .
55 */
56 len += sprintf(page + len,
57 "Model: %-16.16s %-16.16s\n",
58 info->model_capacity, info->model);
59 else
60 len += sprintf(page + len, "Model: %-16.16s\n",
61 info->model_capacity);
62 len += sprintf(page + len, "Sequence Code: %-16.16s\n",
63 info->sequence);
64 len += sprintf(page + len, "Plant: %-4.4s\n",
65 info->plant);
Martin Schwidefskycbce70e2008-04-17 07:46:10 +020066 len += sprintf(page + len, "Model Capacity: %-16.16s %08u\n",
67 info->model_capacity, *(u32 *) info->model_cap_rating);
68 if (info->model_perm_cap[0] != '\0')
69 len += sprintf(page + len,
70 "Model Perm. Capacity: %-16.16s %08u\n",
71 info->model_perm_cap,
72 *(u32 *) info->model_perm_cap_rating);
73 if (info->model_temp_cap[0] != '\0')
74 len += sprintf(page + len,
75 "Model Temp. Capacity: %-16.16s %08u\n",
76 info->model_temp_cap,
77 *(u32 *) info->model_temp_cap_rating);
Martin Schwidefsky0fee6442006-09-20 15:59:10 +020078 return len;
79}
80
81#if 0 /* Currently unused */
82static int stsi_1_2_1(struct sysinfo_1_2_1 *info, char *page, int len)
83{
84 if (stsi(info, 1, 2, 1) == -ENOSYS)
85 return len;
86
87 len += sprintf(page + len, "\n");
88 EBCASC(info->sequence, sizeof(info->sequence));
89 EBCASC(info->plant, sizeof(info->plant));
90 len += sprintf(page + len, "Sequence Code of CPU: %-16.16s\n",
91 info->sequence);
92 len += sprintf(page + len, "Plant of CPU: %-16.16s\n",
93 info->plant);
94 return len;
95}
96#endif
97
98static int stsi_1_2_2(struct sysinfo_1_2_2 *info, char *page, int len)
99{
100 struct sysinfo_1_2_2_extension *ext;
101 int i;
102
103 if (stsi(info, 1, 2, 2) == -ENOSYS)
104 return len;
105 ext = (struct sysinfo_1_2_2_extension *)
106 ((unsigned long) info + info->acc_offset);
107
108 len += sprintf(page + len, "\n");
109 len += sprintf(page + len, "CPUs Total: %d\n",
110 info->cpus_total);
111 len += sprintf(page + len, "CPUs Configured: %d\n",
112 info->cpus_configured);
113 len += sprintf(page + len, "CPUs Standby: %d\n",
114 info->cpus_standby);
115 len += sprintf(page + len, "CPUs Reserved: %d\n",
116 info->cpus_reserved);
117
118 if (info->format == 1) {
119 /*
120 * Sigh 2. According to the specification the alternate
121 * capability field is a 32 bit floating point number
122 * if the higher order 8 bits are not zero. Printing
123 * a floating point number in the kernel is a no-no,
124 * always print the number as 32 bit unsigned integer.
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +0100125 * The user-space needs to know about the strange
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200126 * encoding of the alternate cpu capability.
127 */
128 len += sprintf(page + len, "Capability: %u %u\n",
129 info->capability, ext->alt_capability);
130 for (i = 2; i <= info->cpus_total; i++)
131 len += sprintf(page + len,
132 "Adjustment %02d-way: %u %u\n",
133 i, info->adjustment[i-2],
134 ext->alt_adjustment[i-2]);
135
136 } else {
137 len += sprintf(page + len, "Capability: %u\n",
138 info->capability);
139 for (i = 2; i <= info->cpus_total; i++)
140 len += sprintf(page + len,
141 "Adjustment %02d-way: %u\n",
142 i, info->adjustment[i-2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200144
145 if (info->secondary_capability != 0)
146 len += sprintf(page + len, "Secondary Capability: %d\n",
147 info->secondary_capability);
148
149 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200152#if 0 /* Currently unused */
153static int stsi_2_2_1(struct sysinfo_2_2_1 *info, char *page, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200155 if (stsi(info, 2, 2, 1) == -ENOSYS)
156 return len;
157
158 len += sprintf(page + len, "\n");
159 EBCASC (info->sequence, sizeof(info->sequence));
160 EBCASC (info->plant, sizeof(info->plant));
161 len += sprintf(page + len, "Sequence Code of logical CPU: %-16.16s\n",
162 info->sequence);
163 len += sprintf(page + len, "Plant of logical CPU: %-16.16s\n",
164 info->plant);
165 return len;
166}
167#endif
168
169static int stsi_2_2_2(struct sysinfo_2_2_2 *info, char *page, int len)
170{
171 if (stsi(info, 2, 2, 2) == -ENOSYS)
172 return len;
173
174 EBCASC (info->name, sizeof(info->name));
175
176 len += sprintf(page + len, "\n");
177 len += sprintf(page + len, "LPAR Number: %d\n",
178 info->lpar_number);
179
180 len += sprintf(page + len, "LPAR Characteristics: ");
181 if (info->characteristics & LPAR_CHAR_DEDICATED)
182 len += sprintf(page + len, "Dedicated ");
183 if (info->characteristics & LPAR_CHAR_SHARED)
184 len += sprintf(page + len, "Shared ");
185 if (info->characteristics & LPAR_CHAR_LIMITED)
186 len += sprintf(page + len, "Limited ");
187 len += sprintf(page + len, "\n");
188
189 len += sprintf(page + len, "LPAR Name: %-8.8s\n",
190 info->name);
191
192 len += sprintf(page + len, "LPAR Adjustment: %d\n",
193 info->caf);
194
195 len += sprintf(page + len, "LPAR CPUs Total: %d\n",
196 info->cpus_total);
197 len += sprintf(page + len, "LPAR CPUs Configured: %d\n",
198 info->cpus_configured);
199 len += sprintf(page + len, "LPAR CPUs Standby: %d\n",
200 info->cpus_standby);
201 len += sprintf(page + len, "LPAR CPUs Reserved: %d\n",
202 info->cpus_reserved);
203 len += sprintf(page + len, "LPAR CPUs Dedicated: %d\n",
204 info->cpus_dedicated);
205 len += sprintf(page + len, "LPAR CPUs Shared: %d\n",
206 info->cpus_shared);
207 return len;
208}
209
210static int stsi_3_2_2(struct sysinfo_3_2_2 *info, char *page, int len)
211{
212 int i;
213
214 if (stsi(info, 3, 2, 2) == -ENOSYS)
215 return len;
216 for (i = 0; i < info->count; i++) {
217 EBCASC (info->vm[i].name, sizeof(info->vm[i].name));
218 EBCASC (info->vm[i].cpi, sizeof(info->vm[i].cpi));
219 len += sprintf(page + len, "\n");
220 len += sprintf(page + len, "VM%02d Name: %-8.8s\n",
221 i, info->vm[i].name);
222 len += sprintf(page + len, "VM%02d Control Program: %-16.16s\n",
223 i, info->vm[i].cpi);
224
225 len += sprintf(page + len, "VM%02d Adjustment: %d\n",
226 i, info->vm[i].caf);
227
228 len += sprintf(page + len, "VM%02d CPUs Total: %d\n",
229 i, info->vm[i].cpus_total);
230 len += sprintf(page + len, "VM%02d CPUs Configured: %d\n",
231 i, info->vm[i].cpus_configured);
232 len += sprintf(page + len, "VM%02d CPUs Standby: %d\n",
233 i, info->vm[i].cpus_standby);
234 len += sprintf(page + len, "VM%02d CPUs Reserved: %d\n",
235 i, info->vm[i].cpus_reserved);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200237 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238}
239
240
241static int proc_read_sysinfo(char *page, char **start,
242 off_t off, int count,
243 int *eof, void *data)
244{
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200245 unsigned long info = get_zeroed_page (GFP_KERNEL);
246 int level, len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
248 if (!info)
249 return 0;
250
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200251 len = 0;
252 level = stsi_0();
253 if (level >= 1)
254 len = stsi_1_1_1((struct sysinfo_1_1_1 *) info, page, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200256 if (level >= 1)
257 len = stsi_1_2_2((struct sysinfo_1_2_2 *) info, page, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200259 if (level >= 2)
260 len = stsi_2_2_2((struct sysinfo_2_2_2 *) info, page, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200262 if (level >= 3)
263 len = stsi_3_2_2((struct sysinfo_3_2_2 *) info, page, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200265 free_page (info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 return len;
267}
268
269static __init int create_proc_sysinfo(void)
270{
Martin Schwidefsky0fee6442006-09-20 15:59:10 +0200271 create_proc_read_entry("sysinfo", 0444, NULL,
272 proc_read_sysinfo, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return 0;
274}
275
276__initcall(create_proc_sysinfo);
277
Martin Schwidefsky6bcac502008-12-25 13:38:49 +0100278/*
279 * Service levels interface.
280 */
281
282static DECLARE_RWSEM(service_level_sem);
283static LIST_HEAD(service_level_list);
284
285int register_service_level(struct service_level *slr)
286{
287 struct service_level *ptr;
288
289 down_write(&service_level_sem);
290 list_for_each_entry(ptr, &service_level_list, list)
291 if (ptr == slr) {
292 up_write(&service_level_sem);
293 return -EEXIST;
294 }
295 list_add_tail(&slr->list, &service_level_list);
296 up_write(&service_level_sem);
297 return 0;
298}
299EXPORT_SYMBOL(register_service_level);
300
301int unregister_service_level(struct service_level *slr)
302{
303 struct service_level *ptr, *next;
304 int rc = -ENOENT;
305
306 down_write(&service_level_sem);
307 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
308 if (ptr != slr)
309 continue;
310 list_del(&ptr->list);
311 rc = 0;
312 break;
313 }
314 up_write(&service_level_sem);
315 return rc;
316}
317EXPORT_SYMBOL(unregister_service_level);
318
319static void *service_level_start(struct seq_file *m, loff_t *pos)
320{
321 down_read(&service_level_sem);
322 return seq_list_start(&service_level_list, *pos);
323}
324
325static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
326{
327 return seq_list_next(p, &service_level_list, pos);
328}
329
330static void service_level_stop(struct seq_file *m, void *p)
331{
332 up_read(&service_level_sem);
333}
334
335static int service_level_show(struct seq_file *m, void *p)
336{
337 struct service_level *slr;
338
339 slr = list_entry(p, struct service_level, list);
340 slr->seq_print(m, slr);
341 return 0;
342}
343
344static const struct seq_operations service_level_seq_ops = {
345 .start = service_level_start,
346 .next = service_level_next,
347 .stop = service_level_stop,
348 .show = service_level_show
349};
350
351static int service_level_open(struct inode *inode, struct file *file)
352{
353 return seq_open(file, &service_level_seq_ops);
354}
355
356static const struct file_operations service_level_ops = {
357 .open = service_level_open,
358 .read = seq_read,
359 .llseek = seq_lseek,
360 .release = seq_release
361};
362
363static void service_level_vm_print(struct seq_file *m,
364 struct service_level *slr)
365{
366 char *query_buffer, *str;
367
368 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
369 if (!query_buffer)
370 return;
371 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
372 str = strchr(query_buffer, '\n');
373 if (str)
374 *str = 0;
375 seq_printf(m, "VM: %s\n", query_buffer);
376 kfree(query_buffer);
377}
378
379static struct service_level service_level_vm = {
380 .seq_print = service_level_vm_print
381};
382
383static __init int create_proc_service_level(void)
384{
385 proc_create("service_levels", 0, NULL, &service_level_ops);
386 if (MACHINE_IS_VM)
387 register_service_level(&service_level_vm);
388 return 0;
389}
390
391subsys_initcall(create_proc_service_level);
392
393/*
394 * Bogomips calculation based on cpu capability.
395 */
396
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200397int get_cpu_capability(unsigned int *capability)
398{
399 struct sysinfo_1_2_2 *info;
400 int rc;
401
402 info = (void *) get_zeroed_page(GFP_KERNEL);
403 if (!info)
404 return -ENOMEM;
405 rc = stsi(info, 1, 2, 2);
406 if (rc == -ENOSYS)
407 goto out;
408 rc = 0;
409 *capability = info->capability;
410out:
411 free_page((unsigned long) info);
412 return rc;
413}
414
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +0100415/*
416 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
417 */
418void s390_adjust_jiffies(void)
419{
420 struct sysinfo_1_2_2 *info;
421 const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */
422 FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
423 FP_DECL_EX;
424 unsigned int capability;
425
426 info = (void *) get_zeroed_page(GFP_KERNEL);
427 if (!info)
428 return;
429
430 if (stsi(info, 1, 2, 2) != -ENOSYS) {
431 /*
432 * Major sigh. The cpu capability encoding is "special".
433 * If the first 9 bits of info->capability are 0 then it
434 * is a 32 bit unsigned integer in the range 0 .. 2^23.
435 * If the first 9 bits are != 0 then it is a 32 bit float.
436 * In addition a lower value indicates a proportionally
437 * higher cpu capacity. Bogomips are the other way round.
438 * To get to a halfway suitable number we divide 1e7
439 * by the cpu capability number. Yes, that means a floating
440 * point division .. math-emu here we come :-)
441 */
442 FP_UNPACK_SP(SA, &fmil);
443 if ((info->capability >> 23) == 0)
444 FP_FROM_INT_S(SB, info->capability, 32, int);
445 else
446 FP_UNPACK_SP(SB, &info->capability);
447 FP_DIV_S(SR, SA, SB);
448 FP_TO_INT_S(capability, SR, 32, 0);
449 } else
450 /*
451 * Really old machine without stsi block for basic
452 * cpu information. Report 42.0 bogomips.
453 */
454 capability = 42;
455 loops_per_jiffy = capability * (500000/HZ);
456 free_page((unsigned long) info);
457}
458
459/*
460 * calibrate the delay loop
461 */
Adrian Bunk6c81c322008-02-06 01:37:51 -0800462void __cpuinit calibrate_delay(void)
Martin Schwidefsky31ee4b22007-02-05 21:18:31 +0100463{
464 s390_adjust_jiffies();
465 /* Print the good old Bogomips line .. */
466 printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
467 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
468 (loops_per_jiffy/(5000/HZ)) % 100);
469}