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>
20 /* Sigh, math-emu. Don't ask. */
21 #include <asm/sfp-util.h>
22 #include <math-emu/soft-fp.h>
23 #include <math-emu/single.h>
25 int topology_max_mnest
;
28 * stsi - store system information
30 * Returns the current configuration level if function code 0 was specified.
31 * Otherwise returns 0 on success or a negative value on error.
33 int stsi(void *sysinfo
, int fc
, int sel1
, int sel2
)
35 register int r0
asm("0") = (fc
<< 28) | sel1
;
36 register int r1
asm("1") = sel2
;
45 : "+d" (r0
), "+d" (rc
)
46 : "d" (r1
), "a" (sysinfo
), "K" (-EOPNOTSUPP
)
50 return fc
? 0 : ((unsigned int) r0
) >> 28;
54 static void stsi_1_1_1(struct seq_file
*m
, struct sysinfo_1_1_1
*info
)
58 if (stsi(info
, 1, 1, 1))
60 EBCASC(info
->manufacturer
, sizeof(info
->manufacturer
));
61 EBCASC(info
->type
, sizeof(info
->type
));
62 EBCASC(info
->model
, sizeof(info
->model
));
63 EBCASC(info
->sequence
, sizeof(info
->sequence
));
64 EBCASC(info
->plant
, sizeof(info
->plant
));
65 EBCASC(info
->model_capacity
, sizeof(info
->model_capacity
));
66 EBCASC(info
->model_perm_cap
, sizeof(info
->model_perm_cap
));
67 EBCASC(info
->model_temp_cap
, sizeof(info
->model_temp_cap
));
68 seq_printf(m
, "Manufacturer: %-16.16s\n", info
->manufacturer
);
69 seq_printf(m
, "Type: %-4.4s\n", info
->type
);
71 * Sigh: the model field has been renamed with System z9
72 * to model_capacity and a new model field has been added
73 * after the plant field. To avoid confusing older programs
74 * the "Model:" prints "model_capacity model" or just
75 * "model_capacity" if the model string is empty .
77 seq_printf(m
, "Model: %-16.16s", info
->model_capacity
);
78 if (info
->model
[0] != '\0')
79 seq_printf(m
, " %-16.16s", info
->model
);
81 seq_printf(m
, "Sequence Code: %-16.16s\n", info
->sequence
);
82 seq_printf(m
, "Plant: %-4.4s\n", info
->plant
);
83 seq_printf(m
, "Model Capacity: %-16.16s %08u\n",
84 info
->model_capacity
, info
->model_cap_rating
);
85 if (info
->model_perm_cap_rating
)
86 seq_printf(m
, "Model Perm. Capacity: %-16.16s %08u\n",
88 info
->model_perm_cap_rating
);
89 if (info
->model_temp_cap_rating
)
90 seq_printf(m
, "Model Temp. Capacity: %-16.16s %08u\n",
92 info
->model_temp_cap_rating
);
94 seq_printf(m
, "Nominal Cap. Rating: %08u\n", info
->ncr
);
96 seq_printf(m
, "Nominal Perm. Rating: %08u\n", info
->npr
);
98 seq_printf(m
, "Nominal Temp. Rating: %08u\n", info
->ntr
);
100 seq_printf(m
, "Capacity Adj. Ind.: %d\n", info
->cai
);
101 seq_printf(m
, "Capacity Ch. Reason: %d\n", info
->ccr
);
102 seq_printf(m
, "Capacity Transient: %d\n", info
->t
);
105 for (i
= 1; i
<= ARRAY_SIZE(info
->typepct
); i
++) {
106 seq_printf(m
, "Type %d Percentage: %d\n",
107 i
, info
->typepct
[i
- 1]);
112 static void stsi_15_1_x(struct seq_file
*m
, struct sysinfo_15_1_x
*info
)
114 static int max_mnest
;
118 if (!MACHINE_HAS_TOPOLOGY
)
120 if (stsi(info
, 15, 1, topology_max_mnest
))
122 seq_printf(m
, "CPU Topology HW: ");
123 for (i
= 0; i
< TOPOLOGY_NR_MAG
; i
++)
124 seq_printf(m
, " %d", info
->mag
[i
]);
126 #ifdef CONFIG_SCHED_MC
127 store_topology(info
);
128 seq_printf(m
, "CPU Topology SW: ");
129 for (i
= 0; i
< TOPOLOGY_NR_MAG
; i
++)
130 seq_printf(m
, " %d", info
->mag
[i
]);
135 static void stsi_1_2_2(struct seq_file
*m
, struct sysinfo_1_2_2
*info
)
137 struct sysinfo_1_2_2_extension
*ext
;
140 if (stsi(info
, 1, 2, 2))
142 ext
= (struct sysinfo_1_2_2_extension
*)
143 ((unsigned long) info
+ info
->acc_offset
);
144 seq_printf(m
, "CPUs Total: %d\n", info
->cpus_total
);
145 seq_printf(m
, "CPUs Configured: %d\n", info
->cpus_configured
);
146 seq_printf(m
, "CPUs Standby: %d\n", info
->cpus_standby
);
147 seq_printf(m
, "CPUs Reserved: %d\n", info
->cpus_reserved
);
149 * Sigh 2. According to the specification the alternate
150 * capability field is a 32 bit floating point number
151 * if the higher order 8 bits are not zero. Printing
152 * a floating point number in the kernel is a no-no,
153 * always print the number as 32 bit unsigned integer.
154 * The user-space needs to know about the strange
155 * encoding of the alternate cpu capability.
157 seq_printf(m
, "Capability: %u", info
->capability
);
158 if (info
->format
== 1)
159 seq_printf(m
, " %u", ext
->alt_capability
);
161 if (info
->nominal_cap
)
162 seq_printf(m
, "Nominal Capability: %d\n", info
->nominal_cap
);
163 if (info
->secondary_cap
)
164 seq_printf(m
, "Secondary Capability: %d\n", info
->secondary_cap
);
165 for (i
= 2; i
<= info
->cpus_total
; i
++) {
166 seq_printf(m
, "Adjustment %02d-way: %u",
167 i
, info
->adjustment
[i
-2]);
168 if (info
->format
== 1)
169 seq_printf(m
, " %u", ext
->alt_adjustment
[i
-2]);
174 static void stsi_2_2_2(struct seq_file
*m
, struct sysinfo_2_2_2
*info
)
176 if (stsi(info
, 2, 2, 2))
178 EBCASC(info
->name
, sizeof(info
->name
));
180 seq_printf(m
, "LPAR Number: %d\n", info
->lpar_number
);
181 seq_printf(m
, "LPAR Characteristics: ");
182 if (info
->characteristics
& LPAR_CHAR_DEDICATED
)
183 seq_printf(m
, "Dedicated ");
184 if (info
->characteristics
& LPAR_CHAR_SHARED
)
185 seq_printf(m
, "Shared ");
186 if (info
->characteristics
& LPAR_CHAR_LIMITED
)
187 seq_printf(m
, "Limited ");
189 seq_printf(m
, "LPAR Name: %-8.8s\n", info
->name
);
190 seq_printf(m
, "LPAR Adjustment: %d\n", info
->caf
);
191 seq_printf(m
, "LPAR CPUs Total: %d\n", info
->cpus_total
);
192 seq_printf(m
, "LPAR CPUs Configured: %d\n", info
->cpus_configured
);
193 seq_printf(m
, "LPAR CPUs Standby: %d\n", info
->cpus_standby
);
194 seq_printf(m
, "LPAR CPUs Reserved: %d\n", info
->cpus_reserved
);
195 seq_printf(m
, "LPAR CPUs Dedicated: %d\n", info
->cpus_dedicated
);
196 seq_printf(m
, "LPAR CPUs Shared: %d\n", info
->cpus_shared
);
199 static void print_ext_name(struct seq_file
*m
, int lvl
,
200 struct sysinfo_3_2_2
*info
)
202 if (info
->vm
[lvl
].ext_name_encoding
== 0)
204 if (info
->ext_names
[lvl
][0] == 0)
206 switch (info
->vm
[lvl
].ext_name_encoding
) {
208 EBCASC(info
->ext_names
[lvl
], sizeof(info
->ext_names
[lvl
]));
215 seq_printf(m
, "VM%02d Extended Name: %-.256s\n", lvl
,
216 info
->ext_names
[lvl
]);
219 static void print_uuid(struct seq_file
*m
, int i
, struct sysinfo_3_2_2
*info
)
221 if (!memcmp(&info
->vm
[i
].uuid
, &NULL_UUID_BE
, sizeof(uuid_be
)))
223 seq_printf(m
, "VM%02d UUID: %pUb\n", i
, &info
->vm
[i
].uuid
);
226 static void stsi_3_2_2(struct seq_file
*m
, struct sysinfo_3_2_2
*info
)
230 if (stsi(info
, 3, 2, 2))
232 for (i
= 0; i
< info
->count
; i
++) {
233 EBCASC(info
->vm
[i
].name
, sizeof(info
->vm
[i
].name
));
234 EBCASC(info
->vm
[i
].cpi
, sizeof(info
->vm
[i
].cpi
));
236 seq_printf(m
, "VM%02d Name: %-8.8s\n", i
, info
->vm
[i
].name
);
237 seq_printf(m
, "VM%02d Control Program: %-16.16s\n", i
, info
->vm
[i
].cpi
);
238 seq_printf(m
, "VM%02d Adjustment: %d\n", i
, info
->vm
[i
].caf
);
239 seq_printf(m
, "VM%02d CPUs Total: %d\n", i
, info
->vm
[i
].cpus_total
);
240 seq_printf(m
, "VM%02d CPUs Configured: %d\n", i
, info
->vm
[i
].cpus_configured
);
241 seq_printf(m
, "VM%02d CPUs Standby: %d\n", i
, info
->vm
[i
].cpus_standby
);
242 seq_printf(m
, "VM%02d CPUs Reserved: %d\n", i
, info
->vm
[i
].cpus_reserved
);
243 print_ext_name(m
, i
, info
);
244 print_uuid(m
, i
, info
);
248 static int sysinfo_show(struct seq_file
*m
, void *v
)
250 void *info
= (void *)get_zeroed_page(GFP_KERNEL
);
255 level
= stsi(NULL
, 0, 0, 0);
259 stsi_15_1_x(m
, info
);
266 free_page((unsigned long)info
);
270 static int sysinfo_open(struct inode
*inode
, struct file
*file
)
272 return single_open(file
, sysinfo_show
, NULL
);
275 static const struct file_operations sysinfo_fops
= {
276 .open
= sysinfo_open
,
279 .release
= single_release
,
282 static int __init
sysinfo_create_proc(void)
284 proc_create("sysinfo", 0444, NULL
, &sysinfo_fops
);
287 device_initcall(sysinfo_create_proc
);
290 * Service levels interface.
293 static DECLARE_RWSEM(service_level_sem
);
294 static LIST_HEAD(service_level_list
);
296 int register_service_level(struct service_level
*slr
)
298 struct service_level
*ptr
;
300 down_write(&service_level_sem
);
301 list_for_each_entry(ptr
, &service_level_list
, list
)
303 up_write(&service_level_sem
);
306 list_add_tail(&slr
->list
, &service_level_list
);
307 up_write(&service_level_sem
);
310 EXPORT_SYMBOL(register_service_level
);
312 int unregister_service_level(struct service_level
*slr
)
314 struct service_level
*ptr
, *next
;
317 down_write(&service_level_sem
);
318 list_for_each_entry_safe(ptr
, next
, &service_level_list
, list
) {
321 list_del(&ptr
->list
);
325 up_write(&service_level_sem
);
328 EXPORT_SYMBOL(unregister_service_level
);
330 static void *service_level_start(struct seq_file
*m
, loff_t
*pos
)
332 down_read(&service_level_sem
);
333 return seq_list_start(&service_level_list
, *pos
);
336 static void *service_level_next(struct seq_file
*m
, void *p
, loff_t
*pos
)
338 return seq_list_next(p
, &service_level_list
, pos
);
341 static void service_level_stop(struct seq_file
*m
, void *p
)
343 up_read(&service_level_sem
);
346 static int service_level_show(struct seq_file
*m
, void *p
)
348 struct service_level
*slr
;
350 slr
= list_entry(p
, struct service_level
, list
);
351 slr
->seq_print(m
, slr
);
355 static const struct seq_operations service_level_seq_ops
= {
356 .start
= service_level_start
,
357 .next
= service_level_next
,
358 .stop
= service_level_stop
,
359 .show
= service_level_show
362 static int service_level_open(struct inode
*inode
, struct file
*file
)
364 return seq_open(file
, &service_level_seq_ops
);
367 static const struct file_operations service_level_ops
= {
368 .open
= service_level_open
,
371 .release
= seq_release
374 static void service_level_vm_print(struct seq_file
*m
,
375 struct service_level
*slr
)
377 char *query_buffer
, *str
;
379 query_buffer
= kmalloc(1024, GFP_KERNEL
| GFP_DMA
);
382 cpcmd("QUERY CPLEVEL", query_buffer
, 1024, NULL
);
383 str
= strchr(query_buffer
, '\n');
386 seq_printf(m
, "VM: %s\n", query_buffer
);
390 static struct service_level service_level_vm
= {
391 .seq_print
= service_level_vm_print
394 static __init
int create_proc_service_level(void)
396 proc_create("service_levels", 0, NULL
, &service_level_ops
);
398 register_service_level(&service_level_vm
);
401 subsys_initcall(create_proc_service_level
);
404 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
406 void s390_adjust_jiffies(void)
408 struct sysinfo_1_2_2
*info
;
409 const unsigned int fmil
= 0x4b189680; /* 1e7 as 32-bit float. */
410 FP_DECL_S(SA
); FP_DECL_S(SB
); FP_DECL_S(SR
);
412 unsigned int capability
;
414 info
= (void *) get_zeroed_page(GFP_KERNEL
);
418 if (stsi(info
, 1, 2, 2) == 0) {
420 * Major sigh. The cpu capability encoding is "special".
421 * If the first 9 bits of info->capability are 0 then it
422 * is a 32 bit unsigned integer in the range 0 .. 2^23.
423 * If the first 9 bits are != 0 then it is a 32 bit float.
424 * In addition a lower value indicates a proportionally
425 * higher cpu capacity. Bogomips are the other way round.
426 * To get to a halfway suitable number we divide 1e7
427 * by the cpu capability number. Yes, that means a floating
428 * point division .. math-emu here we come :-)
430 FP_UNPACK_SP(SA
, &fmil
);
431 if ((info
->capability
>> 23) == 0)
432 FP_FROM_INT_S(SB
, (long) info
->capability
, 64, long);
434 FP_UNPACK_SP(SB
, &info
->capability
);
435 FP_DIV_S(SR
, SA
, SB
);
436 FP_TO_INT_S(capability
, SR
, 32, 0);
439 * Really old machine without stsi block for basic
440 * cpu information. Report 42.0 bogomips.
443 loops_per_jiffy
= capability
* (500000/HZ
);
444 free_page((unsigned long) info
);
448 * calibrate the delay loop
450 void calibrate_delay(void)
452 s390_adjust_jiffies();
453 /* Print the good old Bogomips line .. */
454 printk(KERN_DEBUG
"Calibrating delay loop (skipped)... "
455 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy
/(500000/HZ
),
456 (loops_per_jiffy
/(5000/HZ
)) % 100);