xref: /dflybsd-src/sys/dev/drm/i915/intel_ringbuffer.h (revision b5c29a3405686a232e667f64c5ecf10bac5f8907)
1e3adcf8fSFrançois Tigeot #ifndef _INTEL_RINGBUFFER_H_
2e3adcf8fSFrançois Tigeot #define _INTEL_RINGBUFFER_H_
3e3adcf8fSFrançois Tigeot 
470f8ca4eSFrançois Tigeot #include <linux/io.h>
570f8ca4eSFrançois Tigeot 
6f4e1c372SFrançois Tigeot /*
7f4e1c372SFrançois Tigeot  * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
8f4e1c372SFrançois Tigeot  * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
9f4e1c372SFrançois Tigeot  * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
10f4e1c372SFrançois Tigeot  *
11f4e1c372SFrançois Tigeot  * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
12f4e1c372SFrançois Tigeot  * cacheline, the Head Pointer must not be greater than the Tail
13f4e1c372SFrançois Tigeot  * Pointer."
14f4e1c372SFrançois Tigeot  */
15f4e1c372SFrançois Tigeot #define I915_RING_FREE_SPACE 64
16f4e1c372SFrançois Tigeot 
17e3adcf8fSFrançois Tigeot struct  intel_hw_status_page {
18f4e1c372SFrançois Tigeot 	u32		*page_addr;
19e3adcf8fSFrançois Tigeot 	unsigned int	gfx_addr;
20e3adcf8fSFrançois Tigeot 	struct		drm_i915_gem_object *obj;
21e3adcf8fSFrançois Tigeot };
22e3adcf8fSFrançois Tigeot 
23e3adcf8fSFrançois Tigeot #define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
24e3adcf8fSFrançois Tigeot #define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
25e3adcf8fSFrançois Tigeot 
26e3adcf8fSFrançois Tigeot #define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base))
27e3adcf8fSFrançois Tigeot #define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
28e3adcf8fSFrançois Tigeot 
29e3adcf8fSFrançois Tigeot #define I915_READ_HEAD(ring)  I915_READ(RING_HEAD((ring)->mmio_base))
30e3adcf8fSFrançois Tigeot #define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
31e3adcf8fSFrançois Tigeot 
32e3adcf8fSFrançois Tigeot #define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base))
33e3adcf8fSFrançois Tigeot #define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
34e3adcf8fSFrançois Tigeot 
35e3adcf8fSFrançois Tigeot #define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base))
36e3adcf8fSFrançois Tigeot #define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
37e3adcf8fSFrançois Tigeot 
38e3adcf8fSFrançois Tigeot #define I915_READ_NOPID(ring) I915_READ(RING_NOPID((ring)->mmio_base))
39e3adcf8fSFrançois Tigeot #define I915_READ_SYNC_0(ring) I915_READ(RING_SYNC_0((ring)->mmio_base))
40e3adcf8fSFrançois Tigeot #define I915_READ_SYNC_1(ring) I915_READ(RING_SYNC_1((ring)->mmio_base))
41e3adcf8fSFrançois Tigeot 
42e3adcf8fSFrançois Tigeot struct  intel_ring_buffer {
43e3adcf8fSFrançois Tigeot 	const char	*name;
44e3adcf8fSFrançois Tigeot 	enum intel_ring_id {
45e3adcf8fSFrançois Tigeot 		RCS = 0x0,
46e3adcf8fSFrançois Tigeot 		VCS,
47e3adcf8fSFrançois Tigeot 		BCS,
48e3adcf8fSFrançois Tigeot 	} id;
49e3adcf8fSFrançois Tigeot #define I915_NUM_RINGS 3
5015ac6249SFrançois Tigeot 	u32		mmio_base;
5115ac6249SFrançois Tigeot 	void		__iomem *virtual_start;
52e3adcf8fSFrançois Tigeot 	struct		drm_device *dev;
53e3adcf8fSFrançois Tigeot 	struct		drm_i915_gem_object *obj;
54e3adcf8fSFrançois Tigeot 
5515ac6249SFrançois Tigeot 	u32		head;
5615ac6249SFrançois Tigeot 	u32		tail;
57e3adcf8fSFrançois Tigeot 	int		space;
58e3adcf8fSFrançois Tigeot 	int		size;
59e3adcf8fSFrançois Tigeot 	int		effective_size;
60e3adcf8fSFrançois Tigeot 	struct intel_hw_status_page status_page;
61e3adcf8fSFrançois Tigeot 
62e3adcf8fSFrançois Tigeot 	/** We track the position of the requests in the ring buffer, and
63e3adcf8fSFrançois Tigeot 	 * when each is retired we increment last_retired_head as the GPU
64e3adcf8fSFrançois Tigeot 	 * must have finished processing the request and so we know we
65e3adcf8fSFrançois Tigeot 	 * can advance the ringbuffer up to that position.
66e3adcf8fSFrançois Tigeot 	 *
67e3adcf8fSFrançois Tigeot 	 * last_retired_head is set to -1 after the value is consumed so
68e3adcf8fSFrançois Tigeot 	 * we can detect new retirements.
69e3adcf8fSFrançois Tigeot 	 */
70e3adcf8fSFrançois Tigeot 	u32		last_retired_head;
71e3adcf8fSFrançois Tigeot 
7215ac6249SFrançois Tigeot 	u32		irq_refcount;		/* protected by dev_priv->irq_lock */
7315ac6249SFrançois Tigeot 	u32		irq_enable_mask;	/* bitmask to enable ring interrupt */
74b030f26bSFrançois Tigeot 	u32		trace_irq_seqno;
75b030f26bSFrançois Tigeot 	u32		sync_seqno[I915_NUM_RINGS-1];
7615ac6249SFrançois Tigeot 	bool __must_check (*irq_get)(struct intel_ring_buffer *ring);
77e3adcf8fSFrançois Tigeot 	void		(*irq_put)(struct intel_ring_buffer *ring);
78e3adcf8fSFrançois Tigeot 
79e3adcf8fSFrançois Tigeot 	int		(*init)(struct intel_ring_buffer *ring);
80e3adcf8fSFrançois Tigeot 
81e3adcf8fSFrançois Tigeot 	void		(*write_tail)(struct intel_ring_buffer *ring,
8215ac6249SFrançois Tigeot 				      u32 value);
8315ac6249SFrançois Tigeot 	int __must_check (*flush)(struct intel_ring_buffer *ring,
8415ac6249SFrançois Tigeot 				  u32	invalidate_domains,
8515ac6249SFrançois Tigeot 				  u32	flush_domains);
86*b5c29a34SFrançois Tigeot 	int		(*add_request)(struct intel_ring_buffer *ring);
87b030f26bSFrançois Tigeot 	/* Some chipsets are not quite as coherent as advertised and need
88b030f26bSFrançois Tigeot 	 * an expensive kick to force a true read of the up-to-date seqno.
89b030f26bSFrançois Tigeot 	 * However, the up-to-date seqno is not always required and the last
90b030f26bSFrançois Tigeot 	 * seen value is good enough. Note that the seqno will always be
91b030f26bSFrançois Tigeot 	 * monotonic, even if not coherent.
92b030f26bSFrançois Tigeot 	 */
93b030f26bSFrançois Tigeot 	u32		(*get_seqno)(struct intel_ring_buffer *ring,
94b030f26bSFrançois Tigeot 				     bool lazy_coherency);
95e3adcf8fSFrançois Tigeot 	int		(*dispatch_execbuffer)(struct intel_ring_buffer *ring,
96*b5c29a34SFrançois Tigeot 					       u32 offset, u32 length,
97*b5c29a34SFrançois Tigeot 					       unsigned flags);
9815ac6249SFrançois Tigeot #define I915_DISPATCH_SECURE 0x1
9915ac6249SFrançois Tigeot #define I915_DISPATCH_PINNED 0x2
100e3adcf8fSFrançois Tigeot 	void		(*cleanup)(struct intel_ring_buffer *ring);
101e3adcf8fSFrançois Tigeot 	int		(*sync_to)(struct intel_ring_buffer *ring,
102e3adcf8fSFrançois Tigeot 				   struct intel_ring_buffer *to,
103e3adcf8fSFrançois Tigeot 				   u32 seqno);
104e3adcf8fSFrançois Tigeot 
105e3adcf8fSFrançois Tigeot 	u32		semaphore_register[3]; /*our mbox written by others */
106e3adcf8fSFrançois Tigeot 	u32		signal_mbox[2]; /* mboxes this ring signals to */
107e3adcf8fSFrançois Tigeot 	/**
108e3adcf8fSFrançois Tigeot 	 * List of objects currently involved in rendering from the
109e3adcf8fSFrançois Tigeot 	 * ringbuffer.
110e3adcf8fSFrançois Tigeot 	 *
111e3adcf8fSFrançois Tigeot 	 * Includes buffers having the contents of their GPU caches
112e3adcf8fSFrançois Tigeot 	 * flushed, not necessarily primitives.  last_rendering_seqno
113e3adcf8fSFrançois Tigeot 	 * represents when the rendering involved will be completed.
114e3adcf8fSFrançois Tigeot 	 *
115e3adcf8fSFrançois Tigeot 	 * A reference is held on the buffer while on this list.
116e3adcf8fSFrançois Tigeot 	 */
117e3adcf8fSFrançois Tigeot 	struct list_head active_list;
118e3adcf8fSFrançois Tigeot 
119e3adcf8fSFrançois Tigeot 	/**
120e3adcf8fSFrançois Tigeot 	 * List of breadcrumbs associated with GPU requests currently
121e3adcf8fSFrançois Tigeot 	 * outstanding.
122e3adcf8fSFrançois Tigeot 	 */
123e3adcf8fSFrançois Tigeot 	struct list_head request_list;
124e3adcf8fSFrançois Tigeot 
125e3adcf8fSFrançois Tigeot 	struct list_head gpu_write_list;
126e3adcf8fSFrançois Tigeot 
127e3adcf8fSFrançois Tigeot 	/**
128e3adcf8fSFrançois Tigeot 	 * Do we have some not yet emitted requests outstanding?
129e3adcf8fSFrançois Tigeot 	 */
13015ac6249SFrançois Tigeot 	u32 outstanding_lazy_request;
131b030f26bSFrançois Tigeot 	bool gpu_caches_dirty;
132b030f26bSFrançois Tigeot 
133b030f26bSFrançois Tigeot 	wait_queue_head_t irq_queue;
134e3adcf8fSFrançois Tigeot 
13515ac6249SFrançois Tigeot 	/**
13615ac6249SFrançois Tigeot 	 * Do an explicit TLB flush before MI_SET_CONTEXT
13715ac6249SFrançois Tigeot 	 */
13815ac6249SFrançois Tigeot 	bool itlb_before_ctx_switch;
13915ac6249SFrançois Tigeot 	struct i915_hw_context *default_context;
14015ac6249SFrançois Tigeot 	struct drm_i915_gem_object *last_context_obj;
14115ac6249SFrançois Tigeot 
142e3adcf8fSFrançois Tigeot 	void *private;
143e3adcf8fSFrançois Tigeot };
144e3adcf8fSFrançois Tigeot 
145f4e1c372SFrançois Tigeot static inline bool
146f4e1c372SFrançois Tigeot intel_ring_initialized(struct intel_ring_buffer *ring)
147f4e1c372SFrançois Tigeot {
148f4e1c372SFrançois Tigeot 	return ring->obj != NULL;
149f4e1c372SFrançois Tigeot }
150f4e1c372SFrançois Tigeot 
151e3adcf8fSFrançois Tigeot static inline unsigned
152e3adcf8fSFrançois Tigeot intel_ring_flag(struct intel_ring_buffer *ring)
153e3adcf8fSFrançois Tigeot {
154e3adcf8fSFrançois Tigeot 	return 1 << ring->id;
155e3adcf8fSFrançois Tigeot }
156e3adcf8fSFrançois Tigeot 
157f4e1c372SFrançois Tigeot static inline u32
158e3adcf8fSFrançois Tigeot intel_ring_sync_index(struct intel_ring_buffer *ring,
159e3adcf8fSFrançois Tigeot 		      struct intel_ring_buffer *other)
160e3adcf8fSFrançois Tigeot {
161e3adcf8fSFrançois Tigeot 	int idx;
162e3adcf8fSFrançois Tigeot 
163e3adcf8fSFrançois Tigeot 	/*
164e3adcf8fSFrançois Tigeot 	 * cs -> 0 = vcs, 1 = bcs
165e3adcf8fSFrançois Tigeot 	 * vcs -> 0 = bcs, 1 = cs,
166e3adcf8fSFrançois Tigeot 	 * bcs -> 0 = cs, 1 = vcs.
167e3adcf8fSFrançois Tigeot 	 */
168e3adcf8fSFrançois Tigeot 
169e3adcf8fSFrançois Tigeot 	idx = (other - ring) - 1;
170e3adcf8fSFrançois Tigeot 	if (idx < 0)
171e3adcf8fSFrançois Tigeot 		idx += I915_NUM_RINGS;
172e3adcf8fSFrançois Tigeot 
173e3adcf8fSFrançois Tigeot 	return idx;
174e3adcf8fSFrançois Tigeot }
175e3adcf8fSFrançois Tigeot 
176f4e1c372SFrançois Tigeot static inline u32
177f4e1c372SFrançois Tigeot intel_read_status_page(struct intel_ring_buffer *ring,
178f4e1c372SFrançois Tigeot 		       int reg)
179e3adcf8fSFrançois Tigeot {
180f4e1c372SFrançois Tigeot 	/* Ensure that the compiler doesn't optimize away the load. */
181f4e1c372SFrançois Tigeot 	cpu_ccfence();
182f4e1c372SFrançois Tigeot 	return ring->status_page.page_addr[reg];
183e3adcf8fSFrançois Tigeot }
184e3adcf8fSFrançois Tigeot 
185f4e1c372SFrançois Tigeot /**
186f4e1c372SFrançois Tigeot  * Reads a dword out of the status page, which is written to from the command
187f4e1c372SFrançois Tigeot  * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
188f4e1c372SFrançois Tigeot  * MI_STORE_DATA_IMM.
189f4e1c372SFrançois Tigeot  *
190f4e1c372SFrançois Tigeot  * The following dwords have a reserved meaning:
191f4e1c372SFrançois Tigeot  * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
192f4e1c372SFrançois Tigeot  * 0x04: ring 0 head pointer
193f4e1c372SFrançois Tigeot  * 0x05: ring 1 head pointer (915-class)
194f4e1c372SFrançois Tigeot  * 0x06: ring 2 head pointer (915-class)
195f4e1c372SFrançois Tigeot  * 0x10-0x1b: Context status DWords (GM45)
196f4e1c372SFrançois Tigeot  * 0x1f: Last written status offset. (GM45)
197f4e1c372SFrançois Tigeot  *
198f4e1c372SFrançois Tigeot  * The area from dword 0x20 to 0x3ff is available for driver usage.
199f4e1c372SFrançois Tigeot  */
200f4e1c372SFrançois Tigeot #define I915_GEM_HWS_INDEX		0x20
201f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_INDEX	0x30
202f4e1c372SFrançois Tigeot #define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
203e3adcf8fSFrançois Tigeot 
204f4e1c372SFrançois Tigeot void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
205f4e1c372SFrançois Tigeot 
206f4e1c372SFrançois Tigeot int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
207e3adcf8fSFrançois Tigeot static inline void intel_ring_emit(struct intel_ring_buffer *ring,
208f4e1c372SFrançois Tigeot 				   u32 data)
209e3adcf8fSFrançois Tigeot {
210f4e1c372SFrançois Tigeot 	iowrite32(data, ring->virtual_start + ring->tail);
211e3adcf8fSFrançois Tigeot 	ring->tail += 4;
212e3adcf8fSFrançois Tigeot }
213e3adcf8fSFrançois Tigeot void intel_ring_advance(struct intel_ring_buffer *ring);
214f4e1c372SFrançois Tigeot int __must_check intel_ring_idle(struct intel_ring_buffer *ring);
215e3adcf8fSFrançois Tigeot 
216f4e1c372SFrançois Tigeot int intel_ring_flush_all_caches(struct intel_ring_buffer *ring);
217f4e1c372SFrançois Tigeot int intel_ring_invalidate_all_caches(struct intel_ring_buffer *ring);
218e3adcf8fSFrançois Tigeot 
219e3adcf8fSFrançois Tigeot int intel_init_render_ring_buffer(struct drm_device *dev);
220e3adcf8fSFrançois Tigeot int intel_init_bsd_ring_buffer(struct drm_device *dev);
221e3adcf8fSFrançois Tigeot int intel_init_blt_ring_buffer(struct drm_device *dev);
222e3adcf8fSFrançois Tigeot 
223e3adcf8fSFrançois Tigeot u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
224e3adcf8fSFrançois Tigeot void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
225e3adcf8fSFrançois Tigeot 
226e3adcf8fSFrançois Tigeot static inline u32 intel_ring_get_tail(struct intel_ring_buffer *ring)
227e3adcf8fSFrançois Tigeot {
228e3adcf8fSFrançois Tigeot 	return ring->tail;
229e3adcf8fSFrançois Tigeot }
230e3adcf8fSFrançois Tigeot 
231f4e1c372SFrançois Tigeot static inline u32 intel_ring_get_seqno(struct intel_ring_buffer *ring)
232f4e1c372SFrançois Tigeot {
233f4e1c372SFrançois Tigeot 	BUG_ON(ring->outstanding_lazy_request == 0);
234f4e1c372SFrançois Tigeot 	return ring->outstanding_lazy_request;
235f4e1c372SFrançois Tigeot }
236f4e1c372SFrançois Tigeot 
237f4e1c372SFrançois Tigeot static inline void i915_trace_irq_get(struct intel_ring_buffer *ring, u32 seqno)
238f4e1c372SFrançois Tigeot {
239f4e1c372SFrançois Tigeot 	if (ring->trace_irq_seqno == 0 && ring->irq_get(ring))
240f4e1c372SFrançois Tigeot 		ring->trace_irq_seqno = seqno;
241f4e1c372SFrançois Tigeot }
242e3adcf8fSFrançois Tigeot 
243e3adcf8fSFrançois Tigeot /* DRI warts */
244f4e1c372SFrançois Tigeot int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size);
245e3adcf8fSFrançois Tigeot 
246e3adcf8fSFrançois Tigeot #endif /* _INTEL_RINGBUFFER_H_ */
247