blob: c28e0dae38f7cdec251f9b265ce1ca8f85f42890 [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
Daniel Vetter704cfb82013-12-18 09:08:43 +010065static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050066 [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
Paulo Zanoni5c502442014-04-01 15:37:11 -030083/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -030084#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -030085 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
86 POSTING_READ(GEN8_##type##_IMR(which)); \
87 I915_WRITE(GEN8_##type##_IER(which), 0); \
88 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
89 POSTING_READ(GEN8_##type##_IIR(which)); \
90 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
91 POSTING_READ(GEN8_##type##_IIR(which)); \
92} while (0)
93
Paulo Zanonif86f3fb2014-04-01 15:37:14 -030094#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -030095 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -030096 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -030097 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -030098 I915_WRITE(type##IIR, 0xffffffff); \
99 POSTING_READ(type##IIR); \
100 I915_WRITE(type##IIR, 0xffffffff); \
101 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300102} while (0)
103
Paulo Zanoni337ba012014-04-01 15:37:16 -0300104/*
105 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
106 */
107#define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
108 u32 val = I915_READ(reg); \
109 if (val) { \
110 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
111 (reg), val); \
112 I915_WRITE((reg), 0xffffffff); \
113 POSTING_READ(reg); \
114 I915_WRITE((reg), 0xffffffff); \
115 POSTING_READ(reg); \
116 } \
117} while (0)
118
Paulo Zanoni35079892014-04-01 15:37:15 -0300119#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300120 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300121 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
122 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
123 POSTING_READ(GEN8_##type##_IER(which)); \
124} while (0)
125
126#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300127 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300128 I915_WRITE(type##IMR, (imr_val)); \
129 I915_WRITE(type##IER, (ier_val)); \
130 POSTING_READ(type##IER); \
131} while (0)
132
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800133/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +0100134static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300135ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800136{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200137 assert_spin_locked(&dev_priv->irq_lock);
138
Paulo Zanoni730488b2014-03-07 20:12:32 -0300139 if (WARN_ON(dev_priv->pm.irqs_disabled))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300140 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300141
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000142 if ((dev_priv->irq_mask & mask) != 0) {
143 dev_priv->irq_mask &= ~mask;
144 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000145 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800146 }
147}
148
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300149static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300150ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800151{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200152 assert_spin_locked(&dev_priv->irq_lock);
153
Paulo Zanoni730488b2014-03-07 20:12:32 -0300154 if (WARN_ON(dev_priv->pm.irqs_disabled))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300155 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300156
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000157 if ((dev_priv->irq_mask & mask) != mask) {
158 dev_priv->irq_mask |= mask;
159 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000160 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800161 }
162}
163
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300164/**
165 * ilk_update_gt_irq - update GTIMR
166 * @dev_priv: driver private
167 * @interrupt_mask: mask of interrupt bits to update
168 * @enabled_irq_mask: mask of interrupt bits to enable
169 */
170static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
171 uint32_t interrupt_mask,
172 uint32_t enabled_irq_mask)
173{
174 assert_spin_locked(&dev_priv->irq_lock);
175
Paulo Zanoni730488b2014-03-07 20:12:32 -0300176 if (WARN_ON(dev_priv->pm.irqs_disabled))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300177 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300178
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300179 dev_priv->gt_irq_mask &= ~interrupt_mask;
180 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
181 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
182 POSTING_READ(GTIMR);
183}
184
185void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
186{
187 ilk_update_gt_irq(dev_priv, mask, mask);
188}
189
190void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
191{
192 ilk_update_gt_irq(dev_priv, mask, 0);
193}
194
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300195/**
196 * snb_update_pm_irq - update GEN6_PMIMR
197 * @dev_priv: driver private
198 * @interrupt_mask: mask of interrupt bits to update
199 * @enabled_irq_mask: mask of interrupt bits to enable
200 */
201static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
202 uint32_t interrupt_mask,
203 uint32_t enabled_irq_mask)
204{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300205 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300206
207 assert_spin_locked(&dev_priv->irq_lock);
208
Paulo Zanoni730488b2014-03-07 20:12:32 -0300209 if (WARN_ON(dev_priv->pm.irqs_disabled))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300210 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300211
Paulo Zanoni605cd252013-08-06 18:57:15 -0300212 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300213 new_val &= ~interrupt_mask;
214 new_val |= (~enabled_irq_mask & interrupt_mask);
215
Paulo Zanoni605cd252013-08-06 18:57:15 -0300216 if (new_val != dev_priv->pm_irq_mask) {
217 dev_priv->pm_irq_mask = new_val;
218 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300219 POSTING_READ(GEN6_PMIMR);
220 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300221}
222
223void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
224{
225 snb_update_pm_irq(dev_priv, mask, mask);
226}
227
228void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
229{
230 snb_update_pm_irq(dev_priv, mask, 0);
231}
232
Paulo Zanoni86642812013-04-12 17:57:57 -0300233static bool ivb_can_enable_err_int(struct drm_device *dev)
234{
235 struct drm_i915_private *dev_priv = dev->dev_private;
236 struct intel_crtc *crtc;
237 enum pipe pipe;
238
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200239 assert_spin_locked(&dev_priv->irq_lock);
240
Paulo Zanoni86642812013-04-12 17:57:57 -0300241 for_each_pipe(pipe) {
242 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
243
244 if (crtc->cpu_fifo_underrun_disabled)
245 return false;
246 }
247
248 return true;
249}
250
Ben Widawsky09610212014-05-15 20:58:08 +0300251/**
252 * bdw_update_pm_irq - update GT interrupt 2
253 * @dev_priv: driver private
254 * @interrupt_mask: mask of interrupt bits to update
255 * @enabled_irq_mask: mask of interrupt bits to enable
256 *
257 * Copied from the snb function, updated with relevant register offsets
258 */
259static void bdw_update_pm_irq(struct drm_i915_private *dev_priv,
260 uint32_t interrupt_mask,
261 uint32_t enabled_irq_mask)
262{
263 uint32_t new_val;
264
265 assert_spin_locked(&dev_priv->irq_lock);
266
267 if (WARN_ON(dev_priv->pm.irqs_disabled))
268 return;
269
270 new_val = dev_priv->pm_irq_mask;
271 new_val &= ~interrupt_mask;
272 new_val |= (~enabled_irq_mask & interrupt_mask);
273
274 if (new_val != dev_priv->pm_irq_mask) {
275 dev_priv->pm_irq_mask = new_val;
276 I915_WRITE(GEN8_GT_IMR(2), dev_priv->pm_irq_mask);
277 POSTING_READ(GEN8_GT_IMR(2));
278 }
279}
280
281void bdw_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
282{
283 bdw_update_pm_irq(dev_priv, mask, mask);
284}
285
286void bdw_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
287{
288 bdw_update_pm_irq(dev_priv, mask, 0);
289}
290
Paulo Zanoni86642812013-04-12 17:57:57 -0300291static bool cpt_can_enable_serr_int(struct drm_device *dev)
292{
293 struct drm_i915_private *dev_priv = dev->dev_private;
294 enum pipe pipe;
295 struct intel_crtc *crtc;
296
Daniel Vetterfee884e2013-07-04 23:35:21 +0200297 assert_spin_locked(&dev_priv->irq_lock);
298
Paulo Zanoni86642812013-04-12 17:57:57 -0300299 for_each_pipe(pipe) {
300 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
301
302 if (crtc->pch_fifo_underrun_disabled)
303 return false;
304 }
305
306 return true;
307}
308
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300309void i9xx_check_fifo_underruns(struct drm_device *dev)
310{
311 struct drm_i915_private *dev_priv = dev->dev_private;
312 struct intel_crtc *crtc;
313 unsigned long flags;
314
315 spin_lock_irqsave(&dev_priv->irq_lock, flags);
316
317 for_each_intel_crtc(dev, crtc) {
318 u32 reg = PIPESTAT(crtc->pipe);
319 u32 pipestat;
320
321 if (crtc->cpu_fifo_underrun_disabled)
322 continue;
323
324 pipestat = I915_READ(reg) & 0xffff0000;
325 if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
326 continue;
327
328 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
329 POSTING_READ(reg);
330
331 DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
332 }
333
334 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
335}
336
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300337static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
338 enum pipe pipe, bool enable)
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200339{
340 struct drm_i915_private *dev_priv = dev->dev_private;
341 u32 reg = PIPESTAT(pipe);
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300342 u32 pipestat = I915_READ(reg) & 0xffff0000;
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200343
344 assert_spin_locked(&dev_priv->irq_lock);
345
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300346 if (enable) {
347 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
348 POSTING_READ(reg);
349 } else {
350 if (pipestat & PIPE_FIFO_UNDERRUN_STATUS)
351 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
352 }
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200353}
354
Paulo Zanoni86642812013-04-12 17:57:57 -0300355static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
356 enum pipe pipe, bool enable)
357{
358 struct drm_i915_private *dev_priv = dev->dev_private;
359 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
360 DE_PIPEB_FIFO_UNDERRUN;
361
362 if (enable)
363 ironlake_enable_display_irq(dev_priv, bit);
364 else
365 ironlake_disable_display_irq(dev_priv, bit);
366}
367
368static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200369 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300370{
371 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300372 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200373 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
374
Paulo Zanoni86642812013-04-12 17:57:57 -0300375 if (!ivb_can_enable_err_int(dev))
376 return;
377
Paulo Zanoni86642812013-04-12 17:57:57 -0300378 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
379 } else {
380 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200381
Ville Syrjälä29c6b0c2014-05-16 19:40:24 +0300382 if (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300383 DRM_ERROR("uncleared fifo underrun on pipe %c\n",
384 pipe_name(pipe));
Daniel Vetter7336df62013-07-09 22:59:16 +0200385 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300386 }
387}
388
Daniel Vetter38d83c962013-11-07 11:05:46 +0100389static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
390 enum pipe pipe, bool enable)
391{
392 struct drm_i915_private *dev_priv = dev->dev_private;
393
394 assert_spin_locked(&dev_priv->irq_lock);
395
396 if (enable)
397 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
398 else
399 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
400 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
401 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
402}
403
Daniel Vetterfee884e2013-07-04 23:35:21 +0200404/**
405 * ibx_display_interrupt_update - update SDEIMR
406 * @dev_priv: driver private
407 * @interrupt_mask: mask of interrupt bits to update
408 * @enabled_irq_mask: mask of interrupt bits to enable
409 */
410static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
411 uint32_t interrupt_mask,
412 uint32_t enabled_irq_mask)
413{
414 uint32_t sdeimr = I915_READ(SDEIMR);
415 sdeimr &= ~interrupt_mask;
416 sdeimr |= (~enabled_irq_mask & interrupt_mask);
417
418 assert_spin_locked(&dev_priv->irq_lock);
419
Paulo Zanoni730488b2014-03-07 20:12:32 -0300420 if (WARN_ON(dev_priv->pm.irqs_disabled))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300421 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300422
Daniel Vetterfee884e2013-07-04 23:35:21 +0200423 I915_WRITE(SDEIMR, sdeimr);
424 POSTING_READ(SDEIMR);
425}
426#define ibx_enable_display_interrupt(dev_priv, bits) \
427 ibx_display_interrupt_update((dev_priv), (bits), (bits))
428#define ibx_disable_display_interrupt(dev_priv, bits) \
429 ibx_display_interrupt_update((dev_priv), (bits), 0)
430
Daniel Vetterde280752013-07-04 23:35:24 +0200431static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
432 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300433 bool enable)
434{
Paulo Zanoni86642812013-04-12 17:57:57 -0300435 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200436 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
437 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300438
439 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200440 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300441 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200442 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300443}
444
445static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
446 enum transcoder pch_transcoder,
447 bool enable)
448{
449 struct drm_i915_private *dev_priv = dev->dev_private;
450
451 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200452 I915_WRITE(SERR_INT,
453 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
454
Paulo Zanoni86642812013-04-12 17:57:57 -0300455 if (!cpt_can_enable_serr_int(dev))
456 return;
457
Daniel Vetterfee884e2013-07-04 23:35:21 +0200458 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300459 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +0200460 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200461
Ville Syrjälä29c6b0c2014-05-16 19:40:24 +0300462 if (I915_READ(SERR_INT) & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300463 DRM_ERROR("uncleared pch fifo underrun on pch transcoder %c\n",
464 transcoder_name(pch_transcoder));
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200465 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300466 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300467}
468
469/**
470 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
471 * @dev: drm device
472 * @pipe: pipe
473 * @enable: true if we want to report FIFO underrun errors, false otherwise
474 *
475 * This function makes us disable or enable CPU fifo underruns for a specific
476 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
477 * reporting for one pipe may also disable all the other CPU error interruts for
478 * the other pipes, due to the fact that there's just one interrupt mask/enable
479 * bit for all the pipes.
480 *
481 * Returns the previous state of underrun reporting.
482 */
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +0200483static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
484 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300485{
486 struct drm_i915_private *dev_priv = dev->dev_private;
487 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
488 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300489 bool ret;
490
Imre Deak77961eb2014-03-05 16:20:56 +0200491 assert_spin_locked(&dev_priv->irq_lock);
492
Paulo Zanoni86642812013-04-12 17:57:57 -0300493 ret = !intel_crtc->cpu_fifo_underrun_disabled;
494
495 if (enable == ret)
496 goto done;
497
498 intel_crtc->cpu_fifo_underrun_disabled = !enable;
499
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300500 if (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev))
501 i9xx_set_fifo_underrun_reporting(dev, pipe, enable);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200502 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300503 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
504 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200505 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100506 else if (IS_GEN8(dev))
507 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300508
509done:
Imre Deakf88d42f2014-03-04 19:23:09 +0200510 return ret;
511}
512
513bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
514 enum pipe pipe, bool enable)
515{
516 struct drm_i915_private *dev_priv = dev->dev_private;
517 unsigned long flags;
518 bool ret;
519
520 spin_lock_irqsave(&dev_priv->irq_lock, flags);
521 ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300522 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Imre Deakf88d42f2014-03-04 19:23:09 +0200523
Paulo Zanoni86642812013-04-12 17:57:57 -0300524 return ret;
525}
526
Imre Deak91d181d2014-02-10 18:42:49 +0200527static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
528 enum pipe pipe)
529{
530 struct drm_i915_private *dev_priv = dev->dev_private;
531 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
532 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
533
534 return !intel_crtc->cpu_fifo_underrun_disabled;
535}
536
Paulo Zanoni86642812013-04-12 17:57:57 -0300537/**
538 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
539 * @dev: drm device
540 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
541 * @enable: true if we want to report FIFO underrun errors, false otherwise
542 *
543 * This function makes us disable or enable PCH fifo underruns for a specific
544 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
545 * underrun reporting for one transcoder may also disable all the other PCH
546 * error interruts for the other transcoders, due to the fact that there's just
547 * one interrupt mask/enable bit for all the transcoders.
548 *
549 * Returns the previous state of underrun reporting.
550 */
551bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
552 enum transcoder pch_transcoder,
553 bool enable)
554{
555 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200556 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
557 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300558 unsigned long flags;
559 bool ret;
560
Daniel Vetterde280752013-07-04 23:35:24 +0200561 /*
562 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
563 * has only one pch transcoder A that all pipes can use. To avoid racy
564 * pch transcoder -> pipe lookups from interrupt code simply store the
565 * underrun statistics in crtc A. Since we never expose this anywhere
566 * nor use it outside of the fifo underrun code here using the "wrong"
567 * crtc on LPT won't cause issues.
568 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300569
570 spin_lock_irqsave(&dev_priv->irq_lock, flags);
571
572 ret = !intel_crtc->pch_fifo_underrun_disabled;
573
574 if (enable == ret)
575 goto done;
576
577 intel_crtc->pch_fifo_underrun_disabled = !enable;
578
579 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200580 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300581 else
582 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
583
584done:
585 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
586 return ret;
587}
588
589
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100590static void
Imre Deak755e9012014-02-10 18:42:47 +0200591__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
592 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800593{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200594 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200595 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800596
Daniel Vetterb79480b2013-06-27 17:52:10 +0200597 assert_spin_locked(&dev_priv->irq_lock);
598
Ville Syrjälä04feced2014-04-03 13:28:33 +0300599 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
600 status_mask & ~PIPESTAT_INT_STATUS_MASK,
601 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
602 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200603 return;
604
605 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200606 return;
607
Imre Deak91d181d2014-02-10 18:42:49 +0200608 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
609
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200610 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200611 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200612 I915_WRITE(reg, pipestat);
613 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800614}
615
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100616static void
Imre Deak755e9012014-02-10 18:42:47 +0200617__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
618 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800619{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200620 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200621 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800622
Daniel Vetterb79480b2013-06-27 17:52:10 +0200623 assert_spin_locked(&dev_priv->irq_lock);
624
Ville Syrjälä04feced2014-04-03 13:28:33 +0300625 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
626 status_mask & ~PIPESTAT_INT_STATUS_MASK,
627 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
628 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200629 return;
630
Imre Deak755e9012014-02-10 18:42:47 +0200631 if ((pipestat & enable_mask) == 0)
632 return;
633
Imre Deak91d181d2014-02-10 18:42:49 +0200634 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
635
Imre Deak755e9012014-02-10 18:42:47 +0200636 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200637 I915_WRITE(reg, pipestat);
638 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800639}
640
Imre Deak10c59c52014-02-10 18:42:48 +0200641static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
642{
643 u32 enable_mask = status_mask << 16;
644
645 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300646 * On pipe A we don't support the PSR interrupt yet,
647 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200648 */
649 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
650 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300651 /*
652 * On pipe B and C we don't support the PSR interrupt yet, on pipe
653 * A the same bit is for perf counters which we don't use either.
654 */
655 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
656 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200657
658 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
659 SPRITE0_FLIP_DONE_INT_EN_VLV |
660 SPRITE1_FLIP_DONE_INT_EN_VLV);
661 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
662 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
663 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
664 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
665
666 return enable_mask;
667}
668
Imre Deak755e9012014-02-10 18:42:47 +0200669void
670i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
671 u32 status_mask)
672{
673 u32 enable_mask;
674
Imre Deak10c59c52014-02-10 18:42:48 +0200675 if (IS_VALLEYVIEW(dev_priv->dev))
676 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
677 status_mask);
678 else
679 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200680 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
681}
682
683void
684i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
685 u32 status_mask)
686{
687 u32 enable_mask;
688
Imre Deak10c59c52014-02-10 18:42:48 +0200689 if (IS_VALLEYVIEW(dev_priv->dev))
690 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
691 status_mask);
692 else
693 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200694 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
695}
696
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000697/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300698 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000699 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300700static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000701{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300702 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000703 unsigned long irqflags;
704
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300705 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
706 return;
707
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000708 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000709
Imre Deak755e9012014-02-10 18:42:47 +0200710 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300711 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200712 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200713 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000714
715 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000716}
717
718/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700719 * i915_pipe_enabled - check if a pipe is enabled
720 * @dev: DRM device
721 * @pipe: pipe to check
722 *
723 * Reading certain registers when the pipe is disabled can hang the chip.
724 * Use this routine to make sure the PLL is running and the pipe is active
725 * before reading such registers if unsure.
726 */
727static int
728i915_pipe_enabled(struct drm_device *dev, int pipe)
729{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300730 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200731
Daniel Vettera01025a2013-05-22 00:50:23 +0200732 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
733 /* Locking is horribly broken here, but whatever. */
734 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
735 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300736
Daniel Vettera01025a2013-05-22 00:50:23 +0200737 return intel_crtc->active;
738 } else {
739 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
740 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700741}
742
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300743/*
744 * This timing diagram depicts the video signal in and
745 * around the vertical blanking period.
746 *
747 * Assumptions about the fictitious mode used in this example:
748 * vblank_start >= 3
749 * vsync_start = vblank_start + 1
750 * vsync_end = vblank_start + 2
751 * vtotal = vblank_start + 3
752 *
753 * start of vblank:
754 * latch double buffered registers
755 * increment frame counter (ctg+)
756 * generate start of vblank interrupt (gen4+)
757 * |
758 * | frame start:
759 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
760 * | may be shifted forward 1-3 extra lines via PIPECONF
761 * | |
762 * | | start of vsync:
763 * | | generate vsync interrupt
764 * | | |
765 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
766 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
767 * ----va---> <-----------------vb--------------------> <--------va-------------
768 * | | <----vs-----> |
769 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
770 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
771 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
772 * | | |
773 * last visible pixel first visible pixel
774 * | increment frame counter (gen3/4)
775 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
776 *
777 * x = horizontal active
778 * _ = horizontal blanking
779 * hs = horizontal sync
780 * va = vertical active
781 * vb = vertical blanking
782 * vs = vertical sync
783 * vbs = vblank_start (number)
784 *
785 * Summary:
786 * - most events happen at the start of horizontal sync
787 * - frame start happens at the start of horizontal blank, 1-4 lines
788 * (depending on PIPECONF settings) after the start of vblank
789 * - gen3/4 pixel and frame counter are synchronized with the start
790 * of horizontal active on the first line of vertical active
791 */
792
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300793static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
794{
795 /* Gen2 doesn't have a hardware frame counter */
796 return 0;
797}
798
Keith Packard42f52ef2008-10-18 19:39:29 -0700799/* Called from drm generic code, passed a 'crtc', which
800 * we use as a pipe index
801 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700802static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700803{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300804 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700805 unsigned long high_frame;
806 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300807 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700808
809 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800810 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800811 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700812 return 0;
813 }
814
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300815 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
816 struct intel_crtc *intel_crtc =
817 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
818 const struct drm_display_mode *mode =
819 &intel_crtc->config.adjusted_mode;
820
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300821 htotal = mode->crtc_htotal;
822 hsync_start = mode->crtc_hsync_start;
823 vbl_start = mode->crtc_vblank_start;
824 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
825 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300826 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100827 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300828
829 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300830 hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300831 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300832 if ((I915_READ(PIPECONF(cpu_transcoder)) &
833 PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE)
834 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300835 }
836
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300837 /* Convert to pixel count */
838 vbl_start *= htotal;
839
840 /* Start of vblank event occurs at start of hsync */
841 vbl_start -= htotal - hsync_start;
842
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800843 high_frame = PIPEFRAME(pipe);
844 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100845
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700846 /*
847 * High & low register fields aren't synchronized, so make sure
848 * we get a low value that's stable across two reads of the high
849 * register.
850 */
851 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100852 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300853 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100854 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700855 } while (high1 != high2);
856
Chris Wilson5eddb702010-09-11 13:48:45 +0100857 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300858 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100859 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300860
861 /*
862 * The frame counter increments at beginning of active.
863 * Cook up a vblank counter by also checking the pixel
864 * counter against vblank start.
865 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200866 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700867}
868
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700869static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800870{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300871 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800872 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800873
874 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800875 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800876 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800877 return 0;
878 }
879
880 return I915_READ(reg);
881}
882
Mario Kleinerad3543e2013-10-30 05:13:08 +0100883/* raw reads, only for fast reads of display block, no need for forcewake etc. */
884#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100885
Ville Syrjäläa225f072014-04-29 13:35:45 +0300886static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
887{
888 struct drm_device *dev = crtc->base.dev;
889 struct drm_i915_private *dev_priv = dev->dev_private;
890 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
891 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300892 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300893
Ville Syrjälä80715b22014-05-15 20:23:23 +0300894 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300895 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
896 vtotal /= 2;
897
898 if (IS_GEN2(dev))
899 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
900 else
901 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
902
903 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300904 * See update_scanline_offset() for the details on the
905 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300906 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300907 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300908}
909
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700910static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200911 unsigned int flags, int *vpos, int *hpos,
912 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100913{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300914 struct drm_i915_private *dev_priv = dev->dev_private;
915 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
916 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
917 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300918 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300919 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100920 bool in_vbl = true;
921 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100922 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100923
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300924 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100925 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800926 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100927 return 0;
928 }
929
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300930 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300931 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300932 vtotal = mode->crtc_vtotal;
933 vbl_start = mode->crtc_vblank_start;
934 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100935
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200936 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
937 vbl_start = DIV_ROUND_UP(vbl_start, 2);
938 vbl_end /= 2;
939 vtotal /= 2;
940 }
941
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300942 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
943
Mario Kleinerad3543e2013-10-30 05:13:08 +0100944 /*
945 * Lock uncore.lock, as we will do multiple timing critical raw
946 * register reads, potentially with preemption disabled, so the
947 * following code must not block on uncore.lock.
948 */
949 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300950
Mario Kleinerad3543e2013-10-30 05:13:08 +0100951 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
952
953 /* Get optional system timestamp before query. */
954 if (stime)
955 *stime = ktime_get();
956
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300957 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100958 /* No obvious pixelcount register. Only query vertical
959 * scanout position from Display scan line register.
960 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300961 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100962 } else {
963 /* Have access to pixelcount since start of frame.
964 * We can split this into vertical and horizontal
965 * scanout position.
966 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100967 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100968
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300969 /* convert to pixel counts */
970 vbl_start *= htotal;
971 vbl_end *= htotal;
972 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300973
974 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300975 * In interlaced modes, the pixel counter counts all pixels,
976 * so one field will have htotal more pixels. In order to avoid
977 * the reported position from jumping backwards when the pixel
978 * counter is beyond the length of the shorter field, just
979 * clamp the position the length of the shorter field. This
980 * matches how the scanline counter based position works since
981 * the scanline counter doesn't count the two half lines.
982 */
983 if (position >= vtotal)
984 position = vtotal - 1;
985
986 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300987 * Start of vblank interrupt is triggered at start of hsync,
988 * just prior to the first active line of vblank. However we
989 * consider lines to start at the leading edge of horizontal
990 * active. So, should we get here before we've crossed into
991 * the horizontal active of the first line in vblank, we would
992 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
993 * always add htotal-hsync_start to the current pixel position.
994 */
995 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300996 }
997
Mario Kleinerad3543e2013-10-30 05:13:08 +0100998 /* Get optional system timestamp after query. */
999 if (etime)
1000 *etime = ktime_get();
1001
1002 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1003
1004 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1005
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001006 in_vbl = position >= vbl_start && position < vbl_end;
1007
1008 /*
1009 * While in vblank, position will be negative
1010 * counting up towards 0 at vbl_end. And outside
1011 * vblank, position will be positive counting
1012 * up since vbl_end.
1013 */
1014 if (position >= vbl_start)
1015 position -= vbl_end;
1016 else
1017 position += vtotal - vbl_end;
1018
Ville Syrjälä7c06b082013-10-11 21:52:43 +03001019 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001020 *vpos = position;
1021 *hpos = 0;
1022 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001023 *vpos = position / htotal;
1024 *hpos = position - (*vpos * htotal);
1025 }
1026
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001027 /* In vblank? */
1028 if (in_vbl)
1029 ret |= DRM_SCANOUTPOS_INVBL;
1030
1031 return ret;
1032}
1033
Ville Syrjäläa225f072014-04-29 13:35:45 +03001034int intel_get_crtc_scanline(struct intel_crtc *crtc)
1035{
1036 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
1037 unsigned long irqflags;
1038 int position;
1039
1040 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1041 position = __intel_get_crtc_scanline(crtc);
1042 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1043
1044 return position;
1045}
1046
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001047static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001048 int *max_error,
1049 struct timeval *vblank_time,
1050 unsigned flags)
1051{
Chris Wilson4041b852011-01-22 10:07:56 +00001052 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001053
Ben Widawsky7eb552a2013-03-13 14:05:41 -07001054 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +00001055 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001056 return -EINVAL;
1057 }
1058
1059 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +00001060 crtc = intel_get_crtc_for_pipe(dev, pipe);
1061 if (crtc == NULL) {
1062 DRM_ERROR("Invalid crtc %d\n", pipe);
1063 return -EINVAL;
1064 }
1065
1066 if (!crtc->enabled) {
1067 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
1068 return -EBUSY;
1069 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001070
1071 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +00001072 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
1073 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +03001074 crtc,
1075 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001076}
1077
Jani Nikula67c347f2013-09-17 14:26:34 +03001078static bool intel_hpd_irq_event(struct drm_device *dev,
1079 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +02001080{
1081 enum drm_connector_status old_status;
1082
1083 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1084 old_status = connector->status;
1085
1086 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +03001087 if (old_status == connector->status)
1088 return false;
1089
1090 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +02001091 connector->base.id,
1092 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +03001093 drm_get_connector_status_name(old_status),
1094 drm_get_connector_status_name(connector->status));
1095
1096 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +02001097}
1098
Jesse Barnes5ca58282009-03-31 14:11:15 -07001099/*
1100 * Handle hotplug events outside the interrupt handler proper.
1101 */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001102#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
1103
Jesse Barnes5ca58282009-03-31 14:11:15 -07001104static void i915_hotplug_work_func(struct work_struct *work)
1105{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001106 struct drm_i915_private *dev_priv =
1107 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001108 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -07001109 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001110 struct intel_connector *intel_connector;
1111 struct intel_encoder *intel_encoder;
1112 struct drm_connector *connector;
1113 unsigned long irqflags;
1114 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +02001115 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +02001116 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001117
Daniel Vetter52d7ece2012-12-01 21:03:22 +01001118 /* HPD irq before everything is fully set up. */
1119 if (!dev_priv->enable_hotplug_processing)
1120 return;
1121
Keith Packarda65e34c2011-07-25 10:04:56 -07001122 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -08001123 DRM_DEBUG_KMS("running encoder hotplug functions\n");
1124
Egbert Eichcd569ae2013-04-16 13:36:57 +02001125 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +02001126
1127 hpd_event_bits = dev_priv->hpd_event_bits;
1128 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001129 list_for_each_entry(connector, &mode_config->connector_list, head) {
1130 intel_connector = to_intel_connector(connector);
1131 intel_encoder = intel_connector->encoder;
1132 if (intel_encoder->hpd_pin > HPD_NONE &&
1133 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
1134 connector->polled == DRM_CONNECTOR_POLL_HPD) {
1135 DRM_INFO("HPD interrupt storm detected on connector %s: "
1136 "switching from hotplug detection to polling\n",
1137 drm_get_connector_name(connector));
1138 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1139 connector->polled = DRM_CONNECTOR_POLL_CONNECT
1140 | DRM_CONNECTOR_POLL_DISCONNECT;
1141 hpd_disabled = true;
1142 }
Egbert Eich142e2392013-04-11 15:57:57 +02001143 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1144 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
1145 drm_get_connector_name(connector), intel_encoder->hpd_pin);
1146 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001147 }
1148 /* if there were no outputs to poll, poll was disabled,
1149 * therefore make sure it's enabled when disabling HPD on
1150 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001151 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +02001152 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02001153 mod_timer(&dev_priv->hotplug_reenable_timer,
1154 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
1155 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001156
1157 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1158
Egbert Eich321a1b32013-04-11 16:00:26 +02001159 list_for_each_entry(connector, &mode_config->connector_list, head) {
1160 intel_connector = to_intel_connector(connector);
1161 intel_encoder = intel_connector->encoder;
1162 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1163 if (intel_encoder->hot_plug)
1164 intel_encoder->hot_plug(intel_encoder);
1165 if (intel_hpd_irq_event(dev, connector))
1166 changed = true;
1167 }
1168 }
Keith Packard40ee3382011-07-28 15:31:19 -07001169 mutex_unlock(&mode_config->mutex);
1170
Egbert Eich321a1b32013-04-11 16:00:26 +02001171 if (changed)
1172 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001173}
1174
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02001175static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
1176{
1177 del_timer_sync(&dev_priv->hotplug_reenable_timer);
1178}
1179
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001180static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001181{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001182 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001183 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001184 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001185
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001186 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001187
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001188 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1189
Daniel Vetter20e4d402012-08-08 23:35:39 +02001190 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001191
Jesse Barnes7648fa92010-05-20 14:28:11 -07001192 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001193 busy_up = I915_READ(RCPREVBSYTUPAVG);
1194 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001195 max_avg = I915_READ(RCBMAXAVG);
1196 min_avg = I915_READ(RCBMINAVG);
1197
1198 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001199 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001200 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1201 new_delay = dev_priv->ips.cur_delay - 1;
1202 if (new_delay < dev_priv->ips.max_delay)
1203 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001204 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001205 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1206 new_delay = dev_priv->ips.cur_delay + 1;
1207 if (new_delay > dev_priv->ips.min_delay)
1208 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001209 }
1210
Jesse Barnes7648fa92010-05-20 14:28:11 -07001211 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001212 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001213
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001214 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001215
Jesse Barnesf97108d2010-01-29 11:27:07 -08001216 return;
1217}
1218
Chris Wilson549f7362010-10-19 11:19:32 +01001219static void notify_ring(struct drm_device *dev,
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001220 struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +01001221{
Chris Wilson475553d2011-01-20 09:52:56 +00001222 if (ring->obj == NULL)
1223 return;
1224
Chris Wilson814e9b52013-09-23 17:33:19 -03001225 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001226
Chris Wilson549f7362010-10-19 11:19:32 +01001227 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001228 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001229}
1230
Ben Widawsky4912d042011-04-25 11:25:20 -07001231static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001232{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001233 struct drm_i915_private *dev_priv =
1234 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001235 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001236 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001237
Daniel Vetter59cdb632013-07-04 23:35:28 +02001238 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001239 pm_iir = dev_priv->rps.pm_iir;
1240 dev_priv->rps.pm_iir = 0;
Ben Widawsky09610212014-05-15 20:58:08 +03001241 if (IS_BROADWELL(dev_priv->dev))
1242 bdw_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
1243 else {
1244 /* Make sure not to corrupt PMIMR state used by ringbuffer */
1245 snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
1246 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001247 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001248
Paulo Zanoni60611c12013-08-15 11:50:01 -03001249 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301250 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001251
Deepak Sa6706b42014-03-15 20:23:22 +05301252 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001253 return;
1254
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001255 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001256
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001257 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001258 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001259 if (adj > 0)
1260 adj *= 2;
1261 else
1262 adj = 1;
Ben Widawskyb39fb292014-03-19 18:31:11 -07001263 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001264
1265 /*
1266 * For better performance, jump directly
1267 * to RPe if we're below it.
1268 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001269 if (new_delay < dev_priv->rps.efficient_freq)
1270 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001271 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001272 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1273 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001274 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001275 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001276 adj = 0;
1277 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1278 if (adj < 0)
1279 adj *= 2;
1280 else
1281 adj = -1;
Ben Widawskyb39fb292014-03-19 18:31:11 -07001282 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001283 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001284 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001285 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001286
Ben Widawsky79249632012-09-07 19:43:42 -07001287 /* sysfs frequency interfaces may have snuck in while servicing the
1288 * interrupt
1289 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001290 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001291 dev_priv->rps.min_freq_softlimit,
1292 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301293
Ben Widawskyb39fb292014-03-19 18:31:11 -07001294 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001295
1296 if (IS_VALLEYVIEW(dev_priv->dev))
1297 valleyview_set_rps(dev_priv->dev, new_delay);
1298 else
1299 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001300
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001301 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001302}
1303
Ben Widawskye3689192012-05-25 16:56:22 -07001304
1305/**
1306 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1307 * occurred.
1308 * @work: workqueue struct
1309 *
1310 * Doesn't actually do anything except notify userspace. As a consequence of
1311 * this event, userspace should try to remap the bad rows since statistically
1312 * it is likely the same row is more likely to go bad again.
1313 */
1314static void ivybridge_parity_work(struct work_struct *work)
1315{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001316 struct drm_i915_private *dev_priv =
1317 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001318 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001319 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001320 uint32_t misccpctl;
1321 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001322 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001323
1324 /* We must turn off DOP level clock gating to access the L3 registers.
1325 * In order to prevent a get/put style interface, acquire struct mutex
1326 * any time we access those registers.
1327 */
1328 mutex_lock(&dev_priv->dev->struct_mutex);
1329
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001330 /* If we've screwed up tracking, just let the interrupt fire again */
1331 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1332 goto out;
1333
Ben Widawskye3689192012-05-25 16:56:22 -07001334 misccpctl = I915_READ(GEN7_MISCCPCTL);
1335 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1336 POSTING_READ(GEN7_MISCCPCTL);
1337
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001338 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1339 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001340
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001341 slice--;
1342 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1343 break;
1344
1345 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1346
1347 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1348
1349 error_status = I915_READ(reg);
1350 row = GEN7_PARITY_ERROR_ROW(error_status);
1351 bank = GEN7_PARITY_ERROR_BANK(error_status);
1352 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1353
1354 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1355 POSTING_READ(reg);
1356
1357 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1358 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1359 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1360 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1361 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1362 parity_event[5] = NULL;
1363
Dave Airlie5bdebb12013-10-11 14:07:25 +10001364 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001365 KOBJ_CHANGE, parity_event);
1366
1367 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1368 slice, row, bank, subbank);
1369
1370 kfree(parity_event[4]);
1371 kfree(parity_event[3]);
1372 kfree(parity_event[2]);
1373 kfree(parity_event[1]);
1374 }
Ben Widawskye3689192012-05-25 16:56:22 -07001375
1376 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1377
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001378out:
1379 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001380 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001381 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001382 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1383
1384 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001385}
1386
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001387static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001388{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001389 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001390
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001391 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001392 return;
1393
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001394 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001395 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001396 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001397
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001398 iir &= GT_PARITY_ERROR(dev);
1399 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1400 dev_priv->l3_parity.which_slice |= 1 << 1;
1401
1402 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1403 dev_priv->l3_parity.which_slice |= 1 << 0;
1404
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001405 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001406}
1407
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001408static void ilk_gt_irq_handler(struct drm_device *dev,
1409 struct drm_i915_private *dev_priv,
1410 u32 gt_iir)
1411{
1412 if (gt_iir &
1413 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1414 notify_ring(dev, &dev_priv->ring[RCS]);
1415 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1416 notify_ring(dev, &dev_priv->ring[VCS]);
1417}
1418
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001419static void snb_gt_irq_handler(struct drm_device *dev,
1420 struct drm_i915_private *dev_priv,
1421 u32 gt_iir)
1422{
1423
Ben Widawskycc609d52013-05-28 19:22:29 -07001424 if (gt_iir &
1425 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001426 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001427 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001428 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001429 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001430 notify_ring(dev, &dev_priv->ring[BCS]);
1431
Ben Widawskycc609d52013-05-28 19:22:29 -07001432 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1433 GT_BSD_CS_ERROR_INTERRUPT |
1434 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001435 i915_handle_error(dev, false, "GT error interrupt 0x%08x",
1436 gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001437 }
Ben Widawskye3689192012-05-25 16:56:22 -07001438
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001439 if (gt_iir & GT_PARITY_ERROR(dev))
1440 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001441}
1442
Ben Widawsky09610212014-05-15 20:58:08 +03001443static void gen8_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1444{
1445 if ((pm_iir & dev_priv->pm_rps_events) == 0)
1446 return;
1447
1448 spin_lock(&dev_priv->irq_lock);
1449 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1450 bdw_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
1451 spin_unlock(&dev_priv->irq_lock);
1452
1453 queue_work(dev_priv->wq, &dev_priv->rps.work);
1454}
1455
Ben Widawskyabd58f02013-11-02 21:07:09 -07001456static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1457 struct drm_i915_private *dev_priv,
1458 u32 master_ctl)
1459{
1460 u32 rcs, bcs, vcs;
1461 uint32_t tmp = 0;
1462 irqreturn_t ret = IRQ_NONE;
1463
1464 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1465 tmp = I915_READ(GEN8_GT_IIR(0));
1466 if (tmp) {
1467 ret = IRQ_HANDLED;
1468 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1469 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1470 if (rcs & GT_RENDER_USER_INTERRUPT)
1471 notify_ring(dev, &dev_priv->ring[RCS]);
1472 if (bcs & GT_RENDER_USER_INTERRUPT)
1473 notify_ring(dev, &dev_priv->ring[BCS]);
1474 I915_WRITE(GEN8_GT_IIR(0), tmp);
1475 } else
1476 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1477 }
1478
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001479 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07001480 tmp = I915_READ(GEN8_GT_IIR(1));
1481 if (tmp) {
1482 ret = IRQ_HANDLED;
1483 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1484 if (vcs & GT_RENDER_USER_INTERRUPT)
1485 notify_ring(dev, &dev_priv->ring[VCS]);
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001486 vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
1487 if (vcs & GT_RENDER_USER_INTERRUPT)
1488 notify_ring(dev, &dev_priv->ring[VCS2]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001489 I915_WRITE(GEN8_GT_IIR(1), tmp);
1490 } else
1491 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1492 }
1493
Ben Widawsky09610212014-05-15 20:58:08 +03001494 if (master_ctl & GEN8_GT_PM_IRQ) {
1495 tmp = I915_READ(GEN8_GT_IIR(2));
1496 if (tmp & dev_priv->pm_rps_events) {
1497 ret = IRQ_HANDLED;
1498 gen8_rps_irq_handler(dev_priv, tmp);
1499 I915_WRITE(GEN8_GT_IIR(2),
1500 tmp & dev_priv->pm_rps_events);
1501 } else
1502 DRM_ERROR("The master control interrupt lied (PM)!\n");
1503 }
1504
Ben Widawskyabd58f02013-11-02 21:07:09 -07001505 if (master_ctl & GEN8_GT_VECS_IRQ) {
1506 tmp = I915_READ(GEN8_GT_IIR(3));
1507 if (tmp) {
1508 ret = IRQ_HANDLED;
1509 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1510 if (vcs & GT_RENDER_USER_INTERRUPT)
1511 notify_ring(dev, &dev_priv->ring[VECS]);
1512 I915_WRITE(GEN8_GT_IIR(3), tmp);
1513 } else
1514 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1515 }
1516
1517 return ret;
1518}
1519
Egbert Eichb543fb02013-04-16 13:36:54 +02001520#define HPD_STORM_DETECT_PERIOD 1000
1521#define HPD_STORM_THRESHOLD 5
1522
Daniel Vetter10a504d2013-06-27 17:52:12 +02001523static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001524 u32 hotplug_trigger,
1525 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001526{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001527 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001528 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001529 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001530
Daniel Vetter91d131d2013-06-27 17:52:14 +02001531 if (!hotplug_trigger)
1532 return;
1533
Imre Deakcc9bd492014-01-16 19:56:54 +02001534 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1535 hotplug_trigger);
1536
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001537 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001538 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001539
Daniel Vetter3ff04a162014-04-24 12:03:17 +02001540 if (hpd[i] & hotplug_trigger &&
1541 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
1542 /*
1543 * On GMCH platforms the interrupt mask bits only
1544 * prevent irq generation, not the setting of the
1545 * hotplug bits itself. So only WARN about unexpected
1546 * interrupts on saner platforms.
1547 */
1548 WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
1549 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1550 hotplug_trigger, i, hpd[i]);
1551
1552 continue;
1553 }
Egbert Eichb8f102e2013-07-26 14:14:24 +02001554
Egbert Eichb543fb02013-04-16 13:36:54 +02001555 if (!(hpd[i] & hotplug_trigger) ||
1556 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1557 continue;
1558
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001559 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001560 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1561 dev_priv->hpd_stats[i].hpd_last_jiffies
1562 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1563 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1564 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001565 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001566 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1567 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001568 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001569 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001570 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001571 } else {
1572 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001573 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1574 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001575 }
1576 }
1577
Daniel Vetter10a504d2013-06-27 17:52:12 +02001578 if (storm_detected)
1579 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001580 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001581
Daniel Vetter645416f2013-09-02 16:22:25 +02001582 /*
1583 * Our hotplug handler can grab modeset locks (by calling down into the
1584 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1585 * queue for otherwise the flush_work in the pageflip code will
1586 * deadlock.
1587 */
1588 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001589}
1590
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001591static void gmbus_irq_handler(struct drm_device *dev)
1592{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001593 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001594
Daniel Vetter28c70f12012-12-01 13:53:45 +01001595 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001596}
1597
Daniel Vetterce99c252012-12-01 13:53:47 +01001598static void dp_aux_irq_handler(struct drm_device *dev)
1599{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001600 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001601
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001602 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001603}
1604
Shuang He8bf1e9f2013-10-15 18:55:27 +01001605#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001606static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1607 uint32_t crc0, uint32_t crc1,
1608 uint32_t crc2, uint32_t crc3,
1609 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001610{
1611 struct drm_i915_private *dev_priv = dev->dev_private;
1612 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1613 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001614 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001615
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001616 spin_lock(&pipe_crc->lock);
1617
Damien Lespiau0c912c72013-10-15 18:55:37 +01001618 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001619 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001620 DRM_ERROR("spurious interrupt\n");
1621 return;
1622 }
1623
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001624 head = pipe_crc->head;
1625 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001626
1627 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001628 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001629 DRM_ERROR("CRC buffer overflowing\n");
1630 return;
1631 }
1632
1633 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001634
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001635 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001636 entry->crc[0] = crc0;
1637 entry->crc[1] = crc1;
1638 entry->crc[2] = crc2;
1639 entry->crc[3] = crc3;
1640 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001641
1642 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001643 pipe_crc->head = head;
1644
1645 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001646
1647 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001648}
Daniel Vetter277de952013-10-18 16:37:07 +02001649#else
1650static inline void
1651display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1652 uint32_t crc0, uint32_t crc1,
1653 uint32_t crc2, uint32_t crc3,
1654 uint32_t crc4) {}
1655#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001656
Daniel Vetter277de952013-10-18 16:37:07 +02001657
1658static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001659{
1660 struct drm_i915_private *dev_priv = dev->dev_private;
1661
Daniel Vetter277de952013-10-18 16:37:07 +02001662 display_pipe_crc_irq_handler(dev, pipe,
1663 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1664 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001665}
1666
Daniel Vetter277de952013-10-18 16:37:07 +02001667static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001668{
1669 struct drm_i915_private *dev_priv = dev->dev_private;
1670
Daniel Vetter277de952013-10-18 16:37:07 +02001671 display_pipe_crc_irq_handler(dev, pipe,
1672 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1673 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1674 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1675 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1676 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001677}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001678
Daniel Vetter277de952013-10-18 16:37:07 +02001679static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001680{
1681 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001682 uint32_t res1, res2;
1683
1684 if (INTEL_INFO(dev)->gen >= 3)
1685 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1686 else
1687 res1 = 0;
1688
1689 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1690 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1691 else
1692 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001693
Daniel Vetter277de952013-10-18 16:37:07 +02001694 display_pipe_crc_irq_handler(dev, pipe,
1695 I915_READ(PIPE_CRC_RES_RED(pipe)),
1696 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1697 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1698 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001699}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001700
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001701/* The RPS events need forcewake, so we add them to a work queue and mask their
1702 * IMR bits until the work is done. Other interrupts can be processed without
1703 * the work queue. */
1704static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001705{
Deepak Sa6706b42014-03-15 20:23:22 +05301706 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001707 spin_lock(&dev_priv->irq_lock);
Deepak Sa6706b42014-03-15 20:23:22 +05301708 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1709 snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001710 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001711
1712 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001713 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001714
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001715 if (HAS_VEBOX(dev_priv->dev)) {
1716 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1717 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001718
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001719 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001720 i915_handle_error(dev_priv->dev, false,
1721 "VEBOX CS error interrupt 0x%08x",
1722 pm_iir);
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001723 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001724 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001725}
1726
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001727static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1728{
1729 struct intel_crtc *crtc;
1730
1731 if (!drm_handle_vblank(dev, pipe))
1732 return false;
1733
1734 crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe));
1735 wake_up(&crtc->vbl_wait);
1736
1737 return true;
1738}
1739
Imre Deakc1874ed2014-02-04 21:35:46 +02001740static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1741{
1742 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001743 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001744 int pipe;
1745
Imre Deak58ead0d2014-02-04 21:35:47 +02001746 spin_lock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001747 for_each_pipe(pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001748 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001749 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001750
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001751 /*
1752 * PIPESTAT bits get signalled even when the interrupt is
1753 * disabled with the mask bits, and some of the status bits do
1754 * not generate interrupts at all (like the underrun bit). Hence
1755 * we need to be careful that we only handle what we want to
1756 * handle.
1757 */
1758 mask = 0;
1759 if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
1760 mask |= PIPE_FIFO_UNDERRUN_STATUS;
1761
1762 switch (pipe) {
1763 case PIPE_A:
1764 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1765 break;
1766 case PIPE_B:
1767 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1768 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001769 case PIPE_C:
1770 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1771 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001772 }
1773 if (iir & iir_bit)
1774 mask |= dev_priv->pipestat_irq_mask[pipe];
1775
1776 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001777 continue;
1778
1779 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001780 mask |= PIPESTAT_INT_ENABLE_MASK;
1781 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001782
1783 /*
1784 * Clear the PIPE*STAT regs before the IIR
1785 */
Imre Deak91d181d2014-02-10 18:42:49 +02001786 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1787 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001788 I915_WRITE(reg, pipe_stats[pipe]);
1789 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001790 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001791
1792 for_each_pipe(pipe) {
1793 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001794 intel_pipe_handle_vblank(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001795
Imre Deak579a9b02014-02-04 21:35:48 +02001796 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001797 intel_prepare_page_flip(dev, pipe);
1798 intel_finish_page_flip(dev, pipe);
1799 }
1800
1801 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1802 i9xx_pipe_crc_irq_handler(dev, pipe);
1803
1804 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1805 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1806 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1807 }
1808
1809 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1810 gmbus_irq_handler(dev);
1811}
1812
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001813static void i9xx_hpd_irq_handler(struct drm_device *dev)
1814{
1815 struct drm_i915_private *dev_priv = dev->dev_private;
1816 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1817
1818 if (IS_G4X(dev)) {
1819 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1820
1821 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_g4x);
1822 } else {
1823 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1824
1825 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1826 }
1827
1828 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
1829 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1830 dp_aux_irq_handler(dev);
1831
1832 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1833 /*
1834 * Make sure hotplug status is cleared before we clear IIR, or else we
1835 * may miss hotplug events.
1836 */
1837 POSTING_READ(PORT_HOTPLUG_STAT);
1838}
1839
Daniel Vetterff1f5252012-10-02 15:10:55 +02001840static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001841{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001842 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001843 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001844 u32 iir, gt_iir, pm_iir;
1845 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001846
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001847 while (true) {
1848 iir = I915_READ(VLV_IIR);
1849 gt_iir = I915_READ(GTIIR);
1850 pm_iir = I915_READ(GEN6_PMIIR);
1851
1852 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1853 goto out;
1854
1855 ret = IRQ_HANDLED;
1856
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001857 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001858
Imre Deakc1874ed2014-02-04 21:35:46 +02001859 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001860
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001861 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001862 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1863 i9xx_hpd_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001864
Paulo Zanoni60611c12013-08-15 11:50:01 -03001865 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001866 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001867
1868 I915_WRITE(GTIIR, gt_iir);
1869 I915_WRITE(GEN6_PMIIR, pm_iir);
1870 I915_WRITE(VLV_IIR, iir);
1871 }
1872
1873out:
1874 return ret;
1875}
1876
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001877static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1878{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001879 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001880 struct drm_i915_private *dev_priv = dev->dev_private;
1881 u32 master_ctl, iir;
1882 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001883
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001884 for (;;) {
1885 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1886 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001887
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001888 if (master_ctl == 0 && iir == 0)
1889 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001890
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001891 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001892
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001893 gen8_gt_irq_handler(dev, dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001894
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001895 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001896
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001897 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä3278f672014-04-09 13:28:49 +03001898 i9xx_hpd_irq_handler(dev);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001899
1900 I915_WRITE(VLV_IIR, iir);
1901
1902 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1903 POSTING_READ(GEN8_MASTER_IRQ);
1904
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001905 ret = IRQ_HANDLED;
1906 }
1907
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001908 return ret;
1909}
1910
Adam Jackson23e81d62012-06-06 15:45:44 -04001911static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001912{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001913 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001914 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001915 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001916
Daniel Vetter91d131d2013-06-27 17:52:14 +02001917 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1918
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001919 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1920 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1921 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001922 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001923 port_name(port));
1924 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001925
Daniel Vetterce99c252012-12-01 13:53:47 +01001926 if (pch_iir & SDE_AUX_MASK)
1927 dp_aux_irq_handler(dev);
1928
Jesse Barnes776ad802011-01-04 15:09:39 -08001929 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001930 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001931
1932 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1933 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1934
1935 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1936 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1937
1938 if (pch_iir & SDE_POISON)
1939 DRM_ERROR("PCH poison interrupt\n");
1940
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001941 if (pch_iir & SDE_FDI_MASK)
1942 for_each_pipe(pipe)
1943 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1944 pipe_name(pipe),
1945 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001946
1947 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1948 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1949
1950 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1951 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1952
Jesse Barnes776ad802011-01-04 15:09:39 -08001953 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001954 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1955 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001956 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001957
1958 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1959 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1960 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001961 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001962}
1963
1964static void ivb_err_int_handler(struct drm_device *dev)
1965{
1966 struct drm_i915_private *dev_priv = dev->dev_private;
1967 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001968 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001969
Paulo Zanonide032bf2013-04-12 17:57:58 -03001970 if (err_int & ERR_INT_POISON)
1971 DRM_ERROR("Poison interrupt\n");
1972
Daniel Vetter5a69b892013-10-16 22:55:52 +02001973 for_each_pipe(pipe) {
1974 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1975 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1976 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001977 DRM_ERROR("Pipe %c FIFO underrun\n",
1978 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001979 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001980
Daniel Vetter5a69b892013-10-16 22:55:52 +02001981 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1982 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001983 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001984 else
Daniel Vetter277de952013-10-18 16:37:07 +02001985 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001986 }
1987 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001988
Paulo Zanoni86642812013-04-12 17:57:57 -03001989 I915_WRITE(GEN7_ERR_INT, err_int);
1990}
1991
1992static void cpt_serr_int_handler(struct drm_device *dev)
1993{
1994 struct drm_i915_private *dev_priv = dev->dev_private;
1995 u32 serr_int = I915_READ(SERR_INT);
1996
Paulo Zanonide032bf2013-04-12 17:57:58 -03001997 if (serr_int & SERR_INT_POISON)
1998 DRM_ERROR("PCH poison interrupt\n");
1999
Paulo Zanoni86642812013-04-12 17:57:57 -03002000 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
2001 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2002 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002003 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002004
2005 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
2006 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2007 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002008 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002009
2010 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
2011 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
2012 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002013 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002014
2015 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002016}
2017
Adam Jackson23e81d62012-06-06 15:45:44 -04002018static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
2019{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002020 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04002021 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002022 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002023
Daniel Vetter91d131d2013-06-27 17:52:14 +02002024 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
2025
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002026 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2027 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2028 SDE_AUDIO_POWER_SHIFT_CPT);
2029 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2030 port_name(port));
2031 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002032
2033 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01002034 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002035
2036 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002037 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002038
2039 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2040 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2041
2042 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2043 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2044
2045 if (pch_iir & SDE_FDI_MASK_CPT)
2046 for_each_pipe(pipe)
2047 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2048 pipe_name(pipe),
2049 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002050
2051 if (pch_iir & SDE_ERROR_CPT)
2052 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002053}
2054
Paulo Zanonic008bc62013-07-12 16:35:10 -03002055static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2056{
2057 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02002058 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03002059
2060 if (de_iir & DE_AUX_CHANNEL_A)
2061 dp_aux_irq_handler(dev);
2062
2063 if (de_iir & DE_GSE)
2064 intel_opregion_asle_intr(dev);
2065
Paulo Zanonic008bc62013-07-12 16:35:10 -03002066 if (de_iir & DE_POISON)
2067 DRM_ERROR("Poison interrupt\n");
2068
Daniel Vetter40da17c2013-10-21 18:04:36 +02002069 for_each_pipe(pipe) {
2070 if (de_iir & DE_PIPE_VBLANK(pipe))
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002071 intel_pipe_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002072
Daniel Vetter40da17c2013-10-21 18:04:36 +02002073 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2074 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002075 DRM_ERROR("Pipe %c FIFO underrun\n",
2076 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03002077
Daniel Vetter40da17c2013-10-21 18:04:36 +02002078 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2079 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002080
Daniel Vetter40da17c2013-10-21 18:04:36 +02002081 /* plane/pipes map 1:1 on ilk+ */
2082 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2083 intel_prepare_page_flip(dev, pipe);
2084 intel_finish_page_flip_plane(dev, pipe);
2085 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03002086 }
2087
2088 /* check event from PCH */
2089 if (de_iir & DE_PCH_EVENT) {
2090 u32 pch_iir = I915_READ(SDEIIR);
2091
2092 if (HAS_PCH_CPT(dev))
2093 cpt_irq_handler(dev, pch_iir);
2094 else
2095 ibx_irq_handler(dev, pch_iir);
2096
2097 /* should clear PCH hotplug event before clear CPU irq */
2098 I915_WRITE(SDEIIR, pch_iir);
2099 }
2100
2101 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2102 ironlake_rps_change_irq_handler(dev);
2103}
2104
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002105static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2106{
2107 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002108 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002109
2110 if (de_iir & DE_ERR_INT_IVB)
2111 ivb_err_int_handler(dev);
2112
2113 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2114 dp_aux_irq_handler(dev);
2115
2116 if (de_iir & DE_GSE_IVB)
2117 intel_opregion_asle_intr(dev);
2118
Damien Lespiau07d27e22014-03-03 17:31:46 +00002119 for_each_pipe(pipe) {
2120 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002121 intel_pipe_handle_vblank(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02002122
2123 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002124 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2125 intel_prepare_page_flip(dev, pipe);
2126 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002127 }
2128 }
2129
2130 /* check event from PCH */
2131 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2132 u32 pch_iir = I915_READ(SDEIIR);
2133
2134 cpt_irq_handler(dev, pch_iir);
2135
2136 /* clear PCH hotplug event before clear CPU irq */
2137 I915_WRITE(SDEIIR, pch_iir);
2138 }
2139}
2140
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002141static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002142{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002143 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002144 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002145 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002146 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002147
Paulo Zanoni86642812013-04-12 17:57:57 -03002148 /* We get interrupts on unclaimed registers, so check for this before we
2149 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002150 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002151
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002152 /* disable master interrupt before clearing iir */
2153 de_ier = I915_READ(DEIER);
2154 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002155 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002156
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002157 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2158 * interrupts will will be stored on its back queue, and then we'll be
2159 * able to process them after we restore SDEIER (as soon as we restore
2160 * it, we'll get an interrupt if SDEIIR still has something to process
2161 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002162 if (!HAS_PCH_NOP(dev)) {
2163 sde_ier = I915_READ(SDEIER);
2164 I915_WRITE(SDEIER, 0);
2165 POSTING_READ(SDEIER);
2166 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002167
Chris Wilson0e434062012-05-09 21:45:44 +01002168 gt_iir = I915_READ(GTIIR);
2169 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002170 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002171 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002172 else
2173 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002174 I915_WRITE(GTIIR, gt_iir);
2175 ret = IRQ_HANDLED;
2176 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002177
2178 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002179 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002180 if (INTEL_INFO(dev)->gen >= 7)
2181 ivb_display_irq_handler(dev, de_iir);
2182 else
2183 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002184 I915_WRITE(DEIIR, de_iir);
2185 ret = IRQ_HANDLED;
2186 }
2187
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002188 if (INTEL_INFO(dev)->gen >= 6) {
2189 u32 pm_iir = I915_READ(GEN6_PMIIR);
2190 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002191 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002192 I915_WRITE(GEN6_PMIIR, pm_iir);
2193 ret = IRQ_HANDLED;
2194 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002195 }
2196
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002197 I915_WRITE(DEIER, de_ier);
2198 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002199 if (!HAS_PCH_NOP(dev)) {
2200 I915_WRITE(SDEIER, sde_ier);
2201 POSTING_READ(SDEIER);
2202 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002203
2204 return ret;
2205}
2206
Ben Widawskyabd58f02013-11-02 21:07:09 -07002207static irqreturn_t gen8_irq_handler(int irq, void *arg)
2208{
2209 struct drm_device *dev = arg;
2210 struct drm_i915_private *dev_priv = dev->dev_private;
2211 u32 master_ctl;
2212 irqreturn_t ret = IRQ_NONE;
2213 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002214 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002215
Ben Widawskyabd58f02013-11-02 21:07:09 -07002216 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2217 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2218 if (!master_ctl)
2219 return IRQ_NONE;
2220
2221 I915_WRITE(GEN8_MASTER_IRQ, 0);
2222 POSTING_READ(GEN8_MASTER_IRQ);
2223
2224 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2225
2226 if (master_ctl & GEN8_DE_MISC_IRQ) {
2227 tmp = I915_READ(GEN8_DE_MISC_IIR);
2228 if (tmp & GEN8_DE_MISC_GSE)
2229 intel_opregion_asle_intr(dev);
2230 else if (tmp)
2231 DRM_ERROR("Unexpected DE Misc interrupt\n");
2232 else
2233 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
2234
2235 if (tmp) {
2236 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2237 ret = IRQ_HANDLED;
2238 }
2239 }
2240
Daniel Vetter6d766f02013-11-07 14:49:55 +01002241 if (master_ctl & GEN8_DE_PORT_IRQ) {
2242 tmp = I915_READ(GEN8_DE_PORT_IIR);
2243 if (tmp & GEN8_AUX_CHANNEL_A)
2244 dp_aux_irq_handler(dev);
2245 else if (tmp)
2246 DRM_ERROR("Unexpected DE Port interrupt\n");
2247 else
2248 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
2249
2250 if (tmp) {
2251 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2252 ret = IRQ_HANDLED;
2253 }
2254 }
2255
Daniel Vetterc42664c2013-11-07 11:05:40 +01002256 for_each_pipe(pipe) {
2257 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002258
Daniel Vetterc42664c2013-11-07 11:05:40 +01002259 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2260 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002261
Daniel Vetterc42664c2013-11-07 11:05:40 +01002262 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2263 if (pipe_iir & GEN8_PIPE_VBLANK)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002264 intel_pipe_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002265
Damien Lespiaud0e1f1c2014-04-08 01:22:44 +01002266 if (pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE) {
Daniel Vetterc42664c2013-11-07 11:05:40 +01002267 intel_prepare_page_flip(dev, pipe);
2268 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002269 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002270
Daniel Vetter0fbe7872013-11-07 11:05:44 +01002271 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2272 hsw_pipe_crc_irq_handler(dev, pipe);
2273
Daniel Vetter38d83c962013-11-07 11:05:46 +01002274 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
2275 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2276 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002277 DRM_ERROR("Pipe %c FIFO underrun\n",
2278 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01002279 }
2280
Daniel Vetter30100f22013-11-07 14:49:24 +01002281 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
2282 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2283 pipe_name(pipe),
2284 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2285 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002286
2287 if (pipe_iir) {
2288 ret = IRQ_HANDLED;
2289 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
2290 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002291 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2292 }
2293
Daniel Vetter92d03a82013-11-07 11:05:43 +01002294 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2295 /*
2296 * FIXME(BDW): Assume for now that the new interrupt handling
2297 * scheme also closed the SDE interrupt handling race we've seen
2298 * on older pch-split platforms. But this needs testing.
2299 */
2300 u32 pch_iir = I915_READ(SDEIIR);
2301
2302 cpt_irq_handler(dev, pch_iir);
2303
2304 if (pch_iir) {
2305 I915_WRITE(SDEIIR, pch_iir);
2306 ret = IRQ_HANDLED;
2307 }
2308 }
2309
Ben Widawskyabd58f02013-11-02 21:07:09 -07002310 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2311 POSTING_READ(GEN8_MASTER_IRQ);
2312
2313 return ret;
2314}
2315
Daniel Vetter17e1df02013-09-08 21:57:13 +02002316static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2317 bool reset_completed)
2318{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002319 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002320 int i;
2321
2322 /*
2323 * Notify all waiters for GPU completion events that reset state has
2324 * been changed, and that they need to restart their wait after
2325 * checking for potential errors (and bail out to drop locks if there is
2326 * a gpu reset pending so that i915_error_work_func can acquire them).
2327 */
2328
2329 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2330 for_each_ring(ring, dev_priv, i)
2331 wake_up_all(&ring->irq_queue);
2332
2333 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2334 wake_up_all(&dev_priv->pending_flip_queue);
2335
2336 /*
2337 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2338 * reset state is cleared.
2339 */
2340 if (reset_completed)
2341 wake_up_all(&dev_priv->gpu_error.reset_queue);
2342}
2343
Jesse Barnes8a905232009-07-11 16:48:03 -04002344/**
2345 * i915_error_work_func - do process context error handling work
2346 * @work: work struct
2347 *
2348 * Fire an error uevent so userspace can see that a hang or error
2349 * was detected.
2350 */
2351static void i915_error_work_func(struct work_struct *work)
2352{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002353 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2354 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002355 struct drm_i915_private *dev_priv =
2356 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002357 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002358 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2359 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2360 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002361 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002362
Dave Airlie5bdebb12013-10-11 14:07:25 +10002363 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002364
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002365 /*
2366 * Note that there's only one work item which does gpu resets, so we
2367 * need not worry about concurrent gpu resets potentially incrementing
2368 * error->reset_counter twice. We only need to take care of another
2369 * racing irq/hangcheck declaring the gpu dead for a second time. A
2370 * quick check for that is good enough: schedule_work ensures the
2371 * correct ordering between hang detection and this work item, and since
2372 * the reset in-progress bit is only ever set by code outside of this
2373 * work we don't need to worry about any other races.
2374 */
2375 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002376 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002377 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002378 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002379
Daniel Vetter17e1df02013-09-08 21:57:13 +02002380 /*
Imre Deakf454c692014-04-23 01:09:04 +03002381 * In most cases it's guaranteed that we get here with an RPM
2382 * reference held, for example because there is a pending GPU
2383 * request that won't finish until the reset is done. This
2384 * isn't the case at least when we get here by doing a
2385 * simulated reset via debugs, so get an RPM reference.
2386 */
2387 intel_runtime_pm_get(dev_priv);
2388 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002389 * All state reset _must_ be completed before we update the
2390 * reset counter, for otherwise waiters might miss the reset
2391 * pending state and not properly drop locks, resulting in
2392 * deadlocks with the reset work.
2393 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002394 ret = i915_reset(dev);
2395
Daniel Vetter17e1df02013-09-08 21:57:13 +02002396 intel_display_handle_reset(dev);
2397
Imre Deakf454c692014-04-23 01:09:04 +03002398 intel_runtime_pm_put(dev_priv);
2399
Daniel Vetterf69061b2012-12-06 09:01:42 +01002400 if (ret == 0) {
2401 /*
2402 * After all the gem state is reset, increment the reset
2403 * counter and wake up everyone waiting for the reset to
2404 * complete.
2405 *
2406 * Since unlock operations are a one-sided barrier only,
2407 * we need to insert a barrier here to order any seqno
2408 * updates before
2409 * the counter increment.
2410 */
2411 smp_mb__before_atomic_inc();
2412 atomic_inc(&dev_priv->gpu_error.reset_counter);
2413
Dave Airlie5bdebb12013-10-11 14:07:25 +10002414 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002415 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002416 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002417 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002418 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002419
Daniel Vetter17e1df02013-09-08 21:57:13 +02002420 /*
2421 * Note: The wake_up also serves as a memory barrier so that
2422 * waiters see the update value of the reset counter atomic_t.
2423 */
2424 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002425 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002426}
2427
Chris Wilson35aed2e2010-05-27 13:18:12 +01002428static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002429{
2430 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002431 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002432 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002433 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002434
Chris Wilson35aed2e2010-05-27 13:18:12 +01002435 if (!eir)
2436 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002437
Joe Perchesa70491c2012-03-18 13:00:11 -07002438 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002439
Ben Widawskybd9854f2012-08-23 15:18:09 -07002440 i915_get_extra_instdone(dev, instdone);
2441
Jesse Barnes8a905232009-07-11 16:48:03 -04002442 if (IS_G4X(dev)) {
2443 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2444 u32 ipeir = I915_READ(IPEIR_I965);
2445
Joe Perchesa70491c2012-03-18 13:00:11 -07002446 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2447 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002448 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2449 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002450 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002451 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002452 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002453 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002454 }
2455 if (eir & GM45_ERROR_PAGE_TABLE) {
2456 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002457 pr_err("page table error\n");
2458 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002459 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002460 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002461 }
2462 }
2463
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002464 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002465 if (eir & I915_ERROR_PAGE_TABLE) {
2466 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002467 pr_err("page table error\n");
2468 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002469 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002470 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002471 }
2472 }
2473
2474 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002475 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002476 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002477 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002478 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002479 /* pipestat has already been acked */
2480 }
2481 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002482 pr_err("instruction error\n");
2483 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002484 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2485 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002486 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002487 u32 ipeir = I915_READ(IPEIR);
2488
Joe Perchesa70491c2012-03-18 13:00:11 -07002489 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2490 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002491 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002492 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002493 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002494 } else {
2495 u32 ipeir = I915_READ(IPEIR_I965);
2496
Joe Perchesa70491c2012-03-18 13:00:11 -07002497 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2498 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002499 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002500 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002501 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002502 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002503 }
2504 }
2505
2506 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002507 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002508 eir = I915_READ(EIR);
2509 if (eir) {
2510 /*
2511 * some errors might have become stuck,
2512 * mask them.
2513 */
2514 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2515 I915_WRITE(EMR, I915_READ(EMR) | eir);
2516 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2517 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002518}
2519
2520/**
2521 * i915_handle_error - handle an error interrupt
2522 * @dev: drm device
2523 *
2524 * Do some basic checking of regsiter state at error interrupt time and
2525 * dump it to the syslog. Also call i915_capture_error_state() to make
2526 * sure we get a record and make it available in debugfs. Fire a uevent
2527 * so userspace knows something bad happened (should trigger collection
2528 * of a ring dump etc.).
2529 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002530void i915_handle_error(struct drm_device *dev, bool wedged,
2531 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002532{
2533 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002534 va_list args;
2535 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002536
Mika Kuoppala58174462014-02-25 17:11:26 +02002537 va_start(args, fmt);
2538 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2539 va_end(args);
2540
2541 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002542 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002543
Ben Gamariba1234d2009-09-14 17:48:47 -04002544 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002545 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2546 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002547
Ben Gamari11ed50e2009-09-14 17:48:45 -04002548 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002549 * Wakeup waiting processes so that the reset work function
2550 * i915_error_work_func doesn't deadlock trying to grab various
2551 * locks. By bumping the reset counter first, the woken
2552 * processes will see a reset in progress and back off,
2553 * releasing their locks and then wait for the reset completion.
2554 * We must do this for _all_ gpu waiters that might hold locks
2555 * that the reset work needs to acquire.
2556 *
2557 * Note: The wake_up serves as the required memory barrier to
2558 * ensure that the waiters see the updated value of the reset
2559 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002560 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002561 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002562 }
2563
Daniel Vetter122f46b2013-09-04 17:36:14 +02002564 /*
2565 * Our reset work can grab modeset locks (since it needs to reset the
2566 * state of outstanding pagelips). Hence it must not be run on our own
2567 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2568 * code will deadlock.
2569 */
2570 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002571}
2572
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002573static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002574{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002575 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002576 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2577 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002578 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002579 struct intel_unpin_work *work;
2580 unsigned long flags;
2581 bool stall_detected;
2582
2583 /* Ignore early vblank irqs */
2584 if (intel_crtc == NULL)
2585 return;
2586
2587 spin_lock_irqsave(&dev->event_lock, flags);
2588 work = intel_crtc->unpin_work;
2589
Chris Wilsone7d841c2012-12-03 11:36:30 +00002590 if (work == NULL ||
2591 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2592 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002593 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2594 spin_unlock_irqrestore(&dev->event_lock, flags);
2595 return;
2596 }
2597
2598 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002599 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002600 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002601 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002602 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002603 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002604 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002605 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002606 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Matt Roperf4510a22014-04-01 15:22:40 -07002607 crtc->y * crtc->primary->fb->pitches[0] +
2608 crtc->x * crtc->primary->fb->bits_per_pixel/8);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002609 }
2610
2611 spin_unlock_irqrestore(&dev->event_lock, flags);
2612
2613 if (stall_detected) {
2614 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2615 intel_prepare_page_flip(dev, intel_crtc->plane);
2616 }
2617}
2618
Keith Packard42f52ef2008-10-18 19:39:29 -07002619/* Called from drm generic code, passed 'crtc' which
2620 * we use as a pipe index
2621 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002622static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002623{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002624 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002625 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002626
Chris Wilson5eddb702010-09-11 13:48:45 +01002627 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002628 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002629
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002630 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002631 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002632 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002633 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002634 else
Keith Packard7c463582008-11-04 02:03:27 -08002635 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002636 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002637
2638 /* maintain vblank delivery even in deep C-states */
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002639 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002640 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002641 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002642
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002643 return 0;
2644}
2645
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002646static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002647{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002648 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002649 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002650 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002651 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002652
2653 if (!i915_pipe_enabled(dev, pipe))
2654 return -EINVAL;
2655
2656 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002657 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002658 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2659
2660 return 0;
2661}
2662
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002663static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2664{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002665 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002666 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002667
2668 if (!i915_pipe_enabled(dev, pipe))
2669 return -EINVAL;
2670
2671 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002672 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002673 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002674 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2675
2676 return 0;
2677}
2678
Ben Widawskyabd58f02013-11-02 21:07:09 -07002679static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2680{
2681 struct drm_i915_private *dev_priv = dev->dev_private;
2682 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002683
2684 if (!i915_pipe_enabled(dev, pipe))
2685 return -EINVAL;
2686
2687 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002688 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2689 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2690 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002691 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2692 return 0;
2693}
2694
Keith Packard42f52ef2008-10-18 19:39:29 -07002695/* Called from drm generic code, passed 'crtc' which
2696 * we use as a pipe index
2697 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002698static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002699{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002700 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002701 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002702
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002703 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002704 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002705 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002706
Jesse Barnesf796cf82011-04-07 13:58:17 -07002707 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002708 PIPE_VBLANK_INTERRUPT_STATUS |
2709 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002710 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2711}
2712
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002713static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002714{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002715 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002716 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002717 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002718 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002719
2720 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002721 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002722 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2723}
2724
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002725static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2726{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002727 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002728 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002729
2730 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002731 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002732 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002733 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2734}
2735
Ben Widawskyabd58f02013-11-02 21:07:09 -07002736static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2737{
2738 struct drm_i915_private *dev_priv = dev->dev_private;
2739 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002740
2741 if (!i915_pipe_enabled(dev, pipe))
2742 return;
2743
2744 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002745 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2746 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2747 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002748 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2749}
2750
Chris Wilson893eead2010-10-27 14:44:35 +01002751static u32
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002752ring_last_seqno(struct intel_engine_cs *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002753{
Chris Wilson893eead2010-10-27 14:44:35 +01002754 return list_entry(ring->request_list.prev,
2755 struct drm_i915_gem_request, list)->seqno;
2756}
2757
Chris Wilson9107e9d2013-06-10 11:20:20 +01002758static bool
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002759ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002760{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002761 return (list_empty(&ring->request_list) ||
2762 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002763}
2764
Daniel Vettera028c4b2014-03-15 00:08:56 +01002765static bool
2766ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2767{
2768 if (INTEL_INFO(dev)->gen >= 8) {
2769 /*
2770 * FIXME: gen8 semaphore support - currently we don't emit
2771 * semaphores on bdw anyway, but this needs to be addressed when
2772 * we merge that code.
2773 */
2774 return false;
2775 } else {
2776 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2777 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2778 MI_SEMAPHORE_REGISTER);
2779 }
2780}
2781
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002782static struct intel_engine_cs *
2783semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002784{
2785 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002786 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002787 int i;
2788
2789 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
2790 /*
2791 * FIXME: gen8 semaphore support - currently we don't emit
2792 * semaphores on bdw anyway, but this needs to be addressed when
2793 * we merge that code.
2794 */
2795 return NULL;
2796 } else {
2797 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2798
2799 for_each_ring(signaller, dev_priv, i) {
2800 if(ring == signaller)
2801 continue;
2802
Ben Widawskyebc348b2014-04-29 14:52:28 -07002803 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002804 return signaller;
2805 }
2806 }
2807
2808 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x\n",
2809 ring->id, ipehr);
2810
2811 return NULL;
2812}
2813
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002814static struct intel_engine_cs *
2815semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002816{
2817 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002818 u32 cmd, ipehr, head;
2819 int i;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002820
2821 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002822 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002823 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002824
Daniel Vetter88fe4292014-03-15 00:08:55 +01002825 /*
2826 * HEAD is likely pointing to the dword after the actual command,
2827 * so scan backwards until we find the MBOX. But limit it to just 3
2828 * dwords. Note that we don't care about ACTHD here since that might
2829 * point at at batch, and semaphores are always emitted into the
2830 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002831 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002832 head = I915_READ_HEAD(ring) & HEAD_ADDR;
2833
2834 for (i = 4; i; --i) {
2835 /*
2836 * Be paranoid and presume the hw has gone off into the wild -
2837 * our ring is smaller than what the hardware (and hence
2838 * HEAD_ADDR) allows. Also handles wrap-around.
2839 */
2840 head &= ring->size - 1;
2841
2842 /* This here seems to blow up */
2843 cmd = ioread32(ring->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002844 if (cmd == ipehr)
2845 break;
2846
Daniel Vetter88fe4292014-03-15 00:08:55 +01002847 head -= 4;
2848 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002849
Daniel Vetter88fe4292014-03-15 00:08:55 +01002850 if (!i)
2851 return NULL;
2852
2853 *seqno = ioread32(ring->virtual_start + head + 4) + 1;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002854 return semaphore_wait_to_signaller_ring(ring, ipehr);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002855}
2856
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002857static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01002858{
2859 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002860 struct intel_engine_cs *signaller;
Chris Wilson6274f212013-06-10 11:20:21 +01002861 u32 seqno, ctl;
2862
2863 ring->hangcheck.deadlock = true;
2864
2865 signaller = semaphore_waits_for(ring, &seqno);
2866 if (signaller == NULL || signaller->hangcheck.deadlock)
2867 return -1;
2868
2869 /* cursory check for an unkickable deadlock */
2870 ctl = I915_READ_CTL(signaller);
2871 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2872 return -1;
2873
2874 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2875}
2876
2877static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2878{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002879 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01002880 int i;
2881
2882 for_each_ring(ring, dev_priv, i)
2883 ring->hangcheck.deadlock = false;
2884}
2885
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002886static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002887ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002888{
2889 struct drm_device *dev = ring->dev;
2890 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002891 u32 tmp;
2892
Chris Wilson6274f212013-06-10 11:20:21 +01002893 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002894 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002895
Chris Wilson9107e9d2013-06-10 11:20:20 +01002896 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002897 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002898
2899 /* Is the chip hanging on a WAIT_FOR_EVENT?
2900 * If so we can simply poke the RB_WAIT bit
2901 * and break the hang. This should work on
2902 * all but the second generation chipsets.
2903 */
2904 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002905 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002906 i915_handle_error(dev, false,
2907 "Kicking stuck wait on %s",
2908 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002909 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002910 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002911 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002912
Chris Wilson6274f212013-06-10 11:20:21 +01002913 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2914 switch (semaphore_passed(ring)) {
2915 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002916 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002917 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002918 i915_handle_error(dev, false,
2919 "Kicking stuck semaphore on %s",
2920 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002921 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002922 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002923 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002924 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002925 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002926 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002927
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002928 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002929}
2930
Ben Gamarif65d9422009-09-14 17:48:44 -04002931/**
2932 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002933 * batchbuffers in a long time. We keep track per ring seqno progress and
2934 * if there are no progress, hangcheck score for that ring is increased.
2935 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2936 * we kick the ring. If we see no progress on three subsequent calls
2937 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002938 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002939static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002940{
2941 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002942 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002943 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002944 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002945 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002946 bool stuck[I915_NUM_RINGS] = { 0 };
2947#define BUSY 1
2948#define KICK 5
2949#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002950
Jani Nikulad330a952014-01-21 11:24:25 +02002951 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002952 return;
2953
Chris Wilsonb4519512012-05-11 14:29:30 +01002954 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002955 u64 acthd;
2956 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002957 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002958
Chris Wilson6274f212013-06-10 11:20:21 +01002959 semaphore_clear_deadlocks(dev_priv);
2960
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002961 seqno = ring->get_seqno(ring, false);
2962 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002963
Chris Wilson9107e9d2013-06-10 11:20:20 +01002964 if (ring->hangcheck.seqno == seqno) {
2965 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002966 ring->hangcheck.action = HANGCHECK_IDLE;
2967
Chris Wilson9107e9d2013-06-10 11:20:20 +01002968 if (waitqueue_active(&ring->irq_queue)) {
2969 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002970 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002971 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2972 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2973 ring->name);
2974 else
2975 DRM_INFO("Fake missed irq on %s\n",
2976 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002977 wake_up_all(&ring->irq_queue);
2978 }
2979 /* Safeguard against driver failure */
2980 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002981 } else
2982 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002983 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002984 /* We always increment the hangcheck score
2985 * if the ring is busy and still processing
2986 * the same request, so that no single request
2987 * can run indefinitely (such as a chain of
2988 * batches). The only time we do not increment
2989 * the hangcheck score on this ring, if this
2990 * ring is in a legitimate wait for another
2991 * ring. In that case the waiting ring is a
2992 * victim and we want to be sure we catch the
2993 * right culprit. Then every time we do kick
2994 * the ring, add a small increment to the
2995 * score so that we can catch a batch that is
2996 * being repeatedly kicked and so responsible
2997 * for stalling the machine.
2998 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002999 ring->hangcheck.action = ring_stuck(ring,
3000 acthd);
3001
3002 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003003 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003004 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01003005 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003006 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003007 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003008 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003009 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003010 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003011 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003012 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003013 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003014 stuck[i] = true;
3015 break;
3016 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003017 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003018 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03003019 ring->hangcheck.action = HANGCHECK_ACTIVE;
3020
Chris Wilson9107e9d2013-06-10 11:20:20 +01003021 /* Gradually reduce the count so that we catch DoS
3022 * attempts across multiple batches.
3023 */
3024 if (ring->hangcheck.score > 0)
3025 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01003026 }
3027
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003028 ring->hangcheck.seqno = seqno;
3029 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003030 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003031 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003032
Mika Kuoppala92cab732013-05-24 17:16:07 +03003033 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02003034 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003035 DRM_INFO("%s on %s\n",
3036 stuck[i] ? "stuck" : "no progress",
3037 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01003038 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003039 }
3040 }
3041
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003042 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02003043 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003044
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003045 if (busy_count)
3046 /* Reset timer case chip hangs without another request
3047 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003048 i915_queue_hangcheck(dev);
3049}
3050
3051void i915_queue_hangcheck(struct drm_device *dev)
3052{
3053 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02003054 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003055 return;
3056
3057 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
3058 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003059}
3060
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003061static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003062{
3063 struct drm_i915_private *dev_priv = dev->dev_private;
3064
3065 if (HAS_PCH_NOP(dev))
3066 return;
3067
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003068 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003069
3070 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3071 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003072}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003073
Paulo Zanoni622364b2014-04-01 15:37:22 -03003074/*
3075 * SDEIER is also touched by the interrupt handler to work around missed PCH
3076 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3077 * instead we unconditionally enable all PCH interrupt sources here, but then
3078 * only unmask them as needed with SDEIMR.
3079 *
3080 * This function needs to be called before interrupts are enabled.
3081 */
3082static void ibx_irq_pre_postinstall(struct drm_device *dev)
3083{
3084 struct drm_i915_private *dev_priv = dev->dev_private;
3085
3086 if (HAS_PCH_NOP(dev))
3087 return;
3088
3089 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003090 I915_WRITE(SDEIER, 0xffffffff);
3091 POSTING_READ(SDEIER);
3092}
3093
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003094static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003095{
3096 struct drm_i915_private *dev_priv = dev->dev_private;
3097
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003098 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003099 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003100 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003101}
3102
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103/* drm_dma.h hooks
3104*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003105static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003106{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003107 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003108
Paulo Zanoni0c841212014-04-01 15:37:27 -03003109 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003110
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003111 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003112 if (IS_GEN7(dev))
3113 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003114
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003115 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003116
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003117 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003118}
3119
Paulo Zanonibe30b292014-04-01 15:37:25 -03003120static void ironlake_irq_preinstall(struct drm_device *dev)
3121{
Paulo Zanonibe30b292014-04-01 15:37:25 -03003122 ironlake_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003123}
3124
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003125static void valleyview_irq_preinstall(struct drm_device *dev)
3126{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003127 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003128 int pipe;
3129
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003130 /* VLV magic */
3131 I915_WRITE(VLV_IMR, 0);
3132 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3133 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3134 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3135
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003136 /* and GT */
3137 I915_WRITE(GTIIR, I915_READ(GTIIR));
3138 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003139
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003140 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003141
3142 I915_WRITE(DPINVGTT, 0xff);
3143
3144 I915_WRITE(PORT_HOTPLUG_EN, 0);
3145 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3146 for_each_pipe(pipe)
3147 I915_WRITE(PIPESTAT(pipe), 0xffff);
3148 I915_WRITE(VLV_IIR, 0xffffffff);
3149 I915_WRITE(VLV_IMR, 0xffffffff);
3150 I915_WRITE(VLV_IER, 0x0);
3151 POSTING_READ(VLV_IER);
3152}
3153
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003154static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003155{
3156 struct drm_i915_private *dev_priv = dev->dev_private;
3157 int pipe;
3158
Ben Widawskyabd58f02013-11-02 21:07:09 -07003159 I915_WRITE(GEN8_MASTER_IRQ, 0);
3160 POSTING_READ(GEN8_MASTER_IRQ);
3161
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003162 GEN8_IRQ_RESET_NDX(GT, 0);
3163 GEN8_IRQ_RESET_NDX(GT, 1);
3164 GEN8_IRQ_RESET_NDX(GT, 2);
3165 GEN8_IRQ_RESET_NDX(GT, 3);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003166
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003167 for_each_pipe(pipe)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003168 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003169
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003170 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3171 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3172 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003173
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003174 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003175}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003176
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003177static void gen8_irq_preinstall(struct drm_device *dev)
3178{
3179 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003180}
3181
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003182static void cherryview_irq_preinstall(struct drm_device *dev)
3183{
3184 struct drm_i915_private *dev_priv = dev->dev_private;
3185 int pipe;
3186
3187 I915_WRITE(GEN8_MASTER_IRQ, 0);
3188 POSTING_READ(GEN8_MASTER_IRQ);
3189
3190 GEN8_IRQ_RESET_NDX(GT, 0);
3191 GEN8_IRQ_RESET_NDX(GT, 1);
3192 GEN8_IRQ_RESET_NDX(GT, 2);
3193 GEN8_IRQ_RESET_NDX(GT, 3);
3194
3195 GEN5_IRQ_RESET(GEN8_PCU_);
3196
3197 POSTING_READ(GEN8_PCU_IIR);
3198
3199 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3200
3201 I915_WRITE(PORT_HOTPLUG_EN, 0);
3202 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3203
3204 for_each_pipe(pipe)
3205 I915_WRITE(PIPESTAT(pipe), 0xffff);
3206
3207 I915_WRITE(VLV_IMR, 0xffffffff);
3208 I915_WRITE(VLV_IER, 0x0);
3209 I915_WRITE(VLV_IIR, 0xffffffff);
3210 POSTING_READ(VLV_IIR);
3211}
3212
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003213static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003214{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003215 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003216 struct drm_mode_config *mode_config = &dev->mode_config;
3217 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02003218 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07003219
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003220 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003221 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003222 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003223 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003224 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003225 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003226 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003227 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003228 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003229 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003230 }
3231
Daniel Vetterfee884e2013-07-04 23:35:21 +02003232 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003233
3234 /*
3235 * Enable digital hotplug on the PCH, and configure the DP short pulse
3236 * duration to 2ms (which is the minimum in the Display Port spec)
3237 *
3238 * This register is the same on all known PCH chips.
3239 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003240 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3241 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3242 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3243 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3244 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3245 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3246}
3247
Paulo Zanonid46da432013-02-08 17:35:15 -02003248static void ibx_irq_postinstall(struct drm_device *dev)
3249{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003250 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003251 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003252
Daniel Vetter692a04c2013-05-29 21:43:05 +02003253 if (HAS_PCH_NOP(dev))
3254 return;
3255
Paulo Zanoni105b1222014-04-01 15:37:17 -03003256 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003257 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003258 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003259 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003260
Paulo Zanoni337ba012014-04-01 15:37:16 -03003261 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003262 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003263}
3264
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003265static void gen5_gt_irq_postinstall(struct drm_device *dev)
3266{
3267 struct drm_i915_private *dev_priv = dev->dev_private;
3268 u32 pm_irqs, gt_irqs;
3269
3270 pm_irqs = gt_irqs = 0;
3271
3272 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003273 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003274 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003275 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3276 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003277 }
3278
3279 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3280 if (IS_GEN5(dev)) {
3281 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3282 ILK_BSD_USER_INTERRUPT;
3283 } else {
3284 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3285 }
3286
Paulo Zanoni35079892014-04-01 15:37:15 -03003287 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003288
3289 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303290 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003291
3292 if (HAS_VEBOX(dev))
3293 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3294
Paulo Zanoni605cd252013-08-06 18:57:15 -03003295 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003296 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003297 }
3298}
3299
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003300static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003301{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003302 unsigned long irqflags;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003303 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003304 u32 display_mask, extra_mask;
3305
3306 if (INTEL_INFO(dev)->gen >= 7) {
3307 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3308 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3309 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003310 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003311 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003312 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003313 } else {
3314 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3315 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003316 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003317 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3318 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003319 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3320 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003321 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003322
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003323 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003324
Paulo Zanoni0c841212014-04-01 15:37:27 -03003325 I915_WRITE(HWSTAM, 0xeffe);
3326
Paulo Zanoni622364b2014-04-01 15:37:22 -03003327 ibx_irq_pre_postinstall(dev);
3328
Paulo Zanoni35079892014-04-01 15:37:15 -03003329 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003330
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003331 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003332
Paulo Zanonid46da432013-02-08 17:35:15 -02003333 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003334
Jesse Barnesf97108d2010-01-29 11:27:07 -08003335 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003336 /* Enable PCU event interrupts
3337 *
3338 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003339 * setup is guaranteed to run in single-threaded context. But we
3340 * need it to make the assert_spin_locked happy. */
3341 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003342 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003343 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003344 }
3345
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003346 return 0;
3347}
3348
Imre Deakf8b79e52014-03-04 19:23:07 +02003349static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3350{
3351 u32 pipestat_mask;
3352 u32 iir_mask;
3353
3354 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3355 PIPE_FIFO_UNDERRUN_STATUS;
3356
3357 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3358 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3359 POSTING_READ(PIPESTAT(PIPE_A));
3360
3361 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3362 PIPE_CRC_DONE_INTERRUPT_STATUS;
3363
3364 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3365 PIPE_GMBUS_INTERRUPT_STATUS);
3366 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3367
3368 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3369 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3370 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3371 dev_priv->irq_mask &= ~iir_mask;
3372
3373 I915_WRITE(VLV_IIR, iir_mask);
3374 I915_WRITE(VLV_IIR, iir_mask);
3375 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3376 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3377 POSTING_READ(VLV_IER);
3378}
3379
3380static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3381{
3382 u32 pipestat_mask;
3383 u32 iir_mask;
3384
3385 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3386 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003387 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003388
3389 dev_priv->irq_mask |= iir_mask;
3390 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3391 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3392 I915_WRITE(VLV_IIR, iir_mask);
3393 I915_WRITE(VLV_IIR, iir_mask);
3394 POSTING_READ(VLV_IIR);
3395
3396 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3397 PIPE_CRC_DONE_INTERRUPT_STATUS;
3398
3399 i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3400 PIPE_GMBUS_INTERRUPT_STATUS);
3401 i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3402
3403 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3404 PIPE_FIFO_UNDERRUN_STATUS;
3405 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3406 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3407 POSTING_READ(PIPESTAT(PIPE_A));
3408}
3409
3410void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3411{
3412 assert_spin_locked(&dev_priv->irq_lock);
3413
3414 if (dev_priv->display_irqs_enabled)
3415 return;
3416
3417 dev_priv->display_irqs_enabled = true;
3418
3419 if (dev_priv->dev->irq_enabled)
3420 valleyview_display_irqs_install(dev_priv);
3421}
3422
3423void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3424{
3425 assert_spin_locked(&dev_priv->irq_lock);
3426
3427 if (!dev_priv->display_irqs_enabled)
3428 return;
3429
3430 dev_priv->display_irqs_enabled = false;
3431
3432 if (dev_priv->dev->irq_enabled)
3433 valleyview_display_irqs_uninstall(dev_priv);
3434}
3435
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003436static int valleyview_irq_postinstall(struct drm_device *dev)
3437{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003438 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003439 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003440
Imre Deakf8b79e52014-03-04 19:23:07 +02003441 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003442
Daniel Vetter20afbda2012-12-11 14:05:07 +01003443 I915_WRITE(PORT_HOTPLUG_EN, 0);
3444 POSTING_READ(PORT_HOTPLUG_EN);
3445
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003446 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003447 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003448 I915_WRITE(VLV_IIR, 0xffffffff);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003449 POSTING_READ(VLV_IER);
3450
Daniel Vetterb79480b2013-06-27 17:52:10 +02003451 /* Interrupt setup is already guaranteed to be single-threaded, this is
3452 * just to make the assert_spin_locked check happy. */
3453 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deakf8b79e52014-03-04 19:23:07 +02003454 if (dev_priv->display_irqs_enabled)
3455 valleyview_display_irqs_install(dev_priv);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003456 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003457
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003458 I915_WRITE(VLV_IIR, 0xffffffff);
3459 I915_WRITE(VLV_IIR, 0xffffffff);
3460
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003461 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003462
3463 /* ack & enable invalid PTE error interrupts */
3464#if 0 /* FIXME: add support to irq handler for checking these bits */
3465 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3466 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3467#endif
3468
3469 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003470
3471 return 0;
3472}
3473
Ben Widawskyabd58f02013-11-02 21:07:09 -07003474static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3475{
3476 int i;
3477
3478 /* These are interrupts we'll toggle with the ring mask register */
3479 uint32_t gt_interrupts[] = {
3480 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3481 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3482 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3483 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3484 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3485 0,
3486 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3487 };
3488
Paulo Zanoni337ba012014-04-01 15:37:16 -03003489 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++)
Paulo Zanoni35079892014-04-01 15:37:15 -03003490 GEN8_IRQ_INIT_NDX(GT, i, ~gt_interrupts[i], gt_interrupts[i]);
Ben Widawsky09610212014-05-15 20:58:08 +03003491
3492 dev_priv->pm_irq_mask = 0xffffffff;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003493}
3494
3495static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3496{
3497 struct drm_device *dev = dev_priv->dev;
Damien Lespiaud0e1f1c2014-04-08 01:22:44 +01003498 uint32_t de_pipe_masked = GEN8_PIPE_PRIMARY_FLIP_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003499 GEN8_PIPE_CDCLK_CRC_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003500 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Daniel Vetter5c673b62014-03-07 20:34:46 +01003501 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3502 GEN8_PIPE_FIFO_UNDERRUN;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003503 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003504 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3505 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3506 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003507
Paulo Zanoni337ba012014-04-01 15:37:16 -03003508 for_each_pipe(pipe)
Paulo Zanoni35079892014-04-01 15:37:15 -03003509 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe, dev_priv->de_irq_mask[pipe],
3510 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003511
Paulo Zanoni35079892014-04-01 15:37:15 -03003512 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003513}
3514
3515static int gen8_irq_postinstall(struct drm_device *dev)
3516{
3517 struct drm_i915_private *dev_priv = dev->dev_private;
3518
Paulo Zanoni622364b2014-04-01 15:37:22 -03003519 ibx_irq_pre_postinstall(dev);
3520
Ben Widawskyabd58f02013-11-02 21:07:09 -07003521 gen8_gt_irq_postinstall(dev_priv);
3522 gen8_de_irq_postinstall(dev_priv);
3523
3524 ibx_irq_postinstall(dev);
3525
3526 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3527 POSTING_READ(GEN8_MASTER_IRQ);
3528
3529 return 0;
3530}
3531
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003532static int cherryview_irq_postinstall(struct drm_device *dev)
3533{
3534 struct drm_i915_private *dev_priv = dev->dev_private;
3535 u32 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3536 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003537 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä3278f672014-04-09 13:28:49 +03003538 I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3539 u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
3540 PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003541 unsigned long irqflags;
3542 int pipe;
3543
3544 /*
3545 * Leave vblank interrupts masked initially. enable/disable will
3546 * toggle them based on usage.
3547 */
Ville Syrjälä3278f672014-04-09 13:28:49 +03003548 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003549
3550 for_each_pipe(pipe)
3551 I915_WRITE(PIPESTAT(pipe), 0xffff);
3552
3553 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä3278f672014-04-09 13:28:49 +03003554 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003555 for_each_pipe(pipe)
3556 i915_enable_pipestat(dev_priv, pipe, pipestat_enable);
3557 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3558
3559 I915_WRITE(VLV_IIR, 0xffffffff);
3560 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3561 I915_WRITE(VLV_IER, enable_mask);
3562
3563 gen8_gt_irq_postinstall(dev_priv);
3564
3565 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3566 POSTING_READ(GEN8_MASTER_IRQ);
3567
3568 return 0;
3569}
3570
Ben Widawskyabd58f02013-11-02 21:07:09 -07003571static void gen8_irq_uninstall(struct drm_device *dev)
3572{
3573 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003574
3575 if (!dev_priv)
3576 return;
3577
Paulo Zanonid4eb6b12014-04-01 15:37:24 -03003578 intel_hpd_irq_uninstall(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003579
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003580 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003581}
3582
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003583static void valleyview_irq_uninstall(struct drm_device *dev)
3584{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003585 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakf8b79e52014-03-04 19:23:07 +02003586 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003587 int pipe;
3588
3589 if (!dev_priv)
3590 return;
3591
Imre Deak843d0e72014-04-14 20:24:23 +03003592 I915_WRITE(VLV_MASTER_IER, 0);
3593
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003594 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003595
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003596 for_each_pipe(pipe)
3597 I915_WRITE(PIPESTAT(pipe), 0xffff);
3598
3599 I915_WRITE(HWSTAM, 0xffffffff);
3600 I915_WRITE(PORT_HOTPLUG_EN, 0);
3601 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Imre Deakf8b79e52014-03-04 19:23:07 +02003602
3603 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3604 if (dev_priv->display_irqs_enabled)
3605 valleyview_display_irqs_uninstall(dev_priv);
3606 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3607
3608 dev_priv->irq_mask = 0;
3609
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003610 I915_WRITE(VLV_IIR, 0xffffffff);
3611 I915_WRITE(VLV_IMR, 0xffffffff);
3612 I915_WRITE(VLV_IER, 0x0);
3613 POSTING_READ(VLV_IER);
3614}
3615
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003616static void cherryview_irq_uninstall(struct drm_device *dev)
3617{
3618 struct drm_i915_private *dev_priv = dev->dev_private;
3619 int pipe;
3620
3621 if (!dev_priv)
3622 return;
3623
3624 I915_WRITE(GEN8_MASTER_IRQ, 0);
3625 POSTING_READ(GEN8_MASTER_IRQ);
3626
3627#define GEN8_IRQ_FINI_NDX(type, which) \
3628do { \
3629 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3630 I915_WRITE(GEN8_##type##_IER(which), 0); \
3631 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3632 POSTING_READ(GEN8_##type##_IIR(which)); \
3633 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3634} while (0)
3635
3636#define GEN8_IRQ_FINI(type) \
3637do { \
3638 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3639 I915_WRITE(GEN8_##type##_IER, 0); \
3640 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3641 POSTING_READ(GEN8_##type##_IIR); \
3642 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3643} while (0)
3644
3645 GEN8_IRQ_FINI_NDX(GT, 0);
3646 GEN8_IRQ_FINI_NDX(GT, 1);
3647 GEN8_IRQ_FINI_NDX(GT, 2);
3648 GEN8_IRQ_FINI_NDX(GT, 3);
3649
3650 GEN8_IRQ_FINI(PCU);
3651
3652#undef GEN8_IRQ_FINI
3653#undef GEN8_IRQ_FINI_NDX
3654
3655 I915_WRITE(PORT_HOTPLUG_EN, 0);
3656 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3657
3658 for_each_pipe(pipe)
3659 I915_WRITE(PIPESTAT(pipe), 0xffff);
3660
3661 I915_WRITE(VLV_IMR, 0xffffffff);
3662 I915_WRITE(VLV_IER, 0x0);
3663 I915_WRITE(VLV_IIR, 0xffffffff);
3664 POSTING_READ(VLV_IIR);
3665}
3666
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003667static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003668{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003669 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003670
3671 if (!dev_priv)
3672 return;
3673
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003674 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003675
Paulo Zanonibe30b292014-04-01 15:37:25 -03003676 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003677}
3678
Chris Wilsonc2798b12012-04-22 21:13:57 +01003679static void i8xx_irq_preinstall(struct drm_device * dev)
3680{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003681 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003682 int pipe;
3683
Chris Wilsonc2798b12012-04-22 21:13:57 +01003684 for_each_pipe(pipe)
3685 I915_WRITE(PIPESTAT(pipe), 0);
3686 I915_WRITE16(IMR, 0xffff);
3687 I915_WRITE16(IER, 0x0);
3688 POSTING_READ16(IER);
3689}
3690
3691static int i8xx_irq_postinstall(struct drm_device *dev)
3692{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003693 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003694 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003695
Chris Wilsonc2798b12012-04-22 21:13:57 +01003696 I915_WRITE16(EMR,
3697 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3698
3699 /* Unmask the interrupts that we always want on. */
3700 dev_priv->irq_mask =
3701 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3702 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3703 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3704 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3705 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3706 I915_WRITE16(IMR, dev_priv->irq_mask);
3707
3708 I915_WRITE16(IER,
3709 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3710 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3711 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3712 I915_USER_INTERRUPT);
3713 POSTING_READ16(IER);
3714
Daniel Vetter379ef822013-10-16 22:55:56 +02003715 /* Interrupt setup is already guaranteed to be single-threaded, this is
3716 * just to make the assert_spin_locked check happy. */
3717 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003718 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3719 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003720 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3721
Chris Wilsonc2798b12012-04-22 21:13:57 +01003722 return 0;
3723}
3724
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003725/*
3726 * Returns true when a page flip has completed.
3727 */
3728static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003729 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003730{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003731 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003732 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003733
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003734 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003735 return false;
3736
3737 if ((iir & flip_pending) == 0)
3738 return false;
3739
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003740 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003741
3742 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3743 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3744 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3745 * the flip is completed (no longer pending). Since this doesn't raise
3746 * an interrupt per se, we watch for the change at vblank.
3747 */
3748 if (I915_READ16(ISR) & flip_pending)
3749 return false;
3750
3751 intel_finish_page_flip(dev, pipe);
3752
3753 return true;
3754}
3755
Daniel Vetterff1f5252012-10-02 15:10:55 +02003756static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003757{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003758 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003759 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003760 u16 iir, new_iir;
3761 u32 pipe_stats[2];
3762 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003763 int pipe;
3764 u16 flip_mask =
3765 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3766 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3767
Chris Wilsonc2798b12012-04-22 21:13:57 +01003768 iir = I915_READ16(IIR);
3769 if (iir == 0)
3770 return IRQ_NONE;
3771
3772 while (iir & ~flip_mask) {
3773 /* Can't rely on pipestat interrupt bit in iir as it might
3774 * have been cleared after the pipestat interrupt was received.
3775 * It doesn't set the bit in iir again, but it still produces
3776 * interrupts (for non-MSI).
3777 */
3778 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3779 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003780 i915_handle_error(dev, false,
3781 "Command parser error, iir 0x%08x",
3782 iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003783
3784 for_each_pipe(pipe) {
3785 int reg = PIPESTAT(pipe);
3786 pipe_stats[pipe] = I915_READ(reg);
3787
3788 /*
3789 * Clear the PIPE*STAT regs before the IIR
3790 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003791 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003792 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003793 }
3794 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3795
3796 I915_WRITE16(IIR, iir & ~flip_mask);
3797 new_iir = I915_READ16(IIR); /* Flush posted writes */
3798
Daniel Vetterd05c6172012-04-26 23:28:09 +02003799 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003800
3801 if (iir & I915_USER_INTERRUPT)
3802 notify_ring(dev, &dev_priv->ring[RCS]);
3803
Daniel Vetter4356d582013-10-16 22:55:55 +02003804 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003805 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003806 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003807 plane = !plane;
3808
Daniel Vetter4356d582013-10-16 22:55:55 +02003809 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003810 i8xx_handle_vblank(dev, plane, pipe, iir))
3811 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003812
Daniel Vetter4356d582013-10-16 22:55:55 +02003813 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003814 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003815
3816 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3817 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003818 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003819 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003820
3821 iir = new_iir;
3822 }
3823
3824 return IRQ_HANDLED;
3825}
3826
3827static void i8xx_irq_uninstall(struct drm_device * dev)
3828{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003829 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003830 int pipe;
3831
Chris Wilsonc2798b12012-04-22 21:13:57 +01003832 for_each_pipe(pipe) {
3833 /* Clear enable bits; then clear status bits */
3834 I915_WRITE(PIPESTAT(pipe), 0);
3835 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3836 }
3837 I915_WRITE16(IMR, 0xffff);
3838 I915_WRITE16(IER, 0x0);
3839 I915_WRITE16(IIR, I915_READ16(IIR));
3840}
3841
Chris Wilsona266c7d2012-04-24 22:59:44 +01003842static void i915_irq_preinstall(struct drm_device * dev)
3843{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003844 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003845 int pipe;
3846
Chris Wilsona266c7d2012-04-24 22:59:44 +01003847 if (I915_HAS_HOTPLUG(dev)) {
3848 I915_WRITE(PORT_HOTPLUG_EN, 0);
3849 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3850 }
3851
Chris Wilson00d98eb2012-04-24 22:59:48 +01003852 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003853 for_each_pipe(pipe)
3854 I915_WRITE(PIPESTAT(pipe), 0);
3855 I915_WRITE(IMR, 0xffffffff);
3856 I915_WRITE(IER, 0x0);
3857 POSTING_READ(IER);
3858}
3859
3860static int i915_irq_postinstall(struct drm_device *dev)
3861{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003862 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003863 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003864 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003865
Chris Wilson38bde182012-04-24 22:59:50 +01003866 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3867
3868 /* Unmask the interrupts that we always want on. */
3869 dev_priv->irq_mask =
3870 ~(I915_ASLE_INTERRUPT |
3871 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3872 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3873 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3874 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3875 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3876
3877 enable_mask =
3878 I915_ASLE_INTERRUPT |
3879 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3880 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3881 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3882 I915_USER_INTERRUPT;
3883
Chris Wilsona266c7d2012-04-24 22:59:44 +01003884 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003885 I915_WRITE(PORT_HOTPLUG_EN, 0);
3886 POSTING_READ(PORT_HOTPLUG_EN);
3887
Chris Wilsona266c7d2012-04-24 22:59:44 +01003888 /* Enable in IER... */
3889 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3890 /* and unmask in IMR */
3891 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3892 }
3893
Chris Wilsona266c7d2012-04-24 22:59:44 +01003894 I915_WRITE(IMR, dev_priv->irq_mask);
3895 I915_WRITE(IER, enable_mask);
3896 POSTING_READ(IER);
3897
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003898 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003899
Daniel Vetter379ef822013-10-16 22:55:56 +02003900 /* Interrupt setup is already guaranteed to be single-threaded, this is
3901 * just to make the assert_spin_locked check happy. */
3902 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003903 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3904 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003905 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3906
Daniel Vetter20afbda2012-12-11 14:05:07 +01003907 return 0;
3908}
3909
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003910/*
3911 * Returns true when a page flip has completed.
3912 */
3913static bool i915_handle_vblank(struct drm_device *dev,
3914 int plane, int pipe, u32 iir)
3915{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003916 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003917 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3918
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003919 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003920 return false;
3921
3922 if ((iir & flip_pending) == 0)
3923 return false;
3924
3925 intel_prepare_page_flip(dev, plane);
3926
3927 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3928 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3929 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3930 * the flip is completed (no longer pending). Since this doesn't raise
3931 * an interrupt per se, we watch for the change at vblank.
3932 */
3933 if (I915_READ(ISR) & flip_pending)
3934 return false;
3935
3936 intel_finish_page_flip(dev, pipe);
3937
3938 return true;
3939}
3940
Daniel Vetterff1f5252012-10-02 15:10:55 +02003941static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003942{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003943 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003944 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003945 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003946 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003947 u32 flip_mask =
3948 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3949 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003950 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003951
Chris Wilsona266c7d2012-04-24 22:59:44 +01003952 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003953 do {
3954 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003955 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003956
3957 /* Can't rely on pipestat interrupt bit in iir as it might
3958 * have been cleared after the pipestat interrupt was received.
3959 * It doesn't set the bit in iir again, but it still produces
3960 * interrupts (for non-MSI).
3961 */
3962 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3963 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003964 i915_handle_error(dev, false,
3965 "Command parser error, iir 0x%08x",
3966 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003967
3968 for_each_pipe(pipe) {
3969 int reg = PIPESTAT(pipe);
3970 pipe_stats[pipe] = I915_READ(reg);
3971
Chris Wilson38bde182012-04-24 22:59:50 +01003972 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003973 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003974 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003975 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003976 }
3977 }
3978 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3979
3980 if (!irq_received)
3981 break;
3982
Chris Wilsona266c7d2012-04-24 22:59:44 +01003983 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003984 if (I915_HAS_HOTPLUG(dev) &&
3985 iir & I915_DISPLAY_PORT_INTERRUPT)
3986 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003987
Chris Wilson38bde182012-04-24 22:59:50 +01003988 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003989 new_iir = I915_READ(IIR); /* Flush posted writes */
3990
Chris Wilsona266c7d2012-04-24 22:59:44 +01003991 if (iir & I915_USER_INTERRUPT)
3992 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003993
Chris Wilsona266c7d2012-04-24 22:59:44 +01003994 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003995 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003996 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003997 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003998
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003999 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4000 i915_handle_vblank(dev, plane, pipe, iir))
4001 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004002
4003 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4004 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004005
4006 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004007 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004008
4009 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4010 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004011 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004012 }
4013
Chris Wilsona266c7d2012-04-24 22:59:44 +01004014 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4015 intel_opregion_asle_intr(dev);
4016
4017 /* With MSI, interrupts are only generated when iir
4018 * transitions from zero to nonzero. If another bit got
4019 * set while we were handling the existing iir bits, then
4020 * we would never get another interrupt.
4021 *
4022 * This is fine on non-MSI as well, as if we hit this path
4023 * we avoid exiting the interrupt handler only to generate
4024 * another one.
4025 *
4026 * Note that for MSI this could cause a stray interrupt report
4027 * if an interrupt landed in the time between writing IIR and
4028 * the posting read. This should be rare enough to never
4029 * trigger the 99% of 100,000 interrupts test for disabling
4030 * stray interrupts.
4031 */
Chris Wilson38bde182012-04-24 22:59:50 +01004032 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004033 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004034 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004035
Daniel Vetterd05c6172012-04-26 23:28:09 +02004036 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004037
Chris Wilsona266c7d2012-04-24 22:59:44 +01004038 return ret;
4039}
4040
4041static void i915_irq_uninstall(struct drm_device * dev)
4042{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004043 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004044 int pipe;
4045
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004046 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004047
Chris Wilsona266c7d2012-04-24 22:59:44 +01004048 if (I915_HAS_HOTPLUG(dev)) {
4049 I915_WRITE(PORT_HOTPLUG_EN, 0);
4050 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4051 }
4052
Chris Wilson00d98eb2012-04-24 22:59:48 +01004053 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01004054 for_each_pipe(pipe) {
4055 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004056 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004057 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4058 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004059 I915_WRITE(IMR, 0xffffffff);
4060 I915_WRITE(IER, 0x0);
4061
Chris Wilsona266c7d2012-04-24 22:59:44 +01004062 I915_WRITE(IIR, I915_READ(IIR));
4063}
4064
4065static void i965_irq_preinstall(struct drm_device * dev)
4066{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004067 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004068 int pipe;
4069
Chris Wilsonadca4732012-05-11 18:01:31 +01004070 I915_WRITE(PORT_HOTPLUG_EN, 0);
4071 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004072
4073 I915_WRITE(HWSTAM, 0xeffe);
4074 for_each_pipe(pipe)
4075 I915_WRITE(PIPESTAT(pipe), 0);
4076 I915_WRITE(IMR, 0xffffffff);
4077 I915_WRITE(IER, 0x0);
4078 POSTING_READ(IER);
4079}
4080
4081static int i965_irq_postinstall(struct drm_device *dev)
4082{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004083 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004084 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004085 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02004086 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004087
Chris Wilsona266c7d2012-04-24 22:59:44 +01004088 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004089 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004090 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004091 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4092 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4093 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4094 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4095 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4096
4097 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004098 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4099 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004100 enable_mask |= I915_USER_INTERRUPT;
4101
4102 if (IS_G4X(dev))
4103 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004104
Daniel Vetterb79480b2013-06-27 17:52:10 +02004105 /* Interrupt setup is already guaranteed to be single-threaded, this is
4106 * just to make the assert_spin_locked check happy. */
4107 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02004108 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4109 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4110 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterb79480b2013-06-27 17:52:10 +02004111 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004112
Chris Wilsona266c7d2012-04-24 22:59:44 +01004113 /*
4114 * Enable some error detection, note the instruction error mask
4115 * bit is reserved, so we leave it masked.
4116 */
4117 if (IS_G4X(dev)) {
4118 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4119 GM45_ERROR_MEM_PRIV |
4120 GM45_ERROR_CP_PRIV |
4121 I915_ERROR_MEMORY_REFRESH);
4122 } else {
4123 error_mask = ~(I915_ERROR_PAGE_TABLE |
4124 I915_ERROR_MEMORY_REFRESH);
4125 }
4126 I915_WRITE(EMR, error_mask);
4127
4128 I915_WRITE(IMR, dev_priv->irq_mask);
4129 I915_WRITE(IER, enable_mask);
4130 POSTING_READ(IER);
4131
Daniel Vetter20afbda2012-12-11 14:05:07 +01004132 I915_WRITE(PORT_HOTPLUG_EN, 0);
4133 POSTING_READ(PORT_HOTPLUG_EN);
4134
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004135 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004136
4137 return 0;
4138}
4139
Egbert Eichbac56d52013-02-25 12:06:51 -05004140static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004141{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004142 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05004143 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02004144 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004145 u32 hotplug_en;
4146
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004147 assert_spin_locked(&dev_priv->irq_lock);
4148
Egbert Eichbac56d52013-02-25 12:06:51 -05004149 if (I915_HAS_HOTPLUG(dev)) {
4150 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4151 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4152 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05004153 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02004154 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
4155 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4156 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05004157 /* Programming the CRT detection parameters tends
4158 to generate a spurious hotplug event about three
4159 seconds later. So just do it once.
4160 */
4161 if (IS_G4X(dev))
4162 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01004163 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05004164 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004165
Egbert Eichbac56d52013-02-25 12:06:51 -05004166 /* Ignore TV since it's buggy */
4167 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4168 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004169}
4170
Daniel Vetterff1f5252012-10-02 15:10:55 +02004171static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004172{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004173 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004174 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004175 u32 iir, new_iir;
4176 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004177 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004178 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004179 u32 flip_mask =
4180 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4181 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004182
Chris Wilsona266c7d2012-04-24 22:59:44 +01004183 iir = I915_READ(IIR);
4184
Chris Wilsona266c7d2012-04-24 22:59:44 +01004185 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004186 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004187 bool blc_event = false;
4188
Chris Wilsona266c7d2012-04-24 22:59:44 +01004189 /* Can't rely on pipestat interrupt bit in iir as it might
4190 * have been cleared after the pipestat interrupt was received.
4191 * It doesn't set the bit in iir again, but it still produces
4192 * interrupts (for non-MSI).
4193 */
4194 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4195 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004196 i915_handle_error(dev, false,
4197 "Command parser error, iir 0x%08x",
4198 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004199
4200 for_each_pipe(pipe) {
4201 int reg = PIPESTAT(pipe);
4202 pipe_stats[pipe] = I915_READ(reg);
4203
4204 /*
4205 * Clear the PIPE*STAT regs before the IIR
4206 */
4207 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004208 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004209 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004210 }
4211 }
4212 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4213
4214 if (!irq_received)
4215 break;
4216
4217 ret = IRQ_HANDLED;
4218
4219 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004220 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4221 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004222
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004223 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004224 new_iir = I915_READ(IIR); /* Flush posted writes */
4225
Chris Wilsona266c7d2012-04-24 22:59:44 +01004226 if (iir & I915_USER_INTERRUPT)
4227 notify_ring(dev, &dev_priv->ring[RCS]);
4228 if (iir & I915_BSD_USER_INTERRUPT)
4229 notify_ring(dev, &dev_priv->ring[VCS]);
4230
Chris Wilsona266c7d2012-04-24 22:59:44 +01004231 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004232 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004233 i915_handle_vblank(dev, pipe, pipe, iir))
4234 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004235
4236 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4237 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004238
4239 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004240 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004241
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004242 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4243 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004244 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004245 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004246
4247 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4248 intel_opregion_asle_intr(dev);
4249
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004250 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4251 gmbus_irq_handler(dev);
4252
Chris Wilsona266c7d2012-04-24 22:59:44 +01004253 /* With MSI, interrupts are only generated when iir
4254 * transitions from zero to nonzero. If another bit got
4255 * set while we were handling the existing iir bits, then
4256 * we would never get another interrupt.
4257 *
4258 * This is fine on non-MSI as well, as if we hit this path
4259 * we avoid exiting the interrupt handler only to generate
4260 * another one.
4261 *
4262 * Note that for MSI this could cause a stray interrupt report
4263 * if an interrupt landed in the time between writing IIR and
4264 * the posting read. This should be rare enough to never
4265 * trigger the 99% of 100,000 interrupts test for disabling
4266 * stray interrupts.
4267 */
4268 iir = new_iir;
4269 }
4270
Daniel Vetterd05c6172012-04-26 23:28:09 +02004271 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01004272
Chris Wilsona266c7d2012-04-24 22:59:44 +01004273 return ret;
4274}
4275
4276static void i965_irq_uninstall(struct drm_device * dev)
4277{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004278 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004279 int pipe;
4280
4281 if (!dev_priv)
4282 return;
4283
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004284 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004285
Chris Wilsonadca4732012-05-11 18:01:31 +01004286 I915_WRITE(PORT_HOTPLUG_EN, 0);
4287 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004288
4289 I915_WRITE(HWSTAM, 0xffffffff);
4290 for_each_pipe(pipe)
4291 I915_WRITE(PIPESTAT(pipe), 0);
4292 I915_WRITE(IMR, 0xffffffff);
4293 I915_WRITE(IER, 0x0);
4294
4295 for_each_pipe(pipe)
4296 I915_WRITE(PIPESTAT(pipe),
4297 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4298 I915_WRITE(IIR, I915_READ(IIR));
4299}
4300
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004301static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02004302{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004303 struct drm_i915_private *dev_priv = (struct drm_i915_private *)data;
Egbert Eichac4c16c2013-04-16 13:36:58 +02004304 struct drm_device *dev = dev_priv->dev;
4305 struct drm_mode_config *mode_config = &dev->mode_config;
4306 unsigned long irqflags;
4307 int i;
4308
4309 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4310 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4311 struct drm_connector *connector;
4312
4313 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4314 continue;
4315
4316 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4317
4318 list_for_each_entry(connector, &mode_config->connector_list, head) {
4319 struct intel_connector *intel_connector = to_intel_connector(connector);
4320
4321 if (intel_connector->encoder->hpd_pin == i) {
4322 if (connector->polled != intel_connector->polled)
4323 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
4324 drm_get_connector_name(connector));
4325 connector->polled = intel_connector->polled;
4326 if (!connector->polled)
4327 connector->polled = DRM_CONNECTOR_POLL_HPD;
4328 }
4329 }
4330 }
4331 if (dev_priv->display.hpd_irq_setup)
4332 dev_priv->display.hpd_irq_setup(dev);
4333 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4334}
4335
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004336void intel_irq_init(struct drm_device *dev)
4337{
Chris Wilson8b2e3262012-04-24 22:59:41 +01004338 struct drm_i915_private *dev_priv = dev->dev_private;
4339
4340 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004341 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004342 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004343 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004344
Deepak Sa6706b42014-03-15 20:23:22 +05304345 /* Let's track the enabled rps events */
4346 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
4347
Daniel Vetter99584db2012-11-14 17:14:04 +01004348 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4349 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004350 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004351 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02004352 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01004353
Tomas Janousek97a19a22012-12-08 13:48:13 +01004354 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004355
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004356 if (IS_GEN2(dev)) {
4357 dev->max_vblank_count = 0;
4358 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4359 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004360 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4361 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004362 } else {
4363 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4364 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004365 }
4366
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004367 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004368 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004369 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4370 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004371
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004372 if (IS_CHERRYVIEW(dev)) {
4373 dev->driver->irq_handler = cherryview_irq_handler;
4374 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4375 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4376 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4377 dev->driver->enable_vblank = valleyview_enable_vblank;
4378 dev->driver->disable_vblank = valleyview_disable_vblank;
4379 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4380 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004381 dev->driver->irq_handler = valleyview_irq_handler;
4382 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4383 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4384 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4385 dev->driver->enable_vblank = valleyview_enable_vblank;
4386 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004387 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004388 } else if (IS_GEN8(dev)) {
4389 dev->driver->irq_handler = gen8_irq_handler;
4390 dev->driver->irq_preinstall = gen8_irq_preinstall;
4391 dev->driver->irq_postinstall = gen8_irq_postinstall;
4392 dev->driver->irq_uninstall = gen8_irq_uninstall;
4393 dev->driver->enable_vblank = gen8_enable_vblank;
4394 dev->driver->disable_vblank = gen8_disable_vblank;
4395 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004396 } else if (HAS_PCH_SPLIT(dev)) {
4397 dev->driver->irq_handler = ironlake_irq_handler;
4398 dev->driver->irq_preinstall = ironlake_irq_preinstall;
4399 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4400 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4401 dev->driver->enable_vblank = ironlake_enable_vblank;
4402 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004403 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004404 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004405 if (INTEL_INFO(dev)->gen == 2) {
4406 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4407 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4408 dev->driver->irq_handler = i8xx_irq_handler;
4409 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004410 } else if (INTEL_INFO(dev)->gen == 3) {
4411 dev->driver->irq_preinstall = i915_irq_preinstall;
4412 dev->driver->irq_postinstall = i915_irq_postinstall;
4413 dev->driver->irq_uninstall = i915_irq_uninstall;
4414 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004415 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004416 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004417 dev->driver->irq_preinstall = i965_irq_preinstall;
4418 dev->driver->irq_postinstall = i965_irq_postinstall;
4419 dev->driver->irq_uninstall = i965_irq_uninstall;
4420 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004421 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004422 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004423 dev->driver->enable_vblank = i915_enable_vblank;
4424 dev->driver->disable_vblank = i915_disable_vblank;
4425 }
4426}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004427
4428void intel_hpd_init(struct drm_device *dev)
4429{
4430 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02004431 struct drm_mode_config *mode_config = &dev->mode_config;
4432 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004433 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02004434 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004435
Egbert Eich821450c2013-04-16 13:36:55 +02004436 for (i = 1; i < HPD_NUM_PINS; i++) {
4437 dev_priv->hpd_stats[i].hpd_cnt = 0;
4438 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4439 }
4440 list_for_each_entry(connector, &mode_config->connector_list, head) {
4441 struct intel_connector *intel_connector = to_intel_connector(connector);
4442 connector->polled = intel_connector->polled;
4443 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4444 connector->polled = DRM_CONNECTOR_POLL_HPD;
4445 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004446
4447 /* Interrupt setup is already guaranteed to be single-threaded, this is
4448 * just to make the assert_spin_locked checks happy. */
4449 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004450 if (dev_priv->display.hpd_irq_setup)
4451 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004452 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004453}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004454
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004455/* Disable interrupts so we can allow runtime PM. */
Paulo Zanoni730488b2014-03-07 20:12:32 -03004456void intel_runtime_pm_disable_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004457{
4458 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004459
Paulo Zanoni730488b2014-03-07 20:12:32 -03004460 dev->driver->irq_uninstall(dev);
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004461 dev_priv->pm.irqs_disabled = true;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004462}
4463
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004464/* Restore interrupts so we can recover from runtime PM. */
Paulo Zanoni730488b2014-03-07 20:12:32 -03004465void intel_runtime_pm_restore_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004466{
4467 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004468
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004469 dev_priv->pm.irqs_disabled = false;
Paulo Zanoni730488b2014-03-07 20:12:32 -03004470 dev->driver->irq_preinstall(dev);
4471 dev->driver->irq_postinstall(dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004472}