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/kernel.h>
9 #include <linux/proc_fs.h>
10 #include <linux/seq_file.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <asm/ebcdic.h>
16 #include <asm/sysinfo.h>
17 #include <asm/cpcmd.h>
18 #include <asm/topology.h>
19 #include <asm/fpu/api.h>
21 int topology_max_mnest;
23 static inline int __stsi(void *sysinfo, int fc, int sel1, int sel2, int *lvl)
25 register int r0 asm("0") = (fc << 28) | sel1;
26 register int r1 asm("1") = sel2;
35 : "+d" (r0), "+d" (rc)
36 : "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP)
38 *lvl = ((unsigned int) r0) >> 28;
43 * stsi - store system information
45 * Returns the current configuration level if function code 0 was specified.
46 * Otherwise returns 0 on success or a negative value on error.
48 int stsi(void *sysinfo, int fc, int sel1, int sel2)
52 rc = __stsi(sysinfo, fc, sel1, sel2, &lvl);
59 static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
63 if (stsi(info, 1, 1, 1))
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));
71 EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
72 EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
73 seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
74 seq_printf(m, "Type: %-4.4s\n", info->type);
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 .
82 seq_printf(m, "Model: %-16.16s", info->model_capacity);
83 if (info->model[0] != '\0')
84 seq_printf(m, " %-16.16s", info->model);
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",
89 info->model_capacity, info->model_cap_rating);
90 if (info->model_perm_cap_rating)
91 seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
93 info->model_perm_cap_rating);
94 if (info->model_temp_cap_rating)
95 seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
97 info->model_temp_cap_rating);
99 seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
101 seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
103 seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
105 seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
106 seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
107 seq_printf(m, "Capacity Transient: %d\n", info->t);
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]);
117 static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
122 if (!MACHINE_HAS_TOPOLOGY)
124 if (stsi(info, 15, 1, topology_max_mnest))
126 seq_printf(m, "CPU Topology HW: ");
127 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
128 seq_printf(m, " %d", info->mag[i]);
130 #ifdef CONFIG_SCHED_TOPOLOGY
131 store_topology(info);
132 seq_printf(m, "CPU Topology SW: ");
133 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
134 seq_printf(m, " %d", info->mag[i]);
139 static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
141 struct sysinfo_1_2_2_extension *ext;
144 if (stsi(info, 1, 2, 2))
146 ext = (struct sysinfo_1_2_2_extension *)
147 ((unsigned long) info + info->acc_offset);
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);
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);
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.
165 seq_printf(m, "Capability: %u", info->capability);
166 if (info->format == 1)
167 seq_printf(m, " %u", ext->alt_capability);
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);
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]);
182 static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
184 if (stsi(info, 2, 2, 2))
186 EBCASC(info->name, sizeof(info->name));
188 seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
189 seq_printf(m, "LPAR Characteristics: ");
190 if (info->characteristics & LPAR_CHAR_DEDICATED)
191 seq_printf(m, "Dedicated ");
192 if (info->characteristics & LPAR_CHAR_SHARED)
193 seq_printf(m, "Shared ");
194 if (info->characteristics & LPAR_CHAR_LIMITED)
195 seq_printf(m, "Limited ");
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);
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);
212 static void print_ext_name(struct seq_file *m, int lvl,
213 struct sysinfo_3_2_2 *info)
215 if (info->vm[lvl].ext_name_encoding == 0)
217 if (info->ext_names[lvl][0] == 0)
219 switch (info->vm[lvl].ext_name_encoding) {
221 EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl]));
228 seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl,
229 info->ext_names[lvl]);
232 static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
234 if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
236 seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid);
239 static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
243 if (stsi(info, 3, 2, 2))
245 for (i = 0; i < info->count; i++) {
246 EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
247 EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
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);
256 print_ext_name(m, i, info);
257 print_uuid(m, i, info);
261 static int sysinfo_show(struct seq_file *m, void *v)
263 void *info = (void *)get_zeroed_page(GFP_KERNEL);
268 level = stsi(NULL, 0, 0, 0);
272 stsi_15_1_x(m, info);
279 free_page((unsigned long)info);
283 static int sysinfo_open(struct inode *inode, struct file *file)
285 return single_open(file, sysinfo_show, NULL);
288 static const struct file_operations sysinfo_fops = {
289 .open = sysinfo_open,
292 .release = single_release,
295 static int __init sysinfo_create_proc(void)
297 proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
300 device_initcall(sysinfo_create_proc);
303 * Service levels interface.
306 static DECLARE_RWSEM(service_level_sem);
307 static LIST_HEAD(service_level_list);
309 int register_service_level(struct service_level *slr)
311 struct service_level *ptr;
313 down_write(&service_level_sem);
314 list_for_each_entry(ptr, &service_level_list, list)
316 up_write(&service_level_sem);
319 list_add_tail(&slr->list, &service_level_list);
320 up_write(&service_level_sem);
323 EXPORT_SYMBOL(register_service_level);
325 int unregister_service_level(struct service_level *slr)
327 struct service_level *ptr, *next;
330 down_write(&service_level_sem);
331 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
334 list_del(&ptr->list);
338 up_write(&service_level_sem);
341 EXPORT_SYMBOL(unregister_service_level);
343 static void *service_level_start(struct seq_file *m, loff_t *pos)
345 down_read(&service_level_sem);
346 return seq_list_start(&service_level_list, *pos);
349 static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
351 return seq_list_next(p, &service_level_list, pos);
354 static void service_level_stop(struct seq_file *m, void *p)
356 up_read(&service_level_sem);
359 static int service_level_show(struct seq_file *m, void *p)
361 struct service_level *slr;
363 slr = list_entry(p, struct service_level, list);
364 slr->seq_print(m, slr);
368 static 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
375 static int service_level_open(struct inode *inode, struct file *file)
377 return seq_open(file, &service_level_seq_ops);
380 static const struct file_operations service_level_ops = {
381 .open = service_level_open,
384 .release = seq_release
387 static void service_level_vm_print(struct seq_file *m,
388 struct service_level *slr)
390 char *query_buffer, *str;
392 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
395 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
396 str = strchr(query_buffer, '\n');
399 seq_printf(m, "VM: %s\n", query_buffer);
403 static struct service_level service_level_vm = {
404 .seq_print = service_level_vm_print
407 static __init int create_proc_service_level(void)
409 proc_create("service_levels", 0, NULL, &service_level_ops);
411 register_service_level(&service_level_vm);
414 subsys_initcall(create_proc_service_level);
417 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
419 void s390_adjust_jiffies(void)
421 struct sysinfo_1_2_2 *info;
422 unsigned long capability;
423 struct kernel_fpu fpu;
425 info = (void *) get_zeroed_page(GFP_KERNEL);
429 if (stsi(info, 1, 2, 2) == 0) {
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
441 kernel_fpu_begin(&fpu, KERNEL_FPR);
454 : "Q" (info->capability), "d" (10000000), "d" (0)
457 kernel_fpu_end(&fpu, KERNEL_FPR);
460 * Really old machine without stsi block for basic
461 * cpu information. Report 42.0 bogomips.
464 loops_per_jiffy = capability * (500000/HZ);
465 free_page((unsigned long) info);
469 * calibrate the delay loop
471 void calibrate_delay(void)
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);