Merge remote-tracking branch 'lightnvm/for-next'
[deliverable/linux.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>
9c203239 19#include <asm/fpu/api.h>
31ee4b2f 20
fade4dc4
HC
21int topology_max_mnest;
22
2c79813a 23static inline int __stsi(void *sysinfo, int fc, int sel1, int sel2, int *lvl)
1da177e4 24{
caf757c6
HC
25 register int r0 asm("0") = (fc << 28) | sel1;
26 register int r1 asm("1") = sel2;
27 int rc = 0;
28
29 asm volatile(
30 " stsi 0(%3)\n"
31 "0: jz 2f\n"
32 "1: lhi %1,%4\n"
33 "2:\n"
34 EX_TABLE(0b, 1b)
35 : "+d" (r0), "+d" (rc)
36 : "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP)
37 : "cc", "memory");
2c79813a
HC
38 *lvl = ((unsigned int) r0) >> 28;
39 return rc;
40}
41
42/*
43 * stsi - store system information
44 *
45 * Returns the current configuration level if function code 0 was specified.
46 * Otherwise returns 0 on success or a negative value on error.
47 */
48int stsi(void *sysinfo, int fc, int sel1, int sel2)
49{
50 int lvl, rc;
51
52 rc = __stsi(sysinfo, fc, sel1, sel2, &lvl);
caf757c6
HC
53 if (rc)
54 return rc;
2c79813a 55 return fc ? 0 : lvl;
1da177e4 56}
caf757c6 57EXPORT_SYMBOL(stsi);
1da177e4 58
0facaa17 59static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
1da177e4 60{
25502f00
HC
61 int i;
62
caf757c6 63 if (stsi(info, 1, 1, 1))
0facaa17 64 return;
0fee644a
MS
65 EBCASC(info->manufacturer, sizeof(info->manufacturer));
66 EBCASC(info->type, sizeof(info->type));
67 EBCASC(info->model, sizeof(info->model));
68 EBCASC(info->sequence, sizeof(info->sequence));
69 EBCASC(info->plant, sizeof(info->plant));
70 EBCASC(info->model_capacity, sizeof(info->model_capacity));
cbce70e6
MS
71 EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
72 EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
0facaa17
HC
73 seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
74 seq_printf(m, "Type: %-4.4s\n", info->type);
75 /*
76 * Sigh: the model field has been renamed with System z9
77 * to model_capacity and a new model field has been added
78 * after the plant field. To avoid confusing older programs
79 * the "Model:" prints "model_capacity model" or just
80 * "model_capacity" if the model string is empty .
81 */
82 seq_printf(m, "Model: %-16.16s", info->model_capacity);
0fee644a 83 if (info->model[0] != '\0')
0facaa17
HC
84 seq_printf(m, " %-16.16s", info->model);
85 seq_putc(m, '\n');
86 seq_printf(m, "Sequence Code: %-16.16s\n", info->sequence);
87 seq_printf(m, "Plant: %-4.4s\n", info->plant);
88 seq_printf(m, "Model Capacity: %-16.16s %08u\n",
25502f00
HC
89 info->model_capacity, info->model_cap_rating);
90 if (info->model_perm_cap_rating)
0facaa17
HC
91 seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
92 info->model_perm_cap,
25502f00
HC
93 info->model_perm_cap_rating);
94 if (info->model_temp_cap_rating)
0facaa17
HC
95 seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
96 info->model_temp_cap,
25502f00
HC
97 info->model_temp_cap_rating);
98 if (info->ncr)
99 seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
100 if (info->npr)
101 seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
102 if (info->ntr)
103 seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
7aca2eda 104 if (info->cai) {
0facaa17
HC
105 seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
106 seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
25502f00
HC
107 seq_printf(m, "Capacity Transient: %d\n", info->t);
108 }
109 if (info->p) {
110 for (i = 1; i <= ARRAY_SIZE(info->typepct); i++) {
111 seq_printf(m, "Type %d Percentage: %d\n",
112 i, info->typepct[i - 1]);
113 }
7aca2eda 114 }
1da177e4
LT
115}
116
0facaa17 117static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
96f4a70d 118{
e527aec4 119 int i;
96f4a70d 120
0facaa17 121 seq_putc(m, '\n');
96f4a70d 122 if (!MACHINE_HAS_TOPOLOGY)
0facaa17 123 return;
caf757c6
HC
124 if (stsi(info, 15, 1, topology_max_mnest))
125 return;
0facaa17 126 seq_printf(m, "CPU Topology HW: ");
96f4a70d 127 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
0facaa17
HC
128 seq_printf(m, " %d", info->mag[i]);
129 seq_putc(m, '\n');
9236b4dd 130#ifdef CONFIG_SCHED_TOPOLOGY
96f4a70d 131 store_topology(info);
0facaa17 132 seq_printf(m, "CPU Topology SW: ");
96f4a70d 133 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
0facaa17
HC
134 seq_printf(m, " %d", info->mag[i]);
135 seq_putc(m, '\n');
8d11e021 136#endif
96f4a70d
HC
137}
138
0facaa17 139static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
1da177e4 140{
0fee644a
MS
141 struct sysinfo_1_2_2_extension *ext;
142 int i;
143
caf757c6 144 if (stsi(info, 1, 2, 2))
0facaa17 145 return;
0fee644a
MS
146 ext = (struct sysinfo_1_2_2_extension *)
147 ((unsigned long) info + info->acc_offset);
0facaa17
HC
148 seq_printf(m, "CPUs Total: %d\n", info->cpus_total);
149 seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured);
150 seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby);
151 seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved);
7022ec49
HC
152 if (info->mt_installed) {
153 seq_printf(m, "CPUs G-MTID: %d\n", info->mt_gtid);
154 seq_printf(m, "CPUs S-MTID: %d\n", info->mt_stid);
155 }
0facaa17
HC
156 /*
157 * Sigh 2. According to the specification the alternate
158 * capability field is a 32 bit floating point number
159 * if the higher order 8 bits are not zero. Printing
160 * a floating point number in the kernel is a no-no,
161 * always print the number as 32 bit unsigned integer.
162 * The user-space needs to know about the strange
163 * encoding of the alternate cpu capability.
164 */
165 seq_printf(m, "Capability: %u", info->capability);
166 if (info->format == 1)
167 seq_printf(m, " %u", ext->alt_capability);
168 seq_putc(m, '\n');
25502f00
HC
169 if (info->nominal_cap)
170 seq_printf(m, "Nominal Capability: %d\n", info->nominal_cap);
171 if (info->secondary_cap)
172 seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap);
0facaa17
HC
173 for (i = 2; i <= info->cpus_total; i++) {
174 seq_printf(m, "Adjustment %02d-way: %u",
175 i, info->adjustment[i-2]);
176 if (info->format == 1)
177 seq_printf(m, " %u", ext->alt_adjustment[i-2]);
178 seq_putc(m, '\n');
0fee644a 179 }
1da177e4
LT
180}
181
0facaa17 182static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
1da177e4 183{
caf757c6 184 if (stsi(info, 2, 2, 2))
0facaa17 185 return;
94f5b09d 186 EBCASC(info->name, sizeof(info->name));
0facaa17
HC
187 seq_putc(m, '\n');
188 seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
189 seq_printf(m, "LPAR Characteristics: ");
0fee644a 190 if (info->characteristics & LPAR_CHAR_DEDICATED)
0facaa17 191 seq_printf(m, "Dedicated ");
0fee644a 192 if (info->characteristics & LPAR_CHAR_SHARED)
0facaa17 193 seq_printf(m, "Shared ");
0fee644a 194 if (info->characteristics & LPAR_CHAR_LIMITED)
0facaa17
HC
195 seq_printf(m, "Limited ");
196 seq_putc(m, '\n');
197 seq_printf(m, "LPAR Name: %-8.8s\n", info->name);
198 seq_printf(m, "LPAR Adjustment: %d\n", info->caf);
199 seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total);
200 seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
201 seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby);
202 seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved);
203 seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated);
204 seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared);
7022ec49
HC
205 if (info->mt_installed) {
206 seq_printf(m, "LPAR CPUs G-MTID: %d\n", info->mt_gtid);
207 seq_printf(m, "LPAR CPUs S-MTID: %d\n", info->mt_stid);
208 seq_printf(m, "LPAR CPUs PS-MTID: %d\n", info->mt_psmtid);
10ad34bc 209 }
1da177e4
LT
210}
211
f3d0bd6c
ET
212static void print_ext_name(struct seq_file *m, int lvl,
213 struct sysinfo_3_2_2 *info)
214{
215 if (info->vm[lvl].ext_name_encoding == 0)
216 return;
217 if (info->ext_names[lvl][0] == 0)
218 return;
219 switch (info->vm[lvl].ext_name_encoding) {
220 case 1: /* EBCDIC */
221 EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl]));
222 break;
223 case 2: /* UTF-8 */
224 break;
225 default:
226 return;
227 }
228 seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl,
229 info->ext_names[lvl]);
230}
231
232static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
233{
234 if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
235 return;
236 seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid);
237}
238
0facaa17 239static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
1da177e4 240{
0fee644a
MS
241 int i;
242
caf757c6 243 if (stsi(info, 3, 2, 2))
0facaa17 244 return;
0fee644a 245 for (i = 0; i < info->count; i++) {
94f5b09d
HC
246 EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
247 EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
0facaa17
HC
248 seq_putc(m, '\n');
249 seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name);
250 seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
251 seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf);
252 seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total);
253 seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
254 seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby);
255 seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved);
f3d0bd6c
ET
256 print_ext_name(m, i, info);
257 print_uuid(m, i, info);
1da177e4 258 }
1da177e4
LT
259}
260
0facaa17 261static int sysinfo_show(struct seq_file *m, void *v)
1da177e4 262{
0facaa17
HC
263 void *info = (void *)get_zeroed_page(GFP_KERNEL);
264 int level;
94f5b09d 265
1da177e4
LT
266 if (!info)
267 return 0;
caf757c6 268 level = stsi(NULL, 0, 0, 0);
0fee644a 269 if (level >= 1)
0facaa17 270 stsi_1_1_1(m, info);
0fee644a 271 if (level >= 1)
0facaa17 272 stsi_15_1_x(m, info);
96f4a70d 273 if (level >= 1)
0facaa17 274 stsi_1_2_2(m, info);
0fee644a 275 if (level >= 2)
0facaa17 276 stsi_2_2_2(m, info);
0fee644a 277 if (level >= 3)
0facaa17
HC
278 stsi_3_2_2(m, info);
279 free_page((unsigned long)info);
280 return 0;
281}
1da177e4 282
0facaa17
HC
283static int sysinfo_open(struct inode *inode, struct file *file)
284{
285 return single_open(file, sysinfo_show, NULL);
1da177e4
LT
286}
287
0facaa17
HC
288static const struct file_operations sysinfo_fops = {
289 .open = sysinfo_open,
290 .read = seq_read,
291 .llseek = seq_lseek,
292 .release = single_release,
293};
294
295static int __init sysinfo_create_proc(void)
1da177e4 296{
0facaa17 297 proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
1da177e4
LT
298 return 0;
299}
0facaa17 300device_initcall(sysinfo_create_proc);
1da177e4 301
6bcac508
MS
302/*
303 * Service levels interface.
304 */
305
306static DECLARE_RWSEM(service_level_sem);
307static LIST_HEAD(service_level_list);
308
309int register_service_level(struct service_level *slr)
310{
311 struct service_level *ptr;
312
313 down_write(&service_level_sem);
314 list_for_each_entry(ptr, &service_level_list, list)
315 if (ptr == slr) {
316 up_write(&service_level_sem);
317 return -EEXIST;
318 }
319 list_add_tail(&slr->list, &service_level_list);
320 up_write(&service_level_sem);
321 return 0;
322}
323EXPORT_SYMBOL(register_service_level);
324
325int unregister_service_level(struct service_level *slr)
326{
327 struct service_level *ptr, *next;
328 int rc = -ENOENT;
329
330 down_write(&service_level_sem);
331 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
332 if (ptr != slr)
333 continue;
334 list_del(&ptr->list);
335 rc = 0;
336 break;
337 }
338 up_write(&service_level_sem);
339 return rc;
340}
341EXPORT_SYMBOL(unregister_service_level);
342
343static void *service_level_start(struct seq_file *m, loff_t *pos)
344{
345 down_read(&service_level_sem);
346 return seq_list_start(&service_level_list, *pos);
347}
348
349static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
350{
351 return seq_list_next(p, &service_level_list, pos);
352}
353
354static void service_level_stop(struct seq_file *m, void *p)
355{
356 up_read(&service_level_sem);
357}
358
359static int service_level_show(struct seq_file *m, void *p)
360{
361 struct service_level *slr;
362
363 slr = list_entry(p, struct service_level, list);
364 slr->seq_print(m, slr);
365 return 0;
366}
367
368static const struct seq_operations service_level_seq_ops = {
369 .start = service_level_start,
370 .next = service_level_next,
371 .stop = service_level_stop,
372 .show = service_level_show
373};
374
375static int service_level_open(struct inode *inode, struct file *file)
376{
377 return seq_open(file, &service_level_seq_ops);
378}
379
380static const struct file_operations service_level_ops = {
381 .open = service_level_open,
382 .read = seq_read,
383 .llseek = seq_lseek,
384 .release = seq_release
385};
386
387static void service_level_vm_print(struct seq_file *m,
388 struct service_level *slr)
389{
390 char *query_buffer, *str;
391
392 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
393 if (!query_buffer)
394 return;
395 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
396 str = strchr(query_buffer, '\n');
397 if (str)
398 *str = 0;
399 seq_printf(m, "VM: %s\n", query_buffer);
400 kfree(query_buffer);
401}
402
403static struct service_level service_level_vm = {
404 .seq_print = service_level_vm_print
405};
406
407static __init int create_proc_service_level(void)
408{
409 proc_create("service_levels", 0, NULL, &service_level_ops);
410 if (MACHINE_IS_VM)
411 register_service_level(&service_level_vm);
412 return 0;
413}
6bcac508
MS
414subsys_initcall(create_proc_service_level);
415
31ee4b2f
MS
416/*
417 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
418 */
419void s390_adjust_jiffies(void)
420{
421 struct sysinfo_1_2_2 *info;
9c203239
HC
422 unsigned long capability;
423 struct kernel_fpu fpu;
31ee4b2f
MS
424
425 info = (void *) get_zeroed_page(GFP_KERNEL);
426 if (!info)
427 return;
428
caf757c6 429 if (stsi(info, 1, 2, 2) == 0) {
31ee4b2f
MS
430 /*
431 * Major sigh. The cpu capability encoding is "special".
432 * If the first 9 bits of info->capability are 0 then it
433 * is a 32 bit unsigned integer in the range 0 .. 2^23.
434 * If the first 9 bits are != 0 then it is a 32 bit float.
435 * In addition a lower value indicates a proportionally
436 * higher cpu capacity. Bogomips are the other way round.
437 * To get to a halfway suitable number we divide 1e7
438 * by the cpu capability number. Yes, that means a floating
9c203239 439 * point division ..
31ee4b2f 440 */
9c203239
HC
441 kernel_fpu_begin(&fpu, KERNEL_FPR);
442 asm volatile(
443 " sfpc %3\n"
444 " l %0,%1\n"
445 " tmlh %0,0xff80\n"
446 " jnz 0f\n"
447 " cefbr %%f2,%0\n"
448 " j 1f\n"
449 "0: le %%f2,%1\n"
450 "1: cefbr %%f0,%2\n"
451 " debr %%f0,%%f2\n"
452 " cgebr %0,5,%%f0\n"
453 : "=&d" (capability)
454 : "Q" (info->capability), "d" (10000000), "d" (0)
455 : "cc"
456 );
7f79695c 457 kernel_fpu_end(&fpu, KERNEL_FPR);
31ee4b2f
MS
458 } else
459 /*
460 * Really old machine without stsi block for basic
461 * cpu information. Report 42.0 bogomips.
462 */
463 capability = 42;
464 loops_per_jiffy = capability * (500000/HZ);
465 free_page((unsigned long) info);
466}
467
468/*
469 * calibrate the delay loop
470 */
e2741f17 471void calibrate_delay(void)
31ee4b2f
MS
472{
473 s390_adjust_jiffies();
474 /* Print the good old Bogomips line .. */
475 printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
476 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
477 (loops_per_jiffy/(5000/HZ)) % 100);
478}
This page took 0.983934 seconds and 5 git commands to generate.