Linux Audio

Check our new training course

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