xref: /dflybsd-src/sys/dev/drm/i915/intel_ringbuffer.h (revision 2c9916cd50d5c4c4defa089bebed8c8865efa896)
1e3adcf8fSFrançois Tigeot #ifndef _INTEL_RINGBUFFER_H_
2e3adcf8fSFrançois Tigeot #define _INTEL_RINGBUFFER_H_
3e3adcf8fSFrançois Tigeot 
4ba55f2f5SFrançois Tigeot #include <linux/hashtable.h>
5ba55f2f5SFrançois Tigeot 
6ba55f2f5SFrançois Tigeot #define I915_CMD_HASH_ORDER 9
7ba55f2f5SFrançois Tigeot 
81b13d190SFrançois Tigeot /* Early gen2 devices have a cacheline of just 32 bytes, using 64 is overkill,
91b13d190SFrançois Tigeot  * but keeps the logic simple. Indeed, the whole purpose of this macro is just
101b13d190SFrançois Tigeot  * to give some inclination as to some of the magic values used in the various
111b13d190SFrançois Tigeot  * workarounds!
121b13d190SFrançois Tigeot  */
131b13d190SFrançois Tigeot #define CACHELINE_BYTES 64
141b13d190SFrançois Tigeot 
15f4e1c372SFrançois Tigeot /*
16f4e1c372SFrançois Tigeot  * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
17f4e1c372SFrançois Tigeot  * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
18f4e1c372SFrançois Tigeot  * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
19f4e1c372SFrançois Tigeot  *
20f4e1c372SFrançois Tigeot  * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
21f4e1c372SFrançois Tigeot  * cacheline, the Head Pointer must not be greater than the Tail
22f4e1c372SFrançois Tigeot  * Pointer."
23f4e1c372SFrançois Tigeot  */
24f4e1c372SFrançois Tigeot #define I915_RING_FREE_SPACE 64
25f4e1c372SFrançois Tigeot 
26e3adcf8fSFrançois Tigeot struct  intel_hw_status_page {
27f4e1c372SFrançois Tigeot 	u32		*page_addr;
28e3adcf8fSFrançois Tigeot 	unsigned int	gfx_addr;
29e3adcf8fSFrançois Tigeot 	struct		drm_i915_gem_object *obj;
30e3adcf8fSFrançois Tigeot };
31e3adcf8fSFrançois Tigeot 
32e3adcf8fSFrançois Tigeot #define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
33e3adcf8fSFrançois Tigeot #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
34e3adcf8fSFrançois Tigeot 
35e3adcf8fSFrançois Tigeot #define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base))
36e3adcf8fSFrançois Tigeot #define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
37e3adcf8fSFrançois Tigeot 
38e3adcf8fSFrançois Tigeot #define I915_READ_HEAD(ring)  I915_READ(RING_HEAD((ring)->mmio_base))
39e3adcf8fSFrançois Tigeot #define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
40e3adcf8fSFrançois Tigeot 
41e3adcf8fSFrançois Tigeot #define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base))
42e3adcf8fSFrançois Tigeot #define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
43e3adcf8fSFrançois Tigeot 
44e3adcf8fSFrançois Tigeot #define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base))
45e3adcf8fSFrançois Tigeot #define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
46e3adcf8fSFrançois Tigeot 
47ba55f2f5SFrançois Tigeot #define I915_READ_MODE(ring) I915_READ(RING_MI_MODE((ring)->mmio_base))
48ba55f2f5SFrançois Tigeot #define I915_WRITE_MODE(ring, val) I915_WRITE(RING_MI_MODE((ring)->mmio_base), val)
49ba55f2f5SFrançois Tigeot 
5024edb884SFrançois Tigeot /* seqno size is actually only a uint32, but since we plan to use MI_FLUSH_DW to
5124edb884SFrançois Tigeot  * do the writes, and that must have qw aligned offsets, simply pretend it's 8b.
5224edb884SFrançois Tigeot  */
5324edb884SFrançois Tigeot #define i915_semaphore_seqno_size sizeof(uint64_t)
5424edb884SFrançois Tigeot #define GEN8_SIGNAL_OFFSET(__ring, to)			     \
5524edb884SFrançois Tigeot 	(i915_gem_obj_ggtt_offset(dev_priv->semaphore_obj) + \
5624edb884SFrançois Tigeot 	((__ring)->id * I915_NUM_RINGS * i915_semaphore_seqno_size) +	\
5724edb884SFrançois Tigeot 	(i915_semaphore_seqno_size * (to)))
5824edb884SFrançois Tigeot 
5924edb884SFrançois Tigeot #define GEN8_WAIT_OFFSET(__ring, from)			     \
6024edb884SFrançois Tigeot 	(i915_gem_obj_ggtt_offset(dev_priv->semaphore_obj) + \
6124edb884SFrançois Tigeot 	((from) * I915_NUM_RINGS * i915_semaphore_seqno_size) + \
6224edb884SFrançois Tigeot 	(i915_semaphore_seqno_size * (__ring)->id))
6324edb884SFrançois Tigeot 
6424edb884SFrançois Tigeot #define GEN8_RING_SEMAPHORE_INIT do { \
6524edb884SFrançois Tigeot 	if (!dev_priv->semaphore_obj) { \
6624edb884SFrançois Tigeot 		break; \
6724edb884SFrançois Tigeot 	} \
6824edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[RCS] = GEN8_SIGNAL_OFFSET(ring, RCS); \
6924edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[VCS] = GEN8_SIGNAL_OFFSET(ring, VCS); \
7024edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[BCS] = GEN8_SIGNAL_OFFSET(ring, BCS); \
7124edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[VECS] = GEN8_SIGNAL_OFFSET(ring, VECS); \
7224edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[VCS2] = GEN8_SIGNAL_OFFSET(ring, VCS2); \
7324edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[ring->id] = MI_SEMAPHORE_SYNC_INVALID; \
7424edb884SFrançois Tigeot 	} while(0)
7524edb884SFrançois Tigeot 
769edbd4a0SFrançois Tigeot enum intel_ring_hangcheck_action {
779edbd4a0SFrançois Tigeot 	HANGCHECK_IDLE = 0,
789edbd4a0SFrançois Tigeot 	HANGCHECK_WAIT,
799edbd4a0SFrançois Tigeot 	HANGCHECK_ACTIVE,
8024edb884SFrançois Tigeot 	HANGCHECK_ACTIVE_LOOP,
819edbd4a0SFrançois Tigeot 	HANGCHECK_KICK,
829edbd4a0SFrançois Tigeot 	HANGCHECK_HUNG,
839edbd4a0SFrançois Tigeot };
845d0b1887SFrançois Tigeot 
85ba55f2f5SFrançois Tigeot #define HANGCHECK_SCORE_RING_HUNG 31
86ba55f2f5SFrançois Tigeot 
875d0b1887SFrançois Tigeot struct intel_ring_hangcheck {
88ba55f2f5SFrançois Tigeot 	u64 acthd;
8924edb884SFrançois Tigeot 	u64 max_acthd;
905d0b1887SFrançois Tigeot 	u32 seqno;
915d0b1887SFrançois Tigeot 	int score;
925d0b1887SFrançois Tigeot 	enum intel_ring_hangcheck_action action;
93ba55f2f5SFrançois Tigeot 	int deadlock;
945d0b1887SFrançois Tigeot };
955d0b1887SFrançois Tigeot 
96ba55f2f5SFrançois Tigeot struct intel_ringbuffer {
97e3adcf8fSFrançois Tigeot 	struct drm_i915_gem_object *obj;
98ba55f2f5SFrançois Tigeot 	void __iomem *virtual_start;
99e3adcf8fSFrançois Tigeot 
1001b13d190SFrançois Tigeot 	struct intel_engine_cs *ring;
1011b13d190SFrançois Tigeot 
10215ac6249SFrançois Tigeot 	u32 head;
10315ac6249SFrançois Tigeot 	u32 tail;
104e3adcf8fSFrançois Tigeot 	int space;
105e3adcf8fSFrançois Tigeot 	int size;
106e3adcf8fSFrançois Tigeot 	int effective_size;
107e3adcf8fSFrançois Tigeot 
108e3adcf8fSFrançois Tigeot 	/** We track the position of the requests in the ring buffer, and
109e3adcf8fSFrançois Tigeot 	 * when each is retired we increment last_retired_head as the GPU
110e3adcf8fSFrançois Tigeot 	 * must have finished processing the request and so we know we
111e3adcf8fSFrançois Tigeot 	 * can advance the ringbuffer up to that position.
112e3adcf8fSFrançois Tigeot 	 *
113e3adcf8fSFrançois Tigeot 	 * last_retired_head is set to -1 after the value is consumed so
114e3adcf8fSFrançois Tigeot 	 * we can detect new retirements.
115e3adcf8fSFrançois Tigeot 	 */
116e3adcf8fSFrançois Tigeot 	u32 last_retired_head;
117ba55f2f5SFrançois Tigeot };
118ba55f2f5SFrançois Tigeot 
119*2c9916cdSFrançois Tigeot struct	intel_context;
120*2c9916cdSFrançois Tigeot 
121ba55f2f5SFrançois Tigeot struct  intel_engine_cs {
122ba55f2f5SFrançois Tigeot 	const char	*name;
123ba55f2f5SFrançois Tigeot 	enum intel_ring_id {
124ba55f2f5SFrançois Tigeot 		RCS = 0x0,
125ba55f2f5SFrançois Tigeot 		VCS,
126ba55f2f5SFrançois Tigeot 		BCS,
127ba55f2f5SFrançois Tigeot 		VECS,
128ba55f2f5SFrançois Tigeot 		VCS2
129ba55f2f5SFrançois Tigeot 	} id;
130ba55f2f5SFrançois Tigeot #define I915_NUM_RINGS 5
131ba55f2f5SFrançois Tigeot #define LAST_USER_RING (VECS + 1)
132ba55f2f5SFrançois Tigeot 	u32		mmio_base;
133ba55f2f5SFrançois Tigeot 	struct		drm_device *dev;
134ba55f2f5SFrançois Tigeot 	struct intel_ringbuffer *buffer;
135ba55f2f5SFrançois Tigeot 
136ba55f2f5SFrançois Tigeot 	struct intel_hw_status_page status_page;
137e3adcf8fSFrançois Tigeot 
1389edbd4a0SFrançois Tigeot 	unsigned irq_refcount; /* protected by dev_priv->irq_lock */
13915ac6249SFrançois Tigeot 	u32		irq_enable_mask;	/* bitmask to enable ring interrupt */
140*2c9916cdSFrançois Tigeot 	struct drm_i915_gem_request *trace_irq_req;
141ba55f2f5SFrançois Tigeot 	bool __must_check (*irq_get)(struct intel_engine_cs *ring);
142ba55f2f5SFrançois Tigeot 	void		(*irq_put)(struct intel_engine_cs *ring);
143e3adcf8fSFrançois Tigeot 
144*2c9916cdSFrançois Tigeot 	int		(*init_hw)(struct intel_engine_cs *ring);
145e3adcf8fSFrançois Tigeot 
146*2c9916cdSFrançois Tigeot 	int		(*init_context)(struct intel_engine_cs *ring,
147*2c9916cdSFrançois Tigeot 					struct intel_context *ctx);
1481b13d190SFrançois Tigeot 
149ba55f2f5SFrançois Tigeot 	void		(*write_tail)(struct intel_engine_cs *ring,
15015ac6249SFrançois Tigeot 				      u32 value);
151ba55f2f5SFrançois Tigeot 	int __must_check (*flush)(struct intel_engine_cs *ring,
15215ac6249SFrançois Tigeot 				  u32	invalidate_domains,
15315ac6249SFrançois Tigeot 				  u32	flush_domains);
154ba55f2f5SFrançois Tigeot 	int		(*add_request)(struct intel_engine_cs *ring);
155b030f26bSFrançois Tigeot 	/* Some chipsets are not quite as coherent as advertised and need
156b030f26bSFrançois Tigeot 	 * an expensive kick to force a true read of the up-to-date seqno.
157b030f26bSFrançois Tigeot 	 * However, the up-to-date seqno is not always required and the last
158b030f26bSFrançois Tigeot 	 * seen value is good enough. Note that the seqno will always be
159b030f26bSFrançois Tigeot 	 * monotonic, even if not coherent.
160b030f26bSFrançois Tigeot 	 */
161ba55f2f5SFrançois Tigeot 	u32		(*get_seqno)(struct intel_engine_cs *ring,
162b030f26bSFrançois Tigeot 				     bool lazy_coherency);
163ba55f2f5SFrançois Tigeot 	void		(*set_seqno)(struct intel_engine_cs *ring,
164a2fdbec6SFrançois Tigeot 				     u32 seqno);
165ba55f2f5SFrançois Tigeot 	int		(*dispatch_execbuffer)(struct intel_engine_cs *ring,
166ba55f2f5SFrançois Tigeot 					       u64 offset, u32 length,
167b5c29a34SFrançois Tigeot 					       unsigned flags);
16815ac6249SFrançois Tigeot #define I915_DISPATCH_SECURE 0x1
16915ac6249SFrançois Tigeot #define I915_DISPATCH_PINNED 0x2
170ba55f2f5SFrançois Tigeot 	void		(*cleanup)(struct intel_engine_cs *ring);
171e3adcf8fSFrançois Tigeot 
17224edb884SFrançois Tigeot 	/* GEN8 signal/wait table - never trust comments!
17324edb884SFrançois Tigeot 	 *	  signal to	signal to    signal to   signal to      signal to
17424edb884SFrançois Tigeot 	 *	    RCS		   VCS          BCS        VECS		 VCS2
17524edb884SFrançois Tigeot 	 *      --------------------------------------------------------------------
17624edb884SFrançois Tigeot 	 *  RCS | NOP (0x00) | VCS (0x08) | BCS (0x10) | VECS (0x18) | VCS2 (0x20) |
17724edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
17824edb884SFrançois Tigeot 	 *  VCS | RCS (0x28) | NOP (0x30) | BCS (0x38) | VECS (0x40) | VCS2 (0x48) |
17924edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
18024edb884SFrançois Tigeot 	 *  BCS | RCS (0x50) | VCS (0x58) | NOP (0x60) | VECS (0x68) | VCS2 (0x70) |
18124edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
18224edb884SFrançois Tigeot 	 * VECS | RCS (0x78) | VCS (0x80) | BCS (0x88) |  NOP (0x90) | VCS2 (0x98) |
18324edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
18424edb884SFrançois Tigeot 	 * VCS2 | RCS (0xa0) | VCS (0xa8) | BCS (0xb0) | VECS (0xb8) | NOP  (0xc0) |
18524edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
18624edb884SFrançois Tigeot 	 *
18724edb884SFrançois Tigeot 	 * Generalization:
18824edb884SFrançois Tigeot 	 *  f(x, y) := (x->id * NUM_RINGS * seqno_size) + (seqno_size * y->id)
18924edb884SFrançois Tigeot 	 *  ie. transpose of g(x, y)
19024edb884SFrançois Tigeot 	 *
19124edb884SFrançois Tigeot 	 *	 sync from	sync from    sync from    sync from	sync from
19224edb884SFrançois Tigeot 	 *	    RCS		   VCS          BCS        VECS		 VCS2
19324edb884SFrançois Tigeot 	 *      --------------------------------------------------------------------
19424edb884SFrançois Tigeot 	 *  RCS | NOP (0x00) | VCS (0x28) | BCS (0x50) | VECS (0x78) | VCS2 (0xa0) |
19524edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
19624edb884SFrançois Tigeot 	 *  VCS | RCS (0x08) | NOP (0x30) | BCS (0x58) | VECS (0x80) | VCS2 (0xa8) |
19724edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
19824edb884SFrançois Tigeot 	 *  BCS | RCS (0x10) | VCS (0x38) | NOP (0x60) | VECS (0x88) | VCS2 (0xb0) |
19924edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
20024edb884SFrançois Tigeot 	 * VECS | RCS (0x18) | VCS (0x40) | BCS (0x68) |  NOP (0x90) | VCS2 (0xb8) |
20124edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
20224edb884SFrançois Tigeot 	 * VCS2 | RCS (0x20) | VCS (0x48) | BCS (0x70) | VECS (0x98) |  NOP (0xc0) |
20324edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
20424edb884SFrançois Tigeot 	 *
20524edb884SFrançois Tigeot 	 * Generalization:
20624edb884SFrançois Tigeot 	 *  g(x, y) := (y->id * NUM_RINGS * seqno_size) + (seqno_size * x->id)
20724edb884SFrançois Tigeot 	 *  ie. transpose of f(x, y)
20824edb884SFrançois Tigeot 	 */
209ba55f2f5SFrançois Tigeot 	struct {
210ba55f2f5SFrançois Tigeot 		u32	sync_seqno[I915_NUM_RINGS-1];
211ba55f2f5SFrançois Tigeot 
21224edb884SFrançois Tigeot 		union {
213ba55f2f5SFrançois Tigeot 			struct {
2145d0b1887SFrançois Tigeot 				/* our mbox written by others */
215ba55f2f5SFrançois Tigeot 				u32		wait[I915_NUM_RINGS];
2165d0b1887SFrançois Tigeot 				/* mboxes this ring signals to */
217ba55f2f5SFrançois Tigeot 				u32		signal[I915_NUM_RINGS];
218ba55f2f5SFrançois Tigeot 			} mbox;
21924edb884SFrançois Tigeot 			u64		signal_ggtt[I915_NUM_RINGS];
22024edb884SFrançois Tigeot 		};
221ba55f2f5SFrançois Tigeot 
222ba55f2f5SFrançois Tigeot 		/* AKA wait() */
223ba55f2f5SFrançois Tigeot 		int	(*sync_to)(struct intel_engine_cs *ring,
224ba55f2f5SFrançois Tigeot 				   struct intel_engine_cs *to,
225ba55f2f5SFrançois Tigeot 				   u32 seqno);
226ba55f2f5SFrançois Tigeot 		int	(*signal)(struct intel_engine_cs *signaller,
227ba55f2f5SFrançois Tigeot 				  /* num_dwords needed by caller */
228ba55f2f5SFrançois Tigeot 				  unsigned int num_dwords);
229ba55f2f5SFrançois Tigeot 	} semaphore;
2305d0b1887SFrançois Tigeot 
2311b13d190SFrançois Tigeot 	/* Execlists */
2321b13d190SFrançois Tigeot 	struct lock execlist_lock;
2331b13d190SFrançois Tigeot 	struct list_head execlist_queue;
234*2c9916cdSFrançois Tigeot 	struct list_head execlist_retired_req_list;
2351b13d190SFrançois Tigeot 	u8 next_context_status_buffer;
2361b13d190SFrançois Tigeot 	u32             irq_keep_mask; /* bitmask for interrupts that should not be masked */
237*2c9916cdSFrançois Tigeot 	int		(*emit_request)(struct intel_ringbuffer *ringbuf,
238*2c9916cdSFrançois Tigeot 					struct drm_i915_gem_request *request);
2391b13d190SFrançois Tigeot 	int		(*emit_flush)(struct intel_ringbuffer *ringbuf,
240*2c9916cdSFrançois Tigeot 				      struct intel_context *ctx,
2411b13d190SFrançois Tigeot 				      u32 invalidate_domains,
2421b13d190SFrançois Tigeot 				      u32 flush_domains);
2431b13d190SFrançois Tigeot 	int		(*emit_bb_start)(struct intel_ringbuffer *ringbuf,
244*2c9916cdSFrançois Tigeot 					 struct intel_context *ctx,
2451b13d190SFrançois Tigeot 					 u64 offset, unsigned flags);
2461b13d190SFrançois Tigeot 
247e3adcf8fSFrançois Tigeot 	/**
248e3adcf8fSFrançois Tigeot 	 * List of objects currently involved in rendering from the
249e3adcf8fSFrançois Tigeot 	 * ringbuffer.
250e3adcf8fSFrançois Tigeot 	 *
251e3adcf8fSFrançois Tigeot 	 * Includes buffers having the contents of their GPU caches
252*2c9916cdSFrançois Tigeot 	 * flushed, not necessarily primitives.  last_read_req
253e3adcf8fSFrançois Tigeot 	 * represents when the rendering involved will be completed.
254e3adcf8fSFrançois Tigeot 	 *
255e3adcf8fSFrançois Tigeot 	 * A reference is held on the buffer while on this list.
256e3adcf8fSFrançois Tigeot 	 */
257e3adcf8fSFrançois Tigeot 	struct list_head active_list;
258e3adcf8fSFrançois Tigeot 
259e3adcf8fSFrançois Tigeot 	/**
260e3adcf8fSFrançois Tigeot 	 * List of breadcrumbs associated with GPU requests currently
261e3adcf8fSFrançois Tigeot 	 * outstanding.
262e3adcf8fSFrançois Tigeot 	 */
263e3adcf8fSFrançois Tigeot 	struct list_head request_list;
264e3adcf8fSFrançois Tigeot 
265e3adcf8fSFrançois Tigeot 	/**
266e3adcf8fSFrançois Tigeot 	 * Do we have some not yet emitted requests outstanding?
267e3adcf8fSFrançois Tigeot 	 */
268*2c9916cdSFrançois Tigeot 	struct drm_i915_gem_request *outstanding_lazy_request;
269b030f26bSFrançois Tigeot 	bool gpu_caches_dirty;
2705d0b1887SFrançois Tigeot 	bool fbc_dirty;
271b030f26bSFrançois Tigeot 
272b030f26bSFrançois Tigeot 	wait_queue_head_t irq_queue;
273e3adcf8fSFrançois Tigeot 
274ba55f2f5SFrançois Tigeot 	struct intel_context *default_context;
275ba55f2f5SFrançois Tigeot 	struct intel_context *last_context;
2765d0b1887SFrançois Tigeot 
2775d0b1887SFrançois Tigeot 	struct intel_ring_hangcheck hangcheck;
27815ac6249SFrançois Tigeot 
2799edbd4a0SFrançois Tigeot 	struct {
2809edbd4a0SFrançois Tigeot 		struct drm_i915_gem_object *obj;
2819edbd4a0SFrançois Tigeot 		u32 gtt_offset;
2829edbd4a0SFrançois Tigeot 		volatile u32 *cpu_page;
2839edbd4a0SFrançois Tigeot 	} scratch;
284ba55f2f5SFrançois Tigeot 
285ba55f2f5SFrançois Tigeot 	bool needs_cmd_parser;
286ba55f2f5SFrançois Tigeot 
287ba55f2f5SFrançois Tigeot 	/*
288ba55f2f5SFrançois Tigeot 	 * Table of commands the command parser needs to know about
289ba55f2f5SFrançois Tigeot 	 * for this ring.
290ba55f2f5SFrançois Tigeot 	 */
291ba55f2f5SFrançois Tigeot 	DECLARE_HASHTABLE(cmd_hash, I915_CMD_HASH_ORDER);
292ba55f2f5SFrançois Tigeot 
293ba55f2f5SFrançois Tigeot 	/*
294ba55f2f5SFrançois Tigeot 	 * Table of registers allowed in commands that read/write registers.
295ba55f2f5SFrançois Tigeot 	 */
296ba55f2f5SFrançois Tigeot 	const u32 *reg_table;
297ba55f2f5SFrançois Tigeot 	int reg_count;
298ba55f2f5SFrançois Tigeot 
299ba55f2f5SFrançois Tigeot 	/*
300ba55f2f5SFrançois Tigeot 	 * Table of registers allowed in commands that read/write registers, but
301ba55f2f5SFrançois Tigeot 	 * only from the DRM master.
302ba55f2f5SFrançois Tigeot 	 */
303ba55f2f5SFrançois Tigeot 	const u32 *master_reg_table;
304ba55f2f5SFrançois Tigeot 	int master_reg_count;
305ba55f2f5SFrançois Tigeot 
306ba55f2f5SFrançois Tigeot 	/*
307ba55f2f5SFrançois Tigeot 	 * Returns the bitmask for the length field of the specified command.
308ba55f2f5SFrançois Tigeot 	 * Return 0 for an unrecognized/invalid command.
309ba55f2f5SFrançois Tigeot 	 *
310ba55f2f5SFrançois Tigeot 	 * If the command parser finds an entry for a command in the ring's
311ba55f2f5SFrançois Tigeot 	 * cmd_tables, it gets the command's length based on the table entry.
312ba55f2f5SFrançois Tigeot 	 * If not, it calls this function to determine the per-ring length field
313ba55f2f5SFrançois Tigeot 	 * encoding for the command (i.e. certain opcode ranges use certain bits
314ba55f2f5SFrançois Tigeot 	 * to encode the command length in the header).
315ba55f2f5SFrançois Tigeot 	 */
316ba55f2f5SFrançois Tigeot 	u32 (*get_cmd_length_mask)(u32 cmd_header);
317e3adcf8fSFrançois Tigeot };
318e3adcf8fSFrançois Tigeot 
3191b13d190SFrançois Tigeot bool intel_ring_initialized(struct intel_engine_cs *ring);
320f4e1c372SFrançois Tigeot 
321e3adcf8fSFrançois Tigeot static inline unsigned
322ba55f2f5SFrançois Tigeot intel_ring_flag(struct intel_engine_cs *ring)
323e3adcf8fSFrançois Tigeot {
324e3adcf8fSFrançois Tigeot 	return 1 << ring->id;
325e3adcf8fSFrançois Tigeot }
326e3adcf8fSFrançois Tigeot 
327f4e1c372SFrançois Tigeot static inline u32
328ba55f2f5SFrançois Tigeot intel_ring_sync_index(struct intel_engine_cs *ring,
329ba55f2f5SFrançois Tigeot 		      struct intel_engine_cs *other)
330e3adcf8fSFrançois Tigeot {
331e3adcf8fSFrançois Tigeot 	int idx;
332e3adcf8fSFrançois Tigeot 
333e3adcf8fSFrançois Tigeot 	/*
33424edb884SFrançois Tigeot 	 * rcs -> 0 = vcs, 1 = bcs, 2 = vecs, 3 = vcs2;
33524edb884SFrançois Tigeot 	 * vcs -> 0 = bcs, 1 = vecs, 2 = vcs2, 3 = rcs;
33624edb884SFrançois Tigeot 	 * bcs -> 0 = vecs, 1 = vcs2. 2 = rcs, 3 = vcs;
33724edb884SFrançois Tigeot 	 * vecs -> 0 = vcs2, 1 = rcs, 2 = vcs, 3 = bcs;
33824edb884SFrançois Tigeot 	 * vcs2 -> 0 = rcs, 1 = vcs, 2 = bcs, 3 = vecs;
339e3adcf8fSFrançois Tigeot 	 */
340e3adcf8fSFrançois Tigeot 
341e3adcf8fSFrançois Tigeot 	idx = (other - ring) - 1;
342e3adcf8fSFrançois Tigeot 	if (idx < 0)
343e3adcf8fSFrançois Tigeot 		idx += I915_NUM_RINGS;
344e3adcf8fSFrançois Tigeot 
345e3adcf8fSFrançois Tigeot 	return idx;
346e3adcf8fSFrançois Tigeot }
347e3adcf8fSFrançois Tigeot 
348f4e1c372SFrançois Tigeot static inline u32
349ba55f2f5SFrançois Tigeot intel_read_status_page(struct intel_engine_cs *ring,
350f4e1c372SFrançois Tigeot 		       int reg)
351e3adcf8fSFrançois Tigeot {
352f4e1c372SFrançois Tigeot 	/* Ensure that the compiler doesn't optimize away the load. */
3539edbd4a0SFrançois Tigeot 	barrier();
354f4e1c372SFrançois Tigeot 	return ring->status_page.page_addr[reg];
355e3adcf8fSFrançois Tigeot }
356e3adcf8fSFrançois Tigeot 
357a2fdbec6SFrançois Tigeot static inline void
358ba55f2f5SFrançois Tigeot intel_write_status_page(struct intel_engine_cs *ring,
359a2fdbec6SFrançois Tigeot 			int reg, u32 value)
360a2fdbec6SFrançois Tigeot {
361a2fdbec6SFrançois Tigeot 	ring->status_page.page_addr[reg] = value;
362a2fdbec6SFrançois Tigeot }
363a2fdbec6SFrançois Tigeot 
364f4e1c372SFrançois Tigeot /**
365f4e1c372SFrançois Tigeot  * Reads a dword out of the status page, which is written to from the command
366f4e1c372SFrançois Tigeot  * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
367f4e1c372SFrançois Tigeot  * MI_STORE_DATA_IMM.
368f4e1c372SFrançois Tigeot  *
369f4e1c372SFrançois Tigeot  * The following dwords have a reserved meaning:
370f4e1c372SFrançois Tigeot  * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
371f4e1c372SFrançois Tigeot  * 0x04: ring 0 head pointer
372f4e1c372SFrançois Tigeot  * 0x05: ring 1 head pointer (915-class)
373f4e1c372SFrançois Tigeot  * 0x06: ring 2 head pointer (915-class)
374f4e1c372SFrançois Tigeot  * 0x10-0x1b: Context status DWords (GM45)
375f4e1c372SFrançois Tigeot  * 0x1f: Last written status offset. (GM45)
376f4e1c372SFrançois Tigeot  *
377f4e1c372SFrançois Tigeot  * The area from dword 0x20 to 0x3ff is available for driver usage.
378f4e1c372SFrançois Tigeot  */
379f4e1c372SFrançois Tigeot #define I915_GEM_HWS_INDEX		0x20
380f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_INDEX	0x30
381f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
382e3adcf8fSFrançois Tigeot 
383*2c9916cdSFrançois Tigeot void intel_unpin_ringbuffer_obj(struct intel_ringbuffer *ringbuf);
384*2c9916cdSFrançois Tigeot int intel_pin_and_map_ringbuffer_obj(struct drm_device *dev,
385*2c9916cdSFrançois Tigeot 				     struct intel_ringbuffer *ringbuf);
3861b13d190SFrançois Tigeot void intel_destroy_ringbuffer_obj(struct intel_ringbuffer *ringbuf);
3871b13d190SFrançois Tigeot int intel_alloc_ringbuffer_obj(struct drm_device *dev,
3881b13d190SFrançois Tigeot 			       struct intel_ringbuffer *ringbuf);
3891b13d190SFrançois Tigeot 
390ba55f2f5SFrançois Tigeot void intel_stop_ring_buffer(struct intel_engine_cs *ring);
391ba55f2f5SFrançois Tigeot void intel_cleanup_ring_buffer(struct intel_engine_cs *ring);
392f4e1c372SFrançois Tigeot 
393ba55f2f5SFrançois Tigeot int __must_check intel_ring_begin(struct intel_engine_cs *ring, int n);
394ba55f2f5SFrançois Tigeot int __must_check intel_ring_cacheline_align(struct intel_engine_cs *ring);
395ba55f2f5SFrançois Tigeot static inline void intel_ring_emit(struct intel_engine_cs *ring,
396f4e1c372SFrançois Tigeot 				   u32 data)
397e3adcf8fSFrançois Tigeot {
398ba55f2f5SFrançois Tigeot 	struct intel_ringbuffer *ringbuf = ring->buffer;
399ba55f2f5SFrançois Tigeot 	iowrite32(data, ringbuf->virtual_start + ringbuf->tail);
400ba55f2f5SFrançois Tigeot 	ringbuf->tail += 4;
401e3adcf8fSFrançois Tigeot }
402ba55f2f5SFrançois Tigeot static inline void intel_ring_advance(struct intel_engine_cs *ring)
4039edbd4a0SFrançois Tigeot {
404ba55f2f5SFrançois Tigeot 	struct intel_ringbuffer *ringbuf = ring->buffer;
405ba55f2f5SFrançois Tigeot 	ringbuf->tail &= ringbuf->size - 1;
4069edbd4a0SFrançois Tigeot }
4071b13d190SFrançois Tigeot int __intel_ring_space(int head, int tail, int size);
408*2c9916cdSFrançois Tigeot void intel_ring_update_space(struct intel_ringbuffer *ringbuf);
4091b13d190SFrançois Tigeot int intel_ring_space(struct intel_ringbuffer *ringbuf);
4101b13d190SFrançois Tigeot bool intel_ring_stopped(struct intel_engine_cs *ring);
411ba55f2f5SFrançois Tigeot void __intel_ring_advance(struct intel_engine_cs *ring);
4129edbd4a0SFrançois Tigeot 
413ba55f2f5SFrançois Tigeot int __must_check intel_ring_idle(struct intel_engine_cs *ring);
414ba55f2f5SFrançois Tigeot void intel_ring_init_seqno(struct intel_engine_cs *ring, u32 seqno);
415ba55f2f5SFrançois Tigeot int intel_ring_flush_all_caches(struct intel_engine_cs *ring);
416ba55f2f5SFrançois Tigeot int intel_ring_invalidate_all_caches(struct intel_engine_cs *ring);
417e3adcf8fSFrançois Tigeot 
4181b13d190SFrançois Tigeot void intel_fini_pipe_control(struct intel_engine_cs *ring);
4191b13d190SFrançois Tigeot int intel_init_pipe_control(struct intel_engine_cs *ring);
4201b13d190SFrançois Tigeot 
421e3adcf8fSFrançois Tigeot int intel_init_render_ring_buffer(struct drm_device *dev);
422e3adcf8fSFrançois Tigeot int intel_init_bsd_ring_buffer(struct drm_device *dev);
423ba55f2f5SFrançois Tigeot int intel_init_bsd2_ring_buffer(struct drm_device *dev);
424e3adcf8fSFrançois Tigeot int intel_init_blt_ring_buffer(struct drm_device *dev);
4255d0b1887SFrançois Tigeot int intel_init_vebox_ring_buffer(struct drm_device *dev);
426e3adcf8fSFrançois Tigeot 
427ba55f2f5SFrançois Tigeot u64 intel_ring_get_active_head(struct intel_engine_cs *ring);
428ba55f2f5SFrançois Tigeot void intel_ring_setup_status_page(struct intel_engine_cs *ring);
429e3adcf8fSFrançois Tigeot 
430*2c9916cdSFrançois Tigeot int init_workarounds_ring(struct intel_engine_cs *ring);
431*2c9916cdSFrançois Tigeot 
43224edb884SFrançois Tigeot static inline u32 intel_ring_get_tail(struct intel_ringbuffer *ringbuf)
433e3adcf8fSFrançois Tigeot {
43424edb884SFrançois Tigeot 	return ringbuf->tail;
435e3adcf8fSFrançois Tigeot }
436e3adcf8fSFrançois Tigeot 
437*2c9916cdSFrançois Tigeot static inline struct drm_i915_gem_request *
438*2c9916cdSFrançois Tigeot intel_ring_get_request(struct intel_engine_cs *ring)
439f4e1c372SFrançois Tigeot {
440*2c9916cdSFrançois Tigeot 	BUG_ON(ring->outstanding_lazy_request == NULL);
441*2c9916cdSFrançois Tigeot 	return ring->outstanding_lazy_request;
442f4e1c372SFrançois Tigeot }
443f4e1c372SFrançois Tigeot 
444e3adcf8fSFrançois Tigeot #endif /* _INTEL_RINGBUFFER_H_ */
445