intel_ringbuffer.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #ifndef _INTEL_RINGBUFFER_H_
  2. #define _INTEL_RINGBUFFER_H_
  3. /*
  4. * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
  5. * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
  6. * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
  7. *
  8. * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
  9. * cacheline, the Head Pointer must not be greater than the Tail
  10. * Pointer."
  11. */
  12. #define I915_RING_FREE_SPACE 64
  13. struct intel_hw_status_page {
  14. u32 *page_addr;
  15. unsigned int gfx_addr;
  16. struct drm_i915_gem_object *obj;
  17. };
  18. #define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
  19. #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
  20. #define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base))
  21. #define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
  22. #define I915_READ_HEAD(ring) I915_READ(RING_HEAD((ring)->mmio_base))
  23. #define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
  24. #define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base))
  25. #define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
  26. #define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base))
  27. #define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
  28. enum intel_ring_hangcheck_action {
  29. HANGCHECK_IDLE = 0,
  30. HANGCHECK_WAIT,
  31. HANGCHECK_ACTIVE,
  32. HANGCHECK_KICK,
  33. HANGCHECK_HUNG,
  34. };
  35. struct intel_ring_hangcheck {
  36. bool deadlock;
  37. u32 seqno;
  38. u32 acthd;
  39. int score;
  40. enum intel_ring_hangcheck_action action;
  41. };
  42. struct intel_ring_buffer {
  43. const char *name;
  44. enum intel_ring_id {
  45. RCS = 0x0,
  46. VCS,
  47. BCS,
  48. VECS,
  49. } id;
  50. #define I915_NUM_RINGS 4
  51. u32 mmio_base;
  52. void __iomem *virtual_start;
  53. struct drm_device *dev;
  54. struct drm_i915_gem_object *obj;
  55. u32 head;
  56. u32 tail;
  57. int space;
  58. int size;
  59. int effective_size;
  60. struct intel_hw_status_page status_page;
  61. /** We track the position of the requests in the ring buffer, and
  62. * when each is retired we increment last_retired_head as the GPU
  63. * must have finished processing the request and so we know we
  64. * can advance the ringbuffer up to that position.
  65. *
  66. * last_retired_head is set to -1 after the value is consumed so
  67. * we can detect new retirements.
  68. */
  69. u32 last_retired_head;
  70. unsigned irq_refcount; /* protected by dev_priv->irq_lock */
  71. u32 irq_enable_mask; /* bitmask to enable ring interrupt */
  72. u32 trace_irq_seqno;
  73. u32 sync_seqno[I915_NUM_RINGS-1];
  74. bool __must_check (*irq_get)(struct intel_ring_buffer *ring);
  75. void (*irq_put)(struct intel_ring_buffer *ring);
  76. int (*init)(struct intel_ring_buffer *ring);
  77. void (*write_tail)(struct intel_ring_buffer *ring,
  78. u32 value);
  79. int __must_check (*flush)(struct intel_ring_buffer *ring,
  80. u32 invalidate_domains,
  81. u32 flush_domains);
  82. int (*add_request)(struct intel_ring_buffer *ring);
  83. /* Some chipsets are not quite as coherent as advertised and need
  84. * an expensive kick to force a true read of the up-to-date seqno.
  85. * However, the up-to-date seqno is not always required and the last
  86. * seen value is good enough. Note that the seqno will always be
  87. * monotonic, even if not coherent.
  88. */
  89. u32 (*get_seqno)(struct intel_ring_buffer *ring,
  90. bool lazy_coherency);
  91. void (*set_seqno)(struct intel_ring_buffer *ring,
  92. u32 seqno);
  93. int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
  94. u32 offset, u32 length,
  95. unsigned flags);
  96. #define I915_DISPATCH_SECURE 0x1
  97. #define I915_DISPATCH_PINNED 0x2
  98. void (*cleanup)(struct intel_ring_buffer *ring);
  99. int (*sync_to)(struct intel_ring_buffer *ring,
  100. struct intel_ring_buffer *to,
  101. u32 seqno);
  102. /* our mbox written by others */
  103. u32 semaphore_register[I915_NUM_RINGS];
  104. /* mboxes this ring signals to */
  105. u32 signal_mbox[I915_NUM_RINGS];
  106. /**
  107. * List of objects currently involved in rendering from the
  108. * ringbuffer.
  109. *
  110. * Includes buffers having the contents of their GPU caches
  111. * flushed, not necessarily primitives. last_rendering_seqno
  112. * represents when the rendering involved will be completed.
  113. *
  114. * A reference is held on the buffer while on this list.
  115. */
  116. struct list_head active_list;
  117. /**
  118. * List of breadcrumbs associated with GPU requests currently
  119. * outstanding.
  120. */
  121. struct list_head request_list;
  122. /**
  123. * Do we have some not yet emitted requests outstanding?
  124. */
  125. struct drm_i915_gem_request *preallocated_lazy_request;
  126. u32 outstanding_lazy_seqno;
  127. bool gpu_caches_dirty;
  128. bool fbc_dirty;
  129. wait_queue_head_t irq_queue;
  130. /**
  131. * Do an explicit TLB flush before MI_SET_CONTEXT
  132. */
  133. bool itlb_before_ctx_switch;
  134. struct i915_hw_context *default_context;
  135. struct i915_hw_context *last_context;
  136. struct intel_ring_hangcheck hangcheck;
  137. struct {
  138. struct drm_i915_gem_object *obj;
  139. u32 gtt_offset;
  140. volatile u32 *cpu_page;
  141. } scratch;
  142. };
  143. static inline bool
  144. intel_ring_initialized(struct intel_ring_buffer *ring)
  145. {
  146. return ring->obj != NULL;
  147. }
  148. static inline unsigned
  149. intel_ring_flag(struct intel_ring_buffer *ring)
  150. {
  151. return 1 << ring->id;
  152. }
  153. static inline u32
  154. intel_ring_sync_index(struct intel_ring_buffer *ring,
  155. struct intel_ring_buffer *other)
  156. {
  157. int idx;
  158. /*
  159. * cs -> 0 = vcs, 1 = bcs
  160. * vcs -> 0 = bcs, 1 = cs,
  161. * bcs -> 0 = cs, 1 = vcs.
  162. */
  163. idx = (other - ring) - 1;
  164. if (idx < 0)
  165. idx += I915_NUM_RINGS;
  166. return idx;
  167. }
  168. static inline u32
  169. intel_read_status_page(struct intel_ring_buffer *ring,
  170. int reg)
  171. {
  172. /* Ensure that the compiler doesn't optimize away the load. */
  173. barrier();
  174. return ring->status_page.page_addr[reg];
  175. }
  176. static inline void
  177. intel_write_status_page(struct intel_ring_buffer *ring,
  178. int reg, u32 value)
  179. {
  180. ring->status_page.page_addr[reg] = value;
  181. }
  182. /**
  183. * Reads a dword out of the status page, which is written to from the command
  184. * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
  185. * MI_STORE_DATA_IMM.
  186. *
  187. * The following dwords have a reserved meaning:
  188. * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
  189. * 0x04: ring 0 head pointer
  190. * 0x05: ring 1 head pointer (915-class)
  191. * 0x06: ring 2 head pointer (915-class)
  192. * 0x10-0x1b: Context status DWords (GM45)
  193. * 0x1f: Last written status offset. (GM45)
  194. *
  195. * The area from dword 0x20 to 0x3ff is available for driver usage.
  196. */
  197. #define I915_GEM_HWS_INDEX 0x20
  198. #define I915_GEM_HWS_SCRATCH_INDEX 0x30
  199. #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
  200. void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
  201. int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
  202. static inline void intel_ring_emit(struct intel_ring_buffer *ring,
  203. u32 data)
  204. {
  205. iowrite32(data, ring->virtual_start + ring->tail);
  206. ring->tail += 4;
  207. }
  208. static inline void intel_ring_advance(struct intel_ring_buffer *ring)
  209. {
  210. ring->tail &= ring->size - 1;
  211. }
  212. void __intel_ring_advance(struct intel_ring_buffer *ring);
  213. int __must_check intel_ring_idle(struct intel_ring_buffer *ring);
  214. void intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno);
  215. int intel_ring_flush_all_caches(struct intel_ring_buffer *ring);
  216. int intel_ring_invalidate_all_caches(struct intel_ring_buffer *ring);
  217. int intel_init_render_ring_buffer(struct drm_device *dev);
  218. int intel_init_bsd_ring_buffer(struct drm_device *dev);
  219. int intel_init_blt_ring_buffer(struct drm_device *dev);
  220. int intel_init_vebox_ring_buffer(struct drm_device *dev);
  221. u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
  222. void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
  223. static inline u32 intel_ring_get_tail(struct intel_ring_buffer *ring)
  224. {
  225. return ring->tail;
  226. }
  227. static inline u32 intel_ring_get_seqno(struct intel_ring_buffer *ring)
  228. {
  229. BUG_ON(ring->outstanding_lazy_seqno == 0);
  230. return ring->outstanding_lazy_seqno;
  231. }
  232. static inline void i915_trace_irq_get(struct intel_ring_buffer *ring, u32 seqno)
  233. {
  234. if (ring->trace_irq_seqno == 0 && ring->irq_get(ring))
  235. ring->trace_irq_seqno = seqno;
  236. }
  237. /* DRI warts */
  238. int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size);
  239. #endif /* _INTEL_RINGBUFFER_H_ */