1 // SPDX-License-Identifier: GPL-2.0
3 * Implementation of s390 diagnose codes
5 * Copyright IBM Corp. 2007
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>
17 #include <asm/trace/diag.h>
18 #include <asm/sections.h>
22 unsigned int counter[NR_DIAG_STAT];
25 static DEFINE_PER_CPU(struct diag_stat, diag_stat);
32 static 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" },
58 struct 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
67 static struct diag210 _diag210_tmp_amode31 __section(".amode31.data");
68 struct diag210 __amode31_ref *__diag210_tmp_amode31 = &_diag210_tmp_amode31;
70 static struct diag8c _diag8c_tmp_amode31 __section(".amode31.data");
71 static struct diag8c __amode31_ref *__diag8c_tmp_amode31 = &_diag8c_tmp_amode31;
73 static int show_diag_stat(struct seq_file *m, void *v)
75 struct diag_stat *stat;
76 unsigned long n = (unsigned long) v - 1;
83 for_each_online_cpu(cpu) {
85 for (tmp = 10; cpu >= tmp; tmp *= 10)
87 seq_printf(m, "%*s%d", prec, "CPU", cpu);
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]);
96 seq_printf(m, " %s\n", diag_map[n-1].name);
102 static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
104 return *pos <= NR_DIAG_STAT ? (void *)((unsigned long) *pos + 1) : NULL;
107 static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
110 return show_diag_stat_start(m, pos);
113 static void show_diag_stat_stop(struct seq_file *m, void *v)
117 static 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,
124 DEFINE_SEQ_ATTRIBUTE(show_diag_stat);
126 static int __init show_diag_stat_init(void)
128 debugfs_create_file("diag_stat", 0400, NULL, NULL,
129 &show_diag_stat_fops);
133 device_initcall(show_diag_stat_init);
135 void diag_stat_inc(enum diag_stat_enum nr)
137 this_cpu_inc(diag_stat.counter[nr]);
138 trace_s390_diagnose(diag_map[nr].code);
140 EXPORT_SYMBOL(diag_stat_inc);
142 void notrace diag_stat_inc_norecursion(enum diag_stat_enum nr)
144 this_cpu_inc(diag_stat.counter[nr]);
145 trace_s390_diagnose_norecursion(diag_map[nr].code);
147 EXPORT_SYMBOL(diag_stat_inc_norecursion);
150 * Diagnose 0c: Pseudo Timer
152 void diag0c(struct hypfs_diag0c_entry *data)
154 diag_stat_inc(DIAG_STAT_X00C);
155 diag_amode31_ops.diag0c(virt_to_phys(data));
159 * Diagnose 14: Input spool file manipulation
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
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
172 int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
174 diag_stat_inc(DIAG_STAT_X014);
178 rx = virt_to_phys((void *)rx);
184 return diag_amode31_ops.diag14(rx, ry1, subcode);
186 EXPORT_SYMBOL(diag14);
188 static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
190 union register_pair rp = { .even = *subcode, .odd = size };
193 " diag %[addr],%[rp],0x204\n"
196 : [rp] "+&d" (rp.pair) : [addr] "d" (addr) : "memory");
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.
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.
214 int diag204(unsigned long subcode, unsigned long size, void *addr)
217 if (WARN_ON_ONCE(!is_vmalloc_addr(addr)))
219 if (WARN_ON_ONCE(!IS_ALIGNED((unsigned long)addr, PAGE_SIZE)))
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);
230 EXPORT_SYMBOL(diag204);
233 * Diagnose 210: Get information about a virtual device
235 int diag210(struct diag210 *addr)
237 static DEFINE_SPINLOCK(diag210_lock);
241 spin_lock_irqsave(&diag210_lock, flags);
242 *__diag210_tmp_amode31 = *addr;
244 diag_stat_inc(DIAG_STAT_X210);
245 ccode = diag_amode31_ops.diag210(__diag210_tmp_amode31);
247 *addr = *__diag210_tmp_amode31;
248 spin_unlock_irqrestore(&diag210_lock, flags);
252 EXPORT_SYMBOL(diag210);
255 * Diagnose 8C: Access 3270 Display Device Information
257 int diag8c(struct diag8c *addr, struct ccw_dev_id *devno)
259 static DEFINE_SPINLOCK(diag8c_lock);
263 spin_lock_irqsave(&diag8c_lock, flags);
265 diag_stat_inc(DIAG_STAT_X08C);
266 ccode = diag_amode31_ops.diag8c(__diag8c_tmp_amode31, devno, sizeof(*addr));
268 *addr = *__diag8c_tmp_amode31;
269 spin_unlock_irqrestore(&diag8c_lock, flags);
273 EXPORT_SYMBOL(diag8c);
275 int diag224(void *ptr)
277 unsigned long addr = __pa(ptr);
278 int rc = -EOPNOTSUPP;
280 diag_stat_inc(DIAG_STAT_X224);
282 " diag %1,%2,0x224\n"
286 : "+d" (rc) :"d" (0), "d" (addr) : "memory");
289 EXPORT_SYMBOL(diag224);
292 * Diagnose 26C: Access Certain System Information
294 int diag26c(void *req, void *resp, enum diag26c_sc subcode)
296 diag_stat_inc(DIAG_STAT_X26C);
297 return diag_amode31_ops.diag26c(virt_to_phys(req), virt_to_phys(resp), subcode);
299 EXPORT_SYMBOL(diag26c);