Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
94f5b09d HC |
2 | * Copyright IBM Corp. 2001, 2009 |
3 | * Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>, | |
4 | * Martin Schwidefsky <schwidefsky@de.ibm.com>, | |
1da177e4 LT |
5 | */ |
6 | ||
1da177e4 LT |
7 | #include <linux/kernel.h> |
8 | #include <linux/mm.h> | |
9 | #include <linux/proc_fs.h> | |
6bcac508 | 10 | #include <linux/seq_file.h> |
1da177e4 | 11 | #include <linux/init.h> |
31ee4b2f | 12 | #include <linux/delay.h> |
6bcac508 | 13 | #include <linux/module.h> |
5a0e3ad6 | 14 | #include <linux/slab.h> |
1da177e4 | 15 | #include <asm/ebcdic.h> |
aa24f7f0 | 16 | #include <asm/sysinfo.h> |
6bcac508 | 17 | #include <asm/cpcmd.h> |
96f4a70d | 18 | #include <asm/topology.h> |
1da177e4 | 19 | |
31ee4b2f MS |
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> | |
24 | ||
fade4dc4 HC |
25 | int topology_max_mnest; |
26 | ||
caf757c6 HC |
27 | /* |
28 | * stsi - store system information | |
29 | * | |
30 | * Returns the current configuration level if function code 0 was specified. | |
31 | * Otherwise returns 0 on success or a negative value on error. | |
32 | */ | |
33 | int stsi(void *sysinfo, int fc, int sel1, int sel2) | |
1da177e4 | 34 | { |
caf757c6 HC |
35 | register int r0 asm("0") = (fc << 28) | sel1; |
36 | register int r1 asm("1") = sel2; | |
37 | int rc = 0; | |
38 | ||
39 | asm volatile( | |
40 | " stsi 0(%3)\n" | |
41 | "0: jz 2f\n" | |
42 | "1: lhi %1,%4\n" | |
43 | "2:\n" | |
44 | EX_TABLE(0b, 1b) | |
45 | : "+d" (r0), "+d" (rc) | |
46 | : "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP) | |
47 | : "cc", "memory"); | |
48 | if (rc) | |
49 | return rc; | |
50 | return fc ? 0 : ((unsigned int) r0) >> 28; | |
1da177e4 | 51 | } |
caf757c6 | 52 | EXPORT_SYMBOL(stsi); |
1da177e4 | 53 | |
0facaa17 | 54 | static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info) |
1da177e4 | 55 | { |
25502f00 HC |
56 | int i; |
57 | ||
caf757c6 | 58 | if (stsi(info, 1, 1, 1)) |
0facaa17 | 59 | return; |
0fee644a MS |
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)); | |
cbce70e6 MS |
66 | EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap)); |
67 | EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap)); | |
0facaa17 HC |
68 | seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer); |
69 | seq_printf(m, "Type: %-4.4s\n", info->type); | |
70 | /* | |
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 . | |
76 | */ | |
77 | seq_printf(m, "Model: %-16.16s", info->model_capacity); | |
0fee644a | 78 | if (info->model[0] != '\0') |
0facaa17 HC |
79 | seq_printf(m, " %-16.16s", info->model); |
80 | seq_putc(m, '\n'); | |
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", | |
25502f00 HC |
84 | info->model_capacity, info->model_cap_rating); |
85 | if (info->model_perm_cap_rating) | |
0facaa17 HC |
86 | seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n", |
87 | info->model_perm_cap, | |
25502f00 HC |
88 | info->model_perm_cap_rating); |
89 | if (info->model_temp_cap_rating) | |
0facaa17 HC |
90 | seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n", |
91 | info->model_temp_cap, | |
25502f00 HC |
92 | info->model_temp_cap_rating); |
93 | if (info->ncr) | |
94 | seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr); | |
95 | if (info->npr) | |
96 | seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr); | |
97 | if (info->ntr) | |
98 | seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr); | |
7aca2eda | 99 | if (info->cai) { |
0facaa17 HC |
100 | seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai); |
101 | seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr); | |
25502f00 HC |
102 | seq_printf(m, "Capacity Transient: %d\n", info->t); |
103 | } | |
104 | if (info->p) { | |
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]); | |
108 | } | |
7aca2eda | 109 | } |
1da177e4 LT |
110 | } |
111 | ||
0facaa17 | 112 | static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info) |
96f4a70d | 113 | { |
e527aec4 | 114 | int i; |
96f4a70d | 115 | |
0facaa17 | 116 | seq_putc(m, '\n'); |
96f4a70d | 117 | if (!MACHINE_HAS_TOPOLOGY) |
0facaa17 | 118 | return; |
caf757c6 HC |
119 | if (stsi(info, 15, 1, topology_max_mnest)) |
120 | return; | |
0facaa17 | 121 | seq_printf(m, "CPU Topology HW: "); |
96f4a70d | 122 | for (i = 0; i < TOPOLOGY_NR_MAG; i++) |
0facaa17 HC |
123 | seq_printf(m, " %d", info->mag[i]); |
124 | seq_putc(m, '\n'); | |
9236b4dd | 125 | #ifdef CONFIG_SCHED_TOPOLOGY |
96f4a70d | 126 | store_topology(info); |
0facaa17 | 127 | seq_printf(m, "CPU Topology SW: "); |
96f4a70d | 128 | for (i = 0; i < TOPOLOGY_NR_MAG; i++) |
0facaa17 HC |
129 | seq_printf(m, " %d", info->mag[i]); |
130 | seq_putc(m, '\n'); | |
8d11e021 | 131 | #endif |
96f4a70d HC |
132 | } |
133 | ||
0facaa17 | 134 | static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info) |
1da177e4 | 135 | { |
0fee644a MS |
136 | struct sysinfo_1_2_2_extension *ext; |
137 | int i; | |
138 | ||
caf757c6 | 139 | if (stsi(info, 1, 2, 2)) |
0facaa17 | 140 | return; |
0fee644a MS |
141 | ext = (struct sysinfo_1_2_2_extension *) |
142 | ((unsigned long) info + info->acc_offset); | |
0facaa17 HC |
143 | seq_printf(m, "CPUs Total: %d\n", info->cpus_total); |
144 | seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured); | |
145 | seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby); | |
146 | seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved); | |
147 | /* | |
148 | * Sigh 2. According to the specification the alternate | |
149 | * capability field is a 32 bit floating point number | |
150 | * if the higher order 8 bits are not zero. Printing | |
151 | * a floating point number in the kernel is a no-no, | |
152 | * always print the number as 32 bit unsigned integer. | |
153 | * The user-space needs to know about the strange | |
154 | * encoding of the alternate cpu capability. | |
155 | */ | |
156 | seq_printf(m, "Capability: %u", info->capability); | |
157 | if (info->format == 1) | |
158 | seq_printf(m, " %u", ext->alt_capability); | |
159 | seq_putc(m, '\n'); | |
25502f00 HC |
160 | if (info->nominal_cap) |
161 | seq_printf(m, "Nominal Capability: %d\n", info->nominal_cap); | |
162 | if (info->secondary_cap) | |
163 | seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap); | |
0facaa17 HC |
164 | for (i = 2; i <= info->cpus_total; i++) { |
165 | seq_printf(m, "Adjustment %02d-way: %u", | |
166 | i, info->adjustment[i-2]); | |
167 | if (info->format == 1) | |
168 | seq_printf(m, " %u", ext->alt_adjustment[i-2]); | |
169 | seq_putc(m, '\n'); | |
0fee644a | 170 | } |
1da177e4 LT |
171 | } |
172 | ||
0facaa17 | 173 | static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info) |
1da177e4 | 174 | { |
caf757c6 | 175 | if (stsi(info, 2, 2, 2)) |
0facaa17 | 176 | return; |
94f5b09d | 177 | EBCASC(info->name, sizeof(info->name)); |
0facaa17 HC |
178 | seq_putc(m, '\n'); |
179 | seq_printf(m, "LPAR Number: %d\n", info->lpar_number); | |
180 | seq_printf(m, "LPAR Characteristics: "); | |
0fee644a | 181 | if (info->characteristics & LPAR_CHAR_DEDICATED) |
0facaa17 | 182 | seq_printf(m, "Dedicated "); |
0fee644a | 183 | if (info->characteristics & LPAR_CHAR_SHARED) |
0facaa17 | 184 | seq_printf(m, "Shared "); |
0fee644a | 185 | if (info->characteristics & LPAR_CHAR_LIMITED) |
0facaa17 HC |
186 | seq_printf(m, "Limited "); |
187 | seq_putc(m, '\n'); | |
188 | seq_printf(m, "LPAR Name: %-8.8s\n", info->name); | |
189 | seq_printf(m, "LPAR Adjustment: %d\n", info->caf); | |
190 | seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total); | |
191 | seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured); | |
192 | seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby); | |
193 | seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved); | |
194 | seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated); | |
195 | seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared); | |
10ad34bc MS |
196 | if (info->mt_installed & 0x80) { |
197 | seq_printf(m, "LPAR CPUs G-MTID: %d\n", | |
198 | info->mt_general & 0x1f); | |
199 | seq_printf(m, "LPAR CPUs S-MTID: %d\n", | |
200 | info->mt_installed & 0x1f); | |
201 | seq_printf(m, "LPAR CPUs PS-MTID: %d\n", | |
202 | info->mt_psmtid & 0x1f); | |
203 | } | |
1da177e4 LT |
204 | } |
205 | ||
f3d0bd6c ET |
206 | static void print_ext_name(struct seq_file *m, int lvl, |
207 | struct sysinfo_3_2_2 *info) | |
208 | { | |
209 | if (info->vm[lvl].ext_name_encoding == 0) | |
210 | return; | |
211 | if (info->ext_names[lvl][0] == 0) | |
212 | return; | |
213 | switch (info->vm[lvl].ext_name_encoding) { | |
214 | case 1: /* EBCDIC */ | |
215 | EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl])); | |
216 | break; | |
217 | case 2: /* UTF-8 */ | |
218 | break; | |
219 | default: | |
220 | return; | |
221 | } | |
222 | seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl, | |
223 | info->ext_names[lvl]); | |
224 | } | |
225 | ||
226 | static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info) | |
227 | { | |
228 | if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be))) | |
229 | return; | |
230 | seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid); | |
231 | } | |
232 | ||
0facaa17 | 233 | static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info) |
1da177e4 | 234 | { |
0fee644a MS |
235 | int i; |
236 | ||
caf757c6 | 237 | if (stsi(info, 3, 2, 2)) |
0facaa17 | 238 | return; |
0fee644a | 239 | for (i = 0; i < info->count; i++) { |
94f5b09d HC |
240 | EBCASC(info->vm[i].name, sizeof(info->vm[i].name)); |
241 | EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi)); | |
0facaa17 HC |
242 | seq_putc(m, '\n'); |
243 | seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name); | |
244 | seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi); | |
245 | seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf); | |
246 | seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total); | |
247 | seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured); | |
248 | seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby); | |
249 | seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved); | |
f3d0bd6c ET |
250 | print_ext_name(m, i, info); |
251 | print_uuid(m, i, info); | |
1da177e4 | 252 | } |
1da177e4 LT |
253 | } |
254 | ||
0facaa17 | 255 | static int sysinfo_show(struct seq_file *m, void *v) |
1da177e4 | 256 | { |
0facaa17 HC |
257 | void *info = (void *)get_zeroed_page(GFP_KERNEL); |
258 | int level; | |
94f5b09d | 259 | |
1da177e4 LT |
260 | if (!info) |
261 | return 0; | |
caf757c6 | 262 | level = stsi(NULL, 0, 0, 0); |
0fee644a | 263 | if (level >= 1) |
0facaa17 | 264 | stsi_1_1_1(m, info); |
0fee644a | 265 | if (level >= 1) |
0facaa17 | 266 | stsi_15_1_x(m, info); |
96f4a70d | 267 | if (level >= 1) |
0facaa17 | 268 | stsi_1_2_2(m, info); |
0fee644a | 269 | if (level >= 2) |
0facaa17 | 270 | stsi_2_2_2(m, info); |
0fee644a | 271 | if (level >= 3) |
0facaa17 HC |
272 | stsi_3_2_2(m, info); |
273 | free_page((unsigned long)info); | |
274 | return 0; | |
275 | } | |
1da177e4 | 276 | |
0facaa17 HC |
277 | static int sysinfo_open(struct inode *inode, struct file *file) |
278 | { | |
279 | return single_open(file, sysinfo_show, NULL); | |
1da177e4 LT |
280 | } |
281 | ||
0facaa17 HC |
282 | static const struct file_operations sysinfo_fops = { |
283 | .open = sysinfo_open, | |
284 | .read = seq_read, | |
285 | .llseek = seq_lseek, | |
286 | .release = single_release, | |
287 | }; | |
288 | ||
289 | static int __init sysinfo_create_proc(void) | |
1da177e4 | 290 | { |
0facaa17 | 291 | proc_create("sysinfo", 0444, NULL, &sysinfo_fops); |
1da177e4 LT |
292 | return 0; |
293 | } | |
0facaa17 | 294 | device_initcall(sysinfo_create_proc); |
1da177e4 | 295 | |
6bcac508 MS |
296 | /* |
297 | * Service levels interface. | |
298 | */ | |
299 | ||
300 | static DECLARE_RWSEM(service_level_sem); | |
301 | static LIST_HEAD(service_level_list); | |
302 | ||
303 | int register_service_level(struct service_level *slr) | |
304 | { | |
305 | struct service_level *ptr; | |
306 | ||
307 | down_write(&service_level_sem); | |
308 | list_for_each_entry(ptr, &service_level_list, list) | |
309 | if (ptr == slr) { | |
310 | up_write(&service_level_sem); | |
311 | return -EEXIST; | |
312 | } | |
313 | list_add_tail(&slr->list, &service_level_list); | |
314 | up_write(&service_level_sem); | |
315 | return 0; | |
316 | } | |
317 | EXPORT_SYMBOL(register_service_level); | |
318 | ||
319 | int unregister_service_level(struct service_level *slr) | |
320 | { | |
321 | struct service_level *ptr, *next; | |
322 | int rc = -ENOENT; | |
323 | ||
324 | down_write(&service_level_sem); | |
325 | list_for_each_entry_safe(ptr, next, &service_level_list, list) { | |
326 | if (ptr != slr) | |
327 | continue; | |
328 | list_del(&ptr->list); | |
329 | rc = 0; | |
330 | break; | |
331 | } | |
332 | up_write(&service_level_sem); | |
333 | return rc; | |
334 | } | |
335 | EXPORT_SYMBOL(unregister_service_level); | |
336 | ||
337 | static void *service_level_start(struct seq_file *m, loff_t *pos) | |
338 | { | |
339 | down_read(&service_level_sem); | |
340 | return seq_list_start(&service_level_list, *pos); | |
341 | } | |
342 | ||
343 | static void *service_level_next(struct seq_file *m, void *p, loff_t *pos) | |
344 | { | |
345 | return seq_list_next(p, &service_level_list, pos); | |
346 | } | |
347 | ||
348 | static void service_level_stop(struct seq_file *m, void *p) | |
349 | { | |
350 | up_read(&service_level_sem); | |
351 | } | |
352 | ||
353 | static int service_level_show(struct seq_file *m, void *p) | |
354 | { | |
355 | struct service_level *slr; | |
356 | ||
357 | slr = list_entry(p, struct service_level, list); | |
358 | slr->seq_print(m, slr); | |
359 | return 0; | |
360 | } | |
361 | ||
362 | static const struct seq_operations service_level_seq_ops = { | |
363 | .start = service_level_start, | |
364 | .next = service_level_next, | |
365 | .stop = service_level_stop, | |
366 | .show = service_level_show | |
367 | }; | |
368 | ||
369 | static int service_level_open(struct inode *inode, struct file *file) | |
370 | { | |
371 | return seq_open(file, &service_level_seq_ops); | |
372 | } | |
373 | ||
374 | static const struct file_operations service_level_ops = { | |
375 | .open = service_level_open, | |
376 | .read = seq_read, | |
377 | .llseek = seq_lseek, | |
378 | .release = seq_release | |
379 | }; | |
380 | ||
381 | static void service_level_vm_print(struct seq_file *m, | |
382 | struct service_level *slr) | |
383 | { | |
384 | char *query_buffer, *str; | |
385 | ||
386 | query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA); | |
387 | if (!query_buffer) | |
388 | return; | |
389 | cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL); | |
390 | str = strchr(query_buffer, '\n'); | |
391 | if (str) | |
392 | *str = 0; | |
393 | seq_printf(m, "VM: %s\n", query_buffer); | |
394 | kfree(query_buffer); | |
395 | } | |
396 | ||
397 | static struct service_level service_level_vm = { | |
398 | .seq_print = service_level_vm_print | |
399 | }; | |
400 | ||
401 | static __init int create_proc_service_level(void) | |
402 | { | |
403 | proc_create("service_levels", 0, NULL, &service_level_ops); | |
404 | if (MACHINE_IS_VM) | |
405 | register_service_level(&service_level_vm); | |
406 | return 0; | |
407 | } | |
6bcac508 MS |
408 | subsys_initcall(create_proc_service_level); |
409 | ||
31ee4b2f MS |
410 | /* |
411 | * CPU capability might have changed. Therefore recalculate loops_per_jiffy. | |
412 | */ | |
413 | void s390_adjust_jiffies(void) | |
414 | { | |
415 | struct sysinfo_1_2_2 *info; | |
416 | const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */ | |
417 | FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR); | |
418 | FP_DECL_EX; | |
419 | unsigned int capability; | |
420 | ||
421 | info = (void *) get_zeroed_page(GFP_KERNEL); | |
422 | if (!info) | |
423 | return; | |
424 | ||
caf757c6 | 425 | if (stsi(info, 1, 2, 2) == 0) { |
31ee4b2f MS |
426 | /* |
427 | * Major sigh. The cpu capability encoding is "special". | |
428 | * If the first 9 bits of info->capability are 0 then it | |
429 | * is a 32 bit unsigned integer in the range 0 .. 2^23. | |
430 | * If the first 9 bits are != 0 then it is a 32 bit float. | |
431 | * In addition a lower value indicates a proportionally | |
432 | * higher cpu capacity. Bogomips are the other way round. | |
433 | * To get to a halfway suitable number we divide 1e7 | |
434 | * by the cpu capability number. Yes, that means a floating | |
435 | * point division .. math-emu here we come :-) | |
436 | */ | |
437 | FP_UNPACK_SP(SA, &fmil); | |
438 | if ((info->capability >> 23) == 0) | |
5b479a79 | 439 | FP_FROM_INT_S(SB, (long) info->capability, 64, long); |
31ee4b2f MS |
440 | else |
441 | FP_UNPACK_SP(SB, &info->capability); | |
442 | FP_DIV_S(SR, SA, SB); | |
443 | FP_TO_INT_S(capability, SR, 32, 0); | |
444 | } else | |
445 | /* | |
446 | * Really old machine without stsi block for basic | |
447 | * cpu information. Report 42.0 bogomips. | |
448 | */ | |
449 | capability = 42; | |
450 | loops_per_jiffy = capability * (500000/HZ); | |
451 | free_page((unsigned long) info); | |
452 | } | |
453 | ||
454 | /* | |
455 | * calibrate the delay loop | |
456 | */ | |
e2741f17 | 457 | void calibrate_delay(void) |
31ee4b2f MS |
458 | { |
459 | s390_adjust_jiffies(); | |
460 | /* Print the good old Bogomips line .. */ | |
461 | printk(KERN_DEBUG "Calibrating delay loop (skipped)... " | |
462 | "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ), | |
463 | (loops_per_jiffy/(5000/HZ)) % 100); | |
464 | } |