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/export.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 bool convert_ext_name(unsigned char encoding, char *name, size_t len)
73 static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
77 if (stsi(info, 1, 1, 1))
79 EBCASC(info->manufacturer, sizeof(info->manufacturer));
80 EBCASC(info->type, sizeof(info->type));
81 EBCASC(info->model, sizeof(info->model));
82 EBCASC(info->sequence, sizeof(info->sequence));
83 EBCASC(info->plant, sizeof(info->plant));
84 EBCASC(info->model_capacity, sizeof(info->model_capacity));
85 EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
86 EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
87 seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
88 seq_printf(m, "Type: %-4.4s\n", info->type);
90 * Sigh: the model field has been renamed with System z9
91 * to model_capacity and a new model field has been added
92 * after the plant field. To avoid confusing older programs
93 * the "Model:" prints "model_capacity model" or just
94 * "model_capacity" if the model string is empty .
96 seq_printf(m, "Model: %-16.16s", info->model_capacity);
97 if (info->model[0] != '\0')
98 seq_printf(m, " %-16.16s", info->model);
100 seq_printf(m, "Sequence Code: %-16.16s\n", info->sequence);
101 seq_printf(m, "Plant: %-4.4s\n", info->plant);
102 seq_printf(m, "Model Capacity: %-16.16s %08u\n",
103 info->model_capacity, info->model_cap_rating);
104 if (info->model_perm_cap_rating)
105 seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
106 info->model_perm_cap,
107 info->model_perm_cap_rating);
108 if (info->model_temp_cap_rating)
109 seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
110 info->model_temp_cap,
111 info->model_temp_cap_rating);
113 seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
115 seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
117 seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
119 seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
120 seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
121 seq_printf(m, "Capacity Transient: %d\n", info->t);
124 for (i = 1; i <= ARRAY_SIZE(info->typepct); i++) {
125 seq_printf(m, "Type %d Percentage: %d\n",
126 i, info->typepct[i - 1]);
131 static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
136 if (!MACHINE_HAS_TOPOLOGY)
138 if (stsi(info, 15, 1, topology_max_mnest))
140 seq_printf(m, "CPU Topology HW: ");
141 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
142 seq_printf(m, " %d", info->mag[i]);
144 #ifdef CONFIG_SCHED_TOPOLOGY
145 store_topology(info);
146 seq_printf(m, "CPU Topology SW: ");
147 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
148 seq_printf(m, " %d", info->mag[i]);
153 static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
155 struct sysinfo_1_2_2_extension *ext;
158 if (stsi(info, 1, 2, 2))
160 ext = (struct sysinfo_1_2_2_extension *)
161 ((unsigned long) info + info->acc_offset);
162 seq_printf(m, "CPUs Total: %d\n", info->cpus_total);
163 seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured);
164 seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby);
165 seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved);
166 if (info->mt_installed) {
167 seq_printf(m, "CPUs G-MTID: %d\n", info->mt_gtid);
168 seq_printf(m, "CPUs S-MTID: %d\n", info->mt_stid);
171 * Sigh 2. According to the specification the alternate
172 * capability field is a 32 bit floating point number
173 * if the higher order 8 bits are not zero. Printing
174 * a floating point number in the kernel is a no-no,
175 * always print the number as 32 bit unsigned integer.
176 * The user-space needs to know about the strange
177 * encoding of the alternate cpu capability.
179 seq_printf(m, "Capability: %u", info->capability);
180 if (info->format == 1)
181 seq_printf(m, " %u", ext->alt_capability);
183 if (info->nominal_cap)
184 seq_printf(m, "Nominal Capability: %d\n", info->nominal_cap);
185 if (info->secondary_cap)
186 seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap);
187 for (i = 2; i <= info->cpus_total; i++) {
188 seq_printf(m, "Adjustment %02d-way: %u",
189 i, info->adjustment[i-2]);
190 if (info->format == 1)
191 seq_printf(m, " %u", ext->alt_adjustment[i-2]);
196 static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
198 if (stsi(info, 2, 2, 2))
200 EBCASC(info->name, sizeof(info->name));
202 seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
203 seq_printf(m, "LPAR Characteristics: ");
204 if (info->characteristics & LPAR_CHAR_DEDICATED)
205 seq_printf(m, "Dedicated ");
206 if (info->characteristics & LPAR_CHAR_SHARED)
207 seq_printf(m, "Shared ");
208 if (info->characteristics & LPAR_CHAR_LIMITED)
209 seq_printf(m, "Limited ");
211 seq_printf(m, "LPAR Name: %-8.8s\n", info->name);
212 seq_printf(m, "LPAR Adjustment: %d\n", info->caf);
213 seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total);
214 seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
215 seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby);
216 seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved);
217 seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated);
218 seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared);
219 if (info->mt_installed) {
220 seq_printf(m, "LPAR CPUs G-MTID: %d\n", info->mt_gtid);
221 seq_printf(m, "LPAR CPUs S-MTID: %d\n", info->mt_stid);
222 seq_printf(m, "LPAR CPUs PS-MTID: %d\n", info->mt_psmtid);
224 if (convert_ext_name(info->vsne, info->ext_name, sizeof(info->ext_name))) {
225 seq_printf(m, "LPAR Extended Name: %-.256s\n", info->ext_name);
226 seq_printf(m, "LPAR UUID: %pUb\n", &info->uuid);
230 static void print_ext_name(struct seq_file *m, int lvl,
231 struct sysinfo_3_2_2 *info)
233 size_t len = sizeof(info->ext_names[lvl]);
235 if (!convert_ext_name(info->vm[lvl].evmne, info->ext_names[lvl], len))
237 seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl,
238 info->ext_names[lvl]);
241 static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
243 if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
245 seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid);
248 static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
252 if (stsi(info, 3, 2, 2))
254 for (i = 0; i < info->count; i++) {
255 EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
256 EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
258 seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name);
259 seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
260 seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf);
261 seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total);
262 seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
263 seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby);
264 seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved);
265 print_ext_name(m, i, info);
266 print_uuid(m, i, info);
270 static int sysinfo_show(struct seq_file *m, void *v)
272 void *info = (void *)get_zeroed_page(GFP_KERNEL);
277 level = stsi(NULL, 0, 0, 0);
281 stsi_15_1_x(m, info);
288 free_page((unsigned long)info);
292 static int sysinfo_open(struct inode *inode, struct file *file)
294 return single_open(file, sysinfo_show, NULL);
297 static const struct file_operations sysinfo_fops = {
298 .open = sysinfo_open,
301 .release = single_release,
304 static int __init sysinfo_create_proc(void)
306 proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
309 device_initcall(sysinfo_create_proc);
312 * Service levels interface.
315 static DECLARE_RWSEM(service_level_sem);
316 static LIST_HEAD(service_level_list);
318 int register_service_level(struct service_level *slr)
320 struct service_level *ptr;
322 down_write(&service_level_sem);
323 list_for_each_entry(ptr, &service_level_list, list)
325 up_write(&service_level_sem);
328 list_add_tail(&slr->list, &service_level_list);
329 up_write(&service_level_sem);
332 EXPORT_SYMBOL(register_service_level);
334 int unregister_service_level(struct service_level *slr)
336 struct service_level *ptr, *next;
339 down_write(&service_level_sem);
340 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
343 list_del(&ptr->list);
347 up_write(&service_level_sem);
350 EXPORT_SYMBOL(unregister_service_level);
352 static void *service_level_start(struct seq_file *m, loff_t *pos)
354 down_read(&service_level_sem);
355 return seq_list_start(&service_level_list, *pos);
358 static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
360 return seq_list_next(p, &service_level_list, pos);
363 static void service_level_stop(struct seq_file *m, void *p)
365 up_read(&service_level_sem);
368 static int service_level_show(struct seq_file *m, void *p)
370 struct service_level *slr;
372 slr = list_entry(p, struct service_level, list);
373 slr->seq_print(m, slr);
377 static const struct seq_operations service_level_seq_ops = {
378 .start = service_level_start,
379 .next = service_level_next,
380 .stop = service_level_stop,
381 .show = service_level_show
384 static int service_level_open(struct inode *inode, struct file *file)
386 return seq_open(file, &service_level_seq_ops);
389 static const struct file_operations service_level_ops = {
390 .open = service_level_open,
393 .release = seq_release
396 static void service_level_vm_print(struct seq_file *m,
397 struct service_level *slr)
399 char *query_buffer, *str;
401 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
404 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
405 str = strchr(query_buffer, '\n');
408 seq_printf(m, "VM: %s\n", query_buffer);
412 static struct service_level service_level_vm = {
413 .seq_print = service_level_vm_print
416 static __init int create_proc_service_level(void)
418 proc_create("service_levels", 0, NULL, &service_level_ops);
420 register_service_level(&service_level_vm);
423 subsys_initcall(create_proc_service_level);
426 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
428 void s390_adjust_jiffies(void)
430 struct sysinfo_1_2_2 *info;
431 unsigned long capability;
432 struct kernel_fpu fpu;
434 info = (void *) get_zeroed_page(GFP_KERNEL);
438 if (stsi(info, 1, 2, 2) == 0) {
440 * Major sigh. The cpu capability encoding is "special".
441 * If the first 9 bits of info->capability are 0 then it
442 * is a 32 bit unsigned integer in the range 0 .. 2^23.
443 * If the first 9 bits are != 0 then it is a 32 bit float.
444 * In addition a lower value indicates a proportionally
445 * higher cpu capacity. Bogomips are the other way round.
446 * To get to a halfway suitable number we divide 1e7
447 * by the cpu capability number. Yes, that means a floating
450 kernel_fpu_begin(&fpu, KERNEL_FPR);
463 : "Q" (info->capability), "d" (10000000), "d" (0)
466 kernel_fpu_end(&fpu, KERNEL_FPR);
469 * Really old machine without stsi block for basic
470 * cpu information. Report 42.0 bogomips.
473 loops_per_jiffy = capability * (500000/HZ);
474 free_page((unsigned long) info);
478 * calibrate the delay loop
480 void calibrate_delay(void)
482 s390_adjust_jiffies();
483 /* Print the good old Bogomips line .. */
484 printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
485 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
486 (loops_per_jiffy/(5000/HZ)) % 100);