diag.c 6.6 KB

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