i915_gem_debug.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright © 2008 Intel Corporation
  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
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Keith Packard <keithp@keithp.com>
  25. *
  26. */
  27. #include "drmP.h"
  28. #include "drm.h"
  29. #include "i915_drm.h"
  30. #include "i915_drv.h"
  31. #if WATCH_LISTS
  32. int
  33. i915_verify_lists(struct drm_device *dev)
  34. {
  35. static int warned;
  36. drm_i915_private_t *dev_priv = dev->dev_private;
  37. struct drm_i915_gem_object *obj;
  38. int err = 0;
  39. if (warned)
  40. return 0;
  41. list_for_each_entry(obj, &dev_priv->render_ring.active_list, list) {
  42. if (obj->base.dev != dev ||
  43. !atomic_read(&obj->base.refcount.refcount)) {
  44. DRM_ERROR("freed render active %p\n", obj);
  45. err++;
  46. break;
  47. } else if (!obj->active ||
  48. (obj->base.read_domains & I915_GEM_GPU_DOMAINS) == 0) {
  49. DRM_ERROR("invalid render active %p (a %d r %x)\n",
  50. obj,
  51. obj->active,
  52. obj->base.read_domains);
  53. err++;
  54. } else if (obj->base.write_domain && list_empty(&obj->gpu_write_list)) {
  55. DRM_ERROR("invalid render active %p (w %x, gwl %d)\n",
  56. obj,
  57. obj->base.write_domain,
  58. !list_empty(&obj->gpu_write_list));
  59. err++;
  60. }
  61. }
  62. list_for_each_entry(obj, &dev_priv->mm.flushing_list, list) {
  63. if (obj->base.dev != dev ||
  64. !atomic_read(&obj->base.refcount.refcount)) {
  65. DRM_ERROR("freed flushing %p\n", obj);
  66. err++;
  67. break;
  68. } else if (!obj->active ||
  69. (obj->base.write_domain & I915_GEM_GPU_DOMAINS) == 0 ||
  70. list_empty(&obj->gpu_write_list)) {
  71. DRM_ERROR("invalid flushing %p (a %d w %x gwl %d)\n",
  72. obj,
  73. obj->active,
  74. obj->base.write_domain,
  75. !list_empty(&obj->gpu_write_list));
  76. err++;
  77. }
  78. }
  79. list_for_each_entry(obj, &dev_priv->mm.gpu_write_list, gpu_write_list) {
  80. if (obj->base.dev != dev ||
  81. !atomic_read(&obj->base.refcount.refcount)) {
  82. DRM_ERROR("freed gpu write %p\n", obj);
  83. err++;
  84. break;
  85. } else if (!obj->active ||
  86. (obj->base.write_domain & I915_GEM_GPU_DOMAINS) == 0) {
  87. DRM_ERROR("invalid gpu write %p (a %d w %x)\n",
  88. obj,
  89. obj->active,
  90. obj->base.write_domain);
  91. err++;
  92. }
  93. }
  94. list_for_each_entry(obj, &dev_priv->mm.inactive_list, list) {
  95. if (obj->base.dev != dev ||
  96. !atomic_read(&obj->base.refcount.refcount)) {
  97. DRM_ERROR("freed inactive %p\n", obj);
  98. err++;
  99. break;
  100. } else if (obj->pin_count || obj->active ||
  101. (obj->base.write_domain & I915_GEM_GPU_DOMAINS)) {
  102. DRM_ERROR("invalid inactive %p (p %d a %d w %x)\n",
  103. obj,
  104. obj->pin_count, obj->active,
  105. obj->base.write_domain);
  106. err++;
  107. }
  108. }
  109. list_for_each_entry(obj, &dev_priv->mm.pinned_list, list) {
  110. if (obj->base.dev != dev ||
  111. !atomic_read(&obj->base.refcount.refcount)) {
  112. DRM_ERROR("freed pinned %p\n", obj);
  113. err++;
  114. break;
  115. } else if (!obj->pin_count || obj->active ||
  116. (obj->base.write_domain & I915_GEM_GPU_DOMAINS)) {
  117. DRM_ERROR("invalid pinned %p (p %d a %d w %x)\n",
  118. obj,
  119. obj->pin_count, obj->active,
  120. obj->base.write_domain);
  121. err++;
  122. }
  123. }
  124. return warned = err;
  125. }
  126. #endif /* WATCH_INACTIVE */
  127. #if WATCH_COHERENCY
  128. void
  129. i915_gem_object_check_coherency(struct drm_i915_gem_object *obj, int handle)
  130. {
  131. struct drm_device *dev = obj->base.dev;
  132. int page;
  133. uint32_t *gtt_mapping;
  134. uint32_t *backing_map = NULL;
  135. int bad_count = 0;
  136. DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %zdkb):\n",
  137. __func__, obj, obj->gtt_offset, handle,
  138. obj->size / 1024);
  139. gtt_mapping = ioremap(dev->agp->base + obj->gtt_offset, obj->base.size);
  140. if (gtt_mapping == NULL) {
  141. DRM_ERROR("failed to map GTT space\n");
  142. return;
  143. }
  144. for (page = 0; page < obj->size / PAGE_SIZE; page++) {
  145. int i;
  146. backing_map = kmap_atomic(obj->pages[page]);
  147. if (backing_map == NULL) {
  148. DRM_ERROR("failed to map backing page\n");
  149. goto out;
  150. }
  151. for (i = 0; i < PAGE_SIZE / 4; i++) {
  152. uint32_t cpuval = backing_map[i];
  153. uint32_t gttval = readl(gtt_mapping +
  154. page * 1024 + i);
  155. if (cpuval != gttval) {
  156. DRM_INFO("incoherent CPU vs GPU at 0x%08x: "
  157. "0x%08x vs 0x%08x\n",
  158. (int)(obj->gtt_offset +
  159. page * PAGE_SIZE + i * 4),
  160. cpuval, gttval);
  161. if (bad_count++ >= 8) {
  162. DRM_INFO("...\n");
  163. goto out;
  164. }
  165. }
  166. }
  167. kunmap_atomic(backing_map);
  168. backing_map = NULL;
  169. }
  170. out:
  171. if (backing_map != NULL)
  172. kunmap_atomic(backing_map);
  173. iounmap(gtt_mapping);
  174. /* give syslog time to catch up */
  175. msleep(1);
  176. /* Directly flush the object, since we just loaded values with the CPU
  177. * from the backing pages and we don't want to disturb the cache
  178. * management that we're trying to observe.
  179. */
  180. i915_gem_clflush_object(obj);
  181. }
  182. #endif