i915_gem_debug.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. return warned = err;
  110. }
  111. #endif /* WATCH_INACTIVE */
  112. #if WATCH_COHERENCY
  113. void
  114. i915_gem_object_check_coherency(struct drm_i915_gem_object *obj, int handle)
  115. {
  116. struct drm_device *dev = obj->base.dev;
  117. int page;
  118. uint32_t *gtt_mapping;
  119. uint32_t *backing_map = NULL;
  120. int bad_count = 0;
  121. DRM_INFO("%s: checking coherency of object %p@0x%08x (%d, %zdkb):\n",
  122. __func__, obj, obj->gtt_offset, handle,
  123. obj->size / 1024);
  124. gtt_mapping = ioremap(dev_priv->mm.gtt_base_addr + obj->gtt_offset,
  125. obj->base.size);
  126. if (gtt_mapping == NULL) {
  127. DRM_ERROR("failed to map GTT space\n");
  128. return;
  129. }
  130. for (page = 0; page < obj->size / PAGE_SIZE; page++) {
  131. int i;
  132. backing_map = kmap_atomic(obj->pages[page]);
  133. if (backing_map == NULL) {
  134. DRM_ERROR("failed to map backing page\n");
  135. goto out;
  136. }
  137. for (i = 0; i < PAGE_SIZE / 4; i++) {
  138. uint32_t cpuval = backing_map[i];
  139. uint32_t gttval = readl(gtt_mapping +
  140. page * 1024 + i);
  141. if (cpuval != gttval) {
  142. DRM_INFO("incoherent CPU vs GPU at 0x%08x: "
  143. "0x%08x vs 0x%08x\n",
  144. (int)(obj->gtt_offset +
  145. page * PAGE_SIZE + i * 4),
  146. cpuval, gttval);
  147. if (bad_count++ >= 8) {
  148. DRM_INFO("...\n");
  149. goto out;
  150. }
  151. }
  152. }
  153. kunmap_atomic(backing_map);
  154. backing_map = NULL;
  155. }
  156. out:
  157. if (backing_map != NULL)
  158. kunmap_atomic(backing_map);
  159. iounmap(gtt_mapping);
  160. /* give syslog time to catch up */
  161. msleep(1);
  162. /* Directly flush the object, since we just loaded values with the CPU
  163. * from the backing pages and we don't want to disturb the cache
  164. * management that we're trying to observe.
  165. */
  166. i915_gem_clflush_object(obj);
  167. }
  168. #endif