intel_ringbuffer.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef _INTEL_RINGBUFFER_H_
  2. #define _INTEL_RINGBUFFER_H_
  3. enum {
  4. RCS = 0x0,
  5. VCS,
  6. BCS,
  7. I915_NUM_RINGS,
  8. };
  9. struct intel_hw_status_page {
  10. u32 __iomem *page_addr;
  11. unsigned int gfx_addr;
  12. struct drm_i915_gem_object *obj;
  13. };
  14. #define I915_RING_READ(reg) i915_safe_read(dev_priv, reg)
  15. #define I915_READ_TAIL(ring) I915_RING_READ(RING_TAIL((ring)->mmio_base))
  16. #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
  17. #define I915_READ_START(ring) I915_RING_READ(RING_START((ring)->mmio_base))
  18. #define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
  19. #define I915_READ_HEAD(ring) I915_RING_READ(RING_HEAD((ring)->mmio_base))
  20. #define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
  21. #define I915_READ_CTL(ring) I915_RING_READ(RING_CTL((ring)->mmio_base))
  22. #define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
  23. #define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
  24. #define I915_READ_IMR(ring) I915_RING_READ(RING_IMR((ring)->mmio_base))
  25. #define I915_READ_NOPID(ring) I915_RING_READ(RING_NOPID((ring)->mmio_base))
  26. #define I915_READ_SYNC_0(ring) I915_RING_READ(RING_SYNC_0((ring)->mmio_base))
  27. #define I915_READ_SYNC_1(ring) I915_RING_READ(RING_SYNC_1((ring)->mmio_base))
  28. struct intel_ring_buffer {
  29. const char *name;
  30. enum intel_ring_id {
  31. RING_RENDER = 0x1,
  32. RING_BSD = 0x2,
  33. RING_BLT = 0x4,
  34. } id;
  35. u32 mmio_base;
  36. void *virtual_start;
  37. struct drm_device *dev;
  38. struct drm_i915_gem_object *obj;
  39. u32 actual_head;
  40. u32 head;
  41. u32 tail;
  42. int space;
  43. int size;
  44. int effective_size;
  45. struct intel_hw_status_page status_page;
  46. spinlock_t irq_lock;
  47. u32 irq_refcount;
  48. u32 irq_mask;
  49. u32 irq_seqno; /* last seq seem at irq time */
  50. u32 waiting_seqno;
  51. u32 sync_seqno[I915_NUM_RINGS-1];
  52. bool __must_check (*irq_get)(struct intel_ring_buffer *ring);
  53. void (*irq_put)(struct intel_ring_buffer *ring);
  54. int (*init)(struct intel_ring_buffer *ring);
  55. void (*write_tail)(struct intel_ring_buffer *ring,
  56. u32 value);
  57. int __must_check (*flush)(struct intel_ring_buffer *ring,
  58. u32 invalidate_domains,
  59. u32 flush_domains);
  60. int (*add_request)(struct intel_ring_buffer *ring,
  61. u32 *seqno);
  62. u32 (*get_seqno)(struct intel_ring_buffer *ring);
  63. int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
  64. u32 offset, u32 length);
  65. void (*cleanup)(struct intel_ring_buffer *ring);
  66. /**
  67. * List of objects currently involved in rendering from the
  68. * ringbuffer.
  69. *
  70. * Includes buffers having the contents of their GPU caches
  71. * flushed, not necessarily primitives. last_rendering_seqno
  72. * represents when the rendering involved will be completed.
  73. *
  74. * A reference is held on the buffer while on this list.
  75. */
  76. struct list_head active_list;
  77. /**
  78. * List of breadcrumbs associated with GPU requests currently
  79. * outstanding.
  80. */
  81. struct list_head request_list;
  82. /**
  83. * List of objects currently pending a GPU write flush.
  84. *
  85. * All elements on this list will belong to either the
  86. * active_list or flushing_list, last_rendering_seqno can
  87. * be used to differentiate between the two elements.
  88. */
  89. struct list_head gpu_write_list;
  90. /**
  91. * Do we have some not yet emitted requests outstanding?
  92. */
  93. u32 outstanding_lazy_request;
  94. wait_queue_head_t irq_queue;
  95. drm_local_map_t map;
  96. void *private;
  97. };
  98. static inline u32
  99. intel_ring_sync_index(struct intel_ring_buffer *ring,
  100. struct intel_ring_buffer *other)
  101. {
  102. int idx;
  103. /*
  104. * cs -> 0 = vcs, 1 = bcs
  105. * vcs -> 0 = bcs, 1 = cs,
  106. * bcs -> 0 = cs, 1 = vcs.
  107. */
  108. idx = (other - ring) - 1;
  109. if (idx < 0)
  110. idx += I915_NUM_RINGS;
  111. return idx;
  112. }
  113. static inline u32
  114. intel_read_status_page(struct intel_ring_buffer *ring,
  115. int reg)
  116. {
  117. return ioread32(ring->status_page.page_addr + reg);
  118. }
  119. void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
  120. int __must_check intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n);
  121. int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
  122. static inline void intel_ring_emit(struct intel_ring_buffer *ring,
  123. u32 data)
  124. {
  125. iowrite32(data, ring->virtual_start + ring->tail);
  126. ring->tail += 4;
  127. }
  128. void intel_ring_advance(struct intel_ring_buffer *ring);
  129. u32 intel_ring_get_seqno(struct intel_ring_buffer *ring);
  130. int intel_ring_sync(struct intel_ring_buffer *ring,
  131. struct intel_ring_buffer *to,
  132. u32 seqno);
  133. int intel_init_render_ring_buffer(struct drm_device *dev);
  134. int intel_init_bsd_ring_buffer(struct drm_device *dev);
  135. int intel_init_blt_ring_buffer(struct drm_device *dev);
  136. u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
  137. void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
  138. #endif /* _INTEL_RINGBUFFER_H_ */