blob: 5e831b7eb3f1bd21d1270149d27a1e151c51da71 [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
Jesse Barnes5ca58282009-03-31 14:11:15 -0700251/*
252 * Handle hotplug events outside the interrupt handler proper.
253 */
254static void i915_hotplug_work_func(struct work_struct *work)
255{
256 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
257 hotplug_work);
258 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700259 struct drm_mode_config *mode_config = &dev->mode_config;
Chris Wilson4ef69c72010-09-09 15:14:28 +0100260 struct intel_encoder *encoder;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700261
Chris Wilson4ef69c72010-09-09 15:14:28 +0100262 list_for_each_entry(encoder, &mode_config->encoder_list, base.head)
263 if (encoder->hot_plug)
264 encoder->hot_plug(encoder);
265
Jesse Barnes5ca58282009-03-31 14:11:15 -0700266 /* Just fire off a uevent and let userspace tell us what to do */
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000267 drm_helper_hpd_irq_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700268}
269
Jesse Barnesf97108d2010-01-29 11:27:07 -0800270static void i915_handle_rps_change(struct drm_device *dev)
271{
272 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000273 u32 busy_up, busy_down, max_avg, min_avg;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800274 u8 new_delay = dev_priv->cur_delay;
275
Jesse Barnes7648fa92010-05-20 14:28:11 -0700276 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000277 busy_up = I915_READ(RCPREVBSYTUPAVG);
278 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800279 max_avg = I915_READ(RCBMAXAVG);
280 min_avg = I915_READ(RCBMINAVG);
281
282 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000283 if (busy_up > max_avg) {
Jesse Barnesf97108d2010-01-29 11:27:07 -0800284 if (dev_priv->cur_delay != dev_priv->max_delay)
285 new_delay = dev_priv->cur_delay - 1;
286 if (new_delay < dev_priv->max_delay)
287 new_delay = dev_priv->max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000288 } else if (busy_down < min_avg) {
Jesse Barnesf97108d2010-01-29 11:27:07 -0800289 if (dev_priv->cur_delay != dev_priv->min_delay)
290 new_delay = dev_priv->cur_delay + 1;
291 if (new_delay > dev_priv->min_delay)
292 new_delay = dev_priv->min_delay;
293 }
294
Jesse Barnes7648fa92010-05-20 14:28:11 -0700295 if (ironlake_set_drps(dev, new_delay))
296 dev_priv->cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800297
298 return;
299}
300
Chris Wilson549f7362010-10-19 11:19:32 +0100301static void notify_ring(struct drm_device *dev,
302 struct intel_ring_buffer *ring)
303{
304 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson78501ea2010-10-27 12:18:21 +0100305 u32 seqno = ring->get_seqno(ring);
Chris Wilsonb2223492010-10-27 15:27:33 +0100306 ring->irq_seqno = seqno;
Chris Wilson549f7362010-10-19 11:19:32 +0100307 trace_i915_gem_request_complete(dev, seqno);
308 wake_up_all(&ring->irq_queue);
309 dev_priv->hangcheck_count = 0;
310 mod_timer(&dev_priv->hangcheck_timer,
311 jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
312}
313
Chris Wilson995b6762010-08-20 13:23:26 +0100314static irqreturn_t ironlake_irq_handler(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800315{
316 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
317 int ret = IRQ_NONE;
Dave Airlie3ff99162009-12-08 14:03:47 +1000318 u32 de_iir, gt_iir, de_ier, pch_iir;
Yuanhan Liu2d7b8362010-10-08 10:21:06 +0100319 u32 hotplug_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800320 struct drm_i915_master_private *master_priv;
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100321 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
322
323 if (IS_GEN6(dev))
324 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800325
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000326 /* disable master interrupt before clearing iir */
327 de_ier = I915_READ(DEIER);
328 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000329 POSTING_READ(DEIER);
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000330
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800331 de_iir = I915_READ(DEIIR);
332 gt_iir = I915_READ(GTIIR);
Zhenyu Wangc6501562009-11-03 18:57:21 +0000333 pch_iir = I915_READ(SDEIIR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800334
Zou Nan haic7c85102010-01-15 10:29:06 +0800335 if (de_iir == 0 && gt_iir == 0 && pch_iir == 0)
336 goto done;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800337
Yuanhan Liu2d7b8362010-10-08 10:21:06 +0100338 if (HAS_PCH_CPT(dev))
339 hotplug_mask = SDE_HOTPLUG_MASK_CPT;
340 else
341 hotplug_mask = SDE_HOTPLUG_MASK;
342
Zou Nan haic7c85102010-01-15 10:29:06 +0800343 ret = IRQ_HANDLED;
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800344
Zou Nan haic7c85102010-01-15 10:29:06 +0800345 if (dev->primary->master) {
346 master_priv = dev->primary->master->driver_priv;
347 if (master_priv->sarea_priv)
348 master_priv->sarea_priv->last_dispatch =
349 READ_BREADCRUMB(dev_priv);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800350 }
351
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000352 if (gt_iir & (GT_USER_INTERRUPT | GT_PIPE_NOTIFY))
353 notify_ring(dev, &dev_priv->ring[RCS]);
Xiang, Haihao881f47b2010-09-19 14:40:43 +0100354 if (gt_iir & bsd_usr_interrupt)
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000355 notify_ring(dev, &dev_priv->ring[VCS]);
356 if (gt_iir & GT_BLT_USER_INTERRUPT)
357 notify_ring(dev, &dev_priv->ring[BCS]);
Zou Nan haic7c85102010-01-15 10:29:06 +0800358
359 if (de_iir & DE_GSE)
Chris Wilson3b617962010-08-24 09:02:58 +0100360 intel_opregion_gse_intr(dev);
Zou Nan haic7c85102010-01-15 10:29:06 +0800361
Zhenyu Wangf072d2e2010-02-09 09:46:19 +0800362 if (de_iir & DE_PLANEA_FLIP_DONE) {
Jesse Barnes013d5aa2010-01-29 11:18:31 -0800363 intel_prepare_page_flip(dev, 0);
Chris Wilson2bbda382010-09-02 17:59:39 +0100364 intel_finish_page_flip_plane(dev, 0);
Jesse Barnes013d5aa2010-01-29 11:18:31 -0800365 }
366
Zhenyu Wangf072d2e2010-02-09 09:46:19 +0800367 if (de_iir & DE_PLANEB_FLIP_DONE) {
368 intel_prepare_page_flip(dev, 1);
Chris Wilson2bbda382010-09-02 17:59:39 +0100369 intel_finish_page_flip_plane(dev, 1);
Jesse Barnes013d5aa2010-01-29 11:18:31 -0800370 }
Li Pengc062df62010-01-23 00:12:58 +0800371
Zhenyu Wangf072d2e2010-02-09 09:46:19 +0800372 if (de_iir & DE_PIPEA_VBLANK)
373 drm_handle_vblank(dev, 0);
374
375 if (de_iir & DE_PIPEB_VBLANK)
376 drm_handle_vblank(dev, 1);
377
Zou Nan haic7c85102010-01-15 10:29:06 +0800378 /* check event from PCH */
Yuanhan Liu2d7b8362010-10-08 10:21:06 +0100379 if ((de_iir & DE_PCH_EVENT) && (pch_iir & hotplug_mask))
Zou Nan haic7c85102010-01-15 10:29:06 +0800380 queue_work(dev_priv->wq, &dev_priv->hotplug_work);
Zou Nan haic7c85102010-01-15 10:29:06 +0800381
Jesse Barnesf97108d2010-01-29 11:27:07 -0800382 if (de_iir & DE_PCU_EVENT) {
Jesse Barnes7648fa92010-05-20 14:28:11 -0700383 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
Jesse Barnesf97108d2010-01-29 11:27:07 -0800384 i915_handle_rps_change(dev);
385 }
386
Zou Nan haic7c85102010-01-15 10:29:06 +0800387 /* should clear PCH hotplug event before clear CPU irq */
388 I915_WRITE(SDEIIR, pch_iir);
389 I915_WRITE(GTIIR, gt_iir);
390 I915_WRITE(DEIIR, de_iir);
391
392done:
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000393 I915_WRITE(DEIER, de_ier);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000394 POSTING_READ(DEIER);
Zou, Nanhai2d109a82009-11-06 02:13:01 +0000395
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800396 return ret;
397}
398
Jesse Barnes8a905232009-07-11 16:48:03 -0400399/**
400 * i915_error_work_func - do process context error handling work
401 * @work: work struct
402 *
403 * Fire an error uevent so userspace can see that a hang or error
404 * was detected.
405 */
406static void i915_error_work_func(struct work_struct *work)
407{
408 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
409 error_work);
410 struct drm_device *dev = dev_priv->dev;
Ben Gamarif316a422009-09-14 17:48:46 -0400411 char *error_event[] = { "ERROR=1", NULL };
412 char *reset_event[] = { "RESET=1", NULL };
413 char *reset_done_event[] = { "ERROR=0", NULL };
Jesse Barnes8a905232009-07-11 16:48:03 -0400414
Ben Gamarif316a422009-09-14 17:48:46 -0400415 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -0400416
Ben Gamariba1234d2009-09-14 17:48:47 -0400417 if (atomic_read(&dev_priv->mm.wedged)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +0100418 DRM_DEBUG_DRIVER("resetting chip\n");
419 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_event);
420 if (!i915_reset(dev, GRDOM_RENDER)) {
421 atomic_set(&dev_priv->mm.wedged, 0);
422 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, reset_done_event);
Ben Gamarif316a422009-09-14 17:48:46 -0400423 }
Chris Wilson30dbf0c2010-09-25 10:19:17 +0100424 complete_all(&dev_priv->error_completion);
Ben Gamarif316a422009-09-14 17:48:46 -0400425 }
Jesse Barnes8a905232009-07-11 16:48:03 -0400426}
427
Chris Wilson3bd3c932010-08-19 08:19:30 +0100428#ifdef CONFIG_DEBUG_FS
Chris Wilson9df30792010-02-18 10:24:56 +0000429static struct drm_i915_error_object *
430i915_error_object_create(struct drm_device *dev,
Chris Wilson05394f32010-11-08 19:18:58 +0000431 struct drm_i915_gem_object *src)
Chris Wilson9df30792010-02-18 10:24:56 +0000432{
Chris Wilsone56660d2010-08-07 11:01:26 +0100433 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilson9df30792010-02-18 10:24:56 +0000434 struct drm_i915_error_object *dst;
Chris Wilson9df30792010-02-18 10:24:56 +0000435 int page, page_count;
Chris Wilsone56660d2010-08-07 11:01:26 +0100436 u32 reloc_offset;
Chris Wilson9df30792010-02-18 10:24:56 +0000437
Chris Wilson05394f32010-11-08 19:18:58 +0000438 if (src == NULL || src->pages == NULL)
Chris Wilson9df30792010-02-18 10:24:56 +0000439 return NULL;
440
Chris Wilson05394f32010-11-08 19:18:58 +0000441 page_count = src->base.size / PAGE_SIZE;
Chris Wilson9df30792010-02-18 10:24:56 +0000442
443 dst = kmalloc(sizeof(*dst) + page_count * sizeof (u32 *), GFP_ATOMIC);
444 if (dst == NULL)
445 return NULL;
446
Chris Wilson05394f32010-11-08 19:18:58 +0000447 reloc_offset = src->gtt_offset;
Chris Wilson9df30792010-02-18 10:24:56 +0000448 for (page = 0; page < page_count; page++) {
Andrew Morton788885a2010-05-11 14:07:05 -0700449 unsigned long flags;
Chris Wilsone56660d2010-08-07 11:01:26 +0100450 void __iomem *s;
451 void *d;
Andrew Morton788885a2010-05-11 14:07:05 -0700452
Chris Wilsone56660d2010-08-07 11:01:26 +0100453 d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
Chris Wilson9df30792010-02-18 10:24:56 +0000454 if (d == NULL)
455 goto unwind;
Chris Wilsone56660d2010-08-07 11:01:26 +0100456
Andrew Morton788885a2010-05-11 14:07:05 -0700457 local_irq_save(flags);
Chris Wilsone56660d2010-08-07 11:01:26 +0100458 s = io_mapping_map_atomic_wc(dev_priv->mm.gtt_mapping,
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -0700459 reloc_offset);
Chris Wilsone56660d2010-08-07 11:01:26 +0100460 memcpy_fromio(d, s, PAGE_SIZE);
Peter Zijlstra3e4d3af2010-10-26 14:21:51 -0700461 io_mapping_unmap_atomic(s);
Andrew Morton788885a2010-05-11 14:07:05 -0700462 local_irq_restore(flags);
Chris Wilsone56660d2010-08-07 11:01:26 +0100463
Chris Wilson9df30792010-02-18 10:24:56 +0000464 dst->pages[page] = d;
Chris Wilsone56660d2010-08-07 11:01:26 +0100465
466 reloc_offset += PAGE_SIZE;
Chris Wilson9df30792010-02-18 10:24:56 +0000467 }
468 dst->page_count = page_count;
Chris Wilson05394f32010-11-08 19:18:58 +0000469 dst->gtt_offset = src->gtt_offset;
Chris Wilson9df30792010-02-18 10:24:56 +0000470
471 return dst;
472
473unwind:
474 while (page--)
475 kfree(dst->pages[page]);
476 kfree(dst);
477 return NULL;
478}
479
480static void
481i915_error_object_free(struct drm_i915_error_object *obj)
482{
483 int page;
484
485 if (obj == NULL)
486 return;
487
488 for (page = 0; page < obj->page_count; page++)
489 kfree(obj->pages[page]);
490
491 kfree(obj);
492}
493
494static void
495i915_error_state_free(struct drm_device *dev,
496 struct drm_i915_error_state *error)
497{
498 i915_error_object_free(error->batchbuffer[0]);
499 i915_error_object_free(error->batchbuffer[1]);
500 i915_error_object_free(error->ringbuffer);
501 kfree(error->active_bo);
Chris Wilson6ef3d422010-08-04 20:26:07 +0100502 kfree(error->overlay);
Chris Wilson9df30792010-02-18 10:24:56 +0000503 kfree(error);
504}
505
506static u32
507i915_get_bbaddr(struct drm_device *dev, u32 *ring)
508{
509 u32 cmd;
510
511 if (IS_I830(dev) || IS_845G(dev))
512 cmd = MI_BATCH_BUFFER;
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100513 else if (INTEL_INFO(dev)->gen >= 4)
Chris Wilson9df30792010-02-18 10:24:56 +0000514 cmd = (MI_BATCH_BUFFER_START | (2 << 6) |
515 MI_BATCH_NON_SECURE_I965);
516 else
517 cmd = (MI_BATCH_BUFFER_START | (2 << 6));
518
519 return ring[0] == cmd ? ring[1] : 0;
520}
521
522static u32
Chris Wilson8168bd42010-11-11 17:54:52 +0000523i915_ringbuffer_last_batch(struct drm_device *dev,
524 struct intel_ring_buffer *ring)
Chris Wilson9df30792010-02-18 10:24:56 +0000525{
526 struct drm_i915_private *dev_priv = dev->dev_private;
527 u32 head, bbaddr;
Chris Wilson8168bd42010-11-11 17:54:52 +0000528 u32 *val;
Chris Wilson9df30792010-02-18 10:24:56 +0000529
530 /* Locate the current position in the ringbuffer and walk back
531 * to find the most recently dispatched batch buffer.
532 */
Chris Wilson8168bd42010-11-11 17:54:52 +0000533 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Chris Wilson9df30792010-02-18 10:24:56 +0000534
Chris Wilsonab5793a2010-11-22 13:24:13 +0000535 val = (u32 *)(ring->virtual_start + head);
Chris Wilson8168bd42010-11-11 17:54:52 +0000536 while (--val >= (u32 *)ring->virtual_start) {
537 bbaddr = i915_get_bbaddr(dev, val);
Chris Wilson9df30792010-02-18 10:24:56 +0000538 if (bbaddr)
Chris Wilsonab5793a2010-11-22 13:24:13 +0000539 return bbaddr;
Chris Wilson9df30792010-02-18 10:24:56 +0000540 }
541
Chris Wilsonab5793a2010-11-22 13:24:13 +0000542 val = (u32 *)(ring->virtual_start + ring->size);
543 while (--val >= (u32 *)ring->virtual_start) {
544 bbaddr = i915_get_bbaddr(dev, val);
545 if (bbaddr)
546 return bbaddr;
Chris Wilson9df30792010-02-18 10:24:56 +0000547 }
548
Chris Wilsonab5793a2010-11-22 13:24:13 +0000549 return 0;
Chris Wilson9df30792010-02-18 10:24:56 +0000550}
551
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000552static u32 capture_bo_list(struct drm_i915_error_buffer *err,
553 int count,
554 struct list_head *head)
555{
556 struct drm_i915_gem_object *obj;
557 int i = 0;
558
559 list_for_each_entry(obj, head, mm_list) {
560 err->size = obj->base.size;
561 err->name = obj->base.name;
562 err->seqno = obj->last_rendering_seqno;
563 err->gtt_offset = obj->gtt_offset;
564 err->read_domains = obj->base.read_domains;
565 err->write_domain = obj->base.write_domain;
566 err->fence_reg = obj->fence_reg;
567 err->pinned = 0;
568 if (obj->pin_count > 0)
569 err->pinned = 1;
570 if (obj->user_pin_count > 0)
571 err->pinned = -1;
572 err->tiling = obj->tiling_mode;
573 err->dirty = obj->dirty;
574 err->purgeable = obj->madv != I915_MADV_WILLNEED;
Chris Wilson36850922010-11-23 08:49:38 +0000575 err->ring = obj->ring ? obj->ring->id : 0;
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000576
577 if (++i == count)
578 break;
579
580 err++;
581 }
582
583 return i;
584}
585
Chris Wilson748ebc62010-10-24 10:28:47 +0100586static void i915_gem_record_fences(struct drm_device *dev,
587 struct drm_i915_error_state *error)
588{
589 struct drm_i915_private *dev_priv = dev->dev_private;
590 int i;
591
592 /* Fences */
593 switch (INTEL_INFO(dev)->gen) {
594 case 6:
595 for (i = 0; i < 16; i++)
596 error->fence[i] = I915_READ64(FENCE_REG_SANDYBRIDGE_0 + (i * 8));
597 break;
598 case 5:
599 case 4:
600 for (i = 0; i < 16; i++)
601 error->fence[i] = I915_READ64(FENCE_REG_965_0 + (i * 8));
602 break;
603 case 3:
604 if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
605 for (i = 0; i < 8; i++)
606 error->fence[i+8] = I915_READ(FENCE_REG_945_8 + (i * 4));
607 case 2:
608 for (i = 0; i < 8; i++)
609 error->fence[i] = I915_READ(FENCE_REG_830_0 + (i * 4));
610 break;
611
612 }
613}
614
Jesse Barnes8a905232009-07-11 16:48:03 -0400615/**
616 * i915_capture_error_state - capture an error record for later analysis
617 * @dev: drm device
618 *
619 * Should be called when an error is detected (either a hang or an error
620 * interrupt) to capture error state from the time of the error. Fills
621 * out a structure which becomes available in debugfs for user level tools
622 * to pick up.
623 */
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700624static void i915_capture_error_state(struct drm_device *dev)
625{
626 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson05394f32010-11-08 19:18:58 +0000627 struct drm_i915_gem_object *obj;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700628 struct drm_i915_error_state *error;
Chris Wilson05394f32010-11-08 19:18:58 +0000629 struct drm_i915_gem_object *batchbuffer[2];
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700630 unsigned long flags;
Chris Wilson9df30792010-02-18 10:24:56 +0000631 u32 bbaddr;
632 int count;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700633
634 spin_lock_irqsave(&dev_priv->error_lock, flags);
Chris Wilson9df30792010-02-18 10:24:56 +0000635 error = dev_priv->first_error;
636 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
637 if (error)
638 return;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700639
640 error = kmalloc(sizeof(*error), GFP_ATOMIC);
641 if (!error) {
Chris Wilson9df30792010-02-18 10:24:56 +0000642 DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
643 return;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700644 }
645
Chris Wilson2fa772f2010-10-01 13:23:27 +0100646 DRM_DEBUG_DRIVER("generating error event\n");
647
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000648 error->seqno = dev_priv->ring[RCS].get_seqno(&dev_priv->ring[RCS]);
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700649 error->eir = I915_READ(EIR);
650 error->pgtbl_er = I915_READ(PGTBL_ER);
651 error->pipeastat = I915_READ(PIPEASTAT);
652 error->pipebstat = I915_READ(PIPEBSTAT);
653 error->instpm = I915_READ(INSTPM);
Chris Wilsonf4068392010-10-27 20:36:41 +0100654 error->error = 0;
655 if (INTEL_INFO(dev)->gen >= 6) {
656 error->error = I915_READ(ERROR_GEN6);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100657
Chris Wilson1d8f38f2010-10-29 19:00:51 +0100658 error->bcs_acthd = I915_READ(BCS_ACTHD);
659 error->bcs_ipehr = I915_READ(BCS_IPEHR);
660 error->bcs_ipeir = I915_READ(BCS_IPEIR);
661 error->bcs_instdone = I915_READ(BCS_INSTDONE);
662 error->bcs_seqno = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000663 if (dev_priv->ring[BCS].get_seqno)
664 error->bcs_seqno = dev_priv->ring[BCS].get_seqno(&dev_priv->ring[BCS]);
Chris Wilsonadd354d2010-10-29 19:00:51 +0100665
666 error->vcs_acthd = I915_READ(VCS_ACTHD);
667 error->vcs_ipehr = I915_READ(VCS_IPEHR);
668 error->vcs_ipeir = I915_READ(VCS_IPEIR);
669 error->vcs_instdone = I915_READ(VCS_INSTDONE);
670 error->vcs_seqno = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000671 if (dev_priv->ring[VCS].get_seqno)
672 error->vcs_seqno = dev_priv->ring[VCS].get_seqno(&dev_priv->ring[VCS]);
Chris Wilsonf4068392010-10-27 20:36:41 +0100673 }
674 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700675 error->ipeir = I915_READ(IPEIR_I965);
676 error->ipehr = I915_READ(IPEHR_I965);
677 error->instdone = I915_READ(INSTDONE_I965);
678 error->instps = I915_READ(INSTPS);
679 error->instdone1 = I915_READ(INSTDONE1);
680 error->acthd = I915_READ(ACTHD_I965);
Chris Wilson9df30792010-02-18 10:24:56 +0000681 error->bbaddr = I915_READ64(BB_ADDR);
Chris Wilsonf4068392010-10-27 20:36:41 +0100682 } else {
683 error->ipeir = I915_READ(IPEIR);
684 error->ipehr = I915_READ(IPEHR);
685 error->instdone = I915_READ(INSTDONE);
686 error->acthd = I915_READ(ACTHD);
687 error->bbaddr = 0;
Chris Wilson9df30792010-02-18 10:24:56 +0000688 }
Chris Wilson748ebc62010-10-24 10:28:47 +0100689 i915_gem_record_fences(dev, error);
Chris Wilson9df30792010-02-18 10:24:56 +0000690
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000691 bbaddr = i915_ringbuffer_last_batch(dev, &dev_priv->ring[RCS]);
Chris Wilson9df30792010-02-18 10:24:56 +0000692
693 /* Grab the current batchbuffer, most likely to have crashed. */
694 batchbuffer[0] = NULL;
695 batchbuffer[1] = NULL;
696 count = 0;
Chris Wilson05394f32010-11-08 19:18:58 +0000697 list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
Chris Wilson9df30792010-02-18 10:24:56 +0000698 if (batchbuffer[0] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000699 bbaddr >= obj->gtt_offset &&
700 bbaddr < obj->gtt_offset + obj->base.size)
Chris Wilson9df30792010-02-18 10:24:56 +0000701 batchbuffer[0] = obj;
702
703 if (batchbuffer[1] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000704 error->acthd >= obj->gtt_offset &&
705 error->acthd < obj->gtt_offset + obj->base.size)
Chris Wilson9df30792010-02-18 10:24:56 +0000706 batchbuffer[1] = obj;
707
708 count++;
709 }
Chris Wilsone56660d2010-08-07 11:01:26 +0100710 /* Scan the other lists for completeness for those bizarre errors. */
711 if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) {
Chris Wilson05394f32010-11-08 19:18:58 +0000712 list_for_each_entry(obj, &dev_priv->mm.flushing_list, mm_list) {
Chris Wilsone56660d2010-08-07 11:01:26 +0100713 if (batchbuffer[0] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000714 bbaddr >= obj->gtt_offset &&
715 bbaddr < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100716 batchbuffer[0] = obj;
717
718 if (batchbuffer[1] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000719 error->acthd >= obj->gtt_offset &&
720 error->acthd < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100721 batchbuffer[1] = obj;
722
723 if (batchbuffer[0] && batchbuffer[1])
724 break;
725 }
726 }
727 if (batchbuffer[0] == NULL || batchbuffer[1] == NULL) {
Chris Wilson05394f32010-11-08 19:18:58 +0000728 list_for_each_entry(obj, &dev_priv->mm.inactive_list, mm_list) {
Chris Wilsone56660d2010-08-07 11:01:26 +0100729 if (batchbuffer[0] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000730 bbaddr >= obj->gtt_offset &&
731 bbaddr < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100732 batchbuffer[0] = obj;
733
734 if (batchbuffer[1] == NULL &&
Chris Wilson05394f32010-11-08 19:18:58 +0000735 error->acthd >= obj->gtt_offset &&
736 error->acthd < obj->gtt_offset + obj->base.size)
Chris Wilsone56660d2010-08-07 11:01:26 +0100737 batchbuffer[1] = obj;
738
739 if (batchbuffer[0] && batchbuffer[1])
740 break;
741 }
742 }
Chris Wilson9df30792010-02-18 10:24:56 +0000743
744 /* We need to copy these to an anonymous buffer as the simplest
Andrea Gelmini139d3632010-10-15 17:14:33 +0200745 * method to avoid being overwritten by userspace.
Chris Wilson9df30792010-02-18 10:24:56 +0000746 */
747 error->batchbuffer[0] = i915_error_object_create(dev, batchbuffer[0]);
Chris Wilsone56660d2010-08-07 11:01:26 +0100748 if (batchbuffer[1] != batchbuffer[0])
749 error->batchbuffer[1] = i915_error_object_create(dev, batchbuffer[1]);
750 else
751 error->batchbuffer[1] = NULL;
Chris Wilson9df30792010-02-18 10:24:56 +0000752
753 /* Record the ringbuffer */
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800754 error->ringbuffer = i915_error_object_create(dev,
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000755 dev_priv->ring[RCS].obj);
Chris Wilson9df30792010-02-18 10:24:56 +0000756
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000757 /* Record buffers on the active and pinned lists. */
Chris Wilson9df30792010-02-18 10:24:56 +0000758 error->active_bo = NULL;
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000759 error->pinned_bo = NULL;
Chris Wilson9df30792010-02-18 10:24:56 +0000760
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000761 error->active_bo_count = count;
Chris Wilson05394f32010-11-08 19:18:58 +0000762 list_for_each_entry(obj, &dev_priv->mm.pinned_list, mm_list)
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000763 count++;
764 error->pinned_bo_count = count - error->active_bo_count;
765
766 if (count) {
Chris Wilson9df30792010-02-18 10:24:56 +0000767 error->active_bo = kmalloc(sizeof(*error->active_bo)*count,
768 GFP_ATOMIC);
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000769 if (error->active_bo)
770 error->pinned_bo =
771 error->active_bo + error->active_bo_count;
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700772 }
773
Chris Wilsonc724e8a2010-11-22 08:07:02 +0000774 if (error->active_bo)
775 error->active_bo_count =
776 capture_bo_list(error->active_bo,
777 error->active_bo_count,
778 &dev_priv->mm.active_list);
779
780 if (error->pinned_bo)
781 error->pinned_bo_count =
782 capture_bo_list(error->pinned_bo,
783 error->pinned_bo_count,
784 &dev_priv->mm.pinned_list);
785
Jesse Barnes8a905232009-07-11 16:48:03 -0400786 do_gettimeofday(&error->time);
787
Chris Wilson6ef3d422010-08-04 20:26:07 +0100788 error->overlay = intel_overlay_capture_error_state(dev);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +0000789 error->display = intel_display_capture_error_state(dev);
Chris Wilson6ef3d422010-08-04 20:26:07 +0100790
Chris Wilson9df30792010-02-18 10:24:56 +0000791 spin_lock_irqsave(&dev_priv->error_lock, flags);
792 if (dev_priv->first_error == NULL) {
793 dev_priv->first_error = error;
794 error = NULL;
795 }
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700796 spin_unlock_irqrestore(&dev_priv->error_lock, flags);
Chris Wilson9df30792010-02-18 10:24:56 +0000797
798 if (error)
799 i915_error_state_free(dev, error);
800}
801
802void i915_destroy_error_state(struct drm_device *dev)
803{
804 struct drm_i915_private *dev_priv = dev->dev_private;
805 struct drm_i915_error_state *error;
806
807 spin_lock(&dev_priv->error_lock);
808 error = dev_priv->first_error;
809 dev_priv->first_error = NULL;
810 spin_unlock(&dev_priv->error_lock);
811
812 if (error)
813 i915_error_state_free(dev, error);
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700814}
Chris Wilson3bd3c932010-08-19 08:19:30 +0100815#else
816#define i915_capture_error_state(x)
817#endif
Jesse Barnes63eeaf32009-06-18 16:56:52 -0700818
Chris Wilson35aed2e2010-05-27 13:18:12 +0100819static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -0400820{
821 struct drm_i915_private *dev_priv = dev->dev_private;
822 u32 eir = I915_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -0400823
Chris Wilson35aed2e2010-05-27 13:18:12 +0100824 if (!eir)
825 return;
Jesse Barnes8a905232009-07-11 16:48:03 -0400826
827 printk(KERN_ERR "render error detected, EIR: 0x%08x\n",
828 eir);
829
830 if (IS_G4X(dev)) {
831 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
832 u32 ipeir = I915_READ(IPEIR_I965);
833
834 printk(KERN_ERR " IPEIR: 0x%08x\n",
835 I915_READ(IPEIR_I965));
836 printk(KERN_ERR " IPEHR: 0x%08x\n",
837 I915_READ(IPEHR_I965));
838 printk(KERN_ERR " INSTDONE: 0x%08x\n",
839 I915_READ(INSTDONE_I965));
840 printk(KERN_ERR " INSTPS: 0x%08x\n",
841 I915_READ(INSTPS));
842 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
843 I915_READ(INSTDONE1));
844 printk(KERN_ERR " ACTHD: 0x%08x\n",
845 I915_READ(ACTHD_I965));
846 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000847 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -0400848 }
849 if (eir & GM45_ERROR_PAGE_TABLE) {
850 u32 pgtbl_err = I915_READ(PGTBL_ER);
851 printk(KERN_ERR "page table error\n");
852 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
853 pgtbl_err);
854 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000855 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -0400856 }
857 }
858
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100859 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -0400860 if (eir & I915_ERROR_PAGE_TABLE) {
861 u32 pgtbl_err = I915_READ(PGTBL_ER);
862 printk(KERN_ERR "page table error\n");
863 printk(KERN_ERR " PGTBL_ER: 0x%08x\n",
864 pgtbl_err);
865 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000866 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -0400867 }
868 }
869
870 if (eir & I915_ERROR_MEMORY_REFRESH) {
Chris Wilson35aed2e2010-05-27 13:18:12 +0100871 u32 pipea_stats = I915_READ(PIPEASTAT);
872 u32 pipeb_stats = I915_READ(PIPEBSTAT);
873
Jesse Barnes8a905232009-07-11 16:48:03 -0400874 printk(KERN_ERR "memory refresh error\n");
875 printk(KERN_ERR "PIPEASTAT: 0x%08x\n",
876 pipea_stats);
877 printk(KERN_ERR "PIPEBSTAT: 0x%08x\n",
878 pipeb_stats);
879 /* pipestat has already been acked */
880 }
881 if (eir & I915_ERROR_INSTRUCTION) {
882 printk(KERN_ERR "instruction error\n");
883 printk(KERN_ERR " INSTPM: 0x%08x\n",
884 I915_READ(INSTPM));
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100885 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -0400886 u32 ipeir = I915_READ(IPEIR);
887
888 printk(KERN_ERR " IPEIR: 0x%08x\n",
889 I915_READ(IPEIR));
890 printk(KERN_ERR " IPEHR: 0x%08x\n",
891 I915_READ(IPEHR));
892 printk(KERN_ERR " INSTDONE: 0x%08x\n",
893 I915_READ(INSTDONE));
894 printk(KERN_ERR " ACTHD: 0x%08x\n",
895 I915_READ(ACTHD));
896 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000897 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -0400898 } else {
899 u32 ipeir = I915_READ(IPEIR_I965);
900
901 printk(KERN_ERR " IPEIR: 0x%08x\n",
902 I915_READ(IPEIR_I965));
903 printk(KERN_ERR " IPEHR: 0x%08x\n",
904 I915_READ(IPEHR_I965));
905 printk(KERN_ERR " INSTDONE: 0x%08x\n",
906 I915_READ(INSTDONE_I965));
907 printk(KERN_ERR " INSTPS: 0x%08x\n",
908 I915_READ(INSTPS));
909 printk(KERN_ERR " INSTDONE1: 0x%08x\n",
910 I915_READ(INSTDONE1));
911 printk(KERN_ERR " ACTHD: 0x%08x\n",
912 I915_READ(ACTHD_I965));
913 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000914 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -0400915 }
916 }
917
918 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000919 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -0400920 eir = I915_READ(EIR);
921 if (eir) {
922 /*
923 * some errors might have become stuck,
924 * mask them.
925 */
926 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
927 I915_WRITE(EMR, I915_READ(EMR) | eir);
928 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
929 }
Chris Wilson35aed2e2010-05-27 13:18:12 +0100930}
931
932/**
933 * i915_handle_error - handle an error interrupt
934 * @dev: drm device
935 *
936 * Do some basic checking of regsiter state at error interrupt time and
937 * dump it to the syslog. Also call i915_capture_error_state() to make
938 * sure we get a record and make it available in debugfs. Fire a uevent
939 * so userspace knows something bad happened (should trigger collection
940 * of a ring dump etc.).
941 */
Chris Wilson527f9e92010-11-11 01:16:58 +0000942void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +0100943{
944 struct drm_i915_private *dev_priv = dev->dev_private;
945
946 i915_capture_error_state(dev);
947 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -0400948
Ben Gamariba1234d2009-09-14 17:48:47 -0400949 if (wedged) {
Chris Wilson30dbf0c2010-09-25 10:19:17 +0100950 INIT_COMPLETION(dev_priv->error_completion);
Ben Gamariba1234d2009-09-14 17:48:47 -0400951 atomic_set(&dev_priv->mm.wedged, 1);
952
Ben Gamari11ed50e2009-09-14 17:48:45 -0400953 /*
954 * Wakeup waiting processes so they don't hang
955 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000956 wake_up_all(&dev_priv->ring[RCS].irq_queue);
Chris Wilsonf787a5f2010-09-24 16:02:42 +0100957 if (HAS_BSD(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000958 wake_up_all(&dev_priv->ring[VCS].irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +0100959 if (HAS_BLT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000960 wake_up_all(&dev_priv->ring[BCS].irq_queue);
Ben Gamari11ed50e2009-09-14 17:48:45 -0400961 }
962
Eric Anholt9c9fe1f2009-08-03 16:09:16 -0700963 queue_work(dev_priv->wq, &dev_priv->error_work);
Jesse Barnes8a905232009-07-11 16:48:03 -0400964}
965
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100966static void i915_pageflip_stall_check(struct drm_device *dev, int pipe)
967{
968 drm_i915_private_t *dev_priv = dev->dev_private;
969 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
970 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +0000971 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100972 struct intel_unpin_work *work;
973 unsigned long flags;
974 bool stall_detected;
975
976 /* Ignore early vblank irqs */
977 if (intel_crtc == NULL)
978 return;
979
980 spin_lock_irqsave(&dev->event_lock, flags);
981 work = intel_crtc->unpin_work;
982
983 if (work == NULL || work->pending || !work->enable_stall_check) {
984 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
985 spin_unlock_irqrestore(&dev->event_lock, flags);
986 return;
987 }
988
989 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +0000990 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +0100991 if (INTEL_INFO(dev)->gen >= 4) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100992 int dspsurf = intel_crtc->plane == 0 ? DSPASURF : DSPBSURF;
Chris Wilson05394f32010-11-08 19:18:58 +0000993 stall_detected = I915_READ(dspsurf) == obj->gtt_offset;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100994 } else {
995 int dspaddr = intel_crtc->plane == 0 ? DSPAADDR : DSPBADDR;
Chris Wilson05394f32010-11-08 19:18:58 +0000996 stall_detected = I915_READ(dspaddr) == (obj->gtt_offset +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100997 crtc->y * crtc->fb->pitch +
998 crtc->x * crtc->fb->bits_per_pixel/8);
999 }
1000
1001 spin_unlock_irqrestore(&dev->event_lock, flags);
1002
1003 if (stall_detected) {
1004 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1005 intel_prepare_page_flip(dev, intel_crtc->plane);
1006 }
1007}
1008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
1010{
Dave Airlie84b1fd12007-07-11 15:53:27 +10001011 struct drm_device *dev = (struct drm_device *) arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001013 struct drm_i915_master_private *master_priv;
Eric Anholtcdfbc412008-11-04 15:50:30 -08001014 u32 iir, new_iir;
1015 u32 pipea_stats, pipeb_stats;
Keith Packard05eff842008-11-19 14:03:05 -08001016 u32 vblank_status;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001017 int vblank = 0;
Keith Packard7c463582008-11-04 02:03:27 -08001018 unsigned long irqflags;
Keith Packard05eff842008-11-19 14:03:05 -08001019 int irq_received;
1020 int ret = IRQ_NONE;
Dave Airlieaf6061a2008-05-07 12:15:39 +10001021
Eric Anholt630681d2008-10-06 15:14:12 -07001022 atomic_inc(&dev_priv->irq_received);
1023
Eric Anholtbad720f2009-10-22 16:11:14 -07001024 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001025 return ironlake_irq_handler(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001026
Eric Anholted4cb412008-07-29 12:10:39 -07001027 iir = I915_READ(IIR);
Dave Airlieaf6061a2008-05-07 12:15:39 +10001028
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001029 if (INTEL_INFO(dev)->gen >= 4)
Jesse Barnesd874bcf2010-06-30 13:16:00 -07001030 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS;
Jesse Barnese25e6602010-06-30 13:15:19 -07001031 else
Jesse Barnesd874bcf2010-06-30 13:16:00 -07001032 vblank_status = PIPE_VBLANK_INTERRUPT_STATUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Keith Packard05eff842008-11-19 14:03:05 -08001034 for (;;) {
1035 irq_received = iir != 0;
1036
1037 /* Can't rely on pipestat interrupt bit in iir as it might
1038 * have been cleared after the pipestat interrupt was received.
1039 * It doesn't set the bit in iir again, but it still produces
1040 * interrupts (for non-MSI).
1041 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001042 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Keith Packard05eff842008-11-19 14:03:05 -08001043 pipea_stats = I915_READ(PIPEASTAT);
1044 pipeb_stats = I915_READ(PIPEBSTAT);
Jesse Barnes79e53942008-11-07 14:24:08 -08001045
Jesse Barnes8a905232009-07-11 16:48:03 -04001046 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Ben Gamariba1234d2009-09-14 17:48:47 -04001047 i915_handle_error(dev, false);
Jesse Barnes8a905232009-07-11 16:48:03 -04001048
Eric Anholtcdfbc412008-11-04 15:50:30 -08001049 /*
1050 * Clear the PIPE(A|B)STAT regs before the IIR
1051 */
Keith Packard05eff842008-11-19 14:03:05 -08001052 if (pipea_stats & 0x8000ffff) {
Shaohua Li7662c8b2009-06-26 11:23:55 +08001053 if (pipea_stats & PIPE_FIFO_UNDERRUN_STATUS)
Zhao Yakui44d98a62009-10-09 11:39:40 +08001054 DRM_DEBUG_DRIVER("pipe a underrun\n");
Eric Anholtcdfbc412008-11-04 15:50:30 -08001055 I915_WRITE(PIPEASTAT, pipea_stats);
Keith Packard05eff842008-11-19 14:03:05 -08001056 irq_received = 1;
Eric Anholtcdfbc412008-11-04 15:50:30 -08001057 }
Keith Packard7c463582008-11-04 02:03:27 -08001058
Keith Packard05eff842008-11-19 14:03:05 -08001059 if (pipeb_stats & 0x8000ffff) {
Shaohua Li7662c8b2009-06-26 11:23:55 +08001060 if (pipeb_stats & PIPE_FIFO_UNDERRUN_STATUS)
Zhao Yakui44d98a62009-10-09 11:39:40 +08001061 DRM_DEBUG_DRIVER("pipe b underrun\n");
Eric Anholtcdfbc412008-11-04 15:50:30 -08001062 I915_WRITE(PIPEBSTAT, pipeb_stats);
Keith Packard05eff842008-11-19 14:03:05 -08001063 irq_received = 1;
Eric Anholtcdfbc412008-11-04 15:50:30 -08001064 }
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001065 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Keith Packard05eff842008-11-19 14:03:05 -08001066
1067 if (!irq_received)
1068 break;
1069
1070 ret = IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
Jesse Barnes5ca58282009-03-31 14:11:15 -07001072 /* Consume port. Then clear IIR or we'll miss events */
1073 if ((I915_HAS_HOTPLUG(dev)) &&
1074 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
1075 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1076
Zhao Yakui44d98a62009-10-09 11:39:40 +08001077 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
Jesse Barnes5ca58282009-03-31 14:11:15 -07001078 hotplug_status);
1079 if (hotplug_status & dev_priv->hotplug_supported_mask)
Eric Anholt9c9fe1f2009-08-03 16:09:16 -07001080 queue_work(dev_priv->wq,
1081 &dev_priv->hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001082
1083 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1084 I915_READ(PORT_HOTPLUG_STAT);
1085 }
1086
Eric Anholtcdfbc412008-11-04 15:50:30 -08001087 I915_WRITE(IIR, iir);
1088 new_iir = I915_READ(IIR); /* Flush posted writes */
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001089
Dave Airlie7c1c2872008-11-28 14:22:24 +10001090 if (dev->primary->master) {
1091 master_priv = dev->primary->master->driver_priv;
1092 if (master_priv->sarea_priv)
1093 master_priv->sarea_priv->last_dispatch =
1094 READ_BREADCRUMB(dev_priv);
1095 }
Keith Packard7c463582008-11-04 02:03:27 -08001096
Chris Wilson549f7362010-10-19 11:19:32 +01001097 if (iir & I915_USER_INTERRUPT)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001098 notify_ring(dev, &dev_priv->ring[RCS]);
1099 if (iir & I915_BSD_USER_INTERRUPT)
1100 notify_ring(dev, &dev_priv->ring[VCS]);
Zou Nan haid1b851f2010-05-21 09:08:57 +08001101
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001102 if (iir & I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT) {
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05001103 intel_prepare_page_flip(dev, 0);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001104 if (dev_priv->flip_pending_is_done)
1105 intel_finish_page_flip_plane(dev, 0);
1106 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05001107
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001108 if (iir & I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT) {
Jesse Barnes70565d02010-07-01 04:45:43 -07001109 intel_prepare_page_flip(dev, 1);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001110 if (dev_priv->flip_pending_is_done)
1111 intel_finish_page_flip_plane(dev, 1);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001112 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05001113
Keith Packard05eff842008-11-19 14:03:05 -08001114 if (pipea_stats & vblank_status) {
Eric Anholtcdfbc412008-11-04 15:50:30 -08001115 vblank++;
1116 drm_handle_vblank(dev, 0);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001117 if (!dev_priv->flip_pending_is_done) {
1118 i915_pageflip_stall_check(dev, 0);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001119 intel_finish_page_flip(dev, 0);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001120 }
Eric Anholtcdfbc412008-11-04 15:50:30 -08001121 }
Eric Anholt673a3942008-07-30 12:06:12 -07001122
Keith Packard05eff842008-11-19 14:03:05 -08001123 if (pipeb_stats & vblank_status) {
Eric Anholtcdfbc412008-11-04 15:50:30 -08001124 vblank++;
1125 drm_handle_vblank(dev, 1);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001126 if (!dev_priv->flip_pending_is_done) {
1127 i915_pageflip_stall_check(dev, 1);
Jesse Barnes1afe3e92010-03-26 10:35:20 -07001128 intel_finish_page_flip(dev, 1);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001129 }
Eric Anholtcdfbc412008-11-04 15:50:30 -08001130 }
Keith Packard7c463582008-11-04 02:03:27 -08001131
Jesse Barnesd874bcf2010-06-30 13:16:00 -07001132 if ((pipea_stats & PIPE_LEGACY_BLC_EVENT_STATUS) ||
1133 (pipeb_stats & PIPE_LEGACY_BLC_EVENT_STATUS) ||
Eric Anholtcdfbc412008-11-04 15:50:30 -08001134 (iir & I915_ASLE_INTERRUPT))
Chris Wilson3b617962010-08-24 09:02:58 +01001135 intel_opregion_asle_intr(dev);
Keith Packard7c463582008-11-04 02:03:27 -08001136
Eric Anholtcdfbc412008-11-04 15:50:30 -08001137 /* With MSI, interrupts are only generated when iir
1138 * transitions from zero to nonzero. If another bit got
1139 * set while we were handling the existing iir bits, then
1140 * we would never get another interrupt.
1141 *
1142 * This is fine on non-MSI as well, as if we hit this path
1143 * we avoid exiting the interrupt handler only to generate
1144 * another one.
1145 *
1146 * Note that for MSI this could cause a stray interrupt report
1147 * if an interrupt landed in the time between writing IIR and
1148 * the posting read. This should be rare enough to never
1149 * trigger the 99% of 100,000 interrupts test for disabling
1150 * stray interrupts.
1151 */
1152 iir = new_iir;
Keith Packard05eff842008-11-19 14:03:05 -08001153 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001154
Keith Packard05eff842008-11-19 14:03:05 -08001155 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156}
1157
Dave Airlieaf6061a2008-05-07 12:15:39 +10001158static int i915_emit_irq(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159{
1160 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001161 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 i915_kernel_lost_context(dev);
1164
Zhao Yakui44d98a62009-10-09 11:39:40 +08001165 DRM_DEBUG_DRIVER("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Kristian Høgsbergc99b0582008-08-20 11:20:13 -04001167 dev_priv->counter++;
Alan Hourihanec29b6692006-08-12 16:29:24 +10001168 if (dev_priv->counter > 0x7FFFFFFFUL)
Kristian Høgsbergc99b0582008-08-20 11:20:13 -04001169 dev_priv->counter = 1;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001170 if (master_priv->sarea_priv)
1171 master_priv->sarea_priv->last_enqueue = dev_priv->counter;
Alan Hourihanec29b6692006-08-12 16:29:24 +10001172
Chris Wilsone1f99ce2010-10-27 12:45:26 +01001173 if (BEGIN_LP_RING(4) == 0) {
1174 OUT_RING(MI_STORE_DWORD_INDEX);
1175 OUT_RING(I915_BREADCRUMB_INDEX << MI_STORE_DWORD_INDEX_SHIFT);
1176 OUT_RING(dev_priv->counter);
1177 OUT_RING(MI_USER_INTERRUPT);
1178 ADVANCE_LP_RING();
1179 }
Dave Airliebc5f4522007-11-05 12:50:58 +10001180
Alan Hourihanec29b6692006-08-12 16:29:24 +10001181 return dev_priv->counter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Chris Wilson9d34e5d2009-09-24 05:26:06 +01001184void i915_trace_irq_get(struct drm_device *dev, u32 seqno)
1185{
1186 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001187 struct intel_ring_buffer *ring = LP_RING(dev_priv);
Chris Wilson9d34e5d2009-09-24 05:26:06 +01001188
1189 if (dev_priv->trace_irq_seqno == 0)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001190 ring->irq_get(ring);
Chris Wilson9d34e5d2009-09-24 05:26:06 +01001191
1192 dev_priv->trace_irq_seqno = seqno;
1193}
1194
Dave Airlie84b1fd12007-07-11 15:53:27 +10001195static int i915_wait_irq(struct drm_device * dev, int irq_nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
1197 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie7c1c2872008-11-28 14:22:24 +10001198 struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 int ret = 0;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001200 struct intel_ring_buffer *ring = LP_RING(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
Zhao Yakui44d98a62009-10-09 11:39:40 +08001202 DRM_DEBUG_DRIVER("irq_nr=%d breadcrumb=%d\n", irq_nr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 READ_BREADCRUMB(dev_priv));
1204
Eric Anholted4cb412008-07-29 12:10:39 -07001205 if (READ_BREADCRUMB(dev_priv) >= irq_nr) {
Dave Airlie7c1c2872008-11-28 14:22:24 +10001206 if (master_priv->sarea_priv)
1207 master_priv->sarea_priv->last_dispatch = READ_BREADCRUMB(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 return 0;
Eric Anholted4cb412008-07-29 12:10:39 -07001209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210
Dave Airlie7c1c2872008-11-28 14:22:24 +10001211 if (master_priv->sarea_priv)
1212 master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001214 ring->irq_get(ring);
1215 DRM_WAIT_ON(ret, ring->irq_queue, 3 * DRM_HZ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 READ_BREADCRUMB(dev_priv) >= irq_nr);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001217 ring->irq_put(ring);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
Eric Anholt20caafa2007-08-25 19:22:43 +10001219 if (ret == -EBUSY) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001220 DRM_ERROR("EBUSY -- rec: %d emitted: %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 READ_BREADCRUMB(dev_priv), (int)dev_priv->counter);
1222 }
1223
Dave Airlieaf6061a2008-05-07 12:15:39 +10001224 return ret;
1225}
1226
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227/* Needs the lock as it touches the ring.
1228 */
Eric Anholtc153f452007-09-03 12:06:45 +10001229int i915_irq_emit(struct drm_device *dev, void *data,
1230 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001233 drm_i915_irq_emit_t *emit = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 int result;
1235
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001236 if (!dev_priv || !LP_RING(dev_priv)->virtual_start) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001237 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001238 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 }
Eric Anholt299eb932009-02-24 22:14:12 -08001240
1241 RING_LOCK_TEST_WITH_RETURN(dev, file_priv);
1242
Eric Anholt546b0972008-09-01 16:45:29 -07001243 mutex_lock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 result = i915_emit_irq(dev);
Eric Anholt546b0972008-09-01 16:45:29 -07001245 mutex_unlock(&dev->struct_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
Eric Anholtc153f452007-09-03 12:06:45 +10001247 if (DRM_COPY_TO_USER(emit->irq_seq, &result, sizeof(int))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 DRM_ERROR("copy_to_user\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001249 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251
1252 return 0;
1253}
1254
1255/* Doesn't need the hardware lock.
1256 */
Eric Anholtc153f452007-09-03 12:06:45 +10001257int i915_irq_wait(struct drm_device *dev, void *data,
1258 struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001261 drm_i915_irq_wait_t *irqwait = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001264 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001265 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
1267
Eric Anholtc153f452007-09-03 12:06:45 +10001268 return i915_wait_irq(dev, irqwait->irq_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Keith Packard42f52ef2008-10-18 19:39:29 -07001271/* Called from drm generic code, passed 'crtc' which
1272 * we use as a pipe index
1273 */
1274int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001275{
1276 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001277 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001278
Chris Wilson5eddb702010-09-11 13:48:45 +01001279 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001280 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001281
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001282 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Eric Anholtbad720f2009-10-22 16:11:14 -07001283 if (HAS_PCH_SPLIT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001284 ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
Li Pengc062df62010-01-23 00:12:58 +08001285 DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001286 else if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08001287 i915_enable_pipestat(dev_priv, pipe,
1288 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07001289 else
Keith Packard7c463582008-11-04 02:03:27 -08001290 i915_enable_pipestat(dev_priv, pipe,
1291 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001292 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001293 return 0;
1294}
1295
Keith Packard42f52ef2008-10-18 19:39:29 -07001296/* Called from drm generic code, passed 'crtc' which
1297 * we use as a pipe index
1298 */
1299void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001300{
1301 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001302 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001303
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001304 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Eric Anholtbad720f2009-10-22 16:11:14 -07001305 if (HAS_PCH_SPLIT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001306 ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
Li Pengc062df62010-01-23 00:12:58 +08001307 DE_PIPEA_VBLANK: DE_PIPEB_VBLANK);
1308 else
1309 i915_disable_pipestat(dev_priv, pipe,
1310 PIPE_VBLANK_INTERRUPT_ENABLE |
1311 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001312 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001313}
1314
Jesse Barnes79e53942008-11-07 14:24:08 -08001315void i915_enable_interrupt (struct drm_device *dev)
1316{
1317 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wange170b032009-06-05 15:38:40 +08001318
Eric Anholtbad720f2009-10-22 16:11:14 -07001319 if (!HAS_PCH_SPLIT(dev))
Chris Wilson3b617962010-08-24 09:02:58 +01001320 intel_opregion_enable_asle(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08001321 dev_priv->irq_enabled = 1;
1322}
1323
1324
Dave Airlie702880f2006-06-24 17:07:34 +10001325/* Set the vblank monitor pipe
1326 */
Eric Anholtc153f452007-09-03 12:06:45 +10001327int i915_vblank_pipe_set(struct drm_device *dev, void *data,
1328 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +10001329{
Dave Airlie702880f2006-06-24 17:07:34 +10001330 drm_i915_private_t *dev_priv = dev->dev_private;
Dave Airlie702880f2006-06-24 17:07:34 +10001331
1332 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001333 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001334 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +10001335 }
1336
=?utf-8?q?Michel_D=C3=A4nzer?=5b516942006-10-25 00:08:23 +10001337 return 0;
Dave Airlie702880f2006-06-24 17:07:34 +10001338}
1339
Eric Anholtc153f452007-09-03 12:06:45 +10001340int i915_vblank_pipe_get(struct drm_device *dev, void *data,
1341 struct drm_file *file_priv)
Dave Airlie702880f2006-06-24 17:07:34 +10001342{
Dave Airlie702880f2006-06-24 17:07:34 +10001343 drm_i915_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001344 drm_i915_vblank_pipe_t *pipe = data;
Dave Airlie702880f2006-06-24 17:07:34 +10001345
1346 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001347 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001348 return -EINVAL;
Dave Airlie702880f2006-06-24 17:07:34 +10001349 }
1350
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001351 pipe->pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
Eric Anholtc153f452007-09-03 12:06:45 +10001352
Dave Airlie702880f2006-06-24 17:07:34 +10001353 return 0;
1354}
1355
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +10001356/**
1357 * Schedule buffer swap at given vertical blank.
1358 */
Eric Anholtc153f452007-09-03 12:06:45 +10001359int i915_vblank_swap(struct drm_device *dev, void *data,
1360 struct drm_file *file_priv)
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +10001361{
Eric Anholtbd95e0a2008-11-04 12:01:24 -08001362 /* The delayed swap mechanism was fundamentally racy, and has been
1363 * removed. The model was that the client requested a delayed flip/swap
1364 * from the kernel, then waited for vblank before continuing to perform
1365 * rendering. The problem was that the kernel might wake the client
1366 * up before it dispatched the vblank swap (since the lock has to be
1367 * held while touching the ringbuffer), in which case the client would
1368 * clear and start the next frame before the swap occurred, and
1369 * flicker would occur in addition to likely missing the vblank.
1370 *
1371 * In the absence of this ioctl, userland falls back to a correct path
1372 * of waiting for a vblank, then dispatching the swap on its own.
1373 * Context switching to userland and back is plenty fast enough for
1374 * meeting the requirements of vblank swapping.
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001375 */
Eric Anholtbd95e0a2008-11-04 12:01:24 -08001376 return -EINVAL;
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +10001377}
1378
Chris Wilson893eead2010-10-27 14:44:35 +01001379static u32
1380ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08001381{
Chris Wilson893eead2010-10-27 14:44:35 +01001382 return list_entry(ring->request_list.prev,
1383 struct drm_i915_gem_request, list)->seqno;
1384}
1385
1386static bool i915_hangcheck_ring_idle(struct intel_ring_buffer *ring, bool *err)
1387{
1388 if (list_empty(&ring->request_list) ||
1389 i915_seqno_passed(ring->get_seqno(ring), ring_last_seqno(ring))) {
1390 /* Issue a wake-up to catch stuck h/w. */
Chris Wilsonb2223492010-10-27 15:27:33 +01001391 if (ring->waiting_seqno && waitqueue_active(&ring->irq_queue)) {
Chris Wilson893eead2010-10-27 14:44:35 +01001392 DRM_ERROR("Hangcheck timer elapsed... %s idle [waiting on %d, at %d], missed IRQ?\n",
1393 ring->name,
Chris Wilsonb2223492010-10-27 15:27:33 +01001394 ring->waiting_seqno,
Chris Wilson893eead2010-10-27 14:44:35 +01001395 ring->get_seqno(ring));
1396 wake_up_all(&ring->irq_queue);
1397 *err = true;
1398 }
1399 return true;
1400 }
1401 return false;
Ben Gamarif65d9422009-09-14 17:48:44 -04001402}
1403
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001404static bool kick_ring(struct intel_ring_buffer *ring)
1405{
1406 struct drm_device *dev = ring->dev;
1407 struct drm_i915_private *dev_priv = dev->dev_private;
1408 u32 tmp = I915_READ_CTL(ring);
1409 if (tmp & RING_WAIT) {
1410 DRM_ERROR("Kicking stuck wait on %s\n",
1411 ring->name);
1412 I915_WRITE_CTL(ring, tmp);
1413 return true;
1414 }
1415 if (IS_GEN6(dev) &&
1416 (tmp & RING_WAIT_SEMAPHORE)) {
1417 DRM_ERROR("Kicking stuck semaphore on %s\n",
1418 ring->name);
1419 I915_WRITE_CTL(ring, tmp);
1420 return true;
1421 }
1422 return false;
1423}
1424
Ben Gamarif65d9422009-09-14 17:48:44 -04001425/**
1426 * This is called when the chip hasn't reported back with completed
1427 * batchbuffers in a long time. The first time this is called we simply record
1428 * ACTHD. If ACTHD hasn't changed by the time the hangcheck timer elapses
1429 * again, we assume the chip is wedged and try to fix it.
1430 */
1431void i915_hangcheck_elapsed(unsigned long data)
1432{
1433 struct drm_device *dev = (struct drm_device *)data;
1434 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001435 uint32_t acthd, instdone, instdone1;
Chris Wilson893eead2010-10-27 14:44:35 +01001436 bool err = false;
1437
1438 /* If all work is done then ACTHD clearly hasn't advanced. */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001439 if (i915_hangcheck_ring_idle(&dev_priv->ring[RCS], &err) &&
1440 i915_hangcheck_ring_idle(&dev_priv->ring[VCS], &err) &&
1441 i915_hangcheck_ring_idle(&dev_priv->ring[BCS], &err)) {
Chris Wilson893eead2010-10-27 14:44:35 +01001442 dev_priv->hangcheck_count = 0;
1443 if (err)
1444 goto repeat;
1445 return;
1446 }
Eric Anholtb9201c12010-01-08 14:25:16 -08001447
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001448 if (INTEL_INFO(dev)->gen < 4) {
Ben Gamarif65d9422009-09-14 17:48:44 -04001449 acthd = I915_READ(ACTHD);
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001450 instdone = I915_READ(INSTDONE);
1451 instdone1 = 0;
1452 } else {
Ben Gamarif65d9422009-09-14 17:48:44 -04001453 acthd = I915_READ(ACTHD_I965);
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001454 instdone = I915_READ(INSTDONE_I965);
1455 instdone1 = I915_READ(INSTDONE1);
1456 }
Ben Gamarif65d9422009-09-14 17:48:44 -04001457
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001458 if (dev_priv->last_acthd == acthd &&
1459 dev_priv->last_instdone == instdone &&
1460 dev_priv->last_instdone1 == instdone1) {
1461 if (dev_priv->hangcheck_count++ > 1) {
1462 DRM_ERROR("Hangcheck timer elapsed... GPU hung\n");
Chris Wilson8c80b592010-08-08 20:38:12 +01001463
1464 if (!IS_GEN2(dev)) {
1465 /* Is the chip hanging on a WAIT_FOR_EVENT?
1466 * If so we can simply poke the RB_WAIT bit
1467 * and break the hang. This should work on
1468 * all but the second generation chipsets.
1469 */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001470
1471 if (kick_ring(&dev_priv->ring[RCS]))
Chris Wilson893eead2010-10-27 14:44:35 +01001472 goto repeat;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001473
1474 if (HAS_BSD(dev) &&
1475 kick_ring(&dev_priv->ring[VCS]))
1476 goto repeat;
1477
1478 if (HAS_BLT(dev) &&
1479 kick_ring(&dev_priv->ring[BCS]))
1480 goto repeat;
Chris Wilson8c80b592010-08-08 20:38:12 +01001481 }
1482
Chris Wilsoncbb465e2010-06-06 12:16:24 +01001483 i915_handle_error(dev, true);
1484 return;
1485 }
1486 } else {
1487 dev_priv->hangcheck_count = 0;
1488
1489 dev_priv->last_acthd = acthd;
1490 dev_priv->last_instdone = instdone;
1491 dev_priv->last_instdone1 = instdone1;
1492 }
Ben Gamarif65d9422009-09-14 17:48:44 -04001493
Chris Wilson893eead2010-10-27 14:44:35 +01001494repeat:
Ben Gamarif65d9422009-09-14 17:48:44 -04001495 /* Reset timer case chip hangs without another request being added */
Chris Wilsonb3b079d2010-09-13 23:44:34 +01001496 mod_timer(&dev_priv->hangcheck_timer,
1497 jiffies + msecs_to_jiffies(DRM_I915_HANGCHECK_PERIOD));
Ben Gamarif65d9422009-09-14 17:48:44 -04001498}
1499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500/* drm_dma.h hooks
1501*/
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001502static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001503{
1504 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1505
1506 I915_WRITE(HWSTAM, 0xeffe);
1507
1508 /* XXX hotplug from PCH */
1509
1510 I915_WRITE(DEIMR, 0xffffffff);
1511 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001512 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001513
1514 /* and GT */
1515 I915_WRITE(GTIMR, 0xffffffff);
1516 I915_WRITE(GTIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001517 POSTING_READ(GTIER);
Zhenyu Wangc6501562009-11-03 18:57:21 +00001518
1519 /* south display irq */
1520 I915_WRITE(SDEIMR, 0xffffffff);
1521 I915_WRITE(SDEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001522 POSTING_READ(SDEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001523}
1524
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001525static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001526{
1527 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1528 /* enable kind of interrupts always enabled */
Jesse Barnes013d5aa2010-01-29 11:18:31 -08001529 u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
1530 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001531 u32 render_irqs;
Yuanhan Liu2d7b8362010-10-08 10:21:06 +01001532 u32 hotplug_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001533
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001534 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001535
1536 /* should always can generate irq */
1537 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001538 I915_WRITE(DEIMR, dev_priv->irq_mask);
1539 I915_WRITE(DEIER, display_mask | DE_PIPEA_VBLANK | DE_PIPEB_VBLANK);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001540 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001541
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001542 dev_priv->gt_irq_mask = ~0;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001543
1544 I915_WRITE(GTIIR, I915_READ(GTIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001545 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001546 if (IS_GEN6(dev)) {
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001547 I915_WRITE(GEN6_RENDER_IMR, ~GEN6_RENDER_USER_INTERRUPT);
1548 I915_WRITE(GEN6_BSD_IMR, ~GEN6_BSD_USER_INTERRUPT);
Chris Wilson549f7362010-10-19 11:19:32 +01001549 I915_WRITE(GEN6_BLITTER_IMR, ~GEN6_BLITTER_USER_INTERRUPT);
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001550 }
1551
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001552 if (IS_GEN6(dev))
1553 render_irqs =
1554 GT_USER_INTERRUPT |
1555 GT_GEN6_BSD_USER_INTERRUPT |
1556 GT_BLT_USER_INTERRUPT;
1557 else
1558 render_irqs =
1559 GT_PIPE_NOTIFY |
1560 GT_BSD_USER_INTERRUPT;
1561 I915_WRITE(GTIER, render_irqs);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001562 POSTING_READ(GTIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001563
Yuanhan Liu2d7b8362010-10-08 10:21:06 +01001564 if (HAS_PCH_CPT(dev)) {
1565 hotplug_mask = SDE_CRT_HOTPLUG_CPT | SDE_PORTB_HOTPLUG_CPT |
1566 SDE_PORTC_HOTPLUG_CPT | SDE_PORTD_HOTPLUG_CPT ;
1567 } else {
1568 hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG |
1569 SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG;
1570 }
1571
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001572 dev_priv->pch_irq_mask = ~hotplug_mask;
Zhenyu Wangc6501562009-11-03 18:57:21 +00001573
1574 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001575 I915_WRITE(SDEIMR, dev_priv->pch_irq_mask);
1576 I915_WRITE(SDEIER, hotplug_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001577 POSTING_READ(SDEIER);
Zhenyu Wangc6501562009-11-03 18:57:21 +00001578
Jesse Barnesf97108d2010-01-29 11:27:07 -08001579 if (IS_IRONLAKE_M(dev)) {
1580 /* Clear & enable PCU event interrupts */
1581 I915_WRITE(DEIIR, DE_PCU_EVENT);
1582 I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT);
1583 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
1584 }
1585
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001586 return 0;
1587}
1588
Dave Airlie84b1fd12007-07-11 15:53:27 +10001589void i915_driver_irq_preinstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
1591 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1592
Jesse Barnes79e53942008-11-07 14:24:08 -08001593 atomic_set(&dev_priv->irq_received, 0);
1594
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001595 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Jesse Barnes8a905232009-07-11 16:48:03 -04001596 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001597
Eric Anholtbad720f2009-10-22 16:11:14 -07001598 if (HAS_PCH_SPLIT(dev)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001599 ironlake_irq_preinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001600 return;
1601 }
1602
Jesse Barnes5ca58282009-03-31 14:11:15 -07001603 if (I915_HAS_HOTPLUG(dev)) {
1604 I915_WRITE(PORT_HOTPLUG_EN, 0);
1605 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1606 }
1607
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001608 I915_WRITE(HWSTAM, 0xeffe);
Keith Packard7c463582008-11-04 02:03:27 -08001609 I915_WRITE(PIPEASTAT, 0);
1610 I915_WRITE(PIPEBSTAT, 0);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001611 I915_WRITE(IMR, 0xffffffff);
Eric Anholted4cb412008-07-29 12:10:39 -07001612 I915_WRITE(IER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001613 POSTING_READ(IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001616/*
1617 * Must be called after intel_modeset_init or hotplug interrupts won't be
1618 * enabled correctly.
1619 */
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001620int i915_driver_irq_postinstall(struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
1622 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001623 u32 enable_mask = I915_INTERRUPT_ENABLE_FIX | I915_INTERRUPT_ENABLE_VAR;
Jesse Barnes63eeaf32009-06-18 16:56:52 -07001624 u32 error_mask;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001625
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001626 DRM_INIT_WAITQUEUE(&dev_priv->ring[RCS].irq_queue);
Zou Nan haid1b851f2010-05-21 09:08:57 +08001627 if (HAS_BSD(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001628 DRM_INIT_WAITQUEUE(&dev_priv->ring[VCS].irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +01001629 if (HAS_BLT(dev))
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001630 DRM_INIT_WAITQUEUE(&dev_priv->ring[BCS].irq_queue);
Zou Nan haid1b851f2010-05-21 09:08:57 +08001631
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001632 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001633
Eric Anholtbad720f2009-10-22 16:11:14 -07001634 if (HAS_PCH_SPLIT(dev))
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001635 return ironlake_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001636
Keith Packard7c463582008-11-04 02:03:27 -08001637 /* Unmask the interrupts that we always want on. */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001638 dev_priv->irq_mask = ~I915_INTERRUPT_ENABLE_FIX;
Matthew Garrett8ee1c3d2008-08-05 19:37:25 +01001639
Keith Packard7c463582008-11-04 02:03:27 -08001640 dev_priv->pipestat[0] = 0;
1641 dev_priv->pipestat[1] = 0;
1642
Jesse Barnes5ca58282009-03-31 14:11:15 -07001643 if (I915_HAS_HOTPLUG(dev)) {
Adam Jacksonc496fa12010-05-27 17:26:45 -04001644 /* Enable in IER... */
1645 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
1646 /* and unmask in IMR */
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001647 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
Adam Jacksonc496fa12010-05-27 17:26:45 -04001648 }
1649
1650 /*
1651 * Enable some error detection, note the instruction error mask
1652 * bit is reserved, so we leave it masked.
1653 */
1654 if (IS_G4X(dev)) {
1655 error_mask = ~(GM45_ERROR_PAGE_TABLE |
1656 GM45_ERROR_MEM_PRIV |
1657 GM45_ERROR_CP_PRIV |
1658 I915_ERROR_MEMORY_REFRESH);
1659 } else {
1660 error_mask = ~(I915_ERROR_PAGE_TABLE |
1661 I915_ERROR_MEMORY_REFRESH);
1662 }
1663 I915_WRITE(EMR, error_mask);
1664
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001665 I915_WRITE(IMR, dev_priv->irq_mask);
Adam Jacksonc496fa12010-05-27 17:26:45 -04001666 I915_WRITE(IER, enable_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001667 POSTING_READ(IER);
Adam Jacksonc496fa12010-05-27 17:26:45 -04001668
1669 if (I915_HAS_HOTPLUG(dev)) {
Jesse Barnes5ca58282009-03-31 14:11:15 -07001670 u32 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
1671
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001672 /* Note HDMI and DP share bits */
1673 if (dev_priv->hotplug_supported_mask & HDMIB_HOTPLUG_INT_STATUS)
1674 hotplug_en |= HDMIB_HOTPLUG_INT_EN;
1675 if (dev_priv->hotplug_supported_mask & HDMIC_HOTPLUG_INT_STATUS)
1676 hotplug_en |= HDMIC_HOTPLUG_INT_EN;
1677 if (dev_priv->hotplug_supported_mask & HDMID_HOTPLUG_INT_STATUS)
1678 hotplug_en |= HDMID_HOTPLUG_INT_EN;
1679 if (dev_priv->hotplug_supported_mask & SDVOC_HOTPLUG_INT_STATUS)
1680 hotplug_en |= SDVOC_HOTPLUG_INT_EN;
1681 if (dev_priv->hotplug_supported_mask & SDVOB_HOTPLUG_INT_STATUS)
1682 hotplug_en |= SDVOB_HOTPLUG_INT_EN;
Andy Lutomirski2d1c9752010-06-12 05:21:18 -04001683 if (dev_priv->hotplug_supported_mask & CRT_HOTPLUG_INT_STATUS) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001684 hotplug_en |= CRT_HOTPLUG_INT_EN;
Andy Lutomirski2d1c9752010-06-12 05:21:18 -04001685
1686 /* Programming the CRT detection parameters tends
1687 to generate a spurious hotplug event about three
1688 seconds later. So just do it once.
1689 */
1690 if (IS_G4X(dev))
1691 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
1692 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
1693 }
1694
Jesse Barnesb01f2c32009-12-11 11:07:17 -08001695 /* Ignore TV since it's buggy */
1696
Jesse Barnes5ca58282009-03-31 14:11:15 -07001697 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001698 }
1699
Chris Wilson3b617962010-08-24 09:02:58 +01001700 intel_opregion_enable_asle(dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001701
1702 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001705static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001706{
1707 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1708 I915_WRITE(HWSTAM, 0xffffffff);
1709
1710 I915_WRITE(DEIMR, 0xffffffff);
1711 I915_WRITE(DEIER, 0x0);
1712 I915_WRITE(DEIIR, I915_READ(DEIIR));
1713
1714 I915_WRITE(GTIMR, 0xffffffff);
1715 I915_WRITE(GTIER, 0x0);
1716 I915_WRITE(GTIIR, I915_READ(GTIIR));
1717}
1718
Dave Airlie84b1fd12007-07-11 15:53:27 +10001719void i915_driver_irq_uninstall(struct drm_device * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
1721 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Dave Airlie91e37382006-02-18 15:17:04 +11001722
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 if (!dev_priv)
1724 return;
1725
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001726 dev_priv->vblank_pipe = 0;
1727
Eric Anholtbad720f2009-10-22 16:11:14 -07001728 if (HAS_PCH_SPLIT(dev)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -05001729 ironlake_irq_uninstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001730 return;
1731 }
1732
Jesse Barnes5ca58282009-03-31 14:11:15 -07001733 if (I915_HAS_HOTPLUG(dev)) {
1734 I915_WRITE(PORT_HOTPLUG_EN, 0);
1735 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
1736 }
1737
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001738 I915_WRITE(HWSTAM, 0xffffffff);
Keith Packard7c463582008-11-04 02:03:27 -08001739 I915_WRITE(PIPEASTAT, 0);
1740 I915_WRITE(PIPEBSTAT, 0);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001741 I915_WRITE(IMR, 0xffffffff);
Eric Anholted4cb412008-07-29 12:10:39 -07001742 I915_WRITE(IER, 0x0);
Dave Airlie91e37382006-02-18 15:17:04 +11001743
Keith Packard7c463582008-11-04 02:03:27 -08001744 I915_WRITE(PIPEASTAT, I915_READ(PIPEASTAT) & 0x8000ffff);
1745 I915_WRITE(PIPEBSTAT, I915_READ(PIPEBSTAT) & 0x8000ffff);
1746 I915_WRITE(IIR, I915_READ(IIR));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}