xref: /dflybsd-src/sys/dev/drm/i915/intel_ringbuffer.h (revision 24edb8848e2499ece59b84a04f554a7a897feeab)
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 
8f4e1c372SFrançois Tigeot /*
9f4e1c372SFrançois Tigeot  * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
10f4e1c372SFrançois Tigeot  * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
11f4e1c372SFrançois Tigeot  * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
12f4e1c372SFrançois Tigeot  *
13f4e1c372SFrançois Tigeot  * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
14f4e1c372SFrançois Tigeot  * cacheline, the Head Pointer must not be greater than the Tail
15f4e1c372SFrançois Tigeot  * Pointer."
16f4e1c372SFrançois Tigeot  */
17f4e1c372SFrançois Tigeot #define I915_RING_FREE_SPACE 64
18f4e1c372SFrançois Tigeot 
19e3adcf8fSFrançois Tigeot struct  intel_hw_status_page {
20f4e1c372SFrançois Tigeot 	u32		*page_addr;
21e3adcf8fSFrançois Tigeot 	unsigned int	gfx_addr;
22e3adcf8fSFrançois Tigeot 	struct		drm_i915_gem_object *obj;
23e3adcf8fSFrançois Tigeot };
24e3adcf8fSFrançois Tigeot 
25e3adcf8fSFrançois Tigeot #define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
26e3adcf8fSFrançois Tigeot #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
27e3adcf8fSFrançois Tigeot 
28e3adcf8fSFrançois Tigeot #define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base))
29e3adcf8fSFrançois Tigeot #define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
30e3adcf8fSFrançois Tigeot 
31e3adcf8fSFrançois Tigeot #define I915_READ_HEAD(ring)  I915_READ(RING_HEAD((ring)->mmio_base))
32e3adcf8fSFrançois Tigeot #define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
33e3adcf8fSFrançois Tigeot 
34e3adcf8fSFrançois Tigeot #define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base))
35e3adcf8fSFrançois Tigeot #define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
36e3adcf8fSFrançois Tigeot 
37e3adcf8fSFrançois Tigeot #define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base))
38e3adcf8fSFrançois Tigeot #define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
39e3adcf8fSFrançois Tigeot 
40ba55f2f5SFrançois Tigeot #define I915_READ_MODE(ring) I915_READ(RING_MI_MODE((ring)->mmio_base))
41ba55f2f5SFrançois Tigeot #define I915_WRITE_MODE(ring, val) I915_WRITE(RING_MI_MODE((ring)->mmio_base), val)
42ba55f2f5SFrançois Tigeot 
43*24edb884SFrançois Tigeot /* seqno size is actually only a uint32, but since we plan to use MI_FLUSH_DW to
44*24edb884SFrançois Tigeot  * do the writes, and that must have qw aligned offsets, simply pretend it's 8b.
45*24edb884SFrançois Tigeot  */
46*24edb884SFrançois Tigeot #define i915_semaphore_seqno_size sizeof(uint64_t)
47*24edb884SFrançois Tigeot #define GEN8_SIGNAL_OFFSET(__ring, to)			     \
48*24edb884SFrançois Tigeot 	(i915_gem_obj_ggtt_offset(dev_priv->semaphore_obj) + \
49*24edb884SFrançois Tigeot 	((__ring)->id * I915_NUM_RINGS * i915_semaphore_seqno_size) +	\
50*24edb884SFrançois Tigeot 	(i915_semaphore_seqno_size * (to)))
51*24edb884SFrançois Tigeot 
52*24edb884SFrançois Tigeot #define GEN8_WAIT_OFFSET(__ring, from)			     \
53*24edb884SFrançois Tigeot 	(i915_gem_obj_ggtt_offset(dev_priv->semaphore_obj) + \
54*24edb884SFrançois Tigeot 	((from) * I915_NUM_RINGS * i915_semaphore_seqno_size) + \
55*24edb884SFrançois Tigeot 	(i915_semaphore_seqno_size * (__ring)->id))
56*24edb884SFrançois Tigeot 
57*24edb884SFrançois Tigeot #define GEN8_RING_SEMAPHORE_INIT do { \
58*24edb884SFrançois Tigeot 	if (!dev_priv->semaphore_obj) { \
59*24edb884SFrançois Tigeot 		break; \
60*24edb884SFrançois Tigeot 	} \
61*24edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[RCS] = GEN8_SIGNAL_OFFSET(ring, RCS); \
62*24edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[VCS] = GEN8_SIGNAL_OFFSET(ring, VCS); \
63*24edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[BCS] = GEN8_SIGNAL_OFFSET(ring, BCS); \
64*24edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[VECS] = GEN8_SIGNAL_OFFSET(ring, VECS); \
65*24edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[VCS2] = GEN8_SIGNAL_OFFSET(ring, VCS2); \
66*24edb884SFrançois Tigeot 	ring->semaphore.signal_ggtt[ring->id] = MI_SEMAPHORE_SYNC_INVALID; \
67*24edb884SFrançois Tigeot 	} while(0)
68*24edb884SFrançois Tigeot 
699edbd4a0SFrançois Tigeot enum intel_ring_hangcheck_action {
709edbd4a0SFrançois Tigeot 	HANGCHECK_IDLE = 0,
719edbd4a0SFrançois Tigeot 	HANGCHECK_WAIT,
729edbd4a0SFrançois Tigeot 	HANGCHECK_ACTIVE,
73*24edb884SFrançois Tigeot 	HANGCHECK_ACTIVE_LOOP,
749edbd4a0SFrançois Tigeot 	HANGCHECK_KICK,
759edbd4a0SFrançois Tigeot 	HANGCHECK_HUNG,
769edbd4a0SFrançois Tigeot };
775d0b1887SFrançois Tigeot 
78ba55f2f5SFrançois Tigeot #define HANGCHECK_SCORE_RING_HUNG 31
79ba55f2f5SFrançois Tigeot 
805d0b1887SFrançois Tigeot struct intel_ring_hangcheck {
81ba55f2f5SFrançois Tigeot 	u64 acthd;
82*24edb884SFrançois Tigeot 	u64 max_acthd;
835d0b1887SFrançois Tigeot 	u32 seqno;
845d0b1887SFrançois Tigeot 	int score;
855d0b1887SFrançois Tigeot 	enum intel_ring_hangcheck_action action;
86ba55f2f5SFrançois Tigeot 	int deadlock;
875d0b1887SFrançois Tigeot };
885d0b1887SFrançois Tigeot 
89ba55f2f5SFrançois Tigeot struct intel_ringbuffer {
90e3adcf8fSFrançois Tigeot 	struct drm_i915_gem_object *obj;
91ba55f2f5SFrançois Tigeot 	void __iomem *virtual_start;
92e3adcf8fSFrançois Tigeot 
9315ac6249SFrançois Tigeot 	u32 head;
9415ac6249SFrançois Tigeot 	u32 tail;
95e3adcf8fSFrançois Tigeot 	int space;
96e3adcf8fSFrançois Tigeot 	int size;
97e3adcf8fSFrançois Tigeot 	int effective_size;
98e3adcf8fSFrançois Tigeot 
99e3adcf8fSFrançois Tigeot 	/** We track the position of the requests in the ring buffer, and
100e3adcf8fSFrançois Tigeot 	 * when each is retired we increment last_retired_head as the GPU
101e3adcf8fSFrançois Tigeot 	 * must have finished processing the request and so we know we
102e3adcf8fSFrançois Tigeot 	 * can advance the ringbuffer up to that position.
103e3adcf8fSFrançois Tigeot 	 *
104e3adcf8fSFrançois Tigeot 	 * last_retired_head is set to -1 after the value is consumed so
105e3adcf8fSFrançois Tigeot 	 * we can detect new retirements.
106e3adcf8fSFrançois Tigeot 	 */
107e3adcf8fSFrançois Tigeot 	u32 last_retired_head;
108ba55f2f5SFrançois Tigeot };
109ba55f2f5SFrançois Tigeot 
110ba55f2f5SFrançois Tigeot struct  intel_engine_cs {
111ba55f2f5SFrançois Tigeot 	const char	*name;
112ba55f2f5SFrançois Tigeot 	enum intel_ring_id {
113ba55f2f5SFrançois Tigeot 		RCS = 0x0,
114ba55f2f5SFrançois Tigeot 		VCS,
115ba55f2f5SFrançois Tigeot 		BCS,
116ba55f2f5SFrançois Tigeot 		VECS,
117ba55f2f5SFrançois Tigeot 		VCS2
118ba55f2f5SFrançois Tigeot 	} id;
119ba55f2f5SFrançois Tigeot #define I915_NUM_RINGS 5
120ba55f2f5SFrançois Tigeot #define LAST_USER_RING (VECS + 1)
121ba55f2f5SFrançois Tigeot 	u32		mmio_base;
122ba55f2f5SFrançois Tigeot 	struct		drm_device *dev;
123ba55f2f5SFrançois Tigeot 	struct intel_ringbuffer *buffer;
124ba55f2f5SFrançois Tigeot 
125ba55f2f5SFrançois Tigeot 	struct intel_hw_status_page status_page;
126e3adcf8fSFrançois Tigeot 
1279edbd4a0SFrançois Tigeot 	unsigned irq_refcount; /* protected by dev_priv->irq_lock */
12815ac6249SFrançois Tigeot 	u32		irq_enable_mask;	/* bitmask to enable ring interrupt */
129b030f26bSFrançois Tigeot 	u32		trace_irq_seqno;
130ba55f2f5SFrançois Tigeot 	bool __must_check (*irq_get)(struct intel_engine_cs *ring);
131ba55f2f5SFrançois Tigeot 	void		(*irq_put)(struct intel_engine_cs *ring);
132e3adcf8fSFrançois Tigeot 
133ba55f2f5SFrançois Tigeot 	int		(*init)(struct intel_engine_cs *ring);
134e3adcf8fSFrançois Tigeot 
135ba55f2f5SFrançois Tigeot 	void		(*write_tail)(struct intel_engine_cs *ring,
13615ac6249SFrançois Tigeot 				      u32 value);
137ba55f2f5SFrançois Tigeot 	int __must_check (*flush)(struct intel_engine_cs *ring,
13815ac6249SFrançois Tigeot 				  u32	invalidate_domains,
13915ac6249SFrançois Tigeot 				  u32	flush_domains);
140ba55f2f5SFrançois Tigeot 	int		(*add_request)(struct intel_engine_cs *ring);
141b030f26bSFrançois Tigeot 	/* Some chipsets are not quite as coherent as advertised and need
142b030f26bSFrançois Tigeot 	 * an expensive kick to force a true read of the up-to-date seqno.
143b030f26bSFrançois Tigeot 	 * However, the up-to-date seqno is not always required and the last
144b030f26bSFrançois Tigeot 	 * seen value is good enough. Note that the seqno will always be
145b030f26bSFrançois Tigeot 	 * monotonic, even if not coherent.
146b030f26bSFrançois Tigeot 	 */
147ba55f2f5SFrançois Tigeot 	u32		(*get_seqno)(struct intel_engine_cs *ring,
148b030f26bSFrançois Tigeot 				     bool lazy_coherency);
149ba55f2f5SFrançois Tigeot 	void		(*set_seqno)(struct intel_engine_cs *ring,
150a2fdbec6SFrançois Tigeot 				     u32 seqno);
151ba55f2f5SFrançois Tigeot 	int		(*dispatch_execbuffer)(struct intel_engine_cs *ring,
152ba55f2f5SFrançois Tigeot 					       u64 offset, u32 length,
153b5c29a34SFrançois Tigeot 					       unsigned flags);
15415ac6249SFrançois Tigeot #define I915_DISPATCH_SECURE 0x1
15515ac6249SFrançois Tigeot #define I915_DISPATCH_PINNED 0x2
156ba55f2f5SFrançois Tigeot 	void		(*cleanup)(struct intel_engine_cs *ring);
157e3adcf8fSFrançois Tigeot 
158*24edb884SFrançois Tigeot 	/* GEN8 signal/wait table - never trust comments!
159*24edb884SFrançois Tigeot 	 *	  signal to	signal to    signal to   signal to      signal to
160*24edb884SFrançois Tigeot 	 *	    RCS		   VCS          BCS        VECS		 VCS2
161*24edb884SFrançois Tigeot 	 *      --------------------------------------------------------------------
162*24edb884SFrançois Tigeot 	 *  RCS | NOP (0x00) | VCS (0x08) | BCS (0x10) | VECS (0x18) | VCS2 (0x20) |
163*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
164*24edb884SFrançois Tigeot 	 *  VCS | RCS (0x28) | NOP (0x30) | BCS (0x38) | VECS (0x40) | VCS2 (0x48) |
165*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
166*24edb884SFrançois Tigeot 	 *  BCS | RCS (0x50) | VCS (0x58) | NOP (0x60) | VECS (0x68) | VCS2 (0x70) |
167*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
168*24edb884SFrançois Tigeot 	 * VECS | RCS (0x78) | VCS (0x80) | BCS (0x88) |  NOP (0x90) | VCS2 (0x98) |
169*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
170*24edb884SFrançois Tigeot 	 * VCS2 | RCS (0xa0) | VCS (0xa8) | BCS (0xb0) | VECS (0xb8) | NOP  (0xc0) |
171*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
172*24edb884SFrançois Tigeot 	 *
173*24edb884SFrançois Tigeot 	 * Generalization:
174*24edb884SFrançois Tigeot 	 *  f(x, y) := (x->id * NUM_RINGS * seqno_size) + (seqno_size * y->id)
175*24edb884SFrançois Tigeot 	 *  ie. transpose of g(x, y)
176*24edb884SFrançois Tigeot 	 *
177*24edb884SFrançois Tigeot 	 *	 sync from	sync from    sync from    sync from	sync from
178*24edb884SFrançois Tigeot 	 *	    RCS		   VCS          BCS        VECS		 VCS2
179*24edb884SFrançois Tigeot 	 *      --------------------------------------------------------------------
180*24edb884SFrançois Tigeot 	 *  RCS | NOP (0x00) | VCS (0x28) | BCS (0x50) | VECS (0x78) | VCS2 (0xa0) |
181*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
182*24edb884SFrançois Tigeot 	 *  VCS | RCS (0x08) | NOP (0x30) | BCS (0x58) | VECS (0x80) | VCS2 (0xa8) |
183*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
184*24edb884SFrançois Tigeot 	 *  BCS | RCS (0x10) | VCS (0x38) | NOP (0x60) | VECS (0x88) | VCS2 (0xb0) |
185*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
186*24edb884SFrançois Tigeot 	 * VECS | RCS (0x18) | VCS (0x40) | BCS (0x68) |  NOP (0x90) | VCS2 (0xb8) |
187*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
188*24edb884SFrançois Tigeot 	 * VCS2 | RCS (0x20) | VCS (0x48) | BCS (0x70) | VECS (0x98) |  NOP (0xc0) |
189*24edb884SFrançois Tigeot 	 *	|-------------------------------------------------------------------
190*24edb884SFrançois Tigeot 	 *
191*24edb884SFrançois Tigeot 	 * Generalization:
192*24edb884SFrançois Tigeot 	 *  g(x, y) := (y->id * NUM_RINGS * seqno_size) + (seqno_size * x->id)
193*24edb884SFrançois Tigeot 	 *  ie. transpose of f(x, y)
194*24edb884SFrançois Tigeot 	 */
195ba55f2f5SFrançois Tigeot 	struct {
196ba55f2f5SFrançois Tigeot 		u32	sync_seqno[I915_NUM_RINGS-1];
197ba55f2f5SFrançois Tigeot 
198*24edb884SFrançois Tigeot 		union {
199ba55f2f5SFrançois Tigeot 			struct {
2005d0b1887SFrançois Tigeot 				/* our mbox written by others */
201ba55f2f5SFrançois Tigeot 				u32		wait[I915_NUM_RINGS];
2025d0b1887SFrançois Tigeot 				/* mboxes this ring signals to */
203ba55f2f5SFrançois Tigeot 				u32		signal[I915_NUM_RINGS];
204ba55f2f5SFrançois Tigeot 			} mbox;
205*24edb884SFrançois Tigeot 			u64		signal_ggtt[I915_NUM_RINGS];
206*24edb884SFrançois Tigeot 		};
207ba55f2f5SFrançois Tigeot 
208ba55f2f5SFrançois Tigeot 		/* AKA wait() */
209ba55f2f5SFrançois Tigeot 		int	(*sync_to)(struct intel_engine_cs *ring,
210ba55f2f5SFrançois Tigeot 				   struct intel_engine_cs *to,
211ba55f2f5SFrançois Tigeot 				   u32 seqno);
212ba55f2f5SFrançois Tigeot 		int	(*signal)(struct intel_engine_cs *signaller,
213ba55f2f5SFrançois Tigeot 				  /* num_dwords needed by caller */
214ba55f2f5SFrançois Tigeot 				  unsigned int num_dwords);
215ba55f2f5SFrançois Tigeot 	} semaphore;
2165d0b1887SFrançois Tigeot 
217e3adcf8fSFrançois Tigeot 	/**
218e3adcf8fSFrançois Tigeot 	 * List of objects currently involved in rendering from the
219e3adcf8fSFrançois Tigeot 	 * ringbuffer.
220e3adcf8fSFrançois Tigeot 	 *
221e3adcf8fSFrançois Tigeot 	 * Includes buffers having the contents of their GPU caches
222e3adcf8fSFrançois Tigeot 	 * flushed, not necessarily primitives.  last_rendering_seqno
223e3adcf8fSFrançois Tigeot 	 * represents when the rendering involved will be completed.
224e3adcf8fSFrançois Tigeot 	 *
225e3adcf8fSFrançois Tigeot 	 * A reference is held on the buffer while on this list.
226e3adcf8fSFrançois Tigeot 	 */
227e3adcf8fSFrançois Tigeot 	struct list_head active_list;
228e3adcf8fSFrançois Tigeot 
229e3adcf8fSFrançois Tigeot 	/**
230e3adcf8fSFrançois Tigeot 	 * List of breadcrumbs associated with GPU requests currently
231e3adcf8fSFrançois Tigeot 	 * outstanding.
232e3adcf8fSFrançois Tigeot 	 */
233e3adcf8fSFrançois Tigeot 	struct list_head request_list;
234e3adcf8fSFrançois Tigeot 
235e3adcf8fSFrançois Tigeot 	/**
236e3adcf8fSFrançois Tigeot 	 * Do we have some not yet emitted requests outstanding?
237e3adcf8fSFrançois Tigeot 	 */
2389edbd4a0SFrançois Tigeot 	struct drm_i915_gem_request *preallocated_lazy_request;
2399edbd4a0SFrançois Tigeot 	u32 outstanding_lazy_seqno;
240b030f26bSFrançois Tigeot 	bool gpu_caches_dirty;
2415d0b1887SFrançois Tigeot 	bool fbc_dirty;
242b030f26bSFrançois Tigeot 
243b030f26bSFrançois Tigeot 	wait_queue_head_t irq_queue;
244e3adcf8fSFrançois Tigeot 
245ba55f2f5SFrançois Tigeot 	struct intel_context *default_context;
246ba55f2f5SFrançois Tigeot 	struct intel_context *last_context;
2475d0b1887SFrançois Tigeot 
2485d0b1887SFrançois Tigeot 	struct intel_ring_hangcheck hangcheck;
24915ac6249SFrançois Tigeot 
2509edbd4a0SFrançois Tigeot 	struct {
2519edbd4a0SFrançois Tigeot 		struct drm_i915_gem_object *obj;
2529edbd4a0SFrançois Tigeot 		u32 gtt_offset;
2539edbd4a0SFrançois Tigeot 		volatile u32 *cpu_page;
2549edbd4a0SFrançois Tigeot 	} scratch;
255ba55f2f5SFrançois Tigeot 
256ba55f2f5SFrançois Tigeot 	bool needs_cmd_parser;
257ba55f2f5SFrançois Tigeot 
258ba55f2f5SFrançois Tigeot 	/*
259ba55f2f5SFrançois Tigeot 	 * Table of commands the command parser needs to know about
260ba55f2f5SFrançois Tigeot 	 * for this ring.
261ba55f2f5SFrançois Tigeot 	 */
262ba55f2f5SFrançois Tigeot 	DECLARE_HASHTABLE(cmd_hash, I915_CMD_HASH_ORDER);
263ba55f2f5SFrançois Tigeot 
264ba55f2f5SFrançois Tigeot 	/*
265ba55f2f5SFrançois Tigeot 	 * Table of registers allowed in commands that read/write registers.
266ba55f2f5SFrançois Tigeot 	 */
267ba55f2f5SFrançois Tigeot 	const u32 *reg_table;
268ba55f2f5SFrançois Tigeot 	int reg_count;
269ba55f2f5SFrançois Tigeot 
270ba55f2f5SFrançois Tigeot 	/*
271ba55f2f5SFrançois Tigeot 	 * Table of registers allowed in commands that read/write registers, but
272ba55f2f5SFrançois Tigeot 	 * only from the DRM master.
273ba55f2f5SFrançois Tigeot 	 */
274ba55f2f5SFrançois Tigeot 	const u32 *master_reg_table;
275ba55f2f5SFrançois Tigeot 	int master_reg_count;
276ba55f2f5SFrançois Tigeot 
277ba55f2f5SFrançois Tigeot 	/*
278ba55f2f5SFrançois Tigeot 	 * Returns the bitmask for the length field of the specified command.
279ba55f2f5SFrançois Tigeot 	 * Return 0 for an unrecognized/invalid command.
280ba55f2f5SFrançois Tigeot 	 *
281ba55f2f5SFrançois Tigeot 	 * If the command parser finds an entry for a command in the ring's
282ba55f2f5SFrançois Tigeot 	 * cmd_tables, it gets the command's length based on the table entry.
283ba55f2f5SFrançois Tigeot 	 * If not, it calls this function to determine the per-ring length field
284ba55f2f5SFrançois Tigeot 	 * encoding for the command (i.e. certain opcode ranges use certain bits
285ba55f2f5SFrançois Tigeot 	 * to encode the command length in the header).
286ba55f2f5SFrançois Tigeot 	 */
287ba55f2f5SFrançois Tigeot 	u32 (*get_cmd_length_mask)(u32 cmd_header);
288e3adcf8fSFrançois Tigeot };
289e3adcf8fSFrançois Tigeot 
290f4e1c372SFrançois Tigeot static inline bool
291ba55f2f5SFrançois Tigeot intel_ring_initialized(struct intel_engine_cs *ring)
292f4e1c372SFrançois Tigeot {
293ba55f2f5SFrançois Tigeot 	return ring->buffer && ring->buffer->obj;
294f4e1c372SFrançois Tigeot }
295f4e1c372SFrançois Tigeot 
296e3adcf8fSFrançois Tigeot static inline unsigned
297ba55f2f5SFrançois Tigeot intel_ring_flag(struct intel_engine_cs *ring)
298e3adcf8fSFrançois Tigeot {
299e3adcf8fSFrançois Tigeot 	return 1 << ring->id;
300e3adcf8fSFrançois Tigeot }
301e3adcf8fSFrançois Tigeot 
302f4e1c372SFrançois Tigeot static inline u32
303ba55f2f5SFrançois Tigeot intel_ring_sync_index(struct intel_engine_cs *ring,
304ba55f2f5SFrançois Tigeot 		      struct intel_engine_cs *other)
305e3adcf8fSFrançois Tigeot {
306e3adcf8fSFrançois Tigeot 	int idx;
307e3adcf8fSFrançois Tigeot 
308e3adcf8fSFrançois Tigeot 	/*
309*24edb884SFrançois Tigeot 	 * rcs -> 0 = vcs, 1 = bcs, 2 = vecs, 3 = vcs2;
310*24edb884SFrançois Tigeot 	 * vcs -> 0 = bcs, 1 = vecs, 2 = vcs2, 3 = rcs;
311*24edb884SFrançois Tigeot 	 * bcs -> 0 = vecs, 1 = vcs2. 2 = rcs, 3 = vcs;
312*24edb884SFrançois Tigeot 	 * vecs -> 0 = vcs2, 1 = rcs, 2 = vcs, 3 = bcs;
313*24edb884SFrançois Tigeot 	 * vcs2 -> 0 = rcs, 1 = vcs, 2 = bcs, 3 = vecs;
314e3adcf8fSFrançois Tigeot 	 */
315e3adcf8fSFrançois Tigeot 
316e3adcf8fSFrançois Tigeot 	idx = (other - ring) - 1;
317e3adcf8fSFrançois Tigeot 	if (idx < 0)
318e3adcf8fSFrançois Tigeot 		idx += I915_NUM_RINGS;
319e3adcf8fSFrançois Tigeot 
320e3adcf8fSFrançois Tigeot 	return idx;
321e3adcf8fSFrançois Tigeot }
322e3adcf8fSFrançois Tigeot 
323f4e1c372SFrançois Tigeot static inline u32
324ba55f2f5SFrançois Tigeot intel_read_status_page(struct intel_engine_cs *ring,
325f4e1c372SFrançois Tigeot 		       int reg)
326e3adcf8fSFrançois Tigeot {
327f4e1c372SFrançois Tigeot 	/* Ensure that the compiler doesn't optimize away the load. */
3289edbd4a0SFrançois Tigeot 	barrier();
329f4e1c372SFrançois Tigeot 	return ring->status_page.page_addr[reg];
330e3adcf8fSFrançois Tigeot }
331e3adcf8fSFrançois Tigeot 
332a2fdbec6SFrançois Tigeot static inline void
333ba55f2f5SFrançois Tigeot intel_write_status_page(struct intel_engine_cs *ring,
334a2fdbec6SFrançois Tigeot 			int reg, u32 value)
335a2fdbec6SFrançois Tigeot {
336a2fdbec6SFrançois Tigeot 	ring->status_page.page_addr[reg] = value;
337a2fdbec6SFrançois Tigeot }
338a2fdbec6SFrançois Tigeot 
339f4e1c372SFrançois Tigeot /**
340f4e1c372SFrançois Tigeot  * Reads a dword out of the status page, which is written to from the command
341f4e1c372SFrançois Tigeot  * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
342f4e1c372SFrançois Tigeot  * MI_STORE_DATA_IMM.
343f4e1c372SFrançois Tigeot  *
344f4e1c372SFrançois Tigeot  * The following dwords have a reserved meaning:
345f4e1c372SFrançois Tigeot  * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
346f4e1c372SFrançois Tigeot  * 0x04: ring 0 head pointer
347f4e1c372SFrançois Tigeot  * 0x05: ring 1 head pointer (915-class)
348f4e1c372SFrançois Tigeot  * 0x06: ring 2 head pointer (915-class)
349f4e1c372SFrançois Tigeot  * 0x10-0x1b: Context status DWords (GM45)
350f4e1c372SFrançois Tigeot  * 0x1f: Last written status offset. (GM45)
351f4e1c372SFrançois Tigeot  *
352f4e1c372SFrançois Tigeot  * The area from dword 0x20 to 0x3ff is available for driver usage.
353f4e1c372SFrançois Tigeot  */
354f4e1c372SFrançois Tigeot #define I915_GEM_HWS_INDEX		0x20
355f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_INDEX	0x30
356f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
357e3adcf8fSFrançois Tigeot 
358ba55f2f5SFrançois Tigeot void intel_stop_ring_buffer(struct intel_engine_cs *ring);
359ba55f2f5SFrançois Tigeot void intel_cleanup_ring_buffer(struct intel_engine_cs *ring);
360f4e1c372SFrançois Tigeot 
361ba55f2f5SFrançois Tigeot int __must_check intel_ring_begin(struct intel_engine_cs *ring, int n);
362ba55f2f5SFrançois Tigeot int __must_check intel_ring_cacheline_align(struct intel_engine_cs *ring);
363ba55f2f5SFrançois Tigeot static inline void intel_ring_emit(struct intel_engine_cs *ring,
364f4e1c372SFrançois Tigeot 				   u32 data)
365e3adcf8fSFrançois Tigeot {
366ba55f2f5SFrançois Tigeot 	struct intel_ringbuffer *ringbuf = ring->buffer;
367ba55f2f5SFrançois Tigeot 	iowrite32(data, ringbuf->virtual_start + ringbuf->tail);
368ba55f2f5SFrançois Tigeot 	ringbuf->tail += 4;
369e3adcf8fSFrançois Tigeot }
370ba55f2f5SFrançois Tigeot static inline void intel_ring_advance(struct intel_engine_cs *ring)
3719edbd4a0SFrançois Tigeot {
372ba55f2f5SFrançois Tigeot 	struct intel_ringbuffer *ringbuf = ring->buffer;
373ba55f2f5SFrançois Tigeot 	ringbuf->tail &= ringbuf->size - 1;
3749edbd4a0SFrançois Tigeot }
375ba55f2f5SFrançois Tigeot void __intel_ring_advance(struct intel_engine_cs *ring);
3769edbd4a0SFrançois Tigeot 
377ba55f2f5SFrançois Tigeot int __must_check intel_ring_idle(struct intel_engine_cs *ring);
378ba55f2f5SFrançois Tigeot void intel_ring_init_seqno(struct intel_engine_cs *ring, u32 seqno);
379ba55f2f5SFrançois Tigeot int intel_ring_flush_all_caches(struct intel_engine_cs *ring);
380ba55f2f5SFrançois Tigeot int intel_ring_invalidate_all_caches(struct intel_engine_cs *ring);
381e3adcf8fSFrançois Tigeot 
382e3adcf8fSFrançois Tigeot int intel_init_render_ring_buffer(struct drm_device *dev);
383e3adcf8fSFrançois Tigeot int intel_init_bsd_ring_buffer(struct drm_device *dev);
384ba55f2f5SFrançois Tigeot int intel_init_bsd2_ring_buffer(struct drm_device *dev);
385e3adcf8fSFrançois Tigeot int intel_init_blt_ring_buffer(struct drm_device *dev);
3865d0b1887SFrançois Tigeot int intel_init_vebox_ring_buffer(struct drm_device *dev);
387e3adcf8fSFrançois Tigeot 
388ba55f2f5SFrançois Tigeot u64 intel_ring_get_active_head(struct intel_engine_cs *ring);
389ba55f2f5SFrançois Tigeot void intel_ring_setup_status_page(struct intel_engine_cs *ring);
390e3adcf8fSFrançois Tigeot 
391*24edb884SFrançois Tigeot static inline u32 intel_ring_get_tail(struct intel_ringbuffer *ringbuf)
392e3adcf8fSFrançois Tigeot {
393*24edb884SFrançois Tigeot 	return ringbuf->tail;
394e3adcf8fSFrançois Tigeot }
395e3adcf8fSFrançois Tigeot 
396ba55f2f5SFrançois Tigeot static inline u32 intel_ring_get_seqno(struct intel_engine_cs *ring)
397f4e1c372SFrançois Tigeot {
3989edbd4a0SFrançois Tigeot 	BUG_ON(ring->outstanding_lazy_seqno == 0);
3999edbd4a0SFrançois Tigeot 	return ring->outstanding_lazy_seqno;
400f4e1c372SFrançois Tigeot }
401f4e1c372SFrançois Tigeot 
402ba55f2f5SFrançois Tigeot static inline void i915_trace_irq_get(struct intel_engine_cs *ring, u32 seqno)
403f4e1c372SFrançois Tigeot {
404f4e1c372SFrançois Tigeot 	if (ring->trace_irq_seqno == 0 && ring->irq_get(ring))
405f4e1c372SFrançois Tigeot 		ring->trace_irq_seqno = seqno;
406f4e1c372SFrançois Tigeot }
407e3adcf8fSFrançois Tigeot 
408e3adcf8fSFrançois Tigeot /* DRI warts */
409f4e1c372SFrançois Tigeot int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size);
410e3adcf8fSFrançois Tigeot 
411e3adcf8fSFrançois Tigeot #endif /* _INTEL_RINGBUFFER_H_ */
412