nouveau_debugfs.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. * Ben Skeggs <bskeggs@redhat.com>
  28. */
  29. #include <linux/debugfs.h>
  30. #include "drmP.h"
  31. #include "nouveau_drv.h"
  32. #include <ttm/ttm_page_alloc.h>
  33. static int
  34. nouveau_debugfs_channel_info(struct seq_file *m, void *data)
  35. {
  36. struct drm_info_node *node = (struct drm_info_node *) m->private;
  37. struct nouveau_channel *chan = node->info_ent->data;
  38. seq_printf(m, "channel id : %d\n", chan->id);
  39. seq_printf(m, "cpu fifo state:\n");
  40. seq_printf(m, " base: 0x%10llx\n", chan->pushbuf_base);
  41. seq_printf(m, " max: 0x%08x\n", chan->dma.max << 2);
  42. seq_printf(m, " cur: 0x%08x\n", chan->dma.cur << 2);
  43. seq_printf(m, " put: 0x%08x\n", chan->dma.put << 2);
  44. seq_printf(m, " free: 0x%08x\n", chan->dma.free << 2);
  45. if (chan->dma.ib_max) {
  46. seq_printf(m, " ib max: 0x%08x\n", chan->dma.ib_max);
  47. seq_printf(m, " ib put: 0x%08x\n", chan->dma.ib_put);
  48. seq_printf(m, " ib free: 0x%08x\n", chan->dma.ib_free);
  49. }
  50. seq_printf(m, "gpu fifo state:\n");
  51. seq_printf(m, " get: 0x%08x\n",
  52. nvchan_rd32(chan, chan->user_get));
  53. seq_printf(m, " put: 0x%08x\n",
  54. nvchan_rd32(chan, chan->user_put));
  55. if (chan->dma.ib_max) {
  56. seq_printf(m, " ib get: 0x%08x\n",
  57. nvchan_rd32(chan, 0x88));
  58. seq_printf(m, " ib put: 0x%08x\n",
  59. nvchan_rd32(chan, 0x8c));
  60. }
  61. return 0;
  62. }
  63. int
  64. nouveau_debugfs_channel_init(struct nouveau_channel *chan)
  65. {
  66. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  67. struct drm_minor *minor = chan->dev->primary;
  68. int ret;
  69. if (!dev_priv->debugfs.channel_root) {
  70. dev_priv->debugfs.channel_root =
  71. debugfs_create_dir("channel", minor->debugfs_root);
  72. if (!dev_priv->debugfs.channel_root)
  73. return -ENOENT;
  74. }
  75. snprintf(chan->debugfs.name, 32, "%d", chan->id);
  76. chan->debugfs.info.name = chan->debugfs.name;
  77. chan->debugfs.info.show = nouveau_debugfs_channel_info;
  78. chan->debugfs.info.driver_features = 0;
  79. chan->debugfs.info.data = chan;
  80. ret = drm_debugfs_create_files(&chan->debugfs.info, 1,
  81. dev_priv->debugfs.channel_root,
  82. chan->dev->primary);
  83. if (ret == 0)
  84. chan->debugfs.active = true;
  85. return ret;
  86. }
  87. void
  88. nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
  89. {
  90. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  91. if (!chan->debugfs.active)
  92. return;
  93. drm_debugfs_remove_files(&chan->debugfs.info, 1, chan->dev->primary);
  94. chan->debugfs.active = false;
  95. if (chan == dev_priv->channel) {
  96. debugfs_remove(dev_priv->debugfs.channel_root);
  97. dev_priv->debugfs.channel_root = NULL;
  98. }
  99. }
  100. static int
  101. nouveau_debugfs_chipset_info(struct seq_file *m, void *data)
  102. {
  103. struct drm_info_node *node = (struct drm_info_node *) m->private;
  104. struct drm_minor *minor = node->minor;
  105. struct drm_device *dev = minor->dev;
  106. struct drm_nouveau_private *dev_priv = dev->dev_private;
  107. uint32_t ppci_0;
  108. ppci_0 = nv_rd32(dev, dev_priv->chipset >= 0x40 ? 0x88000 : 0x1800);
  109. seq_printf(m, "PMC_BOOT_0: 0x%08x\n", nv_rd32(dev, NV03_PMC_BOOT_0));
  110. seq_printf(m, "PCI ID : 0x%04x:0x%04x\n",
  111. ppci_0 & 0xffff, ppci_0 >> 16);
  112. return 0;
  113. }
  114. static int
  115. nouveau_debugfs_memory_info(struct seq_file *m, void *data)
  116. {
  117. struct drm_info_node *node = (struct drm_info_node *) m->private;
  118. struct drm_minor *minor = node->minor;
  119. struct drm_nouveau_private *dev_priv = minor->dev->dev_private;
  120. seq_printf(m, "VRAM total: %dKiB\n", (int)(dev_priv->vram_size >> 10));
  121. return 0;
  122. }
  123. static int
  124. nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
  125. {
  126. struct drm_info_node *node = (struct drm_info_node *) m->private;
  127. struct drm_nouveau_private *dev_priv = node->minor->dev->dev_private;
  128. int i;
  129. for (i = 0; i < dev_priv->vbios.length; i++)
  130. seq_printf(m, "%c", dev_priv->vbios.data[i]);
  131. return 0;
  132. }
  133. static int
  134. nouveau_debugfs_evict_vram(struct seq_file *m, void *data)
  135. {
  136. struct drm_info_node *node = (struct drm_info_node *) m->private;
  137. struct drm_nouveau_private *dev_priv = node->minor->dev->dev_private;
  138. int ret;
  139. ret = ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
  140. if (ret)
  141. seq_printf(m, "failed: %d", ret);
  142. else
  143. seq_printf(m, "succeeded\n");
  144. return 0;
  145. }
  146. static struct drm_info_list nouveau_debugfs_list[] = {
  147. { "evict_vram", nouveau_debugfs_evict_vram, 0, NULL },
  148. { "chipset", nouveau_debugfs_chipset_info, 0, NULL },
  149. { "memory", nouveau_debugfs_memory_info, 0, NULL },
  150. { "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL },
  151. { "ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL },
  152. { "ttm_dma_page_pool", ttm_dma_page_alloc_debugfs, 0, NULL },
  153. };
  154. #define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
  155. int
  156. nouveau_debugfs_init(struct drm_minor *minor)
  157. {
  158. drm_debugfs_create_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES,
  159. minor->debugfs_root, minor);
  160. return 0;
  161. }
  162. void
  163. nouveau_debugfs_takedown(struct drm_minor *minor)
  164. {
  165. drm_debugfs_remove_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES,
  166. minor);
  167. }