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