intel_ringbuffer.h 7.3 KB

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