1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2001, 2009
4 * Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
8 #include <linux/debugfs.h>
9 #include <linux/kernel.h>
11 #include <linux/proc_fs.h>
12 #include <linux/seq_file.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
15 #include <linux/export.h>
16 #include <linux/slab.h>
17 #include <asm/ebcdic.h>
18 #include <asm/debug.h>
19 #include <asm/sysinfo.h>
20 #include <asm/cpcmd.h>
21 #include <asm/topology.h>
22 #include <asm/fpu/api.h>
24 int topology_max_mnest
;
26 static inline int __stsi(void *sysinfo
, int fc
, int sel1
, int sel2
, int *lvl
)
28 register int r0
asm("0") = (fc
<< 28) | sel1
;
29 register int r1
asm("1") = sel2
;
38 : "+d" (r0
), "+d" (rc
)
39 : "d" (r1
), "a" (sysinfo
), "K" (-EOPNOTSUPP
)
41 *lvl
= ((unsigned int) r0
) >> 28;
46 * stsi - store system information
48 * Returns the current configuration level if function code 0 was specified.
49 * Otherwise returns 0 on success or a negative value on error.
51 int stsi(void *sysinfo
, int fc
, int sel1
, int sel2
)
55 rc
= __stsi(sysinfo
, fc
, sel1
, sel2
, &lvl
);
64 static bool convert_ext_name(unsigned char encoding
, char *name
, size_t len
)
78 static void stsi_1_1_1(struct seq_file
*m
, struct sysinfo_1_1_1
*info
)
82 if (stsi(info
, 1, 1, 1))
84 EBCASC(info
->manufacturer
, sizeof(info
->manufacturer
));
85 EBCASC(info
->type
, sizeof(info
->type
));
86 EBCASC(info
->model
, sizeof(info
->model
));
87 EBCASC(info
->sequence
, sizeof(info
->sequence
));
88 EBCASC(info
->plant
, sizeof(info
->plant
));
89 EBCASC(info
->model_capacity
, sizeof(info
->model_capacity
));
90 EBCASC(info
->model_perm_cap
, sizeof(info
->model_perm_cap
));
91 EBCASC(info
->model_temp_cap
, sizeof(info
->model_temp_cap
));
92 seq_printf(m
, "Manufacturer: %-16.16s\n", info
->manufacturer
);
93 seq_printf(m
, "Type: %-4.4s\n", info
->type
);
95 * Sigh: the model field has been renamed with System z9
96 * to model_capacity and a new model field has been added
97 * after the plant field. To avoid confusing older programs
98 * the "Model:" prints "model_capacity model" or just
99 * "model_capacity" if the model string is empty .
101 seq_printf(m
, "Model: %-16.16s", info
->model_capacity
);
102 if (info
->model
[0] != '\0')
103 seq_printf(m
, " %-16.16s", info
->model
);
105 seq_printf(m
, "Sequence Code: %-16.16s\n", info
->sequence
);
106 seq_printf(m
, "Plant: %-4.4s\n", info
->plant
);
107 seq_printf(m
, "Model Capacity: %-16.16s %08u\n",
108 info
->model_capacity
, info
->model_cap_rating
);
109 if (info
->model_perm_cap_rating
)
110 seq_printf(m
, "Model Perm. Capacity: %-16.16s %08u\n",
111 info
->model_perm_cap
,
112 info
->model_perm_cap_rating
);
113 if (info
->model_temp_cap_rating
)
114 seq_printf(m
, "Model Temp. Capacity: %-16.16s %08u\n",
115 info
->model_temp_cap
,
116 info
->model_temp_cap_rating
);
118 seq_printf(m
, "Nominal Cap. Rating: %08u\n", info
->ncr
);
120 seq_printf(m
, "Nominal Perm. Rating: %08u\n", info
->npr
);
122 seq_printf(m
, "Nominal Temp. Rating: %08u\n", info
->ntr
);
124 seq_printf(m
, "Capacity Adj. Ind.: %d\n", info
->cai
);
125 seq_printf(m
, "Capacity Ch. Reason: %d\n", info
->ccr
);
126 seq_printf(m
, "Capacity Transient: %d\n", info
->t
);
129 for (i
= 1; i
<= ARRAY_SIZE(info
->typepct
); i
++) {
130 seq_printf(m
, "Type %d Percentage: %d\n",
131 i
, info
->typepct
[i
- 1]);
136 static void stsi_15_1_x(struct seq_file
*m
, struct sysinfo_15_1_x
*info
)
141 if (!MACHINE_HAS_TOPOLOGY
)
143 if (stsi(info
, 15, 1, topology_max_mnest
))
145 seq_printf(m
, "CPU Topology HW: ");
146 for (i
= 0; i
< TOPOLOGY_NR_MAG
; i
++)
147 seq_printf(m
, " %d", info
->mag
[i
]);
149 #ifdef CONFIG_SCHED_TOPOLOGY
150 store_topology(info
);
151 seq_printf(m
, "CPU Topology SW: ");
152 for (i
= 0; i
< TOPOLOGY_NR_MAG
; i
++)
153 seq_printf(m
, " %d", info
->mag
[i
]);
158 static void stsi_1_2_2(struct seq_file
*m
, struct sysinfo_1_2_2
*info
)
160 struct sysinfo_1_2_2_extension
*ext
;
163 if (stsi(info
, 1, 2, 2))
165 ext
= (struct sysinfo_1_2_2_extension
*)
166 ((unsigned long) info
+ info
->acc_offset
);
167 seq_printf(m
, "CPUs Total: %d\n", info
->cpus_total
);
168 seq_printf(m
, "CPUs Configured: %d\n", info
->cpus_configured
);
169 seq_printf(m
, "CPUs Standby: %d\n", info
->cpus_standby
);
170 seq_printf(m
, "CPUs Reserved: %d\n", info
->cpus_reserved
);
171 if (info
->mt_installed
) {
172 seq_printf(m
, "CPUs G-MTID: %d\n", info
->mt_gtid
);
173 seq_printf(m
, "CPUs S-MTID: %d\n", info
->mt_stid
);
176 * Sigh 2. According to the specification the alternate
177 * capability field is a 32 bit floating point number
178 * if the higher order 8 bits are not zero. Printing
179 * a floating point number in the kernel is a no-no,
180 * always print the number as 32 bit unsigned integer.
181 * The user-space needs to know about the strange
182 * encoding of the alternate cpu capability.
184 seq_printf(m
, "Capability: %u", info
->capability
);
185 if (info
->format
== 1)
186 seq_printf(m
, " %u", ext
->alt_capability
);
188 if (info
->nominal_cap
)
189 seq_printf(m
, "Nominal Capability: %d\n", info
->nominal_cap
);
190 if (info
->secondary_cap
)
191 seq_printf(m
, "Secondary Capability: %d\n", info
->secondary_cap
);
192 for (i
= 2; i
<= info
->cpus_total
; i
++) {
193 seq_printf(m
, "Adjustment %02d-way: %u",
194 i
, info
->adjustment
[i
-2]);
195 if (info
->format
== 1)
196 seq_printf(m
, " %u", ext
->alt_adjustment
[i
-2]);
201 static void stsi_2_2_2(struct seq_file
*m
, struct sysinfo_2_2_2
*info
)
203 if (stsi(info
, 2, 2, 2))
205 EBCASC(info
->name
, sizeof(info
->name
));
207 seq_printf(m
, "LPAR Number: %d\n", info
->lpar_number
);
208 seq_printf(m
, "LPAR Characteristics: ");
209 if (info
->characteristics
& LPAR_CHAR_DEDICATED
)
210 seq_printf(m
, "Dedicated ");
211 if (info
->characteristics
& LPAR_CHAR_SHARED
)
212 seq_printf(m
, "Shared ");
213 if (info
->characteristics
& LPAR_CHAR_LIMITED
)
214 seq_printf(m
, "Limited ");
216 seq_printf(m
, "LPAR Name: %-8.8s\n", info
->name
);
217 seq_printf(m
, "LPAR Adjustment: %d\n", info
->caf
);
218 seq_printf(m
, "LPAR CPUs Total: %d\n", info
->cpus_total
);
219 seq_printf(m
, "LPAR CPUs Configured: %d\n", info
->cpus_configured
);
220 seq_printf(m
, "LPAR CPUs Standby: %d\n", info
->cpus_standby
);
221 seq_printf(m
, "LPAR CPUs Reserved: %d\n", info
->cpus_reserved
);
222 seq_printf(m
, "LPAR CPUs Dedicated: %d\n", info
->cpus_dedicated
);
223 seq_printf(m
, "LPAR CPUs Shared: %d\n", info
->cpus_shared
);
224 if (info
->mt_installed
) {
225 seq_printf(m
, "LPAR CPUs G-MTID: %d\n", info
->mt_gtid
);
226 seq_printf(m
, "LPAR CPUs S-MTID: %d\n", info
->mt_stid
);
227 seq_printf(m
, "LPAR CPUs PS-MTID: %d\n", info
->mt_psmtid
);
229 if (convert_ext_name(info
->vsne
, info
->ext_name
, sizeof(info
->ext_name
))) {
230 seq_printf(m
, "LPAR Extended Name: %-.256s\n", info
->ext_name
);
231 seq_printf(m
, "LPAR UUID: %pUb\n", &info
->uuid
);
235 static void print_ext_name(struct seq_file
*m
, int lvl
,
236 struct sysinfo_3_2_2
*info
)
238 size_t len
= sizeof(info
->ext_names
[lvl
]);
240 if (!convert_ext_name(info
->vm
[lvl
].evmne
, info
->ext_names
[lvl
], len
))
242 seq_printf(m
, "VM%02d Extended Name: %-.256s\n", lvl
,
243 info
->ext_names
[lvl
]);
246 static void print_uuid(struct seq_file
*m
, int i
, struct sysinfo_3_2_2
*info
)
248 if (uuid_is_null(&info
->vm
[i
].uuid
))
250 seq_printf(m
, "VM%02d UUID: %pUb\n", i
, &info
->vm
[i
].uuid
);
253 static void stsi_3_2_2(struct seq_file
*m
, struct sysinfo_3_2_2
*info
)
257 if (stsi(info
, 3, 2, 2))
259 for (i
= 0; i
< info
->count
; i
++) {
260 EBCASC(info
->vm
[i
].name
, sizeof(info
->vm
[i
].name
));
261 EBCASC(info
->vm
[i
].cpi
, sizeof(info
->vm
[i
].cpi
));
263 seq_printf(m
, "VM%02d Name: %-8.8s\n", i
, info
->vm
[i
].name
);
264 seq_printf(m
, "VM%02d Control Program: %-16.16s\n", i
, info
->vm
[i
].cpi
);
265 seq_printf(m
, "VM%02d Adjustment: %d\n", i
, info
->vm
[i
].caf
);
266 seq_printf(m
, "VM%02d CPUs Total: %d\n", i
, info
->vm
[i
].cpus_total
);
267 seq_printf(m
, "VM%02d CPUs Configured: %d\n", i
, info
->vm
[i
].cpus_configured
);
268 seq_printf(m
, "VM%02d CPUs Standby: %d\n", i
, info
->vm
[i
].cpus_standby
);
269 seq_printf(m
, "VM%02d CPUs Reserved: %d\n", i
, info
->vm
[i
].cpus_reserved
);
270 print_ext_name(m
, i
, info
);
271 print_uuid(m
, i
, info
);
275 static int sysinfo_show(struct seq_file
*m
, void *v
)
277 void *info
= (void *)get_zeroed_page(GFP_KERNEL
);
282 level
= stsi(NULL
, 0, 0, 0);
286 stsi_15_1_x(m
, info
);
293 free_page((unsigned long)info
);
297 static int sysinfo_open(struct inode
*inode
, struct file
*file
)
299 return single_open(file
, sysinfo_show
, NULL
);
302 static const struct file_operations sysinfo_fops
= {
303 .open
= sysinfo_open
,
306 .release
= single_release
,
309 static int __init
sysinfo_create_proc(void)
311 proc_create("sysinfo", 0444, NULL
, &sysinfo_fops
);
314 device_initcall(sysinfo_create_proc
);
316 #endif /* CONFIG_PROC_FS */
319 * Service levels interface.
322 static DECLARE_RWSEM(service_level_sem
);
323 static LIST_HEAD(service_level_list
);
325 int register_service_level(struct service_level
*slr
)
327 struct service_level
*ptr
;
329 down_write(&service_level_sem
);
330 list_for_each_entry(ptr
, &service_level_list
, list
)
332 up_write(&service_level_sem
);
335 list_add_tail(&slr
->list
, &service_level_list
);
336 up_write(&service_level_sem
);
339 EXPORT_SYMBOL(register_service_level
);
341 int unregister_service_level(struct service_level
*slr
)
343 struct service_level
*ptr
, *next
;
346 down_write(&service_level_sem
);
347 list_for_each_entry_safe(ptr
, next
, &service_level_list
, list
) {
350 list_del(&ptr
->list
);
354 up_write(&service_level_sem
);
357 EXPORT_SYMBOL(unregister_service_level
);
359 static void *service_level_start(struct seq_file
*m
, loff_t
*pos
)
361 down_read(&service_level_sem
);
362 return seq_list_start(&service_level_list
, *pos
);
365 static void *service_level_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
367 return seq_list_next(p
, &service_level_list
, pos
);
370 static void service_level_stop(struct seq_file
*m
, void *p
)
372 up_read(&service_level_sem
);
375 static int service_level_show(struct seq_file
*m
, void *p
)
377 struct service_level
*slr
;
379 slr
= list_entry(p
, struct service_level
, list
);
380 slr
->seq_print(m
, slr
);
384 static const struct seq_operations service_level_seq_ops
= {
385 .start
= service_level_start
,
386 .next
= service_level_next
,
387 .stop
= service_level_stop
,
388 .show
= service_level_show
391 static int service_level_open(struct inode
*inode
, struct file
*file
)
393 return seq_open(file
, &service_level_seq_ops
);
396 static const struct file_operations service_level_ops
= {
397 .open
= service_level_open
,
400 .release
= seq_release
403 static void service_level_vm_print(struct seq_file
*m
,
404 struct service_level
*slr
)
406 char *query_buffer
, *str
;
408 query_buffer
= kmalloc(1024, GFP_KERNEL
| GFP_DMA
);
411 cpcmd("QUERY CPLEVEL", query_buffer
, 1024, NULL
);
412 str
= strchr(query_buffer
, '\n');
415 seq_printf(m
, "VM: %s\n", query_buffer
);
419 static struct service_level service_level_vm
= {
420 .seq_print
= service_level_vm_print
423 static __init
int create_proc_service_level(void)
425 proc_create("service_levels", 0, NULL
, &service_level_ops
);
427 register_service_level(&service_level_vm
);
430 subsys_initcall(create_proc_service_level
);
433 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
435 void s390_adjust_jiffies(void)
437 struct sysinfo_1_2_2
*info
;
438 unsigned long capability
;
439 struct kernel_fpu fpu
;
441 info
= (void *) get_zeroed_page(GFP_KERNEL
);
445 if (stsi(info
, 1, 2, 2) == 0) {
447 * Major sigh. The cpu capability encoding is "special".
448 * If the first 9 bits of info->capability are 0 then it
449 * is a 32 bit unsigned integer in the range 0 .. 2^23.
450 * If the first 9 bits are != 0 then it is a 32 bit float.
451 * In addition a lower value indicates a proportionally
452 * higher cpu capacity. Bogomips are the other way round.
453 * To get to a halfway suitable number we divide 1e7
454 * by the cpu capability number. Yes, that means a floating
457 kernel_fpu_begin(&fpu
, KERNEL_FPR
);
470 : "Q" (info
->capability
), "d" (10000000), "d" (0)
473 kernel_fpu_end(&fpu
, KERNEL_FPR
);
476 * Really old machine without stsi block for basic
477 * cpu information. Report 42.0 bogomips.
480 loops_per_jiffy
= capability
* (500000/HZ
);
481 free_page((unsigned long) info
);
485 * calibrate the delay loop
487 void calibrate_delay(void)
489 s390_adjust_jiffies();
490 /* Print the good old Bogomips line .. */
491 printk(KERN_DEBUG
"Calibrating delay loop (skipped)... "
492 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy
/(500000/HZ
),
493 (loops_per_jiffy
/(5000/HZ
)) % 100);
496 #ifdef CONFIG_DEBUG_FS
498 #define STSI_FILE(fc, s1, s2) \
499 static int stsi_open_##fc##_##s1##_##s2(struct inode *inode, struct file *file)\
501 file->private_data = (void *) get_zeroed_page(GFP_KERNEL); \
502 if (!file->private_data) \
504 if (stsi(file->private_data, fc, s1, s2)) { \
505 free_page((unsigned long)file->private_data); \
506 file->private_data = NULL; \
509 return nonseekable_open(inode, file); \
512 static const struct file_operations stsi_##fc##_##s1##_##s2##_fs_ops = { \
513 .open = stsi_open_##fc##_##s1##_##s2, \
514 .release = stsi_release, \
516 .llseek = no_llseek, \
519 static int stsi_release(struct inode
*inode
, struct file
*file
)
521 free_page((unsigned long)file
->private_data
);
525 static ssize_t
stsi_read(struct file
*file
, char __user
*buf
, size_t size
, loff_t
*ppos
)
527 return simple_read_from_buffer(buf
, size
, ppos
, file
->private_data
, PAGE_SIZE
);
543 const struct file_operations
*fops
;
547 static struct stsi_file stsi_file
[] __initdata
= {
548 {.fops
= &stsi_1_1_1_fs_ops
, .name
= "1_1_1"},
549 {.fops
= &stsi_1_2_1_fs_ops
, .name
= "1_2_1"},
550 {.fops
= &stsi_1_2_2_fs_ops
, .name
= "1_2_2"},
551 {.fops
= &stsi_2_2_1_fs_ops
, .name
= "2_2_1"},
552 {.fops
= &stsi_2_2_2_fs_ops
, .name
= "2_2_2"},
553 {.fops
= &stsi_3_2_2_fs_ops
, .name
= "3_2_2"},
554 {.fops
= &stsi_15_1_2_fs_ops
, .name
= "15_1_2"},
555 {.fops
= &stsi_15_1_3_fs_ops
, .name
= "15_1_3"},
556 {.fops
= &stsi_15_1_4_fs_ops
, .name
= "15_1_4"},
557 {.fops
= &stsi_15_1_5_fs_ops
, .name
= "15_1_5"},
558 {.fops
= &stsi_15_1_6_fs_ops
, .name
= "15_1_6"},
561 static u8 stsi_0_0_0
;
563 static __init
int stsi_init_debugfs(void)
565 struct dentry
*stsi_root
;
566 struct stsi_file
*sf
;
569 stsi_root
= debugfs_create_dir("stsi", arch_debugfs_dir
);
570 if (IS_ERR_OR_NULL(stsi_root
))
572 lvl
= stsi(NULL
, 0, 0, 0);
575 debugfs_create_u8("0_0_0", 0400, stsi_root
, &stsi_0_0_0
);
576 for (i
= 0; i
< ARRAY_SIZE(stsi_file
); i
++) {
578 debugfs_create_file(sf
->name
, 0400, stsi_root
, NULL
, sf
->fops
);
580 if (IS_ENABLED(CONFIG_SCHED_TOPOLOGY
) && MACHINE_HAS_TOPOLOGY
) {
583 sprintf(link_to
, "15_1_%d", topology_mnest_limit());
584 debugfs_create_symlink("topology", stsi_root
, link_to
);
588 device_initcall(stsi_init_debugfs
);
590 #endif /* CONFIG_DEBUG_FS */