Linux Audio

Check our new training course

Loading...
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  Copyright IBM Corp. 2001, 2009
  4 *  Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
  5 *	       Martin Schwidefsky <schwidefsky@de.ibm.com>,
  6 */
  7
  8#include <linux/debugfs.h>
  9#include <linux/kernel.h>
 10#include <linux/mm.h>
 11#include <linux/proc_fs.h>
 12#include <linux/seq_file.h>
 13#include <linux/init.h>
 14#include <linux/delay.h>
 15#include <linux/export.h>
 16#include <linux/slab.h>
 17#include <asm/ebcdic.h>
 18#include <asm/debug.h>
 19#include <asm/sysinfo.h>
 20#include <asm/cpcmd.h>
 21#include <asm/topology.h>
 22#include <asm/fpu/api.h>
 23
 24int topology_max_mnest;
 25
 26static inline int __stsi(void *sysinfo, int fc, int sel1, int sel2, int *lvl)
 27{
 28	register int r0 asm("0") = (fc << 28) | sel1;
 29	register int r1 asm("1") = sel2;
 30	int rc = 0;
 31
 32	asm volatile(
 33		"	stsi	0(%3)\n"
 34		"0:	jz	2f\n"
 35		"1:	lhi	%1,%4\n"
 36		"2:\n"
 37		EX_TABLE(0b, 1b)
 38		: "+d" (r0), "+d" (rc)
 39		: "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP)
 40		: "cc", "memory");
 41	*lvl = ((unsigned int) r0) >> 28;
 42	return rc;
 43}
 44
 45/*
 46 * stsi - store system information
 47 *
 48 * Returns the current configuration level if function code 0 was specified.
 49 * Otherwise returns 0 on success or a negative value on error.
 50 */
 51int stsi(void *sysinfo, int fc, int sel1, int sel2)
 52{
 53	int lvl, rc;
 54
 55	rc = __stsi(sysinfo, fc, sel1, sel2, &lvl);
 56	if (rc)
 57		return rc;
 58	return fc ? 0 : lvl;
 59}
 60EXPORT_SYMBOL(stsi);
 61
 62static bool convert_ext_name(unsigned char encoding, char *name, size_t len)
 63{
 64	switch (encoding) {
 65	case 1: /* EBCDIC */
 66		EBCASC(name, len);
 67		break;
 68	case 2:	/* UTF-8 */
 69		break;
 70	default:
 71		return false;
 72	}
 73	return true;
 74}
 75
 76static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
 77{
 78	int i;
 79
 80	if (stsi(info, 1, 1, 1))
 81		return;
 82	EBCASC(info->manufacturer, sizeof(info->manufacturer));
 83	EBCASC(info->type, sizeof(info->type));
 84	EBCASC(info->model, sizeof(info->model));
 85	EBCASC(info->sequence, sizeof(info->sequence));
 86	EBCASC(info->plant, sizeof(info->plant));
 87	EBCASC(info->model_capacity, sizeof(info->model_capacity));
 88	EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
 89	EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
 90	seq_printf(m, "Manufacturer:         %-16.16s\n", info->manufacturer);
 91	seq_printf(m, "Type:                 %-4.4s\n", info->type);
 92	if (info->lic)
 93		seq_printf(m, "LIC Identifier:       %016lx\n", info->lic);
 94	/*
 95	 * Sigh: the model field has been renamed with System z9
 96	 * to model_capacity and a new model field has been added
 97	 * after the plant field. To avoid confusing older programs
 98	 * the "Model:" prints "model_capacity model" or just
 99	 * "model_capacity" if the model string is empty .
100	 */
101	seq_printf(m, "Model:                %-16.16s", info->model_capacity);
102	if (info->model[0] != '\0')
103		seq_printf(m, " %-16.16s", info->model);
104	seq_putc(m, '\n');
105	seq_printf(m, "Sequence Code:        %-16.16s\n", info->sequence);
106	seq_printf(m, "Plant:                %-4.4s\n", info->plant);
107	seq_printf(m, "Model Capacity:       %-16.16s %08u\n",
108		   info->model_capacity, info->model_cap_rating);
109	if (info->model_perm_cap_rating)
110		seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
111			   info->model_perm_cap,
112			   info->model_perm_cap_rating);
113	if (info->model_temp_cap_rating)
114		seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
115			   info->model_temp_cap,
116			   info->model_temp_cap_rating);
117	if (info->ncr)
118		seq_printf(m, "Nominal Cap. Rating:  %08u\n", info->ncr);
119	if (info->npr)
120		seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
121	if (info->ntr)
122		seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
123	if (info->cai) {
124		seq_printf(m, "Capacity Adj. Ind.:   %d\n", info->cai);
125		seq_printf(m, "Capacity Ch. Reason:  %d\n", info->ccr);
126		seq_printf(m, "Capacity Transient:   %d\n", info->t);
127	}
128	if (info->p) {
129		for (i = 1; i <= ARRAY_SIZE(info->typepct); i++) {
130			seq_printf(m, "Type %d Percentage:    %d\n",
131				   i, info->typepct[i - 1]);
132		}
133	}
134}
135
136static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
137{
138	int i;
139
140	seq_putc(m, '\n');
141	if (!MACHINE_HAS_TOPOLOGY)
142		return;
143	if (stsi(info, 15, 1, topology_max_mnest))
144		return;
145	seq_printf(m, "CPU Topology HW:     ");
146	for (i = 0; i < TOPOLOGY_NR_MAG; i++)
147		seq_printf(m, " %d", info->mag[i]);
148	seq_putc(m, '\n');
149#ifdef CONFIG_SCHED_TOPOLOGY
150	store_topology(info);
151	seq_printf(m, "CPU Topology SW:     ");
152	for (i = 0; i < TOPOLOGY_NR_MAG; i++)
153		seq_printf(m, " %d", info->mag[i]);
154	seq_putc(m, '\n');
155#endif
156}
157
158static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
159{
160	struct sysinfo_1_2_2_extension *ext;
161	int i;
162
163	if (stsi(info, 1, 2, 2))
164		return;
165	ext = (struct sysinfo_1_2_2_extension *)
166		((unsigned long) info + info->acc_offset);
167	seq_printf(m, "CPUs Total:           %d\n", info->cpus_total);
168	seq_printf(m, "CPUs Configured:      %d\n", info->cpus_configured);
169	seq_printf(m, "CPUs Standby:         %d\n", info->cpus_standby);
170	seq_printf(m, "CPUs Reserved:        %d\n", info->cpus_reserved);
171	if (info->mt_installed) {
172		seq_printf(m, "CPUs G-MTID:          %d\n", info->mt_gtid);
173		seq_printf(m, "CPUs S-MTID:          %d\n", info->mt_stid);
174	}
175	/*
176	 * Sigh 2. According to the specification the alternate
177	 * capability field is a 32 bit floating point number
178	 * if the higher order 8 bits are not zero. Printing
179	 * a floating point number in the kernel is a no-no,
180	 * always print the number as 32 bit unsigned integer.
181	 * The user-space needs to know about the strange
182	 * encoding of the alternate cpu capability.
183	 */
184	seq_printf(m, "Capability:           %u", info->capability);
185	if (info->format == 1)
186		seq_printf(m, " %u", ext->alt_capability);
187	seq_putc(m, '\n');
188	if (info->nominal_cap)
189		seq_printf(m, "Nominal Capability:   %d\n", info->nominal_cap);
190	if (info->secondary_cap)
191		seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap);
192	for (i = 2; i <= info->cpus_total; i++) {
193		seq_printf(m, "Adjustment %02d-way:    %u",
194			   i, info->adjustment[i-2]);
195		if (info->format == 1)
196			seq_printf(m, " %u", ext->alt_adjustment[i-2]);
197		seq_putc(m, '\n');
198	}
199}
200
201static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
202{
203	if (stsi(info, 2, 2, 2))
204		return;
205	EBCASC(info->name, sizeof(info->name));
206	seq_putc(m, '\n');
207	seq_printf(m, "LPAR Number:          %d\n", info->lpar_number);
208	seq_printf(m, "LPAR Characteristics: ");
209	if (info->characteristics & LPAR_CHAR_DEDICATED)
210		seq_printf(m, "Dedicated ");
211	if (info->characteristics & LPAR_CHAR_SHARED)
212		seq_printf(m, "Shared ");
213	if (info->characteristics & LPAR_CHAR_LIMITED)
214		seq_printf(m, "Limited ");
215	seq_putc(m, '\n');
216	seq_printf(m, "LPAR Name:            %-8.8s\n", info->name);
217	seq_printf(m, "LPAR Adjustment:      %d\n", info->caf);
218	seq_printf(m, "LPAR CPUs Total:      %d\n", info->cpus_total);
219	seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
220	seq_printf(m, "LPAR CPUs Standby:    %d\n", info->cpus_standby);
221	seq_printf(m, "LPAR CPUs Reserved:   %d\n", info->cpus_reserved);
222	seq_printf(m, "LPAR CPUs Dedicated:  %d\n", info->cpus_dedicated);
223	seq_printf(m, "LPAR CPUs Shared:     %d\n", info->cpus_shared);
224	if (info->mt_installed) {
225		seq_printf(m, "LPAR CPUs G-MTID:     %d\n", info->mt_gtid);
226		seq_printf(m, "LPAR CPUs S-MTID:     %d\n", info->mt_stid);
227		seq_printf(m, "LPAR CPUs PS-MTID:    %d\n", info->mt_psmtid);
228	}
229	if (convert_ext_name(info->vsne, info->ext_name, sizeof(info->ext_name))) {
230		seq_printf(m, "LPAR Extended Name:   %-.256s\n", info->ext_name);
231		seq_printf(m, "LPAR UUID:            %pUb\n", &info->uuid);
232	}
233}
234
235static void print_ext_name(struct seq_file *m, int lvl,
236			   struct sysinfo_3_2_2 *info)
237{
238	size_t len = sizeof(info->ext_names[lvl]);
239
240	if (!convert_ext_name(info->vm[lvl].evmne, info->ext_names[lvl], len))
241		return;
242	seq_printf(m, "VM%02d Extended Name:   %-.256s\n", lvl,
243		   info->ext_names[lvl]);
244}
245
246static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
247{
248	if (uuid_is_null(&info->vm[i].uuid))
249		return;
250	seq_printf(m, "VM%02d UUID:            %pUb\n", i, &info->vm[i].uuid);
251}
252
253static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
254{
255	int i;
256
257	if (stsi(info, 3, 2, 2))
258		return;
259	for (i = 0; i < info->count; i++) {
260		EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
261		EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
262		seq_putc(m, '\n');
263		seq_printf(m, "VM%02d Name:            %-8.8s\n", i, info->vm[i].name);
264		seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
265		seq_printf(m, "VM%02d Adjustment:      %d\n", i, info->vm[i].caf);
266		seq_printf(m, "VM%02d CPUs Total:      %d\n", i, info->vm[i].cpus_total);
267		seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
268		seq_printf(m, "VM%02d CPUs Standby:    %d\n", i, info->vm[i].cpus_standby);
269		seq_printf(m, "VM%02d CPUs Reserved:   %d\n", i, info->vm[i].cpus_reserved);
270		print_ext_name(m, i, info);
271		print_uuid(m, i, info);
272	}
273}
274
275static int sysinfo_show(struct seq_file *m, void *v)
276{
277	void *info = (void *)get_zeroed_page(GFP_KERNEL);
278	int level;
279
280	if (!info)
281		return 0;
282	level = stsi(NULL, 0, 0, 0);
283	if (level >= 1)
284		stsi_1_1_1(m, info);
285	if (level >= 1)
286		stsi_15_1_x(m, info);
287	if (level >= 1)
288		stsi_1_2_2(m, info);
289	if (level >= 2)
290		stsi_2_2_2(m, info);
291	if (level >= 3)
292		stsi_3_2_2(m, info);
293	free_page((unsigned long)info);
294	return 0;
295}
296
297static int sysinfo_open(struct inode *inode, struct file *file)
298{
299	return single_open(file, sysinfo_show, NULL);
300}
301
302static const struct file_operations sysinfo_fops = {
303	.open		= sysinfo_open,
304	.read		= seq_read,
305	.llseek		= seq_lseek,
306	.release	= single_release,
307};
308
309static int __init sysinfo_create_proc(void)
310{
311	proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
312	return 0;
313}
314device_initcall(sysinfo_create_proc);
315
316/*
317 * Service levels interface.
318 */
319
320static DECLARE_RWSEM(service_level_sem);
321static LIST_HEAD(service_level_list);
322
323int register_service_level(struct service_level *slr)
324{
325	struct service_level *ptr;
326
327	down_write(&service_level_sem);
328	list_for_each_entry(ptr, &service_level_list, list)
329		if (ptr == slr) {
330			up_write(&service_level_sem);
331			return -EEXIST;
332		}
333	list_add_tail(&slr->list, &service_level_list);
334	up_write(&service_level_sem);
335	return 0;
336}
337EXPORT_SYMBOL(register_service_level);
338
339int unregister_service_level(struct service_level *slr)
340{
341	struct service_level *ptr, *next;
342	int rc = -ENOENT;
343
344	down_write(&service_level_sem);
345	list_for_each_entry_safe(ptr, next, &service_level_list, list) {
346		if (ptr != slr)
347			continue;
348		list_del(&ptr->list);
349		rc = 0;
350		break;
351	}
352	up_write(&service_level_sem);
353	return rc;
354}
355EXPORT_SYMBOL(unregister_service_level);
356
357static void *service_level_start(struct seq_file *m, loff_t *pos)
358{
359	down_read(&service_level_sem);
360	return seq_list_start(&service_level_list, *pos);
361}
362
363static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
364{
365	return seq_list_next(p, &service_level_list, pos);
366}
367
368static void service_level_stop(struct seq_file *m, void *p)
369{
370	up_read(&service_level_sem);
371}
372
373static int service_level_show(struct seq_file *m, void *p)
374{
375	struct service_level *slr;
376
377	slr = list_entry(p, struct service_level, list);
378	slr->seq_print(m, slr);
379	return 0;
380}
381
382static const struct seq_operations service_level_seq_ops = {
383	.start		= service_level_start,
384	.next		= service_level_next,
385	.stop		= service_level_stop,
386	.show		= service_level_show
387};
388
389static int service_level_open(struct inode *inode, struct file *file)
390{
391	return seq_open(file, &service_level_seq_ops);
392}
393
394static const struct file_operations service_level_ops = {
395	.open		= service_level_open,
396	.read		= seq_read,
397	.llseek 	= seq_lseek,
398	.release	= seq_release
399};
400
401static void service_level_vm_print(struct seq_file *m,
402				   struct service_level *slr)
403{
404	char *query_buffer, *str;
405
406	query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
407	if (!query_buffer)
408		return;
409	cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
410	str = strchr(query_buffer, '\n');
411	if (str)
412		*str = 0;
413	seq_printf(m, "VM: %s\n", query_buffer);
414	kfree(query_buffer);
415}
416
417static struct service_level service_level_vm = {
418	.seq_print = service_level_vm_print
419};
420
421static __init int create_proc_service_level(void)
422{
423	proc_create("service_levels", 0, NULL, &service_level_ops);
424	if (MACHINE_IS_VM)
425		register_service_level(&service_level_vm);
426	return 0;
427}
428subsys_initcall(create_proc_service_level);
429
430/*
431 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
432 */
433void s390_adjust_jiffies(void)
434{
435	struct sysinfo_1_2_2 *info;
436	unsigned long capability;
437	struct kernel_fpu fpu;
438
439	info = (void *) get_zeroed_page(GFP_KERNEL);
440	if (!info)
441		return;
442
443	if (stsi(info, 1, 2, 2) == 0) {
444		/*
445		 * Major sigh. The cpu capability encoding is "special".
446		 * If the first 9 bits of info->capability are 0 then it
447		 * is a 32 bit unsigned integer in the range 0 .. 2^23.
448		 * If the first 9 bits are != 0 then it is a 32 bit float.
449		 * In addition a lower value indicates a proportionally
450		 * higher cpu capacity. Bogomips are the other way round.
451		 * To get to a halfway suitable number we divide 1e7
452		 * by the cpu capability number. Yes, that means a floating
453		 * point division ..
454		 */
455		kernel_fpu_begin(&fpu, KERNEL_FPR);
456		asm volatile(
457			"	sfpc	%3\n"
458			"	l	%0,%1\n"
459			"	tmlh	%0,0xff80\n"
460			"	jnz	0f\n"
461			"	cefbr	%%f2,%0\n"
462			"	j	1f\n"
463			"0:	le	%%f2,%1\n"
464			"1:	cefbr	%%f0,%2\n"
465			"	debr	%%f0,%%f2\n"
466			"	cgebr	%0,5,%%f0\n"
467			: "=&d" (capability)
468			: "Q" (info->capability), "d" (10000000), "d" (0)
469			: "cc"
470			);
471		kernel_fpu_end(&fpu, KERNEL_FPR);
472	} else
473		/*
474		 * Really old machine without stsi block for basic
475		 * cpu information. Report 42.0 bogomips.
476		 */
477		capability = 42;
478	loops_per_jiffy = capability * (500000/HZ);
479	free_page((unsigned long) info);
480}
481
482/*
483 * calibrate the delay loop
484 */
485void calibrate_delay(void)
486{
487	s390_adjust_jiffies();
488	/* Print the good old Bogomips line .. */
489	printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
490	       "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
491	       (loops_per_jiffy/(5000/HZ)) % 100);
492}
493
494#ifdef CONFIG_DEBUG_FS
495
496#define STSI_FILE(fc, s1, s2)						       \
497static int stsi_open_##fc##_##s1##_##s2(struct inode *inode, struct file *file)\
498{									       \
499	file->private_data = (void *) get_zeroed_page(GFP_KERNEL);	       \
500	if (!file->private_data)					       \
501		return -ENOMEM;						       \
502	if (stsi(file->private_data, fc, s1, s2)) {			       \
503		free_page((unsigned long)file->private_data);		       \
504		file->private_data = NULL;				       \
505		return -EACCES;						       \
506	}								       \
507	return nonseekable_open(inode, file);				       \
508}									       \
509									       \
510static const struct file_operations stsi_##fc##_##s1##_##s2##_fs_ops = {       \
511	.open		= stsi_open_##fc##_##s1##_##s2,			       \
512	.release	= stsi_release,					       \
513	.read		= stsi_read,					       \
514	.llseek		= no_llseek,					       \
515};
516
517static int stsi_release(struct inode *inode, struct file *file)
518{
519	free_page((unsigned long)file->private_data);
520	return 0;
521}
522
523static ssize_t stsi_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
524{
525	return simple_read_from_buffer(buf, size, ppos, file->private_data, PAGE_SIZE);
526}
527
528STSI_FILE( 1, 1, 1);
529STSI_FILE( 1, 2, 1);
530STSI_FILE( 1, 2, 2);
531STSI_FILE( 2, 2, 1);
532STSI_FILE( 2, 2, 2);
533STSI_FILE( 3, 2, 2);
534STSI_FILE(15, 1, 2);
535STSI_FILE(15, 1, 3);
536STSI_FILE(15, 1, 4);
537STSI_FILE(15, 1, 5);
538STSI_FILE(15, 1, 6);
539
540struct stsi_file {
541	const struct file_operations *fops;
542	char *name;
543};
544
545static struct stsi_file stsi_file[] __initdata = {
546	{.fops = &stsi_1_1_1_fs_ops,  .name =  "1_1_1"},
547	{.fops = &stsi_1_2_1_fs_ops,  .name =  "1_2_1"},
548	{.fops = &stsi_1_2_2_fs_ops,  .name =  "1_2_2"},
549	{.fops = &stsi_2_2_1_fs_ops,  .name =  "2_2_1"},
550	{.fops = &stsi_2_2_2_fs_ops,  .name =  "2_2_2"},
551	{.fops = &stsi_3_2_2_fs_ops,  .name =  "3_2_2"},
552	{.fops = &stsi_15_1_2_fs_ops, .name = "15_1_2"},
553	{.fops = &stsi_15_1_3_fs_ops, .name = "15_1_3"},
554	{.fops = &stsi_15_1_4_fs_ops, .name = "15_1_4"},
555	{.fops = &stsi_15_1_5_fs_ops, .name = "15_1_5"},
556	{.fops = &stsi_15_1_6_fs_ops, .name = "15_1_6"},
557};
558
559static u8 stsi_0_0_0;
560
561static __init int stsi_init_debugfs(void)
562{
563	struct dentry *stsi_root;
564	struct stsi_file *sf;
565	int lvl, i;
566
567	stsi_root = debugfs_create_dir("stsi", arch_debugfs_dir);
568	if (IS_ERR_OR_NULL(stsi_root))
569		return 0;
570	lvl = stsi(NULL, 0, 0, 0);
571	if (lvl > 0)
572		stsi_0_0_0 = lvl;
573	debugfs_create_u8("0_0_0", 0400, stsi_root, &stsi_0_0_0);
574	for (i = 0; i < ARRAY_SIZE(stsi_file); i++) {
575		sf = &stsi_file[i];
576		debugfs_create_file(sf->name, 0400, stsi_root, NULL, sf->fops);
577	}
578	if (IS_ENABLED(CONFIG_SCHED_TOPOLOGY) && MACHINE_HAS_TOPOLOGY) {
579		char link_to[10];
580
581		sprintf(link_to, "15_1_%d", topology_mnest_limit());
582		debugfs_create_symlink("topology", stsi_root, link_to);
583	}
584	return 0;
585}
586device_initcall(stsi_init_debugfs);
587
588#endif /* CONFIG_DEBUG_FS */
v4.10.11
 
  1/*
  2 *  Copyright IBM Corp. 2001, 2009
  3 *  Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
  4 *	       Martin Schwidefsky <schwidefsky@de.ibm.com>,
  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 * stsi - store system information
 44 *
 45 * Returns the current configuration level if function code 0 was specified.
 46 * Otherwise returns 0 on success or a negative value on error.
 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 bool convert_ext_name(unsigned char encoding, char *name, size_t len)
 60{
 61	switch (encoding) {
 62	case 1: /* EBCDIC */
 63		EBCASC(name, len);
 64		break;
 65	case 2:	/* UTF-8 */
 66		break;
 67	default:
 68		return false;
 69	}
 70	return true;
 71}
 72
 73static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
 74{
 75	int i;
 76
 77	if (stsi(info, 1, 1, 1))
 78		return;
 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);
 
 
 89	/*
 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 .
 95	 */
 96	seq_printf(m, "Model:                %-16.16s", info->model_capacity);
 97	if (info->model[0] != '\0')
 98		seq_printf(m, " %-16.16s", info->model);
 99	seq_putc(m, '\n');
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);
112	if (info->ncr)
113		seq_printf(m, "Nominal Cap. Rating:  %08u\n", info->ncr);
114	if (info->npr)
115		seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
116	if (info->ntr)
117		seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
118	if (info->cai) {
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);
122	}
123	if (info->p) {
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]);
127		}
128	}
129}
130
131static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
132{
133	int i;
134
135	seq_putc(m, '\n');
136	if (!MACHINE_HAS_TOPOLOGY)
137		return;
138	if (stsi(info, 15, 1, topology_max_mnest))
139		return;
140	seq_printf(m, "CPU Topology HW:     ");
141	for (i = 0; i < TOPOLOGY_NR_MAG; i++)
142		seq_printf(m, " %d", info->mag[i]);
143	seq_putc(m, '\n');
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]);
149	seq_putc(m, '\n');
150#endif
151}
152
153static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
154{
155	struct sysinfo_1_2_2_extension *ext;
156	int i;
157
158	if (stsi(info, 1, 2, 2))
159		return;
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);
169	}
170	/*
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.
178	 */
179	seq_printf(m, "Capability:           %u", info->capability);
180	if (info->format == 1)
181		seq_printf(m, " %u", ext->alt_capability);
182	seq_putc(m, '\n');
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]);
192		seq_putc(m, '\n');
193	}
194}
195
196static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
197{
198	if (stsi(info, 2, 2, 2))
199		return;
200	EBCASC(info->name, sizeof(info->name));
201	seq_putc(m, '\n');
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 ");
210	seq_putc(m, '\n');
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);
223	}
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);
227	}
228}
229
230static void print_ext_name(struct seq_file *m, int lvl,
231			   struct sysinfo_3_2_2 *info)
232{
233	size_t len = sizeof(info->ext_names[lvl]);
234
235	if (!convert_ext_name(info->vm[lvl].evmne, info->ext_names[lvl], len))
236		return;
237	seq_printf(m, "VM%02d Extended Name:   %-.256s\n", lvl,
238		   info->ext_names[lvl]);
239}
240
241static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
242{
243	if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
244		return;
245	seq_printf(m, "VM%02d UUID:            %pUb\n", i, &info->vm[i].uuid);
246}
247
248static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
249{
250	int i;
251
252	if (stsi(info, 3, 2, 2))
253		return;
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));
257		seq_putc(m, '\n');
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);
267	}
268}
269
270static int sysinfo_show(struct seq_file *m, void *v)
271{
272	void *info = (void *)get_zeroed_page(GFP_KERNEL);
273	int level;
274
275	if (!info)
276		return 0;
277	level = stsi(NULL, 0, 0, 0);
278	if (level >= 1)
279		stsi_1_1_1(m, info);
280	if (level >= 1)
281		stsi_15_1_x(m, info);
282	if (level >= 1)
283		stsi_1_2_2(m, info);
284	if (level >= 2)
285		stsi_2_2_2(m, info);
286	if (level >= 3)
287		stsi_3_2_2(m, info);
288	free_page((unsigned long)info);
289	return 0;
290}
291
292static int sysinfo_open(struct inode *inode, struct file *file)
293{
294	return single_open(file, sysinfo_show, NULL);
295}
296
297static const struct file_operations sysinfo_fops = {
298	.open		= sysinfo_open,
299	.read		= seq_read,
300	.llseek		= seq_lseek,
301	.release	= single_release,
302};
303
304static int __init sysinfo_create_proc(void)
305{
306	proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
307	return 0;
308}
309device_initcall(sysinfo_create_proc);
310
311/*
312 * Service levels interface.
313 */
314
315static DECLARE_RWSEM(service_level_sem);
316static LIST_HEAD(service_level_list);
317
318int register_service_level(struct service_level *slr)
319{
320	struct service_level *ptr;
321
322	down_write(&service_level_sem);
323	list_for_each_entry(ptr, &service_level_list, list)
324		if (ptr == slr) {
325			up_write(&service_level_sem);
326			return -EEXIST;
327		}
328	list_add_tail(&slr->list, &service_level_list);
329	up_write(&service_level_sem);
330	return 0;
331}
332EXPORT_SYMBOL(register_service_level);
333
334int unregister_service_level(struct service_level *slr)
335{
336	struct service_level *ptr, *next;
337	int rc = -ENOENT;
338
339	down_write(&service_level_sem);
340	list_for_each_entry_safe(ptr, next, &service_level_list, list) {
341		if (ptr != slr)
342			continue;
343		list_del(&ptr->list);
344		rc = 0;
345		break;
346	}
347	up_write(&service_level_sem);
348	return rc;
349}
350EXPORT_SYMBOL(unregister_service_level);
351
352static void *service_level_start(struct seq_file *m, loff_t *pos)
353{
354	down_read(&service_level_sem);
355	return seq_list_start(&service_level_list, *pos);
356}
357
358static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
359{
360	return seq_list_next(p, &service_level_list, pos);
361}
362
363static void service_level_stop(struct seq_file *m, void *p)
364{
365	up_read(&service_level_sem);
366}
367
368static int service_level_show(struct seq_file *m, void *p)
369{
370	struct service_level *slr;
371
372	slr = list_entry(p, struct service_level, list);
373	slr->seq_print(m, slr);
374	return 0;
375}
376
377static 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
382};
383
384static int service_level_open(struct inode *inode, struct file *file)
385{
386	return seq_open(file, &service_level_seq_ops);
387}
388
389static const struct file_operations service_level_ops = {
390	.open		= service_level_open,
391	.read		= seq_read,
392	.llseek 	= seq_lseek,
393	.release	= seq_release
394};
395
396static void service_level_vm_print(struct seq_file *m,
397				   struct service_level *slr)
398{
399	char *query_buffer, *str;
400
401	query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
402	if (!query_buffer)
403		return;
404	cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
405	str = strchr(query_buffer, '\n');
406	if (str)
407		*str = 0;
408	seq_printf(m, "VM: %s\n", query_buffer);
409	kfree(query_buffer);
410}
411
412static struct service_level service_level_vm = {
413	.seq_print = service_level_vm_print
414};
415
416static __init int create_proc_service_level(void)
417{
418	proc_create("service_levels", 0, NULL, &service_level_ops);
419	if (MACHINE_IS_VM)
420		register_service_level(&service_level_vm);
421	return 0;
422}
423subsys_initcall(create_proc_service_level);
424
425/*
426 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
427 */
428void s390_adjust_jiffies(void)
429{
430	struct sysinfo_1_2_2 *info;
431	unsigned long capability;
432	struct kernel_fpu fpu;
433
434	info = (void *) get_zeroed_page(GFP_KERNEL);
435	if (!info)
436		return;
437
438	if (stsi(info, 1, 2, 2) == 0) {
439		/*
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
448		 * point division ..
449		 */
450		kernel_fpu_begin(&fpu, KERNEL_FPR);
451		asm volatile(
452			"	sfpc	%3\n"
453			"	l	%0,%1\n"
454			"	tmlh	%0,0xff80\n"
455			"	jnz	0f\n"
456			"	cefbr	%%f2,%0\n"
457			"	j	1f\n"
458			"0:	le	%%f2,%1\n"
459			"1:	cefbr	%%f0,%2\n"
460			"	debr	%%f0,%%f2\n"
461			"	cgebr	%0,5,%%f0\n"
462			: "=&d" (capability)
463			: "Q" (info->capability), "d" (10000000), "d" (0)
464			: "cc"
465			);
466		kernel_fpu_end(&fpu, KERNEL_FPR);
467	} else
468		/*
469		 * Really old machine without stsi block for basic
470		 * cpu information. Report 42.0 bogomips.
471		 */
472		capability = 42;
473	loops_per_jiffy = capability * (500000/HZ);
474	free_page((unsigned long) info);
475}
476
477/*
478 * calibrate the delay loop
479 */
480void calibrate_delay(void)
481{
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);
487}