blob: a08cdc62f8413927672582ab710eed1178e66bf1 [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;
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300313
Daniel Vetter13321782014-09-15 14:55:29 +0200314 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300315
316 for_each_intel_crtc(dev, crtc) {
317 u32 reg = PIPESTAT(crtc->pipe);
318 u32 pipestat;
319
320 if (crtc->cpu_fifo_underrun_disabled)
321 continue;
322
323 pipestat = I915_READ(reg) & 0xffff0000;
324 if ((pipestat & PIPE_FIFO_UNDERRUN_STATUS) == 0)
325 continue;
326
327 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
328 POSTING_READ(reg);
329
330 DRM_ERROR("pipe %c underrun\n", pipe_name(crtc->pipe));
331 }
332
Daniel Vetter13321782014-09-15 14:55:29 +0200333 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä56b80e12014-05-16 19:40:22 +0300334}
335
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300336static void i9xx_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200337 enum pipe pipe,
338 bool enable, bool old)
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200339{
340 struct drm_i915_private *dev_priv = dev->dev_private;
341 u32 reg = PIPESTAT(pipe);
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300342 u32 pipestat = I915_READ(reg) & 0xffff0000;
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200343
344 assert_spin_locked(&dev_priv->irq_lock);
345
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300346 if (enable) {
347 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
348 POSTING_READ(reg);
349 } else {
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200350 if (old && pipestat & PIPE_FIFO_UNDERRUN_STATUS)
Ville Syrjäläe69abff2014-05-16 19:40:21 +0300351 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
352 }
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200353}
354
Paulo Zanoni86642812013-04-12 17:57:57 -0300355static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
356 enum pipe pipe, bool enable)
357{
358 struct drm_i915_private *dev_priv = dev->dev_private;
359 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
360 DE_PIPEB_FIFO_UNDERRUN;
361
362 if (enable)
363 ironlake_enable_display_irq(dev_priv, bit);
364 else
365 ironlake_disable_display_irq(dev_priv, bit);
366}
367
368static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200369 enum pipe pipe,
370 bool enable, bool old)
Paulo Zanoni86642812013-04-12 17:57:57 -0300371{
372 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300373 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200374 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
375
Paulo Zanoni86642812013-04-12 17:57:57 -0300376 if (!ivb_can_enable_err_int(dev))
377 return;
378
Paulo Zanoni86642812013-04-12 17:57:57 -0300379 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
380 } else {
381 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200382
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200383 if (old &&
384 I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300385 DRM_ERROR("uncleared fifo underrun on pipe %c\n",
386 pipe_name(pipe));
Daniel Vetter7336df62013-07-09 22:59:16 +0200387 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300388 }
389}
390
Daniel Vetter38d83c962013-11-07 11:05:46 +0100391static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
392 enum pipe pipe, bool enable)
393{
394 struct drm_i915_private *dev_priv = dev->dev_private;
395
396 assert_spin_locked(&dev_priv->irq_lock);
397
398 if (enable)
399 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
400 else
401 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
402 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
403 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
404}
405
Daniel Vetterfee884e2013-07-04 23:35:21 +0200406/**
407 * ibx_display_interrupt_update - update SDEIMR
408 * @dev_priv: driver private
409 * @interrupt_mask: mask of interrupt bits to update
410 * @enabled_irq_mask: mask of interrupt bits to enable
411 */
412static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
413 uint32_t interrupt_mask,
414 uint32_t enabled_irq_mask)
415{
416 uint32_t sdeimr = I915_READ(SDEIMR);
417 sdeimr &= ~interrupt_mask;
418 sdeimr |= (~enabled_irq_mask & interrupt_mask);
419
420 assert_spin_locked(&dev_priv->irq_lock);
421
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700422 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300423 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300424
Daniel Vetterfee884e2013-07-04 23:35:21 +0200425 I915_WRITE(SDEIMR, sdeimr);
426 POSTING_READ(SDEIMR);
427}
428#define ibx_enable_display_interrupt(dev_priv, bits) \
429 ibx_display_interrupt_update((dev_priv), (bits), (bits))
430#define ibx_disable_display_interrupt(dev_priv, bits) \
431 ibx_display_interrupt_update((dev_priv), (bits), 0)
432
Daniel Vetterde280752013-07-04 23:35:24 +0200433static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
434 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300435 bool enable)
436{
Paulo Zanoni86642812013-04-12 17:57:57 -0300437 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200438 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
439 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300440
441 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200442 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300443 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200444 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300445}
446
447static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
448 enum transcoder pch_transcoder,
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200449 bool enable, bool old)
Paulo Zanoni86642812013-04-12 17:57:57 -0300450{
451 struct drm_i915_private *dev_priv = dev->dev_private;
452
453 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200454 I915_WRITE(SERR_INT,
455 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
456
Paulo Zanoni86642812013-04-12 17:57:57 -0300457 if (!cpt_can_enable_serr_int(dev))
458 return;
459
Daniel Vetterfee884e2013-07-04 23:35:21 +0200460 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300461 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +0200462 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200463
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200464 if (old && I915_READ(SERR_INT) &
465 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder)) {
Ville Syrjälä823c6902014-05-16 19:40:23 +0300466 DRM_ERROR("uncleared pch fifo underrun on pch transcoder %c\n",
467 transcoder_name(pch_transcoder));
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200468 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300469 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300470}
471
472/**
473 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
474 * @dev: drm device
475 * @pipe: pipe
476 * @enable: true if we want to report FIFO underrun errors, false otherwise
477 *
478 * This function makes us disable or enable CPU fifo underruns for a specific
479 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
480 * reporting for one pipe may also disable all the other CPU error interruts for
481 * the other pipes, due to the fact that there's just one interrupt mask/enable
482 * bit for all the pipes.
483 *
484 * Returns the previous state of underrun reporting.
485 */
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +0200486static bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
487 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300488{
489 struct drm_i915_private *dev_priv = dev->dev_private;
490 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
491 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200492 bool old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300493
Imre Deak77961eb2014-03-05 16:20:56 +0200494 assert_spin_locked(&dev_priv->irq_lock);
495
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200496 old = !intel_crtc->cpu_fifo_underrun_disabled;
Paulo Zanoni86642812013-04-12 17:57:57 -0300497 intel_crtc->cpu_fifo_underrun_disabled = !enable;
498
Ville Syrjäläa3ed6aa2014-09-03 14:09:52 +0300499 if (HAS_GMCH_DISPLAY(dev))
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200500 i9xx_set_fifo_underrun_reporting(dev, pipe, enable, old);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200501 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300502 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
503 else if (IS_GEN7(dev))
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200504 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable, old);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100505 else if (IS_GEN8(dev))
506 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300507
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200508 return old;
Imre Deakf88d42f2014-03-04 19:23:09 +0200509}
510
511bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
512 enum pipe pipe, bool enable)
513{
514 struct drm_i915_private *dev_priv = dev->dev_private;
515 unsigned long flags;
516 bool ret;
517
518 spin_lock_irqsave(&dev_priv->irq_lock, flags);
519 ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300520 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Imre Deakf88d42f2014-03-04 19:23:09 +0200521
Paulo Zanoni86642812013-04-12 17:57:57 -0300522 return ret;
523}
524
Imre Deak91d181d2014-02-10 18:42:49 +0200525static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
526 enum pipe pipe)
527{
528 struct drm_i915_private *dev_priv = dev->dev_private;
529 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
530 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
531
532 return !intel_crtc->cpu_fifo_underrun_disabled;
533}
534
Paulo Zanoni86642812013-04-12 17:57:57 -0300535/**
536 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
537 * @dev: drm device
538 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
539 * @enable: true if we want to report FIFO underrun errors, false otherwise
540 *
541 * This function makes us disable or enable PCH fifo underruns for a specific
542 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
543 * underrun reporting for one transcoder may also disable all the other PCH
544 * error interruts for the other transcoders, due to the fact that there's just
545 * one interrupt mask/enable bit for all the transcoders.
546 *
547 * Returns the previous state of underrun reporting.
548 */
549bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
550 enum transcoder pch_transcoder,
551 bool enable)
552{
553 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200554 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
555 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300556 unsigned long flags;
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200557 bool old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300558
Daniel Vetterde280752013-07-04 23:35:24 +0200559 /*
560 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
561 * has only one pch transcoder A that all pipes can use. To avoid racy
562 * pch transcoder -> pipe lookups from interrupt code simply store the
563 * underrun statistics in crtc A. Since we never expose this anywhere
564 * nor use it outside of the fifo underrun code here using the "wrong"
565 * crtc on LPT won't cause issues.
566 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300567
568 spin_lock_irqsave(&dev_priv->irq_lock, flags);
569
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200570 old = !intel_crtc->pch_fifo_underrun_disabled;
Paulo Zanoni86642812013-04-12 17:57:57 -0300571 intel_crtc->pch_fifo_underrun_disabled = !enable;
572
573 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200574 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300575 else
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200576 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable, old);
Paulo Zanoni86642812013-04-12 17:57:57 -0300577
Paulo Zanoni86642812013-04-12 17:57:57 -0300578 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Daniel Vetter2ae2a502014-05-22 17:56:32 +0200579 return old;
Paulo Zanoni86642812013-04-12 17:57:57 -0300580}
581
582
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100583static void
Imre Deak755e9012014-02-10 18:42:47 +0200584__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
585 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800586{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200587 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200588 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800589
Daniel Vetterb79480b2013-06-27 17:52:10 +0200590 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200591 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200592
Ville Syrjälä04feced2014-04-03 13:28:33 +0300593 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
594 status_mask & ~PIPESTAT_INT_STATUS_MASK,
595 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
596 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200597 return;
598
599 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200600 return;
601
Imre Deak91d181d2014-02-10 18:42:49 +0200602 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
603
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200604 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200605 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200606 I915_WRITE(reg, pipestat);
607 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800608}
609
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100610static void
Imre Deak755e9012014-02-10 18:42:47 +0200611__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
612 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800613{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200614 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200615 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800616
Daniel Vetterb79480b2013-06-27 17:52:10 +0200617 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200618 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200619
Ville Syrjälä04feced2014-04-03 13:28:33 +0300620 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
621 status_mask & ~PIPESTAT_INT_STATUS_MASK,
622 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
623 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200624 return;
625
Imre Deak755e9012014-02-10 18:42:47 +0200626 if ((pipestat & enable_mask) == 0)
627 return;
628
Imre Deak91d181d2014-02-10 18:42:49 +0200629 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
630
Imre Deak755e9012014-02-10 18:42:47 +0200631 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200632 I915_WRITE(reg, pipestat);
633 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800634}
635
Imre Deak10c59c52014-02-10 18:42:48 +0200636static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
637{
638 u32 enable_mask = status_mask << 16;
639
640 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300641 * On pipe A we don't support the PSR interrupt yet,
642 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200643 */
644 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
645 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300646 /*
647 * On pipe B and C we don't support the PSR interrupt yet, on pipe
648 * A the same bit is for perf counters which we don't use either.
649 */
650 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
651 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200652
653 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
654 SPRITE0_FLIP_DONE_INT_EN_VLV |
655 SPRITE1_FLIP_DONE_INT_EN_VLV);
656 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
657 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
658 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
659 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
660
661 return enable_mask;
662}
663
Imre Deak755e9012014-02-10 18:42:47 +0200664void
665i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
666 u32 status_mask)
667{
668 u32 enable_mask;
669
Imre Deak10c59c52014-02-10 18:42:48 +0200670 if (IS_VALLEYVIEW(dev_priv->dev))
671 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
672 status_mask);
673 else
674 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200675 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
676}
677
678void
679i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
680 u32 status_mask)
681{
682 u32 enable_mask;
683
Imre Deak10c59c52014-02-10 18:42:48 +0200684 if (IS_VALLEYVIEW(dev_priv->dev))
685 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
686 status_mask);
687 else
688 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200689 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
690}
691
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000692/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300693 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000694 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300695static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000696{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300697 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000698
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300699 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
700 return;
701
Daniel Vetter13321782014-09-15 14:55:29 +0200702 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000703
Imre Deak755e9012014-02-10 18:42:47 +0200704 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300705 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200706 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200707 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000708
Daniel Vetter13321782014-09-15 14:55:29 +0200709 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000710}
711
712/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700713 * i915_pipe_enabled - check if a pipe is enabled
714 * @dev: DRM device
715 * @pipe: pipe to check
716 *
717 * Reading certain registers when the pipe is disabled can hang the chip.
718 * Use this routine to make sure the PLL is running and the pipe is active
719 * before reading such registers if unsure.
720 */
721static int
722i915_pipe_enabled(struct drm_device *dev, int pipe)
723{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300724 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200725
Daniel Vettera01025a2013-05-22 00:50:23 +0200726 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
727 /* Locking is horribly broken here, but whatever. */
728 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
729 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300730
Daniel Vettera01025a2013-05-22 00:50:23 +0200731 return intel_crtc->active;
732 } else {
733 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
734 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700735}
736
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300737/*
738 * This timing diagram depicts the video signal in and
739 * around the vertical blanking period.
740 *
741 * Assumptions about the fictitious mode used in this example:
742 * vblank_start >= 3
743 * vsync_start = vblank_start + 1
744 * vsync_end = vblank_start + 2
745 * vtotal = vblank_start + 3
746 *
747 * start of vblank:
748 * latch double buffered registers
749 * increment frame counter (ctg+)
750 * generate start of vblank interrupt (gen4+)
751 * |
752 * | frame start:
753 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
754 * | may be shifted forward 1-3 extra lines via PIPECONF
755 * | |
756 * | | start of vsync:
757 * | | generate vsync interrupt
758 * | | |
759 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
760 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
761 * ----va---> <-----------------vb--------------------> <--------va-------------
762 * | | <----vs-----> |
763 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
764 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
765 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
766 * | | |
767 * last visible pixel first visible pixel
768 * | increment frame counter (gen3/4)
769 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
770 *
771 * x = horizontal active
772 * _ = horizontal blanking
773 * hs = horizontal sync
774 * va = vertical active
775 * vb = vertical blanking
776 * vs = vertical sync
777 * vbs = vblank_start (number)
778 *
779 * Summary:
780 * - most events happen at the start of horizontal sync
781 * - frame start happens at the start of horizontal blank, 1-4 lines
782 * (depending on PIPECONF settings) after the start of vblank
783 * - gen3/4 pixel and frame counter are synchronized with the start
784 * of horizontal active on the first line of vertical active
785 */
786
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300787static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
788{
789 /* Gen2 doesn't have a hardware frame counter */
790 return 0;
791}
792
Keith Packard42f52ef2008-10-18 19:39:29 -0700793/* Called from drm generic code, passed a 'crtc', which
794 * we use as a pipe index
795 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700796static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700797{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300798 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700799 unsigned long high_frame;
800 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300801 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700802
803 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800804 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800805 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700806 return 0;
807 }
808
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300809 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
810 struct intel_crtc *intel_crtc =
811 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
812 const struct drm_display_mode *mode =
813 &intel_crtc->config.adjusted_mode;
814
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300815 htotal = mode->crtc_htotal;
816 hsync_start = mode->crtc_hsync_start;
817 vbl_start = mode->crtc_vblank_start;
818 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
819 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300820 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100821 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300822
823 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300824 hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300825 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300826 if ((I915_READ(PIPECONF(cpu_transcoder)) &
827 PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE)
828 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300829 }
830
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300831 /* Convert to pixel count */
832 vbl_start *= htotal;
833
834 /* Start of vblank event occurs at start of hsync */
835 vbl_start -= htotal - hsync_start;
836
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800837 high_frame = PIPEFRAME(pipe);
838 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100839
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700840 /*
841 * High & low register fields aren't synchronized, so make sure
842 * we get a low value that's stable across two reads of the high
843 * register.
844 */
845 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100846 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300847 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100848 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700849 } while (high1 != high2);
850
Chris Wilson5eddb702010-09-11 13:48:45 +0100851 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300852 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100853 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300854
855 /*
856 * The frame counter increments at beginning of active.
857 * Cook up a vblank counter by also checking the pixel
858 * counter against vblank start.
859 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200860 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700861}
862
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700863static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800864{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300865 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800866 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800867
868 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800869 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800870 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800871 return 0;
872 }
873
874 return I915_READ(reg);
875}
876
Mario Kleinerad3543e2013-10-30 05:13:08 +0100877/* raw reads, only for fast reads of display block, no need for forcewake etc. */
878#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100879
Ville Syrjäläa225f072014-04-29 13:35:45 +0300880static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
881{
882 struct drm_device *dev = crtc->base.dev;
883 struct drm_i915_private *dev_priv = dev->dev_private;
884 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
885 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300886 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300887
Ville Syrjälä80715b22014-05-15 20:23:23 +0300888 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300889 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
890 vtotal /= 2;
891
892 if (IS_GEN2(dev))
893 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
894 else
895 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
896
897 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300898 * See update_scanline_offset() for the details on the
899 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300900 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300901 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300902}
903
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700904static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200905 unsigned int flags, int *vpos, int *hpos,
906 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100907{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300908 struct drm_i915_private *dev_priv = dev->dev_private;
909 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
910 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
911 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300912 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300913 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100914 bool in_vbl = true;
915 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100916 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100917
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300918 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100919 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800920 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100921 return 0;
922 }
923
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300924 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300925 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300926 vtotal = mode->crtc_vtotal;
927 vbl_start = mode->crtc_vblank_start;
928 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100929
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200930 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
931 vbl_start = DIV_ROUND_UP(vbl_start, 2);
932 vbl_end /= 2;
933 vtotal /= 2;
934 }
935
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300936 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
937
Mario Kleinerad3543e2013-10-30 05:13:08 +0100938 /*
939 * Lock uncore.lock, as we will do multiple timing critical raw
940 * register reads, potentially with preemption disabled, so the
941 * following code must not block on uncore.lock.
942 */
943 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300944
Mario Kleinerad3543e2013-10-30 05:13:08 +0100945 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
946
947 /* Get optional system timestamp before query. */
948 if (stime)
949 *stime = ktime_get();
950
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300951 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100952 /* No obvious pixelcount register. Only query vertical
953 * scanout position from Display scan line register.
954 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300955 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100956 } else {
957 /* Have access to pixelcount since start of frame.
958 * We can split this into vertical and horizontal
959 * scanout position.
960 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100961 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100962
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300963 /* convert to pixel counts */
964 vbl_start *= htotal;
965 vbl_end *= htotal;
966 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300967
968 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300969 * In interlaced modes, the pixel counter counts all pixels,
970 * so one field will have htotal more pixels. In order to avoid
971 * the reported position from jumping backwards when the pixel
972 * counter is beyond the length of the shorter field, just
973 * clamp the position the length of the shorter field. This
974 * matches how the scanline counter based position works since
975 * the scanline counter doesn't count the two half lines.
976 */
977 if (position >= vtotal)
978 position = vtotal - 1;
979
980 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300981 * Start of vblank interrupt is triggered at start of hsync,
982 * just prior to the first active line of vblank. However we
983 * consider lines to start at the leading edge of horizontal
984 * active. So, should we get here before we've crossed into
985 * the horizontal active of the first line in vblank, we would
986 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
987 * always add htotal-hsync_start to the current pixel position.
988 */
989 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300990 }
991
Mario Kleinerad3543e2013-10-30 05:13:08 +0100992 /* Get optional system timestamp after query. */
993 if (etime)
994 *etime = ktime_get();
995
996 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
997
998 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
999
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001000 in_vbl = position >= vbl_start && position < vbl_end;
1001
1002 /*
1003 * While in vblank, position will be negative
1004 * counting up towards 0 at vbl_end. And outside
1005 * vblank, position will be positive counting
1006 * up since vbl_end.
1007 */
1008 if (position >= vbl_start)
1009 position -= vbl_end;
1010 else
1011 position += vtotal - vbl_end;
1012
Ville Syrjälä7c06b082013-10-11 21:52:43 +03001013 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001014 *vpos = position;
1015 *hpos = 0;
1016 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001017 *vpos = position / htotal;
1018 *hpos = position - (*vpos * htotal);
1019 }
1020
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001021 /* In vblank? */
1022 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +02001023 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001024
1025 return ret;
1026}
1027
Ville Syrjäläa225f072014-04-29 13:35:45 +03001028int intel_get_crtc_scanline(struct intel_crtc *crtc)
1029{
1030 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
1031 unsigned long irqflags;
1032 int position;
1033
1034 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1035 position = __intel_get_crtc_scanline(crtc);
1036 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1037
1038 return position;
1039}
1040
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001041static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001042 int *max_error,
1043 struct timeval *vblank_time,
1044 unsigned flags)
1045{
Chris Wilson4041b852011-01-22 10:07:56 +00001046 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001047
Ben Widawsky7eb552a2013-03-13 14:05:41 -07001048 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +00001049 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001050 return -EINVAL;
1051 }
1052
1053 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +00001054 crtc = intel_get_crtc_for_pipe(dev, pipe);
1055 if (crtc == NULL) {
1056 DRM_ERROR("Invalid crtc %d\n", pipe);
1057 return -EINVAL;
1058 }
1059
1060 if (!crtc->enabled) {
1061 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
1062 return -EBUSY;
1063 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001064
1065 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +00001066 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
1067 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +03001068 crtc,
1069 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001070}
1071
Jani Nikula67c347f2013-09-17 14:26:34 +03001072static bool intel_hpd_irq_event(struct drm_device *dev,
1073 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +02001074{
1075 enum drm_connector_status old_status;
1076
1077 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
1078 old_status = connector->status;
1079
1080 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +03001081 if (old_status == connector->status)
1082 return false;
1083
1084 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +02001085 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03001086 connector->name,
Jani Nikula67c347f2013-09-17 14:26:34 +03001087 drm_get_connector_status_name(old_status),
1088 drm_get_connector_status_name(connector->status));
1089
1090 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +02001091}
1092
Dave Airlie13cf5502014-06-18 11:29:35 +10001093static void i915_digport_work_func(struct work_struct *work)
1094{
1095 struct drm_i915_private *dev_priv =
1096 container_of(work, struct drm_i915_private, dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +10001097 u32 long_port_mask, short_port_mask;
1098 struct intel_digital_port *intel_dig_port;
1099 int i, ret;
1100 u32 old_bits = 0;
1101
Daniel Vetter4cb21832014-09-15 14:55:26 +02001102 spin_lock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001103 long_port_mask = dev_priv->long_hpd_port_mask;
1104 dev_priv->long_hpd_port_mask = 0;
1105 short_port_mask = dev_priv->short_hpd_port_mask;
1106 dev_priv->short_hpd_port_mask = 0;
Daniel Vetter4cb21832014-09-15 14:55:26 +02001107 spin_unlock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001108
1109 for (i = 0; i < I915_MAX_PORTS; i++) {
1110 bool valid = false;
1111 bool long_hpd = false;
1112 intel_dig_port = dev_priv->hpd_irq_port[i];
1113 if (!intel_dig_port || !intel_dig_port->hpd_pulse)
1114 continue;
1115
1116 if (long_port_mask & (1 << i)) {
1117 valid = true;
1118 long_hpd = true;
1119 } else if (short_port_mask & (1 << i))
1120 valid = true;
1121
1122 if (valid) {
1123 ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
1124 if (ret == true) {
1125 /* if we get true fallback to old school hpd */
1126 old_bits |= (1 << intel_dig_port->base.hpd_pin);
1127 }
1128 }
1129 }
1130
1131 if (old_bits) {
Daniel Vetter4cb21832014-09-15 14:55:26 +02001132 spin_lock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001133 dev_priv->hpd_event_bits |= old_bits;
Daniel Vetter4cb21832014-09-15 14:55:26 +02001134 spin_unlock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +10001135 schedule_work(&dev_priv->hotplug_work);
1136 }
1137}
1138
Jesse Barnes5ca58282009-03-31 14:11:15 -07001139/*
1140 * Handle hotplug events outside the interrupt handler proper.
1141 */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001142#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
1143
Jesse Barnes5ca58282009-03-31 14:11:15 -07001144static void i915_hotplug_work_func(struct work_struct *work)
1145{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001146 struct drm_i915_private *dev_priv =
1147 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001148 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -07001149 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001150 struct intel_connector *intel_connector;
1151 struct intel_encoder *intel_encoder;
1152 struct drm_connector *connector;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001153 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +02001154 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +02001155 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -07001156
Keith Packarda65e34c2011-07-25 10:04:56 -07001157 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -08001158 DRM_DEBUG_KMS("running encoder hotplug functions\n");
1159
Daniel Vetter4cb21832014-09-15 14:55:26 +02001160 spin_lock_irq(&dev_priv->irq_lock);
Egbert Eich142e2392013-04-11 15:57:57 +02001161
1162 hpd_event_bits = dev_priv->hpd_event_bits;
1163 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001164 list_for_each_entry(connector, &mode_config->connector_list, head) {
1165 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10001166 if (!intel_connector->encoder)
1167 continue;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001168 intel_encoder = intel_connector->encoder;
1169 if (intel_encoder->hpd_pin > HPD_NONE &&
1170 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
1171 connector->polled == DRM_CONNECTOR_POLL_HPD) {
1172 DRM_INFO("HPD interrupt storm detected on connector %s: "
1173 "switching from hotplug detection to polling\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001174 connector->name);
Egbert Eichcd569ae2013-04-16 13:36:57 +02001175 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1176 connector->polled = DRM_CONNECTOR_POLL_CONNECT
1177 | DRM_CONNECTOR_POLL_DISCONNECT;
1178 hpd_disabled = true;
1179 }
Egbert Eich142e2392013-04-11 15:57:57 +02001180 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1181 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03001182 connector->name, intel_encoder->hpd_pin);
Egbert Eich142e2392013-04-11 15:57:57 +02001183 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001184 }
1185 /* if there were no outputs to poll, poll was disabled,
1186 * therefore make sure it's enabled when disabling HPD on
1187 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001188 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +02001189 drm_kms_helper_poll_enable(dev);
Imre Deak63237512014-08-18 15:37:02 +03001190 mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work,
1191 msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
Egbert Eichac4c16c2013-04-16 13:36:58 +02001192 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001193
Daniel Vetter4cb21832014-09-15 14:55:26 +02001194 spin_unlock_irq(&dev_priv->irq_lock);
Egbert Eichcd569ae2013-04-16 13:36:57 +02001195
Egbert Eich321a1b32013-04-11 16:00:26 +02001196 list_for_each_entry(connector, &mode_config->connector_list, head) {
1197 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10001198 if (!intel_connector->encoder)
1199 continue;
Egbert Eich321a1b32013-04-11 16:00:26 +02001200 intel_encoder = intel_connector->encoder;
1201 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1202 if (intel_encoder->hot_plug)
1203 intel_encoder->hot_plug(intel_encoder);
1204 if (intel_hpd_irq_event(dev, connector))
1205 changed = true;
1206 }
1207 }
Keith Packard40ee3382011-07-28 15:31:19 -07001208 mutex_unlock(&mode_config->mutex);
1209
Egbert Eich321a1b32013-04-11 16:00:26 +02001210 if (changed)
1211 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001212}
1213
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001214static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001215{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001216 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001217 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001218 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001219
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001220 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001221
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001222 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1223
Daniel Vetter20e4d402012-08-08 23:35:39 +02001224 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001225
Jesse Barnes7648fa92010-05-20 14:28:11 -07001226 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001227 busy_up = I915_READ(RCPREVBSYTUPAVG);
1228 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001229 max_avg = I915_READ(RCBMAXAVG);
1230 min_avg = I915_READ(RCBMINAVG);
1231
1232 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001233 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001234 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1235 new_delay = dev_priv->ips.cur_delay - 1;
1236 if (new_delay < dev_priv->ips.max_delay)
1237 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001238 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001239 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1240 new_delay = dev_priv->ips.cur_delay + 1;
1241 if (new_delay > dev_priv->ips.min_delay)
1242 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001243 }
1244
Jesse Barnes7648fa92010-05-20 14:28:11 -07001245 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001246 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001247
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001248 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001249
Jesse Barnesf97108d2010-01-29 11:27:07 -08001250 return;
1251}
1252
Chris Wilson549f7362010-10-19 11:19:32 +01001253static void notify_ring(struct drm_device *dev,
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001254 struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +01001255{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +01001256 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +00001257 return;
1258
Chris Wilson814e9b52013-09-23 17:33:19 -03001259 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001260
Sourab Gupta84c33a62014-06-02 16:47:17 +05301261 if (drm_core_check_feature(dev, DRIVER_MODESET))
1262 intel_notify_mmio_flip(ring);
1263
Chris Wilson549f7362010-10-19 11:19:32 +01001264 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001265 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001266}
1267
Deepak S31685c22014-07-03 17:33:01 -04001268static u32 vlv_c0_residency(struct drm_i915_private *dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001269 struct intel_rps_ei *rps_ei)
Deepak S31685c22014-07-03 17:33:01 -04001270{
1271 u32 cz_ts, cz_freq_khz;
1272 u32 render_count, media_count;
1273 u32 elapsed_render, elapsed_media, elapsed_time;
1274 u32 residency = 0;
1275
1276 cz_ts = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
1277 cz_freq_khz = DIV_ROUND_CLOSEST(dev_priv->mem_freq * 1000, 4);
1278
1279 render_count = I915_READ(VLV_RENDER_C0_COUNT_REG);
1280 media_count = I915_READ(VLV_MEDIA_C0_COUNT_REG);
1281
Chris Wilsonbf225f22014-07-10 20:31:18 +01001282 if (rps_ei->cz_clock == 0) {
1283 rps_ei->cz_clock = cz_ts;
1284 rps_ei->render_c0 = render_count;
1285 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001286
1287 return dev_priv->rps.cur_freq;
1288 }
1289
Chris Wilsonbf225f22014-07-10 20:31:18 +01001290 elapsed_time = cz_ts - rps_ei->cz_clock;
1291 rps_ei->cz_clock = cz_ts;
Deepak S31685c22014-07-03 17:33:01 -04001292
Chris Wilsonbf225f22014-07-10 20:31:18 +01001293 elapsed_render = render_count - rps_ei->render_c0;
1294 rps_ei->render_c0 = render_count;
Deepak S31685c22014-07-03 17:33:01 -04001295
Chris Wilsonbf225f22014-07-10 20:31:18 +01001296 elapsed_media = media_count - rps_ei->media_c0;
1297 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001298
1299 /* Convert all the counters into common unit of milli sec */
1300 elapsed_time /= VLV_CZ_CLOCK_TO_MILLI_SEC;
1301 elapsed_render /= cz_freq_khz;
1302 elapsed_media /= cz_freq_khz;
1303
1304 /*
1305 * Calculate overall C0 residency percentage
1306 * only if elapsed time is non zero
1307 */
1308 if (elapsed_time) {
1309 residency =
1310 ((max(elapsed_render, elapsed_media) * 100)
1311 / elapsed_time);
1312 }
1313
1314 return residency;
1315}
1316
1317/**
1318 * vlv_calc_delay_from_C0_counters - Increase/Decrease freq based on GPU
1319 * busy-ness calculated from C0 counters of render & media power wells
1320 * @dev_priv: DRM device private
1321 *
1322 */
Damien Lespiau4fa79042014-08-08 19:25:57 +01001323static int vlv_calc_delay_from_C0_counters(struct drm_i915_private *dev_priv)
Deepak S31685c22014-07-03 17:33:01 -04001324{
1325 u32 residency_C0_up = 0, residency_C0_down = 0;
Damien Lespiau4fa79042014-08-08 19:25:57 +01001326 int new_delay, adj;
Deepak S31685c22014-07-03 17:33:01 -04001327
1328 dev_priv->rps.ei_interrupt_count++;
1329
1330 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
1331
1332
Chris Wilsonbf225f22014-07-10 20:31:18 +01001333 if (dev_priv->rps.up_ei.cz_clock == 0) {
1334 vlv_c0_residency(dev_priv, &dev_priv->rps.up_ei);
1335 vlv_c0_residency(dev_priv, &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001336 return dev_priv->rps.cur_freq;
1337 }
1338
1339
1340 /*
1341 * To down throttle, C0 residency should be less than down threshold
1342 * for continous EI intervals. So calculate down EI counters
1343 * once in VLV_INT_COUNT_FOR_DOWN_EI
1344 */
1345 if (dev_priv->rps.ei_interrupt_count == VLV_INT_COUNT_FOR_DOWN_EI) {
1346
1347 dev_priv->rps.ei_interrupt_count = 0;
1348
1349 residency_C0_down = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001350 &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001351 } else {
1352 residency_C0_up = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001353 &dev_priv->rps.up_ei);
Deepak S31685c22014-07-03 17:33:01 -04001354 }
1355
1356 new_delay = dev_priv->rps.cur_freq;
1357
1358 adj = dev_priv->rps.last_adj;
1359 /* C0 residency is greater than UP threshold. Increase Frequency */
1360 if (residency_C0_up >= VLV_RP_UP_EI_THRESHOLD) {
1361 if (adj > 0)
1362 adj *= 2;
1363 else
1364 adj = 1;
1365
1366 if (dev_priv->rps.cur_freq < dev_priv->rps.max_freq_softlimit)
1367 new_delay = dev_priv->rps.cur_freq + adj;
1368
1369 /*
1370 * For better performance, jump directly
1371 * to RPe if we're below it.
1372 */
1373 if (new_delay < dev_priv->rps.efficient_freq)
1374 new_delay = dev_priv->rps.efficient_freq;
1375
1376 } else if (!dev_priv->rps.ei_interrupt_count &&
1377 (residency_C0_down < VLV_RP_DOWN_EI_THRESHOLD)) {
1378 if (adj < 0)
1379 adj *= 2;
1380 else
1381 adj = -1;
1382 /*
1383 * This means, C0 residency is less than down threshold over
1384 * a period of VLV_INT_COUNT_FOR_DOWN_EI. So, reduce the freq
1385 */
1386 if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
1387 new_delay = dev_priv->rps.cur_freq + adj;
1388 }
1389
1390 return new_delay;
1391}
1392
Ben Widawsky4912d042011-04-25 11:25:20 -07001393static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001394{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001395 struct drm_i915_private *dev_priv =
1396 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001397 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001398 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001399
Daniel Vetter59cdb632013-07-04 23:35:28 +02001400 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001401 pm_iir = dev_priv->rps.pm_iir;
1402 dev_priv->rps.pm_iir = 0;
Damien Lespiau6af257c2014-07-15 09:17:41 +02001403 if (INTEL_INFO(dev_priv->dev)->gen >= 8)
Daniel Vetter480c8032014-07-16 09:49:40 +02001404 gen8_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001405 else {
1406 /* Make sure not to corrupt PMIMR state used by ringbuffer */
Daniel Vetter480c8032014-07-16 09:49:40 +02001407 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001408 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001409 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001410
Paulo Zanoni60611c12013-08-15 11:50:01 -03001411 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301412 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001413
Deepak Sa6706b42014-03-15 20:23:22 +05301414 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001415 return;
1416
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001417 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001418
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001419 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001420 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001421 if (adj > 0)
1422 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301423 else {
1424 /* CHV needs even encode values */
1425 adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1;
1426 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001427 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001428
1429 /*
1430 * For better performance, jump directly
1431 * to RPe if we're below it.
1432 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001433 if (new_delay < dev_priv->rps.efficient_freq)
1434 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001435 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001436 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1437 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001438 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001439 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001440 adj = 0;
Deepak S31685c22014-07-03 17:33:01 -04001441 } else if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1442 new_delay = vlv_calc_delay_from_C0_counters(dev_priv);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001443 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1444 if (adj < 0)
1445 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301446 else {
1447 /* CHV needs even encode values */
1448 adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1;
1449 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001450 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001451 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001452 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001453 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001454
Ben Widawsky79249632012-09-07 19:43:42 -07001455 /* sysfs frequency interfaces may have snuck in while servicing the
1456 * interrupt
1457 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001458 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001459 dev_priv->rps.min_freq_softlimit,
1460 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301461
Ben Widawskyb39fb292014-03-19 18:31:11 -07001462 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001463
1464 if (IS_VALLEYVIEW(dev_priv->dev))
1465 valleyview_set_rps(dev_priv->dev, new_delay);
1466 else
1467 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001468
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001469 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001470}
1471
Ben Widawskye3689192012-05-25 16:56:22 -07001472
1473/**
1474 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1475 * occurred.
1476 * @work: workqueue struct
1477 *
1478 * Doesn't actually do anything except notify userspace. As a consequence of
1479 * this event, userspace should try to remap the bad rows since statistically
1480 * it is likely the same row is more likely to go bad again.
1481 */
1482static void ivybridge_parity_work(struct work_struct *work)
1483{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001484 struct drm_i915_private *dev_priv =
1485 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001486 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001487 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001488 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001489 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001490
1491 /* We must turn off DOP level clock gating to access the L3 registers.
1492 * In order to prevent a get/put style interface, acquire struct mutex
1493 * any time we access those registers.
1494 */
1495 mutex_lock(&dev_priv->dev->struct_mutex);
1496
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001497 /* If we've screwed up tracking, just let the interrupt fire again */
1498 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1499 goto out;
1500
Ben Widawskye3689192012-05-25 16:56:22 -07001501 misccpctl = I915_READ(GEN7_MISCCPCTL);
1502 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1503 POSTING_READ(GEN7_MISCCPCTL);
1504
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001505 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1506 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001507
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001508 slice--;
1509 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1510 break;
1511
1512 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1513
1514 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1515
1516 error_status = I915_READ(reg);
1517 row = GEN7_PARITY_ERROR_ROW(error_status);
1518 bank = GEN7_PARITY_ERROR_BANK(error_status);
1519 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1520
1521 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1522 POSTING_READ(reg);
1523
1524 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1525 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1526 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1527 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1528 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1529 parity_event[5] = NULL;
1530
Dave Airlie5bdebb12013-10-11 14:07:25 +10001531 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001532 KOBJ_CHANGE, parity_event);
1533
1534 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1535 slice, row, bank, subbank);
1536
1537 kfree(parity_event[4]);
1538 kfree(parity_event[3]);
1539 kfree(parity_event[2]);
1540 kfree(parity_event[1]);
1541 }
Ben Widawskye3689192012-05-25 16:56:22 -07001542
1543 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1544
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001545out:
1546 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001547 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001548 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001549 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001550
1551 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001552}
1553
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001554static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001555{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001556 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001557
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001558 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001559 return;
1560
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001561 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001562 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001563 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001564
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001565 iir &= GT_PARITY_ERROR(dev);
1566 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1567 dev_priv->l3_parity.which_slice |= 1 << 1;
1568
1569 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1570 dev_priv->l3_parity.which_slice |= 1 << 0;
1571
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001572 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001573}
1574
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001575static void ilk_gt_irq_handler(struct drm_device *dev,
1576 struct drm_i915_private *dev_priv,
1577 u32 gt_iir)
1578{
1579 if (gt_iir &
1580 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1581 notify_ring(dev, &dev_priv->ring[RCS]);
1582 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1583 notify_ring(dev, &dev_priv->ring[VCS]);
1584}
1585
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001586static void snb_gt_irq_handler(struct drm_device *dev,
1587 struct drm_i915_private *dev_priv,
1588 u32 gt_iir)
1589{
1590
Ben Widawskycc609d52013-05-28 19:22:29 -07001591 if (gt_iir &
1592 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001593 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001594 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001595 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001596 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001597 notify_ring(dev, &dev_priv->ring[BCS]);
1598
Ben Widawskycc609d52013-05-28 19:22:29 -07001599 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1600 GT_BSD_CS_ERROR_INTERRUPT |
1601 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001602 i915_handle_error(dev, false, "GT error interrupt 0x%08x",
1603 gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001604 }
Ben Widawskye3689192012-05-25 16:56:22 -07001605
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001606 if (gt_iir & GT_PARITY_ERROR(dev))
1607 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001608}
1609
Ben Widawsky09610212014-05-15 20:58:08 +03001610static void gen8_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
1611{
1612 if ((pm_iir & dev_priv->pm_rps_events) == 0)
1613 return;
1614
1615 spin_lock(&dev_priv->irq_lock);
1616 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Daniel Vetter480c8032014-07-16 09:49:40 +02001617 gen8_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Ben Widawsky09610212014-05-15 20:58:08 +03001618 spin_unlock(&dev_priv->irq_lock);
1619
1620 queue_work(dev_priv->wq, &dev_priv->rps.work);
1621}
1622
Ben Widawskyabd58f02013-11-02 21:07:09 -07001623static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1624 struct drm_i915_private *dev_priv,
1625 u32 master_ctl)
1626{
Thomas Daniele981e7b2014-07-24 17:04:39 +01001627 struct intel_engine_cs *ring;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001628 u32 rcs, bcs, vcs;
1629 uint32_t tmp = 0;
1630 irqreturn_t ret = IRQ_NONE;
1631
1632 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1633 tmp = I915_READ(GEN8_GT_IIR(0));
1634 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001635 I915_WRITE(GEN8_GT_IIR(0), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001636 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001637
Ben Widawskyabd58f02013-11-02 21:07:09 -07001638 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001639 ring = &dev_priv->ring[RCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001640 if (rcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001641 notify_ring(dev, ring);
1642 if (rcs & GT_CONTEXT_SWITCH_INTERRUPT)
1643 intel_execlists_handle_ctx_events(ring);
1644
1645 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1646 ring = &dev_priv->ring[BCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001647 if (bcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001648 notify_ring(dev, ring);
1649 if (bcs & GT_CONTEXT_SWITCH_INTERRUPT)
1650 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001651 } else
1652 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1653 }
1654
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001655 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07001656 tmp = I915_READ(GEN8_GT_IIR(1));
1657 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001658 I915_WRITE(GEN8_GT_IIR(1), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001659 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001660
Ben Widawskyabd58f02013-11-02 21:07:09 -07001661 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001662 ring = &dev_priv->ring[VCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001663 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001664 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001665 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001666 intel_execlists_handle_ctx_events(ring);
1667
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001668 vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001669 ring = &dev_priv->ring[VCS2];
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001670 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001671 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001672 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001673 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001674 } else
1675 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1676 }
1677
Ben Widawsky09610212014-05-15 20:58:08 +03001678 if (master_ctl & GEN8_GT_PM_IRQ) {
1679 tmp = I915_READ(GEN8_GT_IIR(2));
1680 if (tmp & dev_priv->pm_rps_events) {
Ben Widawsky09610212014-05-15 20:58:08 +03001681 I915_WRITE(GEN8_GT_IIR(2),
1682 tmp & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001683 ret = IRQ_HANDLED;
1684 gen8_rps_irq_handler(dev_priv, tmp);
Ben Widawsky09610212014-05-15 20:58:08 +03001685 } else
1686 DRM_ERROR("The master control interrupt lied (PM)!\n");
1687 }
1688
Ben Widawskyabd58f02013-11-02 21:07:09 -07001689 if (master_ctl & GEN8_GT_VECS_IRQ) {
1690 tmp = I915_READ(GEN8_GT_IIR(3));
1691 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001692 I915_WRITE(GEN8_GT_IIR(3), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001693 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001694
Ben Widawskyabd58f02013-11-02 21:07:09 -07001695 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001696 ring = &dev_priv->ring[VECS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001697 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001698 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001699 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001700 intel_execlists_handle_ctx_events(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001701 } else
1702 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1703 }
1704
1705 return ret;
1706}
1707
Egbert Eichb543fb02013-04-16 13:36:54 +02001708#define HPD_STORM_DETECT_PERIOD 1000
1709#define HPD_STORM_THRESHOLD 5
1710
Dave Airlie13cf5502014-06-18 11:29:35 +10001711static int ilk_port_to_hotplug_shift(enum port port)
1712{
1713 switch (port) {
1714 case PORT_A:
1715 case PORT_E:
1716 default:
1717 return -1;
1718 case PORT_B:
1719 return 0;
1720 case PORT_C:
1721 return 8;
1722 case PORT_D:
1723 return 16;
1724 }
1725}
1726
1727static int g4x_port_to_hotplug_shift(enum port port)
1728{
1729 switch (port) {
1730 case PORT_A:
1731 case PORT_E:
1732 default:
1733 return -1;
1734 case PORT_B:
1735 return 17;
1736 case PORT_C:
1737 return 19;
1738 case PORT_D:
1739 return 21;
1740 }
1741}
1742
1743static inline enum port get_port_from_pin(enum hpd_pin pin)
1744{
1745 switch (pin) {
1746 case HPD_PORT_B:
1747 return PORT_B;
1748 case HPD_PORT_C:
1749 return PORT_C;
1750 case HPD_PORT_D:
1751 return PORT_D;
1752 default:
1753 return PORT_A; /* no hpd */
1754 }
1755}
1756
Daniel Vetter10a504d2013-06-27 17:52:12 +02001757static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001758 u32 hotplug_trigger,
Dave Airlie13cf5502014-06-18 11:29:35 +10001759 u32 dig_hotplug_reg,
Daniel Vetter22062db2013-06-27 17:52:11 +02001760 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001761{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001762 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001763 int i;
Dave Airlie13cf5502014-06-18 11:29:35 +10001764 enum port port;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001765 bool storm_detected = false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001766 bool queue_dig = false, queue_hp = false;
1767 u32 dig_shift;
1768 u32 dig_port_mask = 0;
Egbert Eichb543fb02013-04-16 13:36:54 +02001769
Daniel Vetter91d131d2013-06-27 17:52:14 +02001770 if (!hotplug_trigger)
1771 return;
1772
Dave Airlie13cf5502014-06-18 11:29:35 +10001773 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n",
1774 hotplug_trigger, dig_hotplug_reg);
Imre Deakcc9bd492014-01-16 19:56:54 +02001775
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001776 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001777 for (i = 1; i < HPD_NUM_PINS; i++) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001778 if (!(hpd[i] & hotplug_trigger))
1779 continue;
Egbert Eich821450c2013-04-16 13:36:55 +02001780
Dave Airlie13cf5502014-06-18 11:29:35 +10001781 port = get_port_from_pin(i);
1782 if (port && dev_priv->hpd_irq_port[port]) {
1783 bool long_hpd;
1784
1785 if (IS_G4X(dev)) {
1786 dig_shift = g4x_port_to_hotplug_shift(port);
1787 long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1788 } else {
1789 dig_shift = ilk_port_to_hotplug_shift(port);
1790 long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
1791 }
1792
Ville Syrjälä26fbb772014-08-11 18:37:37 +03001793 DRM_DEBUG_DRIVER("digital hpd port %c - %s\n",
1794 port_name(port),
1795 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10001796 /* for long HPD pulses we want to have the digital queue happen,
1797 but we still want HPD storm detection to function. */
1798 if (long_hpd) {
1799 dev_priv->long_hpd_port_mask |= (1 << port);
1800 dig_port_mask |= hpd[i];
1801 } else {
1802 /* for short HPD just trigger the digital queue */
1803 dev_priv->short_hpd_port_mask |= (1 << port);
1804 hotplug_trigger &= ~hpd[i];
1805 }
1806 queue_dig = true;
1807 }
1808 }
1809
1810 for (i = 1; i < HPD_NUM_PINS; i++) {
Daniel Vetter3ff04a162014-04-24 12:03:17 +02001811 if (hpd[i] & hotplug_trigger &&
1812 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
1813 /*
1814 * On GMCH platforms the interrupt mask bits only
1815 * prevent irq generation, not the setting of the
1816 * hotplug bits itself. So only WARN about unexpected
1817 * interrupts on saner platforms.
1818 */
1819 WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
1820 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1821 hotplug_trigger, i, hpd[i]);
1822
1823 continue;
1824 }
Egbert Eichb8f102e2013-07-26 14:14:24 +02001825
Egbert Eichb543fb02013-04-16 13:36:54 +02001826 if (!(hpd[i] & hotplug_trigger) ||
1827 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1828 continue;
1829
Dave Airlie13cf5502014-06-18 11:29:35 +10001830 if (!(dig_port_mask & hpd[i])) {
1831 dev_priv->hpd_event_bits |= (1 << i);
1832 queue_hp = true;
1833 }
1834
Egbert Eichb543fb02013-04-16 13:36:54 +02001835 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1836 dev_priv->hpd_stats[i].hpd_last_jiffies
1837 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1838 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1839 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001840 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001841 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1842 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001843 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001844 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001845 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001846 } else {
1847 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001848 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1849 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001850 }
1851 }
1852
Daniel Vetter10a504d2013-06-27 17:52:12 +02001853 if (storm_detected)
1854 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001855 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001856
Daniel Vetter645416f2013-09-02 16:22:25 +02001857 /*
1858 * Our hotplug handler can grab modeset locks (by calling down into the
1859 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1860 * queue for otherwise the flush_work in the pageflip code will
1861 * deadlock.
1862 */
Dave Airlie13cf5502014-06-18 11:29:35 +10001863 if (queue_dig)
Dave Airlie0e32b392014-05-02 14:02:48 +10001864 queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +10001865 if (queue_hp)
1866 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001867}
1868
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001869static void gmbus_irq_handler(struct drm_device *dev)
1870{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001871 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001872
Daniel Vetter28c70f12012-12-01 13:53:45 +01001873 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001874}
1875
Daniel Vetterce99c252012-12-01 13:53:47 +01001876static void dp_aux_irq_handler(struct drm_device *dev)
1877{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001878 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001879
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001880 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001881}
1882
Shuang He8bf1e9f2013-10-15 18:55:27 +01001883#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001884static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1885 uint32_t crc0, uint32_t crc1,
1886 uint32_t crc2, uint32_t crc3,
1887 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001888{
1889 struct drm_i915_private *dev_priv = dev->dev_private;
1890 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1891 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001892 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001893
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001894 spin_lock(&pipe_crc->lock);
1895
Damien Lespiau0c912c72013-10-15 18:55:37 +01001896 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001897 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001898 DRM_ERROR("spurious interrupt\n");
1899 return;
1900 }
1901
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001902 head = pipe_crc->head;
1903 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001904
1905 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001906 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001907 DRM_ERROR("CRC buffer overflowing\n");
1908 return;
1909 }
1910
1911 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001912
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001913 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001914 entry->crc[0] = crc0;
1915 entry->crc[1] = crc1;
1916 entry->crc[2] = crc2;
1917 entry->crc[3] = crc3;
1918 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001919
1920 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001921 pipe_crc->head = head;
1922
1923 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001924
1925 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001926}
Daniel Vetter277de952013-10-18 16:37:07 +02001927#else
1928static inline void
1929display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1930 uint32_t crc0, uint32_t crc1,
1931 uint32_t crc2, uint32_t crc3,
1932 uint32_t crc4) {}
1933#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001934
Daniel Vetter277de952013-10-18 16:37:07 +02001935
1936static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001937{
1938 struct drm_i915_private *dev_priv = dev->dev_private;
1939
Daniel Vetter277de952013-10-18 16:37:07 +02001940 display_pipe_crc_irq_handler(dev, pipe,
1941 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1942 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001943}
1944
Daniel Vetter277de952013-10-18 16:37:07 +02001945static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001946{
1947 struct drm_i915_private *dev_priv = dev->dev_private;
1948
Daniel Vetter277de952013-10-18 16:37:07 +02001949 display_pipe_crc_irq_handler(dev, pipe,
1950 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1951 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1952 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1953 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1954 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001955}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001956
Daniel Vetter277de952013-10-18 16:37:07 +02001957static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001958{
1959 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001960 uint32_t res1, res2;
1961
1962 if (INTEL_INFO(dev)->gen >= 3)
1963 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1964 else
1965 res1 = 0;
1966
1967 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1968 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1969 else
1970 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001971
Daniel Vetter277de952013-10-18 16:37:07 +02001972 display_pipe_crc_irq_handler(dev, pipe,
1973 I915_READ(PIPE_CRC_RES_RED(pipe)),
1974 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1975 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1976 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001977}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001978
Daisy Sunc76bb612014-08-11 11:08:38 -07001979void gen8_flip_interrupt(struct drm_device *dev)
1980{
1981 struct drm_i915_private *dev_priv = dev->dev_private;
1982
1983 if (!dev_priv->rps.is_bdw_sw_turbo)
1984 return;
1985
1986 if(atomic_read(&dev_priv->rps.sw_turbo.flip_received)) {
1987 mod_timer(&dev_priv->rps.sw_turbo.flip_timer,
1988 usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies);
1989 }
1990 else {
1991 dev_priv->rps.sw_turbo.flip_timer.expires =
1992 usecs_to_jiffies(dev_priv->rps.sw_turbo.timeout) + jiffies;
1993 add_timer(&dev_priv->rps.sw_turbo.flip_timer);
1994 atomic_set(&dev_priv->rps.sw_turbo.flip_received, true);
1995 }
1996
1997 bdw_software_turbo(dev);
1998}
1999
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002000/* The RPS events need forcewake, so we add them to a work queue and mask their
2001 * IMR bits until the work is done. Other interrupts can be processed without
2002 * the work queue. */
2003static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07002004{
Deepak Sa6706b42014-03-15 20:23:22 +05302005 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02002006 spin_lock(&dev_priv->irq_lock);
Deepak Sa6706b42014-03-15 20:23:22 +05302007 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Daniel Vetter480c8032014-07-16 09:49:40 +02002008 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02002009 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02002010
2011 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07002012 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07002013
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002014 if (HAS_VEBOX(dev_priv->dev)) {
2015 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
2016 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07002017
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002018 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002019 i915_handle_error(dev_priv->dev, false,
2020 "VEBOX CS error interrupt 0x%08x",
2021 pm_iir);
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03002022 }
Ben Widawsky12638c52013-05-28 19:22:31 -07002023 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07002024}
2025
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002026static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
2027{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002028 if (!drm_handle_vblank(dev, pipe))
2029 return false;
2030
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03002031 return true;
2032}
2033
Imre Deakc1874ed2014-02-04 21:35:46 +02002034static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
2035{
2036 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02002037 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02002038 int pipe;
2039
Imre Deak58ead0d2014-02-04 21:35:47 +02002040 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01002041 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02002042 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002043 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02002044
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002045 /*
2046 * PIPESTAT bits get signalled even when the interrupt is
2047 * disabled with the mask bits, and some of the status bits do
2048 * not generate interrupts at all (like the underrun bit). Hence
2049 * we need to be careful that we only handle what we want to
2050 * handle.
2051 */
2052 mask = 0;
2053 if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
2054 mask |= PIPE_FIFO_UNDERRUN_STATUS;
2055
2056 switch (pipe) {
2057 case PIPE_A:
2058 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
2059 break;
2060 case PIPE_B:
2061 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
2062 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03002063 case PIPE_C:
2064 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
2065 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002066 }
2067 if (iir & iir_bit)
2068 mask |= dev_priv->pipestat_irq_mask[pipe];
2069
2070 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02002071 continue;
2072
2073 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01002074 mask |= PIPESTAT_INT_ENABLE_MASK;
2075 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02002076
2077 /*
2078 * Clear the PIPE*STAT regs before the IIR
2079 */
Imre Deak91d181d2014-02-10 18:42:49 +02002080 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
2081 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02002082 I915_WRITE(reg, pipe_stats[pipe]);
2083 }
Imre Deak58ead0d2014-02-04 21:35:47 +02002084 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02002085
Damien Lespiau055e3932014-08-18 13:49:10 +01002086 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002087 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
2088 intel_pipe_handle_vblank(dev, pipe))
2089 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002090
Imre Deak579a9b02014-02-04 21:35:48 +02002091 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02002092 intel_prepare_page_flip(dev, pipe);
2093 intel_finish_page_flip(dev, pipe);
2094 }
2095
2096 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2097 i9xx_pipe_crc_irq_handler(dev, pipe);
2098
2099 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
2100 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
2101 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
2102 }
2103
2104 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2105 gmbus_irq_handler(dev);
2106}
2107
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002108static void i9xx_hpd_irq_handler(struct drm_device *dev)
2109{
2110 struct drm_i915_private *dev_priv = dev->dev_private;
2111 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
2112
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002113 if (hotplug_status) {
2114 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2115 /*
2116 * Make sure hotplug status is cleared before we clear IIR, or else we
2117 * may miss hotplug events.
2118 */
2119 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002120
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002121 if (IS_G4X(dev)) {
2122 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002123
Dave Airlie13cf5502014-06-18 11:29:35 +10002124 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002125 } else {
2126 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
2127
Dave Airlie13cf5502014-06-18 11:29:35 +10002128 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002129 }
2130
2131 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
2132 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
2133 dp_aux_irq_handler(dev);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002134 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002135}
2136
Daniel Vetterff1f5252012-10-02 15:10:55 +02002137static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002138{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002139 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002140 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002141 u32 iir, gt_iir, pm_iir;
2142 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002143
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002144 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002145 /* Find, clear, then process each source of interrupt */
2146
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002147 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002148 if (gt_iir)
2149 I915_WRITE(GTIIR, gt_iir);
2150
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002151 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002152 if (pm_iir)
2153 I915_WRITE(GEN6_PMIIR, pm_iir);
2154
2155 iir = I915_READ(VLV_IIR);
2156 if (iir) {
2157 /* Consume port before clearing IIR or we'll miss events */
2158 if (iir & I915_DISPLAY_PORT_INTERRUPT)
2159 i9xx_hpd_irq_handler(dev);
2160 I915_WRITE(VLV_IIR, iir);
2161 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002162
2163 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
2164 goto out;
2165
2166 ret = IRQ_HANDLED;
2167
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002168 if (gt_iir)
2169 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03002170 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02002171 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002172 /* Call regardless, as some status bits might not be
2173 * signalled in iir */
2174 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002175 }
2176
2177out:
2178 return ret;
2179}
2180
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002181static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2182{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002183 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002184 struct drm_i915_private *dev_priv = dev->dev_private;
2185 u32 master_ctl, iir;
2186 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002187
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002188 for (;;) {
2189 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2190 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002191
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002192 if (master_ctl == 0 && iir == 0)
2193 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002194
Oscar Mateo27b6c122014-06-16 16:11:00 +01002195 ret = IRQ_HANDLED;
2196
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002197 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002198
Oscar Mateo27b6c122014-06-16 16:11:00 +01002199 /* Find, clear, then process each source of interrupt */
2200
2201 if (iir) {
2202 /* Consume port before clearing IIR or we'll miss events */
2203 if (iir & I915_DISPLAY_PORT_INTERRUPT)
2204 i9xx_hpd_irq_handler(dev);
2205 I915_WRITE(VLV_IIR, iir);
2206 }
2207
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002208 gen8_gt_irq_handler(dev, dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002209
Oscar Mateo27b6c122014-06-16 16:11:00 +01002210 /* Call regardless, as some status bits might not be
2211 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002212 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002213
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002214 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
2215 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002216 }
2217
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002218 return ret;
2219}
2220
Adam Jackson23e81d62012-06-06 15:45:44 -04002221static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002222{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002223 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002224 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002225 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Dave Airlie13cf5502014-06-18 11:29:35 +10002226 u32 dig_hotplug_reg;
Jesse Barnes776ad802011-01-04 15:09:39 -08002227
Dave Airlie13cf5502014-06-18 11:29:35 +10002228 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2229 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2230
2231 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002232
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002233 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2234 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2235 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002236 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002237 port_name(port));
2238 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002239
Daniel Vetterce99c252012-12-01 13:53:47 +01002240 if (pch_iir & SDE_AUX_MASK)
2241 dp_aux_irq_handler(dev);
2242
Jesse Barnes776ad802011-01-04 15:09:39 -08002243 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002244 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08002245
2246 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2247 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2248
2249 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2250 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2251
2252 if (pch_iir & SDE_POISON)
2253 DRM_ERROR("PCH poison interrupt\n");
2254
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002255 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002256 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002257 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2258 pipe_name(pipe),
2259 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002260
2261 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2262 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2263
2264 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2265 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2266
Jesse Barnes776ad802011-01-04 15:09:39 -08002267 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03002268 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2269 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002270 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002271
2272 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
2273 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2274 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002275 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002276}
2277
2278static void ivb_err_int_handler(struct drm_device *dev)
2279{
2280 struct drm_i915_private *dev_priv = dev->dev_private;
2281 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002282 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002283
Paulo Zanonide032bf2013-04-12 17:57:58 -03002284 if (err_int & ERR_INT_POISON)
2285 DRM_ERROR("Poison interrupt\n");
2286
Damien Lespiau055e3932014-08-18 13:49:10 +01002287 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a69b892013-10-16 22:55:52 +02002288 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
2289 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2290 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002291 DRM_ERROR("Pipe %c FIFO underrun\n",
2292 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02002293 }
Paulo Zanoni86642812013-04-12 17:57:57 -03002294
Daniel Vetter5a69b892013-10-16 22:55:52 +02002295 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
2296 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02002297 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002298 else
Daniel Vetter277de952013-10-18 16:37:07 +02002299 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002300 }
2301 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002302
Paulo Zanoni86642812013-04-12 17:57:57 -03002303 I915_WRITE(GEN7_ERR_INT, err_int);
2304}
2305
2306static void cpt_serr_int_handler(struct drm_device *dev)
2307{
2308 struct drm_i915_private *dev_priv = dev->dev_private;
2309 u32 serr_int = I915_READ(SERR_INT);
2310
Paulo Zanonide032bf2013-04-12 17:57:58 -03002311 if (serr_int & SERR_INT_POISON)
2312 DRM_ERROR("PCH poison interrupt\n");
2313
Paulo Zanoni86642812013-04-12 17:57:57 -03002314 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
2315 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
2316 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002317 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002318
2319 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
2320 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
2321 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002322 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002323
2324 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
2325 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
2326 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002327 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03002328
2329 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002330}
2331
Adam Jackson23e81d62012-06-06 15:45:44 -04002332static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
2333{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002334 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04002335 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002336 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Dave Airlie13cf5502014-06-18 11:29:35 +10002337 u32 dig_hotplug_reg;
Adam Jackson23e81d62012-06-06 15:45:44 -04002338
Dave Airlie13cf5502014-06-18 11:29:35 +10002339 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2340 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2341
2342 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002343
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002344 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2345 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2346 SDE_AUDIO_POWER_SHIFT_CPT);
2347 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2348 port_name(port));
2349 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002350
2351 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01002352 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002353
2354 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002355 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002356
2357 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2358 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2359
2360 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2361 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2362
2363 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002364 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002365 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2366 pipe_name(pipe),
2367 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002368
2369 if (pch_iir & SDE_ERROR_CPT)
2370 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002371}
2372
Paulo Zanonic008bc62013-07-12 16:35:10 -03002373static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2374{
2375 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02002376 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03002377
2378 if (de_iir & DE_AUX_CHANNEL_A)
2379 dp_aux_irq_handler(dev);
2380
2381 if (de_iir & DE_GSE)
2382 intel_opregion_asle_intr(dev);
2383
Paulo Zanonic008bc62013-07-12 16:35:10 -03002384 if (de_iir & DE_POISON)
2385 DRM_ERROR("Poison interrupt\n");
2386
Damien Lespiau055e3932014-08-18 13:49:10 +01002387 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002388 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2389 intel_pipe_handle_vblank(dev, pipe))
2390 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002391
Daniel Vetter40da17c2013-10-21 18:04:36 +02002392 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
2393 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002394 DRM_ERROR("Pipe %c FIFO underrun\n",
2395 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03002396
Daniel Vetter40da17c2013-10-21 18:04:36 +02002397 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2398 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002399
Daniel Vetter40da17c2013-10-21 18:04:36 +02002400 /* plane/pipes map 1:1 on ilk+ */
2401 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2402 intel_prepare_page_flip(dev, pipe);
2403 intel_finish_page_flip_plane(dev, pipe);
2404 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03002405 }
2406
2407 /* check event from PCH */
2408 if (de_iir & DE_PCH_EVENT) {
2409 u32 pch_iir = I915_READ(SDEIIR);
2410
2411 if (HAS_PCH_CPT(dev))
2412 cpt_irq_handler(dev, pch_iir);
2413 else
2414 ibx_irq_handler(dev, pch_iir);
2415
2416 /* should clear PCH hotplug event before clear CPU irq */
2417 I915_WRITE(SDEIIR, pch_iir);
2418 }
2419
2420 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2421 ironlake_rps_change_irq_handler(dev);
2422}
2423
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002424static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2425{
2426 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002427 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002428
2429 if (de_iir & DE_ERR_INT_IVB)
2430 ivb_err_int_handler(dev);
2431
2432 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2433 dp_aux_irq_handler(dev);
2434
2435 if (de_iir & DE_GSE_IVB)
2436 intel_opregion_asle_intr(dev);
2437
Damien Lespiau055e3932014-08-18 13:49:10 +01002438 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002439 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2440 intel_pipe_handle_vblank(dev, pipe))
2441 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02002442
2443 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002444 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2445 intel_prepare_page_flip(dev, pipe);
2446 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002447 }
2448 }
2449
2450 /* check event from PCH */
2451 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2452 u32 pch_iir = I915_READ(SDEIIR);
2453
2454 cpt_irq_handler(dev, pch_iir);
2455
2456 /* clear PCH hotplug event before clear CPU irq */
2457 I915_WRITE(SDEIIR, pch_iir);
2458 }
2459}
2460
Oscar Mateo72c90f62014-06-16 16:10:57 +01002461/*
2462 * To handle irqs with the minimum potential races with fresh interrupts, we:
2463 * 1 - Disable Master Interrupt Control.
2464 * 2 - Find the source(s) of the interrupt.
2465 * 3 - Clear the Interrupt Identity bits (IIR).
2466 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2467 * 5 - Re-enable Master Interrupt Control.
2468 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002469static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002470{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002471 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002472 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002473 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002474 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002475
Paulo Zanoni86642812013-04-12 17:57:57 -03002476 /* We get interrupts on unclaimed registers, so check for this before we
2477 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002478 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002479
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002480 /* disable master interrupt before clearing iir */
2481 de_ier = I915_READ(DEIER);
2482 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002483 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002484
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002485 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2486 * interrupts will will be stored on its back queue, and then we'll be
2487 * able to process them after we restore SDEIER (as soon as we restore
2488 * it, we'll get an interrupt if SDEIIR still has something to process
2489 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002490 if (!HAS_PCH_NOP(dev)) {
2491 sde_ier = I915_READ(SDEIER);
2492 I915_WRITE(SDEIER, 0);
2493 POSTING_READ(SDEIER);
2494 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002495
Oscar Mateo72c90f62014-06-16 16:10:57 +01002496 /* Find, clear, then process each source of interrupt */
2497
Chris Wilson0e434062012-05-09 21:45:44 +01002498 gt_iir = I915_READ(GTIIR);
2499 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002500 I915_WRITE(GTIIR, gt_iir);
2501 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002502 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002503 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002504 else
2505 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002506 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002507
2508 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002509 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002510 I915_WRITE(DEIIR, de_iir);
2511 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002512 if (INTEL_INFO(dev)->gen >= 7)
2513 ivb_display_irq_handler(dev, de_iir);
2514 else
2515 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002516 }
2517
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002518 if (INTEL_INFO(dev)->gen >= 6) {
2519 u32 pm_iir = I915_READ(GEN6_PMIIR);
2520 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002521 I915_WRITE(GEN6_PMIIR, pm_iir);
2522 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002523 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002524 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002525 }
2526
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002527 I915_WRITE(DEIER, de_ier);
2528 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002529 if (!HAS_PCH_NOP(dev)) {
2530 I915_WRITE(SDEIER, sde_ier);
2531 POSTING_READ(SDEIER);
2532 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002533
2534 return ret;
2535}
2536
Ben Widawskyabd58f02013-11-02 21:07:09 -07002537static irqreturn_t gen8_irq_handler(int irq, void *arg)
2538{
2539 struct drm_device *dev = arg;
2540 struct drm_i915_private *dev_priv = dev->dev_private;
2541 u32 master_ctl;
2542 irqreturn_t ret = IRQ_NONE;
2543 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002544 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002545
Ben Widawskyabd58f02013-11-02 21:07:09 -07002546 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2547 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2548 if (!master_ctl)
2549 return IRQ_NONE;
2550
2551 I915_WRITE(GEN8_MASTER_IRQ, 0);
2552 POSTING_READ(GEN8_MASTER_IRQ);
2553
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002554 /* Find, clear, then process each source of interrupt */
2555
Ben Widawskyabd58f02013-11-02 21:07:09 -07002556 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2557
2558 if (master_ctl & GEN8_DE_MISC_IRQ) {
2559 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002560 if (tmp) {
2561 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2562 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002563 if (tmp & GEN8_DE_MISC_GSE)
2564 intel_opregion_asle_intr(dev);
2565 else
2566 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002567 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002568 else
2569 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002570 }
2571
Daniel Vetter6d766f02013-11-07 14:49:55 +01002572 if (master_ctl & GEN8_DE_PORT_IRQ) {
2573 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002574 if (tmp) {
2575 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2576 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002577 if (tmp & GEN8_AUX_CHANNEL_A)
2578 dp_aux_irq_handler(dev);
2579 else
2580 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002581 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002582 else
2583 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002584 }
2585
Damien Lespiau055e3932014-08-18 13:49:10 +01002586 for_each_pipe(dev_priv, pipe) {
Daniel Vetterc42664c2013-11-07 11:05:40 +01002587 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002588
Daniel Vetterc42664c2013-11-07 11:05:40 +01002589 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2590 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002591
Daniel Vetterc42664c2013-11-07 11:05:40 +01002592 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002593 if (pipe_iir) {
2594 ret = IRQ_HANDLED;
2595 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002596 if (pipe_iir & GEN8_PIPE_VBLANK &&
2597 intel_pipe_handle_vblank(dev, pipe))
2598 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002599
2600 if (pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE) {
2601 intel_prepare_page_flip(dev, pipe);
2602 intel_finish_page_flip_plane(dev, pipe);
2603 }
2604
2605 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2606 hsw_pipe_crc_irq_handler(dev, pipe);
2607
2608 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
2609 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2610 false))
2611 DRM_ERROR("Pipe %c FIFO underrun\n",
2612 pipe_name(pipe));
2613 }
2614
2615 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
2616 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2617 pipe_name(pipe),
2618 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2619 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002620 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002621 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2622 }
2623
Daniel Vetter92d03a82013-11-07 11:05:43 +01002624 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2625 /*
2626 * FIXME(BDW): Assume for now that the new interrupt handling
2627 * scheme also closed the SDE interrupt handling race we've seen
2628 * on older pch-split platforms. But this needs testing.
2629 */
2630 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002631 if (pch_iir) {
2632 I915_WRITE(SDEIIR, pch_iir);
2633 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002634 cpt_irq_handler(dev, pch_iir);
2635 } else
2636 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2637
Daniel Vetter92d03a82013-11-07 11:05:43 +01002638 }
2639
Ben Widawskyabd58f02013-11-02 21:07:09 -07002640 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2641 POSTING_READ(GEN8_MASTER_IRQ);
2642
2643 return ret;
2644}
2645
Daniel Vetter17e1df02013-09-08 21:57:13 +02002646static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2647 bool reset_completed)
2648{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002649 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002650 int i;
2651
2652 /*
2653 * Notify all waiters for GPU completion events that reset state has
2654 * been changed, and that they need to restart their wait after
2655 * checking for potential errors (and bail out to drop locks if there is
2656 * a gpu reset pending so that i915_error_work_func can acquire them).
2657 */
2658
2659 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2660 for_each_ring(ring, dev_priv, i)
2661 wake_up_all(&ring->irq_queue);
2662
2663 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2664 wake_up_all(&dev_priv->pending_flip_queue);
2665
2666 /*
2667 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2668 * reset state is cleared.
2669 */
2670 if (reset_completed)
2671 wake_up_all(&dev_priv->gpu_error.reset_queue);
2672}
2673
Jesse Barnes8a905232009-07-11 16:48:03 -04002674/**
2675 * i915_error_work_func - do process context error handling work
2676 * @work: work struct
2677 *
2678 * Fire an error uevent so userspace can see that a hang or error
2679 * was detected.
2680 */
2681static void i915_error_work_func(struct work_struct *work)
2682{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002683 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2684 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002685 struct drm_i915_private *dev_priv =
2686 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002687 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002688 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2689 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2690 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002691 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002692
Dave Airlie5bdebb12013-10-11 14:07:25 +10002693 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002694
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002695 /*
2696 * Note that there's only one work item which does gpu resets, so we
2697 * need not worry about concurrent gpu resets potentially incrementing
2698 * error->reset_counter twice. We only need to take care of another
2699 * racing irq/hangcheck declaring the gpu dead for a second time. A
2700 * quick check for that is good enough: schedule_work ensures the
2701 * correct ordering between hang detection and this work item, and since
2702 * the reset in-progress bit is only ever set by code outside of this
2703 * work we don't need to worry about any other races.
2704 */
2705 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002706 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002707 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002708 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002709
Daniel Vetter17e1df02013-09-08 21:57:13 +02002710 /*
Imre Deakf454c692014-04-23 01:09:04 +03002711 * In most cases it's guaranteed that we get here with an RPM
2712 * reference held, for example because there is a pending GPU
2713 * request that won't finish until the reset is done. This
2714 * isn't the case at least when we get here by doing a
2715 * simulated reset via debugs, so get an RPM reference.
2716 */
2717 intel_runtime_pm_get(dev_priv);
2718 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002719 * All state reset _must_ be completed before we update the
2720 * reset counter, for otherwise waiters might miss the reset
2721 * pending state and not properly drop locks, resulting in
2722 * deadlocks with the reset work.
2723 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002724 ret = i915_reset(dev);
2725
Daniel Vetter17e1df02013-09-08 21:57:13 +02002726 intel_display_handle_reset(dev);
2727
Imre Deakf454c692014-04-23 01:09:04 +03002728 intel_runtime_pm_put(dev_priv);
2729
Daniel Vetterf69061b2012-12-06 09:01:42 +01002730 if (ret == 0) {
2731 /*
2732 * After all the gem state is reset, increment the reset
2733 * counter and wake up everyone waiting for the reset to
2734 * complete.
2735 *
2736 * Since unlock operations are a one-sided barrier only,
2737 * we need to insert a barrier here to order any seqno
2738 * updates before
2739 * the counter increment.
2740 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002741 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002742 atomic_inc(&dev_priv->gpu_error.reset_counter);
2743
Dave Airlie5bdebb12013-10-11 14:07:25 +10002744 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002745 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002746 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002747 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002748 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002749
Daniel Vetter17e1df02013-09-08 21:57:13 +02002750 /*
2751 * Note: The wake_up also serves as a memory barrier so that
2752 * waiters see the update value of the reset counter atomic_t.
2753 */
2754 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002755 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002756}
2757
Chris Wilson35aed2e2010-05-27 13:18:12 +01002758static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002759{
2760 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002761 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002762 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002763 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002764
Chris Wilson35aed2e2010-05-27 13:18:12 +01002765 if (!eir)
2766 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002767
Joe Perchesa70491c2012-03-18 13:00:11 -07002768 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002769
Ben Widawskybd9854f2012-08-23 15:18:09 -07002770 i915_get_extra_instdone(dev, instdone);
2771
Jesse Barnes8a905232009-07-11 16:48:03 -04002772 if (IS_G4X(dev)) {
2773 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2774 u32 ipeir = I915_READ(IPEIR_I965);
2775
Joe Perchesa70491c2012-03-18 13:00:11 -07002776 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2777 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002778 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2779 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002780 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002781 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002782 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002783 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002784 }
2785 if (eir & GM45_ERROR_PAGE_TABLE) {
2786 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002787 pr_err("page table error\n");
2788 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002789 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002790 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002791 }
2792 }
2793
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002794 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002795 if (eir & I915_ERROR_PAGE_TABLE) {
2796 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002797 pr_err("page table error\n");
2798 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002799 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002800 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002801 }
2802 }
2803
2804 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002805 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002806 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002807 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002808 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002809 /* pipestat has already been acked */
2810 }
2811 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002812 pr_err("instruction error\n");
2813 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002814 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2815 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002816 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002817 u32 ipeir = I915_READ(IPEIR);
2818
Joe Perchesa70491c2012-03-18 13:00:11 -07002819 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2820 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002821 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002822 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002823 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002824 } else {
2825 u32 ipeir = I915_READ(IPEIR_I965);
2826
Joe Perchesa70491c2012-03-18 13:00:11 -07002827 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2828 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002829 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002830 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002831 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002832 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002833 }
2834 }
2835
2836 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002837 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002838 eir = I915_READ(EIR);
2839 if (eir) {
2840 /*
2841 * some errors might have become stuck,
2842 * mask them.
2843 */
2844 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2845 I915_WRITE(EMR, I915_READ(EMR) | eir);
2846 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2847 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002848}
2849
2850/**
2851 * i915_handle_error - handle an error interrupt
2852 * @dev: drm device
2853 *
2854 * Do some basic checking of regsiter state at error interrupt time and
2855 * dump it to the syslog. Also call i915_capture_error_state() to make
2856 * sure we get a record and make it available in debugfs. Fire a uevent
2857 * so userspace knows something bad happened (should trigger collection
2858 * of a ring dump etc.).
2859 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002860void i915_handle_error(struct drm_device *dev, bool wedged,
2861 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002862{
2863 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002864 va_list args;
2865 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002866
Mika Kuoppala58174462014-02-25 17:11:26 +02002867 va_start(args, fmt);
2868 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2869 va_end(args);
2870
2871 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002872 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002873
Ben Gamariba1234d2009-09-14 17:48:47 -04002874 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002875 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2876 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002877
Ben Gamari11ed50e2009-09-14 17:48:45 -04002878 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002879 * Wakeup waiting processes so that the reset work function
2880 * i915_error_work_func doesn't deadlock trying to grab various
2881 * locks. By bumping the reset counter first, the woken
2882 * processes will see a reset in progress and back off,
2883 * releasing their locks and then wait for the reset completion.
2884 * We must do this for _all_ gpu waiters that might hold locks
2885 * that the reset work needs to acquire.
2886 *
2887 * Note: The wake_up serves as the required memory barrier to
2888 * ensure that the waiters see the updated value of the reset
2889 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002890 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002891 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002892 }
2893
Daniel Vetter122f46b2013-09-04 17:36:14 +02002894 /*
2895 * Our reset work can grab modeset locks (since it needs to reset the
2896 * state of outstanding pagelips). Hence it must not be run on our own
2897 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2898 * code will deadlock.
2899 */
2900 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002901}
2902
Keith Packard42f52ef2008-10-18 19:39:29 -07002903/* Called from drm generic code, passed 'crtc' which
2904 * we use as a pipe index
2905 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002906static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002907{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002908 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002909 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002910
Chris Wilson5eddb702010-09-11 13:48:45 +01002911 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002912 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002913
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002914 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002915 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002916 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002917 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002918 else
Keith Packard7c463582008-11-04 02:03:27 -08002919 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002920 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002921 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002922
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002923 return 0;
2924}
2925
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002926static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002927{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002928 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002929 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002930 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002931 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002932
2933 if (!i915_pipe_enabled(dev, pipe))
2934 return -EINVAL;
2935
2936 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002937 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002938 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2939
2940 return 0;
2941}
2942
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002943static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2944{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002945 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002946 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002947
2948 if (!i915_pipe_enabled(dev, pipe))
2949 return -EINVAL;
2950
2951 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002952 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002953 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002954 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2955
2956 return 0;
2957}
2958
Ben Widawskyabd58f02013-11-02 21:07:09 -07002959static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2960{
2961 struct drm_i915_private *dev_priv = dev->dev_private;
2962 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002963
2964 if (!i915_pipe_enabled(dev, pipe))
2965 return -EINVAL;
2966
2967 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002968 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2969 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2970 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002971 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2972 return 0;
2973}
2974
Keith Packard42f52ef2008-10-18 19:39:29 -07002975/* Called from drm generic code, passed 'crtc' which
2976 * we use as a pipe index
2977 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002978static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002979{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002980 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002981 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002982
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002983 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002984 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002985 PIPE_VBLANK_INTERRUPT_STATUS |
2986 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002987 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2988}
2989
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002990static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002991{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002992 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002993 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002994 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002995 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002996
2997 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002998 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002999 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3000}
3001
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003002static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
3003{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003004 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003005 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003006
3007 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003008 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003009 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003010 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3011}
3012
Ben Widawskyabd58f02013-11-02 21:07:09 -07003013static void gen8_disable_vblank(struct drm_device *dev, int pipe)
3014{
3015 struct drm_i915_private *dev_priv = dev->dev_private;
3016 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003017
3018 if (!i915_pipe_enabled(dev, pipe))
3019 return;
3020
3021 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01003022 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
3023 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3024 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07003025 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3026}
3027
Chris Wilson893eead2010-10-27 14:44:35 +01003028static u32
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003029ring_last_seqno(struct intel_engine_cs *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08003030{
Chris Wilson893eead2010-10-27 14:44:35 +01003031 return list_entry(ring->request_list.prev,
3032 struct drm_i915_gem_request, list)->seqno;
3033}
3034
Chris Wilson9107e9d2013-06-10 11:20:20 +01003035static bool
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003036ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01003037{
Chris Wilson9107e9d2013-06-10 11:20:20 +01003038 return (list_empty(&ring->request_list) ||
3039 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04003040}
3041
Daniel Vettera028c4b2014-03-15 00:08:56 +01003042static bool
3043ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
3044{
3045 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003046 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01003047 } else {
3048 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
3049 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
3050 MI_SEMAPHORE_REGISTER);
3051 }
3052}
3053
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003054static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003055semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01003056{
3057 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003058 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01003059 int i;
3060
3061 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003062 for_each_ring(signaller, dev_priv, i) {
3063 if (ring == signaller)
3064 continue;
3065
3066 if (offset == signaller->semaphore.signal_ggtt[ring->id])
3067 return signaller;
3068 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01003069 } else {
3070 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
3071
3072 for_each_ring(signaller, dev_priv, i) {
3073 if(ring == signaller)
3074 continue;
3075
Ben Widawskyebc348b2014-04-29 14:52:28 -07003076 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01003077 return signaller;
3078 }
3079 }
3080
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003081 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
3082 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01003083
3084 return NULL;
3085}
3086
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003087static struct intel_engine_cs *
3088semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02003089{
3090 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003091 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003092 u64 offset = 0;
3093 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02003094
3095 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01003096 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01003097 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02003098
Daniel Vetter88fe4292014-03-15 00:08:55 +01003099 /*
3100 * HEAD is likely pointing to the dword after the actual command,
3101 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003102 * or 4 dwords depending on the semaphore wait command size.
3103 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01003104 * point at at batch, and semaphores are always emitted into the
3105 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02003106 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01003107 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003108 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003109
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003110 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01003111 /*
3112 * Be paranoid and presume the hw has gone off into the wild -
3113 * our ring is smaller than what the hardware (and hence
3114 * HEAD_ADDR) allows. Also handles wrap-around.
3115 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003116 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01003117
3118 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003119 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02003120 if (cmd == ipehr)
3121 break;
3122
Daniel Vetter88fe4292014-03-15 00:08:55 +01003123 head -= 4;
3124 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003125
Daniel Vetter88fe4292014-03-15 00:08:55 +01003126 if (!i)
3127 return NULL;
3128
Oscar Mateoee1b1e52014-05-22 14:13:35 +01003129 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07003130 if (INTEL_INFO(ring->dev)->gen >= 8) {
3131 offset = ioread32(ring->buffer->virtual_start + head + 12);
3132 offset <<= 32;
3133 offset = ioread32(ring->buffer->virtual_start + head + 8);
3134 }
3135 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02003136}
3137
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003138static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01003139{
3140 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003141 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01003142 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01003143
Chris Wilson4be17382014-06-06 10:22:29 +01003144 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01003145
3146 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01003147 if (signaller == NULL)
3148 return -1;
3149
3150 /* Prevent pathological recursion due to driver bugs */
3151 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01003152 return -1;
3153
Chris Wilson4be17382014-06-06 10:22:29 +01003154 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
3155 return 1;
3156
Chris Wilsona0d036b2014-07-19 12:40:42 +01003157 /* cursory check for an unkickable deadlock */
3158 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
3159 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01003160 return -1;
3161
3162 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01003163}
3164
3165static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
3166{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003167 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01003168 int i;
3169
3170 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01003171 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01003172}
3173
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003174static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003175ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003176{
3177 struct drm_device *dev = ring->dev;
3178 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003179 u32 tmp;
3180
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003181 if (acthd != ring->hangcheck.acthd) {
3182 if (acthd > ring->hangcheck.max_acthd) {
3183 ring->hangcheck.max_acthd = acthd;
3184 return HANGCHECK_ACTIVE;
3185 }
3186
3187 return HANGCHECK_ACTIVE_LOOP;
3188 }
Chris Wilson6274f212013-06-10 11:20:21 +01003189
Chris Wilson9107e9d2013-06-10 11:20:20 +01003190 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003191 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003192
3193 /* Is the chip hanging on a WAIT_FOR_EVENT?
3194 * If so we can simply poke the RB_WAIT bit
3195 * and break the hang. This should work on
3196 * all but the second generation chipsets.
3197 */
3198 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003199 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02003200 i915_handle_error(dev, false,
3201 "Kicking stuck wait on %s",
3202 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003203 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003204 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003205 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003206
Chris Wilson6274f212013-06-10 11:20:21 +01003207 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
3208 switch (semaphore_passed(ring)) {
3209 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003210 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003211 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02003212 i915_handle_error(dev, false,
3213 "Kicking stuck semaphore on %s",
3214 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01003215 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003216 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003217 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003218 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003219 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003220 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003221
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003222 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003223}
3224
Ben Gamarif65d9422009-09-14 17:48:44 -04003225/**
3226 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003227 * batchbuffers in a long time. We keep track per ring seqno progress and
3228 * if there are no progress, hangcheck score for that ring is increased.
3229 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3230 * we kick the ring. If we see no progress on three subsequent calls
3231 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003232 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01003233static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04003234{
3235 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003236 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01003237 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01003238 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003239 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003240 bool stuck[I915_NUM_RINGS] = { 0 };
3241#define BUSY 1
3242#define KICK 5
3243#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01003244
Jani Nikulad330a952014-01-21 11:24:25 +02003245 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003246 return;
3247
Chris Wilsonb4519512012-05-11 14:29:30 +01003248 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00003249 u64 acthd;
3250 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003251 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01003252
Chris Wilson6274f212013-06-10 11:20:21 +01003253 semaphore_clear_deadlocks(dev_priv);
3254
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003255 seqno = ring->get_seqno(ring, false);
3256 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003257
Chris Wilson9107e9d2013-06-10 11:20:20 +01003258 if (ring->hangcheck.seqno == seqno) {
3259 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003260 ring->hangcheck.action = HANGCHECK_IDLE;
3261
Chris Wilson9107e9d2013-06-10 11:20:20 +01003262 if (waitqueue_active(&ring->irq_queue)) {
3263 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01003264 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01003265 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
3266 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
3267 ring->name);
3268 else
3269 DRM_INFO("Fake missed irq on %s\n",
3270 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01003271 wake_up_all(&ring->irq_queue);
3272 }
3273 /* Safeguard against driver failure */
3274 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003275 } else
3276 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003277 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003278 /* We always increment the hangcheck score
3279 * if the ring is busy and still processing
3280 * the same request, so that no single request
3281 * can run indefinitely (such as a chain of
3282 * batches). The only time we do not increment
3283 * the hangcheck score on this ring, if this
3284 * ring is in a legitimate wait for another
3285 * ring. In that case the waiting ring is a
3286 * victim and we want to be sure we catch the
3287 * right culprit. Then every time we do kick
3288 * the ring, add a small increment to the
3289 * score so that we can catch a batch that is
3290 * being repeatedly kicked and so responsible
3291 * for stalling the machine.
3292 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003293 ring->hangcheck.action = ring_stuck(ring,
3294 acthd);
3295
3296 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003297 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003298 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003299 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003300 break;
3301 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003302 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003303 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003304 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003305 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003306 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003307 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003308 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003309 stuck[i] = true;
3310 break;
3311 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003312 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003313 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03003314 ring->hangcheck.action = HANGCHECK_ACTIVE;
3315
Chris Wilson9107e9d2013-06-10 11:20:20 +01003316 /* Gradually reduce the count so that we catch DoS
3317 * attempts across multiple batches.
3318 */
3319 if (ring->hangcheck.score > 0)
3320 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003321
3322 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01003323 }
3324
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003325 ring->hangcheck.seqno = seqno;
3326 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003327 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003328 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003329
Mika Kuoppala92cab732013-05-24 17:16:07 +03003330 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02003331 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003332 DRM_INFO("%s on %s\n",
3333 stuck[i] ? "stuck" : "no progress",
3334 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01003335 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003336 }
3337 }
3338
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003339 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02003340 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003341
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003342 if (busy_count)
3343 /* Reset timer case chip hangs without another request
3344 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003345 i915_queue_hangcheck(dev);
3346}
3347
3348void i915_queue_hangcheck(struct drm_device *dev)
3349{
3350 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02003351 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003352 return;
3353
3354 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
3355 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003356}
3357
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003358static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003359{
3360 struct drm_i915_private *dev_priv = dev->dev_private;
3361
3362 if (HAS_PCH_NOP(dev))
3363 return;
3364
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003365 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003366
3367 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3368 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003369}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003370
Paulo Zanoni622364b2014-04-01 15:37:22 -03003371/*
3372 * SDEIER is also touched by the interrupt handler to work around missed PCH
3373 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3374 * instead we unconditionally enable all PCH interrupt sources here, but then
3375 * only unmask them as needed with SDEIMR.
3376 *
3377 * This function needs to be called before interrupts are enabled.
3378 */
3379static void ibx_irq_pre_postinstall(struct drm_device *dev)
3380{
3381 struct drm_i915_private *dev_priv = dev->dev_private;
3382
3383 if (HAS_PCH_NOP(dev))
3384 return;
3385
3386 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003387 I915_WRITE(SDEIER, 0xffffffff);
3388 POSTING_READ(SDEIER);
3389}
3390
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003391static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003392{
3393 struct drm_i915_private *dev_priv = dev->dev_private;
3394
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003395 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003396 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003397 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003398}
3399
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400/* drm_dma.h hooks
3401*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003402static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003403{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003404 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003405
Paulo Zanoni0c841212014-04-01 15:37:27 -03003406 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003407
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003408 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003409 if (IS_GEN7(dev))
3410 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003411
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003412 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003413
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003414 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003415}
3416
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003417static void valleyview_irq_preinstall(struct drm_device *dev)
3418{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003419 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003420 int pipe;
3421
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003422 /* VLV magic */
3423 I915_WRITE(VLV_IMR, 0);
3424 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3425 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3426 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3427
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003428 /* and GT */
3429 I915_WRITE(GTIIR, I915_READ(GTIIR));
3430 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003431
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003432 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003433
3434 I915_WRITE(DPINVGTT, 0xff);
3435
3436 I915_WRITE(PORT_HOTPLUG_EN, 0);
3437 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Damien Lespiau055e3932014-08-18 13:49:10 +01003438 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003439 I915_WRITE(PIPESTAT(pipe), 0xffff);
3440 I915_WRITE(VLV_IIR, 0xffffffff);
3441 I915_WRITE(VLV_IMR, 0xffffffff);
3442 I915_WRITE(VLV_IER, 0x0);
3443 POSTING_READ(VLV_IER);
3444}
3445
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003446static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3447{
3448 GEN8_IRQ_RESET_NDX(GT, 0);
3449 GEN8_IRQ_RESET_NDX(GT, 1);
3450 GEN8_IRQ_RESET_NDX(GT, 2);
3451 GEN8_IRQ_RESET_NDX(GT, 3);
3452}
3453
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003454static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003455{
3456 struct drm_i915_private *dev_priv = dev->dev_private;
3457 int pipe;
3458
Ben Widawskyabd58f02013-11-02 21:07:09 -07003459 I915_WRITE(GEN8_MASTER_IRQ, 0);
3460 POSTING_READ(GEN8_MASTER_IRQ);
3461
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003462 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003463
Damien Lespiau055e3932014-08-18 13:49:10 +01003464 for_each_pipe(dev_priv, pipe)
Paulo Zanoni813bde42014-07-04 11:50:29 -03003465 if (intel_display_power_enabled(dev_priv,
3466 POWER_DOMAIN_PIPE(pipe)))
3467 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003468
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003469 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3470 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3471 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003472
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003473 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003474}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003475
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003476void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv)
3477{
Daniel Vetter13321782014-09-15 14:55:29 +02003478 spin_lock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003479 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B, dev_priv->de_irq_mask[PIPE_B],
3480 ~dev_priv->de_irq_mask[PIPE_B]);
3481 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C, dev_priv->de_irq_mask[PIPE_C],
3482 ~dev_priv->de_irq_mask[PIPE_C]);
Daniel Vetter13321782014-09-15 14:55:29 +02003483 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003484}
3485
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003486static void cherryview_irq_preinstall(struct drm_device *dev)
3487{
3488 struct drm_i915_private *dev_priv = dev->dev_private;
3489 int pipe;
3490
3491 I915_WRITE(GEN8_MASTER_IRQ, 0);
3492 POSTING_READ(GEN8_MASTER_IRQ);
3493
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003494 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003495
3496 GEN5_IRQ_RESET(GEN8_PCU_);
3497
3498 POSTING_READ(GEN8_PCU_IIR);
3499
3500 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3501
3502 I915_WRITE(PORT_HOTPLUG_EN, 0);
3503 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3504
Damien Lespiau055e3932014-08-18 13:49:10 +01003505 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003506 I915_WRITE(PIPESTAT(pipe), 0xffff);
3507
3508 I915_WRITE(VLV_IMR, 0xffffffff);
3509 I915_WRITE(VLV_IER, 0x0);
3510 I915_WRITE(VLV_IIR, 0xffffffff);
3511 POSTING_READ(VLV_IIR);
3512}
3513
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003514static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003515{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003516 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003517 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02003518 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07003519
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003520 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003521 hotplug_irqs = SDE_HOTPLUG_MASK;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003522 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003523 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003524 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003525 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003526 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003527 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003528 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003529 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003530 }
3531
Daniel Vetterfee884e2013-07-04 23:35:21 +02003532 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003533
3534 /*
3535 * Enable digital hotplug on the PCH, and configure the DP short pulse
3536 * duration to 2ms (which is the minimum in the Display Port spec)
3537 *
3538 * This register is the same on all known PCH chips.
3539 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003540 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3541 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3542 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3543 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3544 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3545 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3546}
3547
Paulo Zanonid46da432013-02-08 17:35:15 -02003548static void ibx_irq_postinstall(struct drm_device *dev)
3549{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003550 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003551 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003552
Daniel Vetter692a04c2013-05-29 21:43:05 +02003553 if (HAS_PCH_NOP(dev))
3554 return;
3555
Paulo Zanoni105b1222014-04-01 15:37:17 -03003556 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003557 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003558 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003559 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003560
Paulo Zanoni337ba012014-04-01 15:37:16 -03003561 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003562 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003563}
3564
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003565static void gen5_gt_irq_postinstall(struct drm_device *dev)
3566{
3567 struct drm_i915_private *dev_priv = dev->dev_private;
3568 u32 pm_irqs, gt_irqs;
3569
3570 pm_irqs = gt_irqs = 0;
3571
3572 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003573 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003574 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003575 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3576 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003577 }
3578
3579 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3580 if (IS_GEN5(dev)) {
3581 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3582 ILK_BSD_USER_INTERRUPT;
3583 } else {
3584 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3585 }
3586
Paulo Zanoni35079892014-04-01 15:37:15 -03003587 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003588
3589 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303590 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003591
3592 if (HAS_VEBOX(dev))
3593 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3594
Paulo Zanoni605cd252013-08-06 18:57:15 -03003595 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003596 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003597 }
3598}
3599
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003600static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003601{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003602 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003603 u32 display_mask, extra_mask;
3604
3605 if (INTEL_INFO(dev)->gen >= 7) {
3606 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3607 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3608 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003609 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003610 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003611 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003612 } else {
3613 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3614 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003615 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003616 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3617 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003618 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3619 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003620 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003621
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003622 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003623
Paulo Zanoni0c841212014-04-01 15:37:27 -03003624 I915_WRITE(HWSTAM, 0xeffe);
3625
Paulo Zanoni622364b2014-04-01 15:37:22 -03003626 ibx_irq_pre_postinstall(dev);
3627
Paulo Zanoni35079892014-04-01 15:37:15 -03003628 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003629
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003630 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003631
Paulo Zanonid46da432013-02-08 17:35:15 -02003632 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003633
Jesse Barnesf97108d2010-01-29 11:27:07 -08003634 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003635 /* Enable PCU event interrupts
3636 *
3637 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003638 * setup is guaranteed to run in single-threaded context. But we
3639 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003640 spin_lock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003641 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003642 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003643 }
3644
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003645 return 0;
3646}
3647
Imre Deakf8b79e52014-03-04 19:23:07 +02003648static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3649{
3650 u32 pipestat_mask;
3651 u32 iir_mask;
3652
3653 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3654 PIPE_FIFO_UNDERRUN_STATUS;
3655
3656 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3657 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3658 POSTING_READ(PIPESTAT(PIPE_A));
3659
3660 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3661 PIPE_CRC_DONE_INTERRUPT_STATUS;
3662
3663 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3664 PIPE_GMBUS_INTERRUPT_STATUS);
3665 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3666
3667 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3668 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3669 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3670 dev_priv->irq_mask &= ~iir_mask;
3671
3672 I915_WRITE(VLV_IIR, iir_mask);
3673 I915_WRITE(VLV_IIR, iir_mask);
3674 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3675 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3676 POSTING_READ(VLV_IER);
3677}
3678
3679static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3680{
3681 u32 pipestat_mask;
3682 u32 iir_mask;
3683
3684 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3685 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003686 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003687
3688 dev_priv->irq_mask |= iir_mask;
3689 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3690 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3691 I915_WRITE(VLV_IIR, iir_mask);
3692 I915_WRITE(VLV_IIR, iir_mask);
3693 POSTING_READ(VLV_IIR);
3694
3695 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3696 PIPE_CRC_DONE_INTERRUPT_STATUS;
3697
3698 i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3699 PIPE_GMBUS_INTERRUPT_STATUS);
3700 i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3701
3702 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3703 PIPE_FIFO_UNDERRUN_STATUS;
3704 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3705 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3706 POSTING_READ(PIPESTAT(PIPE_A));
3707}
3708
3709void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3710{
3711 assert_spin_locked(&dev_priv->irq_lock);
3712
3713 if (dev_priv->display_irqs_enabled)
3714 return;
3715
3716 dev_priv->display_irqs_enabled = true;
3717
Imre Deak950eaba2014-09-08 15:21:09 +03003718 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003719 valleyview_display_irqs_install(dev_priv);
3720}
3721
3722void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3723{
3724 assert_spin_locked(&dev_priv->irq_lock);
3725
3726 if (!dev_priv->display_irqs_enabled)
3727 return;
3728
3729 dev_priv->display_irqs_enabled = false;
3730
Imre Deak950eaba2014-09-08 15:21:09 +03003731 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003732 valleyview_display_irqs_uninstall(dev_priv);
3733}
3734
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003735static int valleyview_irq_postinstall(struct drm_device *dev)
3736{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003737 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003738
Imre Deakf8b79e52014-03-04 19:23:07 +02003739 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003740
Daniel Vetter20afbda2012-12-11 14:05:07 +01003741 I915_WRITE(PORT_HOTPLUG_EN, 0);
3742 POSTING_READ(PORT_HOTPLUG_EN);
3743
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003744 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003745 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003746 I915_WRITE(VLV_IIR, 0xffffffff);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003747 POSTING_READ(VLV_IER);
3748
Daniel Vetterb79480b2013-06-27 17:52:10 +02003749 /* Interrupt setup is already guaranteed to be single-threaded, this is
3750 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003751 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003752 if (dev_priv->display_irqs_enabled)
3753 valleyview_display_irqs_install(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003754 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003755
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003756 I915_WRITE(VLV_IIR, 0xffffffff);
3757 I915_WRITE(VLV_IIR, 0xffffffff);
3758
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003759 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003760
3761 /* ack & enable invalid PTE error interrupts */
3762#if 0 /* FIXME: add support to irq handler for checking these bits */
3763 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3764 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3765#endif
3766
3767 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003768
3769 return 0;
3770}
3771
Ben Widawskyabd58f02013-11-02 21:07:09 -07003772static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3773{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003774 /* These are interrupts we'll toggle with the ring mask register */
3775 uint32_t gt_interrupts[] = {
3776 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003777 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003778 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003779 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3780 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003781 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003782 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3783 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3784 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003785 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003786 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3787 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003788 };
3789
Ben Widawsky09610212014-05-15 20:58:08 +03003790 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303791 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3792 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
3793 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, dev_priv->pm_rps_events);
3794 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003795}
3796
3797static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3798{
Damien Lespiaud0e1f1c2014-04-08 01:22:44 +01003799 uint32_t de_pipe_masked = GEN8_PIPE_PRIMARY_FLIP_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003800 GEN8_PIPE_CDCLK_CRC_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003801 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Daniel Vetter5c673b62014-03-07 20:34:46 +01003802 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3803 GEN8_PIPE_FIFO_UNDERRUN;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003804 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003805 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3806 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3807 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003808
Damien Lespiau055e3932014-08-18 13:49:10 +01003809 for_each_pipe(dev_priv, pipe)
Paulo Zanoni813bde42014-07-04 11:50:29 -03003810 if (intel_display_power_enabled(dev_priv,
3811 POWER_DOMAIN_PIPE(pipe)))
3812 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3813 dev_priv->de_irq_mask[pipe],
3814 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003815
Paulo Zanoni35079892014-04-01 15:37:15 -03003816 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~GEN8_AUX_CHANNEL_A, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003817}
3818
3819static int gen8_irq_postinstall(struct drm_device *dev)
3820{
3821 struct drm_i915_private *dev_priv = dev->dev_private;
3822
Paulo Zanoni622364b2014-04-01 15:37:22 -03003823 ibx_irq_pre_postinstall(dev);
3824
Ben Widawskyabd58f02013-11-02 21:07:09 -07003825 gen8_gt_irq_postinstall(dev_priv);
3826 gen8_de_irq_postinstall(dev_priv);
3827
3828 ibx_irq_postinstall(dev);
3829
3830 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3831 POSTING_READ(GEN8_MASTER_IRQ);
3832
3833 return 0;
3834}
3835
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003836static int cherryview_irq_postinstall(struct drm_device *dev)
3837{
3838 struct drm_i915_private *dev_priv = dev->dev_private;
3839 u32 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3840 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003841 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä3278f672014-04-09 13:28:49 +03003842 I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
3843 u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
3844 PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003845 int pipe;
3846
3847 /*
3848 * Leave vblank interrupts masked initially. enable/disable will
3849 * toggle them based on usage.
3850 */
Ville Syrjälä3278f672014-04-09 13:28:49 +03003851 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003852
Damien Lespiau055e3932014-08-18 13:49:10 +01003853 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003854 I915_WRITE(PIPESTAT(pipe), 0xffff);
3855
Daniel Vetterd6207432014-09-15 14:55:27 +02003856 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä3278f672014-04-09 13:28:49 +03003857 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
Damien Lespiau055e3932014-08-18 13:49:10 +01003858 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003859 i915_enable_pipestat(dev_priv, pipe, pipestat_enable);
Daniel Vetterd6207432014-09-15 14:55:27 +02003860 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003861
3862 I915_WRITE(VLV_IIR, 0xffffffff);
3863 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3864 I915_WRITE(VLV_IER, enable_mask);
3865
3866 gen8_gt_irq_postinstall(dev_priv);
3867
3868 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3869 POSTING_READ(GEN8_MASTER_IRQ);
3870
3871 return 0;
3872}
3873
Ben Widawskyabd58f02013-11-02 21:07:09 -07003874static void gen8_irq_uninstall(struct drm_device *dev)
3875{
3876 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003877
3878 if (!dev_priv)
3879 return;
3880
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003881 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003882}
3883
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003884static void valleyview_irq_uninstall(struct drm_device *dev)
3885{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003886 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003887 int pipe;
3888
3889 if (!dev_priv)
3890 return;
3891
Imre Deak843d0e72014-04-14 20:24:23 +03003892 I915_WRITE(VLV_MASTER_IER, 0);
3893
Damien Lespiau055e3932014-08-18 13:49:10 +01003894 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003895 I915_WRITE(PIPESTAT(pipe), 0xffff);
3896
3897 I915_WRITE(HWSTAM, 0xffffffff);
3898 I915_WRITE(PORT_HOTPLUG_EN, 0);
3899 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Imre Deakf8b79e52014-03-04 19:23:07 +02003900
Daniel Vetterd6207432014-09-15 14:55:27 +02003901 /* Interrupt setup is already guaranteed to be single-threaded, this is
3902 * just to make the assert_spin_locked check happy. */
3903 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003904 if (dev_priv->display_irqs_enabled)
3905 valleyview_display_irqs_uninstall(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003906 spin_unlock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003907
3908 dev_priv->irq_mask = 0;
3909
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003910 I915_WRITE(VLV_IIR, 0xffffffff);
3911 I915_WRITE(VLV_IMR, 0xffffffff);
3912 I915_WRITE(VLV_IER, 0x0);
3913 POSTING_READ(VLV_IER);
3914}
3915
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003916static void cherryview_irq_uninstall(struct drm_device *dev)
3917{
3918 struct drm_i915_private *dev_priv = dev->dev_private;
3919 int pipe;
3920
3921 if (!dev_priv)
3922 return;
3923
3924 I915_WRITE(GEN8_MASTER_IRQ, 0);
3925 POSTING_READ(GEN8_MASTER_IRQ);
3926
3927#define GEN8_IRQ_FINI_NDX(type, which) \
3928do { \
3929 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3930 I915_WRITE(GEN8_##type##_IER(which), 0); \
3931 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3932 POSTING_READ(GEN8_##type##_IIR(which)); \
3933 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3934} while (0)
3935
3936#define GEN8_IRQ_FINI(type) \
3937do { \
3938 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3939 I915_WRITE(GEN8_##type##_IER, 0); \
3940 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3941 POSTING_READ(GEN8_##type##_IIR); \
3942 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3943} while (0)
3944
3945 GEN8_IRQ_FINI_NDX(GT, 0);
3946 GEN8_IRQ_FINI_NDX(GT, 1);
3947 GEN8_IRQ_FINI_NDX(GT, 2);
3948 GEN8_IRQ_FINI_NDX(GT, 3);
3949
3950 GEN8_IRQ_FINI(PCU);
3951
3952#undef GEN8_IRQ_FINI
3953#undef GEN8_IRQ_FINI_NDX
3954
3955 I915_WRITE(PORT_HOTPLUG_EN, 0);
3956 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3957
Damien Lespiau055e3932014-08-18 13:49:10 +01003958 for_each_pipe(dev_priv, pipe)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003959 I915_WRITE(PIPESTAT(pipe), 0xffff);
3960
3961 I915_WRITE(VLV_IMR, 0xffffffff);
3962 I915_WRITE(VLV_IER, 0x0);
3963 I915_WRITE(VLV_IIR, 0xffffffff);
3964 POSTING_READ(VLV_IIR);
3965}
3966
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003967static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003968{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003969 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003970
3971 if (!dev_priv)
3972 return;
3973
Paulo Zanonibe30b292014-04-01 15:37:25 -03003974 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003975}
3976
Chris Wilsonc2798b12012-04-22 21:13:57 +01003977static void i8xx_irq_preinstall(struct drm_device * dev)
3978{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003979 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003980 int pipe;
3981
Damien Lespiau055e3932014-08-18 13:49:10 +01003982 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003983 I915_WRITE(PIPESTAT(pipe), 0);
3984 I915_WRITE16(IMR, 0xffff);
3985 I915_WRITE16(IER, 0x0);
3986 POSTING_READ16(IER);
3987}
3988
3989static int i8xx_irq_postinstall(struct drm_device *dev)
3990{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003991 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003992
Chris Wilsonc2798b12012-04-22 21:13:57 +01003993 I915_WRITE16(EMR,
3994 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3995
3996 /* Unmask the interrupts that we always want on. */
3997 dev_priv->irq_mask =
3998 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3999 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4000 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4001 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4002 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4003 I915_WRITE16(IMR, dev_priv->irq_mask);
4004
4005 I915_WRITE16(IER,
4006 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4007 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4008 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4009 I915_USER_INTERRUPT);
4010 POSTING_READ16(IER);
4011
Daniel Vetter379ef822013-10-16 22:55:56 +02004012 /* Interrupt setup is already guaranteed to be single-threaded, this is
4013 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004014 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004015 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4016 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004017 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004018
Chris Wilsonc2798b12012-04-22 21:13:57 +01004019 return 0;
4020}
4021
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004022/*
4023 * Returns true when a page flip has completed.
4024 */
4025static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004026 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004027{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004028 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004029 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004030
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004031 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004032 return false;
4033
4034 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004035 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004036
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004037 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004038
4039 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4040 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4041 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4042 * the flip is completed (no longer pending). Since this doesn't raise
4043 * an interrupt per se, we watch for the change at vblank.
4044 */
4045 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004046 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004047
4048 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004049 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004050
4051check_page_flip:
4052 intel_check_page_flip(dev, pipe);
4053 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004054}
4055
Daniel Vetterff1f5252012-10-02 15:10:55 +02004056static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004057{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004058 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004059 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004060 u16 iir, new_iir;
4061 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01004062 int pipe;
4063 u16 flip_mask =
4064 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4065 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
4066
Chris Wilsonc2798b12012-04-22 21:13:57 +01004067 iir = I915_READ16(IIR);
4068 if (iir == 0)
4069 return IRQ_NONE;
4070
4071 while (iir & ~flip_mask) {
4072 /* Can't rely on pipestat interrupt bit in iir as it might
4073 * have been cleared after the pipestat interrupt was received.
4074 * It doesn't set the bit in iir again, but it still produces
4075 * interrupts (for non-MSI).
4076 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004077 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004078 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004079 i915_handle_error(dev, false,
4080 "Command parser error, iir 0x%08x",
4081 iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004082
Damien Lespiau055e3932014-08-18 13:49:10 +01004083 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004084 int reg = PIPESTAT(pipe);
4085 pipe_stats[pipe] = I915_READ(reg);
4086
4087 /*
4088 * Clear the PIPE*STAT regs before the IIR
4089 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004090 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004091 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004092 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004093 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004094
4095 I915_WRITE16(IIR, iir & ~flip_mask);
4096 new_iir = I915_READ16(IIR); /* Flush posted writes */
4097
Daniel Vetterd05c6172012-04-26 23:28:09 +02004098 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004099
4100 if (iir & I915_USER_INTERRUPT)
4101 notify_ring(dev, &dev_priv->ring[RCS]);
4102
Damien Lespiau055e3932014-08-18 13:49:10 +01004103 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004104 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004105 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004106 plane = !plane;
4107
Daniel Vetter4356d582013-10-16 22:55:55 +02004108 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02004109 i8xx_handle_vblank(dev, plane, pipe, iir))
4110 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004111
Daniel Vetter4356d582013-10-16 22:55:55 +02004112 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004113 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004114
4115 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4116 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004117 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02004118 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004119
4120 iir = new_iir;
4121 }
4122
4123 return IRQ_HANDLED;
4124}
4125
4126static void i8xx_irq_uninstall(struct drm_device * dev)
4127{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004128 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004129 int pipe;
4130
Damien Lespiau055e3932014-08-18 13:49:10 +01004131 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004132 /* Clear enable bits; then clear status bits */
4133 I915_WRITE(PIPESTAT(pipe), 0);
4134 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4135 }
4136 I915_WRITE16(IMR, 0xffff);
4137 I915_WRITE16(IER, 0x0);
4138 I915_WRITE16(IIR, I915_READ16(IIR));
4139}
4140
Chris Wilsona266c7d2012-04-24 22:59:44 +01004141static void i915_irq_preinstall(struct drm_device * dev)
4142{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004143 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004144 int pipe;
4145
Chris Wilsona266c7d2012-04-24 22:59:44 +01004146 if (I915_HAS_HOTPLUG(dev)) {
4147 I915_WRITE(PORT_HOTPLUG_EN, 0);
4148 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4149 }
4150
Chris Wilson00d98eb2012-04-24 22:59:48 +01004151 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004152 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004153 I915_WRITE(PIPESTAT(pipe), 0);
4154 I915_WRITE(IMR, 0xffffffff);
4155 I915_WRITE(IER, 0x0);
4156 POSTING_READ(IER);
4157}
4158
4159static int i915_irq_postinstall(struct drm_device *dev)
4160{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004161 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01004162 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004163
Chris Wilson38bde182012-04-24 22:59:50 +01004164 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4165
4166 /* Unmask the interrupts that we always want on. */
4167 dev_priv->irq_mask =
4168 ~(I915_ASLE_INTERRUPT |
4169 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4170 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4171 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4172 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4173 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4174
4175 enable_mask =
4176 I915_ASLE_INTERRUPT |
4177 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4178 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4179 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4180 I915_USER_INTERRUPT;
4181
Chris Wilsona266c7d2012-04-24 22:59:44 +01004182 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01004183 I915_WRITE(PORT_HOTPLUG_EN, 0);
4184 POSTING_READ(PORT_HOTPLUG_EN);
4185
Chris Wilsona266c7d2012-04-24 22:59:44 +01004186 /* Enable in IER... */
4187 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4188 /* and unmask in IMR */
4189 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4190 }
4191
Chris Wilsona266c7d2012-04-24 22:59:44 +01004192 I915_WRITE(IMR, dev_priv->irq_mask);
4193 I915_WRITE(IER, enable_mask);
4194 POSTING_READ(IER);
4195
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004196 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004197
Daniel Vetter379ef822013-10-16 22:55:56 +02004198 /* Interrupt setup is already guaranteed to be single-threaded, this is
4199 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004200 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004201 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4202 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004203 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004204
Daniel Vetter20afbda2012-12-11 14:05:07 +01004205 return 0;
4206}
4207
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004208/*
4209 * Returns true when a page flip has completed.
4210 */
4211static bool i915_handle_vblank(struct drm_device *dev,
4212 int plane, int pipe, u32 iir)
4213{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004214 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004215 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4216
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004217 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004218 return false;
4219
4220 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004221 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004222
4223 intel_prepare_page_flip(dev, plane);
4224
4225 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4226 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4227 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4228 * the flip is completed (no longer pending). Since this doesn't raise
4229 * an interrupt per se, we watch for the change at vblank.
4230 */
4231 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004232 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004233
4234 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004235 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004236
4237check_page_flip:
4238 intel_check_page_flip(dev, pipe);
4239 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004240}
4241
Daniel Vetterff1f5252012-10-02 15:10:55 +02004242static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004243{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004244 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004245 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01004246 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004247 u32 flip_mask =
4248 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4249 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004250 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004251
Chris Wilsona266c7d2012-04-24 22:59:44 +01004252 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004253 do {
4254 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004255 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004256
4257 /* Can't rely on pipestat interrupt bit in iir as it might
4258 * have been cleared after the pipestat interrupt was received.
4259 * It doesn't set the bit in iir again, but it still produces
4260 * interrupts (for non-MSI).
4261 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004262 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004263 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004264 i915_handle_error(dev, false,
4265 "Command parser error, iir 0x%08x",
4266 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004267
Damien Lespiau055e3932014-08-18 13:49:10 +01004268 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004269 int reg = PIPESTAT(pipe);
4270 pipe_stats[pipe] = I915_READ(reg);
4271
Chris Wilson38bde182012-04-24 22:59:50 +01004272 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004273 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004274 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004275 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004276 }
4277 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004278 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004279
4280 if (!irq_received)
4281 break;
4282
Chris Wilsona266c7d2012-04-24 22:59:44 +01004283 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004284 if (I915_HAS_HOTPLUG(dev) &&
4285 iir & I915_DISPLAY_PORT_INTERRUPT)
4286 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004287
Chris Wilson38bde182012-04-24 22:59:50 +01004288 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004289 new_iir = I915_READ(IIR); /* Flush posted writes */
4290
Chris Wilsona266c7d2012-04-24 22:59:44 +01004291 if (iir & I915_USER_INTERRUPT)
4292 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004293
Damien Lespiau055e3932014-08-18 13:49:10 +01004294 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01004295 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004296 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01004297 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02004298
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004299 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4300 i915_handle_vblank(dev, plane, pipe, iir))
4301 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004302
4303 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4304 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004305
4306 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004307 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004308
4309 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4310 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004311 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004312 }
4313
Chris Wilsona266c7d2012-04-24 22:59:44 +01004314 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4315 intel_opregion_asle_intr(dev);
4316
4317 /* With MSI, interrupts are only generated when iir
4318 * transitions from zero to nonzero. If another bit got
4319 * set while we were handling the existing iir bits, then
4320 * we would never get another interrupt.
4321 *
4322 * This is fine on non-MSI as well, as if we hit this path
4323 * we avoid exiting the interrupt handler only to generate
4324 * another one.
4325 *
4326 * Note that for MSI this could cause a stray interrupt report
4327 * if an interrupt landed in the time between writing IIR and
4328 * the posting read. This should be rare enough to never
4329 * trigger the 99% of 100,000 interrupts test for disabling
4330 * stray interrupts.
4331 */
Chris Wilson38bde182012-04-24 22:59:50 +01004332 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004333 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004334 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004335
Daniel Vetterd05c6172012-04-26 23:28:09 +02004336 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004337
Chris Wilsona266c7d2012-04-24 22:59:44 +01004338 return ret;
4339}
4340
4341static void i915_irq_uninstall(struct drm_device * dev)
4342{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004343 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004344 int pipe;
4345
Chris Wilsona266c7d2012-04-24 22:59:44 +01004346 if (I915_HAS_HOTPLUG(dev)) {
4347 I915_WRITE(PORT_HOTPLUG_EN, 0);
4348 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4349 }
4350
Chris Wilson00d98eb2012-04-24 22:59:48 +01004351 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004352 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004353 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004354 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004355 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4356 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004357 I915_WRITE(IMR, 0xffffffff);
4358 I915_WRITE(IER, 0x0);
4359
Chris Wilsona266c7d2012-04-24 22:59:44 +01004360 I915_WRITE(IIR, I915_READ(IIR));
4361}
4362
4363static void i965_irq_preinstall(struct drm_device * dev)
4364{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004365 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004366 int pipe;
4367
Chris Wilsonadca4732012-05-11 18:01:31 +01004368 I915_WRITE(PORT_HOTPLUG_EN, 0);
4369 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004370
4371 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004372 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004373 I915_WRITE(PIPESTAT(pipe), 0);
4374 I915_WRITE(IMR, 0xffffffff);
4375 I915_WRITE(IER, 0x0);
4376 POSTING_READ(IER);
4377}
4378
4379static int i965_irq_postinstall(struct drm_device *dev)
4380{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004381 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004382 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004383 u32 error_mask;
4384
Chris Wilsona266c7d2012-04-24 22:59:44 +01004385 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004386 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004387 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004388 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4389 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4390 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4391 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4392 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4393
4394 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004395 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4396 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004397 enable_mask |= I915_USER_INTERRUPT;
4398
4399 if (IS_G4X(dev))
4400 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004401
Daniel Vetterb79480b2013-06-27 17:52:10 +02004402 /* Interrupt setup is already guaranteed to be single-threaded, this is
4403 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004404 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004405 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4406 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4407 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004408 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004409
Chris Wilsona266c7d2012-04-24 22:59:44 +01004410 /*
4411 * Enable some error detection, note the instruction error mask
4412 * bit is reserved, so we leave it masked.
4413 */
4414 if (IS_G4X(dev)) {
4415 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4416 GM45_ERROR_MEM_PRIV |
4417 GM45_ERROR_CP_PRIV |
4418 I915_ERROR_MEMORY_REFRESH);
4419 } else {
4420 error_mask = ~(I915_ERROR_PAGE_TABLE |
4421 I915_ERROR_MEMORY_REFRESH);
4422 }
4423 I915_WRITE(EMR, error_mask);
4424
4425 I915_WRITE(IMR, dev_priv->irq_mask);
4426 I915_WRITE(IER, enable_mask);
4427 POSTING_READ(IER);
4428
Daniel Vetter20afbda2012-12-11 14:05:07 +01004429 I915_WRITE(PORT_HOTPLUG_EN, 0);
4430 POSTING_READ(PORT_HOTPLUG_EN);
4431
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004432 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004433
4434 return 0;
4435}
4436
Egbert Eichbac56d52013-02-25 12:06:51 -05004437static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004438{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004439 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichcd569ae2013-04-16 13:36:57 +02004440 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004441 u32 hotplug_en;
4442
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004443 assert_spin_locked(&dev_priv->irq_lock);
4444
Egbert Eichbac56d52013-02-25 12:06:51 -05004445 if (I915_HAS_HOTPLUG(dev)) {
4446 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4447 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4448 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05004449 /* enable bits are the same for all generations */
Damien Lespiaub2784e12014-08-05 11:29:37 +01004450 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02004451 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4452 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05004453 /* Programming the CRT detection parameters tends
4454 to generate a spurious hotplug event about three
4455 seconds later. So just do it once.
4456 */
4457 if (IS_G4X(dev))
4458 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01004459 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05004460 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004461
Egbert Eichbac56d52013-02-25 12:06:51 -05004462 /* Ignore TV since it's buggy */
4463 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4464 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004465}
4466
Daniel Vetterff1f5252012-10-02 15:10:55 +02004467static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004468{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004469 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004470 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004471 u32 iir, new_iir;
4472 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004473 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004474 u32 flip_mask =
4475 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4476 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004477
Chris Wilsona266c7d2012-04-24 22:59:44 +01004478 iir = I915_READ(IIR);
4479
Chris Wilsona266c7d2012-04-24 22:59:44 +01004480 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004481 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004482 bool blc_event = false;
4483
Chris Wilsona266c7d2012-04-24 22:59:44 +01004484 /* Can't rely on pipestat interrupt bit in iir as it might
4485 * have been cleared after the pipestat interrupt was received.
4486 * It doesn't set the bit in iir again, but it still produces
4487 * interrupts (for non-MSI).
4488 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004489 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004490 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02004491 i915_handle_error(dev, false,
4492 "Command parser error, iir 0x%08x",
4493 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004494
Damien Lespiau055e3932014-08-18 13:49:10 +01004495 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004496 int reg = PIPESTAT(pipe);
4497 pipe_stats[pipe] = I915_READ(reg);
4498
4499 /*
4500 * Clear the PIPE*STAT regs before the IIR
4501 */
4502 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004503 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004504 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004505 }
4506 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004507 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004508
4509 if (!irq_received)
4510 break;
4511
4512 ret = IRQ_HANDLED;
4513
4514 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004515 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4516 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004517
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004518 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004519 new_iir = I915_READ(IIR); /* Flush posted writes */
4520
Chris Wilsona266c7d2012-04-24 22:59:44 +01004521 if (iir & I915_USER_INTERRUPT)
4522 notify_ring(dev, &dev_priv->ring[RCS]);
4523 if (iir & I915_BSD_USER_INTERRUPT)
4524 notify_ring(dev, &dev_priv->ring[VCS]);
4525
Damien Lespiau055e3932014-08-18 13:49:10 +01004526 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004527 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004528 i915_handle_vblank(dev, pipe, pipe, iir))
4529 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004530
4531 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4532 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004533
4534 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004535 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004536
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004537 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
4538 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02004539 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004540 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004541
4542 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4543 intel_opregion_asle_intr(dev);
4544
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004545 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4546 gmbus_irq_handler(dev);
4547
Chris Wilsona266c7d2012-04-24 22:59:44 +01004548 /* With MSI, interrupts are only generated when iir
4549 * transitions from zero to nonzero. If another bit got
4550 * set while we were handling the existing iir bits, then
4551 * we would never get another interrupt.
4552 *
4553 * This is fine on non-MSI as well, as if we hit this path
4554 * we avoid exiting the interrupt handler only to generate
4555 * another one.
4556 *
4557 * Note that for MSI this could cause a stray interrupt report
4558 * if an interrupt landed in the time between writing IIR and
4559 * the posting read. This should be rare enough to never
4560 * trigger the 99% of 100,000 interrupts test for disabling
4561 * stray interrupts.
4562 */
4563 iir = new_iir;
4564 }
4565
Daniel Vetterd05c6172012-04-26 23:28:09 +02004566 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01004567
Chris Wilsona266c7d2012-04-24 22:59:44 +01004568 return ret;
4569}
4570
4571static void i965_irq_uninstall(struct drm_device * dev)
4572{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004573 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004574 int pipe;
4575
4576 if (!dev_priv)
4577 return;
4578
Chris Wilsonadca4732012-05-11 18:01:31 +01004579 I915_WRITE(PORT_HOTPLUG_EN, 0);
4580 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004581
4582 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004583 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004584 I915_WRITE(PIPESTAT(pipe), 0);
4585 I915_WRITE(IMR, 0xffffffff);
4586 I915_WRITE(IER, 0x0);
4587
Damien Lespiau055e3932014-08-18 13:49:10 +01004588 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004589 I915_WRITE(PIPESTAT(pipe),
4590 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4591 I915_WRITE(IIR, I915_READ(IIR));
4592}
4593
Daniel Vetter4cb21832014-09-15 14:55:26 +02004594static void intel_hpd_irq_reenable_work(struct work_struct *work)
Egbert Eichac4c16c2013-04-16 13:36:58 +02004595{
Imre Deak63237512014-08-18 15:37:02 +03004596 struct drm_i915_private *dev_priv =
4597 container_of(work, typeof(*dev_priv),
4598 hotplug_reenable_work.work);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004599 struct drm_device *dev = dev_priv->dev;
4600 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichac4c16c2013-04-16 13:36:58 +02004601 int i;
4602
Imre Deak63237512014-08-18 15:37:02 +03004603 intel_runtime_pm_get(dev_priv);
4604
Daniel Vetter4cb21832014-09-15 14:55:26 +02004605 spin_lock_irq(&dev_priv->irq_lock);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004606 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4607 struct drm_connector *connector;
4608
4609 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4610 continue;
4611
4612 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4613
4614 list_for_each_entry(connector, &mode_config->connector_list, head) {
4615 struct intel_connector *intel_connector = to_intel_connector(connector);
4616
4617 if (intel_connector->encoder->hpd_pin == i) {
4618 if (connector->polled != intel_connector->polled)
4619 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03004620 connector->name);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004621 connector->polled = intel_connector->polled;
4622 if (!connector->polled)
4623 connector->polled = DRM_CONNECTOR_POLL_HPD;
4624 }
4625 }
4626 }
4627 if (dev_priv->display.hpd_irq_setup)
4628 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetter4cb21832014-09-15 14:55:26 +02004629 spin_unlock_irq(&dev_priv->irq_lock);
Imre Deak63237512014-08-18 15:37:02 +03004630
4631 intel_runtime_pm_put(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004632}
4633
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004634void intel_irq_init(struct drm_device *dev)
4635{
Chris Wilson8b2e3262012-04-24 22:59:41 +01004636 struct drm_i915_private *dev_priv = dev->dev_private;
4637
4638 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Dave Airlie13cf5502014-06-18 11:29:35 +10004639 INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004640 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004641 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004642 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004643
Deepak Sa6706b42014-03-15 20:23:22 +05304644 /* Let's track the enabled rps events */
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004645 if (IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev))
4646 /* WaGsvRC0ResidencyMethod:vlv */
Deepak S31685c22014-07-03 17:33:01 -04004647 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
4648 else
4649 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304650
Daniel Vetter99584db2012-11-14 17:14:04 +01004651 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4652 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004653 (unsigned long) dev);
Imre Deak63237512014-08-18 15:37:02 +03004654 INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work,
Daniel Vetter4cb21832014-09-15 14:55:26 +02004655 intel_hpd_irq_reenable_work);
Daniel Vetter61bac782012-12-01 21:03:21 +01004656
Tomas Janousek97a19a22012-12-08 13:48:13 +01004657 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004658
Jesse Barnes95f25be2014-06-20 09:29:22 -07004659 /* Haven't installed the IRQ handler yet */
4660 dev_priv->pm._irqs_disabled = true;
4661
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004662 if (IS_GEN2(dev)) {
4663 dev->max_vblank_count = 0;
4664 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4665 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004666 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4667 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004668 } else {
4669 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4670 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004671 }
4672
Ville Syrjälä21da2702014-08-06 14:49:55 +03004673 /*
4674 * Opt out of the vblank disable timer on everything except gen2.
4675 * Gen2 doesn't have a hardware frame counter and so depends on
4676 * vblank interrupts to produce sane vblank seuquence numbers.
4677 */
4678 if (!IS_GEN2(dev))
4679 dev->vblank_disable_immediate = true;
4680
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004681 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004682 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004683 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4684 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004685
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004686 if (IS_CHERRYVIEW(dev)) {
4687 dev->driver->irq_handler = cherryview_irq_handler;
4688 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4689 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4690 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4691 dev->driver->enable_vblank = valleyview_enable_vblank;
4692 dev->driver->disable_vblank = valleyview_disable_vblank;
4693 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
4694 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004695 dev->driver->irq_handler = valleyview_irq_handler;
4696 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4697 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4698 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4699 dev->driver->enable_vblank = valleyview_enable_vblank;
4700 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004701 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004702 } else if (IS_GEN8(dev)) {
4703 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004704 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004705 dev->driver->irq_postinstall = gen8_irq_postinstall;
4706 dev->driver->irq_uninstall = gen8_irq_uninstall;
4707 dev->driver->enable_vblank = gen8_enable_vblank;
4708 dev->driver->disable_vblank = gen8_disable_vblank;
4709 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004710 } else if (HAS_PCH_SPLIT(dev)) {
4711 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004712 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004713 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4714 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4715 dev->driver->enable_vblank = ironlake_enable_vblank;
4716 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004717 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004718 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004719 if (INTEL_INFO(dev)->gen == 2) {
4720 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4721 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4722 dev->driver->irq_handler = i8xx_irq_handler;
4723 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004724 } else if (INTEL_INFO(dev)->gen == 3) {
4725 dev->driver->irq_preinstall = i915_irq_preinstall;
4726 dev->driver->irq_postinstall = i915_irq_postinstall;
4727 dev->driver->irq_uninstall = i915_irq_uninstall;
4728 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004729 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004730 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004731 dev->driver->irq_preinstall = i965_irq_preinstall;
4732 dev->driver->irq_postinstall = i965_irq_postinstall;
4733 dev->driver->irq_uninstall = i965_irq_uninstall;
4734 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004735 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004736 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004737 dev->driver->enable_vblank = i915_enable_vblank;
4738 dev->driver->disable_vblank = i915_disable_vblank;
4739 }
4740}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004741
4742void intel_hpd_init(struct drm_device *dev)
4743{
4744 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02004745 struct drm_mode_config *mode_config = &dev->mode_config;
4746 struct drm_connector *connector;
4747 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004748
Egbert Eich821450c2013-04-16 13:36:55 +02004749 for (i = 1; i < HPD_NUM_PINS; i++) {
4750 dev_priv->hpd_stats[i].hpd_cnt = 0;
4751 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4752 }
4753 list_for_each_entry(connector, &mode_config->connector_list, head) {
4754 struct intel_connector *intel_connector = to_intel_connector(connector);
4755 connector->polled = intel_connector->polled;
Dave Airlie0e32b392014-05-02 14:02:48 +10004756 if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4757 connector->polled = DRM_CONNECTOR_POLL_HPD;
4758 if (intel_connector->mst_port)
Egbert Eich821450c2013-04-16 13:36:55 +02004759 connector->polled = DRM_CONNECTOR_POLL_HPD;
4760 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004761
4762 /* Interrupt setup is already guaranteed to be single-threaded, this is
4763 * just to make the assert_spin_locked checks happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004764 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004765 if (dev_priv->display.hpd_irq_setup)
4766 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterd6207432014-09-15 14:55:27 +02004767 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004768}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004769
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004770/* Disable interrupts so we can allow runtime PM. */
Paulo Zanoni730488b2014-03-07 20:12:32 -03004771void intel_runtime_pm_disable_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004772{
4773 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004774
Paulo Zanoni730488b2014-03-07 20:12:32 -03004775 dev->driver->irq_uninstall(dev);
Jesse Barnes9df7575f2014-06-20 09:29:20 -07004776 dev_priv->pm._irqs_disabled = true;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004777}
4778
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004779/* Restore interrupts so we can recover from runtime PM. */
Paulo Zanoni730488b2014-03-07 20:12:32 -03004780void intel_runtime_pm_restore_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004781{
4782 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004783
Jesse Barnes9df7575f2014-06-20 09:29:20 -07004784 dev_priv->pm._irqs_disabled = false;
Paulo Zanoni730488b2014-03-07 20:12:32 -03004785 dev->driver->irq_preinstall(dev);
4786 dev->driver->irq_postinstall(dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004787}