1 // SPDX-License-Identifier: GPL-2.0
3 * Implementation of s390 diagnose codes
5 * Copyright IBM Corp. 2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
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>
15 #include <asm/trace/diag.h>
18 unsigned int counter[NR_DIAG_STAT];
21 static DEFINE_PER_CPU(struct diag_stat, diag_stat);
28 static const struct diag_desc diag_map[NR_DIAG_STAT] = {
29 [DIAG_STAT_X008] = { .code = 0x008, .name = "Console Function" },
30 [DIAG_STAT_X00C] = { .code = 0x00c, .name = "Pseudo Timer" },
31 [DIAG_STAT_X010] = { .code = 0x010, .name = "Release Pages" },
32 [DIAG_STAT_X014] = { .code = 0x014, .name = "Spool File Services" },
33 [DIAG_STAT_X044] = { .code = 0x044, .name = "Voluntary Timeslice End" },
34 [DIAG_STAT_X064] = { .code = 0x064, .name = "NSS Manipulation" },
35 [DIAG_STAT_X09C] = { .code = 0x09c, .name = "Relinquish Timeslice" },
36 [DIAG_STAT_X0DC] = { .code = 0x0dc, .name = "Appldata Control" },
37 [DIAG_STAT_X204] = { .code = 0x204, .name = "Logical-CPU Utilization" },
38 [DIAG_STAT_X210] = { .code = 0x210, .name = "Device Information" },
39 [DIAG_STAT_X224] = { .code = 0x224, .name = "EBCDIC-Name Table" },
40 [DIAG_STAT_X250] = { .code = 0x250, .name = "Block I/O" },
41 [DIAG_STAT_X258] = { .code = 0x258, .name = "Page-Reference Services" },
42 [DIAG_STAT_X26C] = { .code = 0x26c, .name = "Certain System Information" },
43 [DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
44 [DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
45 [DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
46 [DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
47 [DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
48 [DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
51 static int show_diag_stat(struct seq_file *m, void *v)
53 struct diag_stat *stat;
54 unsigned long n = (unsigned long) v - 1;
61 for_each_online_cpu(cpu) {
63 for (tmp = 10; cpu >= tmp; tmp *= 10)
65 seq_printf(m, "%*s%d", prec, "CPU", cpu);
68 } else if (n <= NR_DIAG_STAT) {
69 seq_printf(m, "diag %03x:", diag_map[n-1].code);
70 for_each_online_cpu(cpu) {
71 stat = &per_cpu(diag_stat, cpu);
72 seq_printf(m, " %10u", stat->counter[n-1]);
74 seq_printf(m, " %s\n", diag_map[n-1].name);
80 static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
82 return *pos <= nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
85 static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
88 return show_diag_stat_start(m, pos);
91 static void show_diag_stat_stop(struct seq_file *m, void *v)
95 static const struct seq_operations show_diag_stat_sops = {
96 .start = show_diag_stat_start,
97 .next = show_diag_stat_next,
98 .stop = show_diag_stat_stop,
99 .show = show_diag_stat,
102 static int show_diag_stat_open(struct inode *inode, struct file *file)
104 return seq_open(file, &show_diag_stat_sops);
107 static const struct file_operations show_diag_stat_fops = {
108 .open = show_diag_stat_open,
111 .release = seq_release,
115 static int __init show_diag_stat_init(void)
117 debugfs_create_file("diag_stat", 0400, NULL, NULL,
118 &show_diag_stat_fops);
122 device_initcall(show_diag_stat_init);
124 void diag_stat_inc(enum diag_stat_enum nr)
126 this_cpu_inc(diag_stat.counter[nr]);
127 trace_s390_diagnose(diag_map[nr].code);
129 EXPORT_SYMBOL(diag_stat_inc);
131 void diag_stat_inc_norecursion(enum diag_stat_enum nr)
133 this_cpu_inc(diag_stat.counter[nr]);
134 trace_s390_diagnose_norecursion(diag_map[nr].code);
136 EXPORT_SYMBOL(diag_stat_inc_norecursion);
139 * Diagnose 14: Input spool file manipulation
141 static inline int __diag14(unsigned long rx, unsigned long ry1,
142 unsigned long subcode)
144 register unsigned long _ry1 asm("2") = ry1;
145 register unsigned long _ry2 asm("3") = subcode;
154 : "=d" (rc), "+d" (_ry2)
155 : "d" (rx), "d" (_ry1)
161 int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
163 diag_stat_inc(DIAG_STAT_X014);
164 return __diag14(rx, ry1, subcode);
166 EXPORT_SYMBOL(diag14);
168 static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
170 register unsigned long _subcode asm("0") = *subcode;
171 register unsigned long _size asm("1") = size;
174 " diag %2,%0,0x204\n"
177 : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
182 int diag204(unsigned long subcode, unsigned long size, void *addr)
184 diag_stat_inc(DIAG_STAT_X204);
185 size = __diag204(&subcode, size, addr);
190 EXPORT_SYMBOL(diag204);
193 * Diagnose 210: Get information about a virtual device
195 int diag210(struct diag210 *addr)
198 * diag 210 needs its data below the 2GB border, so we
199 * use a static data area to be sure
201 static struct diag210 diag210_tmp;
202 static DEFINE_SPINLOCK(diag210_lock);
206 spin_lock_irqsave(&diag210_lock, flags);
209 diag_stat_inc(DIAG_STAT_X210);
218 : "=&d" (ccode) : "a" (&diag210_tmp) : "cc", "memory");
221 spin_unlock_irqrestore(&diag210_lock, flags);
225 EXPORT_SYMBOL(diag210);
227 int diag224(void *ptr)
229 int rc = -EOPNOTSUPP;
231 diag_stat_inc(DIAG_STAT_X224);
233 " diag %1,%2,0x224\n"
237 : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
240 EXPORT_SYMBOL(diag224);
243 * Diagnose 26C: Access Certain System Information
245 static inline int __diag26c(void *req, void *resp, enum diag26c_sc subcode)
247 register unsigned long _req asm("2") = (addr_t) req;
248 register unsigned long _resp asm("3") = (addr_t) resp;
249 register unsigned long _subcode asm("4") = subcode;
250 register unsigned long _rc asm("5") = -EOPNOTSUPP;
254 " diag %[rx],%[ry],0x26c\n"
258 : [rx] "d" (_req), "d" (_resp), [ry] "d" (_subcode)
263 int diag26c(void *req, void *resp, enum diag26c_sc subcode)
265 diag_stat_inc(DIAG_STAT_X26C);
266 return __diag26c(req, resp, subcode);
268 EXPORT_SYMBOL(diag26c);