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