intel_engine_cs.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. #include "intel_ringbuffer.h"
  26. #include "intel_lrc.h"
  27. static const struct engine_info {
  28. const char *name;
  29. unsigned exec_id;
  30. unsigned guc_id;
  31. u32 mmio_base;
  32. unsigned irq_shift;
  33. int (*init_legacy)(struct intel_engine_cs *engine);
  34. int (*init_execlists)(struct intel_engine_cs *engine);
  35. } intel_engines[] = {
  36. [RCS] = {
  37. .name = "render ring",
  38. .exec_id = I915_EXEC_RENDER,
  39. .guc_id = GUC_RENDER_ENGINE,
  40. .mmio_base = RENDER_RING_BASE,
  41. .irq_shift = GEN8_RCS_IRQ_SHIFT,
  42. .init_execlists = logical_render_ring_init,
  43. .init_legacy = intel_init_render_ring_buffer,
  44. },
  45. [BCS] = {
  46. .name = "blitter ring",
  47. .exec_id = I915_EXEC_BLT,
  48. .guc_id = GUC_BLITTER_ENGINE,
  49. .mmio_base = BLT_RING_BASE,
  50. .irq_shift = GEN8_BCS_IRQ_SHIFT,
  51. .init_execlists = logical_xcs_ring_init,
  52. .init_legacy = intel_init_blt_ring_buffer,
  53. },
  54. [VCS] = {
  55. .name = "bsd ring",
  56. .exec_id = I915_EXEC_BSD,
  57. .guc_id = GUC_VIDEO_ENGINE,
  58. .mmio_base = GEN6_BSD_RING_BASE,
  59. .irq_shift = GEN8_VCS1_IRQ_SHIFT,
  60. .init_execlists = logical_xcs_ring_init,
  61. .init_legacy = intel_init_bsd_ring_buffer,
  62. },
  63. [VCS2] = {
  64. .name = "bsd2 ring",
  65. .exec_id = I915_EXEC_BSD,
  66. .guc_id = GUC_VIDEO_ENGINE2,
  67. .mmio_base = GEN8_BSD2_RING_BASE,
  68. .irq_shift = GEN8_VCS2_IRQ_SHIFT,
  69. .init_execlists = logical_xcs_ring_init,
  70. .init_legacy = intel_init_bsd2_ring_buffer,
  71. },
  72. [VECS] = {
  73. .name = "video enhancement ring",
  74. .exec_id = I915_EXEC_VEBOX,
  75. .guc_id = GUC_VIDEOENHANCE_ENGINE,
  76. .mmio_base = VEBOX_RING_BASE,
  77. .irq_shift = GEN8_VECS_IRQ_SHIFT,
  78. .init_execlists = logical_xcs_ring_init,
  79. .init_legacy = intel_init_vebox_ring_buffer,
  80. },
  81. };
  82. static struct intel_engine_cs *
  83. intel_engine_setup(struct drm_i915_private *dev_priv,
  84. enum intel_engine_id id)
  85. {
  86. const struct engine_info *info = &intel_engines[id];
  87. struct intel_engine_cs *engine = &dev_priv->engine[id];
  88. engine->id = id;
  89. engine->i915 = dev_priv;
  90. engine->name = info->name;
  91. engine->exec_id = info->exec_id;
  92. engine->hw_id = engine->guc_id = info->guc_id;
  93. engine->mmio_base = info->mmio_base;
  94. engine->irq_shift = info->irq_shift;
  95. return engine;
  96. }
  97. /**
  98. * intel_engines_init() - allocate, populate and init the Engine Command Streamers
  99. * @dev: DRM device.
  100. *
  101. * Return: non-zero if the initialization failed.
  102. */
  103. int intel_engines_init(struct drm_device *dev)
  104. {
  105. struct drm_i915_private *dev_priv = to_i915(dev);
  106. unsigned int mask = 0;
  107. int (*init)(struct intel_engine_cs *engine);
  108. unsigned int i;
  109. int ret;
  110. WARN_ON(INTEL_INFO(dev_priv)->ring_mask == 0);
  111. WARN_ON(INTEL_INFO(dev_priv)->ring_mask &
  112. GENMASK(sizeof(mask) * BITS_PER_BYTE - 1, I915_NUM_ENGINES));
  113. for (i = 0; i < ARRAY_SIZE(intel_engines); i++) {
  114. if (!HAS_ENGINE(dev_priv, i))
  115. continue;
  116. if (i915.enable_execlists)
  117. init = intel_engines[i].init_execlists;
  118. else
  119. init = intel_engines[i].init_legacy;
  120. if (!init)
  121. continue;
  122. ret = init(intel_engine_setup(dev_priv, i));
  123. if (ret)
  124. goto cleanup;
  125. mask |= ENGINE_MASK(i);
  126. }
  127. /*
  128. * Catch failures to update intel_engines table when the new engines
  129. * are added to the driver by a warning and disabling the forgotten
  130. * engines.
  131. */
  132. if (WARN_ON(mask != INTEL_INFO(dev_priv)->ring_mask)) {
  133. struct intel_device_info *info =
  134. (struct intel_device_info *)&dev_priv->info;
  135. info->ring_mask = mask;
  136. }
  137. return 0;
  138. cleanup:
  139. for (i = 0; i < I915_NUM_ENGINES; i++) {
  140. if (i915.enable_execlists)
  141. intel_logical_ring_cleanup(&dev_priv->engine[i]);
  142. else
  143. intel_engine_cleanup(&dev_priv->engine[i]);
  144. }
  145. return ret;
  146. }
  147. void intel_engine_init_hangcheck(struct intel_engine_cs *engine)
  148. {
  149. memset(&engine->hangcheck, 0, sizeof(engine->hangcheck));
  150. }
  151. /**
  152. * intel_engines_setup_common - setup engine state not requiring hw access
  153. * @engine: Engine to setup.
  154. *
  155. * Initializes @engine@ structure members shared between legacy and execlists
  156. * submission modes which do not require hardware access.
  157. *
  158. * Typically done early in the submission mode specific engine setup stage.
  159. */
  160. void intel_engine_setup_common(struct intel_engine_cs *engine)
  161. {
  162. INIT_LIST_HEAD(&engine->request_list);
  163. INIT_LIST_HEAD(&engine->buffers);
  164. INIT_LIST_HEAD(&engine->execlist_queue);
  165. spin_lock_init(&engine->execlist_lock);
  166. engine->fence_context = fence_context_alloc(1);
  167. intel_engine_init_hangcheck(engine);
  168. i915_gem_batch_pool_init(&engine->i915->drm, &engine->batch_pool);
  169. }
  170. /**
  171. * intel_engines_init_common - initialize cengine state which might require hw access
  172. * @engine: Engine to initialize.
  173. *
  174. * Initializes @engine@ structure members shared between legacy and execlists
  175. * submission modes which do require hardware access.
  176. *
  177. * Typcally done at later stages of submission mode specific engine setup.
  178. *
  179. * Returns zero on success or an error code on failure.
  180. */
  181. int intel_engine_init_common(struct intel_engine_cs *engine)
  182. {
  183. int ret;
  184. ret = intel_engine_init_breadcrumbs(engine);
  185. if (ret)
  186. return ret;
  187. return intel_engine_init_cmd_parser(engine);
  188. }
  189. /**
  190. * intel_engines_cleanup_common - cleans up the engine state created by
  191. * the common initiailizers.
  192. * @engine: Engine to cleanup.
  193. *
  194. * This cleans up everything created by the common helpers.
  195. */
  196. void intel_engine_cleanup_common(struct intel_engine_cs *engine)
  197. {
  198. intel_engine_cleanup_cmd_parser(engine);
  199. intel_engine_fini_breadcrumbs(engine);
  200. i915_gem_batch_pool_fini(&engine->batch_pool);
  201. }