Loading...
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/diag.h>
15#include <asm/trace/diag.h>
16#include <asm/sections.h>
17
18struct diag_stat {
19 unsigned int counter[NR_DIAG_STAT];
20};
21
22static DEFINE_PER_CPU(struct diag_stat, diag_stat);
23
24struct diag_desc {
25 int code;
26 char *name;
27};
28
29static const struct diag_desc diag_map[NR_DIAG_STAT] = {
30 [DIAG_STAT_X008] = { .code = 0x008, .name = "Console Function" },
31 [DIAG_STAT_X00C] = { .code = 0x00c, .name = "Pseudo Timer" },
32 [DIAG_STAT_X010] = { .code = 0x010, .name = "Release Pages" },
33 [DIAG_STAT_X014] = { .code = 0x014, .name = "Spool File Services" },
34 [DIAG_STAT_X044] = { .code = 0x044, .name = "Voluntary Timeslice End" },
35 [DIAG_STAT_X064] = { .code = 0x064, .name = "NSS Manipulation" },
36 [DIAG_STAT_X09C] = { .code = 0x09c, .name = "Relinquish Timeslice" },
37 [DIAG_STAT_X0DC] = { .code = 0x0dc, .name = "Appldata Control" },
38 [DIAG_STAT_X204] = { .code = 0x204, .name = "Logical-CPU Utilization" },
39 [DIAG_STAT_X210] = { .code = 0x210, .name = "Device Information" },
40 [DIAG_STAT_X224] = { .code = 0x224, .name = "EBCDIC-Name Table" },
41 [DIAG_STAT_X250] = { .code = 0x250, .name = "Block I/O" },
42 [DIAG_STAT_X258] = { .code = 0x258, .name = "Page-Reference Services" },
43 [DIAG_STAT_X26C] = { .code = 0x26c, .name = "Certain System Information" },
44 [DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
45 [DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
46 [DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
47 [DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
48 [DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
49 [DIAG_STAT_X318] = { .code = 0x318, .name = "CP Name and Version Codes" },
50 [DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
51};
52
53struct diag_ops __bootdata_preserved(diag_dma_ops);
54struct diag210 *__bootdata_preserved(__diag210_tmp_dma);
55
56static int show_diag_stat(struct seq_file *m, void *v)
57{
58 struct diag_stat *stat;
59 unsigned long n = (unsigned long) v - 1;
60 int cpu, prec, tmp;
61
62 get_online_cpus();
63 if (n == 0) {
64 seq_puts(m, " ");
65
66 for_each_online_cpu(cpu) {
67 prec = 10;
68 for (tmp = 10; cpu >= tmp; tmp *= 10)
69 prec--;
70 seq_printf(m, "%*s%d", prec, "CPU", cpu);
71 }
72 seq_putc(m, '\n');
73 } else if (n <= NR_DIAG_STAT) {
74 seq_printf(m, "diag %03x:", diag_map[n-1].code);
75 for_each_online_cpu(cpu) {
76 stat = &per_cpu(diag_stat, cpu);
77 seq_printf(m, " %10u", stat->counter[n-1]);
78 }
79 seq_printf(m, " %s\n", diag_map[n-1].name);
80 }
81 put_online_cpus();
82 return 0;
83}
84
85static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
86{
87 return *pos <= nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
88}
89
90static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
91{
92 ++*pos;
93 return show_diag_stat_start(m, pos);
94}
95
96static void show_diag_stat_stop(struct seq_file *m, void *v)
97{
98}
99
100static const struct seq_operations show_diag_stat_sops = {
101 .start = show_diag_stat_start,
102 .next = show_diag_stat_next,
103 .stop = show_diag_stat_stop,
104 .show = show_diag_stat,
105};
106
107static int show_diag_stat_open(struct inode *inode, struct file *file)
108{
109 return seq_open(file, &show_diag_stat_sops);
110}
111
112static const struct file_operations show_diag_stat_fops = {
113 .open = show_diag_stat_open,
114 .read = seq_read,
115 .llseek = seq_lseek,
116 .release = seq_release,
117};
118
119
120static int __init show_diag_stat_init(void)
121{
122 debugfs_create_file("diag_stat", 0400, NULL, NULL,
123 &show_diag_stat_fops);
124 return 0;
125}
126
127device_initcall(show_diag_stat_init);
128
129void diag_stat_inc(enum diag_stat_enum nr)
130{
131 this_cpu_inc(diag_stat.counter[nr]);
132 trace_s390_diagnose(diag_map[nr].code);
133}
134EXPORT_SYMBOL(diag_stat_inc);
135
136void diag_stat_inc_norecursion(enum diag_stat_enum nr)
137{
138 this_cpu_inc(diag_stat.counter[nr]);
139 trace_s390_diagnose_norecursion(diag_map[nr].code);
140}
141EXPORT_SYMBOL(diag_stat_inc_norecursion);
142
143/*
144 * Diagnose 14: Input spool file manipulation
145 */
146int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
147{
148 diag_stat_inc(DIAG_STAT_X014);
149 return diag_dma_ops.diag14(rx, ry1, subcode);
150}
151EXPORT_SYMBOL(diag14);
152
153static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
154{
155 register unsigned long _subcode asm("0") = *subcode;
156 register unsigned long _size asm("1") = size;
157
158 asm volatile(
159 " diag %2,%0,0x204\n"
160 "0: nopr %%r7\n"
161 EX_TABLE(0b,0b)
162 : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
163 *subcode = _subcode;
164 return _size;
165}
166
167int diag204(unsigned long subcode, unsigned long size, void *addr)
168{
169 diag_stat_inc(DIAG_STAT_X204);
170 size = __diag204(&subcode, size, addr);
171 if (subcode)
172 return -1;
173 return size;
174}
175EXPORT_SYMBOL(diag204);
176
177/*
178 * Diagnose 210: Get information about a virtual device
179 */
180int diag210(struct diag210 *addr)
181{
182 static DEFINE_SPINLOCK(diag210_lock);
183 unsigned long flags;
184 int ccode;
185
186 spin_lock_irqsave(&diag210_lock, flags);
187 *__diag210_tmp_dma = *addr;
188
189 diag_stat_inc(DIAG_STAT_X210);
190 ccode = diag_dma_ops.diag210(__diag210_tmp_dma);
191
192 *addr = *__diag210_tmp_dma;
193 spin_unlock_irqrestore(&diag210_lock, flags);
194
195 return ccode;
196}
197EXPORT_SYMBOL(diag210);
198
199int diag224(void *ptr)
200{
201 int rc = -EOPNOTSUPP;
202
203 diag_stat_inc(DIAG_STAT_X224);
204 asm volatile(
205 " diag %1,%2,0x224\n"
206 "0: lhi %0,0x0\n"
207 "1:\n"
208 EX_TABLE(0b,1b)
209 : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
210 return rc;
211}
212EXPORT_SYMBOL(diag224);
213
214/*
215 * Diagnose 26C: Access Certain System Information
216 */
217int diag26c(void *req, void *resp, enum diag26c_sc subcode)
218{
219 diag_stat_inc(DIAG_STAT_X26C);
220 return diag_dma_ops.diag26c(req, resp, subcode);
221}
222EXPORT_SYMBOL(diag26c);
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/diag.h>
15#include <asm/trace/diag.h>
16
17struct diag_stat {
18 unsigned int counter[NR_DIAG_STAT];
19};
20
21static DEFINE_PER_CPU(struct diag_stat, diag_stat);
22
23struct diag_desc {
24 int code;
25 char *name;
26};
27
28static 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" },
49};
50
51static int show_diag_stat(struct seq_file *m, void *v)
52{
53 struct diag_stat *stat;
54 unsigned long n = (unsigned long) v - 1;
55 int cpu, prec, tmp;
56
57 get_online_cpus();
58 if (n == 0) {
59 seq_puts(m, " ");
60
61 for_each_online_cpu(cpu) {
62 prec = 10;
63 for (tmp = 10; cpu >= tmp; tmp *= 10)
64 prec--;
65 seq_printf(m, "%*s%d", prec, "CPU", cpu);
66 }
67 seq_putc(m, '\n');
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]);
73 }
74 seq_printf(m, " %s\n", diag_map[n-1].name);
75 }
76 put_online_cpus();
77 return 0;
78}
79
80static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
81{
82 return *pos <= nr_cpu_ids ? (void *)((unsigned long) *pos + 1) : NULL;
83}
84
85static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
86{
87 ++*pos;
88 return show_diag_stat_start(m, pos);
89}
90
91static void show_diag_stat_stop(struct seq_file *m, void *v)
92{
93}
94
95static 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,
100};
101
102static int show_diag_stat_open(struct inode *inode, struct file *file)
103{
104 return seq_open(file, &show_diag_stat_sops);
105}
106
107static const struct file_operations show_diag_stat_fops = {
108 .open = show_diag_stat_open,
109 .read = seq_read,
110 .llseek = seq_lseek,
111 .release = seq_release,
112};
113
114
115static int __init show_diag_stat_init(void)
116{
117 debugfs_create_file("diag_stat", 0400, NULL, NULL,
118 &show_diag_stat_fops);
119 return 0;
120}
121
122device_initcall(show_diag_stat_init);
123
124void diag_stat_inc(enum diag_stat_enum nr)
125{
126 this_cpu_inc(diag_stat.counter[nr]);
127 trace_s390_diagnose(diag_map[nr].code);
128}
129EXPORT_SYMBOL(diag_stat_inc);
130
131void diag_stat_inc_norecursion(enum diag_stat_enum nr)
132{
133 this_cpu_inc(diag_stat.counter[nr]);
134 trace_s390_diagnose_norecursion(diag_map[nr].code);
135}
136EXPORT_SYMBOL(diag_stat_inc_norecursion);
137
138/*
139 * Diagnose 14: Input spool file manipulation
140 */
141static inline int __diag14(unsigned long rx, unsigned long ry1,
142 unsigned long subcode)
143{
144 register unsigned long _ry1 asm("2") = ry1;
145 register unsigned long _ry2 asm("3") = subcode;
146 int rc = 0;
147
148 asm volatile(
149 " sam31\n"
150 " diag %2,2,0x14\n"
151 " sam64\n"
152 " ipm %0\n"
153 " srl %0,28\n"
154 : "=d" (rc), "+d" (_ry2)
155 : "d" (rx), "d" (_ry1)
156 : "cc");
157
158 return rc;
159}
160
161int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
162{
163 diag_stat_inc(DIAG_STAT_X014);
164 return __diag14(rx, ry1, subcode);
165}
166EXPORT_SYMBOL(diag14);
167
168static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
169{
170 register unsigned long _subcode asm("0") = *subcode;
171 register unsigned long _size asm("1") = size;
172
173 asm volatile(
174 " diag %2,%0,0x204\n"
175 "0: nopr %%r7\n"
176 EX_TABLE(0b,0b)
177 : "+d" (_subcode), "+d" (_size) : "d" (addr) : "memory");
178 *subcode = _subcode;
179 return _size;
180}
181
182int diag204(unsigned long subcode, unsigned long size, void *addr)
183{
184 diag_stat_inc(DIAG_STAT_X204);
185 size = __diag204(&subcode, size, addr);
186 if (subcode)
187 return -1;
188 return size;
189}
190EXPORT_SYMBOL(diag204);
191
192/*
193 * Diagnose 210: Get information about a virtual device
194 */
195int diag210(struct diag210 *addr)
196{
197 /*
198 * diag 210 needs its data below the 2GB border, so we
199 * use a static data area to be sure
200 */
201 static struct diag210 diag210_tmp;
202 static DEFINE_SPINLOCK(diag210_lock);
203 unsigned long flags;
204 int ccode;
205
206 spin_lock_irqsave(&diag210_lock, flags);
207 diag210_tmp = *addr;
208
209 diag_stat_inc(DIAG_STAT_X210);
210 asm volatile(
211 " lhi %0,-1\n"
212 " sam31\n"
213 " diag %1,0,0x210\n"
214 "0: ipm %0\n"
215 " srl %0,28\n"
216 "1: sam64\n"
217 EX_TABLE(0b, 1b)
218 : "=&d" (ccode) : "a" (&diag210_tmp) : "cc", "memory");
219
220 *addr = diag210_tmp;
221 spin_unlock_irqrestore(&diag210_lock, flags);
222
223 return ccode;
224}
225EXPORT_SYMBOL(diag210);
226
227int diag224(void *ptr)
228{
229 int rc = -EOPNOTSUPP;
230
231 diag_stat_inc(DIAG_STAT_X224);
232 asm volatile(
233 " diag %1,%2,0x224\n"
234 "0: lhi %0,0x0\n"
235 "1:\n"
236 EX_TABLE(0b,1b)
237 : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
238 return rc;
239}
240EXPORT_SYMBOL(diag224);
241
242/*
243 * Diagnose 26C: Access Certain System Information
244 */
245static inline int __diag26c(void *req, void *resp, enum diag26c_sc subcode)
246{
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;
251
252 asm volatile(
253 " sam31\n"
254 " diag %[rx],%[ry],0x26c\n"
255 "0: sam64\n"
256 EX_TABLE(0b,0b)
257 : "+d" (_rc)
258 : [rx] "d" (_req), "d" (_resp), [ry] "d" (_subcode)
259 : "cc", "memory");
260 return _rc;
261}
262
263int diag26c(void *req, void *resp, enum diag26c_sc subcode)
264{
265 diag_stat_inc(DIAG_STAT_X26C);
266 return __diag26c(req, resp, subcode);
267}
268EXPORT_SYMBOL(diag26c);