vas-debug.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright 2016-17 IBM Corp.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #define pr_fmt(fmt) "vas: " fmt
  10. #include <linux/types.h>
  11. #include <linux/slab.h>
  12. #include <linux/debugfs.h>
  13. #include <linux/seq_file.h>
  14. #include "vas.h"
  15. static struct dentry *vas_debugfs;
  16. static char *cop_to_str(int cop)
  17. {
  18. switch (cop) {
  19. case VAS_COP_TYPE_FAULT: return "Fault";
  20. case VAS_COP_TYPE_842: return "NX-842 Normal Priority";
  21. case VAS_COP_TYPE_842_HIPRI: return "NX-842 High Priority";
  22. case VAS_COP_TYPE_GZIP: return "NX-GZIP Normal Priority";
  23. case VAS_COP_TYPE_GZIP_HIPRI: return "NX-GZIP High Priority";
  24. case VAS_COP_TYPE_FTW: return "Fast Thread-wakeup";
  25. default: return "Unknown";
  26. }
  27. }
  28. static int info_dbg_show(struct seq_file *s, void *private)
  29. {
  30. struct vas_window *window = s->private;
  31. mutex_lock(&vas_mutex);
  32. /* ensure window is not unmapped */
  33. if (!window->hvwc_map)
  34. goto unlock;
  35. seq_printf(s, "Type: %s, %s\n", cop_to_str(window->cop),
  36. window->tx_win ? "Send" : "Receive");
  37. seq_printf(s, "Pid : %d\n", window->pid);
  38. unlock:
  39. mutex_unlock(&vas_mutex);
  40. return 0;
  41. }
  42. static int info_dbg_open(struct inode *inode, struct file *file)
  43. {
  44. return single_open(file, info_dbg_show, inode->i_private);
  45. }
  46. static const struct file_operations info_fops = {
  47. .open = info_dbg_open,
  48. .read = seq_read,
  49. .llseek = seq_lseek,
  50. .release = single_release,
  51. };
  52. static inline void print_reg(struct seq_file *s, struct vas_window *win,
  53. char *name, u32 reg)
  54. {
  55. seq_printf(s, "0x%016llx %s\n", read_hvwc_reg(win, name, reg), name);
  56. }
  57. static int hvwc_dbg_show(struct seq_file *s, void *private)
  58. {
  59. struct vas_window *window = s->private;
  60. mutex_lock(&vas_mutex);
  61. /* ensure window is not unmapped */
  62. if (!window->hvwc_map)
  63. goto unlock;
  64. print_reg(s, window, VREG(LPID));
  65. print_reg(s, window, VREG(PID));
  66. print_reg(s, window, VREG(XLATE_MSR));
  67. print_reg(s, window, VREG(XLATE_LPCR));
  68. print_reg(s, window, VREG(XLATE_CTL));
  69. print_reg(s, window, VREG(AMR));
  70. print_reg(s, window, VREG(SEIDR));
  71. print_reg(s, window, VREG(FAULT_TX_WIN));
  72. print_reg(s, window, VREG(OSU_INTR_SRC_RA));
  73. print_reg(s, window, VREG(HV_INTR_SRC_RA));
  74. print_reg(s, window, VREG(PSWID));
  75. print_reg(s, window, VREG(LFIFO_BAR));
  76. print_reg(s, window, VREG(LDATA_STAMP_CTL));
  77. print_reg(s, window, VREG(LDMA_CACHE_CTL));
  78. print_reg(s, window, VREG(LRFIFO_PUSH));
  79. print_reg(s, window, VREG(CURR_MSG_COUNT));
  80. print_reg(s, window, VREG(LNOTIFY_AFTER_COUNT));
  81. print_reg(s, window, VREG(LRX_WCRED));
  82. print_reg(s, window, VREG(LRX_WCRED_ADDER));
  83. print_reg(s, window, VREG(TX_WCRED));
  84. print_reg(s, window, VREG(TX_WCRED_ADDER));
  85. print_reg(s, window, VREG(LFIFO_SIZE));
  86. print_reg(s, window, VREG(WINCTL));
  87. print_reg(s, window, VREG(WIN_STATUS));
  88. print_reg(s, window, VREG(WIN_CTX_CACHING_CTL));
  89. print_reg(s, window, VREG(TX_RSVD_BUF_COUNT));
  90. print_reg(s, window, VREG(LRFIFO_WIN_PTR));
  91. print_reg(s, window, VREG(LNOTIFY_CTL));
  92. print_reg(s, window, VREG(LNOTIFY_PID));
  93. print_reg(s, window, VREG(LNOTIFY_LPID));
  94. print_reg(s, window, VREG(LNOTIFY_TID));
  95. print_reg(s, window, VREG(LNOTIFY_SCOPE));
  96. print_reg(s, window, VREG(NX_UTIL_ADDER));
  97. unlock:
  98. mutex_unlock(&vas_mutex);
  99. return 0;
  100. }
  101. static int hvwc_dbg_open(struct inode *inode, struct file *file)
  102. {
  103. return single_open(file, hvwc_dbg_show, inode->i_private);
  104. }
  105. static const struct file_operations hvwc_fops = {
  106. .open = hvwc_dbg_open,
  107. .read = seq_read,
  108. .llseek = seq_lseek,
  109. .release = single_release,
  110. };
  111. void vas_window_free_dbgdir(struct vas_window *window)
  112. {
  113. if (window->dbgdir) {
  114. debugfs_remove_recursive(window->dbgdir);
  115. kfree(window->dbgname);
  116. window->dbgdir = NULL;
  117. window->dbgname = NULL;
  118. }
  119. }
  120. void vas_window_init_dbgdir(struct vas_window *window)
  121. {
  122. struct dentry *f, *d;
  123. if (!window->vinst->dbgdir)
  124. return;
  125. window->dbgname = kzalloc(16, GFP_KERNEL);
  126. if (!window->dbgname)
  127. return;
  128. snprintf(window->dbgname, 16, "w%d", window->winid);
  129. d = debugfs_create_dir(window->dbgname, window->vinst->dbgdir);
  130. if (IS_ERR(d))
  131. goto free_name;
  132. window->dbgdir = d;
  133. f = debugfs_create_file("info", 0444, d, window, &info_fops);
  134. if (IS_ERR(f))
  135. goto remove_dir;
  136. f = debugfs_create_file("hvwc", 0444, d, window, &hvwc_fops);
  137. if (IS_ERR(f))
  138. goto remove_dir;
  139. return;
  140. remove_dir:
  141. debugfs_remove_recursive(window->dbgdir);
  142. window->dbgdir = NULL;
  143. free_name:
  144. kfree(window->dbgname);
  145. window->dbgname = NULL;
  146. }
  147. void vas_instance_init_dbgdir(struct vas_instance *vinst)
  148. {
  149. struct dentry *d;
  150. vas_init_dbgdir();
  151. if (!vas_debugfs)
  152. return;
  153. vinst->dbgname = kzalloc(16, GFP_KERNEL);
  154. if (!vinst->dbgname)
  155. return;
  156. snprintf(vinst->dbgname, 16, "v%d", vinst->vas_id);
  157. d = debugfs_create_dir(vinst->dbgname, vas_debugfs);
  158. if (IS_ERR(d))
  159. goto free_name;
  160. vinst->dbgdir = d;
  161. return;
  162. free_name:
  163. kfree(vinst->dbgname);
  164. vinst->dbgname = NULL;
  165. vinst->dbgdir = NULL;
  166. }
  167. /*
  168. * Set up the "root" VAS debugfs dir. Return if we already set it up
  169. * (or failed to) in an earlier instance of VAS.
  170. */
  171. void vas_init_dbgdir(void)
  172. {
  173. static bool first_time = true;
  174. if (!first_time)
  175. return;
  176. first_time = false;
  177. vas_debugfs = debugfs_create_dir("vas", NULL);
  178. if (IS_ERR(vas_debugfs))
  179. vas_debugfs = NULL;
  180. }