intel_ringbuffer.h 7.8 KB

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