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 <asm/ebcdic.h>
15 #include <asm/sysinfo.h>
16 #include <asm/cpcmd.h>
18 /* Sigh, math-emu. Don't ask. */
19 #include <asm/sfp-util.h>
20 #include <math-emu/soft-fp.h>
21 #include <math-emu/single.h>
23 static inline int stsi_0(void)
25 int rc
= stsi(NULL
, 0, 0, 0);
26 return rc
== -ENOSYS
? rc
: (((unsigned int) rc
) >> 28);
29 static int stsi_1_1_1(struct sysinfo_1_1_1
*info
, char *page
, int len
)
31 if (stsi(info
, 1, 1, 1) == -ENOSYS
)
34 EBCASC(info
->manufacturer
, sizeof(info
->manufacturer
));
35 EBCASC(info
->type
, sizeof(info
->type
));
36 EBCASC(info
->model
, sizeof(info
->model
));
37 EBCASC(info
->sequence
, sizeof(info
->sequence
));
38 EBCASC(info
->plant
, sizeof(info
->plant
));
39 EBCASC(info
->model_capacity
, sizeof(info
->model_capacity
));
40 EBCASC(info
->model_perm_cap
, sizeof(info
->model_perm_cap
));
41 EBCASC(info
->model_temp_cap
, sizeof(info
->model_temp_cap
));
42 len
+= sprintf(page
+ len
, "Manufacturer: %-16.16s\n",
44 len
+= sprintf(page
+ len
, "Type: %-4.4s\n",
46 if (info
->model
[0] != '\0')
48 * Sigh: the model field has been renamed with System z9
49 * to model_capacity and a new model field has been added
50 * after the plant field. To avoid confusing older programs
51 * the "Model:" prints "model_capacity model" or just
52 * "model_capacity" if the model string is empty .
54 len
+= sprintf(page
+ len
,
55 "Model: %-16.16s %-16.16s\n",
56 info
->model_capacity
, info
->model
);
58 len
+= sprintf(page
+ len
, "Model: %-16.16s\n",
59 info
->model_capacity
);
60 len
+= sprintf(page
+ len
, "Sequence Code: %-16.16s\n",
62 len
+= sprintf(page
+ len
, "Plant: %-4.4s\n",
64 len
+= sprintf(page
+ len
, "Model Capacity: %-16.16s %08u\n",
65 info
->model_capacity
, *(u32
*) info
->model_cap_rating
);
66 if (info
->model_perm_cap
[0] != '\0')
67 len
+= sprintf(page
+ len
,
68 "Model Perm. Capacity: %-16.16s %08u\n",
70 *(u32
*) info
->model_perm_cap_rating
);
71 if (info
->model_temp_cap
[0] != '\0')
72 len
+= sprintf(page
+ len
,
73 "Model Temp. Capacity: %-16.16s %08u\n",
75 *(u32
*) info
->model_temp_cap_rating
);
79 static int stsi_1_2_2(struct sysinfo_1_2_2
*info
, char *page
, int len
)
81 struct sysinfo_1_2_2_extension
*ext
;
84 if (stsi(info
, 1, 2, 2) == -ENOSYS
)
86 ext
= (struct sysinfo_1_2_2_extension
*)
87 ((unsigned long) info
+ info
->acc_offset
);
89 len
+= sprintf(page
+ len
, "\n");
90 len
+= sprintf(page
+ len
, "CPUs Total: %d\n",
92 len
+= sprintf(page
+ len
, "CPUs Configured: %d\n",
93 info
->cpus_configured
);
94 len
+= sprintf(page
+ len
, "CPUs Standby: %d\n",
96 len
+= sprintf(page
+ len
, "CPUs Reserved: %d\n",
99 if (info
->format
== 1) {
101 * Sigh 2. According to the specification the alternate
102 * capability field is a 32 bit floating point number
103 * if the higher order 8 bits are not zero. Printing
104 * a floating point number in the kernel is a no-no,
105 * always print the number as 32 bit unsigned integer.
106 * The user-space needs to know about the strange
107 * encoding of the alternate cpu capability.
109 len
+= sprintf(page
+ len
, "Capability: %u %u\n",
110 info
->capability
, ext
->alt_capability
);
111 for (i
= 2; i
<= info
->cpus_total
; i
++)
112 len
+= sprintf(page
+ len
,
113 "Adjustment %02d-way: %u %u\n",
114 i
, info
->adjustment
[i
-2],
115 ext
->alt_adjustment
[i
-2]);
118 len
+= sprintf(page
+ len
, "Capability: %u\n",
120 for (i
= 2; i
<= info
->cpus_total
; i
++)
121 len
+= sprintf(page
+ len
,
122 "Adjustment %02d-way: %u\n",
123 i
, info
->adjustment
[i
-2]);
126 if (info
->secondary_capability
!= 0)
127 len
+= sprintf(page
+ len
, "Secondary Capability: %d\n",
128 info
->secondary_capability
);
132 static int stsi_2_2_2(struct sysinfo_2_2_2
*info
, char *page
, int len
)
134 if (stsi(info
, 2, 2, 2) == -ENOSYS
)
137 EBCASC(info
->name
, sizeof(info
->name
));
139 len
+= sprintf(page
+ len
, "\n");
140 len
+= sprintf(page
+ len
, "LPAR Number: %d\n",
143 len
+= sprintf(page
+ len
, "LPAR Characteristics: ");
144 if (info
->characteristics
& LPAR_CHAR_DEDICATED
)
145 len
+= sprintf(page
+ len
, "Dedicated ");
146 if (info
->characteristics
& LPAR_CHAR_SHARED
)
147 len
+= sprintf(page
+ len
, "Shared ");
148 if (info
->characteristics
& LPAR_CHAR_LIMITED
)
149 len
+= sprintf(page
+ len
, "Limited ");
150 len
+= sprintf(page
+ len
, "\n");
152 len
+= sprintf(page
+ len
, "LPAR Name: %-8.8s\n",
155 len
+= sprintf(page
+ len
, "LPAR Adjustment: %d\n",
158 len
+= sprintf(page
+ len
, "LPAR CPUs Total: %d\n",
160 len
+= sprintf(page
+ len
, "LPAR CPUs Configured: %d\n",
161 info
->cpus_configured
);
162 len
+= sprintf(page
+ len
, "LPAR CPUs Standby: %d\n",
164 len
+= sprintf(page
+ len
, "LPAR CPUs Reserved: %d\n",
165 info
->cpus_reserved
);
166 len
+= sprintf(page
+ len
, "LPAR CPUs Dedicated: %d\n",
167 info
->cpus_dedicated
);
168 len
+= sprintf(page
+ len
, "LPAR CPUs Shared: %d\n",
173 static int stsi_3_2_2(struct sysinfo_3_2_2
*info
, char *page
, int len
)
177 if (stsi(info
, 3, 2, 2) == -ENOSYS
)
179 for (i
= 0; i
< info
->count
; i
++) {
180 EBCASC(info
->vm
[i
].name
, sizeof(info
->vm
[i
].name
));
181 EBCASC(info
->vm
[i
].cpi
, sizeof(info
->vm
[i
].cpi
));
182 len
+= sprintf(page
+ len
, "\n");
183 len
+= sprintf(page
+ len
, "VM%02d Name: %-8.8s\n",
184 i
, info
->vm
[i
].name
);
185 len
+= sprintf(page
+ len
, "VM%02d Control Program: %-16.16s\n",
188 len
+= sprintf(page
+ len
, "VM%02d Adjustment: %d\n",
191 len
+= sprintf(page
+ len
, "VM%02d CPUs Total: %d\n",
192 i
, info
->vm
[i
].cpus_total
);
193 len
+= sprintf(page
+ len
, "VM%02d CPUs Configured: %d\n",
194 i
, info
->vm
[i
].cpus_configured
);
195 len
+= sprintf(page
+ len
, "VM%02d CPUs Standby: %d\n",
196 i
, info
->vm
[i
].cpus_standby
);
197 len
+= sprintf(page
+ len
, "VM%02d CPUs Reserved: %d\n",
198 i
, info
->vm
[i
].cpus_reserved
);
203 static int proc_read_sysinfo(char *page
, char **start
,
204 off_t off
, int count
,
205 int *eof
, void *data
)
207 unsigned long info
= get_zeroed_page(GFP_KERNEL
);
216 len
= stsi_1_1_1((struct sysinfo_1_1_1
*) info
, page
, len
);
219 len
= stsi_1_2_2((struct sysinfo_1_2_2
*) info
, page
, len
);
222 len
= stsi_2_2_2((struct sysinfo_2_2_2
*) info
, page
, len
);
225 len
= stsi_3_2_2((struct sysinfo_3_2_2
*) info
, page
, len
);
231 static __init
int create_proc_sysinfo(void)
233 create_proc_read_entry("sysinfo", 0444, NULL
,
234 proc_read_sysinfo
, NULL
);
237 device_initcall(create_proc_sysinfo
);
240 * Service levels interface.
243 static DECLARE_RWSEM(service_level_sem
);
244 static LIST_HEAD(service_level_list
);
246 int register_service_level(struct service_level
*slr
)
248 struct service_level
*ptr
;
250 down_write(&service_level_sem
);
251 list_for_each_entry(ptr
, &service_level_list
, list
)
253 up_write(&service_level_sem
);
256 list_add_tail(&slr
->list
, &service_level_list
);
257 up_write(&service_level_sem
);
260 EXPORT_SYMBOL(register_service_level
);
262 int unregister_service_level(struct service_level
*slr
)
264 struct service_level
*ptr
, *next
;
267 down_write(&service_level_sem
);
268 list_for_each_entry_safe(ptr
, next
, &service_level_list
, list
) {
271 list_del(&ptr
->list
);
275 up_write(&service_level_sem
);
278 EXPORT_SYMBOL(unregister_service_level
);
280 static void *service_level_start(struct seq_file
*m
, loff_t
*pos
)
282 down_read(&service_level_sem
);
283 return seq_list_start(&service_level_list
, *pos
);
286 static void *service_level_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
288 return seq_list_next(p
, &service_level_list
, pos
);
291 static void service_level_stop(struct seq_file
*m
, void *p
)
293 up_read(&service_level_sem
);
296 static int service_level_show(struct seq_file
*m
, void *p
)
298 struct service_level
*slr
;
300 slr
= list_entry(p
, struct service_level
, list
);
301 slr
->seq_print(m
, slr
);
305 static const struct seq_operations service_level_seq_ops
= {
306 .start
= service_level_start
,
307 .next
= service_level_next
,
308 .stop
= service_level_stop
,
309 .show
= service_level_show
312 static int service_level_open(struct inode
*inode
, struct file
*file
)
314 return seq_open(file
, &service_level_seq_ops
);
317 static const struct file_operations service_level_ops
= {
318 .open
= service_level_open
,
321 .release
= seq_release
324 static void service_level_vm_print(struct seq_file
*m
,
325 struct service_level
*slr
)
327 char *query_buffer
, *str
;
329 query_buffer
= kmalloc(1024, GFP_KERNEL
| GFP_DMA
);
332 cpcmd("QUERY CPLEVEL", query_buffer
, 1024, NULL
);
333 str
= strchr(query_buffer
, '\n');
336 seq_printf(m
, "VM: %s\n", query_buffer
);
340 static struct service_level service_level_vm
= {
341 .seq_print
= service_level_vm_print
344 static __init
int create_proc_service_level(void)
346 proc_create("service_levels", 0, NULL
, &service_level_ops
);
348 register_service_level(&service_level_vm
);
351 subsys_initcall(create_proc_service_level
);
354 * Bogomips calculation based on cpu capability.
356 int get_cpu_capability(unsigned int *capability
)
358 struct sysinfo_1_2_2
*info
;
361 info
= (void *) get_zeroed_page(GFP_KERNEL
);
364 rc
= stsi(info
, 1, 2, 2);
368 *capability
= info
->capability
;
370 free_page((unsigned long) info
);
375 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
377 void s390_adjust_jiffies(void)
379 struct sysinfo_1_2_2
*info
;
380 const unsigned int fmil
= 0x4b189680; /* 1e7 as 32-bit float. */
381 FP_DECL_S(SA
); FP_DECL_S(SB
); FP_DECL_S(SR
);
383 unsigned int capability
;
385 info
= (void *) get_zeroed_page(GFP_KERNEL
);
389 if (stsi(info
, 1, 2, 2) != -ENOSYS
) {
391 * Major sigh. The cpu capability encoding is "special".
392 * If the first 9 bits of info->capability are 0 then it
393 * is a 32 bit unsigned integer in the range 0 .. 2^23.
394 * If the first 9 bits are != 0 then it is a 32 bit float.
395 * In addition a lower value indicates a proportionally
396 * higher cpu capacity. Bogomips are the other way round.
397 * To get to a halfway suitable number we divide 1e7
398 * by the cpu capability number. Yes, that means a floating
399 * point division .. math-emu here we come :-)
401 FP_UNPACK_SP(SA
, &fmil
);
402 if ((info
->capability
>> 23) == 0)
403 FP_FROM_INT_S(SB
, info
->capability
, 32, int);
405 FP_UNPACK_SP(SB
, &info
->capability
);
406 FP_DIV_S(SR
, SA
, SB
);
407 FP_TO_INT_S(capability
, SR
, 32, 0);
410 * Really old machine without stsi block for basic
411 * cpu information. Report 42.0 bogomips.
414 loops_per_jiffy
= capability
* (500000/HZ
);
415 free_page((unsigned long) info
);
419 * calibrate the delay loop
421 void __cpuinit
calibrate_delay(void)
423 s390_adjust_jiffies();
424 /* Print the good old Bogomips line .. */
425 printk(KERN_DEBUG
"Calibrating delay loop (skipped)... "
426 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy
/(500000/HZ
),
427 (loops_per_jiffy
/(5000/HZ
)) % 100);