blob: 737b23982b958b8a2f7367818bdc6f8d8a5a1d35 [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
Daniel Vetterfca52a52014-09-30 10:56:45 +020040/**
41 * DOC: interrupt handling
42 *
43 * These functions provide the basic support for enabling and disabling the
44 * interrupt handling support. There's a lot more functionality in i915_irq.c
45 * and related files, but that will be described in separate chapters.
46 */
47
Egbert Eiche5868a32013-02-28 04:17:12 -050048static const u32 hpd_ibx[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG,
50 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
51 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
54};
55
56static const u32 hpd_cpt[] = {
57 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010058 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050059 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
60 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
61 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
62};
63
64static const u32 hpd_mask_i915[] = {
65 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
68 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
69 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
71};
72
Daniel Vetter704cfb82013-12-18 09:08:43 +010073static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050074 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
77 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
78 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
79 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
80};
81
Egbert Eiche5868a32013-02-28 04:17:12 -050082static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
83 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
84 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
85 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
86 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
87 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
88 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
89};
90
Paulo Zanoni5c502442014-04-01 15:37:11 -030091/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -030092#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -030093 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
94 POSTING_READ(GEN8_##type##_IMR(which)); \
95 I915_WRITE(GEN8_##type##_IER(which), 0); \
96 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
97 POSTING_READ(GEN8_##type##_IIR(which)); \
98 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
99 POSTING_READ(GEN8_##type##_IIR(which)); \
100} while (0)
101
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300102#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300103 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300104 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300105 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300106 I915_WRITE(type##IIR, 0xffffffff); \
107 POSTING_READ(type##IIR); \
108 I915_WRITE(type##IIR, 0xffffffff); \
109 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300110} while (0)
111
Paulo Zanoni337ba012014-04-01 15:37:16 -0300112/*
113 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
114 */
115#define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
116 u32 val = I915_READ(reg); \
117 if (val) { \
118 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
119 (reg), val); \
120 I915_WRITE((reg), 0xffffffff); \
121 POSTING_READ(reg); \
122 I915_WRITE((reg), 0xffffffff); \
123 POSTING_READ(reg); \
124 } \
125} while (0)
126
Paulo Zanoni35079892014-04-01 15:37:15 -0300127#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300128 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300129 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
130 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
131 POSTING_READ(GEN8_##type##_IER(which)); \
132} while (0)
133
134#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300135 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300136 I915_WRITE(type##IMR, (imr_val)); \
137 I915_WRITE(type##IER, (ier_val)); \
138 POSTING_READ(type##IER); \
139} while (0)
140
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800141/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +0100142static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300143ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800144{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200145 assert_spin_locked(&dev_priv->irq_lock);
146
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700147 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300148 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300149
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000150 if ((dev_priv->irq_mask & mask) != 0) {
151 dev_priv->irq_mask &= ~mask;
152 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000153 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800154 }
155}
156
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300157static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300158ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800159{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200160 assert_spin_locked(&dev_priv->irq_lock);
161
Paulo Zanoni06ffc772014-07-17 17:43:46 -0300162 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300163 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300164
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000165 if ((dev_priv->irq_mask & mask) != mask) {
166 dev_priv->irq_mask |= mask;
167 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000168 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800169 }
170}
171
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300172/**
173 * ilk_update_gt_irq - update GTIMR
174 * @dev_priv: driver private
175 * @interrupt_mask: mask of interrupt bits to update
176 * @enabled_irq_mask: mask of interrupt bits to enable
177 */
178static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
179 uint32_t interrupt_mask,
180 uint32_t enabled_irq_mask)
181{
182 assert_spin_locked(&dev_priv->irq_lock);
183
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700184 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300185 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300186
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300187 dev_priv->gt_irq_mask &= ~interrupt_mask;
188 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
189 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
190 POSTING_READ(GTIMR);
191}
192
Daniel Vetter480c8032014-07-16 09:49:40 +0200193void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300194{
195 ilk_update_gt_irq(dev_priv, mask, mask);
196}
197
Daniel Vetter480c8032014-07-16 09:49:40 +0200198void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300199{
200 ilk_update_gt_irq(dev_priv, mask, 0);
201}
202
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300203/**
204 * snb_update_pm_irq - update GEN6_PMIMR
205 * @dev_priv: driver private
206 * @interrupt_mask: mask of interrupt bits to update
207 * @enabled_irq_mask: mask of interrupt bits to enable
208 */
209static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
210 uint32_t interrupt_mask,
211 uint32_t enabled_irq_mask)
212{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300213 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300214
215 assert_spin_locked(&dev_priv->irq_lock);
216
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700217 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300218 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300219
Paulo Zanoni605cd252013-08-06 18:57:15 -0300220 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300221 new_val &= ~interrupt_mask;
222 new_val |= (~enabled_irq_mask & interrupt_mask);
223
Paulo Zanoni605cd252013-08-06 18:57:15 -0300224 if (new_val != dev_priv->pm_irq_mask) {
225 dev_priv->pm_irq_mask = new_val;
226 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300227 POSTING_READ(GEN6_PMIMR);
228 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300229}
230
Daniel Vetter480c8032014-07-16 09:49:40 +0200231void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300232{
233 snb_update_pm_irq(dev_priv, mask, mask);
234}
235
Daniel Vetter480c8032014-07-16 09:49:40 +0200236void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300237{
238 snb_update_pm_irq(dev_priv, mask, 0);
239}
240
Paulo Zanoni86642812013-04-12 17:57:57 -0300241static bool ivb_can_enable_err_int(struct drm_device *dev)
242{
243 struct drm_i915_private *dev_priv = dev->dev_private;
244 struct intel_crtc *crtc;
245 enum pipe pipe;
246
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200247 assert_spin_locked(&dev_priv->irq_lock);
248
Damien Lespiau055e3932014-08-18 13:49:10 +0100249 for_each_pipe(dev_priv, pipe) {
Paulo Zanoni86642812013-04-12 17:57:57 -0300250 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
251
252 if (crtc->cpu_fifo_underrun_disabled)
253 return false;
254 }
255
256 return true;
257}
258
Ben Widawsky09610212014-05-15 20:58:08 +0300259/**
260 * bdw_update_pm_irq - update GT interrupt 2
261 * @dev_priv: driver private
262 * @interrupt_mask: mask of interrupt bits to update
263 * @enabled_irq_mask: mask of interrupt bits to enable
264 *
265 * Copied from the snb function, updated with relevant register offsets
266 */
267static void bdw_update_pm_irq(struct drm_i915_private *dev_priv,
268 uint32_t interrupt_mask,
269 uint32_t enabled_irq_mask)
270{
271 uint32_t new_val;
272
273 assert_spin_locked(&dev_priv->irq_lock);
274
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700275 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Ben Widawsky09610212014-05-15 20:58:08 +0300276 return;
277
278 new_val = dev_priv->pm_irq_mask;
279 new_val &= ~interrupt_mask;
280 new_val |= (~enabled_irq_mask & interrupt_mask);
281
282 if (new_val != dev_priv->pm_irq_mask) {
283 dev_priv->pm_irq_mask = new_val;
284 I915_WRITE(GEN8_GT_IMR(2), dev_priv->pm_irq_mask);
285 POSTING_READ(GEN8_GT_IMR(2));
286 }
287}
288
Daniel Vetter480c8032014-07-16 09:49:40 +0200289void gen8_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Ben Widawsky09610212014-05-15 20:58:08 +0300290{
291 bdw_update_pm_irq(dev_priv, mask, mask);
292}
293
Daniel Vetter480c8032014-07-16 09:49:40 +0200294void gen8_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Ben Widawsky09610212014-05-15 20:58:08 +0300295{
296 bdw_update_pm_irq(dev_priv, mask, 0);
297}
298
Paulo Zanoni86642812013-04-12 17:57:57 -0300299static bool cpt_can_enable_serr_int(struct drm_device *dev)
300{
301 struct drm_i915_private *dev_priv = dev->dev_private;
302 enum pipe pipe;
303 struct intel_crtc *crtc;
304
Daniel Vetterfee884e2013-07-04 23:35:21 +0200305 assert_spin_locked(&dev_priv->irq_lock);
306
Damien Lespiau055e3932014-08-18 13:49:10 +0100307 for_each_pipe(dev_priv, pipe) {
Paulo Zanoni86642812013-04-12 17:57:57 -0300308 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
309
310 if (crtc->pch_fifo_underrun_disabled)
311 return false;
312 }
313
314 return true;
315}
316
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300317void i9xx_check_fifo_underruns(struct drm_device *dev)
318{
319 struct drm_i915_private *dev_priv = dev->dev_private;
320 struct intel_crtc *crtc;
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300321
Daniel Vetter13321782014-09-15 14:55:29 +0200322 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300323
324 for_each_intel_crtc(dev, crtc) {
325 u32 reg = PIPESTAT(crtc->pipe);
326 u32 pipestat;
327
328 if (crtc->cpu_fifo_underrun_disabled)
329 continue;
330
331 pipestat = I915_READ(reg) & 0xffff0000;
332 if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
333 continue;
334
335 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
336 POSTING_READ(reg);
337
338 DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
339 }
340
Daniel Vetter13321782014-09-15 14:55:29 +0200341 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300342}
343
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300344static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200345 enum pipe pipe,
346 bool enable, bool old)
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200347{
348 struct drm_i915_private *dev_priv = dev->dev_private;
349 u32 reg = PIPESTAT(pipe);
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300350 u32 pipestat = I915_READ(reg) & 0xffff0000;
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200351
352 assert_spin_locked(&dev_priv->irq_lock);
353
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300354 if (enable) {
355 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
356 POSTING_READ(reg);
357 } else {
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200358 if (old && pipestat & PIPE_FIFO_UNDERRUN_STATUS)
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300359 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
360 }
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200361}
362
Paulo Zanoni86642812013-04-12 17:57:57 -0300363static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
364 enum pipe pipe, bool enable)
365{
366 struct drm_i915_private *dev_priv = dev->dev_private;
367 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
368 DE_PIPEB_FIFO_UNDERRUN;
369
370 if (enable)
371 ironlake_enable_display_irq(dev_priv, bit);
372 else
373 ironlake_disable_display_irq(dev_priv, bit);
374}
375
376static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200377 enum pipe pipe,
378 bool enable, bool old)
Paulo Zanoni86642812013-04-12 17:57:57 -0300379{
380 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300381 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200382 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
383
Paulo Zanoni86642812013-04-12 17:57:57 -0300384 if (!ivb_can_enable_err_int(dev))
385 return;
386
Paulo Zanoni86642812013-04-12 17:57:57 -0300387 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
388 } else {
389 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200390
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200391 if (old &&
392 I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300393 DRM_ERROR("uncleared fifo underrun on pipe %c\n",
394 pipe_name(pipe));
Daniel Vetter7336df62013-07-09 22:59:16 +0200395 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300396 }
397}
398
Daniel Vetter38d83c962013-11-07 11:05:46 +0100399static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
400 enum pipe pipe, bool enable)
401{
402 struct drm_i915_private *dev_priv = dev->dev_private;
403
404 assert_spin_locked(&dev_priv->irq_lock);
405
406 if (enable)
407 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
408 else
409 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
410 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
411 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
412}
413
Daniel Vetterfee884e2013-07-04 23:35:21 +0200414/**
415 * ibx_display_interrupt_update - update SDEIMR
416 * @dev_priv: driver private
417 * @interrupt_mask: mask of interrupt bits to update
418 * @enabled_irq_mask: mask of interrupt bits to enable
419 */
420static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
421 uint32_t interrupt_mask,
422 uint32_t enabled_irq_mask)
423{
424 uint32_t sdeimr = I915_READ(SDEIMR);
425 sdeimr &= ~interrupt_mask;
426 sdeimr |= (~enabled_irq_mask & interrupt_mask);
427
428 assert_spin_locked(&dev_priv->irq_lock);
429
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700430 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300431 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300432
Daniel Vetterfee884e2013-07-04 23:35:21 +0200433 I915_WRITE(SDEIMR, sdeimr);
434 POSTING_READ(SDEIMR);
435}
436#define ibx_enable_display_interrupt(dev_priv, bits) \
437 ibx_display_interrupt_update((dev_priv), (bits), (bits))
438#define ibx_disable_display_interrupt(dev_priv, bits) \
439 ibx_display_interrupt_update((dev_priv), (bits), 0)
440
Daniel Vetterde280752013-07-04 23:35:24 +0200441static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
442 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300443 bool enable)
444{
Paulo Zanoni86642812013-04-12 17:57:57 -0300445 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200446 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
447 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300448
449 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200450 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300451 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200452 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300453}
454
455static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
456 enum transcoder pch_transcoder,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200457 bool enable, bool old)
Paulo Zanoni86642812013-04-12 17:57:57 -0300458{
459 struct drm_i915_private *dev_priv = dev->dev_private;
460
461 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200462 I915_WRITE(SERR_INT,
463 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
464
Paulo Zanoni86642812013-04-12 17:57:57 -0300465 if (!cpt_can_enable_serr_int(dev))
466 return;
467
Daniel Vetterfee884e2013-07-04 23:35:21 +0200468 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300469 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +0200470 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200471
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200472 if (old && I915_READ(SERR_INT) &
473 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300474 DRM_ERROR("uncleared pch fifo underrun on pch transcoder %c\n",
475 transcoder_name(pch_transcoder));
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200476 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300477 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300478}
479
480/**
481 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
482 * @dev: drm device
483 * @pipe: pipe
484 * @enable: true if we want to report FIFO underrun errors, false otherwise
485 *
486 * This function makes us disable or enable CPU fifo underruns for a specific
487 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
488 * reporting for one pipe may also disable all the other CPU error interruts for
489 * the other pipes, due to the fact that there's just one interrupt mask/enable
490 * bit for all the pipes.
491 *
492 * Returns the previous state of underrun reporting.
493 */
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +0200494static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
495 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300496{
497 struct drm_i915_private *dev_priv = dev->dev_private;
498 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
499 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200500 bool old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300501
Imre Deak77961eb2014-03-05 16:20:56 +0200502 assert_spin_locked(&dev_priv->irq_lock);
503
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200504 old = !intel_crtc->cpu_fifo_underrun_disabled;
Paulo Zanoni86642812013-04-12 17:57:57 -0300505 intel_crtc->cpu_fifo_underrun_disabled = !enable;
506
Ville Syrjäläa3ed6aa2014-09-03 14:09:52 +0300507 if (HAS_GMCH_DISPLAY(dev))
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200508 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200509 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300510 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
511 else if (IS_GEN7(dev))
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200512 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
Damien Lespiaua440ca62014-06-04 19:25:23 +0100513 else if (IS_GEN8(dev) || IS_GEN9(dev))
Daniel Vetter38d83c962013-11-07 11:05:46 +0100514 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300515
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200516 return old;
Imre Deakf88d42f2014-03-04 19:23:09 +0200517}
518
519bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
520 enum pipe pipe, bool enable)
521{
522 struct drm_i915_private *dev_priv = dev->dev_private;
523 unsigned long flags;
524 bool ret;
525
526 spin_lock_irqsave(&dev_priv->irq_lock, flags);
527 ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300528 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Imre Deakf88d42f2014-03-04 19:23:09 +0200529
Paulo Zanoni86642812013-04-12 17:57:57 -0300530 return ret;
531}
532
Imre Deak91d181d2014-02-10 18:42:49 +0200533static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
534 enum pipe pipe)
535{
536 struct drm_i915_private *dev_priv = dev->dev_private;
537 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
538 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
539
540 return !intel_crtc->cpu_fifo_underrun_disabled;
541}
542
Paulo Zanoni86642812013-04-12 17:57:57 -0300543/**
544 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
545 * @dev: drm device
546 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
547 * @enable: true if we want to report FIFO underrun errors, false otherwise
548 *
549 * This function makes us disable or enable PCH fifo underruns for a specific
550 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
551 * underrun reporting for one transcoder may also disable all the other PCH
552 * error interruts for the other transcoders, due to the fact that there's just
553 * one interrupt mask/enable bit for all the transcoders.
554 *
555 * Returns the previous state of underrun reporting.
556 */
557bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
558 enum transcoder pch_transcoder,
559 bool enable)
560{
561 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200562 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
563 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300564 unsigned long flags;
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200565 bool old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300566
Daniel Vetterde280752013-07-04 23:35:24 +0200567 /*
568 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
569 * has only one pch transcoder A that all pipes can use. To avoid racy
570 * pch transcoder -> pipe lookups from interrupt code simply store the
571 * underrun statistics in crtc A. Since we never expose this anywhere
572 * nor use it outside of the fifo underrun code here using the "wrong"
573 * crtc on LPT won't cause issues.
574 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300575
576 spin_lock_irqsave(&dev_priv->irq_lock, flags);
577
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200578 old = !intel_crtc->pch_fifo_underrun_disabled;
Paulo Zanoni86642812013-04-12 17:57:57 -0300579 intel_crtc->pch_fifo_underrun_disabled = !enable;
580
581 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200582 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300583 else
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200584 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable, old);
Paulo Zanoni86642812013-04-12 17:57:57 -0300585
Paulo Zanoni86642812013-04-12 17:57:57 -0300586 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200587 return old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300588}
589
590
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100591static void
Imre Deak755e9012014-02-10 18:42:47 +0200592__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
593 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800594{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200595 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200596 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800597
Daniel Vetterb79480b2013-06-27 17:52:10 +0200598 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200599 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200600
Ville Syrjälä04feced2014-04-03 13:28:33 +0300601 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
602 status_mask & ~PIPESTAT_INT_STATUS_MASK,
603 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
604 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200605 return;
606
607 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200608 return;
609
Imre Deak91d181d2014-02-10 18:42:49 +0200610 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
611
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200612 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200613 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200614 I915_WRITE(reg, pipestat);
615 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800616}
617
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100618static void
Imre Deak755e9012014-02-10 18:42:47 +0200619__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
620 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800621{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200622 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200623 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800624
Daniel Vetterb79480b2013-06-27 17:52:10 +0200625 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200626 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200627
Ville Syrjälä04feced2014-04-03 13:28:33 +0300628 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
629 status_mask & ~PIPESTAT_INT_STATUS_MASK,
630 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
631 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200632 return;
633
Imre Deak755e9012014-02-10 18:42:47 +0200634 if ((pipestat & enable_mask) == 0)
635 return;
636
Imre Deak91d181d2014-02-10 18:42:49 +0200637 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
638
Imre Deak755e9012014-02-10 18:42:47 +0200639 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200640 I915_WRITE(reg, pipestat);
641 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800642}
643
Imre Deak10c59c52014-02-10 18:42:48 +0200644static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
645{
646 u32 enable_mask = status_mask << 16;
647
648 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300649 * On pipe A we don't support the PSR interrupt yet,
650 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200651 */
652 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
653 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300654 /*
655 * On pipe B and C we don't support the PSR interrupt yet, on pipe
656 * A the same bit is for perf counters which we don't use either.
657 */
658 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
659 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200660
661 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
662 SPRITE0_FLIP_DONE_INT_EN_VLV |
663 SPRITE1_FLIP_DONE_INT_EN_VLV);
664 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
665 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
666 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
667 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
668
669 return enable_mask;
670}
671
Imre Deak755e9012014-02-10 18:42:47 +0200672void
673i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
674 u32 status_mask)
675{
676 u32 enable_mask;
677
Imre Deak10c59c52014-02-10 18:42:48 +0200678 if (IS_VALLEYVIEW(dev_priv->dev))
679 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
680 status_mask);
681 else
682 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200683 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
684}
685
686void
687i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
688 u32 status_mask)
689{
690 u32 enable_mask;
691
Imre Deak10c59c52014-02-10 18:42:48 +0200692 if (IS_VALLEYVIEW(dev_priv->dev))
693 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
694 status_mask);
695 else
696 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200697 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
698}
699
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000700/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300701 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000702 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300703static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000704{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300705 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000706
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300707 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
708 return;
709
Daniel Vetter13321782014-09-15 14:55:29 +0200710 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000711
Imre Deak755e9012014-02-10 18:42:47 +0200712 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300713 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200714 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200715 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000716
Daniel Vetter13321782014-09-15 14:55:29 +0200717 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000718}
719
720/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700721 * i915_pipe_enabled - check if a pipe is enabled
722 * @dev: DRM device
723 * @pipe: pipe to check
724 *
725 * Reading certain registers when the pipe is disabled can hang the chip.
726 * Use this routine to make sure the PLL is running and the pipe is active
727 * before reading such registers if unsure.
728 */
729static int
730i915_pipe_enabled(struct drm_device *dev, int pipe)
731{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300732 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200733
Daniel Vettera01025a2013-05-22 00:50:23 +0200734 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
735 /* Locking is horribly broken here, but whatever. */
736 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
737 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300738
Daniel Vettera01025a2013-05-22 00:50:23 +0200739 return intel_crtc->active;
740 } else {
741 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
742 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700743}
744
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300745/*
746 * This timing diagram depicts the video signal in and
747 * around the vertical blanking period.
748 *
749 * Assumptions about the fictitious mode used in this example:
750 * vblank_start >= 3
751 * vsync_start = vblank_start + 1
752 * vsync_end = vblank_start + 2
753 * vtotal = vblank_start + 3
754 *
755 * start of vblank:
756 * latch double buffered registers
757 * increment frame counter (ctg+)
758 * generate start of vblank interrupt (gen4+)
759 * |
760 * | frame start:
761 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
762 * | may be shifted forward 1-3 extra lines via PIPECONF
763 * | |
764 * | | start of vsync:
765 * | | generate vsync interrupt
766 * | | |
767 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
768 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
769 * ----va---> <-----------------vb--------------------> <--------va-------------
770 * | | <----vs-----> |
771 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
772 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
773 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
774 * | | |
775 * last visible pixel first visible pixel
776 * | increment frame counter (gen3/4)
777 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
778 *
779 * x = horizontal active
780 * _ = horizontal blanking
781 * hs = horizontal sync
782 * va = vertical active
783 * vb = vertical blanking
784 * vs = vertical sync
785 * vbs = vblank_start (number)
786 *
787 * Summary:
788 * - most events happen at the start of horizontal sync
789 * - frame start happens at the start of horizontal blank, 1-4 lines
790 * (depending on PIPECONF settings) after the start of vblank
791 * - gen3/4 pixel and frame counter are synchronized with the start
792 * of horizontal active on the first line of vertical active
793 */
794
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300795static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
796{
797 /* Gen2 doesn't have a hardware frame counter */
798 return 0;
799}
800
Keith Packard42f52ef2008-10-18 19:39:29 -0700801/* Called from drm generic code, passed a 'crtc', which
802 * we use as a pipe index
803 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700804static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700805{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300806 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700807 unsigned long high_frame;
808 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300809 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700810
811 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800812 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800813 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700814 return 0;
815 }
816
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300817 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
818 struct intel_crtc *intel_crtc =
819 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
820 const struct drm_display_mode *mode =
821 &intel_crtc->config.adjusted_mode;
822
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300823 htotal = mode->crtc_htotal;
824 hsync_start = mode->crtc_hsync_start;
825 vbl_start = mode->crtc_vblank_start;
826 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
827 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300828 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100829 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300830
831 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300832 hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300833 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300834 if ((I915_READ(PIPECONF(cpu_transcoder)) &
835 PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE)
836 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300837 }
838
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300839 /* Convert to pixel count */
840 vbl_start *= htotal;
841
842 /* Start of vblank event occurs at start of hsync */
843 vbl_start -= htotal - hsync_start;
844
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800845 high_frame = PIPEFRAME(pipe);
846 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100847
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700848 /*
849 * High & low register fields aren't synchronized, so make sure
850 * we get a low value that's stable across two reads of the high
851 * register.
852 */
853 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100854 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300855 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100856 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700857 } while (high1 != high2);
858
Chris Wilson5eddb702010-09-11 13:48:45 +0100859 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300860 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100861 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300862
863 /*
864 * The frame counter increments at beginning of active.
865 * Cook up a vblank counter by also checking the pixel
866 * counter against vblank start.
867 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200868 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700869}
870
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700871static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800872{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300873 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800874 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800875
876 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800877 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800878 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800879 return 0;
880 }
881
882 return I915_READ(reg);
883}
884
Mario Kleinerad3543e2013-10-30 05:13:08 +0100885/* raw reads, only for fast reads of display block, no need for forcewake etc. */
886#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100887
Ville Syrjäläa225f072014-04-29 13:35:45 +0300888static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
889{
890 struct drm_device *dev = crtc->base.dev;
891 struct drm_i915_private *dev_priv = dev->dev_private;
892 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
893 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300894 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300895
Ville Syrjälä80715b22014-05-15 20:23:23 +0300896 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300897 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
898 vtotal /= 2;
899
900 if (IS_GEN2(dev))
901 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
902 else
903 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
904
905 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300906 * See update_scanline_offset() for the details on the
907 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300908 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300909 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300910}
911
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700912static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200913 unsigned int flags, int *vpos, int *hpos,
914 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100915{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300916 struct drm_i915_private *dev_priv = dev->dev_private;
917 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
918 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
919 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300920 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300921 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100922 bool in_vbl = true;
923 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100924 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100925
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300926 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100927 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800928 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100929 return 0;
930 }
931
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300932 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300933 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300934 vtotal = mode->crtc_vtotal;
935 vbl_start = mode->crtc_vblank_start;
936 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100937
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200938 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
939 vbl_start = DIV_ROUND_UP(vbl_start, 2);
940 vbl_end /= 2;
941 vtotal /= 2;
942 }
943
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300944 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
945
Mario Kleinerad3543e2013-10-30 05:13:08 +0100946 /*
947 * Lock uncore.lock, as we will do multiple timing critical raw
948 * register reads, potentially with preemption disabled, so the
949 * following code must not block on uncore.lock.
950 */
951 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300952
Mario Kleinerad3543e2013-10-30 05:13:08 +0100953 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
954
955 /* Get optional system timestamp before query. */
956 if (stime)
957 *stime = ktime_get();
958
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300959 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100960 /* No obvious pixelcount register. Only query vertical
961 * scanout position from Display scan line register.
962 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300963 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100964 } else {
965 /* Have access to pixelcount since start of frame.
966 * We can split this into vertical and horizontal
967 * scanout position.
968 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100969 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100970
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300971 /* convert to pixel counts */
972 vbl_start *= htotal;
973 vbl_end *= htotal;
974 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300975
976 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300977 * In interlaced modes, the pixel counter counts all pixels,
978 * so one field will have htotal more pixels. In order to avoid
979 * the reported position from jumping backwards when the pixel
980 * counter is beyond the length of the shorter field, just
981 * clamp the position the length of the shorter field. This
982 * matches how the scanline counter based position works since
983 * the scanline counter doesn't count the two half lines.
984 */
985 if (position >= vtotal)
986 position = vtotal - 1;
987
988 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300989 * Start of vblank interrupt is triggered at start of hsync,
990 * just prior to the first active line of vblank. However we
991 * consider lines to start at the leading edge of horizontal
992 * active. So, should we get here before we've crossed into
993 * the horizontal active of the first line in vblank, we would
994 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
995 * always add htotal-hsync_start to the current pixel position.
996 */
997 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300998 }
999
Mario Kleinerad3543e2013-10-30 05:13:08 +01001000 /* Get optional system timestamp after query. */
1001 if (etime)
1002 *etime = ktime_get();
1003
1004 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1005
1006 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1007
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001008 in_vbl = position >= vbl_start && position < vbl_end;
1009
1010 /*
1011 * While in vblank, position will be negative
1012 * counting up towards 0 at vbl_end. And outside
1013 * vblank, position will be positive counting
1014 * up since vbl_end.
1015 */
1016 if (position >= vbl_start)
1017 position -= vbl_end;
1018 else
1019 position += vtotal - vbl_end;
1020
Ville Syrjälä7c06b082013-10-11 21:52:43 +03001021 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001022 *vpos = position;
1023 *hpos = 0;
1024 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001025 *vpos = position / htotal;
1026 *hpos = position - (*vpos * htotal);
1027 }
1028
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001029 /* In vblank? */
1030 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +02001031 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001032
1033 return ret;
1034}
1035
Ville Syrjäläa225f072014-04-29 13:35:45 +03001036int intel_get_crtc_scanline(struct intel_crtc *crtc)
1037{
1038 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
1039 unsigned long irqflags;
1040 int position;
1041
1042 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1043 position = __intel_get_crtc_scanline(crtc);
1044 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1045
1046 return position;
1047}
1048
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001049static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001050 int *max_error,
1051 struct timeval *vblank_time,
1052 unsigned flags)
1053{
Chris Wilson4041b852011-01-22 10:07:56 +00001054 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001055
Ben Widawsky7eb552a2013-03-13 14:05:41 -07001056 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +00001057 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001058 return -EINVAL;
1059 }
1060
1061 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +00001062 crtc = intel_get_crtc_for_pipe(dev, pipe);
1063 if (crtc == NULL) {
1064 DRM_ERROR("Invalid crtc %d\n", pipe);
1065 return -EINVAL;
1066 }
1067
1068 if (!crtc->enabled) {
1069 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
1070 return -EBUSY;
1071 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001072
1073 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +00001074 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
1075 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +03001076 crtc,
1077 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001078}
1079
Jani Nikula67c347f2013-09-17 14:26:34 +03001080static bool intel_hpd_irq_event(struct drm_device *dev,
1081 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +02001082{
1083 enum drm_connector_status old_status;
1084
1085 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1086 old_status = connector->status;
1087
1088 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +03001089 if (old_status == connector->status)
1090 return false;
1091
1092 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +02001093 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03001094 connector->name,
Jani Nikula67c347f2013-09-17 14:26:34 +03001095 drm_get_connector_status_name(old_status),
1096 drm_get_connector_status_name(connector->status));
1097
1098 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +02001099}
1100
Dave Airlie13cf5502014-06-18 11:29:35 +10001101static void i915_digport_work_func(struct work_struct *work)
1102{
1103 struct drm_i915_private *dev_priv =
1104 container_of(work, struct drm_i915_private, dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +10001105 u32 long_port_mask, short_port_mask;
1106 struct intel_digital_port *intel_dig_port;
1107 int i, ret;
1108 u32 old_bits = 0;
1109
Daniel Vetter4cb21832014-09-15 14:55:26 +02001110 spin_lock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001111 long_port_mask = dev_priv->long_hpd_port_mask;
1112 dev_priv->long_hpd_port_mask = 0;
1113 short_port_mask = dev_priv->short_hpd_port_mask;
1114 dev_priv->short_hpd_port_mask = 0;
Daniel Vetter4cb21832014-09-15 14:55:26 +02001115 spin_unlock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001116
1117 for (i = 0; i < I915_MAX_PORTS; i++) {
1118 bool valid = false;
1119 bool long_hpd = false;
1120 intel_dig_port = dev_priv->hpd_irq_port[i];
1121 if (!intel_dig_port || !intel_dig_port->hpd_pulse)
1122 continue;
1123
1124 if (long_port_mask & (1 << i)) {
1125 valid = true;
1126 long_hpd = true;
1127 } else if (short_port_mask & (1 << i))
1128 valid = true;
1129
1130 if (valid) {
1131 ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
1132 if (ret == true) {
1133 /* if we get true fallback to old school hpd */
1134 old_bits |= (1 << intel_dig_port->base.hpd_pin);
1135 }
1136 }
1137 }
1138
1139 if (old_bits) {
Daniel Vetter4cb21832014-09-15 14:55:26 +02001140 spin_lock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001141 dev_priv->hpd_event_bits |= old_bits;
Daniel Vetter4cb21832014-09-15 14:55:26 +02001142 spin_unlock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001143 schedule_work(&dev_priv->hotplug_work);
1144 }
1145}
1146
Jesse Barnes5ca58282009-03-31 14:11:15 -07001147/*
1148 * Handle hotplug events outside the interrupt handler proper.
1149 */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001150#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
1151
Jesse Barnes5ca58282009-03-31 14:11:15 -07001152static void i915_hotplug_work_func(struct work_struct *work)
1153{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001154 struct drm_i915_private *dev_priv =
1155 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001156 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -07001157 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001158 struct intel_connector *intel_connector;
1159 struct intel_encoder *intel_encoder;
1160 struct drm_connector *connector;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001161 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +02001162 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +02001163 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001164
Keith Packarda65e34c2011-07-25 10:04:56 -07001165 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -08001166 DRM_DEBUG_KMS("running encoder hotplug functions\n");
1167
Daniel Vetter4cb21832014-09-15 14:55:26 +02001168 spin_lock_irq(&dev_priv->irq_lock);
Egbert Eich142e2392013-04-11 15:57:57 +02001169
1170 hpd_event_bits = dev_priv->hpd_event_bits;
1171 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001172 list_for_each_entry(connector, &mode_config->connector_list, head) {
1173 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10001174 if (!intel_connector->encoder)
1175 continue;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001176 intel_encoder = intel_connector->encoder;
1177 if (intel_encoder->hpd_pin > HPD_NONE &&
1178 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
1179 connector->polled == DRM_CONNECTOR_POLL_HPD) {
1180 DRM_INFO("HPD interrupt storm detected on connector %s: "
1181 "switching from hotplug detection to polling\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001182 connector->name);
Egbert Eichcd569ae2013-04-16 13:36:57 +02001183 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1184 connector->polled = DRM_CONNECTOR_POLL_CONNECT
1185 | DRM_CONNECTOR_POLL_DISCONNECT;
1186 hpd_disabled = true;
1187 }
Egbert Eich142e2392013-04-11 15:57:57 +02001188 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1189 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001190 connector->name, intel_encoder->hpd_pin);
Egbert Eich142e2392013-04-11 15:57:57 +02001191 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001192 }
1193 /* if there were no outputs to poll, poll was disabled,
1194 * therefore make sure it's enabled when disabling HPD on
1195 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001196 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +02001197 drm_kms_helper_poll_enable(dev);
Imre Deak63237512014-08-18 15:37:02 +03001198 mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work,
1199 msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
Egbert Eichac4c16c2013-04-16 13:36:58 +02001200 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001201
Daniel Vetter4cb21832014-09-15 14:55:26 +02001202 spin_unlock_irq(&dev_priv->irq_lock);
Egbert Eichcd569ae2013-04-16 13:36:57 +02001203
Egbert Eich321a1b32013-04-11 16:00:26 +02001204 list_for_each_entry(connector, &mode_config->connector_list, head) {
1205 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10001206 if (!intel_connector->encoder)
1207 continue;
Egbert Eich321a1b32013-04-11 16:00:26 +02001208 intel_encoder = intel_connector->encoder;
1209 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1210 if (intel_encoder->hot_plug)
1211 intel_encoder->hot_plug(intel_encoder);
1212 if (intel_hpd_irq_event(dev, connector))
1213 changed = true;
1214 }
1215 }
Keith Packard40ee3382011-07-28 15:31:19 -07001216 mutex_unlock(&mode_config->mutex);
1217
Egbert Eich321a1b32013-04-11 16:00:26 +02001218 if (changed)
1219 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001220}
1221
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001222static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001223{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001224 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001225 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001226 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001227
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001228 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001229
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001230 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1231
Daniel Vetter20e4d402012-08-08 23:35:39 +02001232 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001233
Jesse Barnes7648fa92010-05-20 14:28:11 -07001234 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001235 busy_up = I915_READ(RCPREVBSYTUPAVG);
1236 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001237 max_avg = I915_READ(RCBMAXAVG);
1238 min_avg = I915_READ(RCBMINAVG);
1239
1240 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001241 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001242 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1243 new_delay = dev_priv->ips.cur_delay - 1;
1244 if (new_delay < dev_priv->ips.max_delay)
1245 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001246 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001247 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1248 new_delay = dev_priv->ips.cur_delay + 1;
1249 if (new_delay > dev_priv->ips.min_delay)
1250 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001251 }
1252
Jesse Barnes7648fa92010-05-20 14:28:11 -07001253 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001254 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001255
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001256 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001257
Jesse Barnesf97108d2010-01-29 11:27:07 -08001258 return;
1259}
1260
Chris Wilson549f7362010-10-19 11:19:32 +01001261static void notify_ring(struct drm_device *dev,
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001262 struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +01001263{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +01001264 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +00001265 return;
1266
Chris Wilson814e9b52013-09-23 17:33:19 -03001267 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001268
Sourab Gupta84c33a62014-06-02 16:47:17 +05301269 if (drm_core_check_feature(dev, DRIVER_MODESET))
1270 intel_notify_mmio_flip(ring);
1271
Chris Wilson549f7362010-10-19 11:19:32 +01001272 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001273 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001274}
1275
Deepak S31685c22014-07-03 17:33:01 -04001276static u32 vlv_c0_residency(struct drm_i915_private *dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001277 struct intel_rps_ei *rps_ei)
Deepak S31685c22014-07-03 17:33:01 -04001278{
1279 u32 cz_ts, cz_freq_khz;
1280 u32 render_count, media_count;
1281 u32 elapsed_render, elapsed_media, elapsed_time;
1282 u32 residency = 0;
1283
1284 cz_ts = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
1285 cz_freq_khz = DIV_ROUND_CLOSEST(dev_priv->mem_freq * 1000, 4);
1286
1287 render_count = I915_READ(VLV_RENDER_C0_COUNT_REG);
1288 media_count = I915_READ(VLV_MEDIA_C0_COUNT_REG);
1289
Chris Wilsonbf225f22014-07-10 20:31:18 +01001290 if (rps_ei->cz_clock == 0) {
1291 rps_ei->cz_clock = cz_ts;
1292 rps_ei->render_c0 = render_count;
1293 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001294
1295 return dev_priv->rps.cur_freq;
1296 }
1297
Chris Wilsonbf225f22014-07-10 20:31:18 +01001298 elapsed_time = cz_ts - rps_ei->cz_clock;
1299 rps_ei->cz_clock = cz_ts;
Deepak S31685c22014-07-03 17:33:01 -04001300
Chris Wilsonbf225f22014-07-10 20:31:18 +01001301 elapsed_render = render_count - rps_ei->render_c0;
1302 rps_ei->render_c0 = render_count;
Deepak S31685c22014-07-03 17:33:01 -04001303
Chris Wilsonbf225f22014-07-10 20:31:18 +01001304 elapsed_media = media_count - rps_ei->media_c0;
1305 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001306
1307 /* Convert all the counters into common unit of milli sec */
1308 elapsed_time /= VLV_CZ_CLOCK_TO_MILLI_SEC;
1309 elapsed_render /= cz_freq_khz;
1310 elapsed_media /= cz_freq_khz;
1311
1312 /*
1313 * Calculate overall C0 residency percentage
1314 * only if elapsed time is non zero
1315 */
1316 if (elapsed_time) {
1317 residency =
1318 ((max(elapsed_render, elapsed_media) * 100)
1319 / elapsed_time);
1320 }
1321
1322 return residency;
1323}
1324
1325/**
1326 * vlv_calc_delay_from_C0_counters - Increase/Decrease freq based on GPU
1327 * busy-ness calculated from C0 counters of render & media power wells
1328 * @dev_priv: DRM device private
1329 *
1330 */
Damien Lespiau4fa79042014-08-08 19:25:57 +01001331static int vlv_calc_delay_from_C0_counters(struct drm_i915_private *dev_priv)
Deepak S31685c22014-07-03 17:33:01 -04001332{
1333 u32 residency_C0_up = 0, residency_C0_down = 0;
Damien Lespiau4fa79042014-08-08 19:25:57 +01001334 int new_delay, adj;
Deepak S31685c22014-07-03 17:33:01 -04001335
1336 dev_priv->rps.ei_interrupt_count++;
1337
1338 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
1339
1340
Chris Wilsonbf225f22014-07-10 20:31:18 +01001341 if (dev_priv->rps.up_ei.cz_clock == 0) {
1342 vlv_c0_residency(dev_priv, &dev_priv->rps.up_ei);
1343 vlv_c0_residency(dev_priv, &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001344 return dev_priv->rps.cur_freq;
1345 }
1346
1347
1348 /*
1349 * To down throttle, C0 residency should be less than down threshold
1350 * for continous EI intervals. So calculate down EI counters
1351 * once in VLV_INT_COUNT_FOR_DOWN_EI
1352 */
1353 if (dev_priv->rps.ei_interrupt_count == VLV_INT_COUNT_FOR_DOWN_EI) {
1354
1355 dev_priv->rps.ei_interrupt_count = 0;
1356
1357 residency_C0_down = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001358 &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001359 } else {
1360 residency_C0_up = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001361 &dev_priv->rps.up_ei);
Deepak S31685c22014-07-03 17:33:01 -04001362 }
1363
1364 new_delay = dev_priv->rps.cur_freq;
1365
1366 adj = dev_priv->rps.last_adj;
1367 /* C0 residency is greater than UP threshold. Increase Frequency */
1368 if (residency_C0_up >= VLV_RP_UP_EI_THRESHOLD) {
1369 if (adj > 0)
1370 adj *= 2;
1371 else
1372 adj = 1;
1373
1374 if (dev_priv->rps.cur_freq < dev_priv->rps.max_freq_softlimit)
1375 new_delay = dev_priv->rps.cur_freq + adj;
1376
1377 /*
1378 * For better performance, jump directly
1379 * to RPe if we're below it.
1380 */
1381 if (new_delay < dev_priv->rps.efficient_freq)
1382 new_delay = dev_priv->rps.efficient_freq;
1383
1384 } else if (!dev_priv->rps.ei_interrupt_count &&
1385 (residency_C0_down < VLV_RP_DOWN_EI_THRESHOLD)) {
1386 if (adj < 0)
1387 adj *= 2;
1388 else
1389 adj = -1;
1390 /*
1391 * This means, C0 residency is less than down threshold over
1392 * a period of VLV_INT_COUNT_FOR_DOWN_EI. So, reduce the freq
1393 */
1394 if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
1395 new_delay = dev_priv->rps.cur_freq + adj;
1396 }
1397
1398 return new_delay;
1399}
1400
Ben Widawsky4912d042011-04-25 11:25:20 -07001401static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001402{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001403 struct drm_i915_private *dev_priv =
1404 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001405 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001406 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001407
Daniel Vetter59cdb632013-07-04 23:35:28 +02001408 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001409 pm_iir = dev_priv->rps.pm_iir;
1410 dev_priv->rps.pm_iir = 0;
Damien Lespiau6af257c2014-07-15 09:17:41 +02001411 if (INTEL_INFO(dev_priv->dev)->gen >= 8)
Daniel Vetter480c8032014-07-16 09:49:40 +02001412 gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001413 else {
1414 /* Make sure not to corrupt PMIMR state used by ringbuffer */
Daniel Vetter480c8032014-07-16 09:49:40 +02001415 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001416 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001417 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001418
Paulo Zanoni60611c12013-08-15 11:50:01 -03001419 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301420 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001421
Deepak Sa6706b42014-03-15 20:23:22 +05301422 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001423 return;
1424
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001425 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001426
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001427 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001428 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001429 if (adj > 0)
1430 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301431 else {
1432 /* CHV needs even encode values */
1433 adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1;
1434 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001435 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001436
1437 /*
1438 * For better performance, jump directly
1439 * to RPe if we're below it.
1440 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001441 if (new_delay < dev_priv->rps.efficient_freq)
1442 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001443 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001444 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1445 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001446 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001447 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001448 adj = 0;
Deepak S31685c22014-07-03 17:33:01 -04001449 } else if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1450 new_delay = vlv_calc_delay_from_C0_counters(dev_priv);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001451 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1452 if (adj < 0)
1453 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301454 else {
1455 /* CHV needs even encode values */
1456 adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1;
1457 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001458 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001459 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001460 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001461 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001462
Ben Widawsky79249632012-09-07 19:43:42 -07001463 /* sysfs frequency interfaces may have snuck in while servicing the
1464 * interrupt
1465 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001466 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001467 dev_priv->rps.min_freq_softlimit,
1468 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301469
Ben Widawskyb39fb292014-03-19 18:31:11 -07001470 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001471
1472 if (IS_VALLEYVIEW(dev_priv->dev))
1473 valleyview_set_rps(dev_priv->dev, new_delay);
1474 else
1475 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001476
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001477 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001478}
1479
Ben Widawskye3689192012-05-25 16:56:22 -07001480
1481/**
1482 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1483 * occurred.
1484 * @work: workqueue struct
1485 *
1486 * Doesn't actually do anything except notify userspace. As a consequence of
1487 * this event, userspace should try to remap the bad rows since statistically
1488 * it is likely the same row is more likely to go bad again.
1489 */
1490static void ivybridge_parity_work(struct work_struct *work)
1491{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001492 struct drm_i915_private *dev_priv =
1493 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001494 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001495 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001496 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001497 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001498
1499 /* We must turn off DOP level clock gating to access the L3 registers.
1500 * In order to prevent a get/put style interface, acquire struct mutex
1501 * any time we access those registers.
1502 */
1503 mutex_lock(&dev_priv->dev->struct_mutex);
1504
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001505 /* If we've screwed up tracking, just let the interrupt fire again */
1506 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1507 goto out;
1508
Ben Widawskye3689192012-05-25 16:56:22 -07001509 misccpctl = I915_READ(GEN7_MISCCPCTL);
1510 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1511 POSTING_READ(GEN7_MISCCPCTL);
1512
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001513 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1514 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001515
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001516 slice--;
1517 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1518 break;
1519
1520 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1521
1522 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1523
1524 error_status = I915_READ(reg);
1525 row = GEN7_PARITY_ERROR_ROW(error_status);
1526 bank = GEN7_PARITY_ERROR_BANK(error_status);
1527 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1528
1529 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1530 POSTING_READ(reg);
1531
1532 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1533 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1534 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1535 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1536 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1537 parity_event[5] = NULL;
1538
Dave Airlie5bdebb12013-10-11 14:07:25 +10001539 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001540 KOBJ_CHANGE, parity_event);
1541
1542 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1543 slice, row, bank, subbank);
1544
1545 kfree(parity_event[4]);
1546 kfree(parity_event[3]);
1547 kfree(parity_event[2]);
1548 kfree(parity_event[1]);
1549 }
Ben Widawskye3689192012-05-25 16:56:22 -07001550
1551 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1552
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001553out:
1554 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001555 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001556 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001557 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001558
1559 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001560}
1561
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001562static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001563{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001564 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001565
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001566 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001567 return;
1568
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001569 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001570 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001571 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001572
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001573 iir &= GT_PARITY_ERROR(dev);
1574 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1575 dev_priv->l3_parity.which_slice |= 1 << 1;
1576
1577 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1578 dev_priv->l3_parity.which_slice |= 1 << 0;
1579
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001580 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001581}
1582
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001583static void ilk_gt_irq_handler(struct drm_device *dev,
1584 struct drm_i915_private *dev_priv,
1585 u32 gt_iir)
1586{
1587 if (gt_iir &
1588 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1589 notify_ring(dev, &dev_priv->ring[RCS]);
1590 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1591 notify_ring(dev, &dev_priv->ring[VCS]);
1592}
1593
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001594static void snb_gt_irq_handler(struct drm_device *dev,
1595 struct drm_i915_private *dev_priv,
1596 u32 gt_iir)
1597{
1598
Ben Widawskycc609d52013-05-28 19:22:29 -07001599 if (gt_iir &
1600 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001601 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001602 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001603 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001604 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001605 notify_ring(dev, &dev_priv->ring[BCS]);
1606
Ben Widawskycc609d52013-05-28 19:22:29 -07001607 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1608 GT_BSD_CS_ERROR_INTERRUPT |
1609 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001610 i915_handle_error(dev, false, "GT error interrupt 0x%08x",
1611 gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001612 }
Ben Widawskye3689192012-05-25 16:56:22 -07001613
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001614 if (gt_iir & GT_PARITY_ERROR(dev))
1615 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001616}
1617
Ben Widawsky09610212014-05-15 20:58:08 +03001618static void gen8_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1619{
1620 if ((pm_iir & dev_priv->pm_rps_events) == 0)
1621 return;
1622
1623 spin_lock(&dev_priv->irq_lock);
1624 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Daniel Vetter480c8032014-07-16 09:49:40 +02001625 gen8_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001626 spin_unlock(&dev_priv->irq_lock);
1627
1628 queue_work(dev_priv->wq, &dev_priv->rps.work);
1629}
1630
Ben Widawskyabd58f02013-11-02 21:07:09 -07001631static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1632 struct drm_i915_private *dev_priv,
1633 u32 master_ctl)
1634{
Thomas Daniele981e7b2014-07-24 17:04:39 +01001635 struct intel_engine_cs *ring;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001636 u32 rcs, bcs, vcs;
1637 uint32_t tmp = 0;
1638 irqreturn_t ret = IRQ_NONE;
1639
1640 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1641 tmp = I915_READ(GEN8_GT_IIR(0));
1642 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001643 I915_WRITE(GEN8_GT_IIR(0), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001644 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001645
Ben Widawskyabd58f02013-11-02 21:07:09 -07001646 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001647 ring = &dev_priv->ring[RCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001648 if (rcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001649 notify_ring(dev, ring);
1650 if (rcs & GT_CONTEXT_SWITCH_INTERRUPT)
1651 intel_execlists_handle_ctx_events(ring);
1652
1653 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1654 ring = &dev_priv->ring[BCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001655 if (bcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001656 notify_ring(dev, ring);
1657 if (bcs & GT_CONTEXT_SWITCH_INTERRUPT)
1658 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001659 } else
1660 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1661 }
1662
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001663 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07001664 tmp = I915_READ(GEN8_GT_IIR(1));
1665 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001666 I915_WRITE(GEN8_GT_IIR(1), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001667 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001668
Ben Widawskyabd58f02013-11-02 21:07:09 -07001669 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001670 ring = &dev_priv->ring[VCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001671 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001672 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001673 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001674 intel_execlists_handle_ctx_events(ring);
1675
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001676 vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001677 ring = &dev_priv->ring[VCS2];
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001678 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001679 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001680 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001681 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001682 } else
1683 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1684 }
1685
Ben Widawsky09610212014-05-15 20:58:08 +03001686 if (master_ctl & GEN8_GT_PM_IRQ) {
1687 tmp = I915_READ(GEN8_GT_IIR(2));
1688 if (tmp & dev_priv->pm_rps_events) {
Ben Widawsky09610212014-05-15 20:58:08 +03001689 I915_WRITE(GEN8_GT_IIR(2),
1690 tmp & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001691 ret = IRQ_HANDLED;
1692 gen8_rps_irq_handler(dev_priv, tmp);
Ben Widawsky09610212014-05-15 20:58:08 +03001693 } else
1694 DRM_ERROR("The master control interrupt lied (PM)!\n");
1695 }
1696
Ben Widawskyabd58f02013-11-02 21:07:09 -07001697 if (master_ctl & GEN8_GT_VECS_IRQ) {
1698 tmp = I915_READ(GEN8_GT_IIR(3));
1699 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001700 I915_WRITE(GEN8_GT_IIR(3), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001701 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001702
Ben Widawskyabd58f02013-11-02 21:07:09 -07001703 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001704 ring = &dev_priv->ring[VECS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001705 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001706 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001707 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001708 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001709 } else
1710 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1711 }
1712
1713 return ret;
1714}
1715
Egbert Eichb543fb02013-04-16 13:36:54 +02001716#define HPD_STORM_DETECT_PERIOD 1000
1717#define HPD_STORM_THRESHOLD 5
1718
Dave Airlie13cf5502014-06-18 11:29:35 +10001719static int ilk_port_to_hotplug_shift(enum port port)
1720{
1721 switch (port) {
1722 case PORT_A:
1723 case PORT_E:
1724 default:
1725 return -1;
1726 case PORT_B:
1727 return 0;
1728 case PORT_C:
1729 return 8;
1730 case PORT_D:
1731 return 16;
1732 }
1733}
1734
1735static int g4x_port_to_hotplug_shift(enum port port)
1736{
1737 switch (port) {
1738 case PORT_A:
1739 case PORT_E:
1740 default:
1741 return -1;
1742 case PORT_B:
1743 return 17;
1744 case PORT_C:
1745 return 19;
1746 case PORT_D:
1747 return 21;
1748 }
1749}
1750
1751static inline enum port get_port_from_pin(enum hpd_pin pin)
1752{
1753 switch (pin) {
1754 case HPD_PORT_B:
1755 return PORT_B;
1756 case HPD_PORT_C:
1757 return PORT_C;
1758 case HPD_PORT_D:
1759 return PORT_D;
1760 default:
1761 return PORT_A; /* no hpd */
1762 }
1763}
1764
Daniel Vetter10a504d2013-06-27 17:52:12 +02001765static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001766 u32 hotplug_trigger,
Dave Airlie13cf5502014-06-18 11:29:35 +10001767 u32 dig_hotplug_reg,
Daniel Vetter22062db2013-06-27 17:52:11 +02001768 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001769{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001770 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001771 int i;
Dave Airlie13cf5502014-06-18 11:29:35 +10001772 enum port port;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001773 bool storm_detected = false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001774 bool queue_dig = false, queue_hp = false;
1775 u32 dig_shift;
1776 u32 dig_port_mask = 0;
Egbert Eichb543fb02013-04-16 13:36:54 +02001777
Daniel Vetter91d131d2013-06-27 17:52:14 +02001778 if (!hotplug_trigger)
1779 return;
1780
Dave Airlie13cf5502014-06-18 11:29:35 +10001781 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n",
1782 hotplug_trigger, dig_hotplug_reg);
Imre Deakcc9bd492014-01-16 19:56:54 +02001783
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001784 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001785 for (i = 1; i < HPD_NUM_PINS; i++) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001786 if (!(hpd[i] & hotplug_trigger))
1787 continue;
Egbert Eich821450c2013-04-16 13:36:55 +02001788
Dave Airlie13cf5502014-06-18 11:29:35 +10001789 port = get_port_from_pin(i);
1790 if (port && dev_priv->hpd_irq_port[port]) {
1791 bool long_hpd;
1792
1793 if (IS_G4X(dev)) {
1794 dig_shift = g4x_port_to_hotplug_shift(port);
1795 long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1796 } else {
1797 dig_shift = ilk_port_to_hotplug_shift(port);
1798 long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1799 }
1800
Ville Syrjälä26fbb772014-08-11 18:37:37 +03001801 DRM_DEBUG_DRIVER("digital hpd port %c - %s\n",
1802 port_name(port),
1803 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10001804 /* for long HPD pulses we want to have the digital queue happen,
1805 but we still want HPD storm detection to function. */
1806 if (long_hpd) {
1807 dev_priv->long_hpd_port_mask |= (1 << port);
1808 dig_port_mask |= hpd[i];
1809 } else {
1810 /* for short HPD just trigger the digital queue */
1811 dev_priv->short_hpd_port_mask |= (1 << port);
1812 hotplug_trigger &= ~hpd[i];
1813 }
1814 queue_dig = true;
1815 }
1816 }
1817
1818 for (i = 1; i < HPD_NUM_PINS; i++) {
Daniel Vetter3ff04a162014-04-24 12:03:17 +02001819 if (hpd[i] & hotplug_trigger &&
1820 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
1821 /*
1822 * On GMCH platforms the interrupt mask bits only
1823 * prevent irq generation, not the setting of the
1824 * hotplug bits itself. So only WARN about unexpected
1825 * interrupts on saner platforms.
1826 */
1827 WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
1828 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1829 hotplug_trigger, i, hpd[i]);
1830
1831 continue;
1832 }
Egbert Eichb8f102e2013-07-26 14:14:24 +02001833
Egbert Eichb543fb02013-04-16 13:36:54 +02001834 if (!(hpd[i] & hotplug_trigger) ||
1835 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1836 continue;
1837
Dave Airlie13cf5502014-06-18 11:29:35 +10001838 if (!(dig_port_mask & hpd[i])) {
1839 dev_priv->hpd_event_bits |= (1 << i);
1840 queue_hp = true;
1841 }
1842
Egbert Eichb543fb02013-04-16 13:36:54 +02001843 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1844 dev_priv->hpd_stats[i].hpd_last_jiffies
1845 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1846 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1847 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001848 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001849 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1850 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001851 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001852 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001853 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001854 } else {
1855 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001856 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1857 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001858 }
1859 }
1860
Daniel Vetter10a504d2013-06-27 17:52:12 +02001861 if (storm_detected)
1862 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001863 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001864
Daniel Vetter645416f2013-09-02 16:22:25 +02001865 /*
1866 * Our hotplug handler can grab modeset locks (by calling down into the
1867 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1868 * queue for otherwise the flush_work in the pageflip code will
1869 * deadlock.
1870 */
Dave Airlie13cf5502014-06-18 11:29:35 +10001871 if (queue_dig)
Dave Airlie0e32b392014-05-02 14:02:48 +10001872 queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +10001873 if (queue_hp)
1874 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001875}
1876
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001877static void gmbus_irq_handler(struct drm_device *dev)
1878{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001879 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001880
Daniel Vetter28c70f12012-12-01 13:53:45 +01001881 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001882}
1883
Daniel Vetterce99c252012-12-01 13:53:47 +01001884static void dp_aux_irq_handler(struct drm_device *dev)
1885{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001886 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001887
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001888 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001889}
1890
Shuang He8bf1e9f2013-10-15 18:55:27 +01001891#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001892static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1893 uint32_t crc0, uint32_t crc1,
1894 uint32_t crc2, uint32_t crc3,
1895 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001896{
1897 struct drm_i915_private *dev_priv = dev->dev_private;
1898 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1899 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001900 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001901
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001902 spin_lock(&pipe_crc->lock);
1903
Damien Lespiau0c912c72013-10-15 18:55:37 +01001904 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001905 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001906 DRM_ERROR("spurious interrupt\n");
1907 return;
1908 }
1909
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001910 head = pipe_crc->head;
1911 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001912
1913 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001914 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001915 DRM_ERROR("CRC buffer overflowing\n");
1916 return;
1917 }
1918
1919 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001920
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001921 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001922 entry->crc[0] = crc0;
1923 entry->crc[1] = crc1;
1924 entry->crc[2] = crc2;
1925 entry->crc[3] = crc3;
1926 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001927
1928 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001929 pipe_crc->head = head;
1930
1931 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001932
1933 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001934}
Daniel Vetter277de952013-10-18 16:37:07 +02001935#else
1936static inline void
1937display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1938 uint32_t crc0, uint32_t crc1,
1939 uint32_t crc2, uint32_t crc3,
1940 uint32_t crc4) {}
1941#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001942
Daniel Vetter277de952013-10-18 16:37:07 +02001943
1944static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001945{
1946 struct drm_i915_private *dev_priv = dev->dev_private;
1947
Daniel Vetter277de952013-10-18 16:37:07 +02001948 display_pipe_crc_irq_handler(dev, pipe,
1949 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1950 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001951}
1952
Daniel Vetter277de952013-10-18 16:37:07 +02001953static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001954{
1955 struct drm_i915_private *dev_priv = dev->dev_private;
1956
Daniel Vetter277de952013-10-18 16:37:07 +02001957 display_pipe_crc_irq_handler(dev, pipe,
1958 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1959 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1960 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1961 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1962 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001963}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001964
Daniel Vetter277de952013-10-18 16:37:07 +02001965static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001966{
1967 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001968 uint32_t res1, res2;
1969
1970 if (INTEL_INFO(dev)->gen >= 3)
1971 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1972 else
1973 res1 = 0;
1974
1975 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1976 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1977 else
1978 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001979
Daniel Vetter277de952013-10-18 16:37:07 +02001980 display_pipe_crc_irq_handler(dev, pipe,
1981 I915_READ(PIPE_CRC_RES_RED(pipe)),
1982 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1983 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1984 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001985}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001986
Daisy Sunc76bb612014-08-11 11:08:38 -07001987void gen8_flip_interrupt(struct drm_device *dev)
1988{
1989 struct drm_i915_private *dev_priv = dev->dev_private;
1990
1991 if (!dev_priv->rps.is_bdw_sw_turbo)
1992 return;
1993
1994 if(atomic_read(&dev_priv->rps.sw_turbo.flip_received)) {
1995 mod_timer(&dev_priv->rps.sw_turbo.flip_timer,
1996 usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies);
1997 }
1998 else {
1999 dev_priv->rps.sw_turbo.flip_timer.expires =
2000 usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies;
2001 add_timer(&dev_priv->rps.sw_turbo.flip_timer);
2002 atomic_set(&dev_priv->rps.sw_turbo.flip_received, true);
2003 }
2004
2005 bdw_software_turbo(dev);
2006}
2007
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002008/* The RPS events need forcewake, so we add them to a work queue and mask their
2009 * IMR bits until the work is done. Other interrupts can be processed without
2010 * the work queue. */
2011static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07002012{
Deepak Sa6706b42014-03-15 20:23:22 +05302013 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02002014 spin_lock(&dev_priv->irq_lock);
Deepak Sa6706b42014-03-15 20:23:22 +05302015 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Daniel Vetter480c8032014-07-16 09:49:40 +02002016 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02002017 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02002018
2019 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07002020 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07002021
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002022 if (HAS_VEBOX(dev_priv->dev)) {
2023 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
2024 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07002025
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002026 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002027 i915_handle_error(dev_priv->dev, false,
2028 "VEBOX CS error interrupt 0x%08x",
2029 pm_iir);
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002030 }
Ben Widawsky12638c52013-05-28 19:22:31 -07002031 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07002032}
2033
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002034static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
2035{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002036 if (!drm_handle_vblank(dev, pipe))
2037 return false;
2038
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002039 return true;
2040}
2041
Imre Deakc1874ed2014-02-04 21:35:46 +02002042static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
2043{
2044 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02002045 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02002046 int pipe;
2047
Imre Deak58ead0d2014-02-04 21:35:47 +02002048 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01002049 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02002050 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002051 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02002052
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002053 /*
2054 * PIPESTAT bits get signalled even when the interrupt is
2055 * disabled with the mask bits, and some of the status bits do
2056 * not generate interrupts at all (like the underrun bit). Hence
2057 * we need to be careful that we only handle what we want to
2058 * handle.
2059 */
2060 mask = 0;
2061 if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
2062 mask |= PIPE_FIFO_UNDERRUN_STATUS;
2063
2064 switch (pipe) {
2065 case PIPE_A:
2066 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
2067 break;
2068 case PIPE_B:
2069 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
2070 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03002071 case PIPE_C:
2072 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
2073 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002074 }
2075 if (iir & iir_bit)
2076 mask |= dev_priv->pipestat_irq_mask[pipe];
2077
2078 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02002079 continue;
2080
2081 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002082 mask |= PIPESTAT_INT_ENABLE_MASK;
2083 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02002084
2085 /*
2086 * Clear the PIPE*STAT regs before the IIR
2087 */
Imre Deak91d181d2014-02-10 18:42:49 +02002088 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
2089 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02002090 I915_WRITE(reg, pipe_stats[pipe]);
2091 }
Imre Deak58ead0d2014-02-04 21:35:47 +02002092 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02002093
Damien Lespiau055e3932014-08-18 13:49:10 +01002094 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002095 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
2096 intel_pipe_handle_vblank(dev, pipe))
2097 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002098
Imre Deak579a9b02014-02-04 21:35:48 +02002099 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02002100 intel_prepare_page_flip(dev, pipe);
2101 intel_finish_page_flip(dev, pipe);
2102 }
2103
2104 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2105 i9xx_pipe_crc_irq_handler(dev, pipe);
2106
2107 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
2108 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
2109 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
2110 }
2111
2112 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2113 gmbus_irq_handler(dev);
2114}
2115
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002116static void i9xx_hpd_irq_handler(struct drm_device *dev)
2117{
2118 struct drm_i915_private *dev_priv = dev->dev_private;
2119 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
2120
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002121 if (hotplug_status) {
2122 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2123 /*
2124 * Make sure hotplug status is cleared before we clear IIR, or else we
2125 * may miss hotplug events.
2126 */
2127 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002128
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002129 if (IS_G4X(dev)) {
2130 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002131
Dave Airlie13cf5502014-06-18 11:29:35 +10002132 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002133 } else {
2134 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
2135
Dave Airlie13cf5502014-06-18 11:29:35 +10002136 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002137 }
2138
2139 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
2140 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
2141 dp_aux_irq_handler(dev);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002142 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002143}
2144
Daniel Vetterff1f5252012-10-02 15:10:55 +02002145static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002146{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002147 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002148 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002149 u32 iir, gt_iir, pm_iir;
2150 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002151
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002152 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002153 /* Find, clear, then process each source of interrupt */
2154
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002155 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002156 if (gt_iir)
2157 I915_WRITE(GTIIR, gt_iir);
2158
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002159 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002160 if (pm_iir)
2161 I915_WRITE(GEN6_PMIIR, pm_iir);
2162
2163 iir = I915_READ(VLV_IIR);
2164 if (iir) {
2165 /* Consume port before clearing IIR or we'll miss events */
2166 if (iir & I915_DISPLAY_PORT_INTERRUPT)
2167 i9xx_hpd_irq_handler(dev);
2168 I915_WRITE(VLV_IIR, iir);
2169 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002170
2171 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
2172 goto out;
2173
2174 ret = IRQ_HANDLED;
2175
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002176 if (gt_iir)
2177 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03002178 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02002179 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002180 /* Call regardless, as some status bits might not be
2181 * signalled in iir */
2182 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002183 }
2184
2185out:
2186 return ret;
2187}
2188
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002189static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2190{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002191 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002192 struct drm_i915_private *dev_priv = dev->dev_private;
2193 u32 master_ctl, iir;
2194 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002195
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002196 for (;;) {
2197 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2198 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002199
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002200 if (master_ctl == 0 && iir == 0)
2201 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002202
Oscar Mateo27b6c122014-06-16 16:11:00 +01002203 ret = IRQ_HANDLED;
2204
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002205 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002206
Oscar Mateo27b6c122014-06-16 16:11:00 +01002207 /* Find, clear, then process each source of interrupt */
2208
2209 if (iir) {
2210 /* Consume port before clearing IIR or we'll miss events */
2211 if (iir & I915_DISPLAY_PORT_INTERRUPT)
2212 i9xx_hpd_irq_handler(dev);
2213 I915_WRITE(VLV_IIR, iir);
2214 }
2215
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002216 gen8_gt_irq_handler(dev, dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002217
Oscar Mateo27b6c122014-06-16 16:11:00 +01002218 /* Call regardless, as some status bits might not be
2219 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002220 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002221
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002222 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
2223 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002224 }
2225
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002226 return ret;
2227}
2228
Adam Jackson23e81d62012-06-06 15:45:44 -04002229static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002230{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002231 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002232 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002233 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Dave Airlie13cf5502014-06-18 11:29:35 +10002234 u32 dig_hotplug_reg;
Jesse Barnes776ad802011-01-04 15:09:39 -08002235
Dave Airlie13cf5502014-06-18 11:29:35 +10002236 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2237 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2238
2239 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002240
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002241 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2242 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2243 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002244 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002245 port_name(port));
2246 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002247
Daniel Vetterce99c252012-12-01 13:53:47 +01002248 if (pch_iir & SDE_AUX_MASK)
2249 dp_aux_irq_handler(dev);
2250
Jesse Barnes776ad802011-01-04 15:09:39 -08002251 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002252 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08002253
2254 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2255 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2256
2257 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2258 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2259
2260 if (pch_iir & SDE_POISON)
2261 DRM_ERROR("PCH poison interrupt\n");
2262
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002263 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002264 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002265 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2266 pipe_name(pipe),
2267 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002268
2269 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2270 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2271
2272 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2273 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2274
Jesse Barnes776ad802011-01-04 15:09:39 -08002275 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03002276 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2277 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002278 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002279
2280 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
2281 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2282 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002283 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002284}
2285
2286static void ivb_err_int_handler(struct drm_device *dev)
2287{
2288 struct drm_i915_private *dev_priv = dev->dev_private;
2289 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002290 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002291
Paulo Zanonide032bf2013-04-12 17:57:58 -03002292 if (err_int & ERR_INT_POISON)
2293 DRM_ERROR("Poison interrupt\n");
2294
Damien Lespiau055e3932014-08-18 13:49:10 +01002295 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a69b892013-10-16 22:55:52 +02002296 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
2297 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2298 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002299 DRM_ERROR("Pipe %c FIFO underrun\n",
2300 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02002301 }
Paulo Zanoni86642812013-04-12 17:57:57 -03002302
Daniel Vetter5a69b892013-10-16 22:55:52 +02002303 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
2304 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02002305 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002306 else
Daniel Vetter277de952013-10-18 16:37:07 +02002307 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002308 }
2309 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002310
Paulo Zanoni86642812013-04-12 17:57:57 -03002311 I915_WRITE(GEN7_ERR_INT, err_int);
2312}
2313
2314static void cpt_serr_int_handler(struct drm_device *dev)
2315{
2316 struct drm_i915_private *dev_priv = dev->dev_private;
2317 u32 serr_int = I915_READ(SERR_INT);
2318
Paulo Zanonide032bf2013-04-12 17:57:58 -03002319 if (serr_int & SERR_INT_POISON)
2320 DRM_ERROR("PCH poison interrupt\n");
2321
Paulo Zanoni86642812013-04-12 17:57:57 -03002322 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
2323 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2324 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002325 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002326
2327 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
2328 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2329 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002330 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002331
2332 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
2333 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
2334 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002335 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002336
2337 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002338}
2339
Adam Jackson23e81d62012-06-06 15:45:44 -04002340static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
2341{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002342 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04002343 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002344 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Dave Airlie13cf5502014-06-18 11:29:35 +10002345 u32 dig_hotplug_reg;
Adam Jackson23e81d62012-06-06 15:45:44 -04002346
Dave Airlie13cf5502014-06-18 11:29:35 +10002347 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2348 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2349
2350 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002351
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002352 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2353 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2354 SDE_AUDIO_POWER_SHIFT_CPT);
2355 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2356 port_name(port));
2357 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002358
2359 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01002360 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002361
2362 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002363 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002364
2365 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2366 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2367
2368 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2369 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2370
2371 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002372 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002373 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2374 pipe_name(pipe),
2375 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002376
2377 if (pch_iir & SDE_ERROR_CPT)
2378 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002379}
2380
Paulo Zanonic008bc62013-07-12 16:35:10 -03002381static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2382{
2383 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02002384 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03002385
2386 if (de_iir & DE_AUX_CHANNEL_A)
2387 dp_aux_irq_handler(dev);
2388
2389 if (de_iir & DE_GSE)
2390 intel_opregion_asle_intr(dev);
2391
Paulo Zanonic008bc62013-07-12 16:35:10 -03002392 if (de_iir & DE_POISON)
2393 DRM_ERROR("Poison interrupt\n");
2394
Damien Lespiau055e3932014-08-18 13:49:10 +01002395 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002396 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2397 intel_pipe_handle_vblank(dev, pipe))
2398 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002399
Daniel Vetter40da17c2013-10-21 18:04:36 +02002400 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2401 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002402 DRM_ERROR("Pipe %c FIFO underrun\n",
2403 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03002404
Daniel Vetter40da17c2013-10-21 18:04:36 +02002405 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2406 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002407
Daniel Vetter40da17c2013-10-21 18:04:36 +02002408 /* plane/pipes map 1:1 on ilk+ */
2409 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2410 intel_prepare_page_flip(dev, pipe);
2411 intel_finish_page_flip_plane(dev, pipe);
2412 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03002413 }
2414
2415 /* check event from PCH */
2416 if (de_iir & DE_PCH_EVENT) {
2417 u32 pch_iir = I915_READ(SDEIIR);
2418
2419 if (HAS_PCH_CPT(dev))
2420 cpt_irq_handler(dev, pch_iir);
2421 else
2422 ibx_irq_handler(dev, pch_iir);
2423
2424 /* should clear PCH hotplug event before clear CPU irq */
2425 I915_WRITE(SDEIIR, pch_iir);
2426 }
2427
2428 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2429 ironlake_rps_change_irq_handler(dev);
2430}
2431
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002432static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2433{
2434 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002435 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002436
2437 if (de_iir & DE_ERR_INT_IVB)
2438 ivb_err_int_handler(dev);
2439
2440 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2441 dp_aux_irq_handler(dev);
2442
2443 if (de_iir & DE_GSE_IVB)
2444 intel_opregion_asle_intr(dev);
2445
Damien Lespiau055e3932014-08-18 13:49:10 +01002446 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002447 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2448 intel_pipe_handle_vblank(dev, pipe))
2449 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02002450
2451 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002452 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2453 intel_prepare_page_flip(dev, pipe);
2454 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002455 }
2456 }
2457
2458 /* check event from PCH */
2459 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2460 u32 pch_iir = I915_READ(SDEIIR);
2461
2462 cpt_irq_handler(dev, pch_iir);
2463
2464 /* clear PCH hotplug event before clear CPU irq */
2465 I915_WRITE(SDEIIR, pch_iir);
2466 }
2467}
2468
Oscar Mateo72c90f62014-06-16 16:10:57 +01002469/*
2470 * To handle irqs with the minimum potential races with fresh interrupts, we:
2471 * 1 - Disable Master Interrupt Control.
2472 * 2 - Find the source(s) of the interrupt.
2473 * 3 - Clear the Interrupt Identity bits (IIR).
2474 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2475 * 5 - Re-enable Master Interrupt Control.
2476 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002477static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002478{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002479 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002480 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002481 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002482 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002483
Paulo Zanoni86642812013-04-12 17:57:57 -03002484 /* We get interrupts on unclaimed registers, so check for this before we
2485 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002486 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002487
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002488 /* disable master interrupt before clearing iir */
2489 de_ier = I915_READ(DEIER);
2490 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002491 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002492
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002493 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2494 * interrupts will will be stored on its back queue, and then we'll be
2495 * able to process them after we restore SDEIER (as soon as we restore
2496 * it, we'll get an interrupt if SDEIIR still has something to process
2497 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002498 if (!HAS_PCH_NOP(dev)) {
2499 sde_ier = I915_READ(SDEIER);
2500 I915_WRITE(SDEIER, 0);
2501 POSTING_READ(SDEIER);
2502 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002503
Oscar Mateo72c90f62014-06-16 16:10:57 +01002504 /* Find, clear, then process each source of interrupt */
2505
Chris Wilson0e434062012-05-09 21:45:44 +01002506 gt_iir = I915_READ(GTIIR);
2507 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002508 I915_WRITE(GTIIR, gt_iir);
2509 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002510 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002511 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002512 else
2513 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002514 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002515
2516 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002517 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002518 I915_WRITE(DEIIR, de_iir);
2519 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002520 if (INTEL_INFO(dev)->gen >= 7)
2521 ivb_display_irq_handler(dev, de_iir);
2522 else
2523 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002524 }
2525
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002526 if (INTEL_INFO(dev)->gen >= 6) {
2527 u32 pm_iir = I915_READ(GEN6_PMIIR);
2528 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002529 I915_WRITE(GEN6_PMIIR, pm_iir);
2530 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002531 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002532 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002533 }
2534
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002535 I915_WRITE(DEIER, de_ier);
2536 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002537 if (!HAS_PCH_NOP(dev)) {
2538 I915_WRITE(SDEIER, sde_ier);
2539 POSTING_READ(SDEIER);
2540 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002541
2542 return ret;
2543}
2544
Ben Widawskyabd58f02013-11-02 21:07:09 -07002545static irqreturn_t gen8_irq_handler(int irq, void *arg)
2546{
2547 struct drm_device *dev = arg;
2548 struct drm_i915_private *dev_priv = dev->dev_private;
2549 u32 master_ctl;
2550 irqreturn_t ret = IRQ_NONE;
2551 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002552 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002553
Ben Widawskyabd58f02013-11-02 21:07:09 -07002554 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2555 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2556 if (!master_ctl)
2557 return IRQ_NONE;
2558
2559 I915_WRITE(GEN8_MASTER_IRQ, 0);
2560 POSTING_READ(GEN8_MASTER_IRQ);
2561
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002562 /* Find, clear, then process each source of interrupt */
2563
Ben Widawskyabd58f02013-11-02 21:07:09 -07002564 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2565
2566 if (master_ctl & GEN8_DE_MISC_IRQ) {
2567 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002568 if (tmp) {
2569 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2570 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002571 if (tmp & GEN8_DE_MISC_GSE)
2572 intel_opregion_asle_intr(dev);
2573 else
2574 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002575 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002576 else
2577 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002578 }
2579
Daniel Vetter6d766f02013-11-07 14:49:55 +01002580 if (master_ctl & GEN8_DE_PORT_IRQ) {
2581 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002582 if (tmp) {
2583 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2584 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002585 if (tmp & GEN8_AUX_CHANNEL_A)
2586 dp_aux_irq_handler(dev);
2587 else
2588 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002589 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002590 else
2591 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002592 }
2593
Damien Lespiau055e3932014-08-18 13:49:10 +01002594 for_each_pipe(dev_priv, pipe) {
Damien Lespiau770de832014-03-20 20:45:01 +00002595 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002596
Daniel Vetterc42664c2013-11-07 11:05:40 +01002597 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2598 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002599
Daniel Vetterc42664c2013-11-07 11:05:40 +01002600 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002601 if (pipe_iir) {
2602 ret = IRQ_HANDLED;
2603 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Damien Lespiau770de832014-03-20 20:45:01 +00002604
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002605 if (pipe_iir & GEN8_PIPE_VBLANK &&
2606 intel_pipe_handle_vblank(dev, pipe))
2607 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002608
Damien Lespiau770de832014-03-20 20:45:01 +00002609 if (IS_GEN9(dev))
2610 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2611 else
2612 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2613
2614 if (flip_done) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002615 intel_prepare_page_flip(dev, pipe);
2616 intel_finish_page_flip_plane(dev, pipe);
2617 }
2618
2619 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2620 hsw_pipe_crc_irq_handler(dev, pipe);
2621
2622 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
2623 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2624 false))
2625 DRM_ERROR("Pipe %c FIFO underrun\n",
2626 pipe_name(pipe));
2627 }
2628
Damien Lespiau770de832014-03-20 20:45:01 +00002629
2630 if (IS_GEN9(dev))
2631 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2632 else
2633 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2634
2635 if (fault_errors)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002636 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2637 pipe_name(pipe),
2638 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
Daniel Vetterc42664c2013-11-07 11:05:40 +01002639 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002640 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2641 }
2642
Daniel Vetter92d03a82013-11-07 11:05:43 +01002643 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2644 /*
2645 * FIXME(BDW): Assume for now that the new interrupt handling
2646 * scheme also closed the SDE interrupt handling race we've seen
2647 * on older pch-split platforms. But this needs testing.
2648 */
2649 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002650 if (pch_iir) {
2651 I915_WRITE(SDEIIR, pch_iir);
2652 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002653 cpt_irq_handler(dev, pch_iir);
2654 } else
2655 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2656
Daniel Vetter92d03a82013-11-07 11:05:43 +01002657 }
2658
Ben Widawskyabd58f02013-11-02 21:07:09 -07002659 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2660 POSTING_READ(GEN8_MASTER_IRQ);
2661
2662 return ret;
2663}
2664
Daniel Vetter17e1df02013-09-08 21:57:13 +02002665static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2666 bool reset_completed)
2667{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002668 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002669 int i;
2670
2671 /*
2672 * Notify all waiters for GPU completion events that reset state has
2673 * been changed, and that they need to restart their wait after
2674 * checking for potential errors (and bail out to drop locks if there is
2675 * a gpu reset pending so that i915_error_work_func can acquire them).
2676 */
2677
2678 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2679 for_each_ring(ring, dev_priv, i)
2680 wake_up_all(&ring->irq_queue);
2681
2682 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2683 wake_up_all(&dev_priv->pending_flip_queue);
2684
2685 /*
2686 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2687 * reset state is cleared.
2688 */
2689 if (reset_completed)
2690 wake_up_all(&dev_priv->gpu_error.reset_queue);
2691}
2692
Jesse Barnes8a905232009-07-11 16:48:03 -04002693/**
2694 * i915_error_work_func - do process context error handling work
2695 * @work: work struct
2696 *
2697 * Fire an error uevent so userspace can see that a hang or error
2698 * was detected.
2699 */
2700static void i915_error_work_func(struct work_struct *work)
2701{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002702 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2703 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002704 struct drm_i915_private *dev_priv =
2705 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002706 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002707 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2708 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2709 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002710 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002711
Dave Airlie5bdebb12013-10-11 14:07:25 +10002712 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002713
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002714 /*
2715 * Note that there's only one work item which does gpu resets, so we
2716 * need not worry about concurrent gpu resets potentially incrementing
2717 * error->reset_counter twice. We only need to take care of another
2718 * racing irq/hangcheck declaring the gpu dead for a second time. A
2719 * quick check for that is good enough: schedule_work ensures the
2720 * correct ordering between hang detection and this work item, and since
2721 * the reset in-progress bit is only ever set by code outside of this
2722 * work we don't need to worry about any other races.
2723 */
2724 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002725 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002726 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002727 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002728
Daniel Vetter17e1df02013-09-08 21:57:13 +02002729 /*
Imre Deakf454c692014-04-23 01:09:04 +03002730 * In most cases it's guaranteed that we get here with an RPM
2731 * reference held, for example because there is a pending GPU
2732 * request that won't finish until the reset is done. This
2733 * isn't the case at least when we get here by doing a
2734 * simulated reset via debugs, so get an RPM reference.
2735 */
2736 intel_runtime_pm_get(dev_priv);
2737 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002738 * All state reset _must_ be completed before we update the
2739 * reset counter, for otherwise waiters might miss the reset
2740 * pending state and not properly drop locks, resulting in
2741 * deadlocks with the reset work.
2742 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002743 ret = i915_reset(dev);
2744
Daniel Vetter17e1df02013-09-08 21:57:13 +02002745 intel_display_handle_reset(dev);
2746
Imre Deakf454c692014-04-23 01:09:04 +03002747 intel_runtime_pm_put(dev_priv);
2748
Daniel Vetterf69061b2012-12-06 09:01:42 +01002749 if (ret == 0) {
2750 /*
2751 * After all the gem state is reset, increment the reset
2752 * counter and wake up everyone waiting for the reset to
2753 * complete.
2754 *
2755 * Since unlock operations are a one-sided barrier only,
2756 * we need to insert a barrier here to order any seqno
2757 * updates before
2758 * the counter increment.
2759 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002760 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002761 atomic_inc(&dev_priv->gpu_error.reset_counter);
2762
Dave Airlie5bdebb12013-10-11 14:07:25 +10002763 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002764 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002765 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002766 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002767 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002768
Daniel Vetter17e1df02013-09-08 21:57:13 +02002769 /*
2770 * Note: The wake_up also serves as a memory barrier so that
2771 * waiters see the update value of the reset counter atomic_t.
2772 */
2773 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002774 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002775}
2776
Chris Wilson35aed2e2010-05-27 13:18:12 +01002777static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002778{
2779 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002780 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002781 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002782 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002783
Chris Wilson35aed2e2010-05-27 13:18:12 +01002784 if (!eir)
2785 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002786
Joe Perchesa70491c2012-03-18 13:00:11 -07002787 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002788
Ben Widawskybd9854f2012-08-23 15:18:09 -07002789 i915_get_extra_instdone(dev, instdone);
2790
Jesse Barnes8a905232009-07-11 16:48:03 -04002791 if (IS_G4X(dev)) {
2792 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2793 u32 ipeir = I915_READ(IPEIR_I965);
2794
Joe Perchesa70491c2012-03-18 13:00:11 -07002795 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2796 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002797 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2798 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002799 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002800 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002801 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002802 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002803 }
2804 if (eir & GM45_ERROR_PAGE_TABLE) {
2805 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002806 pr_err("page table error\n");
2807 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002808 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002809 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002810 }
2811 }
2812
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002813 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002814 if (eir & I915_ERROR_PAGE_TABLE) {
2815 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002816 pr_err("page table error\n");
2817 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002818 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002819 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002820 }
2821 }
2822
2823 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002824 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002825 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002826 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002827 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002828 /* pipestat has already been acked */
2829 }
2830 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002831 pr_err("instruction error\n");
2832 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002833 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2834 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002835 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002836 u32 ipeir = I915_READ(IPEIR);
2837
Joe Perchesa70491c2012-03-18 13:00:11 -07002838 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2839 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002840 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002841 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002842 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002843 } else {
2844 u32 ipeir = I915_READ(IPEIR_I965);
2845
Joe Perchesa70491c2012-03-18 13:00:11 -07002846 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2847 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002848 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002849 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002850 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002851 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002852 }
2853 }
2854
2855 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002856 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002857 eir = I915_READ(EIR);
2858 if (eir) {
2859 /*
2860 * some errors might have become stuck,
2861 * mask them.
2862 */
2863 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2864 I915_WRITE(EMR, I915_READ(EMR) | eir);
2865 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2866 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002867}
2868
2869/**
2870 * i915_handle_error - handle an error interrupt
2871 * @dev: drm device
2872 *
2873 * Do some basic checking of regsiter state at error interrupt time and
2874 * dump it to the syslog. Also call i915_capture_error_state() to make
2875 * sure we get a record and make it available in debugfs. Fire a uevent
2876 * so userspace knows something bad happened (should trigger collection
2877 * of a ring dump etc.).
2878 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002879void i915_handle_error(struct drm_device *dev, bool wedged,
2880 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002881{
2882 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002883 va_list args;
2884 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002885
Mika Kuoppala58174462014-02-25 17:11:26 +02002886 va_start(args, fmt);
2887 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2888 va_end(args);
2889
2890 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002891 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002892
Ben Gamariba1234d2009-09-14 17:48:47 -04002893 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002894 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2895 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002896
Ben Gamari11ed50e2009-09-14 17:48:45 -04002897 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002898 * Wakeup waiting processes so that the reset work function
2899 * i915_error_work_func doesn't deadlock trying to grab various
2900 * locks. By bumping the reset counter first, the woken
2901 * processes will see a reset in progress and back off,
2902 * releasing their locks and then wait for the reset completion.
2903 * We must do this for _all_ gpu waiters that might hold locks
2904 * that the reset work needs to acquire.
2905 *
2906 * Note: The wake_up serves as the required memory barrier to
2907 * ensure that the waiters see the updated value of the reset
2908 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002909 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002910 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002911 }
2912
Daniel Vetter122f46b2013-09-04 17:36:14 +02002913 /*
2914 * Our reset work can grab modeset locks (since it needs to reset the
2915 * state of outstanding pagelips). Hence it must not be run on our own
2916 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2917 * code will deadlock.
2918 */
2919 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002920}
2921
Keith Packard42f52ef2008-10-18 19:39:29 -07002922/* Called from drm generic code, passed 'crtc' which
2923 * we use as a pipe index
2924 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002925static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002926{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002927 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002928 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002929
Chris Wilson5eddb702010-09-11 13:48:45 +01002930 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002931 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002932
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002933 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002934 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002935 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002936 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002937 else
Keith Packard7c463582008-11-04 02:03:27 -08002938 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002939 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002940 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002941
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002942 return 0;
2943}
2944
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002945static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002946{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002947 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002948 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002949 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002950 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002951
2952 if (!i915_pipe_enabled(dev, pipe))
2953 return -EINVAL;
2954
2955 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002956 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002957 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2958
2959 return 0;
2960}
2961
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002962static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2963{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002964 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002965 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002966
2967 if (!i915_pipe_enabled(dev, pipe))
2968 return -EINVAL;
2969
2970 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002971 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002972 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002973 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2974
2975 return 0;
2976}
2977
Ben Widawskyabd58f02013-11-02 21:07:09 -07002978static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2979{
2980 struct drm_i915_private *dev_priv = dev->dev_private;
2981 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002982
2983 if (!i915_pipe_enabled(dev, pipe))
2984 return -EINVAL;
2985
2986 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002987 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2988 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2989 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002990 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2991 return 0;
2992}
2993
Keith Packard42f52ef2008-10-18 19:39:29 -07002994/* Called from drm generic code, passed 'crtc' which
2995 * we use as a pipe index
2996 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002997static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002998{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002999 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07003000 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003001
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003002 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003003 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003004 PIPE_VBLANK_INTERRUPT_STATUS |
3005 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003006 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3007}
3008
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003009static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003010{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003011 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07003012 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03003013 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02003014 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003015
3016 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03003017 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003018 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3019}
3020
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003021static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
3022{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003023 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003024 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003025
3026 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003027 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003028 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003029 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3030}
3031
Ben Widawskyabd58f02013-11-02 21:07:09 -07003032static void gen8_disable_vblank(struct drm_device *dev, int pipe)
3033{
3034 struct drm_i915_private *dev_priv = dev->dev_private;
3035 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003036
3037 if (!i915_pipe_enabled(dev, pipe))
3038 return;
3039
3040 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01003041 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
3042 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3043 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07003044 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3045}
3046
Chris Wilson893eead2010-10-27 14:44:35 +01003047static u32
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003048ring_last_seqno(struct intel_engine_cs *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08003049{
Chris Wilson893eead2010-10-27 14:44:35 +01003050 return list_entry(ring->request_list.prev,
3051 struct drm_i915_gem_request, list)->seqno;
3052}
3053
Chris Wilson9107e9d2013-06-10 11:20:20 +01003054static bool
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003055ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01003056{
Chris Wilson9107e9d2013-06-10 11:20:20 +01003057 return (list_empty(&ring->request_list) ||
3058 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04003059}
3060
Daniel Vettera028c4b2014-03-15 00:08:56 +01003061static bool
3062ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
3063{
3064 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003065 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01003066 } else {
3067 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
3068 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
3069 MI_SEMAPHORE_REGISTER);
3070 }
3071}
3072
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003073static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003074semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01003075{
3076 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003077 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01003078 int i;
3079
3080 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003081 for_each_ring(signaller, dev_priv, i) {
3082 if (ring == signaller)
3083 continue;
3084
3085 if (offset == signaller->semaphore.signal_ggtt[ring->id])
3086 return signaller;
3087 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01003088 } else {
3089 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
3090
3091 for_each_ring(signaller, dev_priv, i) {
3092 if(ring == signaller)
3093 continue;
3094
Ben Widawskyebc348b2014-04-29 14:52:28 -07003095 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01003096 return signaller;
3097 }
3098 }
3099
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003100 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
3101 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01003102
3103 return NULL;
3104}
3105
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003106static struct intel_engine_cs *
3107semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02003108{
3109 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003110 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003111 u64 offset = 0;
3112 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02003113
3114 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01003115 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01003116 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02003117
Daniel Vetter88fe4292014-03-15 00:08:55 +01003118 /*
3119 * HEAD is likely pointing to the dword after the actual command,
3120 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003121 * or 4 dwords depending on the semaphore wait command size.
3122 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01003123 * point at at batch, and semaphores are always emitted into the
3124 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02003125 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01003126 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003127 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003128
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003129 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01003130 /*
3131 * Be paranoid and presume the hw has gone off into the wild -
3132 * our ring is smaller than what the hardware (and hence
3133 * HEAD_ADDR) allows. Also handles wrap-around.
3134 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003135 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003136
3137 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003138 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02003139 if (cmd == ipehr)
3140 break;
3141
Daniel Vetter88fe4292014-03-15 00:08:55 +01003142 head -= 4;
3143 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003144
Daniel Vetter88fe4292014-03-15 00:08:55 +01003145 if (!i)
3146 return NULL;
3147
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003148 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003149 if (INTEL_INFO(ring->dev)->gen >= 8) {
3150 offset = ioread32(ring->buffer->virtual_start + head + 12);
3151 offset <<= 32;
3152 offset = ioread32(ring->buffer->virtual_start + head + 8);
3153 }
3154 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02003155}
3156
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003157static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01003158{
3159 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003160 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01003161 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01003162
Chris Wilson4be17382014-06-06 10:22:29 +01003163 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01003164
3165 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01003166 if (signaller == NULL)
3167 return -1;
3168
3169 /* Prevent pathological recursion due to driver bugs */
3170 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01003171 return -1;
3172
Chris Wilson4be17382014-06-06 10:22:29 +01003173 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
3174 return 1;
3175
Chris Wilsona0d036b2014-07-19 12:40:42 +01003176 /* cursory check for an unkickable deadlock */
3177 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
3178 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01003179 return -1;
3180
3181 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01003182}
3183
3184static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
3185{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003186 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01003187 int i;
3188
3189 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01003190 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01003191}
3192
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003193static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003194ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003195{
3196 struct drm_device *dev = ring->dev;
3197 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003198 u32 tmp;
3199
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003200 if (acthd != ring->hangcheck.acthd) {
3201 if (acthd > ring->hangcheck.max_acthd) {
3202 ring->hangcheck.max_acthd = acthd;
3203 return HANGCHECK_ACTIVE;
3204 }
3205
3206 return HANGCHECK_ACTIVE_LOOP;
3207 }
Chris Wilson6274f212013-06-10 11:20:21 +01003208
Chris Wilson9107e9d2013-06-10 11:20:20 +01003209 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003210 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003211
3212 /* Is the chip hanging on a WAIT_FOR_EVENT?
3213 * If so we can simply poke the RB_WAIT bit
3214 * and break the hang. This should work on
3215 * all but the second generation chipsets.
3216 */
3217 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003218 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02003219 i915_handle_error(dev, false,
3220 "Kicking stuck wait on %s",
3221 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003222 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003223 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003224 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003225
Chris Wilson6274f212013-06-10 11:20:21 +01003226 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
3227 switch (semaphore_passed(ring)) {
3228 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003229 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003230 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02003231 i915_handle_error(dev, false,
3232 "Kicking stuck semaphore on %s",
3233 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01003234 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003235 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003236 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003237 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003238 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003239 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003240
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003241 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003242}
3243
Ben Gamarif65d9422009-09-14 17:48:44 -04003244/**
3245 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003246 * batchbuffers in a long time. We keep track per ring seqno progress and
3247 * if there are no progress, hangcheck score for that ring is increased.
3248 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3249 * we kick the ring. If we see no progress on three subsequent calls
3250 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003251 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01003252static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04003253{
3254 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003255 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003256 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01003257 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003258 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003259 bool stuck[I915_NUM_RINGS] = { 0 };
3260#define BUSY 1
3261#define KICK 5
3262#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01003263
Jani Nikulad330a952014-01-21 11:24:25 +02003264 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003265 return;
3266
Chris Wilsonb4519512012-05-11 14:29:30 +01003267 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00003268 u64 acthd;
3269 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003270 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01003271
Chris Wilson6274f212013-06-10 11:20:21 +01003272 semaphore_clear_deadlocks(dev_priv);
3273
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003274 seqno = ring->get_seqno(ring, false);
3275 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003276
Chris Wilson9107e9d2013-06-10 11:20:20 +01003277 if (ring->hangcheck.seqno == seqno) {
3278 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003279 ring->hangcheck.action = HANGCHECK_IDLE;
3280
Chris Wilson9107e9d2013-06-10 11:20:20 +01003281 if (waitqueue_active(&ring->irq_queue)) {
3282 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01003283 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01003284 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
3285 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
3286 ring->name);
3287 else
3288 DRM_INFO("Fake missed irq on %s\n",
3289 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01003290 wake_up_all(&ring->irq_queue);
3291 }
3292 /* Safeguard against driver failure */
3293 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003294 } else
3295 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003296 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003297 /* We always increment the hangcheck score
3298 * if the ring is busy and still processing
3299 * the same request, so that no single request
3300 * can run indefinitely (such as a chain of
3301 * batches). The only time we do not increment
3302 * the hangcheck score on this ring, if this
3303 * ring is in a legitimate wait for another
3304 * ring. In that case the waiting ring is a
3305 * victim and we want to be sure we catch the
3306 * right culprit. Then every time we do kick
3307 * the ring, add a small increment to the
3308 * score so that we can catch a batch that is
3309 * being repeatedly kicked and so responsible
3310 * for stalling the machine.
3311 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003312 ring->hangcheck.action = ring_stuck(ring,
3313 acthd);
3314
3315 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003316 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003317 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003318 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003319 break;
3320 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003321 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003322 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003323 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003324 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003325 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003326 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003327 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003328 stuck[i] = true;
3329 break;
3330 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003331 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003332 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03003333 ring->hangcheck.action = HANGCHECK_ACTIVE;
3334
Chris Wilson9107e9d2013-06-10 11:20:20 +01003335 /* Gradually reduce the count so that we catch DoS
3336 * attempts across multiple batches.
3337 */
3338 if (ring->hangcheck.score > 0)
3339 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003340
3341 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01003342 }
3343
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003344 ring->hangcheck.seqno = seqno;
3345 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003346 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003347 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003348
Mika Kuoppala92cab732013-05-24 17:16:07 +03003349 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02003350 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003351 DRM_INFO("%s on %s\n",
3352 stuck[i] ? "stuck" : "no progress",
3353 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01003354 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003355 }
3356 }
3357
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003358 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02003359 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003360
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003361 if (busy_count)
3362 /* Reset timer case chip hangs without another request
3363 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003364 i915_queue_hangcheck(dev);
3365}
3366
3367void i915_queue_hangcheck(struct drm_device *dev)
3368{
3369 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02003370 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003371 return;
3372
3373 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
3374 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003375}
3376
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003377static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003378{
3379 struct drm_i915_private *dev_priv = dev->dev_private;
3380
3381 if (HAS_PCH_NOP(dev))
3382 return;
3383
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003384 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003385
3386 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3387 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003388}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003389
Paulo Zanoni622364b2014-04-01 15:37:22 -03003390/*
3391 * SDEIER is also touched by the interrupt handler to work around missed PCH
3392 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3393 * instead we unconditionally enable all PCH interrupt sources here, but then
3394 * only unmask them as needed with SDEIMR.
3395 *
3396 * This function needs to be called before interrupts are enabled.
3397 */
3398static void ibx_irq_pre_postinstall(struct drm_device *dev)
3399{
3400 struct drm_i915_private *dev_priv = dev->dev_private;
3401
3402 if (HAS_PCH_NOP(dev))
3403 return;
3404
3405 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003406 I915_WRITE(SDEIER, 0xffffffff);
3407 POSTING_READ(SDEIER);
3408}
3409
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003410static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003411{
3412 struct drm_i915_private *dev_priv = dev->dev_private;
3413
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003414 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003415 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003416 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003417}
3418
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419/* drm_dma.h hooks
3420*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003421static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003422{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003423 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003424
Paulo Zanoni0c841212014-04-01 15:37:27 -03003425 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003426
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003427 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003428 if (IS_GEN7(dev))
3429 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003430
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003431 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003432
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003433 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003434}
3435
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003436static void valleyview_irq_preinstall(struct drm_device *dev)
3437{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003438 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003439 int pipe;
3440
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003441 /* VLV magic */
3442 I915_WRITE(VLV_IMR, 0);
3443 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3444 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3445 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3446
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003447 /* and GT */
3448 I915_WRITE(GTIIR, I915_READ(GTIIR));
3449 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003450
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003451 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003452
3453 I915_WRITE(DPINVGTT, 0xff);
3454
3455 I915_WRITE(PORT_HOTPLUG_EN, 0);
3456 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Damien Lespiau055e3932014-08-18 13:49:10 +01003457 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003458 I915_WRITE(PIPESTAT(pipe), 0xffff);
3459 I915_WRITE(VLV_IIR, 0xffffffff);
3460 I915_WRITE(VLV_IMR, 0xffffffff);
3461 I915_WRITE(VLV_IER, 0x0);
3462 POSTING_READ(VLV_IER);
3463}
3464
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003465static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3466{
3467 GEN8_IRQ_RESET_NDX(GT, 0);
3468 GEN8_IRQ_RESET_NDX(GT, 1);
3469 GEN8_IRQ_RESET_NDX(GT, 2);
3470 GEN8_IRQ_RESET_NDX(GT, 3);
3471}
3472
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003473static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003474{
3475 struct drm_i915_private *dev_priv = dev->dev_private;
3476 int pipe;
3477
Ben Widawskyabd58f02013-11-02 21:07:09 -07003478 I915_WRITE(GEN8_MASTER_IRQ, 0);
3479 POSTING_READ(GEN8_MASTER_IRQ);
3480
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003481 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003482
Damien Lespiau055e3932014-08-18 13:49:10 +01003483 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003484 if (intel_display_power_is_enabled(dev_priv,
3485 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003486 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003487
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003488 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3489 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3490 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003491
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003492 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003493}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003494
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003495void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv)
3496{
Daniel Vetter13321782014-09-15 14:55:29 +02003497 spin_lock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003498 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B, dev_priv->de_irq_mask[PIPE_B],
3499 ~dev_priv->de_irq_mask[PIPE_B]);
3500 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C, dev_priv->de_irq_mask[PIPE_C],
3501 ~dev_priv->de_irq_mask[PIPE_C]);
Daniel Vetter13321782014-09-15 14:55:29 +02003502 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003503}
3504
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003505static void cherryview_irq_preinstall(struct drm_device *dev)
3506{
3507 struct drm_i915_private *dev_priv = dev->dev_private;
3508 int pipe;
3509
3510 I915_WRITE(GEN8_MASTER_IRQ, 0);
3511 POSTING_READ(GEN8_MASTER_IRQ);
3512
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003513 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003514
3515 GEN5_IRQ_RESET(GEN8_PCU_);
3516
3517 POSTING_READ(GEN8_PCU_IIR);
3518
3519 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3520
3521 I915_WRITE(PORT_HOTPLUG_EN, 0);
3522 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3523
Damien Lespiau055e3932014-08-18 13:49:10 +01003524 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003525 I915_WRITE(PIPESTAT(pipe), 0xffff);
3526
3527 I915_WRITE(VLV_IMR, 0xffffffff);
3528 I915_WRITE(VLV_IER, 0x0);
3529 I915_WRITE(VLV_IIR, 0xffffffff);
3530 POSTING_READ(VLV_IIR);
3531}
3532
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003533static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003534{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003535 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003536 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02003537 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07003538
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003539 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003540 hotplug_irqs = SDE_HOTPLUG_MASK;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003541 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003542 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003543 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003544 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003545 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003546 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003547 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003548 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003549 }
3550
Daniel Vetterfee884e2013-07-04 23:35:21 +02003551 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003552
3553 /*
3554 * Enable digital hotplug on the PCH, and configure the DP short pulse
3555 * duration to 2ms (which is the minimum in the Display Port spec)
3556 *
3557 * This register is the same on all known PCH chips.
3558 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003559 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3560 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3561 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3562 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3563 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3564 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3565}
3566
Paulo Zanonid46da432013-02-08 17:35:15 -02003567static void ibx_irq_postinstall(struct drm_device *dev)
3568{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003569 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003570 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003571
Daniel Vetter692a04c2013-05-29 21:43:05 +02003572 if (HAS_PCH_NOP(dev))
3573 return;
3574
Paulo Zanoni105b1222014-04-01 15:37:17 -03003575 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003576 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003577 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003578 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003579
Paulo Zanoni337ba012014-04-01 15:37:16 -03003580 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003581 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003582}
3583
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003584static void gen5_gt_irq_postinstall(struct drm_device *dev)
3585{
3586 struct drm_i915_private *dev_priv = dev->dev_private;
3587 u32 pm_irqs, gt_irqs;
3588
3589 pm_irqs = gt_irqs = 0;
3590
3591 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003592 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003593 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003594 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3595 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003596 }
3597
3598 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3599 if (IS_GEN5(dev)) {
3600 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3601 ILK_BSD_USER_INTERRUPT;
3602 } else {
3603 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3604 }
3605
Paulo Zanoni35079892014-04-01 15:37:15 -03003606 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003607
3608 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303609 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003610
3611 if (HAS_VEBOX(dev))
3612 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3613
Paulo Zanoni605cd252013-08-06 18:57:15 -03003614 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003615 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003616 }
3617}
3618
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003619static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003620{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003621 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003622 u32 display_mask, extra_mask;
3623
3624 if (INTEL_INFO(dev)->gen >= 7) {
3625 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3626 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3627 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003628 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003629 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003630 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003631 } else {
3632 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3633 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003634 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003635 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3636 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003637 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3638 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003639 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003640
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003641 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003642
Paulo Zanoni0c841212014-04-01 15:37:27 -03003643 I915_WRITE(HWSTAM, 0xeffe);
3644
Paulo Zanoni622364b2014-04-01 15:37:22 -03003645 ibx_irq_pre_postinstall(dev);
3646
Paulo Zanoni35079892014-04-01 15:37:15 -03003647 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003648
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003649 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003650
Paulo Zanonid46da432013-02-08 17:35:15 -02003651 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003652
Jesse Barnesf97108d2010-01-29 11:27:07 -08003653 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003654 /* Enable PCU event interrupts
3655 *
3656 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003657 * setup is guaranteed to run in single-threaded context. But we
3658 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003659 spin_lock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003660 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003661 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003662 }
3663
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003664 return 0;
3665}
3666
Imre Deakf8b79e52014-03-04 19:23:07 +02003667static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3668{
3669 u32 pipestat_mask;
3670 u32 iir_mask;
3671
3672 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3673 PIPE_FIFO_UNDERRUN_STATUS;
3674
3675 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3676 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3677 POSTING_READ(PIPESTAT(PIPE_A));
3678
3679 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3680 PIPE_CRC_DONE_INTERRUPT_STATUS;
3681
3682 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3683 PIPE_GMBUS_INTERRUPT_STATUS);
3684 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3685
3686 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3687 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3688 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3689 dev_priv->irq_mask &= ~iir_mask;
3690
3691 I915_WRITE(VLV_IIR, iir_mask);
3692 I915_WRITE(VLV_IIR, iir_mask);
3693 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3694 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3695 POSTING_READ(VLV_IER);
3696}
3697
3698static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3699{
3700 u32 pipestat_mask;
3701 u32 iir_mask;
3702
3703 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3704 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003705 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003706
3707 dev_priv->irq_mask |= iir_mask;
3708 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3709 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3710 I915_WRITE(VLV_IIR, iir_mask);
3711 I915_WRITE(VLV_IIR, iir_mask);
3712 POSTING_READ(VLV_IIR);
3713
3714 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3715 PIPE_CRC_DONE_INTERRUPT_STATUS;
3716
3717 i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3718 PIPE_GMBUS_INTERRUPT_STATUS);
3719 i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3720
3721 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3722 PIPE_FIFO_UNDERRUN_STATUS;
3723 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3724 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3725 POSTING_READ(PIPESTAT(PIPE_A));
3726}
3727
3728void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3729{
3730 assert_spin_locked(&dev_priv->irq_lock);
3731
3732 if (dev_priv->display_irqs_enabled)
3733 return;
3734
3735 dev_priv->display_irqs_enabled = true;
3736
Imre Deak950eaba2014-09-08 15:21:09 +03003737 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003738 valleyview_display_irqs_install(dev_priv);
3739}
3740
3741void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3742{
3743 assert_spin_locked(&dev_priv->irq_lock);
3744
3745 if (!dev_priv->display_irqs_enabled)
3746 return;
3747
3748 dev_priv->display_irqs_enabled = false;
3749
Imre Deak950eaba2014-09-08 15:21:09 +03003750 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003751 valleyview_display_irqs_uninstall(dev_priv);
3752}
3753
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003754static int valleyview_irq_postinstall(struct drm_device *dev)
3755{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003756 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003757
Imre Deakf8b79e52014-03-04 19:23:07 +02003758 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003759
Daniel Vetter20afbda2012-12-11 14:05:07 +01003760 I915_WRITE(PORT_HOTPLUG_EN, 0);
3761 POSTING_READ(PORT_HOTPLUG_EN);
3762
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003763 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003764 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003765 I915_WRITE(VLV_IIR, 0xffffffff);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003766 POSTING_READ(VLV_IER);
3767
Daniel Vetterb79480b2013-06-27 17:52:10 +02003768 /* Interrupt setup is already guaranteed to be single-threaded, this is
3769 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003770 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003771 if (dev_priv->display_irqs_enabled)
3772 valleyview_display_irqs_install(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003773 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003774
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003775 I915_WRITE(VLV_IIR, 0xffffffff);
3776 I915_WRITE(VLV_IIR, 0xffffffff);
3777
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003778 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003779
3780 /* ack & enable invalid PTE error interrupts */
3781#if 0 /* FIXME: add support to irq handler for checking these bits */
3782 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3783 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3784#endif
3785
3786 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003787
3788 return 0;
3789}
3790
Ben Widawskyabd58f02013-11-02 21:07:09 -07003791static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3792{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003793 /* These are interrupts we'll toggle with the ring mask register */
3794 uint32_t gt_interrupts[] = {
3795 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003796 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003797 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003798 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3799 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003800 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003801 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3802 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3803 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003804 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003805 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3806 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003807 };
3808
Ben Widawsky09610212014-05-15 20:58:08 +03003809 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303810 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3811 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
3812 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, dev_priv->pm_rps_events);
3813 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003814}
3815
3816static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3817{
Damien Lespiau770de832014-03-20 20:45:01 +00003818 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3819 uint32_t de_pipe_enables;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003820 int pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003821
3822 if (IS_GEN9(dev_priv))
3823 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3824 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
3825 else
3826 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3827 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3828
3829 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3830 GEN8_PIPE_FIFO_UNDERRUN;
3831
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003832 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3833 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3834 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003835
Damien Lespiau055e3932014-08-18 13:49:10 +01003836 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003837 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003838 POWER_DOMAIN_PIPE(pipe)))
3839 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3840 dev_priv->de_irq_mask[pipe],
3841 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003842
Paulo Zanoni35079892014-04-01 15:37:15 -03003843 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003844}
3845
3846static int gen8_irq_postinstall(struct drm_device *dev)
3847{
3848 struct drm_i915_private *dev_priv = dev->dev_private;
3849
Paulo Zanoni622364b2014-04-01 15:37:22 -03003850 ibx_irq_pre_postinstall(dev);
3851
Ben Widawskyabd58f02013-11-02 21:07:09 -07003852 gen8_gt_irq_postinstall(dev_priv);
3853 gen8_de_irq_postinstall(dev_priv);
3854
3855 ibx_irq_postinstall(dev);
3856
3857 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3858 POSTING_READ(GEN8_MASTER_IRQ);
3859
3860 return 0;
3861}
3862
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003863static int cherryview_irq_postinstall(struct drm_device *dev)
3864{
3865 struct drm_i915_private *dev_priv = dev->dev_private;
3866 u32 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3867 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003868 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä3278f672014-04-09 13:28:49 +03003869 I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3870 u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
3871 PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003872 int pipe;
3873
3874 /*
3875 * Leave vblank interrupts masked initially. enable/disable will
3876 * toggle them based on usage.
3877 */
Ville Syrjälä3278f672014-04-09 13:28:49 +03003878 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003879
Damien Lespiau055e3932014-08-18 13:49:10 +01003880 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003881 I915_WRITE(PIPESTAT(pipe), 0xffff);
3882
Daniel Vetterd6207432014-09-15 14:55:27 +02003883 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä3278f672014-04-09 13:28:49 +03003884 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
Damien Lespiau055e3932014-08-18 13:49:10 +01003885 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003886 i915_enable_pipestat(dev_priv, pipe, pipestat_enable);
Daniel Vetterd6207432014-09-15 14:55:27 +02003887 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003888
3889 I915_WRITE(VLV_IIR, 0xffffffff);
3890 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3891 I915_WRITE(VLV_IER, enable_mask);
3892
3893 gen8_gt_irq_postinstall(dev_priv);
3894
3895 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3896 POSTING_READ(GEN8_MASTER_IRQ);
3897
3898 return 0;
3899}
3900
Ben Widawskyabd58f02013-11-02 21:07:09 -07003901static void gen8_irq_uninstall(struct drm_device *dev)
3902{
3903 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003904
3905 if (!dev_priv)
3906 return;
3907
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003908 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003909}
3910
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003911static void valleyview_irq_uninstall(struct drm_device *dev)
3912{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003913 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003914 int pipe;
3915
3916 if (!dev_priv)
3917 return;
3918
Imre Deak843d0e72014-04-14 20:24:23 +03003919 I915_WRITE(VLV_MASTER_IER, 0);
3920
Damien Lespiau055e3932014-08-18 13:49:10 +01003921 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003922 I915_WRITE(PIPESTAT(pipe), 0xffff);
3923
3924 I915_WRITE(HWSTAM, 0xffffffff);
3925 I915_WRITE(PORT_HOTPLUG_EN, 0);
3926 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Imre Deakf8b79e52014-03-04 19:23:07 +02003927
Daniel Vetterd6207432014-09-15 14:55:27 +02003928 /* Interrupt setup is already guaranteed to be single-threaded, this is
3929 * just to make the assert_spin_locked check happy. */
3930 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003931 if (dev_priv->display_irqs_enabled)
3932 valleyview_display_irqs_uninstall(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003933 spin_unlock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003934
3935 dev_priv->irq_mask = 0;
3936
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003937 I915_WRITE(VLV_IIR, 0xffffffff);
3938 I915_WRITE(VLV_IMR, 0xffffffff);
3939 I915_WRITE(VLV_IER, 0x0);
3940 POSTING_READ(VLV_IER);
3941}
3942
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003943static void cherryview_irq_uninstall(struct drm_device *dev)
3944{
3945 struct drm_i915_private *dev_priv = dev->dev_private;
3946 int pipe;
3947
3948 if (!dev_priv)
3949 return;
3950
3951 I915_WRITE(GEN8_MASTER_IRQ, 0);
3952 POSTING_READ(GEN8_MASTER_IRQ);
3953
3954#define GEN8_IRQ_FINI_NDX(type, which) \
3955do { \
3956 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3957 I915_WRITE(GEN8_##type##_IER(which), 0); \
3958 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3959 POSTING_READ(GEN8_##type##_IIR(which)); \
3960 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3961} while (0)
3962
3963#define GEN8_IRQ_FINI(type) \
3964do { \
3965 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3966 I915_WRITE(GEN8_##type##_IER, 0); \
3967 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3968 POSTING_READ(GEN8_##type##_IIR); \
3969 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3970} while (0)
3971
3972 GEN8_IRQ_FINI_NDX(GT, 0);
3973 GEN8_IRQ_FINI_NDX(GT, 1);
3974 GEN8_IRQ_FINI_NDX(GT, 2);
3975 GEN8_IRQ_FINI_NDX(GT, 3);
3976
3977 GEN8_IRQ_FINI(PCU);
3978
3979#undef GEN8_IRQ_FINI
3980#undef GEN8_IRQ_FINI_NDX
3981
3982 I915_WRITE(PORT_HOTPLUG_EN, 0);
3983 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3984
Damien Lespiau055e3932014-08-18 13:49:10 +01003985 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003986 I915_WRITE(PIPESTAT(pipe), 0xffff);
3987
3988 I915_WRITE(VLV_IMR, 0xffffffff);
3989 I915_WRITE(VLV_IER, 0x0);
3990 I915_WRITE(VLV_IIR, 0xffffffff);
3991 POSTING_READ(VLV_IIR);
3992}
3993
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003994static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003995{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003996 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003997
3998 if (!dev_priv)
3999 return;
4000
Paulo Zanonibe30b292014-04-01 15:37:25 -03004001 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004002}
4003
Chris Wilsonc2798b12012-04-22 21:13:57 +01004004static void i8xx_irq_preinstall(struct drm_device * dev)
4005{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004006 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004007 int pipe;
4008
Damien Lespiau055e3932014-08-18 13:49:10 +01004009 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004010 I915_WRITE(PIPESTAT(pipe), 0);
4011 I915_WRITE16(IMR, 0xffff);
4012 I915_WRITE16(IER, 0x0);
4013 POSTING_READ16(IER);
4014}
4015
4016static int i8xx_irq_postinstall(struct drm_device *dev)
4017{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004018 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004019
Chris Wilsonc2798b12012-04-22 21:13:57 +01004020 I915_WRITE16(EMR,
4021 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4022
4023 /* Unmask the interrupts that we always want on. */
4024 dev_priv->irq_mask =
4025 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4026 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4027 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4028 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4029 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4030 I915_WRITE16(IMR, dev_priv->irq_mask);
4031
4032 I915_WRITE16(IER,
4033 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4034 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4035 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4036 I915_USER_INTERRUPT);
4037 POSTING_READ16(IER);
4038
Daniel Vetter379ef822013-10-16 22:55:56 +02004039 /* Interrupt setup is already guaranteed to be single-threaded, this is
4040 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004041 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004042 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4043 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004044 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004045
Chris Wilsonc2798b12012-04-22 21:13:57 +01004046 return 0;
4047}
4048
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004049/*
4050 * Returns true when a page flip has completed.
4051 */
4052static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004053 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004054{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004055 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004056 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004057
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004058 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004059 return false;
4060
4061 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004062 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004063
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004064 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004065
4066 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4067 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4068 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4069 * the flip is completed (no longer pending). Since this doesn't raise
4070 * an interrupt per se, we watch for the change at vblank.
4071 */
4072 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004073 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004074
4075 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004076 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004077
4078check_page_flip:
4079 intel_check_page_flip(dev, pipe);
4080 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004081}
4082
Daniel Vetterff1f5252012-10-02 15:10:55 +02004083static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004084{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004085 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004086 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004087 u16 iir, new_iir;
4088 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01004089 int pipe;
4090 u16 flip_mask =
4091 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4092 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
4093
Chris Wilsonc2798b12012-04-22 21:13:57 +01004094 iir = I915_READ16(IIR);
4095 if (iir == 0)
4096 return IRQ_NONE;
4097
4098 while (iir & ~flip_mask) {
4099 /* Can't rely on pipestat interrupt bit in iir as it might
4100 * have been cleared after the pipestat interrupt was received.
4101 * It doesn't set the bit in iir again, but it still produces
4102 * interrupts (for non-MSI).
4103 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004104 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004105 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004106 i915_handle_error(dev, false,
4107 "Command parser error, iir 0x%08x",
4108 iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004109
Damien Lespiau055e3932014-08-18 13:49:10 +01004110 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004111 int reg = PIPESTAT(pipe);
4112 pipe_stats[pipe] = I915_READ(reg);
4113
4114 /*
4115 * Clear the PIPE*STAT regs before the IIR
4116 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004117 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004118 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004119 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004120 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004121
4122 I915_WRITE16(IIR, iir & ~flip_mask);
4123 new_iir = I915_READ16(IIR); /* Flush posted writes */
4124
Daniel Vetterd05c6172012-04-26 23:28:09 +02004125 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004126
4127 if (iir & I915_USER_INTERRUPT)
4128 notify_ring(dev, &dev_priv->ring[RCS]);
4129
Damien Lespiau055e3932014-08-18 13:49:10 +01004130 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004131 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004132 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004133 plane = !plane;
4134
Daniel Vetter4356d582013-10-16 22:55:55 +02004135 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004136 i8xx_handle_vblank(dev, plane, pipe, iir))
4137 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004138
Daniel Vetter4356d582013-10-16 22:55:55 +02004139 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004140 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004141
4142 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4143 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004144 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02004145 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004146
4147 iir = new_iir;
4148 }
4149
4150 return IRQ_HANDLED;
4151}
4152
4153static void i8xx_irq_uninstall(struct drm_device * dev)
4154{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004155 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004156 int pipe;
4157
Damien Lespiau055e3932014-08-18 13:49:10 +01004158 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004159 /* Clear enable bits; then clear status bits */
4160 I915_WRITE(PIPESTAT(pipe), 0);
4161 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4162 }
4163 I915_WRITE16(IMR, 0xffff);
4164 I915_WRITE16(IER, 0x0);
4165 I915_WRITE16(IIR, I915_READ16(IIR));
4166}
4167
Chris Wilsona266c7d2012-04-24 22:59:44 +01004168static void i915_irq_preinstall(struct drm_device * dev)
4169{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004170 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004171 int pipe;
4172
Chris Wilsona266c7d2012-04-24 22:59:44 +01004173 if (I915_HAS_HOTPLUG(dev)) {
4174 I915_WRITE(PORT_HOTPLUG_EN, 0);
4175 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4176 }
4177
Chris Wilson00d98eb2012-04-24 22:59:48 +01004178 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004179 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180 I915_WRITE(PIPESTAT(pipe), 0);
4181 I915_WRITE(IMR, 0xffffffff);
4182 I915_WRITE(IER, 0x0);
4183 POSTING_READ(IER);
4184}
4185
4186static int i915_irq_postinstall(struct drm_device *dev)
4187{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004188 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01004189 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004190
Chris Wilson38bde182012-04-24 22:59:50 +01004191 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4192
4193 /* Unmask the interrupts that we always want on. */
4194 dev_priv->irq_mask =
4195 ~(I915_ASLE_INTERRUPT |
4196 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4197 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4198 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4199 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4200 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4201
4202 enable_mask =
4203 I915_ASLE_INTERRUPT |
4204 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4205 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4206 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4207 I915_USER_INTERRUPT;
4208
Chris Wilsona266c7d2012-04-24 22:59:44 +01004209 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01004210 I915_WRITE(PORT_HOTPLUG_EN, 0);
4211 POSTING_READ(PORT_HOTPLUG_EN);
4212
Chris Wilsona266c7d2012-04-24 22:59:44 +01004213 /* Enable in IER... */
4214 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4215 /* and unmask in IMR */
4216 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4217 }
4218
Chris Wilsona266c7d2012-04-24 22:59:44 +01004219 I915_WRITE(IMR, dev_priv->irq_mask);
4220 I915_WRITE(IER, enable_mask);
4221 POSTING_READ(IER);
4222
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004223 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004224
Daniel Vetter379ef822013-10-16 22:55:56 +02004225 /* Interrupt setup is already guaranteed to be single-threaded, this is
4226 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004227 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004228 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4229 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004230 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004231
Daniel Vetter20afbda2012-12-11 14:05:07 +01004232 return 0;
4233}
4234
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004235/*
4236 * Returns true when a page flip has completed.
4237 */
4238static bool i915_handle_vblank(struct drm_device *dev,
4239 int plane, int pipe, u32 iir)
4240{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004241 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004242 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4243
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004244 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004245 return false;
4246
4247 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004248 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004249
4250 intel_prepare_page_flip(dev, plane);
4251
4252 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4253 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4254 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4255 * the flip is completed (no longer pending). Since this doesn't raise
4256 * an interrupt per se, we watch for the change at vblank.
4257 */
4258 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004259 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004260
4261 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004262 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004263
4264check_page_flip:
4265 intel_check_page_flip(dev, pipe);
4266 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004267}
4268
Daniel Vetterff1f5252012-10-02 15:10:55 +02004269static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004270{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004271 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004272 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01004273 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004274 u32 flip_mask =
4275 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4276 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004277 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004278
Chris Wilsona266c7d2012-04-24 22:59:44 +01004279 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004280 do {
4281 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004282 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004283
4284 /* Can't rely on pipestat interrupt bit in iir as it might
4285 * have been cleared after the pipestat interrupt was received.
4286 * It doesn't set the bit in iir again, but it still produces
4287 * interrupts (for non-MSI).
4288 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004289 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004290 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004291 i915_handle_error(dev, false,
4292 "Command parser error, iir 0x%08x",
4293 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004294
Damien Lespiau055e3932014-08-18 13:49:10 +01004295 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004296 int reg = PIPESTAT(pipe);
4297 pipe_stats[pipe] = I915_READ(reg);
4298
Chris Wilson38bde182012-04-24 22:59:50 +01004299 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004300 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004301 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004302 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004303 }
4304 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004305 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004306
4307 if (!irq_received)
4308 break;
4309
Chris Wilsona266c7d2012-04-24 22:59:44 +01004310 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004311 if (I915_HAS_HOTPLUG(dev) &&
4312 iir & I915_DISPLAY_PORT_INTERRUPT)
4313 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004314
Chris Wilson38bde182012-04-24 22:59:50 +01004315 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004316 new_iir = I915_READ(IIR); /* Flush posted writes */
4317
Chris Wilsona266c7d2012-04-24 22:59:44 +01004318 if (iir & I915_USER_INTERRUPT)
4319 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004320
Damien Lespiau055e3932014-08-18 13:49:10 +01004321 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01004322 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004323 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01004324 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02004325
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004326 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4327 i915_handle_vblank(dev, plane, pipe, iir))
4328 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004329
4330 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4331 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004332
4333 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004334 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004335
4336 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4337 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004338 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004339 }
4340
Chris Wilsona266c7d2012-04-24 22:59:44 +01004341 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4342 intel_opregion_asle_intr(dev);
4343
4344 /* With MSI, interrupts are only generated when iir
4345 * transitions from zero to nonzero. If another bit got
4346 * set while we were handling the existing iir bits, then
4347 * we would never get another interrupt.
4348 *
4349 * This is fine on non-MSI as well, as if we hit this path
4350 * we avoid exiting the interrupt handler only to generate
4351 * another one.
4352 *
4353 * Note that for MSI this could cause a stray interrupt report
4354 * if an interrupt landed in the time between writing IIR and
4355 * the posting read. This should be rare enough to never
4356 * trigger the 99% of 100,000 interrupts test for disabling
4357 * stray interrupts.
4358 */
Chris Wilson38bde182012-04-24 22:59:50 +01004359 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004360 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004361 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004362
Daniel Vetterd05c6172012-04-26 23:28:09 +02004363 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004364
Chris Wilsona266c7d2012-04-24 22:59:44 +01004365 return ret;
4366}
4367
4368static void i915_irq_uninstall(struct drm_device * dev)
4369{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004370 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004371 int pipe;
4372
Chris Wilsona266c7d2012-04-24 22:59:44 +01004373 if (I915_HAS_HOTPLUG(dev)) {
4374 I915_WRITE(PORT_HOTPLUG_EN, 0);
4375 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4376 }
4377
Chris Wilson00d98eb2012-04-24 22:59:48 +01004378 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004379 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004380 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004381 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004382 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4383 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004384 I915_WRITE(IMR, 0xffffffff);
4385 I915_WRITE(IER, 0x0);
4386
Chris Wilsona266c7d2012-04-24 22:59:44 +01004387 I915_WRITE(IIR, I915_READ(IIR));
4388}
4389
4390static void i965_irq_preinstall(struct drm_device * dev)
4391{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004392 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004393 int pipe;
4394
Chris Wilsonadca4732012-05-11 18:01:31 +01004395 I915_WRITE(PORT_HOTPLUG_EN, 0);
4396 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004397
4398 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004399 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004400 I915_WRITE(PIPESTAT(pipe), 0);
4401 I915_WRITE(IMR, 0xffffffff);
4402 I915_WRITE(IER, 0x0);
4403 POSTING_READ(IER);
4404}
4405
4406static int i965_irq_postinstall(struct drm_device *dev)
4407{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004408 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004409 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004410 u32 error_mask;
4411
Chris Wilsona266c7d2012-04-24 22:59:44 +01004412 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004413 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004414 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004415 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4416 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4417 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4418 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4419 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4420
4421 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004422 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4423 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004424 enable_mask |= I915_USER_INTERRUPT;
4425
4426 if (IS_G4X(dev))
4427 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004428
Daniel Vetterb79480b2013-06-27 17:52:10 +02004429 /* Interrupt setup is already guaranteed to be single-threaded, this is
4430 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004431 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004432 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4433 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4434 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004435 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004436
Chris Wilsona266c7d2012-04-24 22:59:44 +01004437 /*
4438 * Enable some error detection, note the instruction error mask
4439 * bit is reserved, so we leave it masked.
4440 */
4441 if (IS_G4X(dev)) {
4442 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4443 GM45_ERROR_MEM_PRIV |
4444 GM45_ERROR_CP_PRIV |
4445 I915_ERROR_MEMORY_REFRESH);
4446 } else {
4447 error_mask = ~(I915_ERROR_PAGE_TABLE |
4448 I915_ERROR_MEMORY_REFRESH);
4449 }
4450 I915_WRITE(EMR, error_mask);
4451
4452 I915_WRITE(IMR, dev_priv->irq_mask);
4453 I915_WRITE(IER, enable_mask);
4454 POSTING_READ(IER);
4455
Daniel Vetter20afbda2012-12-11 14:05:07 +01004456 I915_WRITE(PORT_HOTPLUG_EN, 0);
4457 POSTING_READ(PORT_HOTPLUG_EN);
4458
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004459 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004460
4461 return 0;
4462}
4463
Egbert Eichbac56d52013-02-25 12:06:51 -05004464static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004465{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004466 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichcd569ae2013-04-16 13:36:57 +02004467 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004468 u32 hotplug_en;
4469
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004470 assert_spin_locked(&dev_priv->irq_lock);
4471
Egbert Eichbac56d52013-02-25 12:06:51 -05004472 if (I915_HAS_HOTPLUG(dev)) {
4473 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4474 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4475 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05004476 /* enable bits are the same for all generations */
Damien Lespiaub2784e12014-08-05 11:29:37 +01004477 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02004478 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4479 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05004480 /* Programming the CRT detection parameters tends
4481 to generate a spurious hotplug event about three
4482 seconds later. So just do it once.
4483 */
4484 if (IS_G4X(dev))
4485 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01004486 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05004487 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004488
Egbert Eichbac56d52013-02-25 12:06:51 -05004489 /* Ignore TV since it's buggy */
4490 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4491 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004492}
4493
Daniel Vetterff1f5252012-10-02 15:10:55 +02004494static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004495{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004496 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004497 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004498 u32 iir, new_iir;
4499 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004500 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004501 u32 flip_mask =
4502 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4503 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004504
Chris Wilsona266c7d2012-04-24 22:59:44 +01004505 iir = I915_READ(IIR);
4506
Chris Wilsona266c7d2012-04-24 22:59:44 +01004507 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004508 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004509 bool blc_event = false;
4510
Chris Wilsona266c7d2012-04-24 22:59:44 +01004511 /* Can't rely on pipestat interrupt bit in iir as it might
4512 * have been cleared after the pipestat interrupt was received.
4513 * It doesn't set the bit in iir again, but it still produces
4514 * interrupts (for non-MSI).
4515 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004516 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004517 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004518 i915_handle_error(dev, false,
4519 "Command parser error, iir 0x%08x",
4520 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004521
Damien Lespiau055e3932014-08-18 13:49:10 +01004522 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004523 int reg = PIPESTAT(pipe);
4524 pipe_stats[pipe] = I915_READ(reg);
4525
4526 /*
4527 * Clear the PIPE*STAT regs before the IIR
4528 */
4529 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004530 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004531 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004532 }
4533 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004534 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004535
4536 if (!irq_received)
4537 break;
4538
4539 ret = IRQ_HANDLED;
4540
4541 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004542 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4543 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004544
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004545 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004546 new_iir = I915_READ(IIR); /* Flush posted writes */
4547
Chris Wilsona266c7d2012-04-24 22:59:44 +01004548 if (iir & I915_USER_INTERRUPT)
4549 notify_ring(dev, &dev_priv->ring[RCS]);
4550 if (iir & I915_BSD_USER_INTERRUPT)
4551 notify_ring(dev, &dev_priv->ring[VCS]);
4552
Damien Lespiau055e3932014-08-18 13:49:10 +01004553 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004554 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004555 i915_handle_vblank(dev, pipe, pipe, iir))
4556 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004557
4558 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4559 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004560
4561 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004562 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004563
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004564 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4565 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004566 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004567 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004568
4569 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4570 intel_opregion_asle_intr(dev);
4571
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004572 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4573 gmbus_irq_handler(dev);
4574
Chris Wilsona266c7d2012-04-24 22:59:44 +01004575 /* With MSI, interrupts are only generated when iir
4576 * transitions from zero to nonzero. If another bit got
4577 * set while we were handling the existing iir bits, then
4578 * we would never get another interrupt.
4579 *
4580 * This is fine on non-MSI as well, as if we hit this path
4581 * we avoid exiting the interrupt handler only to generate
4582 * another one.
4583 *
4584 * Note that for MSI this could cause a stray interrupt report
4585 * if an interrupt landed in the time between writing IIR and
4586 * the posting read. This should be rare enough to never
4587 * trigger the 99% of 100,000 interrupts test for disabling
4588 * stray interrupts.
4589 */
4590 iir = new_iir;
4591 }
4592
Daniel Vetterd05c6172012-04-26 23:28:09 +02004593 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01004594
Chris Wilsona266c7d2012-04-24 22:59:44 +01004595 return ret;
4596}
4597
4598static void i965_irq_uninstall(struct drm_device * dev)
4599{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004600 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004601 int pipe;
4602
4603 if (!dev_priv)
4604 return;
4605
Chris Wilsonadca4732012-05-11 18:01:31 +01004606 I915_WRITE(PORT_HOTPLUG_EN, 0);
4607 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004608
4609 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004610 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004611 I915_WRITE(PIPESTAT(pipe), 0);
4612 I915_WRITE(IMR, 0xffffffff);
4613 I915_WRITE(IER, 0x0);
4614
Damien Lespiau055e3932014-08-18 13:49:10 +01004615 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004616 I915_WRITE(PIPESTAT(pipe),
4617 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4618 I915_WRITE(IIR, I915_READ(IIR));
4619}
4620
Daniel Vetter4cb21832014-09-15 14:55:26 +02004621static void intel_hpd_irq_reenable_work(struct work_struct *work)
Egbert Eichac4c16c2013-04-16 13:36:58 +02004622{
Imre Deak63237512014-08-18 15:37:02 +03004623 struct drm_i915_private *dev_priv =
4624 container_of(work, typeof(*dev_priv),
4625 hotplug_reenable_work.work);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004626 struct drm_device *dev = dev_priv->dev;
4627 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichac4c16c2013-04-16 13:36:58 +02004628 int i;
4629
Imre Deak63237512014-08-18 15:37:02 +03004630 intel_runtime_pm_get(dev_priv);
4631
Daniel Vetter4cb21832014-09-15 14:55:26 +02004632 spin_lock_irq(&dev_priv->irq_lock);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004633 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4634 struct drm_connector *connector;
4635
4636 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4637 continue;
4638
4639 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4640
4641 list_for_each_entry(connector, &mode_config->connector_list, head) {
4642 struct intel_connector *intel_connector = to_intel_connector(connector);
4643
4644 if (intel_connector->encoder->hpd_pin == i) {
4645 if (connector->polled != intel_connector->polled)
4646 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03004647 connector->name);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004648 connector->polled = intel_connector->polled;
4649 if (!connector->polled)
4650 connector->polled = DRM_CONNECTOR_POLL_HPD;
4651 }
4652 }
4653 }
4654 if (dev_priv->display.hpd_irq_setup)
4655 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetter4cb21832014-09-15 14:55:26 +02004656 spin_unlock_irq(&dev_priv->irq_lock);
Imre Deak63237512014-08-18 15:37:02 +03004657
4658 intel_runtime_pm_put(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004659}
4660
Daniel Vetterfca52a52014-09-30 10:56:45 +02004661/**
4662 * intel_irq_init - initializes irq support
4663 * @dev_priv: i915 device instance
4664 *
4665 * This function initializes all the irq support including work items, timers
4666 * and all the vtables. It does not setup the interrupt itself though.
4667 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004668void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004669{
Daniel Vetterb9632912014-09-30 10:56:44 +02004670 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004671
4672 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Dave Airlie13cf5502014-06-18 11:29:35 +10004673 INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004674 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004675 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004676 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004677
Deepak Sa6706b42014-03-15 20:23:22 +05304678 /* Let's track the enabled rps events */
Daniel Vetterb9632912014-09-30 10:56:44 +02004679 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004680 /* WaGsvRC0ResidencyMethod:vlv */
Deepak S31685c22014-07-03 17:33:01 -04004681 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
4682 else
4683 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304684
Daniel Vetter99584db2012-11-14 17:14:04 +01004685 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4686 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004687 (unsigned long) dev);
Imre Deak63237512014-08-18 15:37:02 +03004688 INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work,
Daniel Vetter4cb21832014-09-15 14:55:26 +02004689 intel_hpd_irq_reenable_work);
Daniel Vetter61bac782012-12-01 21:03:21 +01004690
Tomas Janousek97a19a22012-12-08 13:48:13 +01004691 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004692
Daniel Vetterb9632912014-09-30 10:56:44 +02004693 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004694 dev->max_vblank_count = 0;
4695 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004696 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004697 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4698 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004699 } else {
4700 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4701 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004702 }
4703
Ville Syrjälä21da2702014-08-06 14:49:55 +03004704 /*
4705 * Opt out of the vblank disable timer on everything except gen2.
4706 * Gen2 doesn't have a hardware frame counter and so depends on
4707 * vblank interrupts to produce sane vblank seuquence numbers.
4708 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004709 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004710 dev->vblank_disable_immediate = true;
4711
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004712 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004713 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004714 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4715 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004716
Daniel Vetterb9632912014-09-30 10:56:44 +02004717 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004718 dev->driver->irq_handler = cherryview_irq_handler;
4719 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4720 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4721 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4722 dev->driver->enable_vblank = valleyview_enable_vblank;
4723 dev->driver->disable_vblank = valleyview_disable_vblank;
4724 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004725 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004726 dev->driver->irq_handler = valleyview_irq_handler;
4727 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4728 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4729 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4730 dev->driver->enable_vblank = valleyview_enable_vblank;
4731 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004732 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004733 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004734 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004735 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004736 dev->driver->irq_postinstall = gen8_irq_postinstall;
4737 dev->driver->irq_uninstall = gen8_irq_uninstall;
4738 dev->driver->enable_vblank = gen8_enable_vblank;
4739 dev->driver->disable_vblank = gen8_disable_vblank;
4740 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004741 } else if (HAS_PCH_SPLIT(dev)) {
4742 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004743 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004744 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4745 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4746 dev->driver->enable_vblank = ironlake_enable_vblank;
4747 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004748 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004749 } else {
Daniel Vetterb9632912014-09-30 10:56:44 +02004750 if (INTEL_INFO(dev_priv)->gen == 2) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004751 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4752 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4753 dev->driver->irq_handler = i8xx_irq_handler;
4754 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Daniel Vetterb9632912014-09-30 10:56:44 +02004755 } else if (INTEL_INFO(dev_priv)->gen == 3) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004756 dev->driver->irq_preinstall = i915_irq_preinstall;
4757 dev->driver->irq_postinstall = i915_irq_postinstall;
4758 dev->driver->irq_uninstall = i915_irq_uninstall;
4759 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004760 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004761 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004762 dev->driver->irq_preinstall = i965_irq_preinstall;
4763 dev->driver->irq_postinstall = i965_irq_postinstall;
4764 dev->driver->irq_uninstall = i965_irq_uninstall;
4765 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004766 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004767 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004768 dev->driver->enable_vblank = i915_enable_vblank;
4769 dev->driver->disable_vblank = i915_disable_vblank;
4770 }
4771}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004772
Daniel Vetterfca52a52014-09-30 10:56:45 +02004773/**
4774 * intel_hpd_init - initializes and enables hpd support
4775 * @dev_priv: i915 device instance
4776 *
4777 * This function enables the hotplug support. It requires that interrupts have
4778 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
4779 * poll request can run concurrently to other code, so locking rules must be
4780 * obeyed.
4781 *
4782 * This is a separate step from interrupt enabling to simplify the locking rules
4783 * in the driver load and resume code.
4784 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004785void intel_hpd_init(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004786{
Daniel Vetterb9632912014-09-30 10:56:44 +02004787 struct drm_device *dev = dev_priv->dev;
Egbert Eich821450c2013-04-16 13:36:55 +02004788 struct drm_mode_config *mode_config = &dev->mode_config;
4789 struct drm_connector *connector;
4790 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004791
Egbert Eich821450c2013-04-16 13:36:55 +02004792 for (i = 1; i < HPD_NUM_PINS; i++) {
4793 dev_priv->hpd_stats[i].hpd_cnt = 0;
4794 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4795 }
4796 list_for_each_entry(connector, &mode_config->connector_list, head) {
4797 struct intel_connector *intel_connector = to_intel_connector(connector);
4798 connector->polled = intel_connector->polled;
Dave Airlie0e32b392014-05-02 14:02:48 +10004799 if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4800 connector->polled = DRM_CONNECTOR_POLL_HPD;
4801 if (intel_connector->mst_port)
Egbert Eich821450c2013-04-16 13:36:55 +02004802 connector->polled = DRM_CONNECTOR_POLL_HPD;
4803 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004804
4805 /* Interrupt setup is already guaranteed to be single-threaded, this is
4806 * just to make the assert_spin_locked checks happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004807 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004808 if (dev_priv->display.hpd_irq_setup)
4809 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterd6207432014-09-15 14:55:27 +02004810 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004811}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004812
Daniel Vetterfca52a52014-09-30 10:56:45 +02004813/**
4814 * intel_irq_install - enables the hardware interrupt
4815 * @dev_priv: i915 device instance
4816 *
4817 * This function enables the hardware interrupt handling, but leaves the hotplug
4818 * handling still disabled. It is called after intel_irq_init().
4819 *
4820 * In the driver load and resume code we need working interrupts in a few places
4821 * but don't want to deal with the hassle of concurrent probe and hotplug
4822 * workers. Hence the split into this two-stage approach.
4823 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004824int intel_irq_install(struct drm_i915_private *dev_priv)
4825{
4826 /*
4827 * We enable some interrupt sources in our postinstall hooks, so mark
4828 * interrupts as enabled _before_ actually enabling them to avoid
4829 * special cases in our ordering checks.
4830 */
4831 dev_priv->pm.irqs_enabled = true;
4832
4833 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4834}
4835
Daniel Vetterfca52a52014-09-30 10:56:45 +02004836/**
4837 * intel_irq_uninstall - finilizes all irq handling
4838 * @dev_priv: i915 device instance
4839 *
4840 * This stops interrupt and hotplug handling and unregisters and frees all
4841 * resources acquired in the init functions.
4842 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004843void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4844{
4845 drm_irq_uninstall(dev_priv->dev);
4846 intel_hpd_cancel_work(dev_priv);
4847 dev_priv->pm.irqs_enabled = false;
4848}
4849
Daniel Vetterfca52a52014-09-30 10:56:45 +02004850/**
4851 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4852 * @dev_priv: i915 device instance
4853 *
4854 * This function is used to disable interrupts at runtime, both in the runtime
4855 * pm and the system suspend/resume code.
4856 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004857void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004858{
Daniel Vetterb9632912014-09-30 10:56:44 +02004859 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004860 dev_priv->pm.irqs_enabled = false;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004861}
4862
Daniel Vetterfca52a52014-09-30 10:56:45 +02004863/**
4864 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4865 * @dev_priv: i915 device instance
4866 *
4867 * This function is used to enable interrupts at runtime, both in the runtime
4868 * pm and the system suspend/resume code.
4869 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004870void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004871{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004872 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004873 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4874 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004875}