i915_request.h 23 KB

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