blob: 68936da7c25d5c4c06d0e4aa2d5d3b97a212f1a8 [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
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Egbert Eiche5868a32013-02-28 04:17:12 -050040static const u32 hpd_ibx[] = {
41 [HPD_CRT] = SDE_CRT_HOTPLUG,
42 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
43 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
44 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
45 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
46};
47
48static const u32 hpd_cpt[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010050 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050051 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
54};
55
56static const u32 hpd_mask_i915[] = {
57 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
58 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
59 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
60 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
61 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
62 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
63};
64
65static const u32 hpd_status_gen4[] = {
66 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
67 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
68 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
69 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
70 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
71 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
72};
73
Egbert Eiche5868a32013-02-28 04:17:12 -050074static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
75 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
76 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
77 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
78 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
79 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
80 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
81};
82
Zhenyu Wang036a4a72009-06-08 14:40:19 +080083/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010084static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050085ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080086{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020087 assert_spin_locked(&dev_priv->irq_lock);
88
Paulo Zanonic67a4702013-08-19 13:18:09 -030089 if (dev_priv->pc8.irqs_disabled) {
90 WARN(1, "IRQs disabled\n");
91 dev_priv->pc8.regsave.deimr &= ~mask;
92 return;
93 }
94
Chris Wilson1ec14ad2010-12-04 11:30:53 +000095 if ((dev_priv->irq_mask & mask) != 0) {
96 dev_priv->irq_mask &= ~mask;
97 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000098 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080099 }
100}
101
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300102static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500103ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200105 assert_spin_locked(&dev_priv->irq_lock);
106
Paulo Zanonic67a4702013-08-19 13:18:09 -0300107 if (dev_priv->pc8.irqs_disabled) {
108 WARN(1, "IRQs disabled\n");
109 dev_priv->pc8.regsave.deimr |= mask;
110 return;
111 }
112
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000113 if ((dev_priv->irq_mask & mask) != mask) {
114 dev_priv->irq_mask |= mask;
115 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000116 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800117 }
118}
119
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300120/**
121 * ilk_update_gt_irq - update GTIMR
122 * @dev_priv: driver private
123 * @interrupt_mask: mask of interrupt bits to update
124 * @enabled_irq_mask: mask of interrupt bits to enable
125 */
126static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
127 uint32_t interrupt_mask,
128 uint32_t enabled_irq_mask)
129{
130 assert_spin_locked(&dev_priv->irq_lock);
131
Paulo Zanonic67a4702013-08-19 13:18:09 -0300132 if (dev_priv->pc8.irqs_disabled) {
133 WARN(1, "IRQs disabled\n");
134 dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
135 dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
136 interrupt_mask);
137 return;
138 }
139
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300140 dev_priv->gt_irq_mask &= ~interrupt_mask;
141 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
142 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
143 POSTING_READ(GTIMR);
144}
145
146void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
147{
148 ilk_update_gt_irq(dev_priv, mask, mask);
149}
150
151void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
152{
153 ilk_update_gt_irq(dev_priv, mask, 0);
154}
155
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300156/**
157 * snb_update_pm_irq - update GEN6_PMIMR
158 * @dev_priv: driver private
159 * @interrupt_mask: mask of interrupt bits to update
160 * @enabled_irq_mask: mask of interrupt bits to enable
161 */
162static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
163 uint32_t interrupt_mask,
164 uint32_t enabled_irq_mask)
165{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300166 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300167
168 assert_spin_locked(&dev_priv->irq_lock);
169
Paulo Zanonic67a4702013-08-19 13:18:09 -0300170 if (dev_priv->pc8.irqs_disabled) {
171 WARN(1, "IRQs disabled\n");
172 dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
173 dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
174 interrupt_mask);
175 return;
176 }
177
Paulo Zanoni605cd252013-08-06 18:57:15 -0300178 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300179 new_val &= ~interrupt_mask;
180 new_val |= (~enabled_irq_mask & interrupt_mask);
181
Paulo Zanoni605cd252013-08-06 18:57:15 -0300182 if (new_val != dev_priv->pm_irq_mask) {
183 dev_priv->pm_irq_mask = new_val;
184 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300185 POSTING_READ(GEN6_PMIMR);
186 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300187}
188
189void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
190{
191 snb_update_pm_irq(dev_priv, mask, mask);
192}
193
194void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
195{
196 snb_update_pm_irq(dev_priv, mask, 0);
197}
198
Paulo Zanoni86642812013-04-12 17:57:57 -0300199static bool ivb_can_enable_err_int(struct drm_device *dev)
200{
201 struct drm_i915_private *dev_priv = dev->dev_private;
202 struct intel_crtc *crtc;
203 enum pipe pipe;
204
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200205 assert_spin_locked(&dev_priv->irq_lock);
206
Paulo Zanoni86642812013-04-12 17:57:57 -0300207 for_each_pipe(pipe) {
208 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
209
210 if (crtc->cpu_fifo_underrun_disabled)
211 return false;
212 }
213
214 return true;
215}
216
217static bool cpt_can_enable_serr_int(struct drm_device *dev)
218{
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 enum pipe pipe;
221 struct intel_crtc *crtc;
222
Daniel Vetterfee884e2013-07-04 23:35:21 +0200223 assert_spin_locked(&dev_priv->irq_lock);
224
Paulo Zanoni86642812013-04-12 17:57:57 -0300225 for_each_pipe(pipe) {
226 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
227
228 if (crtc->pch_fifo_underrun_disabled)
229 return false;
230 }
231
232 return true;
233}
234
235static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
236 enum pipe pipe, bool enable)
237{
238 struct drm_i915_private *dev_priv = dev->dev_private;
239 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
240 DE_PIPEB_FIFO_UNDERRUN;
241
242 if (enable)
243 ironlake_enable_display_irq(dev_priv, bit);
244 else
245 ironlake_disable_display_irq(dev_priv, bit);
246}
247
248static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200249 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300250{
251 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300252 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200253 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
254
Paulo Zanoni86642812013-04-12 17:57:57 -0300255 if (!ivb_can_enable_err_int(dev))
256 return;
257
Paulo Zanoni86642812013-04-12 17:57:57 -0300258 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
259 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200260 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
261
262 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300263 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200264
265 if (!was_enabled &&
266 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
267 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
268 pipe_name(pipe));
269 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 }
271}
272
Daniel Vetterfee884e2013-07-04 23:35:21 +0200273/**
274 * ibx_display_interrupt_update - update SDEIMR
275 * @dev_priv: driver private
276 * @interrupt_mask: mask of interrupt bits to update
277 * @enabled_irq_mask: mask of interrupt bits to enable
278 */
279static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
280 uint32_t interrupt_mask,
281 uint32_t enabled_irq_mask)
282{
283 uint32_t sdeimr = I915_READ(SDEIMR);
284 sdeimr &= ~interrupt_mask;
285 sdeimr |= (~enabled_irq_mask & interrupt_mask);
286
287 assert_spin_locked(&dev_priv->irq_lock);
288
Paulo Zanonic67a4702013-08-19 13:18:09 -0300289 if (dev_priv->pc8.irqs_disabled &&
290 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
291 WARN(1, "IRQs disabled\n");
292 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
293 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
294 interrupt_mask);
295 return;
296 }
297
Daniel Vetterfee884e2013-07-04 23:35:21 +0200298 I915_WRITE(SDEIMR, sdeimr);
299 POSTING_READ(SDEIMR);
300}
301#define ibx_enable_display_interrupt(dev_priv, bits) \
302 ibx_display_interrupt_update((dev_priv), (bits), (bits))
303#define ibx_disable_display_interrupt(dev_priv, bits) \
304 ibx_display_interrupt_update((dev_priv), (bits), 0)
305
Daniel Vetterde280752013-07-04 23:35:24 +0200306static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
307 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300308 bool enable)
309{
Paulo Zanoni86642812013-04-12 17:57:57 -0300310 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200311 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
312 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300313
314 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200315 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300316 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200317 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300318}
319
320static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
321 enum transcoder pch_transcoder,
322 bool enable)
323{
324 struct drm_i915_private *dev_priv = dev->dev_private;
325
326 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200327 I915_WRITE(SERR_INT,
328 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
329
Paulo Zanoni86642812013-04-12 17:57:57 -0300330 if (!cpt_can_enable_serr_int(dev))
331 return;
332
Daniel Vetterfee884e2013-07-04 23:35:21 +0200333 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300334 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200335 uint32_t tmp = I915_READ(SERR_INT);
336 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
337
338 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200339 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200340
341 if (!was_enabled &&
342 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
343 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
344 transcoder_name(pch_transcoder));
345 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300346 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300347}
348
349/**
350 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
351 * @dev: drm device
352 * @pipe: pipe
353 * @enable: true if we want to report FIFO underrun errors, false otherwise
354 *
355 * This function makes us disable or enable CPU fifo underruns for a specific
356 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
357 * reporting for one pipe may also disable all the other CPU error interruts for
358 * the other pipes, due to the fact that there's just one interrupt mask/enable
359 * bit for all the pipes.
360 *
361 * Returns the previous state of underrun reporting.
362 */
363bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
364 enum pipe pipe, bool enable)
365{
366 struct drm_i915_private *dev_priv = dev->dev_private;
367 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
368 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
369 unsigned long flags;
370 bool ret;
371
372 spin_lock_irqsave(&dev_priv->irq_lock, flags);
373
374 ret = !intel_crtc->cpu_fifo_underrun_disabled;
375
376 if (enable == ret)
377 goto done;
378
379 intel_crtc->cpu_fifo_underrun_disabled = !enable;
380
381 if (IS_GEN5(dev) || IS_GEN6(dev))
382 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
383 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200384 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300385
386done:
387 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
388 return ret;
389}
390
391/**
392 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
393 * @dev: drm device
394 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
395 * @enable: true if we want to report FIFO underrun errors, false otherwise
396 *
397 * This function makes us disable or enable PCH fifo underruns for a specific
398 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
399 * underrun reporting for one transcoder may also disable all the other PCH
400 * error interruts for the other transcoders, due to the fact that there's just
401 * one interrupt mask/enable bit for all the transcoders.
402 *
403 * Returns the previous state of underrun reporting.
404 */
405bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
406 enum transcoder pch_transcoder,
407 bool enable)
408{
409 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200410 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
411 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300412 unsigned long flags;
413 bool ret;
414
Daniel Vetterde280752013-07-04 23:35:24 +0200415 /*
416 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
417 * has only one pch transcoder A that all pipes can use. To avoid racy
418 * pch transcoder -> pipe lookups from interrupt code simply store the
419 * underrun statistics in crtc A. Since we never expose this anywhere
420 * nor use it outside of the fifo underrun code here using the "wrong"
421 * crtc on LPT won't cause issues.
422 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300423
424 spin_lock_irqsave(&dev_priv->irq_lock, flags);
425
426 ret = !intel_crtc->pch_fifo_underrun_disabled;
427
428 if (enable == ret)
429 goto done;
430
431 intel_crtc->pch_fifo_underrun_disabled = !enable;
432
433 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200434 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300435 else
436 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
437
438done:
439 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
440 return ret;
441}
442
443
Keith Packard7c463582008-11-04 02:03:27 -0800444void
445i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
446{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200447 u32 reg = PIPESTAT(pipe);
448 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800449
Daniel Vetterb79480b2013-06-27 17:52:10 +0200450 assert_spin_locked(&dev_priv->irq_lock);
451
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200452 if ((pipestat & mask) == mask)
453 return;
454
455 /* Enable the interrupt, clear any pending status */
456 pipestat |= mask | (mask >> 16);
457 I915_WRITE(reg, pipestat);
458 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800459}
460
461void
462i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
463{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200464 u32 reg = PIPESTAT(pipe);
465 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800466
Daniel Vetterb79480b2013-06-27 17:52:10 +0200467 assert_spin_locked(&dev_priv->irq_lock);
468
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200469 if ((pipestat & mask) == 0)
470 return;
471
472 pipestat &= ~mask;
473 I915_WRITE(reg, pipestat);
474 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800475}
476
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000477/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300478 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000479 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300480static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000481{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000482 drm_i915_private_t *dev_priv = dev->dev_private;
483 unsigned long irqflags;
484
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300485 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
486 return;
487
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000488 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000489
Jani Nikulaf8987802013-04-29 13:02:53 +0300490 i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE);
491 if (INTEL_INFO(dev)->gen >= 4)
492 i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000493
494 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000495}
496
497/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700498 * i915_pipe_enabled - check if a pipe is enabled
499 * @dev: DRM device
500 * @pipe: pipe to check
501 *
502 * Reading certain registers when the pipe is disabled can hang the chip.
503 * Use this routine to make sure the PLL is running and the pipe is active
504 * before reading such registers if unsure.
505 */
506static int
507i915_pipe_enabled(struct drm_device *dev, int pipe)
508{
509 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200510
Daniel Vettera01025a2013-05-22 00:50:23 +0200511 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
512 /* Locking is horribly broken here, but whatever. */
513 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
514 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300515
Daniel Vettera01025a2013-05-22 00:50:23 +0200516 return intel_crtc->active;
517 } else {
518 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
519 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700520}
521
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300522static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
523{
524 /* Gen2 doesn't have a hardware frame counter */
525 return 0;
526}
527
Keith Packard42f52ef2008-10-18 19:39:29 -0700528/* Called from drm generic code, passed a 'crtc', which
529 * we use as a pipe index
530 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700531static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700532{
533 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
534 unsigned long high_frame;
535 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300536 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700537
538 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800539 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800540 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700541 return 0;
542 }
543
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300544 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
545 struct intel_crtc *intel_crtc =
546 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
547 const struct drm_display_mode *mode =
548 &intel_crtc->config.adjusted_mode;
549
550 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
551 } else {
552 enum transcoder cpu_transcoder =
553 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
554 u32 htotal;
555
556 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
557 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
558
559 vbl_start *= htotal;
560 }
561
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800562 high_frame = PIPEFRAME(pipe);
563 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100564
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700565 /*
566 * High & low register fields aren't synchronized, so make sure
567 * we get a low value that's stable across two reads of the high
568 * register.
569 */
570 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100571 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300572 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100573 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700574 } while (high1 != high2);
575
Chris Wilson5eddb702010-09-11 13:48:45 +0100576 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300577 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100578 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300579
580 /*
581 * The frame counter increments at beginning of active.
582 * Cook up a vblank counter by also checking the pixel
583 * counter against vblank start.
584 */
585 return ((high1 << 8) | low) + (pixel >= vbl_start);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700586}
587
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700588static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800589{
590 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800591 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800592
593 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800594 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800595 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800596 return 0;
597 }
598
599 return I915_READ(reg);
600}
601
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300602static bool intel_pipe_in_vblank(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300603{
604 struct drm_i915_private *dev_priv = dev->dev_private;
605 uint32_t status;
606
607 if (IS_VALLEYVIEW(dev)) {
608 status = pipe == PIPE_A ?
609 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
610 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
611
612 return I915_READ(VLV_ISR) & status;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300613 } else if (IS_GEN2(dev)) {
614 status = pipe == PIPE_A ?
615 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
616 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
617
618 return I915_READ16(ISR) & status;
619 } else if (INTEL_INFO(dev)->gen < 5) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300620 status = pipe == PIPE_A ?
621 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
622 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
623
624 return I915_READ(ISR) & status;
625 } else if (INTEL_INFO(dev)->gen < 7) {
626 status = pipe == PIPE_A ?
627 DE_PIPEA_VBLANK :
628 DE_PIPEB_VBLANK;
629
630 return I915_READ(DEISR) & status;
631 } else {
632 switch (pipe) {
633 default:
634 case PIPE_A:
635 status = DE_PIPEA_VBLANK_IVB;
636 break;
637 case PIPE_B:
638 status = DE_PIPEB_VBLANK_IVB;
639 break;
640 case PIPE_C:
641 status = DE_PIPEC_VBLANK_IVB;
642 break;
643 }
644
645 return I915_READ(DEISR) & status;
646 }
647}
648
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700649static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100650 int *vpos, int *hpos)
651{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300652 struct drm_i915_private *dev_priv = dev->dev_private;
653 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
654 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
655 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300656 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100657 int vbl_start, vbl_end, htotal, vtotal;
658 bool in_vbl = true;
659 int ret = 0;
660
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300661 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100662 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800663 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100664 return 0;
665 }
666
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300667 htotal = mode->crtc_htotal;
668 vtotal = mode->crtc_vtotal;
669 vbl_start = mode->crtc_vblank_start;
670 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100671
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300672 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
673
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300674 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100675 /* No obvious pixelcount register. Only query vertical
676 * scanout position from Display scan line register.
677 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300678 if (IS_GEN2(dev))
679 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
680 else
681 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300682
683 /*
684 * The scanline counter increments at the leading edge
685 * of hsync, ie. it completely misses the active portion
686 * of the line. Fix up the counter at both edges of vblank
687 * to get a more accurate picture whether we're in vblank
688 * or not.
689 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300690 in_vbl = intel_pipe_in_vblank(dev, pipe);
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300691 if ((in_vbl && position == vbl_start - 1) ||
692 (!in_vbl && position == vbl_end - 1))
693 position = (position + 1) % vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100694 } else {
695 /* Have access to pixelcount since start of frame.
696 * We can split this into vertical and horizontal
697 * scanout position.
698 */
699 position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
700
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300701 /* convert to pixel counts */
702 vbl_start *= htotal;
703 vbl_end *= htotal;
704 vtotal *= htotal;
705 }
706
707 in_vbl = position >= vbl_start && position < vbl_end;
708
709 /*
710 * While in vblank, position will be negative
711 * counting up towards 0 at vbl_end. And outside
712 * vblank, position will be positive counting
713 * up since vbl_end.
714 */
715 if (position >= vbl_start)
716 position -= vbl_end;
717 else
718 position += vtotal - vbl_end;
719
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300720 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300721 *vpos = position;
722 *hpos = 0;
723 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100724 *vpos = position / htotal;
725 *hpos = position - (*vpos * htotal);
726 }
727
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100728 /* In vblank? */
729 if (in_vbl)
730 ret |= DRM_SCANOUTPOS_INVBL;
731
732 return ret;
733}
734
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700735static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100736 int *max_error,
737 struct timeval *vblank_time,
738 unsigned flags)
739{
Chris Wilson4041b852011-01-22 10:07:56 +0000740 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100741
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700742 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000743 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100744 return -EINVAL;
745 }
746
747 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000748 crtc = intel_get_crtc_for_pipe(dev, pipe);
749 if (crtc == NULL) {
750 DRM_ERROR("Invalid crtc %d\n", pipe);
751 return -EINVAL;
752 }
753
754 if (!crtc->enabled) {
755 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
756 return -EBUSY;
757 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100758
759 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000760 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
761 vblank_time, flags,
762 crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100763}
764
Jani Nikula67c347f2013-09-17 14:26:34 +0300765static bool intel_hpd_irq_event(struct drm_device *dev,
766 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200767{
768 enum drm_connector_status old_status;
769
770 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
771 old_status = connector->status;
772
773 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300774 if (old_status == connector->status)
775 return false;
776
777 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200778 connector->base.id,
779 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300780 drm_get_connector_status_name(old_status),
781 drm_get_connector_status_name(connector->status));
782
783 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200784}
785
Jesse Barnes5ca58282009-03-31 14:11:15 -0700786/*
787 * Handle hotplug events outside the interrupt handler proper.
788 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200789#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
790
Jesse Barnes5ca58282009-03-31 14:11:15 -0700791static void i915_hotplug_work_func(struct work_struct *work)
792{
793 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
794 hotplug_work);
795 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700796 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200797 struct intel_connector *intel_connector;
798 struct intel_encoder *intel_encoder;
799 struct drm_connector *connector;
800 unsigned long irqflags;
801 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200802 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200803 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700804
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100805 /* HPD irq before everything is fully set up. */
806 if (!dev_priv->enable_hotplug_processing)
807 return;
808
Keith Packarda65e34c2011-07-25 10:04:56 -0700809 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800810 DRM_DEBUG_KMS("running encoder hotplug functions\n");
811
Egbert Eichcd569ae2013-04-16 13:36:57 +0200812 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200813
814 hpd_event_bits = dev_priv->hpd_event_bits;
815 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200816 list_for_each_entry(connector, &mode_config->connector_list, head) {
817 intel_connector = to_intel_connector(connector);
818 intel_encoder = intel_connector->encoder;
819 if (intel_encoder->hpd_pin > HPD_NONE &&
820 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
821 connector->polled == DRM_CONNECTOR_POLL_HPD) {
822 DRM_INFO("HPD interrupt storm detected on connector %s: "
823 "switching from hotplug detection to polling\n",
824 drm_get_connector_name(connector));
825 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
826 connector->polled = DRM_CONNECTOR_POLL_CONNECT
827 | DRM_CONNECTOR_POLL_DISCONNECT;
828 hpd_disabled = true;
829 }
Egbert Eich142e2392013-04-11 15:57:57 +0200830 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
831 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
832 drm_get_connector_name(connector), intel_encoder->hpd_pin);
833 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200834 }
835 /* if there were no outputs to poll, poll was disabled,
836 * therefore make sure it's enabled when disabling HPD on
837 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200838 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200839 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200840 mod_timer(&dev_priv->hotplug_reenable_timer,
841 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
842 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200843
844 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
845
Egbert Eich321a1b32013-04-11 16:00:26 +0200846 list_for_each_entry(connector, &mode_config->connector_list, head) {
847 intel_connector = to_intel_connector(connector);
848 intel_encoder = intel_connector->encoder;
849 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
850 if (intel_encoder->hot_plug)
851 intel_encoder->hot_plug(intel_encoder);
852 if (intel_hpd_irq_event(dev, connector))
853 changed = true;
854 }
855 }
Keith Packard40ee3382011-07-28 15:31:19 -0700856 mutex_unlock(&mode_config->mutex);
857
Egbert Eich321a1b32013-04-11 16:00:26 +0200858 if (changed)
859 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700860}
861
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200862static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800863{
864 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000865 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200866 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200867
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200868 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800869
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200870 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
871
Daniel Vetter20e4d402012-08-08 23:35:39 +0200872 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200873
Jesse Barnes7648fa92010-05-20 14:28:11 -0700874 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000875 busy_up = I915_READ(RCPREVBSYTUPAVG);
876 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800877 max_avg = I915_READ(RCBMAXAVG);
878 min_avg = I915_READ(RCBMINAVG);
879
880 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000881 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200882 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
883 new_delay = dev_priv->ips.cur_delay - 1;
884 if (new_delay < dev_priv->ips.max_delay)
885 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000886 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200887 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
888 new_delay = dev_priv->ips.cur_delay + 1;
889 if (new_delay > dev_priv->ips.min_delay)
890 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800891 }
892
Jesse Barnes7648fa92010-05-20 14:28:11 -0700893 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200894 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800895
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200896 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200897
Jesse Barnesf97108d2010-01-29 11:27:07 -0800898 return;
899}
900
Chris Wilson549f7362010-10-19 11:19:32 +0100901static void notify_ring(struct drm_device *dev,
902 struct intel_ring_buffer *ring)
903{
Chris Wilson475553d2011-01-20 09:52:56 +0000904 if (ring->obj == NULL)
905 return;
906
Chris Wilson814e9b52013-09-23 17:33:19 -0300907 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000908
Chris Wilson549f7362010-10-19 11:19:32 +0100909 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300910 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100911}
912
Ben Widawsky4912d042011-04-25 11:25:20 -0700913static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800914{
Ben Widawsky4912d042011-04-25 11:25:20 -0700915 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200916 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300917 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100918 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800919
Daniel Vetter59cdb632013-07-04 23:35:28 +0200920 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200921 pm_iir = dev_priv->rps.pm_iir;
922 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -0700923 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300924 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200925 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700926
Paulo Zanoni60611c12013-08-15 11:50:01 -0300927 /* Make sure we didn't queue anything we're not going to process. */
928 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
929
Ben Widawsky48484052013-05-28 19:22:27 -0700930 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800931 return;
932
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700933 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100934
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100935 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300936 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100937 if (adj > 0)
938 adj *= 2;
939 else
940 adj = 1;
941 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300942
943 /*
944 * For better performance, jump directly
945 * to RPe if we're below it.
946 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100947 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +0300948 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100949 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
950 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
951 new_delay = dev_priv->rps.rpe_delay;
952 else
953 new_delay = dev_priv->rps.min_delay;
954 adj = 0;
955 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
956 if (adj < 0)
957 adj *= 2;
958 else
959 adj = -1;
960 new_delay = dev_priv->rps.cur_delay + adj;
961 } else { /* unknown event */
962 new_delay = dev_priv->rps.cur_delay;
963 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800964
Ben Widawsky79249632012-09-07 19:43:42 -0700965 /* sysfs frequency interfaces may have snuck in while servicing the
966 * interrupt
967 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100968 if (new_delay < (int)dev_priv->rps.min_delay)
969 new_delay = dev_priv->rps.min_delay;
970 if (new_delay > (int)dev_priv->rps.max_delay)
971 new_delay = dev_priv->rps.max_delay;
972 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
973
974 if (IS_VALLEYVIEW(dev_priv->dev))
975 valleyview_set_rps(dev_priv->dev, new_delay);
976 else
977 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800978
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700979 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800980}
981
Ben Widawskye3689192012-05-25 16:56:22 -0700982
983/**
984 * ivybridge_parity_work - Workqueue called when a parity error interrupt
985 * occurred.
986 * @work: workqueue struct
987 *
988 * Doesn't actually do anything except notify userspace. As a consequence of
989 * this event, userspace should try to remap the bad rows since statistically
990 * it is likely the same row is more likely to go bad again.
991 */
992static void ivybridge_parity_work(struct work_struct *work)
993{
994 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +0100995 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -0700996 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -0700997 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -0700998 uint32_t misccpctl;
999 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001000 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001001
1002 /* We must turn off DOP level clock gating to access the L3 registers.
1003 * In order to prevent a get/put style interface, acquire struct mutex
1004 * any time we access those registers.
1005 */
1006 mutex_lock(&dev_priv->dev->struct_mutex);
1007
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001008 /* If we've screwed up tracking, just let the interrupt fire again */
1009 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1010 goto out;
1011
Ben Widawskye3689192012-05-25 16:56:22 -07001012 misccpctl = I915_READ(GEN7_MISCCPCTL);
1013 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1014 POSTING_READ(GEN7_MISCCPCTL);
1015
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001016 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1017 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001018
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001019 slice--;
1020 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1021 break;
1022
1023 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1024
1025 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1026
1027 error_status = I915_READ(reg);
1028 row = GEN7_PARITY_ERROR_ROW(error_status);
1029 bank = GEN7_PARITY_ERROR_BANK(error_status);
1030 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1031
1032 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1033 POSTING_READ(reg);
1034
1035 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1036 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1037 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1038 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1039 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1040 parity_event[5] = NULL;
1041
1042 kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
1043 KOBJ_CHANGE, parity_event);
1044
1045 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1046 slice, row, bank, subbank);
1047
1048 kfree(parity_event[4]);
1049 kfree(parity_event[3]);
1050 kfree(parity_event[2]);
1051 kfree(parity_event[1]);
1052 }
Ben Widawskye3689192012-05-25 16:56:22 -07001053
1054 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1055
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001056out:
1057 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001058 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001059 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001060 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1061
1062 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001063}
1064
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001065static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001066{
1067 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001068
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001069 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001070 return;
1071
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001072 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001073 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001074 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001075
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001076 iir &= GT_PARITY_ERROR(dev);
1077 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1078 dev_priv->l3_parity.which_slice |= 1 << 1;
1079
1080 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1081 dev_priv->l3_parity.which_slice |= 1 << 0;
1082
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001083 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001084}
1085
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001086static void ilk_gt_irq_handler(struct drm_device *dev,
1087 struct drm_i915_private *dev_priv,
1088 u32 gt_iir)
1089{
1090 if (gt_iir &
1091 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1092 notify_ring(dev, &dev_priv->ring[RCS]);
1093 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1094 notify_ring(dev, &dev_priv->ring[VCS]);
1095}
1096
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001097static void snb_gt_irq_handler(struct drm_device *dev,
1098 struct drm_i915_private *dev_priv,
1099 u32 gt_iir)
1100{
1101
Ben Widawskycc609d52013-05-28 19:22:29 -07001102 if (gt_iir &
1103 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001104 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001105 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001106 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001107 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001108 notify_ring(dev, &dev_priv->ring[BCS]);
1109
Ben Widawskycc609d52013-05-28 19:22:29 -07001110 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1111 GT_BSD_CS_ERROR_INTERRUPT |
1112 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001113 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1114 i915_handle_error(dev, false);
1115 }
Ben Widawskye3689192012-05-25 16:56:22 -07001116
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001117 if (gt_iir & GT_PARITY_ERROR(dev))
1118 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001119}
1120
Egbert Eichb543fb02013-04-16 13:36:54 +02001121#define HPD_STORM_DETECT_PERIOD 1000
1122#define HPD_STORM_THRESHOLD 5
1123
Daniel Vetter10a504d2013-06-27 17:52:12 +02001124static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001125 u32 hotplug_trigger,
1126 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001127{
1128 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001129 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001130 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001131
Daniel Vetter91d131d2013-06-27 17:52:14 +02001132 if (!hotplug_trigger)
1133 return;
1134
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001135 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001136 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001137
Egbert Eichb8f102e2013-07-26 14:14:24 +02001138 WARN(((hpd[i] & hotplug_trigger) &&
1139 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED),
1140 "Received HPD interrupt although disabled\n");
1141
Egbert Eichb543fb02013-04-16 13:36:54 +02001142 if (!(hpd[i] & hotplug_trigger) ||
1143 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1144 continue;
1145
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001146 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001147 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1148 dev_priv->hpd_stats[i].hpd_last_jiffies
1149 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1150 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1151 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001152 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001153 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1154 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001155 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001156 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001157 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001158 } else {
1159 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001160 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1161 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001162 }
1163 }
1164
Daniel Vetter10a504d2013-06-27 17:52:12 +02001165 if (storm_detected)
1166 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001167 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001168
Daniel Vetter645416f2013-09-02 16:22:25 +02001169 /*
1170 * Our hotplug handler can grab modeset locks (by calling down into the
1171 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1172 * queue for otherwise the flush_work in the pageflip code will
1173 * deadlock.
1174 */
1175 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001176}
1177
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001178static void gmbus_irq_handler(struct drm_device *dev)
1179{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001180 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1181
Daniel Vetter28c70f12012-12-01 13:53:45 +01001182 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001183}
1184
Daniel Vetterce99c252012-12-01 13:53:47 +01001185static void dp_aux_irq_handler(struct drm_device *dev)
1186{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001187 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1188
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001189 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001190}
1191
Shuang He8bf1e9f2013-10-15 18:55:27 +01001192#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001193static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1194 uint32_t crc0, uint32_t crc1,
1195 uint32_t crc2, uint32_t crc3,
1196 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001197{
1198 struct drm_i915_private *dev_priv = dev->dev_private;
1199 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1200 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001201 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001202
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001203 spin_lock(&pipe_crc->lock);
1204
Damien Lespiau0c912c72013-10-15 18:55:37 +01001205 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001206 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001207 DRM_ERROR("spurious interrupt\n");
1208 return;
1209 }
1210
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001211 head = pipe_crc->head;
1212 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001213
1214 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001215 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001216 DRM_ERROR("CRC buffer overflowing\n");
1217 return;
1218 }
1219
1220 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001221
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001222 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001223 entry->crc[0] = crc0;
1224 entry->crc[1] = crc1;
1225 entry->crc[2] = crc2;
1226 entry->crc[3] = crc3;
1227 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001228
1229 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001230 pipe_crc->head = head;
1231
1232 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001233
1234 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001235}
Daniel Vetter277de952013-10-18 16:37:07 +02001236#else
1237static inline void
1238display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1239 uint32_t crc0, uint32_t crc1,
1240 uint32_t crc2, uint32_t crc3,
1241 uint32_t crc4) {}
1242#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001243
Daniel Vetter277de952013-10-18 16:37:07 +02001244
1245static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001246{
1247 struct drm_i915_private *dev_priv = dev->dev_private;
1248
Daniel Vetter277de952013-10-18 16:37:07 +02001249 display_pipe_crc_irq_handler(dev, pipe,
1250 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1251 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001252}
1253
Daniel Vetter277de952013-10-18 16:37:07 +02001254static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001255{
1256 struct drm_i915_private *dev_priv = dev->dev_private;
1257
Daniel Vetter277de952013-10-18 16:37:07 +02001258 display_pipe_crc_irq_handler(dev, pipe,
1259 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1260 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1261 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1262 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1263 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001264}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001265
Daniel Vetter277de952013-10-18 16:37:07 +02001266static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001267{
1268 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001269 uint32_t res1, res2;
1270
1271 if (INTEL_INFO(dev)->gen >= 3)
1272 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1273 else
1274 res1 = 0;
1275
1276 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1277 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1278 else
1279 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001280
Daniel Vetter277de952013-10-18 16:37:07 +02001281 display_pipe_crc_irq_handler(dev, pipe,
1282 I915_READ(PIPE_CRC_RES_RED(pipe)),
1283 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1284 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1285 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001286}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001287
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001288/* The RPS events need forcewake, so we add them to a work queue and mask their
1289 * IMR bits until the work is done. Other interrupts can be processed without
1290 * the work queue. */
1291static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001292{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001293 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001294 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001295 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001296 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001297 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001298
1299 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001300 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001301
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001302 if (HAS_VEBOX(dev_priv->dev)) {
1303 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1304 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001305
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001306 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1307 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1308 i915_handle_error(dev_priv->dev, false);
1309 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001310 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001311}
1312
Daniel Vetterff1f5252012-10-02 15:10:55 +02001313static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001314{
1315 struct drm_device *dev = (struct drm_device *) arg;
1316 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1317 u32 iir, gt_iir, pm_iir;
1318 irqreturn_t ret = IRQ_NONE;
1319 unsigned long irqflags;
1320 int pipe;
1321 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001322
1323 atomic_inc(&dev_priv->irq_received);
1324
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001325 while (true) {
1326 iir = I915_READ(VLV_IIR);
1327 gt_iir = I915_READ(GTIIR);
1328 pm_iir = I915_READ(GEN6_PMIIR);
1329
1330 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1331 goto out;
1332
1333 ret = IRQ_HANDLED;
1334
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001335 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001336
1337 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1338 for_each_pipe(pipe) {
1339 int reg = PIPESTAT(pipe);
1340 pipe_stats[pipe] = I915_READ(reg);
1341
1342 /*
1343 * Clear the PIPE*STAT regs before the IIR
1344 */
1345 if (pipe_stats[pipe] & 0x8000ffff) {
1346 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1347 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1348 pipe_name(pipe));
1349 I915_WRITE(reg, pipe_stats[pipe]);
1350 }
1351 }
1352 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1353
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001354 for_each_pipe(pipe) {
1355 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1356 drm_handle_vblank(dev, pipe);
1357
1358 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1359 intel_prepare_page_flip(dev, pipe);
1360 intel_finish_page_flip(dev, pipe);
1361 }
Daniel Vetter4356d582013-10-16 22:55:55 +02001362
1363 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02001364 i9xx_pipe_crc_irq_handler(dev, pipe);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001365 }
1366
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001367 /* Consume port. Then clear IIR or we'll miss events */
1368 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1369 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001370 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001371
1372 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1373 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001374
1375 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1376
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001377 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1378 I915_READ(PORT_HOTPLUG_STAT);
1379 }
1380
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001381 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1382 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001383
Paulo Zanoni60611c12013-08-15 11:50:01 -03001384 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001385 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001386
1387 I915_WRITE(GTIIR, gt_iir);
1388 I915_WRITE(GEN6_PMIIR, pm_iir);
1389 I915_WRITE(VLV_IIR, iir);
1390 }
1391
1392out:
1393 return ret;
1394}
1395
Adam Jackson23e81d62012-06-06 15:45:44 -04001396static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001397{
1398 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001399 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001400 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001401
Daniel Vetter91d131d2013-06-27 17:52:14 +02001402 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1403
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001404 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1405 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1406 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001407 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001408 port_name(port));
1409 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001410
Daniel Vetterce99c252012-12-01 13:53:47 +01001411 if (pch_iir & SDE_AUX_MASK)
1412 dp_aux_irq_handler(dev);
1413
Jesse Barnes776ad802011-01-04 15:09:39 -08001414 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001415 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001416
1417 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1418 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1419
1420 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1421 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1422
1423 if (pch_iir & SDE_POISON)
1424 DRM_ERROR("PCH poison interrupt\n");
1425
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001426 if (pch_iir & SDE_FDI_MASK)
1427 for_each_pipe(pipe)
1428 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1429 pipe_name(pipe),
1430 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001431
1432 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1433 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1434
1435 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1436 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1437
Jesse Barnes776ad802011-01-04 15:09:39 -08001438 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001439 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1440 false))
1441 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1442
1443 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1444 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1445 false))
1446 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1447}
1448
1449static void ivb_err_int_handler(struct drm_device *dev)
1450{
1451 struct drm_i915_private *dev_priv = dev->dev_private;
1452 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001453 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001454
Paulo Zanonide032bf2013-04-12 17:57:58 -03001455 if (err_int & ERR_INT_POISON)
1456 DRM_ERROR("Poison interrupt\n");
1457
Daniel Vetter5a69b892013-10-16 22:55:52 +02001458 for_each_pipe(pipe) {
1459 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1460 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1461 false))
1462 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1463 pipe_name(pipe));
1464 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001465
Daniel Vetter5a69b892013-10-16 22:55:52 +02001466 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1467 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001468 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001469 else
Daniel Vetter277de952013-10-18 16:37:07 +02001470 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001471 }
1472 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001473
Paulo Zanoni86642812013-04-12 17:57:57 -03001474 I915_WRITE(GEN7_ERR_INT, err_int);
1475}
1476
1477static void cpt_serr_int_handler(struct drm_device *dev)
1478{
1479 struct drm_i915_private *dev_priv = dev->dev_private;
1480 u32 serr_int = I915_READ(SERR_INT);
1481
Paulo Zanonide032bf2013-04-12 17:57:58 -03001482 if (serr_int & SERR_INT_POISON)
1483 DRM_ERROR("PCH poison interrupt\n");
1484
Paulo Zanoni86642812013-04-12 17:57:57 -03001485 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1486 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1487 false))
1488 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1489
1490 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1491 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1492 false))
1493 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1494
1495 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1496 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1497 false))
1498 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1499
1500 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001501}
1502
Adam Jackson23e81d62012-06-06 15:45:44 -04001503static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1504{
1505 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1506 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001507 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001508
Daniel Vetter91d131d2013-06-27 17:52:14 +02001509 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1510
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001511 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1512 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1513 SDE_AUDIO_POWER_SHIFT_CPT);
1514 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1515 port_name(port));
1516 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001517
1518 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001519 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001520
1521 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001522 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001523
1524 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1525 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1526
1527 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1528 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1529
1530 if (pch_iir & SDE_FDI_MASK_CPT)
1531 for_each_pipe(pipe)
1532 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1533 pipe_name(pipe),
1534 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001535
1536 if (pch_iir & SDE_ERROR_CPT)
1537 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001538}
1539
Paulo Zanonic008bc62013-07-12 16:35:10 -03001540static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1541{
1542 struct drm_i915_private *dev_priv = dev->dev_private;
1543
1544 if (de_iir & DE_AUX_CHANNEL_A)
1545 dp_aux_irq_handler(dev);
1546
1547 if (de_iir & DE_GSE)
1548 intel_opregion_asle_intr(dev);
1549
1550 if (de_iir & DE_PIPEA_VBLANK)
1551 drm_handle_vblank(dev, 0);
1552
1553 if (de_iir & DE_PIPEB_VBLANK)
1554 drm_handle_vblank(dev, 1);
1555
1556 if (de_iir & DE_POISON)
1557 DRM_ERROR("Poison interrupt\n");
1558
1559 if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
1560 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1561 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1562
1563 if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
1564 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1565 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1566
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001567 if (de_iir & DE_PIPEA_CRC_DONE)
Daniel Vetter277de952013-10-18 16:37:07 +02001568 i9xx_pipe_crc_irq_handler(dev, PIPE_A);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001569
1570 if (de_iir & DE_PIPEB_CRC_DONE)
Daniel Vetter277de952013-10-18 16:37:07 +02001571 i9xx_pipe_crc_irq_handler(dev, PIPE_B);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001572
Paulo Zanonic008bc62013-07-12 16:35:10 -03001573 if (de_iir & DE_PLANEA_FLIP_DONE) {
1574 intel_prepare_page_flip(dev, 0);
1575 intel_finish_page_flip_plane(dev, 0);
1576 }
1577
1578 if (de_iir & DE_PLANEB_FLIP_DONE) {
1579 intel_prepare_page_flip(dev, 1);
1580 intel_finish_page_flip_plane(dev, 1);
1581 }
1582
1583 /* check event from PCH */
1584 if (de_iir & DE_PCH_EVENT) {
1585 u32 pch_iir = I915_READ(SDEIIR);
1586
1587 if (HAS_PCH_CPT(dev))
1588 cpt_irq_handler(dev, pch_iir);
1589 else
1590 ibx_irq_handler(dev, pch_iir);
1591
1592 /* should clear PCH hotplug event before clear CPU irq */
1593 I915_WRITE(SDEIIR, pch_iir);
1594 }
1595
1596 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1597 ironlake_rps_change_irq_handler(dev);
1598}
1599
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001600static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1601{
1602 struct drm_i915_private *dev_priv = dev->dev_private;
1603 int i;
1604
1605 if (de_iir & DE_ERR_INT_IVB)
1606 ivb_err_int_handler(dev);
1607
1608 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1609 dp_aux_irq_handler(dev);
1610
1611 if (de_iir & DE_GSE_IVB)
1612 intel_opregion_asle_intr(dev);
1613
1614 for (i = 0; i < 3; i++) {
1615 if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
1616 drm_handle_vblank(dev, i);
1617 if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
1618 intel_prepare_page_flip(dev, i);
1619 intel_finish_page_flip_plane(dev, i);
1620 }
1621 }
1622
1623 /* check event from PCH */
1624 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1625 u32 pch_iir = I915_READ(SDEIIR);
1626
1627 cpt_irq_handler(dev, pch_iir);
1628
1629 /* clear PCH hotplug event before clear CPU irq */
1630 I915_WRITE(SDEIIR, pch_iir);
1631 }
1632}
1633
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001634static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001635{
1636 struct drm_device *dev = (struct drm_device *) arg;
1637 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001638 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001639 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001640
1641 atomic_inc(&dev_priv->irq_received);
1642
Paulo Zanoni86642812013-04-12 17:57:57 -03001643 /* We get interrupts on unclaimed registers, so check for this before we
1644 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001645 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001646
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001647 /* disable master interrupt before clearing iir */
1648 de_ier = I915_READ(DEIER);
1649 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001650 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001651
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001652 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1653 * interrupts will will be stored on its back queue, and then we'll be
1654 * able to process them after we restore SDEIER (as soon as we restore
1655 * it, we'll get an interrupt if SDEIIR still has something to process
1656 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001657 if (!HAS_PCH_NOP(dev)) {
1658 sde_ier = I915_READ(SDEIER);
1659 I915_WRITE(SDEIER, 0);
1660 POSTING_READ(SDEIER);
1661 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001662
Chris Wilson0e434062012-05-09 21:45:44 +01001663 gt_iir = I915_READ(GTIIR);
1664 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001665 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001666 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001667 else
1668 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001669 I915_WRITE(GTIIR, gt_iir);
1670 ret = IRQ_HANDLED;
1671 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001672
1673 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001674 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001675 if (INTEL_INFO(dev)->gen >= 7)
1676 ivb_display_irq_handler(dev, de_iir);
1677 else
1678 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001679 I915_WRITE(DEIIR, de_iir);
1680 ret = IRQ_HANDLED;
1681 }
1682
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001683 if (INTEL_INFO(dev)->gen >= 6) {
1684 u32 pm_iir = I915_READ(GEN6_PMIIR);
1685 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001686 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001687 I915_WRITE(GEN6_PMIIR, pm_iir);
1688 ret = IRQ_HANDLED;
1689 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001690 }
1691
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001692 I915_WRITE(DEIER, de_ier);
1693 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001694 if (!HAS_PCH_NOP(dev)) {
1695 I915_WRITE(SDEIER, sde_ier);
1696 POSTING_READ(SDEIER);
1697 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001698
1699 return ret;
1700}
1701
Daniel Vetter17e1df02013-09-08 21:57:13 +02001702static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1703 bool reset_completed)
1704{
1705 struct intel_ring_buffer *ring;
1706 int i;
1707
1708 /*
1709 * Notify all waiters for GPU completion events that reset state has
1710 * been changed, and that they need to restart their wait after
1711 * checking for potential errors (and bail out to drop locks if there is
1712 * a gpu reset pending so that i915_error_work_func can acquire them).
1713 */
1714
1715 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1716 for_each_ring(ring, dev_priv, i)
1717 wake_up_all(&ring->irq_queue);
1718
1719 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1720 wake_up_all(&dev_priv->pending_flip_queue);
1721
1722 /*
1723 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1724 * reset state is cleared.
1725 */
1726 if (reset_completed)
1727 wake_up_all(&dev_priv->gpu_error.reset_queue);
1728}
1729
Jesse Barnes8a905232009-07-11 16:48:03 -04001730/**
1731 * i915_error_work_func - do process context error handling work
1732 * @work: work struct
1733 *
1734 * Fire an error uevent so userspace can see that a hang or error
1735 * was detected.
1736 */
1737static void i915_error_work_func(struct work_struct *work)
1738{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001739 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1740 work);
1741 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1742 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001743 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07001744 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1745 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1746 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02001747 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001748
Ben Gamarif316a422009-09-14 17:48:46 -04001749 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001750
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001751 /*
1752 * Note that there's only one work item which does gpu resets, so we
1753 * need not worry about concurrent gpu resets potentially incrementing
1754 * error->reset_counter twice. We only need to take care of another
1755 * racing irq/hangcheck declaring the gpu dead for a second time. A
1756 * quick check for that is good enough: schedule_work ensures the
1757 * correct ordering between hang detection and this work item, and since
1758 * the reset in-progress bit is only ever set by code outside of this
1759 * work we don't need to worry about any other races.
1760 */
1761 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001762 DRM_DEBUG_DRIVER("resetting chip\n");
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001763 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
1764 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001765
Daniel Vetter17e1df02013-09-08 21:57:13 +02001766 /*
1767 * All state reset _must_ be completed before we update the
1768 * reset counter, for otherwise waiters might miss the reset
1769 * pending state and not properly drop locks, resulting in
1770 * deadlocks with the reset work.
1771 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01001772 ret = i915_reset(dev);
1773
Daniel Vetter17e1df02013-09-08 21:57:13 +02001774 intel_display_handle_reset(dev);
1775
Daniel Vetterf69061b2012-12-06 09:01:42 +01001776 if (ret == 0) {
1777 /*
1778 * After all the gem state is reset, increment the reset
1779 * counter and wake up everyone waiting for the reset to
1780 * complete.
1781 *
1782 * Since unlock operations are a one-sided barrier only,
1783 * we need to insert a barrier here to order any seqno
1784 * updates before
1785 * the counter increment.
1786 */
1787 smp_mb__before_atomic_inc();
1788 atomic_inc(&dev_priv->gpu_error.reset_counter);
1789
1790 kobject_uevent_env(&dev->primary->kdev.kobj,
1791 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001792 } else {
1793 atomic_set(&error->reset_counter, I915_WEDGED);
Ben Gamarif316a422009-09-14 17:48:46 -04001794 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001795
Daniel Vetter17e1df02013-09-08 21:57:13 +02001796 /*
1797 * Note: The wake_up also serves as a memory barrier so that
1798 * waiters see the update value of the reset counter atomic_t.
1799 */
1800 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04001801 }
Jesse Barnes8a905232009-07-11 16:48:03 -04001802}
1803
Chris Wilson35aed2e2010-05-27 13:18:12 +01001804static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04001805{
1806 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07001807 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04001808 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07001809 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04001810
Chris Wilson35aed2e2010-05-27 13:18:12 +01001811 if (!eir)
1812 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04001813
Joe Perchesa70491c2012-03-18 13:00:11 -07001814 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04001815
Ben Widawskybd9854f2012-08-23 15:18:09 -07001816 i915_get_extra_instdone(dev, instdone);
1817
Jesse Barnes8a905232009-07-11 16:48:03 -04001818 if (IS_G4X(dev)) {
1819 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1820 u32 ipeir = I915_READ(IPEIR_I965);
1821
Joe Perchesa70491c2012-03-18 13:00:11 -07001822 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1823 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07001824 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1825 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07001826 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001827 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001828 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001829 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001830 }
1831 if (eir & GM45_ERROR_PAGE_TABLE) {
1832 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001833 pr_err("page table error\n");
1834 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001835 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001836 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001837 }
1838 }
1839
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001840 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001841 if (eir & I915_ERROR_PAGE_TABLE) {
1842 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001843 pr_err("page table error\n");
1844 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001845 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001846 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001847 }
1848 }
1849
1850 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001851 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001852 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07001853 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001854 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04001855 /* pipestat has already been acked */
1856 }
1857 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001858 pr_err("instruction error\n");
1859 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07001860 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1861 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001862 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001863 u32 ipeir = I915_READ(IPEIR);
1864
Joe Perchesa70491c2012-03-18 13:00:11 -07001865 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
1866 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07001867 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04001868 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001869 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001870 } else {
1871 u32 ipeir = I915_READ(IPEIR_I965);
1872
Joe Perchesa70491c2012-03-18 13:00:11 -07001873 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1874 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07001875 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001876 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001877 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001878 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001879 }
1880 }
1881
1882 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001883 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001884 eir = I915_READ(EIR);
1885 if (eir) {
1886 /*
1887 * some errors might have become stuck,
1888 * mask them.
1889 */
1890 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1891 I915_WRITE(EMR, I915_READ(EMR) | eir);
1892 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1893 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01001894}
1895
1896/**
1897 * i915_handle_error - handle an error interrupt
1898 * @dev: drm device
1899 *
1900 * Do some basic checking of regsiter state at error interrupt time and
1901 * dump it to the syslog. Also call i915_capture_error_state() to make
1902 * sure we get a record and make it available in debugfs. Fire a uevent
1903 * so userspace knows something bad happened (should trigger collection
1904 * of a ring dump etc.).
1905 */
Chris Wilson527f9e92010-11-11 01:16:58 +00001906void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01001907{
1908 struct drm_i915_private *dev_priv = dev->dev_private;
1909
1910 i915_capture_error_state(dev);
1911 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04001912
Ben Gamariba1234d2009-09-14 17:48:47 -04001913 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01001914 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
1915 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04001916
Ben Gamari11ed50e2009-09-14 17:48:45 -04001917 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02001918 * Wakeup waiting processes so that the reset work function
1919 * i915_error_work_func doesn't deadlock trying to grab various
1920 * locks. By bumping the reset counter first, the woken
1921 * processes will see a reset in progress and back off,
1922 * releasing their locks and then wait for the reset completion.
1923 * We must do this for _all_ gpu waiters that might hold locks
1924 * that the reset work needs to acquire.
1925 *
1926 * Note: The wake_up serves as the required memory barrier to
1927 * ensure that the waiters see the updated value of the reset
1928 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04001929 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02001930 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04001931 }
1932
Daniel Vetter122f46b2013-09-04 17:36:14 +02001933 /*
1934 * Our reset work can grab modeset locks (since it needs to reset the
1935 * state of outstanding pagelips). Hence it must not be run on our own
1936 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
1937 * code will deadlock.
1938 */
1939 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04001940}
1941
Ville Syrjälä21ad8332013-02-19 15:16:39 +02001942static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001943{
1944 drm_i915_private_t *dev_priv = dev->dev_private;
1945 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1946 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00001947 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001948 struct intel_unpin_work *work;
1949 unsigned long flags;
1950 bool stall_detected;
1951
1952 /* Ignore early vblank irqs */
1953 if (intel_crtc == NULL)
1954 return;
1955
1956 spin_lock_irqsave(&dev->event_lock, flags);
1957 work = intel_crtc->unpin_work;
1958
Chris Wilsone7d841c2012-12-03 11:36:30 +00001959 if (work == NULL ||
1960 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
1961 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001962 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1963 spin_unlock_irqrestore(&dev->event_lock, flags);
1964 return;
1965 }
1966
1967 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00001968 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001969 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001970 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07001971 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001972 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001973 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001974 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001975 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02001976 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001977 crtc->x * crtc->fb->bits_per_pixel/8);
1978 }
1979
1980 spin_unlock_irqrestore(&dev->event_lock, flags);
1981
1982 if (stall_detected) {
1983 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1984 intel_prepare_page_flip(dev, intel_crtc->plane);
1985 }
1986}
1987
Keith Packard42f52ef2008-10-18 19:39:29 -07001988/* Called from drm generic code, passed 'crtc' which
1989 * we use as a pipe index
1990 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001991static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001992{
1993 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001994 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001995
Chris Wilson5eddb702010-09-11 13:48:45 +01001996 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001997 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001998
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001999 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002000 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002001 i915_enable_pipestat(dev_priv, pipe,
2002 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07002003 else
Keith Packard7c463582008-11-04 02:03:27 -08002004 i915_enable_pipestat(dev_priv, pipe,
2005 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002006
2007 /* maintain vblank delivery even in deep C-states */
2008 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002009 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002010 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002011
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002012 return 0;
2013}
2014
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002015static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002016{
2017 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2018 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002019 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2020 DE_PIPE_VBLANK_ILK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002021
2022 if (!i915_pipe_enabled(dev, pipe))
2023 return -EINVAL;
2024
2025 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002026 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002027 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2028
2029 return 0;
2030}
2031
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002032static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2033{
2034 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2035 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002036 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002037
2038 if (!i915_pipe_enabled(dev, pipe))
2039 return -EINVAL;
2040
2041 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002042 imr = I915_READ(VLV_IMR);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002043 if (pipe == 0)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002044 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002045 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002046 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002047 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002048 i915_enable_pipestat(dev_priv, pipe,
2049 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002050 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2051
2052 return 0;
2053}
2054
Keith Packard42f52ef2008-10-18 19:39:29 -07002055/* Called from drm generic code, passed 'crtc' which
2056 * we use as a pipe index
2057 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002058static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002059{
2060 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002061 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002062
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002063 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002064 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002065 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002066
Jesse Barnesf796cf82011-04-07 13:58:17 -07002067 i915_disable_pipestat(dev_priv, pipe,
2068 PIPE_VBLANK_INTERRUPT_ENABLE |
2069 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2070 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2071}
2072
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002073static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002074{
2075 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2076 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002077 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
2078 DE_PIPE_VBLANK_ILK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002079
2080 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002081 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002082 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2083}
2084
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002085static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2086{
2087 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2088 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002089 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002090
2091 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002092 i915_disable_pipestat(dev_priv, pipe,
2093 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002094 imr = I915_READ(VLV_IMR);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002095 if (pipe == 0)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002096 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002097 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002098 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002099 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002100 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2101}
2102
Chris Wilson893eead2010-10-27 14:44:35 +01002103static u32
2104ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002105{
Chris Wilson893eead2010-10-27 14:44:35 +01002106 return list_entry(ring->request_list.prev,
2107 struct drm_i915_gem_request, list)->seqno;
2108}
2109
Chris Wilson9107e9d2013-06-10 11:20:20 +01002110static bool
2111ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002112{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002113 return (list_empty(&ring->request_list) ||
2114 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002115}
2116
Chris Wilson6274f212013-06-10 11:20:21 +01002117static struct intel_ring_buffer *
2118semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002119{
2120 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002121 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002122
2123 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2124 if ((ipehr & ~(0x3 << 16)) !=
2125 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002126 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002127
2128 /* ACTHD is likely pointing to the dword after the actual command,
2129 * so scan backwards until we find the MBOX.
2130 */
Chris Wilson6274f212013-06-10 11:20:21 +01002131 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002132 acthd_min = max((int)acthd - 3 * 4, 0);
2133 do {
2134 cmd = ioread32(ring->virtual_start + acthd);
2135 if (cmd == ipehr)
2136 break;
2137
2138 acthd -= 4;
2139 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002140 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002141 } while (1);
2142
Chris Wilson6274f212013-06-10 11:20:21 +01002143 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2144 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002145}
2146
Chris Wilson6274f212013-06-10 11:20:21 +01002147static int semaphore_passed(struct intel_ring_buffer *ring)
2148{
2149 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2150 struct intel_ring_buffer *signaller;
2151 u32 seqno, ctl;
2152
2153 ring->hangcheck.deadlock = true;
2154
2155 signaller = semaphore_waits_for(ring, &seqno);
2156 if (signaller == NULL || signaller->hangcheck.deadlock)
2157 return -1;
2158
2159 /* cursory check for an unkickable deadlock */
2160 ctl = I915_READ_CTL(signaller);
2161 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2162 return -1;
2163
2164 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2165}
2166
2167static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2168{
2169 struct intel_ring_buffer *ring;
2170 int i;
2171
2172 for_each_ring(ring, dev_priv, i)
2173 ring->hangcheck.deadlock = false;
2174}
2175
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002176static enum intel_ring_hangcheck_action
2177ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002178{
2179 struct drm_device *dev = ring->dev;
2180 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002181 u32 tmp;
2182
Chris Wilson6274f212013-06-10 11:20:21 +01002183 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002184 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002185
Chris Wilson9107e9d2013-06-10 11:20:20 +01002186 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002187 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002188
2189 /* Is the chip hanging on a WAIT_FOR_EVENT?
2190 * If so we can simply poke the RB_WAIT bit
2191 * and break the hang. This should work on
2192 * all but the second generation chipsets.
2193 */
2194 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002195 if (tmp & RING_WAIT) {
2196 DRM_ERROR("Kicking stuck wait on %s\n",
2197 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002198 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002199 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002200 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002201 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002202
Chris Wilson6274f212013-06-10 11:20:21 +01002203 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2204 switch (semaphore_passed(ring)) {
2205 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002206 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002207 case 1:
2208 DRM_ERROR("Kicking stuck semaphore on %s\n",
2209 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002210 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002211 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002212 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002213 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002214 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002215 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002216 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002217
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002218 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002219}
2220
Ben Gamarif65d9422009-09-14 17:48:44 -04002221/**
2222 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002223 * batchbuffers in a long time. We keep track per ring seqno progress and
2224 * if there are no progress, hangcheck score for that ring is increased.
2225 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2226 * we kick the ring. If we see no progress on three subsequent calls
2227 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002228 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002229static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002230{
2231 struct drm_device *dev = (struct drm_device *)data;
2232 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002233 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002234 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002235 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002236 bool stuck[I915_NUM_RINGS] = { 0 };
2237#define BUSY 1
2238#define KICK 5
2239#define HUNG 20
2240#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01002241
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002242 if (!i915_enable_hangcheck)
2243 return;
2244
Chris Wilsonb4519512012-05-11 14:29:30 +01002245 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002246 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002247 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002248
Chris Wilson6274f212013-06-10 11:20:21 +01002249 semaphore_clear_deadlocks(dev_priv);
2250
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002251 seqno = ring->get_seqno(ring, false);
2252 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002253
Chris Wilson9107e9d2013-06-10 11:20:20 +01002254 if (ring->hangcheck.seqno == seqno) {
2255 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002256 ring->hangcheck.action = HANGCHECK_IDLE;
2257
Chris Wilson9107e9d2013-06-10 11:20:20 +01002258 if (waitqueue_active(&ring->irq_queue)) {
2259 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002260 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002261 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2262 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2263 ring->name);
2264 else
2265 DRM_INFO("Fake missed irq on %s\n",
2266 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002267 wake_up_all(&ring->irq_queue);
2268 }
2269 /* Safeguard against driver failure */
2270 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002271 } else
2272 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002273 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002274 /* We always increment the hangcheck score
2275 * if the ring is busy and still processing
2276 * the same request, so that no single request
2277 * can run indefinitely (such as a chain of
2278 * batches). The only time we do not increment
2279 * the hangcheck score on this ring, if this
2280 * ring is in a legitimate wait for another
2281 * ring. In that case the waiting ring is a
2282 * victim and we want to be sure we catch the
2283 * right culprit. Then every time we do kick
2284 * the ring, add a small increment to the
2285 * score so that we can catch a batch that is
2286 * being repeatedly kicked and so responsible
2287 * for stalling the machine.
2288 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002289 ring->hangcheck.action = ring_stuck(ring,
2290 acthd);
2291
2292 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002293 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002294 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002295 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002296 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002297 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002298 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002299 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002300 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002301 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002302 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002303 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002304 stuck[i] = true;
2305 break;
2306 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002307 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002308 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002309 ring->hangcheck.action = HANGCHECK_ACTIVE;
2310
Chris Wilson9107e9d2013-06-10 11:20:20 +01002311 /* Gradually reduce the count so that we catch DoS
2312 * attempts across multiple batches.
2313 */
2314 if (ring->hangcheck.score > 0)
2315 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002316 }
2317
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002318 ring->hangcheck.seqno = seqno;
2319 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002320 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002321 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002322
Mika Kuoppala92cab732013-05-24 17:16:07 +03002323 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002324 if (ring->hangcheck.score > FIRE) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002325 DRM_INFO("%s on %s\n",
2326 stuck[i] ? "stuck" : "no progress",
2327 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002328 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002329 }
2330 }
2331
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002332 if (rings_hung)
2333 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002334
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002335 if (busy_count)
2336 /* Reset timer case chip hangs without another request
2337 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002338 i915_queue_hangcheck(dev);
2339}
2340
2341void i915_queue_hangcheck(struct drm_device *dev)
2342{
2343 struct drm_i915_private *dev_priv = dev->dev_private;
2344 if (!i915_enable_hangcheck)
2345 return;
2346
2347 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2348 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002349}
2350
Paulo Zanoni91738a92013-06-05 14:21:51 -03002351static void ibx_irq_preinstall(struct drm_device *dev)
2352{
2353 struct drm_i915_private *dev_priv = dev->dev_private;
2354
2355 if (HAS_PCH_NOP(dev))
2356 return;
2357
2358 /* south display irq */
2359 I915_WRITE(SDEIMR, 0xffffffff);
2360 /*
2361 * SDEIER is also touched by the interrupt handler to work around missed
2362 * PCH interrupts. Hence we can't update it after the interrupt handler
2363 * is enabled - instead we unconditionally enable all PCH interrupt
2364 * sources here, but then only unmask them as needed with SDEIMR.
2365 */
2366 I915_WRITE(SDEIER, 0xffffffff);
2367 POSTING_READ(SDEIER);
2368}
2369
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002370static void gen5_gt_irq_preinstall(struct drm_device *dev)
2371{
2372 struct drm_i915_private *dev_priv = dev->dev_private;
2373
2374 /* and GT */
2375 I915_WRITE(GTIMR, 0xffffffff);
2376 I915_WRITE(GTIER, 0x0);
2377 POSTING_READ(GTIER);
2378
2379 if (INTEL_INFO(dev)->gen >= 6) {
2380 /* and PM */
2381 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2382 I915_WRITE(GEN6_PMIER, 0x0);
2383 POSTING_READ(GEN6_PMIER);
2384 }
2385}
2386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387/* drm_dma.h hooks
2388*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002389static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002390{
2391 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2392
Jesse Barnes46979952011-04-07 13:53:55 -07002393 atomic_set(&dev_priv->irq_received, 0);
2394
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002395 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002396
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002397 I915_WRITE(DEIMR, 0xffffffff);
2398 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002399 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002400
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002401 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002402
Paulo Zanoni91738a92013-06-05 14:21:51 -03002403 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002404}
2405
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002406static void valleyview_irq_preinstall(struct drm_device *dev)
2407{
2408 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2409 int pipe;
2410
2411 atomic_set(&dev_priv->irq_received, 0);
2412
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002413 /* VLV magic */
2414 I915_WRITE(VLV_IMR, 0);
2415 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2416 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2417 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2418
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002419 /* and GT */
2420 I915_WRITE(GTIIR, I915_READ(GTIIR));
2421 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002422
2423 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002424
2425 I915_WRITE(DPINVGTT, 0xff);
2426
2427 I915_WRITE(PORT_HOTPLUG_EN, 0);
2428 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2429 for_each_pipe(pipe)
2430 I915_WRITE(PIPESTAT(pipe), 0xffff);
2431 I915_WRITE(VLV_IIR, 0xffffffff);
2432 I915_WRITE(VLV_IMR, 0xffffffff);
2433 I915_WRITE(VLV_IER, 0x0);
2434 POSTING_READ(VLV_IER);
2435}
2436
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002437static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002438{
2439 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002440 struct drm_mode_config *mode_config = &dev->mode_config;
2441 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002442 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002443
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002444 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002445 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002446 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002447 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002448 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002449 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002450 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002451 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002452 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002453 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002454 }
2455
Daniel Vetterfee884e2013-07-04 23:35:21 +02002456 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002457
2458 /*
2459 * Enable digital hotplug on the PCH, and configure the DP short pulse
2460 * duration to 2ms (which is the minimum in the Display Port spec)
2461 *
2462 * This register is the same on all known PCH chips.
2463 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002464 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2465 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2466 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2467 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2468 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2469 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2470}
2471
Paulo Zanonid46da432013-02-08 17:35:15 -02002472static void ibx_irq_postinstall(struct drm_device *dev)
2473{
2474 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002475 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002476
Daniel Vetter692a04c2013-05-29 21:43:05 +02002477 if (HAS_PCH_NOP(dev))
2478 return;
2479
Paulo Zanoni86642812013-04-12 17:57:57 -03002480 if (HAS_PCH_IBX(dev)) {
2481 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002482 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002483 } else {
2484 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2485
2486 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2487 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002488
Paulo Zanonid46da432013-02-08 17:35:15 -02002489 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2490 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002491}
2492
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002493static void gen5_gt_irq_postinstall(struct drm_device *dev)
2494{
2495 struct drm_i915_private *dev_priv = dev->dev_private;
2496 u32 pm_irqs, gt_irqs;
2497
2498 pm_irqs = gt_irqs = 0;
2499
2500 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002501 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002502 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002503 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2504 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002505 }
2506
2507 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2508 if (IS_GEN5(dev)) {
2509 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2510 ILK_BSD_USER_INTERRUPT;
2511 } else {
2512 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2513 }
2514
2515 I915_WRITE(GTIIR, I915_READ(GTIIR));
2516 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2517 I915_WRITE(GTIER, gt_irqs);
2518 POSTING_READ(GTIER);
2519
2520 if (INTEL_INFO(dev)->gen >= 6) {
2521 pm_irqs |= GEN6_PM_RPS_EVENTS;
2522
2523 if (HAS_VEBOX(dev))
2524 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2525
Paulo Zanoni605cd252013-08-06 18:57:15 -03002526 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002527 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002528 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002529 I915_WRITE(GEN6_PMIER, pm_irqs);
2530 POSTING_READ(GEN6_PMIER);
2531 }
2532}
2533
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002534static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002535{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002536 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002537 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002538 u32 display_mask, extra_mask;
2539
2540 if (INTEL_INFO(dev)->gen >= 7) {
2541 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2542 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2543 DE_PLANEB_FLIP_DONE_IVB |
2544 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2545 DE_ERR_INT_IVB);
2546 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2547 DE_PIPEA_VBLANK_IVB);
2548
2549 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2550 } else {
2551 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2552 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002553 DE_AUX_CHANNEL_A |
2554 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2555 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2556 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002557 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2558 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002559
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002560 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002561
2562 /* should always can generate irq */
2563 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002564 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002565 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002566 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002567
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002568 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002569
Paulo Zanonid46da432013-02-08 17:35:15 -02002570 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002571
Jesse Barnesf97108d2010-01-29 11:27:07 -08002572 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002573 /* Enable PCU event interrupts
2574 *
2575 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002576 * setup is guaranteed to run in single-threaded context. But we
2577 * need it to make the assert_spin_locked happy. */
2578 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002579 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002580 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002581 }
2582
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002583 return 0;
2584}
2585
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002586static int valleyview_irq_postinstall(struct drm_device *dev)
2587{
2588 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002589 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002590 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2591 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002592 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002593
2594 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002595 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2596 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2597 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002598 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2599
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002600 /*
2601 *Leave vblank interrupts masked initially. enable/disable will
2602 * toggle them based on usage.
2603 */
2604 dev_priv->irq_mask = (~enable_mask) |
2605 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2606 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002607
Daniel Vetter20afbda2012-12-11 14:05:07 +01002608 I915_WRITE(PORT_HOTPLUG_EN, 0);
2609 POSTING_READ(PORT_HOTPLUG_EN);
2610
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002611 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2612 I915_WRITE(VLV_IER, enable_mask);
2613 I915_WRITE(VLV_IIR, 0xffffffff);
2614 I915_WRITE(PIPESTAT(0), 0xffff);
2615 I915_WRITE(PIPESTAT(1), 0xffff);
2616 POSTING_READ(VLV_IER);
2617
Daniel Vetterb79480b2013-06-27 17:52:10 +02002618 /* Interrupt setup is already guaranteed to be single-threaded, this is
2619 * just to make the assert_spin_locked check happy. */
2620 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002621 i915_enable_pipestat(dev_priv, 0, pipestat_enable);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002622 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002623 i915_enable_pipestat(dev_priv, 1, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002624 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002625
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002626 I915_WRITE(VLV_IIR, 0xffffffff);
2627 I915_WRITE(VLV_IIR, 0xffffffff);
2628
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002629 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002630
2631 /* ack & enable invalid PTE error interrupts */
2632#if 0 /* FIXME: add support to irq handler for checking these bits */
2633 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2634 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2635#endif
2636
2637 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002638
2639 return 0;
2640}
2641
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002642static void valleyview_irq_uninstall(struct drm_device *dev)
2643{
2644 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2645 int pipe;
2646
2647 if (!dev_priv)
2648 return;
2649
Egbert Eichac4c16c2013-04-16 13:36:58 +02002650 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2651
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002652 for_each_pipe(pipe)
2653 I915_WRITE(PIPESTAT(pipe), 0xffff);
2654
2655 I915_WRITE(HWSTAM, 0xffffffff);
2656 I915_WRITE(PORT_HOTPLUG_EN, 0);
2657 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2658 for_each_pipe(pipe)
2659 I915_WRITE(PIPESTAT(pipe), 0xffff);
2660 I915_WRITE(VLV_IIR, 0xffffffff);
2661 I915_WRITE(VLV_IMR, 0xffffffff);
2662 I915_WRITE(VLV_IER, 0x0);
2663 POSTING_READ(VLV_IER);
2664}
2665
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002666static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002667{
2668 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07002669
2670 if (!dev_priv)
2671 return;
2672
Egbert Eichac4c16c2013-04-16 13:36:58 +02002673 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2674
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002675 I915_WRITE(HWSTAM, 0xffffffff);
2676
2677 I915_WRITE(DEIMR, 0xffffffff);
2678 I915_WRITE(DEIER, 0x0);
2679 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002680 if (IS_GEN7(dev))
2681 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002682
2683 I915_WRITE(GTIMR, 0xffffffff);
2684 I915_WRITE(GTIER, 0x0);
2685 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07002686
Ben Widawskyab5c6082013-04-05 13:12:41 -07002687 if (HAS_PCH_NOP(dev))
2688 return;
2689
Keith Packard192aac1f2011-09-20 10:12:44 -07002690 I915_WRITE(SDEIMR, 0xffffffff);
2691 I915_WRITE(SDEIER, 0x0);
2692 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002693 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
2694 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002695}
2696
Chris Wilsonc2798b12012-04-22 21:13:57 +01002697static void i8xx_irq_preinstall(struct drm_device * dev)
2698{
2699 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2700 int pipe;
2701
2702 atomic_set(&dev_priv->irq_received, 0);
2703
2704 for_each_pipe(pipe)
2705 I915_WRITE(PIPESTAT(pipe), 0);
2706 I915_WRITE16(IMR, 0xffff);
2707 I915_WRITE16(IER, 0x0);
2708 POSTING_READ16(IER);
2709}
2710
2711static int i8xx_irq_postinstall(struct drm_device *dev)
2712{
2713 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02002714 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002715
Chris Wilsonc2798b12012-04-22 21:13:57 +01002716 I915_WRITE16(EMR,
2717 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2718
2719 /* Unmask the interrupts that we always want on. */
2720 dev_priv->irq_mask =
2721 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2722 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2723 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2724 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2725 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2726 I915_WRITE16(IMR, dev_priv->irq_mask);
2727
2728 I915_WRITE16(IER,
2729 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2730 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2731 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2732 I915_USER_INTERRUPT);
2733 POSTING_READ16(IER);
2734
Daniel Vetter379ef822013-10-16 22:55:56 +02002735 /* Interrupt setup is already guaranteed to be single-threaded, this is
2736 * just to make the assert_spin_locked check happy. */
2737 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2738 i915_enable_pipestat(dev_priv, 0, PIPE_CRC_DONE_ENABLE);
2739 i915_enable_pipestat(dev_priv, 1, PIPE_CRC_DONE_ENABLE);
2740 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2741
Chris Wilsonc2798b12012-04-22 21:13:57 +01002742 return 0;
2743}
2744
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002745/*
2746 * Returns true when a page flip has completed.
2747 */
2748static bool i8xx_handle_vblank(struct drm_device *dev,
2749 int pipe, u16 iir)
2750{
2751 drm_i915_private_t *dev_priv = dev->dev_private;
2752 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
2753
2754 if (!drm_handle_vblank(dev, pipe))
2755 return false;
2756
2757 if ((iir & flip_pending) == 0)
2758 return false;
2759
2760 intel_prepare_page_flip(dev, pipe);
2761
2762 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2763 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2764 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2765 * the flip is completed (no longer pending). Since this doesn't raise
2766 * an interrupt per se, we watch for the change at vblank.
2767 */
2768 if (I915_READ16(ISR) & flip_pending)
2769 return false;
2770
2771 intel_finish_page_flip(dev, pipe);
2772
2773 return true;
2774}
2775
Daniel Vetterff1f5252012-10-02 15:10:55 +02002776static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01002777{
2778 struct drm_device *dev = (struct drm_device *) arg;
2779 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002780 u16 iir, new_iir;
2781 u32 pipe_stats[2];
2782 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002783 int pipe;
2784 u16 flip_mask =
2785 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2786 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
2787
2788 atomic_inc(&dev_priv->irq_received);
2789
2790 iir = I915_READ16(IIR);
2791 if (iir == 0)
2792 return IRQ_NONE;
2793
2794 while (iir & ~flip_mask) {
2795 /* Can't rely on pipestat interrupt bit in iir as it might
2796 * have been cleared after the pipestat interrupt was received.
2797 * It doesn't set the bit in iir again, but it still produces
2798 * interrupts (for non-MSI).
2799 */
2800 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2801 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2802 i915_handle_error(dev, false);
2803
2804 for_each_pipe(pipe) {
2805 int reg = PIPESTAT(pipe);
2806 pipe_stats[pipe] = I915_READ(reg);
2807
2808 /*
2809 * Clear the PIPE*STAT regs before the IIR
2810 */
2811 if (pipe_stats[pipe] & 0x8000ffff) {
2812 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2813 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2814 pipe_name(pipe));
2815 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002816 }
2817 }
2818 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2819
2820 I915_WRITE16(IIR, iir & ~flip_mask);
2821 new_iir = I915_READ16(IIR); /* Flush posted writes */
2822
Daniel Vetterd05c6172012-04-26 23:28:09 +02002823 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002824
2825 if (iir & I915_USER_INTERRUPT)
2826 notify_ring(dev, &dev_priv->ring[RCS]);
2827
Daniel Vetter4356d582013-10-16 22:55:55 +02002828 for_each_pipe(pipe) {
2829 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
2830 i8xx_handle_vblank(dev, pipe, iir))
2831 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002832
Daniel Vetter4356d582013-10-16 22:55:55 +02002833 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02002834 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02002835 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01002836
2837 iir = new_iir;
2838 }
2839
2840 return IRQ_HANDLED;
2841}
2842
2843static void i8xx_irq_uninstall(struct drm_device * dev)
2844{
2845 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2846 int pipe;
2847
Chris Wilsonc2798b12012-04-22 21:13:57 +01002848 for_each_pipe(pipe) {
2849 /* Clear enable bits; then clear status bits */
2850 I915_WRITE(PIPESTAT(pipe), 0);
2851 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2852 }
2853 I915_WRITE16(IMR, 0xffff);
2854 I915_WRITE16(IER, 0x0);
2855 I915_WRITE16(IIR, I915_READ16(IIR));
2856}
2857
Chris Wilsona266c7d2012-04-24 22:59:44 +01002858static void i915_irq_preinstall(struct drm_device * dev)
2859{
2860 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2861 int pipe;
2862
2863 atomic_set(&dev_priv->irq_received, 0);
2864
2865 if (I915_HAS_HOTPLUG(dev)) {
2866 I915_WRITE(PORT_HOTPLUG_EN, 0);
2867 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2868 }
2869
Chris Wilson00d98eb2012-04-24 22:59:48 +01002870 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002871 for_each_pipe(pipe)
2872 I915_WRITE(PIPESTAT(pipe), 0);
2873 I915_WRITE(IMR, 0xffffffff);
2874 I915_WRITE(IER, 0x0);
2875 POSTING_READ(IER);
2876}
2877
2878static int i915_irq_postinstall(struct drm_device *dev)
2879{
2880 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01002881 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002882 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002883
Chris Wilson38bde182012-04-24 22:59:50 +01002884 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2885
2886 /* Unmask the interrupts that we always want on. */
2887 dev_priv->irq_mask =
2888 ~(I915_ASLE_INTERRUPT |
2889 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2890 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2891 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2892 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2893 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2894
2895 enable_mask =
2896 I915_ASLE_INTERRUPT |
2897 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2898 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2899 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2900 I915_USER_INTERRUPT;
2901
Chris Wilsona266c7d2012-04-24 22:59:44 +01002902 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01002903 I915_WRITE(PORT_HOTPLUG_EN, 0);
2904 POSTING_READ(PORT_HOTPLUG_EN);
2905
Chris Wilsona266c7d2012-04-24 22:59:44 +01002906 /* Enable in IER... */
2907 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
2908 /* and unmask in IMR */
2909 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
2910 }
2911
Chris Wilsona266c7d2012-04-24 22:59:44 +01002912 I915_WRITE(IMR, dev_priv->irq_mask);
2913 I915_WRITE(IER, enable_mask);
2914 POSTING_READ(IER);
2915
Jani Nikulaf49e38d2013-04-29 13:02:54 +03002916 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002917
Daniel Vetter379ef822013-10-16 22:55:56 +02002918 /* Interrupt setup is already guaranteed to be single-threaded, this is
2919 * just to make the assert_spin_locked check happy. */
2920 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2921 i915_enable_pipestat(dev_priv, 0, PIPE_CRC_DONE_ENABLE);
2922 i915_enable_pipestat(dev_priv, 1, PIPE_CRC_DONE_ENABLE);
2923 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2924
Daniel Vetter20afbda2012-12-11 14:05:07 +01002925 return 0;
2926}
2927
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002928/*
2929 * Returns true when a page flip has completed.
2930 */
2931static bool i915_handle_vblank(struct drm_device *dev,
2932 int plane, int pipe, u32 iir)
2933{
2934 drm_i915_private_t *dev_priv = dev->dev_private;
2935 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
2936
2937 if (!drm_handle_vblank(dev, pipe))
2938 return false;
2939
2940 if ((iir & flip_pending) == 0)
2941 return false;
2942
2943 intel_prepare_page_flip(dev, plane);
2944
2945 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2946 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2947 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2948 * the flip is completed (no longer pending). Since this doesn't raise
2949 * an interrupt per se, we watch for the change at vblank.
2950 */
2951 if (I915_READ(ISR) & flip_pending)
2952 return false;
2953
2954 intel_finish_page_flip(dev, pipe);
2955
2956 return true;
2957}
2958
Daniel Vetterff1f5252012-10-02 15:10:55 +02002959static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01002960{
2961 struct drm_device *dev = (struct drm_device *) arg;
2962 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01002963 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01002964 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01002965 u32 flip_mask =
2966 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2967 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01002968 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002969
2970 atomic_inc(&dev_priv->irq_received);
2971
2972 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01002973 do {
2974 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01002975 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002976
2977 /* Can't rely on pipestat interrupt bit in iir as it might
2978 * have been cleared after the pipestat interrupt was received.
2979 * It doesn't set the bit in iir again, but it still produces
2980 * interrupts (for non-MSI).
2981 */
2982 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2983 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2984 i915_handle_error(dev, false);
2985
2986 for_each_pipe(pipe) {
2987 int reg = PIPESTAT(pipe);
2988 pipe_stats[pipe] = I915_READ(reg);
2989
Chris Wilson38bde182012-04-24 22:59:50 +01002990 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01002991 if (pipe_stats[pipe] & 0x8000ffff) {
2992 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2993 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2994 pipe_name(pipe));
2995 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01002996 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002997 }
2998 }
2999 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3000
3001 if (!irq_received)
3002 break;
3003
Chris Wilsona266c7d2012-04-24 22:59:44 +01003004 /* Consume port. Then clear IIR or we'll miss events */
3005 if ((I915_HAS_HOTPLUG(dev)) &&
3006 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3007 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003008 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003009
3010 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3011 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003012
3013 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3014
Chris Wilsona266c7d2012-04-24 22:59:44 +01003015 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003016 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003017 }
3018
Chris Wilson38bde182012-04-24 22:59:50 +01003019 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003020 new_iir = I915_READ(IIR); /* Flush posted writes */
3021
Chris Wilsona266c7d2012-04-24 22:59:44 +01003022 if (iir & I915_USER_INTERRUPT)
3023 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003024
Chris Wilsona266c7d2012-04-24 22:59:44 +01003025 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003026 int plane = pipe;
3027 if (IS_MOBILE(dev))
3028 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003029
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003030 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3031 i915_handle_vblank(dev, plane, pipe, iir))
3032 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003033
3034 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3035 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003036
3037 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003038 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003039 }
3040
Chris Wilsona266c7d2012-04-24 22:59:44 +01003041 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3042 intel_opregion_asle_intr(dev);
3043
3044 /* With MSI, interrupts are only generated when iir
3045 * transitions from zero to nonzero. If another bit got
3046 * set while we were handling the existing iir bits, then
3047 * we would never get another interrupt.
3048 *
3049 * This is fine on non-MSI as well, as if we hit this path
3050 * we avoid exiting the interrupt handler only to generate
3051 * another one.
3052 *
3053 * Note that for MSI this could cause a stray interrupt report
3054 * if an interrupt landed in the time between writing IIR and
3055 * the posting read. This should be rare enough to never
3056 * trigger the 99% of 100,000 interrupts test for disabling
3057 * stray interrupts.
3058 */
Chris Wilson38bde182012-04-24 22:59:50 +01003059 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003060 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003061 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003062
Daniel Vetterd05c6172012-04-26 23:28:09 +02003063 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003064
Chris Wilsona266c7d2012-04-24 22:59:44 +01003065 return ret;
3066}
3067
3068static void i915_irq_uninstall(struct drm_device * dev)
3069{
3070 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3071 int pipe;
3072
Egbert Eichac4c16c2013-04-16 13:36:58 +02003073 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3074
Chris Wilsona266c7d2012-04-24 22:59:44 +01003075 if (I915_HAS_HOTPLUG(dev)) {
3076 I915_WRITE(PORT_HOTPLUG_EN, 0);
3077 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3078 }
3079
Chris Wilson00d98eb2012-04-24 22:59:48 +01003080 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003081 for_each_pipe(pipe) {
3082 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003083 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003084 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3085 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003086 I915_WRITE(IMR, 0xffffffff);
3087 I915_WRITE(IER, 0x0);
3088
Chris Wilsona266c7d2012-04-24 22:59:44 +01003089 I915_WRITE(IIR, I915_READ(IIR));
3090}
3091
3092static void i965_irq_preinstall(struct drm_device * dev)
3093{
3094 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3095 int pipe;
3096
3097 atomic_set(&dev_priv->irq_received, 0);
3098
Chris Wilsonadca4732012-05-11 18:01:31 +01003099 I915_WRITE(PORT_HOTPLUG_EN, 0);
3100 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003101
3102 I915_WRITE(HWSTAM, 0xeffe);
3103 for_each_pipe(pipe)
3104 I915_WRITE(PIPESTAT(pipe), 0);
3105 I915_WRITE(IMR, 0xffffffff);
3106 I915_WRITE(IER, 0x0);
3107 POSTING_READ(IER);
3108}
3109
3110static int i965_irq_postinstall(struct drm_device *dev)
3111{
3112 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003113 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003114 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003115 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003116
Chris Wilsona266c7d2012-04-24 22:59:44 +01003117 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003118 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003119 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003120 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3121 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3122 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3123 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3124 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3125
3126 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003127 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3128 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003129 enable_mask |= I915_USER_INTERRUPT;
3130
3131 if (IS_G4X(dev))
3132 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003133
Daniel Vetterb79480b2013-06-27 17:52:10 +02003134 /* Interrupt setup is already guaranteed to be single-threaded, this is
3135 * just to make the assert_spin_locked check happy. */
3136 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003137 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003138 i915_enable_pipestat(dev_priv, 0, PIPE_CRC_DONE_ENABLE);
3139 i915_enable_pipestat(dev_priv, 1, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003140 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003141
Chris Wilsona266c7d2012-04-24 22:59:44 +01003142 /*
3143 * Enable some error detection, note the instruction error mask
3144 * bit is reserved, so we leave it masked.
3145 */
3146 if (IS_G4X(dev)) {
3147 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3148 GM45_ERROR_MEM_PRIV |
3149 GM45_ERROR_CP_PRIV |
3150 I915_ERROR_MEMORY_REFRESH);
3151 } else {
3152 error_mask = ~(I915_ERROR_PAGE_TABLE |
3153 I915_ERROR_MEMORY_REFRESH);
3154 }
3155 I915_WRITE(EMR, error_mask);
3156
3157 I915_WRITE(IMR, dev_priv->irq_mask);
3158 I915_WRITE(IER, enable_mask);
3159 POSTING_READ(IER);
3160
Daniel Vetter20afbda2012-12-11 14:05:07 +01003161 I915_WRITE(PORT_HOTPLUG_EN, 0);
3162 POSTING_READ(PORT_HOTPLUG_EN);
3163
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003164 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003165
3166 return 0;
3167}
3168
Egbert Eichbac56d52013-02-25 12:06:51 -05003169static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003170{
3171 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003172 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003173 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003174 u32 hotplug_en;
3175
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003176 assert_spin_locked(&dev_priv->irq_lock);
3177
Egbert Eichbac56d52013-02-25 12:06:51 -05003178 if (I915_HAS_HOTPLUG(dev)) {
3179 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3180 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3181 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003182 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003183 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3184 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3185 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003186 /* Programming the CRT detection parameters tends
3187 to generate a spurious hotplug event about three
3188 seconds later. So just do it once.
3189 */
3190 if (IS_G4X(dev))
3191 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003192 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003193 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003194
Egbert Eichbac56d52013-02-25 12:06:51 -05003195 /* Ignore TV since it's buggy */
3196 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3197 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003198}
3199
Daniel Vetterff1f5252012-10-02 15:10:55 +02003200static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003201{
3202 struct drm_device *dev = (struct drm_device *) arg;
3203 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003204 u32 iir, new_iir;
3205 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003206 unsigned long irqflags;
3207 int irq_received;
3208 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003209 u32 flip_mask =
3210 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3211 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003212
3213 atomic_inc(&dev_priv->irq_received);
3214
3215 iir = I915_READ(IIR);
3216
Chris Wilsona266c7d2012-04-24 22:59:44 +01003217 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003218 bool blc_event = false;
3219
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003220 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003221
3222 /* Can't rely on pipestat interrupt bit in iir as it might
3223 * have been cleared after the pipestat interrupt was received.
3224 * It doesn't set the bit in iir again, but it still produces
3225 * interrupts (for non-MSI).
3226 */
3227 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3228 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3229 i915_handle_error(dev, false);
3230
3231 for_each_pipe(pipe) {
3232 int reg = PIPESTAT(pipe);
3233 pipe_stats[pipe] = I915_READ(reg);
3234
3235 /*
3236 * Clear the PIPE*STAT regs before the IIR
3237 */
3238 if (pipe_stats[pipe] & 0x8000ffff) {
3239 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3240 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3241 pipe_name(pipe));
3242 I915_WRITE(reg, pipe_stats[pipe]);
3243 irq_received = 1;
3244 }
3245 }
3246 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3247
3248 if (!irq_received)
3249 break;
3250
3251 ret = IRQ_HANDLED;
3252
3253 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003254 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003255 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003256 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3257 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003258 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003259
3260 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3261 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003262
3263 intel_hpd_irq_handler(dev, hotplug_trigger,
3264 IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
3265
Chris Wilsona266c7d2012-04-24 22:59:44 +01003266 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3267 I915_READ(PORT_HOTPLUG_STAT);
3268 }
3269
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003270 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003271 new_iir = I915_READ(IIR); /* Flush posted writes */
3272
Chris Wilsona266c7d2012-04-24 22:59:44 +01003273 if (iir & I915_USER_INTERRUPT)
3274 notify_ring(dev, &dev_priv->ring[RCS]);
3275 if (iir & I915_BSD_USER_INTERRUPT)
3276 notify_ring(dev, &dev_priv->ring[VCS]);
3277
Chris Wilsona266c7d2012-04-24 22:59:44 +01003278 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003279 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003280 i915_handle_vblank(dev, pipe, pipe, iir))
3281 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003282
3283 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3284 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003285
3286 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003287 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003288 }
3289
3290
3291 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3292 intel_opregion_asle_intr(dev);
3293
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003294 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3295 gmbus_irq_handler(dev);
3296
Chris Wilsona266c7d2012-04-24 22:59:44 +01003297 /* With MSI, interrupts are only generated when iir
3298 * transitions from zero to nonzero. If another bit got
3299 * set while we were handling the existing iir bits, then
3300 * we would never get another interrupt.
3301 *
3302 * This is fine on non-MSI as well, as if we hit this path
3303 * we avoid exiting the interrupt handler only to generate
3304 * another one.
3305 *
3306 * Note that for MSI this could cause a stray interrupt report
3307 * if an interrupt landed in the time between writing IIR and
3308 * the posting read. This should be rare enough to never
3309 * trigger the 99% of 100,000 interrupts test for disabling
3310 * stray interrupts.
3311 */
3312 iir = new_iir;
3313 }
3314
Daniel Vetterd05c6172012-04-26 23:28:09 +02003315 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003316
Chris Wilsona266c7d2012-04-24 22:59:44 +01003317 return ret;
3318}
3319
3320static void i965_irq_uninstall(struct drm_device * dev)
3321{
3322 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3323 int pipe;
3324
3325 if (!dev_priv)
3326 return;
3327
Egbert Eichac4c16c2013-04-16 13:36:58 +02003328 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3329
Chris Wilsonadca4732012-05-11 18:01:31 +01003330 I915_WRITE(PORT_HOTPLUG_EN, 0);
3331 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003332
3333 I915_WRITE(HWSTAM, 0xffffffff);
3334 for_each_pipe(pipe)
3335 I915_WRITE(PIPESTAT(pipe), 0);
3336 I915_WRITE(IMR, 0xffffffff);
3337 I915_WRITE(IER, 0x0);
3338
3339 for_each_pipe(pipe)
3340 I915_WRITE(PIPESTAT(pipe),
3341 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3342 I915_WRITE(IIR, I915_READ(IIR));
3343}
3344
Egbert Eichac4c16c2013-04-16 13:36:58 +02003345static void i915_reenable_hotplug_timer_func(unsigned long data)
3346{
3347 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3348 struct drm_device *dev = dev_priv->dev;
3349 struct drm_mode_config *mode_config = &dev->mode_config;
3350 unsigned long irqflags;
3351 int i;
3352
3353 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3354 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3355 struct drm_connector *connector;
3356
3357 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3358 continue;
3359
3360 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3361
3362 list_for_each_entry(connector, &mode_config->connector_list, head) {
3363 struct intel_connector *intel_connector = to_intel_connector(connector);
3364
3365 if (intel_connector->encoder->hpd_pin == i) {
3366 if (connector->polled != intel_connector->polled)
3367 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3368 drm_get_connector_name(connector));
3369 connector->polled = intel_connector->polled;
3370 if (!connector->polled)
3371 connector->polled = DRM_CONNECTOR_POLL_HPD;
3372 }
3373 }
3374 }
3375 if (dev_priv->display.hpd_irq_setup)
3376 dev_priv->display.hpd_irq_setup(dev);
3377 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3378}
3379
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003380void intel_irq_init(struct drm_device *dev)
3381{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003382 struct drm_i915_private *dev_priv = dev->dev_private;
3383
3384 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003385 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003386 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003387 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003388
Daniel Vetter99584db2012-11-14 17:14:04 +01003389 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3390 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003391 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003392 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3393 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003394
Tomas Janousek97a19a22012-12-08 13:48:13 +01003395 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003396
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003397 if (IS_GEN2(dev)) {
3398 dev->max_vblank_count = 0;
3399 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3400 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003401 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3402 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003403 } else {
3404 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3405 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003406 }
3407
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003408 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003409 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003410 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3411 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003412
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003413 if (IS_VALLEYVIEW(dev)) {
3414 dev->driver->irq_handler = valleyview_irq_handler;
3415 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3416 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3417 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3418 dev->driver->enable_vblank = valleyview_enable_vblank;
3419 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003420 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003421 } else if (HAS_PCH_SPLIT(dev)) {
3422 dev->driver->irq_handler = ironlake_irq_handler;
3423 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3424 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3425 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3426 dev->driver->enable_vblank = ironlake_enable_vblank;
3427 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003428 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003429 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003430 if (INTEL_INFO(dev)->gen == 2) {
3431 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3432 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3433 dev->driver->irq_handler = i8xx_irq_handler;
3434 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003435 } else if (INTEL_INFO(dev)->gen == 3) {
3436 dev->driver->irq_preinstall = i915_irq_preinstall;
3437 dev->driver->irq_postinstall = i915_irq_postinstall;
3438 dev->driver->irq_uninstall = i915_irq_uninstall;
3439 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003440 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003441 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003442 dev->driver->irq_preinstall = i965_irq_preinstall;
3443 dev->driver->irq_postinstall = i965_irq_postinstall;
3444 dev->driver->irq_uninstall = i965_irq_uninstall;
3445 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003446 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003447 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003448 dev->driver->enable_vblank = i915_enable_vblank;
3449 dev->driver->disable_vblank = i915_disable_vblank;
3450 }
3451}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003452
3453void intel_hpd_init(struct drm_device *dev)
3454{
3455 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003456 struct drm_mode_config *mode_config = &dev->mode_config;
3457 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003458 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003459 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003460
Egbert Eich821450c2013-04-16 13:36:55 +02003461 for (i = 1; i < HPD_NUM_PINS; i++) {
3462 dev_priv->hpd_stats[i].hpd_cnt = 0;
3463 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3464 }
3465 list_for_each_entry(connector, &mode_config->connector_list, head) {
3466 struct intel_connector *intel_connector = to_intel_connector(connector);
3467 connector->polled = intel_connector->polled;
3468 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3469 connector->polled = DRM_CONNECTOR_POLL_HPD;
3470 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003471
3472 /* Interrupt setup is already guaranteed to be single-threaded, this is
3473 * just to make the assert_spin_locked checks happy. */
3474 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003475 if (dev_priv->display.hpd_irq_setup)
3476 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003477 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003478}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003479
3480/* Disable interrupts so we can allow Package C8+. */
3481void hsw_pc8_disable_interrupts(struct drm_device *dev)
3482{
3483 struct drm_i915_private *dev_priv = dev->dev_private;
3484 unsigned long irqflags;
3485
3486 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3487
3488 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3489 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3490 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3491 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3492 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3493
3494 ironlake_disable_display_irq(dev_priv, ~DE_PCH_EVENT_IVB);
3495 ibx_disable_display_interrupt(dev_priv, ~SDE_HOTPLUG_MASK_CPT);
3496 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3497 snb_disable_pm_irq(dev_priv, 0xffffffff);
3498
3499 dev_priv->pc8.irqs_disabled = true;
3500
3501 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3502}
3503
3504/* Restore interrupts so we can recover from Package C8+. */
3505void hsw_pc8_restore_interrupts(struct drm_device *dev)
3506{
3507 struct drm_i915_private *dev_priv = dev->dev_private;
3508 unsigned long irqflags;
3509 uint32_t val, expected;
3510
3511 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3512
3513 val = I915_READ(DEIMR);
3514 expected = ~DE_PCH_EVENT_IVB;
3515 WARN(val != expected, "DEIMR is 0x%08x, not 0x%08x\n", val, expected);
3516
3517 val = I915_READ(SDEIMR) & ~SDE_HOTPLUG_MASK_CPT;
3518 expected = ~SDE_HOTPLUG_MASK_CPT;
3519 WARN(val != expected, "SDEIMR non-HPD bits are 0x%08x, not 0x%08x\n",
3520 val, expected);
3521
3522 val = I915_READ(GTIMR);
3523 expected = 0xffffffff;
3524 WARN(val != expected, "GTIMR is 0x%08x, not 0x%08x\n", val, expected);
3525
3526 val = I915_READ(GEN6_PMIMR);
3527 expected = 0xffffffff;
3528 WARN(val != expected, "GEN6_PMIMR is 0x%08x, not 0x%08x\n", val,
3529 expected);
3530
3531 dev_priv->pc8.irqs_disabled = false;
3532
3533 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
3534 ibx_enable_display_interrupt(dev_priv,
3535 ~dev_priv->pc8.regsave.sdeimr &
3536 ~SDE_HOTPLUG_MASK_CPT);
3537 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3538 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3539 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3540
3541 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3542}