2 * Copyright IBM Corp. 2001, 2009
3 * Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
4 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 #include <linux/debugfs.h>
8 #include <linux/kernel.h>
10 #include <linux/proc_fs.h>
11 #include <linux/seq_file.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
14 #include <linux/export.h>
15 #include <linux/slab.h>
16 #include <asm/ebcdic.h>
17 #include <asm/debug.h>
18 #include <asm/sysinfo.h>
19 #include <asm/cpcmd.h>
20 #include <asm/topology.h>
21 #include <asm/fpu/api.h>
23 int topology_max_mnest;
25 static inline int __stsi(void *sysinfo, int fc, int sel1, int sel2, int *lvl)
27 register int r0 asm("0") = (fc << 28) | sel1;
28 register int r1 asm("1") = sel2;
37 : "+d" (r0), "+d" (rc)
38 : "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP)
40 *lvl = ((unsigned int) r0) >> 28;
45 * stsi - store system information
47 * Returns the current configuration level if function code 0 was specified.
48 * Otherwise returns 0 on success or a negative value on error.
50 int stsi(void *sysinfo, int fc, int sel1, int sel2)
54 rc = __stsi(sysinfo, fc, sel1, sel2, &lvl);
61 static bool convert_ext_name(unsigned char encoding, char *name, size_t len)
75 static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
79 if (stsi(info, 1, 1, 1))
81 EBCASC(info->manufacturer, sizeof(info->manufacturer));
82 EBCASC(info->type, sizeof(info->type));
83 EBCASC(info->model, sizeof(info->model));
84 EBCASC(info->sequence, sizeof(info->sequence));
85 EBCASC(info->plant, sizeof(info->plant));
86 EBCASC(info->model_capacity, sizeof(info->model_capacity));
87 EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
88 EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
89 seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
90 seq_printf(m, "Type: %-4.4s\n", info->type);
92 * Sigh: the model field has been renamed with System z9
93 * to model_capacity and a new model field has been added
94 * after the plant field. To avoid confusing older programs
95 * the "Model:" prints "model_capacity model" or just
96 * "model_capacity" if the model string is empty .
98 seq_printf(m, "Model: %-16.16s", info->model_capacity);
99 if (info->model[0] != '\0')
100 seq_printf(m, " %-16.16s", info->model);
102 seq_printf(m, "Sequence Code: %-16.16s\n", info->sequence);
103 seq_printf(m, "Plant: %-4.4s\n", info->plant);
104 seq_printf(m, "Model Capacity: %-16.16s %08u\n",
105 info->model_capacity, info->model_cap_rating);
106 if (info->model_perm_cap_rating)
107 seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
108 info->model_perm_cap,
109 info->model_perm_cap_rating);
110 if (info->model_temp_cap_rating)
111 seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
112 info->model_temp_cap,
113 info->model_temp_cap_rating);
115 seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
117 seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
119 seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
121 seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
122 seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
123 seq_printf(m, "Capacity Transient: %d\n", info->t);
126 for (i = 1; i <= ARRAY_SIZE(info->typepct); i++) {
127 seq_printf(m, "Type %d Percentage: %d\n",
128 i, info->typepct[i - 1]);
133 static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
138 if (!MACHINE_HAS_TOPOLOGY)
140 if (stsi(info, 15, 1, topology_max_mnest))
142 seq_printf(m, "CPU Topology HW: ");
143 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
144 seq_printf(m, " %d", info->mag[i]);
146 #ifdef CONFIG_SCHED_TOPOLOGY
147 store_topology(info);
148 seq_printf(m, "CPU Topology SW: ");
149 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
150 seq_printf(m, " %d", info->mag[i]);
155 static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
157 struct sysinfo_1_2_2_extension *ext;
160 if (stsi(info, 1, 2, 2))
162 ext = (struct sysinfo_1_2_2_extension *)
163 ((unsigned long) info + info->acc_offset);
164 seq_printf(m, "CPUs Total: %d\n", info->cpus_total);
165 seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured);
166 seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby);
167 seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved);
168 if (info->mt_installed) {
169 seq_printf(m, "CPUs G-MTID: %d\n", info->mt_gtid);
170 seq_printf(m, "CPUs S-MTID: %d\n", info->mt_stid);
173 * Sigh 2. According to the specification the alternate
174 * capability field is a 32 bit floating point number
175 * if the higher order 8 bits are not zero. Printing
176 * a floating point number in the kernel is a no-no,
177 * always print the number as 32 bit unsigned integer.
178 * The user-space needs to know about the strange
179 * encoding of the alternate cpu capability.
181 seq_printf(m, "Capability: %u", info->capability);
182 if (info->format == 1)
183 seq_printf(m, " %u", ext->alt_capability);
185 if (info->nominal_cap)
186 seq_printf(m, "Nominal Capability: %d\n", info->nominal_cap);
187 if (info->secondary_cap)
188 seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap);
189 for (i = 2; i <= info->cpus_total; i++) {
190 seq_printf(m, "Adjustment %02d-way: %u",
191 i, info->adjustment[i-2]);
192 if (info->format == 1)
193 seq_printf(m, " %u", ext->alt_adjustment[i-2]);
198 static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
200 if (stsi(info, 2, 2, 2))
202 EBCASC(info->name, sizeof(info->name));
204 seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
205 seq_printf(m, "LPAR Characteristics: ");
206 if (info->characteristics & LPAR_CHAR_DEDICATED)
207 seq_printf(m, "Dedicated ");
208 if (info->characteristics & LPAR_CHAR_SHARED)
209 seq_printf(m, "Shared ");
210 if (info->characteristics & LPAR_CHAR_LIMITED)
211 seq_printf(m, "Limited ");
213 seq_printf(m, "LPAR Name: %-8.8s\n", info->name);
214 seq_printf(m, "LPAR Adjustment: %d\n", info->caf);
215 seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total);
216 seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
217 seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby);
218 seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved);
219 seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated);
220 seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared);
221 if (info->mt_installed) {
222 seq_printf(m, "LPAR CPUs G-MTID: %d\n", info->mt_gtid);
223 seq_printf(m, "LPAR CPUs S-MTID: %d\n", info->mt_stid);
224 seq_printf(m, "LPAR CPUs PS-MTID: %d\n", info->mt_psmtid);
226 if (convert_ext_name(info->vsne, info->ext_name, sizeof(info->ext_name))) {
227 seq_printf(m, "LPAR Extended Name: %-.256s\n", info->ext_name);
228 seq_printf(m, "LPAR UUID: %pUb\n", &info->uuid);
232 static void print_ext_name(struct seq_file *m, int lvl,
233 struct sysinfo_3_2_2 *info)
235 size_t len = sizeof(info->ext_names[lvl]);
237 if (!convert_ext_name(info->vm[lvl].evmne, info->ext_names[lvl], len))
239 seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl,
240 info->ext_names[lvl]);
243 static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
245 if (uuid_is_null(&info->vm[i].uuid))
247 seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid);
250 static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
254 if (stsi(info, 3, 2, 2))
256 for (i = 0; i < info->count; i++) {
257 EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
258 EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
260 seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name);
261 seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
262 seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf);
263 seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total);
264 seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
265 seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby);
266 seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved);
267 print_ext_name(m, i, info);
268 print_uuid(m, i, info);
272 static int sysinfo_show(struct seq_file *m, void *v)
274 void *info = (void *)get_zeroed_page(GFP_KERNEL);
279 level = stsi(NULL, 0, 0, 0);
283 stsi_15_1_x(m, info);
290 free_page((unsigned long)info);
294 static int sysinfo_open(struct inode *inode, struct file *file)
296 return single_open(file, sysinfo_show, NULL);
299 static const struct file_operations sysinfo_fops = {
300 .open = sysinfo_open,
303 .release = single_release,
306 static int __init sysinfo_create_proc(void)
308 proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
311 device_initcall(sysinfo_create_proc);
314 * Service levels interface.
317 static DECLARE_RWSEM(service_level_sem);
318 static LIST_HEAD(service_level_list);
320 int register_service_level(struct service_level *slr)
322 struct service_level *ptr;
324 down_write(&service_level_sem);
325 list_for_each_entry(ptr, &service_level_list, list)
327 up_write(&service_level_sem);
330 list_add_tail(&slr->list, &service_level_list);
331 up_write(&service_level_sem);
334 EXPORT_SYMBOL(register_service_level);
336 int unregister_service_level(struct service_level *slr)
338 struct service_level *ptr, *next;
341 down_write(&service_level_sem);
342 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
345 list_del(&ptr->list);
349 up_write(&service_level_sem);
352 EXPORT_SYMBOL(unregister_service_level);
354 static void *service_level_start(struct seq_file *m, loff_t *pos)
356 down_read(&service_level_sem);
357 return seq_list_start(&service_level_list, *pos);
360 static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
362 return seq_list_next(p, &service_level_list, pos);
365 static void service_level_stop(struct seq_file *m, void *p)
367 up_read(&service_level_sem);
370 static int service_level_show(struct seq_file *m, void *p)
372 struct service_level *slr;
374 slr = list_entry(p, struct service_level, list);
375 slr->seq_print(m, slr);
379 static const struct seq_operations service_level_seq_ops = {
380 .start = service_level_start,
381 .next = service_level_next,
382 .stop = service_level_stop,
383 .show = service_level_show
386 static int service_level_open(struct inode *inode, struct file *file)
388 return seq_open(file, &service_level_seq_ops);
391 static const struct file_operations service_level_ops = {
392 .open = service_level_open,
395 .release = seq_release
398 static void service_level_vm_print(struct seq_file *m,
399 struct service_level *slr)
401 char *query_buffer, *str;
403 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
406 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
407 str = strchr(query_buffer, '\n');
410 seq_printf(m, "VM: %s\n", query_buffer);
414 static struct service_level service_level_vm = {
415 .seq_print = service_level_vm_print
418 static __init int create_proc_service_level(void)
420 proc_create("service_levels", 0, NULL, &service_level_ops);
422 register_service_level(&service_level_vm);
425 subsys_initcall(create_proc_service_level);
428 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
430 void s390_adjust_jiffies(void)
432 struct sysinfo_1_2_2 *info;
433 unsigned long capability;
434 struct kernel_fpu fpu;
436 info = (void *) get_zeroed_page(GFP_KERNEL);
440 if (stsi(info, 1, 2, 2) == 0) {
442 * Major sigh. The cpu capability encoding is "special".
443 * If the first 9 bits of info->capability are 0 then it
444 * is a 32 bit unsigned integer in the range 0 .. 2^23.
445 * If the first 9 bits are != 0 then it is a 32 bit float.
446 * In addition a lower value indicates a proportionally
447 * higher cpu capacity. Bogomips are the other way round.
448 * To get to a halfway suitable number we divide 1e7
449 * by the cpu capability number. Yes, that means a floating
452 kernel_fpu_begin(&fpu, KERNEL_FPR);
465 : "Q" (info->capability), "d" (10000000), "d" (0)
468 kernel_fpu_end(&fpu, KERNEL_FPR);
471 * Really old machine without stsi block for basic
472 * cpu information. Report 42.0 bogomips.
475 loops_per_jiffy = capability * (500000/HZ);
476 free_page((unsigned long) info);
480 * calibrate the delay loop
482 void calibrate_delay(void)
484 s390_adjust_jiffies();
485 /* Print the good old Bogomips line .. */
486 printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
487 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
488 (loops_per_jiffy/(5000/HZ)) % 100);
491 #ifdef CONFIG_DEBUG_FS
493 #define STSI_FILE(fc, s1, s2) \
494 static int stsi_open_##fc##_##s1##_##s2(struct inode *inode, struct file *file)\
496 file->private_data = (void *) get_zeroed_page(GFP_KERNEL); \
497 if (!file->private_data) \
499 if (stsi(file->private_data, fc, s1, s2)) { \
500 free_page((unsigned long)file->private_data); \
501 file->private_data = NULL; \
504 return nonseekable_open(inode, file); \
507 static const struct file_operations stsi_##fc##_##s1##_##s2##_fs_ops = { \
508 .open = stsi_open_##fc##_##s1##_##s2, \
509 .release = stsi_release, \
511 .llseek = no_llseek, \
514 static int stsi_release(struct inode *inode, struct file *file)
516 free_page((unsigned long)file->private_data);
520 static ssize_t stsi_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
522 return simple_read_from_buffer(buf, size, ppos, file->private_data, PAGE_SIZE);
538 const struct file_operations *fops;
542 static struct stsi_file stsi_file[] __initdata = {
543 {.fops = &stsi_1_1_1_fs_ops, .name = "1_1_1"},
544 {.fops = &stsi_1_2_1_fs_ops, .name = "1_2_1"},
545 {.fops = &stsi_1_2_2_fs_ops, .name = "1_2_2"},
546 {.fops = &stsi_2_2_1_fs_ops, .name = "2_2_1"},
547 {.fops = &stsi_2_2_2_fs_ops, .name = "2_2_2"},
548 {.fops = &stsi_3_2_2_fs_ops, .name = "3_2_2"},
549 {.fops = &stsi_15_1_2_fs_ops, .name = "15_1_2"},
550 {.fops = &stsi_15_1_3_fs_ops, .name = "15_1_3"},
551 {.fops = &stsi_15_1_4_fs_ops, .name = "15_1_4"},
552 {.fops = &stsi_15_1_5_fs_ops, .name = "15_1_5"},
553 {.fops = &stsi_15_1_6_fs_ops, .name = "15_1_6"},
556 static u8 stsi_0_0_0;
558 static __init int stsi_init_debugfs(void)
560 struct dentry *stsi_root;
561 struct stsi_file *sf;
564 stsi_root = debugfs_create_dir("stsi", arch_debugfs_dir);
565 if (IS_ERR_OR_NULL(stsi_root))
567 lvl = stsi(NULL, 0, 0, 0);
570 debugfs_create_u8("0_0_0", 0400, stsi_root, &stsi_0_0_0);
571 for (i = 0; i < ARRAY_SIZE(stsi_file); i++) {
573 debugfs_create_file(sf->name, 0400, stsi_root, NULL, sf->fops);
575 if (IS_ENABLED(CONFIG_SCHED_TOPOLOGY) && MACHINE_HAS_TOPOLOGY) {
578 sprintf(link_to, "15_1_%d", topology_mnest_limit());
579 debugfs_create_symlink("topology", stsi_root, link_to);
583 device_initcall(stsi_init_debugfs);
585 #endif /* CONFIG_DEBUG_FS */