1
2
3
4
5
6
7#include <linux/kernel.h>
8#include <linux/mm.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>
20
21int topology_max_mnest;
22
23static inline int __stsi(void *sysinfo, int fc, int sel1, int sel2, int *lvl)
24{
25 register int r0 asm("0") = (fc << 28) | sel1;
26 register int r1 asm("1") = sel2;
27 int rc = 0;
28
29 asm volatile(
30 " stsi 0(%3)\n"
31 "0: jz 2f\n"
32 "1: lhi %1,%4\n"
33 "2:\n"
34 EX_TABLE(0b, 1b)
35 : "+d" (r0), "+d" (rc)
36 : "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP)
37 : "cc", "memory");
38 *lvl = ((unsigned int) r0) >> 28;
39 return rc;
40}
41
42
43
44
45
46
47
48int stsi(void *sysinfo, int fc, int sel1, int sel2)
49{
50 int lvl, rc;
51
52 rc = __stsi(sysinfo, fc, sel1, sel2, &lvl);
53 if (rc)
54 return rc;
55 return fc ? 0 : lvl;
56}
57EXPORT_SYMBOL(stsi);
58
59static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
60{
61 int i;
62
63 if (stsi(info, 1, 1, 1))
64 return;
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);
75
76
77
78
79
80
81
82 seq_printf(m, "Model: %-16.16s", info->model_capacity);
83 if (info->model[0] != '\0')
84 seq_printf(m, " %-16.16s", info->model);
85 seq_putc(m, '\n');
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",
92 info->model_perm_cap,
93 info->model_perm_cap_rating);
94 if (info->model_temp_cap_rating)
95 seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
96 info->model_temp_cap,
97 info->model_temp_cap_rating);
98 if (info->ncr)
99 seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
100 if (info->npr)
101 seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
102 if (info->ntr)
103 seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
104 if (info->cai) {
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);
108 }
109 if (info->p) {
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]);
113 }
114 }
115}
116
117static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
118{
119 int i;
120
121 seq_putc(m, '\n');
122 if (!MACHINE_HAS_TOPOLOGY)
123 return;
124 if (stsi(info, 15, 1, topology_max_mnest))
125 return;
126 seq_printf(m, "CPU Topology HW: ");
127 for (i = 0; i < TOPOLOGY_NR_MAG; i++)
128 seq_printf(m, " %d", info->mag[i]);
129 seq_putc(m, '\n');
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]);
135 seq_putc(m, '\n');
136#endif
137}
138
139static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
140{
141 struct sysinfo_1_2_2_extension *ext;
142 int i;
143
144 if (stsi(info, 1, 2, 2))
145 return;
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);
155 }
156
157
158
159
160
161
162
163
164
165 seq_printf(m, "Capability: %u", info->capability);
166 if (info->format == 1)
167 seq_printf(m, " %u", ext->alt_capability);
168 seq_putc(m, '\n');
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]);
178 seq_putc(m, '\n');
179 }
180}
181
182static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
183{
184 if (stsi(info, 2, 2, 2))
185 return;
186 EBCASC(info->name, sizeof(info->name));
187 seq_putc(m, '\n');
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 ");
196 seq_putc(m, '\n');
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);
209 }
210}
211
212static void print_ext_name(struct seq_file *m, int lvl,
213 struct sysinfo_3_2_2 *info)
214{
215 if (info->vm[lvl].ext_name_encoding == 0)
216 return;
217 if (info->ext_names[lvl][0] == 0)
218 return;
219 switch (info->vm[lvl].ext_name_encoding) {
220 case 1:
221 EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl]));
222 break;
223 case 2:
224 break;
225 default:
226 return;
227 }
228 seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl,
229 info->ext_names[lvl]);
230}
231
232static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
233{
234 if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
235 return;
236 seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid);
237}
238
239static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
240{
241 int i;
242
243 if (stsi(info, 3, 2, 2))
244 return;
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));
248 seq_putc(m, '\n');
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);
258 }
259}
260
261static int sysinfo_show(struct seq_file *m, void *v)
262{
263 void *info = (void *)get_zeroed_page(GFP_KERNEL);
264 int level;
265
266 if (!info)
267 return 0;
268 level = stsi(NULL, 0, 0, 0);
269 if (level >= 1)
270 stsi_1_1_1(m, info);
271 if (level >= 1)
272 stsi_15_1_x(m, info);
273 if (level >= 1)
274 stsi_1_2_2(m, info);
275 if (level >= 2)
276 stsi_2_2_2(m, info);
277 if (level >= 3)
278 stsi_3_2_2(m, info);
279 free_page((unsigned long)info);
280 return 0;
281}
282
283static int sysinfo_open(struct inode *inode, struct file *file)
284{
285 return single_open(file, sysinfo_show, NULL);
286}
287
288static const struct file_operations sysinfo_fops = {
289 .open = sysinfo_open,
290 .read = seq_read,
291 .llseek = seq_lseek,
292 .release = single_release,
293};
294
295static int __init sysinfo_create_proc(void)
296{
297 proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
298 return 0;
299}
300device_initcall(sysinfo_create_proc);
301
302
303
304
305
306static DECLARE_RWSEM(service_level_sem);
307static LIST_HEAD(service_level_list);
308
309int register_service_level(struct service_level *slr)
310{
311 struct service_level *ptr;
312
313 down_write(&service_level_sem);
314 list_for_each_entry(ptr, &service_level_list, list)
315 if (ptr == slr) {
316 up_write(&service_level_sem);
317 return -EEXIST;
318 }
319 list_add_tail(&slr->list, &service_level_list);
320 up_write(&service_level_sem);
321 return 0;
322}
323EXPORT_SYMBOL(register_service_level);
324
325int unregister_service_level(struct service_level *slr)
326{
327 struct service_level *ptr, *next;
328 int rc = -ENOENT;
329
330 down_write(&service_level_sem);
331 list_for_each_entry_safe(ptr, next, &service_level_list, list) {
332 if (ptr != slr)
333 continue;
334 list_del(&ptr->list);
335 rc = 0;
336 break;
337 }
338 up_write(&service_level_sem);
339 return rc;
340}
341EXPORT_SYMBOL(unregister_service_level);
342
343static void *service_level_start(struct seq_file *m, loff_t *pos)
344{
345 down_read(&service_level_sem);
346 return seq_list_start(&service_level_list, *pos);
347}
348
349static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
350{
351 return seq_list_next(p, &service_level_list, pos);
352}
353
354static void service_level_stop(struct seq_file *m, void *p)
355{
356 up_read(&service_level_sem);
357}
358
359static int service_level_show(struct seq_file *m, void *p)
360{
361 struct service_level *slr;
362
363 slr = list_entry(p, struct service_level, list);
364 slr->seq_print(m, slr);
365 return 0;
366}
367
368static 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
373};
374
375static int service_level_open(struct inode *inode, struct file *file)
376{
377 return seq_open(file, &service_level_seq_ops);
378}
379
380static const struct file_operations service_level_ops = {
381 .open = service_level_open,
382 .read = seq_read,
383 .llseek = seq_lseek,
384 .release = seq_release
385};
386
387static void service_level_vm_print(struct seq_file *m,
388 struct service_level *slr)
389{
390 char *query_buffer, *str;
391
392 query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
393 if (!query_buffer)
394 return;
395 cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
396 str = strchr(query_buffer, '\n');
397 if (str)
398 *str = 0;
399 seq_printf(m, "VM: %s\n", query_buffer);
400 kfree(query_buffer);
401}
402
403static struct service_level service_level_vm = {
404 .seq_print = service_level_vm_print
405};
406
407static __init int create_proc_service_level(void)
408{
409 proc_create("service_levels", 0, NULL, &service_level_ops);
410 if (MACHINE_IS_VM)
411 register_service_level(&service_level_vm);
412 return 0;
413}
414subsys_initcall(create_proc_service_level);
415
416
417
418
419void s390_adjust_jiffies(void)
420{
421 struct sysinfo_1_2_2 *info;
422 unsigned long capability;
423 struct kernel_fpu fpu;
424
425 info = (void *) get_zeroed_page(GFP_KERNEL);
426 if (!info)
427 return;
428
429 if (stsi(info, 1, 2, 2) == 0) {
430
431
432
433
434
435
436
437
438
439
440
441 kernel_fpu_begin(&fpu, KERNEL_FPR);
442 asm volatile(
443 " sfpc %3\n"
444 " l %0,%1\n"
445 " tmlh %0,0xff80\n"
446 " jnz 0f\n"
447 " cefbr %%f2,%0\n"
448 " j 1f\n"
449 "0: le %%f2,%1\n"
450 "1: cefbr %%f0,%2\n"
451 " debr %%f0,%%f2\n"
452 " cgebr %0,5,%%f0\n"
453 : "=&d" (capability)
454 : "Q" (info->capability), "d" (10000000), "d" (0)
455 : "cc"
456 );
457 kernel_fpu_end(&fpu);
458 } else
459
460
461
462
463 capability = 42;
464 loops_per_jiffy = capability * (500000/HZ);
465 free_page((unsigned long) info);
466}
467
468
469
470
471void calibrate_delay(void)
472{
473 s390_adjust_jiffies();
474
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);
478}
479