blob: 4847ed58597f7ca53fd87b69188540ae22ac936e [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Egbert Eiche5868a32013-02-28 04:17:12 -050040static const u32 hpd_ibx[] = {
41 [HPD_CRT] = SDE_CRT_HOTPLUG,
42 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
43 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
44 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
45 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
46};
47
48static const u32 hpd_cpt[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010050 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050051 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
54};
55
56static const u32 hpd_mask_i915[] = {
57 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
58 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
59 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
60 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
61 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
62 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
63};
64
Daniel Vetter704cfb82013-12-18 09:08:43 +010065static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050066 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
67 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
68 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
69 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
70 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
71 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
72};
73
Egbert Eiche5868a32013-02-28 04:17:12 -050074static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
75 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
76 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
77 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
78 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
79 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
80 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
81};
82
Paulo Zanoni5c502442014-04-01 15:37:11 -030083/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -030084#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -030085 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
86 POSTING_READ(GEN8_##type##_IMR(which)); \
87 I915_WRITE(GEN8_##type##_IER(which), 0); \
88 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
89 POSTING_READ(GEN8_##type##_IIR(which)); \
90 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
91 POSTING_READ(GEN8_##type##_IIR(which)); \
92} while (0)
93
Paulo Zanonif86f3fb2014-04-01 15:37:14 -030094#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -030095 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -030096 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -030097 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -030098 I915_WRITE(type##IIR, 0xffffffff); \
99 POSTING_READ(type##IIR); \
100 I915_WRITE(type##IIR, 0xffffffff); \
101 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300102} while (0)
103
Paulo Zanoni337ba012014-04-01 15:37:16 -0300104/*
105 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
106 */
107#define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
108 u32 val = I915_READ(reg); \
109 if (val) { \
110 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
111 (reg), val); \
112 I915_WRITE((reg), 0xffffffff); \
113 POSTING_READ(reg); \
114 I915_WRITE((reg), 0xffffffff); \
115 POSTING_READ(reg); \
116 } \
117} while (0)
118
Paulo Zanoni35079892014-04-01 15:37:15 -0300119#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300120 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300121 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
122 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
123 POSTING_READ(GEN8_##type##_IER(which)); \
124} while (0)
125
126#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300127 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300128 I915_WRITE(type##IMR, (imr_val)); \
129 I915_WRITE(type##IER, (ier_val)); \
130 POSTING_READ(type##IER); \
131} while (0)
132
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800133/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +0100134static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300135ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800136{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200137 assert_spin_locked(&dev_priv->irq_lock);
138
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700139 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300140 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300141
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000142 if ((dev_priv->irq_mask & mask) != 0) {
143 dev_priv->irq_mask &= ~mask;
144 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000145 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800146 }
147}
148
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300149static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300150ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800151{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200152 assert_spin_locked(&dev_priv->irq_lock);
153
Paulo Zanoni06ffc772014-07-17 17:43:46 -0300154 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300155 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300156
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000157 if ((dev_priv->irq_mask & mask) != mask) {
158 dev_priv->irq_mask |= mask;
159 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000160 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800161 }
162}
163
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300164/**
165 * ilk_update_gt_irq - update GTIMR
166 * @dev_priv: driver private
167 * @interrupt_mask: mask of interrupt bits to update
168 * @enabled_irq_mask: mask of interrupt bits to enable
169 */
170static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
171 uint32_t interrupt_mask,
172 uint32_t enabled_irq_mask)
173{
174 assert_spin_locked(&dev_priv->irq_lock);
175
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700176 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300177 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300178
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300179 dev_priv->gt_irq_mask &= ~interrupt_mask;
180 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
181 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
182 POSTING_READ(GTIMR);
183}
184
Daniel Vetter480c8032014-07-16 09:49:40 +0200185void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300186{
187 ilk_update_gt_irq(dev_priv, mask, mask);
188}
189
Daniel Vetter480c8032014-07-16 09:49:40 +0200190void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300191{
192 ilk_update_gt_irq(dev_priv, mask, 0);
193}
194
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300195/**
196 * snb_update_pm_irq - update GEN6_PMIMR
197 * @dev_priv: driver private
198 * @interrupt_mask: mask of interrupt bits to update
199 * @enabled_irq_mask: mask of interrupt bits to enable
200 */
201static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
202 uint32_t interrupt_mask,
203 uint32_t enabled_irq_mask)
204{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300205 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300206
207 assert_spin_locked(&dev_priv->irq_lock);
208
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700209 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300210 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300211
Paulo Zanoni605cd252013-08-06 18:57:15 -0300212 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300213 new_val &= ~interrupt_mask;
214 new_val |= (~enabled_irq_mask & interrupt_mask);
215
Paulo Zanoni605cd252013-08-06 18:57:15 -0300216 if (new_val != dev_priv->pm_irq_mask) {
217 dev_priv->pm_irq_mask = new_val;
218 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300219 POSTING_READ(GEN6_PMIMR);
220 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300221}
222
Daniel Vetter480c8032014-07-16 09:49:40 +0200223void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300224{
225 snb_update_pm_irq(dev_priv, mask, mask);
226}
227
Daniel Vetter480c8032014-07-16 09:49:40 +0200228void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300229{
230 snb_update_pm_irq(dev_priv, mask, 0);
231}
232
Paulo Zanoni86642812013-04-12 17:57:57 -0300233static bool ivb_can_enable_err_int(struct drm_device *dev)
234{
235 struct drm_i915_private *dev_priv = dev->dev_private;
236 struct intel_crtc *crtc;
237 enum pipe pipe;
238
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200239 assert_spin_locked(&dev_priv->irq_lock);
240
Damien Lespiau055e3932014-08-18 13:49:10 +0100241 for_each_pipe(dev_priv, pipe) {
Paulo Zanoni86642812013-04-12 17:57:57 -0300242 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
243
244 if (crtc->cpu_fifo_underrun_disabled)
245 return false;
246 }
247
248 return true;
249}
250
Ben Widawsky09610212014-05-15 20:58:08 +0300251/**
252 * bdw_update_pm_irq - update GT interrupt 2
253 * @dev_priv: driver private
254 * @interrupt_mask: mask of interrupt bits to update
255 * @enabled_irq_mask: mask of interrupt bits to enable
256 *
257 * Copied from the snb function, updated with relevant register offsets
258 */
259static void bdw_update_pm_irq(struct drm_i915_private *dev_priv,
260 uint32_t interrupt_mask,
261 uint32_t enabled_irq_mask)
262{
263 uint32_t new_val;
264
265 assert_spin_locked(&dev_priv->irq_lock);
266
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700267 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Ben Widawsky09610212014-05-15 20:58:08 +0300268 return;
269
270 new_val = dev_priv->pm_irq_mask;
271 new_val &= ~interrupt_mask;
272 new_val |= (~enabled_irq_mask & interrupt_mask);
273
274 if (new_val != dev_priv->pm_irq_mask) {
275 dev_priv->pm_irq_mask = new_val;
276 I915_WRITE(GEN8_GT_IMR(2), dev_priv->pm_irq_mask);
277 POSTING_READ(GEN8_GT_IMR(2));
278 }
279}
280
Daniel Vetter480c8032014-07-16 09:49:40 +0200281void gen8_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Ben Widawsky09610212014-05-15 20:58:08 +0300282{
283 bdw_update_pm_irq(dev_priv, mask, mask);
284}
285
Daniel Vetter480c8032014-07-16 09:49:40 +0200286void gen8_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Ben Widawsky09610212014-05-15 20:58:08 +0300287{
288 bdw_update_pm_irq(dev_priv, mask, 0);
289}
290
Paulo Zanoni86642812013-04-12 17:57:57 -0300291static bool cpt_can_enable_serr_int(struct drm_device *dev)
292{
293 struct drm_i915_private *dev_priv = dev->dev_private;
294 enum pipe pipe;
295 struct intel_crtc *crtc;
296
Daniel Vetterfee884e2013-07-04 23:35:21 +0200297 assert_spin_locked(&dev_priv->irq_lock);
298
Damien Lespiau055e3932014-08-18 13:49:10 +0100299 for_each_pipe(dev_priv, pipe) {
Paulo Zanoni86642812013-04-12 17:57:57 -0300300 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
301
302 if (crtc->pch_fifo_underrun_disabled)
303 return false;
304 }
305
306 return true;
307}
308
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300309void i9xx_check_fifo_underruns(struct drm_device *dev)
310{
311 struct drm_i915_private *dev_priv = dev->dev_private;
312 struct intel_crtc *crtc;
313 unsigned long flags;
314
315 spin_lock_irqsave(&dev_priv->irq_lock, flags);
316
317 for_each_intel_crtc(dev, crtc) {
318 u32 reg = PIPESTAT(crtc->pipe);
319 u32 pipestat;
320
321 if (crtc->cpu_fifo_underrun_disabled)
322 continue;
323
324 pipestat = I915_READ(reg) & 0xffff0000;
325 if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
326 continue;
327
328 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
329 POSTING_READ(reg);
330
331 DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
332 }
333
334 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
335}
336
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300337static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200338 enum pipe pipe,
339 bool enable, bool old)
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200340{
341 struct drm_i915_private *dev_priv = dev->dev_private;
342 u32 reg = PIPESTAT(pipe);
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300343 u32 pipestat = I915_READ(reg) & 0xffff0000;
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200344
345 assert_spin_locked(&dev_priv->irq_lock);
346
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300347 if (enable) {
348 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
349 POSTING_READ(reg);
350 } else {
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200351 if (old && pipestat & PIPE_FIFO_UNDERRUN_STATUS)
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300352 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
353 }
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200354}
355
Paulo Zanoni86642812013-04-12 17:57:57 -0300356static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
357 enum pipe pipe, bool enable)
358{
359 struct drm_i915_private *dev_priv = dev->dev_private;
360 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
361 DE_PIPEB_FIFO_UNDERRUN;
362
363 if (enable)
364 ironlake_enable_display_irq(dev_priv, bit);
365 else
366 ironlake_disable_display_irq(dev_priv, bit);
367}
368
369static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200370 enum pipe pipe,
371 bool enable, bool old)
Paulo Zanoni86642812013-04-12 17:57:57 -0300372{
373 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300374 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200375 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
376
Paulo Zanoni86642812013-04-12 17:57:57 -0300377 if (!ivb_can_enable_err_int(dev))
378 return;
379
Paulo Zanoni86642812013-04-12 17:57:57 -0300380 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
381 } else {
382 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200383
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200384 if (old &&
385 I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300386 DRM_ERROR("uncleared fifo underrun on pipe %c\n",
387 pipe_name(pipe));
Daniel Vetter7336df62013-07-09 22:59:16 +0200388 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300389 }
390}
391
Daniel Vetter38d83c962013-11-07 11:05:46 +0100392static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
393 enum pipe pipe, bool enable)
394{
395 struct drm_i915_private *dev_priv = dev->dev_private;
396
397 assert_spin_locked(&dev_priv->irq_lock);
398
399 if (enable)
400 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
401 else
402 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
403 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
404 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
405}
406
Daniel Vetterfee884e2013-07-04 23:35:21 +0200407/**
408 * ibx_display_interrupt_update - update SDEIMR
409 * @dev_priv: driver private
410 * @interrupt_mask: mask of interrupt bits to update
411 * @enabled_irq_mask: mask of interrupt bits to enable
412 */
413static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
414 uint32_t interrupt_mask,
415 uint32_t enabled_irq_mask)
416{
417 uint32_t sdeimr = I915_READ(SDEIMR);
418 sdeimr &= ~interrupt_mask;
419 sdeimr |= (~enabled_irq_mask & interrupt_mask);
420
421 assert_spin_locked(&dev_priv->irq_lock);
422
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700423 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300424 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300425
Daniel Vetterfee884e2013-07-04 23:35:21 +0200426 I915_WRITE(SDEIMR, sdeimr);
427 POSTING_READ(SDEIMR);
428}
429#define ibx_enable_display_interrupt(dev_priv, bits) \
430 ibx_display_interrupt_update((dev_priv), (bits), (bits))
431#define ibx_disable_display_interrupt(dev_priv, bits) \
432 ibx_display_interrupt_update((dev_priv), (bits), 0)
433
Daniel Vetterde280752013-07-04 23:35:24 +0200434static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
435 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300436 bool enable)
437{
Paulo Zanoni86642812013-04-12 17:57:57 -0300438 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200439 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
440 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300441
442 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200443 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300444 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200445 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300446}
447
448static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
449 enum transcoder pch_transcoder,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200450 bool enable, bool old)
Paulo Zanoni86642812013-04-12 17:57:57 -0300451{
452 struct drm_i915_private *dev_priv = dev->dev_private;
453
454 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200455 I915_WRITE(SERR_INT,
456 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
457
Paulo Zanoni86642812013-04-12 17:57:57 -0300458 if (!cpt_can_enable_serr_int(dev))
459 return;
460
Daniel Vetterfee884e2013-07-04 23:35:21 +0200461 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300462 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +0200463 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200464
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200465 if (old && I915_READ(SERR_INT) &
466 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300467 DRM_ERROR("uncleared pch fifo underrun on pch transcoder %c\n",
468 transcoder_name(pch_transcoder));
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200469 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300470 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300471}
472
473/**
474 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
475 * @dev: drm device
476 * @pipe: pipe
477 * @enable: true if we want to report FIFO underrun errors, false otherwise
478 *
479 * This function makes us disable or enable CPU fifo underruns for a specific
480 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
481 * reporting for one pipe may also disable all the other CPU error interruts for
482 * the other pipes, due to the fact that there's just one interrupt mask/enable
483 * bit for all the pipes.
484 *
485 * Returns the previous state of underrun reporting.
486 */
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +0200487static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
488 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300489{
490 struct drm_i915_private *dev_priv = dev->dev_private;
491 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
492 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200493 bool old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300494
Imre Deak77961eb2014-03-05 16:20:56 +0200495 assert_spin_locked(&dev_priv->irq_lock);
496
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200497 old = !intel_crtc->cpu_fifo_underrun_disabled;
Paulo Zanoni86642812013-04-12 17:57:57 -0300498 intel_crtc->cpu_fifo_underrun_disabled = !enable;
499
Ville Syrjäläa3ed6aa2014-09-03 14:09:52 +0300500 if (HAS_GMCH_DISPLAY(dev))
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200501 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200502 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300503 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
504 else if (IS_GEN7(dev))
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200505 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100506 else if (IS_GEN8(dev))
507 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300508
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200509 return old;
Imre Deakf88d42f2014-03-04 19:23:09 +0200510}
511
512bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
513 enum pipe pipe, bool enable)
514{
515 struct drm_i915_private *dev_priv = dev->dev_private;
516 unsigned long flags;
517 bool ret;
518
519 spin_lock_irqsave(&dev_priv->irq_lock, flags);
520 ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300521 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Imre Deakf88d42f2014-03-04 19:23:09 +0200522
Paulo Zanoni86642812013-04-12 17:57:57 -0300523 return ret;
524}
525
Imre Deak91d181d2014-02-10 18:42:49 +0200526static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
527 enum pipe pipe)
528{
529 struct drm_i915_private *dev_priv = dev->dev_private;
530 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
531 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
532
533 return !intel_crtc->cpu_fifo_underrun_disabled;
534}
535
Paulo Zanoni86642812013-04-12 17:57:57 -0300536/**
537 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
538 * @dev: drm device
539 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
540 * @enable: true if we want to report FIFO underrun errors, false otherwise
541 *
542 * This function makes us disable or enable PCH fifo underruns for a specific
543 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
544 * underrun reporting for one transcoder may also disable all the other PCH
545 * error interruts for the other transcoders, due to the fact that there's just
546 * one interrupt mask/enable bit for all the transcoders.
547 *
548 * Returns the previous state of underrun reporting.
549 */
550bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
551 enum transcoder pch_transcoder,
552 bool enable)
553{
554 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200555 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
556 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300557 unsigned long flags;
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200558 bool old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300559
Daniel Vetterde280752013-07-04 23:35:24 +0200560 /*
561 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
562 * has only one pch transcoder A that all pipes can use. To avoid racy
563 * pch transcoder -> pipe lookups from interrupt code simply store the
564 * underrun statistics in crtc A. Since we never expose this anywhere
565 * nor use it outside of the fifo underrun code here using the "wrong"
566 * crtc on LPT won't cause issues.
567 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300568
569 spin_lock_irqsave(&dev_priv->irq_lock, flags);
570
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200571 old = !intel_crtc->pch_fifo_underrun_disabled;
Paulo Zanoni86642812013-04-12 17:57:57 -0300572 intel_crtc->pch_fifo_underrun_disabled = !enable;
573
574 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200575 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300576 else
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200577 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable, old);
Paulo Zanoni86642812013-04-12 17:57:57 -0300578
Paulo Zanoni86642812013-04-12 17:57:57 -0300579 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200580 return old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300581}
582
583
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100584static void
Imre Deak755e9012014-02-10 18:42:47 +0200585__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
586 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800587{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200588 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200589 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800590
Daniel Vetterb79480b2013-06-27 17:52:10 +0200591 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200592 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200593
Ville Syrjälä04feced2014-04-03 13:28:33 +0300594 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
595 status_mask & ~PIPESTAT_INT_STATUS_MASK,
596 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
597 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200598 return;
599
600 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200601 return;
602
Imre Deak91d181d2014-02-10 18:42:49 +0200603 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
604
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200605 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200606 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200607 I915_WRITE(reg, pipestat);
608 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800609}
610
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100611static void
Imre Deak755e9012014-02-10 18:42:47 +0200612__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
613 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800614{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200615 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200616 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800617
Daniel Vetterb79480b2013-06-27 17:52:10 +0200618 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200619 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200620
Ville Syrjälä04feced2014-04-03 13:28:33 +0300621 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
622 status_mask & ~PIPESTAT_INT_STATUS_MASK,
623 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
624 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200625 return;
626
Imre Deak755e9012014-02-10 18:42:47 +0200627 if ((pipestat & enable_mask) == 0)
628 return;
629
Imre Deak91d181d2014-02-10 18:42:49 +0200630 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
631
Imre Deak755e9012014-02-10 18:42:47 +0200632 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200633 I915_WRITE(reg, pipestat);
634 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800635}
636
Imre Deak10c59c52014-02-10 18:42:48 +0200637static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
638{
639 u32 enable_mask = status_mask << 16;
640
641 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300642 * On pipe A we don't support the PSR interrupt yet,
643 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200644 */
645 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
646 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300647 /*
648 * On pipe B and C we don't support the PSR interrupt yet, on pipe
649 * A the same bit is for perf counters which we don't use either.
650 */
651 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
652 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200653
654 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
655 SPRITE0_FLIP_DONE_INT_EN_VLV |
656 SPRITE1_FLIP_DONE_INT_EN_VLV);
657 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
658 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
659 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
660 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
661
662 return enable_mask;
663}
664
Imre Deak755e9012014-02-10 18:42:47 +0200665void
666i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
667 u32 status_mask)
668{
669 u32 enable_mask;
670
Imre Deak10c59c52014-02-10 18:42:48 +0200671 if (IS_VALLEYVIEW(dev_priv->dev))
672 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
673 status_mask);
674 else
675 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200676 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
677}
678
679void
680i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
681 u32 status_mask)
682{
683 u32 enable_mask;
684
Imre Deak10c59c52014-02-10 18:42:48 +0200685 if (IS_VALLEYVIEW(dev_priv->dev))
686 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
687 status_mask);
688 else
689 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200690 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
691}
692
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000693/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300694 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000695 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300696static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000697{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300698 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000699 unsigned long irqflags;
700
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300701 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
702 return;
703
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000704 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000705
Imre Deak755e9012014-02-10 18:42:47 +0200706 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300707 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200708 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200709 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000710
711 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000712}
713
714/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700715 * i915_pipe_enabled - check if a pipe is enabled
716 * @dev: DRM device
717 * @pipe: pipe to check
718 *
719 * Reading certain registers when the pipe is disabled can hang the chip.
720 * Use this routine to make sure the PLL is running and the pipe is active
721 * before reading such registers if unsure.
722 */
723static int
724i915_pipe_enabled(struct drm_device *dev, int pipe)
725{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300726 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200727
Daniel Vettera01025a2013-05-22 00:50:23 +0200728 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
729 /* Locking is horribly broken here, but whatever. */
730 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
731 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300732
Daniel Vettera01025a2013-05-22 00:50:23 +0200733 return intel_crtc->active;
734 } else {
735 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
736 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700737}
738
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300739/*
740 * This timing diagram depicts the video signal in and
741 * around the vertical blanking period.
742 *
743 * Assumptions about the fictitious mode used in this example:
744 * vblank_start >= 3
745 * vsync_start = vblank_start + 1
746 * vsync_end = vblank_start + 2
747 * vtotal = vblank_start + 3
748 *
749 * start of vblank:
750 * latch double buffered registers
751 * increment frame counter (ctg+)
752 * generate start of vblank interrupt (gen4+)
753 * |
754 * | frame start:
755 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
756 * | may be shifted forward 1-3 extra lines via PIPECONF
757 * | |
758 * | | start of vsync:
759 * | | generate vsync interrupt
760 * | | |
761 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
762 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
763 * ----va---> <-----------------vb--------------------> <--------va-------------
764 * | | <----vs-----> |
765 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
766 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
767 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
768 * | | |
769 * last visible pixel first visible pixel
770 * | increment frame counter (gen3/4)
771 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
772 *
773 * x = horizontal active
774 * _ = horizontal blanking
775 * hs = horizontal sync
776 * va = vertical active
777 * vb = vertical blanking
778 * vs = vertical sync
779 * vbs = vblank_start (number)
780 *
781 * Summary:
782 * - most events happen at the start of horizontal sync
783 * - frame start happens at the start of horizontal blank, 1-4 lines
784 * (depending on PIPECONF settings) after the start of vblank
785 * - gen3/4 pixel and frame counter are synchronized with the start
786 * of horizontal active on the first line of vertical active
787 */
788
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300789static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
790{
791 /* Gen2 doesn't have a hardware frame counter */
792 return 0;
793}
794
Keith Packard42f52ef2008-10-18 19:39:29 -0700795/* Called from drm generic code, passed a 'crtc', which
796 * we use as a pipe index
797 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700798static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700799{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300800 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700801 unsigned long high_frame;
802 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300803 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700804
805 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800806 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800807 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700808 return 0;
809 }
810
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300811 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
812 struct intel_crtc *intel_crtc =
813 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
814 const struct drm_display_mode *mode =
815 &intel_crtc->config.adjusted_mode;
816
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300817 htotal = mode->crtc_htotal;
818 hsync_start = mode->crtc_hsync_start;
819 vbl_start = mode->crtc_vblank_start;
820 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
821 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300822 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100823 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300824
825 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300826 hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300827 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300828 if ((I915_READ(PIPECONF(cpu_transcoder)) &
829 PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE)
830 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300831 }
832
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300833 /* Convert to pixel count */
834 vbl_start *= htotal;
835
836 /* Start of vblank event occurs at start of hsync */
837 vbl_start -= htotal - hsync_start;
838
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800839 high_frame = PIPEFRAME(pipe);
840 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100841
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700842 /*
843 * High & low register fields aren't synchronized, so make sure
844 * we get a low value that's stable across two reads of the high
845 * register.
846 */
847 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100848 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300849 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100850 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700851 } while (high1 != high2);
852
Chris Wilson5eddb702010-09-11 13:48:45 +0100853 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300854 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100855 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300856
857 /*
858 * The frame counter increments at beginning of active.
859 * Cook up a vblank counter by also checking the pixel
860 * counter against vblank start.
861 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200862 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700863}
864
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700865static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800866{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300867 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800868 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800869
870 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800871 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800872 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800873 return 0;
874 }
875
876 return I915_READ(reg);
877}
878
Mario Kleinerad3543e2013-10-30 05:13:08 +0100879/* raw reads, only for fast reads of display block, no need for forcewake etc. */
880#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100881
Ville Syrjäläa225f072014-04-29 13:35:45 +0300882static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
883{
884 struct drm_device *dev = crtc->base.dev;
885 struct drm_i915_private *dev_priv = dev->dev_private;
886 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
887 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300888 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300889
Ville Syrjälä80715b22014-05-15 20:23:23 +0300890 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300891 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
892 vtotal /= 2;
893
894 if (IS_GEN2(dev))
895 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
896 else
897 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
898
899 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300900 * See update_scanline_offset() for the details on the
901 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300902 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300903 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300904}
905
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700906static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200907 unsigned int flags, int *vpos, int *hpos,
908 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100909{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300910 struct drm_i915_private *dev_priv = dev->dev_private;
911 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
912 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
913 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300914 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300915 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100916 bool in_vbl = true;
917 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100918 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100919
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300920 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100921 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800922 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100923 return 0;
924 }
925
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300926 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300927 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300928 vtotal = mode->crtc_vtotal;
929 vbl_start = mode->crtc_vblank_start;
930 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100931
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200932 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
933 vbl_start = DIV_ROUND_UP(vbl_start, 2);
934 vbl_end /= 2;
935 vtotal /= 2;
936 }
937
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300938 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
939
Mario Kleinerad3543e2013-10-30 05:13:08 +0100940 /*
941 * Lock uncore.lock, as we will do multiple timing critical raw
942 * register reads, potentially with preemption disabled, so the
943 * following code must not block on uncore.lock.
944 */
945 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300946
Mario Kleinerad3543e2013-10-30 05:13:08 +0100947 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
948
949 /* Get optional system timestamp before query. */
950 if (stime)
951 *stime = ktime_get();
952
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300953 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100954 /* No obvious pixelcount register. Only query vertical
955 * scanout position from Display scan line register.
956 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300957 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100958 } else {
959 /* Have access to pixelcount since start of frame.
960 * We can split this into vertical and horizontal
961 * scanout position.
962 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100963 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100964
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300965 /* convert to pixel counts */
966 vbl_start *= htotal;
967 vbl_end *= htotal;
968 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300969
970 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300971 * In interlaced modes, the pixel counter counts all pixels,
972 * so one field will have htotal more pixels. In order to avoid
973 * the reported position from jumping backwards when the pixel
974 * counter is beyond the length of the shorter field, just
975 * clamp the position the length of the shorter field. This
976 * matches how the scanline counter based position works since
977 * the scanline counter doesn't count the two half lines.
978 */
979 if (position >= vtotal)
980 position = vtotal - 1;
981
982 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300983 * Start of vblank interrupt is triggered at start of hsync,
984 * just prior to the first active line of vblank. However we
985 * consider lines to start at the leading edge of horizontal
986 * active. So, should we get here before we've crossed into
987 * the horizontal active of the first line in vblank, we would
988 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
989 * always add htotal-hsync_start to the current pixel position.
990 */
991 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300992 }
993
Mario Kleinerad3543e2013-10-30 05:13:08 +0100994 /* Get optional system timestamp after query. */
995 if (etime)
996 *etime = ktime_get();
997
998 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
999
1000 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1001
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001002 in_vbl = position >= vbl_start && position < vbl_end;
1003
1004 /*
1005 * While in vblank, position will be negative
1006 * counting up towards 0 at vbl_end. And outside
1007 * vblank, position will be positive counting
1008 * up since vbl_end.
1009 */
1010 if (position >= vbl_start)
1011 position -= vbl_end;
1012 else
1013 position += vtotal - vbl_end;
1014
Ville Syrjälä7c06b082013-10-11 21:52:43 +03001015 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001016 *vpos = position;
1017 *hpos = 0;
1018 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001019 *vpos = position / htotal;
1020 *hpos = position - (*vpos * htotal);
1021 }
1022
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001023 /* In vblank? */
1024 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +02001025 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001026
1027 return ret;
1028}
1029
Ville Syrjäläa225f072014-04-29 13:35:45 +03001030int intel_get_crtc_scanline(struct intel_crtc *crtc)
1031{
1032 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
1033 unsigned long irqflags;
1034 int position;
1035
1036 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1037 position = __intel_get_crtc_scanline(crtc);
1038 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1039
1040 return position;
1041}
1042
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001043static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001044 int *max_error,
1045 struct timeval *vblank_time,
1046 unsigned flags)
1047{
Chris Wilson4041b852011-01-22 10:07:56 +00001048 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001049
Ben Widawsky7eb552a2013-03-13 14:05:41 -07001050 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +00001051 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001052 return -EINVAL;
1053 }
1054
1055 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +00001056 crtc = intel_get_crtc_for_pipe(dev, pipe);
1057 if (crtc == NULL) {
1058 DRM_ERROR("Invalid crtc %d\n", pipe);
1059 return -EINVAL;
1060 }
1061
1062 if (!crtc->enabled) {
1063 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
1064 return -EBUSY;
1065 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001066
1067 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +00001068 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
1069 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +03001070 crtc,
1071 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001072}
1073
Jani Nikula67c347f2013-09-17 14:26:34 +03001074static bool intel_hpd_irq_event(struct drm_device *dev,
1075 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +02001076{
1077 enum drm_connector_status old_status;
1078
1079 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1080 old_status = connector->status;
1081
1082 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +03001083 if (old_status == connector->status)
1084 return false;
1085
1086 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +02001087 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03001088 connector->name,
Jani Nikula67c347f2013-09-17 14:26:34 +03001089 drm_get_connector_status_name(old_status),
1090 drm_get_connector_status_name(connector->status));
1091
1092 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +02001093}
1094
Dave Airlie13cf5502014-06-18 11:29:35 +10001095static void i915_digport_work_func(struct work_struct *work)
1096{
1097 struct drm_i915_private *dev_priv =
1098 container_of(work, struct drm_i915_private, dig_port_work);
1099 unsigned long irqflags;
1100 u32 long_port_mask, short_port_mask;
1101 struct intel_digital_port *intel_dig_port;
1102 int i, ret;
1103 u32 old_bits = 0;
1104
1105 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1106 long_port_mask = dev_priv->long_hpd_port_mask;
1107 dev_priv->long_hpd_port_mask = 0;
1108 short_port_mask = dev_priv->short_hpd_port_mask;
1109 dev_priv->short_hpd_port_mask = 0;
1110 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1111
1112 for (i = 0; i < I915_MAX_PORTS; i++) {
1113 bool valid = false;
1114 bool long_hpd = false;
1115 intel_dig_port = dev_priv->hpd_irq_port[i];
1116 if (!intel_dig_port || !intel_dig_port->hpd_pulse)
1117 continue;
1118
1119 if (long_port_mask & (1 << i)) {
1120 valid = true;
1121 long_hpd = true;
1122 } else if (short_port_mask & (1 << i))
1123 valid = true;
1124
1125 if (valid) {
1126 ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
1127 if (ret == true) {
1128 /* if we get true fallback to old school hpd */
1129 old_bits |= (1 << intel_dig_port->base.hpd_pin);
1130 }
1131 }
1132 }
1133
1134 if (old_bits) {
1135 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1136 dev_priv->hpd_event_bits |= old_bits;
1137 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1138 schedule_work(&dev_priv->hotplug_work);
1139 }
1140}
1141
Jesse Barnes5ca58282009-03-31 14:11:15 -07001142/*
1143 * Handle hotplug events outside the interrupt handler proper.
1144 */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001145#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
1146
Jesse Barnes5ca58282009-03-31 14:11:15 -07001147static void i915_hotplug_work_func(struct work_struct *work)
1148{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001149 struct drm_i915_private *dev_priv =
1150 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001151 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -07001152 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001153 struct intel_connector *intel_connector;
1154 struct intel_encoder *intel_encoder;
1155 struct drm_connector *connector;
1156 unsigned long irqflags;
1157 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +02001158 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +02001159 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001160
Keith Packarda65e34c2011-07-25 10:04:56 -07001161 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -08001162 DRM_DEBUG_KMS("running encoder hotplug functions\n");
1163
Egbert Eichcd569ae2013-04-16 13:36:57 +02001164 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +02001165
1166 hpd_event_bits = dev_priv->hpd_event_bits;
1167 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001168 list_for_each_entry(connector, &mode_config->connector_list, head) {
1169 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10001170 if (!intel_connector->encoder)
1171 continue;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001172 intel_encoder = intel_connector->encoder;
1173 if (intel_encoder->hpd_pin > HPD_NONE &&
1174 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
1175 connector->polled == DRM_CONNECTOR_POLL_HPD) {
1176 DRM_INFO("HPD interrupt storm detected on connector %s: "
1177 "switching from hotplug detection to polling\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001178 connector->name);
Egbert Eichcd569ae2013-04-16 13:36:57 +02001179 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1180 connector->polled = DRM_CONNECTOR_POLL_CONNECT
1181 | DRM_CONNECTOR_POLL_DISCONNECT;
1182 hpd_disabled = true;
1183 }
Egbert Eich142e2392013-04-11 15:57:57 +02001184 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1185 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001186 connector->name, intel_encoder->hpd_pin);
Egbert Eich142e2392013-04-11 15:57:57 +02001187 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001188 }
1189 /* if there were no outputs to poll, poll was disabled,
1190 * therefore make sure it's enabled when disabling HPD on
1191 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001192 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +02001193 drm_kms_helper_poll_enable(dev);
Imre Deak63237512014-08-18 15:37:02 +03001194 mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work,
1195 msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
Egbert Eichac4c16c2013-04-16 13:36:58 +02001196 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001197
1198 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1199
Egbert Eich321a1b32013-04-11 16:00:26 +02001200 list_for_each_entry(connector, &mode_config->connector_list, head) {
1201 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10001202 if (!intel_connector->encoder)
1203 continue;
Egbert Eich321a1b32013-04-11 16:00:26 +02001204 intel_encoder = intel_connector->encoder;
1205 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1206 if (intel_encoder->hot_plug)
1207 intel_encoder->hot_plug(intel_encoder);
1208 if (intel_hpd_irq_event(dev, connector))
1209 changed = true;
1210 }
1211 }
Keith Packard40ee3382011-07-28 15:31:19 -07001212 mutex_unlock(&mode_config->mutex);
1213
Egbert Eich321a1b32013-04-11 16:00:26 +02001214 if (changed)
1215 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001216}
1217
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001218static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001219{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001220 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001221 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001222 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001223
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001224 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001225
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001226 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1227
Daniel Vetter20e4d402012-08-08 23:35:39 +02001228 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001229
Jesse Barnes7648fa92010-05-20 14:28:11 -07001230 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001231 busy_up = I915_READ(RCPREVBSYTUPAVG);
1232 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001233 max_avg = I915_READ(RCBMAXAVG);
1234 min_avg = I915_READ(RCBMINAVG);
1235
1236 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001237 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001238 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1239 new_delay = dev_priv->ips.cur_delay - 1;
1240 if (new_delay < dev_priv->ips.max_delay)
1241 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001242 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001243 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1244 new_delay = dev_priv->ips.cur_delay + 1;
1245 if (new_delay > dev_priv->ips.min_delay)
1246 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001247 }
1248
Jesse Barnes7648fa92010-05-20 14:28:11 -07001249 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001250 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001251
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001252 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001253
Jesse Barnesf97108d2010-01-29 11:27:07 -08001254 return;
1255}
1256
Chris Wilson549f7362010-10-19 11:19:32 +01001257static void notify_ring(struct drm_device *dev,
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001258 struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +01001259{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +01001260 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +00001261 return;
1262
Chris Wilson814e9b52013-09-23 17:33:19 -03001263 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001264
Sourab Gupta84c33a62014-06-02 16:47:17 +05301265 if (drm_core_check_feature(dev, DRIVER_MODESET))
1266 intel_notify_mmio_flip(ring);
1267
Chris Wilson549f7362010-10-19 11:19:32 +01001268 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001269 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001270}
1271
Deepak S31685c22014-07-03 17:33:01 -04001272static u32 vlv_c0_residency(struct drm_i915_private *dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001273 struct intel_rps_ei *rps_ei)
Deepak S31685c22014-07-03 17:33:01 -04001274{
1275 u32 cz_ts, cz_freq_khz;
1276 u32 render_count, media_count;
1277 u32 elapsed_render, elapsed_media, elapsed_time;
1278 u32 residency = 0;
1279
1280 cz_ts = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
1281 cz_freq_khz = DIV_ROUND_CLOSEST(dev_priv->mem_freq * 1000, 4);
1282
1283 render_count = I915_READ(VLV_RENDER_C0_COUNT_REG);
1284 media_count = I915_READ(VLV_MEDIA_C0_COUNT_REG);
1285
Chris Wilsonbf225f22014-07-10 20:31:18 +01001286 if (rps_ei->cz_clock == 0) {
1287 rps_ei->cz_clock = cz_ts;
1288 rps_ei->render_c0 = render_count;
1289 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001290
1291 return dev_priv->rps.cur_freq;
1292 }
1293
Chris Wilsonbf225f22014-07-10 20:31:18 +01001294 elapsed_time = cz_ts - rps_ei->cz_clock;
1295 rps_ei->cz_clock = cz_ts;
Deepak S31685c22014-07-03 17:33:01 -04001296
Chris Wilsonbf225f22014-07-10 20:31:18 +01001297 elapsed_render = render_count - rps_ei->render_c0;
1298 rps_ei->render_c0 = render_count;
Deepak S31685c22014-07-03 17:33:01 -04001299
Chris Wilsonbf225f22014-07-10 20:31:18 +01001300 elapsed_media = media_count - rps_ei->media_c0;
1301 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001302
1303 /* Convert all the counters into common unit of milli sec */
1304 elapsed_time /= VLV_CZ_CLOCK_TO_MILLI_SEC;
1305 elapsed_render /= cz_freq_khz;
1306 elapsed_media /= cz_freq_khz;
1307
1308 /*
1309 * Calculate overall C0 residency percentage
1310 * only if elapsed time is non zero
1311 */
1312 if (elapsed_time) {
1313 residency =
1314 ((max(elapsed_render, elapsed_media) * 100)
1315 / elapsed_time);
1316 }
1317
1318 return residency;
1319}
1320
1321/**
1322 * vlv_calc_delay_from_C0_counters - Increase/Decrease freq based on GPU
1323 * busy-ness calculated from C0 counters of render & media power wells
1324 * @dev_priv: DRM device private
1325 *
1326 */
Damien Lespiau4fa79042014-08-08 19:25:57 +01001327static int vlv_calc_delay_from_C0_counters(struct drm_i915_private *dev_priv)
Deepak S31685c22014-07-03 17:33:01 -04001328{
1329 u32 residency_C0_up = 0, residency_C0_down = 0;
Damien Lespiau4fa79042014-08-08 19:25:57 +01001330 int new_delay, adj;
Deepak S31685c22014-07-03 17:33:01 -04001331
1332 dev_priv->rps.ei_interrupt_count++;
1333
1334 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
1335
1336
Chris Wilsonbf225f22014-07-10 20:31:18 +01001337 if (dev_priv->rps.up_ei.cz_clock == 0) {
1338 vlv_c0_residency(dev_priv, &dev_priv->rps.up_ei);
1339 vlv_c0_residency(dev_priv, &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001340 return dev_priv->rps.cur_freq;
1341 }
1342
1343
1344 /*
1345 * To down throttle, C0 residency should be less than down threshold
1346 * for continous EI intervals. So calculate down EI counters
1347 * once in VLV_INT_COUNT_FOR_DOWN_EI
1348 */
1349 if (dev_priv->rps.ei_interrupt_count == VLV_INT_COUNT_FOR_DOWN_EI) {
1350
1351 dev_priv->rps.ei_interrupt_count = 0;
1352
1353 residency_C0_down = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001354 &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001355 } else {
1356 residency_C0_up = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001357 &dev_priv->rps.up_ei);
Deepak S31685c22014-07-03 17:33:01 -04001358 }
1359
1360 new_delay = dev_priv->rps.cur_freq;
1361
1362 adj = dev_priv->rps.last_adj;
1363 /* C0 residency is greater than UP threshold. Increase Frequency */
1364 if (residency_C0_up >= VLV_RP_UP_EI_THRESHOLD) {
1365 if (adj > 0)
1366 adj *= 2;
1367 else
1368 adj = 1;
1369
1370 if (dev_priv->rps.cur_freq < dev_priv->rps.max_freq_softlimit)
1371 new_delay = dev_priv->rps.cur_freq + adj;
1372
1373 /*
1374 * For better performance, jump directly
1375 * to RPe if we're below it.
1376 */
1377 if (new_delay < dev_priv->rps.efficient_freq)
1378 new_delay = dev_priv->rps.efficient_freq;
1379
1380 } else if (!dev_priv->rps.ei_interrupt_count &&
1381 (residency_C0_down < VLV_RP_DOWN_EI_THRESHOLD)) {
1382 if (adj < 0)
1383 adj *= 2;
1384 else
1385 adj = -1;
1386 /*
1387 * This means, C0 residency is less than down threshold over
1388 * a period of VLV_INT_COUNT_FOR_DOWN_EI. So, reduce the freq
1389 */
1390 if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
1391 new_delay = dev_priv->rps.cur_freq + adj;
1392 }
1393
1394 return new_delay;
1395}
1396
Ben Widawsky4912d042011-04-25 11:25:20 -07001397static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001398{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001399 struct drm_i915_private *dev_priv =
1400 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001401 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001402 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001403
Daniel Vetter59cdb632013-07-04 23:35:28 +02001404 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001405 pm_iir = dev_priv->rps.pm_iir;
1406 dev_priv->rps.pm_iir = 0;
Damien Lespiau6af257c2014-07-15 09:17:41 +02001407 if (INTEL_INFO(dev_priv->dev)->gen >= 8)
Daniel Vetter480c8032014-07-16 09:49:40 +02001408 gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001409 else {
1410 /* Make sure not to corrupt PMIMR state used by ringbuffer */
Daniel Vetter480c8032014-07-16 09:49:40 +02001411 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001412 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001413 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001414
Paulo Zanoni60611c12013-08-15 11:50:01 -03001415 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301416 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001417
Deepak Sa6706b42014-03-15 20:23:22 +05301418 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001419 return;
1420
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001421 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001422
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001423 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001424 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001425 if (adj > 0)
1426 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301427 else {
1428 /* CHV needs even encode values */
1429 adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1;
1430 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001431 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001432
1433 /*
1434 * For better performance, jump directly
1435 * to RPe if we're below it.
1436 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001437 if (new_delay < dev_priv->rps.efficient_freq)
1438 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001439 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001440 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1441 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001442 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001443 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001444 adj = 0;
Deepak S31685c22014-07-03 17:33:01 -04001445 } else if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1446 new_delay = vlv_calc_delay_from_C0_counters(dev_priv);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001447 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1448 if (adj < 0)
1449 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301450 else {
1451 /* CHV needs even encode values */
1452 adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1;
1453 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001454 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001455 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001456 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001457 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001458
Ben Widawsky79249632012-09-07 19:43:42 -07001459 /* sysfs frequency interfaces may have snuck in while servicing the
1460 * interrupt
1461 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001462 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001463 dev_priv->rps.min_freq_softlimit,
1464 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301465
Ben Widawskyb39fb292014-03-19 18:31:11 -07001466 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001467
1468 if (IS_VALLEYVIEW(dev_priv->dev))
1469 valleyview_set_rps(dev_priv->dev, new_delay);
1470 else
1471 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001472
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001473 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001474}
1475
Ben Widawskye3689192012-05-25 16:56:22 -07001476
1477/**
1478 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1479 * occurred.
1480 * @work: workqueue struct
1481 *
1482 * Doesn't actually do anything except notify userspace. As a consequence of
1483 * this event, userspace should try to remap the bad rows since statistically
1484 * it is likely the same row is more likely to go bad again.
1485 */
1486static void ivybridge_parity_work(struct work_struct *work)
1487{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001488 struct drm_i915_private *dev_priv =
1489 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001490 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001491 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001492 uint32_t misccpctl;
1493 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001494 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001495
1496 /* We must turn off DOP level clock gating to access the L3 registers.
1497 * In order to prevent a get/put style interface, acquire struct mutex
1498 * any time we access those registers.
1499 */
1500 mutex_lock(&dev_priv->dev->struct_mutex);
1501
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001502 /* If we've screwed up tracking, just let the interrupt fire again */
1503 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1504 goto out;
1505
Ben Widawskye3689192012-05-25 16:56:22 -07001506 misccpctl = I915_READ(GEN7_MISCCPCTL);
1507 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1508 POSTING_READ(GEN7_MISCCPCTL);
1509
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001510 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1511 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001512
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001513 slice--;
1514 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1515 break;
1516
1517 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1518
1519 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1520
1521 error_status = I915_READ(reg);
1522 row = GEN7_PARITY_ERROR_ROW(error_status);
1523 bank = GEN7_PARITY_ERROR_BANK(error_status);
1524 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1525
1526 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1527 POSTING_READ(reg);
1528
1529 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1530 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1531 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1532 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1533 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1534 parity_event[5] = NULL;
1535
Dave Airlie5bdebb12013-10-11 14:07:25 +10001536 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001537 KOBJ_CHANGE, parity_event);
1538
1539 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1540 slice, row, bank, subbank);
1541
1542 kfree(parity_event[4]);
1543 kfree(parity_event[3]);
1544 kfree(parity_event[2]);
1545 kfree(parity_event[1]);
1546 }
Ben Widawskye3689192012-05-25 16:56:22 -07001547
1548 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1549
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001550out:
1551 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001552 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Daniel Vetter480c8032014-07-16 09:49:40 +02001553 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001554 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1555
1556 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001557}
1558
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001559static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001560{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001561 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001562
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001563 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001564 return;
1565
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001566 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001567 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001568 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001569
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001570 iir &= GT_PARITY_ERROR(dev);
1571 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1572 dev_priv->l3_parity.which_slice |= 1 << 1;
1573
1574 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1575 dev_priv->l3_parity.which_slice |= 1 << 0;
1576
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001577 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001578}
1579
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001580static void ilk_gt_irq_handler(struct drm_device *dev,
1581 struct drm_i915_private *dev_priv,
1582 u32 gt_iir)
1583{
1584 if (gt_iir &
1585 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1586 notify_ring(dev, &dev_priv->ring[RCS]);
1587 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1588 notify_ring(dev, &dev_priv->ring[VCS]);
1589}
1590
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001591static void snb_gt_irq_handler(struct drm_device *dev,
1592 struct drm_i915_private *dev_priv,
1593 u32 gt_iir)
1594{
1595
Ben Widawskycc609d52013-05-28 19:22:29 -07001596 if (gt_iir &
1597 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001598 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001599 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001600 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001601 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001602 notify_ring(dev, &dev_priv->ring[BCS]);
1603
Ben Widawskycc609d52013-05-28 19:22:29 -07001604 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1605 GT_BSD_CS_ERROR_INTERRUPT |
1606 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001607 i915_handle_error(dev, false, "GT error interrupt 0x%08x",
1608 gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001609 }
Ben Widawskye3689192012-05-25 16:56:22 -07001610
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001611 if (gt_iir & GT_PARITY_ERROR(dev))
1612 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001613}
1614
Ben Widawsky09610212014-05-15 20:58:08 +03001615static void gen8_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1616{
1617 if ((pm_iir & dev_priv->pm_rps_events) == 0)
1618 return;
1619
1620 spin_lock(&dev_priv->irq_lock);
1621 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Daniel Vetter480c8032014-07-16 09:49:40 +02001622 gen8_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001623 spin_unlock(&dev_priv->irq_lock);
1624
1625 queue_work(dev_priv->wq, &dev_priv->rps.work);
1626}
1627
Ben Widawskyabd58f02013-11-02 21:07:09 -07001628static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1629 struct drm_i915_private *dev_priv,
1630 u32 master_ctl)
1631{
Thomas Daniele981e7b2014-07-24 17:04:39 +01001632 struct intel_engine_cs *ring;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001633 u32 rcs, bcs, vcs;
1634 uint32_t tmp = 0;
1635 irqreturn_t ret = IRQ_NONE;
1636
1637 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1638 tmp = I915_READ(GEN8_GT_IIR(0));
1639 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001640 I915_WRITE(GEN8_GT_IIR(0), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001641 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001642
Ben Widawskyabd58f02013-11-02 21:07:09 -07001643 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001644 ring = &dev_priv->ring[RCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001645 if (rcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001646 notify_ring(dev, ring);
1647 if (rcs & GT_CONTEXT_SWITCH_INTERRUPT)
1648 intel_execlists_handle_ctx_events(ring);
1649
1650 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1651 ring = &dev_priv->ring[BCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001652 if (bcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001653 notify_ring(dev, ring);
1654 if (bcs & GT_CONTEXT_SWITCH_INTERRUPT)
1655 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001656 } else
1657 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1658 }
1659
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001660 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07001661 tmp = I915_READ(GEN8_GT_IIR(1));
1662 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001663 I915_WRITE(GEN8_GT_IIR(1), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001664 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001665
Ben Widawskyabd58f02013-11-02 21:07:09 -07001666 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001667 ring = &dev_priv->ring[VCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001668 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001669 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001670 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001671 intel_execlists_handle_ctx_events(ring);
1672
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001673 vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001674 ring = &dev_priv->ring[VCS2];
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001675 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001676 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001677 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001678 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001679 } else
1680 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1681 }
1682
Ben Widawsky09610212014-05-15 20:58:08 +03001683 if (master_ctl & GEN8_GT_PM_IRQ) {
1684 tmp = I915_READ(GEN8_GT_IIR(2));
1685 if (tmp & dev_priv->pm_rps_events) {
Ben Widawsky09610212014-05-15 20:58:08 +03001686 I915_WRITE(GEN8_GT_IIR(2),
1687 tmp & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001688 ret = IRQ_HANDLED;
1689 gen8_rps_irq_handler(dev_priv, tmp);
Ben Widawsky09610212014-05-15 20:58:08 +03001690 } else
1691 DRM_ERROR("The master control interrupt lied (PM)!\n");
1692 }
1693
Ben Widawskyabd58f02013-11-02 21:07:09 -07001694 if (master_ctl & GEN8_GT_VECS_IRQ) {
1695 tmp = I915_READ(GEN8_GT_IIR(3));
1696 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001697 I915_WRITE(GEN8_GT_IIR(3), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001698 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001699
Ben Widawskyabd58f02013-11-02 21:07:09 -07001700 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001701 ring = &dev_priv->ring[VECS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001702 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001703 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001704 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001705 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001706 } else
1707 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1708 }
1709
1710 return ret;
1711}
1712
Egbert Eichb543fb02013-04-16 13:36:54 +02001713#define HPD_STORM_DETECT_PERIOD 1000
1714#define HPD_STORM_THRESHOLD 5
1715
Dave Airlie13cf5502014-06-18 11:29:35 +10001716static int ilk_port_to_hotplug_shift(enum port port)
1717{
1718 switch (port) {
1719 case PORT_A:
1720 case PORT_E:
1721 default:
1722 return -1;
1723 case PORT_B:
1724 return 0;
1725 case PORT_C:
1726 return 8;
1727 case PORT_D:
1728 return 16;
1729 }
1730}
1731
1732static int g4x_port_to_hotplug_shift(enum port port)
1733{
1734 switch (port) {
1735 case PORT_A:
1736 case PORT_E:
1737 default:
1738 return -1;
1739 case PORT_B:
1740 return 17;
1741 case PORT_C:
1742 return 19;
1743 case PORT_D:
1744 return 21;
1745 }
1746}
1747
1748static inline enum port get_port_from_pin(enum hpd_pin pin)
1749{
1750 switch (pin) {
1751 case HPD_PORT_B:
1752 return PORT_B;
1753 case HPD_PORT_C:
1754 return PORT_C;
1755 case HPD_PORT_D:
1756 return PORT_D;
1757 default:
1758 return PORT_A; /* no hpd */
1759 }
1760}
1761
Daniel Vetter10a504d2013-06-27 17:52:12 +02001762static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001763 u32 hotplug_trigger,
Dave Airlie13cf5502014-06-18 11:29:35 +10001764 u32 dig_hotplug_reg,
Daniel Vetter22062db2013-06-27 17:52:11 +02001765 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001766{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001767 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001768 int i;
Dave Airlie13cf5502014-06-18 11:29:35 +10001769 enum port port;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001770 bool storm_detected = false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001771 bool queue_dig = false, queue_hp = false;
1772 u32 dig_shift;
1773 u32 dig_port_mask = 0;
Egbert Eichb543fb02013-04-16 13:36:54 +02001774
Daniel Vetter91d131d2013-06-27 17:52:14 +02001775 if (!hotplug_trigger)
1776 return;
1777
Dave Airlie13cf5502014-06-18 11:29:35 +10001778 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n",
1779 hotplug_trigger, dig_hotplug_reg);
Imre Deakcc9bd492014-01-16 19:56:54 +02001780
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001781 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001782 for (i = 1; i < HPD_NUM_PINS; i++) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001783 if (!(hpd[i] & hotplug_trigger))
1784 continue;
Egbert Eich821450c2013-04-16 13:36:55 +02001785
Dave Airlie13cf5502014-06-18 11:29:35 +10001786 port = get_port_from_pin(i);
1787 if (port && dev_priv->hpd_irq_port[port]) {
1788 bool long_hpd;
1789
1790 if (IS_G4X(dev)) {
1791 dig_shift = g4x_port_to_hotplug_shift(port);
1792 long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1793 } else {
1794 dig_shift = ilk_port_to_hotplug_shift(port);
1795 long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1796 }
1797
Ville Syrjälä26fbb772014-08-11 18:37:37 +03001798 DRM_DEBUG_DRIVER("digital hpd port %c - %s\n",
1799 port_name(port),
1800 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10001801 /* for long HPD pulses we want to have the digital queue happen,
1802 but we still want HPD storm detection to function. */
1803 if (long_hpd) {
1804 dev_priv->long_hpd_port_mask |= (1 << port);
1805 dig_port_mask |= hpd[i];
1806 } else {
1807 /* for short HPD just trigger the digital queue */
1808 dev_priv->short_hpd_port_mask |= (1 << port);
1809 hotplug_trigger &= ~hpd[i];
1810 }
1811 queue_dig = true;
1812 }
1813 }
1814
1815 for (i = 1; i < HPD_NUM_PINS; i++) {
Daniel Vetter3ff04a162014-04-24 12:03:17 +02001816 if (hpd[i] & hotplug_trigger &&
1817 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
1818 /*
1819 * On GMCH platforms the interrupt mask bits only
1820 * prevent irq generation, not the setting of the
1821 * hotplug bits itself. So only WARN about unexpected
1822 * interrupts on saner platforms.
1823 */
1824 WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
1825 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1826 hotplug_trigger, i, hpd[i]);
1827
1828 continue;
1829 }
Egbert Eichb8f102e2013-07-26 14:14:24 +02001830
Egbert Eichb543fb02013-04-16 13:36:54 +02001831 if (!(hpd[i] & hotplug_trigger) ||
1832 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1833 continue;
1834
Dave Airlie13cf5502014-06-18 11:29:35 +10001835 if (!(dig_port_mask & hpd[i])) {
1836 dev_priv->hpd_event_bits |= (1 << i);
1837 queue_hp = true;
1838 }
1839
Egbert Eichb543fb02013-04-16 13:36:54 +02001840 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1841 dev_priv->hpd_stats[i].hpd_last_jiffies
1842 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1843 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1844 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001845 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001846 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1847 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001848 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001849 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001850 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001851 } else {
1852 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001853 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1854 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001855 }
1856 }
1857
Daniel Vetter10a504d2013-06-27 17:52:12 +02001858 if (storm_detected)
1859 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001860 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001861
Daniel Vetter645416f2013-09-02 16:22:25 +02001862 /*
1863 * Our hotplug handler can grab modeset locks (by calling down into the
1864 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1865 * queue for otherwise the flush_work in the pageflip code will
1866 * deadlock.
1867 */
Dave Airlie13cf5502014-06-18 11:29:35 +10001868 if (queue_dig)
Dave Airlie0e32b392014-05-02 14:02:48 +10001869 queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +10001870 if (queue_hp)
1871 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001872}
1873
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001874static void gmbus_irq_handler(struct drm_device *dev)
1875{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001876 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001877
Daniel Vetter28c70f12012-12-01 13:53:45 +01001878 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001879}
1880
Daniel Vetterce99c252012-12-01 13:53:47 +01001881static void dp_aux_irq_handler(struct drm_device *dev)
1882{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001883 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001884
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001885 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001886}
1887
Shuang He8bf1e9f2013-10-15 18:55:27 +01001888#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001889static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1890 uint32_t crc0, uint32_t crc1,
1891 uint32_t crc2, uint32_t crc3,
1892 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001893{
1894 struct drm_i915_private *dev_priv = dev->dev_private;
1895 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1896 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001897 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001898
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001899 spin_lock(&pipe_crc->lock);
1900
Damien Lespiau0c912c72013-10-15 18:55:37 +01001901 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001902 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001903 DRM_ERROR("spurious interrupt\n");
1904 return;
1905 }
1906
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001907 head = pipe_crc->head;
1908 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001909
1910 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001911 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001912 DRM_ERROR("CRC buffer overflowing\n");
1913 return;
1914 }
1915
1916 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001917
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001918 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001919 entry->crc[0] = crc0;
1920 entry->crc[1] = crc1;
1921 entry->crc[2] = crc2;
1922 entry->crc[3] = crc3;
1923 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001924
1925 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001926 pipe_crc->head = head;
1927
1928 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001929
1930 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001931}
Daniel Vetter277de952013-10-18 16:37:07 +02001932#else
1933static inline void
1934display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1935 uint32_t crc0, uint32_t crc1,
1936 uint32_t crc2, uint32_t crc3,
1937 uint32_t crc4) {}
1938#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001939
Daniel Vetter277de952013-10-18 16:37:07 +02001940
1941static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001942{
1943 struct drm_i915_private *dev_priv = dev->dev_private;
1944
Daniel Vetter277de952013-10-18 16:37:07 +02001945 display_pipe_crc_irq_handler(dev, pipe,
1946 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1947 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001948}
1949
Daniel Vetter277de952013-10-18 16:37:07 +02001950static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001951{
1952 struct drm_i915_private *dev_priv = dev->dev_private;
1953
Daniel Vetter277de952013-10-18 16:37:07 +02001954 display_pipe_crc_irq_handler(dev, pipe,
1955 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1956 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1957 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1958 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1959 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001960}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001961
Daniel Vetter277de952013-10-18 16:37:07 +02001962static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001963{
1964 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001965 uint32_t res1, res2;
1966
1967 if (INTEL_INFO(dev)->gen >= 3)
1968 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1969 else
1970 res1 = 0;
1971
1972 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1973 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1974 else
1975 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001976
Daniel Vetter277de952013-10-18 16:37:07 +02001977 display_pipe_crc_irq_handler(dev, pipe,
1978 I915_READ(PIPE_CRC_RES_RED(pipe)),
1979 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1980 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1981 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001982}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001983
Daisy Sunc76bb612014-08-11 11:08:38 -07001984void gen8_flip_interrupt(struct drm_device *dev)
1985{
1986 struct drm_i915_private *dev_priv = dev->dev_private;
1987
1988 if (!dev_priv->rps.is_bdw_sw_turbo)
1989 return;
1990
1991 if(atomic_read(&dev_priv->rps.sw_turbo.flip_received)) {
1992 mod_timer(&dev_priv->rps.sw_turbo.flip_timer,
1993 usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies);
1994 }
1995 else {
1996 dev_priv->rps.sw_turbo.flip_timer.expires =
1997 usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies;
1998 add_timer(&dev_priv->rps.sw_turbo.flip_timer);
1999 atomic_set(&dev_priv->rps.sw_turbo.flip_received, true);
2000 }
2001
2002 bdw_software_turbo(dev);
2003}
2004
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002005/* The RPS events need forcewake, so we add them to a work queue and mask their
2006 * IMR bits until the work is done. Other interrupts can be processed without
2007 * the work queue. */
2008static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07002009{
Deepak Sa6706b42014-03-15 20:23:22 +05302010 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02002011 spin_lock(&dev_priv->irq_lock);
Deepak Sa6706b42014-03-15 20:23:22 +05302012 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Daniel Vetter480c8032014-07-16 09:49:40 +02002013 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02002014 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02002015
2016 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07002017 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07002018
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002019 if (HAS_VEBOX(dev_priv->dev)) {
2020 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
2021 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07002022
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002023 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002024 i915_handle_error(dev_priv->dev, false,
2025 "VEBOX CS error interrupt 0x%08x",
2026 pm_iir);
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002027 }
Ben Widawsky12638c52013-05-28 19:22:31 -07002028 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07002029}
2030
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002031static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
2032{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002033 if (!drm_handle_vblank(dev, pipe))
2034 return false;
2035
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002036 return true;
2037}
2038
Imre Deakc1874ed2014-02-04 21:35:46 +02002039static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
2040{
2041 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02002042 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02002043 int pipe;
2044
Imre Deak58ead0d2014-02-04 21:35:47 +02002045 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01002046 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02002047 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002048 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02002049
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002050 /*
2051 * PIPESTAT bits get signalled even when the interrupt is
2052 * disabled with the mask bits, and some of the status bits do
2053 * not generate interrupts at all (like the underrun bit). Hence
2054 * we need to be careful that we only handle what we want to
2055 * handle.
2056 */
2057 mask = 0;
2058 if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
2059 mask |= PIPE_FIFO_UNDERRUN_STATUS;
2060
2061 switch (pipe) {
2062 case PIPE_A:
2063 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
2064 break;
2065 case PIPE_B:
2066 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
2067 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03002068 case PIPE_C:
2069 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
2070 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002071 }
2072 if (iir & iir_bit)
2073 mask |= dev_priv->pipestat_irq_mask[pipe];
2074
2075 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02002076 continue;
2077
2078 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002079 mask |= PIPESTAT_INT_ENABLE_MASK;
2080 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02002081
2082 /*
2083 * Clear the PIPE*STAT regs before the IIR
2084 */
Imre Deak91d181d2014-02-10 18:42:49 +02002085 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
2086 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02002087 I915_WRITE(reg, pipe_stats[pipe]);
2088 }
Imre Deak58ead0d2014-02-04 21:35:47 +02002089 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02002090
Damien Lespiau055e3932014-08-18 13:49:10 +01002091 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002092 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
2093 intel_pipe_handle_vblank(dev, pipe))
2094 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002095
Imre Deak579a9b02014-02-04 21:35:48 +02002096 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02002097 intel_prepare_page_flip(dev, pipe);
2098 intel_finish_page_flip(dev, pipe);
2099 }
2100
2101 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2102 i9xx_pipe_crc_irq_handler(dev, pipe);
2103
2104 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
2105 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
2106 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
2107 }
2108
2109 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2110 gmbus_irq_handler(dev);
2111}
2112
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002113static void i9xx_hpd_irq_handler(struct drm_device *dev)
2114{
2115 struct drm_i915_private *dev_priv = dev->dev_private;
2116 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
2117
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002118 if (hotplug_status) {
2119 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2120 /*
2121 * Make sure hotplug status is cleared before we clear IIR, or else we
2122 * may miss hotplug events.
2123 */
2124 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002125
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002126 if (IS_G4X(dev)) {
2127 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002128
Dave Airlie13cf5502014-06-18 11:29:35 +10002129 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002130 } else {
2131 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
2132
Dave Airlie13cf5502014-06-18 11:29:35 +10002133 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002134 }
2135
2136 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
2137 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
2138 dp_aux_irq_handler(dev);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002139 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002140}
2141
Daniel Vetterff1f5252012-10-02 15:10:55 +02002142static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002143{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002144 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002145 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002146 u32 iir, gt_iir, pm_iir;
2147 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002148
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002149 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002150 /* Find, clear, then process each source of interrupt */
2151
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002152 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002153 if (gt_iir)
2154 I915_WRITE(GTIIR, gt_iir);
2155
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002156 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002157 if (pm_iir)
2158 I915_WRITE(GEN6_PMIIR, pm_iir);
2159
2160 iir = I915_READ(VLV_IIR);
2161 if (iir) {
2162 /* Consume port before clearing IIR or we'll miss events */
2163 if (iir & I915_DISPLAY_PORT_INTERRUPT)
2164 i9xx_hpd_irq_handler(dev);
2165 I915_WRITE(VLV_IIR, iir);
2166 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002167
2168 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
2169 goto out;
2170
2171 ret = IRQ_HANDLED;
2172
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002173 if (gt_iir)
2174 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03002175 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02002176 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002177 /* Call regardless, as some status bits might not be
2178 * signalled in iir */
2179 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002180 }
2181
2182out:
2183 return ret;
2184}
2185
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002186static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2187{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002188 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002189 struct drm_i915_private *dev_priv = dev->dev_private;
2190 u32 master_ctl, iir;
2191 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002192
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002193 for (;;) {
2194 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2195 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002196
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002197 if (master_ctl == 0 && iir == 0)
2198 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002199
Oscar Mateo27b6c122014-06-16 16:11:00 +01002200 ret = IRQ_HANDLED;
2201
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002202 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002203
Oscar Mateo27b6c122014-06-16 16:11:00 +01002204 /* Find, clear, then process each source of interrupt */
2205
2206 if (iir) {
2207 /* Consume port before clearing IIR or we'll miss events */
2208 if (iir & I915_DISPLAY_PORT_INTERRUPT)
2209 i9xx_hpd_irq_handler(dev);
2210 I915_WRITE(VLV_IIR, iir);
2211 }
2212
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002213 gen8_gt_irq_handler(dev, dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002214
Oscar Mateo27b6c122014-06-16 16:11:00 +01002215 /* Call regardless, as some status bits might not be
2216 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002217 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002218
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002219 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
2220 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002221 }
2222
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002223 return ret;
2224}
2225
Adam Jackson23e81d62012-06-06 15:45:44 -04002226static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002227{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002228 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002229 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002230 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Dave Airlie13cf5502014-06-18 11:29:35 +10002231 u32 dig_hotplug_reg;
Jesse Barnes776ad802011-01-04 15:09:39 -08002232
Dave Airlie13cf5502014-06-18 11:29:35 +10002233 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2234 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2235
2236 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002237
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002238 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2239 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2240 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002241 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002242 port_name(port));
2243 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002244
Daniel Vetterce99c252012-12-01 13:53:47 +01002245 if (pch_iir & SDE_AUX_MASK)
2246 dp_aux_irq_handler(dev);
2247
Jesse Barnes776ad802011-01-04 15:09:39 -08002248 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002249 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08002250
2251 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2252 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2253
2254 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2255 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2256
2257 if (pch_iir & SDE_POISON)
2258 DRM_ERROR("PCH poison interrupt\n");
2259
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002260 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002261 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002262 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2263 pipe_name(pipe),
2264 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002265
2266 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2267 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2268
2269 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2270 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2271
Jesse Barnes776ad802011-01-04 15:09:39 -08002272 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03002273 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2274 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002275 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002276
2277 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
2278 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2279 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002280 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002281}
2282
2283static void ivb_err_int_handler(struct drm_device *dev)
2284{
2285 struct drm_i915_private *dev_priv = dev->dev_private;
2286 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002287 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002288
Paulo Zanonide032bf2013-04-12 17:57:58 -03002289 if (err_int & ERR_INT_POISON)
2290 DRM_ERROR("Poison interrupt\n");
2291
Damien Lespiau055e3932014-08-18 13:49:10 +01002292 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a69b892013-10-16 22:55:52 +02002293 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
2294 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2295 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002296 DRM_ERROR("Pipe %c FIFO underrun\n",
2297 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02002298 }
Paulo Zanoni86642812013-04-12 17:57:57 -03002299
Daniel Vetter5a69b892013-10-16 22:55:52 +02002300 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
2301 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02002302 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002303 else
Daniel Vetter277de952013-10-18 16:37:07 +02002304 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002305 }
2306 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002307
Paulo Zanoni86642812013-04-12 17:57:57 -03002308 I915_WRITE(GEN7_ERR_INT, err_int);
2309}
2310
2311static void cpt_serr_int_handler(struct drm_device *dev)
2312{
2313 struct drm_i915_private *dev_priv = dev->dev_private;
2314 u32 serr_int = I915_READ(SERR_INT);
2315
Paulo Zanonide032bf2013-04-12 17:57:58 -03002316 if (serr_int & SERR_INT_POISON)
2317 DRM_ERROR("PCH poison interrupt\n");
2318
Paulo Zanoni86642812013-04-12 17:57:57 -03002319 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
2320 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2321 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002322 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002323
2324 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
2325 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2326 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002327 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002328
2329 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
2330 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
2331 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002332 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002333
2334 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002335}
2336
Adam Jackson23e81d62012-06-06 15:45:44 -04002337static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
2338{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002339 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04002340 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002341 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Dave Airlie13cf5502014-06-18 11:29:35 +10002342 u32 dig_hotplug_reg;
Adam Jackson23e81d62012-06-06 15:45:44 -04002343
Dave Airlie13cf5502014-06-18 11:29:35 +10002344 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2345 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2346
2347 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002348
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002349 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2350 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2351 SDE_AUDIO_POWER_SHIFT_CPT);
2352 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2353 port_name(port));
2354 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002355
2356 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01002357 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002358
2359 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002360 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002361
2362 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2363 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2364
2365 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2366 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2367
2368 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002369 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002370 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2371 pipe_name(pipe),
2372 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002373
2374 if (pch_iir & SDE_ERROR_CPT)
2375 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002376}
2377
Paulo Zanonic008bc62013-07-12 16:35:10 -03002378static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2379{
2380 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02002381 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03002382
2383 if (de_iir & DE_AUX_CHANNEL_A)
2384 dp_aux_irq_handler(dev);
2385
2386 if (de_iir & DE_GSE)
2387 intel_opregion_asle_intr(dev);
2388
Paulo Zanonic008bc62013-07-12 16:35:10 -03002389 if (de_iir & DE_POISON)
2390 DRM_ERROR("Poison interrupt\n");
2391
Damien Lespiau055e3932014-08-18 13:49:10 +01002392 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002393 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2394 intel_pipe_handle_vblank(dev, pipe))
2395 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002396
Daniel Vetter40da17c2013-10-21 18:04:36 +02002397 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2398 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002399 DRM_ERROR("Pipe %c FIFO underrun\n",
2400 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03002401
Daniel Vetter40da17c2013-10-21 18:04:36 +02002402 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2403 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002404
Daniel Vetter40da17c2013-10-21 18:04:36 +02002405 /* plane/pipes map 1:1 on ilk+ */
2406 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2407 intel_prepare_page_flip(dev, pipe);
2408 intel_finish_page_flip_plane(dev, pipe);
2409 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03002410 }
2411
2412 /* check event from PCH */
2413 if (de_iir & DE_PCH_EVENT) {
2414 u32 pch_iir = I915_READ(SDEIIR);
2415
2416 if (HAS_PCH_CPT(dev))
2417 cpt_irq_handler(dev, pch_iir);
2418 else
2419 ibx_irq_handler(dev, pch_iir);
2420
2421 /* should clear PCH hotplug event before clear CPU irq */
2422 I915_WRITE(SDEIIR, pch_iir);
2423 }
2424
2425 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2426 ironlake_rps_change_irq_handler(dev);
2427}
2428
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002429static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2430{
2431 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002432 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002433
2434 if (de_iir & DE_ERR_INT_IVB)
2435 ivb_err_int_handler(dev);
2436
2437 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2438 dp_aux_irq_handler(dev);
2439
2440 if (de_iir & DE_GSE_IVB)
2441 intel_opregion_asle_intr(dev);
2442
Damien Lespiau055e3932014-08-18 13:49:10 +01002443 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002444 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2445 intel_pipe_handle_vblank(dev, pipe))
2446 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02002447
2448 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002449 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2450 intel_prepare_page_flip(dev, pipe);
2451 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002452 }
2453 }
2454
2455 /* check event from PCH */
2456 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2457 u32 pch_iir = I915_READ(SDEIIR);
2458
2459 cpt_irq_handler(dev, pch_iir);
2460
2461 /* clear PCH hotplug event before clear CPU irq */
2462 I915_WRITE(SDEIIR, pch_iir);
2463 }
2464}
2465
Oscar Mateo72c90f62014-06-16 16:10:57 +01002466/*
2467 * To handle irqs with the minimum potential races with fresh interrupts, we:
2468 * 1 - Disable Master Interrupt Control.
2469 * 2 - Find the source(s) of the interrupt.
2470 * 3 - Clear the Interrupt Identity bits (IIR).
2471 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2472 * 5 - Re-enable Master Interrupt Control.
2473 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002474static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002475{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002476 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002477 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002478 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002479 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002480
Paulo Zanoni86642812013-04-12 17:57:57 -03002481 /* We get interrupts on unclaimed registers, so check for this before we
2482 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002483 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002484
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002485 /* disable master interrupt before clearing iir */
2486 de_ier = I915_READ(DEIER);
2487 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002488 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002489
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002490 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2491 * interrupts will will be stored on its back queue, and then we'll be
2492 * able to process them after we restore SDEIER (as soon as we restore
2493 * it, we'll get an interrupt if SDEIIR still has something to process
2494 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002495 if (!HAS_PCH_NOP(dev)) {
2496 sde_ier = I915_READ(SDEIER);
2497 I915_WRITE(SDEIER, 0);
2498 POSTING_READ(SDEIER);
2499 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002500
Oscar Mateo72c90f62014-06-16 16:10:57 +01002501 /* Find, clear, then process each source of interrupt */
2502
Chris Wilson0e434062012-05-09 21:45:44 +01002503 gt_iir = I915_READ(GTIIR);
2504 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002505 I915_WRITE(GTIIR, gt_iir);
2506 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002507 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002508 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002509 else
2510 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002511 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002512
2513 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002514 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002515 I915_WRITE(DEIIR, de_iir);
2516 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002517 if (INTEL_INFO(dev)->gen >= 7)
2518 ivb_display_irq_handler(dev, de_iir);
2519 else
2520 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002521 }
2522
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002523 if (INTEL_INFO(dev)->gen >= 6) {
2524 u32 pm_iir = I915_READ(GEN6_PMIIR);
2525 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002526 I915_WRITE(GEN6_PMIIR, pm_iir);
2527 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002528 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002529 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002530 }
2531
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002532 I915_WRITE(DEIER, de_ier);
2533 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002534 if (!HAS_PCH_NOP(dev)) {
2535 I915_WRITE(SDEIER, sde_ier);
2536 POSTING_READ(SDEIER);
2537 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002538
2539 return ret;
2540}
2541
Ben Widawskyabd58f02013-11-02 21:07:09 -07002542static irqreturn_t gen8_irq_handler(int irq, void *arg)
2543{
2544 struct drm_device *dev = arg;
2545 struct drm_i915_private *dev_priv = dev->dev_private;
2546 u32 master_ctl;
2547 irqreturn_t ret = IRQ_NONE;
2548 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002549 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002550
Ben Widawskyabd58f02013-11-02 21:07:09 -07002551 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2552 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2553 if (!master_ctl)
2554 return IRQ_NONE;
2555
2556 I915_WRITE(GEN8_MASTER_IRQ, 0);
2557 POSTING_READ(GEN8_MASTER_IRQ);
2558
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002559 /* Find, clear, then process each source of interrupt */
2560
Ben Widawskyabd58f02013-11-02 21:07:09 -07002561 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2562
2563 if (master_ctl & GEN8_DE_MISC_IRQ) {
2564 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002565 if (tmp) {
2566 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2567 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002568 if (tmp & GEN8_DE_MISC_GSE)
2569 intel_opregion_asle_intr(dev);
2570 else
2571 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002572 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002573 else
2574 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002575 }
2576
Daniel Vetter6d766f02013-11-07 14:49:55 +01002577 if (master_ctl & GEN8_DE_PORT_IRQ) {
2578 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002579 if (tmp) {
2580 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2581 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002582 if (tmp & GEN8_AUX_CHANNEL_A)
2583 dp_aux_irq_handler(dev);
2584 else
2585 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002586 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002587 else
2588 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002589 }
2590
Damien Lespiau055e3932014-08-18 13:49:10 +01002591 for_each_pipe(dev_priv, pipe) {
Daniel Vetterc42664c2013-11-07 11:05:40 +01002592 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002593
Daniel Vetterc42664c2013-11-07 11:05:40 +01002594 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2595 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002596
Daniel Vetterc42664c2013-11-07 11:05:40 +01002597 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002598 if (pipe_iir) {
2599 ret = IRQ_HANDLED;
2600 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002601 if (pipe_iir & GEN8_PIPE_VBLANK &&
2602 intel_pipe_handle_vblank(dev, pipe))
2603 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002604
2605 if (pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE) {
2606 intel_prepare_page_flip(dev, pipe);
2607 intel_finish_page_flip_plane(dev, pipe);
2608 }
2609
2610 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2611 hsw_pipe_crc_irq_handler(dev, pipe);
2612
2613 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
2614 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2615 false))
2616 DRM_ERROR("Pipe %c FIFO underrun\n",
2617 pipe_name(pipe));
2618 }
2619
2620 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
2621 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2622 pipe_name(pipe),
2623 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2624 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002625 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002626 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2627 }
2628
Daniel Vetter92d03a82013-11-07 11:05:43 +01002629 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2630 /*
2631 * FIXME(BDW): Assume for now that the new interrupt handling
2632 * scheme also closed the SDE interrupt handling race we've seen
2633 * on older pch-split platforms. But this needs testing.
2634 */
2635 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002636 if (pch_iir) {
2637 I915_WRITE(SDEIIR, pch_iir);
2638 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002639 cpt_irq_handler(dev, pch_iir);
2640 } else
2641 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2642
Daniel Vetter92d03a82013-11-07 11:05:43 +01002643 }
2644
Ben Widawskyabd58f02013-11-02 21:07:09 -07002645 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2646 POSTING_READ(GEN8_MASTER_IRQ);
2647
2648 return ret;
2649}
2650
Daniel Vetter17e1df02013-09-08 21:57:13 +02002651static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2652 bool reset_completed)
2653{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002654 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002655 int i;
2656
2657 /*
2658 * Notify all waiters for GPU completion events that reset state has
2659 * been changed, and that they need to restart their wait after
2660 * checking for potential errors (and bail out to drop locks if there is
2661 * a gpu reset pending so that i915_error_work_func can acquire them).
2662 */
2663
2664 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2665 for_each_ring(ring, dev_priv, i)
2666 wake_up_all(&ring->irq_queue);
2667
2668 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2669 wake_up_all(&dev_priv->pending_flip_queue);
2670
2671 /*
2672 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2673 * reset state is cleared.
2674 */
2675 if (reset_completed)
2676 wake_up_all(&dev_priv->gpu_error.reset_queue);
2677}
2678
Jesse Barnes8a905232009-07-11 16:48:03 -04002679/**
2680 * i915_error_work_func - do process context error handling work
2681 * @work: work struct
2682 *
2683 * Fire an error uevent so userspace can see that a hang or error
2684 * was detected.
2685 */
2686static void i915_error_work_func(struct work_struct *work)
2687{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002688 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2689 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002690 struct drm_i915_private *dev_priv =
2691 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002692 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002693 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2694 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2695 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002696 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002697
Dave Airlie5bdebb12013-10-11 14:07:25 +10002698 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002699
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002700 /*
2701 * Note that there's only one work item which does gpu resets, so we
2702 * need not worry about concurrent gpu resets potentially incrementing
2703 * error->reset_counter twice. We only need to take care of another
2704 * racing irq/hangcheck declaring the gpu dead for a second time. A
2705 * quick check for that is good enough: schedule_work ensures the
2706 * correct ordering between hang detection and this work item, and since
2707 * the reset in-progress bit is only ever set by code outside of this
2708 * work we don't need to worry about any other races.
2709 */
2710 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002711 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002712 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002713 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002714
Daniel Vetter17e1df02013-09-08 21:57:13 +02002715 /*
Imre Deakf454c692014-04-23 01:09:04 +03002716 * In most cases it's guaranteed that we get here with an RPM
2717 * reference held, for example because there is a pending GPU
2718 * request that won't finish until the reset is done. This
2719 * isn't the case at least when we get here by doing a
2720 * simulated reset via debugs, so get an RPM reference.
2721 */
2722 intel_runtime_pm_get(dev_priv);
2723 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002724 * All state reset _must_ be completed before we update the
2725 * reset counter, for otherwise waiters might miss the reset
2726 * pending state and not properly drop locks, resulting in
2727 * deadlocks with the reset work.
2728 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002729 ret = i915_reset(dev);
2730
Daniel Vetter17e1df02013-09-08 21:57:13 +02002731 intel_display_handle_reset(dev);
2732
Imre Deakf454c692014-04-23 01:09:04 +03002733 intel_runtime_pm_put(dev_priv);
2734
Daniel Vetterf69061b2012-12-06 09:01:42 +01002735 if (ret == 0) {
2736 /*
2737 * After all the gem state is reset, increment the reset
2738 * counter and wake up everyone waiting for the reset to
2739 * complete.
2740 *
2741 * Since unlock operations are a one-sided barrier only,
2742 * we need to insert a barrier here to order any seqno
2743 * updates before
2744 * the counter increment.
2745 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002746 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002747 atomic_inc(&dev_priv->gpu_error.reset_counter);
2748
Dave Airlie5bdebb12013-10-11 14:07:25 +10002749 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002750 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002751 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002752 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002753 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002754
Daniel Vetter17e1df02013-09-08 21:57:13 +02002755 /*
2756 * Note: The wake_up also serves as a memory barrier so that
2757 * waiters see the update value of the reset counter atomic_t.
2758 */
2759 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002760 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002761}
2762
Chris Wilson35aed2e2010-05-27 13:18:12 +01002763static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002764{
2765 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002766 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002767 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002768 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002769
Chris Wilson35aed2e2010-05-27 13:18:12 +01002770 if (!eir)
2771 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002772
Joe Perchesa70491c2012-03-18 13:00:11 -07002773 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002774
Ben Widawskybd9854f2012-08-23 15:18:09 -07002775 i915_get_extra_instdone(dev, instdone);
2776
Jesse Barnes8a905232009-07-11 16:48:03 -04002777 if (IS_G4X(dev)) {
2778 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2779 u32 ipeir = I915_READ(IPEIR_I965);
2780
Joe Perchesa70491c2012-03-18 13:00:11 -07002781 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2782 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002783 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2784 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002785 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002786 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002787 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002788 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002789 }
2790 if (eir & GM45_ERROR_PAGE_TABLE) {
2791 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002792 pr_err("page table error\n");
2793 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002794 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002795 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002796 }
2797 }
2798
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002799 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002800 if (eir & I915_ERROR_PAGE_TABLE) {
2801 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002802 pr_err("page table error\n");
2803 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002804 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002805 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002806 }
2807 }
2808
2809 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002810 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002811 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002812 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002813 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002814 /* pipestat has already been acked */
2815 }
2816 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002817 pr_err("instruction error\n");
2818 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002819 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2820 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002821 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002822 u32 ipeir = I915_READ(IPEIR);
2823
Joe Perchesa70491c2012-03-18 13:00:11 -07002824 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2825 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002826 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002827 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002828 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002829 } else {
2830 u32 ipeir = I915_READ(IPEIR_I965);
2831
Joe Perchesa70491c2012-03-18 13:00:11 -07002832 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2833 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002834 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002835 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002836 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002837 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002838 }
2839 }
2840
2841 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002842 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002843 eir = I915_READ(EIR);
2844 if (eir) {
2845 /*
2846 * some errors might have become stuck,
2847 * mask them.
2848 */
2849 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2850 I915_WRITE(EMR, I915_READ(EMR) | eir);
2851 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2852 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002853}
2854
2855/**
2856 * i915_handle_error - handle an error interrupt
2857 * @dev: drm device
2858 *
2859 * Do some basic checking of regsiter state at error interrupt time and
2860 * dump it to the syslog. Also call i915_capture_error_state() to make
2861 * sure we get a record and make it available in debugfs. Fire a uevent
2862 * so userspace knows something bad happened (should trigger collection
2863 * of a ring dump etc.).
2864 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002865void i915_handle_error(struct drm_device *dev, bool wedged,
2866 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002867{
2868 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002869 va_list args;
2870 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002871
Mika Kuoppala58174462014-02-25 17:11:26 +02002872 va_start(args, fmt);
2873 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2874 va_end(args);
2875
2876 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002877 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002878
Ben Gamariba1234d2009-09-14 17:48:47 -04002879 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002880 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2881 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002882
Ben Gamari11ed50e2009-09-14 17:48:45 -04002883 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002884 * Wakeup waiting processes so that the reset work function
2885 * i915_error_work_func doesn't deadlock trying to grab various
2886 * locks. By bumping the reset counter first, the woken
2887 * processes will see a reset in progress and back off,
2888 * releasing their locks and then wait for the reset completion.
2889 * We must do this for _all_ gpu waiters that might hold locks
2890 * that the reset work needs to acquire.
2891 *
2892 * Note: The wake_up serves as the required memory barrier to
2893 * ensure that the waiters see the updated value of the reset
2894 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002895 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002896 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002897 }
2898
Daniel Vetter122f46b2013-09-04 17:36:14 +02002899 /*
2900 * Our reset work can grab modeset locks (since it needs to reset the
2901 * state of outstanding pagelips). Hence it must not be run on our own
2902 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2903 * code will deadlock.
2904 */
2905 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002906}
2907
Keith Packard42f52ef2008-10-18 19:39:29 -07002908/* Called from drm generic code, passed 'crtc' which
2909 * we use as a pipe index
2910 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002911static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002912{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002913 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002914 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002915
Chris Wilson5eddb702010-09-11 13:48:45 +01002916 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002917 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002918
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002919 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002920 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002921 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002922 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002923 else
Keith Packard7c463582008-11-04 02:03:27 -08002924 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002925 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002926 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002927
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002928 return 0;
2929}
2930
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002931static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002932{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002933 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002934 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002935 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002936 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002937
2938 if (!i915_pipe_enabled(dev, pipe))
2939 return -EINVAL;
2940
2941 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002942 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002943 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2944
2945 return 0;
2946}
2947
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002948static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2949{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002950 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002951 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002952
2953 if (!i915_pipe_enabled(dev, pipe))
2954 return -EINVAL;
2955
2956 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002957 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002958 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002959 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2960
2961 return 0;
2962}
2963
Ben Widawskyabd58f02013-11-02 21:07:09 -07002964static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2965{
2966 struct drm_i915_private *dev_priv = dev->dev_private;
2967 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002968
2969 if (!i915_pipe_enabled(dev, pipe))
2970 return -EINVAL;
2971
2972 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002973 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2974 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2975 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002976 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2977 return 0;
2978}
2979
Keith Packard42f52ef2008-10-18 19:39:29 -07002980/* Called from drm generic code, passed 'crtc' which
2981 * we use as a pipe index
2982 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002983static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002984{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002985 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002986 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002987
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002988 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002989 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002990 PIPE_VBLANK_INTERRUPT_STATUS |
2991 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002992 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2993}
2994
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002995static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002996{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002997 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002998 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002999 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02003000 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003001
3002 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03003003 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003004 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3005}
3006
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003007static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
3008{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003009 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003010 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003011
3012 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003013 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003014 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003015 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3016}
3017
Ben Widawskyabd58f02013-11-02 21:07:09 -07003018static void gen8_disable_vblank(struct drm_device *dev, int pipe)
3019{
3020 struct drm_i915_private *dev_priv = dev->dev_private;
3021 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003022
3023 if (!i915_pipe_enabled(dev, pipe))
3024 return;
3025
3026 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01003027 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
3028 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3029 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07003030 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3031}
3032
Chris Wilson893eead2010-10-27 14:44:35 +01003033static u32
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003034ring_last_seqno(struct intel_engine_cs *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08003035{
Chris Wilson893eead2010-10-27 14:44:35 +01003036 return list_entry(ring->request_list.prev,
3037 struct drm_i915_gem_request, list)->seqno;
3038}
3039
Chris Wilson9107e9d2013-06-10 11:20:20 +01003040static bool
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003041ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01003042{
Chris Wilson9107e9d2013-06-10 11:20:20 +01003043 return (list_empty(&ring->request_list) ||
3044 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04003045}
3046
Daniel Vettera028c4b2014-03-15 00:08:56 +01003047static bool
3048ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
3049{
3050 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003051 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01003052 } else {
3053 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
3054 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
3055 MI_SEMAPHORE_REGISTER);
3056 }
3057}
3058
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003059static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003060semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01003061{
3062 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003063 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01003064 int i;
3065
3066 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003067 for_each_ring(signaller, dev_priv, i) {
3068 if (ring == signaller)
3069 continue;
3070
3071 if (offset == signaller->semaphore.signal_ggtt[ring->id])
3072 return signaller;
3073 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01003074 } else {
3075 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
3076
3077 for_each_ring(signaller, dev_priv, i) {
3078 if(ring == signaller)
3079 continue;
3080
Ben Widawskyebc348b2014-04-29 14:52:28 -07003081 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01003082 return signaller;
3083 }
3084 }
3085
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003086 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
3087 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01003088
3089 return NULL;
3090}
3091
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003092static struct intel_engine_cs *
3093semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02003094{
3095 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003096 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003097 u64 offset = 0;
3098 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02003099
3100 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01003101 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01003102 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02003103
Daniel Vetter88fe4292014-03-15 00:08:55 +01003104 /*
3105 * HEAD is likely pointing to the dword after the actual command,
3106 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003107 * or 4 dwords depending on the semaphore wait command size.
3108 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01003109 * point at at batch, and semaphores are always emitted into the
3110 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02003111 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01003112 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003113 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003114
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003115 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01003116 /*
3117 * Be paranoid and presume the hw has gone off into the wild -
3118 * our ring is smaller than what the hardware (and hence
3119 * HEAD_ADDR) allows. Also handles wrap-around.
3120 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003121 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003122
3123 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003124 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02003125 if (cmd == ipehr)
3126 break;
3127
Daniel Vetter88fe4292014-03-15 00:08:55 +01003128 head -= 4;
3129 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003130
Daniel Vetter88fe4292014-03-15 00:08:55 +01003131 if (!i)
3132 return NULL;
3133
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003134 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003135 if (INTEL_INFO(ring->dev)->gen >= 8) {
3136 offset = ioread32(ring->buffer->virtual_start + head + 12);
3137 offset <<= 32;
3138 offset = ioread32(ring->buffer->virtual_start + head + 8);
3139 }
3140 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02003141}
3142
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003143static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01003144{
3145 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003146 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01003147 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01003148
Chris Wilson4be17382014-06-06 10:22:29 +01003149 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01003150
3151 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01003152 if (signaller == NULL)
3153 return -1;
3154
3155 /* Prevent pathological recursion due to driver bugs */
3156 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01003157 return -1;
3158
Chris Wilson4be17382014-06-06 10:22:29 +01003159 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
3160 return 1;
3161
Chris Wilsona0d036b2014-07-19 12:40:42 +01003162 /* cursory check for an unkickable deadlock */
3163 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
3164 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01003165 return -1;
3166
3167 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01003168}
3169
3170static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
3171{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003172 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01003173 int i;
3174
3175 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01003176 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01003177}
3178
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003179static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003180ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003181{
3182 struct drm_device *dev = ring->dev;
3183 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003184 u32 tmp;
3185
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003186 if (acthd != ring->hangcheck.acthd) {
3187 if (acthd > ring->hangcheck.max_acthd) {
3188 ring->hangcheck.max_acthd = acthd;
3189 return HANGCHECK_ACTIVE;
3190 }
3191
3192 return HANGCHECK_ACTIVE_LOOP;
3193 }
Chris Wilson6274f212013-06-10 11:20:21 +01003194
Chris Wilson9107e9d2013-06-10 11:20:20 +01003195 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003196 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003197
3198 /* Is the chip hanging on a WAIT_FOR_EVENT?
3199 * If so we can simply poke the RB_WAIT bit
3200 * and break the hang. This should work on
3201 * all but the second generation chipsets.
3202 */
3203 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003204 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02003205 i915_handle_error(dev, false,
3206 "Kicking stuck wait on %s",
3207 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003208 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003209 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003210 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003211
Chris Wilson6274f212013-06-10 11:20:21 +01003212 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
3213 switch (semaphore_passed(ring)) {
3214 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003215 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003216 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02003217 i915_handle_error(dev, false,
3218 "Kicking stuck semaphore on %s",
3219 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01003220 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003221 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003222 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003223 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003224 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003225 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003226
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003227 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003228}
3229
Ben Gamarif65d9422009-09-14 17:48:44 -04003230/**
3231 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003232 * batchbuffers in a long time. We keep track per ring seqno progress and
3233 * if there are no progress, hangcheck score for that ring is increased.
3234 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3235 * we kick the ring. If we see no progress on three subsequent calls
3236 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003237 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01003238static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04003239{
3240 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003241 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003242 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01003243 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003244 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003245 bool stuck[I915_NUM_RINGS] = { 0 };
3246#define BUSY 1
3247#define KICK 5
3248#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01003249
Jani Nikulad330a952014-01-21 11:24:25 +02003250 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003251 return;
3252
Chris Wilsonb4519512012-05-11 14:29:30 +01003253 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00003254 u64 acthd;
3255 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003256 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01003257
Chris Wilson6274f212013-06-10 11:20:21 +01003258 semaphore_clear_deadlocks(dev_priv);
3259
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003260 seqno = ring->get_seqno(ring, false);
3261 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003262
Chris Wilson9107e9d2013-06-10 11:20:20 +01003263 if (ring->hangcheck.seqno == seqno) {
3264 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003265 ring->hangcheck.action = HANGCHECK_IDLE;
3266
Chris Wilson9107e9d2013-06-10 11:20:20 +01003267 if (waitqueue_active(&ring->irq_queue)) {
3268 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01003269 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01003270 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
3271 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
3272 ring->name);
3273 else
3274 DRM_INFO("Fake missed irq on %s\n",
3275 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01003276 wake_up_all(&ring->irq_queue);
3277 }
3278 /* Safeguard against driver failure */
3279 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003280 } else
3281 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003282 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003283 /* We always increment the hangcheck score
3284 * if the ring is busy and still processing
3285 * the same request, so that no single request
3286 * can run indefinitely (such as a chain of
3287 * batches). The only time we do not increment
3288 * the hangcheck score on this ring, if this
3289 * ring is in a legitimate wait for another
3290 * ring. In that case the waiting ring is a
3291 * victim and we want to be sure we catch the
3292 * right culprit. Then every time we do kick
3293 * the ring, add a small increment to the
3294 * score so that we can catch a batch that is
3295 * being repeatedly kicked and so responsible
3296 * for stalling the machine.
3297 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003298 ring->hangcheck.action = ring_stuck(ring,
3299 acthd);
3300
3301 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003302 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003303 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003304 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003305 break;
3306 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003307 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003308 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003309 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003310 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003311 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003312 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003313 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003314 stuck[i] = true;
3315 break;
3316 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003317 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003318 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03003319 ring->hangcheck.action = HANGCHECK_ACTIVE;
3320
Chris Wilson9107e9d2013-06-10 11:20:20 +01003321 /* Gradually reduce the count so that we catch DoS
3322 * attempts across multiple batches.
3323 */
3324 if (ring->hangcheck.score > 0)
3325 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003326
3327 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01003328 }
3329
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003330 ring->hangcheck.seqno = seqno;
3331 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003332 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003333 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003334
Mika Kuoppala92cab732013-05-24 17:16:07 +03003335 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02003336 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003337 DRM_INFO("%s on %s\n",
3338 stuck[i] ? "stuck" : "no progress",
3339 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01003340 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003341 }
3342 }
3343
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003344 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02003345 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003346
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003347 if (busy_count)
3348 /* Reset timer case chip hangs without another request
3349 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003350 i915_queue_hangcheck(dev);
3351}
3352
3353void i915_queue_hangcheck(struct drm_device *dev)
3354{
3355 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02003356 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003357 return;
3358
3359 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
3360 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003361}
3362
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003363static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003364{
3365 struct drm_i915_private *dev_priv = dev->dev_private;
3366
3367 if (HAS_PCH_NOP(dev))
3368 return;
3369
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003370 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003371
3372 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3373 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003374}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003375
Paulo Zanoni622364b2014-04-01 15:37:22 -03003376/*
3377 * SDEIER is also touched by the interrupt handler to work around missed PCH
3378 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3379 * instead we unconditionally enable all PCH interrupt sources here, but then
3380 * only unmask them as needed with SDEIMR.
3381 *
3382 * This function needs to be called before interrupts are enabled.
3383 */
3384static void ibx_irq_pre_postinstall(struct drm_device *dev)
3385{
3386 struct drm_i915_private *dev_priv = dev->dev_private;
3387
3388 if (HAS_PCH_NOP(dev))
3389 return;
3390
3391 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003392 I915_WRITE(SDEIER, 0xffffffff);
3393 POSTING_READ(SDEIER);
3394}
3395
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003396static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003397{
3398 struct drm_i915_private *dev_priv = dev->dev_private;
3399
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003400 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003401 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003402 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003403}
3404
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405/* drm_dma.h hooks
3406*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003407static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003408{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003409 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003410
Paulo Zanoni0c841212014-04-01 15:37:27 -03003411 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003412
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003413 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003414 if (IS_GEN7(dev))
3415 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003416
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003417 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003418
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003419 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003420}
3421
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003422static void valleyview_irq_preinstall(struct drm_device *dev)
3423{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003424 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003425 int pipe;
3426
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003427 /* VLV magic */
3428 I915_WRITE(VLV_IMR, 0);
3429 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3430 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3431 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3432
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003433 /* and GT */
3434 I915_WRITE(GTIIR, I915_READ(GTIIR));
3435 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003436
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003437 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003438
3439 I915_WRITE(DPINVGTT, 0xff);
3440
3441 I915_WRITE(PORT_HOTPLUG_EN, 0);
3442 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Damien Lespiau055e3932014-08-18 13:49:10 +01003443 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003444 I915_WRITE(PIPESTAT(pipe), 0xffff);
3445 I915_WRITE(VLV_IIR, 0xffffffff);
3446 I915_WRITE(VLV_IMR, 0xffffffff);
3447 I915_WRITE(VLV_IER, 0x0);
3448 POSTING_READ(VLV_IER);
3449}
3450
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003451static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3452{
3453 GEN8_IRQ_RESET_NDX(GT, 0);
3454 GEN8_IRQ_RESET_NDX(GT, 1);
3455 GEN8_IRQ_RESET_NDX(GT, 2);
3456 GEN8_IRQ_RESET_NDX(GT, 3);
3457}
3458
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003459static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003460{
3461 struct drm_i915_private *dev_priv = dev->dev_private;
3462 int pipe;
3463
Ben Widawskyabd58f02013-11-02 21:07:09 -07003464 I915_WRITE(GEN8_MASTER_IRQ, 0);
3465 POSTING_READ(GEN8_MASTER_IRQ);
3466
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003467 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003468
Damien Lespiau055e3932014-08-18 13:49:10 +01003469 for_each_pipe(dev_priv, pipe)
Paulo Zanoni813bde42014-07-04 11:50:29 -03003470 if (intel_display_power_enabled(dev_priv,
3471 POWER_DOMAIN_PIPE(pipe)))
3472 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003473
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003474 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3475 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3476 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003477
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003478 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003479}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003480
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003481void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv)
3482{
3483 unsigned long irqflags;
3484
3485 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3486 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B, dev_priv->de_irq_mask[PIPE_B],
3487 ~dev_priv->de_irq_mask[PIPE_B]);
3488 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C, dev_priv->de_irq_mask[PIPE_C],
3489 ~dev_priv->de_irq_mask[PIPE_C]);
3490 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3491}
3492
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003493static void cherryview_irq_preinstall(struct drm_device *dev)
3494{
3495 struct drm_i915_private *dev_priv = dev->dev_private;
3496 int pipe;
3497
3498 I915_WRITE(GEN8_MASTER_IRQ, 0);
3499 POSTING_READ(GEN8_MASTER_IRQ);
3500
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003501 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003502
3503 GEN5_IRQ_RESET(GEN8_PCU_);
3504
3505 POSTING_READ(GEN8_PCU_IIR);
3506
3507 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3508
3509 I915_WRITE(PORT_HOTPLUG_EN, 0);
3510 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3511
Damien Lespiau055e3932014-08-18 13:49:10 +01003512 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003513 I915_WRITE(PIPESTAT(pipe), 0xffff);
3514
3515 I915_WRITE(VLV_IMR, 0xffffffff);
3516 I915_WRITE(VLV_IER, 0x0);
3517 I915_WRITE(VLV_IIR, 0xffffffff);
3518 POSTING_READ(VLV_IIR);
3519}
3520
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003521static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003522{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003523 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003524 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02003525 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07003526
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003527 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003528 hotplug_irqs = SDE_HOTPLUG_MASK;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003529 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003530 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003531 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003532 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003533 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003534 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003535 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003536 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003537 }
3538
Daniel Vetterfee884e2013-07-04 23:35:21 +02003539 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003540
3541 /*
3542 * Enable digital hotplug on the PCH, and configure the DP short pulse
3543 * duration to 2ms (which is the minimum in the Display Port spec)
3544 *
3545 * This register is the same on all known PCH chips.
3546 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003547 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3548 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3549 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3550 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3551 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3552 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3553}
3554
Paulo Zanonid46da432013-02-08 17:35:15 -02003555static void ibx_irq_postinstall(struct drm_device *dev)
3556{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003557 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003558 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003559
Daniel Vetter692a04c2013-05-29 21:43:05 +02003560 if (HAS_PCH_NOP(dev))
3561 return;
3562
Paulo Zanoni105b1222014-04-01 15:37:17 -03003563 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003564 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003565 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003566 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003567
Paulo Zanoni337ba012014-04-01 15:37:16 -03003568 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003569 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003570}
3571
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003572static void gen5_gt_irq_postinstall(struct drm_device *dev)
3573{
3574 struct drm_i915_private *dev_priv = dev->dev_private;
3575 u32 pm_irqs, gt_irqs;
3576
3577 pm_irqs = gt_irqs = 0;
3578
3579 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003580 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003581 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003582 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3583 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003584 }
3585
3586 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3587 if (IS_GEN5(dev)) {
3588 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3589 ILK_BSD_USER_INTERRUPT;
3590 } else {
3591 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3592 }
3593
Paulo Zanoni35079892014-04-01 15:37:15 -03003594 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003595
3596 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303597 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003598
3599 if (HAS_VEBOX(dev))
3600 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3601
Paulo Zanoni605cd252013-08-06 18:57:15 -03003602 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003603 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003604 }
3605}
3606
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003607static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003608{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003609 unsigned long irqflags;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003610 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003611 u32 display_mask, extra_mask;
3612
3613 if (INTEL_INFO(dev)->gen >= 7) {
3614 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3615 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3616 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003617 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003618 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003619 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003620 } else {
3621 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3622 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003623 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003624 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3625 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003626 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3627 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003628 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003629
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003630 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003631
Paulo Zanoni0c841212014-04-01 15:37:27 -03003632 I915_WRITE(HWSTAM, 0xeffe);
3633
Paulo Zanoni622364b2014-04-01 15:37:22 -03003634 ibx_irq_pre_postinstall(dev);
3635
Paulo Zanoni35079892014-04-01 15:37:15 -03003636 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003637
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003638 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003639
Paulo Zanonid46da432013-02-08 17:35:15 -02003640 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003641
Jesse Barnesf97108d2010-01-29 11:27:07 -08003642 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003643 /* Enable PCU event interrupts
3644 *
3645 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003646 * setup is guaranteed to run in single-threaded context. But we
3647 * need it to make the assert_spin_locked happy. */
3648 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003649 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003650 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003651 }
3652
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003653 return 0;
3654}
3655
Imre Deakf8b79e52014-03-04 19:23:07 +02003656static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3657{
3658 u32 pipestat_mask;
3659 u32 iir_mask;
3660
3661 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3662 PIPE_FIFO_UNDERRUN_STATUS;
3663
3664 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3665 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3666 POSTING_READ(PIPESTAT(PIPE_A));
3667
3668 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3669 PIPE_CRC_DONE_INTERRUPT_STATUS;
3670
3671 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3672 PIPE_GMBUS_INTERRUPT_STATUS);
3673 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3674
3675 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3676 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3677 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3678 dev_priv->irq_mask &= ~iir_mask;
3679
3680 I915_WRITE(VLV_IIR, iir_mask);
3681 I915_WRITE(VLV_IIR, iir_mask);
3682 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3683 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3684 POSTING_READ(VLV_IER);
3685}
3686
3687static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3688{
3689 u32 pipestat_mask;
3690 u32 iir_mask;
3691
3692 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3693 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003694 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003695
3696 dev_priv->irq_mask |= iir_mask;
3697 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3698 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3699 I915_WRITE(VLV_IIR, iir_mask);
3700 I915_WRITE(VLV_IIR, iir_mask);
3701 POSTING_READ(VLV_IIR);
3702
3703 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3704 PIPE_CRC_DONE_INTERRUPT_STATUS;
3705
3706 i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3707 PIPE_GMBUS_INTERRUPT_STATUS);
3708 i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3709
3710 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3711 PIPE_FIFO_UNDERRUN_STATUS;
3712 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3713 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3714 POSTING_READ(PIPESTAT(PIPE_A));
3715}
3716
3717void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3718{
3719 assert_spin_locked(&dev_priv->irq_lock);
3720
3721 if (dev_priv->display_irqs_enabled)
3722 return;
3723
3724 dev_priv->display_irqs_enabled = true;
3725
3726 if (dev_priv->dev->irq_enabled)
3727 valleyview_display_irqs_install(dev_priv);
3728}
3729
3730void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3731{
3732 assert_spin_locked(&dev_priv->irq_lock);
3733
3734 if (!dev_priv->display_irqs_enabled)
3735 return;
3736
3737 dev_priv->display_irqs_enabled = false;
3738
3739 if (dev_priv->dev->irq_enabled)
3740 valleyview_display_irqs_uninstall(dev_priv);
3741}
3742
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003743static int valleyview_irq_postinstall(struct drm_device *dev)
3744{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003745 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003746 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003747
Imre Deakf8b79e52014-03-04 19:23:07 +02003748 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003749
Daniel Vetter20afbda2012-12-11 14:05:07 +01003750 I915_WRITE(PORT_HOTPLUG_EN, 0);
3751 POSTING_READ(PORT_HOTPLUG_EN);
3752
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003753 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003754 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003755 I915_WRITE(VLV_IIR, 0xffffffff);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003756 POSTING_READ(VLV_IER);
3757
Daniel Vetterb79480b2013-06-27 17:52:10 +02003758 /* Interrupt setup is already guaranteed to be single-threaded, this is
3759 * just to make the assert_spin_locked check happy. */
3760 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deakf8b79e52014-03-04 19:23:07 +02003761 if (dev_priv->display_irqs_enabled)
3762 valleyview_display_irqs_install(dev_priv);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003763 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003764
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003765 I915_WRITE(VLV_IIR, 0xffffffff);
3766 I915_WRITE(VLV_IIR, 0xffffffff);
3767
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003768 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003769
3770 /* ack & enable invalid PTE error interrupts */
3771#if 0 /* FIXME: add support to irq handler for checking these bits */
3772 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3773 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3774#endif
3775
3776 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003777
3778 return 0;
3779}
3780
Ben Widawskyabd58f02013-11-02 21:07:09 -07003781static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3782{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003783 /* These are interrupts we'll toggle with the ring mask register */
3784 uint32_t gt_interrupts[] = {
3785 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003786 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003787 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003788 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3789 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003790 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003791 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3792 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3793 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003794 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003795 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3796 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003797 };
3798
Ben Widawsky09610212014-05-15 20:58:08 +03003799 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303800 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3801 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
3802 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, dev_priv->pm_rps_events);
3803 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003804}
3805
3806static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3807{
Damien Lespiaud0e1f1c2014-04-08 01:22:44 +01003808 uint32_t de_pipe_masked = GEN8_PIPE_PRIMARY_FLIP_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003809 GEN8_PIPE_CDCLK_CRC_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003810 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Daniel Vetter5c673b62014-03-07 20:34:46 +01003811 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3812 GEN8_PIPE_FIFO_UNDERRUN;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003813 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003814 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3815 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3816 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003817
Damien Lespiau055e3932014-08-18 13:49:10 +01003818 for_each_pipe(dev_priv, pipe)
Paulo Zanoni813bde42014-07-04 11:50:29 -03003819 if (intel_display_power_enabled(dev_priv,
3820 POWER_DOMAIN_PIPE(pipe)))
3821 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3822 dev_priv->de_irq_mask[pipe],
3823 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003824
Paulo Zanoni35079892014-04-01 15:37:15 -03003825 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003826}
3827
3828static int gen8_irq_postinstall(struct drm_device *dev)
3829{
3830 struct drm_i915_private *dev_priv = dev->dev_private;
3831
Paulo Zanoni622364b2014-04-01 15:37:22 -03003832 ibx_irq_pre_postinstall(dev);
3833
Ben Widawskyabd58f02013-11-02 21:07:09 -07003834 gen8_gt_irq_postinstall(dev_priv);
3835 gen8_de_irq_postinstall(dev_priv);
3836
3837 ibx_irq_postinstall(dev);
3838
3839 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3840 POSTING_READ(GEN8_MASTER_IRQ);
3841
3842 return 0;
3843}
3844
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003845static int cherryview_irq_postinstall(struct drm_device *dev)
3846{
3847 struct drm_i915_private *dev_priv = dev->dev_private;
3848 u32 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3849 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003850 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä3278f672014-04-09 13:28:49 +03003851 I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3852 u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
3853 PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003854 unsigned long irqflags;
3855 int pipe;
3856
3857 /*
3858 * Leave vblank interrupts masked initially. enable/disable will
3859 * toggle them based on usage.
3860 */
Ville Syrjälä3278f672014-04-09 13:28:49 +03003861 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003862
Damien Lespiau055e3932014-08-18 13:49:10 +01003863 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003864 I915_WRITE(PIPESTAT(pipe), 0xffff);
3865
3866 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä3278f672014-04-09 13:28:49 +03003867 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
Damien Lespiau055e3932014-08-18 13:49:10 +01003868 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003869 i915_enable_pipestat(dev_priv, pipe, pipestat_enable);
3870 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3871
3872 I915_WRITE(VLV_IIR, 0xffffffff);
3873 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3874 I915_WRITE(VLV_IER, enable_mask);
3875
3876 gen8_gt_irq_postinstall(dev_priv);
3877
3878 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3879 POSTING_READ(GEN8_MASTER_IRQ);
3880
3881 return 0;
3882}
3883
Ben Widawskyabd58f02013-11-02 21:07:09 -07003884static void gen8_irq_uninstall(struct drm_device *dev)
3885{
3886 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003887
3888 if (!dev_priv)
3889 return;
3890
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003891 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003892}
3893
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003894static void valleyview_irq_uninstall(struct drm_device *dev)
3895{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003896 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakf8b79e52014-03-04 19:23:07 +02003897 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003898 int pipe;
3899
3900 if (!dev_priv)
3901 return;
3902
Imre Deak843d0e72014-04-14 20:24:23 +03003903 I915_WRITE(VLV_MASTER_IER, 0);
3904
Damien Lespiau055e3932014-08-18 13:49:10 +01003905 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003906 I915_WRITE(PIPESTAT(pipe), 0xffff);
3907
3908 I915_WRITE(HWSTAM, 0xffffffff);
3909 I915_WRITE(PORT_HOTPLUG_EN, 0);
3910 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Imre Deakf8b79e52014-03-04 19:23:07 +02003911
3912 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3913 if (dev_priv->display_irqs_enabled)
3914 valleyview_display_irqs_uninstall(dev_priv);
3915 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3916
3917 dev_priv->irq_mask = 0;
3918
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003919 I915_WRITE(VLV_IIR, 0xffffffff);
3920 I915_WRITE(VLV_IMR, 0xffffffff);
3921 I915_WRITE(VLV_IER, 0x0);
3922 POSTING_READ(VLV_IER);
3923}
3924
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003925static void cherryview_irq_uninstall(struct drm_device *dev)
3926{
3927 struct drm_i915_private *dev_priv = dev->dev_private;
3928 int pipe;
3929
3930 if (!dev_priv)
3931 return;
3932
3933 I915_WRITE(GEN8_MASTER_IRQ, 0);
3934 POSTING_READ(GEN8_MASTER_IRQ);
3935
3936#define GEN8_IRQ_FINI_NDX(type, which) \
3937do { \
3938 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3939 I915_WRITE(GEN8_##type##_IER(which), 0); \
3940 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3941 POSTING_READ(GEN8_##type##_IIR(which)); \
3942 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3943} while (0)
3944
3945#define GEN8_IRQ_FINI(type) \
3946do { \
3947 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3948 I915_WRITE(GEN8_##type##_IER, 0); \
3949 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3950 POSTING_READ(GEN8_##type##_IIR); \
3951 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3952} while (0)
3953
3954 GEN8_IRQ_FINI_NDX(GT, 0);
3955 GEN8_IRQ_FINI_NDX(GT, 1);
3956 GEN8_IRQ_FINI_NDX(GT, 2);
3957 GEN8_IRQ_FINI_NDX(GT, 3);
3958
3959 GEN8_IRQ_FINI(PCU);
3960
3961#undef GEN8_IRQ_FINI
3962#undef GEN8_IRQ_FINI_NDX
3963
3964 I915_WRITE(PORT_HOTPLUG_EN, 0);
3965 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3966
Damien Lespiau055e3932014-08-18 13:49:10 +01003967 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003968 I915_WRITE(PIPESTAT(pipe), 0xffff);
3969
3970 I915_WRITE(VLV_IMR, 0xffffffff);
3971 I915_WRITE(VLV_IER, 0x0);
3972 I915_WRITE(VLV_IIR, 0xffffffff);
3973 POSTING_READ(VLV_IIR);
3974}
3975
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003976static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003977{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003978 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003979
3980 if (!dev_priv)
3981 return;
3982
Paulo Zanonibe30b292014-04-01 15:37:25 -03003983 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003984}
3985
Chris Wilsonc2798b12012-04-22 21:13:57 +01003986static void i8xx_irq_preinstall(struct drm_device * dev)
3987{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003988 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003989 int pipe;
3990
Damien Lespiau055e3932014-08-18 13:49:10 +01003991 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003992 I915_WRITE(PIPESTAT(pipe), 0);
3993 I915_WRITE16(IMR, 0xffff);
3994 I915_WRITE16(IER, 0x0);
3995 POSTING_READ16(IER);
3996}
3997
3998static int i8xx_irq_postinstall(struct drm_device *dev)
3999{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004000 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02004001 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004002
Chris Wilsonc2798b12012-04-22 21:13:57 +01004003 I915_WRITE16(EMR,
4004 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4005
4006 /* Unmask the interrupts that we always want on. */
4007 dev_priv->irq_mask =
4008 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4009 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4010 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4011 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4012 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4013 I915_WRITE16(IMR, dev_priv->irq_mask);
4014
4015 I915_WRITE16(IER,
4016 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4017 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4018 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4019 I915_USER_INTERRUPT);
4020 POSTING_READ16(IER);
4021
Daniel Vetter379ef822013-10-16 22:55:56 +02004022 /* Interrupt setup is already guaranteed to be single-threaded, this is
4023 * just to make the assert_spin_locked check happy. */
4024 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02004025 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4026 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02004027 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4028
Chris Wilsonc2798b12012-04-22 21:13:57 +01004029 return 0;
4030}
4031
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004032/*
4033 * Returns true when a page flip has completed.
4034 */
4035static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004036 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004037{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004038 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004039 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004040
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004041 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004042 return false;
4043
4044 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004045 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004046
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004047 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004048
4049 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4050 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4051 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4052 * the flip is completed (no longer pending). Since this doesn't raise
4053 * an interrupt per se, we watch for the change at vblank.
4054 */
4055 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004056 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004057
4058 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004059 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004060
4061check_page_flip:
4062 intel_check_page_flip(dev, pipe);
4063 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004064}
4065
Daniel Vetterff1f5252012-10-02 15:10:55 +02004066static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004067{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004068 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004069 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004070 u16 iir, new_iir;
4071 u32 pipe_stats[2];
4072 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004073 int pipe;
4074 u16 flip_mask =
4075 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4076 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
4077
Chris Wilsonc2798b12012-04-22 21:13:57 +01004078 iir = I915_READ16(IIR);
4079 if (iir == 0)
4080 return IRQ_NONE;
4081
4082 while (iir & ~flip_mask) {
4083 /* Can't rely on pipestat interrupt bit in iir as it might
4084 * have been cleared after the pipestat interrupt was received.
4085 * It doesn't set the bit in iir again, but it still produces
4086 * interrupts (for non-MSI).
4087 */
4088 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4089 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004090 i915_handle_error(dev, false,
4091 "Command parser error, iir 0x%08x",
4092 iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004093
Damien Lespiau055e3932014-08-18 13:49:10 +01004094 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004095 int reg = PIPESTAT(pipe);
4096 pipe_stats[pipe] = I915_READ(reg);
4097
4098 /*
4099 * Clear the PIPE*STAT regs before the IIR
4100 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004101 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004102 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004103 }
4104 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4105
4106 I915_WRITE16(IIR, iir & ~flip_mask);
4107 new_iir = I915_READ16(IIR); /* Flush posted writes */
4108
Daniel Vetterd05c6172012-04-26 23:28:09 +02004109 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004110
4111 if (iir & I915_USER_INTERRUPT)
4112 notify_ring(dev, &dev_priv->ring[RCS]);
4113
Damien Lespiau055e3932014-08-18 13:49:10 +01004114 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004115 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004116 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004117 plane = !plane;
4118
Daniel Vetter4356d582013-10-16 22:55:55 +02004119 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004120 i8xx_handle_vblank(dev, plane, pipe, iir))
4121 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004122
Daniel Vetter4356d582013-10-16 22:55:55 +02004123 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004124 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004125
4126 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4127 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004128 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02004129 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004130
4131 iir = new_iir;
4132 }
4133
4134 return IRQ_HANDLED;
4135}
4136
4137static void i8xx_irq_uninstall(struct drm_device * dev)
4138{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004139 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004140 int pipe;
4141
Damien Lespiau055e3932014-08-18 13:49:10 +01004142 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004143 /* Clear enable bits; then clear status bits */
4144 I915_WRITE(PIPESTAT(pipe), 0);
4145 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4146 }
4147 I915_WRITE16(IMR, 0xffff);
4148 I915_WRITE16(IER, 0x0);
4149 I915_WRITE16(IIR, I915_READ16(IIR));
4150}
4151
Chris Wilsona266c7d2012-04-24 22:59:44 +01004152static void i915_irq_preinstall(struct drm_device * dev)
4153{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004154 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004155 int pipe;
4156
Chris Wilsona266c7d2012-04-24 22:59:44 +01004157 if (I915_HAS_HOTPLUG(dev)) {
4158 I915_WRITE(PORT_HOTPLUG_EN, 0);
4159 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4160 }
4161
Chris Wilson00d98eb2012-04-24 22:59:48 +01004162 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004163 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004164 I915_WRITE(PIPESTAT(pipe), 0);
4165 I915_WRITE(IMR, 0xffffffff);
4166 I915_WRITE(IER, 0x0);
4167 POSTING_READ(IER);
4168}
4169
4170static int i915_irq_postinstall(struct drm_device *dev)
4171{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004172 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01004173 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02004174 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004175
Chris Wilson38bde182012-04-24 22:59:50 +01004176 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4177
4178 /* Unmask the interrupts that we always want on. */
4179 dev_priv->irq_mask =
4180 ~(I915_ASLE_INTERRUPT |
4181 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4182 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4183 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4184 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4185 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4186
4187 enable_mask =
4188 I915_ASLE_INTERRUPT |
4189 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4190 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4191 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4192 I915_USER_INTERRUPT;
4193
Chris Wilsona266c7d2012-04-24 22:59:44 +01004194 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01004195 I915_WRITE(PORT_HOTPLUG_EN, 0);
4196 POSTING_READ(PORT_HOTPLUG_EN);
4197
Chris Wilsona266c7d2012-04-24 22:59:44 +01004198 /* Enable in IER... */
4199 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4200 /* and unmask in IMR */
4201 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4202 }
4203
Chris Wilsona266c7d2012-04-24 22:59:44 +01004204 I915_WRITE(IMR, dev_priv->irq_mask);
4205 I915_WRITE(IER, enable_mask);
4206 POSTING_READ(IER);
4207
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004208 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004209
Daniel Vetter379ef822013-10-16 22:55:56 +02004210 /* Interrupt setup is already guaranteed to be single-threaded, this is
4211 * just to make the assert_spin_locked check happy. */
4212 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02004213 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4214 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02004215 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4216
Daniel Vetter20afbda2012-12-11 14:05:07 +01004217 return 0;
4218}
4219
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004220/*
4221 * Returns true when a page flip has completed.
4222 */
4223static bool i915_handle_vblank(struct drm_device *dev,
4224 int plane, int pipe, u32 iir)
4225{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004226 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004227 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4228
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004229 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004230 return false;
4231
4232 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004233 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004234
4235 intel_prepare_page_flip(dev, plane);
4236
4237 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4238 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4239 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4240 * the flip is completed (no longer pending). Since this doesn't raise
4241 * an interrupt per se, we watch for the change at vblank.
4242 */
4243 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004244 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004245
4246 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004247 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004248
4249check_page_flip:
4250 intel_check_page_flip(dev, pipe);
4251 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004252}
4253
Daniel Vetterff1f5252012-10-02 15:10:55 +02004254static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004255{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004256 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004257 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01004258 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004259 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01004260 u32 flip_mask =
4261 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4262 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004263 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004264
Chris Wilsona266c7d2012-04-24 22:59:44 +01004265 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004266 do {
4267 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004268 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004269
4270 /* Can't rely on pipestat interrupt bit in iir as it might
4271 * have been cleared after the pipestat interrupt was received.
4272 * It doesn't set the bit in iir again, but it still produces
4273 * interrupts (for non-MSI).
4274 */
4275 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4276 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004277 i915_handle_error(dev, false,
4278 "Command parser error, iir 0x%08x",
4279 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004280
Damien Lespiau055e3932014-08-18 13:49:10 +01004281 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004282 int reg = PIPESTAT(pipe);
4283 pipe_stats[pipe] = I915_READ(reg);
4284
Chris Wilson38bde182012-04-24 22:59:50 +01004285 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004286 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004287 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004288 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004289 }
4290 }
4291 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4292
4293 if (!irq_received)
4294 break;
4295
Chris Wilsona266c7d2012-04-24 22:59:44 +01004296 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004297 if (I915_HAS_HOTPLUG(dev) &&
4298 iir & I915_DISPLAY_PORT_INTERRUPT)
4299 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004300
Chris Wilson38bde182012-04-24 22:59:50 +01004301 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004302 new_iir = I915_READ(IIR); /* Flush posted writes */
4303
Chris Wilsona266c7d2012-04-24 22:59:44 +01004304 if (iir & I915_USER_INTERRUPT)
4305 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004306
Damien Lespiau055e3932014-08-18 13:49:10 +01004307 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01004308 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004309 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01004310 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02004311
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004312 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4313 i915_handle_vblank(dev, plane, pipe, iir))
4314 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004315
4316 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4317 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004318
4319 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004320 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004321
4322 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4323 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004324 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004325 }
4326
Chris Wilsona266c7d2012-04-24 22:59:44 +01004327 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4328 intel_opregion_asle_intr(dev);
4329
4330 /* With MSI, interrupts are only generated when iir
4331 * transitions from zero to nonzero. If another bit got
4332 * set while we were handling the existing iir bits, then
4333 * we would never get another interrupt.
4334 *
4335 * This is fine on non-MSI as well, as if we hit this path
4336 * we avoid exiting the interrupt handler only to generate
4337 * another one.
4338 *
4339 * Note that for MSI this could cause a stray interrupt report
4340 * if an interrupt landed in the time between writing IIR and
4341 * the posting read. This should be rare enough to never
4342 * trigger the 99% of 100,000 interrupts test for disabling
4343 * stray interrupts.
4344 */
Chris Wilson38bde182012-04-24 22:59:50 +01004345 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004346 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004347 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004348
Daniel Vetterd05c6172012-04-26 23:28:09 +02004349 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004350
Chris Wilsona266c7d2012-04-24 22:59:44 +01004351 return ret;
4352}
4353
4354static void i915_irq_uninstall(struct drm_device * dev)
4355{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004356 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004357 int pipe;
4358
Chris Wilsona266c7d2012-04-24 22:59:44 +01004359 if (I915_HAS_HOTPLUG(dev)) {
4360 I915_WRITE(PORT_HOTPLUG_EN, 0);
4361 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4362 }
4363
Chris Wilson00d98eb2012-04-24 22:59:48 +01004364 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004365 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004366 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004367 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004368 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4369 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004370 I915_WRITE(IMR, 0xffffffff);
4371 I915_WRITE(IER, 0x0);
4372
Chris Wilsona266c7d2012-04-24 22:59:44 +01004373 I915_WRITE(IIR, I915_READ(IIR));
4374}
4375
4376static void i965_irq_preinstall(struct drm_device * dev)
4377{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004378 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004379 int pipe;
4380
Chris Wilsonadca4732012-05-11 18:01:31 +01004381 I915_WRITE(PORT_HOTPLUG_EN, 0);
4382 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004383
4384 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004385 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004386 I915_WRITE(PIPESTAT(pipe), 0);
4387 I915_WRITE(IMR, 0xffffffff);
4388 I915_WRITE(IER, 0x0);
4389 POSTING_READ(IER);
4390}
4391
4392static int i965_irq_postinstall(struct drm_device *dev)
4393{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004394 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004395 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004396 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02004397 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004398
Chris Wilsona266c7d2012-04-24 22:59:44 +01004399 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004400 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004401 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004402 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4403 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4404 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4405 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4406 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4407
4408 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004409 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4410 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004411 enable_mask |= I915_USER_INTERRUPT;
4412
4413 if (IS_G4X(dev))
4414 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004415
Daniel Vetterb79480b2013-06-27 17:52:10 +02004416 /* Interrupt setup is already guaranteed to be single-threaded, this is
4417 * just to make the assert_spin_locked check happy. */
4418 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02004419 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4420 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4421 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterb79480b2013-06-27 17:52:10 +02004422 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004423
Chris Wilsona266c7d2012-04-24 22:59:44 +01004424 /*
4425 * Enable some error detection, note the instruction error mask
4426 * bit is reserved, so we leave it masked.
4427 */
4428 if (IS_G4X(dev)) {
4429 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4430 GM45_ERROR_MEM_PRIV |
4431 GM45_ERROR_CP_PRIV |
4432 I915_ERROR_MEMORY_REFRESH);
4433 } else {
4434 error_mask = ~(I915_ERROR_PAGE_TABLE |
4435 I915_ERROR_MEMORY_REFRESH);
4436 }
4437 I915_WRITE(EMR, error_mask);
4438
4439 I915_WRITE(IMR, dev_priv->irq_mask);
4440 I915_WRITE(IER, enable_mask);
4441 POSTING_READ(IER);
4442
Daniel Vetter20afbda2012-12-11 14:05:07 +01004443 I915_WRITE(PORT_HOTPLUG_EN, 0);
4444 POSTING_READ(PORT_HOTPLUG_EN);
4445
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004446 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004447
4448 return 0;
4449}
4450
Egbert Eichbac56d52013-02-25 12:06:51 -05004451static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004452{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004453 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichcd569ae2013-04-16 13:36:57 +02004454 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004455 u32 hotplug_en;
4456
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004457 assert_spin_locked(&dev_priv->irq_lock);
4458
Egbert Eichbac56d52013-02-25 12:06:51 -05004459 if (I915_HAS_HOTPLUG(dev)) {
4460 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4461 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4462 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05004463 /* enable bits are the same for all generations */
Damien Lespiaub2784e12014-08-05 11:29:37 +01004464 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02004465 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4466 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05004467 /* Programming the CRT detection parameters tends
4468 to generate a spurious hotplug event about three
4469 seconds later. So just do it once.
4470 */
4471 if (IS_G4X(dev))
4472 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01004473 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05004474 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004475
Egbert Eichbac56d52013-02-25 12:06:51 -05004476 /* Ignore TV since it's buggy */
4477 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4478 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004479}
4480
Daniel Vetterff1f5252012-10-02 15:10:55 +02004481static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004482{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004483 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004484 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004485 u32 iir, new_iir;
4486 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004487 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004488 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004489 u32 flip_mask =
4490 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4491 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004492
Chris Wilsona266c7d2012-04-24 22:59:44 +01004493 iir = I915_READ(IIR);
4494
Chris Wilsona266c7d2012-04-24 22:59:44 +01004495 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004496 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004497 bool blc_event = false;
4498
Chris Wilsona266c7d2012-04-24 22:59:44 +01004499 /* Can't rely on pipestat interrupt bit in iir as it might
4500 * have been cleared after the pipestat interrupt was received.
4501 * It doesn't set the bit in iir again, but it still produces
4502 * interrupts (for non-MSI).
4503 */
4504 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4505 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004506 i915_handle_error(dev, false,
4507 "Command parser error, iir 0x%08x",
4508 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004509
Damien Lespiau055e3932014-08-18 13:49:10 +01004510 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004511 int reg = PIPESTAT(pipe);
4512 pipe_stats[pipe] = I915_READ(reg);
4513
4514 /*
4515 * Clear the PIPE*STAT regs before the IIR
4516 */
4517 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004518 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004519 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004520 }
4521 }
4522 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4523
4524 if (!irq_received)
4525 break;
4526
4527 ret = IRQ_HANDLED;
4528
4529 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004530 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4531 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004532
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004533 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004534 new_iir = I915_READ(IIR); /* Flush posted writes */
4535
Chris Wilsona266c7d2012-04-24 22:59:44 +01004536 if (iir & I915_USER_INTERRUPT)
4537 notify_ring(dev, &dev_priv->ring[RCS]);
4538 if (iir & I915_BSD_USER_INTERRUPT)
4539 notify_ring(dev, &dev_priv->ring[VCS]);
4540
Damien Lespiau055e3932014-08-18 13:49:10 +01004541 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004542 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004543 i915_handle_vblank(dev, pipe, pipe, iir))
4544 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004545
4546 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4547 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004548
4549 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004550 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004551
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004552 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4553 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004554 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004555 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004556
4557 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4558 intel_opregion_asle_intr(dev);
4559
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004560 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4561 gmbus_irq_handler(dev);
4562
Chris Wilsona266c7d2012-04-24 22:59:44 +01004563 /* With MSI, interrupts are only generated when iir
4564 * transitions from zero to nonzero. If another bit got
4565 * set while we were handling the existing iir bits, then
4566 * we would never get another interrupt.
4567 *
4568 * This is fine on non-MSI as well, as if we hit this path
4569 * we avoid exiting the interrupt handler only to generate
4570 * another one.
4571 *
4572 * Note that for MSI this could cause a stray interrupt report
4573 * if an interrupt landed in the time between writing IIR and
4574 * the posting read. This should be rare enough to never
4575 * trigger the 99% of 100,000 interrupts test for disabling
4576 * stray interrupts.
4577 */
4578 iir = new_iir;
4579 }
4580
Daniel Vetterd05c6172012-04-26 23:28:09 +02004581 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01004582
Chris Wilsona266c7d2012-04-24 22:59:44 +01004583 return ret;
4584}
4585
4586static void i965_irq_uninstall(struct drm_device * dev)
4587{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004588 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004589 int pipe;
4590
4591 if (!dev_priv)
4592 return;
4593
Chris Wilsonadca4732012-05-11 18:01:31 +01004594 I915_WRITE(PORT_HOTPLUG_EN, 0);
4595 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004596
4597 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004598 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004599 I915_WRITE(PIPESTAT(pipe), 0);
4600 I915_WRITE(IMR, 0xffffffff);
4601 I915_WRITE(IER, 0x0);
4602
Damien Lespiau055e3932014-08-18 13:49:10 +01004603 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004604 I915_WRITE(PIPESTAT(pipe),
4605 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4606 I915_WRITE(IIR, I915_READ(IIR));
4607}
4608
Imre Deak63237512014-08-18 15:37:02 +03004609static void intel_hpd_irq_reenable(struct work_struct *work)
Egbert Eichac4c16c2013-04-16 13:36:58 +02004610{
Imre Deak63237512014-08-18 15:37:02 +03004611 struct drm_i915_private *dev_priv =
4612 container_of(work, typeof(*dev_priv),
4613 hotplug_reenable_work.work);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004614 struct drm_device *dev = dev_priv->dev;
4615 struct drm_mode_config *mode_config = &dev->mode_config;
4616 unsigned long irqflags;
4617 int i;
4618
Imre Deak63237512014-08-18 15:37:02 +03004619 intel_runtime_pm_get(dev_priv);
4620
Egbert Eichac4c16c2013-04-16 13:36:58 +02004621 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4622 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4623 struct drm_connector *connector;
4624
4625 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4626 continue;
4627
4628 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4629
4630 list_for_each_entry(connector, &mode_config->connector_list, head) {
4631 struct intel_connector *intel_connector = to_intel_connector(connector);
4632
4633 if (intel_connector->encoder->hpd_pin == i) {
4634 if (connector->polled != intel_connector->polled)
4635 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03004636 connector->name);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004637 connector->polled = intel_connector->polled;
4638 if (!connector->polled)
4639 connector->polled = DRM_CONNECTOR_POLL_HPD;
4640 }
4641 }
4642 }
4643 if (dev_priv->display.hpd_irq_setup)
4644 dev_priv->display.hpd_irq_setup(dev);
4645 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Imre Deak63237512014-08-18 15:37:02 +03004646
4647 intel_runtime_pm_put(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004648}
4649
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004650void intel_irq_init(struct drm_device *dev)
4651{
Chris Wilson8b2e3262012-04-24 22:59:41 +01004652 struct drm_i915_private *dev_priv = dev->dev_private;
4653
4654 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Dave Airlie13cf5502014-06-18 11:29:35 +10004655 INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004656 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004657 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004658 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004659
Deepak Sa6706b42014-03-15 20:23:22 +05304660 /* Let's track the enabled rps events */
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004661 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev))
4662 /* WaGsvRC0ResidencyMethod:vlv */
Deepak S31685c22014-07-03 17:33:01 -04004663 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
4664 else
4665 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304666
Daniel Vetter99584db2012-11-14 17:14:04 +01004667 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4668 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004669 (unsigned long) dev);
Imre Deak63237512014-08-18 15:37:02 +03004670 INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work,
4671 intel_hpd_irq_reenable);
Daniel Vetter61bac782012-12-01 21:03:21 +01004672
Tomas Janousek97a19a22012-12-08 13:48:13 +01004673 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004674
Jesse Barnes95f25be2014-06-20 09:29:22 -07004675 /* Haven't installed the IRQ handler yet */
4676 dev_priv->pm._irqs_disabled = true;
4677
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004678 if (IS_GEN2(dev)) {
4679 dev->max_vblank_count = 0;
4680 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4681 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004682 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4683 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004684 } else {
4685 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4686 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004687 }
4688
Ville Syrjälä21da2702014-08-06 14:49:55 +03004689 /*
4690 * Opt out of the vblank disable timer on everything except gen2.
4691 * Gen2 doesn't have a hardware frame counter and so depends on
4692 * vblank interrupts to produce sane vblank seuquence numbers.
4693 */
4694 if (!IS_GEN2(dev))
4695 dev->vblank_disable_immediate = true;
4696
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004697 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004698 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004699 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4700 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004701
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004702 if (IS_CHERRYVIEW(dev)) {
4703 dev->driver->irq_handler = cherryview_irq_handler;
4704 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4705 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4706 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4707 dev->driver->enable_vblank = valleyview_enable_vblank;
4708 dev->driver->disable_vblank = valleyview_disable_vblank;
4709 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4710 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004711 dev->driver->irq_handler = valleyview_irq_handler;
4712 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4713 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4714 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4715 dev->driver->enable_vblank = valleyview_enable_vblank;
4716 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004717 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004718 } else if (IS_GEN8(dev)) {
4719 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004720 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004721 dev->driver->irq_postinstall = gen8_irq_postinstall;
4722 dev->driver->irq_uninstall = gen8_irq_uninstall;
4723 dev->driver->enable_vblank = gen8_enable_vblank;
4724 dev->driver->disable_vblank = gen8_disable_vblank;
4725 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004726 } else if (HAS_PCH_SPLIT(dev)) {
4727 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004728 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004729 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4730 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4731 dev->driver->enable_vblank = ironlake_enable_vblank;
4732 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004733 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004734 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004735 if (INTEL_INFO(dev)->gen == 2) {
4736 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4737 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4738 dev->driver->irq_handler = i8xx_irq_handler;
4739 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004740 } else if (INTEL_INFO(dev)->gen == 3) {
4741 dev->driver->irq_preinstall = i915_irq_preinstall;
4742 dev->driver->irq_postinstall = i915_irq_postinstall;
4743 dev->driver->irq_uninstall = i915_irq_uninstall;
4744 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004745 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004746 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004747 dev->driver->irq_preinstall = i965_irq_preinstall;
4748 dev->driver->irq_postinstall = i965_irq_postinstall;
4749 dev->driver->irq_uninstall = i965_irq_uninstall;
4750 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004751 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004752 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004753 dev->driver->enable_vblank = i915_enable_vblank;
4754 dev->driver->disable_vblank = i915_disable_vblank;
4755 }
4756}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004757
4758void intel_hpd_init(struct drm_device *dev)
4759{
4760 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02004761 struct drm_mode_config *mode_config = &dev->mode_config;
4762 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004763 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02004764 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004765
Egbert Eich821450c2013-04-16 13:36:55 +02004766 for (i = 1; i < HPD_NUM_PINS; i++) {
4767 dev_priv->hpd_stats[i].hpd_cnt = 0;
4768 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4769 }
4770 list_for_each_entry(connector, &mode_config->connector_list, head) {
4771 struct intel_connector *intel_connector = to_intel_connector(connector);
4772 connector->polled = intel_connector->polled;
Dave Airlie0e32b392014-05-02 14:02:48 +10004773 if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4774 connector->polled = DRM_CONNECTOR_POLL_HPD;
4775 if (intel_connector->mst_port)
Egbert Eich821450c2013-04-16 13:36:55 +02004776 connector->polled = DRM_CONNECTOR_POLL_HPD;
4777 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004778
4779 /* Interrupt setup is already guaranteed to be single-threaded, this is
4780 * just to make the assert_spin_locked checks happy. */
4781 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004782 if (dev_priv->display.hpd_irq_setup)
4783 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004784 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004785}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004786
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004787/* Disable interrupts so we can allow runtime PM. */
Paulo Zanoni730488b2014-03-07 20:12:32 -03004788void intel_runtime_pm_disable_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004789{
4790 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004791
Paulo Zanoni730488b2014-03-07 20:12:32 -03004792 dev->driver->irq_uninstall(dev);
Jesse Barnes9df7575f2014-06-20 09:29:20 -07004793 dev_priv->pm._irqs_disabled = true;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004794}
4795
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004796/* Restore interrupts so we can recover from runtime PM. */
Paulo Zanoni730488b2014-03-07 20:12:32 -03004797void intel_runtime_pm_restore_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004798{
4799 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004800
Jesse Barnes9df7575f2014-06-20 09:29:20 -07004801 dev_priv->pm._irqs_disabled = false;
Paulo Zanoni730488b2014-03-07 20:12:32 -03004802 dev->driver->irq_preinstall(dev);
4803 dev->driver->irq_postinstall(dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004804}