1e3adcf8fSFrançois Tigeot #ifndef _INTEL_RINGBUFFER_H_ 2e3adcf8fSFrançois Tigeot #define _INTEL_RINGBUFFER_H_ 3e3adcf8fSFrançois Tigeot 4ba55f2f5SFrançois Tigeot #include <linux/hashtable.h> 519c468b4SFrançois Tigeot #include "i915_gem_batch_pool.h" 6ba55f2f5SFrançois Tigeot 7ba55f2f5SFrançois Tigeot #define I915_CMD_HASH_ORDER 9 8ba55f2f5SFrançois Tigeot 91b13d190SFrançois Tigeot /* Early gen2 devices have a cacheline of just 32 bytes, using 64 is overkill, 101b13d190SFrançois Tigeot * but keeps the logic simple. Indeed, the whole purpose of this macro is just 111b13d190SFrançois Tigeot * to give some inclination as to some of the magic values used in the various 121b13d190SFrançois Tigeot * workarounds! 131b13d190SFrançois Tigeot */ 141b13d190SFrançois Tigeot #define CACHELINE_BYTES 64 15*a05eeebfSFrançois Tigeot #define CACHELINE_DWORDS (CACHELINE_BYTES / sizeof(uint32_t)) 161b13d190SFrançois Tigeot 17f4e1c372SFrançois Tigeot /* 18f4e1c372SFrançois Tigeot * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use" 19f4e1c372SFrançois Tigeot * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use" 20f4e1c372SFrançois Tigeot * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use" 21f4e1c372SFrançois Tigeot * 22f4e1c372SFrançois Tigeot * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same 23f4e1c372SFrançois Tigeot * cacheline, the Head Pointer must not be greater than the Tail 24f4e1c372SFrançois Tigeot * Pointer." 25f4e1c372SFrançois Tigeot */ 26f4e1c372SFrançois Tigeot #define I915_RING_FREE_SPACE 64 27f4e1c372SFrançois Tigeot 28e3adcf8fSFrançois Tigeot struct intel_hw_status_page { 29f4e1c372SFrançois Tigeot u32 *page_addr; 30e3adcf8fSFrançois Tigeot unsigned int gfx_addr; 31e3adcf8fSFrançois Tigeot struct drm_i915_gem_object *obj; 32e3adcf8fSFrançois Tigeot }; 33e3adcf8fSFrançois Tigeot 34e3adcf8fSFrançois Tigeot #define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base)) 35e3adcf8fSFrançois Tigeot #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val) 36e3adcf8fSFrançois Tigeot 37e3adcf8fSFrançois Tigeot #define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base)) 38e3adcf8fSFrançois Tigeot #define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val) 39e3adcf8fSFrançois Tigeot 40e3adcf8fSFrançois Tigeot #define I915_READ_HEAD(ring) I915_READ(RING_HEAD((ring)->mmio_base)) 41e3adcf8fSFrançois Tigeot #define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val) 42e3adcf8fSFrançois Tigeot 43e3adcf8fSFrançois Tigeot #define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base)) 44e3adcf8fSFrançois Tigeot #define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val) 45e3adcf8fSFrançois Tigeot 46e3adcf8fSFrançois Tigeot #define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base)) 47e3adcf8fSFrançois Tigeot #define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val) 48e3adcf8fSFrançois Tigeot 49ba55f2f5SFrançois Tigeot #define I915_READ_MODE(ring) I915_READ(RING_MI_MODE((ring)->mmio_base)) 50ba55f2f5SFrançois Tigeot #define I915_WRITE_MODE(ring, val) I915_WRITE(RING_MI_MODE((ring)->mmio_base), val) 51ba55f2f5SFrançois Tigeot 5224edb884SFrançois Tigeot /* seqno size is actually only a uint32, but since we plan to use MI_FLUSH_DW to 5324edb884SFrançois Tigeot * do the writes, and that must have qw aligned offsets, simply pretend it's 8b. 5424edb884SFrançois Tigeot */ 5524edb884SFrançois Tigeot #define i915_semaphore_seqno_size sizeof(uint64_t) 5624edb884SFrançois Tigeot #define GEN8_SIGNAL_OFFSET(__ring, to) \ 5724edb884SFrançois Tigeot (i915_gem_obj_ggtt_offset(dev_priv->semaphore_obj) + \ 5824edb884SFrançois Tigeot ((__ring)->id * I915_NUM_RINGS * i915_semaphore_seqno_size) + \ 5924edb884SFrançois Tigeot (i915_semaphore_seqno_size * (to))) 6024edb884SFrançois Tigeot 6124edb884SFrançois Tigeot #define GEN8_WAIT_OFFSET(__ring, from) \ 6224edb884SFrançois Tigeot (i915_gem_obj_ggtt_offset(dev_priv->semaphore_obj) + \ 6324edb884SFrançois Tigeot ((from) * I915_NUM_RINGS * i915_semaphore_seqno_size) + \ 6424edb884SFrançois Tigeot (i915_semaphore_seqno_size * (__ring)->id)) 6524edb884SFrançois Tigeot 6624edb884SFrançois Tigeot #define GEN8_RING_SEMAPHORE_INIT do { \ 6724edb884SFrançois Tigeot if (!dev_priv->semaphore_obj) { \ 6824edb884SFrançois Tigeot break; \ 6924edb884SFrançois Tigeot } \ 7024edb884SFrançois Tigeot ring->semaphore.signal_ggtt[RCS] = GEN8_SIGNAL_OFFSET(ring, RCS); \ 7124edb884SFrançois Tigeot ring->semaphore.signal_ggtt[VCS] = GEN8_SIGNAL_OFFSET(ring, VCS); \ 7224edb884SFrançois Tigeot ring->semaphore.signal_ggtt[BCS] = GEN8_SIGNAL_OFFSET(ring, BCS); \ 7324edb884SFrançois Tigeot ring->semaphore.signal_ggtt[VECS] = GEN8_SIGNAL_OFFSET(ring, VECS); \ 7424edb884SFrançois Tigeot ring->semaphore.signal_ggtt[VCS2] = GEN8_SIGNAL_OFFSET(ring, VCS2); \ 7524edb884SFrançois Tigeot ring->semaphore.signal_ggtt[ring->id] = MI_SEMAPHORE_SYNC_INVALID; \ 7624edb884SFrançois Tigeot } while(0) 7724edb884SFrançois Tigeot 789edbd4a0SFrançois Tigeot enum intel_ring_hangcheck_action { 799edbd4a0SFrançois Tigeot HANGCHECK_IDLE = 0, 809edbd4a0SFrançois Tigeot HANGCHECK_WAIT, 819edbd4a0SFrançois Tigeot HANGCHECK_ACTIVE, 8224edb884SFrançois Tigeot HANGCHECK_ACTIVE_LOOP, 839edbd4a0SFrançois Tigeot HANGCHECK_KICK, 849edbd4a0SFrançois Tigeot HANGCHECK_HUNG, 859edbd4a0SFrançois Tigeot }; 865d0b1887SFrançois Tigeot 87ba55f2f5SFrançois Tigeot #define HANGCHECK_SCORE_RING_HUNG 31 88ba55f2f5SFrançois Tigeot 895d0b1887SFrançois Tigeot struct intel_ring_hangcheck { 90ba55f2f5SFrançois Tigeot u64 acthd; 9124edb884SFrançois Tigeot u64 max_acthd; 925d0b1887SFrançois Tigeot u32 seqno; 935d0b1887SFrançois Tigeot int score; 945d0b1887SFrançois Tigeot enum intel_ring_hangcheck_action action; 95ba55f2f5SFrançois Tigeot int deadlock; 965d0b1887SFrançois Tigeot }; 975d0b1887SFrançois Tigeot 98ba55f2f5SFrançois Tigeot struct intel_ringbuffer { 99e3adcf8fSFrançois Tigeot struct drm_i915_gem_object *obj; 10019c468b4SFrançois Tigeot char __iomem *virtual_start; 101e3adcf8fSFrançois Tigeot 1021b13d190SFrançois Tigeot struct intel_engine_cs *ring; 1031b13d190SFrançois Tigeot 10415ac6249SFrançois Tigeot u32 head; 10515ac6249SFrançois Tigeot u32 tail; 106e3adcf8fSFrançois Tigeot int space; 107e3adcf8fSFrançois Tigeot int size; 108e3adcf8fSFrançois Tigeot int effective_size; 109*a05eeebfSFrançois Tigeot int reserved_size; 110*a05eeebfSFrançois Tigeot int reserved_tail; 111*a05eeebfSFrançois Tigeot bool reserved_in_use; 112e3adcf8fSFrançois Tigeot 113e3adcf8fSFrançois Tigeot /** We track the position of the requests in the ring buffer, and 114e3adcf8fSFrançois Tigeot * when each is retired we increment last_retired_head as the GPU 115e3adcf8fSFrançois Tigeot * must have finished processing the request and so we know we 116e3adcf8fSFrançois Tigeot * can advance the ringbuffer up to that position. 117e3adcf8fSFrançois Tigeot * 118e3adcf8fSFrançois Tigeot * last_retired_head is set to -1 after the value is consumed so 119e3adcf8fSFrançois Tigeot * we can detect new retirements. 120e3adcf8fSFrançois Tigeot */ 121e3adcf8fSFrançois Tigeot u32 last_retired_head; 122ba55f2f5SFrançois Tigeot }; 123ba55f2f5SFrançois Tigeot 1242c9916cdSFrançois Tigeot struct intel_context; 12519c468b4SFrançois Tigeot struct drm_i915_reg_descriptor; 1262c9916cdSFrançois Tigeot 127*a05eeebfSFrançois Tigeot /* 128*a05eeebfSFrançois Tigeot * we use a single page to load ctx workarounds so all of these 129*a05eeebfSFrançois Tigeot * values are referred in terms of dwords 130*a05eeebfSFrançois Tigeot * 131*a05eeebfSFrançois Tigeot * struct i915_wa_ctx_bb: 132*a05eeebfSFrançois Tigeot * offset: specifies batch starting position, also helpful in case 133*a05eeebfSFrançois Tigeot * if we want to have multiple batches at different offsets based on 134*a05eeebfSFrançois Tigeot * some criteria. It is not a requirement at the moment but provides 135*a05eeebfSFrançois Tigeot * an option for future use. 136*a05eeebfSFrançois Tigeot * size: size of the batch in DWORDS 137*a05eeebfSFrançois Tigeot */ 138*a05eeebfSFrançois Tigeot struct i915_ctx_workarounds { 139*a05eeebfSFrançois Tigeot struct i915_wa_ctx_bb { 140*a05eeebfSFrançois Tigeot u32 offset; 141*a05eeebfSFrançois Tigeot u32 size; 142*a05eeebfSFrançois Tigeot } indirect_ctx, per_ctx; 143*a05eeebfSFrançois Tigeot struct drm_i915_gem_object *obj; 144*a05eeebfSFrançois Tigeot }; 145*a05eeebfSFrançois Tigeot 146ba55f2f5SFrançois Tigeot struct intel_engine_cs { 147ba55f2f5SFrançois Tigeot const char *name; 148ba55f2f5SFrançois Tigeot enum intel_ring_id { 149ba55f2f5SFrançois Tigeot RCS = 0x0, 150ba55f2f5SFrançois Tigeot VCS, 151ba55f2f5SFrançois Tigeot BCS, 152ba55f2f5SFrançois Tigeot VECS, 153ba55f2f5SFrançois Tigeot VCS2 154ba55f2f5SFrançois Tigeot } id; 155ba55f2f5SFrançois Tigeot #define I915_NUM_RINGS 5 156ba55f2f5SFrançois Tigeot #define LAST_USER_RING (VECS + 1) 157ba55f2f5SFrançois Tigeot u32 mmio_base; 158ba55f2f5SFrançois Tigeot struct drm_device *dev; 159ba55f2f5SFrançois Tigeot struct intel_ringbuffer *buffer; 160ba55f2f5SFrançois Tigeot 16119c468b4SFrançois Tigeot /* 16219c468b4SFrançois Tigeot * A pool of objects to use as shadow copies of client batch buffers 16319c468b4SFrançois Tigeot * when the command parser is enabled. Prevents the client from 16419c468b4SFrançois Tigeot * modifying the batch contents after software parsing. 16519c468b4SFrançois Tigeot */ 16619c468b4SFrançois Tigeot struct i915_gem_batch_pool batch_pool; 16719c468b4SFrançois Tigeot 168ba55f2f5SFrançois Tigeot struct intel_hw_status_page status_page; 169*a05eeebfSFrançois Tigeot struct i915_ctx_workarounds wa_ctx; 170e3adcf8fSFrançois Tigeot 1719edbd4a0SFrançois Tigeot unsigned irq_refcount; /* protected by dev_priv->irq_lock */ 17215ac6249SFrançois Tigeot u32 irq_enable_mask; /* bitmask to enable ring interrupt */ 1732c9916cdSFrançois Tigeot struct drm_i915_gem_request *trace_irq_req; 174ba55f2f5SFrançois Tigeot bool __must_check (*irq_get)(struct intel_engine_cs *ring); 175ba55f2f5SFrançois Tigeot void (*irq_put)(struct intel_engine_cs *ring); 176e3adcf8fSFrançois Tigeot 1772c9916cdSFrançois Tigeot int (*init_hw)(struct intel_engine_cs *ring); 178e3adcf8fSFrançois Tigeot 179*a05eeebfSFrançois Tigeot int (*init_context)(struct drm_i915_gem_request *req); 1801b13d190SFrançois Tigeot 181ba55f2f5SFrançois Tigeot void (*write_tail)(struct intel_engine_cs *ring, 18215ac6249SFrançois Tigeot u32 value); 183*a05eeebfSFrançois Tigeot int __must_check (*flush)(struct drm_i915_gem_request *req, 18415ac6249SFrançois Tigeot u32 invalidate_domains, 18515ac6249SFrançois Tigeot u32 flush_domains); 186*a05eeebfSFrançois Tigeot int (*add_request)(struct drm_i915_gem_request *req); 187b030f26bSFrançois Tigeot /* Some chipsets are not quite as coherent as advertised and need 188b030f26bSFrançois Tigeot * an expensive kick to force a true read of the up-to-date seqno. 189b030f26bSFrançois Tigeot * However, the up-to-date seqno is not always required and the last 190b030f26bSFrançois Tigeot * seen value is good enough. Note that the seqno will always be 191b030f26bSFrançois Tigeot * monotonic, even if not coherent. 192b030f26bSFrançois Tigeot */ 193ba55f2f5SFrançois Tigeot u32 (*get_seqno)(struct intel_engine_cs *ring, 194b030f26bSFrançois Tigeot bool lazy_coherency); 195ba55f2f5SFrançois Tigeot void (*set_seqno)(struct intel_engine_cs *ring, 196a2fdbec6SFrançois Tigeot u32 seqno); 197*a05eeebfSFrançois Tigeot int (*dispatch_execbuffer)(struct drm_i915_gem_request *req, 198ba55f2f5SFrançois Tigeot u64 offset, u32 length, 199477eb7f9SFrançois Tigeot unsigned dispatch_flags); 20015ac6249SFrançois Tigeot #define I915_DISPATCH_SECURE 0x1 20115ac6249SFrançois Tigeot #define I915_DISPATCH_PINNED 0x2 202*a05eeebfSFrançois Tigeot #define I915_DISPATCH_RS 0x4 203ba55f2f5SFrançois Tigeot void (*cleanup)(struct intel_engine_cs *ring); 204e3adcf8fSFrançois Tigeot 20524edb884SFrançois Tigeot /* GEN8 signal/wait table - never trust comments! 20624edb884SFrançois Tigeot * signal to signal to signal to signal to signal to 20724edb884SFrançois Tigeot * RCS VCS BCS VECS VCS2 20824edb884SFrançois Tigeot * -------------------------------------------------------------------- 20924edb884SFrançois Tigeot * RCS | NOP (0x00) | VCS (0x08) | BCS (0x10) | VECS (0x18) | VCS2 (0x20) | 21024edb884SFrançois Tigeot * |------------------------------------------------------------------- 21124edb884SFrançois Tigeot * VCS | RCS (0x28) | NOP (0x30) | BCS (0x38) | VECS (0x40) | VCS2 (0x48) | 21224edb884SFrançois Tigeot * |------------------------------------------------------------------- 21324edb884SFrançois Tigeot * BCS | RCS (0x50) | VCS (0x58) | NOP (0x60) | VECS (0x68) | VCS2 (0x70) | 21424edb884SFrançois Tigeot * |------------------------------------------------------------------- 21524edb884SFrançois Tigeot * VECS | RCS (0x78) | VCS (0x80) | BCS (0x88) | NOP (0x90) | VCS2 (0x98) | 21624edb884SFrançois Tigeot * |------------------------------------------------------------------- 21724edb884SFrançois Tigeot * VCS2 | RCS (0xa0) | VCS (0xa8) | BCS (0xb0) | VECS (0xb8) | NOP (0xc0) | 21824edb884SFrançois Tigeot * |------------------------------------------------------------------- 21924edb884SFrançois Tigeot * 22024edb884SFrançois Tigeot * Generalization: 22124edb884SFrançois Tigeot * f(x, y) := (x->id * NUM_RINGS * seqno_size) + (seqno_size * y->id) 22224edb884SFrançois Tigeot * ie. transpose of g(x, y) 22324edb884SFrançois Tigeot * 22424edb884SFrançois Tigeot * sync from sync from sync from sync from sync from 22524edb884SFrançois Tigeot * RCS VCS BCS VECS VCS2 22624edb884SFrançois Tigeot * -------------------------------------------------------------------- 22724edb884SFrançois Tigeot * RCS | NOP (0x00) | VCS (0x28) | BCS (0x50) | VECS (0x78) | VCS2 (0xa0) | 22824edb884SFrançois Tigeot * |------------------------------------------------------------------- 22924edb884SFrançois Tigeot * VCS | RCS (0x08) | NOP (0x30) | BCS (0x58) | VECS (0x80) | VCS2 (0xa8) | 23024edb884SFrançois Tigeot * |------------------------------------------------------------------- 23124edb884SFrançois Tigeot * BCS | RCS (0x10) | VCS (0x38) | NOP (0x60) | VECS (0x88) | VCS2 (0xb0) | 23224edb884SFrançois Tigeot * |------------------------------------------------------------------- 23324edb884SFrançois Tigeot * VECS | RCS (0x18) | VCS (0x40) | BCS (0x68) | NOP (0x90) | VCS2 (0xb8) | 23424edb884SFrançois Tigeot * |------------------------------------------------------------------- 23524edb884SFrançois Tigeot * VCS2 | RCS (0x20) | VCS (0x48) | BCS (0x70) | VECS (0x98) | NOP (0xc0) | 23624edb884SFrançois Tigeot * |------------------------------------------------------------------- 23724edb884SFrançois Tigeot * 23824edb884SFrançois Tigeot * Generalization: 23924edb884SFrançois Tigeot * g(x, y) := (y->id * NUM_RINGS * seqno_size) + (seqno_size * x->id) 24024edb884SFrançois Tigeot * ie. transpose of f(x, y) 24124edb884SFrançois Tigeot */ 242ba55f2f5SFrançois Tigeot struct { 243ba55f2f5SFrançois Tigeot u32 sync_seqno[I915_NUM_RINGS-1]; 244ba55f2f5SFrançois Tigeot 24524edb884SFrançois Tigeot union { 246ba55f2f5SFrançois Tigeot struct { 2475d0b1887SFrançois Tigeot /* our mbox written by others */ 248ba55f2f5SFrançois Tigeot u32 wait[I915_NUM_RINGS]; 2495d0b1887SFrançois Tigeot /* mboxes this ring signals to */ 250ba55f2f5SFrançois Tigeot u32 signal[I915_NUM_RINGS]; 251ba55f2f5SFrançois Tigeot } mbox; 25224edb884SFrançois Tigeot u64 signal_ggtt[I915_NUM_RINGS]; 25324edb884SFrançois Tigeot }; 254ba55f2f5SFrançois Tigeot 255ba55f2f5SFrançois Tigeot /* AKA wait() */ 256*a05eeebfSFrançois Tigeot int (*sync_to)(struct drm_i915_gem_request *to_req, 257*a05eeebfSFrançois Tigeot struct intel_engine_cs *from, 258ba55f2f5SFrançois Tigeot u32 seqno); 259*a05eeebfSFrançois Tigeot int (*signal)(struct drm_i915_gem_request *signaller_req, 260ba55f2f5SFrançois Tigeot /* num_dwords needed by caller */ 261ba55f2f5SFrançois Tigeot unsigned int num_dwords); 262ba55f2f5SFrançois Tigeot } semaphore; 2635d0b1887SFrançois Tigeot 2641b13d190SFrançois Tigeot /* Execlists */ 2651b13d190SFrançois Tigeot struct lock execlist_lock; 2661b13d190SFrançois Tigeot struct list_head execlist_queue; 2672c9916cdSFrançois Tigeot struct list_head execlist_retired_req_list; 2681b13d190SFrançois Tigeot u8 next_context_status_buffer; 2691b13d190SFrançois Tigeot u32 irq_keep_mask; /* bitmask for interrupts that should not be masked */ 270*a05eeebfSFrançois Tigeot int (*emit_request)(struct drm_i915_gem_request *request); 271*a05eeebfSFrançois Tigeot int (*emit_flush)(struct drm_i915_gem_request *request, 2721b13d190SFrançois Tigeot u32 invalidate_domains, 2731b13d190SFrançois Tigeot u32 flush_domains); 274*a05eeebfSFrançois Tigeot int (*emit_bb_start)(struct drm_i915_gem_request *req, 275477eb7f9SFrançois Tigeot u64 offset, unsigned dispatch_flags); 2761b13d190SFrançois Tigeot 277e3adcf8fSFrançois Tigeot /** 278e3adcf8fSFrançois Tigeot * List of objects currently involved in rendering from the 279e3adcf8fSFrançois Tigeot * ringbuffer. 280e3adcf8fSFrançois Tigeot * 281e3adcf8fSFrançois Tigeot * Includes buffers having the contents of their GPU caches 2822c9916cdSFrançois Tigeot * flushed, not necessarily primitives. last_read_req 283e3adcf8fSFrançois Tigeot * represents when the rendering involved will be completed. 284e3adcf8fSFrançois Tigeot * 285e3adcf8fSFrançois Tigeot * A reference is held on the buffer while on this list. 286e3adcf8fSFrançois Tigeot */ 287e3adcf8fSFrançois Tigeot struct list_head active_list; 288e3adcf8fSFrançois Tigeot 289e3adcf8fSFrançois Tigeot /** 290e3adcf8fSFrançois Tigeot * List of breadcrumbs associated with GPU requests currently 291e3adcf8fSFrançois Tigeot * outstanding. 292e3adcf8fSFrançois Tigeot */ 293e3adcf8fSFrançois Tigeot struct list_head request_list; 294e3adcf8fSFrançois Tigeot 295e3adcf8fSFrançois Tigeot /** 29619c468b4SFrançois Tigeot * Seqno of request most recently submitted to request_list. 29719c468b4SFrançois Tigeot * Used exclusively by hang checker to avoid grabbing lock while 29819c468b4SFrançois Tigeot * inspecting request list. 29919c468b4SFrançois Tigeot */ 30019c468b4SFrançois Tigeot u32 last_submitted_seqno; 30119c468b4SFrançois Tigeot 302b030f26bSFrançois Tigeot bool gpu_caches_dirty; 303b030f26bSFrançois Tigeot 304b030f26bSFrançois Tigeot wait_queue_head_t irq_queue; 305e3adcf8fSFrançois Tigeot 306ba55f2f5SFrançois Tigeot struct intel_context *default_context; 307ba55f2f5SFrançois Tigeot struct intel_context *last_context; 3085d0b1887SFrançois Tigeot 3095d0b1887SFrançois Tigeot struct intel_ring_hangcheck hangcheck; 31015ac6249SFrançois Tigeot 3119edbd4a0SFrançois Tigeot struct { 3129edbd4a0SFrançois Tigeot struct drm_i915_gem_object *obj; 3139edbd4a0SFrançois Tigeot u32 gtt_offset; 3149edbd4a0SFrançois Tigeot volatile u32 *cpu_page; 3159edbd4a0SFrançois Tigeot } scratch; 316ba55f2f5SFrançois Tigeot 317ba55f2f5SFrançois Tigeot bool needs_cmd_parser; 318ba55f2f5SFrançois Tigeot 319ba55f2f5SFrançois Tigeot /* 320ba55f2f5SFrançois Tigeot * Table of commands the command parser needs to know about 321ba55f2f5SFrançois Tigeot * for this ring. 322ba55f2f5SFrançois Tigeot */ 323ba55f2f5SFrançois Tigeot DECLARE_HASHTABLE(cmd_hash, I915_CMD_HASH_ORDER); 324ba55f2f5SFrançois Tigeot 325ba55f2f5SFrançois Tigeot /* 326ba55f2f5SFrançois Tigeot * Table of registers allowed in commands that read/write registers. 327ba55f2f5SFrançois Tigeot */ 32819c468b4SFrançois Tigeot const struct drm_i915_reg_descriptor *reg_table; 329ba55f2f5SFrançois Tigeot int reg_count; 330ba55f2f5SFrançois Tigeot 331ba55f2f5SFrançois Tigeot /* 332ba55f2f5SFrançois Tigeot * Table of registers allowed in commands that read/write registers, but 333ba55f2f5SFrançois Tigeot * only from the DRM master. 334ba55f2f5SFrançois Tigeot */ 33519c468b4SFrançois Tigeot const struct drm_i915_reg_descriptor *master_reg_table; 336ba55f2f5SFrançois Tigeot int master_reg_count; 337ba55f2f5SFrançois Tigeot 338ba55f2f5SFrançois Tigeot /* 339ba55f2f5SFrançois Tigeot * Returns the bitmask for the length field of the specified command. 340ba55f2f5SFrançois Tigeot * Return 0 for an unrecognized/invalid command. 341ba55f2f5SFrançois Tigeot * 342ba55f2f5SFrançois Tigeot * If the command parser finds an entry for a command in the ring's 343ba55f2f5SFrançois Tigeot * cmd_tables, it gets the command's length based on the table entry. 344ba55f2f5SFrançois Tigeot * If not, it calls this function to determine the per-ring length field 345ba55f2f5SFrançois Tigeot * encoding for the command (i.e. certain opcode ranges use certain bits 346ba55f2f5SFrançois Tigeot * to encode the command length in the header). 347ba55f2f5SFrançois Tigeot */ 348ba55f2f5SFrançois Tigeot u32 (*get_cmd_length_mask)(u32 cmd_header); 349e3adcf8fSFrançois Tigeot }; 350e3adcf8fSFrançois Tigeot 3511b13d190SFrançois Tigeot bool intel_ring_initialized(struct intel_engine_cs *ring); 352f4e1c372SFrançois Tigeot 353e3adcf8fSFrançois Tigeot static inline unsigned 354ba55f2f5SFrançois Tigeot intel_ring_flag(struct intel_engine_cs *ring) 355e3adcf8fSFrançois Tigeot { 356e3adcf8fSFrançois Tigeot return 1 << ring->id; 357e3adcf8fSFrançois Tigeot } 358e3adcf8fSFrançois Tigeot 359f4e1c372SFrançois Tigeot static inline u32 360ba55f2f5SFrançois Tigeot intel_ring_sync_index(struct intel_engine_cs *ring, 361ba55f2f5SFrançois Tigeot struct intel_engine_cs *other) 362e3adcf8fSFrançois Tigeot { 363e3adcf8fSFrançois Tigeot int idx; 364e3adcf8fSFrançois Tigeot 365e3adcf8fSFrançois Tigeot /* 36624edb884SFrançois Tigeot * rcs -> 0 = vcs, 1 = bcs, 2 = vecs, 3 = vcs2; 36724edb884SFrançois Tigeot * vcs -> 0 = bcs, 1 = vecs, 2 = vcs2, 3 = rcs; 36824edb884SFrançois Tigeot * bcs -> 0 = vecs, 1 = vcs2. 2 = rcs, 3 = vcs; 36924edb884SFrançois Tigeot * vecs -> 0 = vcs2, 1 = rcs, 2 = vcs, 3 = bcs; 37024edb884SFrançois Tigeot * vcs2 -> 0 = rcs, 1 = vcs, 2 = bcs, 3 = vecs; 371e3adcf8fSFrançois Tigeot */ 372e3adcf8fSFrançois Tigeot 373e3adcf8fSFrançois Tigeot idx = (other - ring) - 1; 374e3adcf8fSFrançois Tigeot if (idx < 0) 375e3adcf8fSFrançois Tigeot idx += I915_NUM_RINGS; 376e3adcf8fSFrançois Tigeot 377e3adcf8fSFrançois Tigeot return idx; 378e3adcf8fSFrançois Tigeot } 379e3adcf8fSFrançois Tigeot 380f4e1c372SFrançois Tigeot static inline u32 381ba55f2f5SFrançois Tigeot intel_read_status_page(struct intel_engine_cs *ring, 382f4e1c372SFrançois Tigeot int reg) 383e3adcf8fSFrançois Tigeot { 384f4e1c372SFrançois Tigeot /* Ensure that the compiler doesn't optimize away the load. */ 3859edbd4a0SFrançois Tigeot barrier(); 386f4e1c372SFrançois Tigeot return ring->status_page.page_addr[reg]; 387e3adcf8fSFrançois Tigeot } 388e3adcf8fSFrançois Tigeot 389a2fdbec6SFrançois Tigeot static inline void 390ba55f2f5SFrançois Tigeot intel_write_status_page(struct intel_engine_cs *ring, 391a2fdbec6SFrançois Tigeot int reg, u32 value) 392a2fdbec6SFrançois Tigeot { 393a2fdbec6SFrançois Tigeot ring->status_page.page_addr[reg] = value; 394a2fdbec6SFrançois Tigeot } 395a2fdbec6SFrançois Tigeot 396f4e1c372SFrançois Tigeot /** 397f4e1c372SFrançois Tigeot * Reads a dword out of the status page, which is written to from the command 398f4e1c372SFrançois Tigeot * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or 399f4e1c372SFrançois Tigeot * MI_STORE_DATA_IMM. 400f4e1c372SFrançois Tigeot * 401f4e1c372SFrançois Tigeot * The following dwords have a reserved meaning: 402f4e1c372SFrançois Tigeot * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes. 403f4e1c372SFrançois Tigeot * 0x04: ring 0 head pointer 404f4e1c372SFrançois Tigeot * 0x05: ring 1 head pointer (915-class) 405f4e1c372SFrançois Tigeot * 0x06: ring 2 head pointer (915-class) 406f4e1c372SFrançois Tigeot * 0x10-0x1b: Context status DWords (GM45) 407f4e1c372SFrançois Tigeot * 0x1f: Last written status offset. (GM45) 408477eb7f9SFrançois Tigeot * 0x20-0x2f: Reserved (Gen6+) 409f4e1c372SFrançois Tigeot * 410477eb7f9SFrançois Tigeot * The area from dword 0x30 to 0x3ff is available for driver usage. 411f4e1c372SFrançois Tigeot */ 412477eb7f9SFrançois Tigeot #define I915_GEM_HWS_INDEX 0x30 413477eb7f9SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_INDEX 0x40 414f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT) 415e3adcf8fSFrançois Tigeot 4162c9916cdSFrançois Tigeot void intel_unpin_ringbuffer_obj(struct intel_ringbuffer *ringbuf); 4172c9916cdSFrançois Tigeot int intel_pin_and_map_ringbuffer_obj(struct drm_device *dev, 4182c9916cdSFrançois Tigeot struct intel_ringbuffer *ringbuf); 4191b13d190SFrançois Tigeot void intel_destroy_ringbuffer_obj(struct intel_ringbuffer *ringbuf); 4201b13d190SFrançois Tigeot int intel_alloc_ringbuffer_obj(struct drm_device *dev, 4211b13d190SFrançois Tigeot struct intel_ringbuffer *ringbuf); 4221b13d190SFrançois Tigeot 423ba55f2f5SFrançois Tigeot void intel_stop_ring_buffer(struct intel_engine_cs *ring); 424ba55f2f5SFrançois Tigeot void intel_cleanup_ring_buffer(struct intel_engine_cs *ring); 425f4e1c372SFrançois Tigeot 42619c468b4SFrançois Tigeot int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request); 42719c468b4SFrançois Tigeot 428*a05eeebfSFrançois Tigeot int __must_check intel_ring_begin(struct drm_i915_gem_request *req, int n); 429*a05eeebfSFrançois Tigeot int __must_check intel_ring_cacheline_align(struct drm_i915_gem_request *req); 430ba55f2f5SFrançois Tigeot static inline void intel_ring_emit(struct intel_engine_cs *ring, 431f4e1c372SFrançois Tigeot u32 data) 432e3adcf8fSFrançois Tigeot { 433ba55f2f5SFrançois Tigeot struct intel_ringbuffer *ringbuf = ring->buffer; 434ba55f2f5SFrançois Tigeot iowrite32(data, ringbuf->virtual_start + ringbuf->tail); 435ba55f2f5SFrançois Tigeot ringbuf->tail += 4; 436e3adcf8fSFrançois Tigeot } 437ba55f2f5SFrançois Tigeot static inline void intel_ring_advance(struct intel_engine_cs *ring) 4389edbd4a0SFrançois Tigeot { 439ba55f2f5SFrançois Tigeot struct intel_ringbuffer *ringbuf = ring->buffer; 440ba55f2f5SFrançois Tigeot ringbuf->tail &= ringbuf->size - 1; 4419edbd4a0SFrançois Tigeot } 4421b13d190SFrançois Tigeot int __intel_ring_space(int head, int tail, int size); 4432c9916cdSFrançois Tigeot void intel_ring_update_space(struct intel_ringbuffer *ringbuf); 4441b13d190SFrançois Tigeot int intel_ring_space(struct intel_ringbuffer *ringbuf); 4451b13d190SFrançois Tigeot bool intel_ring_stopped(struct intel_engine_cs *ring); 4469edbd4a0SFrançois Tigeot 447ba55f2f5SFrançois Tigeot int __must_check intel_ring_idle(struct intel_engine_cs *ring); 448ba55f2f5SFrançois Tigeot void intel_ring_init_seqno(struct intel_engine_cs *ring, u32 seqno); 449*a05eeebfSFrançois Tigeot int intel_ring_flush_all_caches(struct drm_i915_gem_request *req); 450*a05eeebfSFrançois Tigeot int intel_ring_invalidate_all_caches(struct drm_i915_gem_request *req); 451e3adcf8fSFrançois Tigeot 4521b13d190SFrançois Tigeot void intel_fini_pipe_control(struct intel_engine_cs *ring); 4531b13d190SFrançois Tigeot int intel_init_pipe_control(struct intel_engine_cs *ring); 4541b13d190SFrançois Tigeot 455e3adcf8fSFrançois Tigeot int intel_init_render_ring_buffer(struct drm_device *dev); 456e3adcf8fSFrançois Tigeot int intel_init_bsd_ring_buffer(struct drm_device *dev); 457ba55f2f5SFrançois Tigeot int intel_init_bsd2_ring_buffer(struct drm_device *dev); 458e3adcf8fSFrançois Tigeot int intel_init_blt_ring_buffer(struct drm_device *dev); 4595d0b1887SFrançois Tigeot int intel_init_vebox_ring_buffer(struct drm_device *dev); 460e3adcf8fSFrançois Tigeot 461ba55f2f5SFrançois Tigeot u64 intel_ring_get_active_head(struct intel_engine_cs *ring); 462e3adcf8fSFrançois Tigeot 4632c9916cdSFrançois Tigeot int init_workarounds_ring(struct intel_engine_cs *ring); 4642c9916cdSFrançois Tigeot 46524edb884SFrançois Tigeot static inline u32 intel_ring_get_tail(struct intel_ringbuffer *ringbuf) 466e3adcf8fSFrançois Tigeot { 46724edb884SFrançois Tigeot return ringbuf->tail; 468e3adcf8fSFrançois Tigeot } 469e3adcf8fSFrançois Tigeot 470*a05eeebfSFrançois Tigeot /* 471*a05eeebfSFrançois Tigeot * Arbitrary size for largest possible 'add request' sequence. The code paths 472*a05eeebfSFrançois Tigeot * are complex and variable. Empirical measurement shows that the worst case 473*a05eeebfSFrançois Tigeot * is ILK at 136 words. Reserving too much is better than reserving too little 474*a05eeebfSFrançois Tigeot * as that allows for corner cases that might have been missed. So the figure 475*a05eeebfSFrançois Tigeot * has been rounded up to 160 words. 476*a05eeebfSFrançois Tigeot */ 477*a05eeebfSFrançois Tigeot #define MIN_SPACE_FOR_ADD_REQUEST 160 478*a05eeebfSFrançois Tigeot 479*a05eeebfSFrançois Tigeot /* 480*a05eeebfSFrançois Tigeot * Reserve space in the ring to guarantee that the i915_add_request() call 481*a05eeebfSFrançois Tigeot * will always have sufficient room to do its stuff. The request creation 482*a05eeebfSFrançois Tigeot * code calls this automatically. 483*a05eeebfSFrançois Tigeot */ 484*a05eeebfSFrançois Tigeot void intel_ring_reserved_space_reserve(struct intel_ringbuffer *ringbuf, int size); 485*a05eeebfSFrançois Tigeot /* Cancel the reservation, e.g. because the request is being discarded. */ 486*a05eeebfSFrançois Tigeot void intel_ring_reserved_space_cancel(struct intel_ringbuffer *ringbuf); 487*a05eeebfSFrançois Tigeot /* Use the reserved space - for use by i915_add_request() only. */ 488*a05eeebfSFrançois Tigeot void intel_ring_reserved_space_use(struct intel_ringbuffer *ringbuf); 489*a05eeebfSFrançois Tigeot /* Finish with the reserved space - for use by i915_add_request() only. */ 490*a05eeebfSFrançois Tigeot void intel_ring_reserved_space_end(struct intel_ringbuffer *ringbuf); 491*a05eeebfSFrançois Tigeot 492*a05eeebfSFrançois Tigeot /* Legacy ringbuffer specific portion of reservation code: */ 493*a05eeebfSFrançois Tigeot int intel_ring_reserve_space(struct drm_i915_gem_request *request); 494f4e1c372SFrançois Tigeot 495e3adcf8fSFrançois Tigeot #endif /* _INTEL_RINGBUFFER_H_ */ 496