Merge tag 'hyperv-next-signed-20230902' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / arch / s390 / kernel / diag.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
0a87c5cf
MH
2/*
3 * Implementation of s390 diagnose codes
4 *
5 * Copyright IBM Corp. 2007
6 * Author(s): Michael Holzheu <holzheu@de.ibm.com>
7 */
8
3994a52b
PG
9#include <linux/export.h>
10#include <linux/init.h>
1ec2772e
MS
11#include <linux/cpu.h>
12#include <linux/seq_file.h>
13#include <linux/debugfs.h>
83f95671 14#include <linux/vmalloc.h>
d09a307f 15#include <asm/asm-extable.h>
0a87c5cf 16#include <asm/diag.h>
b5a6b71b 17#include <asm/trace/diag.h>
a80313ff 18#include <asm/sections.h>
6bda6670 19#include "entry.h"
0a87c5cf 20
b5a6b71b
MS
21struct diag_stat {
22 unsigned int counter[NR_DIAG_STAT];
23};
24
25static DEFINE_PER_CPU(struct diag_stat, diag_stat);
1ec2772e
MS
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" },
fbaee746 39 [DIAG_STAT_X08C] = { .code = 0x08c, .name = "Access 3270 Display Device Information" },
1ec2772e
MS
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" },
1b030478 47 [DIAG_STAT_X26C] = { .code = 0x26c, .name = "Certain System Information" },
1ec2772e
MS
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" },
4ad78b86 53 [DIAG_STAT_X318] = { .code = 0x318, .name = "CP Name and Version Codes" },
8cf57d72 54 [DIAG_STAT_X320] = { .code = 0x320, .name = "Certificate Store" },
1ec2772e
MS
55 [DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
56};
57
c78d0c74
HC
58struct diag_ops __amode31_ref diag_amode31_ops = {
59 .diag210 = _diag210_amode31,
60 .diag26c = _diag26c_amode31,
61 .diag14 = _diag14_amode31,
62 .diag0c = _diag0c_amode31,
fbaee746 63 .diag8c = _diag8c_amode31,
c78d0c74 64 .diag308_reset = _diag308_reset_amode31
6bda6670
AE
65};
66
c78d0c74
HC
67static struct diag210 _diag210_tmp_amode31 __section(".amode31.data");
68struct diag210 __amode31_ref *__diag210_tmp_amode31 = &_diag210_tmp_amode31;
a80313ff 69
fbaee746 70static struct diag8c _diag8c_tmp_amode31 __section(".amode31.data");
18e5cb7a 71static struct diag8c __amode31_ref *__diag8c_tmp_amode31 = &_diag8c_tmp_amode31;
fbaee746 72
1ec2772e
MS
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
a73de293 79 cpus_read_lock();
1ec2772e
MS
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 }
a73de293 98 cpus_read_unlock();
1ec2772e
MS
99 return 0;
100}
101
102static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
103{
6c7c851f 104 return *pos <= NR_DIAG_STAT ? (void *)((unsigned long) *pos + 1) : NULL;
1ec2772e
MS
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
61f2e774 124DEFINE_SEQ_ATTRIBUTE(show_diag_stat);
1ec2772e
MS
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
b5a6b71b
MS
135void diag_stat_inc(enum diag_stat_enum nr)
136{
137 this_cpu_inc(diag_stat.counter[nr]);
230ccb37 138 trace_s390_diagnose(diag_map[nr].code);
b5a6b71b
MS
139}
140EXPORT_SYMBOL(diag_stat_inc);
141
8ebf6da9 142void notrace diag_stat_inc_norecursion(enum diag_stat_enum nr)
b5a6b71b
MS
143{
144 this_cpu_inc(diag_stat.counter[nr]);
230ccb37 145 trace_s390_diagnose_norecursion(diag_map[nr].code);
b5a6b71b
MS
146}
147EXPORT_SYMBOL(diag_stat_inc_norecursion);
148
0a87c5cf
MH
149/*
150 * Diagnose 14: Input spool file manipulation
151 */
1ec2772e
MS
152int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
153{
154 diag_stat_inc(DIAG_STAT_X014);
c78d0c74 155 return diag_amode31_ops.diag14(rx, ry1, subcode);
1ec2772e 156}
0a87c5cf
MH
157EXPORT_SYMBOL(diag14);
158
221bb8a4 159static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
e65f30e0 160{
3c45a07b 161 union register_pair rp = { .even = *subcode, .odd = size };
e65f30e0
JF
162
163 asm volatile(
3c45a07b 164 " diag %[addr],%[rp],0x204\n"
221bb8a4 165 "0: nopr %%r7\n"
e65f30e0 166 EX_TABLE(0b,0b)
3c45a07b
HC
167 : [rp] "+&d" (rp.pair) : [addr] "d" (addr) : "memory");
168 *subcode = rp.even;
169 return rp.odd;
e65f30e0
JF
170}
171
83f95671
HC
172/**
173 * diag204() - Issue diagnose 204 call.
174 * @subcode: Subcode of diagnose 204 to be executed.
175 * @size: Size of area in pages which @area points to, if given.
176 * @addr: Vmalloc'ed memory area where the result is written to.
177 *
178 * Execute diagnose 204 with the given subcode and write the result to the
179 * memory area specified with @addr. For subcodes which do not write a
180 * result to memory both @size and @addr must be zero. If @addr is
181 * specified it must be page aligned and must have been allocated with
182 * vmalloc(). Conversion to real / physical addresses will be handled by
183 * this function if required.
184 */
e65f30e0
JF
185int diag204(unsigned long subcode, unsigned long size, void *addr)
186{
83f95671
HC
187 if (addr) {
188 if (WARN_ON_ONCE(!is_vmalloc_addr(addr)))
189 return -1;
190 if (WARN_ON_ONCE(!IS_ALIGNED((unsigned long)addr, PAGE_SIZE)))
191 return -1;
192 }
c83cd4fe 193 if ((subcode & DIAG204_SUBCODE_MASK) == DIAG204_SUBC_STIB4)
83f95671
HC
194 addr = (void *)pfn_to_phys(vmalloc_to_pfn(addr));
195 diag_stat_inc(DIAG_STAT_X204);
221bb8a4
LT
196 size = __diag204(&subcode, size, addr);
197 if (subcode)
198 return -1;
199 return size;
e65f30e0
JF
200}
201EXPORT_SYMBOL(diag204);
202
0a87c5cf
MH
203/*
204 * Diagnose 210: Get information about a virtual device
205 */
206int diag210(struct diag210 *addr)
207{
0a87c5cf
MH
208 static DEFINE_SPINLOCK(diag210_lock);
209 unsigned long flags;
210 int ccode;
211
212 spin_lock_irqsave(&diag210_lock, flags);
c78d0c74 213 *__diag210_tmp_amode31 = *addr;
0a87c5cf 214
1ec2772e 215 diag_stat_inc(DIAG_STAT_X210);
c78d0c74 216 ccode = diag_amode31_ops.diag210(__diag210_tmp_amode31);
a80313ff 217
c78d0c74 218 *addr = *__diag210_tmp_amode31;
0a87c5cf
MH
219 spin_unlock_irqrestore(&diag210_lock, flags);
220
221 return ccode;
222}
223EXPORT_SYMBOL(diag210);
022bd2d1 224
fbaee746 225/*
e8104873 226 * Diagnose 8C: Access 3270 Display Device Information
fbaee746
SS
227 */
228int diag8c(struct diag8c *addr, struct ccw_dev_id *devno)
229{
230 static DEFINE_SPINLOCK(diag8c_lock);
231 unsigned long flags;
232 int ccode;
233
234 spin_lock_irqsave(&diag8c_lock, flags);
235
236 diag_stat_inc(DIAG_STAT_X08C);
237 ccode = diag_amode31_ops.diag8c(__diag8c_tmp_amode31, devno, sizeof(*addr));
238
239 *addr = *__diag8c_tmp_amode31;
240 spin_unlock_irqrestore(&diag8c_lock, flags);
241
242 return ccode;
243}
244EXPORT_SYMBOL(diag8c);
245
022bd2d1
JF
246int diag224(void *ptr)
247{
248 int rc = -EOPNOTSUPP;
249
250 diag_stat_inc(DIAG_STAT_X224);
251 asm volatile(
252 " diag %1,%2,0x224\n"
253 "0: lhi %0,0x0\n"
254 "1:\n"
255 EX_TABLE(0b,1b)
256 : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
257 return rc;
258}
259EXPORT_SYMBOL(diag224);
1b030478
JW
260
261/*
262 * Diagnose 26C: Access Certain System Information
263 */
1b030478
JW
264int diag26c(void *req, void *resp, enum diag26c_sc subcode)
265{
266 diag_stat_inc(DIAG_STAT_X26C);
c78d0c74 267 return diag_amode31_ops.diag26c(req, resp, subcode);
1b030478
JW
268}
269EXPORT_SYMBOL(diag26c);