blob: 799f04c9da45a0bc30b19dd841547f75a6d4958e [file] [log] [blame]
Zou Nan hai8187a2b2010-05-21 09:08:55 +08001#ifndef _INTEL_RINGBUFFER_H_
2#define _INTEL_RINGBUFFER_H_
3
Ville Syrjälä633cf8f2012-12-03 18:43:32 +02004/*
5 * Gen2 BSpec "1. Programming Environment" / 1.4.4.6 "Ring Buffer Use"
6 * Gen3 BSpec "vol1c Memory Interface Functions" / 2.3.4.5 "Ring Buffer Use"
7 * Gen4+ BSpec "vol1c Memory Interface and Command Stream" / 5.3.4.5 "Ring Buffer Use"
8 *
9 * "If the Ring Buffer Head Pointer and the Tail Pointer are on the same
10 * cacheline, the Head Pointer must not be greater than the Tail
11 * Pointer."
12 */
13#define I915_RING_FREE_SPACE 64
14
Zou Nan hai8187a2b2010-05-21 09:08:55 +080015struct intel_hw_status_page {
Daniel Vetter4225d0f2012-04-26 23:28:16 +020016 u32 *page_addr;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080017 unsigned int gfx_addr;
Chris Wilson05394f32010-11-08 19:18:58 +000018 struct drm_i915_gem_object *obj;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080019};
20
Ben Widawskyb7287d82011-04-25 11:22:22 -070021#define I915_READ_TAIL(ring) I915_READ(RING_TAIL((ring)->mmio_base))
22#define I915_WRITE_TAIL(ring, val) I915_WRITE(RING_TAIL((ring)->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080023
Ben Widawskyb7287d82011-04-25 11:22:22 -070024#define I915_READ_START(ring) I915_READ(RING_START((ring)->mmio_base))
25#define I915_WRITE_START(ring, val) I915_WRITE(RING_START((ring)->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080026
Ben Widawskyb7287d82011-04-25 11:22:22 -070027#define I915_READ_HEAD(ring) I915_READ(RING_HEAD((ring)->mmio_base))
28#define I915_WRITE_HEAD(ring, val) I915_WRITE(RING_HEAD((ring)->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080029
Ben Widawskyb7287d82011-04-25 11:22:22 -070030#define I915_READ_CTL(ring) I915_READ(RING_CTL((ring)->mmio_base))
31#define I915_WRITE_CTL(ring, val) I915_WRITE(RING_CTL((ring)->mmio_base), val)
Zou Nan haicae58522010-11-09 17:17:32 +080032
Ben Widawskyb7287d82011-04-25 11:22:22 -070033#define I915_READ_IMR(ring) I915_READ(RING_IMR((ring)->mmio_base))
34#define I915_WRITE_IMR(ring, val) I915_WRITE(RING_IMR((ring)->mmio_base), val)
Daniel Vetter870e86d2010-08-02 16:29:44 +020035
Ben Widawskyb7287d82011-04-25 11:22:22 -070036#define I915_READ_NOPID(ring) I915_READ(RING_NOPID((ring)->mmio_base))
37#define I915_READ_SYNC_0(ring) I915_READ(RING_SYNC_0((ring)->mmio_base))
38#define I915_READ_SYNC_1(ring) I915_READ(RING_SYNC_1((ring)->mmio_base))
Chris Wilson1ec14ad2010-12-04 11:30:53 +000039
Mika Kuoppalaad8beae2013-06-12 12:35:32 +030040enum intel_ring_hangcheck_action { wait, active, kick, hung };
41
Mika Kuoppala92cab732013-05-24 17:16:07 +030042struct intel_ring_hangcheck {
Chris Wilson6274f212013-06-10 11:20:21 +010043 bool deadlock;
Mika Kuoppala92cab732013-05-24 17:16:07 +030044 u32 seqno;
Mika Kuoppala05407ff2013-05-30 09:04:29 +030045 u32 acthd;
46 int score;
Mika Kuoppalaad8beae2013-06-12 12:35:32 +030047 enum intel_ring_hangcheck_action action;
Mika Kuoppala92cab732013-05-24 17:16:07 +030048};
49
Zou Nan hai8187a2b2010-05-21 09:08:55 +080050struct intel_ring_buffer {
51 const char *name;
Chris Wilson92204342010-09-18 11:02:01 +010052 enum intel_ring_id {
Daniel Vetter96154f22011-12-14 13:57:00 +010053 RCS = 0x0,
54 VCS,
55 BCS,
Ben Widawsky4a3dd192013-05-28 19:22:19 -070056 VECS,
Chris Wilson92204342010-09-18 11:02:01 +010057 } id;
Ben Widawsky4a3dd192013-05-28 19:22:19 -070058#define I915_NUM_RINGS 4
Daniel Vetter333e9fe2010-08-02 16:24:01 +020059 u32 mmio_base;
Chris Wilson311bd682011-01-13 19:06:50 +000060 void __iomem *virtual_start;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080061 struct drm_device *dev;
Chris Wilson05394f32010-11-08 19:18:58 +000062 struct drm_i915_gem_object *obj;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080063
Chris Wilson8c0a6bf2010-12-09 12:56:37 +000064 u32 head;
65 u32 tail;
Chris Wilson780f0ca2010-09-23 17:45:39 +010066 int space;
Chris Wilsonc2c347a92010-10-27 15:11:53 +010067 int size;
Chris Wilson55249ba2010-12-22 14:04:47 +000068 int effective_size;
Zou Nan hai8187a2b2010-05-21 09:08:55 +080069 struct intel_hw_status_page status_page;
70
Chris Wilsona71d8d92012-02-15 11:25:36 +000071 /** We track the position of the requests in the ring buffer, and
72 * when each is retired we increment last_retired_head as the GPU
73 * must have finished processing the request and so we know we
74 * can advance the ringbuffer up to that position.
75 *
76 * last_retired_head is set to -1 after the value is consumed so
77 * we can detect new retirements.
78 */
79 u32 last_retired_head;
80
Ben Widawskyaeb06592013-05-28 19:22:28 -070081 struct {
Ben Widawskya19d2932013-05-28 19:22:30 -070082 u32 gt; /* protected by dev_priv->irq_lock */
83 u32 pm; /* protected by dev_priv->rps.lock (sucks) */
84 } irq_refcount;
Daniel Vetter6a848cc2012-04-11 22:12:46 +020085 u32 irq_enable_mask; /* bitmask to enable ring interrupt */
Chris Wilsondb53a302011-02-03 11:57:46 +000086 u32 trace_irq_seqno;
Chris Wilson1ec14ad2010-12-04 11:30:53 +000087 u32 sync_seqno[I915_NUM_RINGS-1];
Chris Wilsonb13c2b92010-12-13 16:54:50 +000088 bool __must_check (*irq_get)(struct intel_ring_buffer *ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +000089 void (*irq_put)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080090
Chris Wilson78501ea2010-10-27 12:18:21 +010091 int (*init)(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +080092
Chris Wilson78501ea2010-10-27 12:18:21 +010093 void (*write_tail)(struct intel_ring_buffer *ring,
Chris Wilson297b0c52010-10-22 17:02:41 +010094 u32 value);
Chris Wilsonb72f3ac2011-01-04 17:34:02 +000095 int __must_check (*flush)(struct intel_ring_buffer *ring,
96 u32 invalidate_domains,
97 u32 flush_domains);
Chris Wilson9d7730912012-11-27 16:22:52 +000098 int (*add_request)(struct intel_ring_buffer *ring);
Chris Wilsonb2eadbc2012-08-09 10:58:30 +010099 /* Some chipsets are not quite as coherent as advertised and need
100 * an expensive kick to force a true read of the up-to-date seqno.
101 * However, the up-to-date seqno is not always required and the last
102 * seen value is good enough. Note that the seqno will always be
103 * monotonic, even if not coherent.
104 */
105 u32 (*get_seqno)(struct intel_ring_buffer *ring,
106 bool lazy_coherency);
Mika Kuoppalab70ec5b2012-12-19 11:13:05 +0200107 void (*set_seqno)(struct intel_ring_buffer *ring,
108 u32 seqno);
Chris Wilson78501ea2010-10-27 12:18:21 +0100109 int (*dispatch_execbuffer)(struct intel_ring_buffer *ring,
Chris Wilsond7d4eed2012-10-17 12:09:54 +0100110 u32 offset, u32 length,
111 unsigned flags);
112#define I915_DISPATCH_SECURE 0x1
Daniel Vetterb45305f2012-12-17 16:21:27 +0100113#define I915_DISPATCH_PINNED 0x2
Zou Nan hai8d192152010-11-02 16:31:01 +0800114 void (*cleanup)(struct intel_ring_buffer *ring);
Ben Widawskyc8c99b02011-09-14 20:32:47 -0700115 int (*sync_to)(struct intel_ring_buffer *ring,
116 struct intel_ring_buffer *to,
117 u32 seqno);
Ben Widawskyad776f82013-05-28 19:22:18 -0700118
Ben Widawsky55861812013-05-28 19:22:17 -0700119 /* our mbox written by others */
120 u32 semaphore_register[I915_NUM_RINGS];
Ben Widawskyad776f82013-05-28 19:22:18 -0700121 /* mboxes this ring signals to */
122 u32 signal_mbox[I915_NUM_RINGS];
123
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800124 /**
125 * List of objects currently involved in rendering from the
126 * ringbuffer.
127 *
128 * Includes buffers having the contents of their GPU caches
129 * flushed, not necessarily primitives. last_rendering_seqno
130 * represents when the rendering involved will be completed.
131 *
132 * A reference is held on the buffer while on this list.
133 */
134 struct list_head active_list;
135
136 /**
137 * List of breadcrumbs associated with GPU requests currently
138 * outstanding.
139 */
140 struct list_head request_list;
141
Chris Wilsona56ba562010-09-28 10:07:56 +0100142 /**
143 * Do we have some not yet emitted requests outstanding?
144 */
Chris Wilson5d97eb62010-11-10 20:40:02 +0000145 u32 outstanding_lazy_request;
Daniel Vettercc889e02012-06-13 20:45:19 +0200146 bool gpu_caches_dirty;
Chris Wilsonc65355b2013-06-06 16:53:41 -0300147 bool fbc_dirty;
Chris Wilsona56ba562010-09-28 10:07:56 +0100148
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800149 wait_queue_head_t irq_queue;
Zou Nan hai8d192152010-11-02 16:31:01 +0800150
Ben Widawsky12b02862012-06-04 14:42:50 -0700151 /**
152 * Do an explicit TLB flush before MI_SET_CONTEXT
153 */
154 bool itlb_before_ctx_switch;
Ben Widawsky40521052012-06-04 14:42:43 -0700155 struct i915_hw_context *default_context;
Chris Wilson112522f2013-05-02 16:48:07 +0300156 struct i915_hw_context *last_context;
Ben Widawsky40521052012-06-04 14:42:43 -0700157
Mika Kuoppala92cab732013-05-24 17:16:07 +0300158 struct intel_ring_hangcheck hangcheck;
159
Zou Nan hai8d192152010-11-02 16:31:01 +0800160 void *private;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800161};
162
Chris Wilsonb4519512012-05-11 14:29:30 +0100163static inline bool
164intel_ring_initialized(struct intel_ring_buffer *ring)
165{
166 return ring->obj != NULL;
167}
168
Daniel Vetter96154f22011-12-14 13:57:00 +0100169static inline unsigned
170intel_ring_flag(struct intel_ring_buffer *ring)
171{
172 return 1 << ring->id;
173}
174
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800175static inline u32
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000176intel_ring_sync_index(struct intel_ring_buffer *ring,
177 struct intel_ring_buffer *other)
178{
179 int idx;
180
181 /*
182 * cs -> 0 = vcs, 1 = bcs
183 * vcs -> 0 = bcs, 1 = cs,
184 * bcs -> 0 = cs, 1 = vcs.
185 */
186
187 idx = (other - ring) - 1;
188 if (idx < 0)
189 idx += I915_NUM_RINGS;
190
191 return idx;
192}
193
194static inline u32
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800195intel_read_status_page(struct intel_ring_buffer *ring,
Chris Wilson78501ea2010-10-27 12:18:21 +0100196 int reg)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800197{
Daniel Vetter4225d0f2012-04-26 23:28:16 +0200198 /* Ensure that the compiler doesn't optimize away the load. */
199 barrier();
200 return ring->status_page.page_addr[reg];
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800201}
202
Mika Kuoppalab70ec5b2012-12-19 11:13:05 +0200203static inline void
204intel_write_status_page(struct intel_ring_buffer *ring,
205 int reg, u32 value)
206{
207 ring->status_page.page_addr[reg] = value;
208}
209
Chris Wilson311bd682011-01-13 19:06:50 +0000210/**
211 * Reads a dword out of the status page, which is written to from the command
212 * queue by automatic updates, MI_REPORT_HEAD, MI_STORE_DATA_INDEX, or
213 * MI_STORE_DATA_IMM.
214 *
215 * The following dwords have a reserved meaning:
216 * 0x00: ISR copy, updated when an ISR bit not set in the HWSTAM changes.
217 * 0x04: ring 0 head pointer
218 * 0x05: ring 1 head pointer (915-class)
219 * 0x06: ring 2 head pointer (915-class)
220 * 0x10-0x1b: Context status DWords (GM45)
221 * 0x1f: Last written status offset. (GM45)
222 *
223 * The area from dword 0x20 to 0x3ff is available for driver usage.
224 */
Chris Wilson311bd682011-01-13 19:06:50 +0000225#define I915_GEM_HWS_INDEX 0x20
Jesse Barnes9a289772012-10-26 09:42:42 -0700226#define I915_GEM_HWS_SCRATCH_INDEX 0x30
227#define I915_GEM_HWS_SCRATCH_ADDR (I915_GEM_HWS_SCRATCH_INDEX << MI_STORE_DWORD_INDEX_SHIFT)
Chris Wilson311bd682011-01-13 19:06:50 +0000228
Chris Wilson78501ea2010-10-27 12:18:21 +0100229void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring);
Ben Widawsky96f298a2011-03-19 18:14:27 -0700230
Chris Wilsone1f99ce2010-10-27 12:45:26 +0100231int __must_check intel_ring_begin(struct intel_ring_buffer *ring, int n);
Chris Wilson78501ea2010-10-27 12:18:21 +0100232static inline void intel_ring_emit(struct intel_ring_buffer *ring,
233 u32 data)
Chris Wilsone898cd22010-08-04 15:18:14 +0100234{
Chris Wilson78501ea2010-10-27 12:18:21 +0100235 iowrite32(data, ring->virtual_start + ring->tail);
Chris Wilsone898cd22010-08-04 15:18:14 +0100236 ring->tail += 4;
237}
Chris Wilson78501ea2010-10-27 12:18:21 +0100238void intel_ring_advance(struct intel_ring_buffer *ring);
Chris Wilson3e960502012-11-27 16:22:54 +0000239int __must_check intel_ring_idle(struct intel_ring_buffer *ring);
Mika Kuoppalaf7e98ad2012-12-19 11:13:06 +0200240void intel_ring_init_seqno(struct intel_ring_buffer *ring, u32 seqno);
Chris Wilsona7b97612012-07-20 12:41:08 +0100241int intel_ring_flush_all_caches(struct intel_ring_buffer *ring);
242int intel_ring_invalidate_all_caches(struct intel_ring_buffer *ring);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800243
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800244int intel_init_render_ring_buffer(struct drm_device *dev);
245int intel_init_bsd_ring_buffer(struct drm_device *dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100246int intel_init_blt_ring_buffer(struct drm_device *dev);
Ben Widawsky9a8a2212013-05-28 19:22:23 -0700247int intel_init_vebox_ring_buffer(struct drm_device *dev);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800248
Chris Wilson78501ea2010-10-27 12:18:21 +0100249u32 intel_ring_get_active_head(struct intel_ring_buffer *ring);
250void intel_ring_setup_status_page(struct intel_ring_buffer *ring);
Daniel Vetter79f321b2010-09-24 21:20:10 +0200251
Chris Wilsona71d8d92012-02-15 11:25:36 +0000252static inline u32 intel_ring_get_tail(struct intel_ring_buffer *ring)
253{
254 return ring->tail;
255}
256
Chris Wilson9d7730912012-11-27 16:22:52 +0000257static inline u32 intel_ring_get_seqno(struct intel_ring_buffer *ring)
258{
259 BUG_ON(ring->outstanding_lazy_request == 0);
260 return ring->outstanding_lazy_request;
261}
262
Chris Wilsondb53a302011-02-03 11:57:46 +0000263static inline void i915_trace_irq_get(struct intel_ring_buffer *ring, u32 seqno)
264{
265 if (ring->trace_irq_seqno == 0 && ring->irq_get(ring))
266 ring->trace_irq_seqno = seqno;
267}
268
Chris Wilsone8616b62011-01-20 09:57:11 +0000269/* DRI warts */
270int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size);
271
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800272#endif /* _INTEL_RINGBUFFER_H_ */