diag.c 5.0 KB

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