blob: a3e73d4cd391f557868e6468f86caffc98aac17b [file] [log] [blame]
Eric Anholt62fdfea2010-05-21 13:26:39 -07001/*
2 * Copyright © 2008-2010 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Zou Nan hai <nanhai.zou@intel.com>
26 * Xiang Hai hao<haihao.xiang@intel.com>
27 *
28 */
29
30#include "drmP.h"
31#include "drm.h"
Eric Anholt62fdfea2010-05-21 13:26:39 -070032#include "i915_drv.h"
Zou Nan hai8187a2b2010-05-21 09:08:55 +080033#include "i915_drm.h"
Eric Anholt62fdfea2010-05-21 13:26:39 -070034#include "i915_trace.h"
Xiang, Haihao881f47b2010-09-19 14:40:43 +010035#include "intel_drv.h"
Eric Anholt62fdfea2010-05-21 13:26:39 -070036
Chris Wilson6f392d52010-08-07 11:01:22 +010037static u32 i915_gem_get_seqno(struct drm_device *dev)
38{
39 drm_i915_private_t *dev_priv = dev->dev_private;
40 u32 seqno;
41
42 seqno = dev_priv->next_seqno;
43
44 /* reserve 0 for non-seqno */
45 if (++dev_priv->next_seqno == 0)
46 dev_priv->next_seqno = 1;
47
48 return seqno;
49}
50
Zou Nan hai8187a2b2010-05-21 09:08:55 +080051static void
52render_ring_flush(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +010053 struct intel_ring_buffer *ring,
54 u32 invalidate_domains,
55 u32 flush_domains)
Eric Anholt62fdfea2010-05-21 13:26:39 -070056{
Chris Wilson6f392d52010-08-07 11:01:22 +010057 drm_i915_private_t *dev_priv = dev->dev_private;
58 u32 cmd;
59
Eric Anholt62fdfea2010-05-21 13:26:39 -070060#if WATCH_EXEC
61 DRM_INFO("%s: invalidate %08x flush %08x\n", __func__,
62 invalidate_domains, flush_domains);
63#endif
Chris Wilson6f392d52010-08-07 11:01:22 +010064
65 trace_i915_gem_request_flush(dev, dev_priv->next_seqno,
Eric Anholt62fdfea2010-05-21 13:26:39 -070066 invalidate_domains, flush_domains);
67
Eric Anholt62fdfea2010-05-21 13:26:39 -070068 if ((invalidate_domains | flush_domains) & I915_GEM_GPU_DOMAINS) {
69 /*
70 * read/write caches:
71 *
72 * I915_GEM_DOMAIN_RENDER is always invalidated, but is
73 * only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is
74 * also flushed at 2d versus 3d pipeline switches.
75 *
76 * read-only caches:
77 *
78 * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if
79 * MI_READ_FLUSH is set, and is always flushed on 965.
80 *
81 * I915_GEM_DOMAIN_COMMAND may not exist?
82 *
83 * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is
84 * invalidated when MI_EXE_FLUSH is set.
85 *
86 * I915_GEM_DOMAIN_VERTEX, which exists on 965, is
87 * invalidated with every MI_FLUSH.
88 *
89 * TLBs:
90 *
91 * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND
92 * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and
93 * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER
94 * are flushed at any MI_FLUSH.
95 */
96
97 cmd = MI_FLUSH | MI_NO_WRITE_FLUSH;
98 if ((invalidate_domains|flush_domains) &
99 I915_GEM_DOMAIN_RENDER)
100 cmd &= ~MI_NO_WRITE_FLUSH;
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100101 if (INTEL_INFO(dev)->gen < 4) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700102 /*
103 * On the 965, the sampler cache always gets flushed
104 * and this bit is reserved.
105 */
106 if (invalidate_domains & I915_GEM_DOMAIN_SAMPLER)
107 cmd |= MI_READ_FLUSH;
108 }
109 if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION)
110 cmd |= MI_EXE_FLUSH;
111
112#if WATCH_EXEC
113 DRM_INFO("%s: queue flush %08x to ring\n", __func__, cmd);
114#endif
Zou Nan haibe26a102010-06-12 17:40:24 +0800115 intel_ring_begin(dev, ring, 2);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800116 intel_ring_emit(dev, ring, cmd);
117 intel_ring_emit(dev, ring, MI_NOOP);
118 intel_ring_advance(dev, ring);
119 }
120}
121
Daniel Vetter870e86d2010-08-02 16:29:44 +0200122static void ring_set_tail(struct drm_device *dev,
123 struct intel_ring_buffer *ring,
124 u32 value)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800125{
126 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter870e86d2010-08-02 16:29:44 +0200127 I915_WRITE_TAIL(ring, ring->tail);
Xiang, Haihaod46eefa2010-09-16 10:43:12 +0800128}
129
Daniel Vetter79f321b2010-09-24 21:20:10 +0200130u32 intel_ring_get_active_head(struct drm_device *dev,
131 struct intel_ring_buffer *ring)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800132{
133 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter3d281d82010-09-24 21:14:22 +0200134 u32 acthd_reg = INTEL_INFO(dev)->gen >= 4 ?
135 RING_ACTHD(ring->mmio_base) : ACTHD;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800136
137 return I915_READ(acthd_reg);
138}
139
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800140static int init_ring_common(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100141 struct intel_ring_buffer *ring)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800142{
143 u32 head;
144 drm_i915_private_t *dev_priv = dev->dev_private;
145 struct drm_i915_gem_object *obj_priv;
146 obj_priv = to_intel_bo(ring->gem_object);
147
148 /* Stop the ring if it's running. */
Daniel Vetter7f2ab692010-08-02 17:06:59 +0200149 I915_WRITE_CTL(ring, 0);
Daniel Vetter570ef602010-08-02 17:06:23 +0200150 I915_WRITE_HEAD(ring, 0);
Daniel Vetter870e86d2010-08-02 16:29:44 +0200151 ring->set_tail(dev, ring, 0);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800152
153 /* Initialize the ring. */
Daniel Vetter6c0e1c52010-08-02 16:33:33 +0200154 I915_WRITE_START(ring, obj_priv->gtt_offset);
Daniel Vetter570ef602010-08-02 17:06:23 +0200155 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800156
157 /* G45 ring initialization fails to reset head to zero */
158 if (head != 0) {
159 DRM_ERROR("%s head not reset to zero "
160 "ctl %08x head %08x tail %08x start %08x\n",
161 ring->name,
Daniel Vetter7f2ab692010-08-02 17:06:59 +0200162 I915_READ_CTL(ring),
Daniel Vetter570ef602010-08-02 17:06:23 +0200163 I915_READ_HEAD(ring),
Daniel Vetter870e86d2010-08-02 16:29:44 +0200164 I915_READ_TAIL(ring),
Daniel Vetter6c0e1c52010-08-02 16:33:33 +0200165 I915_READ_START(ring));
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800166
Daniel Vetter570ef602010-08-02 17:06:23 +0200167 I915_WRITE_HEAD(ring, 0);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800168
169 DRM_ERROR("%s head forced to zero "
170 "ctl %08x head %08x tail %08x start %08x\n",
171 ring->name,
Daniel Vetter7f2ab692010-08-02 17:06:59 +0200172 I915_READ_CTL(ring),
Daniel Vetter570ef602010-08-02 17:06:23 +0200173 I915_READ_HEAD(ring),
Daniel Vetter870e86d2010-08-02 16:29:44 +0200174 I915_READ_TAIL(ring),
Daniel Vetter6c0e1c52010-08-02 16:33:33 +0200175 I915_READ_START(ring));
Eric Anholt62fdfea2010-05-21 13:26:39 -0700176 }
177
Daniel Vetter7f2ab692010-08-02 17:06:59 +0200178 I915_WRITE_CTL(ring,
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800179 ((ring->gem_object->size - PAGE_SIZE) & RING_NR_PAGES)
180 | RING_NO_REPORT | RING_VALID);
181
Daniel Vetter570ef602010-08-02 17:06:23 +0200182 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800183 /* If the head is still not zero, the ring is dead */
184 if (head != 0) {
185 DRM_ERROR("%s initialization failed "
186 "ctl %08x head %08x tail %08x start %08x\n",
187 ring->name,
Daniel Vetter7f2ab692010-08-02 17:06:59 +0200188 I915_READ_CTL(ring),
Daniel Vetter570ef602010-08-02 17:06:23 +0200189 I915_READ_HEAD(ring),
Daniel Vetter870e86d2010-08-02 16:29:44 +0200190 I915_READ_TAIL(ring),
Daniel Vetter6c0e1c52010-08-02 16:33:33 +0200191 I915_READ_START(ring));
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800192 return -EIO;
193 }
194
195 if (!drm_core_check_feature(dev, DRIVER_MODESET))
196 i915_kernel_lost_context(dev);
197 else {
Daniel Vetter570ef602010-08-02 17:06:23 +0200198 ring->head = I915_READ_HEAD(ring) & HEAD_ADDR;
Daniel Vetter870e86d2010-08-02 16:29:44 +0200199 ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800200 ring->space = ring->head - (ring->tail + 8);
201 if (ring->space < 0)
202 ring->space += ring->size;
203 }
204 return 0;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700205}
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800206
207static int init_render_ring(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100208 struct intel_ring_buffer *ring)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800209{
210 drm_i915_private_t *dev_priv = dev->dev_private;
211 int ret = init_ring_common(dev, ring);
Zhenyu Wanga69ffdb2010-08-30 16:12:42 +0800212 int mode;
213
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100214 if (INTEL_INFO(dev)->gen > 3) {
Zhenyu Wanga69ffdb2010-08-30 16:12:42 +0800215 mode = VS_TIMER_DISPATCH << 16 | VS_TIMER_DISPATCH;
216 if (IS_GEN6(dev))
217 mode |= MI_FLUSH_ENABLE << 16 | MI_FLUSH_ENABLE;
218 I915_WRITE(MI_MODE, mode);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800219 }
220 return ret;
221}
222
Eric Anholt62fdfea2010-05-21 13:26:39 -0700223#define PIPE_CONTROL_FLUSH(addr) \
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800224do { \
Eric Anholt62fdfea2010-05-21 13:26:39 -0700225 OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | \
Zhenyu Wangca764822010-05-27 10:26:42 +0800226 PIPE_CONTROL_DEPTH_STALL | 2); \
Eric Anholt62fdfea2010-05-21 13:26:39 -0700227 OUT_RING(addr | PIPE_CONTROL_GLOBAL_GTT); \
228 OUT_RING(0); \
229 OUT_RING(0); \
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800230} while (0)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700231
232/**
233 * Creates a new sequence number, emitting a write of it to the status page
234 * plus an interrupt, which will trigger i915_user_interrupt_handler.
235 *
236 * Must be called with struct_lock held.
237 *
238 * Returned sequence numbers are nonzero on success.
239 */
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800240static u32
241render_ring_add_request(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100242 struct intel_ring_buffer *ring,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100243 u32 flush_domains)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700244{
245 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson6f392d52010-08-07 11:01:22 +0100246 u32 seqno;
247
248 seqno = i915_gem_get_seqno(dev);
Zhenyu Wangca764822010-05-27 10:26:42 +0800249
250 if (IS_GEN6(dev)) {
251 BEGIN_LP_RING(6);
252 OUT_RING(GFX_OP_PIPE_CONTROL | 3);
253 OUT_RING(PIPE_CONTROL_QW_WRITE |
254 PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_IS_FLUSH |
255 PIPE_CONTROL_NOTIFY);
256 OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT);
257 OUT_RING(seqno);
258 OUT_RING(0);
259 OUT_RING(0);
260 ADVANCE_LP_RING();
261 } else if (HAS_PIPE_CONTROL(dev)) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700262 u32 scratch_addr = dev_priv->seqno_gfx_addr + 128;
263
264 /*
265 * Workaround qword write incoherence by flushing the
266 * PIPE_NOTIFY buffers out to memory before requesting
267 * an interrupt.
268 */
269 BEGIN_LP_RING(32);
270 OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE |
271 PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH);
272 OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT);
273 OUT_RING(seqno);
274 OUT_RING(0);
275 PIPE_CONTROL_FLUSH(scratch_addr);
276 scratch_addr += 128; /* write to separate cachelines */
277 PIPE_CONTROL_FLUSH(scratch_addr);
278 scratch_addr += 128;
279 PIPE_CONTROL_FLUSH(scratch_addr);
280 scratch_addr += 128;
281 PIPE_CONTROL_FLUSH(scratch_addr);
282 scratch_addr += 128;
283 PIPE_CONTROL_FLUSH(scratch_addr);
284 scratch_addr += 128;
285 PIPE_CONTROL_FLUSH(scratch_addr);
286 OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE |
287 PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH |
288 PIPE_CONTROL_NOTIFY);
289 OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT);
290 OUT_RING(seqno);
291 OUT_RING(0);
292 ADVANCE_LP_RING();
293 } else {
294 BEGIN_LP_RING(4);
295 OUT_RING(MI_STORE_DWORD_INDEX);
296 OUT_RING(I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
297 OUT_RING(seqno);
298
299 OUT_RING(MI_USER_INTERRUPT);
300 ADVANCE_LP_RING();
301 }
302 return seqno;
303}
304
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800305static u32
Chris Wilsonf787a5f2010-09-24 16:02:42 +0100306render_ring_get_seqno(struct drm_device *dev,
307 struct intel_ring_buffer *ring)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800308{
309 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
310 if (HAS_PIPE_CONTROL(dev))
311 return ((volatile u32 *)(dev_priv->seqno_page))[0];
312 else
313 return intel_read_status_page(ring, I915_GEM_HWS_INDEX);
314}
315
316static void
317render_ring_get_user_irq(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100318 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700319{
320 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
321 unsigned long irqflags;
322
323 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800324 if (dev->irq_enabled && (++ring->user_irq_refcount == 1)) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700325 if (HAS_PCH_SPLIT(dev))
326 ironlake_enable_graphics_irq(dev_priv, GT_PIPE_NOTIFY);
327 else
328 i915_enable_irq(dev_priv, I915_USER_INTERRUPT);
329 }
330 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
331}
332
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800333static void
334render_ring_put_user_irq(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100335 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700336{
337 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
338 unsigned long irqflags;
339
340 spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800341 BUG_ON(dev->irq_enabled && ring->user_irq_refcount <= 0);
342 if (dev->irq_enabled && (--ring->user_irq_refcount == 0)) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700343 if (HAS_PCH_SPLIT(dev))
344 ironlake_disable_graphics_irq(dev_priv, GT_PIPE_NOTIFY);
345 else
346 i915_disable_irq(dev_priv, I915_USER_INTERRUPT);
347 }
348 spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
349}
350
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800351static void render_setup_status_page(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100352 struct intel_ring_buffer *ring)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800353{
354 drm_i915_private_t *dev_priv = dev->dev_private;
355 if (IS_GEN6(dev)) {
Daniel Vetter3d281d82010-09-24 21:14:22 +0200356 I915_WRITE(RING_HWS_PGA_GEN6(ring->mmio_base),
357 ring->status_page.gfx_addr);
358 I915_READ(RING_HWS_PGA_GEN6(ring->mmio_base)); /* posting read */
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800359 } else {
Daniel Vetter3d281d82010-09-24 21:14:22 +0200360 I915_WRITE(RING_HWS_PGA(ring->mmio_base),
361 ring->status_page.gfx_addr);
362 I915_READ(RING_HWS_PGA(ring->mmio_base)); /* posting read */
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800363 }
364
365}
366
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100367static void
Zou Nan haid1b851f2010-05-21 09:08:57 +0800368bsd_ring_flush(struct drm_device *dev,
369 struct intel_ring_buffer *ring,
370 u32 invalidate_domains,
371 u32 flush_domains)
372{
Zou Nan haibe26a102010-06-12 17:40:24 +0800373 intel_ring_begin(dev, ring, 2);
Zou Nan haid1b851f2010-05-21 09:08:57 +0800374 intel_ring_emit(dev, ring, MI_FLUSH);
375 intel_ring_emit(dev, ring, MI_NOOP);
376 intel_ring_advance(dev, ring);
377}
378
Zou Nan haid1b851f2010-05-21 09:08:57 +0800379static int init_bsd_ring(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100380 struct intel_ring_buffer *ring)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800381{
382 return init_ring_common(dev, ring);
383}
384
385static u32
386bsd_ring_add_request(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100387 struct intel_ring_buffer *ring,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100388 u32 flush_domains)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800389{
390 u32 seqno;
Chris Wilson6f392d52010-08-07 11:01:22 +0100391
392 seqno = i915_gem_get_seqno(dev);
393
Zou Nan haid1b851f2010-05-21 09:08:57 +0800394 intel_ring_begin(dev, ring, 4);
395 intel_ring_emit(dev, ring, MI_STORE_DWORD_INDEX);
396 intel_ring_emit(dev, ring,
397 I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
398 intel_ring_emit(dev, ring, seqno);
399 intel_ring_emit(dev, ring, MI_USER_INTERRUPT);
400 intel_ring_advance(dev, ring);
401
402 DRM_DEBUG_DRIVER("%s %d\n", ring->name, seqno);
403
404 return seqno;
405}
406
407static void bsd_setup_status_page(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100408 struct intel_ring_buffer *ring)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800409{
410 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter3d281d82010-09-24 21:14:22 +0200411 I915_WRITE(RING_HWS_PGA(ring->mmio_base), ring->status_page.gfx_addr);
412 I915_READ(RING_HWS_PGA(ring->mmio_base));
Zou Nan haid1b851f2010-05-21 09:08:57 +0800413}
414
415static void
416bsd_ring_get_user_irq(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100417 struct intel_ring_buffer *ring)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800418{
419 /* do nothing */
420}
421static void
422bsd_ring_put_user_irq(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100423 struct intel_ring_buffer *ring)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800424{
425 /* do nothing */
426}
427
428static u32
Chris Wilsonf787a5f2010-09-24 16:02:42 +0100429bsd_ring_get_seqno(struct drm_device *dev,
430 struct intel_ring_buffer *ring)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800431{
432 return intel_read_status_page(ring, I915_GEM_HWS_INDEX);
433}
434
435static int
436bsd_ring_dispatch_gem_execbuffer(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100437 struct intel_ring_buffer *ring,
438 struct drm_i915_gem_execbuffer2 *exec,
439 struct drm_clip_rect *cliprects,
440 uint64_t exec_offset)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800441{
442 uint32_t exec_start;
443 exec_start = (uint32_t) exec_offset + exec->batch_start_offset;
444 intel_ring_begin(dev, ring, 2);
445 intel_ring_emit(dev, ring, MI_BATCH_BUFFER_START |
446 (2 << 6) | MI_BATCH_NON_SECURE_I965);
447 intel_ring_emit(dev, ring, exec_start);
448 intel_ring_advance(dev, ring);
449 return 0;
450}
451
452
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800453static int
454render_ring_dispatch_gem_execbuffer(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100455 struct intel_ring_buffer *ring,
456 struct drm_i915_gem_execbuffer2 *exec,
457 struct drm_clip_rect *cliprects,
458 uint64_t exec_offset)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700459{
460 drm_i915_private_t *dev_priv = dev->dev_private;
461 int nbox = exec->num_cliprects;
462 int i = 0, count;
463 uint32_t exec_start, exec_len;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700464 exec_start = (uint32_t) exec_offset + exec->batch_start_offset;
465 exec_len = (uint32_t) exec->batch_len;
466
Chris Wilson6f392d52010-08-07 11:01:22 +0100467 trace_i915_gem_request_submit(dev, dev_priv->next_seqno + 1);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700468
469 count = nbox ? nbox : 1;
470
471 for (i = 0; i < count; i++) {
472 if (i < nbox) {
473 int ret = i915_emit_box(dev, cliprects, i,
474 exec->DR1, exec->DR4);
475 if (ret)
476 return ret;
477 }
478
479 if (IS_I830(dev) || IS_845G(dev)) {
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800480 intel_ring_begin(dev, ring, 4);
481 intel_ring_emit(dev, ring, MI_BATCH_BUFFER);
482 intel_ring_emit(dev, ring,
483 exec_start | MI_BATCH_NON_SECURE);
484 intel_ring_emit(dev, ring, exec_start + exec_len - 4);
485 intel_ring_emit(dev, ring, 0);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700486 } else {
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800487 intel_ring_begin(dev, ring, 4);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100488 if (INTEL_INFO(dev)->gen >= 4) {
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800489 intel_ring_emit(dev, ring,
490 MI_BATCH_BUFFER_START | (2 << 6)
491 | MI_BATCH_NON_SECURE_I965);
492 intel_ring_emit(dev, ring, exec_start);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700493 } else {
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800494 intel_ring_emit(dev, ring, MI_BATCH_BUFFER_START
495 | (2 << 6));
496 intel_ring_emit(dev, ring, exec_start |
497 MI_BATCH_NON_SECURE);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700498 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700499 }
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800500 intel_ring_advance(dev, ring);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700501 }
502
Zou Nan hai1cafd342010-06-25 13:40:24 +0800503 if (IS_G4X(dev) || IS_IRONLAKE(dev)) {
504 intel_ring_begin(dev, ring, 2);
505 intel_ring_emit(dev, ring, MI_FLUSH |
506 MI_NO_WRITE_FLUSH |
507 MI_INVALIDATE_ISP );
508 intel_ring_emit(dev, ring, MI_NOOP);
509 intel_ring_advance(dev, ring);
510 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700511 /* XXX breadcrumb */
Zou Nan hai1cafd342010-06-25 13:40:24 +0800512
Eric Anholt62fdfea2010-05-21 13:26:39 -0700513 return 0;
514}
515
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800516static void cleanup_status_page(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100517 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700518{
519 drm_i915_private_t *dev_priv = dev->dev_private;
520 struct drm_gem_object *obj;
521 struct drm_i915_gem_object *obj_priv;
522
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800523 obj = ring->status_page.obj;
524 if (obj == NULL)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700525 return;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700526 obj_priv = to_intel_bo(obj);
527
528 kunmap(obj_priv->pages[0]);
529 i915_gem_object_unpin(obj);
530 drm_gem_object_unreference(obj);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800531 ring->status_page.obj = NULL;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700532
533 memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map));
Eric Anholt62fdfea2010-05-21 13:26:39 -0700534}
535
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800536static int init_status_page(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100537 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700538{
539 drm_i915_private_t *dev_priv = dev->dev_private;
540 struct drm_gem_object *obj;
541 struct drm_i915_gem_object *obj_priv;
542 int ret;
543
Eric Anholt62fdfea2010-05-21 13:26:39 -0700544 obj = i915_gem_alloc_object(dev, 4096);
545 if (obj == NULL) {
546 DRM_ERROR("Failed to allocate status page\n");
547 ret = -ENOMEM;
548 goto err;
549 }
550 obj_priv = to_intel_bo(obj);
551 obj_priv->agp_type = AGP_USER_CACHED_MEMORY;
552
553 ret = i915_gem_object_pin(obj, 4096);
554 if (ret != 0) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700555 goto err_unref;
556 }
557
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800558 ring->status_page.gfx_addr = obj_priv->gtt_offset;
559 ring->status_page.page_addr = kmap(obj_priv->pages[0]);
560 if (ring->status_page.page_addr == NULL) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700561 memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map));
Eric Anholt62fdfea2010-05-21 13:26:39 -0700562 goto err_unpin;
563 }
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800564 ring->status_page.obj = obj;
565 memset(ring->status_page.page_addr, 0, PAGE_SIZE);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700566
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800567 ring->setup_status_page(dev, ring);
568 DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n",
569 ring->name, ring->status_page.gfx_addr);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700570
571 return 0;
572
573err_unpin:
574 i915_gem_object_unpin(obj);
575err_unref:
576 drm_gem_object_unreference(obj);
577err:
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800578 return ret;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700579}
580
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800581int intel_init_ring_buffer(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100582 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700583{
Daniel Vetter870e86d2010-08-02 16:29:44 +0200584 struct drm_i915_private *dev_priv = dev->dev_private;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800585 struct drm_i915_gem_object *obj_priv;
586 struct drm_gem_object *obj;
Chris Wilsondd785e32010-08-07 11:01:34 +0100587 int ret;
588
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800589 ring->dev = dev;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700590
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800591 if (I915_NEED_GFX_HWS(dev)) {
592 ret = init_status_page(dev, ring);
593 if (ret)
594 return ret;
595 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700596
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800597 obj = i915_gem_alloc_object(dev, ring->size);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700598 if (obj == NULL) {
599 DRM_ERROR("Failed to allocate ringbuffer\n");
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800600 ret = -ENOMEM;
Chris Wilsondd785e32010-08-07 11:01:34 +0100601 goto err_hws;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700602 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700603
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800604 ring->gem_object = obj;
605
Daniel Vettera9db5c82010-08-02 17:22:48 +0200606 ret = i915_gem_object_pin(obj, PAGE_SIZE);
Chris Wilsondd785e32010-08-07 11:01:34 +0100607 if (ret)
608 goto err_unref;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700609
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800610 obj_priv = to_intel_bo(obj);
611 ring->map.size = ring->size;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700612 ring->map.offset = dev->agp->base + obj_priv->gtt_offset;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700613 ring->map.type = 0;
614 ring->map.flags = 0;
615 ring->map.mtrr = 0;
616
617 drm_core_ioremap_wc(&ring->map, dev);
618 if (ring->map.handle == NULL) {
619 DRM_ERROR("Failed to map ringbuffer.\n");
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800620 ret = -EINVAL;
Chris Wilsondd785e32010-08-07 11:01:34 +0100621 goto err_unpin;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700622 }
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800623
Eric Anholt62fdfea2010-05-21 13:26:39 -0700624 ring->virtual_start = ring->map.handle;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800625 ret = ring->init(dev, ring);
Chris Wilsondd785e32010-08-07 11:01:34 +0100626 if (ret)
627 goto err_unmap;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700628
Eric Anholt62fdfea2010-05-21 13:26:39 -0700629 if (!drm_core_check_feature(dev, DRIVER_MODESET))
630 i915_kernel_lost_context(dev);
631 else {
Daniel Vetter570ef602010-08-02 17:06:23 +0200632 ring->head = I915_READ_HEAD(ring) & HEAD_ADDR;
Daniel Vetter870e86d2010-08-02 16:29:44 +0200633 ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700634 ring->space = ring->head - (ring->tail + 8);
635 if (ring->space < 0)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800636 ring->space += ring->size;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700637 }
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800638 INIT_LIST_HEAD(&ring->active_list);
639 INIT_LIST_HEAD(&ring->request_list);
640 return ret;
Chris Wilsondd785e32010-08-07 11:01:34 +0100641
642err_unmap:
643 drm_core_ioremapfree(&ring->map, dev);
644err_unpin:
645 i915_gem_object_unpin(obj);
646err_unref:
647 drm_gem_object_unreference(obj);
648 ring->gem_object = NULL;
649err_hws:
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800650 cleanup_status_page(dev, ring);
651 return ret;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700652}
653
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800654void intel_cleanup_ring_buffer(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100655 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700656{
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800657 if (ring->gem_object == NULL)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700658 return;
659
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800660 drm_core_ioremapfree(&ring->map, dev);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700661
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800662 i915_gem_object_unpin(ring->gem_object);
663 drm_gem_object_unreference(ring->gem_object);
664 ring->gem_object = NULL;
665 cleanup_status_page(dev, ring);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700666}
667
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100668static int intel_wrap_ring_buffer(struct drm_device *dev,
669 struct intel_ring_buffer *ring)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700670{
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800671 unsigned int *virt;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700672 int rem;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800673 rem = ring->size - ring->tail;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700674
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800675 if (ring->space < rem) {
676 int ret = intel_wait_ring_buffer(dev, ring, rem);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700677 if (ret)
678 return ret;
679 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700680
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800681 virt = (unsigned int *)(ring->virtual_start + ring->tail);
Chris Wilson1741dd42010-08-04 15:18:12 +0100682 rem /= 8;
683 while (rem--) {
Eric Anholt62fdfea2010-05-21 13:26:39 -0700684 *virt++ = MI_NOOP;
Chris Wilson1741dd42010-08-04 15:18:12 +0100685 *virt++ = MI_NOOP;
686 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700687
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800688 ring->tail = 0;
Chris Wilson43ed3402010-07-01 17:53:00 +0100689 ring->space = ring->head - 8;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700690
691 return 0;
692}
693
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800694int intel_wait_ring_buffer(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100695 struct intel_ring_buffer *ring, int n)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700696{
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800697 unsigned long end;
Daniel Vetter570ef602010-08-02 17:06:23 +0200698 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700699
700 trace_i915_ring_wait_begin (dev);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800701 end = jiffies + 3 * HZ;
702 do {
Daniel Vetter570ef602010-08-02 17:06:23 +0200703 ring->head = I915_READ_HEAD(ring) & HEAD_ADDR;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700704 ring->space = ring->head - (ring->tail + 8);
705 if (ring->space < 0)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800706 ring->space += ring->size;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700707 if (ring->space >= n) {
708 trace_i915_ring_wait_end (dev);
709 return 0;
710 }
711
712 if (dev->primary->master) {
713 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
714 if (master_priv->sarea_priv)
715 master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
716 }
Zou Nan haid1b851f2010-05-21 09:08:57 +0800717
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800718 yield();
719 } while (!time_after(jiffies, end));
Eric Anholt62fdfea2010-05-21 13:26:39 -0700720 trace_i915_ring_wait_end (dev);
721 return -EBUSY;
722}
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800723
724void intel_ring_begin(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100725 struct intel_ring_buffer *ring,
726 int num_dwords)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800727{
Zou Nan haibe26a102010-06-12 17:40:24 +0800728 int n = 4*num_dwords;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800729 if (unlikely(ring->tail + n > ring->size))
730 intel_wrap_ring_buffer(dev, ring);
731 if (unlikely(ring->space < n))
732 intel_wait_ring_buffer(dev, ring, n);
Chris Wilsond97ed332010-08-04 15:18:13 +0100733
734 ring->space -= n;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800735}
736
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800737void intel_ring_advance(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100738 struct intel_ring_buffer *ring)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800739{
Chris Wilsond97ed332010-08-04 15:18:13 +0100740 ring->tail &= ring->size - 1;
Daniel Vetter870e86d2010-08-02 16:29:44 +0200741 ring->set_tail(dev, ring, ring->tail);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800742}
743
744void intel_fill_struct(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100745 struct intel_ring_buffer *ring,
746 void *data,
747 unsigned int len)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800748{
749 unsigned int *virt = ring->virtual_start + ring->tail;
750 BUG_ON((len&~(4-1)) != 0);
Zou Nan haibe26a102010-06-12 17:40:24 +0800751 intel_ring_begin(dev, ring, len/4);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800752 memcpy(virt, data, len);
753 ring->tail += len;
754 ring->tail &= ring->size - 1;
755 ring->space -= len;
756 intel_ring_advance(dev, ring);
757}
758
Chris Wilsone0708682010-09-19 14:46:27 +0100759static const struct intel_ring_buffer render_ring = {
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800760 .name = "render ring",
Chris Wilson92204342010-09-18 11:02:01 +0100761 .id = RING_RENDER,
Daniel Vetter333e9fe2010-08-02 16:24:01 +0200762 .mmio_base = RENDER_RING_BASE,
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800763 .size = 32 * PAGE_SIZE,
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800764 .setup_status_page = render_setup_status_page,
765 .init = init_render_ring,
Daniel Vetter870e86d2010-08-02 16:29:44 +0200766 .set_tail = ring_set_tail,
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800767 .flush = render_ring_flush,
768 .add_request = render_ring_add_request,
Chris Wilsonf787a5f2010-09-24 16:02:42 +0100769 .get_seqno = render_ring_get_seqno,
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800770 .user_irq_get = render_ring_get_user_irq,
771 .user_irq_put = render_ring_put_user_irq,
772 .dispatch_gem_execbuffer = render_ring_dispatch_gem_execbuffer,
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800773};
Zou Nan haid1b851f2010-05-21 09:08:57 +0800774
775/* ring buffer for bit-stream decoder */
776
Chris Wilsone0708682010-09-19 14:46:27 +0100777static const struct intel_ring_buffer bsd_ring = {
Zou Nan haid1b851f2010-05-21 09:08:57 +0800778 .name = "bsd ring",
Chris Wilson92204342010-09-18 11:02:01 +0100779 .id = RING_BSD,
Daniel Vetter333e9fe2010-08-02 16:24:01 +0200780 .mmio_base = BSD_RING_BASE,
Zou Nan haid1b851f2010-05-21 09:08:57 +0800781 .size = 32 * PAGE_SIZE,
Zou Nan haid1b851f2010-05-21 09:08:57 +0800782 .setup_status_page = bsd_setup_status_page,
783 .init = init_bsd_ring,
Daniel Vetter870e86d2010-08-02 16:29:44 +0200784 .set_tail = ring_set_tail,
Zou Nan haid1b851f2010-05-21 09:08:57 +0800785 .flush = bsd_ring_flush,
786 .add_request = bsd_ring_add_request,
Chris Wilsonf787a5f2010-09-24 16:02:42 +0100787 .get_seqno = bsd_ring_get_seqno,
Zou Nan haid1b851f2010-05-21 09:08:57 +0800788 .user_irq_get = bsd_ring_get_user_irq,
789 .user_irq_put = bsd_ring_put_user_irq,
790 .dispatch_gem_execbuffer = bsd_ring_dispatch_gem_execbuffer,
Zou Nan haid1b851f2010-05-21 09:08:57 +0800791};
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800792
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100793
794static void gen6_bsd_setup_status_page(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100795 struct intel_ring_buffer *ring)
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100796{
797 drm_i915_private_t *dev_priv = dev->dev_private;
Daniel Vetter3d281d82010-09-24 21:14:22 +0200798 I915_WRITE(RING_HWS_PGA_GEN6(ring->mmio_base), ring->status_page.gfx_addr);
799 I915_READ(RING_HWS_PGA_GEN6(ring->mmio_base));
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100800}
801
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100802static void gen6_bsd_ring_set_tail(struct drm_device *dev,
803 struct intel_ring_buffer *ring,
804 u32 value)
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100805{
806 drm_i915_private_t *dev_priv = dev->dev_private;
807
808 /* Every tail move must follow the sequence below */
809 I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL,
810 GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK |
811 GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_DISABLE);
812 I915_WRITE(GEN6_BSD_RNCID, 0x0);
813
814 if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) &
815 GEN6_BSD_SLEEP_PSMI_CONTROL_IDLE_INDICATOR) == 0,
816 50))
817 DRM_ERROR("timed out waiting for IDLE Indicator\n");
818
Daniel Vetter870e86d2010-08-02 16:29:44 +0200819 I915_WRITE_TAIL(ring, value);
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100820 I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL,
821 GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK |
822 GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_ENABLE);
823}
824
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100825static void gen6_bsd_ring_flush(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100826 struct intel_ring_buffer *ring,
827 u32 invalidate_domains,
828 u32 flush_domains)
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100829{
830 intel_ring_begin(dev, ring, 4);
831 intel_ring_emit(dev, ring, MI_FLUSH_DW);
832 intel_ring_emit(dev, ring, 0);
833 intel_ring_emit(dev, ring, 0);
834 intel_ring_emit(dev, ring, 0);
835 intel_ring_advance(dev, ring);
836}
837
838static int
839gen6_bsd_ring_dispatch_gem_execbuffer(struct drm_device *dev,
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100840 struct intel_ring_buffer *ring,
841 struct drm_i915_gem_execbuffer2 *exec,
842 struct drm_clip_rect *cliprects,
843 uint64_t exec_offset)
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100844{
845 uint32_t exec_start;
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100846
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100847 exec_start = (uint32_t) exec_offset + exec->batch_start_offset;
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100848
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100849 intel_ring_begin(dev, ring, 2);
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100850 intel_ring_emit(dev, ring,
851 MI_BATCH_BUFFER_START | MI_BATCH_NON_SECURE_I965);
852 /* bit0-7 is the length on GEN6+ */
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100853 intel_ring_emit(dev, ring, exec_start);
854 intel_ring_advance(dev, ring);
Chris Wilsonab6f8e32010-09-19 17:53:44 +0100855
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100856 return 0;
857}
858
859/* ring buffer for Video Codec for Gen6+ */
Chris Wilsone0708682010-09-19 14:46:27 +0100860static const struct intel_ring_buffer gen6_bsd_ring = {
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100861 .name = "gen6 bsd ring",
862 .id = RING_BSD,
Daniel Vetter333e9fe2010-08-02 16:24:01 +0200863 .mmio_base = GEN6_BSD_RING_BASE,
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100864 .size = 32 * PAGE_SIZE,
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100865 .setup_status_page = gen6_bsd_setup_status_page,
866 .init = init_bsd_ring,
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100867 .set_tail = gen6_bsd_ring_set_tail,
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100868 .flush = gen6_bsd_ring_flush,
869 .add_request = bsd_ring_add_request,
Chris Wilsonf787a5f2010-09-24 16:02:42 +0100870 .get_seqno = bsd_ring_get_seqno,
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100871 .user_irq_get = bsd_ring_get_user_irq,
872 .user_irq_put = bsd_ring_put_user_irq,
873 .dispatch_gem_execbuffer = gen6_bsd_ring_dispatch_gem_execbuffer,
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100874};
875
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800876int intel_init_render_ring_buffer(struct drm_device *dev)
877{
878 drm_i915_private_t *dev_priv = dev->dev_private;
879
880 dev_priv->render_ring = render_ring;
881
882 if (!I915_NEED_GFX_HWS(dev)) {
883 dev_priv->render_ring.status_page.page_addr
884 = dev_priv->status_page_dmah->vaddr;
885 memset(dev_priv->render_ring.status_page.page_addr,
886 0, PAGE_SIZE);
887 }
888
889 return intel_init_ring_buffer(dev, &dev_priv->render_ring);
890}
891
892int intel_init_bsd_ring_buffer(struct drm_device *dev)
893{
894 drm_i915_private_t *dev_priv = dev->dev_private;
895
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100896 if (IS_GEN6(dev))
897 dev_priv->bsd_ring = gen6_bsd_ring;
898 else
899 dev_priv->bsd_ring = bsd_ring;
Xiang, Haihao5c1143b2010-09-16 10:43:11 +0800900
901 return intel_init_ring_buffer(dev, &dev_priv->bsd_ring);
902}