blob: 0dadc025b77b6d8ec17236086beef4b700f2ba06 [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Jesse Barnes63eeaf32009-06-18 16:56:52 -070029#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090030#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "drmP.h"
32#include "drm.h"
33#include "i915_drm.h"
34#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010035#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080036#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define MAX_NOPID ((u32)~0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Keith Packard7c463582008-11-04 02:03:27 -080040/**
41 * Interrupts that are always left unmasked.
42 *
43 * Since pipe events are edge-triggered from the PIPESTAT register to IIR,
44 * we leave them always unmasked in IMR and then control enabling them through
45 * PIPESTAT alone.
46 */
Kristian Høgsberg6b95a202009-11-18 11:25:18 -050047#define I915_INTERRUPT_ENABLE_FIX \
48 (I915_ASLE_INTERRUPT | \
49 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | \
50 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | \
51 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT | \
52 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT | \
53 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Keith Packard7c463582008-11-04 02:03:27 -080054
55/** Interrupts that we mask and unmask at runtime. */
Zou Nan haid1b851f2010-05-21 09:08:57 +080056#define I915_INTERRUPT_ENABLE_VAR (I915_USER_INTERRUPT | I915_BSD_USER_INTERRUPT)
Keith Packard7c463582008-11-04 02:03:27 -080057
Jesse Barnes79e53942008-11-07 14:24:08 -080058#define I915_PIPE_VBLANK_STATUS (PIPE_START_VBLANK_INTERRUPT_STATUS |\
59 PIPE_VBLANK_INTERRUPT_STATUS)
60
61#define I915_PIPE_VBLANK_ENABLE (PIPE_START_VBLANK_INTERRUPT_ENABLE |\
62 PIPE_VBLANK_INTERRUPT_ENABLE)
63
64#define DRM_I915_VBLANK_PIPE_ALL (DRM_I915_VBLANK_PIPE_A | \
65 DRM_I915_VBLANK_PIPE_B)
66
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +010067void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050068ironlake_enable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080069{
Chris Wilson1ec14ad2010-12-04 11:30:53 +000070 if ((dev_priv->gt_irq_mask & mask) != 0) {
71 dev_priv->gt_irq_mask &= ~mask;
72 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000073 POSTING_READ(GTIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080074 }
75}
76
Eric Anholt62fdfea2010-05-21 13:26:39 -070077void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050078ironlake_disable_graphics_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080079{
Chris Wilson1ec14ad2010-12-04 11:30:53 +000080 if ((dev_priv->gt_irq_mask & mask) != mask) {
81 dev_priv->gt_irq_mask |= mask;
82 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000083 POSTING_READ(GTIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080084 }
85}
86
87/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010088static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050089ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080090{
Chris Wilson1ec14ad2010-12-04 11:30:53 +000091 if ((dev_priv->irq_mask & mask) != 0) {
92 dev_priv->irq_mask &= ~mask;
93 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000094 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080095 }
96}
97
98static inline void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050099ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800100{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000101 if ((dev_priv->irq_mask & mask) != mask) {
102 dev_priv->irq_mask |= mask;
103 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000104 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800105 }
106}
107
108void
Eric Anholted4cb412008-07-29 12:10:39 -0700109i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask)
110{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000111 if ((dev_priv->irq_mask & mask) != 0) {
112 dev_priv->irq_mask &= ~mask;
113 I915_WRITE(IMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000114 POSTING_READ(IMR);
Eric Anholted4cb412008-07-29 12:10:39 -0700115 }
116}
117
Eric Anholt62fdfea2010-05-21 13:26:39 -0700118void
Eric Anholted4cb412008-07-29 12:10:39 -0700119i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask)
120{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000121 if ((dev_priv->irq_mask & mask) != mask) {
122 dev_priv->irq_mask |= mask;
123 I915_WRITE(IMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000124 POSTING_READ(IMR);
Eric Anholted4cb412008-07-29 12:10:39 -0700125 }
126}
127
Keith Packard7c463582008-11-04 02:03:27 -0800128static inline u32
129i915_pipestat(int pipe)
130{
131 if (pipe == 0)
132 return PIPEASTAT;
133 if (pipe == 1)
134 return PIPEBSTAT;
Andrew Morton9c84ba42008-12-01 13:14:08 -0800135 BUG();
Keith Packard7c463582008-11-04 02:03:27 -0800136}
137
138void
139i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
140{
141 if ((dev_priv->pipestat[pipe] & mask) != mask) {
142 u32 reg = i915_pipestat(pipe);
143
144 dev_priv->pipestat[pipe] |= mask;
145 /* Enable the interrupt, clear any pending status */
146 I915_WRITE(reg, dev_priv->pipestat[pipe] | (mask >> 16));
Chris Wilson3143a2b2010-11-16 15:55:10 +0000147 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800148 }
149}
150
151void
152i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
153{
154 if ((dev_priv->pipestat[pipe] & mask) != 0) {
155 u32 reg = i915_pipestat(pipe);
156
157 dev_priv->pipestat[pipe] &= ~mask;
158 I915_WRITE(reg, dev_priv->pipestat[pipe]);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000159 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800160 }
161}
162
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000163/**
Zhao Yakui01c66882009-10-28 05:10:00 +0000164 * intel_enable_asle - enable ASLE interrupt for OpRegion
165 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000166void intel_enable_asle(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000167{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000168 drm_i915_private_t *dev_priv = dev->dev_private;
169 unsigned long irqflags;
170
171 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000172
Eric Anholtc619eed2010-01-28 16:45:52 -0800173 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500174 ironlake_enable_display_irq(dev_priv, DE_GSE);
Zhao Yakuiedcb49c2010-04-07 17:11:21 +0800175 else {
Zhao Yakui01c66882009-10-28 05:10:00 +0000176 i915_enable_pipestat(dev_priv, 1,
Jesse Barnesd874bcf2010-06-30 13:16:00 -0700177 PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100178 if (INTEL_INFO(dev)->gen >= 4)
Zhao Yakuiedcb49c2010-04-07 17:11:21 +0800179 i915_enable_pipestat(dev_priv, 0,
Jesse Barnesd874bcf2010-06-30 13:16:00 -0700180 PIPE_LEGACY_BLC_EVENT_ENABLE);
Zhao Yakuiedcb49c2010-04-07 17:11:21 +0800181 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000182
183 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000184}
185
186/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700187 * i915_pipe_enabled - check if a pipe is enabled
188 * @dev: DRM device
189 * @pipe: pipe to check
190 *
191 * Reading certain registers when the pipe is disabled can hang the chip.
192 * Use this routine to make sure the PLL is running and the pipe is active
193 * before reading such registers if unsure.
194 */
195static int
196i915_pipe_enabled(struct drm_device *dev, int pipe)
197{
198 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson5eddb702010-09-11 13:48:45 +0100199 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700200}
201
Keith Packard42f52ef2008-10-18 19:39:29 -0700202/* Called from drm generic code, passed a 'crtc', which
203 * we use as a pipe index
204 */
205u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700206{
207 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
208 unsigned long high_frame;
209 unsigned long low_frame;
Chris Wilson5eddb702010-09-11 13:48:45 +0100210 u32 high1, high2, low;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700211
212 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800213 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
214 "pipe %d\n", pipe);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700215 return 0;
216 }
217
Chris Wilson5eddb702010-09-11 13:48:45 +0100218 high_frame = pipe ? PIPEBFRAMEHIGH : PIPEAFRAMEHIGH;
219 low_frame = pipe ? PIPEBFRAMEPIXEL : PIPEAFRAMEPIXEL;
220
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700221 /*
222 * High & low register fields aren't synchronized, so make sure
223 * we get a low value that's stable across two reads of the high
224 * register.
225 */
226 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100227 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
228 low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
229 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700230 } while (high1 != high2);
231
Chris Wilson5eddb702010-09-11 13:48:45 +0100232 high1 >>= PIPE_FRAME_HIGH_SHIFT;
233 low >>= PIPE_FRAME_LOW_SHIFT;
234 return (high1 << 8) | low;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700235}
236
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800237u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
238{
239 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
240 int reg = pipe ? PIPEB_FRMCOUNT_GM45 : PIPEA_FRMCOUNT_GM45;
241
242 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800243 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
244 "pipe %d\n", pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800245 return 0;
246 }
247
248 return I915_READ(reg);
249}
250
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100251int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
252 int *vpos, int *hpos)
253{
254 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
255 u32 vbl = 0, position = 0;
256 int vbl_start, vbl_end, htotal, vtotal;
257 bool in_vbl = true;
258 int ret = 0;
259
260 if (!i915_pipe_enabled(dev, pipe)) {
261 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
262 "pipe %d\n", pipe);
263 return 0;
264 }
265
266 /* Get vtotal. */
267 vtotal = 1 + ((I915_READ(VTOTAL(pipe)) >> 16) & 0x1fff);
268
269 if (INTEL_INFO(dev)->gen >= 4) {
270 /* No obvious pixelcount register. Only query vertical
271 * scanout position from Display scan line register.
272 */
273 position = I915_READ(PIPEDSL(pipe));
274
275 /* Decode into vertical scanout position. Don't have
276 * horizontal scanout position.
277 */
278 *vpos = position & 0x1fff;
279 *hpos = 0;
280 } else {
281 /* Have access to pixelcount since start of frame.
282 * We can split this into vertical and horizontal
283 * scanout position.
284 */
285 position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
286
287 htotal = 1 + ((I915_READ(HTOTAL(pipe)) >> 16) & 0x1fff);
288 *vpos = position / htotal;
289 *hpos = position - (*vpos * htotal);
290 }
291
292 /* Query vblank area. */
293 vbl = I915_READ(VBLANK(pipe));
294
295 /* Test position against vblank region. */
296 vbl_start = vbl & 0x1fff;
297 vbl_end = (vbl >> 16) & 0x1fff;
298
299 if ((*vpos < vbl_start) || (*vpos > vbl_end))
300 in_vbl = false;
301
302 /* Inside "upper part" of vblank area? Apply corrective offset: */
303 if (in_vbl && (*vpos >= vbl_start))
304 *vpos = *vpos - vtotal;
305
306 /* Readouts valid? */
307 if (vbl > 0)
308 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
309
310 /* In vblank? */
311 if (in_vbl)
312 ret |= DRM_SCANOUTPOS_INVBL;
313
314 return ret;
315}
316
317int i915_get_vblank_timestamp(struct drm_device *dev, int crtc,
318 int *max_error,
319 struct timeval *vblank_time,
320 unsigned flags)
321{
322 struct drm_crtc *drmcrtc;
323
324 if (crtc < 0 || crtc >= dev->num_crtcs) {
325 DRM_ERROR("Invalid crtc %d\n", crtc);
326 return -EINVAL;
327 }
328
329 /* Get drm_crtc to timestamp: */
330 drmcrtc = intel_get_crtc_for_pipe(dev, crtc);
331
332 /* Helper routine in DRM core does all the work: */
333 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error,
334 vblank_time, flags, drmcrtc);
335}
336
Jesse Barnes5ca58282009-03-31 14:11:15 -0700337/*
338 * Handle hotplug events outside the interrupt handler proper.
339 */
340static void i915_hotplug_work_func(struct work_struct *work)
341{
342 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
343 hotplug_work);
344 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700345 struct drm_mode_config *mode_config = &dev->mode_config;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100346 struct intel_encoder *encoder;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700347
Chris Wilson4ef69c72010-09-09 15:14:28 +0100348 list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
349 if (encoder->hot_plug)
350 encoder->hot_plug(encoder);
351
Jesse Barnes5ca58282009-03-31 14:11:15 -0700352 /* Just fire off a uevent and let userspace tell us what to do */
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000353 drm_helper_hpd_irq_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700354}
355
Jesse Barnesf97108d2010-01-29 11:27:07 -0800356static void i915_handle_rps_change(struct drm_device *dev)
357{
358 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000359 u32 busy_up, busy_down, max_avg, min_avg;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800360 u8 new_delay = dev_priv->cur_delay;
361
Jesse Barnes7648fa92010-05-20 14:28:11 -0700362 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000363 busy_up = I915_READ(RCPREVBSYTUPAVG);
364 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800365 max_avg = I915_READ(RCBMAXAVG);
366 min_avg = I915_READ(RCBMINAVG);
367
368 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000369 if (busy_up > max_avg) {
Jesse Barnesf97108d2010-01-29 11:27:07 -0800370 if (dev_priv->cur_delay != dev_priv->max_delay)
371 new_delay = dev_priv->cur_delay - 1;
372 if (new_delay < dev_priv->max_delay)
373 new_delay = dev_priv->max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000374 } else if (busy_down < min_avg) {
Jesse Barnesf97108d2010-01-29 11:27:07 -0800375 if (dev_priv->cur_delay != dev_priv->min_delay)
376 new_delay = dev_priv->cur_delay + 1;
377 if (new_delay > dev_priv->min_delay)
378 new_delay = dev_priv->min_delay;
379 }
380
Jesse Barnes7648fa92010-05-20 14:28:11 -0700381 if (ironlake_set_drps(dev, new_delay))
382 dev_priv->cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800383
384 return;
385}
386
Chris Wilson549f7362010-10-19 11:19:32 +0100387static void notify_ring(struct drm_device *dev,
388 struct intel_ring_buffer *ring)
389{
390 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson78501ea2010-10-27 12:18:21 +0100391 u32 seqno = ring->get_seqno(ring);
Chris Wilsonb2223492010-10-27 15:27:33 +0100392 ring->irq_seqno = seqno;
Chris Wilson549f7362010-10-19 11:19:32 +0100393 trace_i915_gem_request_complete(dev, seqno);
394 wake_up_all(&ring->irq_queue);
395 dev_priv->hangcheck_count = 0;
396 mod_timer(&dev_priv->hangcheck_timer,
397 jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
398}
399
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800400static void gen6_pm_irq_handler(struct drm_device *dev)
401{
402 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
403 u8 new_delay = dev_priv->cur_delay;
404 u32 pm_iir;
405
406 pm_iir = I915_READ(GEN6_PMIIR);
407 if (!pm_iir)
408 return;
409
410 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
411 if (dev_priv->cur_delay != dev_priv->max_delay)
412 new_delay = dev_priv->cur_delay + 1;
413 if (new_delay > dev_priv->max_delay)
414 new_delay = dev_priv->max_delay;
415 } else if (pm_iir & (GEN6_PM_RP_DOWN_THRESHOLD | GEN6_PM_RP_DOWN_TIMEOUT)) {
416 if (dev_priv->cur_delay != dev_priv->min_delay)
417 new_delay = dev_priv->cur_delay - 1;
418 if (new_delay < dev_priv->min_delay) {
419 new_delay = dev_priv->min_delay;
420 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
421 I915_READ(GEN6_RP_INTERRUPT_LIMITS) |
422 ((new_delay << 16) & 0x3f0000));
423 } else {
424 /* Make sure we continue to get down interrupts
425 * until we hit the minimum frequency */
426 I915_WRITE(GEN6_RP_INTERRUPT_LIMITS,
427 I915_READ(GEN6_RP_INTERRUPT_LIMITS) & ~0x3f0000);
428 }
429
430 }
431
432 gen6_set_rps(dev, new_delay);
433 dev_priv->cur_delay = new_delay;
434
435 I915_WRITE(GEN6_PMIIR, pm_iir);
436}
437
Chris Wilson995b6762010-08-20 13:23:26 +0100438static irqreturn_t ironlake_irq_handler(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800439{
440 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
441 int ret = IRQ_NONE;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800442 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
Yuanhan Liu2d7b8362010-10-08 10:21:06 +0100443 u32 hotplug_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800444 struct drm_i915_master_private *master_priv;
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100445 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
446
447 if (IS_GEN6(dev))
448 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800449
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000450 /* disable master interrupt before clearing iir */
451 de_ier = I915_READ(DEIER);
452 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000453 POSTING_READ(DEIER);
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000454
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800455 de_iir = I915_READ(DEIIR);
456 gt_iir = I915_READ(GTIIR);
Zhenyu Wangc6501562009-11-03 18:57:21 +0000457 pch_iir = I915_READ(SDEIIR);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800458 pm_iir = I915_READ(GEN6_PMIIR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800459
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800460 if (de_iir == 0 && gt_iir == 0 && pch_iir == 0 &&
461 (!IS_GEN6(dev) || pm_iir == 0))
Zou Nan haic7c85102010-01-15 10:29:06 +0800462 goto done;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800463
Yuanhan Liu2d7b8362010-10-08 10:21:06 +0100464 if (HAS_PCH_CPT(dev))
465 hotplug_mask = SDE_HOTPLUG_MASK_CPT;
466 else
467 hotplug_mask = SDE_HOTPLUG_MASK;
468
Zou Nan haic7c85102010-01-15 10:29:06 +0800469 ret = IRQ_HANDLED;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800470
Zou Nan haic7c85102010-01-15 10:29:06 +0800471 if (dev->primary->master) {
472 master_priv = dev->primary->master->driver_priv;
473 if (master_priv->sarea_priv)
474 master_priv->sarea_priv->last_dispatch =
475 READ_BREADCRUMB(dev_priv);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800476 }
477
Chris Wilsonc6df5412010-12-15 09:56:50 +0000478 if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000479 notify_ring(dev, &dev_priv->ring[RCS]);
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100480 if (gt_iir & bsd_usr_interrupt)
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000481 notify_ring(dev, &dev_priv->ring[VCS]);
482 if (gt_iir & GT_BLT_USER_INTERRUPT)
483 notify_ring(dev, &dev_priv->ring[BCS]);
Zou Nan haic7c85102010-01-15 10:29:06 +0800484
485 if (de_iir & DE_GSE)
Chris Wilson3b617962010-08-24 09:02:58 +0100486 intel_opregion_gse_intr(dev);
Zou Nan haic7c85102010-01-15 10:29:06 +0800487
Zhenyu Wangf072d2e2010-02-09 09:46:19 +0800488 if (de_iir & DE_PLANEA_FLIP_DONE) {
Jesse Barnes013d5aa2010-01-29 11:18:31 -0800489 intel_prepare_page_flip(dev, 0);
Chris Wilson2bbda382010-09-02 17:59:39 +0100490 intel_finish_page_flip_plane(dev, 0);
Jesse Barnes013d5aa2010-01-29 11:18:31 -0800491 }
492
Zhenyu Wangf072d2e2010-02-09 09:46:19 +0800493 if (de_iir & DE_PLANEB_FLIP_DONE) {
494 intel_prepare_page_flip(dev, 1);
Chris Wilson2bbda382010-09-02 17:59:39 +0100495 intel_finish_page_flip_plane(dev, 1);
Jesse Barnes013d5aa2010-01-29 11:18:31 -0800496 }
Li Pengc062df62010-01-23 00:12:58 +0800497
Zhenyu Wangf072d2e2010-02-09 09:46:19 +0800498 if (de_iir & DE_PIPEA_VBLANK)
499 drm_handle_vblank(dev, 0);
500
501 if (de_iir & DE_PIPEB_VBLANK)
502 drm_handle_vblank(dev, 1);
503
Zou Nan haic7c85102010-01-15 10:29:06 +0800504 /* check event from PCH */
Yuanhan Liu2d7b8362010-10-08 10:21:06 +0100505 if ((de_iir & DE_PCH_EVENT) && (pch_iir & hotplug_mask))
Zou Nan haic7c85102010-01-15 10:29:06 +0800506 queue_work(dev_priv->wq, &dev_priv->hotplug_work);
Zou Nan haic7c85102010-01-15 10:29:06 +0800507
Jesse Barnesf97108d2010-01-29 11:27:07 -0800508 if (de_iir & DE_PCU_EVENT) {
Jesse Barnes7648fa92010-05-20 14:28:11 -0700509 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
Jesse Barnesf97108d2010-01-29 11:27:07 -0800510 i915_handle_rps_change(dev);
511 }
512
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800513 if (IS_GEN6(dev))
514 gen6_pm_irq_handler(dev);
515
Zou Nan haic7c85102010-01-15 10:29:06 +0800516 /* should clear PCH hotplug event before clear CPU irq */
517 I915_WRITE(SDEIIR, pch_iir);
518 I915_WRITE(GTIIR, gt_iir);
519 I915_WRITE(DEIIR, de_iir);
520
521done:
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000522 I915_WRITE(DEIER, de_ier);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000523 POSTING_READ(DEIER);
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000524
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800525 return ret;
526}
527
Jesse Barnes8a905232009-07-11 16:48:03 -0400528/**
529 * i915_error_work_func - do process context error handling work
530 * @work: work struct
531 *
532 * Fire an error uevent so userspace can see that a hang or error
533 * was detected.
534 */
535static void i915_error_work_func(struct work_struct *work)
536{
537 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
538 error_work);
539 struct drm_device *dev = dev_priv->dev;
Ben Gamarif316a422009-09-14 17:48:46 -0400540 char *error_event[] = { "ERROR=1", NULL };
541 char *reset_event[] = { "RESET=1", NULL };
542 char *reset_done_event[] = { "ERROR=0", NULL };
Jesse Barnes8a905232009-07-11 16:48:03 -0400543
Ben Gamarif316a422009-09-14 17:48:46 -0400544 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -0400545
Ben Gamariba1234d2009-09-14 17:48:47 -0400546 if (atomic_read(&dev_priv->mm.wedged)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +0100547 DRM_DEBUG_DRIVER("resetting chip\n");
548 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
549 if (!i915_reset(dev, GRDOM_RENDER)) {
550 atomic_set(&dev_priv->mm.wedged, 0);
551 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
Ben Gamarif316a422009-09-14 17:48:46 -0400552 }
Chris Wilson30dbf0c2010-09-25 10:19:17 +0100553 complete_all(&dev_priv->error_completion);
Ben Gamarif316a422009-09-14 17:48:46 -0400554 }
Jesse Barnes8a905232009-07-11 16:48:03 -0400555}
556
Chris Wilson3bd3c932010-08-19 08:19:30 +0100557#ifdef CONFIG_DEBUG_FS
Chris Wilson9df30792010-02-18 10:24:56 +0000558static struct drm_i915_error_object *
559i915_error_object_create(struct drm_device *dev,
Chris Wilson05394f32010-11-08 19:18:58 +0000560 struct drm_i915_gem_object *src)
Chris Wilson9df30792010-02-18 10:24:56 +0000561{
Chris Wilsone56660d2010-08-07 11:01:26 +0100562 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson9df30792010-02-18 10:24:56 +0000563 struct drm_i915_error_object *dst;
Chris Wilson9df30792010-02-18 10:24:56 +0000564 int page, page_count;
Chris Wilsone56660d2010-08-07 11:01:26 +0100565 u32 reloc_offset;
Chris Wilson9df30792010-02-18 10:24:56 +0000566
Chris Wilson05394f32010-11-08 19:18:58 +0000567 if (src == NULL || src->pages == NULL)
Chris Wilson9df30792010-02-18 10:24:56 +0000568 return NULL;
569
Chris Wilson05394f32010-11-08 19:18:58 +0000570 page_count = src->base.size / PAGE_SIZE;
Chris Wilson9df30792010-02-18 10:24:56 +0000571
572 dst = kmalloc(sizeof(*dst) + page_count * sizeof (u32 *), GFP_ATOMIC);
573 if (dst == NULL)
574 return NULL;
575
Chris Wilson05394f32010-11-08 19:18:58 +0000576 reloc_offset = src->gtt_offset;
Chris Wilson9df30792010-02-18 10:24:56 +0000577 for (page = 0; page < page_count; page++) {
Andrew Morton788885a2010-05-11 14:07:05 -0700578 unsigned long flags;
Chris Wilsone56660d2010-08-07 11:01:26 +0100579 void __iomem *s;
580 void *d;
Andrew Morton788885a2010-05-11 14:07:05 -0700581
Chris Wilsone56660d2010-08-07 11:01:26 +0100582 d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
Chris Wilson9df30792010-02-18 10:24:56 +0000583 if (d == NULL)
584 goto unwind;
Chris Wilsone56660d2010-08-07 11:01:26 +0100585
Andrew Morton788885a2010-05-11 14:07:05 -0700586 local_irq_save(flags);
Chris Wilsone56660d2010-08-07 11:01:26 +0100587 s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -0700588 reloc_offset);
Chris Wilsone56660d2010-08-07 11:01:26 +0100589 memcpy_fromio(d, s, PAGE_SIZE);
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -0700590 io_mapping_unmap_atomic(s);
Andrew Morton788885a2010-05-11 14:07:05 -0700591 local_irq_restore(flags);
Chris Wilsone56660d2010-08-07 11:01:26 +0100592
Chris Wilson9df30792010-02-18 10:24:56 +0000593 dst->pages[page] = d;
Chris Wilsone56660d2010-08-07 11:01:26 +0100594
595 reloc_offset += PAGE_SIZE;
Chris Wilson9df30792010-02-18 10:24:56 +0000596 }
597 dst->page_count = page_count;
Chris Wilson05394f32010-11-08 19:18:58 +0000598 dst->gtt_offset = src->gtt_offset;
Chris Wilson9df30792010-02-18 10:24:56 +0000599
600 return dst;
601
602unwind:
603 while (page--)
604 kfree(dst->pages[page]);
605 kfree(dst);
606 return NULL;
607}
608
609static void
610i915_error_object_free(struct drm_i915_error_object *obj)
611{
612 int page;
613
614 if (obj == NULL)
615 return;
616
617 for (page = 0; page < obj->page_count; page++)
618 kfree(obj->pages[page]);
619
620 kfree(obj);
621}
622
623static void
624i915_error_state_free(struct drm_device *dev,
625 struct drm_i915_error_state *error)
626{
627 i915_error_object_free(error->batchbuffer[0]);
628 i915_error_object_free(error->batchbuffer[1]);
629 i915_error_object_free(error->ringbuffer);
630 kfree(error->active_bo);
Chris Wilson6ef3d422010-08-04 20:26:07 +0100631 kfree(error->overlay);
Chris Wilson9df30792010-02-18 10:24:56 +0000632 kfree(error);
633}
634
635static u32
636i915_get_bbaddr(struct drm_device *dev, u32 *ring)
637{
638 u32 cmd;
639
640 if (IS_I830(dev) || IS_845G(dev))
641 cmd = MI_BATCH_BUFFER;
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100642 else if (INTEL_INFO(dev)->gen >= 4)
Chris Wilson9df30792010-02-18 10:24:56 +0000643 cmd = (MI_BATCH_BUFFER_START | (2 << 6) |
644 MI_BATCH_NON_SECURE_I965);
645 else
646 cmd = (MI_BATCH_BUFFER_START | (2 << 6));
647
648 return ring[0] == cmd ? ring[1] : 0;
649}
650
651static u32
Chris Wilson8168bd42010-11-11 17:54:52 +0000652i915_ringbuffer_last_batch(struct drm_device *dev,
653 struct intel_ring_buffer *ring)
Chris Wilson9df30792010-02-18 10:24:56 +0000654{
655 struct drm_i915_private *dev_priv = dev->dev_private;
656 u32 head, bbaddr;
Chris Wilson8168bd42010-11-11 17:54:52 +0000657 u32 *val;
Chris Wilson9df30792010-02-18 10:24:56 +0000658
659 /* Locate the current position in the ringbuffer and walk back
660 * to find the most recently dispatched batch buffer.
661 */
Chris Wilson8168bd42010-11-11 17:54:52 +0000662 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Chris Wilson9df30792010-02-18 10:24:56 +0000663
Chris Wilsonab5793a2010-11-22 13:24:13 +0000664 val = (u32 *)(ring->virtual_start + head);
Chris Wilson8168bd42010-11-11 17:54:52 +0000665 while (--val >= (u32 *)ring->virtual_start) {
666 bbaddr = i915_get_bbaddr(dev, val);
Chris Wilson9df30792010-02-18 10:24:56 +0000667 if (bbaddr)
Chris Wilsonab5793a2010-11-22 13:24:13 +0000668 return bbaddr;
Chris Wilson9df30792010-02-18 10:24:56 +0000669 }
670
Chris Wilsonab5793a2010-11-22 13:24:13 +0000671 val = (u32 *)(ring->virtual_start + ring->size);
672 while (--val >= (u32 *)ring->virtual_start) {
673 bbaddr = i915_get_bbaddr(dev, val);
674 if (bbaddr)
675 return bbaddr;
Chris Wilson9df30792010-02-18 10:24:56 +0000676 }
677
Chris Wilsonab5793a2010-11-22 13:24:13 +0000678 return 0;
Chris Wilson9df30792010-02-18 10:24:56 +0000679}
680
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000681static u32 capture_bo_list(struct drm_i915_error_buffer *err,
682 int count,
683 struct list_head *head)
684{
685 struct drm_i915_gem_object *obj;
686 int i = 0;
687
688 list_for_each_entry(obj, head, mm_list) {
689 err->size = obj->base.size;
690 err->name = obj->base.name;
691 err->seqno = obj->last_rendering_seqno;
692 err->gtt_offset = obj->gtt_offset;
693 err->read_domains = obj->base.read_domains;
694 err->write_domain = obj->base.write_domain;
695 err->fence_reg = obj->fence_reg;
696 err->pinned = 0;
697 if (obj->pin_count > 0)
698 err->pinned = 1;
699 if (obj->user_pin_count > 0)
700 err->pinned = -1;
701 err->tiling = obj->tiling_mode;
702 err->dirty = obj->dirty;
703 err->purgeable = obj->madv != I915_MADV_WILLNEED;
Chris Wilson36850922010-11-23 08:49:38 +0000704 err->ring = obj->ring ? obj->ring->id : 0;
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000705
706 if (++i == count)
707 break;
708
709 err++;
710 }
711
712 return i;
713}
714
Chris Wilson748ebc62010-10-24 10:28:47 +0100715static void i915_gem_record_fences(struct drm_device *dev,
716 struct drm_i915_error_state *error)
717{
718 struct drm_i915_private *dev_priv = dev->dev_private;
719 int i;
720
721 /* Fences */
722 switch (INTEL_INFO(dev)->gen) {
723 case 6:
724 for (i = 0; i < 16; i++)
725 error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
726 break;
727 case 5:
728 case 4:
729 for (i = 0; i < 16; i++)
730 error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
731 break;
732 case 3:
733 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
734 for (i = 0; i < 8; i++)
735 error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
736 case 2:
737 for (i = 0; i < 8; i++)
738 error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
739 break;
740
741 }
742}
743
Jesse Barnes8a905232009-07-11 16:48:03 -0400744/**
745 * i915_capture_error_state - capture an error record for later analysis
746 * @dev: drm device
747 *
748 * Should be called when an error is detected (either a hang or an error
749 * interrupt) to capture error state from the time of the error. Fills
750 * out a structure which becomes available in debugfs for user level tools
751 * to pick up.
752 */
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700753static void i915_capture_error_state(struct drm_device *dev)
754{
755 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000756 struct drm_i915_gem_object *obj;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700757 struct drm_i915_error_state *error;
Chris Wilson05394f32010-11-08 19:18:58 +0000758 struct drm_i915_gem_object *batchbuffer[2];
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700759 unsigned long flags;
Chris Wilson9df30792010-02-18 10:24:56 +0000760 u32 bbaddr;
761 int count;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700762
763 spin_lock_irqsave(&dev_priv->error_lock, flags);
Chris Wilson9df30792010-02-18 10:24:56 +0000764 error = dev_priv->first_error;
765 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
766 if (error)
767 return;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700768
769 error = kmalloc(sizeof(*error), GFP_ATOMIC);
770 if (!error) {
Chris Wilson9df30792010-02-18 10:24:56 +0000771 DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
772 return;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700773 }
774
Chris Wilson2fa772f2010-10-01 13:23:27 +0100775 DRM_DEBUG_DRIVER("generating error event\n");
776
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000777 error->seqno = dev_priv->ring[RCS].get_seqno(&dev_priv->ring[RCS]);
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700778 error->eir = I915_READ(EIR);
779 error->pgtbl_er = I915_READ(PGTBL_ER);
780 error->pipeastat = I915_READ(PIPEASTAT);
781 error->pipebstat = I915_READ(PIPEBSTAT);
782 error->instpm = I915_READ(INSTPM);
Chris Wilsonf4068392010-10-27 20:36:41 +0100783 error->error = 0;
784 if (INTEL_INFO(dev)->gen >= 6) {
785 error->error = I915_READ(ERROR_GEN6);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100786
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100787 error->bcs_acthd = I915_READ(BCS_ACTHD);
788 error->bcs_ipehr = I915_READ(BCS_IPEHR);
789 error->bcs_ipeir = I915_READ(BCS_IPEIR);
790 error->bcs_instdone = I915_READ(BCS_INSTDONE);
791 error->bcs_seqno = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000792 if (dev_priv->ring[BCS].get_seqno)
793 error->bcs_seqno = dev_priv->ring[BCS].get_seqno(&dev_priv->ring[BCS]);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100794
795 error->vcs_acthd = I915_READ(VCS_ACTHD);
796 error->vcs_ipehr = I915_READ(VCS_IPEHR);
797 error->vcs_ipeir = I915_READ(VCS_IPEIR);
798 error->vcs_instdone = I915_READ(VCS_INSTDONE);
799 error->vcs_seqno = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000800 if (dev_priv->ring[VCS].get_seqno)
801 error->vcs_seqno = dev_priv->ring[VCS].get_seqno(&dev_priv->ring[VCS]);
Chris Wilsonf4068392010-10-27 20:36:41 +0100802 }
803 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700804 error->ipeir = I915_READ(IPEIR_I965);
805 error->ipehr = I915_READ(IPEHR_I965);
806 error->instdone = I915_READ(INSTDONE_I965);
807 error->instps = I915_READ(INSTPS);
808 error->instdone1 = I915_READ(INSTDONE1);
809 error->acthd = I915_READ(ACTHD_I965);
Chris Wilson9df30792010-02-18 10:24:56 +0000810 error->bbaddr = I915_READ64(BB_ADDR);
Chris Wilsonf4068392010-10-27 20:36:41 +0100811 } else {
812 error->ipeir = I915_READ(IPEIR);
813 error->ipehr = I915_READ(IPEHR);
814 error->instdone = I915_READ(INSTDONE);
815 error->acthd = I915_READ(ACTHD);
816 error->bbaddr = 0;
Chris Wilson9df30792010-02-18 10:24:56 +0000817 }
Chris Wilson748ebc62010-10-24 10:28:47 +0100818 i915_gem_record_fences(dev, error);
Chris Wilson9df30792010-02-18 10:24:56 +0000819
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000820 bbaddr = i915_ringbuffer_last_batch(dev, &dev_priv->ring[RCS]);
Chris Wilson9df30792010-02-18 10:24:56 +0000821
822 /* Grab the current batchbuffer, most likely to have crashed. */
823 batchbuffer[0] = NULL;
824 batchbuffer[1] = NULL;
825 count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000826 list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
Chris Wilson9df30792010-02-18 10:24:56 +0000827 if (batchbuffer[0] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000828 bbaddr >= obj->gtt_offset &&
829 bbaddr < obj->gtt_offset + obj->base.size)
Chris Wilson9df30792010-02-18 10:24:56 +0000830 batchbuffer[0] = obj;
831
832 if (batchbuffer[1] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000833 error->acthd >= obj->gtt_offset &&
834 error->acthd < obj->gtt_offset + obj->base.size)
Chris Wilson9df30792010-02-18 10:24:56 +0000835 batchbuffer[1] = obj;
836
837 count++;
838 }
Chris Wilsone56660d2010-08-07 11:01:26 +0100839 /* Scan the other lists for completeness for those bizarre errors. */
840 if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) {
Chris Wilson05394f32010-11-08 19:18:58 +0000841 list_for_each_entry(obj, &dev_priv->mm.flushing_list, mm_list) {
Chris Wilsone56660d2010-08-07 11:01:26 +0100842 if (batchbuffer[0] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000843 bbaddr >= obj->gtt_offset &&
844 bbaddr < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100845 batchbuffer[0] = obj;
846
847 if (batchbuffer[1] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000848 error->acthd >= obj->gtt_offset &&
849 error->acthd < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100850 batchbuffer[1] = obj;
851
852 if (batchbuffer[0] && batchbuffer[1])
853 break;
854 }
855 }
856 if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) {
Chris Wilson05394f32010-11-08 19:18:58 +0000857 list_for_each_entry(obj, &dev_priv->mm.inactive_list, mm_list) {
Chris Wilsone56660d2010-08-07 11:01:26 +0100858 if (batchbuffer[0] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000859 bbaddr >= obj->gtt_offset &&
860 bbaddr < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100861 batchbuffer[0] = obj;
862
863 if (batchbuffer[1] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000864 error->acthd >= obj->gtt_offset &&
865 error->acthd < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100866 batchbuffer[1] = obj;
867
868 if (batchbuffer[0] && batchbuffer[1])
869 break;
870 }
871 }
Chris Wilson9df30792010-02-18 10:24:56 +0000872
873 /* We need to copy these to an anonymous buffer as the simplest
Andrea Gelmini139d3632010-10-15 17:14:33 +0200874 * method to avoid being overwritten by userspace.
Chris Wilson9df30792010-02-18 10:24:56 +0000875 */
876 error->batchbuffer[0] = i915_error_object_create(dev, batchbuffer[0]);
Chris Wilsone56660d2010-08-07 11:01:26 +0100877 if (batchbuffer[1] != batchbuffer[0])
878 error->batchbuffer[1] = i915_error_object_create(dev, batchbuffer[1]);
879 else
880 error->batchbuffer[1] = NULL;
Chris Wilson9df30792010-02-18 10:24:56 +0000881
882 /* Record the ringbuffer */
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800883 error->ringbuffer = i915_error_object_create(dev,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000884 dev_priv->ring[RCS].obj);
Chris Wilson9df30792010-02-18 10:24:56 +0000885
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000886 /* Record buffers on the active and pinned lists. */
Chris Wilson9df30792010-02-18 10:24:56 +0000887 error->active_bo = NULL;
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000888 error->pinned_bo = NULL;
Chris Wilson9df30792010-02-18 10:24:56 +0000889
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000890 error->active_bo_count = count;
Chris Wilson05394f32010-11-08 19:18:58 +0000891 list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list)
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000892 count++;
893 error->pinned_bo_count = count - error->active_bo_count;
894
895 if (count) {
Chris Wilson9df30792010-02-18 10:24:56 +0000896 error->active_bo = kmalloc(sizeof(*error->active_bo)*count,
897 GFP_ATOMIC);
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000898 if (error->active_bo)
899 error->pinned_bo =
900 error->active_bo + error->active_bo_count;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700901 }
902
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000903 if (error->active_bo)
904 error->active_bo_count =
905 capture_bo_list(error->active_bo,
906 error->active_bo_count,
907 &dev_priv->mm.active_list);
908
909 if (error->pinned_bo)
910 error->pinned_bo_count =
911 capture_bo_list(error->pinned_bo,
912 error->pinned_bo_count,
913 &dev_priv->mm.pinned_list);
914
Jesse Barnes8a905232009-07-11 16:48:03 -0400915 do_gettimeofday(&error->time);
916
Chris Wilson6ef3d422010-08-04 20:26:07 +0100917 error->overlay = intel_overlay_capture_error_state(dev);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000918 error->display = intel_display_capture_error_state(dev);
Chris Wilson6ef3d422010-08-04 20:26:07 +0100919
Chris Wilson9df30792010-02-18 10:24:56 +0000920 spin_lock_irqsave(&dev_priv->error_lock, flags);
921 if (dev_priv->first_error == NULL) {
922 dev_priv->first_error = error;
923 error = NULL;
924 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700925 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
Chris Wilson9df30792010-02-18 10:24:56 +0000926
927 if (error)
928 i915_error_state_free(dev, error);
929}
930
931void i915_destroy_error_state(struct drm_device *dev)
932{
933 struct drm_i915_private *dev_priv = dev->dev_private;
934 struct drm_i915_error_state *error;
935
936 spin_lock(&dev_priv->error_lock);
937 error = dev_priv->first_error;
938 dev_priv->first_error = NULL;
939 spin_unlock(&dev_priv->error_lock);
940
941 if (error)
942 i915_error_state_free(dev, error);
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700943}
Chris Wilson3bd3c932010-08-19 08:19:30 +0100944#else
945#define i915_capture_error_state(x)
946#endif
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700947
Chris Wilson35aed2e2010-05-27 13:18:12 +0100948static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -0400949{
950 struct drm_i915_private *dev_priv = dev->dev_private;
951 u32 eir = I915_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -0400952
Chris Wilson35aed2e2010-05-27 13:18:12 +0100953 if (!eir)
954 return;
Jesse Barnes8a905232009-07-11 16:48:03 -0400955
956 printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
957 eir);
958
959 if (IS_G4X(dev)) {
960 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
961 u32 ipeir = I915_READ(IPEIR_I965);
962
963 printk(KERN_ERR " IPEIR: 0x%08x\n",
964 I915_READ(IPEIR_I965));
965 printk(KERN_ERR " IPEHR: 0x%08x\n",
966 I915_READ(IPEHR_I965));
967 printk(KERN_ERR " INSTDONE: 0x%08x\n",
968 I915_READ(INSTDONE_I965));
969 printk(KERN_ERR " INSTPS: 0x%08x\n",
970 I915_READ(INSTPS));
971 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
972 I915_READ(INSTDONE1));
973 printk(KERN_ERR " ACTHD: 0x%08x\n",
974 I915_READ(ACTHD_I965));
975 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000976 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -0400977 }
978 if (eir & GM45_ERROR_PAGE_TABLE) {
979 u32 pgtbl_err = I915_READ(PGTBL_ER);
980 printk(KERN_ERR "page table error\n");
981 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
982 pgtbl_err);
983 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000984 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -0400985 }
986 }
987
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100988 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -0400989 if (eir & I915_ERROR_PAGE_TABLE) {
990 u32 pgtbl_err = I915_READ(PGTBL_ER);
991 printk(KERN_ERR "page table error\n");
992 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
993 pgtbl_err);
994 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000995 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -0400996 }
997 }
998
999 if (eir & I915_ERROR_MEMORY_REFRESH) {
Chris Wilson35aed2e2010-05-27 13:18:12 +01001000 u32 pipea_stats = I915_READ(PIPEASTAT);
1001 u32 pipeb_stats = I915_READ(PIPEBSTAT);
1002
Jesse Barnes8a905232009-07-11 16:48:03 -04001003 printk(KERN_ERR "memory refresh error\n");
1004 printk(KERN_ERR "PIPEASTAT: 0x%08x\n",
1005 pipea_stats);
1006 printk(KERN_ERR "PIPEBSTAT: 0x%08x\n",
1007 pipeb_stats);
1008 /* pipestat has already been acked */
1009 }
1010 if (eir & I915_ERROR_INSTRUCTION) {
1011 printk(KERN_ERR "instruction error\n");
1012 printk(KERN_ERR " INSTPM: 0x%08x\n",
1013 I915_READ(INSTPM));
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001014 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001015 u32 ipeir = I915_READ(IPEIR);
1016
1017 printk(KERN_ERR " IPEIR: 0x%08x\n",
1018 I915_READ(IPEIR));
1019 printk(KERN_ERR " IPEHR: 0x%08x\n",
1020 I915_READ(IPEHR));
1021 printk(KERN_ERR " INSTDONE: 0x%08x\n",
1022 I915_READ(INSTDONE));
1023 printk(KERN_ERR " ACTHD: 0x%08x\n",
1024 I915_READ(ACTHD));
1025 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001026 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001027 } else {
1028 u32 ipeir = I915_READ(IPEIR_I965);
1029
1030 printk(KERN_ERR " IPEIR: 0x%08x\n",
1031 I915_READ(IPEIR_I965));
1032 printk(KERN_ERR " IPEHR: 0x%08x\n",
1033 I915_READ(IPEHR_I965));
1034 printk(KERN_ERR " INSTDONE: 0x%08x\n",
1035 I915_READ(INSTDONE_I965));
1036 printk(KERN_ERR " INSTPS: 0x%08x\n",
1037 I915_READ(INSTPS));
1038 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
1039 I915_READ(INSTDONE1));
1040 printk(KERN_ERR " ACTHD: 0x%08x\n",
1041 I915_READ(ACTHD_I965));
1042 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001043 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001044 }
1045 }
1046
1047 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001048 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001049 eir = I915_READ(EIR);
1050 if (eir) {
1051 /*
1052 * some errors might have become stuck,
1053 * mask them.
1054 */
1055 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1056 I915_WRITE(EMR, I915_READ(EMR) | eir);
1057 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1058 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01001059}
1060
1061/**
1062 * i915_handle_error - handle an error interrupt
1063 * @dev: drm device
1064 *
1065 * Do some basic checking of regsiter state at error interrupt time and
1066 * dump it to the syslog. Also call i915_capture_error_state() to make
1067 * sure we get a record and make it available in debugfs. Fire a uevent
1068 * so userspace knows something bad happened (should trigger collection
1069 * of a ring dump etc.).
1070 */
Chris Wilson527f9e92010-11-11 01:16:58 +00001071void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01001072{
1073 struct drm_i915_private *dev_priv = dev->dev_private;
1074
1075 i915_capture_error_state(dev);
1076 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04001077
Ben Gamariba1234d2009-09-14 17:48:47 -04001078 if (wedged) {
Chris Wilson30dbf0c2010-09-25 10:19:17 +01001079 INIT_COMPLETION(dev_priv->error_completion);
Ben Gamariba1234d2009-09-14 17:48:47 -04001080 atomic_set(&dev_priv->mm.wedged, 1);
1081
Ben Gamari11ed50e2009-09-14 17:48:45 -04001082 /*
1083 * Wakeup waiting processes so they don't hang
1084 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001085 wake_up_all(&dev_priv->ring[RCS].irq_queue);
Chris Wilsonf787a5f2010-09-24 16:02:42 +01001086 if (HAS_BSD(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001087 wake_up_all(&dev_priv->ring[VCS].irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +01001088 if (HAS_BLT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001089 wake_up_all(&dev_priv->ring[BCS].irq_queue);
Ben Gamari11ed50e2009-09-14 17:48:45 -04001090 }
1091
Eric Anholt9c9fe1f2009-08-03 16:09:16 -07001092 queue_work(dev_priv->wq, &dev_priv->error_work);
Jesse Barnes8a905232009-07-11 16:48:03 -04001093}
1094
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001095static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
1096{
1097 drm_i915_private_t *dev_priv = dev->dev_private;
1098 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1099 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00001100 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001101 struct intel_unpin_work *work;
1102 unsigned long flags;
1103 bool stall_detected;
1104
1105 /* Ignore early vblank irqs */
1106 if (intel_crtc == NULL)
1107 return;
1108
1109 spin_lock_irqsave(&dev->event_lock, flags);
1110 work = intel_crtc->unpin_work;
1111
1112 if (work == NULL || work->pending || !work->enable_stall_check) {
1113 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1114 spin_unlock_irqrestore(&dev->event_lock, flags);
1115 return;
1116 }
1117
1118 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00001119 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001120 if (INTEL_INFO(dev)->gen >= 4) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001121 int dspsurf = intel_crtc->plane == 0 ? DSPASURF : DSPBSURF;
Chris Wilson05394f32010-11-08 19:18:58 +00001122 stall_detected = I915_READ(dspsurf) == obj->gtt_offset;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001123 } else {
1124 int dspaddr = intel_crtc->plane == 0 ? DSPAADDR : DSPBADDR;
Chris Wilson05394f32010-11-08 19:18:58 +00001125 stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001126 crtc->y * crtc->fb->pitch +
1127 crtc->x * crtc->fb->bits_per_pixel/8);
1128 }
1129
1130 spin_unlock_irqrestore(&dev->event_lock, flags);
1131
1132 if (stall_detected) {
1133 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1134 intel_prepare_page_flip(dev, intel_crtc->plane);
1135 }
1136}
1137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
1139{
Dave Airlie84b1fd12007-07-11 15:53:27 +10001140 struct drm_device *dev = (struct drm_device *) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001142 struct drm_i915_master_private *master_priv;
Eric Anholtcdfbc412008-11-04 15:50:30 -08001143 u32 iir, new_iir;
1144 u32 pipea_stats, pipeb_stats;
Keith Packard05eff842008-11-19 14:03:05 -08001145 u32 vblank_status;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001146 int vblank = 0;
Keith Packard7c463582008-11-04 02:03:27 -08001147 unsigned long irqflags;
Keith Packard05eff842008-11-19 14:03:05 -08001148 int irq_received;
1149 int ret = IRQ_NONE;
Dave Airlieaf6061a2008-05-07 12:15:39 +10001150
Eric Anholt630681d2008-10-06 15:14:12 -07001151 atomic_inc(&dev_priv->irq_received);
1152
Eric Anholtbad720f2009-10-22 16:11:14 -07001153 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001154 return ironlake_irq_handler(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001155
Eric Anholted4cb412008-07-29 12:10:39 -07001156 iir = I915_READ(IIR);
Dave Airlieaf6061a2008-05-07 12:15:39 +10001157
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001158 if (INTEL_INFO(dev)->gen >= 4)
Jesse Barnesd874bcf2010-06-30 13:16:00 -07001159 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS;
Jesse Barnese25e6602010-06-30 13:15:19 -07001160 else
Jesse Barnesd874bcf2010-06-30 13:16:00 -07001161 vblank_status = PIPE_VBLANK_INTERRUPT_STATUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
Keith Packard05eff842008-11-19 14:03:05 -08001163 for (;;) {
1164 irq_received = iir != 0;
1165
1166 /* Can't rely on pipestat interrupt bit in iir as it might
1167 * have been cleared after the pipestat interrupt was received.
1168 * It doesn't set the bit in iir again, but it still produces
1169 * interrupts (for non-MSI).
1170 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001171 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Keith Packard05eff842008-11-19 14:03:05 -08001172 pipea_stats = I915_READ(PIPEASTAT);
1173 pipeb_stats = I915_READ(PIPEBSTAT);
Jesse Barnes79e53942008-11-07 14:24:08 -08001174
Jesse Barnes8a905232009-07-11 16:48:03 -04001175 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Ben Gamariba1234d2009-09-14 17:48:47 -04001176 i915_handle_error(dev, false);
Jesse Barnes8a905232009-07-11 16:48:03 -04001177
Eric Anholtcdfbc412008-11-04 15:50:30 -08001178 /*
1179 * Clear the PIPE(A|B)STAT regs before the IIR
1180 */
Keith Packard05eff842008-11-19 14:03:05 -08001181 if (pipea_stats & 0x8000ffff) {
Shaohua Li7662c8b2009-06-26 11:23:55 +08001182 if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS)
Zhao Yakui44d98a62009-10-09 11:39:40 +08001183 DRM_DEBUG_DRIVER("pipe a underrun\n");
Eric Anholtcdfbc412008-11-04 15:50:30 -08001184 I915_WRITE(PIPEASTAT, pipea_stats);
Keith Packard05eff842008-11-19 14:03:05 -08001185 irq_received = 1;
Eric Anholtcdfbc412008-11-04 15:50:30 -08001186 }
Keith Packard7c463582008-11-04 02:03:27 -08001187
Keith Packard05eff842008-11-19 14:03:05 -08001188 if (pipeb_stats & 0x8000ffff) {
Shaohua Li7662c8b2009-06-26 11:23:55 +08001189 if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS)
Zhao Yakui44d98a62009-10-09 11:39:40 +08001190 DRM_DEBUG_DRIVER("pipe b underrun\n");
Eric Anholtcdfbc412008-11-04 15:50:30 -08001191 I915_WRITE(PIPEBSTAT, pipeb_stats);
Keith Packard05eff842008-11-19 14:03:05 -08001192 irq_received = 1;
Eric Anholtcdfbc412008-11-04 15:50:30 -08001193 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001194 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Keith Packard05eff842008-11-19 14:03:05 -08001195
1196 if (!irq_received)
1197 break;
1198
1199 ret = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Jesse Barnes5ca58282009-03-31 14:11:15 -07001201 /* Consume port. Then clear IIR or we'll miss events */
1202 if ((I915_HAS_HOTPLUG(dev)) &&
1203 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
1204 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1205
Zhao Yakui44d98a62009-10-09 11:39:40 +08001206 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
Jesse Barnes5ca58282009-03-31 14:11:15 -07001207 hotplug_status);
1208 if (hotplug_status & dev_priv->hotplug_supported_mask)
Eric Anholt9c9fe1f2009-08-03 16:09:16 -07001209 queue_work(dev_priv->wq,
1210 &dev_priv->hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001211
1212 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1213 I915_READ(PORT_HOTPLUG_STAT);
1214 }
1215
Eric Anholtcdfbc412008-11-04 15:50:30 -08001216 I915_WRITE(IIR, iir);
1217 new_iir = I915_READ(IIR); /* Flush posted writes */
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001218
Dave Airlie7c1c2872008-11-28 14:22:24 +10001219 if (dev->primary->master) {
1220 master_priv = dev->primary->master->driver_priv;
1221 if (master_priv->sarea_priv)
1222 master_priv->sarea_priv->last_dispatch =
1223 READ_BREADCRUMB(dev_priv);
1224 }
Keith Packard7c463582008-11-04 02:03:27 -08001225
Chris Wilson549f7362010-10-19 11:19:32 +01001226 if (iir & I915_USER_INTERRUPT)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001227 notify_ring(dev, &dev_priv->ring[RCS]);
1228 if (iir & I915_BSD_USER_INTERRUPT)
1229 notify_ring(dev, &dev_priv->ring[VCS]);
Zou Nan haid1b851f2010-05-21 09:08:57 +08001230
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001231 if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05001232 intel_prepare_page_flip(dev, 0);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001233 if (dev_priv->flip_pending_is_done)
1234 intel_finish_page_flip_plane(dev, 0);
1235 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05001236
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001237 if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
Jesse Barnes70565d02010-07-01 04:45:43 -07001238 intel_prepare_page_flip(dev, 1);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001239 if (dev_priv->flip_pending_is_done)
1240 intel_finish_page_flip_plane(dev, 1);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001241 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05001242
Keith Packard05eff842008-11-19 14:03:05 -08001243 if (pipea_stats & vblank_status) {
Eric Anholtcdfbc412008-11-04 15:50:30 -08001244 vblank++;
1245 drm_handle_vblank(dev, 0);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001246 if (!dev_priv->flip_pending_is_done) {
1247 i915_pageflip_stall_check(dev, 0);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001248 intel_finish_page_flip(dev, 0);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001249 }
Eric Anholtcdfbc412008-11-04 15:50:30 -08001250 }
Eric Anholt673a3942008-07-30 12:06:12 -07001251
Keith Packard05eff842008-11-19 14:03:05 -08001252 if (pipeb_stats & vblank_status) {
Eric Anholtcdfbc412008-11-04 15:50:30 -08001253 vblank++;
1254 drm_handle_vblank(dev, 1);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001255 if (!dev_priv->flip_pending_is_done) {
1256 i915_pageflip_stall_check(dev, 1);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001257 intel_finish_page_flip(dev, 1);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001258 }
Eric Anholtcdfbc412008-11-04 15:50:30 -08001259 }
Keith Packard7c463582008-11-04 02:03:27 -08001260
Jesse Barnesd874bcf2010-06-30 13:16:00 -07001261 if ((pipea_stats & PIPE_LEGACY_BLC_EVENT_STATUS) ||
1262 (pipeb_stats & PIPE_LEGACY_BLC_EVENT_STATUS) ||
Eric Anholtcdfbc412008-11-04 15:50:30 -08001263 (iir & I915_ASLE_INTERRUPT))
Chris Wilson3b617962010-08-24 09:02:58 +01001264 intel_opregion_asle_intr(dev);
Keith Packard7c463582008-11-04 02:03:27 -08001265
Eric Anholtcdfbc412008-11-04 15:50:30 -08001266 /* With MSI, interrupts are only generated when iir
1267 * transitions from zero to nonzero. If another bit got
1268 * set while we were handling the existing iir bits, then
1269 * we would never get another interrupt.
1270 *
1271 * This is fine on non-MSI as well, as if we hit this path
1272 * we avoid exiting the interrupt handler only to generate
1273 * another one.
1274 *
1275 * Note that for MSI this could cause a stray interrupt report
1276 * if an interrupt landed in the time between writing IIR and
1277 * the posting read. This should be rare enough to never
1278 * trigger the 99% of 100,000 interrupts test for disabling
1279 * stray interrupts.
1280 */
1281 iir = new_iir;
Keith Packard05eff842008-11-19 14:03:05 -08001282 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001283
Keith Packard05eff842008-11-19 14:03:05 -08001284 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285}
1286
Dave Airlieaf6061a2008-05-07 12:15:39 +10001287static int i915_emit_irq(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288{
1289 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001290 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292 i915_kernel_lost_context(dev);
1293
Zhao Yakui44d98a62009-10-09 11:39:40 +08001294 DRM_DEBUG_DRIVER("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Kristian Høgsbergc99b0582008-08-20 11:20:13 -04001296 dev_priv->counter++;
Alan Hourihanec29b6692006-08-12 16:29:24 +10001297 if (dev_priv->counter > 0x7FFFFFFFUL)
Kristian Høgsbergc99b0582008-08-20 11:20:13 -04001298 dev_priv->counter = 1;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001299 if (master_priv->sarea_priv)
1300 master_priv->sarea_priv->last_enqueue = dev_priv->counter;
Alan Hourihanec29b6692006-08-12 16:29:24 +10001301
Chris Wilsone1f99ce2010-10-27 12:45:26 +01001302 if (BEGIN_LP_RING(4) == 0) {
1303 OUT_RING(MI_STORE_DWORD_INDEX);
1304 OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
1305 OUT_RING(dev_priv->counter);
1306 OUT_RING(MI_USER_INTERRUPT);
1307 ADVANCE_LP_RING();
1308 }
Dave Airliebc5f4522007-11-05 12:50:58 +10001309
Alan Hourihanec29b6692006-08-12 16:29:24 +10001310 return dev_priv->counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311}
1312
Chris Wilson9d34e5d2009-09-24 05:26:06 +01001313void i915_trace_irq_get(struct drm_device *dev, u32 seqno)
1314{
1315 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001316 struct intel_ring_buffer *ring = LP_RING(dev_priv);
Chris Wilson9d34e5d2009-09-24 05:26:06 +01001317
Chris Wilsonb13c2b92010-12-13 16:54:50 +00001318 if (dev_priv->trace_irq_seqno == 0 &&
1319 ring->irq_get(ring))
1320 dev_priv->trace_irq_seqno = seqno;
Chris Wilson9d34e5d2009-09-24 05:26:06 +01001321}
1322
Dave Airlie84b1fd12007-07-11 15:53:27 +10001323static int i915_wait_irq(struct drm_device * dev, int irq_nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
1325 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001326 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 int ret = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001328 struct intel_ring_buffer *ring = LP_RING(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
Zhao Yakui44d98a62009-10-09 11:39:40 +08001330 DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 READ_BREADCRUMB(dev_priv));
1332
Eric Anholted4cb412008-07-29 12:10:39 -07001333 if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
Dave Airlie7c1c2872008-11-28 14:22:24 +10001334 if (master_priv->sarea_priv)
1335 master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 return 0;
Eric Anholted4cb412008-07-29 12:10:39 -07001337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Dave Airlie7c1c2872008-11-28 14:22:24 +10001339 if (master_priv->sarea_priv)
1340 master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
Chris Wilsonb13c2b92010-12-13 16:54:50 +00001342 ret = -ENODEV;
1343 if (ring->irq_get(ring)) {
1344 DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ,
1345 READ_BREADCRUMB(dev_priv) >= irq_nr);
1346 ring->irq_put(ring);
1347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
Eric Anholt20caafa2007-08-25 19:22:43 +10001349 if (ret == -EBUSY) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001350 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
1352 }
1353
Dave Airlieaf6061a2008-05-07 12:15:39 +10001354 return ret;
1355}
1356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357/* Needs the lock as it touches the ring.
1358 */
Eric Anholtc153f452007-09-03 12:06:45 +10001359int i915_irq_emit(struct drm_device *dev, void *data,
1360 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001363 drm_i915_irq_emit_t *emit = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 int result;
1365
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001366 if (!dev_priv || !LP_RING(dev_priv)->virtual_start) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001367 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001368 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 }
Eric Anholt299eb932009-02-24 22:14:12 -08001370
1371 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
1372
Eric Anholt546b0972008-09-01 16:45:29 -07001373 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 result = i915_emit_irq(dev);
Eric Anholt546b0972008-09-01 16:45:29 -07001375 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Eric Anholtc153f452007-09-03 12:06:45 +10001377 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 DRM_ERROR("copy_to_user\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001379 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 }
1381
1382 return 0;
1383}
1384
1385/* Doesn't need the hardware lock.
1386 */
Eric Anholtc153f452007-09-03 12:06:45 +10001387int i915_irq_wait(struct drm_device *dev, void *data,
1388 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001391 drm_i915_irq_wait_t *irqwait = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
1393 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001394 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001395 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
1397
Eric Anholtc153f452007-09-03 12:06:45 +10001398 return i915_wait_irq(dev, irqwait->irq_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399}
1400
Keith Packard42f52ef2008-10-18 19:39:29 -07001401/* Called from drm generic code, passed 'crtc' which
1402 * we use as a pipe index
1403 */
1404int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001405{
1406 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001407 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001408
Chris Wilson5eddb702010-09-11 13:48:45 +01001409 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001410 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001411
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001412 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Eric Anholtbad720f2009-10-22 16:11:14 -07001413 if (HAS_PCH_SPLIT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001414 ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
Li Pengc062df62010-01-23 00:12:58 +08001415 DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001416 else if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08001417 i915_enable_pipestat(dev_priv, pipe,
1418 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07001419 else
Keith Packard7c463582008-11-04 02:03:27 -08001420 i915_enable_pipestat(dev_priv, pipe,
1421 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001422 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001423 return 0;
1424}
1425
Keith Packard42f52ef2008-10-18 19:39:29 -07001426/* Called from drm generic code, passed 'crtc' which
1427 * we use as a pipe index
1428 */
1429void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001430{
1431 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001432 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001433
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001434 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Eric Anholtbad720f2009-10-22 16:11:14 -07001435 if (HAS_PCH_SPLIT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001436 ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
Li Pengc062df62010-01-23 00:12:58 +08001437 DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
1438 else
1439 i915_disable_pipestat(dev_priv, pipe,
1440 PIPE_VBLANK_INTERRUPT_ENABLE |
1441 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001442 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001443}
1444
Jesse Barnes79e53942008-11-07 14:24:08 -08001445void i915_enable_interrupt (struct drm_device *dev)
1446{
1447 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wange170b032009-06-05 15:38:40 +08001448
Eric Anholtbad720f2009-10-22 16:11:14 -07001449 if (!HAS_PCH_SPLIT(dev))
Chris Wilson3b617962010-08-24 09:02:58 +01001450 intel_opregion_enable_asle(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08001451 dev_priv->irq_enabled = 1;
1452}
1453
1454
Dave Airlie702880f2006-06-24 17:07:34 +10001455/* Set the vblank monitor pipe
1456 */
Eric Anholtc153f452007-09-03 12:06:45 +10001457int i915_vblank_pipe_set(struct drm_device *dev, void *data,
1458 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +10001459{
Dave Airlie702880f2006-06-24 17:07:34 +10001460 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airlie702880f2006-06-24 17:07:34 +10001461
1462 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001463 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001464 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +10001465 }
1466
=?utf-8?q?Michel_D=C3=A4nzer?=5b516942006-10-25 00:08:23 +10001467 return 0;
Dave Airlie702880f2006-06-24 17:07:34 +10001468}
1469
Eric Anholtc153f452007-09-03 12:06:45 +10001470int i915_vblank_pipe_get(struct drm_device *dev, void *data,
1471 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +10001472{
Dave Airlie702880f2006-06-24 17:07:34 +10001473 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001474 drm_i915_vblank_pipe_t *pipe = data;
Dave Airlie702880f2006-06-24 17:07:34 +10001475
1476 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001477 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001478 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +10001479 }
1480
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001481 pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
Eric Anholtc153f452007-09-03 12:06:45 +10001482
Dave Airlie702880f2006-06-24 17:07:34 +10001483 return 0;
1484}
1485
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +10001486/**
1487 * Schedule buffer swap at given vertical blank.
1488 */
Eric Anholtc153f452007-09-03 12:06:45 +10001489int i915_vblank_swap(struct drm_device *dev, void *data,
1490 struct drm_file *file_priv)
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +10001491{
Eric Anholtbd95e0a2008-11-04 12:01:24 -08001492 /* The delayed swap mechanism was fundamentally racy, and has been
1493 * removed. The model was that the client requested a delayed flip/swap
1494 * from the kernel, then waited for vblank before continuing to perform
1495 * rendering. The problem was that the kernel might wake the client
1496 * up before it dispatched the vblank swap (since the lock has to be
1497 * held while touching the ringbuffer), in which case the client would
1498 * clear and start the next frame before the swap occurred, and
1499 * flicker would occur in addition to likely missing the vblank.
1500 *
1501 * In the absence of this ioctl, userland falls back to a correct path
1502 * of waiting for a vblank, then dispatching the swap on its own.
1503 * Context switching to userland and back is plenty fast enough for
1504 * meeting the requirements of vblank swapping.
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001505 */
Eric Anholtbd95e0a2008-11-04 12:01:24 -08001506 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +10001507}
1508
Chris Wilson893eead2010-10-27 14:44:35 +01001509static u32
1510ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08001511{
Chris Wilson893eead2010-10-27 14:44:35 +01001512 return list_entry(ring->request_list.prev,
1513 struct drm_i915_gem_request, list)->seqno;
1514}
1515
1516static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
1517{
1518 if (list_empty(&ring->request_list) ||
1519 i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) {
1520 /* Issue a wake-up to catch stuck h/w. */
Chris Wilsonb2223492010-10-27 15:27:33 +01001521 if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) {
Chris Wilson893eead2010-10-27 14:44:35 +01001522 DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n",
1523 ring->name,
Chris Wilsonb2223492010-10-27 15:27:33 +01001524 ring->waiting_seqno,
Chris Wilson893eead2010-10-27 14:44:35 +01001525 ring->get_seqno(ring));
1526 wake_up_all(&ring->irq_queue);
1527 *err = true;
1528 }
1529 return true;
1530 }
1531 return false;
Ben Gamarif65d9422009-09-14 17:48:44 -04001532}
1533
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001534static bool kick_ring(struct intel_ring_buffer *ring)
1535{
1536 struct drm_device *dev = ring->dev;
1537 struct drm_i915_private *dev_priv = dev->dev_private;
1538 u32 tmp = I915_READ_CTL(ring);
1539 if (tmp & RING_WAIT) {
1540 DRM_ERROR("Kicking stuck wait on %s\n",
1541 ring->name);
1542 I915_WRITE_CTL(ring, tmp);
1543 return true;
1544 }
1545 if (IS_GEN6(dev) &&
1546 (tmp & RING_WAIT_SEMAPHORE)) {
1547 DRM_ERROR("Kicking stuck semaphore on %s\n",
1548 ring->name);
1549 I915_WRITE_CTL(ring, tmp);
1550 return true;
1551 }
1552 return false;
1553}
1554
Ben Gamarif65d9422009-09-14 17:48:44 -04001555/**
1556 * This is called when the chip hasn't reported back with completed
1557 * batchbuffers in a long time. The first time this is called we simply record
1558 * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
1559 * again, we assume the chip is wedged and try to fix it.
1560 */
1561void i915_hangcheck_elapsed(unsigned long data)
1562{
1563 struct drm_device *dev = (struct drm_device *)data;
1564 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001565 uint32_t acthd, instdone, instdone1;
Chris Wilson893eead2010-10-27 14:44:35 +01001566 bool err = false;
1567
1568 /* If all work is done then ACTHD clearly hasn't advanced. */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001569 if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) &&
1570 i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) &&
1571 i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) {
Chris Wilson893eead2010-10-27 14:44:35 +01001572 dev_priv->hangcheck_count = 0;
1573 if (err)
1574 goto repeat;
1575 return;
1576 }
Eric Anholtb9201c12010-01-08 14:25:16 -08001577
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001578 if (INTEL_INFO(dev)->gen < 4) {
Ben Gamarif65d9422009-09-14 17:48:44 -04001579 acthd = I915_READ(ACTHD);
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001580 instdone = I915_READ(INSTDONE);
1581 instdone1 = 0;
1582 } else {
Ben Gamarif65d9422009-09-14 17:48:44 -04001583 acthd = I915_READ(ACTHD_I965);
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001584 instdone = I915_READ(INSTDONE_I965);
1585 instdone1 = I915_READ(INSTDONE1);
1586 }
Ben Gamarif65d9422009-09-14 17:48:44 -04001587
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001588 if (dev_priv->last_acthd == acthd &&
1589 dev_priv->last_instdone == instdone &&
1590 dev_priv->last_instdone1 == instdone1) {
1591 if (dev_priv->hangcheck_count++ > 1) {
1592 DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
Chris Wilson8c80b592010-08-08 20:38:12 +01001593
1594 if (!IS_GEN2(dev)) {
1595 /* Is the chip hanging on a WAIT_FOR_EVENT?
1596 * If so we can simply poke the RB_WAIT bit
1597 * and break the hang. This should work on
1598 * all but the second generation chipsets.
1599 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001600
1601 if (kick_ring(&dev_priv->ring[RCS]))
Chris Wilson893eead2010-10-27 14:44:35 +01001602 goto repeat;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001603
1604 if (HAS_BSD(dev) &&
1605 kick_ring(&dev_priv->ring[VCS]))
1606 goto repeat;
1607
1608 if (HAS_BLT(dev) &&
1609 kick_ring(&dev_priv->ring[BCS]))
1610 goto repeat;
Chris Wilson8c80b592010-08-08 20:38:12 +01001611 }
1612
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001613 i915_handle_error(dev, true);
1614 return;
1615 }
1616 } else {
1617 dev_priv->hangcheck_count = 0;
1618
1619 dev_priv->last_acthd = acthd;
1620 dev_priv->last_instdone = instdone;
1621 dev_priv->last_instdone1 = instdone1;
1622 }
Ben Gamarif65d9422009-09-14 17:48:44 -04001623
Chris Wilson893eead2010-10-27 14:44:35 +01001624repeat:
Ben Gamarif65d9422009-09-14 17:48:44 -04001625 /* Reset timer case chip hangs without another request being added */
Chris Wilsonb3b079d2010-09-13 23:44:34 +01001626 mod_timer(&dev_priv->hangcheck_timer,
1627 jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
Ben Gamarif65d9422009-09-14 17:48:44 -04001628}
1629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630/* drm_dma.h hooks
1631*/
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001632static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001633{
1634 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1635
1636 I915_WRITE(HWSTAM, 0xeffe);
1637
1638 /* XXX hotplug from PCH */
1639
1640 I915_WRITE(DEIMR, 0xffffffff);
1641 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001642 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001643
1644 /* and GT */
1645 I915_WRITE(GTIMR, 0xffffffff);
1646 I915_WRITE(GTIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001647 POSTING_READ(GTIER);
Zhenyu Wangc6501562009-11-03 18:57:21 +00001648
1649 /* south display irq */
1650 I915_WRITE(SDEIMR, 0xffffffff);
1651 I915_WRITE(SDEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001652 POSTING_READ(SDEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001653}
1654
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001655static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001656{
1657 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1658 /* enable kind of interrupts always enabled */
Jesse Barnes013d5aa2010-01-29 11:18:31 -08001659 u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
1660 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001661 u32 render_irqs;
Yuanhan Liu2d7b8362010-10-08 10:21:06 +01001662 u32 hotplug_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001663
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001664 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001665
1666 /* should always can generate irq */
1667 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001668 I915_WRITE(DEIMR, dev_priv->irq_mask);
1669 I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001670 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001671
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001672 dev_priv->gt_irq_mask = ~0;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001673
1674 I915_WRITE(GTIIR, I915_READ(GTIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001675 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001676 if (IS_GEN6(dev)) {
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001677 I915_WRITE(GEN6_RENDER_IMR, ~GEN6_RENDER_USER_INTERRUPT);
1678 I915_WRITE(GEN6_BSD_IMR, ~GEN6_BSD_USER_INTERRUPT);
Chris Wilson549f7362010-10-19 11:19:32 +01001679 I915_WRITE(GEN6_BLITTER_IMR, ~GEN6_BLITTER_USER_INTERRUPT);
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001680 }
1681
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001682 if (IS_GEN6(dev))
1683 render_irqs =
1684 GT_USER_INTERRUPT |
1685 GT_GEN6_BSD_USER_INTERRUPT |
1686 GT_BLT_USER_INTERRUPT;
1687 else
1688 render_irqs =
Chris Wilson88f23b82010-12-05 15:08:31 +00001689 GT_USER_INTERRUPT |
Chris Wilsonc6df5412010-12-15 09:56:50 +00001690 GT_PIPE_NOTIFY |
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001691 GT_BSD_USER_INTERRUPT;
1692 I915_WRITE(GTIER, render_irqs);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001693 POSTING_READ(GTIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001694
Yuanhan Liu2d7b8362010-10-08 10:21:06 +01001695 if (HAS_PCH_CPT(dev)) {
1696 hotplug_mask = SDE_CRT_HOTPLUG_CPT | SDE_PORTB_HOTPLUG_CPT |
1697 SDE_PORTC_HOTPLUG_CPT | SDE_PORTD_HOTPLUG_CPT ;
1698 } else {
1699 hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG |
1700 SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG;
1701 }
1702
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001703 dev_priv->pch_irq_mask = ~hotplug_mask;
Zhenyu Wangc6501562009-11-03 18:57:21 +00001704
1705 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001706 I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
1707 I915_WRITE(SDEIER, hotplug_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001708 POSTING_READ(SDEIER);
Zhenyu Wangc6501562009-11-03 18:57:21 +00001709
Jesse Barnesf97108d2010-01-29 11:27:07 -08001710 if (IS_IRONLAKE_M(dev)) {
1711 /* Clear & enable PCU event interrupts */
1712 I915_WRITE(DEIIR, DE_PCU_EVENT);
1713 I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT);
1714 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
1715 }
1716
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001717 return 0;
1718}
1719
Dave Airlie84b1fd12007-07-11 15:53:27 +10001720void i915_driver_irq_preinstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721{
1722 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1723
Jesse Barnes79e53942008-11-07 14:24:08 -08001724 atomic_set(&dev_priv->irq_received, 0);
1725
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001726 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Jesse Barnes8a905232009-07-11 16:48:03 -04001727 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001728
Eric Anholtbad720f2009-10-22 16:11:14 -07001729 if (HAS_PCH_SPLIT(dev)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001730 ironlake_irq_preinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001731 return;
1732 }
1733
Jesse Barnes5ca58282009-03-31 14:11:15 -07001734 if (I915_HAS_HOTPLUG(dev)) {
1735 I915_WRITE(PORT_HOTPLUG_EN, 0);
1736 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1737 }
1738
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001739 I915_WRITE(HWSTAM, 0xeffe);
Keith Packard7c463582008-11-04 02:03:27 -08001740 I915_WRITE(PIPEASTAT, 0);
1741 I915_WRITE(PIPEBSTAT, 0);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001742 I915_WRITE(IMR, 0xffffffff);
Eric Anholted4cb412008-07-29 12:10:39 -07001743 I915_WRITE(IER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001744 POSTING_READ(IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001747/*
1748 * Must be called after intel_modeset_init or hotplug interrupts won't be
1749 * enabled correctly.
1750 */
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001751int i915_driver_irq_postinstall(struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
1753 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001754 u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
Jesse Barnes63eeaf32009-06-18 16:56:52 -07001755 u32 error_mask;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001756
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001757 DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue);
Zou Nan haid1b851f2010-05-21 09:08:57 +08001758 if (HAS_BSD(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001759 DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +01001760 if (HAS_BLT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001761 DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue);
Zou Nan haid1b851f2010-05-21 09:08:57 +08001762
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001763 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001764
Eric Anholtbad720f2009-10-22 16:11:14 -07001765 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001766 return ironlake_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001767
Keith Packard7c463582008-11-04 02:03:27 -08001768 /* Unmask the interrupts that we always want on. */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001769 dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX;
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001770
Keith Packard7c463582008-11-04 02:03:27 -08001771 dev_priv->pipestat[0] = 0;
1772 dev_priv->pipestat[1] = 0;
1773
Jesse Barnes5ca58282009-03-31 14:11:15 -07001774 if (I915_HAS_HOTPLUG(dev)) {
Adam Jacksonc496fa12010-05-27 17:26:45 -04001775 /* Enable in IER... */
1776 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
1777 /* and unmask in IMR */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001778 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
Adam Jacksonc496fa12010-05-27 17:26:45 -04001779 }
1780
1781 /*
1782 * Enable some error detection, note the instruction error mask
1783 * bit is reserved, so we leave it masked.
1784 */
1785 if (IS_G4X(dev)) {
1786 error_mask = ~(GM45_ERROR_PAGE_TABLE |
1787 GM45_ERROR_MEM_PRIV |
1788 GM45_ERROR_CP_PRIV |
1789 I915_ERROR_MEMORY_REFRESH);
1790 } else {
1791 error_mask = ~(I915_ERROR_PAGE_TABLE |
1792 I915_ERROR_MEMORY_REFRESH);
1793 }
1794 I915_WRITE(EMR, error_mask);
1795
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001796 I915_WRITE(IMR, dev_priv->irq_mask);
Adam Jacksonc496fa12010-05-27 17:26:45 -04001797 I915_WRITE(IER, enable_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001798 POSTING_READ(IER);
Adam Jacksonc496fa12010-05-27 17:26:45 -04001799
1800 if (I915_HAS_HOTPLUG(dev)) {
Jesse Barnes5ca58282009-03-31 14:11:15 -07001801 u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
1802
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001803 /* Note HDMI and DP share bits */
1804 if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
1805 hotplug_en |= HDMIB_HOTPLUG_INT_EN;
1806 if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
1807 hotplug_en |= HDMIC_HOTPLUG_INT_EN;
1808 if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
1809 hotplug_en |= HDMID_HOTPLUG_INT_EN;
1810 if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS)
1811 hotplug_en |= SDVOC_HOTPLUG_INT_EN;
1812 if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS)
1813 hotplug_en |= SDVOB_HOTPLUG_INT_EN;
Andy Lutomirski2d1c9752010-06-12 05:21:18 -04001814 if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001815 hotplug_en |= CRT_HOTPLUG_INT_EN;
Andy Lutomirski2d1c9752010-06-12 05:21:18 -04001816
1817 /* Programming the CRT detection parameters tends
1818 to generate a spurious hotplug event about three
1819 seconds later. So just do it once.
1820 */
1821 if (IS_G4X(dev))
1822 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
1823 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
1824 }
1825
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001826 /* Ignore TV since it's buggy */
1827
Jesse Barnes5ca58282009-03-31 14:11:15 -07001828 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001829 }
1830
Chris Wilson3b617962010-08-24 09:02:58 +01001831 intel_opregion_enable_asle(dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001832
1833 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834}
1835
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001836static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001837{
1838 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1839 I915_WRITE(HWSTAM, 0xffffffff);
1840
1841 I915_WRITE(DEIMR, 0xffffffff);
1842 I915_WRITE(DEIER, 0x0);
1843 I915_WRITE(DEIIR, I915_READ(DEIIR));
1844
1845 I915_WRITE(GTIMR, 0xffffffff);
1846 I915_WRITE(GTIER, 0x0);
1847 I915_WRITE(GTIIR, I915_READ(GTIIR));
1848}
1849
Dave Airlie84b1fd12007-07-11 15:53:27 +10001850void i915_driver_irq_uninstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
1852 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie91e37382006-02-18 15:17:04 +11001853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 if (!dev_priv)
1855 return;
1856
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001857 dev_priv->vblank_pipe = 0;
1858
Eric Anholtbad720f2009-10-22 16:11:14 -07001859 if (HAS_PCH_SPLIT(dev)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001860 ironlake_irq_uninstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001861 return;
1862 }
1863
Jesse Barnes5ca58282009-03-31 14:11:15 -07001864 if (I915_HAS_HOTPLUG(dev)) {
1865 I915_WRITE(PORT_HOTPLUG_EN, 0);
1866 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1867 }
1868
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001869 I915_WRITE(HWSTAM, 0xffffffff);
Keith Packard7c463582008-11-04 02:03:27 -08001870 I915_WRITE(PIPEASTAT, 0);
1871 I915_WRITE(PIPEBSTAT, 0);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001872 I915_WRITE(IMR, 0xffffffff);
Eric Anholted4cb412008-07-29 12:10:39 -07001873 I915_WRITE(IER, 0x0);
Dave Airlie91e37382006-02-18 15:17:04 +11001874
Keith Packard7c463582008-11-04 02:03:27 -08001875 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
1876 I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
1877 I915_WRITE(IIR, I915_READ(IIR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878}