debugfs.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright(c) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. #include <linux/debugfs.h>
  24. #include <linux/list_sort.h>
  25. #include "i915_drv.h"
  26. #include "gvt.h"
  27. struct mmio_diff_param {
  28. struct intel_vgpu *vgpu;
  29. int total;
  30. int diff;
  31. struct list_head diff_mmio_list;
  32. };
  33. struct diff_mmio {
  34. struct list_head node;
  35. u32 offset;
  36. u32 preg;
  37. u32 vreg;
  38. };
  39. /* Compare two diff_mmio items. */
  40. static int mmio_offset_compare(void *priv,
  41. const struct list_head *a, const struct list_head *b)
  42. {
  43. struct diff_mmio *ma;
  44. struct diff_mmio *mb;
  45. ma = container_of(a, struct diff_mmio, node);
  46. mb = container_of(b, struct diff_mmio, node);
  47. if (ma->offset < mb->offset)
  48. return -1;
  49. else if (ma->offset > mb->offset)
  50. return 1;
  51. return 0;
  52. }
  53. static inline int mmio_diff_handler(struct intel_gvt *gvt,
  54. u32 offset, void *data)
  55. {
  56. struct mmio_diff_param *param = data;
  57. struct diff_mmio *node;
  58. u32 preg, vreg;
  59. preg = intel_uncore_read_notrace(gvt->gt->uncore, _MMIO(offset));
  60. vreg = vgpu_vreg(param->vgpu, offset);
  61. if (preg != vreg) {
  62. node = kmalloc(sizeof(*node), GFP_ATOMIC);
  63. if (!node)
  64. return -ENOMEM;
  65. node->offset = offset;
  66. node->preg = preg;
  67. node->vreg = vreg;
  68. list_add(&node->node, &param->diff_mmio_list);
  69. param->diff++;
  70. }
  71. param->total++;
  72. return 0;
  73. }
  74. /* Show the all the different values of tracked mmio. */
  75. static int vgpu_mmio_diff_show(struct seq_file *s, void *unused)
  76. {
  77. struct intel_vgpu *vgpu = s->private;
  78. struct intel_gvt *gvt = vgpu->gvt;
  79. struct mmio_diff_param param = {
  80. .vgpu = vgpu,
  81. .total = 0,
  82. .diff = 0,
  83. };
  84. struct diff_mmio *node, *next;
  85. INIT_LIST_HEAD(&param.diff_mmio_list);
  86. mutex_lock(&gvt->lock);
  87. spin_lock_bh(&gvt->scheduler.mmio_context_lock);
  88. mmio_hw_access_pre(gvt->gt);
  89. /* Recognize all the diff mmios to list. */
  90. intel_gvt_for_each_tracked_mmio(gvt, mmio_diff_handler, &param);
  91. mmio_hw_access_post(gvt->gt);
  92. spin_unlock_bh(&gvt->scheduler.mmio_context_lock);
  93. mutex_unlock(&gvt->lock);
  94. /* In an ascending order by mmio offset. */
  95. list_sort(NULL, &param.diff_mmio_list, mmio_offset_compare);
  96. seq_printf(s, "%-8s %-8s %-8s %-8s\n", "Offset", "HW", "vGPU", "Diff");
  97. list_for_each_entry_safe(node, next, &param.diff_mmio_list, node) {
  98. u32 diff = node->preg ^ node->vreg;
  99. seq_printf(s, "%08x %08x %08x %*pbl\n",
  100. node->offset, node->preg, node->vreg,
  101. 32, &diff);
  102. list_del(&node->node);
  103. kfree(node);
  104. }
  105. seq_printf(s, "Total: %d, Diff: %d\n", param.total, param.diff);
  106. return 0;
  107. }
  108. DEFINE_SHOW_ATTRIBUTE(vgpu_mmio_diff);
  109. static int
  110. vgpu_scan_nonprivbb_get(void *data, u64 *val)
  111. {
  112. struct intel_vgpu *vgpu = (struct intel_vgpu *)data;
  113. *val = vgpu->scan_nonprivbb;
  114. return 0;
  115. }
  116. /*
  117. * set/unset bit engine_id of vgpu->scan_nonprivbb to turn on/off scanning
  118. * of non-privileged batch buffer. e.g.
  119. * if vgpu->scan_nonprivbb=3, then it will scan non-privileged batch buffer
  120. * on engine 0 and 1.
  121. */
  122. static int
  123. vgpu_scan_nonprivbb_set(void *data, u64 val)
  124. {
  125. struct intel_vgpu *vgpu = (struct intel_vgpu *)data;
  126. vgpu->scan_nonprivbb = val;
  127. return 0;
  128. }
  129. DEFINE_SIMPLE_ATTRIBUTE(vgpu_scan_nonprivbb_fops,
  130. vgpu_scan_nonprivbb_get, vgpu_scan_nonprivbb_set,
  131. "0x%llx\n");
  132. /**
  133. * intel_gvt_debugfs_add_vgpu - register debugfs entries for a vGPU
  134. * @vgpu: a vGPU
  135. */
  136. void intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu)
  137. {
  138. char name[16] = "";
  139. snprintf(name, 16, "vgpu%d", vgpu->id);
  140. vgpu->debugfs = debugfs_create_dir(name, vgpu->gvt->debugfs_root);
  141. debugfs_create_bool("active", 0444, vgpu->debugfs, &vgpu->active);
  142. debugfs_create_file("mmio_diff", 0444, vgpu->debugfs, vgpu,
  143. &vgpu_mmio_diff_fops);
  144. debugfs_create_file("scan_nonprivbb", 0644, vgpu->debugfs, vgpu,
  145. &vgpu_scan_nonprivbb_fops);
  146. }
  147. /**
  148. * intel_gvt_debugfs_remove_vgpu - remove debugfs entries of a vGPU
  149. * @vgpu: a vGPU
  150. */
  151. void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu)
  152. {
  153. struct intel_gvt *gvt = vgpu->gvt;
  154. struct drm_minor *minor = gvt->gt->i915->drm.primary;
  155. if (minor->debugfs_root && gvt->debugfs_root) {
  156. debugfs_remove_recursive(vgpu->debugfs);
  157. vgpu->debugfs = NULL;
  158. }
  159. }
  160. /**
  161. * intel_gvt_debugfs_init - register gvt debugfs root entry
  162. * @gvt: GVT device
  163. */
  164. void intel_gvt_debugfs_init(struct intel_gvt *gvt)
  165. {
  166. struct drm_minor *minor = gvt->gt->i915->drm.primary;
  167. gvt->debugfs_root = debugfs_create_dir("gvt", minor->debugfs_root);
  168. debugfs_create_ulong("num_tracked_mmio", 0444, gvt->debugfs_root,
  169. &gvt->mmio.num_tracked_mmio);
  170. }
  171. /**
  172. * intel_gvt_debugfs_clean - remove debugfs entries
  173. * @gvt: GVT device
  174. */
  175. void intel_gvt_debugfs_clean(struct intel_gvt *gvt)
  176. {
  177. struct drm_minor *minor = gvt->gt->i915->drm.primary;
  178. if (minor->debugfs_root) {
  179. debugfs_remove_recursive(gvt->debugfs_root);
  180. gvt->debugfs_root = NULL;
  181. }
  182. }