intel_ringbuffer.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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_MODE(ring) I915_READ(RING_MI_MODE((ring)->mmio_base))
  29. #define I915_WRITE_MODE(ring, val) I915_WRITE(RING_MI_MODE((ring)->mmio_base), val)
  30. enum intel_ring_hangcheck_action {
  31. HANGCHECK_IDLE = 0,
  32. HANGCHECK_WAIT,
  33. HANGCHECK_ACTIVE,
  34. HANGCHECK_KICK,
  35. HANGCHECK_HUNG,
  36. };
  37. #define HANGCHECK_SCORE_RING_HUNG 31
  38. struct intel_ring_hangcheck {
  39. u64 acthd;
  40. u32 seqno;
  41. int score;
  42. enum intel_ring_hangcheck_action action;
  43. bool deadlock;
  44. };
  45. struct intel_ring_buffer {
  46. const char *name;
  47. enum intel_ring_id {
  48. RCS = 0x0,
  49. VCS,
  50. BCS,
  51. VECS,
  52. VCS2
  53. } id;
  54. #define I915_NUM_RINGS 5
  55. #define LAST_USER_RING (VECS + 1)
  56. u32 mmio_base;
  57. void __iomem *virtual_start;
  58. struct drm_device *dev;
  59. struct drm_i915_gem_object *obj;
  60. u32 head;
  61. u32 tail;
  62. int space;
  63. int size;
  64. int effective_size;
  65. struct intel_hw_status_page status_page;
  66. /** We track the position of the requests in the ring buffer, and
  67. * when each is retired we increment last_retired_head as the GPU
  68. * must have finished processing the request and so we know we
  69. * can advance the ringbuffer up to that position.
  70. *
  71. * last_retired_head is set to -1 after the value is consumed so
  72. * we can detect new retirements.
  73. */
  74. u32 last_retired_head;
  75. unsigned irq_refcount; /* protected by dev_priv->irq_lock */
  76. u32 irq_enable_mask; /* bitmask to enable ring interrupt */
  77. u32 trace_irq_seqno;
  78. bool __must_check (*irq_get)(struct intel_ring_buffer *ring);
  79. void (*irq_put)(struct intel_ring_buffer *ring);
  80. int (*init)(struct intel_ring_buffer *ring);
  81. void (*write_tail)(struct intel_ring_buffer *ring,
  82. u32 value);
  83. int __must_check (*flush)(struct intel_ring_buffer *ring,
  84. u32 invalidate_domains,
  85. u32 flush_domains);
  86. int (*add_request)(struct intel_ring_buffer *ring);
  87. /* Some chipsets are not quite as coherent as advertised and need
  88. * an expensive kick to force a true read of the up-to-date seqno.
  89. * However, the up-to-date seqno is not always required and the last
  90. * seen value is good enough. Note that the seqno will always be
  91. * monotonic, even if not coherent.
  92. */
  93. u32 (*get_seqno)(struct intel_ring_buffer *ring,
  94. bool lazy_coherency);
  95. void (*set_seqno)(struct intel_ring_buffer *ring,
  96. u32 seqno);
  97. int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
  98. u32 offset, u32 length,
  99. unsigned flags);
  100. #define I915_DISPATCH_SECURE 0x1
  101. #define I915_DISPATCH_PINNED 0x2
  102. void (*cleanup)(struct intel_ring_buffer *ring);
  103. struct {
  104. u32 sync_seqno[I915_NUM_RINGS-1];
  105. struct {
  106. /* our mbox written by others */
  107. u32 wait[I915_NUM_RINGS];
  108. /* mboxes this ring signals to */
  109. u32 signal[I915_NUM_RINGS];
  110. } mbox;
  111. /* AKA wait() */
  112. int (*sync_to)(struct intel_ring_buffer *ring,
  113. struct intel_ring_buffer *to,
  114. u32 seqno);
  115. int (*signal)(struct intel_ring_buffer *signaller,
  116. /* num_dwords needed by caller */
  117. unsigned int num_dwords);
  118. } semaphore;
  119. /**
  120. * List of objects currently involved in rendering from the
  121. * ringbuffer.
  122. *
  123. * Includes buffers having the contents of their GPU caches
  124. * flushed, not necessarily primitives. last_rendering_seqno
  125. * represents when the rendering involved will be completed.
  126. *
  127. * A reference is held on the buffer while on this list.
  128. */
  129. struct list_head active_list;
  130. /**
  131. * List of breadcrumbs associated with GPU requests currently
  132. * outstanding.
  133. */
  134. struct list_head request_list;
  135. /**
  136. * Do we have some not yet emitted requests outstanding?
  137. */
  138. struct drm_i915_gem_request *preallocated_lazy_request;
  139. u32 outstanding_lazy_seqno;
  140. bool gpu_caches_dirty;
  141. bool fbc_dirty;
  142. wait_queue_head_t irq_queue;
  143. struct i915_hw_context *default_context;
  144. struct i915_hw_context *last_context;
  145. struct intel_ring_hangcheck hangcheck;
  146. struct {
  147. struct drm_i915_gem_object *obj;
  148. u32 gtt_offset;
  149. volatile u32 *cpu_page;
  150. } scratch;
  151. /*
  152. * Tables of commands the command parser needs to know about
  153. * for this ring.
  154. */
  155. const struct drm_i915_cmd_table *cmd_tables;
  156. int cmd_table_count;
  157. /*
  158. * Table of registers allowed in commands that read/write registers.
  159. */
  160. const u32 *reg_table;
  161. int reg_count;
  162. /*
  163. * Table of registers allowed in commands that read/write registers, but
  164. * only from the DRM master.
  165. */
  166. const u32 *master_reg_table;
  167. int master_reg_count;
  168. /*
  169. * Returns the bitmask for the length field of the specified command.
  170. * Return 0 for an unrecognized/invalid command.
  171. *
  172. * If the command parser finds an entry for a command in the ring's
  173. * cmd_tables, it gets the command's length based on the table entry.
  174. * If not, it calls this function to determine the per-ring length field
  175. * encoding for the command (i.e. certain opcode ranges use certain bits
  176. * to encode the command length in the header).
  177. */
  178. u32 (*get_cmd_length_mask)(u32 cmd_header);
  179. };
  180. static inline bool
  181. intel_ring_initialized(struct intel_ring_buffer *ring)
  182. {
  183. return ring->obj != NULL;
  184. }
  185. static inline unsigned
  186. intel_ring_flag(struct intel_ring_buffer *ring)
  187. {
  188. return 1 << ring->id;
  189. }
  190. static inline u32
  191. intel_ring_sync_index(struct intel_ring_buffer *ring,
  192. struct intel_ring_buffer *other)
  193. {
  194. int idx;
  195. /*
  196. * cs -> 0 = vcs, 1 = bcs
  197. * vcs -> 0 = bcs, 1 = cs,
  198. * bcs -> 0 = cs, 1 = vcs.
  199. */
  200. idx = (other - ring) - 1;
  201. if (idx < 0)
  202. idx += I915_NUM_RINGS;
  203. return idx;
  204. }
  205. static inline u32
  206. intel_read_status_page(struct intel_ring_buffer *ring,
  207. int reg)
  208. {
  209. /* Ensure that the compiler doesn't optimize away the load. */
  210. barrier();
  211. return ring->status_page.page_addr[reg];
  212. }
  213. static inline void
  214. intel_write_status_page(struct intel_ring_buffer *ring,
  215. int reg, u32 value)
  216. {
  217. ring->status_page.page_addr[reg] = value;
  218. }
  219. /**
  220. * Reads a dword out of the status page, which is written to from the command
  221. * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
  222. * MI_STORE_DATA_IMM.
  223. *
  224. * The following dwords have a reserved meaning:
  225. * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
  226. * 0x04: ring 0 head pointer
  227. * 0x05: ring 1 head pointer (915-class)
  228. * 0x06: ring 2 head pointer (915-class)
  229. * 0x10-0x1b: Context status DWords (GM45)
  230. * 0x1f: Last written status offset. (GM45)
  231. *
  232. * The area from dword 0x20 to 0x3ff is available for driver usage.
  233. */
  234. #define I915_GEM_HWS_INDEX 0x20
  235. #define I915_GEM_HWS_SCRATCH_INDEX 0x30
  236. #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
  237. void intel_stop_ring_buffer(struct intel_ring_buffer *ring);
  238. void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
  239. int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
  240. int __must_check intel_ring_cacheline_align(struct intel_ring_buffer *ring);
  241. static inline void intel_ring_emit(struct intel_ring_buffer *ring,
  242. u32 data)
  243. {
  244. iowrite32(data, ring->virtual_start + ring->tail);
  245. ring->tail += 4;
  246. }
  247. static inline void intel_ring_advance(struct intel_ring_buffer *ring)
  248. {
  249. ring->tail &= ring->size - 1;
  250. }
  251. void __intel_ring_advance(struct intel_ring_buffer *ring);
  252. int __must_check intel_ring_idle(struct intel_ring_buffer *ring);
  253. void intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno);
  254. int intel_ring_flush_all_caches(struct intel_ring_buffer *ring);
  255. int intel_ring_invalidate_all_caches(struct intel_ring_buffer *ring);
  256. int intel_init_render_ring_buffer(struct drm_device *dev);
  257. int intel_init_bsd_ring_buffer(struct drm_device *dev);
  258. int intel_init_bsd2_ring_buffer(struct drm_device *dev);
  259. int intel_init_blt_ring_buffer(struct drm_device *dev);
  260. int intel_init_vebox_ring_buffer(struct drm_device *dev);
  261. u64 intel_ring_get_active_head(struct intel_ring_buffer *ring);
  262. void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
  263. static inline u32 intel_ring_get_tail(struct intel_ring_buffer *ring)
  264. {
  265. return ring->tail;
  266. }
  267. static inline u32 intel_ring_get_seqno(struct intel_ring_buffer *ring)
  268. {
  269. BUG_ON(ring->outstanding_lazy_seqno == 0);
  270. return ring->outstanding_lazy_seqno;
  271. }
  272. static inline void i915_trace_irq_get(struct intel_ring_buffer *ring, u32 seqno)
  273. {
  274. if (ring->trace_irq_seqno == 0 && ring->irq_get(ring))
  275. ring->trace_irq_seqno = seqno;
  276. }
  277. /* DRI warts */
  278. int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size);
  279. #endif /* _INTEL_RINGBUFFER_H_ */