i915_request.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. /*
  2. * Copyright © 2008-2018 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_REQUEST_H
  25. #define I915_REQUEST_H
  26. #include <linux/dma-fence.h>
  27. #include <linux/hrtimer.h>
  28. #include <linux/irq_work.h>
  29. #include <linux/llist.h>
  30. #include <linux/lockdep.h>
  31. #include <uapi/drm/i915_drm.h>
  32. #include "gem/i915_gem_context_types.h"
  33. #include "gt/intel_context_types.h"
  34. #include "gt/intel_engine_types.h"
  35. #include "gt/intel_timeline_types.h"
  36. #include "i915_gem.h"
  37. #include "i915_ptr_util.h"
  38. #include "i915_scheduler.h"
  39. #include "i915_selftest.h"
  40. #include "i915_sw_fence.h"
  41. #include "i915_vma_resource.h"
  42. struct drm_file;
  43. struct drm_i915_gem_object;
  44. struct drm_printer;
  45. struct i915_deps;
  46. struct i915_request;
  47. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  48. struct i915_capture_list {
  49. struct i915_vma_resource *vma_res;
  50. struct i915_capture_list *next;
  51. };
  52. void i915_request_free_capture_list(struct i915_capture_list *capture);
  53. #else
  54. #define i915_request_free_capture_list(_a) do {} while (0)
  55. #endif
  56. #define RQ_TRACE(rq, fmt, ...) do { \
  57. const struct i915_request *rq__ = (rq); \
  58. ENGINE_TRACE(rq__->engine, "fence %llx:%lld, current %d " fmt, \
  59. rq__->fence.context, rq__->fence.seqno, \
  60. hwsp_seqno(rq__), ##__VA_ARGS__); \
  61. } while (0)
  62. enum {
  63. /*
  64. * I915_FENCE_FLAG_ACTIVE - this request is currently submitted to HW.
  65. *
  66. * Set by __i915_request_submit() on handing over to HW, and cleared
  67. * by __i915_request_unsubmit() if we preempt this request.
  68. *
  69. * Finally cleared for consistency on retiring the request, when
  70. * we know the HW is no longer running this request.
  71. *
  72. * See i915_request_is_active()
  73. */
  74. I915_FENCE_FLAG_ACTIVE = DMA_FENCE_FLAG_USER_BITS,
  75. /*
  76. * I915_FENCE_FLAG_PQUEUE - this request is ready for execution
  77. *
  78. * Using the scheduler, when a request is ready for execution it is put
  79. * into the priority queue, and removed from that queue when transferred
  80. * to the HW runlists. We want to track its membership within the
  81. * priority queue so that we can easily check before rescheduling.
  82. *
  83. * See i915_request_in_priority_queue()
  84. */
  85. I915_FENCE_FLAG_PQUEUE,
  86. /*
  87. * I915_FENCE_FLAG_HOLD - this request is currently on hold
  88. *
  89. * This request has been suspended, pending an ongoing investigation.
  90. */
  91. I915_FENCE_FLAG_HOLD,
  92. /*
  93. * I915_FENCE_FLAG_INITIAL_BREADCRUMB - this request has the initial
  94. * breadcrumb that marks the end of semaphore waits and start of the
  95. * user payload.
  96. */
  97. I915_FENCE_FLAG_INITIAL_BREADCRUMB,
  98. /*
  99. * I915_FENCE_FLAG_SIGNAL - this request is currently on signal_list
  100. *
  101. * Internal bookkeeping used by the breadcrumb code to track when
  102. * a request is on the various signal_list.
  103. */
  104. I915_FENCE_FLAG_SIGNAL,
  105. /*
  106. * I915_FENCE_FLAG_NOPREEMPT - this request should not be preempted
  107. *
  108. * The execution of some requests should not be interrupted. This is
  109. * a sensitive operation as it makes the request super important,
  110. * blocking other higher priority work. Abuse of this flag will
  111. * lead to quality of service issues.
  112. */
  113. I915_FENCE_FLAG_NOPREEMPT,
  114. /*
  115. * I915_FENCE_FLAG_SENTINEL - this request should be last in the queue
  116. *
  117. * A high priority sentinel request may be submitted to clear the
  118. * submission queue. As it will be the only request in-flight, upon
  119. * execution all other active requests will have been preempted and
  120. * unsubmitted. This preemptive pulse is used to re-evaluate the
  121. * in-flight requests, particularly in cases where an active context
  122. * is banned and those active requests need to be cancelled.
  123. */
  124. I915_FENCE_FLAG_SENTINEL,
  125. /*
  126. * I915_FENCE_FLAG_BOOST - upclock the gpu for this request
  127. *
  128. * Some requests are more important than others! In particular, a
  129. * request that the user is waiting on is typically required for
  130. * interactive latency, for which we want to minimise by upclocking
  131. * the GPU. Here we track such boost requests on a per-request basis.
  132. */
  133. I915_FENCE_FLAG_BOOST,
  134. /*
  135. * I915_FENCE_FLAG_SUBMIT_PARALLEL - request with a context in a
  136. * parent-child relationship (parallel submission, multi-lrc) should
  137. * trigger a submission to the GuC rather than just moving the context
  138. * tail.
  139. */
  140. I915_FENCE_FLAG_SUBMIT_PARALLEL,
  141. /*
  142. * I915_FENCE_FLAG_SKIP_PARALLEL - request with a context in a
  143. * parent-child relationship (parallel submission, multi-lrc) that
  144. * hit an error while generating requests in the execbuf IOCTL.
  145. * Indicates this request should be skipped as another request in
  146. * submission / relationship encountered an error.
  147. */
  148. I915_FENCE_FLAG_SKIP_PARALLEL,
  149. /*
  150. * I915_FENCE_FLAG_COMPOSITE - Indicates fence is part of a composite
  151. * fence (dma_fence_array) and i915 generated for parallel submission.
  152. */
  153. I915_FENCE_FLAG_COMPOSITE,
  154. };
  155. /*
  156. * Request queue structure.
  157. *
  158. * The request queue allows us to note sequence numbers that have been emitted
  159. * and may be associated with active buffers to be retired.
  160. *
  161. * By keeping this list, we can avoid having to do questionable sequence
  162. * number comparisons on buffer last_read|write_seqno. It also allows an
  163. * emission time to be associated with the request for tracking how far ahead
  164. * of the GPU the submission is.
  165. *
  166. * When modifying this structure be very aware that we perform a lockless
  167. * RCU lookup of it that may race against reallocation of the struct
  168. * from the slab freelist. We intentionally do not zero the structure on
  169. * allocation so that the lookup can use the dangling pointers (and is
  170. * cognisant that those pointers may be wrong). Instead, everything that
  171. * needs to be initialised must be done so explicitly.
  172. *
  173. * The requests are reference counted.
  174. */
  175. struct i915_request {
  176. struct dma_fence fence;
  177. spinlock_t lock;
  178. struct drm_i915_private *i915;
  179. /*
  180. * Context and ring buffer related to this request
  181. * Contexts are refcounted, so when this request is associated with a
  182. * context, we must increment the context's refcount, to guarantee that
  183. * it persists while any request is linked to it. Requests themselves
  184. * are also refcounted, so the request will only be freed when the last
  185. * reference to it is dismissed, and the code in
  186. * i915_request_free() will then decrement the refcount on the
  187. * context.
  188. */
  189. struct intel_engine_cs *engine;
  190. struct intel_context *context;
  191. struct intel_ring *ring;
  192. struct intel_timeline __rcu *timeline;
  193. struct list_head signal_link;
  194. struct llist_node signal_node;
  195. /*
  196. * The rcu epoch of when this request was allocated. Used to judiciously
  197. * apply backpressure on future allocations to ensure that under
  198. * mempressure there is sufficient RCU ticks for us to reclaim our
  199. * RCU protected slabs.
  200. */
  201. unsigned long rcustate;
  202. /*
  203. * We pin the timeline->mutex while constructing the request to
  204. * ensure that no caller accidentally drops it during construction.
  205. * The timeline->mutex must be held to ensure that only this caller
  206. * can use the ring and manipulate the associated timeline during
  207. * construction.
  208. */
  209. struct pin_cookie cookie;
  210. /*
  211. * Fences for the various phases in the request's lifetime.
  212. *
  213. * The submit fence is used to await upon all of the request's
  214. * dependencies. When it is signaled, the request is ready to run.
  215. * It is used by the driver to then queue the request for execution.
  216. */
  217. struct i915_sw_fence submit;
  218. union {
  219. wait_queue_entry_t submitq;
  220. struct i915_sw_dma_fence_cb dmaq;
  221. struct i915_request_duration_cb {
  222. struct dma_fence_cb cb;
  223. ktime_t emitted;
  224. } duration;
  225. };
  226. struct llist_head execute_cb;
  227. struct i915_sw_fence semaphore;
  228. /*
  229. * complete submit fence from an IRQ if needed for locking hierarchy
  230. * reasons.
  231. */
  232. struct irq_work submit_work;
  233. /*
  234. * A list of everyone we wait upon, and everyone who waits upon us.
  235. * Even though we will not be submitted to the hardware before the
  236. * submit fence is signaled (it waits for all external events as well
  237. * as our own requests), the scheduler still needs to know the
  238. * dependency tree for the lifetime of the request (from execbuf
  239. * to retirement), i.e. bidirectional dependency information for the
  240. * request not tied to individual fences.
  241. */
  242. struct i915_sched_node sched;
  243. struct i915_dependency dep;
  244. intel_engine_mask_t execution_mask;
  245. /*
  246. * A convenience pointer to the current breadcrumb value stored in
  247. * the HW status page (or our timeline's local equivalent). The full
  248. * path would be rq->hw_context->ring->timeline->hwsp_seqno.
  249. */
  250. const u32 *hwsp_seqno;
  251. /* Position in the ring of the start of the request */
  252. u32 head;
  253. /* Position in the ring of the start of the user packets */
  254. u32 infix;
  255. /*
  256. * Position in the ring of the start of the postfix.
  257. * This is required to calculate the maximum available ring space
  258. * without overwriting the postfix.
  259. */
  260. u32 postfix;
  261. /* Position in the ring of the end of the whole request */
  262. u32 tail;
  263. /* Position in the ring of the end of any workarounds after the tail */
  264. u32 wa_tail;
  265. /* Preallocate space in the ring for the emitting the request */
  266. u32 reserved_space;
  267. /* Batch buffer pointer for selftest internal use. */
  268. I915_SELFTEST_DECLARE(struct i915_vma *batch);
  269. struct i915_vma_resource *batch_res;
  270. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  271. /*
  272. * Additional buffers requested by userspace to be captured upon
  273. * a GPU hang. The vma/obj on this list are protected by their
  274. * active reference - all objects on this list must also be
  275. * on the active_list (of their final request).
  276. */
  277. struct i915_capture_list *capture_list;
  278. #endif
  279. /* Time at which this request was emitted, in jiffies. */
  280. unsigned long emitted_jiffies;
  281. /* timeline->request entry for this request */
  282. struct list_head link;
  283. /* Watchdog support fields. */
  284. struct i915_request_watchdog {
  285. struct llist_node link;
  286. struct hrtimer timer;
  287. } watchdog;
  288. /*
  289. * Requests may need to be stalled when using GuC submission waiting for
  290. * certain GuC operations to complete. If that is the case, stalled
  291. * requests are added to a per context list of stalled requests. The
  292. * below list_head is the link in that list. Protected by
  293. * ce->guc_state.lock.
  294. */
  295. struct list_head guc_fence_link;
  296. /*
  297. * Priority level while the request is in flight. Differs
  298. * from i915 scheduler priority. See comment above
  299. * I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP for details. Protected by
  300. * ce->guc_active.lock. Two special values (GUC_PRIO_INIT and
  301. * GUC_PRIO_FINI) outside the GuC priority range are used to indicate
  302. * if the priority has not been initialized yet or if no more updates
  303. * are possible because the request has completed.
  304. */
  305. #define GUC_PRIO_INIT 0xff
  306. #define GUC_PRIO_FINI 0xfe
  307. u8 guc_prio;
  308. /*
  309. * wait queue entry used to wait on the HuC load to complete
  310. */
  311. wait_queue_entry_t hucq;
  312. I915_SELFTEST_DECLARE(struct {
  313. struct list_head link;
  314. unsigned long delay;
  315. } mock;)
  316. };
  317. #define I915_FENCE_GFP (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
  318. extern const struct dma_fence_ops i915_fence_ops;
  319. static inline bool dma_fence_is_i915(const struct dma_fence *fence)
  320. {
  321. return fence->ops == &i915_fence_ops;
  322. }
  323. struct kmem_cache *i915_request_slab_cache(void);
  324. struct i915_request * __must_check
  325. __i915_request_create(struct intel_context *ce, gfp_t gfp);
  326. struct i915_request * __must_check
  327. i915_request_create(struct intel_context *ce);
  328. void __i915_request_skip(struct i915_request *rq);
  329. bool i915_request_set_error_once(struct i915_request *rq, int error);
  330. struct i915_request *i915_request_mark_eio(struct i915_request *rq);
  331. struct i915_request *__i915_request_commit(struct i915_request *request);
  332. void __i915_request_queue(struct i915_request *rq,
  333. const struct i915_sched_attr *attr);
  334. void __i915_request_queue_bh(struct i915_request *rq);
  335. bool i915_request_retire(struct i915_request *rq);
  336. void i915_request_retire_upto(struct i915_request *rq);
  337. static inline struct i915_request *
  338. to_request(struct dma_fence *fence)
  339. {
  340. /* We assume that NULL fence/request are interoperable */
  341. BUILD_BUG_ON(offsetof(struct i915_request, fence) != 0);
  342. GEM_BUG_ON(fence && !dma_fence_is_i915(fence));
  343. return container_of(fence, struct i915_request, fence);
  344. }
  345. static inline struct i915_request *
  346. i915_request_get(struct i915_request *rq)
  347. {
  348. return to_request(dma_fence_get(&rq->fence));
  349. }
  350. static inline struct i915_request *
  351. i915_request_get_rcu(struct i915_request *rq)
  352. {
  353. return to_request(dma_fence_get_rcu(&rq->fence));
  354. }
  355. static inline void
  356. i915_request_put(struct i915_request *rq)
  357. {
  358. dma_fence_put(&rq->fence);
  359. }
  360. int i915_request_await_object(struct i915_request *to,
  361. struct drm_i915_gem_object *obj,
  362. bool write);
  363. int i915_request_await_dma_fence(struct i915_request *rq,
  364. struct dma_fence *fence);
  365. int i915_request_await_deps(struct i915_request *rq, const struct i915_deps *deps);
  366. int i915_request_await_execution(struct i915_request *rq,
  367. struct dma_fence *fence);
  368. void i915_request_add(struct i915_request *rq);
  369. bool __i915_request_submit(struct i915_request *request);
  370. void i915_request_submit(struct i915_request *request);
  371. void __i915_request_unsubmit(struct i915_request *request);
  372. void i915_request_unsubmit(struct i915_request *request);
  373. void i915_request_cancel(struct i915_request *rq, int error);
  374. long i915_request_wait_timeout(struct i915_request *rq,
  375. unsigned int flags,
  376. long timeout)
  377. __attribute__((nonnull(1)));
  378. long i915_request_wait(struct i915_request *rq,
  379. unsigned int flags,
  380. long timeout)
  381. __attribute__((nonnull(1)));
  382. #define I915_WAIT_INTERRUPTIBLE BIT(0)
  383. #define I915_WAIT_PRIORITY BIT(1) /* small priority bump for the request */
  384. #define I915_WAIT_ALL BIT(2) /* used by i915_gem_object_wait() */
  385. void i915_request_show(struct drm_printer *m,
  386. const struct i915_request *rq,
  387. const char *prefix,
  388. int indent);
  389. static inline bool i915_request_signaled(const struct i915_request *rq)
  390. {
  391. /* The request may live longer than its HWSP, so check flags first! */
  392. return test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &rq->fence.flags);
  393. }
  394. static inline bool i915_request_is_active(const struct i915_request *rq)
  395. {
  396. return test_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
  397. }
  398. static inline bool i915_request_in_priority_queue(const struct i915_request *rq)
  399. {
  400. return test_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
  401. }
  402. static inline bool
  403. i915_request_has_initial_breadcrumb(const struct i915_request *rq)
  404. {
  405. return test_bit(I915_FENCE_FLAG_INITIAL_BREADCRUMB, &rq->fence.flags);
  406. }
  407. /*
  408. * Returns true if seq1 is later than seq2.
  409. */
  410. static inline bool i915_seqno_passed(u32 seq1, u32 seq2)
  411. {
  412. return (s32)(seq1 - seq2) >= 0;
  413. }
  414. static inline u32 __hwsp_seqno(const struct i915_request *rq)
  415. {
  416. const u32 *hwsp = READ_ONCE(rq->hwsp_seqno);
  417. return READ_ONCE(*hwsp);
  418. }
  419. /**
  420. * hwsp_seqno - the current breadcrumb value in the HW status page
  421. * @rq: the request, to chase the relevant HW status page
  422. *
  423. * The emphasis in naming here is that hwsp_seqno() is not a property of the
  424. * request, but an indication of the current HW state (associated with this
  425. * request). Its value will change as the GPU executes more requests.
  426. *
  427. * Returns the current breadcrumb value in the associated HW status page (or
  428. * the local timeline's equivalent) for this request. The request itself
  429. * has the associated breadcrumb value of rq->fence.seqno, when the HW
  430. * status page has that breadcrumb or later, this request is complete.
  431. */
  432. static inline u32 hwsp_seqno(const struct i915_request *rq)
  433. {
  434. u32 seqno;
  435. rcu_read_lock(); /* the HWSP may be freed at runtime */
  436. seqno = __hwsp_seqno(rq);
  437. rcu_read_unlock();
  438. return seqno;
  439. }
  440. static inline bool __i915_request_has_started(const struct i915_request *rq)
  441. {
  442. return i915_seqno_passed(__hwsp_seqno(rq), rq->fence.seqno - 1);
  443. }
  444. /**
  445. * i915_request_started - check if the request has begun being executed
  446. * @rq: the request
  447. *
  448. * If the timeline is not using initial breadcrumbs, a request is
  449. * considered started if the previous request on its timeline (i.e.
  450. * context) has been signaled.
  451. *
  452. * If the timeline is using semaphores, it will also be emitting an
  453. * "initial breadcrumb" after the semaphores are complete and just before
  454. * it began executing the user payload. A request can therefore be active
  455. * on the HW and not yet started as it is still busywaiting on its
  456. * dependencies (via HW semaphores).
  457. *
  458. * If the request has started, its dependencies will have been signaled
  459. * (either by fences or by semaphores) and it will have begun processing
  460. * the user payload.
  461. *
  462. * However, even if a request has started, it may have been preempted and
  463. * so no longer active, or it may have already completed.
  464. *
  465. * See also i915_request_is_active().
  466. *
  467. * Returns true if the request has begun executing the user payload, or
  468. * has completed:
  469. */
  470. static inline bool i915_request_started(const struct i915_request *rq)
  471. {
  472. bool result;
  473. if (i915_request_signaled(rq))
  474. return true;
  475. result = true;
  476. rcu_read_lock(); /* the HWSP may be freed at runtime */
  477. if (likely(!i915_request_signaled(rq)))
  478. /* Remember: started but may have since been preempted! */
  479. result = __i915_request_has_started(rq);
  480. rcu_read_unlock();
  481. return result;
  482. }
  483. /**
  484. * i915_request_is_running - check if the request may actually be executing
  485. * @rq: the request
  486. *
  487. * Returns true if the request is currently submitted to hardware, has passed
  488. * its start point (i.e. the context is setup and not busywaiting). Note that
  489. * it may no longer be running by the time the function returns!
  490. */
  491. static inline bool i915_request_is_running(const struct i915_request *rq)
  492. {
  493. bool result;
  494. if (!i915_request_is_active(rq))
  495. return false;
  496. rcu_read_lock();
  497. result = __i915_request_has_started(rq) && i915_request_is_active(rq);
  498. rcu_read_unlock();
  499. return result;
  500. }
  501. /**
  502. * i915_request_is_ready - check if the request is ready for execution
  503. * @rq: the request
  504. *
  505. * Upon construction, the request is instructed to wait upon various
  506. * signals before it is ready to be executed by the HW. That is, we do
  507. * not want to start execution and read data before it is written. In practice,
  508. * this is controlled with a mixture of interrupts and semaphores. Once
  509. * the submit fence is completed, the backend scheduler will place the
  510. * request into its queue and from there submit it for execution. So we
  511. * can detect when a request is eligible for execution (and is under control
  512. * of the scheduler) by querying where it is in any of the scheduler's lists.
  513. *
  514. * Returns true if the request is ready for execution (it may be inflight),
  515. * false otherwise.
  516. */
  517. static inline bool i915_request_is_ready(const struct i915_request *rq)
  518. {
  519. return !list_empty(&rq->sched.link);
  520. }
  521. static inline bool __i915_request_is_complete(const struct i915_request *rq)
  522. {
  523. return i915_seqno_passed(__hwsp_seqno(rq), rq->fence.seqno);
  524. }
  525. static inline bool i915_request_completed(const struct i915_request *rq)
  526. {
  527. bool result;
  528. if (i915_request_signaled(rq))
  529. return true;
  530. result = true;
  531. rcu_read_lock(); /* the HWSP may be freed at runtime */
  532. if (likely(!i915_request_signaled(rq)))
  533. result = __i915_request_is_complete(rq);
  534. rcu_read_unlock();
  535. return result;
  536. }
  537. static inline void i915_request_mark_complete(struct i915_request *rq)
  538. {
  539. WRITE_ONCE(rq->hwsp_seqno, /* decouple from HWSP */
  540. (u32 *)&rq->fence.seqno);
  541. }
  542. static inline bool i915_request_has_waitboost(const struct i915_request *rq)
  543. {
  544. return test_bit(I915_FENCE_FLAG_BOOST, &rq->fence.flags);
  545. }
  546. static inline bool i915_request_has_nopreempt(const struct i915_request *rq)
  547. {
  548. /* Preemption should only be disabled very rarely */
  549. return unlikely(test_bit(I915_FENCE_FLAG_NOPREEMPT, &rq->fence.flags));
  550. }
  551. static inline bool i915_request_has_sentinel(const struct i915_request *rq)
  552. {
  553. return unlikely(test_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags));
  554. }
  555. static inline bool i915_request_on_hold(const struct i915_request *rq)
  556. {
  557. return unlikely(test_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags));
  558. }
  559. static inline void i915_request_set_hold(struct i915_request *rq)
  560. {
  561. set_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
  562. }
  563. static inline void i915_request_clear_hold(struct i915_request *rq)
  564. {
  565. clear_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
  566. }
  567. static inline struct intel_timeline *
  568. i915_request_timeline(const struct i915_request *rq)
  569. {
  570. /* Valid only while the request is being constructed (or retired). */
  571. return rcu_dereference_protected(rq->timeline,
  572. lockdep_is_held(&rcu_access_pointer(rq->timeline)->mutex) ||
  573. test_bit(CONTEXT_IS_PARKING, &rq->context->flags));
  574. }
  575. static inline struct i915_gem_context *
  576. i915_request_gem_context(const struct i915_request *rq)
  577. {
  578. /* Valid only while the request is being constructed (or retired). */
  579. return rcu_dereference_protected(rq->context->gem_context, true);
  580. }
  581. static inline struct intel_timeline *
  582. i915_request_active_timeline(const struct i915_request *rq)
  583. {
  584. /*
  585. * When in use during submission, we are protected by a guarantee that
  586. * the context/timeline is pinned and must remain pinned until after
  587. * this submission.
  588. */
  589. return rcu_dereference_protected(rq->timeline,
  590. lockdep_is_held(&rq->engine->sched_engine->lock));
  591. }
  592. static inline u32
  593. i915_request_active_seqno(const struct i915_request *rq)
  594. {
  595. u32 hwsp_phys_base =
  596. page_mask_bits(i915_request_active_timeline(rq)->hwsp_offset);
  597. u32 hwsp_relative_offset = offset_in_page(rq->hwsp_seqno);
  598. /*
  599. * Because of wraparound, we cannot simply take tl->hwsp_offset,
  600. * but instead use the fact that the relative for vaddr is the
  601. * offset as for hwsp_offset. Take the top bits from tl->hwsp_offset
  602. * and combine them with the relative offset in rq->hwsp_seqno.
  603. *
  604. * As rw->hwsp_seqno is rewritten when signaled, this only works
  605. * when the request isn't signaled yet, but at that point you
  606. * no longer need the offset.
  607. */
  608. return hwsp_phys_base + hwsp_relative_offset;
  609. }
  610. bool
  611. i915_request_active_engine(struct i915_request *rq,
  612. struct intel_engine_cs **active);
  613. void i915_request_notify_execute_cb_imm(struct i915_request *rq);
  614. enum i915_request_state {
  615. I915_REQUEST_UNKNOWN = 0,
  616. I915_REQUEST_COMPLETE,
  617. I915_REQUEST_PENDING,
  618. I915_REQUEST_QUEUED,
  619. I915_REQUEST_ACTIVE,
  620. };
  621. enum i915_request_state i915_test_request_state(struct i915_request *rq);
  622. void i915_request_module_exit(void);
  623. int i915_request_module_init(void);
  624. #endif /* I915_REQUEST_H */