qxl_debugfs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (C) 2009 Red Hat <bskeggs@redhat.com>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files (the
  6. * "Software"), to deal in the Software without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Software, and to
  9. * permit persons to whom the Software is furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the
  13. * next paragraph) shall be included in all copies or substantial
  14. * portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. */
  25. /*
  26. * Authors:
  27. * Alon Levy <alevy@redhat.com>
  28. */
  29. #include <linux/debugfs.h>
  30. #include "drmP.h"
  31. #include "qxl_drv.h"
  32. #include "qxl_object.h"
  33. #if defined(CONFIG_DEBUG_FS)
  34. static int
  35. qxl_debugfs_irq_received(struct seq_file *m, void *data)
  36. {
  37. struct drm_info_node *node = (struct drm_info_node *) m->private;
  38. struct qxl_device *qdev = node->minor->dev->dev_private;
  39. seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
  40. seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
  41. seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
  42. seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
  43. seq_printf(m, "%d\n", qdev->irq_received_error);
  44. return 0;
  45. }
  46. static int
  47. qxl_debugfs_buffers_info(struct seq_file *m, void *data)
  48. {
  49. struct drm_info_node *node = (struct drm_info_node *) m->private;
  50. struct qxl_device *qdev = node->minor->dev->dev_private;
  51. struct qxl_bo *bo;
  52. list_for_each_entry(bo, &qdev->gem.objects, list) {
  53. struct reservation_object_list *fobj;
  54. int rel;
  55. rcu_read_lock();
  56. fobj = rcu_dereference(bo->tbo.resv->fence);
  57. rel = fobj ? fobj->shared_count : 0;
  58. rcu_read_unlock();
  59. seq_printf(m, "size %ld, pc %d, num releases %d\n",
  60. (unsigned long)bo->gem_base.size,
  61. bo->pin_count, rel);
  62. }
  63. return 0;
  64. }
  65. static struct drm_info_list qxl_debugfs_list[] = {
  66. { "irq_received", qxl_debugfs_irq_received, 0, NULL },
  67. { "qxl_buffers", qxl_debugfs_buffers_info, 0, NULL },
  68. };
  69. #define QXL_DEBUGFS_ENTRIES ARRAY_SIZE(qxl_debugfs_list)
  70. #endif
  71. int
  72. qxl_debugfs_init(struct drm_minor *minor)
  73. {
  74. #if defined(CONFIG_DEBUG_FS)
  75. int r;
  76. struct qxl_device *dev =
  77. (struct qxl_device *) minor->dev->dev_private;
  78. drm_debugfs_create_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES,
  79. minor->debugfs_root, minor);
  80. r = qxl_ttm_debugfs_init(dev);
  81. if (r) {
  82. DRM_ERROR("Failed to init TTM debugfs\n");
  83. return r;
  84. }
  85. #endif
  86. return 0;
  87. }
  88. void
  89. qxl_debugfs_takedown(struct drm_minor *minor)
  90. {
  91. #if defined(CONFIG_DEBUG_FS)
  92. drm_debugfs_remove_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES,
  93. minor);
  94. #endif
  95. }
  96. int qxl_debugfs_add_files(struct qxl_device *qdev,
  97. struct drm_info_list *files,
  98. unsigned nfiles)
  99. {
  100. unsigned i;
  101. for (i = 0; i < qdev->debugfs_count; i++) {
  102. if (qdev->debugfs[i].files == files) {
  103. /* Already registered */
  104. return 0;
  105. }
  106. }
  107. i = qdev->debugfs_count + 1;
  108. if (i > QXL_DEBUGFS_MAX_COMPONENTS) {
  109. DRM_ERROR("Reached maximum number of debugfs components.\n");
  110. DRM_ERROR("Report so we increase QXL_DEBUGFS_MAX_COMPONENTS.\n");
  111. return -EINVAL;
  112. }
  113. qdev->debugfs[qdev->debugfs_count].files = files;
  114. qdev->debugfs[qdev->debugfs_count].num_files = nfiles;
  115. qdev->debugfs_count = i;
  116. #if defined(CONFIG_DEBUG_FS)
  117. drm_debugfs_create_files(files, nfiles,
  118. qdev->ddev->primary->debugfs_root,
  119. qdev->ddev->primary);
  120. #endif
  121. return 0;
  122. }
  123. void qxl_debugfs_remove_files(struct qxl_device *qdev)
  124. {
  125. #if defined(CONFIG_DEBUG_FS)
  126. unsigned i;
  127. for (i = 0; i < qdev->debugfs_count; i++) {
  128. drm_debugfs_remove_files(qdev->debugfs[i].files,
  129. qdev->debugfs[i].num_files,
  130. qdev->ddev->primary);
  131. }
  132. #endif
  133. }