diag.c 5.8 KB

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