diag.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <[email protected]>
  7. */
  8. #include <linux/export.h>
  9. #include <linux/init.h>
  10. #include <linux/cpu.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/debugfs.h>
  13. #include <asm/asm-extable.h>
  14. #include <asm/diag.h>
  15. #include <asm/trace/diag.h>
  16. #include <asm/sections.h>
  17. #include "entry.h"
  18. struct diag_stat {
  19. unsigned int counter[NR_DIAG_STAT];
  20. };
  21. static DEFINE_PER_CPU(struct diag_stat, diag_stat);
  22. struct diag_desc {
  23. int code;
  24. char *name;
  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_X26C] = { .code = 0x26c, .name = "Certain System Information" },
  41. [DIAG_STAT_X288] = { .code = 0x288, .name = "Time Bomb" },
  42. [DIAG_STAT_X2C4] = { .code = 0x2c4, .name = "FTP Services" },
  43. [DIAG_STAT_X2FC] = { .code = 0x2fc, .name = "Guest Performance Data" },
  44. [DIAG_STAT_X304] = { .code = 0x304, .name = "Partition-Resource Service" },
  45. [DIAG_STAT_X308] = { .code = 0x308, .name = "List-Directed IPL" },
  46. [DIAG_STAT_X318] = { .code = 0x318, .name = "CP Name and Version Codes" },
  47. [DIAG_STAT_X500] = { .code = 0x500, .name = "Virtio Service" },
  48. };
  49. struct diag_ops __amode31_ref diag_amode31_ops = {
  50. .diag210 = _diag210_amode31,
  51. .diag26c = _diag26c_amode31,
  52. .diag14 = _diag14_amode31,
  53. .diag0c = _diag0c_amode31,
  54. .diag308_reset = _diag308_reset_amode31
  55. };
  56. static struct diag210 _diag210_tmp_amode31 __section(".amode31.data");
  57. struct diag210 __amode31_ref *__diag210_tmp_amode31 = &_diag210_tmp_amode31;
  58. static int show_diag_stat(struct seq_file *m, void *v)
  59. {
  60. struct diag_stat *stat;
  61. unsigned long n = (unsigned long) v - 1;
  62. int cpu, prec, tmp;
  63. cpus_read_lock();
  64. if (n == 0) {
  65. seq_puts(m, " ");
  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. cpus_read_unlock();
  82. return 0;
  83. }
  84. static void *show_diag_stat_start(struct seq_file *m, loff_t *pos)
  85. {
  86. return *pos <= NR_DIAG_STAT ? (void *)((unsigned long) *pos + 1) : NULL;
  87. }
  88. static void *show_diag_stat_next(struct seq_file *m, void *v, loff_t *pos)
  89. {
  90. ++*pos;
  91. return show_diag_stat_start(m, pos);
  92. }
  93. static void show_diag_stat_stop(struct seq_file *m, void *v)
  94. {
  95. }
  96. static const struct seq_operations show_diag_stat_sops = {
  97. .start = show_diag_stat_start,
  98. .next = show_diag_stat_next,
  99. .stop = show_diag_stat_stop,
  100. .show = show_diag_stat,
  101. };
  102. DEFINE_SEQ_ATTRIBUTE(show_diag_stat);
  103. static int __init show_diag_stat_init(void)
  104. {
  105. debugfs_create_file("diag_stat", 0400, NULL, NULL,
  106. &show_diag_stat_fops);
  107. return 0;
  108. }
  109. device_initcall(show_diag_stat_init);
  110. void diag_stat_inc(enum diag_stat_enum nr)
  111. {
  112. this_cpu_inc(diag_stat.counter[nr]);
  113. trace_s390_diagnose(diag_map[nr].code);
  114. }
  115. EXPORT_SYMBOL(diag_stat_inc);
  116. void notrace diag_stat_inc_norecursion(enum diag_stat_enum nr)
  117. {
  118. this_cpu_inc(diag_stat.counter[nr]);
  119. trace_s390_diagnose_norecursion(diag_map[nr].code);
  120. }
  121. EXPORT_SYMBOL(diag_stat_inc_norecursion);
  122. /*
  123. * Diagnose 14: Input spool file manipulation
  124. */
  125. int diag14(unsigned long rx, unsigned long ry1, unsigned long subcode)
  126. {
  127. diag_stat_inc(DIAG_STAT_X014);
  128. return diag_amode31_ops.diag14(rx, ry1, subcode);
  129. }
  130. EXPORT_SYMBOL(diag14);
  131. static inline int __diag204(unsigned long *subcode, unsigned long size, void *addr)
  132. {
  133. union register_pair rp = { .even = *subcode, .odd = size };
  134. asm volatile(
  135. " diag %[addr],%[rp],0x204\n"
  136. "0: nopr %%r7\n"
  137. EX_TABLE(0b,0b)
  138. : [rp] "+&d" (rp.pair) : [addr] "d" (addr) : "memory");
  139. *subcode = rp.even;
  140. return rp.odd;
  141. }
  142. int diag204(unsigned long subcode, unsigned long size, void *addr)
  143. {
  144. diag_stat_inc(DIAG_STAT_X204);
  145. size = __diag204(&subcode, size, addr);
  146. if (subcode)
  147. return -1;
  148. return size;
  149. }
  150. EXPORT_SYMBOL(diag204);
  151. /*
  152. * Diagnose 210: Get information about a virtual device
  153. */
  154. int diag210(struct diag210 *addr)
  155. {
  156. static DEFINE_SPINLOCK(diag210_lock);
  157. unsigned long flags;
  158. int ccode;
  159. spin_lock_irqsave(&diag210_lock, flags);
  160. *__diag210_tmp_amode31 = *addr;
  161. diag_stat_inc(DIAG_STAT_X210);
  162. ccode = diag_amode31_ops.diag210(__diag210_tmp_amode31);
  163. *addr = *__diag210_tmp_amode31;
  164. spin_unlock_irqrestore(&diag210_lock, flags);
  165. return ccode;
  166. }
  167. EXPORT_SYMBOL(diag210);
  168. int diag224(void *ptr)
  169. {
  170. int rc = -EOPNOTSUPP;
  171. diag_stat_inc(DIAG_STAT_X224);
  172. asm volatile(
  173. " diag %1,%2,0x224\n"
  174. "0: lhi %0,0x0\n"
  175. "1:\n"
  176. EX_TABLE(0b,1b)
  177. : "+d" (rc) :"d" (0), "d" (ptr) : "memory");
  178. return rc;
  179. }
  180. EXPORT_SYMBOL(diag224);
  181. /*
  182. * Diagnose 26C: Access Certain System Information
  183. */
  184. int diag26c(void *req, void *resp, enum diag26c_sc subcode)
  185. {
  186. diag_stat_inc(DIAG_STAT_X26C);
  187. return diag_amode31_ops.diag26c(req, resp, subcode);
  188. }
  189. EXPORT_SYMBOL(diag26c);