i915_gem_timeline.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright © 2016 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. */
  24. #include "i915_drv.h"
  25. static int __i915_gem_timeline_init(struct drm_i915_private *i915,
  26. struct i915_gem_timeline *timeline,
  27. const char *name,
  28. struct lock_class_key *lockclass,
  29. const char *lockname)
  30. {
  31. unsigned int i;
  32. u64 fences;
  33. lockdep_assert_held(&i915->drm.struct_mutex);
  34. timeline->i915 = i915;
  35. timeline->name = kstrdup(name ?: "[kernel]", GFP_KERNEL);
  36. if (!timeline->name)
  37. return -ENOMEM;
  38. list_add(&timeline->link, &i915->gt.timelines);
  39. /* Called during early_init before we know how many engines there are */
  40. fences = dma_fence_context_alloc(ARRAY_SIZE(timeline->engine));
  41. for (i = 0; i < ARRAY_SIZE(timeline->engine); i++) {
  42. struct intel_timeline *tl = &timeline->engine[i];
  43. tl->fence_context = fences++;
  44. tl->common = timeline;
  45. #ifdef CONFIG_DEBUG_SPINLOCK
  46. __raw_spin_lock_init(&tl->lock.rlock, lockname, lockclass);
  47. #else
  48. spin_lock_init(&tl->lock);
  49. #endif
  50. init_request_active(&tl->last_request, NULL);
  51. INIT_LIST_HEAD(&tl->requests);
  52. }
  53. return 0;
  54. }
  55. int i915_gem_timeline_init(struct drm_i915_private *i915,
  56. struct i915_gem_timeline *timeline,
  57. const char *name)
  58. {
  59. static struct lock_class_key class;
  60. return __i915_gem_timeline_init(i915, timeline, name,
  61. &class, "&timeline->lock");
  62. }
  63. int i915_gem_timeline_init__global(struct drm_i915_private *i915)
  64. {
  65. static struct lock_class_key class;
  66. return __i915_gem_timeline_init(i915,
  67. &i915->gt.global_timeline,
  68. "[execution]",
  69. &class, "&global_timeline->lock");
  70. }
  71. void i915_gem_timeline_fini(struct i915_gem_timeline *timeline)
  72. {
  73. int i;
  74. lockdep_assert_held(&timeline->i915->drm.struct_mutex);
  75. for (i = 0; i < ARRAY_SIZE(timeline->engine); i++) {
  76. struct intel_timeline *tl = &timeline->engine[i];
  77. GEM_BUG_ON(!list_empty(&tl->requests));
  78. }
  79. list_del(&timeline->link);
  80. kfree(timeline->name);
  81. }