0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/export.h>
0010 #include <linux/init.h>
0011 #include <linux/cpu.h>
0012 #include <linux/seq_file.h>
0013 #include <linux/debugfs.h>
0014 #include <asm/asm-extable.h>
0015 #include <asm/diag.h>
0016 #include <asm/trace/diag.h>
0017 #include <asm/sections.h>
0018 #include "entry.h"
0019
0020 struct diag_stat {
0021 unsigned int counter[NR_DIAG_STAT];
0022 };
0023
0024 static DEFINE_PER_CPU(struct diag_stat, diag_stat);
0025
0026 struct diag_desc {
0027 int code;
0028 char *name;
0029 };
0030
0031 static const struct diag_desc diag_map[NR_DIAG_STAT] = {
0032 [DIAG_STAT_X008] = { .code = 0x008, .name = "Console Function" },
0033 [DIAG_STAT_X00C] = { .code = 0x00c, .name = "Pseudo Timer" },
0034 [DIAG_STAT_X010] = { .code = 0x010, .name = "Release Pages" },
0035 [DIAG_STAT_X014] = { .code = 0x014, .name = "Spool File Services" },
0036 [DIAG_STAT_X044] = { .code = 0x044, .name = "Voluntary Timeslice End" },
0037 [DIAG_STAT_X064] = { .code = 0x064, .name = "NSS Manipulation" },
0038 [DIAG_STAT_X09C] = { .code = 0x09c, .name = "Relinquish Timeslice" },
0039 [DIAG_STAT_X0DC] = { .code = 0x0dc, .name = "Appldata Control" },
0040 [DIAG_STAT_X204] = { .code = 0x204, .name = "Logical-CPU Utilization" },
0041 [DIAG_STAT_X210] = { .code = 0x210, .name = "Device Information" },
0042 [DIAG_STAT_X224] = { .code = 0x224, .name = "EBCDIC-Name Table" },
0043 [DIAG_STAT_X250] = { .code = 0x250, .name = "Block I/O" },
0044 [DIAG_STAT_X258] = { .code = 0x258, .name = "Page-Reference Services" },
0045 [DIAG_STAT_X26C] = { .code = 0x26c, .name = "Certain System Information" },
0046 [DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
0047 [DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
0048 [DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
0049 [DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
0050 [DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
0051 [DIAG_STAT_X318] = { .code = 0x318, .name = "CP Name and Version Codes" },
0052 [DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
0053 };
0054
0055 struct diag_ops __amode31_ref diag_amode31_ops = {
0056 .diag210 = _diag210_amode31,
0057 .diag26c = _diag26c_amode31,
0058 .diag14 = _diag14_amode31,
0059 .diag0c = _diag0c_amode31,
0060 .diag308_reset = _diag308_reset_amode31
0061 };
0062
0063 static struct diag210 _diag210_tmp_amode31 __section(".amode31.data");
0064 struct diag210 __amode31_ref *__diag210_tmp_amode31 = &_diag210_tmp_amode31;
0065
0066 static int show_diag_stat(struct seq_file *m, void *v)
0067 {
0068 struct diag_stat *stat;
0069 unsigned long n = (unsigned long) v - 1;
0070 int cpu, prec, tmp;
0071
0072 cpus_read_lock();
0073 if (n == 0) {
0074 seq_puts(m, " ");
0075
0076 for_each_online_cpu(cpu) {
0077 prec = 10;
0078 for (tmp = 10; cpu >= tmp; tmp *= 10)
0079 prec--;
0080 seq_printf(m, "%*s%d", prec, "CPU", cpu);
0081 }
0082 seq_putc(m, '\n');
0083 } else if (n <= NR_DIAG_STAT) {
0084 seq_printf(m, "diag %03x:", diag_map[n-1].code);
0085 for_each_online_cpu(cpu) {
0086 stat = &per_cpu(diag_stat, cpu);
0087 seq_printf(m, " %10u", stat->counter[n-1]);
0088 }
0089 seq_printf(m, " %s\n", diag_map[n-1].name);
0090 }
0091 cpus_read_unlock();
0092 return 0;
0093 }
0094
0095 static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
0096 {
0097 return *pos <= NR_DIAG_STAT ? (void *)((unsigned long) *pos + 1) : NULL;
0098 }
0099
0100 static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
0101 {
0102 ++*pos;
0103 return show_diag_stat_start(m, pos);
0104 }
0105
0106 static void show_diag_stat_stop(struct seq_file *m, void *v)
0107 {
0108 }
0109
0110 static const struct seq_operations show_diag_stat_sops = {
0111 .start = show_diag_stat_start,
0112 .next = show_diag_stat_next,
0113 .stop = show_diag_stat_stop,
0114 .show = show_diag_stat,
0115 };
0116
0117 DEFINE_SEQ_ATTRIBUTE(show_diag_stat);
0118
0119 static int __init show_diag_stat_init(void)
0120 {
0121 debugfs_create_file("diag_stat", 0400, NULL, NULL,
0122 &show_diag_stat_fops);
0123 return 0;
0124 }
0125
0126 device_initcall(show_diag_stat_init);
0127
0128 void diag_stat_inc(enum diag_stat_enum nr)
0129 {
0130 this_cpu_inc(diag_stat.counter[nr]);
0131 trace_s390_diagnose(diag_map[nr].code);
0132 }
0133 EXPORT_SYMBOL(diag_stat_inc);
0134
0135 void notrace diag_stat_inc_norecursion(enum diag_stat_enum nr)
0136 {
0137 this_cpu_inc(diag_stat.counter[nr]);
0138 trace_s390_diagnose_norecursion(diag_map[nr].code);
0139 }
0140 EXPORT_SYMBOL(diag_stat_inc_norecursion);
0141
0142
0143
0144
0145 int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
0146 {
0147 diag_stat_inc(DIAG_STAT_X014);
0148 return diag_amode31_ops.diag14(rx, ry1, subcode);
0149 }
0150 EXPORT_SYMBOL(diag14);
0151
0152 static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
0153 {
0154 union register_pair rp = { .even = *subcode, .odd = size };
0155
0156 asm volatile(
0157 " diag %[addr],%[rp],0x204\n"
0158 "0: nopr %%r7\n"
0159 EX_TABLE(0b,0b)
0160 : [rp] "+&d" (rp.pair) : [addr] "d" (addr) : "memory");
0161 *subcode = rp.even;
0162 return rp.odd;
0163 }
0164
0165 int diag204(unsigned long subcode, unsigned long size, void *addr)
0166 {
0167 diag_stat_inc(DIAG_STAT_X204);
0168 size = __diag204(&subcode, size, addr);
0169 if (subcode)
0170 return -1;
0171 return size;
0172 }
0173 EXPORT_SYMBOL(diag204);
0174
0175
0176
0177
0178 int diag210(struct diag210 *addr)
0179 {
0180 static DEFINE_SPINLOCK(diag210_lock);
0181 unsigned long flags;
0182 int ccode;
0183
0184 spin_lock_irqsave(&diag210_lock, flags);
0185 *__diag210_tmp_amode31 = *addr;
0186
0187 diag_stat_inc(DIAG_STAT_X210);
0188 ccode = diag_amode31_ops.diag210(__diag210_tmp_amode31);
0189
0190 *addr = *__diag210_tmp_amode31;
0191 spin_unlock_irqrestore(&diag210_lock, flags);
0192
0193 return ccode;
0194 }
0195 EXPORT_SYMBOL(diag210);
0196
0197 int diag224(void *ptr)
0198 {
0199 int rc = -EOPNOTSUPP;
0200
0201 diag_stat_inc(DIAG_STAT_X224);
0202 asm volatile(
0203 " diag %1,%2,0x224\n"
0204 "0: lhi %0,0x0\n"
0205 "1:\n"
0206 EX_TABLE(0b,1b)
0207 : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
0208 return rc;
0209 }
0210 EXPORT_SYMBOL(diag224);
0211
0212
0213
0214
0215 int diag26c(void *req, void *resp, enum diag26c_sc subcode)
0216 {
0217 diag_stat_inc(DIAG_STAT_X26C);
0218 return diag_amode31_ops.diag26c(req, resp, subcode);
0219 }
0220 EXPORT_SYMBOL(diag26c);