Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 * Implementation of s390 diagnose codes
  3 *
  4 * Copyright IBM Corp. 2007
  5 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  6 */
  7
  8#include <linux/module.h>
 
  9#include <linux/cpu.h>
 10#include <linux/seq_file.h>
 11#include <linux/debugfs.h>
 
 
 12#include <asm/diag.h>
 13#include <asm/trace/diag.h>
 
 
 14
 15struct diag_stat {
 16	unsigned int counter[NR_DIAG_STAT];
 17};
 18
 19static DEFINE_PER_CPU(struct diag_stat, diag_stat);
 20
 21struct diag_desc {
 22	int code;
 23	char *name;
 24};
 25
 26static const struct diag_desc diag_map[NR_DIAG_STAT] = {
 27	[DIAG_STAT_X008] = { .code = 0x008, .name = "Console Function" },
 28	[DIAG_STAT_X00C] = { .code = 0x00c, .name = "Pseudo Timer" },
 29	[DIAG_STAT_X010] = { .code = 0x010, .name = "Release Pages" },
 30	[DIAG_STAT_X014] = { .code = 0x014, .name = "Spool File Services" },
 31	[DIAG_STAT_X044] = { .code = 0x044, .name = "Voluntary Timeslice End" },
 32	[DIAG_STAT_X064] = { .code = 0x064, .name = "NSS Manipulation" },
 
 33	[DIAG_STAT_X09C] = { .code = 0x09c, .name = "Relinquish Timeslice" },
 34	[DIAG_STAT_X0DC] = { .code = 0x0dc, .name = "Appldata Control" },
 35	[DIAG_STAT_X204] = { .code = 0x204, .name = "Logical-CPU Utilization" },
 36	[DIAG_STAT_X210] = { .code = 0x210, .name = "Device Information" },
 37	[DIAG_STAT_X224] = { .code = 0x224, .name = "EBCDIC-Name Table" },
 38	[DIAG_STAT_X250] = { .code = 0x250, .name = "Block I/O" },
 39	[DIAG_STAT_X258] = { .code = 0x258, .name = "Page-Reference Services" },
 
 40	[DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
 41	[DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
 42	[DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
 43	[DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
 44	[DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
 
 
 45	[DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
 46};
 47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 48static int show_diag_stat(struct seq_file *m, void *v)
 49{
 50	struct diag_stat *stat;
 51	unsigned long n = (unsigned long) v - 1;
 52	int cpu, prec, tmp;
 53
 54	get_online_cpus();
 55	if (n == 0) {
 56		seq_puts(m, "         ");
 57
 58		for_each_online_cpu(cpu) {
 59			prec = 10;
 60			for (tmp = 10; cpu >= tmp; tmp *= 10)
 61				prec--;
 62			seq_printf(m, "%*s%d", prec, "CPU", cpu);
 63		}
 64		seq_putc(m, '\n');
 65	} else if (n <= NR_DIAG_STAT) {
 66		seq_printf(m, "diag %03x:", diag_map[n-1].code);
 67		for_each_online_cpu(cpu) {
 68			stat = &per_cpu(diag_stat, cpu);
 69			seq_printf(m, " %10u", stat->counter[n-1]);
 70		}
 71		seq_printf(m, "    %s\n", diag_map[n-1].name);
 72	}
 73	put_online_cpus();
 74	return 0;
 75}
 76
 77static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
 78{
 79	return *pos <= nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
 80}
 81
 82static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
 83{
 84	++*pos;
 85	return show_diag_stat_start(m, pos);
 86}
 87
 88static void show_diag_stat_stop(struct seq_file *m, void *v)
 89{
 90}
 91
 92static const struct seq_operations show_diag_stat_sops = {
 93	.start	= show_diag_stat_start,
 94	.next	= show_diag_stat_next,
 95	.stop	= show_diag_stat_stop,
 96	.show	= show_diag_stat,
 97};
 98
 99static int show_diag_stat_open(struct inode *inode, struct file *file)
100{
101	return seq_open(file, &show_diag_stat_sops);
102}
103
104static const struct file_operations show_diag_stat_fops = {
105	.open		= show_diag_stat_open,
106	.read		= seq_read,
107	.llseek		= seq_lseek,
108	.release	= seq_release,
109};
110
111
112static int __init show_diag_stat_init(void)
113{
114	debugfs_create_file("diag_stat", 0400, NULL, NULL,
115			    &show_diag_stat_fops);
116	return 0;
117}
118
119device_initcall(show_diag_stat_init);
120
121void diag_stat_inc(enum diag_stat_enum nr)
122{
123	this_cpu_inc(diag_stat.counter[nr]);
124	trace_s390_diagnose(diag_map[nr].code);
125}
126EXPORT_SYMBOL(diag_stat_inc);
127
128void diag_stat_inc_norecursion(enum diag_stat_enum nr)
129{
130	this_cpu_inc(diag_stat.counter[nr]);
131	trace_s390_diagnose_norecursion(diag_map[nr].code);
132}
133EXPORT_SYMBOL(diag_stat_inc_norecursion);
134
135/*
136 * Diagnose 14: Input spool file manipulation
137 */
138static inline int __diag14(unsigned long rx, unsigned long ry1,
139			   unsigned long subcode)
140{
141	register unsigned long _ry1 asm("2") = ry1;
142	register unsigned long _ry2 asm("3") = subcode;
143	int rc = 0;
144
145	asm volatile(
146		"   sam31\n"
147		"   diag    %2,2,0x14\n"
148		"   sam64\n"
149		"   ipm     %0\n"
150		"   srl     %0,28\n"
151		: "=d" (rc), "+d" (_ry2)
152		: "d" (rx), "d" (_ry1)
153		: "cc");
154
155	return rc;
156}
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
159{
160	diag_stat_inc(DIAG_STAT_X014);
161	return __diag14(rx, ry1, subcode);
 
 
 
 
 
 
 
 
 
162}
163EXPORT_SYMBOL(diag14);
164
165static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
166{
167	register unsigned long _subcode asm("0") = *subcode;
168	register unsigned long _size asm("1") = size;
169
170	asm volatile(
171		"	diag	%2,%0,0x204\n"
172		"0:	nopr	%%r7\n"
173		EX_TABLE(0b,0b)
174		: "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
175	*subcode = _subcode;
176	return _size;
177}
178
 
 
 
 
 
 
 
 
 
 
 
 
 
179int diag204(unsigned long subcode, unsigned long size, void *addr)
180{
 
 
 
 
 
 
 
 
181	diag_stat_inc(DIAG_STAT_X204);
182	size = __diag204(&subcode, size, addr);
183	if (subcode)
184		return -1;
185	return size;
186}
187EXPORT_SYMBOL(diag204);
188
189/*
190 * Diagnose 210: Get information about a virtual device
191 */
192int diag210(struct diag210 *addr)
193{
194	/*
195	 * diag 210 needs its data below the 2GB border, so we
196	 * use a static data area to be sure
197	 */
198	static struct diag210 diag210_tmp;
199	static DEFINE_SPINLOCK(diag210_lock);
200	unsigned long flags;
201	int ccode;
202
203	spin_lock_irqsave(&diag210_lock, flags);
204	diag210_tmp = *addr;
205
206	diag_stat_inc(DIAG_STAT_X210);
207	asm volatile(
208		"	lhi	%0,-1\n"
209		"	sam31\n"
210		"	diag	%1,0,0x210\n"
211		"0:	ipm	%0\n"
212		"	srl	%0,28\n"
213		"1:	sam64\n"
214		EX_TABLE(0b, 1b)
215		: "=&d" (ccode) : "a" (&diag210_tmp) : "cc", "memory");
216
217	*addr = diag210_tmp;
218	spin_unlock_irqrestore(&diag210_lock, flags);
219
220	return ccode;
221}
222EXPORT_SYMBOL(diag210);
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224int diag224(void *ptr)
225{
 
226	int rc = -EOPNOTSUPP;
227
228	diag_stat_inc(DIAG_STAT_X224);
229	asm volatile(
230		"	diag	%1,%2,0x224\n"
231		"0:	lhi	%0,0x0\n"
232		"1:\n"
233		EX_TABLE(0b,1b)
234		: "+d" (rc) :"d" (0), "d" (ptr) : "memory");
235	return rc;
236}
237EXPORT_SYMBOL(diag224);
v6.9.4
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Implementation of s390 diagnose codes
  4 *
  5 * Copyright IBM Corp. 2007
  6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
  7 */
  8
  9#include <linux/export.h>
 10#include <linux/init.h>
 11#include <linux/cpu.h>
 12#include <linux/seq_file.h>
 13#include <linux/debugfs.h>
 14#include <linux/vmalloc.h>
 15#include <asm/asm-extable.h>
 16#include <asm/diag.h>
 17#include <asm/trace/diag.h>
 18#include <asm/sections.h>
 19#include "entry.h"
 20
 21struct diag_stat {
 22	unsigned int counter[NR_DIAG_STAT];
 23};
 24
 25static DEFINE_PER_CPU(struct diag_stat, diag_stat);
 26
 27struct diag_desc {
 28	int code;
 29	char *name;
 30};
 31
 32static const struct diag_desc diag_map[NR_DIAG_STAT] = {
 33	[DIAG_STAT_X008] = { .code = 0x008, .name = "Console Function" },
 34	[DIAG_STAT_X00C] = { .code = 0x00c, .name = "Pseudo Timer" },
 35	[DIAG_STAT_X010] = { .code = 0x010, .name = "Release Pages" },
 36	[DIAG_STAT_X014] = { .code = 0x014, .name = "Spool File Services" },
 37	[DIAG_STAT_X044] = { .code = 0x044, .name = "Voluntary Timeslice End" },
 38	[DIAG_STAT_X064] = { .code = 0x064, .name = "NSS Manipulation" },
 39	[DIAG_STAT_X08C] = { .code = 0x08c, .name = "Access 3270 Display Device Information" },
 40	[DIAG_STAT_X09C] = { .code = 0x09c, .name = "Relinquish Timeslice" },
 41	[DIAG_STAT_X0DC] = { .code = 0x0dc, .name = "Appldata Control" },
 42	[DIAG_STAT_X204] = { .code = 0x204, .name = "Logical-CPU Utilization" },
 43	[DIAG_STAT_X210] = { .code = 0x210, .name = "Device Information" },
 44	[DIAG_STAT_X224] = { .code = 0x224, .name = "EBCDIC-Name Table" },
 45	[DIAG_STAT_X250] = { .code = 0x250, .name = "Block I/O" },
 46	[DIAG_STAT_X258] = { .code = 0x258, .name = "Page-Reference Services" },
 47	[DIAG_STAT_X26C] = { .code = 0x26c, .name = "Certain System Information" },
 48	[DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
 49	[DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
 50	[DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
 51	[DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
 52	[DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
 53	[DIAG_STAT_X318] = { .code = 0x318, .name = "CP Name and Version Codes" },
 54	[DIAG_STAT_X320] = { .code = 0x320, .name = "Certificate Store" },
 55	[DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
 56};
 57
 58struct diag_ops __amode31_ref diag_amode31_ops = {
 59	.diag210 = _diag210_amode31,
 60	.diag26c = _diag26c_amode31,
 61	.diag14 = _diag14_amode31,
 62	.diag0c = _diag0c_amode31,
 63	.diag8c = _diag8c_amode31,
 64	.diag308_reset = _diag308_reset_amode31
 65};
 66
 67static struct diag210 _diag210_tmp_amode31 __section(".amode31.data");
 68struct diag210 __amode31_ref *__diag210_tmp_amode31 = &_diag210_tmp_amode31;
 69
 70static struct diag8c _diag8c_tmp_amode31 __section(".amode31.data");
 71static struct diag8c __amode31_ref *__diag8c_tmp_amode31 = &_diag8c_tmp_amode31;
 72
 73static int show_diag_stat(struct seq_file *m, void *v)
 74{
 75	struct diag_stat *stat;
 76	unsigned long n = (unsigned long) v - 1;
 77	int cpu, prec, tmp;
 78
 79	cpus_read_lock();
 80	if (n == 0) {
 81		seq_puts(m, "         ");
 82
 83		for_each_online_cpu(cpu) {
 84			prec = 10;
 85			for (tmp = 10; cpu >= tmp; tmp *= 10)
 86				prec--;
 87			seq_printf(m, "%*s%d", prec, "CPU", cpu);
 88		}
 89		seq_putc(m, '\n');
 90	} else if (n <= NR_DIAG_STAT) {
 91		seq_printf(m, "diag %03x:", diag_map[n-1].code);
 92		for_each_online_cpu(cpu) {
 93			stat = &per_cpu(diag_stat, cpu);
 94			seq_printf(m, " %10u", stat->counter[n-1]);
 95		}
 96		seq_printf(m, "    %s\n", diag_map[n-1].name);
 97	}
 98	cpus_read_unlock();
 99	return 0;
100}
101
102static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
103{
104	return *pos <= NR_DIAG_STAT ? (void *)((unsigned long) *pos + 1) : NULL;
105}
106
107static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
108{
109	++*pos;
110	return show_diag_stat_start(m, pos);
111}
112
113static void show_diag_stat_stop(struct seq_file *m, void *v)
114{
115}
116
117static const struct seq_operations show_diag_stat_sops = {
118	.start	= show_diag_stat_start,
119	.next	= show_diag_stat_next,
120	.stop	= show_diag_stat_stop,
121	.show	= show_diag_stat,
122};
123
124DEFINE_SEQ_ATTRIBUTE(show_diag_stat);
 
 
 
 
 
 
 
 
 
 
 
125
126static int __init show_diag_stat_init(void)
127{
128	debugfs_create_file("diag_stat", 0400, NULL, NULL,
129			    &show_diag_stat_fops);
130	return 0;
131}
132
133device_initcall(show_diag_stat_init);
134
135void diag_stat_inc(enum diag_stat_enum nr)
136{
137	this_cpu_inc(diag_stat.counter[nr]);
138	trace_s390_diagnose(diag_map[nr].code);
139}
140EXPORT_SYMBOL(diag_stat_inc);
141
142void notrace diag_stat_inc_norecursion(enum diag_stat_enum nr)
143{
144	this_cpu_inc(diag_stat.counter[nr]);
145	trace_s390_diagnose_norecursion(diag_map[nr].code);
146}
147EXPORT_SYMBOL(diag_stat_inc_norecursion);
148
149/*
150 * Diagnose 0c: Pseudo Timer
151 */
152void diag0c(struct hypfs_diag0c_entry *data)
 
153{
154	diag_stat_inc(DIAG_STAT_X00C);
155	diag_amode31_ops.diag0c(virt_to_phys(data));
 
 
 
 
 
 
 
 
 
 
 
 
 
156}
157
158/*
159 * Diagnose 14: Input spool file manipulation
160 *
161 * The subcode parameter determines the type of the first parameter rx.
162 * Currently used are the following 3 subcommands:
163 * 0x0:   Read the Next Spool File Buffer (Data Record)
164 * 0x28:  Position a Spool File to the Designated Record
165 * 0xfff: Retrieve Next File Descriptor
166 *
167 * For subcommands 0x0 and 0xfff, the value of the first parameter is
168 * a virtual address of a memory buffer and needs virtual to physical
169 * address translation. For other subcommands the rx parameter is not
170 * a virtual address.
171 */
172int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
173{
174	diag_stat_inc(DIAG_STAT_X014);
175	switch (subcode) {
176	case 0x0:
177	case 0xfff:
178		rx = virt_to_phys((void *)rx);
179		break;
180	default:
181		/* Do nothing */
182		break;
183	}
184	return diag_amode31_ops.diag14(rx, ry1, subcode);
185}
186EXPORT_SYMBOL(diag14);
187
188static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
189{
190	union register_pair rp = { .even = *subcode, .odd = size };
 
191
192	asm volatile(
193		"	diag	%[addr],%[rp],0x204\n"
194		"0:	nopr	%%r7\n"
195		EX_TABLE(0b,0b)
196		: [rp] "+&d" (rp.pair) : [addr] "d" (addr) : "memory");
197	*subcode = rp.even;
198	return rp.odd;
199}
200
201/**
202 * diag204() - Issue diagnose 204 call.
203 * @subcode: Subcode of diagnose 204 to be executed.
204 * @size: Size of area in pages which @area points to, if given.
205 * @addr: Vmalloc'ed memory area where the result is written to.
206 *
207 * Execute diagnose 204 with the given subcode and write the result to the
208 * memory area specified with @addr. For subcodes which do not write a
209 * result to memory both @size and @addr must be zero. If @addr is
210 * specified it must be page aligned and must have been allocated with
211 * vmalloc(). Conversion to real / physical addresses will be handled by
212 * this function if required.
213 */
214int diag204(unsigned long subcode, unsigned long size, void *addr)
215{
216	if (addr) {
217		if (WARN_ON_ONCE(!is_vmalloc_addr(addr)))
218			return -1;
219		if (WARN_ON_ONCE(!IS_ALIGNED((unsigned long)addr, PAGE_SIZE)))
220			return -1;
221	}
222	if ((subcode & DIAG204_SUBCODE_MASK) == DIAG204_SUBC_STIB4)
223		addr = (void *)pfn_to_phys(vmalloc_to_pfn(addr));
224	diag_stat_inc(DIAG_STAT_X204);
225	size = __diag204(&subcode, size, addr);
226	if (subcode)
227		return -1;
228	return size;
229}
230EXPORT_SYMBOL(diag204);
231
232/*
233 * Diagnose 210: Get information about a virtual device
234 */
235int diag210(struct diag210 *addr)
236{
 
 
 
 
 
237	static DEFINE_SPINLOCK(diag210_lock);
238	unsigned long flags;
239	int ccode;
240
241	spin_lock_irqsave(&diag210_lock, flags);
242	*__diag210_tmp_amode31 = *addr;
243
244	diag_stat_inc(DIAG_STAT_X210);
245	ccode = diag_amode31_ops.diag210(__diag210_tmp_amode31);
 
 
 
 
 
 
 
 
246
247	*addr = *__diag210_tmp_amode31;
248	spin_unlock_irqrestore(&diag210_lock, flags);
249
250	return ccode;
251}
252EXPORT_SYMBOL(diag210);
253
254/*
255 * Diagnose 8C: Access 3270 Display Device Information
256 */
257int diag8c(struct diag8c *addr, struct ccw_dev_id *devno)
258{
259	static DEFINE_SPINLOCK(diag8c_lock);
260	unsigned long flags;
261	int ccode;
262
263	spin_lock_irqsave(&diag8c_lock, flags);
264
265	diag_stat_inc(DIAG_STAT_X08C);
266	ccode = diag_amode31_ops.diag8c(__diag8c_tmp_amode31, devno, sizeof(*addr));
267
268	*addr = *__diag8c_tmp_amode31;
269	spin_unlock_irqrestore(&diag8c_lock, flags);
270
271	return ccode;
272}
273EXPORT_SYMBOL(diag8c);
274
275int diag224(void *ptr)
276{
277	unsigned long addr = __pa(ptr);
278	int rc = -EOPNOTSUPP;
279
280	diag_stat_inc(DIAG_STAT_X224);
281	asm volatile(
282		"	diag	%1,%2,0x224\n"
283		"0:	lhi	%0,0x0\n"
284		"1:\n"
285		EX_TABLE(0b,1b)
286		: "+d" (rc) :"d" (0), "d" (addr) : "memory");
287	return rc;
288}
289EXPORT_SYMBOL(diag224);
290
291/*
292 * Diagnose 26C: Access Certain System Information
293 */
294int diag26c(void *req, void *resp, enum diag26c_sc subcode)
295{
296	diag_stat_inc(DIAG_STAT_X26C);
297	return diag_amode31_ops.diag26c(virt_to_phys(req), virt_to_phys(resp), subcode);
298}
299EXPORT_SYMBOL(diag26c);