Linux Audio

Check our new training course

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