i915_gem_request.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * Copyright © 2008-2015 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. #ifndef I915_GEM_REQUEST_H
  25. #define I915_GEM_REQUEST_H
  26. #include <linux/fence.h>
  27. #include "i915_gem.h"
  28. /**
  29. * Request queue structure.
  30. *
  31. * The request queue allows us to note sequence numbers that have been emitted
  32. * and may be associated with active buffers to be retired.
  33. *
  34. * By keeping this list, we can avoid having to do questionable sequence
  35. * number comparisons on buffer last_read|write_seqno. It also allows an
  36. * emission time to be associated with the request for tracking how far ahead
  37. * of the GPU the submission is.
  38. *
  39. * The requests are reference counted.
  40. */
  41. struct drm_i915_gem_request {
  42. struct fence fence;
  43. spinlock_t lock;
  44. /** On Which ring this request was generated */
  45. struct drm_i915_private *i915;
  46. /**
  47. * Context and ring buffer related to this request
  48. * Contexts are refcounted, so when this request is associated with a
  49. * context, we must increment the context's refcount, to guarantee that
  50. * it persists while any request is linked to it. Requests themselves
  51. * are also refcounted, so the request will only be freed when the last
  52. * reference to it is dismissed, and the code in
  53. * i915_gem_request_free() will then decrement the refcount on the
  54. * context.
  55. */
  56. struct i915_gem_context *ctx;
  57. struct intel_engine_cs *engine;
  58. struct intel_ring *ring;
  59. struct intel_signal_node signaling;
  60. /** GEM sequence number associated with the previous request,
  61. * when the HWS breadcrumb is equal to this the GPU is processing
  62. * this request.
  63. */
  64. u32 previous_seqno;
  65. /** Position in the ringbuffer of the start of the request */
  66. u32 head;
  67. /**
  68. * Position in the ringbuffer of the start of the postfix.
  69. * This is required to calculate the maximum available ringbuffer
  70. * space without overwriting the postfix.
  71. */
  72. u32 postfix;
  73. /** Position in the ringbuffer of the end of the whole request */
  74. u32 tail;
  75. /** Preallocate space in the ringbuffer for the emitting the request */
  76. u32 reserved_space;
  77. /**
  78. * Context related to the previous request.
  79. * As the contexts are accessed by the hardware until the switch is
  80. * completed to a new context, the hardware may still be writing
  81. * to the context object after the breadcrumb is visible. We must
  82. * not unpin/unbind/prune that object whilst still active and so
  83. * we keep the previous context pinned until the following (this)
  84. * request is retired.
  85. */
  86. struct i915_gem_context *previous_context;
  87. /** Batch buffer related to this request if any (used for
  88. * error state dump only).
  89. */
  90. struct drm_i915_gem_object *batch_obj;
  91. /** Time at which this request was emitted, in jiffies. */
  92. unsigned long emitted_jiffies;
  93. /** global list entry for this request */
  94. struct list_head list;
  95. struct drm_i915_file_private *file_priv;
  96. /** file_priv list entry for this request */
  97. struct list_head client_list;
  98. /** process identifier submitting this request */
  99. struct pid *pid;
  100. /**
  101. * The ELSP only accepts two elements at a time, so we queue
  102. * context/tail pairs on a given queue (ring->execlist_queue) until the
  103. * hardware is available. The queue serves a double purpose: we also use
  104. * it to keep track of the up to 2 contexts currently in the hardware
  105. * (usually one in execution and the other queued up by the GPU): We
  106. * only remove elements from the head of the queue when the hardware
  107. * informs us that an element has been completed.
  108. *
  109. * All accesses to the queue are mediated by a spinlock
  110. * (ring->execlist_lock).
  111. */
  112. /** Execlist link in the submission queue.*/
  113. struct list_head execlist_link;
  114. /** Execlists no. of times this request has been sent to the ELSP */
  115. int elsp_submitted;
  116. /** Execlists context hardware id. */
  117. unsigned int ctx_hw_id;
  118. };
  119. extern const struct fence_ops i915_fence_ops;
  120. static inline bool fence_is_i915(struct fence *fence)
  121. {
  122. return fence->ops == &i915_fence_ops;
  123. }
  124. struct drm_i915_gem_request * __must_check
  125. i915_gem_request_alloc(struct intel_engine_cs *engine,
  126. struct i915_gem_context *ctx);
  127. int i915_gem_request_add_to_client(struct drm_i915_gem_request *req,
  128. struct drm_file *file);
  129. void i915_gem_request_retire_upto(struct drm_i915_gem_request *req);
  130. static inline u32
  131. i915_gem_request_get_seqno(struct drm_i915_gem_request *req)
  132. {
  133. return req ? req->fence.seqno : 0;
  134. }
  135. static inline struct intel_engine_cs *
  136. i915_gem_request_get_engine(struct drm_i915_gem_request *req)
  137. {
  138. return req ? req->engine : NULL;
  139. }
  140. static inline struct drm_i915_gem_request *
  141. to_request(struct fence *fence)
  142. {
  143. /* We assume that NULL fence/request are interoperable */
  144. BUILD_BUG_ON(offsetof(struct drm_i915_gem_request, fence) != 0);
  145. GEM_BUG_ON(fence && !fence_is_i915(fence));
  146. return container_of(fence, struct drm_i915_gem_request, fence);
  147. }
  148. static inline struct drm_i915_gem_request *
  149. i915_gem_request_get(struct drm_i915_gem_request *req)
  150. {
  151. return to_request(fence_get(&req->fence));
  152. }
  153. static inline void
  154. i915_gem_request_put(struct drm_i915_gem_request *req)
  155. {
  156. fence_put(&req->fence);
  157. }
  158. static inline void i915_gem_request_assign(struct drm_i915_gem_request **pdst,
  159. struct drm_i915_gem_request *src)
  160. {
  161. if (src)
  162. i915_gem_request_get(src);
  163. if (*pdst)
  164. i915_gem_request_put(*pdst);
  165. *pdst = src;
  166. }
  167. void __i915_add_request(struct drm_i915_gem_request *req,
  168. struct drm_i915_gem_object *batch_obj,
  169. bool flush_caches);
  170. #define i915_add_request(req) \
  171. __i915_add_request(req, NULL, true)
  172. #define i915_add_request_no_flush(req) \
  173. __i915_add_request(req, NULL, false)
  174. struct intel_rps_client;
  175. #define NO_WAITBOOST ERR_PTR(-1)
  176. #define IS_RPS_CLIENT(p) (!IS_ERR(p))
  177. #define IS_RPS_USER(p) (!IS_ERR_OR_NULL(p))
  178. int __i915_wait_request(struct drm_i915_gem_request *req,
  179. bool interruptible,
  180. s64 *timeout,
  181. struct intel_rps_client *rps);
  182. int __must_check i915_wait_request(struct drm_i915_gem_request *req);
  183. static inline u32 intel_engine_get_seqno(struct intel_engine_cs *engine);
  184. /**
  185. * Returns true if seq1 is later than seq2.
  186. */
  187. static inline bool i915_seqno_passed(u32 seq1, u32 seq2)
  188. {
  189. return (s32)(seq1 - seq2) >= 0;
  190. }
  191. static inline bool
  192. i915_gem_request_started(const struct drm_i915_gem_request *req)
  193. {
  194. return i915_seqno_passed(intel_engine_get_seqno(req->engine),
  195. req->previous_seqno);
  196. }
  197. static inline bool
  198. i915_gem_request_completed(const struct drm_i915_gem_request *req)
  199. {
  200. return i915_seqno_passed(intel_engine_get_seqno(req->engine),
  201. req->fence.seqno);
  202. }
  203. bool __i915_spin_request(const struct drm_i915_gem_request *request,
  204. int state, unsigned long timeout_us);
  205. static inline bool i915_spin_request(const struct drm_i915_gem_request *request,
  206. int state, unsigned long timeout_us)
  207. {
  208. return (i915_gem_request_started(request) &&
  209. __i915_spin_request(request, state, timeout_us));
  210. }
  211. #endif /* I915_GEM_REQUEST_H */