Linux Audio

Check our new training course

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